shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

return_status.php (12234B)


      1 <?php
      2 class ControllerLocalisationReturnStatus extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('localisation/return_status');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		$this->load->model('localisation/return_status');
     11 
     12 		$this->getList();
     13 	}
     14 
     15 	public function add() {
     16 		$this->load->language('localisation/return_status');
     17 
     18 		$this->document->setTitle($this->language->get('heading_title'));
     19 
     20 		$this->load->model('localisation/return_status');
     21 
     22 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
     23 			$this->model_localisation_return_status->addReturnStatus($this->request->post);
     24 
     25 			$this->session->data['success'] = $this->language->get('text_success');
     26 
     27 			$url = '';
     28 
     29 			if (isset($this->request->get['sort'])) {
     30 				$url .= '&sort=' . $this->request->get['sort'];
     31 			}
     32 
     33 			if (isset($this->request->get['order'])) {
     34 				$url .= '&order=' . $this->request->get['order'];
     35 			}
     36 
     37 			if (isset($this->request->get['page'])) {
     38 				$url .= '&page=' . $this->request->get['page'];
     39 			}
     40 
     41 			$this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true));
     42 		}
     43 
     44 		$this->getForm();
     45 	}
     46 
     47 	public function edit() {
     48 		$this->load->language('localisation/return_status');
     49 
     50 		$this->document->setTitle($this->language->get('heading_title'));
     51 
     52 		$this->load->model('localisation/return_status');
     53 
     54 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
     55 			$this->model_localisation_return_status->editReturnStatus($this->request->get['return_status_id'], $this->request->post);
     56 
     57 			$this->session->data['success'] = $this->language->get('text_success');
     58 
     59 			$url = '';
     60 
     61 			if (isset($this->request->get['sort'])) {
     62 				$url .= '&sort=' . $this->request->get['sort'];
     63 			}
     64 
     65 			if (isset($this->request->get['order'])) {
     66 				$url .= '&order=' . $this->request->get['order'];
     67 			}
     68 
     69 			if (isset($this->request->get['page'])) {
     70 				$url .= '&page=' . $this->request->get['page'];
     71 			}
     72 
     73 			$this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true));
     74 		}
     75 
     76 		$this->getForm();
     77 	}
     78 
     79 	public function delete() {
     80 		$this->load->language('localisation/return_status');
     81 
     82 		$this->document->setTitle($this->language->get('heading_title'));
     83 
     84 		$this->load->model('localisation/return_status');
     85 
     86 		if (isset($this->request->post['selected']) && $this->validateDelete()) {
     87 			foreach ($this->request->post['selected'] as $return_status_id) {
     88 				$this->model_localisation_return_status->deleteReturnStatus($return_status_id);
     89 			}
     90 
     91 			$this->session->data['success'] = $this->language->get('text_success');
     92 
     93 			$url = '';
     94 
     95 			if (isset($this->request->get['sort'])) {
     96 				$url .= '&sort=' . $this->request->get['sort'];
     97 			}
     98 
     99 			if (isset($this->request->get['order'])) {
    100 				$url .= '&order=' . $this->request->get['order'];
    101 			}
    102 
    103 			if (isset($this->request->get['page'])) {
    104 				$url .= '&page=' . $this->request->get['page'];
    105 			}
    106 
    107 			$this->response->redirect($this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true));
    108 		}
    109 
    110 		$this->getList();
    111 	}
    112 
    113 	protected function getList() {
    114 		if (isset($this->request->get['sort'])) {
    115 			$sort = $this->request->get['sort'];
    116 		} else {
    117 			$sort = 'name';
    118 		}
    119 
    120 		if (isset($this->request->get['order'])) {
    121 			$order = $this->request->get['order'];
    122 		} else {
    123 			$order = 'ASC';
    124 		}
    125 
    126 		if (isset($this->request->get['page'])) {
    127 			$page = $this->request->get['page'];
    128 		} else {
    129 			$page = 1;
    130 		}
    131 
    132 		$url = '';
    133 
    134 		if (isset($this->request->get['sort'])) {
    135 			$url .= '&sort=' . $this->request->get['sort'];
    136 		}
    137 
    138 		if (isset($this->request->get['order'])) {
    139 			$url .= '&order=' . $this->request->get['order'];
    140 		}
    141 
    142 		if (isset($this->request->get['page'])) {
    143 			$url .= '&page=' . $this->request->get['page'];
    144 		}
    145 
    146 		$data['breadcrumbs'] = array();
    147 
    148 		$data['breadcrumbs'][] = array(
    149 			'text' => $this->language->get('text_home'),
    150 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
    151 		);
    152 
    153 		$data['breadcrumbs'][] = array(
    154 			'text' => $this->language->get('heading_title'),
    155 			'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)
    156 		);
    157 
    158 		$data['add'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
    159 		$data['delete'] = $this->url->link('localisation/return_status/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
    160 
    161 		$data['return_statuses'] = array();
    162 
    163 		$filter_data = array(
    164 			'sort'  => $sort,
    165 			'order' => $order,
    166 			'start' => ($page - 1) * $this->config->get('config_limit_admin'),
    167 			'limit' => $this->config->get('config_limit_admin')
    168 		);
    169 
    170 		$return_status_total = $this->model_localisation_return_status->getTotalReturnStatuses();
    171 
    172 		$results = $this->model_localisation_return_status->getReturnStatuses($filter_data);
    173 
    174 		foreach ($results as $result) {
    175 			$data['return_statuses'][] = array(
    176 				'return_status_id' => $result['return_status_id'],
    177 				'name'             => $result['name'] . (($result['return_status_id'] == $this->config->get('config_return_status_id')) ? $this->language->get('text_default') : null),
    178 				'edit'             => $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $result['return_status_id'] . $url, true)
    179 			);
    180 		}
    181 
    182 		if (isset($this->error['warning'])) {
    183 			$data['error_warning'] = $this->error['warning'];
    184 		} else {
    185 			$data['error_warning'] = '';
    186 		}
    187 
    188 		if (isset($this->session->data['success'])) {
    189 			$data['success'] = $this->session->data['success'];
    190 
    191 			unset($this->session->data['success']);
    192 		} else {
    193 			$data['success'] = '';
    194 		}
    195 
    196 		if (isset($this->request->post['selected'])) {
    197 			$data['selected'] = (array)$this->request->post['selected'];
    198 		} else {
    199 			$data['selected'] = array();
    200 		}
    201 
    202 		$url = '';
    203 
    204 		if ($order == 'ASC') {
    205 			$url .= '&order=DESC';
    206 		} else {
    207 			$url .= '&order=ASC';
    208 		}
    209 
    210 		if (isset($this->request->get['page'])) {
    211 			$url .= '&page=' . $this->request->get['page'];
    212 		}
    213 
    214 		$data['sort_name'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, true);
    215 
    216 		$url = '';
    217 
    218 		if (isset($this->request->get['sort'])) {
    219 			$url .= '&sort=' . $this->request->get['sort'];
    220 		}
    221 
    222 		if (isset($this->request->get['order'])) {
    223 			$url .= '&order=' . $this->request->get['order'];
    224 		}
    225 
    226 		$pagination = new Pagination();
    227 		$pagination->total = $return_status_total;
    228 		$pagination->page = $page;
    229 		$pagination->limit = $this->config->get('config_limit_admin');
    230 		$pagination->url = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', true);
    231 
    232 		$data['pagination'] = $pagination->render();
    233 
    234 		$data['results'] = sprintf($this->language->get('text_pagination'), ($return_status_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($return_status_total - $this->config->get('config_limit_admin'))) ? $return_status_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $return_status_total, ceil($return_status_total / $this->config->get('config_limit_admin')));
    235 
    236 		$data['sort'] = $sort;
    237 		$data['order'] = $order;
    238 
    239 		$data['header'] = $this->load->controller('common/header');
    240 		$data['column_left'] = $this->load->controller('common/column_left');
    241 		$data['footer'] = $this->load->controller('common/footer');
    242 
    243 		$this->response->setOutput($this->load->view('localisation/return_status_list', $data));
    244 	}
    245 
    246 	protected function getForm() {
    247 		$data['text_form'] = !isset($this->request->get['return_status_id']) ? $this->language->get('text_add') : $this->language->get('text_edit');
    248 
    249 		if (isset($this->error['warning'])) {
    250 			$data['error_warning'] = $this->error['warning'];
    251 		} else {
    252 			$data['error_warning'] = '';
    253 		}
    254 
    255 		if (isset($this->error['name'])) {
    256 			$data['error_name'] = $this->error['name'];
    257 		} else {
    258 			$data['error_name'] = array();
    259 		}
    260 
    261 		$url = '';
    262 
    263 		if (isset($this->request->get['sort'])) {
    264 			$url .= '&sort=' . $this->request->get['sort'];
    265 		}
    266 
    267 		if (isset($this->request->get['order'])) {
    268 			$url .= '&order=' . $this->request->get['order'];
    269 		}
    270 
    271 		if (isset($this->request->get['page'])) {
    272 			$url .= '&page=' . $this->request->get['page'];
    273 		}
    274 
    275 		$data['breadcrumbs'] = array();
    276 
    277 		$data['breadcrumbs'][] = array(
    278 			'text' => $this->language->get('text_home'),
    279 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
    280 		);
    281 
    282 		$data['breadcrumbs'][] = array(
    283 			'text' => $this->language->get('heading_title'),
    284 			'href' => $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true)
    285 		);
    286 
    287 		if (!isset($this->request->get['return_status_id'])) {
    288 			$data['action'] = $this->url->link('localisation/return_status/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
    289 		} else {
    290 			$data['action'] = $this->url->link('localisation/return_status/edit', 'user_token=' . $this->session->data['user_token'] . '&return_status_id=' . $this->request->get['return_status_id'] . $url, true);
    291 		}
    292 
    293 		$data['cancel'] = $this->url->link('localisation/return_status', 'user_token=' . $this->session->data['user_token'] . $url, true);
    294 
    295 		$this->load->model('localisation/language');
    296 
    297 		$data['languages'] = $this->model_localisation_language->getLanguages();
    298 
    299 		if (isset($this->request->post['return_status'])) {
    300 			$data['return_status'] = $this->request->post['return_status'];
    301 		} elseif (isset($this->request->get['return_status_id'])) {
    302 			$data['return_status'] = $this->model_localisation_return_status->getReturnStatusDescriptions($this->request->get['return_status_id']);
    303 		} else {
    304 			$data['return_status'] = array();
    305 		}
    306 
    307 		$data['header'] = $this->load->controller('common/header');
    308 		$data['column_left'] = $this->load->controller('common/column_left');
    309 		$data['footer'] = $this->load->controller('common/footer');
    310 
    311 		$this->response->setOutput($this->load->view('localisation/return_status_form', $data));
    312 	}
    313 
    314 	protected function validateForm() {
    315 		if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
    316 			$this->error['warning'] = $this->language->get('error_permission');
    317 		}
    318 
    319 		foreach ($this->request->post['return_status'] as $language_id => $value) {
    320 			if ((utf8_strlen($value['name']) < 3) || (utf8_strlen($value['name']) > 32)) {
    321 				$this->error['name'][$language_id] = $this->language->get('error_name');
    322 			}
    323 		}
    324 
    325 		return !$this->error;
    326 	}
    327 
    328 	protected function validateDelete() {
    329 		if (!$this->user->hasPermission('modify', 'localisation/return_status')) {
    330 			$this->error['warning'] = $this->language->get('error_permission');
    331 		}
    332 
    333 		$this->load->model('sale/return');
    334 
    335 		foreach ($this->request->post['selected'] as $return_status_id) {
    336 			if ($this->config->get('config_return_status_id') == $return_status_id) {
    337 				$this->error['warning'] = $this->language->get('error_default');
    338 			}
    339 
    340 			$return_total = $this->model_sale_return->getTotalReturnsByReturnStatusId($return_status_id);
    341 
    342 			if ($return_total) {
    343 				$this->error['warning'] = sprintf($this->language->get('error_return'), $return_total);
    344 			}
    345 
    346 			$return_total = $this->model_sale_return->getTotalReturnHistoriesByReturnStatusId($return_status_id);
    347 
    348 			if ($return_total) {
    349 				$this->error['warning'] = sprintf($this->language->get('error_return'), $return_total);
    350 			}
    351 		}
    352 
    353 		return !$this->error;
    354 	}
    355 }