<?php
class ControllerExtensionModuleCartbindercombo1a extends Controller {
	private $error = array();

	public function index() {
		$this->load->language('extension/module/cartbindercombo1a');

		$this->document->setTitle($this->language->get('title'));

		$this->load->model('extension/module/cartbindercombo1');
		$this->model_extension_module_cartbindercombo1->createTable();

		$this->load->model('extension/module/cartbindercombo1a');

		$this->getList();
	}

	public function insert() {
		$this->load->language('extension/module/cartbindercombo1a');

		$this->document->setTitle($this->language->get('title'));

		$this->load->model('extension/module/cartbindercombo1a');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
			$this->model_extension_module_cartbindercombo1a->addcartbindercombo1a($this->request->post);
			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			$this->response->redirect($this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'].$url, TRUE));
		}

		$this->getForm();
	}

	public function update() {
		$this->load->language('extension/module/cartbindercombo1a');

		$this->document->setTitle($this->language->get('title'));

		$this->load->model('extension/module/cartbindercombo1a');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {

			$this->model_extension_module_cartbindercombo1a->editcartbindercombo1a($this->request->get['id'], $this->request->post);

			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			$this->response->redirect($this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'].$url, TRUE));
		}

		$this->getForm();
	}

	public function delete() {
		$this->load->language('extension/module/cartbindercombo1a');

		$this->document->setTitle($this->language->get('title'));

		$this->load->model('extension/module/cartbindercombo1a');

		if (isset($this->request->post['selected']) && $this->validateDelete()) {

      		foreach ($this->request->post['selected'] as $id) {
				$this->model_extension_module_cartbindercombo1a->delete($id);
			}

			$this->session->data['success'] = $this->language->get('text_success');

			$url = '';

			if (isset($this->request->get['page'])) {
				$url .= '&page=' . $this->request->get['page'];
			}

			if (isset($this->request->get['sort'])) {
				$url .= '&sort=' . $this->request->get['sort'];
			}

			if (isset($this->request->get['order'])) {
				$url .= '&order=' . $this->request->get['order'];
			}

			$this->response->redirect($this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'].$url, TRUE));
		}

		$this->getList();
	}

	private function getList() {

       // Edit these next three lines to suit your setup and extension ID
      $data['oc_licensing_home'] = 'https://www.cartbinder.com/store/'; // Important to have trailing slash at the end of the SSL URL!
       $data['extension_id'] = 24407;   // Replace extension ID with your extension ID
        

		if (isset($this->request->get['filter_name'])) {
			$filter_name = $this->request->get['filter_name'];
		} else {
			$filter_name = null;
		}

		if (isset($this->request->get['filter_status'])) {
			$filter_status = $this->request->get['filter_status'];
		} else {
			$filter_status = null;
		}

  		$data['breadcrumbs'] = array();

  		$data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('common/home', 'user_token=' . $this->session->data['user_token'], TRUE),
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

  		$data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'], TRUE),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);


		$data['insert']  = $this->url->link('extension/module/cartbindercombo1a/insert', 'user_token=' . $this->session->data['user_token'], TRUE);
		$data['delete']  = $this->url->link('extension/module/cartbindercombo1a/delete', 'user_token=' . $this->session->data['user_token'], TRUE);
		$data['addoffers']  = $this->url->link('extension/module/salescombopge', 'user_token=' . $this->session->data['user_token'], TRUE);

		if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'c.id';
		}

		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'ASC';
		}

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}

		$data['cartbindercombo1as'] = array();

		$filter_data = array(
			'filter_name'	  => $filter_name,
			'filter_status'   => $filter_status,
			'sort'            => $sort,
			'order'           => $order,
			'start'           => ($page - 1) * $this->config->get('config_limit_admin'),
			'limit'           => $this->config->get('config_limit_admin')
		);

		$cartbindercombo1a_total = $this->model_extension_module_cartbindercombo1a->getTotalcartbindercombo1a($filter_data);
		$results = $this->model_extension_module_cartbindercombo1a->getcartbindercombo1as($filter_data,($page - 1) * $this->config->get('config_limit_admin'),$this->config->get('config_limit_admin'));

