customer.php (54921B)
1 <?php 2 class ControllerCustomerCustomer extends Controller { 3 private $error = array(); 4 5 public function index() { 6 $this->load->language('customer/customer'); 7 8 $this->document->setTitle($this->language->get('heading_title')); 9 10 $this->load->model('customer/customer'); 11 12 $this->getList(); 13 } 14 15 public function add() { 16 $this->load->language('customer/customer'); 17 18 $this->document->setTitle($this->language->get('heading_title')); 19 20 $this->load->model('customer/customer'); 21 22 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 23 $this->model_customer_customer->addCustomer($this->request->post); 24 25 $this->session->data['success'] = $this->language->get('text_success'); 26 27 $url = ''; 28 29 if (isset($this->request->get['filter_name'])) { 30 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 31 } 32 33 if (isset($this->request->get['filter_email'])) { 34 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 35 } 36 37 if (isset($this->request->get['filter_customer_group_id'])) { 38 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 39 } 40 41 if (isset($this->request->get['filter_status'])) { 42 $url .= '&filter_status=' . $this->request->get['filter_status']; 43 } 44 45 if (isset($this->request->get['filter_ip'])) { 46 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 47 } 48 49 if (isset($this->request->get['filter_date_added'])) { 50 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 51 } 52 53 if (isset($this->request->get['sort'])) { 54 $url .= '&sort=' . $this->request->get['sort']; 55 } 56 57 if (isset($this->request->get['order'])) { 58 $url .= '&order=' . $this->request->get['order']; 59 } 60 61 if (isset($this->request->get['page'])) { 62 $url .= '&page=' . $this->request->get['page']; 63 } 64 65 $this->response->redirect($this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); 66 } 67 68 $this->getForm(); 69 } 70 71 public function edit() { 72 $this->load->language('customer/customer'); 73 74 $this->document->setTitle($this->language->get('heading_title')); 75 76 $this->load->model('customer/customer'); 77 78 if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) { 79 $this->model_customer_customer->editCustomer($this->request->get['customer_id'], $this->request->post); 80 81 $this->session->data['success'] = $this->language->get('text_success'); 82 83 $url = ''; 84 85 if (isset($this->request->get['filter_name'])) { 86 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 87 } 88 89 if (isset($this->request->get['filter_email'])) { 90 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 91 } 92 93 if (isset($this->request->get['filter_customer_group_id'])) { 94 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 95 } 96 97 if (isset($this->request->get['filter_status'])) { 98 $url .= '&filter_status=' . $this->request->get['filter_status']; 99 } 100 101 if (isset($this->request->get['filter_ip'])) { 102 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 103 } 104 105 if (isset($this->request->get['filter_date_added'])) { 106 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 107 } 108 109 if (isset($this->request->get['sort'])) { 110 $url .= '&sort=' . $this->request->get['sort']; 111 } 112 113 if (isset($this->request->get['order'])) { 114 $url .= '&order=' . $this->request->get['order']; 115 } 116 117 if (isset($this->request->get['page'])) { 118 $url .= '&page=' . $this->request->get['page']; 119 } 120 121 $this->response->redirect($this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); 122 } 123 124 $this->getForm(); 125 } 126 127 public function delete() { 128 $this->load->language('customer/customer'); 129 130 $this->document->setTitle($this->language->get('heading_title')); 131 132 $this->load->model('customer/customer'); 133 134 if (isset($this->request->post['selected']) && $this->validateDelete()) { 135 foreach ($this->request->post['selected'] as $customer_id) { 136 $this->model_customer_customer->deleteCustomer($customer_id); 137 } 138 139 $this->session->data['success'] = $this->language->get('text_success'); 140 141 $url = ''; 142 143 if (isset($this->request->get['filter_name'])) { 144 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 145 } 146 147 if (isset($this->request->get['filter_email'])) { 148 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 149 } 150 151 if (isset($this->request->get['filter_customer_group_id'])) { 152 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 153 } 154 155 if (isset($this->request->get['filter_status'])) { 156 $url .= '&filter_status=' . $this->request->get['filter_status']; 157 } 158 159 if (isset($this->request->get['filter_ip'])) { 160 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 161 } 162 163 if (isset($this->request->get['filter_date_added'])) { 164 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 165 } 166 167 if (isset($this->request->get['sort'])) { 168 $url .= '&sort=' . $this->request->get['sort']; 169 } 170 171 if (isset($this->request->get['order'])) { 172 $url .= '&order=' . $this->request->get['order']; 173 } 174 175 if (isset($this->request->get['page'])) { 176 $url .= '&page=' . $this->request->get['page']; 177 } 178 179 $this->response->redirect($this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); 180 } 181 182 $this->getList(); 183 } 184 185 public function unlock() { 186 $this->load->language('customer/customer'); 187 188 $this->document->setTitle($this->language->get('heading_title')); 189 190 $this->load->model('customer/customer'); 191 192 if (isset($this->request->get['email']) && $this->validateUnlock()) { 193 $this->model_customer_customer->deleteLoginAttempts($this->request->get['email']); 194 195 $this->session->data['success'] = $this->language->get('text_success'); 196 197 $url = ''; 198 199 if (isset($this->request->get['filter_name'])) { 200 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 201 } 202 203 if (isset($this->request->get['filter_email'])) { 204 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 205 } 206 207 if (isset($this->request->get['filter_customer_group_id'])) { 208 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 209 } 210 211 if (isset($this->request->get['filter_status'])) { 212 $url .= '&filter_status=' . $this->request->get['filter_status']; 213 } 214 215 if (isset($this->request->get['filter_ip'])) { 216 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 217 } 218 219 if (isset($this->request->get['filter_date_added'])) { 220 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 221 } 222 223 if (isset($this->request->get['sort'])) { 224 $url .= '&sort=' . $this->request->get['sort']; 225 } 226 227 if (isset($this->request->get['order'])) { 228 $url .= '&order=' . $this->request->get['order']; 229 } 230 231 if (isset($this->request->get['page'])) { 232 $url .= '&page=' . $this->request->get['page']; 233 } 234 235 $this->response->redirect($this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true)); 236 } 237 238 $this->getList(); 239 } 240 241 protected function getList() { 242 if (isset($this->request->get['filter_name'])) { 243 $filter_name = $this->request->get['filter_name']; 244 } else { 245 $filter_name = ''; 246 } 247 248 if (isset($this->request->get['filter_email'])) { 249 $filter_email = $this->request->get['filter_email']; 250 } else { 251 $filter_email = ''; 252 } 253 254 if (isset($this->request->get['filter_customer_group_id'])) { 255 $filter_customer_group_id = $this->request->get['filter_customer_group_id']; 256 } else { 257 $filter_customer_group_id = ''; 258 } 259 260 if (isset($this->request->get['filter_status'])) { 261 $filter_status = $this->request->get['filter_status']; 262 } else { 263 $filter_status = ''; 264 } 265 266 if (isset($this->request->get['filter_ip'])) { 267 $filter_ip = $this->request->get['filter_ip']; 268 } else { 269 $filter_ip = ''; 270 } 271 272 if (isset($this->request->get['filter_date_added'])) { 273 $filter_date_added = $this->request->get['filter_date_added']; 274 } else { 275 $filter_date_added = ''; 276 } 277 278 if (isset($this->request->get['sort'])) { 279 $sort = $this->request->get['sort']; 280 } else { 281 $sort = 'name'; 282 } 283 284 if (isset($this->request->get['order'])) { 285 $order = $this->request->get['order']; 286 } else { 287 $order = 'ASC'; 288 } 289 290 if (isset($this->request->get['page'])) { 291 $page = $this->request->get['page']; 292 } else { 293 $page = 1; 294 } 295 296 $url = ''; 297 298 if (isset($this->request->get['filter_name'])) { 299 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 300 } 301 302 if (isset($this->request->get['filter_email'])) { 303 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 304 } 305 306 if (isset($this->request->get['filter_customer_group_id'])) { 307 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 308 } 309 310 if (isset($this->request->get['filter_status'])) { 311 $url .= '&filter_status=' . $this->request->get['filter_status']; 312 } 313 314 if (isset($this->request->get['filter_ip'])) { 315 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 316 } 317 318 if (isset($this->request->get['filter_date_added'])) { 319 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 320 } 321 322 if (isset($this->request->get['sort'])) { 323 $url .= '&sort=' . $this->request->get['sort']; 324 } 325 326 if (isset($this->request->get['order'])) { 327 $url .= '&order=' . $this->request->get['order']; 328 } 329 330 if (isset($this->request->get['page'])) { 331 $url .= '&page=' . $this->request->get['page']; 332 } 333 334 $data['breadcrumbs'] = array(); 335 336 $data['breadcrumbs'][] = array( 337 'text' => $this->language->get('text_home'), 338 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 339 ); 340 341 $data['breadcrumbs'][] = array( 342 'text' => $this->language->get('heading_title'), 343 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true) 344 ); 345 346 $data['add'] = $this->url->link('customer/customer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 347 $data['delete'] = $this->url->link('customer/customer/delete', 'user_token=' . $this->session->data['user_token'] . $url, true); 348 349 $this->load->model('setting/store'); 350 351 $stores = $this->model_setting_store->getStores(); 352 353 $data['customers'] = array(); 354 355 $filter_data = array( 356 'filter_name' => $filter_name, 357 'filter_email' => $filter_email, 358 'filter_customer_group_id' => $filter_customer_group_id, 359 'filter_status' => $filter_status, 360 'filter_date_added' => $filter_date_added, 361 'filter_ip' => $filter_ip, 362 'sort' => $sort, 363 'order' => $order, 364 'start' => ($page - 1) * $this->config->get('config_limit_admin'), 365 'limit' => $this->config->get('config_limit_admin') 366 ); 367 368 $customer_total = $this->model_customer_customer->getTotalCustomers($filter_data); 369 370 $results = $this->model_customer_customer->getCustomers($filter_data); 371 372 foreach ($results as $result) { 373 $login_info = $this->model_customer_customer->getTotalLoginAttempts($result['email']); 374 375 if ($login_info && $login_info['total'] >= $this->config->get('config_login_attempts')) { 376 $unlock = $this->url->link('customer/customer/unlock', 'user_token=' . $this->session->data['user_token'] . '&email=' . $result['email'] . $url, true); 377 } else { 378 $unlock = ''; 379 } 380 381 $store_data = array(); 382 383 $store_data[] = array( 384 'name' => $this->config->get('config_name'), 385 'href' => $this->url->link('customer/customer/login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=0', true) 386 ); 387 388 foreach ($stores as $store) { 389 $store_data[] = array( 390 'name' => $store['name'], 391 'href' => $this->url->link('customer/customer/login', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . '&store_id=' . $result['store_id'], true) 392 ); 393 } 394 395 $data['customers'][] = array( 396 'customer_id' => $result['customer_id'], 397 'name' => $result['name'], 398 'email' => $result['email'], 399 'customer_group' => $result['customer_group'], 400 'status' => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')), 401 'ip' => $result['ip'], 402 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])), 403 'unlock' => $unlock, 404 'store' => $store_data, 405 'edit' => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . $url, true) 406 ); 407 } 408 409 $data['user_token'] = $this->session->data['user_token']; 410 411 if (isset($this->error['warning'])) { 412 $data['error_warning'] = $this->error['warning']; 413 } else { 414 $data['error_warning'] = ''; 415 } 416 417 if (isset($this->session->data['success'])) { 418 $data['success'] = $this->session->data['success']; 419 420 unset($this->session->data['success']); 421 } else { 422 $data['success'] = ''; 423 } 424 425 if (isset($this->request->post['selected'])) { 426 $data['selected'] = (array)$this->request->post['selected']; 427 } else { 428 $data['selected'] = array(); 429 } 430 431 $url = ''; 432 433 if (isset($this->request->get['filter_name'])) { 434 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 435 } 436 437 if (isset($this->request->get['filter_email'])) { 438 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 439 } 440 441 if (isset($this->request->get['filter_customer_group_id'])) { 442 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 443 } 444 445 if (isset($this->request->get['filter_status'])) { 446 $url .= '&filter_status=' . $this->request->get['filter_status']; 447 } 448 449 if (isset($this->request->get['filter_ip'])) { 450 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 451 } 452 453 if (isset($this->request->get['filter_date_added'])) { 454 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 455 } 456 457 if ($order == 'ASC') { 458 $url .= '&order=DESC'; 459 } else { 460 $url .= '&order=ASC'; 461 } 462 463 if (isset($this->request->get['page'])) { 464 $url .= '&page=' . $this->request->get['page']; 465 } 466 467 $data['sort_name'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true); 468 $data['sort_email'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.email' . $url, true); 469 $data['sort_customer_group'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=customer_group' . $url, true); 470 $data['sort_status'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.status' . $url, true); 471 $data['sort_ip'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.ip' . $url, true); 472 $data['sort_date_added'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.date_added' . $url, true); 473 474 $url = ''; 475 476 if (isset($this->request->get['filter_name'])) { 477 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 478 } 479 480 if (isset($this->request->get['filter_email'])) { 481 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 482 } 483 484 if (isset($this->request->get['filter_customer_group_id'])) { 485 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 486 } 487 488 if (isset($this->request->get['filter_status'])) { 489 $url .= '&filter_status=' . $this->request->get['filter_status']; 490 } 491 492 if (isset($this->request->get['filter_ip'])) { 493 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 494 } 495 496 if (isset($this->request->get['filter_date_added'])) { 497 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 498 } 499 500 if (isset($this->request->get['sort'])) { 501 $url .= '&sort=' . $this->request->get['sort']; 502 } 503 504 if (isset($this->request->get['order'])) { 505 $url .= '&order=' . $this->request->get['order']; 506 } 507 508 $pagination = new Pagination(); 509 $pagination->total = $customer_total; 510 $pagination->page = $page; 511 $pagination->limit = $this->config->get('config_limit_admin'); 512 $pagination->url = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true); 513 514 $data['pagination'] = $pagination->render(); 515 516 $data['results'] = sprintf($this->language->get('text_pagination'), ($customer_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($customer_total - $this->config->get('config_limit_admin'))) ? $customer_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_total, ceil($customer_total / $this->config->get('config_limit_admin'))); 517 518 $data['filter_name'] = $filter_name; 519 $data['filter_email'] = $filter_email; 520 $data['filter_customer_group_id'] = $filter_customer_group_id; 521 $data['filter_status'] = $filter_status; 522 $data['filter_ip'] = $filter_ip; 523 $data['filter_date_added'] = $filter_date_added; 524 525 $this->load->model('customer/customer_group'); 526 527 $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); 528 529 $data['sort'] = $sort; 530 $data['order'] = $order; 531 532 $data['header'] = $this->load->controller('common/header'); 533 $data['column_left'] = $this->load->controller('common/column_left'); 534 $data['footer'] = $this->load->controller('common/footer'); 535 536 $this->response->setOutput($this->load->view('customer/customer_list', $data)); 537 } 538 539 protected function getForm() { 540 $data['text_form'] = !isset($this->request->get['customer_id']) ? $this->language->get('text_add') : $this->language->get('text_edit'); 541 542 $data['user_token'] = $this->session->data['user_token']; 543 544 if (isset($this->request->get['customer_id'])) { 545 $data['customer_id'] = $this->request->get['customer_id']; 546 } else { 547 $data['customer_id'] = 0; 548 } 549 550 if (isset($this->error['warning'])) { 551 $data['error_warning'] = $this->error['warning']; 552 } else { 553 $data['error_warning'] = ''; 554 } 555 556 if (isset($this->error['firstname'])) { 557 $data['error_firstname'] = $this->error['firstname']; 558 } else { 559 $data['error_firstname'] = ''; 560 } 561 562 if (isset($this->error['lastname'])) { 563 $data['error_lastname'] = $this->error['lastname']; 564 } else { 565 $data['error_lastname'] = ''; 566 } 567 568 if (isset($this->error['email'])) { 569 $data['error_email'] = $this->error['email']; 570 } else { 571 $data['error_email'] = ''; 572 } 573 574 if (isset($this->error['telephone'])) { 575 $data['error_telephone'] = $this->error['telephone']; 576 } else { 577 $data['error_telephone'] = ''; 578 } 579 580 if (isset($this->error['cheque'])) { 581 $data['error_cheque'] = $this->error['cheque']; 582 } else { 583 $data['error_cheque'] = ''; 584 } 585 586 if (isset($this->error['paypal'])) { 587 $data['error_paypal'] = $this->error['paypal']; 588 } else { 589 $data['error_paypal'] = ''; 590 } 591 592 if (isset($this->error['bank_account_name'])) { 593 $data['error_bank_account_name'] = $this->error['bank_account_name']; 594 } else { 595 $data['error_bank_account_name'] = ''; 596 } 597 598 if (isset($this->error['bank_account_number'])) { 599 $data['error_bank_account_number'] = $this->error['bank_account_number']; 600 } else { 601 $data['error_bank_account_number'] = ''; 602 } 603 604 if (isset($this->error['password'])) { 605 $data['error_password'] = $this->error['password']; 606 } else { 607 $data['error_password'] = ''; 608 } 609 610 if (isset($this->error['confirm'])) { 611 $data['error_confirm'] = $this->error['confirm']; 612 } else { 613 $data['error_confirm'] = ''; 614 } 615 616 if (isset($this->error['custom_field'])) { 617 $data['error_custom_field'] = $this->error['custom_field']; 618 } else { 619 $data['error_custom_field'] = array(); 620 } 621 622 if (isset($this->error['address'])) { 623 $data['error_address'] = $this->error['address']; 624 } else { 625 $data['error_address'] = array(); 626 } 627 628 $url = ''; 629 630 if (isset($this->request->get['filter_name'])) { 631 $url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8')); 632 } 633 634 if (isset($this->request->get['filter_email'])) { 635 $url .= '&filter_email=' . urlencode(html_entity_decode($this->request->get['filter_email'], ENT_QUOTES, 'UTF-8')); 636 } 637 638 if (isset($this->request->get['filter_customer_group_id'])) { 639 $url .= '&filter_customer_group_id=' . $this->request->get['filter_customer_group_id']; 640 } 641 642 if (isset($this->request->get['filter_status'])) { 643 $url .= '&filter_status=' . $this->request->get['filter_status']; 644 } 645 646 if (isset($this->request->get['filter_ip'])) { 647 $url .= '&filter_ip=' . $this->request->get['filter_ip']; 648 } 649 650 if (isset($this->request->get['filter_date_added'])) { 651 $url .= '&filter_date_added=' . $this->request->get['filter_date_added']; 652 } 653 654 if (isset($this->request->get['sort'])) { 655 $url .= '&sort=' . $this->request->get['sort']; 656 } 657 658 if (isset($this->request->get['order'])) { 659 $url .= '&order=' . $this->request->get['order']; 660 } 661 662 if (isset($this->request->get['page'])) { 663 $url .= '&page=' . $this->request->get['page']; 664 } 665 666 $data['breadcrumbs'] = array(); 667 668 $data['breadcrumbs'][] = array( 669 'text' => $this->language->get('text_home'), 670 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 671 ); 672 673 $data['breadcrumbs'][] = array( 674 'text' => $this->language->get('heading_title'), 675 'href' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true) 676 ); 677 678 if (!isset($this->request->get['customer_id'])) { 679 $data['action'] = $this->url->link('customer/customer/add', 'user_token=' . $this->session->data['user_token'] . $url, true); 680 } else { 681 $data['action'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . $url, true); 682 } 683 684 $data['cancel'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . $url, true); 685 686 if (isset($this->request->get['customer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { 687 $customer_info = $this->model_customer_customer->getCustomer($this->request->get['customer_id']); 688 } 689 690 $this->load->model('customer/customer_group'); 691 692 $data['customer_groups'] = $this->model_customer_customer_group->getCustomerGroups(); 693 694 if (isset($this->request->post['customer_group_id'])) { 695 $data['customer_group_id'] = $this->request->post['customer_group_id']; 696 } elseif (!empty($customer_info)) { 697 $data['customer_group_id'] = $customer_info['customer_group_id']; 698 } else { 699 $data['customer_group_id'] = $this->config->get('config_customer_group_id'); 700 } 701 702 if (isset($this->request->post['firstname'])) { 703 $data['firstname'] = $this->request->post['firstname']; 704 } elseif (!empty($customer_info)) { 705 $data['firstname'] = $customer_info['firstname']; 706 } else { 707 $data['firstname'] = ''; 708 } 709 710 if (isset($this->request->post['lastname'])) { 711 $data['lastname'] = $this->request->post['lastname']; 712 } elseif (!empty($customer_info)) { 713 $data['lastname'] = $customer_info['lastname']; 714 } else { 715 $data['lastname'] = ''; 716 } 717 718 if (isset($this->request->post['email'])) { 719 $data['email'] = $this->request->post['email']; 720 } elseif (!empty($customer_info)) { 721 $data['email'] = $customer_info['email']; 722 } else { 723 $data['email'] = ''; 724 } 725 726 if (isset($this->request->post['telephone'])) { 727 $data['telephone'] = $this->request->post['telephone']; 728 } elseif (!empty($customer_info)) { 729 $data['telephone'] = $customer_info['telephone']; 730 } else { 731 $data['telephone'] = ''; 732 } 733 734 // Custom Fields 735 $this->load->model('customer/custom_field'); 736 737 $data['custom_fields'] = array(); 738 739 $filter_data = array( 740 'sort' => 'cf.sort_order', 741 'order' => 'ASC' 742 ); 743 744 $custom_fields = $this->model_customer_custom_field->getCustomFields($filter_data); 745 746 foreach ($custom_fields as $custom_field) { 747 $data['custom_fields'][] = array( 748 'custom_field_id' => $custom_field['custom_field_id'], 749 'custom_field_value' => $this->model_customer_custom_field->getCustomFieldValues($custom_field['custom_field_id']), 750 'name' => $custom_field['name'], 751 'value' => $custom_field['value'], 752 'type' => $custom_field['type'], 753 'location' => $custom_field['location'], 754 'sort_order' => $custom_field['sort_order'] 755 ); 756 } 757 758 if (isset($this->request->post['custom_field'])) { 759 $data['account_custom_field'] = $this->request->post['custom_field']; 760 } elseif (!empty($customer_info)) { 761 $data['account_custom_field'] = json_decode($customer_info['custom_field'], true); 762 } else { 763 $data['account_custom_field'] = array(); 764 } 765 766 if (isset($this->request->post['newsletter'])) { 767 $data['newsletter'] = $this->request->post['newsletter']; 768 } elseif (!empty($customer_info)) { 769 $data['newsletter'] = $customer_info['newsletter']; 770 } else { 771 $data['newsletter'] = ''; 772 } 773 774 if (isset($this->request->post['status'])) { 775 $data['status'] = $this->request->post['status']; 776 } elseif (!empty($customer_info)) { 777 $data['status'] = $customer_info['status']; 778 } else { 779 $data['status'] = true; 780 } 781 782 if (isset($this->request->post['safe'])) { 783 $data['safe'] = $this->request->post['safe']; 784 } elseif (!empty($customer_info)) { 785 $data['safe'] = $customer_info['safe']; 786 } else { 787 $data['safe'] = 0; 788 } 789 790 if (isset($this->request->post['password'])) { 791 $data['password'] = $this->request->post['password']; 792 } else { 793 $data['password'] = ''; 794 } 795 796 if (isset($this->request->post['confirm'])) { 797 $data['confirm'] = $this->request->post['confirm']; 798 } else { 799 $data['confirm'] = ''; 800 } 801 802 $this->load->model('localisation/country'); 803 804 $data['countries'] = $this->model_localisation_country->getCountries(); 805 806 if (isset($this->request->post['address'])) { 807 $data['addresses'] = $this->request->post['address']; 808 } elseif (isset($this->request->get['customer_id'])) { 809 $data['addresses'] = $this->model_customer_customer->getAddresses($this->request->get['customer_id']); 810 } else { 811 $data['addresses'] = array(); 812 } 813 814 if (isset($this->request->post['address_id'])) { 815 $data['address_id'] = $this->request->post['address_id']; 816 } elseif (!empty($customer_info)) { 817 $data['address_id'] = $customer_info['address_id']; 818 } else { 819 $data['address_id'] = ''; 820 } 821 822 // Affliate 823 if (isset($this->request->get['customer_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) { 824 $affiliate_info = $this->model_customer_customer->getAffiliate($this->request->get['customer_id']); 825 } 826 827 if (isset($this->request->post['affiliate'])) { 828 $data['affiliate'] = $this->request->post['affiliate']; 829 } elseif (!empty($affiliate_info)) { 830 $data['affiliate'] = $affiliate_info['status']; 831 } else { 832 $data['affiliate'] = ''; 833 } 834 835 if (isset($this->request->post['company'])) { 836 $data['company'] = $this->request->post['company']; 837 } elseif (!empty($affiliate_info)) { 838 $data['company'] = $affiliate_info['company']; 839 } else { 840 $data['company'] = ''; 841 } 842 843 if (isset($this->request->post['website'])) { 844 $data['website'] = $this->request->post['website']; 845 } elseif (!empty($affiliate_info)) { 846 $data['website'] = $affiliate_info['website']; 847 } else { 848 $data['website'] = ''; 849 } 850 851 if (isset($this->request->post['tracking'])) { 852 $data['tracking'] = $this->request->post['tracking']; 853 } elseif (!empty($affiliate_info)) { 854 $data['tracking'] = $affiliate_info['tracking']; 855 } else { 856 $data['tracking'] = ''; 857 } 858 859 if (isset($this->request->post['commission'])) { 860 $data['commission'] = $this->request->post['commission']; 861 } elseif (!empty($affiliate_info)) { 862 $data['commission'] = $affiliate_info['commission']; 863 } else { 864 $data['commission'] = $this->config->get('config_affiliate_commission'); 865 } 866 867 if (isset($this->request->post['tax'])) { 868 $data['tax'] = $this->request->post['tax']; 869 } elseif (!empty($affiliate_info)) { 870 $data['tax'] = $affiliate_info['tax']; 871 } else { 872 $data['tax'] = ''; 873 } 874 875 if (isset($this->request->post['payment'])) { 876 $data['payment'] = $this->request->post['payment']; 877 } elseif (!empty($affiliate_info)) { 878 $data['payment'] = $affiliate_info['payment']; 879 } else { 880 $data['payment'] = 'cheque'; 881 } 882 883 if (isset($this->request->post['cheque'])) { 884 $data['cheque'] = $this->request->post['cheque']; 885 } elseif (!empty($affiliate_info)) { 886 $data['cheque'] = $affiliate_info['cheque']; 887 } else { 888 $data['cheque'] = ''; 889 } 890 891 if (isset($this->request->post['paypal'])) { 892 $data['paypal'] = $this->request->post['paypal']; 893 } elseif (!empty($affiliate_info)) { 894 $data['paypal'] = $affiliate_info['paypal']; 895 } else { 896 $data['paypal'] = ''; 897 } 898 899 if (isset($this->request->post['bank_name'])) { 900 $data['bank_name'] = $this->request->post['bank_name']; 901 } elseif (!empty($affiliate_info)) { 902 $data['bank_name'] = $affiliate_info['bank_name']; 903 } else { 904 $data['bank_name'] = ''; 905 } 906 907 if (isset($this->request->post['bank_branch_number'])) { 908 $data['bank_branch_number'] = $this->request->post['bank_branch_number']; 909 } elseif (!empty($affiliate_info)) { 910 $data['bank_branch_number'] = $affiliate_info['bank_branch_number']; 911 } else { 912 $data['bank_branch_number'] = ''; 913 } 914 915 if (isset($this->request->post['bank_swift_code'])) { 916 $data['bank_swift_code'] = $this->request->post['bank_swift_code']; 917 } elseif (!empty($affiliate_info)) { 918 $data['bank_swift_code'] = $affiliate_info['bank_swift_code']; 919 } else { 920 $data['bank_swift_code'] = ''; 921 } 922 923 if (isset($this->request->post['bank_account_name'])) { 924 $data['bank_account_name'] = $this->request->post['bank_account_name']; 925 } elseif (!empty($affiliate_info)) { 926 $data['bank_account_name'] = $affiliate_info['bank_account_name']; 927 } else { 928 $data['bank_account_name'] = ''; 929 } 930 931 if (isset($this->request->post['bank_account_number'])) { 932 $data['bank_account_number'] = $this->request->post['bank_account_number']; 933 } elseif (!empty($affiliate_info)) { 934 $data['bank_account_number'] = $affiliate_info['bank_account_number']; 935 } else { 936 $data['bank_account_number'] = ''; 937 } 938 939 if (isset($this->request->post['custom_field'])) { 940 $data['affiliate_custom_field'] = $this->request->post['custom_field']; 941 } elseif (!empty($affiliate_info)) { 942 $data['affiliate_custom_field'] = json_decode($affiliate_info['custom_field'], true); 943 } else { 944 $data['affiliate_custom_field'] = array(); 945 } 946 947 $data['header'] = $this->load->controller('common/header'); 948 $data['column_left'] = $this->load->controller('common/column_left'); 949 $data['footer'] = $this->load->controller('common/footer'); 950 951 $this->response->setOutput($this->load->view('customer/customer_form', $data)); 952 } 953 954 protected function validateForm() { 955 if (!$this->user->hasPermission('modify', 'customer/customer')) { 956 $this->error['warning'] = $this->language->get('error_permission'); 957 } 958 959 if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) { 960 $this->error['firstname'] = $this->language->get('error_firstname'); 961 } 962 963 if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) { 964 $this->error['lastname'] = $this->language->get('error_lastname'); 965 } 966 967 if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) { 968 $this->error['email'] = $this->language->get('error_email'); 969 } 970 971 $customer_info = $this->model_customer_customer->getCustomerByEmail($this->request->post['email']); 972 973 if (!isset($this->request->get['customer_id'])) { 974 if ($customer_info) { 975 $this->error['warning'] = $this->language->get('error_exists'); 976 } 977 } else { 978 if ($customer_info && ($this->request->get['customer_id'] != $customer_info['customer_id'])) { 979 $this->error['warning'] = $this->language->get('error_exists'); 980 } 981 } 982 983 if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) { 984 $this->error['telephone'] = $this->language->get('error_telephone'); 985 } 986 987 // Custom field validation 988 $this->load->model('customer/custom_field'); 989 990 $custom_fields = $this->model_customer_custom_field->getCustomFields(array('filter_customer_group_id' => $this->request->post['customer_group_id'])); 991 992 foreach ($custom_fields as $custom_field) { 993 if (($custom_field['location'] == 'account') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { 994 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 995 } elseif (($custom_field['location'] == 'account') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { 996 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 997 } 998 } 999 1000 if ($this->request->post['password'] || (!isset($this->request->get['customer_id']))) { 1001 if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) { 1002 $this->error['password'] = $this->language->get('error_password'); 1003 } 1004 1005 if ($this->request->post['password'] != $this->request->post['confirm']) { 1006 $this->error['confirm'] = $this->language->get('error_confirm'); 1007 } 1008 } 1009 1010 if (isset($this->request->post['address'])) { 1011 foreach ($this->request->post['address'] as $key => $value) { 1012 if ((utf8_strlen($value['firstname']) < 1) || (utf8_strlen($value['firstname']) > 32)) { 1013 $this->error['address'][$key]['firstname'] = $this->language->get('error_firstname'); 1014 } 1015 1016 if ((utf8_strlen($value['lastname']) < 1) || (utf8_strlen($value['lastname']) > 32)) { 1017 $this->error['address'][$key]['lastname'] = $this->language->get('error_lastname'); 1018 } 1019 1020 if ((utf8_strlen($value['address_1']) < 3) || (utf8_strlen($value['address_1']) > 128)) { 1021 $this->error['address'][$key]['address_1'] = $this->language->get('error_address_1'); 1022 } 1023 1024 if ((utf8_strlen($value['city']) < 2) || (utf8_strlen($value['city']) > 128)) { 1025 $this->error['address'][$key]['city'] = $this->language->get('error_city'); 1026 } 1027 1028 $this->load->model('localisation/country'); 1029 1030 $country_info = $this->model_localisation_country->getCountry($value['country_id']); 1031 1032 if ($country_info && $country_info['postcode_required'] && (utf8_strlen($value['postcode']) < 2 || utf8_strlen($value['postcode']) > 10)) { 1033 $this->error['address'][$key]['postcode'] = $this->language->get('error_postcode'); 1034 } 1035 1036 if ($value['country_id'] == '') { 1037 $this->error['address'][$key]['country'] = $this->language->get('error_country'); 1038 } 1039 1040 if (!isset($value['zone_id']) || $value['zone_id'] == '') { 1041 $this->error['address'][$key]['zone'] = $this->language->get('error_zone'); 1042 } 1043 1044 foreach ($custom_fields as $custom_field) { 1045 if (($custom_field['location'] == 'address') && $custom_field['required'] && empty($value['custom_field'][$custom_field['custom_field_id']])) { 1046 $this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 1047 } elseif (($custom_field['location'] == 'address') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($value['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { 1048 $this->error['address'][$key]['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 1049 } 1050 } 1051 } 1052 } 1053 1054 if ($this->request->post['affiliate']) { 1055 if ($this->request->post['payment'] == 'cheque') { 1056 if ($this->request->post['cheque'] == '') { 1057 $this->error['cheque'] = $this->language->get('error_cheque'); 1058 } 1059 } elseif ($this->request->post['payment'] == 'paypal') { 1060 if ((utf8_strlen($this->request->post['paypal']) > 96) || !filter_var($this->request->post['paypal'], FILTER_VALIDATE_EMAIL)) { 1061 $this->error['paypal'] = $this->language->get('error_paypal'); 1062 } 1063 } elseif ($this->request->post['payment'] == 'bank') { 1064 if ($this->request->post['bank_account_name'] == '') { 1065 $this->error['bank_account_name'] = $this->language->get('error_bank_account_name'); 1066 } 1067 1068 if ($this->request->post['bank_account_number'] == '') { 1069 $this->error['bank_account_number'] = $this->language->get('error_bank_account_number'); 1070 } 1071 } 1072 1073 if (!$this->request->post['tracking']) { 1074 $this->error['tracking'] = $this->language->get('error_tracking'); 1075 } 1076 1077 $affiliate_info = $this->model_customer_customer->getAffliateByTracking($this->request->post['tracking']); 1078 1079 if (!isset($this->request->get['customer_id'])) { 1080 if ($affiliate_info) { 1081 $this->error['tracking'] = $this->language->get('error_tracking_exists'); 1082 } 1083 } else { 1084 if ($affiliate_info && ($this->request->get['customer_id'] != $affiliate_info['customer_id'])) { 1085 $this->error['tracking'] = $this->language->get('error_tracking_exists'); 1086 } 1087 } 1088 1089 foreach ($custom_fields as $custom_field) { 1090 if (($custom_field['location'] == 'affiliate') && $custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['custom_field_id']])) { 1091 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 1092 } elseif (($custom_field['location'] == 'affiliate') && ($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) { 1093 $this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']); 1094 } 1095 } 1096 } 1097 1098 if ($this->error && !isset($this->error['warning'])) { 1099 $this->error['warning'] = $this->language->get('error_warning'); 1100 } 1101 1102 return !$this->error; 1103 } 1104 1105 protected function validateDelete() { 1106 if (!$this->user->hasPermission('modify', 'customer/customer')) { 1107 $this->error['warning'] = $this->language->get('error_permission'); 1108 } 1109 1110 return !$this->error; 1111 } 1112 1113 protected function validateUnlock() { 1114 if (!$this->user->hasPermission('modify', 'customer/customer')) { 1115 $this->error['warning'] = $this->language->get('error_permission'); 1116 } 1117 1118 return !$this->error; 1119 } 1120 1121 public function login() { 1122 if (isset($this->request->get['customer_id'])) { 1123 $customer_id = $this->request->get['customer_id']; 1124 } else { 1125 $customer_id = 0; 1126 } 1127 1128 $this->load->model('customer/customer'); 1129 1130 $customer_info = $this->model_customer_customer->getCustomer($customer_id); 1131 1132 if ($customer_info) { 1133 // Create token to login with 1134 $token = token(64); 1135 1136 $this->model_customer_customer->editToken($customer_id, $token); 1137 1138 if (isset($this->request->get['store_id'])) { 1139 $store_id = $this->request->get['store_id']; 1140 } else { 1141 $store_id = 0; 1142 } 1143 1144 $this->load->model('setting/store'); 1145 1146 $store_info = $this->model_setting_store->getStore($store_id); 1147 1148 if ($store_info) { 1149 $this->response->redirect($store_info['url'] . 'index.php?route=account/login&token=' . $token); 1150 } else { 1151 $this->response->redirect(HTTP_CATALOG . 'index.php?route=account/login&token=' . $token); 1152 } 1153 } else { 1154 $this->load->language('error/not_found'); 1155 1156 $this->document->setTitle($this->language->get('heading_title')); 1157 1158 $data['breadcrumbs'] = array(); 1159 1160 $data['breadcrumbs'][] = array( 1161 'text' => $this->language->get('text_home'), 1162 'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true) 1163 ); 1164 1165 $data['breadcrumbs'][] = array( 1166 'text' => $this->language->get('heading_title'), 1167 'href' => $this->url->link('error/not_found', 'user_token=' . $this->session->data['user_token'], true) 1168 ); 1169 1170 $data['header'] = $this->load->controller('common/header'); 1171 $data['column_left'] = $this->load->controller('common/column_left'); 1172 $data['footer'] = $this->load->controller('common/footer'); 1173 1174 $this->response->setOutput($this->load->view('error/not_found', $data)); 1175 } 1176 } 1177 1178 public function history() { 1179 $this->load->language('customer/customer'); 1180 1181 $this->load->model('customer/customer'); 1182 1183 if (isset($this->request->get['page'])) { 1184 $page = $this->request->get['page']; 1185 } else { 1186 $page = 1; 1187 } 1188 1189 $data['histories'] = array(); 1190 1191 $results = $this->model_customer_customer->getHistories($this->request->get['customer_id'], ($page - 1) * 10, 10); 1192 1193 foreach ($results as $result) { 1194 $data['histories'][] = array( 1195 'comment' => $result['comment'], 1196 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) 1197 ); 1198 } 1199 1200 $history_total = $this->model_customer_customer->getTotalHistories($this->request->get['customer_id']); 1201 1202 $pagination = new Pagination(); 1203 $pagination->total = $history_total; 1204 $pagination->page = $page; 1205 $pagination->limit = 10; 1206 $pagination->url = $this->url->link('customer/customer/history', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); 1207 1208 $data['pagination'] = $pagination->render(); 1209 1210 $data['results'] = sprintf($this->language->get('text_pagination'), ($history_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($history_total - 10)) ? $history_total : ((($page - 1) * 10) + 10), $history_total, ceil($history_total / 10)); 1211 1212 $this->response->setOutput($this->load->view('customer/customer_history', $data)); 1213 } 1214 1215 public function addHistory() { 1216 $this->load->language('customer/customer'); 1217 1218 $json = array(); 1219 1220 if (!$this->user->hasPermission('modify', 'customer/customer')) { 1221 $json['error'] = $this->language->get('error_permission'); 1222 } else { 1223 $this->load->model('customer/customer'); 1224 1225 $this->model_customer_customer->addHistory($this->request->get['customer_id'], $this->request->post['comment']); 1226 1227 $json['success'] = $this->language->get('text_success'); 1228 } 1229 1230 $this->response->addHeader('Content-Type: application/json'); 1231 $this->response->setOutput(json_encode($json)); 1232 } 1233 1234 public function transaction() { 1235 $this->load->language('customer/customer'); 1236 1237 $this->load->model('customer/customer'); 1238 1239 if (isset($this->request->get['page'])) { 1240 $page = $this->request->get['page']; 1241 } else { 1242 $page = 1; 1243 } 1244 1245 $data['transactions'] = array(); 1246 1247 $results = $this->model_customer_customer->getTransactions($this->request->get['customer_id'], ($page - 1) * 10, 10); 1248 1249 foreach ($results as $result) { 1250 $data['transactions'][] = array( 1251 'amount' => $this->currency->format($result['amount'], $this->config->get('config_currency')), 1252 'description' => $result['description'], 1253 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) 1254 ); 1255 } 1256 1257 $data['balance'] = $this->currency->format($this->model_customer_customer->getTransactionTotal($this->request->get['customer_id']), $this->config->get('config_currency')); 1258 1259 $transaction_total = $this->model_customer_customer->getTotalTransactions($this->request->get['customer_id']); 1260 1261 $pagination = new Pagination(); 1262 $pagination->total = $transaction_total; 1263 $pagination->page = $page; 1264 $pagination->limit = 10; 1265 $pagination->url = $this->url->link('customer/customer/transaction', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); 1266 1267 $data['pagination'] = $pagination->render(); 1268 1269 $data['results'] = sprintf($this->language->get('text_pagination'), ($transaction_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($transaction_total - 10)) ? $transaction_total : ((($page - 1) * 10) + 10), $transaction_total, ceil($transaction_total / 10)); 1270 1271 $this->response->setOutput($this->load->view('customer/customer_transaction', $data)); 1272 } 1273 1274 public function addTransaction() { 1275 $this->load->language('customer/customer'); 1276 1277 $json = array(); 1278 1279 if (!$this->user->hasPermission('modify', 'customer/customer')) { 1280 $json['error'] = $this->language->get('error_permission'); 1281 } else { 1282 $this->load->model('customer/customer'); 1283 1284 $this->model_customer_customer->addTransaction($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['amount']); 1285 1286 $json['success'] = $this->language->get('text_success'); 1287 } 1288 1289 $this->response->addHeader('Content-Type: application/json'); 1290 $this->response->setOutput(json_encode($json)); 1291 } 1292 1293 public function reward() { 1294 $this->load->language('customer/customer'); 1295 1296 $this->load->model('customer/customer'); 1297 1298 if (isset($this->request->get['page'])) { 1299 $page = $this->request->get['page']; 1300 } else { 1301 $page = 1; 1302 } 1303 1304 $data['rewards'] = array(); 1305 1306 $results = $this->model_customer_customer->getRewards($this->request->get['customer_id'], ($page - 1) * 10, 10); 1307 1308 foreach ($results as $result) { 1309 $data['rewards'][] = array( 1310 'points' => $result['points'], 1311 'description' => $result['description'], 1312 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])) 1313 ); 1314 } 1315 1316 $data['balance'] = $this->model_customer_customer->getRewardTotal($this->request->get['customer_id']); 1317 1318 $reward_total = $this->model_customer_customer->getTotalRewards($this->request->get['customer_id']); 1319 1320 $pagination = new Pagination(); 1321 $pagination->total = $reward_total; 1322 $pagination->page = $page; 1323 $pagination->limit = 10; 1324 $pagination->url = $this->url->link('customer/customer/reward', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); 1325 1326 $data['pagination'] = $pagination->render(); 1327 1328 $data['results'] = sprintf($this->language->get('text_pagination'), ($reward_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($reward_total - 10)) ? $reward_total : ((($page - 1) * 10) + 10), $reward_total, ceil($reward_total / 10)); 1329 1330 $this->response->setOutput($this->load->view('customer/customer_reward', $data)); 1331 } 1332 1333 public function addReward() { 1334 $this->load->language('customer/customer'); 1335 1336 $json = array(); 1337 1338 if (!$this->user->hasPermission('modify', 'customer/customer')) { 1339 $json['error'] = $this->language->get('error_permission'); 1340 } else { 1341 $this->load->model('customer/customer'); 1342 1343 $this->model_customer_customer->addReward($this->request->get['customer_id'], $this->request->post['description'], $this->request->post['points']); 1344 1345 $json['success'] = $this->language->get('text_success'); 1346 } 1347 1348 $this->response->addHeader('Content-Type: application/json'); 1349 $this->response->setOutput(json_encode($json)); 1350 } 1351 1352 public function ip() { 1353 $this->load->language('customer/customer'); 1354 1355 $this->load->model('customer/customer'); 1356 1357 if (isset($this->request->get['page'])) { 1358 $page = $this->request->get['page']; 1359 } else { 1360 $page = 1; 1361 } 1362 1363 $data['ips'] = array(); 1364 1365 $results = $this->model_customer_customer->getIps($this->request->get['customer_id'], ($page - 1) * 10, 10); 1366 1367 foreach ($results as $result) { 1368 $data['ips'][] = array( 1369 'ip' => $result['ip'], 1370 'total' => $this->model_customer_customer->getTotalCustomersByIp($result['ip']), 1371 'date_added' => date('d/m/y', strtotime($result['date_added'])), 1372 'filter_ip' => $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&filter_ip=' . $result['ip'], true) 1373 ); 1374 } 1375 1376 $ip_total = $this->model_customer_customer->getTotalIps($this->request->get['customer_id']); 1377 1378 $pagination = new Pagination(); 1379 $pagination->total = $ip_total; 1380 $pagination->page = $page; 1381 $pagination->limit = 10; 1382 $pagination->url = $this->url->link('customer/customer/ip', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page={page}', true); 1383 1384 $data['pagination'] = $pagination->render(); 1385 1386 $data['results'] = sprintf($this->language->get('text_pagination'), ($ip_total) ? (($page - 1) * 10) + 1 : 0, ((($page - 1) * 10) > ($ip_total - 10)) ? $ip_total : ((($page - 1) * 10) + 10), $ip_total, ceil($ip_total / 10)); 1387 1388 $this->response->setOutput($this->load->view('customer/customer_ip', $data)); 1389 } 1390 1391 public function autocomplete() { 1392 $json = array(); 1393 1394 if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_email'])) { 1395 if (isset($this->request->get['filter_name'])) { 1396 $filter_name = $this->request->get['filter_name']; 1397 } else { 1398 $filter_name = ''; 1399 } 1400 1401 if (isset($this->request->get['filter_email'])) { 1402 $filter_email = $this->request->get['filter_email']; 1403 } else { 1404 $filter_email = ''; 1405 } 1406 1407 if (isset($this->request->get['filter_affiliate'])) { 1408 $filter_affiliate = $this->request->get['filter_affiliate']; 1409 } else { 1410 $filter_affiliate = ''; 1411 } 1412 1413 $this->load->model('customer/customer'); 1414 1415 $filter_data = array( 1416 'filter_name' => $filter_name, 1417 'filter_email' => $filter_email, 1418 'filter_affiliate' => $filter_affiliate, 1419 'start' => 0, 1420 'limit' => 5 1421 ); 1422 1423 $results = $this->model_customer_customer->getCustomers($filter_data); 1424 1425 foreach ($results as $result) { 1426 $json[] = array( 1427 'customer_id' => $result['customer_id'], 1428 'customer_group_id' => $result['customer_group_id'], 1429 'name' => strip_tags(html_entity_decode($result['name'], ENT_QUOTES, 'UTF-8')), 1430 'customer_group' => $result['customer_group'], 1431 'firstname' => $result['firstname'], 1432 'lastname' => $result['lastname'], 1433 'email' => $result['email'], 1434 'telephone' => $result['telephone'], 1435 'custom_field' => json_decode($result['custom_field'], true), 1436 'address' => $this->model_customer_customer->getAddresses($result['customer_id']) 1437 ); 1438 } 1439 } 1440 1441 $sort_order = array(); 1442 1443 foreach ($json as $key => $value) { 1444 $sort_order[$key] = $value['name']; 1445 } 1446 1447 array_multisort($sort_order, SORT_ASC, $json); 1448 1449 $this->response->addHeader('Content-Type: application/json'); 1450 $this->response->setOutput(json_encode($json)); 1451 } 1452 1453 public function customfield() { 1454 $json = array(); 1455 1456 $this->load->model('customer/custom_field'); 1457 1458 // Customer Group 1459 if (isset($this->request->get['customer_group_id'])) { 1460 $customer_group_id = $this->request->get['customer_group_id']; 1461 } else { 1462 $customer_group_id = $this->config->get('config_customer_group_id'); 1463 } 1464 1465 $custom_fields = $this->model_customer_custom_field->getCustomFields(array('filter_customer_group_id' => $customer_group_id)); 1466 1467 foreach ($custom_fields as $custom_field) { 1468 $json[] = array( 1469 'custom_field_id' => $custom_field['custom_field_id'], 1470 'required' => empty($custom_field['required']) || $custom_field['required'] == 0 ? false : true 1471 ); 1472 } 1473 1474 $this->response->addHeader('Content-Type: application/json'); 1475 $this->response->setOutput(json_encode($json)); 1476 } 1477 1478 public function address() { 1479 $json = array(); 1480 1481 if (!empty($this->request->get['address_id'])) { 1482 $this->load->model('customer/customer'); 1483 1484 $json = $this->model_customer_customer->getAddress($this->request->get['address_id']); 1485 } 1486 1487 $this->response->addHeader('Content-Type: application/json'); 1488 $this->response->setOutput(json_encode($json)); 1489 } 1490 }