PageRenderTime 27ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/localisation/order_status.php

https://gitlab.com/shapcy/opencart
PHP | 380 lines | 274 code | 106 blank | 0 comment | 60 complexity | 4e8d592e0d70edbbef8eca80ec974574 MD5 | raw file
  1. <?php
  2. class ControllerLocalisationOrderStatus extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('localisation/order_status');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('localisation/order_status');
  8. $this->getList();
  9. }
  10. public function add() {
  11. $this->load->language('localisation/order_status');
  12. $this->document->setTitle($this->language->get('heading_title'));
  13. $this->load->model('localisation/order_status');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_localisation_order_status->addOrderStatus($this->request->post);
  16. $this->session->data['success'] = $this->language->get('text_success');
  17. $url = '';
  18. if (isset($this->request->get['sort'])) {
  19. $url .= '&sort=' . $this->request->get['sort'];
  20. }
  21. if (isset($this->request->get['order'])) {
  22. $url .= '&order=' . $this->request->get['order'];
  23. }
  24. if (isset($this->request->get['page'])) {
  25. $url .= '&page=' . $this->request->get['page'];
  26. }
  27. $this->response->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true));
  28. }
  29. $this->getForm();
  30. }
  31. public function edit() {
  32. $this->load->language('localisation/order_status');
  33. $this->document->setTitle($this->language->get('heading_title'));
  34. $this->load->model('localisation/order_status');
  35. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  36. $this->model_localisation_order_status->editOrderStatus($this->request->get['order_status_id'], $this->request->post);
  37. $this->session->data['success'] = $this->language->get('text_success');
  38. $url = '';
  39. if (isset($this->request->get['sort'])) {
  40. $url .= '&sort=' . $this->request->get['sort'];
  41. }
  42. if (isset($this->request->get['order'])) {
  43. $url .= '&order=' . $this->request->get['order'];
  44. }
  45. if (isset($this->request->get['page'])) {
  46. $url .= '&page=' . $this->request->get['page'];
  47. }
  48. $this->response->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true));
  49. }
  50. $this->getForm();
  51. }
  52. public function delete() {
  53. $this->load->language('localisation/order_status');
  54. $this->document->setTitle($this->language->get('heading_title'));
  55. $this->load->model('localisation/order_status');
  56. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  57. foreach ($this->request->post['selected'] as $order_status_id) {
  58. $this->model_localisation_order_status->deleteOrderStatus($order_status_id);
  59. }
  60. $this->session->data['success'] = $this->language->get('text_success');
  61. $url = '';
  62. if (isset($this->request->get['sort'])) {
  63. $url .= '&sort=' . $this->request->get['sort'];
  64. }
  65. if (isset($this->request->get['order'])) {
  66. $url .= '&order=' . $this->request->get['order'];
  67. }
  68. if (isset($this->request->get['page'])) {
  69. $url .= '&page=' . $this->request->get['page'];
  70. }
  71. $this->response->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true));
  72. }
  73. $this->getList();
  74. }
  75. protected function getList() {
  76. if (isset($this->request->get['sort'])) {
  77. $sort = $this->request->get['sort'];
  78. } else {
  79. $sort = 'name';
  80. }
  81. if (isset($this->request->get['order'])) {
  82. $order = $this->request->get['order'];
  83. } else {
  84. $order = 'ASC';
  85. }
  86. if (isset($this->request->get['page'])) {
  87. $page = $this->request->get['page'];
  88. } else {
  89. $page = 1;
  90. }
  91. $url = '';
  92. if (isset($this->request->get['sort'])) {
  93. $url .= '&sort=' . $this->request->get['sort'];
  94. }
  95. if (isset($this->request->get['order'])) {
  96. $url .= '&order=' . $this->request->get['order'];
  97. }
  98. if (isset($this->request->get['page'])) {
  99. $url .= '&page=' . $this->request->get['page'];
  100. }
  101. $data['breadcrumbs'] = array();
  102. $data['breadcrumbs'][] = array(
  103. 'text' => $this->language->get('text_home'),
  104. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
  105. );
  106. $data['breadcrumbs'][] = array(
  107. 'text' => $this->language->get('heading_title'),
  108. 'href' => $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true)
  109. );
  110. $data['add'] = $this->url->link('localisation/order_status/add', 'token=' . $this->session->data['token'] . $url, true);
  111. $data['delete'] = $this->url->link('localisation/order_status/delete', 'token=' . $this->session->data['token'] . $url, true);
  112. $data['order_statuses'] = array();
  113. $filter_data = array(
  114. 'sort' => $sort,
  115. 'order' => $order,
  116. 'start' => ($page - 1) * $this->config->get('config_limit_admin'),
  117. 'limit' => $this->config->get('config_limit_admin')
  118. );
  119. $order_status_total = $this->model_localisation_order_status->getTotalOrderStatuses();
  120. $results = $this->model_localisation_order_status->getOrderStatuses($filter_data);
  121. foreach ($results as $result) {
  122. $data['order_statuses'][] = array(
  123. 'order_status_id' => $result['order_status_id'],
  124. 'name' => $result['name'] . (($result['order_status_id'] == $this->config->get('config_order_status_id')) ? $this->language->get('text_default') : null),
  125. 'edit' => $this->url->link('localisation/order_status/edit', 'token=' . $this->session->data['token'] . '&order_status_id=' . $result['order_status_id'] . $url, true)
  126. );
  127. }
  128. $data['heading_title'] = $this->language->get('heading_title');
  129. $data['text_list'] = $this->language->get('text_list');
  130. $data['text_no_results'] = $this->language->get('text_no_results');
  131. $data['text_confirm'] = $this->language->get('text_confirm');
  132. $data['column_name'] = $this->language->get('column_name');
  133. $data['column_action'] = $this->language->get('column_action');
  134. $data['button_add'] = $this->language->get('button_add');
  135. $data['button_edit'] = $this->language->get('button_edit');
  136. $data['button_delete'] = $this->language->get('button_delete');
  137. if (isset($this->error['warning'])) {
  138. $data['error_warning'] = $this->error['warning'];
  139. } else {
  140. $data['error_warning'] = '';
  141. }
  142. if (isset($this->session->data['success'])) {
  143. $data['success'] = $this->session->data['success'];
  144. unset($this->session->data['success']);
  145. } else {
  146. $data['success'] = '';
  147. }
  148. if (isset($this->request->post['selected'])) {
  149. $data['selected'] = (array)$this->request->post['selected'];
  150. } else {
  151. $data['selected'] = array();
  152. }
  153. $url = '';
  154. if ($order == 'ASC') {
  155. $url .= '&order=DESC';
  156. } else {
  157. $url .= '&order=ASC';
  158. }
  159. if (isset($this->request->get['page'])) {
  160. $url .= '&page=' . $this->request->get['page'];
  161. }
  162. $data['sort_name'] = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . '&sort=name' . $url, true);
  163. $url = '';
  164. if (isset($this->request->get['sort'])) {
  165. $url .= '&sort=' . $this->request->get['sort'];
  166. }
  167. if (isset($this->request->get['order'])) {
  168. $url .= '&order=' . $this->request->get['order'];
  169. }
  170. $pagination = new Pagination();
  171. $pagination->total = $order_status_total;
  172. $pagination->page = $page;
  173. $pagination->limit = $this->config->get('config_limit_admin');
  174. $pagination->url = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url . '&page={page}', true);
  175. $data['pagination'] = $pagination->render();
  176. $data['results'] = sprintf($this->language->get('text_pagination'), ($order_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($order_status_total - $this->config->get('config_limit_admin'))) ? $order_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $order_status_total, ceil($order_status_total / $this->config->get('config_limit_admin')));
  177. $data['sort'] = $sort;
  178. $data['order'] = $order;
  179. $data['header'] = $this->load->controller('common/header');
  180. $data['column_left'] = $this->load->controller('common/column_left');
  181. $data['footer'] = $this->load->controller('common/footer');
  182. $this->response->setOutput($this->load->view('localisation/order_status_list', $data));
  183. }
  184. protected function getForm() {
  185. $data['heading_title'] = $this->language->get('heading_title');
  186. $data['text_form'] = !isset($this->request->get['order_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
  187. $data['entry_name'] = $this->language->get('entry_name');
  188. $data['button_save'] = $this->language->get('button_save');
  189. $data['button_cancel'] = $this->language->get('button_cancel');
  190. if (isset($this->error['warning'])) {
  191. $data['error_warning'] = $this->error['warning'];
  192. } else {
  193. $data['error_warning'] = '';
  194. }
  195. if (isset($this->error['name'])) {
  196. $data['error_name'] = $this->error['name'];
  197. } else {
  198. $data['error_name'] = array();
  199. }
  200. $url = '';
  201. if (isset($this->request->get['sort'])) {
  202. $url .= '&sort=' . $this->request->get['sort'];
  203. }
  204. if (isset($this->request->get['order'])) {
  205. $url .= '&order=' . $this->request->get['order'];
  206. }
  207. if (isset($this->request->get['page'])) {
  208. $url .= '&page=' . $this->request->get['page'];
  209. }
  210. $data['breadcrumbs'] = array();
  211. $data['breadcrumbs'][] = array(
  212. 'text' => $this->language->get('text_home'),
  213. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], true)
  214. );
  215. $data['breadcrumbs'][] = array(
  216. 'text' => $this->language->get('heading_title'),
  217. 'href' => $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true)
  218. );
  219. if (!isset($this->request->get['order_status_id'])) {
  220. $data['action'] = $this->url->link('localisation/order_status/add', 'token=' . $this->session->data['token'] . $url, true);
  221. } else {
  222. $data['action'] = $this->url->link('localisation/order_status/edit', 'token=' . $this->session->data['token'] . '&order_status_id=' . $this->request->get['order_status_id'] . $url, true);
  223. }
  224. $data['cancel'] = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, true);
  225. $this->load->model('localisation/language');
  226. $data['languages'] = $this->model_localisation_language->getLanguages();
  227. if (isset($this->request->post['order_status'])) {
  228. $data['order_status'] = $this->request->post['order_status'];
  229. } elseif (isset($this->request->get['order_status_id'])) {
  230. $data['order_status'] = $this->model_localisation_order_status->getOrderStatusDescriptions($this->request->get['order_status_id']);
  231. } else {
  232. $data['order_status'] = array();
  233. }
  234. $data['header'] = $this->load->controller('common/header');
  235. $data['column_left'] = $this->load->controller('common/column_left');
  236. $data['footer'] = $this->load->controller('common/footer');
  237. $this->response->setOutput($this->load->view('localisation/order_status_form', $data));
  238. }
  239. protected function validateForm() {
  240. if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
  241. $this->error['warning'] = $this->language->get('error_permission');
  242. }
  243. foreach ($this->request->post['order_status'] as $language_id => $value) {
  244. if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) {
  245. $this->error['name'][$language_id] = $this->language->get('error_name');
  246. }
  247. }
  248. return !$this->error;
  249. }
  250. protected function validateDelete() {
  251. if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
  252. $this->error['warning'] = $this->language->get('error_permission');
  253. }
  254. $this->load->model('setting/store');
  255. $this->load->model('sale/order');
  256. foreach ($this->request->post['selected'] as $order_status_id) {
  257. if ($this->config->get('config_order_status_id') == $order_status_id) {
  258. $this->error['warning'] = $this->language->get('error_default');
  259. }
  260. if ($this->config->get('config_download_status_id') == $order_status_id) {
  261. $this->error['warning'] = $this->language->get('error_download');
  262. }
  263. $store_total = $this->model_setting_store->getTotalStoresByOrderStatusId($order_status_id);
  264. if ($store_total) {
  265. $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
  266. }
  267. $order_total = $this->model_sale_order->getTotalOrderHistoriesByOrderStatusId($order_status_id);
  268. if ($order_total) {
  269. $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total);
  270. }
  271. }
  272. return !$this->error;
  273. }
  274. }