/upload/admin/controller/customer/gdpr.php

https://github.com/ocStore/ocStore · PHP · 298 lines · 202 code · 71 blank · 25 comment · 36 complexity · 37e855e18e79d5648fe3aacd4662b2e0 MD5 · raw file

  1. <?php
  2. namespace Opencart\Admin\Controller\Customer;
  3. class Gdpr extends \Opencart\System\Engine\Controller {
  4. public function index(): void {
  5. $this->load->language('customer/gdpr');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $data['breadcrumbs'] = [];
  8. $data['breadcrumbs'][] = [
  9. 'text' => $this->language->get('text_home'),
  10. 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'])
  11. ];
  12. $data['breadcrumbs'][] = [
  13. 'text' => $this->language->get('heading_title'),
  14. 'href' => $this->url->link('customer/gdpr', 'user_token=' . $this->session->data['user_token'])
  15. ];
  16. $data['text_info'] = sprintf($this->language->get('text_info'), $this->config->get('config_gdpr_limit'));
  17. $data['approve'] = $this->url->link('customer/gdpr|approve', 'user_token=' . $this->session->data['user_token'], true);
  18. $data['deny'] = $this->url->link('customer/gdpr|deny', 'user_token=' . $this->session->data['user_token'], true);
  19. $data['delete'] = $this->url->link('customer/gdpr|delete', 'user_token=' . $this->session->data['user_token'], true);
  20. $data['list'] = $this->getList();
  21. $data['user_token'] = $this->session->data['user_token'];
  22. $data['header'] = $this->load->controller('common/header');
  23. $data['column_left'] = $this->load->controller('common/column_left');
  24. $data['footer'] = $this->load->controller('common/footer');
  25. $this->response->setOutput($this->load->view('customer/gdpr', $data));
  26. }
  27. public function list(): void {
  28. $this->load->language('customer/gdpr');
  29. $this->response->setOutput($this->getList());
  30. }
  31. public function getList(): string {
  32. $this->load->language('customer/gdpr');
  33. if (isset($this->request->get['filter_email'])) {
  34. $filter_email = $this->request->get['filter_email'];
  35. } else {
  36. $filter_email = '';
  37. }
  38. if (isset($this->request->get['filter_action'])) {
  39. $filter_action = $this->request->get['filter_action'];
  40. } else {
  41. $filter_action = '';
  42. }
  43. if (isset($this->request->get['filter_status'])) {
  44. $filter_status = $this->request->get['filter_status'];
  45. } else {
  46. $filter_status = '';
  47. }
  48. if (isset($this->request->get['filter_date_added'])) {
  49. $filter_date_added = $this->request->get['filter_date_added'];
  50. } else {
  51. $filter_date_added = '';
  52. }
  53. if (isset($this->request->get['page'])) {
  54. $page = (int)$this->request->get['page'];
  55. } else {
  56. $page = 1;
  57. }
  58. $url = '';
  59. if (isset($this->request->get['filter_email'])) {
  60. $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8'));
  61. }
  62. if (isset($this->request->get['filter_action'])) {
  63. $url .= '&filter_action=' . $this->request->get['filter_action'];
  64. }
  65. if (isset($this->request->get['filter_status'])) {
  66. $url .= '&filter_status=' . $this->request->get['filter_status'];
  67. }
  68. if (isset($this->request->get['filter_date_added'])) {
  69. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  70. }
  71. $data['action'] = $this->url->link('customer/gdpr|list', 'user_token=' . $this->session->data['user_token'] . $url, true);
  72. $data['gdprs'] = [];
  73. $filter_data = [
  74. 'filter_email' => $filter_email,
  75. 'filter_action' => $filter_action,
  76. 'filter_status' => $filter_status,
  77. 'filter_date_added' => $filter_date_added,
  78. 'start' => ($page - 1) * $this->config->get('config_pagination_admin'),
  79. 'limit' => $this->config->get('config_pagination_admin')
  80. ];
  81. $this->load->model('customer/gdpr');
  82. $this->load->model('customer/customer');
  83. $gdpr_total = $this->model_customer_gdpr->getTotalGdprs($filter_data);
  84. $results = $this->model_customer_gdpr->getGdprs($filter_data);
  85. foreach ($results as $result) {
  86. $customer_info = $this->model_customer_customer->getCustomerByEmail($result['email']);
  87. if ($customer_info) {
  88. $edit = $this->url->link('customer/customer|form', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $customer_info['customer_id'], true);
  89. } else {
  90. $edit = '';
  91. }
  92. $data['gdprs'][] = [
  93. 'gdpr_id' => $result['gdpr_id'],
  94. 'email' => $result['email'],
  95. 'action' => $this->language->get('text_' . $result['action']),
  96. 'status' => $result['status'],
  97. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  98. 'approve' => $this->url->link('customer/gdpr|approve', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
  99. 'deny' => $this->url->link('customer/gdpr|deny', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true),
  100. 'edit' => $edit,
  101. 'delete' => $this->url->link('customer/gdpr|delete', 'user_token=' . $this->session->data['user_token'] . '&gdpr_id=' . $result['gdpr_id'], true)
  102. ];
  103. }
  104. $url = '';
  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. if (isset($this->request->get['filter_action'])) {
  109. $url .= '&filter_action=' . $this->request->get['filter_action'];
  110. }
  111. if (isset($this->request->get['filter_status'])) {
  112. $url .= '&filter_status=' . $this->request->get['filter_status'];
  113. }
  114. if (isset($this->request->get['filter_date_added'])) {
  115. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  116. }
  117. $data['pagination'] = $this->load->controller('common/pagination', [
  118. 'total' => $gdpr_total,
  119. 'page' => $page,
  120. 'limit' => $this->config->get('config_pagination_admin'),
  121. 'url' => $this->url->link('customer/gdpr|list', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}')
  122. ]);
  123. $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')));
  124. return $this->load->view('customer/gdpr_list', $data);
  125. }
  126. /*
  127. * Action Statuses
  128. *
  129. * EXPORT
  130. *
  131. * unverified = 0
  132. * pending = 1
  133. * complete = 3
  134. *
  135. * REMOVE
  136. *
  137. * unverified = 0
  138. * pending = 1
  139. * processing = 2
  140. * delete = 3
  141. *
  142. * DENY
  143. *
  144. * unverified = 0
  145. * pending = 1
  146. * processing = 2
  147. * denied = -1
  148. */
  149. public function approve(): void {
  150. $this->load->language('customer/gdpr');
  151. $json = [];
  152. if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
  153. $json['error'] = $this->language->get('error_permission');
  154. }
  155. if (!$json) {
  156. $gdprs = [];
  157. if (isset($this->request->post['selected'])) {
  158. $gdprs = $this->request->post['selected'];
  159. }
  160. if (isset($this->request->get['gdpr_id'])) {
  161. $gdprs[] = (int)$this->request->get['gdpr_id'];
  162. }
  163. $this->load->model('customer/gdpr');
  164. foreach ($gdprs as $gdpr_id) {
  165. $gdpr_info = $this->model_customer_gdpr->getGdpr($gdpr_id);
  166. if ($gdpr_info) {
  167. // If we remove we want to change the status to processing
  168. // to give time for store owners to process orders and refunds.
  169. if ($gdpr_info['action'] == 'export') {
  170. $this->model_customer_gdpr->editStatus($gdpr_id, 3);
  171. } else {
  172. $this->model_customer_gdpr->editStatus($gdpr_id, 2);
  173. }
  174. }
  175. }
  176. $json['success'] = $this->language->get('text_success');
  177. }
  178. $this->response->addHeader('Content-Type: application/json');
  179. $this->response->setOutput(json_encode($json));
  180. }
  181. public function deny(): void {
  182. $this->load->language('customer/gdpr');
  183. $json = [];
  184. if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
  185. $json['error'] = $this->language->get('error_permission');
  186. }
  187. if (!$json) {
  188. $gdprs = [];
  189. if (isset($this->request->post['selected'])) {
  190. $gdprs = $this->request->post['selected'];
  191. }
  192. if (isset($this->request->get['gdpr_id'])) {
  193. $gdprs[] = (int)$this->request->get['gdpr_id'];
  194. }
  195. $this->load->model('customer/gdpr');
  196. foreach ($gdprs as $gdpr_id) {
  197. $this->model_customer_gdpr->editStatus($gdpr_id, -1);
  198. }
  199. $json['success'] = $this->language->get('text_success');
  200. }
  201. $this->response->addHeader('Content-Type: application/json');
  202. $this->response->setOutput(json_encode($json));
  203. }
  204. public function delete(): void {
  205. $this->load->language('customer/gdpr');
  206. $json = [];
  207. if (!$this->user->hasPermission('modify', 'customer/gdpr')) {
  208. $json['error'] = $this->language->get('error_permission');
  209. }
  210. if (!$json) {
  211. $gdprs = [];
  212. if (isset($this->request->post['selected'])) {
  213. $gdprs = $this->request->post['selected'];
  214. }
  215. if (isset($this->request->get['gdpr_id'])) {
  216. $gdprs[] = (int)$this->request->get['gdpr_id'];
  217. }
  218. $this->load->model('customer/gdpr');
  219. foreach ($gdprs as $gdpr_id) {
  220. $this->model_customer_gdpr->deleteGdpr($gdpr_id);
  221. }
  222. $json['success'] = $this->language->get('text_success');
  223. }
  224. $this->response->addHeader('Content-Type: application/json');
  225. $this->response->setOutput(json_encode($json));
  226. }
  227. }