Skip to content
Permalink
Browse files

added api IP table

  • Loading branch information...
danielkerr committed Jul 8, 2015
1 parent a0ff7c6 commit 6933ac7c50a9bc3be2ca1f6328cc0c9566450d74
@@ -569,6 +569,8 @@ protected function getForm() {
$data['text_form'] = !isset($this->request->get['affiliate_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
$data['text_enabled'] = $this->language->get('text_enabled');
$data['text_affiliate_detail'] = $this->language->get('text_affiliate_detail');
$data['text_affiliate_address'] = $this->language->get('text_affiliate_address');
$data['text_disabled'] = $this->language->get('text_disabled');
$data['text_select'] = $this->language->get('text_select');
$data['text_none'] = $this->language->get('text_none');
@@ -1132,18 +1132,6 @@ protected function validateUnlock() {
return !$this->error;
}
protected function validateHistory() {
if (!$this->user->hasPermission('modify', 'sale/customer')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if (!isset($this->request->post['comment']) || utf8_strlen($this->request->post['comment']) < 1) {
$this->error['warning'] = $this->language->get('error_comment');
}
return !$this->error;
}
public function login() {
$json = array();
@@ -273,10 +273,16 @@ protected function getForm() {
$data['entry_username'] = $this->language->get('entry_username');
$data['entry_password'] = $this->language->get('entry_password');
$data['entry_status'] = $this->language->get('entry_status');
$data['entry_ip'] = $this->language->get('entry_ip');
$data['button_save'] = $this->language->get('button_save');
$data['button_cancel'] = $this->language->get('button_cancel');
$data['button_generate'] = $this->language->get('button_generate');
$data['button_ip_add'] = $this->language->get('button_ip_add');
$data['button_remove'] = $this->language->get('button_remove');
$data['tab_general'] = $this->language->get('tab_general');
$data['tab_ip'] = $this->language->get('tab_ip');
if (isset($this->error['warning'])) {
$data['error_warning'] = $this->error['warning'];
@@ -358,6 +364,15 @@ protected function getForm() {
$data['status'] = 0;
}
// IP
if (isset($this->request->post['api_ip'])) {
$data['api_ips'] = $this->request->post['api_ip'];
} elseif (isset($this->request->get['api_id'])) {
$data['api_ips'] = $this->model_user_api->getApiIps($this->request->get['api_id']);
} else {
$data['api_ips'] = array();
}
$data['header'] = $this->load->controller('common/header');
$data['column_left'] = $this->load->controller('common/column_left');
$data['footer'] = $this->load->controller('common/footer');
@@ -388,4 +403,35 @@ protected function validateDelete() {
return !$this->error;
}
public function addIp() {
$this->load->language('user/api');
$json = array();
if (!$this->user->hasPermission('modify', 'user/api')) {
$json['error'] = $this->language->get('error_permission');
} else {
if (isset($this->request->get['api_id'])) {
$api_id = $this->request->get['api_id'];
} else {
$api_id = 0;
}
$this->load->model('sale/order');
$order_info = $this->model_sale_order->getOrder($order_id);
if ($order_info) {
$this->load->model('marketing/affiliate');
$this->model_marketing_affiliate->addTransaction($order_info['api_id'], $this->language->get('text_order_id') . ' #' . $order_id, $order_info['commission'], $order_id);
}
$json['success'] = $this->language->get('text_ip_added');
}
$this->response->addHeader('Content-Type: application/json');
$this->response->setOutput(json_encode($json));
}
}
@@ -8,6 +8,8 @@
$_['text_list'] = 'Affiliate List';
$_['text_add'] = 'Add Affiliate';
$_['text_edit'] = 'Edit Affiliate';
$_['text_affiliate_detail'] = 'Affiliate Details';
$_['text_affiliate_address'] = 'Affiliate Address';
$_['text_balance'] = 'Balance';
$_['text_cheque'] = 'Cheque';
$_['text_paypal'] = 'PayPal';
@@ -64,6 +66,7 @@
$_['help_commission'] = 'Percentage the affiliate receives on each order.';
// Error
$_['error_warning'] = 'Warning: Please check the form carefully for errors!';
$_['error_permission'] = 'Warning: You do not have permission to modify affiliates!';
$_['error_exists'] = 'Warning: E-Mail Address is already registered!';
$_['error_firstname'] = 'First Name must be between 1 and 32 characters!';
@@ -74,5 +74,4 @@
$_['error_postcode'] = 'Postcode must be between 2 and 10 characters for this country!';
$_['error_country'] = 'Please select a country!';
$_['error_zone'] = 'Please select a region / state!';
$_['error_custom_field'] = '%s required!';
$_['error_comment'] = 'You must enter a comment!';
$_['error_custom_field'] = '%s required!';
@@ -19,6 +19,7 @@
$_['entry_username'] = 'Username';
$_['entry_password'] = 'Password';
$_['entry_status'] = 'Status';
$_['entry_ip'] = 'IP';
// Error
$_['error_permission'] = 'Warning: You do not have permission to modify APIs!';
@@ -2,10 +2,30 @@
class ModelUserApi extends Model {
public function addApi($data) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "api` SET username = '" . $this->db->escape($data['username']) . "', `password` = '" . $this->db->escape($data['password']) . "', status = '" . (int)$data['status'] . "', date_added = NOW(), date_modified = NOW()");
$api_id = $this->db->getLastId();
if (isset($data['api_ip'])) {
foreach ($data['api_ip'] as $ip) {
if ($ip) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET api_id = '" . (int)$api_id . "', ip = '" . $this->db->escape($ip) . "'");
}
}
}
}
public function editApi($api_id, $data) {
$this->db->query("UPDATE `" . DB_PREFIX . "api` SET username = '" . $this->db->escape($data['username']) . "', `password` = '" . $this->db->escape($data['password']) . "', status = '" . (int)$data['status'] . "', date_modified = NOW() WHERE api_id = '" . (int)$api_id . "'");
$this->db->query("DELETE FROM " . DB_PREFIX . "api_ip WHERE api_id = '" . (int)$api_id . "'");
if (isset($data['api_ip'])) {
foreach ($data['api_ip'] as $ip) {
if ($ip) {
$this->db->query("INSERT INTO `" . DB_PREFIX . "api_ip` SET api_id = '" . (int)$api_id . "', ip = '" . $this->db->escape($ip) . "'");
}
}
}
}
public function deleteApi($api_id) {
@@ -57,9 +77,21 @@ public function getApis($data = array()) {
return $query->rows;
}
public function getApiIps($api_id) {
$query = $this->db->query("SELECT * FROM `" . DB_PREFIX . "api_ip` WHERE api_id = '" . (int)$api_id . "'");
return $query->rows;
}
public function getTotalApis() {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "api`");
return $query->row['total'];
}
public function getTotalApiIpsByIp($ip) {
$query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "api_ip` WHERE ip = '" . $this->db->escape($ip) . "'");
return $query->row['total'];
}
}
@@ -82,14 +82,6 @@
<li><a href="<?php echo $order; ?>"><?php echo $text_order; ?></a></li>
<li><a href="<?php echo $order_recurring; ?>"><?php echo $text_order_recurring; ?></a></li>
<li><a href="<?php echo $return; ?>"><?php echo $text_return; ?></a></li>
<li><a class="parent"><?php echo $text_customer; ?></a>
<ul>
<li><a href="<?php echo $customer; ?>"><?php echo $text_customer; ?></a></li>
<li><a href="<?php echo $customer_group; ?>"><?php echo $text_customer_group; ?></a></li>
<li><a href="<?php echo $custom_field; ?>"><?php echo $text_custom_field; ?></a></li>
<li><a href="<?php echo $customer_ban_ip; ?>"><?php echo $text_customer_ban_ip; ?></a></li>
</ul>
</li>
<li><a class="parent"><?php echo $text_voucher; ?></a>
<ul>
<li><a href="<?php echo $voucher; ?>"><?php echo $text_voucher; ?></a></li>
@@ -103,6 +95,14 @@
</li>
</ul>
</li>
<li id="customer"><a class="parent"><i class="fa fa-user fa-fw"></i> <span><?php echo $text_customer; ?></span></a>
<ul>
<li><a href="<?php echo $customer; ?>"><?php echo $text_customer; ?></a></li>
<li><a href="<?php echo $customer_group; ?>"><?php echo $text_customer_group; ?></a></li>
<li><a href="<?php echo $custom_field; ?>"><?php echo $text_custom_field; ?></a></li>
<li><a href="<?php echo $customer_ban_ip; ?>"><?php echo $text_customer_ban_ip; ?></a></li>
</ul>
</li>
<li><a class="parent"><i class="fa fa-share-alt fa-fw"></i> <span><?php echo $text_marketing; ?></span></a>
<ul>
<li><a href="<?php echo $marketing; ?>"><?php echo $text_marketing; ?></a></li>
Oops, something went wrong.

0 comments on commit 6933ac7

Please sign in to comment.
You can’t perform that action at this time.