1: <?php
2: namespace Opencart\Catalog\Controller\Information;
3: /**
4: * Class Gdpr
5: *
6: * @package Opencart\Catalog\Controller\Information
7: */
8: class Gdpr extends \Opencart\System\Engine\Controller {
9: /**
10: * @return \Opencart\System\Engine\Action|null
11: */
12: public function index(): ?\Opencart\System\Engine\Action {
13: $this->load->model('catalog/information');
14:
15: $information_info = $this->model_catalog_information->getInformation($this->config->get('config_gdpr_id'));
16:
17: if ($information_info) {
18: $this->load->language('information/gdpr');
19:
20: $this->document->setTitle($this->language->get('heading_title'));
21:
22: $data['breadcrumbs'] = [];
23:
24: $data['breadcrumbs'][] = [
25: 'text' => $this->language->get('text_home'),
26: 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
27: ];
28:
29: $data['breadcrumbs'][] = [
30: 'text' => $this->language->get('heading_title'),
31: 'href' => $this->url->link('information/gdpr', 'language=' . $this->config->get('config_language'))
32: ];
33:
34: $data['action'] = $this->url->link('information/gdpr.action', 'language=' . $this->config->get('config_language'));
35:
36: $data['title'] = $information_info['title'];
37:
38: $data['gdpr'] = $this->url->link('information/information', 'language=' . $this->config->get('config_language') . '&information_id=' . $information_info['information_id']);
39:
40: $data['email'] = $this->customer->getEmail();
41: $data['store'] = $this->config->get('config_name');
42: $data['limit'] = $this->config->get('config_gdpr_limit');
43:
44: $data['cancel'] = $this->url->link('account/account', 'language=' . $this->config->get('config_language'));
45:
46: $data['column_left'] = $this->load->controller('common/column_left');
47: $data['column_right'] = $this->load->controller('common/column_right');
48: $data['content_top'] = $this->load->controller('common/content_top');
49: $data['content_bottom'] = $this->load->controller('common/content_bottom');
50: $data['footer'] = $this->load->controller('common/footer');
51: $data['header'] = $this->load->controller('common/header');
52:
53: $this->response->setOutput($this->load->view('information/gdpr', $data));
54:
55: return null;
56: } else {
57: return new \Opencart\System\Engine\Action('error/not_found');
58: }
59: }
60:
61: /*
62: * Action Statuses
63: *
64: * EXPORT
65: *
66: * unverified = 0
67: * pending = 1
68: * complete = 3
69: *
70: * REMOVE
71: *
72: * unverified = 0
73: * pending = 1
74: * processing = 2
75: * delete = 3
76: *
77: * DENY
78: *
79: * unverified = 0
80: * pending = 1
81: * processing = 2
82: * denied = -1
83: */
84: /**
85: * Action
86: *
87: * @return void
88: */
89: public function action(): void {
90: $this->load->language('information/gdpr');
91:
92: $json = [];
93:
94: if (isset($this->request->post['email'])) {
95: $email = $this->request->post['email'];
96: } else {
97: $email = '';
98: }
99:
100: if (isset($this->request->post['action'])) {
101: $action = $this->request->post['action'];
102: } else {
103: $action = '';
104: }
105:
106: // Validate E-Mail
107: if ((oc_strlen($email) > 96) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
108: $json['error']['email'] = $this->language->get('error_email');
109: }
110:
111: // Validate Action
112: $allowed = [
113: 'export',
114: 'remove'
115: ];
116:
117: if (!in_array($action, $allowed)) {
118: $json['error']['action'] = $this->language->get('error_action');
119: }
120:
121: if (!$json) {
122: // Added additional check so people are not spamming requests
123: $status = true;
124:
125: $this->load->model('account/gdpr');
126:
127: $results = $this->model_account_gdpr->getGdprsByEmail($email);
128:
129: foreach ($results as $result) {
130: if ($result['action'] == $action) {
131: $status = false;
132:
133: break;
134: }
135: }
136:
137: if ($status) {
138: $this->model_account_gdpr->addGdpr(oc_token(32), $email, $action);
139: }
140:
141: $json['success'] = $this->language->get('text_success');
142: }
143:
144: $this->response->addHeader('Content-Type: application/json');
145: $this->response->setOutput(json_encode($json));
146: }
147:
148: /**
149: * Success
150: *
151: * @return \Opencart\System\Engine\Action|null
152: */
153: public function success(): ?\Opencart\System\Engine\Action {
154: if (isset($this->request->get['code'])) {
155: $code = (string)$this->request->get['code'];
156: } else {
157: $code = '';
158: }
159:
160: $this->load->model('account/gdpr');
161:
162: $gdpr_info = $this->model_account_gdpr->getGdprByCode($code);
163:
164: if ($gdpr_info) {
165: $this->load->language('information/gdpr_success');
166:
167: $this->document->setTitle($this->language->get('heading_title'));
168:
169: $data['breadcrumbs'] = [];
170:
171: $data['breadcrumbs'][] = [
172: 'text' => $this->language->get('text_home'),
173: 'href' => $this->url->link('common/home', 'language=' . $this->config->get('config_language'))
174: ];
175:
176: $data['breadcrumbs'][] = [
177: 'text' => $this->language->get('text_account'),
178: 'href' => $this->url->link('information/gdpr', 'language=' . $this->config->get('config_language'))
179: ];
180:
181: $data['breadcrumbs'][] = [
182: 'text' => $this->language->get('heading_title'),
183: 'href' => $this->url->link('information/gdpr.success', 'language=' . $this->config->get('config_language'))
184: ];
185:
186: if ($gdpr_info['status'] == 0) {
187: $this->model_account_gdpr->editStatus($gdpr_info['gdpr_id'], 1);
188: }
189:
190: if ($gdpr_info['action'] == 'export') {
191: $data['text_message'] = $this->language->get('text_export');
192: } else {
193: $data['text_message'] = sprintf($this->language->get('text_remove'), $this->config->get('config_gdpr_limit'));
194: }
195:
196: $data['column_left'] = $this->load->controller('common/column_left');
197: $data['column_right'] = $this->load->controller('common/column_right');
198: $data['content_top'] = $this->load->controller('common/content_top');
199: $data['content_bottom'] = $this->load->controller('common/content_bottom');
200: $data['footer'] = $this->load->controller('common/footer');
201: $data['header'] = $this->load->controller('common/header');
202:
203: $this->response->setOutput($this->load->view('common/success', $data));
204:
205: return null;
206: } else {
207: return new \Opencart\System\Engine\Action('error/not_found');
208: }
209: }
210: }
211: