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

/opencart_v1.4/upload/admin/controller/localisation/currency.php

http://coderstalk.googlecode.com/
PHP | 460 lines | 348 code | 112 blank | 0 comment | 79 complexity | 21b8deddba2f24222bcc8f6d9095eaf4 MD5 | raw file
Possible License(s): GPL-3.0, LGPL-2.1, AGPL-3.0
  1. <?php
  2. class ControllerLocalisationCurrency extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('localisation/currency');
  6. $this->document->title = $this->language->get('heading_title');
  7. $this->load->model('localisation/currency');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->load->language('localisation/currency');
  12. $this->document->title = $this->language->get('heading_title');
  13. $this->load->model('localisation/currency');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_localisation_currency->addCurrency($this->request->post);
  16. $this->session->data['success'] = $this->language->get('text_success');
  17. $url = '';
  18. if (isset($this->request->get['page'])) {
  19. $url .= '&page=' . $this->request->get['page'];
  20. }
  21. if (isset($this->request->get['sort'])) {
  22. $url .= '&sort=' . $this->request->get['sort'];
  23. }
  24. if (isset($this->request->get['order'])) {
  25. $url .= '&order=' . $this->request->get['order'];
  26. }
  27. $this->redirect($this->url->https('localisation/currency' . $url));
  28. }
  29. $this->getForm();
  30. }
  31. public function update() {
  32. $this->load->language('localisation/currency');
  33. $this->document->title = $this->language->get('heading_title');
  34. $this->load->model('localisation/currency');
  35. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  36. $this->model_localisation_currency->editCurrency($this->request->get['currency_id'], $this->request->post);
  37. $this->session->data['success'] = $this->language->get('text_success');
  38. $url = '';
  39. if (isset($this->request->get['page'])) {
  40. $url .= '&page=' . $this->request->get['page'];
  41. }
  42. if (isset($this->request->get['sort'])) {
  43. $url .= '&sort=' . $this->request->get['sort'];
  44. }
  45. if (isset($this->request->get['order'])) {
  46. $url .= '&order=' . $this->request->get['order'];
  47. }
  48. $this->redirect($this->url->https('localisation/currency' . $url));
  49. }
  50. $this->getForm();
  51. }
  52. public function delete() {
  53. $this->load->language('localisation/currency');
  54. $this->document->title = $this->language->get('heading_title');
  55. $this->load->model('localisation/currency');
  56. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  57. foreach ($this->request->post['selected'] as $currency_id) {
  58. $this->model_localisation_currency->deleteCurrency($currency_id);
  59. }
  60. $this->session->data['success'] = $this->language->get('text_success');
  61. $url = '';
  62. if (isset($this->request->get['page'])) {
  63. $url .= '&page=' . $this->request->get['page'];
  64. }
  65. if (isset($this->request->get['sort'])) {
  66. $url .= '&sort=' . $this->request->get['sort'];
  67. }
  68. if (isset($this->request->get['order'])) {
  69. $url .= '&order=' . $this->request->get['order'];
  70. }
  71. $this->redirect($this->url->https('localisation/currency' . $url));
  72. }
  73. $this->getList();
  74. }
  75. private function getList() {
  76. if (isset($this->request->get['page'])) {
  77. $page = $this->request->get['page'];
  78. } else {
  79. $page = 1;
  80. }
  81. if (isset($this->request->get['sort'])) {
  82. $sort = $this->request->get['sort'];
  83. } else {
  84. $sort = 'title';
  85. }
  86. if (isset($this->request->get['order'])) {
  87. $order = $this->request->get['order'];
  88. } else {
  89. $order = 'ASC';
  90. }
  91. $url = '';
  92. if (isset($this->request->get['page'])) {
  93. $url .= '&page=' . $this->request->get['page'];
  94. }
  95. if (isset($this->request->get['sort'])) {
  96. $url .= '&sort=' . $this->request->get['sort'];
  97. }
  98. if (isset($this->request->get['order'])) {
  99. $url .= '&order=' . $this->request->get['order'];
  100. }
  101. $this->document->breadcrumbs = array();
  102. $this->document->breadcrumbs[] = array(
  103. 'href' => $this->url->https('common/home'),
  104. 'text' => $this->language->get('text_home'),
  105. 'separator' => FALSE
  106. );
  107. $this->document->breadcrumbs[] = array(
  108. 'href' => $this->url->https('localisation/currency' . $url),
  109. 'text' => $this->language->get('heading_title'),
  110. 'separator' => ' :: '
  111. );
  112. $this->data['insert'] = $this->url->https('localisation/currency/insert' . $url);
  113. $this->data['delete'] = $this->url->https('localisation/currency/delete' . $url);
  114. $this->data['currencies'] = array();
  115. $data = array(
  116. 'sort' => $sort,
  117. 'order' => $order,
  118. 'start' => ($page - 1) * 10,
  119. 'limit' => 10
  120. );
  121. $currency_total = $this->model_localisation_currency->getTotalCurrencies();
  122. $results = $this->model_localisation_currency->getCurrencies($data);
  123. foreach ($results as $result) {
  124. $action = array();
  125. $action[] = array(
  126. 'text' => $this->language->get('text_edit'),
  127. 'href' => $this->url->https('localisation/currency/update&currency_id=' . $result['currency_id'] . $url)
  128. );
  129. $this->data['currencies'][] = array(
  130. 'currency_id' => $result['currency_id'],
  131. 'title' => $result['title'] . (($result['code'] == $this->config->get('config_currency')) ? $this->language->get('text_default') : NULL),
  132. 'code' => $result['code'],
  133. 'value' => $result['value'],
  134. 'date_modified' => date($this->language->get('date_format_short'), strtotime($result['date_modified'])),
  135. 'selected' => isset($this->request->post['selected']) && in_array($result['currency_id'], $this->request->post['selected']),
  136. 'action' => $action
  137. );
  138. }
  139. $this->data['heading_title'] = $this->language->get('heading_title');
  140. $this->data['text_no_results'] = $this->language->get('text_no_results');
  141. $this->data['column_title'] = $this->language->get('column_title');
  142. $this->data['column_code'] = $this->language->get('column_code');
  143. $this->data['column_value'] = $this->language->get('column_value');
  144. $this->data['column_date_modified'] = $this->language->get('column_date_modified');
  145. $this->data['column_action'] = $this->language->get('column_action');
  146. $this->data['button_insert'] = $this->language->get('button_insert');
  147. $this->data['button_delete'] = $this->language->get('button_delete');
  148. if (isset($this->error['warning'])) {
  149. $this->data['error_warning'] = $this->error['warning'];
  150. } else {
  151. $this->data['error_warning'] = '';
  152. }
  153. if (isset($this->session->data['success'])) {
  154. $this->data['success'] = $this->session->data['success'];
  155. unset($this->session->data['success']);
  156. } else {
  157. $this->data['success'] = '';
  158. }
  159. $url = '';
  160. if ($order == 'ASC') {
  161. $url .= '&order=' . 'DESC';
  162. } else {
  163. $url .= '&order=' . 'ASC';
  164. }
  165. if (isset($this->request->get['page'])) {
  166. $url .= '&page=' . $this->request->get['page'];
  167. }
  168. $this->data['sort_title'] = $this->url->https('localisation/currency&sort=title' . $url);
  169. $this->data['sort_code'] = $this->url->https('localisation/currency&sort=code' . $url);
  170. $this->data['sort_value'] = $this->url->https('localisation/currency&sort=value' . $url);
  171. $this->data['sort_date_modified'] = $this->url->https('localisation/currency&sort=date_modified' . $url);
  172. $url = '';
  173. if (isset($this->request->get['sort'])) {
  174. $url .= '&sort=' . $this->request->get['sort'];
  175. }
  176. if (isset($this->request->get['order'])) {
  177. $url .= '&order=' . $this->request->get['order'];
  178. }
  179. $pagination = new Pagination();
  180. $pagination->total = $currency_total;
  181. $pagination->page = $page;
  182. $pagination->limit = 10;
  183. $pagination->text = $this->language->get('text_pagination');
  184. $pagination->url = $this->url->https('localisation/currency' . $url . '&page=%s');
  185. $this->data['pagination'] = $pagination->render();
  186. $this->data['sort'] = $sort;
  187. $this->data['order'] = $order;
  188. $this->template = 'localisation/currency_list.tpl';
  189. $this->children = array(
  190. 'common/header',
  191. 'common/footer'
  192. );
  193. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  194. }
  195. private function getForm() {
  196. $this->data['heading_title'] = $this->language->get('heading_title');
  197. $this->data['text_enabled'] = $this->language->get('text_enabled');
  198. $this->data['text_disabled'] = $this->language->get('text_disabled');
  199. $this->data['entry_title'] = $this->language->get('entry_title');
  200. $this->data['entry_code'] = $this->language->get('entry_code');
  201. $this->data['entry_value'] = $this->language->get('entry_value');
  202. $this->data['entry_symbol_left'] = $this->language->get('entry_symbol_left');
  203. $this->data['entry_symbol_right'] = $this->language->get('entry_symbol_right');
  204. $this->data['entry_decimal_place'] = $this->language->get('entry_decimal_place');
  205. $this->data['entry_status'] = $this->language->get('entry_status');
  206. $this->data['button_save'] = $this->language->get('button_save');
  207. $this->data['button_cancel'] = $this->language->get('button_cancel');
  208. $this->data['tab_general'] = $this->language->get('tab_general');
  209. if (isset($this->error['warning'])) {
  210. $this->data['error_warning'] = $this->error['warning'];
  211. } else {
  212. $this->data['error_warning'] = '';
  213. }
  214. if (isset($this->error['title'])) {
  215. $this->data['error_title'] = $this->error['title'];
  216. } else {
  217. $this->data['error_title'] = '';
  218. }
  219. if (isset($this->error['code'])) {
  220. $this->data['error_code'] = $this->error['code'];
  221. } else {
  222. $this->data['error_code'] = '';
  223. }
  224. $url = '';
  225. if (isset($this->request->get['page'])) {
  226. $url .= '&page=' . $this->request->get['page'];
  227. }
  228. if (isset($this->request->get['sort'])) {
  229. $url .= '&sort=' . $this->request->get['sort'];
  230. }
  231. if (isset($this->request->get['order'])) {
  232. $url .= '&order=' . $this->request->get['order'];
  233. }
  234. $this->document->breadcrumbs = array();
  235. $this->document->breadcrumbs[] = array(
  236. 'href' => $this->url->https('common/home'),
  237. 'text' => $this->language->get('text_home'),
  238. 'separator' => FALSE
  239. );
  240. $this->document->breadcrumbs[] = array(
  241. 'href' => $this->url->https('localisation/currency' . $url),
  242. 'text' => $this->language->get('heading_title'),
  243. 'separator' => ' :: '
  244. );
  245. if (!isset($this->request->get['currency_id'])) {
  246. $this->data['action'] = $this->url->https('localisation/currency/insert' . $url);
  247. } else {
  248. $this->data['action'] = $this->url->https('localisation/currency/update&currency_id=' . $this->request->get['currency_id'] . $url);
  249. }
  250. $this->data['cancel'] = $this->url->https('localisation/currency' . $url);
  251. if (isset($this->request->get['currency_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  252. $currency_info = $this->model_localisation_currency->getCurrency($this->request->get['currency_id']);
  253. }
  254. if (isset($this->request->post['title'])) {
  255. $this->data['title'] = $this->request->post['title'];
  256. } elseif (isset($currency_info)) {
  257. $this->data['title'] = $currency_info['title'];
  258. } else {
  259. $this->data['title'] = '';
  260. }
  261. if (isset($this->request->post['code'])) {
  262. $this->data['code'] = $this->request->post['code'];
  263. } elseif (isset($currency_info)) {
  264. $this->data['code'] = $currency_info['code'];
  265. } else {
  266. $this->data['code'] = '';
  267. }
  268. if (isset($this->request->post['symbol_left'])) {
  269. $this->data['symbol_left'] = $this->request->post['symbol_left'];
  270. } elseif (isset($currency_info)) {
  271. $this->data['symbol_left'] = $currency_info['symbol_left'];
  272. } else {
  273. $this->data['symbol_left'] = '';
  274. }
  275. if (isset($this->request->post['symbol_right'])) {
  276. $this->data['symbol_right'] = $this->request->post['symbol_right'];
  277. } elseif (isset($currency_info)) {
  278. $this->data['symbol_right'] = $currency_info['symbol_right'];
  279. } else {
  280. $this->data['symbol_right'] = '';
  281. }
  282. if (isset($this->request->post['decimal_place'])) {
  283. $this->data['decimal_place'] = $this->request->post['decimal_place'];
  284. } elseif (isset($currency_info)) {
  285. $this->data['decimal_place'] = $currency_info['decimal_place'];
  286. } else {
  287. $this->data['decimal_place'] = '';
  288. }
  289. if (isset($this->request->post['value'])) {
  290. $this->data['value'] = $this->request->post['value'];
  291. } elseif (isset($currency_info)) {
  292. $this->data['value'] = $currency_info['value'];
  293. } else {
  294. $this->data['value'] = '';
  295. }
  296. if (isset($this->request->post['status'])) {
  297. $this->data['status'] = $this->request->post['status'];
  298. } elseif (isset($currency_info)) {
  299. $this->data['status'] = @$currency_info['status'];
  300. } else {
  301. $this->data['status'] = '';
  302. }
  303. $this->template = 'localisation/currency_form.tpl';
  304. $this->children = array(
  305. 'common/header',
  306. 'common/footer'
  307. );
  308. $this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
  309. }
  310. private function validateForm() {
  311. if (!$this->user->hasPermission('modify', 'localisation/currency')) {
  312. $this->error['warning'] = $this->language->get('error_permission');
  313. }
  314. if ((strlen(utf8_decode($this->request->post['title'])) < 3) || (strlen(utf8_decode($this->request->post['title'])) > 32)) {
  315. $this->error['title'] = $this->language->get('error_title');
  316. }
  317. if (strlen(utf8_decode($this->request->post['code'])) != 3) {
  318. $this->error['code'] = $this->language->get('error_code');
  319. }
  320. if (!$this->error) {
  321. return TRUE;
  322. } else {
  323. return FALSE;
  324. }
  325. }
  326. private function validateDelete() {
  327. if (!$this->user->hasPermission('modify', 'localisation/currency')) {
  328. $this->error['warning'] = $this->language->get('error_permission');
  329. }
  330. $this->load->model('sale/order');
  331. foreach ($this->request->post['selected'] as $currency_id) {
  332. $currency_info = $this->model_localisation_currency->getCurrency($currency_id);
  333. if ($this->config->get('config_currency') == $currency_info['code']) {
  334. $this->error['warning'] = $this->language->get('error_default');
  335. }
  336. $order_total = $this->model_sale_order->getTotalOrdersByCurrencyId($currency_id);
  337. if ($order_total) {
  338. $this->error['warning'] = sprintf($this->language->get('error_order'), $order_total);
  339. }
  340. }
  341. if (!$this->error) {
  342. return TRUE;
  343. } else {
  344. return FALSE;
  345. }
  346. }
  347. }
  348. ?>