/upload/catalog/controller/account/return.php
PHP | 615 lines | 477 code | 138 blank | 0 comment | 100 complexity | c2b1ea6c3d02c4d85f213200b50d6596 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
- <?php
- class ControllerAccountReturn extends Controller {
- private $error = array();
-
- public function index() {
- if (!$this->customer->isLogged()) {
- $this->session->data['redirect'] = $this->url->link('account/return', '', 'SSL');
-
- $this->redirect($this->url->link('account/login', '', 'SSL'));
- }
-
- $this->data += $this->language->load('account/return');
-
- $this->document->setTitle($this->language->get('heading_title'));
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_account'),
- 'href' => $this->url->link('account/account', '', 'SSL')
- );
-
- $url = '';
-
- if (isset($this->request->get['page'])) {
- $url .= '&page=' . $this->request->get['page'];
- }
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('account/return', $url, 'SSL')
- );
-
- $this->load->model('account/return');
-
- if (isset($this->request->get['page'])) {
- $page = $this->request->get['page'];
- } else {
- $page = 1;
- }
-
- $this->data['returns'] = array();
-
- $return_total = $this->model_account_return->getTotalReturns();
-
- $results = $this->model_account_return->getReturns(($page - 1) * 10, 10);
-
- foreach ($results as $result) {
- $this->data['returns'][] = array(
- 'return_id' => $result['return_id'],
- 'order_id' => $result['order_id'],
- 'name' => $result['firstname'] . ' ' . $result['lastname'],
- 'status' => $result['status'],
- 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
- 'href' => $this->url->link('account/return/info', 'return_id=' . $result['return_id'] . $url, 'SSL')
- );
- }
-
- $pagination = new Pagination();
- $pagination->total = $return_total;
- $pagination->page = $page;
- $pagination->limit = $this->config->get('config_catalog_limit');
- $pagination->text = $this->language->get('text_pagination');
- $pagination->url = $this->url->link('account/history', 'page={page}', 'SSL');
-
- $this->data['pagination'] = $pagination->render();
-
- $this->data['continue'] = $this->url->link('account/account', '', 'SSL');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_list.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/account/return_list.tpl';
- } else {
- $this->template = 'default/template/account/return_list.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
-
- public function info() {
- $this->data += $this->language->load('account/return');
-
- if (isset($this->request->get['return_id'])) {
- $return_id = $this->request->get['return_id'];
- } else {
- $return_id = 0;
- }
-
- if (!$this->customer->isLogged()) {
- $this->session->data['redirect'] = $this->url->link('account/return/info', 'return_id=' . $return_id, 'SSL');
-
- $this->redirect($this->url->link('account/login', '', 'SSL'));
- }
-
- $this->load->model('account/return');
-
- $return_info = $this->model_account_return->getReturn($return_id);
-
- if ($return_info) {
- $this->document->setTitle($this->language->get('text_return'));
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home', '', 'SSL')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_account'),
- 'href' => $this->url->link('account/account', '', 'SSL')
- );
-
- $url = '';
-
- if (isset($this->request->get['page'])) {
- $url .= '&page=' . $this->request->get['page'];
- }
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('account/return', $url, 'SSL')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_return'),
- 'href' => $this->url->link('account/return/info', 'return_id=' . $this->request->get['return_id'] . $url, 'SSL')
- );
-
- $this->data['heading_title'] = $this->language->get('text_return');
-
- $this->data['return_id'] = $return_info['return_id'];
- $this->data['order_id'] = $return_info['order_id'];
- $this->data['date_ordered'] = date($this->language->get('date_format_short'), strtotime($return_info['date_ordered']));
- $this->data['date_added'] = date($this->language->get('date_format_short'), strtotime($return_info['date_added']));
- $this->data['firstname'] = $return_info['firstname'];
- $this->data['lastname'] = $return_info['lastname'];
- $this->data['email'] = $return_info['email'];
- $this->data['telephone'] = $return_info['telephone'];
- $this->data['product'] = $return_info['product'];
- $this->data['model'] = $return_info['model'];
- $this->data['quantity'] = $return_info['quantity'];
- $this->data['reason'] = $return_info['reason'];
- $this->data['opened'] = $return_info['opened'] ? $this->language->get('text_yes') : $this->language->get('text_no');
- $this->data['comment'] = nl2br($return_info['comment']);
- $this->data['action'] = $return_info['action'];
-
- $this->data['histories'] = array();
-
- $results = $this->model_account_return->getReturnHistories($this->request->get['return_id']);
-
- foreach ($results as $result) {
- $this->data['histories'][] = array(
- 'date_added' => date($this->language->get('date_format_short'), strtotime($result['date_added'])),
- 'status' => $result['status'],
- 'comment' => nl2br($result['comment'])
- );
- }
-
- $this->data['continue'] = $this->url->link('account/return', $url, 'SSL');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_info.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/account/return_info.tpl';
- } else {
- $this->template = 'default/template/account/return_info.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- } else {
- $this->document->setTitle($this->language->get('text_return'));
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_account'),
- 'href' => $this->url->link('account/account', '', 'SSL')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('account/return', '', 'SSL')
- );
-
- $url = '';
-
- if (isset($this->request->get['page'])) {
- $url .= '&page=' . $this->request->get['page'];
- }
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_return'),
- 'href' => $this->url->link('account/return/info', 'return_id=' . $return_id . $url, 'SSL')
- );
-
- $this->data['heading_title'] = $this->language->get('text_return');
-
- $this->data['continue'] = $this->url->link('account/return', '', 'SSL');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/error/not_found.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/error/not_found.tpl';
- } else {
- $this->template = 'default/template/error/not_found.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
- }
-
- public function insert() {
- $this->data += $this->language->load('account/return');
-
- $this->load->model('account/return');
-
- if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
- $this->model_account_return->addReturn($this->request->post);
-
- $this->redirect($this->url->link('account/return/success', '', 'SSL'));
- }
-
- $this->document->setTitle($this->language->get('heading_title'));
-
- $this->document->addScript('catalog/view/javascript/jquery/colorbox/jquery.colorbox-min.js');
- $this->document->addStyle('catalog/view/javascript/jquery/colorbox/colorbox.css');
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_account'),
- 'href' => $this->url->link('account/account', '', 'SSL')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('account/return/insert', '', 'SSL')
- );
-
- if (isset($this->error['warning'])) {
- $this->data['error_warning'] = $this->error['warning'];
- } else {
- $this->data['error_warning'] = '';
- }
-
- if (isset($this->error['order_id'])) {
- $this->data['error_order_id'] = $this->error['order_id'];
- } else {
- $this->data['error_order_id'] = '';
- }
-
- if (isset($this->error['firstname'])) {
- $this->data['error_firstname'] = $this->error['firstname'];
- } else {
- $this->data['error_firstname'] = '';
- }
-
- if (isset($this->error['lastname'])) {
- $this->data['error_lastname'] = $this->error['lastname'];
- } else {
- $this->data['error_lastname'] = '';
- }
-
- if (isset($this->error['email'])) {
- $this->data['error_email'] = $this->error['email'];
- } else {
- $this->data['error_email'] = '';
- }
-
- if (isset($this->error['telephone'])) {
- $this->data['error_telephone'] = $this->error['telephone'];
- } else {
- $this->data['error_telephone'] = '';
- }
-
- if (isset($this->error['product'])) {
- $this->data['error_product'] = $this->error['product'];
- } else {
- $this->data['error_product'] = '';
- }
-
- if (isset($this->error['model'])) {
- $this->data['error_model'] = $this->error['model'];
- } else {
- $this->data['error_model'] = '';
- }
-
- if (isset($this->error['reason'])) {
- $this->data['error_reason'] = $this->error['reason'];
- } else {
- $this->data['error_reason'] = '';
- }
-
- if (isset($this->error['captcha'])) {
- $this->data['error_captcha'] = $this->error['captcha'];
- } else {
- $this->data['error_captcha'] = '';
- }
-
- $this->data['action'] = $this->url->link('account/return/insert', '', 'SSL');
-
- $this->load->model('account/order');
-
- if (isset($this->request->get['order_id'])) {
- $order_info = $this->model_account_order->getOrder($this->request->get['order_id']);
- }
-
- $this->load->model('catalog/product');
-
- if (isset($this->request->get['product_id'])) {
- $product_info = $this->model_catalog_product->getProduct($this->request->get['product_id']);
- }
-
- if (isset($this->request->post['order_id'])) {
- $this->data['order_id'] = $this->request->post['order_id'];
- } elseif (!empty($order_info)) {
- $this->data['order_id'] = $order_info['order_id'];
- } else {
- $this->data['order_id'] = '';
- }
-
- if (isset($this->request->post['date_ordered'])) {
- $this->data['date_ordered'] = $this->request->post['date_ordered'];
- } elseif (!empty($order_info)) {
- $this->data['date_ordered'] = date('Y-m-d', strtotime($order_info['date_added']));
- } else {
- $this->data['date_ordered'] = '';
- }
-
- if (isset($this->request->post['firstname'])) {
- $this->data['firstname'] = $this->request->post['firstname'];
- } elseif (!empty($order_info)) {
- $this->data['firstname'] = $order_info['firstname'];
- } else {
- $this->data['firstname'] = $this->customer->getFirstName();
- }
-
- if (isset($this->request->post['lastname'])) {
- $this->data['lastname'] = $this->request->post['lastname'];
- } elseif (!empty($order_info)) {
- $this->data['lastname'] = $order_info['lastname'];
- } else {
- $this->data['lastname'] = $this->customer->getLastName();
- }
-
- if (isset($this->request->post['email'])) {
- $this->data['email'] = $this->request->post['email'];
- } elseif (!empty($order_info)) {
- $this->data['email'] = $order_info['email'];
- } else {
- $this->data['email'] = $this->customer->getEmail();
- }
-
- if (isset($this->request->post['telephone'])) {
- $this->data['telephone'] = $this->request->post['telephone'];
- } elseif (!empty($order_info)) {
- $this->data['telephone'] = $order_info['telephone'];
- } else {
- $this->data['telephone'] = $this->customer->getTelephone();
- }
-
- if (isset($this->request->post['product'])) {
- $this->data['product'] = $this->request->post['product'];
- } elseif (!empty($product_info)) {
- $this->data['product'] = $product_info['name'];
- } else {
- $this->data['product'] = '';
- }
-
- if (isset($this->request->post['model'])) {
- $this->data['model'] = $this->request->post['model'];
- } elseif (!empty($product_info)) {
- $this->data['model'] = $product_info['model'];
- } else {
- $this->data['model'] = '';
- }
-
- if (isset($this->request->post['quantity'])) {
- $this->data['quantity'] = $this->request->post['quantity'];
- } else {
- $this->data['quantity'] = 1;
- }
-
- if (isset($this->request->post['opened'])) {
- $this->data['opened'] = $this->request->post['opened'];
- } else {
- $this->data['opened'] = false;
- }
-
- if (isset($this->request->post['return_reason_id'])) {
- $this->data['return_reason_id'] = $this->request->post['return_reason_id'];
- } else {
- $this->data['return_reason_id'] = '';
- }
-
- $this->load->model('localisation/return_reason');
-
- $this->data['return_reasons'] = $this->model_localisation_return_reason->getReturnReasons();
-
- if (isset($this->request->post['comment'])) {
- $this->data['comment'] = $this->request->post['comment'];
- } else {
- $this->data['comment'] = '';
- }
-
- if (isset($this->request->post['captcha'])) {
- $this->data['captcha'] = $this->request->post['captcha'];
- } else {
- $this->data['captcha'] = '';
- }
-
- if ($this->config->get('config_return_id')) {
- $this->load->model('catalog/information');
-
- $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
-
- if ($information_info) {
- $this->data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/info', 'information_id=' . $this->config->get('config_return_id'), 'SSL'), $information_info['title'], $information_info['title']);
- } else {
- $this->data['text_agree'] = '';
- }
- } else {
- $this->data['text_agree'] = '';
- }
-
- if (isset($this->request->post['agree'])) {
- $this->data['agree'] = $this->request->post['agree'];
- } else {
- $this->data['agree'] = false;
- }
-
- $this->data['back'] = $this->url->link('account/account', '', 'SSL');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/account/return_form.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/account/return_form.tpl';
- } else {
- $this->template = 'default/template/account/return_form.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
-
- public function success() {
- $this->data += $this->language->load('account/return');
-
- $this->document->setTitle($this->language->get('heading_title'));
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('account/return', '', 'SSL')
- );
-
- $this->data['continue'] = $this->url->link('common/home');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/common/success.tpl';
- } else {
- $this->template = 'default/template/common/success.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
-
- protected function validate() {
- if (!$this->request->post['order_id']) {
- $this->error['order_id'] = $this->language->get('error_order_id');
- }
-
- if ((utf8_strlen($this->request->post['firstname']) < 1) || (utf8_strlen($this->request->post['firstname']) > 32)) {
- $this->error['firstname'] = $this->language->get('error_firstname');
- }
-
- if ((utf8_strlen($this->request->post['lastname']) < 1) || (utf8_strlen($this->request->post['lastname']) > 32)) {
- $this->error['lastname'] = $this->language->get('error_lastname');
- }
-
- if ((utf8_strlen($this->request->post['email']) > 96) || !preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
- $this->error['email'] = $this->language->get('error_email');
- }
-
- if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
- $this->error['telephone'] = $this->language->get('error_telephone');
- }
-
- if ((utf8_strlen($this->request->post['product']) < 1) || (utf8_strlen($this->request->post['product']) > 255)) {
- $this->error['product'] = $this->language->get('error_product');
- }
-
- if ((utf8_strlen($this->request->post['model']) < 1) || (utf8_strlen($this->request->post['model']) > 64)) {
- $this->error['model'] = $this->language->get('error_model');
- }
-
- if (empty($this->request->post['return_reason_id'])) {
- $this->error['reason'] = $this->language->get('error_reason');
- }
-
- if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
- $this->error['captcha'] = $this->language->get('error_captcha');
- }
-
- if ($this->config->get('config_return_id')) {
- $this->load->model('catalog/information');
-
- $information_info = $this->model_catalog_information->getInformation($this->config->get('config_return_id'));
-
- if ($information_info && !isset($this->request->post['agree'])) {
- $this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
- }
- }
-
- if (!$this->error) {
- return true;
- } else {
- return false;
- }
- }
-
- public function captcha() {
- $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
-
- $image = imagecreatetruecolor(150, 35);
-
- $width = imagesx($image);
- $height = imagesy($image);
-
- $black = imagecolorallocate($image, 0, 0, 0);
- $white = imagecolorallocate($image, 255, 255, 255);
- $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
- $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
- $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
-
- imagefilledrectangle($image, 0, 0, $width, $height, $white);
-
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
-
- imagefilledrectangle($image, 0, 0, $width, 0, $black);
- imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
- imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
- imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
-
- imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
-
- header('Content-type: image/jpeg');
-
- imagejpeg($image);
-
- imagedestroy($image);
- }
- }
- ?>