1: | <?php
2: | namespace Opencart\Admin\Controller\Extension\Opencart\Fraud;
3: | /**
4: | * Class IP
5: | *
6: | * @package Opencart\Admin\Controller\Extension\Opencart\Fraud
7: | */
8: | class Ip extends \Opencart\System\Engine\Controller {
9: | /**
10: | * Index
11: | *
12: | * @return void
13: | */
14: | public function index(): void {
15: | $this->load->language('extension/opencart/fraud/ip');
16: |
17: | $this->document->setTitle($this->language->get('heading_title'));
18: |
19: | $data['breadcrumbs'] = [];
20: |
21: | $data['breadcrumbs'][] = [
22: | 'text' => $this->language->get('text_home'),
23: | 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
24: | ];
25: |
26: | $data['breadcrumbs'][] = [
27: | 'text' => $this->language->get('text_extension'),
28: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud')
29: | ];
30: |
31: | $data['breadcrumbs'][] = [
32: | 'text' => $this->language->get('text_fraud'),
33: | 'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud')
34: | ];
35: |
36: | $data['breadcrumbs'][] = [
37: | 'text' => $this->language->get('heading_title'),
38: | 'href' => $this->url->link('extension/opencart/fraud/ip', 'user_token=' . $this->session->data['user_token'])
39: | ];
40: |
41: | $data['save'] = $this->url->link('extension/opencart/fraud/ip.save', 'user_token=' . $this->session->data['user_token']);
42: | $data['back'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=fraud');
43: |
44: | $data['fraud_ip_order_status_id'] = $this->config->get('fraud_ip_order_status_id');
45: |
46: | $this->load->model('localisation/order_status');
47: |
48: | $data['order_statuses'] = $this->model_localisation_order_status->getOrderStatuses();
49: |
50: | $data['fraud_ip_status'] = $this->config->get('fraud_ip_status');
51: |
52: | $data['user_token'] = $this->session->data['user_token'];
53: |
54: | $data['header'] = $this->load->controller('common/header');
55: | $data['column_left'] = $this->load->controller('common/column_left');
56: | $data['footer'] = $this->load->controller('common/footer');
57: |
58: | $this->response->setOutput($this->load->view('extension/opencart/fraud/ip', $data));
59: | }
60: |
61: | /**
62: | * Save
63: | *
64: | * @return void
65: | */
66: | public function save(): void {
67: | $this->load->language('extension/opencart/fraud/ip');
68: |
69: | $json = [];
70: |
71: | if (!$this->user->hasPermission('modify', 'extension/opencart/fraud/ip')) {
72: | $json['error'] = $this->language->get('error_permission');
73: | }
74: |
75: | if (!$json) {
76: | $this->load->model('setting/setting');
77: |
78: | $this->model_setting_setting->editSetting('fraud_ip', $this->request->post);
79: |
80: | $json['success'] = $this->language->get('text_success');
81: | }
82: |
83: | $this->response->addHeader('Content-Type: application/json');
84: | $this->response->setOutput(json_encode($json));
85: | }
86: |
87: | /**
88: | * Install
89: | *
90: | * @return void
91: | */
92: | public function install(): void {
93: | if ($this->user->hasPermission('modify', 'extension/fraud')) {
94: | $this->load->model('extension/opencart/fraud/ip');
95: |
96: | $this->model_extension_opencart_fraud_ip->install();
97: | }
98: | }
99: |
100: | /**
101: | * Uninstall
102: | *
103: | * @return void
104: | */
105: | public function uninstall(): void {
106: | if ($this->user->hasPermission('modify', 'extension/fraud')) {
107: | $this->load->model('extension/opencart/fraud/ip');
108: |
109: | $this->model_extension_opencart_fraud_ip->uninstall();
110: | }
111: | }
112: |
113: | /**
114: | * Ip
115: | *
116: | * @return void
117: | */
118: | public function ip(): void {
119: | $this->load->language('extension/opencart/fraud/ip');
120: |
121: | if (isset($this->request->get['page'])) {
122: | $page = (int)$this->request->get['page'];
123: | } else {
124: | $page = 1;
125: | }
126: |
127: | $limit = 10;
128: |
129: | $data['ips'] = [];
130: |
131: | $this->load->model('extension/opencart/fraud/ip');
132: | $this->load->model('customer/customer');
133: |
134: | $results = $this->model_extension_opencart_fraud_ip->getIps(($page - 1) * $limit, $limit);
135: |
136: | foreach ($results as $result) {
137: | $data['ips'][] = [
138: | 'ip' => $result['ip'],
139: | 'total' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']),
140: | 'date_added' => date('d/m/y', strtotime($result['date_added'])),
141: | 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'])
142: | ];
143: | }
144: |
145: | $ip_total = $this->model_extension_opencart_fraud_ip->getTotalIps();
146: |
147: | $data['pagination'] = $this->load->controller('common/pagination', [
148: | 'total' => $ip_total,
149: | 'page' => $page,
150: | 'limit' => $limit,
151: | 'url' => $this->url->link('extension/opencart/fraud/ip.ip', 'user_token=' . $this->session->data['user_token'] . '&page={page}')
152: | ]);
153: |
154: | $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * $limit) + 1 : 0, ((($page - 1) * $limit) > ($ip_total - $limit)) ? $ip_total : ((($page - 1) * $limit) + $limit), $ip_total, ceil($ip_total / $limit));
155: |
156: | $this->response->setOutput($this->load->view('extension/opencart/fraud/ip_ip', $data));
157: | }
158: |
159: | /**
160: | * Add Ip
161: | *
162: | * @return void
163: | */
164: | public function addIp(): void {
165: | $this->load->language('extension/opencart/fraud/ip');
166: |
167: | $json = [];
168: |
169: | if (!$this->user->hasPermission('modify', 'extension/opencart/fraud/ip')) {
170: | $json['error'] = $this->language->get('error_permission');
171: | }
172: |
173: | if (empty($this->request->post['ip'])) {
174: | $json['error'] = $this->language->get('error_required');
175: | } elseif (!filter_var($this->request->post['ip'], FILTER_VALIDATE_IP)) {
176: | $json['error'] = $this->language->get('error_invalid');
177: | }
178: |
179: | if (!$json) {
180: | $this->load->model('extension/opencart/fraud/ip');
181: |
182: | if (!$this->model_extension_opencart_fraud_ip->getTotalIpsByIp($this->request->post['ip'])) {
183: | $this->model_extension_opencart_fraud_ip->addIp($this->request->post['ip']);
184: | }
185: |
186: | $json['success'] = $this->language->get('text_success');
187: | }
188: |
189: | $this->response->addHeader('Content-Type: application/json');
190: | $this->response->setOutput(json_encode($json));
191: | }
192: |
193: | /**
194: | * Remove Ip
195: | *
196: | * @return void
197: | */
198: | public function removeIp(): void {
199: | $this->load->language('extension/opencart/fraud/ip');
200: |
201: | $json = [];
202: |
203: | if (!$this->user->hasPermission('modify', 'extension/opencart/fraud/ip')) {
204: | $json['error'] = $this->language->get('error_permission');
205: | }
206: |
207: | if (!$json) {
208: | $this->load->model('extension/opencart/fraud/ip');
209: |
210: | $this->model_extension_opencart_fraud_ip->removeIp($this->request->post['ip']);
211: |
212: | $json['success'] = $this->language->get('text_success');
213: | }
214: |
215: | $this->response->addHeader('Content-Type: application/json');
216: | $this->response->setOutput(json_encode($json));
217: | }
218: | }
219: |

OpenCart API API documentation generated by ApiGen dev-master