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

/upload/admin/controller/localisation/tax_class.php

https://gitlab.com/m.mirsamie/opencart
PHP | 400 lines | 293 code | 107 blank | 0 comment | 65 complexity | 37f3287317e3d441c4ee2680102ad35e MD5 | raw file
  1. <?php
  2. class ControllerLocalisationTaxClass extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('localisation/tax_class');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('localisation/tax_class');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->load->language('localisation/tax_class');
  12. $this->document->setTitle($this->language->get('heading_title'));
  13. $this->load->model('localisation/tax_class');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_localisation_tax_class->addTaxClass($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/tax_class', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  28. }
  29. $this->getForm();
  30. }
  31. public function update() {
  32. $this->load->language('localisation/tax_class');
  33. $this->document->setTitle($this->language->get('heading_title'));
  34. $this->load->model('localisation/tax_class');
  35. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  36. $this->model_localisation_tax_class->editTaxClass($this->request->get['tax_class_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/tax_class', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  49. }
  50. $this->getForm();
  51. }
  52. public function delete() {
  53. $this->load->language('localisation/tax_class');
  54. $this->document->setTitle($this->language->get('heading_title'));
  55. $this->load->model('localisation/tax_class');
  56. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  57. foreach ($this->request->post['selected'] as $tax_class_id) {
  58. $this->model_localisation_tax_class->deleteTaxClass($tax_class_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/tax_class', '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 = 'title';
  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'], 'SSL')
  105. );
  106. $data['breadcrumbs'][] = array(
  107. 'text' => $this->language->get('heading_title'),
  108. 'href' => $this->url->link('localisation/tax_class', 'token=' . $this->session->data['token'] . $url, 'SSL')
  109. );
  110. $data['insert'] = $this->url->link('localisation/tax_class/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  111. $data['delete'] = $this->url->link('localisation/tax_class/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  112. $data['tax_classes'] = 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. $tax_class_total = $this->model_localisation_tax_class->getTotalTaxClasses();
  120. $results = $this->model_localisation_tax_class->getTaxClasses($filter_data);
  121. foreach ($results as $result) {
  122. $data['tax_classes'][] = array(
  123. 'tax_class_id' => $result['tax_class_id'],
  124. 'title' => $result['title'],
  125. 'edit' => $this->url->link('localisation/tax_class/update', 'token=' . $this->session->data['token'] . '&tax_class_id=' . $result['tax_class_id'] . $url, 'SSL')
  126. );
  127. }
  128. $data['heading_title'] = $this->language->get('heading_title');
  129. $data['text_no_results'] = $this->language->get('text_no_results');
  130. $data['text_confirm'] = $this->language->get('text_confirm');
  131. $data['column_title'] = $this->language->get('column_title');
  132. $data['column_action'] = $this->language->get('column_action');
  133. $data['button_insert'] = $this->language->get('button_insert');
  134. $data['button_edit'] = $this->language->get('button_edit');
  135. $data['button_delete'] = $this->language->get('button_delete');
  136. if (isset($this->error['warning'])) {
  137. $data['error_warning'] = $this->error['warning'];
  138. } else {
  139. $data['error_warning'] = '';
  140. }
  141. if (isset($this->session->data['success'])) {
  142. $data['success'] = $this->session->data['success'];
  143. unset($this->session->data['success']);
  144. } else {
  145. $data['success'] = '';
  146. }
  147. if (isset($this->request->post['selected'])) {
  148. $data['selected'] = (array)$this->request->post['selected'];
  149. } else {
  150. $data['selected'] = array();
  151. }
  152. $url = '';
  153. if ($order == 'ASC') {
  154. $url .= '&order=DESC';
  155. } else {
  156. $url .= '&order=ASC';
  157. }
  158. if (isset($this->request->get['page'])) {
  159. $url .= '&page=' . $this->request->get['page'];
  160. }
  161. $data['sort_title'] = $this->url->link('localisation/tax_class', 'token=' . $this->session->data['token'] . '&sort=title' . $url, 'SSL');
  162. $url = '';
  163. if (isset($this->request->get['sort'])) {
  164. $url .= '&sort=' . $this->request->get['sort'];
  165. }
  166. if (isset($this->request->get['order'])) {
  167. $url .= '&order=' . $this->request->get['order'];
  168. }
  169. $pagination = new Pagination();
  170. $pagination->total = $tax_class_total;
  171. $pagination->page = $page;
  172. $pagination->limit = $this->config->get('config_limit_admin');
  173. $pagination->url = $this->url->link('localisation/tax_class', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  174. $data['pagination'] = $pagination->render();
  175. $data['results'] = sprintf($this->language->get('text_pagination'), ($tax_class_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($tax_class_total - $this->config->get('config_limit_admin'))) ? $tax_class_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $tax_class_total, ceil($tax_class_total / $this->config->get('config_limit_admin')));
  176. $data['sort'] = $sort;
  177. $data['order'] = $order;
  178. $data['header'] = $this->load->controller('common/header');
  179. $data['menu'] = $this->load->controller('common/menu');
  180. $data['footer'] = $this->load->controller('common/footer');
  181. $this->response->setOutput($this->load->view('localisation/tax_class_list.tpl', $data));
  182. }
  183. protected function getForm() {
  184. $data['heading_title'] = $this->language->get('heading_title');
  185. $data['text_shipping'] = $this->language->get('text_shipping');
  186. $data['text_payment'] = $this->language->get('text_payment');
  187. $data['text_store'] = $this->language->get('text_store');
  188. $data['entry_title'] = $this->language->get('entry_title');
  189. $data['entry_description'] = $this->language->get('entry_description');
  190. $data['entry_rate'] = $this->language->get('entry_rate');
  191. $data['entry_based'] = $this->language->get('entry_based');
  192. $data['entry_priority'] = $this->language->get('entry_priority');
  193. $data['button_save'] = $this->language->get('button_save');
  194. $data['button_cancel'] = $this->language->get('button_cancel');
  195. $data['button_rule_add'] = $this->language->get('button_rule_add');
  196. $data['button_remove'] = $this->language->get('button_remove');
  197. if (isset($this->error['warning'])) {
  198. $data['error_warning'] = $this->error['warning'];
  199. } else {
  200. $data['error_warning'] = '';
  201. }
  202. if (isset($this->error['title'])) {
  203. $data['error_title'] = $this->error['title'];
  204. } else {
  205. $data['error_title'] = '';
  206. }
  207. if (isset($this->error['description'])) {
  208. $data['error_description'] = $this->error['description'];
  209. } else {
  210. $data['error_description'] = '';
  211. }
  212. $url = '';
  213. if (isset($this->request->get['sort'])) {
  214. $url .= '&sort=' . $this->request->get['sort'];
  215. }
  216. if (isset($this->request->get['order'])) {
  217. $url .= '&order=' . $this->request->get['order'];
  218. }
  219. if (isset($this->request->get['page'])) {
  220. $url .= '&page=' . $this->request->get['page'];
  221. }
  222. $data['breadcrumbs'] = array();
  223. $data['breadcrumbs'][] = array(
  224. 'text' => $this->language->get('text_home'),
  225. 'href' => $this->url->link('common/dashboard', 'token=' . $this->session->data['token'], 'SSL')
  226. );
  227. $data['breadcrumbs'][] = array(
  228. 'text' => $this->language->get('heading_title'),
  229. 'href' => $this->url->link('localisation/tax_class', 'token=' . $this->session->data['token'] . $url, 'SSL')
  230. );
  231. if (!isset($this->request->get['tax_class_id'])) {
  232. $data['action'] = $this->url->link('localisation/tax_class/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  233. } else {
  234. $data['action'] = $this->url->link('localisation/tax_class/update', 'token=' . $this->session->data['token'] . '&tax_class_id=' . $this->request->get['tax_class_id'] . $url, 'SSL');
  235. }
  236. $data['cancel'] = $this->url->link('localisation/tax_class', 'token=' . $this->session->data['token'] . $url, 'SSL');
  237. if (isset($this->request->get['tax_class_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  238. $tax_class_info = $this->model_localisation_tax_class->getTaxClass($this->request->get['tax_class_id']);
  239. }
  240. if (isset($this->request->post['title'])) {
  241. $data['title'] = $this->request->post['title'];
  242. } elseif (!empty($tax_class_info)) {
  243. $data['title'] = $tax_class_info['title'];
  244. } else {
  245. $data['title'] = '';
  246. }
  247. if (isset($this->request->post['description'])) {
  248. $data['description'] = $this->request->post['description'];
  249. } elseif (!empty($tax_class_info)) {
  250. $data['description'] = $tax_class_info['description'];
  251. } else {
  252. $data['description'] = '';
  253. }
  254. $this->load->model('localisation/tax_rate');
  255. $data['tax_rates'] = $this->model_localisation_tax_rate->getTaxRates();
  256. if (isset($this->request->post['tax_rule'])) {
  257. $data['tax_rules'] = $this->request->post['tax_rule'];
  258. } elseif (isset($this->request->get['tax_class_id'])) {
  259. $data['tax_rules'] = $this->model_localisation_tax_class->getTaxRules($this->request->get['tax_class_id']);
  260. } else {
  261. $data['tax_rules'] = array();
  262. }
  263. $data['header'] = $this->load->controller('common/header');
  264. $data['menu'] = $this->load->controller('common/menu');
  265. $data['footer'] = $this->load->controller('common/footer');
  266. $this->response->setOutput($this->load->view('localisation/tax_class_form.tpl', $data));
  267. }
  268. protected function validateForm() {
  269. if (!$this->user->hasPermission('modify', 'localisation/tax_class')) {
  270. $this->error['warning'] = $this->language->get('error_permission');
  271. }
  272. if ((utf8_strlen($this->request->post['title']) < 3) || (utf8_strlen($this->request->post['title']) > 32)) {
  273. $this->error['title'] = $this->language->get('error_title');
  274. }
  275. if ((utf8_strlen($this->request->post['description']) < 3) || (utf8_strlen($this->request->post['description']) > 255)) {
  276. $this->error['description'] = $this->language->get('error_description');
  277. }
  278. return !$this->error;
  279. }
  280. protected function validateDelete() {
  281. if (!$this->user->hasPermission('modify', 'localisation/tax_class')) {
  282. $this->error['warning'] = $this->language->get('error_permission');
  283. }
  284. $this->load->model('catalog/product');
  285. foreach ($this->request->post['selected'] as $tax_class_id) {
  286. $product_total = $this->model_catalog_product->getTotalProductsByTaxClassId($tax_class_id);
  287. if ($product_total) {
  288. $this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
  289. }
  290. }
  291. return !$this->error;
  292. }
  293. }