shop.balmet.com

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

featured.php (5891B)


      1 <?php
      2 class ControllerExtensionModuleFeatured extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('extension/module/featured');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		$this->load->model('setting/module');
     11 
     12 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     13 			if (!isset($this->request->get['module_id'])) {
     14 				$this->model_setting_module->addModule('featured', $this->request->post);
     15 			} else {
     16 				$this->model_setting_module->editModule($this->request->get['module_id'], $this->request->post);
     17 			}
     18 
     19 			$this->session->data['success'] = $this->language->get('text_success');
     20 
     21 			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));
     22 		}
     23 
     24 		if (isset($this->error['warning'])) {
     25 			$data['error_warning'] = $this->error['warning'];
     26 		} else {
     27 			$data['error_warning'] = '';
     28 		}
     29 
     30 		if (isset($this->error['name'])) {
     31 			$data['error_name'] = $this->error['name'];
     32 		} else {
     33 			$data['error_name'] = '';
     34 		}
     35 
     36 		if (isset($this->error['width'])) {
     37 			$data['error_width'] = $this->error['width'];
     38 		} else {
     39 			$data['error_width'] = '';
     40 		}
     41 
     42 		if (isset($this->error['height'])) {
     43 			$data['error_height'] = $this->error['height'];
     44 		} else {
     45 			$data['error_height'] = '';
     46 		}
     47 
     48 		$data['breadcrumbs'] = array();
     49 
     50 		$data['breadcrumbs'][] = array(
     51 			'text' => $this->language->get('text_home'),
     52 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     53 		);
     54 
     55 		$data['breadcrumbs'][] = array(
     56 			'text' => $this->language->get('text_extension'),
     57 			'href' => $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true)
     58 		);
     59 
     60 		if (!isset($this->request->get['module_id'])) {
     61 			$data['breadcrumbs'][] = array(
     62 				'text' => $this->language->get('heading_title'),
     63 				'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true)
     64 			);
     65 		} else {
     66 			$data['breadcrumbs'][] = array(
     67 				'text' => $this->language->get('heading_title'),
     68 				'href' => $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true)
     69 			);
     70 		}
     71 
     72 		if (!isset($this->request->get['module_id'])) {
     73 			$data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'], true);
     74 		} else {
     75 			$data['action'] = $this->url->link('extension/module/featured', 'user_token=' . $this->session->data['user_token'] . '&module_id=' . $this->request->get['module_id'], true);
     76 		}
     77 
     78 		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);
     79 
     80 		if (isset($this->request->get['module_id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
     81 			$module_info = $this->model_setting_module->getModule($this->request->get['module_id']);
     82 		}
     83 
     84 		$data['user_token'] = $this->session->data['user_token'];
     85 
     86 		if (isset($this->request->post['name'])) {
     87 			$data['name'] = $this->request->post['name'];
     88 		} elseif (!empty($module_info)) {
     89 			$data['name'] = $module_info['name'];
     90 		} else {
     91 			$data['name'] = '';
     92 		}
     93 
     94 		$this->load->model('catalog/product');
     95 
     96 		$data['products'] = array();
     97 
     98 		if (!empty($this->request->post['product'])) {
     99 			$products = $this->request->post['product'];
    100 		} elseif (!empty($module_info['product'])) {
    101 			$products = $module_info['product'];
    102 		} else {
    103 			$products = array();
    104 		}
    105 
    106 		foreach ($products as $product_id) {
    107 			$product_info = $this->model_catalog_product->getProduct($product_id);
    108 
    109 			if ($product_info) {
    110 				$data['products'][] = array(
    111 					'product_id' => $product_info['product_id'],
    112 					'name'       => $product_info['name']
    113 				);
    114 			}
    115 		}
    116 
    117 		if (isset($this->request->post['limit'])) {
    118 			$data['limit'] = $this->request->post['limit'];
    119 		} elseif (!empty($module_info)) {
    120 			$data['limit'] = $module_info['limit'];
    121 		} else {
    122 			$data['limit'] = 5;
    123 		}
    124 
    125 		if (isset($this->request->post['width'])) {
    126 			$data['width'] = $this->request->post['width'];
    127 		} elseif (!empty($module_info)) {
    128 			$data['width'] = $module_info['width'];
    129 		} else {
    130 			$data['width'] = 200;
    131 		}
    132 
    133 		if (isset($this->request->post['height'])) {
    134 			$data['height'] = $this->request->post['height'];
    135 		} elseif (!empty($module_info)) {
    136 			$data['height'] = $module_info['height'];
    137 		} else {
    138 			$data['height'] = 200;
    139 		}
    140 
    141 		if (isset($this->request->post['status'])) {
    142 			$data['status'] = $this->request->post['status'];
    143 		} elseif (!empty($module_info)) {
    144 			$data['status'] = $module_info['status'];
    145 		} else {
    146 			$data['status'] = '';
    147 		}
    148 
    149 		$data['header'] = $this->load->controller('common/header');
    150 		$data['column_left'] = $this->load->controller('common/column_left');
    151 		$data['footer'] = $this->load->controller('common/footer');
    152 
    153 		$this->response->setOutput($this->load->view('extension/module/featured', $data));
    154 	}
    155 
    156 	protected function validate() {
    157 		if (!$this->user->hasPermission('modify', 'extension/module/featured')) {
    158 			$this->error['warning'] = $this->language->get('error_permission');
    159 		}
    160 
    161 		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 64)) {
    162 			$this->error['name'] = $this->language->get('error_name');
    163 		}
    164 
    165 		if (!$this->request->post['width']) {
    166 			$this->error['width'] = $this->language->get('error_width');
    167 		}
    168 
    169 		if (!$this->request->post['height']) {
    170 			$this->error['height'] = $this->language->get('error_height');
    171 		}
    172 
    173 		return !$this->error;
    174 	}
    175 }