<?php
class ControllerModuleCart extends Controller {
	private $error = array(); 
	
	public function index() {   
		$this->load->language('module/cart');

		$this->document->title = $this->language->get('heading_title');
		
		$this->load->model('setting/setting');
				
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && ($this->validate())) {
			$this->model_setting_setting->editSetting('cart', $this->request->post);		
					
			$this->session->data['success'] = $this->language->get('text_success');
						
			$this->redirect($this->url->https('extension/module'));
		}
				
		$this->data['heading_title'] = $this->language->get('heading_title');

		$this->data['text_enabled'] = $this->language->get('text_enabled');
		$this->data['text_disabled'] = $this->language->get('text_disabled');
		$this->data['text_left'] = $this->language->get('text_left');
		$this->data['text_right'] = $this->language->get('text_right');
		
		$this->data['entry_ajax'] = $this->language->get('entry_ajax');
		$this->data['entry_position'] = $this->language->get('entry_position');
		$this->data['entry_status'] = $this->language->get('entry_status');
		$this->data['entry_sort_order'] = $this->language->get('entry_sort_order');
		
		$this->data['button_save'] = $this->language->get('button_save');
		$this->data['button_cancel'] = $this->language->get('button_cancel');

		$this->data['tab_general'] = $this->language->get('tab_general');

		$this->data['error_warning'] = @$this->error['warning'];

  		$this->document->breadcrumbs = array();

   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('common/home'),
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('extension/module'),
       		'text'      => $this->language->get('text_module'),
      		'separator' => ' :: '
   		);
		
   		$this->document->breadcrumbs[] = array(
       		'href'      => $this->url->https('module/cart'),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);
		
		$this->data['action'] = $this->url->https('module/cart');
		
		$this->data['cancel'] = $this->url->https('extension/module');

		if (isset($this->request->post['cart_ajax'])) {
			$this->data['cart_ajax'] = $this->request->post['cart_ajax'];
		} else {
			$this->data['cart_ajax'] = $this->config->get('cart_ajax');
		}
		
		if (isset($this->request->post['cart_position'])) {
			$this->data['cart_position'] = $this->request->post['cart_position'];
		} else {
			$this->data['cart_position'] = $this->config->get('cart_position');
		}
		
		if (isset($this->request->post['cart_status'])) {
			$this->data['cart_status'] = $this->request->post['cart_status'];
		} else {
			$this->data['cart_status'] = $this->config->get('cart_status');
		}
		
		if (isset($this->request->post['cart_sort_order'])) {
			$this->data['cart_sort_order'] = $this->request->post['cart_sort_order'];
		} else {
			$this->data['cart_sort_order'] = $this->config->get('cart_sort_order');
		}				
		
		$this->id       = 'content';
		$this->template = 'module/cart.tpl';
		$this->layout   = 'common/layout';
		
 		$this->render();
	}
	
	private function validate() {
		if (!$this->user->hasPermission('modify', 'module/cart')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}
		
		if (!$this->error) {
			return TRUE;
		} else {
			return FALSE;
		}	
	}
}
?>