PageRenderTime 453ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/admin/controller/sale/customer.php

https://bitbucket.org/monobasic/shop.volero.ch
PHP | 1284 lines | 981 code | 303 blank | 0 comment | 253 complexity | af095267d9a4820397ed69ba7abd2cc4 MD5 | raw file
  1. <?php
  2. class ControllerSaleCustomer extends Controller {
  3. private $error = array();
  4. public function index() {
  5. $this->load->language('sale/customer');
  6. $this->document->setTitle($this->language->get('heading_title'));
  7. $this->load->model('sale/customer');
  8. $this->getList();
  9. }
  10. public function insert() {
  11. $this->load->language('sale/customer');
  12. $this->document->setTitle($this->language->get('heading_title'));
  13. $this->load->model('sale/customer');
  14. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  15. $this->model_sale_customer->addCustomer($this->request->post);
  16. $this->session->data['success'] = $this->language->get('text_success');
  17. $url = '';
  18. if (isset($this->request->get['filter_name'])) {
  19. $url .= '&filter_name=' . $this->request->get['filter_name'];
  20. }
  21. if (isset($this->request->get['filter_email'])) {
  22. $url .= '&filter_email=' . $this->request->get['filter_email'];
  23. }
  24. if (isset($this->request->get['filter_customer_group_id'])) {
  25. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  26. }
  27. if (isset($this->request->get['filter_status'])) {
  28. $url .= '&filter_status=' . $this->request->get['filter_status'];
  29. }
  30. if (isset($this->request->get['filter_approved'])) {
  31. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  32. }
  33. if (isset($this->request->get['filter_ip'])) {
  34. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  35. }
  36. if (isset($this->request->get['filter_date_added'])) {
  37. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  38. }
  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('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  49. }
  50. $this->getForm();
  51. }
  52. public function update() {
  53. $this->load->language('sale/customer');
  54. $this->document->setTitle($this->language->get('heading_title'));
  55. $this->load->model('sale/customer');
  56. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
  57. $this->model_sale_customer->editCustomer($this->request->get['customer_id'], $this->request->post);
  58. $this->session->data['success'] = $this->language->get('text_success');
  59. $url = '';
  60. if (isset($this->request->get['filter_name'])) {
  61. $url .= '&filter_name=' . $this->request->get['filter_name'];
  62. }
  63. if (isset($this->request->get['filter_email'])) {
  64. $url .= '&filter_email=' . $this->request->get['filter_email'];
  65. }
  66. if (isset($this->request->get['filter_customer_group_id'])) {
  67. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  68. }
  69. if (isset($this->request->get['filter_status'])) {
  70. $url .= '&filter_status=' . $this->request->get['filter_status'];
  71. }
  72. if (isset($this->request->get['filter_approved'])) {
  73. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  74. }
  75. if (isset($this->request->get['filter_ip'])) {
  76. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  77. }
  78. if (isset($this->request->get['filter_date_added'])) {
  79. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  80. }
  81. if (isset($this->request->get['sort'])) {
  82. $url .= '&sort=' . $this->request->get['sort'];
  83. }
  84. if (isset($this->request->get['order'])) {
  85. $url .= '&order=' . $this->request->get['order'];
  86. }
  87. if (isset($this->request->get['page'])) {
  88. $url .= '&page=' . $this->request->get['page'];
  89. }
  90. $this->redirect($this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  91. }
  92. $this->getForm();
  93. }
  94. public function delete() {
  95. $this->load->language('sale/customer');
  96. $this->document->setTitle($this->language->get('heading_title'));
  97. $this->load->model('sale/customer');
  98. if (isset($this->request->post['selected']) && $this->validateDelete()) {
  99. foreach ($this->request->post['selected'] as $customer_id) {
  100. $this->model_sale_customer->deleteCustomer($customer_id);
  101. }
  102. $this->session->data['success'] = $this->language->get('text_success');
  103. $url = '';
  104. if (isset($this->request->get['filter_name'])) {
  105. $url .= '&filter_name=' . $this->request->get['filter_name'];
  106. }
  107. if (isset($this->request->get['filter_email'])) {
  108. $url .= '&filter_email=' . $this->request->get['filter_email'];
  109. }
  110. if (isset($this->request->get['filter_customer_group_id'])) {
  111. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  112. }
  113. if (isset($this->request->get['filter_status'])) {
  114. $url .= '&filter_status=' . $this->request->get['filter_status'];
  115. }
  116. if (isset($this->request->get['filter_approved'])) {
  117. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  118. }
  119. if (isset($this->request->get['filter_ip'])) {
  120. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  121. }
  122. if (isset($this->request->get['filter_date_added'])) {
  123. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  124. }
  125. if (isset($this->request->get['sort'])) {
  126. $url .= '&sort=' . $this->request->get['sort'];
  127. }
  128. if (isset($this->request->get['order'])) {
  129. $url .= '&order=' . $this->request->get['order'];
  130. }
  131. if (isset($this->request->get['page'])) {
  132. $url .= '&page=' . $this->request->get['page'];
  133. }
  134. $this->redirect($this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  135. }
  136. $this->getList();
  137. }
  138. public function approve() {
  139. $this->load->language('sale/customer');
  140. $this->document->setTitle($this->language->get('heading_title'));
  141. $this->load->model('sale/customer');
  142. if (!$this->user->hasPermission('modify', 'sale/customer')) {
  143. $this->error['warning'] = $this->language->get('error_permission');
  144. } elseif (isset($this->request->post['selected'])) {
  145. $approved = 0;
  146. foreach ($this->request->post['selected'] as $customer_id) {
  147. $customer_info = $this->model_sale_customer->getCustomer($customer_id);
  148. if ($customer_info && !$customer_info['approved']) {
  149. $this->model_sale_customer->approve($customer_id);
  150. $approved++;
  151. }
  152. }
  153. $this->session->data['success'] = sprintf($this->language->get('text_approved'), $approved);
  154. $url = '';
  155. if (isset($this->request->get['filter_name'])) {
  156. $url .= '&filter_name=' . $this->request->get['filter_name'];
  157. }
  158. if (isset($this->request->get['filter_email'])) {
  159. $url .= '&filter_email=' . $this->request->get['filter_email'];
  160. }
  161. if (isset($this->request->get['filter_customer_group_id'])) {
  162. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  163. }
  164. if (isset($this->request->get['filter_status'])) {
  165. $url .= '&filter_status=' . $this->request->get['filter_status'];
  166. }
  167. if (isset($this->request->get['filter_approved'])) {
  168. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  169. }
  170. if (isset($this->request->get['filter_ip'])) {
  171. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  172. }
  173. if (isset($this->request->get['filter_date_added'])) {
  174. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  175. }
  176. if (isset($this->request->get['sort'])) {
  177. $url .= '&sort=' . $this->request->get['sort'];
  178. }
  179. if (isset($this->request->get['order'])) {
  180. $url .= '&order=' . $this->request->get['order'];
  181. }
  182. if (isset($this->request->get['page'])) {
  183. $url .= '&page=' . $this->request->get['page'];
  184. }
  185. $this->redirect($this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'));
  186. }
  187. $this->getList();
  188. }
  189. private function getList() {
  190. if (isset($this->request->get['filter_name'])) {
  191. $filter_name = $this->request->get['filter_name'];
  192. } else {
  193. $filter_name = null;
  194. }
  195. if (isset($this->request->get['filter_email'])) {
  196. $filter_email = $this->request->get['filter_email'];
  197. } else {
  198. $filter_email = null;
  199. }
  200. if (isset($this->request->get['filter_customer_group_id'])) {
  201. $filter_customer_group_id = $this->request->get['filter_customer_group_id'];
  202. } else {
  203. $filter_customer_group_id = null;
  204. }
  205. if (isset($this->request->get['filter_status'])) {
  206. $filter_status = $this->request->get['filter_status'];
  207. } else {
  208. $filter_status = null;
  209. }
  210. if (isset($this->request->get['filter_approved'])) {
  211. $filter_approved = $this->request->get['filter_approved'];
  212. } else {
  213. $filter_approved = null;
  214. }
  215. if (isset($this->request->get['filter_ip'])) {
  216. $filter_ip = $this->request->get['filter_ip'];
  217. } else {
  218. $filter_ip = null;
  219. }
  220. if (isset($this->request->get['filter_date_added'])) {
  221. $filter_date_added = $this->request->get['filter_date_added'];
  222. } else {
  223. $filter_date_added = null;
  224. }
  225. if (isset($this->request->get['sort'])) {
  226. $sort = $this->request->get['sort'];
  227. } else {
  228. $sort = 'name';
  229. }
  230. if (isset($this->request->get['order'])) {
  231. $order = $this->request->get['order'];
  232. } else {
  233. $order = 'ASC';
  234. }
  235. if (isset($this->request->get['page'])) {
  236. $page = $this->request->get['page'];
  237. } else {
  238. $page = 1;
  239. }
  240. $url = '';
  241. if (isset($this->request->get['filter_name'])) {
  242. $url .= '&filter_name=' . $this->request->get['filter_name'];
  243. }
  244. if (isset($this->request->get['filter_email'])) {
  245. $url .= '&filter_email=' . $this->request->get['filter_email'];
  246. }
  247. if (isset($this->request->get['filter_customer_group_id'])) {
  248. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  249. }
  250. if (isset($this->request->get['filter_status'])) {
  251. $url .= '&filter_status=' . $this->request->get['filter_status'];
  252. }
  253. if (isset($this->request->get['filter_approved'])) {
  254. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  255. }
  256. if (isset($this->request->get['filter_ip'])) {
  257. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  258. }
  259. if (isset($this->request->get['filter_date_added'])) {
  260. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  261. }
  262. if (isset($this->request->get['sort'])) {
  263. $url .= '&sort=' . $this->request->get['sort'];
  264. }
  265. if (isset($this->request->get['order'])) {
  266. $url .= '&order=' . $this->request->get['order'];
  267. }
  268. if (isset($this->request->get['page'])) {
  269. $url .= '&page=' . $this->request->get['page'];
  270. }
  271. $this->data['breadcrumbs'] = array();
  272. $this->data['breadcrumbs'][] = array(
  273. 'text' => $this->language->get('text_home'),
  274. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  275. 'separator' => false
  276. );
  277. $this->data['breadcrumbs'][] = array(
  278. 'text' => $this->language->get('heading_title'),
  279. 'href' => $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  280. 'separator' => ' :: '
  281. );
  282. $this->data['approve'] = $this->url->link('sale/customer/approve', 'token=' . $this->session->data['token'] . $url, 'SSL');
  283. $this->data['insert'] = $this->url->link('sale/customer/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  284. $this->data['delete'] = $this->url->link('sale/customer/delete', 'token=' . $this->session->data['token'] . $url, 'SSL');
  285. $this->data['customers'] = array();
  286. $data = array(
  287. 'filter_name' => $filter_name,
  288. 'filter_email' => $filter_email,
  289. 'filter_customer_group_id' => $filter_customer_group_id,
  290. 'filter_status' => $filter_status,
  291. 'filter_approved' => $filter_approved,
  292. 'filter_date_added' => $filter_date_added,
  293. 'filter_ip' => $filter_ip,
  294. 'sort' => $sort,
  295. 'order' => $order,
  296. 'start' => ($page - 1) * $this->config->get('config_admin_limit'),
  297. 'limit' => $this->config->get('config_admin_limit')
  298. );
  299. $customer_total = $this->model_sale_customer->getTotalCustomers($data);
  300. $results = $this->model_sale_customer->getCustomers($data);
  301. foreach ($results as $result) {
  302. $action = array();
  303. $action[] = array(
  304. 'text' => $this->language->get('text_edit'),
  305. 'href' => $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $result['customer_id'] . $url, 'SSL')
  306. );
  307. $this->data['customers'][] = array(
  308. 'customer_id' => $result['customer_id'],
  309. 'name' => $result['name'],
  310. 'email' => $result['email'],
  311. 'customer_group' => $result['customer_group'],
  312. 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
  313. 'approved' => ($result['approved'] ? $this->language->get('text_yes') : $this->language->get('text_no')),
  314. 'ip' => $result['ip'],
  315. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
  316. 'selected' => isset($this->request->post['selected']) && in_array($result['customer_id'], $this->request->post['selected']),
  317. 'action' => $action
  318. );
  319. }
  320. $this->data['heading_title'] = $this->language->get('heading_title');
  321. $this->data['text_enabled'] = $this->language->get('text_enabled');
  322. $this->data['text_disabled'] = $this->language->get('text_disabled');
  323. $this->data['text_yes'] = $this->language->get('text_yes');
  324. $this->data['text_no'] = $this->language->get('text_no');
  325. $this->data['text_select'] = $this->language->get('text_select');
  326. $this->data['text_default'] = $this->language->get('text_default');
  327. $this->data['text_no_results'] = $this->language->get('text_no_results');
  328. $this->data['column_name'] = $this->language->get('column_name');
  329. $this->data['column_email'] = $this->language->get('column_email');
  330. $this->data['column_customer_group'] = $this->language->get('column_customer_group');
  331. $this->data['column_status'] = $this->language->get('column_status');
  332. $this->data['column_approved'] = $this->language->get('column_approved');
  333. $this->data['column_ip'] = $this->language->get('column_ip');
  334. $this->data['column_date_added'] = $this->language->get('column_date_added');
  335. $this->data['column_login'] = $this->language->get('column_login');
  336. $this->data['column_action'] = $this->language->get('column_action');
  337. $this->data['button_approve'] = $this->language->get('button_approve');
  338. $this->data['button_insert'] = $this->language->get('button_insert');
  339. $this->data['button_delete'] = $this->language->get('button_delete');
  340. $this->data['button_filter'] = $this->language->get('button_filter');
  341. $this->data['token'] = $this->session->data['token'];
  342. if (isset($this->error['warning'])) {
  343. $this->data['error_warning'] = $this->error['warning'];
  344. } else {
  345. $this->data['error_warning'] = '';
  346. }
  347. if (isset($this->session->data['success'])) {
  348. $this->data['success'] = $this->session->data['success'];
  349. unset($this->session->data['success']);
  350. } else {
  351. $this->data['success'] = '';
  352. }
  353. $url = '';
  354. if (isset($this->request->get['filter_name'])) {
  355. $url .= '&filter_name=' . $this->request->get['filter_name'];
  356. }
  357. if (isset($this->request->get['filter_email'])) {
  358. $url .= '&filter_email=' . $this->request->get['filter_email'];
  359. }
  360. if (isset($this->request->get['filter_customer_group_id'])) {
  361. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  362. }
  363. if (isset($this->request->get['filter_status'])) {
  364. $url .= '&filter_status=' . $this->request->get['filter_status'];
  365. }
  366. if (isset($this->request->get['filter_approved'])) {
  367. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  368. }
  369. if (isset($this->request->get['filter_ip'])) {
  370. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  371. }
  372. if (isset($this->request->get['filter_date_added'])) {
  373. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  374. }
  375. if ($order == 'ASC') {
  376. $url .= '&order=DESC';
  377. } else {
  378. $url .= '&order=ASC';
  379. }
  380. if (isset($this->request->get['page'])) {
  381. $url .= '&page=' . $this->request->get['page'];
  382. }
  383. $this->data['sort_name'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=name' . $url, 'SSL');
  384. $this->data['sort_email'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=c.email' . $url, 'SSL');
  385. $this->data['sort_customer_group'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=customer_group' . $url, 'SSL');
  386. $this->data['sort_status'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=c.status' . $url, 'SSL');
  387. $this->data['sort_approved'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=c.approved' . $url, 'SSL');
  388. $this->data['sort_ip'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=c.ip' . $url, 'SSL');
  389. $this->data['sort_date_added'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . '&sort=c.date_added' . $url, 'SSL');
  390. $url = '';
  391. if (isset($this->request->get['filter_name'])) {
  392. $url .= '&filter_name=' . $this->request->get['filter_name'];
  393. }
  394. if (isset($this->request->get['filter_email'])) {
  395. $url .= '&filter_email=' . $this->request->get['filter_email'];
  396. }
  397. if (isset($this->request->get['filter_customer_group_id'])) {
  398. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  399. }
  400. if (isset($this->request->get['filter_status'])) {
  401. $url .= '&filter_status=' . $this->request->get['filter_status'];
  402. }
  403. if (isset($this->request->get['filter_approved'])) {
  404. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  405. }
  406. if (isset($this->request->get['filter_ip'])) {
  407. $url .= '&filter_ip=' . $this->request->get['filter_ip'];
  408. }
  409. if (isset($this->request->get['filter_date_added'])) {
  410. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  411. }
  412. if (isset($this->request->get['sort'])) {
  413. $url .= '&sort=' . $this->request->get['sort'];
  414. }
  415. if (isset($this->request->get['order'])) {
  416. $url .= '&order=' . $this->request->get['order'];
  417. }
  418. $pagination = new Pagination();
  419. $pagination->total = $customer_total;
  420. $pagination->page = $page;
  421. $pagination->limit = $this->config->get('config_admin_limit');
  422. $pagination->text = $this->language->get('text_pagination');
  423. $pagination->url = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url . '&page={page}', 'SSL');
  424. $this->data['pagination'] = $pagination->render();
  425. $this->data['filter_name'] = $filter_name;
  426. $this->data['filter_email'] = $filter_email;
  427. $this->data['filter_customer_group_id'] = $filter_customer_group_id;
  428. $this->data['filter_status'] = $filter_status;
  429. $this->data['filter_approved'] = $filter_approved;
  430. $this->data['filter_ip'] = $filter_ip;
  431. $this->data['filter_date_added'] = $filter_date_added;
  432. $this->load->model('sale/customer_group');
  433. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  434. $this->load->model('setting/store');
  435. $this->data['stores'] = $this->model_setting_store->getStores();
  436. $this->data['sort'] = $sort;
  437. $this->data['order'] = $order;
  438. $this->template = 'sale/customer_list.tpl';
  439. $this->children = array(
  440. 'common/header',
  441. 'common/footer'
  442. );
  443. $this->response->setOutput($this->render());
  444. }
  445. private function getForm() {
  446. $this->data['heading_title'] = $this->language->get('heading_title');
  447. $this->data['text_enabled'] = $this->language->get('text_enabled');
  448. $this->data['text_disabled'] = $this->language->get('text_disabled');
  449. $this->data['text_select'] = $this->language->get('text_select');
  450. $this->data['text_wait'] = $this->language->get('text_wait');
  451. $this->data['text_no_results'] = $this->language->get('text_no_results');
  452. $this->data['column_ip'] = $this->language->get('column_ip');
  453. $this->data['column_total'] = $this->language->get('column_total');
  454. $this->data['column_date_added'] = $this->language->get('column_date_added');
  455. $this->data['entry_firstname'] = $this->language->get('entry_firstname');
  456. $this->data['entry_lastname'] = $this->language->get('entry_lastname');
  457. $this->data['entry_email'] = $this->language->get('entry_email');
  458. $this->data['entry_telephone'] = $this->language->get('entry_telephone');
  459. $this->data['entry_fax'] = $this->language->get('entry_fax');
  460. $this->data['entry_password'] = $this->language->get('entry_password');
  461. $this->data['entry_confirm'] = $this->language->get('entry_confirm');
  462. $this->data['entry_newsletter'] = $this->language->get('entry_newsletter');
  463. $this->data['entry_customer_group'] = $this->language->get('entry_customer_group');
  464. $this->data['entry_status'] = $this->language->get('entry_status');
  465. $this->data['entry_company'] = $this->language->get('entry_company');
  466. $this->data['entry_address_1'] = $this->language->get('entry_address_1');
  467. $this->data['entry_address_2'] = $this->language->get('entry_address_2');
  468. $this->data['entry_city'] = $this->language->get('entry_city');
  469. $this->data['entry_postcode'] = $this->language->get('entry_postcode');
  470. $this->data['entry_zone'] = $this->language->get('entry_zone');
  471. $this->data['entry_country'] = $this->language->get('entry_country');
  472. $this->data['entry_default'] = $this->language->get('entry_default');
  473. $this->data['entry_amount'] = $this->language->get('entry_amount');
  474. $this->data['entry_points'] = $this->language->get('entry_points');
  475. $this->data['entry_description'] = $this->language->get('entry_description');
  476. $this->data['button_save'] = $this->language->get('button_save');
  477. $this->data['button_cancel'] = $this->language->get('button_cancel');
  478. $this->data['button_add_address'] = $this->language->get('button_add_address');
  479. $this->data['button_add_transaction'] = $this->language->get('button_add_transaction');
  480. $this->data['button_add_reward'] = $this->language->get('button_add_reward');
  481. $this->data['button_remove'] = $this->language->get('button_remove');
  482. $this->data['tab_general'] = $this->language->get('tab_general');
  483. $this->data['tab_address'] = $this->language->get('tab_address');
  484. $this->data['tab_transaction'] = $this->language->get('tab_transaction');
  485. $this->data['tab_reward'] = $this->language->get('tab_reward');
  486. $this->data['tab_ip'] = $this->language->get('tab_ip');
  487. $this->data['token'] = $this->session->data['token'];
  488. if (isset($this->request->get['customer_id'])) {
  489. $this->data['customer_id'] = $this->request->get['customer_id'];
  490. } else {
  491. $this->data['customer_id'] = 0;
  492. }
  493. if (isset($this->error['warning'])) {
  494. $this->data['error_warning'] = $this->error['warning'];
  495. } else {
  496. $this->data['error_warning'] = '';
  497. }
  498. if (isset($this->error['firstname'])) {
  499. $this->data['error_firstname'] = $this->error['firstname'];
  500. } else {
  501. $this->data['error_firstname'] = '';
  502. }
  503. if (isset($this->error['lastname'])) {
  504. $this->data['error_lastname'] = $this->error['lastname'];
  505. } else {
  506. $this->data['error_lastname'] = '';
  507. }
  508. if (isset($this->error['email'])) {
  509. $this->data['error_email'] = $this->error['email'];
  510. } else {
  511. $this->data['error_email'] = '';
  512. }
  513. if (isset($this->error['telephone'])) {
  514. $this->data['error_telephone'] = $this->error['telephone'];
  515. } else {
  516. $this->data['error_telephone'] = '';
  517. }
  518. if (isset($this->error['password'])) {
  519. $this->data['error_password'] = $this->error['password'];
  520. } else {
  521. $this->data['error_password'] = '';
  522. }
  523. if (isset($this->error['confirm'])) {
  524. $this->data['error_confirm'] = $this->error['confirm'];
  525. } else {
  526. $this->data['error_confirm'] = '';
  527. }
  528. if (isset($this->error['address_firstname'])) {
  529. $this->data['error_address_firstname'] = $this->error['address_firstname'];
  530. } else {
  531. $this->data['error_address_firstname'] = '';
  532. }
  533. if (isset($this->error['address_lastname'])) {
  534. $this->data['error_address_lastname'] = $this->error['address_lastname'];
  535. } else {
  536. $this->data['error_address_lastname'] = '';
  537. }
  538. if (isset($this->error['address_address_1'])) {
  539. $this->data['error_address_address_1'] = $this->error['address_address_1'];
  540. } else {
  541. $this->data['error_address_address_1'] = '';
  542. }
  543. if (isset($this->error['address_city'])) {
  544. $this->data['error_address_city'] = $this->error['address_city'];
  545. } else {
  546. $this->data['error_address_city'] = '';
  547. }
  548. if (isset($this->error['address_postcode'])) {
  549. $this->data['error_address_postcode'] = $this->error['address_postcode'];
  550. } else {
  551. $this->data['error_address_postcode'] = '';
  552. }
  553. if (isset($this->error['address_country'])) {
  554. $this->data['error_address_country'] = $this->error['address_country'];
  555. } else {
  556. $this->data['error_address_country'] = '';
  557. }
  558. if (isset($this->error['address_zone'])) {
  559. $this->data['error_address_zone'] = $this->error['address_zone'];
  560. } else {
  561. $this->data['error_address_zone'] = '';
  562. }
  563. $url = '';
  564. if (isset($this->request->get['filter_name'])) {
  565. $url .= '&filter_name=' . $this->request->get['filter_name'];
  566. }
  567. if (isset($this->request->get['filter_email'])) {
  568. $url .= '&filter_email=' . $this->request->get['filter_email'];
  569. }
  570. if (isset($this->request->get['filter_customer_group_id'])) {
  571. $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id'];
  572. }
  573. if (isset($this->request->get['filter_status'])) {
  574. $url .= '&filter_status=' . $this->request->get['filter_status'];
  575. }
  576. if (isset($this->request->get['filter_approved'])) {
  577. $url .= '&filter_approved=' . $this->request->get['filter_approved'];
  578. }
  579. if (isset($this->request->get['filter_date_added'])) {
  580. $url .= '&filter_date_added=' . $this->request->get['filter_date_added'];
  581. }
  582. if (isset($this->request->get['sort'])) {
  583. $url .= '&sort=' . $this->request->get['sort'];
  584. }
  585. if (isset($this->request->get['order'])) {
  586. $url .= '&order=' . $this->request->get['order'];
  587. }
  588. if (isset($this->request->get['page'])) {
  589. $url .= '&page=' . $this->request->get['page'];
  590. }
  591. $this->data['breadcrumbs'] = array();
  592. $this->data['breadcrumbs'][] = array(
  593. 'text' => $this->language->get('text_home'),
  594. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  595. 'separator' => false
  596. );
  597. $this->data['breadcrumbs'][] = array(
  598. 'text' => $this->language->get('heading_title'),
  599. 'href' => $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL'),
  600. 'separator' => ' :: '
  601. );
  602. if (!isset($this->request->get['customer_id'])) {
  603. $this->data['action'] = $this->url->link('sale/customer/insert', 'token=' . $this->session->data['token'] . $url, 'SSL');
  604. } else {
  605. $this->data['action'] = $this->url->link('sale/customer/update', 'token=' . $this->session->data['token'] . '&customer_id=' . $this->request->get['customer_id'] . $url, 'SSL');
  606. }
  607. $this->data['cancel'] = $this->url->link('sale/customer', 'token=' . $this->session->data['token'] . $url, 'SSL');
  608. if (isset($this->request->get['customer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
  609. $customer_info = $this->model_sale_customer->getCustomer($this->request->get['customer_id']);
  610. }
  611. if (isset($this->request->post['firstname'])) {
  612. $this->data['firstname'] = $this->request->post['firstname'];
  613. } elseif (isset($customer_info)) {
  614. $this->data['firstname'] = $customer_info['firstname'];
  615. } else {
  616. $this->data['firstname'] = '';
  617. }
  618. if (isset($this->request->post['lastname'])) {
  619. $this->data['lastname'] = $this->request->post['lastname'];
  620. } elseif (isset($customer_info)) {
  621. $this->data['lastname'] = $customer_info['lastname'];
  622. } else {
  623. $this->data['lastname'] = '';
  624. }
  625. if (isset($this->request->post['email'])) {
  626. $this->data['email'] = $this->request->post['email'];
  627. } elseif (isset($customer_info)) {
  628. $this->data['email'] = $customer_info['email'];
  629. } else {
  630. $this->data['email'] = '';
  631. }
  632. if (isset($this->request->post['telephone'])) {
  633. $this->data['telephone'] = $this->request->post['telephone'];
  634. } elseif (isset($customer_info)) {
  635. $this->data['telephone'] = $customer_info['telephone'];
  636. } else {
  637. $this->data['telephone'] = '';
  638. }
  639. if (isset($this->request->post['fax'])) {
  640. $this->data['fax'] = $this->request->post['fax'];
  641. } elseif (isset($customer_info)) {
  642. $this->data['fax'] = $customer_info['fax'];
  643. } else {
  644. $this->data['fax'] = '';
  645. }
  646. if (isset($this->request->post['newsletter'])) {
  647. $this->data['newsletter'] = $this->request->post['newsletter'];
  648. } elseif (isset($customer_info)) {
  649. $this->data['newsletter'] = $customer_info['newsletter'];
  650. } else {
  651. $this->data['newsletter'] = '';
  652. }
  653. $this->load->model('sale/customer_group');
  654. $this->data['customer_groups'] = $this->model_sale_customer_group->getCustomerGroups();
  655. if (isset($this->request->post['customer_group_id'])) {
  656. $this->data['customer_group_id'] = $this->request->post['customer_group_id'];
  657. } elseif (isset($customer_info)) {
  658. $this->data['customer_group_id'] = $customer_info['customer_group_id'];
  659. } else {
  660. $this->data['customer_group_id'] = $this->config->get('config_customer_group_id');
  661. }
  662. if (isset($this->request->post['status'])) {
  663. $this->data['status'] = $this->request->post['status'];
  664. } elseif (isset($customer_info)) {
  665. $this->data['status'] = $customer_info['status'];
  666. } else {
  667. $this->data['status'] = 1;
  668. }
  669. if (isset($this->request->post['password'])) {
  670. $this->data['password'] = $this->request->post['password'];
  671. } else {
  672. $this->data['password'] = '';
  673. }
  674. if (isset($this->request->post['confirm'])) {
  675. $this->data['confirm'] = $this->request->post['confirm'];
  676. } else {
  677. $this->data['confirm'] = '';
  678. }
  679. $this->load->model('localisation/country');
  680. $this->data['countries'] = $this->model_localisation_country->getCountries();
  681. if (isset($this->request->post['address'])) {
  682. $this->data['addresses'] = $this->request->post['address'];
  683. } elseif (isset($this->request->get['customer_id'])) {
  684. $this->data['addresses'] = $this->model_sale_customer->getAddresses($this->request->get['customer_id']);
  685. } else {
  686. $this->data['addresses'] = array();
  687. }
  688. $this->data['ips'] = array();
  689. if (!empty($customer_info)) {
  690. $results = $this->model_sale_customer->getIpsByCustomerId($this->request->get['customer_id']);
  691. foreach ($results as $result) {
  692. $this->data['ips'][] = array(
  693. 'ip' => $result['ip'],
  694. 'total' => $this->model_sale_customer->getTotalCustomersByIp($result['ip']),
  695. 'date_added' => date('d/m/y', strtotime($result['date_added'])),
  696. 'filter_ip' => HTTPS_SERVER . 'index.php?route=sale/customer&token=' . $this->session->data['token'] . '&filter_ip=' . $result['ip']
  697. );
  698. }
  699. }
  700. $this->template = 'sale/customer_form.tpl';
  701. $this->children = array(
  702. 'common/header',
  703. 'common/footer'
  704. );
  705. $this->response->setOutput($this->render());
  706. }
  707. private function validateForm() {
  708. if (!$this->user->hasPermission('modify', 'sale/customer')) {
  709. $this->error['warning'] = $this->language->get('error_permission');
  710. }
  711. if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
  712. $this->error['firstname'] = $this->language->get('error_firstname');
  713. }
  714. if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
  715. $this->error['lastname'] = $this->language->get('error_lastname');
  716. }
  717. if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
  718. $this->error['email'] = $this->language->get('error_email');
  719. }
  720. $customer_info = $this->model_sale_customer->getCustomerByEmail($this->request->post['email']);
  721. if (!isset($this->request->get['customer_id'])) {
  722. if ($customer_info) {
  723. $this->error['warning'] = $this->language->get('error_exists');
  724. }
  725. } else {
  726. if ($customer_info && ($this->request->get['customer_id'] != $customer_info['customer_id'])) {
  727. $this->error['warning'] = $this->language->get('error_exists');
  728. }
  729. }
  730. if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
  731. $this->error['telephone'] = $this->language->get('error_telephone');
  732. }
  733. if ($this->request->post['password'] || (!isset($this->request->get['customer_id']))) {
  734. if ((utf8_strlen($this->request->post['password']) < 4) || (utf8_strlen($this->request->post['password']) > 20)) {
  735. $this->error['password'] = $this->language->get('error_password');
  736. }
  737. if ($this->request->post['password'] != $this->request->post['confirm']) {
  738. $this->error['confirm'] = $this->language->get('error_confirm');
  739. }
  740. }
  741. if (isset($this->request->post['address'])) {
  742. foreach ($this->request->post['address'] as $key => $value) {
  743. if ((utf8_strlen($value['firstname']) < 1) || (utf8_strlen($value['firstname']) > 32)) {
  744. $this->error['address_firstname'][$key] = $this->language->get('error_firstname');
  745. }
  746. if ((utf8_strlen($value['lastname']) < 1) || (utf8_strlen($value['lastname']) > 32)) {
  747. $this->error['address_lastname'][$key] = $this->language->get('error_lastname');
  748. }
  749. if ((utf8_strlen($value['address_1']) < 3) || (utf8_strlen($value['address_1']) > 128)) {
  750. $this->error['address_address_1'][$key] = $this->language->get('error_address_1');
  751. }
  752. if ((utf8_strlen($value['city']) < 2) || (utf8_strlen($value['city']) > 128)) {
  753. $this->error['address_city'][$key] = $this->language->get('error_city');
  754. }
  755. $this->load->model('localisation/country');
  756. $country_info = $this->model_localisation_country->getCountry($value['country_id']);
  757. if ($country_info && $country_info['postcode_required'] && (utf8_strlen($value['postcode']) < 2) || (utf8_strlen($value['postcode']) > 10)) {
  758. $this->error['address_postcode'][$key] = $this->language->get('error_postcode');
  759. }
  760. if ($value['country_id'] == '') {
  761. $this->error['address_country'][$key] = $this->language->get('error_country');
  762. }
  763. if ($value['zone_id'] == '') {
  764. $this->error['address_zone'][$key] = $this->language->get('error_zone');
  765. }
  766. }
  767. }
  768. if ($this->error && !isset($this->error['warning'])) {
  769. $this->error['warning'] = $this->language->get('error_warning');
  770. }
  771. if (!$this->error) {
  772. return true;
  773. } else {
  774. return false;
  775. }
  776. }
  777. private function validateDelete() {
  778. if (!$this->user->hasPermission('modify', 'sale/customer')) {
  779. $this->error['warning'] = $this->language->get('error_permission');
  780. }
  781. if (!$this->error) {
  782. return true;
  783. } else {
  784. return false;
  785. }
  786. }
  787. public function login() {
  788. $json = array();
  789. if (isset($this->request->get['customer_id'])) {
  790. $customer_id = $this->request->get['customer_id'];
  791. } else {
  792. $customer_id = 0;
  793. }
  794. $this->load->model('sale/customer');
  795. $customer_info = $this->model_sale_customer->getCustomer($customer_id);
  796. if ($customer_info) {
  797. $token = md5(mt_rand());
  798. $this->model_sale_customer->editToken($customer_id, $token);
  799. if (isset($this->request->get['store_id'])) {
  800. $store_id = $this->request->get['store_id'];
  801. } else {
  802. $store_id = 0;
  803. }
  804. $this->load->model('setting/store');
  805. $store_info = $this->model_setting_store->getStore($store_id);
  806. if ($store_info) {
  807. $this->redirect($store_info['url'] . 'index.php?route=account/login&token=' . $token);
  808. } else {
  809. $this->redirect(HTTP_CATALOG . 'index.php?route=account/login&token=' . $token);
  810. }
  811. } else {
  812. $this->load->language('error/not_found');
  813. $this->document->setTitle($this->language->get('heading_title'));
  814. $this->data['heading_title'] = $this->language->get('heading_title');
  815. $this->data['text_not_found'] = $this->language->get('text_not_found');
  816. $this->data['breadcrumbs'] = array();
  817. $this->data['breadcrumbs'][] = array(
  818. 'text' => $this->language->get('text_home'),
  819. 'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
  820. 'separator' => false
  821. );
  822. $this->data['breadcrumbs'][] = array(
  823. 'text' => $this->language->get('heading_title'),
  824. 'href' => $this->url->link('error/not_found', 'token=' . $this->session->data['token'], 'SSL'),
  825. 'separator' => ' :: '
  826. );
  827. $this->template = 'error/not_found.tpl';
  828. $this->children = array(
  829. 'common/header',
  830. 'common/footer'
  831. );
  832. $this->response->setOutput($this->render());
  833. }
  834. }
  835. public function zone() {
  836. $output = '<option value="">' . $this->language->get('text_select') . '</option>';
  837. $this->load->model('localisation/zone');
  838. $results = $this->model_localisation_zone->getZonesByCountryId($this->request->get['country_id']);
  839. foreach ($results as $result) {
  840. $output .= '<option value="' . $result['zone_id'] . '"';
  841. if (isset($this->request->get['zone_id']) && ($this->request->get['zone_id'] == $result['zone_id'])) {
  842. $output .= ' selected="selected"';
  843. }
  844. $output .= '>' . $result['name'] . '</option>';
  845. }
  846. if (!$results) {
  847. $output .= '<option value="0">' . $this->language->get('text_none') . '</option>';
  848. }
  849. $this->response->setOutput($output);
  850. }
  851. public function transaction() {
  852. $this->language->load('sale/customer');
  853. $this->load->model('sale/customer');
  854. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
  855. $this->model_sale_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']);
  856. $this->data['success'] = $this->language->get('text_success');
  857. } else {
  858. $this->data['success'] = '';
  859. }
  860. if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
  861. $this->data['error_warning'] = $this->language->get('error_permission');
  862. } else {
  863. $this->data['error_warning'] = '';
  864. }
  865. $this->data['text_no_results'] = $this->language->get('text_no_results');
  866. $this->data['text_balance'] = $this->language->get('text_balance');
  867. $this->data['column_date_added'] = $this->language->get('column_date_added');
  868. $this->data['column_description'] = $this->language->get('column_description');
  869. $this->data['column_amount'] = $this->language->get('column_amount');
  870. if (isset($this->request->get['page'])) {
  871. $page = $this->request->get['page'];
  872. } else {
  873. $page = 1;
  874. }
  875. $this->data['transactions'] = array();
  876. $results = $this->model_sale_customer->getTransactions($this->request->get['customer_id'], ($page - 1) * 10, 10);
  877. foreach ($results as $result) {
  878. $this->data['transactions'][] = array(
  879. 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')),
  880. 'description' => $result['description'],
  881. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  882. );
  883. }
  884. $this->data['balance'] = $this->currency->format($this->model_sale_customer->getTransactionTotal($this->request->get['customer_id']), $this->config->get('config_currency'));
  885. $transaction_total = $this->model_sale_customer->getTotalTransactions($this->request->get['customer_id']);
  886. $pagination = new Pagination();
  887. $pagination->total = $transaction_total;
  888. $pagination->page = $page;
  889. $pagination->limit = 10;
  890. $pagination->text = $this->language->get('text_pagination');
  891. $pagination->url = $this->url->link('sale/customer/transaction', 'token=' . $this->session->data['token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', 'SSL');
  892. $this->data['pagination'] = $pagination->render();
  893. $this->template = 'sale/customer_transaction.tpl';
  894. $this->response->setOutput($this->render());
  895. }
  896. public function reward() {
  897. $this->language->load('sale/customer');
  898. $this->load->model('sale/customer');
  899. if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->user->hasPermission('modify', 'sale/customer')) {
  900. $this->model_sale_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']);
  901. $this->data['success'] = $this->language->get('text_success');
  902. } else {
  903. $this->data['success'] = '';
  904. }
  905. if (($this->request->server['REQUEST_METHOD'] == 'POST') && !$this->user->hasPermission('modify', 'sale/customer')) {
  906. $this->data['error_warning'] = $this->language->get('error_permission');
  907. } else {
  908. $this->data['error_warning'] = '';
  909. }
  910. $this->data['text_no_results'] = $this->language->get('text_no_results');
  911. $this->data['text_balance'] = $this->language->get('text_balance');
  912. $this->data['column_date_added'] = $this->language->get('column_date_added');
  913. $this->data['column_description'] = $this->language->get('column_description');
  914. $this->data['column_points'] = $this->language->get('column_points');
  915. if (isset($this->request->get['page'])) {
  916. $page = $this->request->get['page'];
  917. } else {
  918. $page = 1;
  919. }
  920. $this->data['rewards'] = array();
  921. $results = $this->model_sale_customer->getRewards($this->request->get['customer_id'], ($page - 1) * 10, 10);
  922. foreach ($results as $result) {
  923. $this->data['rewards'][] = array(
  924. 'points' => $result['points'],
  925. 'description' => $result['description'],
  926. 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added']))
  927. );
  928. }
  929. $this->data['balance'] = $this->model_sale_customer->getRewardTotal($this->request->get['customer_id']);
  930. $reward_total = $this->model_sale_customer->getTotalRewards($this->request->get['customer_id']);
  931. $pagination = new Pagination();
  932. $pagination->total = $reward_total;
  933. $pagination->page = $page;
  934. $pagination->limit = 10;
  935. $pagination->text = $this->language->get('text_pagination');
  936. $pagination->url = $this->url->link('sale/customer/reward', 'token=' . $this->session->data['token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', 'SSL');
  937. $this->data['pagination'] = $pagination->render();
  938. $this->template = 'sale/customer_reward.tpl';
  939. $this->response->setOutput($this->render());
  940. }
  941. public function autocomplete() {
  942. $json = array();
  943. if (isset($this->request->get['filter_name'])) {
  944. $this->load->model('sale/customer');
  945. $data = array(
  946. 'filter_name' => $this->request->get['filter_name'],
  947. 'start' => 0,
  948. 'limit' => 20
  949. );
  950. $results = $this->model_sale_customer->getCustomers($data);
  951. foreach ($results as $result) {
  952. $json[] = array(
  953. 'customer_id' => $result['customer_id'],
  954. 'name' => html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8'),
  955. 'customer_group' => $result['customer_group'],
  956. 'firstname' => $result['firstname'],
  957. 'lastname' => $result['lastname'],
  958. 'email' => $result['email'],
  959. 'telephone' => $result['telephone'],
  960. 'fax' => $result['fax'],
  961. 'address' => $this->model_sale_customer->getAddresses($result['customer_id'])
  962. );
  963. }
  964. }
  965. $sort_order = array();
  966. foreach ($json as $key => $value) {
  967. $sort_order[$key] = $value['name'];
  968. }
  969. array_multisort($sort_order, SORT_ASC, $json);
  970. $this->response->setOutput(json_encode($json));
  971. }
  972. public function address() {
  973. $json = array();
  974. if (isset($this->request->get['address_id']) && $this->request->get['address_id']) {
  975. $this->load->model('sale/customer');
  976. $json = $this->model_sale_customer->getAddress($this->request->get['address_id']);
  977. }
  978. $this->response->setOutput(json_encode($json));
  979. }
  980. }
  981. ?>