/upload/admin/controller/localisation/return_status.php

https://bitbucket.org/mjalajel/opencart · PHP · 385 lines · 280 code · 105 blank · 0 comment · 61 complexity · 817581710aab9b38ef97ad51d87bb2a6 MD5 · raw file

  1. <?php
  2. class ControllerLocalisationReturnStatus extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->language->load('localisation/return_status');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('localisation/return_status');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->language->load('localisation/return_status');
  12. $this->document->setTitle($this->language->get('heading_title'));
  13. $this->load->model('localisation/return_status');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_localisation_return_status->addReturnStatus($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/return_status', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  28. }
  29. $this->getForm();
  30. }
  31. public function update() {
  32. $this->language->load('localisation/return_status');
  33. $this->document->setTitle($this->language->get('heading_title'));
  34. $this->load->model('localisation/return_status');
  35. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  36. $this->model_localisation_return_status->editReturnStatus($this->request->get['return_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/return_status', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  49. }
  50. $this->getForm();
  51. }
  52. public function delete() {
  53. $this->language->load('localisation/return_status');
  54. $this->document->setTitle($this->language->get('heading_title'));
  55. $this->load->model('localisation/return_status');
  56. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  57. foreach ($this->request->post['selected'] as $return_status_id) {
  58. $this->model_localisation_return_status->deleteReturnStatus($return_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/return_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/dashboard', 'token=' . $this->session->data['token'], 'SSL')
  105. );
  106. $this->data['breadcrumbs'][] = array(
  107. 'text' => $this->language->get('heading_title'),
  108. 'href' => $this->url->link('localisation/return_status', 'token=' . $this->session->data['token'] . $url, 'SSL')
  109. );
  110. $this->data['insert'] = $this->url->link('localisation/return_status/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  111. $this->data['delete'] = $this->url->link('localisation/return_status/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  112. $this->data['return_statuses'] = array();
  113. $data = array(
  114. 'sort' => $sort,
  115. 'order' => $order,
  116. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  117. 'limit' => $this->config->get('config_admin_limit')
  118. );
  119. $return_status_total = $this->model_localisation_return_status->getTotalReturnStatuses();
  120. $results = $this->model_localisation_return_status->getReturnStatuses($data);
  121. foreach ($results as $result) {
  122. $action = array();
  123. $action[] = array(
  124. 'text' => $this->language->get('text_edit'),
  125. 'href' => $this->url->link('localisation/return_status/update', 'token=' . $this->session->data['token'] . '&return_status_id=' . $result['return_status_id'] . $url, 'SSL')
  126. );
  127. $this->data['return_statuses'][] = array(
  128. 'return_status_id' => $result['return_status_id'],
  129. 'name' => $result['name'] . (($result['return_status_id'] == $this->config->get('config_return_status_id')) ? $this->language->get('text_default') : null),
  130. 'selected' => isset($this->request->post['selected']) && in_array($result['return_status_id'], $this->request->post['selected']),
  131. 'action' => $action
  132. );
  133. }
  134. $this->data['heading_title'] = $this->language->get('heading_title');
  135. $this->data['text_no_results'] = $this->language->get('text_no_results');
  136. $this->data['column_name'] = $this->language->get('column_name');
  137. $this->data['column_action'] = $this->language->get('column_action');
  138. $this->data['button_insert'] = $this->language->get('button_insert');
  139. $this->data['button_delete'] = $this->language->get('button_delete');
  140. if (isset($this->error['warning'])) {
  141. $this->data['error_warning'] = $this->error['warning'];
  142. } else {
  143. $this->data['error_warning'] = '';
  144. }
  145. if (isset($this->session->data['success'])) {
  146. $this->data['success'] = $this->session->data['success'];
  147. unset($this->session->data['success']);
  148. } else {
  149. $this->data['success'] = '';
  150. }
  151. $url = '';
  152. if ($order == 'ASC') {
  153. $url .= '&order=DESC';
  154. } else {
  155. $url .= '&order=ASC';
  156. }
  157. if (isset($this->request->get['page'])) {
  158. $url .= '&page=' . $this->request->get['page'];
  159. }
  160. $this->data['sort_name'] = $this->url->link('localisation/return_status', 'token=' . $this->session->data['token'] . '&sort=name' . $url, 'SSL');
  161. $url = '';
  162. if (isset($this->request->get['sort'])) {
  163. $url .= '&sort=' . $this->request->get['sort'];
  164. }
  165. if (isset($this->request->get['order'])) {
  166. $url .= '&order=' . $this->request->get['order'];
  167. }
  168. $pagination = new Pagination();
  169. $pagination->total = $return_status_total;
  170. $pagination->page = $page;
  171. $pagination->limit = $this->config->get('config_admin_limit');
  172. $pagination->url = $this->url->link('localisation/return_status', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  173. $this->data['pagination'] = $pagination->render();
  174. $this->data['results'] = sprintf($this->language->get('text_pagination'), ($return_status_total) ? (($page - 1) * $this->config->get('config_admin_limit')) + 1 : 0, ((($page - 1) * $this->config->get('config_admin_limit')) > ($return_status_total - $this->config->get('config_admin_limit'))) ? $return_status_total : ((($page - 1) * $this->config->get('config_admin_limit')) + $this->config->get('config_admin_limit')), $return_status_total, ceil($return_status_total / $this->config->get('config_admin_limit')));
  175. $this->data['sort'] = $sort;
  176. $this->data['order'] = $order;
  177. $this->template = 'localisation/return_status_list.tpl';
  178. $this->children = array(
  179. 'common/header',
  180. 'common/footer'
  181. );
  182. $this->response->setOutput($this->render());
  183. }
  184. protected function getForm() {
  185. $this->data['heading_title'] = $this->language->get('heading_title');
  186. $this->data['entry_name'] = $this->language->get('entry_name');
  187. $this->data['button_save'] = $this->language->get('button_save');
  188. $this->data['button_cancel'] = $this->language->get('button_cancel');
  189. if (isset($this->error['warning'])) {
  190. $this->data['error_warning'] = $this->error['warning'];
  191. } else {
  192. $this->data['error_warning'] = '';
  193. }
  194. if (isset($this->error['name'])) {
  195. $this->data['error_name'] = $this->error['name'];
  196. } else {
  197. $this->data['error_name'] = array();
  198. }
  199. $url = '';
  200. if (isset($this->request->get['sort'])) {
  201. $url .= '&sort=' . $this->request->get['sort'];
  202. }
  203. if (isset($this->request->get['order'])) {
  204. $url .= '&order=' . $this->request->get['order'];
  205. }
  206. if (isset($this->request->get['page'])) {
  207. $url .= '&page=' . $this->request->get['page'];
  208. }
  209. $this->data['breadcrumbs'] = array();
  210. $this->data['breadcrumbs'][] = array(
  211. 'text' => $this->language->get('text_home'),
  212. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
  213. );
  214. $this->data['breadcrumbs'][] = array(
  215. 'text' => $this->language->get('heading_title'),
  216. 'href' => $this->url->link('localisation/return_status', 'token=' . $this->session->data['token'] . $url, 'SSL')
  217. );
  218. if (!isset($this->request->get['return_status_id'])) {
  219. $this->data['action'] = $this->url->link('localisation/return_status/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  220. } else {
  221. $this->data['action'] = $this->url->link('localisation/return_status/update', 'token=' . $this->session->data['token'] . '&return_status_id=' . $this->request->get['return_status_id'] . $url, 'SSL');
  222. }
  223. $this->data['cancel'] = $this->url->link('localisation/return_status', 'token=' . $this->session->data['token'] . $url, 'SSL');
  224. $this->load->model('localisation/language');
  225. $this->data['languages'] = $this->model_localisation_language->getLanguages();
  226. if (isset($this->request->post['return_status'])) {
  227. $this->data['return_status'] = $this->request->post['return_status'];
  228. } elseif (isset($this->request->get['return_status_id'])) {
  229. $this->data['return_status'] = $this->model_localisation_return_status->getReturnStatusDescriptions($this->request->get['return_status_id']);
  230. } else {
  231. $this->data['return_status'] = array();
  232. }
  233. $this->template = 'localisation/return_status_form.tpl';
  234. $this->children = array(
  235. 'common/header',
  236. 'common/footer'
  237. );
  238. $this->response->setOutput($this->render());
  239. }
  240. protected function validateForm() {
  241. if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
  242. $this->error['warning'] = $this->language->get('error_permission');
  243. }
  244. foreach ($this->request->post['return_status'] as $language_id => $value) {
  245. if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) {
  246. $this->error['name'][$language_id] = $this->language->get('error_name');
  247. }
  248. }
  249. if (!$this->error) {
  250. return true;
  251. } else {
  252. return false;
  253. }
  254. }
  255. protected function validateDelete() {
  256. if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
  257. $this->error['warning'] = $this->language->get('error_permission');
  258. }
  259. $this->load->model('sale/return');
  260. foreach ($this->request->post['selected'] as $return_status_id) {
  261. if ($this->config->get('config_return_status_id') == $return_status_id) {
  262. $this->error['warning'] = $this->language->get('error_default');
  263. }
  264. $return_total = $this->model_sale_return->getTotalReturnsByReturnStatusId($return_status_id);
  265. if ($return_total) {
  266. $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total);
  267. }
  268. $return_total = $this->model_sale_return->getTotalReturnHistoriesByReturnStatusId($return_status_id);
  269. if ($return_total) {
  270. $this->error['warning'] = sprintf($this->language->get('error_return'), $return_total);
  271. }
  272. }
  273. if (!$this->error) {
  274. return true;
  275. } else {
  276. return false;
  277. }
  278. }
  279. }
  280. ?>