		foreach ($results as $result) {
			$action = array();

			$action[] = array(
				'text' => $this->language->get('button_edit'),
				'href' => $this->url->link('extension/module/cartbindercombo1a/update', 'user_token=' . $this->session->data['user_token'] . '&id=' . $result['id'], TRUE)
			);
			$data['cartbindercombo1as'][] = array(
				'id' 		 	 => $result['id'],
				'name' 	 	     => $result['name'],
				'type' 	 	     => ($result['type'])?"Fixed":"Percentage",
				'discount' 	 	 => $result['discount'],
				'multidiscount' 	 	 => $result['multidiscount'],
				'primaryproducts'  => $this->model_extension_module_cartbindercombo1a->getNames($result['primarypids']),
				'primaryquant'   => $result['primaryquant'],
				'secondaryquant'   => $result['secondaryquant'],
				'total' 	 	 => $this->model_extension_module_cartbindercombo1a->getTotalForOffer($result['id']),
				'offersapplied'  => $this->model_extension_module_cartbindercombo1a->getTotalOfferApplied($result['id']),
				'status' 	 	 => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled')),
				'action'     	 => $action
			);
		}

		$data['user_token'] = $this->session->data['user_token'];

		$url = '';

		if (isset($this->request->get['filter_name'])) {
			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_status'])) {
			$url .= '&filter_status=' . urlencode(html_entity_decode($this->request->get['filter_status'], ENT_QUOTES, 'UTF-8'));
		}

		if ($order == 'ASC') {
			$url .= '&order=DESC';
		} else {
			$url .= '&order=ASC';
		}

		if (isset($this->request->get['page'])) {
			$url .= '&page=' . $this->request->get['page'];
		}

