PageRenderTime 57ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/mall/upload/admin/controller/localisation/order_status.php

https://bitbucket.org/allanxyh/uniquemall
PHP | 393 lines | 288 code | 105 blank | 0 comment | 63 complexity | e84a16d4dd871e5a53b9845dc79c072f MD5 | raw file
  1. <?php
  2. class ControllerLocalisationOrderStatus extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->language->load('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 insert() {
  11. $this->language->load('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->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  28. }
  29. $this->getForm();
  30. }
  31. public function update() {
  32. $this->language->load('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->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  49. }
  50. $this->getForm();
  51. }
  52. public function delete() {
  53. $this->language->load('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->redirect($this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  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. $this->data['breadcrumbs'] = array();
  102. $this->data['breadcrumbs'][] = array(
  103. 'text' => $this->language->get('text_home'),
  104. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  105. 'separator' => false
  106. );
  107. $this->data['breadcrumbs'][] = array(
  108. 'text' => $this->language->get('heading_title'),
  109. 'href' => $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  110. 'separator' => ' :: '
  111. );
  112. $this->data['insert'] = $this->url->link('localisation/order_status/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  113. $this->data['delete'] = $this->url->link('localisation/order_status/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  114. $this->data['order_statuses'] = array();
  115. $data = array(
  116. 'sort' => $sort,
  117. 'order' => $order,
  118. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  119. 'limit' => $this->config->get('config_admin_limit')
  120. );
  121. $order_status_total = $this->model_localisation_order_status->getTotalOrderStatuses();
  122. $results = $this->model_localisation_order_status->getOrderStatuses($data);
  123. foreach ($results as $result) {
  124. $action = array();
  125. $action[] = array(
  126. 'text' => $this->language->get('text_edit'),
  127. 'href' => $this->url->link('localisation/order_status/update', 'token=' . $this->session->data['token'] . '&order_status_id=' . $result['order_status_id'] . $url, 'SSL')
  128. );
  129. $this->data['order_statuses'][] = array(
  130. 'order_status_id' => $result['order_status_id'],
  131. 'name' => $result['name'] . (($result['order_status_id'] == $this->config->get('config_order_status_id')) ? $this->language->get('text_default') : null),
  132. 'selected' => isset($this->request->post['selected']) && in_array($result['order_status_id'], $this->request->post['selected']),
  133. 'action' => $action
  134. );
  135. }
  136. $this->data['heading_title'] = $this->language->get('heading_title');
  137. $this->data['text_no_results'] = $this->language->get('text_no_results');
  138. $this->data['column_name'] = $this->language->get('column_name');
  139. $this->data['column_action'] = $this->language->get('column_action');
  140. $this->data['button_insert'] = $this->language->get('button_insert');
  141. $this->data['button_delete'] = $this->language->get('button_delete');
  142. if (isset($this->error['warning'])) {
  143. $this->data['error_warning'] = $this->error['warning'];
  144. } else {
  145. $this->data['error_warning'] = '';
  146. }
  147. if (isset($this->session->data['success'])) {
  148. $this->data['success'] = $this->session->data['success'];
  149. unset($this->session->data['success']);
  150. } else {
  151. $this->data['success'] = '';
  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. $this->data['sort_name'] = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . '&sort=name' . $url, 'SSL');
  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_admin_limit');
  174. $pagination->text = $this->language->get('text_pagination');
  175. $pagination->url = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  176. $this->data['pagination'] = $pagination->render();
  177. $this->data['sort'] = $sort;
  178. $this->data['order'] = $order;
  179. $this->template = 'localisation/order_status_list.tpl';
  180. $this->children = array(
  181. 'common/header',
  182. 'common/footer'
  183. );
  184. $this->response->setOutput($this->render());
  185. }
  186. protected function getForm() {
  187. $this->data['heading_title'] = $this->language->get('heading_title');
  188. $this->data['entry_name'] = $this->language->get('entry_name');
  189. $this->data['button_save'] = $this->language->get('button_save');
  190. $this->data['button_cancel'] = $this->language->get('button_cancel');
  191. if (isset($this->error['warning'])) {
  192. $this->data['error_warning'] = $this->error['warning'];
  193. } else {
  194. $this->data['error_warning'] = '';
  195. }
  196. if (isset($this->error['name'])) {
  197. $this->data['error_name'] = $this->error['name'];
  198. } else {
  199. $this->data['error_name'] = array();
  200. }
  201. $url = '';
  202. if (isset($this->request->get['sort'])) {
  203. $url .= '&sort=' . $this->request->get['sort'];
  204. }
  205. if (isset($this->request->get['order'])) {
  206. $url .= '&order=' . $this->request->get['order'];
  207. }
  208. if (isset($this->request->get['page'])) {
  209. $url .= '&page=' . $this->request->get['page'];
  210. }
  211. $this->data['breadcrumbs'] = array();
  212. $this->data['breadcrumbs'][] = array(
  213. 'text' => $this->language->get('text_home'),
  214. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  215. 'separator' => false
  216. );
  217. $this->data['breadcrumbs'][] = array(
  218. 'text' => $this->language->get('heading_title'),
  219. 'href' => $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  220. 'separator' => ' :: '
  221. );
  222. if (!isset($this->request->get['order_status_id'])) {
  223. $this->data['action'] = $this->url->link('localisation/order_status/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  224. } else {
  225. $this->data['action'] = $this->url->link('localisation/order_status/update', 'token=' . $this->session->data['token'] . '&order_status_id=' . $this->request->get['order_status_id'] . $url, 'SSL');
  226. }
  227. $this->data['cancel'] = $this->url->link('localisation/order_status', 'token=' . $this->session->data['token'] . $url, 'SSL');
  228. $this->load->model('localisation/language');
  229. $this->data['languages'] = $this->model_localisation_language->getLanguages();
  230. if (isset($this->request->post['order_status'])) {
  231. $this->data['order_status'] = $this->request->post['order_status'];
  232. } elseif (isset($this->request->get['order_status_id'])) {
  233. $this->data['order_status'] = $this->model_localisation_order_status->getOrderStatusDescriptions($this->request->get['order_status_id']);
  234. } else {
  235. $this->data['order_status'] = array();
  236. }
  237. $this->template = 'localisation/order_status_form.tpl';
  238. $this->children = array(
  239. 'common/header',
  240. 'common/footer'
  241. );
  242. $this->response->setOutput($this->render());
  243. }
  244. protected function validateForm() {
  245. if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
  246. $this->error['warning'] = $this->language->get('error_permission');
  247. }
  248. foreach ($this->request->post['order_status'] as $language_id => $value) {
  249. if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) {
  250. $this->error['name'][$language_id] = $this->language->get('error_name');
  251. }
  252. }
  253. if (!$this->error) {
  254. return true;
  255. } else {
  256. return false;
  257. }
  258. }
  259. protected function validateDelete() {
  260. if (!$this->user->hasPermission('modify', 'localisation/order_status')) {
  261. $this->error['warning'] = $this->language->get('error_permission');
  262. }
  263. $this->load->model('setting/store');
  264. $this->load->model('sale/order');
  265. foreach ($this->request->post['selected'] as $order_status_id) {
  266. if ($this->config->get('config_order_status_id') == $order_status_id) {
  267. $this->error['warning'] = $this->language->get('error_default');
  268. }
  269. if ($this->config->get('config_download_status_id') == $order_status_id) {
  270. $this->error['warning'] = $this->language->get('error_download');
  271. }
  272. $store_total = $this->model_setting_store->getTotalStoresByOrderStatusId($order_status_id);
  273. if ($store_total) {
  274. $this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
  275. }
  276. $order_total = $this->model_sale_order->getTotalOrderHistoriesByOrderStatusId($order_status_id);
  277. if ($order_total) {
  278. $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total);
  279. }
  280. }
  281. if (!$this->error) {
  282. return true;
  283. } else {
  284. return false;
  285. }
  286. }
  287. }
  288. ?>