shop.balmet.com

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

layout.php (15002B)


      1 <?php
      2 class ControllerDesignLayout extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('design/layout');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 		
     10 		$this->load->model('design/layout');
     11 
     12 		$this->getList();
     13 	}
     14 
     15 	public function add() {
     16 		$this->load->language('design/layout');
     17 
     18 		$this->document->setTitle($this->language->get('heading_title'));
     19 
     20 		$this->load->model('design/layout');
     21 
     22 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
     23 			$this->model_design_layout->addLayout($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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true));
     42 		}
     43 
     44 		$this->getForm();
     45 	}
     46 
     47 	public function edit() {
     48 		$this->load->language('design/layout');
     49 
     50 		$this->document->setTitle($this->language->get('heading_title'));
     51 
     52 		$this->load->model('design/layout');
     53 
     54 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
     55 			$this->model_design_layout->editLayout($this->request->get['layout_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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true));
     74 		}
     75 
     76 		$this->getForm();
     77 	}
     78 
     79 	public function delete() {
     80 		$this->load->language('design/layout');
     81 
     82 		$this->document->setTitle($this->language->get('heading_title'));
     83 
     84 		$this->load->model('design/layout');
     85 
     86 		if (isset($this->request->post['selected']) && $this->validateDelete()) {
     87 			foreach ($this->request->post['selected'] as $layout_id) {
     88 				$this->model_design_layout->deleteLayout($layout_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('design/layout', '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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)
    156 		);
    157 
    158 		$data['add'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
    159 		$data['delete'] = $this->url->link('design/layout/delete', 'user_token=' . $this->session->data['user_token'] . $url, true);
    160 
    161 		$data['layouts'] = 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 		$layout_total = $this->model_design_layout->getTotalLayouts();
    171 
    172 		$results = $this->model_design_layout->getLayouts($filter_data);
    173 
    174 		foreach ($results as $result) {
    175 			$data['layouts'][] = array(
    176 				'layout_id' => $result['layout_id'],
    177 				'name'      => $result['name'],
    178 				'edit'      => $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $result['layout_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('design/layout', '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 = $layout_total;
    228 		$pagination->page = $page;
    229 		$pagination->limit = $this->config->get('config_limit_admin');
    230 		$pagination->url = $this->url->link('design/layout', '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'), ($layout_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($layout_total - $this->config->get('config_limit_admin'))) ? $layout_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $layout_total, ceil($layout_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('design/layout_list', $data));
    244 	}
    245 
    246 	protected function getForm() {
    247 		$data['text_form'] = !isset($this->request->get['layout_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'] = '';
    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('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true)
    285 		);
    286 
    287 		if (!isset($this->request->get['layout_id'])) {
    288 			$data['action'] = $this->url->link('design/layout/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
    289 		} else {
    290 			$data['action'] = $this->url->link('design/layout/edit', 'user_token=' . $this->session->data['user_token'] . '&layout_id=' . $this->request->get['layout_id'] . $url, true);
    291 		}
    292 
    293 		$data['cancel'] = $this->url->link('design/layout', 'user_token=' . $this->session->data['user_token'] . $url, true);
    294 
    295 		$data['user_token'] = $this->session->data['user_token'];
    296 
    297 		if (isset($this->request->get['layout_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
    298 			$layout_info = $this->model_design_layout->getLayout($this->request->get['layout_id']);
    299 		}
    300 
    301 		if (isset($this->request->post['name'])) {
    302 			$data['name'] = $this->request->post['name'];
    303 		} elseif (!empty($layout_info)) {
    304 			$data['name'] = $layout_info['name'];
    305 		} else {
    306 			$data['name'] = '';
    307 		}
    308 
    309 		$this->load->model('setting/store');
    310 
    311 		$data['stores'] = $this->model_setting_store->getStores();
    312 
    313 		if (isset($this->request->post['layout_route'])) {
    314 			$data['layout_routes'] = $this->request->post['layout_route'];
    315 		} elseif (isset($this->request->get['layout_id'])) {
    316 			$data['layout_routes'] = $this->model_design_layout->getLayoutRoutes($this->request->get['layout_id']);
    317 		} else {
    318 			$data['layout_routes'] = array();
    319 		}
    320 
    321 		$this->load->model('setting/extension');
    322 
    323 		$this->load->model('setting/module');
    324 
    325 		$data['extensions'] = array();
    326 		
    327 		// Get a list of installed modules
    328 		$extensions = $this->model_setting_extension->getInstalled('module');
    329 
    330 		// Add all the modules which have multiple settings for each module
    331 		foreach ($extensions as $code) {
    332 			$this->load->language('extension/module/' . $code, 'extension');
    333 
    334 			$module_data = array();
    335 
    336 			$modules = $this->model_setting_module->getModulesByCode($code);
    337 
    338 			foreach ($modules as $module) {
    339 				$module_data[] = array(
    340 					'name' => strip_tags($module['name']),
    341 					'code' => $code . '.' .  $module['module_id']
    342 				);
    343 			}
    344 
    345 			if ($this->config->has('module_' . $code . '_status') || $module_data) {
    346 				$data['extensions'][] = array(
    347 					'name'   => strip_tags($this->language->get('extension')->get('heading_title')),
    348 					'code'   => $code,
    349 					'module' => $module_data
    350 				);
    351 			}
    352 		}
    353 
    354 		// Modules layout
    355 		if (isset($this->request->post['layout_module'])) {
    356 			$layout_modules = $this->request->post['layout_module'];
    357 		} elseif (isset($this->request->get['layout_id'])) {
    358 			$layout_modules = $this->model_design_layout->getLayoutModules($this->request->get['layout_id']);
    359 		} else {
    360 			$layout_modules = array();
    361 		}
    362 
    363 		$data['layout_modules'] = array();
    364 		
    365 		// Add all the modules which have multiple settings for each module
    366 		foreach ($layout_modules as $layout_module) {
    367 			$part = explode('.', $layout_module['code']);
    368 		
    369 			$this->load->language('extension/module/' . $part[0]);
    370 
    371 			if (!isset($part[1])) {
    372 				$data['layout_modules'][] = array(
    373 					'name'       => strip_tags($this->language->get('heading_title')),
    374 					'code'       => $layout_module['code'],
    375 					'edit'       => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'], true),
    376 					'position'   => $layout_module['position'],
    377 					'sort_order' => $layout_module['sort_order']
    378 				);
    379 			} else {
    380 				$module_info = $this->model_setting_module->getModule($part[1]);
    381 				
    382 				if ($module_info) {
    383 					$data['layout_modules'][] = array(
    384 						'name'       => strip_tags($module_info['name']),
    385 						'code'       => $layout_module['code'],
    386 						'edit'       => $this->url->link('extension/module/' . $part[0], 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $part[1], true),
    387 						'position'   => $layout_module['position'],
    388 						'sort_order' => $layout_module['sort_order']
    389 					);
    390 				}				
    391 			}
    392 		}		
    393 		
    394 		$data['header'] = $this->load->controller('common/header');
    395 		$data['column_left'] = $this->load->controller('common/column_left');
    396 		$data['footer'] = $this->load->controller('common/footer');
    397 
    398 		$this->response->setOutput($this->load->view('design/layout_form', $data));
    399 	}
    400 
    401 	protected function validateForm() {
    402 		if (!$this->user->hasPermission('modify', 'design/layout')) {
    403 			$this->error['warning'] = $this->language->get('error_permission');
    404 		}
    405 
    406 		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
    407 			$this->error['name'] = $this->language->get('error_name');
    408 		}
    409 
    410 		return !$this->error;
    411 	}
    412 
    413 	protected function validateDelete() {
    414 		if (!$this->user->hasPermission('modify', 'design/layout')) {
    415 			$this->error['warning'] = $this->language->get('error_permission');
    416 		}
    417 
    418 		$this->load->model('setting/store');
    419 		$this->load->model('catalog/product');
    420 		$this->load->model('catalog/category');
    421 		$this->load->model('catalog/information');
    422 
    423 		foreach ($this->request->post['selected'] as $layout_id) {
    424 			if ($this->config->get('config_layout_id') == $layout_id) {
    425 				$this->error['warning'] = $this->language->get('error_default');
    426 			}
    427 
    428 			$store_total = $this->model_setting_store->getTotalStoresByLayoutId($layout_id);
    429 
    430 			if ($store_total) {
    431 				$this->error['warning'] = sprintf($this->language->get('error_store'), $store_total);
    432 			}
    433 
    434 			$product_total = $this->model_catalog_product->getTotalProductsByLayoutId($layout_id);
    435 
    436 			if ($product_total) {
    437 				$this->error['warning'] = sprintf($this->language->get('error_product'), $product_total);
    438 			}
    439 
    440 			$category_total = $this->model_catalog_category->getTotalCategoriesByLayoutId($layout_id);
    441 
    442 			if ($category_total) {
    443 				$this->error['warning'] = sprintf($this->language->get('error_category'), $category_total);
    444 			}
    445 
    446 			$information_total = $this->model_catalog_information->getTotalInformationsByLayoutId($layout_id);
    447 
    448 			if ($information_total) {
    449 				$this->error['warning'] = sprintf($this->language->get('error_information'), $information_total);
    450 			}
    451 		}
    452 
    453 		return !$this->error;
    454 	}
    455 }