		$data['sort_name'] = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'] . '&sort=name' . $url, TRUE);
		$data['sort_status'] = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'] . '&sort=status' . $url, TRUE);
		$data['cancel'] = $this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true);

 		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

		if (isset($this->session->data['success'])) {
			$data['success'] = $this->session->data['success'];
			unset($this->session->data['success']);
		} else {
			$data['success'] = '';
		}

		$url = "";

		if (isset($this->request->get['filter_name'])) {
			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_status'])) {
			$url .= '&filter_status=' . urlencode(html_entity_decode($this->request->get['filter_status'], ENT_QUOTES, 'UTF-8'));
		}

		if ($order == 'ASC') {
			$url .= '&order=DESC';
		} else {
			$url .= '&order=ASC';
		}

		$pagination = new Pagination();
		$pagination->total = $cartbindercombo1a_total;
		$pagination->page  = $page;
		$pagination->limit = $this->config->get('config_limit_admin');
		$pagination->url   = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'] . $url . '&page={page}', TRUE);

		$data['pagination'] = $pagination->render();

		$data['results'] = sprintf($this->language->get('text_pagination'), ($cartbindercombo1a_total) ? (($page - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page - 1) * $this->config->get('config_limit_admin')) > ($cartbindercombo1a_total - $this->config->get('config_limit_admin'))) ? $cartbindercombo1a_total : ((($page - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $cartbindercombo1a_total, ceil($cartbindercombo1a_total / $this->config->get('config_limit_admin')));

		$data['filter_name'] = $filter_name;
		$data['filter_status'] = $filter_status;

		$data['sort'] = $sort;
		$data['order'] = $order;


		$data['sort_name'] = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token']. '&sort=c.name' . $url, TRUE);
		$data['sort_status'] = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token']. '&sort=c.status' . $url, TRUE);

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$admin_support_email = 'support@cartbinder.com'; $data['license_purchase_thanks'] = sprintf($this->language->get('license_purchase_thanks'), $admin_support_email); if(isset($this->request->get['emailmal'])){ $data['emailmal'] = true; } if(isset($this->request->get['regerror'])){ if($this->request->get['regerror']=='emailmal'){ $this->error['warning'] = $this->language->get('regerror_email'); }elseif($this->request->get['regerror']=='orderidmal'){ $this->error['warning'] = $this->language->get('regerror_orderid'); }elseif($this->request->get['regerror']=='noreferer'){ $this->error['warning'] = $this->language->get('regerror_noreferer'); }elseif($this->request->get['regerror']=='localhost'){ $this->error['warning'] = $this->language->get('regerror_localhost'); }elseif($this->request->get['regerror']=='licensedupe'){ $this->error['warning'] = $this->language->get('regerror_licensedupe'); } } $domainssl = explode("//", HTTPS_SERVER); $domainnonssl = explode("//", HTTP_SERVER); $domain = ($domainssl[1] != '' ? $domainssl[1] : $domainnonssl[1]);$data['aurl'] = (HTTPS_SERVER !='' ? HTTPS_SERVER : HTTP_SERVER);$data['auri'] = (HTTPS_CATALOG !='' ? HTTPS_CATALOG : HTTP_CATALOG) . substr($_SERVER['REQUEST_URI'], 1); $data['domain'] = $domain; $data['licensed'] = @file_get_contents($data['oc_licensing_home'] . 'licensed.php?domain=' . $domain . '&extension=' . $data['extension_id']); if(!$data['licensed'] || $data['licensed'] == ''){ if(extension_loaded('curl')) { $post_data = array('domain' => $domain, 'extension' => $data['extension_id']); $curl = curl_init(); curl_setopt($curl, CURLOPT_HEADER, false); curl_setopt($curl, CURLINFO_HEADER_OUT, true); curl_setopt($curl, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17'); $follow_allowed = ( ini_get('open_basedir') || ini_get('safe_mode')) ? false : true; if ($follow_allowed) { curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); } curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 9); curl_setopt($curl, CURLOPT_TIMEOUT, 60); curl_setopt($curl, CURLOPT_AUTOREFERER, true); curl_setopt($curl, CURLOPT_VERBOSE, 1); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl, CURLOPT_FORBID_REUSE, false); curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl, CURLOPT_URL, $data['oc_licensing_home'] . 'licensed.php'); curl_setopt($curl, CURLOPT_POST, true); curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data)); $data['licensed'] = curl_exec($curl); curl_close($curl); }else{ $data['licensed'] = 'curl'; } } $data['licensed_md5'] = md5($data['licensed']); $data['entry_free_support'] = $this->language->get('entry_free_support'); $order_details = @file_get_contents($data['oc_licensing_home'] . 'order_details.php?domain=' . $domain . '&extension=' . $data['extension_id']); $order_data = json_decode($order_details, true); if(!is_array($order_data) || $order_data == ''){ if(extension_loaded('curl')) { $post_data2 = array('domain' => $domain, 'extension' => $data['extension_id']); $curl2 = curl_init(); curl_setopt($curl2, CURLOPT_HEADER, false); curl_setopt($curl2, CURLINFO_HEADER_OUT, true); curl_setopt($curl2, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.52 Safari/537.17'); $follow_allowed2 = ( ini_get('open_basedir') || ini_get('safe_mode')) ? false : true; if ($follow_allowed2) { curl_setopt($curl2, CURLOPT_FOLLOWLOCATION, 1); } curl_setopt($curl2, CURLOPT_CONNECTTIMEOUT, 9); curl_setopt($curl2, CURLOPT_TIMEOUT, 60); curl_setopt($curl2, CURLOPT_AUTOREFERER, true); curl_setopt($curl2, CURLOPT_VERBOSE, 1); curl_setopt($curl2, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($curl2, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($curl2, CURLOPT_FORBID_REUSE, false); curl_setopt($curl2, CURLOPT_RETURNTRANSFER, true); curl_setopt($curl2, CURLOPT_URL, $data['oc_licensing_home'] . 'order_details.php'); curl_setopt($curl2, CURLOPT_POST, true); curl_setopt($curl2, CURLOPT_POSTFIELDS, http_build_query($post_data2)); $order_data = json_decode(curl_exec($curl2), true); curl_close($curl2); }else{ $order_data['status'] = 'disabled'; } } if(isset($order_data['status']) && $order_data['status'] == 'enabled'){ $isSecure = false; if (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) { $isSecure = true; } elseif (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https' || !empty($_SERVER['HTTP_X_FORWARDED_SSL']) && $_SERVER['HTTP_X_FORWARDED_SSL'] == 'on') { $isSecure = true; } $data['support_status'] = 'enabled'; $data['support_order_id'] = $order_data['order_id']; $data['support_extension_name'] = $order_data['extension_name']; $data['support_domain'] = $order_data['domain']; $data['support_username'] = $order_data['username']; $data['support_email'] = $order_data['email']; $data['support_registered_date'] = strftime('%Y-%m-%d', $order_data['registered_date']); $data['support_order_date'] = strftime('%Y-%m-%d', ($order_data['order_date'] + 31536000)); if((time() - $order_data['order_date']) > 31536000){ $data['text_free_support_remaining'] = sprintf($this->language->get('text_free_support_expired'), 1, ($isSecure ? 1 : 0), urlencode($domain) , $data['extension_id'] , $this->session->data['token']); }else{ $data['text_free_support_remaining'] = sprintf($this->language->get('text_free_support_remaining'), 366 - ceil((time() - $order_data['order_date']) / 86400)); } }else{ $data['support_status'] = 'disabled'; $data['text_free_support_remaining'] = sprintf($this->language->get('text_free_support_remaining'), 'unknown'); }

		$this->response->setOutput($this->load->view('extension/module/cartbindercombo1a_list', $data));
 	}

	private function getForm() {
		$url = '';

 		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} else {
			$data['error_warning'] = '';
		}

 		if (isset($this->error['error_name'])) {
			$data['error_name'] = $this->error['error_name'];
		} else {
			$data['error_name'] = '';
		}

 		if (isset($this->error['error_cartbindercombo1a_exist'])) {
			$data['error_cartbindercombo1a_exist'] = $this->error['error_cartbindercombo1a_exist'];
		} else {
			$data['error_cartbindercombo1a_exist'] = '';
		}

		if (isset($this->error['error_cartbindercombo1a_empty'])) {
			$data['error_cartbindercombo1a_empty'] = $this->error['error_cartbindercombo1a_empty'];
		} else {
			$data['error_cartbindercombo1a_empty'] = '';
		}

  		$data['breadcrumbs'] = array();

  		$data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('common/home', 'user_token=' . $this->session->data['user_token'], TRUE),
       		'text'      => $this->language->get('text_home'),
      		'separator' => FALSE
   		);

  		$data['breadcrumbs'][] = array(
       		'href'      => $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'], TRUE),
       		'text'      => $this->language->get('heading_title'),
      		'separator' => ' :: '
   		);

		if (!isset($this->request->get['id'])) {
			$data['action'] = $this->url->link('extension/module/cartbindercombo1a/insert', 'user_token=' . $this->session->data['user_token'], TRUE);
		} else {
			$data['action'] = $this->url->link('extension/module/cartbindercombo1a/update', 'user_token=' . $this->session->data['user_token'] . '&id=' . $this->request->get['id'], TRUE);
		}

		$data['user_token'] = $this->session->data['user_token'];

    	$data['cancel'] = $this->url->link('extension/module/cartbindercombo1a', 'user_token=' . $this->session->data['user_token'], TRUE);
    	$data['addoffers']  = $this->url->link('extension/module/salescombopge', 'user_token=' . $this->session->data['user_token'], TRUE);

		if (isset($this->request->get['id']) && ($this->request->server['REQUEST_METHOD'] != 'POST')) {
			$cartbindercombo1a_info = $this->model_extension_module_cartbindercombo1a->getcartbindercombo1a($this->request->get['id']);
		}

		if (isset($this->request->get['id'])) {
			$data['id'] = $this->request->get['id'];
		}

		if (isset($this->error['name'])) {
			$data['error_name'] = $this->error['name'];
		} else {
			$data['error_name'] = array();
		}

		if (isset($this->request->post['name'])) {
			$data['name'] = $this->request->post['name'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['name'] = $cartbindercombo1a_info['name'];
		} else {
			$data['name'] = '';
		}


		if (isset($this->request->post['status'])) {
			$data['status'] = $this->request->post['status'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['status'] = $cartbindercombo1a_info['status'];
		} else {
			$data['status'] = '1';
		}
		$this->load->model('catalog/product');
		if (isset($this->request->post['primaryproducts'])) {
			$primaryproducts = $this->request->post['primaryproducts'];
		} else if(!empty($cartbindercombo1a_info['primarypids'])) {
			$primaryproducts = explode(",",  $cartbindercombo1a_info['primarypids']);
		} else {
			$primaryproducts = array();
		}

		$data['primaryproducts'] = array();
		foreach ($primaryproducts as $product_id) {
			$product_info = $this->model_catalog_product->getProduct($product_id);

			if ($product_info) {
				$data['primaryproducts'][] = array(
					'product_id' => $product_info['product_id'],
					'name'        => $product_info['name']
				);
			}
		}

		if (isset($this->request->post['type'])) {
			$data['type'] = $this->request->post['type'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['type'] = $cartbindercombo1a_info['type'];
		} else {
			$data['type'] = 1;
		}

		if (isset($this->request->post['discount'])) {
			$data['discount'] = $this->request->post['discount'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['discount'] = $cartbindercombo1a_info['discount'];
		} else {
			$data['discount'] = 10;
		}

		if (isset($this->request->post['extras'])) {
			$data['extras'] = $this->request->post['extras'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['extras'] = $cartbindercombo1a_info['extras'];
		} else {
			$data['extras'] = "";
		}

		if (isset($this->request->post['multidiscount'])) {
			$data['multidiscount'] = $this->request->post['multidiscount'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['multidiscount'] = $cartbindercombo1a_info['multidiscount'];
		} else {
			$data['multidiscount'] = "";
		}

		if (isset($this->request->post['primaryquant'])) {
			$data['primaryquant'] = $this->request->post['primaryquant'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['primaryquant'] = $cartbindercombo1a_info['primaryquant'];
		} else {
			$data['primaryquant'] = 1;
		}

		if (isset($this->request->post['maxquantity'])) {
			$data['maxquantity'] = $this->request->post['maxquantity'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['maxquantity'] = $cartbindercombo1a_info['maxquantity'];
		} else {
			$data['maxquantity'] = "";
		}

		if (isset($this->request->post['uses_customer'])) {
			$data['uses_customer'] = $this->request->post['uses_customer'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['uses_customer'] = $cartbindercombo1a_info['uses_customer'];
		} else {
			$data['uses_customer'] = '';
		}

		$this->load->model('extension/module/salescombopge');
		$data['offerpages'] = $this->model_extension_module_salescombopge->getsalescombopges();

		if (isset($this->request->post['sales_offer_id'])) {
			$data['sales_offer_id'] = $this->request->post['sales_offer_id'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['sales_offer_id'] = $cartbindercombo1a_info['sales_offer_id'];
		} else {
			$data['sales_offer_id'] = 0;
		}

		if (isset($this->request->post['secondaryquant'])) {
			$data['secondaryquant'] = $this->request->post['secondaryquant'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['secondaryquant'] = $cartbindercombo1a_info['secondaryquant'];
		} else {
			$data['secondaryquant'] = 1;
		}

		$this->load->model('customer/customer_group');
		$data['customergroups'] = $this->model_customer_customer_group->getCustomerGroups();


		if (isset($this->request->post['cids'])) {
			$data['cids'] = $this->request->post['cids'];
		} else if(isset($cartbindercombo1a_info)) {
			$data['cids'] = json_decode($cartbindercombo1a_info['cids'],true);
		} else {
			$data['cids'] = array();
		}

		if (isset($this->request->post['showoffer'])) {
			$data['showoffer'] = $this->request->post['showoffer'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['showoffer'] = $cartbindercombo1a_info['showoffer'];
		} else {
			$data['showoffer'] = 0;
		}

		if (isset($this->request->post['datestart'])) {
			$data['datestart'] = $this->request->post['datestart'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['datestart'] = ($cartbindercombo1a_info['datestart'] != '0000-00-00') ? $cartbindercombo1a_info['datestart'] : '';
		} else {
			$data['datestart'] = "";
		}

		if (isset($this->request->post['dateend'])) {
			$data['dateend'] = $this->request->post['dateend'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['dateend'] = ($cartbindercombo1a_info['dateend'] != '0000-00-00') ? $cartbindercombo1a_info['dateend'] : '';
		} else {
			$data['dateend'] = "";
		}

		if (isset($this->request->post['bundle'])) {
			$data['bundle'] = $this->request->post['bundle'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['bundle'] = $cartbindercombo1a_info['bundle'];
		} else {
			$data['bundle'] = 0;
		}

		if (isset($this->request->post['displaylocation'])) {
			$data['displaylocation'] = $this->request->post['displaylocation'];
		} elseif (isset($cartbindercombo1a_info)) {
			$data['displaylocation'] = $cartbindercombo1a_info['displaylocation'];
		} else {
			$data['displaylocation'] = 0;
		}

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('extension/module/cartbindercombo1a_form', $data));
	}

	private function validateForm() {

		$this->load->model('extension/module/cartbindercombo1a');

		if (!$this->user->hasPermission('modify', 'extension/module/cartbindercombo1a')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 255)) {
			$this->error['warning'] = $this->language->get('error_name');
		}

		if (empty($this->request->post['primaryproducts'])) {
			$this->error['warning'] = $this->language->get('error_primaryproductsempty');
		}

		if (empty($this->request->post['sales_offer_id'])) {
			$this->error['warning'] = 'Please select offer description page';
		}

		return !$this->error;
	}

	protected function validateDelete() {
		if (!$this->user->hasPermission('modify', 'extension/module/cartbindercombo1a')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		return !$this->error;
	}


	public function autocomplete() {
		$json = array();

		if (isset($this->request->get['filter_name']) || isset($this->request->get['filter_condition'])) {
			$this->load->model('extension/module/cartbindercombo1a');

			if (isset($this->request->get['filter_name'])) {
				$filter_name = $this->request->get['filter_name'];
			} else {
				$filter_name = null;
			}

			if (isset($this->request->get['limit'])) {
				$limit = $this->request->get['limit'];
			} else {
				$limit = 20;
			}

			$data = array(
				'filter_name'  => $filter_name,
				'start'        => 0,
				'limit'        => $limit
			);

			$json = $this->model_extension_module_cartbindercombo1a->getcartbindercombo1as($data);

		}

		$this->response->setOutput(json_encode($json));
	}
}
?>
