| 1: | <?php
|
| 2: | namespace Opencart\Admin\Controller\Mail;
|
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: |
|
| 8: | class Gdpr extends \Opencart\System\Engine\Controller {
|
| 9: |
|
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: |
|
| 19: | public function index(string &$route, array &$args, &$output): void {
|
| 20: | $this->load->model('customer/gdpr');
|
| 21: |
|
| 22: | $gdpr_info = $this->model_customer_gdpr->getGdpr($args[0]);
|
| 23: |
|
| 24: | if ($gdpr_info) {
|
| 25: |
|
| 26: |
|
| 27: |
|
| 28: | if ($gdpr_info['action'] == 'export' && (int)$args[1] == 3) {
|
| 29: | $this->export($gdpr_info);
|
| 30: | }
|
| 31: |
|
| 32: |
|
| 33: | if ($gdpr_info['action'] == 'approve' && (int)$args[1] == 2) {
|
| 34: | $this->approve($gdpr_info);
|
| 35: | }
|
| 36: |
|
| 37: |
|
| 38: | if ($gdpr_info['action'] == 'remove' && (int)$args[1] == 3) {
|
| 39: | $this->remove($gdpr_info);
|
| 40: | }
|
| 41: |
|
| 42: |
|
| 43: | if ($args[1] == -1) {
|
| 44: | $this->deny($gdpr_info);
|
| 45: | }
|
| 46: | }
|
| 47: | }
|
| 48: |
|
| 49: | |
| 50: | |
| 51: | |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: |
|
| 58: | public function export(array $gdpr_info): void {
|
| 59: | $this->load->model('setting/store');
|
| 60: |
|
| 61: | $store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
| 62: |
|
| 63: | if ($store_info) {
|
| 64: | $this->load->model('setting/setting');
|
| 65: |
|
| 66: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
| 67: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
| 68: | $store_url = $store_info['url'];
|
| 69: | } else {
|
| 70: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
| 71: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
| 72: | $store_url = HTTP_CATALOG;
|
| 73: | }
|
| 74: |
|
| 75: |
|
| 76: | $this->load->model('localisation/language');
|
| 77: |
|
| 78: | $language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
| 79: |
|
| 80: | if ($language_info) {
|
| 81: | $language_code = $language_info['code'];
|
| 82: | } else {
|
| 83: | $language_code = $this->config->get('config_language');
|
| 84: | }
|
| 85: |
|
| 86: |
|
| 87: | $this->load->language('default', 'mail', $language_code);
|
| 88: | $this->load->language('mail/gdpr_export', 'mail', $language_code);
|
| 89: |
|
| 90: |
|
| 91: | $results = $this->language->all('mail');
|
| 92: |
|
| 93: | foreach ($results as $key => $value) {
|
| 94: | $data[$key] = $value;
|
| 95: | }
|
| 96: |
|
| 97: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
| 98: |
|
| 99: | if (is_file(DIR_IMAGE . $store_logo)) {
|
| 100: | $data['logo'] = $store_url . 'image/' . $store_logo;
|
| 101: | } else {
|
| 102: | $data['logo'] = '';
|
| 103: | }
|
| 104: |
|
| 105: | $this->load->model('customer/customer');
|
| 106: |
|
| 107: | $customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
| 108: |
|
| 109: | if ($customer_info) {
|
| 110: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
| 111: | } else {
|
| 112: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
| 113: | }
|
| 114: |
|
| 115: |
|
| 116: | if ($customer_info) {
|
| 117: | $data['customer_id'] = $customer_info['customer_id'];
|
| 118: | $data['firstname'] = $customer_info['firstname'];
|
| 119: | $data['lastname'] = $customer_info['lastname'];
|
| 120: | $data['email'] = $customer_info['email'];
|
| 121: | $data['telephone'] = $customer_info['telephone'];
|
| 122: | }
|
| 123: |
|
| 124: |
|
| 125: | $data['addresses'] = [];
|
| 126: |
|
| 127: | if ($customer_info) {
|
| 128: | $results = $this->model_customer_customer->getAddresses($customer_info['customer_id']);
|
| 129: |
|
| 130: | foreach ($results as $result) {
|
| 131: | $address = [
|
| 132: | 'firstname' => $result['firstname'],
|
| 133: | 'lastname' => $result['lastname'],
|
| 134: | 'address_1' => $result['address_1'],
|
| 135: | 'address_2' => $result['address_2'],
|
| 136: | 'city' => $result['city'],
|
| 137: | 'postcode' => $result['postcode'],
|
| 138: | 'country' => $result['country'],
|
| 139: | 'zone' => $result['zone']
|
| 140: | ];
|
| 141: |
|
| 142: | if (!in_array($address, $data['addresses'])) {
|
| 143: | $data['addresses'][] = $address;
|
| 144: | }
|
| 145: | }
|
| 146: | }
|
| 147: |
|
| 148: |
|
| 149: | $this->load->model('sale/order');
|
| 150: |
|
| 151: | $results = $this->model_sale_order->getOrders(['filter_email' => $gdpr_info['email']]);
|
| 152: |
|
| 153: | foreach ($results as $result) {
|
| 154: | $order_info = $this->model_sale_order->getOrder($result['order_id']);
|
| 155: |
|
| 156: | if ($order_info['payment_country_id']) {
|
| 157: | $address = [
|
| 158: | 'firstname' => $order_info['payment_firstname'],
|
| 159: | 'lastname' => $order_info['payment_lastname'],
|
| 160: | 'address_1' => $order_info['payment_address_1'],
|
| 161: | 'address_2' => $order_info['payment_address_2'],
|
| 162: | 'city' => $order_info['payment_city'],
|
| 163: | 'postcode' => $order_info['payment_postcode'],
|
| 164: | 'country' => $order_info['payment_country'],
|
| 165: | 'zone' => $order_info['payment_zone']
|
| 166: | ];
|
| 167: |
|
| 168: | if (!in_array($address, $data['addresses'])) {
|
| 169: | $data['addresses'][] = $address;
|
| 170: | }
|
| 171: | }
|
| 172: |
|
| 173: | if ($order_info['shipping_country_id']) {
|
| 174: | $address = [
|
| 175: | 'firstname' => $order_info['shipping_firstname'],
|
| 176: | 'lastname' => $order_info['shipping_lastname'],
|
| 177: | 'address_1' => $order_info['shipping_address_1'],
|
| 178: | 'address_2' => $order_info['shipping_address_2'],
|
| 179: | 'city' => $order_info['shipping_city'],
|
| 180: | 'postcode' => $order_info['shipping_postcode'],
|
| 181: | 'country' => $order_info['shipping_country'],
|
| 182: | 'zone' => $order_info['shipping_zone']
|
| 183: | ];
|
| 184: |
|
| 185: | if (!in_array($address, $data['addresses'])) {
|
| 186: | $data['addresses'][] = $address;
|
| 187: | }
|
| 188: | }
|
| 189: | }
|
| 190: |
|
| 191: |
|
| 192: | $data['ips'] = [];
|
| 193: |
|
| 194: | if ($customer_info) {
|
| 195: | $results = $this->model_customer_customer->getIps($customer_info['customer_id']);
|
| 196: |
|
| 197: | foreach ($results as $result) {
|
| 198: | $data['ips'][] = [
|
| 199: | 'ip' => $result['ip'],
|
| 200: | 'date_added' => date($this->language->get('mail_datetime_format'), strtotime($result['date_added']))
|
| 201: | ];
|
| 202: | }
|
| 203: | }
|
| 204: |
|
| 205: | $data['store_name'] = $store_name;
|
| 206: | $data['store_url'] = $store_url;
|
| 207: |
|
| 208: | if ($this->config->get('config_mail_engine')) {
|
| 209: | $mail_option = [
|
| 210: | 'parameter' => $this->config->get('config_mail_parameter'),
|
| 211: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
| 212: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
| 213: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
| 214: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
| 215: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
| 216: | ];
|
| 217: |
|
| 218: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
| 219: | $mail->setTo($gdpr_info['email']);
|
| 220: | $mail->setFrom($this->config->get('config_email'));
|
| 221: | $mail->setSender($store_name);
|
| 222: | $mail->setSubject($subject);
|
| 223: | $mail->setHtml($this->load->view('mail/gdpr_export', $data));
|
| 224: | $mail->send();
|
| 225: | }
|
| 226: | }
|
| 227: |
|
| 228: | |
| 229: | |
| 230: | |
| 231: | |
| 232: | |
| 233: | |
| 234: | |
| 235: | |
| 236: |
|
| 237: | public function approve(array $gdpr_info): void {
|
| 238: | $this->load->model('setting/store');
|
| 239: |
|
| 240: | $store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
| 241: |
|
| 242: | if ($store_info) {
|
| 243: | $this->load->model('setting/setting');
|
| 244: |
|
| 245: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
| 246: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
| 247: | $store_url = $store_info['url'];
|
| 248: | } else {
|
| 249: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
| 250: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
| 251: | $store_url = HTTP_CATALOG;
|
| 252: | }
|
| 253: |
|
| 254: |
|
| 255: | $this->load->model('localisation/language');
|
| 256: |
|
| 257: | $language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
| 258: |
|
| 259: | if ($language_info) {
|
| 260: | $language_code = $language_info['code'];
|
| 261: | } else {
|
| 262: | $language_code = $this->config->get('config_language');
|
| 263: | }
|
| 264: |
|
| 265: |
|
| 266: | $this->load->language('default', 'mail', $language_code);
|
| 267: | $this->load->language('mail/gdpr_approve', 'mail', $language_code);
|
| 268: |
|
| 269: |
|
| 270: | $results = $this->language->all('mail');
|
| 271: |
|
| 272: | foreach ($results as $key => $value) {
|
| 273: | $data[$key] = $value;
|
| 274: | }
|
| 275: |
|
| 276: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
| 277: |
|
| 278: | $this->load->model('tool/image');
|
| 279: |
|
| 280: | if (is_file(DIR_IMAGE . $store_logo)) {
|
| 281: | $data['logo'] = $store_url . 'image/' . $store_logo;
|
| 282: | } else {
|
| 283: | $data['logo'] = '';
|
| 284: | }
|
| 285: |
|
| 286: | $this->load->model('customer/customer');
|
| 287: |
|
| 288: | $customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
| 289: |
|
| 290: | if ($customer_info) {
|
| 291: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
| 292: | } else {
|
| 293: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
| 294: | }
|
| 295: |
|
| 296: | $data['text_gdpr'] = sprintf($this->language->get('mail_text_gdpr'), $this->config->get('config_gdpr_limit'));
|
| 297: | $data['text_a'] = sprintf($this->language->get('mail_text_a'), $this->config->get('config_gdpr_limit'));
|
| 298: |
|
| 299: | $data['store_name'] = $store_name;
|
| 300: | $data['store_url'] = $store_url;
|
| 301: |
|
| 302: | if ($this->config->get('config_mail_engine')) {
|
| 303: | $mail_option = [
|
| 304: | 'parameter' => $this->config->get('config_mail_parameter'),
|
| 305: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
| 306: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
| 307: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
| 308: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
| 309: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
| 310: | ];
|
| 311: |
|
| 312: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
| 313: | $mail->setTo($gdpr_info['email']);
|
| 314: | $mail->setFrom($this->config->get('config_email'));
|
| 315: | $mail->setSender($store_name);
|
| 316: | $mail->setSubject($subject);
|
| 317: | $mail->setHtml($this->load->view('mail/gdpr_approve', $data));
|
| 318: | $mail->send();
|
| 319: | }
|
| 320: | }
|
| 321: |
|
| 322: | |
| 323: | |
| 324: | |
| 325: | |
| 326: | |
| 327: | |
| 328: | |
| 329: | |
| 330: |
|
| 331: | public function deny(array $gdpr_info): void {
|
| 332: | $this->load->model('setting/store');
|
| 333: |
|
| 334: | $store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
| 335: |
|
| 336: | if ($store_info) {
|
| 337: | $this->load->model('setting/setting');
|
| 338: |
|
| 339: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
| 340: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
| 341: | $store_url = $store_info['url'];
|
| 342: | } else {
|
| 343: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
| 344: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
| 345: | $store_url = HTTP_CATALOG;
|
| 346: | }
|
| 347: |
|
| 348: |
|
| 349: | $this->load->model('localisation/language');
|
| 350: |
|
| 351: | $language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
| 352: |
|
| 353: | if ($language_info) {
|
| 354: | $language_code = $language_info['code'];
|
| 355: | } else {
|
| 356: | $language_code = $this->config->get('config_language');
|
| 357: | }
|
| 358: |
|
| 359: |
|
| 360: | $this->load->language('default', 'mail', $language_code);
|
| 361: | $this->load->language('mail/gdpr_deny', 'mail', $language_code);
|
| 362: |
|
| 363: |
|
| 364: | $results = $this->language->all('mail');
|
| 365: |
|
| 366: | foreach ($results as $key => $value) {
|
| 367: | $data[$key] = $value;
|
| 368: | }
|
| 369: |
|
| 370: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
| 371: |
|
| 372: | $this->load->model('tool/image');
|
| 373: |
|
| 374: | if (is_file(DIR_IMAGE . $store_logo)) {
|
| 375: | $data['logo'] = $store_url . 'image/' . $store_logo;
|
| 376: | } else {
|
| 377: | $data['logo'] = '';
|
| 378: | }
|
| 379: |
|
| 380: | $data['text_request'] = $this->language->get('mail_text_' . $gdpr_info['action']);
|
| 381: |
|
| 382: | $this->load->model('customer/customer');
|
| 383: |
|
| 384: | $customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
| 385: |
|
| 386: | if ($customer_info) {
|
| 387: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
| 388: | } else {
|
| 389: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
| 390: | }
|
| 391: |
|
| 392: | $data['store_name'] = $store_name;
|
| 393: | $data['store_url'] = $store_url;
|
| 394: | $data['contact'] = $store_url . 'index.php?route=information/contact';
|
| 395: |
|
| 396: | if ($this->config->get('config_mail_engine')) {
|
| 397: | $mail_option = [
|
| 398: | 'parameter' => $this->config->get('config_mail_parameter'),
|
| 399: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
| 400: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
| 401: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
| 402: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
| 403: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
| 404: | ];
|
| 405: |
|
| 406: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
| 407: | $mail->setTo($gdpr_info['email']);
|
| 408: | $mail->setFrom($this->config->get('config_email'));
|
| 409: | $mail->setSender($store_name);
|
| 410: | $mail->setSubject($subject);
|
| 411: | $mail->setHtml($this->load->view('mail/gdpr_deny', $data));
|
| 412: | $mail->send();
|
| 413: | }
|
| 414: | }
|
| 415: |
|
| 416: | |
| 417: | |
| 418: | |
| 419: | |
| 420: | |
| 421: | |
| 422: | |
| 423: | |
| 424: |
|
| 425: | public function remove(array $gdpr_info): void {
|
| 426: | $this->load->model('setting/store');
|
| 427: |
|
| 428: | $store_info = $this->model_setting_store->getStore($gdpr_info['store_id']);
|
| 429: |
|
| 430: | if ($store_info) {
|
| 431: | $this->load->model('setting/setting');
|
| 432: |
|
| 433: | $store_logo = html_entity_decode($this->model_setting_setting->getValue('config_logo', $store_info['store_id']), ENT_QUOTES, 'UTF-8');
|
| 434: | $store_name = html_entity_decode($store_info['name'], ENT_QUOTES, 'UTF-8');
|
| 435: | $store_url = $store_info['url'];
|
| 436: | } else {
|
| 437: | $store_logo = html_entity_decode($this->config->get('config_logo'), ENT_QUOTES, 'UTF-8');
|
| 438: | $store_name = html_entity_decode($this->config->get('config_name'), ENT_QUOTES, 'UTF-8');
|
| 439: | $store_url = HTTP_CATALOG;
|
| 440: | }
|
| 441: |
|
| 442: |
|
| 443: | $this->load->model('localisation/language');
|
| 444: |
|
| 445: | $language_info = $this->model_localisation_language->getLanguage($gdpr_info['language_id']);
|
| 446: |
|
| 447: | if ($language_info) {
|
| 448: | $language_code = $language_info['code'];
|
| 449: | } else {
|
| 450: | $language_code = $this->config->get('config_language');
|
| 451: | }
|
| 452: |
|
| 453: |
|
| 454: | $this->load->language('default', 'mail', $language_code);
|
| 455: | $this->load->language('mail/gdpr_delete', 'mail', $language_code);
|
| 456: |
|
| 457: |
|
| 458: | $results = $this->language->all('mail');
|
| 459: |
|
| 460: | foreach ($results as $key => $value) {
|
| 461: | $data[$key] = $value;
|
| 462: | }
|
| 463: |
|
| 464: | $subject = sprintf($this->language->get('mail_text_subject'), $store_name);
|
| 465: |
|
| 466: | $this->load->model('tool/image');
|
| 467: |
|
| 468: | if (is_file(DIR_IMAGE . $store_logo)) {
|
| 469: | $data['logo'] = $store_url . 'image/' . $store_logo;
|
| 470: | } else {
|
| 471: | $data['logo'] = '';
|
| 472: | }
|
| 473: |
|
| 474: | $this->load->model('customer/customer');
|
| 475: |
|
| 476: | $customer_info = $this->model_customer_customer->getCustomerByEmail($gdpr_info['email']);
|
| 477: |
|
| 478: | if ($customer_info) {
|
| 479: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), html_entity_decode($customer_info['firstname'], ENT_QUOTES, 'UTF-8'));
|
| 480: | } else {
|
| 481: | $data['text_hello'] = sprintf($this->language->get('mail_text_hello'), $this->language->get('mail_text_user'));
|
| 482: | }
|
| 483: |
|
| 484: | $data['store_name'] = $store_name;
|
| 485: | $data['store_url'] = $store_url;
|
| 486: | $data['contact'] = $store_url . 'index.php?route=information/contact';
|
| 487: |
|
| 488: | if ($this->config->get('config_mail_engine')) {
|
| 489: | $mail_option = [
|
| 490: | 'parameter' => $this->config->get('config_mail_parameter'),
|
| 491: | 'smtp_hostname' => $this->config->get('config_mail_smtp_hostname'),
|
| 492: | 'smtp_username' => $this->config->get('config_mail_smtp_username'),
|
| 493: | 'smtp_password' => html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8'),
|
| 494: | 'smtp_port' => $this->config->get('config_mail_smtp_port'),
|
| 495: | 'smtp_timeout' => $this->config->get('config_mail_smtp_timeout')
|
| 496: | ];
|
| 497: |
|
| 498: | $mail = new \Opencart\System\Library\Mail($this->config->get('config_mail_engine'), $mail_option);
|
| 499: | $mail->setTo($gdpr_info['email']);
|
| 500: | $mail->setFrom($this->config->get('config_email'));
|
| 501: | $mail->setSender($store_name);
|
| 502: | $mail->setSubject($subject);
|
| 503: | $mail->setHtml($this->load->view('mail/gdpr_delete', $data));
|
| 504: | $mail->send();
|
| 505: | }
|
| 506: | }
|
| 507: | }
|
| 508: | |