1: | <?php
|
2: | namespace Opencart\Admin\Controller\Customer;
|
3: | |
4: | |
5: | |
6: | |
7: |
|
8: | class Gdpr extends \Opencart\System\Engine\Controller {
|
9: | |
10: | |
11: | |
12: | |
13: |
|
14: | public function index(): void {
|
15: | $this->load->language('customer/gdpr');
|
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('heading_title'),
|
28: | 'href' => $this->url->link('customer/gdpr', 'user_token=' . $this->session->data['user_token'])
|
29: | ];
|
30: |
|
31: | $data['text_info'] = sprintf($this->language->get('text_info'), $this->config->get('config_gdpr_limit'));
|
32: |
|
33: | $data['approve'] = $this->url->link('customer/gdpr.approve', 'user_token=' . $this->session->data['user_token'], true);
|
34: | $data['deny'] = $this->url->link('customer/gdpr.deny', 'user_token=' . $this->session->data['user_token'], true);
|
35: | $data['delete'] = $this->url->link('customer/gdpr.delete', 'user_token=' . $this->session->data['user_token'], true);
|
36: |
|
37: | $data['list'] = $this->getList();
|
38: |
|
39: | $data['user_token'] = $this->session->data['user_token'];
|
40: |
|
41: | $data['header'] = $this->load->controller('common/header');
|
42: | $data['column_left'] = $this->load->controller('common/column_left');
|
43: | $data['footer'] = $this->load->controller('common/footer');
|
44: |
|
45: | $this->response->setOutput($this->load->view('customer/gdpr', $data));
|
46: | }
|
47: |
|
48: | |
49: | |
50: | |
51: | |
52: |
|
53: | public function list(): void {
|
54: | $this->load->language('customer/gdpr');
|
55: |
|
56: | $this->response->setOutput($this->getList());
|
57: | }
|
58: |
|
59: | |
60: | |
61: | |
62: | |
63: |
|
64: | public function getList(): string {
|
65: | $this->load->language('customer/gdpr');
|
66: |
|
67: | if (isset($this->request->get['filter_email'])) {
|
68: | $filter_email = $this->request->get['filter_email'];
|
69: | } else {
|
70: | $filter_email = '';
|
71: | }
|
72: |
|
73: | if (isset($this->request->get['filter_action'])) {
|
74: | $filter_action = $this->request->get['filter_action'];
|
75: | } else {
|
76: | $filter_action = '';
|
77: | }
|
78: |
|
79: | if (isset($this->request->get['filter_status'])) {
|
80: | $filter_status = $this->request->get['filter_status'];
|
81: | } else {
|
82: | $filter_status = '';
|
83: | }
|
84: |
|
85: | if (isset($this->request->get['filter_date_from'])) {
|
86: | $filter_date_from = $this->request->get['filter_date_from'];
|
87: | } else {
|
88: | $filter_date_from = '';
|
89: | }
|
90: |
|
91: | if (isset($this->request->get['filter_date_to'])) {
|
92: | $filter_date_to = $this->request->get['filter_date_to'];
|
93: | } else {
|
94: | $filter_date_to = '';
|
95: | }
|
96: |
|
97: | if (isset($this->request->get['page'])) {
|
98: | $page = (int)$this->request->get['page'];
|
99: | } else {
|
100: | $page = 1;
|
101: | }
|
102: |
|
103: | $url = '';
|
104: |
|
105: | if (isset($this->request->get['filter_email'])) {
|
106: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
107: | }
|
108: |
|
109: | if (isset($this->request->get['filter_action'])) {
|
110: | $url .= '&filter_action=' . $this->request->get['filter_action'];
|
111: | }
|
112: |
|
113: | if (isset($this->request->get['filter_status'])) {
|
114: | $url .= '&filter_status=' . $this->request->get['filter_status'];
|
115: | }
|
116: |
|
117: | if (isset($this->request->get['filter_date_from'])) {
|
118: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
119: | }
|
120: |
|
121: | if (isset($this->request->get['filter_date_to'])) {
|
122: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
123: | }
|
124: |
|
125: | $data['action'] = $this->url->link('customer/gdpr.list', 'user_token=' . $this->session->data['user_token'] . $url, true);
|
126: |
|
127: | $data['gdprs'] = [];
|
128: |
|
129: | $filter_data = [
|
130: | 'filter_email' => $filter_email,
|
131: | 'filter_action' => $filter_action,
|
132: | 'filter_status' => $filter_status,
|
133: | 'filter_date_from' => $filter_date_from,
|
134: | 'filter_date_to' => $filter_date_to,
|
135: | 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
|
136: | 'limit' => $this->config->get('config_pagination_admin')
|
137: | ];
|
138: |
|
139: | $this->load->model('customer/gdpr');
|
140: | $this->load->model('customer/customer');
|
141: |
|
142: | $results = $this->model_customer_gdpr->getGdprs($filter_data);
|
143: |
|
144: | foreach ($results as $result) {
|
145: | $customer_info = $this->model_customer_customer->getCustomerByEmail($result['email']);
|
146: |
|
147: | if ($customer_info) {
|
148: | $edit = $this->url->link('customer/customer.form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_info['customer_id'], true);
|
149: | } else {
|
150: | $edit = '';
|
151: | }
|
152: |
|
153: | $data['gdprs'][] = [
|
154: | 'gdpr_id' => $result['gdpr_id'],
|
155: | 'email' => $result['email'],
|
156: | 'action' => $this->language->get('text_' . $result['action']),
|
157: | 'status' => $result['status'],
|
158: | 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
|
159: | 'approve' => $this->url->link('customer/gdpr.approve', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
|
160: | 'deny' => $this->url->link('customer/gdpr.deny', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
|
161: | 'edit' => $edit,
|
162: | 'delete' => $this->url->link('customer/gdpr.delete', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true)
|
163: | ];
|
164: | }
|
165: |
|
166: | $url = '';
|
167: |
|
168: | if (isset($this->request->get['filter_email'])) {
|
169: | $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
|
170: | }
|
171: |
|
172: | if (isset($this->request->get['filter_action'])) {
|
173: | $url .= '&filter_action=' . $this->request->get['filter_action'];
|
174: | }
|
175: |
|
176: | if (isset($this->request->get['filter_status'])) {
|
177: | $url .= '&filter_status=' . $this->request->get['filter_status'];
|
178: | }
|
179: |
|
180: | if (isset($this->request->get['filter_date_from'])) {
|
181: | $url .= '&filter_date_from=' . $this->request->get['filter_date_from'];
|
182: | }
|
183: |
|
184: | if (isset($this->request->get['filter_date_to'])) {
|
185: | $url .= '&filter_date_to=' . $this->request->get['filter_date_to'];
|
186: | }
|
187: |
|
188: | $gdpr_total = $this->model_customer_gdpr->getTotalGdprs($filter_data);
|
189: |
|
190: | $data['pagination'] = $this->load->controller('common/pagination', [
|
191: | 'total' => $gdpr_total,
|
192: | 'page' => $page,
|
193: | 'limit' => $this->config->get('config_pagination_admin'),
|
194: | 'url' => $this->url->link('customer/gdpr.list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
|
195: | ]);
|
196: |
|
197: | $data['results'] = sprintf($this->language->get('text_pagination'), ($gdpr_total) ? (($page - 1) * $this->config->get('config_pagination_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_pagination_admin')) > ($gdpr_total - $this->config->get('config_pagination_admin'))) ? $gdpr_total : ((($page - 1) * $this->config->get('config_pagination_admin')) + $this->config->get('config_pagination_admin')), $gdpr_total, ceil($gdpr_total / $this->config->get('config_pagination_admin')));
|
198: |
|
199: | return $this->load->view('customer/gdpr_list', $data);
|
200: | }
|
201: |
|
202: | |
203: | |
204: | |
205: | |
206: | |
207: | |
208: | |
209: | |
210: | |
211: | |
212: | |
213: | |
214: | |
215: | |
216: | |
217: | |
218: | |
219: | |
220: | |
221: | |
222: | |
223: | |
224: |
|
225: | |
226: | |
227: | |
228: | |
229: |
|
230: | public function approve(): void {
|
231: | $this->load->language('customer/gdpr');
|
232: |
|
233: | $json = [];
|
234: |
|
235: | $gdprs = [];
|
236: |
|
237: | if (isset($this->request->post['selected'])) {
|
238: | $gdprs = $this->request->post['selected'];
|
239: | }
|
240: |
|
241: | if (isset($this->request->get['gdpr_id'])) {
|
242: | $gdprs[] = (int)$this->request->get['gdpr_id'];
|
243: | }
|
244: |
|
245: | if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
246: | $json['error'] = $this->language->get('error_permission');
|
247: | }
|
248: |
|
249: | if (!$json) {
|
250: | $this->load->model('customer/gdpr');
|
251: |
|
252: | foreach ($gdprs as $gdpr_id) {
|
253: | $gdpr_info = $this->model_customer_gdpr->getGdpr($gdpr_id);
|
254: |
|
255: | if ($gdpr_info) {
|
256: |
|
257: |
|
258: | if ($gdpr_info['action'] == 'export') {
|
259: | $this->model_customer_gdpr->editStatus($gdpr_id, 3);
|
260: | } else {
|
261: | $this->model_customer_gdpr->editStatus($gdpr_id, 2);
|
262: | }
|
263: | }
|
264: | }
|
265: |
|
266: | $json['success'] = $this->language->get('text_success');
|
267: | }
|
268: |
|
269: | $this->response->addHeader('Content-Type: application/json');
|
270: | $this->response->setOutput(json_encode($json));
|
271: | }
|
272: |
|
273: | |
274: | |
275: | |
276: | |
277: |
|
278: | public function deny(): void {
|
279: | $this->load->language('customer/gdpr');
|
280: |
|
281: | $json = [];
|
282: |
|
283: | $gdprs = [];
|
284: |
|
285: | if (isset($this->request->post['selected'])) {
|
286: | $gdprs = $this->request->post['selected'];
|
287: | }
|
288: |
|
289: | if (isset($this->request->get['gdpr_id'])) {
|
290: | $gdprs[] = (int)$this->request->get['gdpr_id'];
|
291: | }
|
292: |
|
293: | if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
294: | $json['error'] = $this->language->get('error_permission');
|
295: | }
|
296: |
|
297: | if (!$json) {
|
298: | $this->load->model('customer/gdpr');
|
299: |
|
300: | foreach ($gdprs as $gdpr_id) {
|
301: | $this->model_customer_gdpr->editStatus($gdpr_id, -1);
|
302: | }
|
303: |
|
304: | $json['success'] = $this->language->get('text_success');
|
305: | }
|
306: |
|
307: | $this->response->addHeader('Content-Type: application/json');
|
308: | $this->response->setOutput(json_encode($json));
|
309: | }
|
310: |
|
311: | |
312: | |
313: | |
314: | |
315: |
|
316: | public function delete(): void {
|
317: | $this->load->language('customer/gdpr');
|
318: |
|
319: | $json = [];
|
320: |
|
321: | $gdprs = [];
|
322: |
|
323: | if (isset($this->request->post['selected'])) {
|
324: | $gdprs = $this->request->post['selected'];
|
325: | }
|
326: |
|
327: | if (isset($this->request->get['gdpr_id'])) {
|
328: | $gdprs[] = (int)$this->request->get['gdpr_id'];
|
329: | }
|
330: |
|
331: | if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
|
332: | $json['error'] = $this->language->get('error_permission');
|
333: | }
|
334: |
|
335: | if (!$json) {
|
336: | $this->load->model('customer/gdpr');
|
337: |
|
338: | foreach ($gdprs as $gdpr_id) {
|
339: | $this->model_customer_gdpr->deleteGdpr($gdpr_id);
|
340: | }
|
341: |
|
342: | $json['success'] = $this->language->get('text_success');
|
343: | }
|
344: |
|
345: | $this->response->addHeader('Content-Type: application/json');
|
346: | $this->response->setOutput(json_encode($json));
|
347: | }
|
348: | }
|
349: | |