<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name><![CDATA[<b style="color:#4170bd">ADV Extended Customer Information</b>]]></name>
	<version><![CDATA[<b style="color:#4170bd">3.0</b>]]></version>
	<code>adv_extended_cust_info</code>
	<link>http://www.opencartreports.com</link>
	<author>ADV Reports and Statistics</author>
	
	<file path="admin/controller/customer/customer.php">	
        <operation>
            <search><![CDATA[
$data['customers'][] = array(
            ]]></search>
            <add position="after"><![CDATA[
				'total_orders' 	 => $this->config->get('adveci_clist_orders_status') == '1' ? ($result['total_orders'] ? $result['total_orders'] : 0) : '',
				'total_value' 	 => $this->config->get('adveci_clist_total_value_status') == '1' ? ($this->currency->format($result['total_value'], $this->config->get('config_currency'))) : '',
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
$data['sort_date_added'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=c.date_added' . $url, true);
            ]]></search>
            <add position="after"><![CDATA[
        $data['laccess'] = FALSE;
		$data['sort_total_orders'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=total_orders' . $url, true);
		$data['sort_total_value'] = $this->url->link('customer/customer', 'user_token=' . $this->session->data['user_token'] . '&sort=total_value' . $url, true);
		
		$data['adveci_clist_orders_status'] = $this->config->get('adveci_clist_orders_status');
		$data['adveci_clist_total_value_status'] = $this->config->get('adveci_clist_total_value_status');
		if (!file_exists(DIR_CONFIG . 'include/adv_access.php')) {
			$this->response->redirect($this->url->link('extension/module/adv_extended_cust_info', 'user_token=' . $this->session->data['user_token'], true));
		}
		$data['adv_ext_name'] = $this->language->get('adv_ext_name');
		$data['adv_ext_short_name'] = 'adv_extended_cust_info';
		$data['adv_ext_version'] = $this->language->get('adv_ext_version');	
		$data['adv_ext_url'] = 'https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=3292';	
		include(DIR_CONFIG . 'include/adv_access.php');
		$data['access_permission2'] = $this->user->hasPermission('access', 'extension/module/adv_extended_cust_info');
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
$customer_info = $this->model_customer_customer->getCustomer($this->request->get['customer_id']);
            ]]></search>
            <add position="after"><![CDATA[
		$customer_note = $this->model_customer_customer->getCustomerNote($this->request->get['customer_id']);
            ]]></add>
        </operation>	
        <operation>
            <search><![CDATA[
if (isset($this->request->post['password'])) {
            ]]></search>
            <add position="before"><![CDATA[
		if (isset($this->request->post['note'])) {
			$data['note'] = $this->request->post['note'];
		} elseif (!empty($customer_note)) {
			$data['note'] = $customer_note['note'];
		} else {
			$data['note'] = '';
		}
            ]]></add>
        </operation>				     
        <operation>
            <search><![CDATA[
protected function getForm() {
            ]]></search>
            <add position="before"><![CDATA[
	public function filter_orders() {
	  $data['customer_id'] = isset($this->request->get['customer_id']);	
			
	  if (isset($this->request->get['customer_id'])) {
		
		$json = array();

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

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

		if (isset($this->request->get['filter_orders_date_end'])) {
			$filter_orders_date_end = $this->request->get['filter_orders_date_end'];
		} else {
			$filter_orders_date_end = '';
		}
		
		$data['ranges_orders'] = array();
		
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_custom'),
			'value' => 'custom',
			'style' => 'color:#666',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_today'),
			'value' => 'today',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_yesterday'),
			'value' => 'yesterday',
			'style' => 'color:#090',
		);		
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_week'),
			'value' => 'week',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_month'),
			'value' => 'month',
			'style' => 'color:#090',
		);					
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_quarter'),
			'value' => 'quarter',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_year'),
			'value' => 'year',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_week'),
			'value' => 'current_week',
			'style' => 'color:#06C',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_month'),
			'value' => 'current_month',
			'style' => 'color:#06C',
		);	
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_quarter'),
			'value' => 'current_quarter',
			'style' => 'color:#06C',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_year'),
			'value' => 'current_year',
			'style' => 'color:#06C',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_week'),
			'value' => 'last_week',
			'style' => 'color:#F90',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_month'),
			'value' => 'last_month',
			'style' => 'color:#F90',
		);	
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_quarter'),
			'value' => 'last_quarter',
			'style' => 'color:#F90',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_year'),
			'value' => 'last_year',
			'style' => 'color:#F90',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_all_time'),
			'value' => 'all_time',
			'style' => 'color:#F00',
		);
		
		if (isset($this->request->get['filter_orders_range'])) {
			$filter_orders_range = $this->request->get['filter_orders_range'];
		} else {
			$filter_orders_range = 'all_time';
		}

		if (isset($this->request->get['filter_orders_order_status'])) {
			$filter_orders_order_status = explode('_', $this->request->get['filter_orders_order_status']);
		} else {
			$filter_orders_order_status = 0;
		}
		
		if (isset($this->request->get['sort_orders'])) {
			$sort_orders = $this->request->get['sort_orders'];
		} else {
			$sort_orders = 'order_id';
		}

		if (isset($this->request->get['order_orders'])) {
			$order_orders = $this->request->get['order_orders'];
		} else {
			$order_orders = 'DESC';
		}
				
		if (isset($this->request->get['page_orders'])) {
			$page_orders = $this->request->get['page_orders'];
		} else {
			$page_orders = 1;
		}
				
		$json['customer_order'] = array();
		
		$filter_data = array(
			'filter_orders_date_start'	  		=> $filter_orders_date_start, 
			'filter_orders_date_end'	  		=> $filter_orders_date_end, 
			'filter_orders_range'	  	  		=> $filter_orders_range, 
			'filter_orders_order_status'	  	=> $filter_orders_order_status,
			'sort_orders'            			=> $sort_orders,
			'order_orders'           			=> $order_orders,
			'start_orders'           	  		=> ($page_orders - 1) * $this->config->get('config_limit_admin'),
			'limit_orders'           	  		=> $this->config->get('config_limit_admin')			
		);
		
		$this->load->model('customer/customer');
		
		$data['order_statuses'] = $this->model_customer_customer->getOrderStatuses(); 
		
		$customer_orders_total = $this->model_customer_customer->getCustomerOrdersTotal($filter_data, $this->request->get['customer_id']);
		
		$customer_orders = $this->model_customer_customer->getCustomerOrders($filter_data, $this->request->get['customer_id']);
		
		foreach ($customer_orders as $order) {
		
			$json['customer_order'][] = array(
				'date_added' 			=> date($this->config->get('adveci_date_format') == 'DDMMYYYY' ? 'd/m/Y' : 'm/d/Y', strtotime($order['date_added'])),
				'order_id'    			=> $order['order_id'],
				'order_id_url' 			=> $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'], true),
				'inv_no'     			=> $order['invoice_prefix'] . $order['invoice_no'],
				'shipping_method'     	=> strip_tags($order['shipping_method']),
				'payment_method'     	=> strip_tags($order['payment_method']),
				'os_name'     			=> $order['os_name'],												
				'store_name'    		=> $order['store_name'],
				'currency'     			=> $order['currency_code'],
				'products'    			=> $order['products'],						
				'sub_total'    			=> $this->currency->format($order['sub_total'], $order['currency_code'], $order['currency_value']),
				'shipping'    			=> $this->currency->format($order['shipping'], $order['currency_code'], $order['currency_value']),
				'tax'    				=> $this->currency->format($order['tax'], $order['currency_code'], $order['currency_value']),						
				'total'    				=> $this->currency->format($order['total'], $order['currency_code'], $order['currency_value']),												
				'total_products'   		=> $order['total_products'],	
				'total_sub_total'   	=> $this->currency->format($order['total_sub_total'], $order['currency_code'], $order['currency_value']),
				'total_shipping'   		=> $this->currency->format($order['total_shipping'], $order['currency_code'], $order['currency_value']),
				'total_tax'   			=> $this->currency->format($order['total_tax'], $order['currency_code'], $order['currency_value']),
				'total_value'   		=> $this->currency->format($order['total_value'], $order['currency_code'], $order['currency_value'])
			);
		}

		$pagination_orders = new Pagination();
		$pagination_orders->total = $customer_orders_total;
		$pagination_orders->page = $page_orders;
		$pagination_orders->limit = $this->config->get('config_limit_admin');
		$pagination_orders->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_orders={page}', true);
			
		$json['pagination_orders'] = $pagination_orders->render();
			
		$json['results_orders'] = sprintf($this->language->get('text_pagination'), ($customer_orders_total) ? (($page_orders - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_orders - 1) * $this->config->get('config_limit_admin')) > ($customer_orders_total - $this->config->get('config_limit_admin'))) ? $customer_orders_total : ((($page_orders - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_orders_total, ceil($customer_orders_total / $this->config->get('config_limit_admin')));
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	  }
	}	
	
	public function filter_products() {
	  $data['customer_id'] = isset($this->request->get['customer_id']);	
			
	  if (isset($this->request->get['customer_id'])) {
		
		$json = array();

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

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

		if (isset($this->request->get['filter_products_date_end'])) {
			$filter_products_date_end = $this->request->get['filter_products_date_end'];
		} else {
			$filter_products_date_end = '';
		}
		
		$data['ranges_products'] = array();
		
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_custom'),
			'value' => 'custom',
			'style' => 'color:#666',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_today'),
			'value' => 'today',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_yesterday'),
			'value' => 'yesterday',
			'style' => 'color:#090',
		);		
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_week'),
			'value' => 'week',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_month'),
			'value' => 'month',
			'style' => 'color:#090',
		);					
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_quarter'),
			'value' => 'quarter',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_year'),
			'value' => 'year',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_week'),
			'value' => 'current_week',
			'style' => 'color:#06C',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_month'),
			'value' => 'current_month',
			'style' => 'color:#06C',
		);	
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_quarter'),
			'value' => 'current_quarter',
			'style' => 'color:#06C',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_year'),
			'value' => 'current_year',
			'style' => 'color:#06C',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_week'),
			'value' => 'last_week',
			'style' => 'color:#F90',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_month'),
			'value' => 'last_month',
			'style' => 'color:#F90',
		);	
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_quarter'),
			'value' => 'last_quarter',
			'style' => 'color:#F90',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_year'),
			'value' => 'last_year',
			'style' => 'color:#F90',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_all_time'),
			'value' => 'all_time',
			'style' => 'color:#F00',
		);
		
		if (isset($this->request->get['filter_products_range'])) {
			$filter_products_range = $this->request->get['filter_products_range'];
		} else {
			$filter_products_range = 'all_time';
		}

		if (isset($this->request->get['filter_products_order_status'])) {
			$filter_products_order_status = explode('_', $this->request->get['filter_products_order_status']);
		} else {
			$filter_products_order_status = 0;
		}
		
		if (isset($this->request->get['sort_products'])) {
			$sort_products = $this->request->get['sort_products'];
		} else {
			$sort_products = 'quantity';
		}

		if (isset($this->request->get['order_products'])) {
			$order_products = $this->request->get['order_products'];
		} else {
			$order_products = 'DESC';
		}
				
		if (isset($this->request->get['page_products'])) {
			$page_products = $this->request->get['page_products'];
		} else {
			$page_products = 1;
		}
				
		$json['customer_product'] = array();
		
		$filter_data = array(
			'filter_products_date_start'	  	=> $filter_products_date_start, 
			'filter_products_date_end'	  		=> $filter_products_date_end, 
			'filter_products_range'	  	  		=> $filter_products_range, 
			'filter_products_order_status'	  	=> $filter_products_order_status,
			'sort_products'            			=> $sort_products,
			'order_products'           			=> $order_products,
			'start_products'           	  		=> ($page_products - 1) * $this->config->get('config_limit_admin'),
			'limit_products'           	  		=> $this->config->get('config_limit_admin')			
		);
		
		$this->load->model('customer/customer');
		$this->load->model('tool/image');
		
		$data['order_statuses'] = $this->model_customer_customer->getOrderStatuses(); 
		
		$customer_products_total = $this->model_customer_customer->getCustomerProductsTotal($filter_data, $this->request->get['customer_id']);
		$counter = 0;
		foreach ($customer_products_total as $total) {
			$counter += count(explode(',',$total['counter'],0));
		}
		$total = $counter;
			
		$customer_products = $this->model_customer_customer->getCustomerProducts($filter_data, $this->request->get['customer_id']);
		
		foreach ($customer_products as $product) {
			
			if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) {
				$image_product = $this->model_tool_image->resize($product['image'], 40, 40);
			} else {
				$image_product = $this->model_tool_image->resize('no_image.jpg', 40, 40);
			}
									
			$json['customer_product'][] = array(
				'product_id' 						=> $product['product_id'],	
				'product_id_url' 					=> $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true),
				'image'      						=> $image_product,
				'sku'    							=> $product['sku'],
				'model'    							=> $product['model'],
				'name'     							=> $product['name'],
				'product_option'    				=> html_entity_decode($product['product_option']),	
				'manufacturer'  					=> $product['manufacturer'],
				'categories'  						=> $product['categories'],
				'quantity' 							=> $product['quantity'],
				'total_excl_vat'  				  	=> $this->currency->format($product['total_excl_vat'], $this->config->get('config_currency')),
				'prod_tax'    						=> $this->currency->format($product['prod_tax'], $this->config->get('config_currency')),												
				'total_incl_vat'   				 	=> $this->currency->format($product['total_incl_vat'], $this->config->get('config_currency')),
				'product_order_ord_id'     			=> $product['product_order_ord_id'],
				'product_order_ord_idc'     		=> $product['product_order_ord_idc'],
				'product_order_date'    			=> $product['product_order_date'],
				'product_order_inv_no'     			=> $product['product_order_inv_no'],
				'product_order_shipping_method' 	=> strip_tags($product['product_order_shipping_method'], '<br>'),
				'product_order_payment_method'  	=> strip_tags($product['product_order_payment_method'], '<br>'),
				'product_order_status'  			=> $product['product_order_status'],
				'product_order_store'      			=> $product['product_order_store'],	
				'product_order_currency' 			=> $product['product_order_currency'],
				'product_order_price' 				=> $product['product_order_price'],
				'product_order_quantity' 			=> $product['product_order_quantity'],
				'product_order_total_excl_vat'  	=> $product['product_order_total_excl_vat'],				
				'product_order_tax'  				=> $product['product_order_tax'],				
				'product_order_total_incl_vat'  	=> $product['product_order_total_incl_vat'],
				'total_quantity' 					=> $product['total_quantity'],
				'total_total_excl_vat' 				=> $this->currency->format($product['total_total_excl_vat'], $this->config->get('config_currency')),
				'total_prod_tax' 					=> $this->currency->format($product['total_prod_tax'], $this->config->get('config_currency')),
				'total_total_incl_vat' 				=> $this->currency->format($product['total_total_incl_vat'], $this->config->get('config_currency'))
			);
		}

		$pagination_products = new Pagination();
		$pagination_products->total = $total;
		$pagination_products->page = $page_products;
		$pagination_products->limit = $this->config->get('config_limit_admin');
		$pagination_products->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_products={page}', true);
			
		$json['pagination_products'] = $pagination_products->render();
			
		$json['results_products'] = sprintf($this->language->get('text_pagination'), ($total) ? (($page_products - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_products - 1) * $this->config->get('config_limit_admin')) > ($total - $this->config->get('config_limit_admin'))) ? $total : ((($page_products - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total, ceil($total / $this->config->get('config_limit_admin')));
		
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	  }
	}
					
	public function filter_track() {
		$data['customer_id'] = isset($this->request->get['customer_id']);	
			
		if (isset($this->request->get['customer_id'])) {
		
			$json = array();

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

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

			if (isset($this->request->get['filter_end_date'])) {
				$filter_end_date = $this->request->get['filter_end_date'];
			} else {
				$filter_end_date = '';
			}
		
			$data['ranges'] = array();
		
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_custom'),
				'value' => 'custom',
				'style' => 'color:#666',
			);			
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_today'),
				'value' => 'today',
				'style' => 'color:#090',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_yesterday'),
				'value' => 'yesterday',
				'style' => 'color:#090',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_week'),
				'value' => 'week',
				'style' => 'color:#090',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_month'),
				'value' => 'month',
				'style' => 'color:#090',
			);					
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_quarter'),
				'value' => 'quarter',
				'style' => 'color:#090',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_year'),
				'value' => 'year',
				'style' => 'color:#090',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_current_week'),
				'value' => 'current_week',
				'style' => 'color:#06C',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_current_month'),
				'value' => 'current_month',
				'style' => 'color:#06C',
			);	
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_current_quarter'),
				'value' => 'current_quarter',
				'style' => 'color:#06C',
			);			
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_current_year'),
				'value' => 'current_year',
				'style' => 'color:#06C',
			);			
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_last_week'),
				'value' => 'last_week',
				'style' => 'color:#F90',
			);
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_last_month'),
				'value' => 'last_month',
				'style' => 'color:#F90',
			);	
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_last_quarter'),
				'value' => 'last_quarter',
				'style' => 'color:#F90',
			);			
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_last_year'),
				'value' => 'last_year',
				'style' => 'color:#F90',
			);			
			$data['ranges'][] = array(
				'text'  => $this->language->get('stat_all_time'),
				'value' => 'all_time',
				'style' => 'color:#F00',
			);
		
			if (isset($this->request->get['filter_range'])) {
				$filter_range = $this->request->get['filter_range'];
			} else {
				$filter_range = 'all_time'; //show All Time in Statistical Range by default
			}

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

			if (isset($this->request->get['order_track'])) {
				$order_track = $this->request->get['order_track'];
			} else {
				$order_track = 'DESC';
			}
				
			if (isset($this->request->get['page_track'])) {
				$page_track = $this->request->get['page_track'];
			} else {
				$page_track = 1;
			}
				
			$json['customer_track'] = array();
		
			$filter_data = array(
				'filter_range'			=>	$filter_range,
				'filter_start_date'		=>	$filter_start_date, 
				'filter_end_date'		=>	$filter_end_date,
				'sort_track'           	=>	$sort_track,
				'order_track'          	=>	$order_track,
				'start_track'          	=>	($page_track - 1) * $this->config->get('config_limit_admin'),
				'limit_track'          	=>	$this->config->get('config_limit_admin')					
			);
		
			$this->load->model('customer/customer');
		
			$customer_tracks_total = $this->model_customer_customer->getCustomerTrackTotal($filter_data, $this->request->get['customer_id']);
			
			$customer_tracks = $this->model_customer_customer->getCustomerTrack($filter_data, $this->request->get['customer_id']);

			foreach ($customer_tracks as $track) {
				$json['customer_track'][] = array(
					'ip_address'    			=> $track['ip_address'],
					'agent_type'    			=> $track['agent_type'],
					'route' 					=> $track['route'],
					'current_url'    			=> htmlspecialchars_decode($track['current_url']),					
					'referrer'    				=> htmlspecialchars_decode($track['referrer']),
					'visit_date'  				=> date($this->config->get('adveci_date_format') == 'DDMMYYYY' ? 'd/m/Y' : 'm/d/Y', strtotime($track['access_time'])),
					'visit_time'    			=> date($this->config->get('adveci_hour_format') == '24' ? 'H:i:s' : 'g:i:s A', strtotime($track['access_time']))
				);
			}
					
			$pagination_track = new Pagination();
			$pagination_track->total = $customer_tracks_total;
			$pagination_track->page = $page_track;
			$pagination_track->limit = $this->config->get('config_limit_admin');
			$pagination_track->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_track={page}', true);
			
			$json['pagination_track'] = $pagination_track->render();
			
			$json['results_track'] = sprintf($this->language->get('text_pagination'), ($customer_tracks_total) ? (($page_track - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_track - 1) * $this->config->get('config_limit_admin')) > ($customer_tracks_total - $this->config->get('config_limit_admin'))) ? $customer_tracks_total : ((($page_track - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_tracks_total, ceil($customer_tracks_total / $this->config->get('config_limit_admin')));
		
			$this->response->addHeader('Content-Type: application/json');
			$this->response->setOutput(json_encode($json));
	  	}
	}	
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
protected function getList() {
            ]]></search>
            <add position="after"><![CDATA[
		if (!$this->IsInstalled()) {		
			$this->session->data['error_eci'] = $this->language->get('error_installed');
			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));		
		}	
            ]]></add>
        </operation>		
        <operation>
            <search><![CDATA[
protected function getForm() {
            ]]></search>
            <add position="after"><![CDATA[
		if (!$this->IsInstalled()) {		
			$this->session->data['error_eci'] = $this->language->get('error_installed');
			$this->response->redirect($this->url->link('marketplace/extension', 'user_token=' . $this->session->data['user_token'] . '&type=module', true));		
		}

	   	$this->document->addScript('view/javascript/jquery/jquery.tmpl.min.js');
		$this->document->addScript('view/javascript/bootstrap/js/bootstrap-multiselect.js');
	   	$this->document->addStyle('view/javascript/bootstrap/css/bootstrap-multiselect.css');
		$this->document->addScript('view/javascript/bootstrap/js/bootstrap-select.min.js');
		$this->document->addStyle('view/javascript/bootstrap/css/bootstrap-select.css');
		$data['laccess'] = FALSE;
		if (!file_exists(DIR_CONFIG . 'include/adv_access.php')) {
			$this->response->redirect($this->url->link('extension/module/adv_extended_cust_info', 'user_token=' . $this->session->data['user_token'], true));
		}
		$data['adv_ext_name'] = $this->language->get('adv_ext_name');
		$data['adv_ext_short_name'] = 'adv_extended_cust_info';
		$data['adv_ext_version'] = $this->language->get('adv_ext_version');	
		$data['adv_ext_url'] = 'https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=3292';	
		include(DIR_CONFIG . 'include/adv_access.php');
		
		$data['customer_id'] = isset($this->request->get['customer_id']);	
			
		if (isset($this->request->get['customer_id'])) {
			$data['customer_id'] = $this->request->get['customer_id'];	
			$data['access_permission1'] = $this->user->hasPermission('modify', 'customer/customer');
			$data['access_permission2'] = $this->user->hasPermission('access', 'extension/module/adv_extended_cust_info');
			$data['url_product'] = $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=', true);

		if (isset($this->request->get['filter_orders_date_start'])) {
			$filter_orders_date_start = $this->request->get['filter_orders_date_start'];
		} else {
			$filter_orders_date_start = '';
		}
						
		if (isset($this->request->get['filter_orders_date_end'])) {
			$filter_orders_date_end = $this->request->get['filter_orders_date_end'];
		} else {
			$filter_orders_date_end = '';
		}
		
		$data['ranges_orders'] = array();
		
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_custom'),
			'value' => 'custom',
			'style' => 'color:#666',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_today'),
			'value' => 'today',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_yesterday'),
			'value' => 'yesterday',
			'style' => 'color:#090',
		);		
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_week'),
			'value' => 'week',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_month'),
			'value' => 'month',
			'style' => 'color:#090',
		);					
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_quarter'),
			'value' => 'quarter',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_year'),
			'value' => 'year',
			'style' => 'color:#090',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_week'),
			'value' => 'current_week',
			'style' => 'color:#06C',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_month'),
			'value' => 'current_month',
			'style' => 'color:#06C',
		);	
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_quarter'),
			'value' => 'current_quarter',
			'style' => 'color:#06C',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_current_year'),
			'value' => 'current_year',
			'style' => 'color:#06C',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_week'),
			'value' => 'last_week',
			'style' => 'color:#F90',
		);
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_month'),
			'value' => 'last_month',
			'style' => 'color:#F90',
		);	
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_quarter'),
			'value' => 'last_quarter',
			'style' => 'color:#F90',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_last_year'),
			'value' => 'last_year',
			'style' => 'color:#F90',
		);			
		$data['ranges_orders'][] = array(
			'text'  => $this->language->get('stat_all_time'),
			'value' => 'all_time',
			'style' => 'color:#F00',
		);
		
		if (isset($this->request->get['filter_orders_range'])) {
			$filter_orders_range = $this->request->get['filter_orders_range'];
		} else {
			$filter_orders_range = 'all_time';
		}

		if (isset($this->request->get['filter_orders_order_status'])) {
			$filter_orders_order_status = explode('_', $this->request->get['filter_orders_order_status']);
		} else {
			$filter_orders_order_status = 0;
		}
		
		if (isset($this->request->get['sort_orders'])) {
			$sort_orders = $this->request->get['sort_orders'];
		} else {
			$sort_orders = 'order_id';
		}

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

		$data['sort_orders'] = $sort_orders;
		$data['order_orders'] = $order_orders;
		$data['page_orders'] = $page_orders;
														
		$data['customer_order'] = array();
				
		$filter_data = array(
			'filter_orders_date_start'	  		=> $filter_orders_date_start, 
			'filter_orders_date_end'	  		=> $filter_orders_date_end, 
			'filter_orders_range'	  	  		=> $filter_orders_range, 
			'filter_orders_order_status'	  	=> $filter_orders_order_status,
			'sort_orders'            			=> $sort_orders,
			'order_orders'           			=> $order_orders,
			'start_orders'           	  		=> ($page_orders - 1) * $this->config->get('config_limit_admin'),
			'limit_orders'           	  		=> $this->config->get('config_limit_admin')	
		);

		$this->load->model('customer/customer');
					
		$data['order_statuses'] = $this->model_customer_customer->getOrderStatuses(); 
		
		$customer_orders_total = $this->model_customer_customer->getCustomerOrdersTotal($filter_data, $this->request->get['customer_id']);
		
		$customer_orders = $this->model_customer_customer->getCustomerOrders($filter_data, $this->request->get['customer_id']);

		foreach ($customer_orders as $order) {
				
			$data['customer_order'][] = array(
				'date_added' 			=> date($this->config->get('adveci_date_format') == 'DDMMYYYY' ? 'd/m/Y' : 'm/d/Y', strtotime($order['date_added'])),
				'order_id'    			=> $order['order_id'],
				'order_id_url' 			=> $this->url->link('sale/order/info', 'user_token=' . $this->session->data['user_token'] . '&order_id=' . $order['order_id'], true),
				'inv_no'     			=> $order['invoice_prefix'] . $order['invoice_no'],
				'shipping_method'     	=> strip_tags($order['shipping_method']),
				'payment_method'     	=> strip_tags($order['payment_method']),
				'os_name'     			=> $order['os_name'],												
				'store_name'    		=> $order['store_name'],
				'currency'     			=> $order['currency_code'],
				'products'    			=> $order['products'],						
				'sub_total'    			=> $this->currency->format($order['sub_total'], $order['currency_code'], $order['currency_value']),
				'shipping'    			=> $this->currency->format($order['shipping'], $order['currency_code'], $order['currency_value']),
				'tax'    				=> $this->currency->format($order['tax'], $order['currency_code'], $order['currency_value']),						
				'total'    				=> $this->currency->format($order['total'], $order['currency_code'], $order['currency_value']),												
				'total_products'   		=> $order['total_products'],	
				'total_sub_total'   	=> $this->currency->format($order['total_sub_total'], $order['currency_code'], $order['currency_value']),
				'total_shipping'   		=> $this->currency->format($order['total_shipping'], $order['currency_code'], $order['currency_value']),
				'total_tax'   			=> $this->currency->format($order['total_tax'], $order['currency_code'], $order['currency_value']),
				'total_value'   		=> $this->currency->format($order['total_value'], $order['currency_code'], $order['currency_value'])
			);
		}
		
		$url = '';

		if (isset($this->request->get['filter_orders_date_start'])) {
			$url .= '&filter_orders_date_start=' . $this->request->get['filter_orders_date_start'];
		}
		
		if (isset($this->request->get['filter_orders_date_end'])) {
			$url .= '&filter_orders_date_end=' . $this->request->get['filter_orders_date_end'];
		}
		
		if (isset($this->request->get['filter_orders_range'])) {
			$url .= '&filter_orders_range=' . $this->request->get['filter_orders_range'];
		}
		
		if (isset($this->request->get['filter_orders_order_status'])) {
			$url .= '&filter_orders_order_status=' . $this->request->get['filter_orders_order_status'];
		}
										
		if ($order_orders == 'ASC') {
			$url .= '&order_orders=DESC';
		} else {
			$url .= '&order_orders=ASC';
		}

		if (isset($this->request->get['page_orders'])) {
			$url .= '&page_orders=' . $this->request->get['page_orders'];
		}
								
		$data['sort_orders_order_id'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.order_id' . $url, true);
		$data['sort_orders_date_added'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.date_added' . $url, true);
		$data['sort_orders_inv_no'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=inv_number' . $url, true);
		$data['sort_orders_shipping_method'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.shipping_method' . $url, true);		
		$data['sort_orders_payment_method'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.payment_method' . $url, true);
		$data['sort_orders_order_status'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=os_name' . $url, true);		
		$data['sort_orders_store'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.store_name' . $url, true);
		$data['sort_orders_currency'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.currency_code' . $url, true);
		$data['sort_orders_quantity'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=products' . $url, true);		
		$data['sort_orders_sub_total'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=sub_total' . $url, true);
		$data['sort_orders_shipping'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=shipping' . $url, true);
		$data['sort_orders_tax'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=tax' . $url, true);
		$data['sort_orders_value'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_orders=o.total' . $url, true);

		$pagination_orders = new Pagination();
		$pagination_orders->total = $customer_orders_total;
		$pagination_orders->page = $page_orders;
		$pagination_orders->limit = $this->config->get('config_limit_admin');
		$pagination_orders->text = $this->language->get('text_pagination');
		$pagination_orders->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_orders={page}', true);
			
		$data['pagination_orders'] = $pagination_orders->render();

		$data['results_orders'] = sprintf($this->language->get('text_pagination'), ($customer_orders_total) ? (($page_orders - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_orders - 1) * $this->config->get('config_limit_admin')) > ($customer_orders_total - $this->config->get('config_limit_admin'))) ? $customer_orders_total : ((($page_orders - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_orders_total, ceil($customer_orders_total / $this->config->get('config_limit_admin')));
										
		$data['filter_orders_date_start'] = $filter_orders_date_start; 
		$data['filter_orders_date_end'] = $filter_orders_date_end; 		
		$data['filter_orders_range'] = $filter_orders_range; 
		$data['filter_orders_order_status'] = $filter_orders_order_status;	
		
		$data['sort_orders'] = $sort_orders;
		$data['order_orders'] = $order_orders;

			
		if (isset($this->request->get['filter_products_date_start'])) {
			$filter_products_date_start = $this->request->get['filter_products_date_start'];
		} else {
			$filter_products_date_start = '';
		}
						
		if (isset($this->request->get['filter_products_date_end'])) {
			$filter_products_date_end = $this->request->get['filter_products_date_end'];
		} else {
			$filter_products_date_end = '';
		}
		
		$data['ranges_products'] = array();
		
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_custom'),
			'value' => 'custom',
			'style' => 'color:#666',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_today'),
			'value' => 'today',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_yesterday'),
			'value' => 'yesterday',
			'style' => 'color:#090',
		);		
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_week'),
			'value' => 'week',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_month'),
			'value' => 'month',
			'style' => 'color:#090',
		);					
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_quarter'),
			'value' => 'quarter',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_year'),
			'value' => 'year',
			'style' => 'color:#090',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_week'),
			'value' => 'current_week',
			'style' => 'color:#06C',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_month'),
			'value' => 'current_month',
			'style' => 'color:#06C',
		);	
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_quarter'),
			'value' => 'current_quarter',
			'style' => 'color:#06C',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_current_year'),
			'value' => 'current_year',
			'style' => 'color:#06C',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_week'),
			'value' => 'last_week',
			'style' => 'color:#F90',
		);
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_month'),
			'value' => 'last_month',
			'style' => 'color:#F90',
		);	
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_quarter'),
			'value' => 'last_quarter',
			'style' => 'color:#F90',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_last_year'),
			'value' => 'last_year',
			'style' => 'color:#F90',
		);			
		$data['ranges_products'][] = array(
			'text'  => $this->language->get('stat_all_time'),
			'value' => 'all_time',
			'style' => 'color:#F00',
		);
		
		if (isset($this->request->get['filter_products_range'])) {
			$filter_products_range = $this->request->get['filter_products_range'];
		} else {
			$filter_products_range = 'all_time';
		}

		if (isset($this->request->get['filter_products_order_status'])) {
			$filter_products_order_status = explode('_', $this->request->get['filter_products_order_status']);
		} else {
			$filter_products_order_status = 0;
		}
		
		if (isset($this->request->get['sort_products'])) {
			$sort_products = $this->request->get['sort_products'];
		} else {
			$sort_products = 'quantity';
		}

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

		$data['sort_products'] = $sort_products;
		$data['order_products'] = $order_products;
		$data['page_products'] = $page_products;
														
		$data['customer_product'] = array();
				
		$filter_data = array(
			'filter_products_date_start'	  	=> $filter_products_date_start, 
			'filter_products_date_end'	  		=> $filter_products_date_end, 
			'filter_products_range'	  	  		=> $filter_products_range, 
			'filter_products_order_status'	  	=> $filter_products_order_status,
			'sort_products'            			=> $sort_products,
			'order_products'           			=> $order_products,
			'start_products'           	  		=> ($page_products - 1) * $this->config->get('config_limit_admin'),
			'limit_products'           	  		=> $this->config->get('config_limit_admin')	
		);

		$this->load->model('customer/customer');
		$this->load->model('tool/image');
					
		$data['order_statuses'] = $this->model_customer_customer->getOrderStatuses(); 
		
		$customer_products_total = $this->model_customer_customer->getCustomerProductsTotal($filter_data, $this->request->get['customer_id']);
		$counter = 0;
		foreach ($customer_products_total as $total) {
			$counter += count(explode(',',$total['counter'],0));
		}
		$total = $counter;
				
		$customer_products = $this->model_customer_customer->getCustomerProducts($filter_data, $this->request->get['customer_id']);

		foreach ($customer_products as $product) {
			
			if ($product['image'] && file_exists(DIR_IMAGE . $product['image'])) {
				$image_product = $this->model_tool_image->resize($product['image'], 40, 40);
			} else {
				$image_product = $this->model_tool_image->resize('no_image.jpg', 40, 40);
			}
			
			$data['customer_product'][] = array(
				'product_id' 						=> $product['product_id'],
				'product_id_url' 					=> $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product['product_id'], true),
				'image'      						=> $image_product,
				'sku'    							=> $product['sku'],
				'model'    							=> $product['model'],
				'name'     							=> $product['name'],
				'product_option'    				=> html_entity_decode($product['product_option']),	
				'manufacturer'  					=> $product['manufacturer'],
				'categories'  						=> $product['categories'],
				'quantity' 							=> $product['quantity'],
				'total_excl_vat'  				  	=> $this->currency->format($product['total_excl_vat'], $this->config->get('config_currency')),
				'prod_tax'    						=> $this->currency->format($product['prod_tax'], $this->config->get('config_currency')),												
				'total_incl_vat'   		 			=> $this->currency->format($product['total_incl_vat'], $this->config->get('config_currency')),
				'product_order_ord_id'     			=> $product['product_order_ord_id'],
				'product_order_ord_idc'     		=> $product['product_order_ord_idc'],
				'product_order_date'    			=> $product['product_order_date'],
				'product_order_inv_no'     			=> $product['product_order_inv_no'],
				'product_order_shipping_method' 	=> strip_tags($product['product_order_shipping_method'], '<br>'),
				'product_order_payment_method'  	=> strip_tags($product['product_order_payment_method'], '<br>'),
				'product_order_status'  			=> $product['product_order_status'],
				'product_order_store'      			=> $product['product_order_store'],	
				'product_order_currency' 			=> $product['product_order_currency'],
				'product_order_price' 				=> $product['product_order_price'],
				'product_order_quantity' 			=> $product['product_order_quantity'],
				'product_order_total_excl_vat'  	=> $product['product_order_total_excl_vat'],				
				'product_order_tax'  				=> $product['product_order_tax'],				
				'product_order_total_incl_vat'  	=> $product['product_order_total_incl_vat'],
				'total_quantity' 					=> $product['total_quantity'],
				'total_total_excl_vat' 				=> $this->currency->format($product['total_total_excl_vat'], $this->config->get('config_currency')),
				'total_prod_tax' 					=> $this->currency->format($product['total_prod_tax'], $this->config->get('config_currency')),
				'total_total_incl_vat' 				=> $this->currency->format($product['total_total_incl_vat'], $this->config->get('config_currency'))
			);
		}

		$url = '';

		if (isset($this->request->get['filter_products_date_start'])) {
			$url .= '&filter_products_date_start=' . $this->request->get['filter_products_date_start'];
		}
		
		if (isset($this->request->get['filter_products_date_end'])) {
			$url .= '&filter_products_date_end=' . $this->request->get['filter_products_date_end'];
		}
		
		if (isset($this->request->get['filter_products_range'])) {
			$url .= '&filter_products_range=' . $this->request->get['filter_products_range'];
		}
		
		if (isset($this->request->get['filter_products_order_status'])) {
			$url .= '&filter_products_order_status=' . $this->request->get['filter_products_order_status'];
		}
										
		if ($order_products == 'ASC') {
			$url .= '&order_products=DESC';
		} else {
			$url .= '&order_products=ASC';
		}

		if (isset($this->request->get['page_products'])) {
			$url .= '&page_products=' . $this->request->get['page_products'];
		}
								
		$data['sort_products_sku'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=sku' . $url, true);
		$data['sort_products_model'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=op.model' . $url, true);
		$data['sort_products_product'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=op.name' . $url, true);
		$data['sort_products_category'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=categories' . $url, true);
		$data['sort_products_manufacturer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=manufacturer' . $url, true);		
		$data['sort_products_quantity'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=quantity' . $url, true);
		$data['sort_products_total_excl_vat'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=total_excl_vat' . $url, true);
		$data['sort_products_prod_tax'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=prod_tax' . $url, true);		
		$data['sort_products_total_incl_vat'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_products=total_incl_vat' . $url, true);

		$pagination_products = new Pagination();
		$pagination_products->total = $total;
		$pagination_products->page = $page_products;
		$pagination_products->limit = $this->config->get('config_limit_admin');
		$pagination_products->text = $this->language->get('text_pagination');
		$pagination_products->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_products={page}', true);
			
		$data['pagination_products'] = $pagination_products->render();

		$data['results_products'] = sprintf($this->language->get('text_pagination'), ($total) ? (($page_products - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_products - 1) * $this->config->get('config_limit_admin')) > ($total - $this->config->get('config_limit_admin'))) ? $total : ((($page_products - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $total, ceil($total / $this->config->get('config_limit_admin')));
										
		$data['filter_products_date_start'] = $filter_products_date_start; 
		$data['filter_products_date_end'] = $filter_products_date_end; 		
		$data['filter_products_range'] = $filter_products_range; 
		$data['filter_products_order_status'] = $filter_products_order_status;	
		
		$data['sort_products'] = $sort_products;
		$data['order_products'] = $order_products;
		
		
		if (isset($this->request->get['filter_start_date'])) {
			$filter_start_date = $this->request->get['filter_start_date'];
		} else {
			$filter_start_date = '';
		}

		if (isset($this->request->get['filter_end_date'])) {
			$filter_end_date = $this->request->get['filter_end_date'];
		} else {
			$filter_end_date = '';
		}
	
		$data['ranges'] = array();
		
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_custom'),
			'value' => 'custom',
			'style' => 'color:#666',
		);			
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_today'),
			'value' => 'today',
			'style' => 'color:#090',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_yesterday'),
			'value' => 'yesterday',
			'style' => 'color:#090',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_week'),
			'value' => 'week',
			'style' => 'color:#090',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_month'),
			'value' => 'month',
			'style' => 'color:#090',
		);					
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_quarter'),
			'value' => 'quarter',
			'style' => 'color:#090',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_year'),
			'value' => 'year',
			'style' => 'color:#090',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_current_week'),
			'value' => 'current_week',
			'style' => 'color:#06C',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_current_month'),
			'value' => 'current_month',
			'style' => 'color:#06C',
		);	
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_current_quarter'),
			'value' => 'current_quarter',
			'style' => 'color:#06C',
		);			
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_current_year'),
			'value' => 'current_year',
			'style' => 'color:#06C',
		);			
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_last_week'),
			'value' => 'last_week',
			'style' => 'color:#F90',
		);
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_last_month'),
			'value' => 'last_month',
			'style' => 'color:#F90',
		);	
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_last_quarter'),
			'value' => 'last_quarter',
			'style' => 'color:#F90',
		);			
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_last_year'),
			'value' => 'last_year',
			'style' => 'color:#F90',
		);			
		$data['ranges'][] = array(
			'text'  => $this->language->get('stat_all_time'),
			'value' => 'all_time',
			'style' => 'color:#F00',
		);
		
		if (isset($this->request->get['filter_range'])) {
			$filter_range = $this->request->get['filter_range'];
		} else {
			$filter_range = 'all_time'; //show All Time in Statistical Range by default
		}

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

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

		$data['sort_track'] = $sort_track;
		$data['order_track'] = $order_track;
		$data['page_track'] = $page_track;
								
		$data['customer_track'] = array();	
					
		$filter_data = array(
			'filter_range'			=>	$filter_range,
			'filter_start_date'		=>	$filter_start_date, 
			'filter_end_date'		=>	$filter_end_date,
			'sort_track'           	=>	$sort_track,
			'order_track'          	=>	$order_track,
			'start_track'          	=>	($page_track - 1) * $this->config->get('config_limit_admin'),
			'limit_track'          	=>	$this->config->get('config_limit_admin')					
		);

		$this->load->model('customer/customer');
						
		$customer_tracks_total = $this->model_customer_customer->getCustomerTrackTotal($filter_data, $this->request->get['customer_id']);
			
		$customer_tracks = $this->model_customer_customer->getCustomerTrack($filter_data, $this->request->get['customer_id']); 
					
		foreach ($customer_tracks as $track) {
			$data['customer_track'][] = array(
				'ip_address'    			=> $track['ip_address'],
				'agent_type'    			=> $track['agent_type'],
				'route' 					=> $track['route'],
				'current_url'    			=> htmlspecialchars_decode($track['current_url']),					
				'referrer'    				=> htmlspecialchars_decode($track['referrer']),
				'visit_date'  				=> date($this->config->get('adveci_date_format') == 'DDMMYYYY' ? 'd/m/Y' : 'm/d/Y', strtotime($track['access_time'])),
				'visit_time'    			=> date($this->config->get('adveci_hour_format') == '24' ? 'H:i:s' : 'g:i:s A', strtotime($track['access_time']))
			);
		}
		
		$furl = '';

		if (isset($this->request->get['filter_start_date'])) {
			$furl .= '&filter_start_date=' . $this->request->get['filter_start_date'];
		}
		
		if (isset($this->request->get['filter_end_date'])) {
			$furl .= '&filter_end_date=' . $this->request->get['filter_end_date'];
		}
		
		if (isset($this->request->get['filter_range'])) {
			$furl .= '&filter_range=' . $this->request->get['filter_range'];
		}
										
		if ($order_track == 'ASC') {
			$furl .= '&order_track=DESC';
		} else {
			$furl .= '&order_track=ASC';
		}

		if (isset($this->request->get['page_track'])) {
			$furl .= '&page_track=' . $this->request->get['page_track'];
		}
								
		$data['sort_track_page'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_track=route' . $furl, true);
		$data['sort_track_url'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_track=current_url' . $furl, true);
		$data['sort_track_referrer'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_track=referrer' . $furl, true);
		$data['sort_track_visit'] = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&sort_track=access_time' . $furl, true);		
		
		$pagination_track = new Pagination();
		$pagination_track->total = $customer_tracks_total;
		$pagination_track->page = $page_track;
		$pagination_track->limit = $this->config->get('config_limit_admin');
		$pagination_track->url = $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . '&page_track={page}', true);
			
		$data['pagination_track'] = $pagination_track->render();
		
		$data['results_track'] = sprintf($this->language->get('text_pagination'), ($customer_tracks_total) ? (($page_track - 1) * $this->config->get('config_limit_admin')) + 1 : 0, ((($page_track - 1) * $this->config->get('config_limit_admin')) > ($customer_tracks_total - $this->config->get('config_limit_admin'))) ? $customer_tracks_total : ((($page_track - 1) * $this->config->get('config_limit_admin')) + $this->config->get('config_limit_admin')), $customer_tracks_total, ceil($customer_tracks_total / $this->config->get('config_limit_admin')));
								
		$data['filter_range'] = $filter_range;
		$data['filter_start_date'] = $filter_start_date;
		$data['filter_end_date'] = $filter_end_date;	
	
		$data['sort_track'] = $sort_track;
		$data['order_track'] = $order_track;
		$data['page_track'] = $page_track;
					

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

		if (isset($this->request->get['delete_wishlist'])) {
			$this->delete_wishlist();
		}
		
		$data['wishlist_products'] = array();		
		$cust_wishlists = $this->model_customer_customer->getCustomerWishList($this->request->get['customer_id']);
		$this->load->model('catalog/product');
		$this->load->model('tool/image');			
			
		foreach ($cust_wishlists as $cust_wishlist) {
		  $product_info = $this->model_catalog_product->getProduct($cust_wishlist['product_id']);
		  if ($product_info) {
		  
				if (isset($product_info['name'])) {
					if ($product_info['image']) {
						$image_wishlist = $this->model_tool_image->resize($product_info['image'], 40, 40);
					} else {
						$image_wishlist = $this->model_tool_image->resize('no_image.jpg', 40, 40);
					}	

			$special = false;

			$product_specials = $this->model_catalog_product->getProductSpecials($product_info['product_id']);

			foreach ($product_specials  as $product_special) {
				if (($product_special['date_start'] == '0000-00-00' || strtotime($product_special['date_start']) < time()) && ($product_special['date_end'] == '0000-00-00' || strtotime($product_special['date_end']) > time())) {
					$special = $product_special['price'];

					break;
				}
			}
									
					$data['wishlist_products'][] = array(
						'image'      			=> $image_wishlist,															   
						'product_name'			=> $product_info['name'],
						'product_sku'			=> $product_info['sku'],
						'product_model'			=> $product_info['model'],
						'product_price'			=> $this->currency->format($product_info['price'], $this->config->get('config_currency')),
						'product_special'    	=> $special,
						'product_id'			=> $product_info['product_id'],
						'product_id_url' 		=> $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_info['product_id'], true)
					);
				} else {
					$data['error_wishlist_product'] = $this->language->get('error_wishlist_product');
				}
		  } else {
			  $this->model_customer_customer->deleteCustomerWishList($this->request->get['customer_id']);
		  }	
		}
		
		if (isset($this->request->get['clear_cart'])) {
			$this->clear_cart();
		}
		
		$data['cart_products'] = array();		
		$cust_carts = $this->model_customer_customer->getCustomerCart($this->request->get['customer_id']);
		$this->load->model('tool/image');
			
		foreach ($cust_carts as $cust_cart) {
			$stock = true;
				
			$product_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "product_to_store p2s LEFT JOIN " . DB_PREFIX . "product p ON (p2s.product_id = p.product_id) LEFT JOIN " . DB_PREFIX . "product_description pd ON (p.product_id = pd.product_id) WHERE p2s.store_id = '" . (int)$this->config->get('config_store_id') . "' AND p2s.product_id = '" . (int)$cust_cart['product_id'] . "' AND pd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND p.date_available <= NOW() AND p.status = '1'");

			if ($product_query->num_rows && ($cust_cart['quantity'] > 0)) {		
				$option_price = 0;
				$option_data = array();
					foreach (json_decode($cust_cart['option']) as $product_option_id => $value) {
						$option_query = $this->db->query("SELECT po.product_option_id, po.option_id, od.name, o.type FROM " . DB_PREFIX . "product_option po LEFT JOIN `" . DB_PREFIX . "option` o ON (po.option_id = o.option_id) LEFT JOIN " . DB_PREFIX . "option_description od ON (o.option_id = od.option_id) WHERE po.product_option_id = '" . (int)$product_option_id . "' AND po.product_id = '" . (int)$cust_cart['product_id'] . "' AND od.language_id = '" . (int)$this->config->get('config_language_id') . "'");
						if ($option_query->num_rows) {
							if ($option_query->row['type'] == 'select' || $option_query->row['type'] == 'radio' || $option_query->row['type'] == 'image') {
								$option_value_query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$value . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
							
								if ($option_value_query->num_rows) {
									if ($option_value_query->row['price_prefix'] == '+') {
										$option_price += $option_value_query->row['price'];
									} elseif ($option_value_query->row['price_prefix'] == '-') {
										$option_price -= $option_value_query->row['price'];
									}
																	
									$option_data[] = array(
										'name'                    => $option_query->row['name'],
										'option_value'            => $option_value_query->row['name'],
										'price'                   => $option_value_query->row['price'],
										'price_prefix'            => $option_value_query->row['price_prefix']
									);
								}
							} elseif ($option_query->row['type'] == 'checkbox' && is_array($value)) {
								foreach ($value as $product_option_value_id) {
									$option_value_query = $this->db->query("SELECT pov.option_value_id, ovd.name, pov.quantity, pov.subtract, pov.price, pov.price_prefix, pov.points, pov.points_prefix, pov.weight, pov.weight_prefix FROM " . DB_PREFIX . "product_option_value pov LEFT JOIN " . DB_PREFIX . "option_value ov ON (pov.option_value_id = ov.option_value_id) LEFT JOIN " . DB_PREFIX . "option_value_description ovd ON (ov.option_value_id = ovd.option_value_id) WHERE pov.product_option_value_id = '" . (int)$product_option_value_id . "' AND pov.product_option_id = '" . (int)$product_option_id . "' AND ovd.language_id = '" . (int)$this->config->get('config_language_id') . "'");
									
									if ($option_value_query->num_rows) {
										if ($option_value_query->row['price_prefix'] == '+') {
											$option_price += $option_value_query->row['price'];
										} elseif ($option_value_query->row['price_prefix'] == '-') {
											$option_price -= $option_value_query->row['price'];
										}
																			
										$option_data[] = array(
											'name'                    => $option_query->row['name'],
											'option_value'            => $option_value_query->row['name'],
											'price'                   => $option_value_query->row['price'],
											'price_prefix'            => $option_value_query->row['price_prefix']
										);
									}
								}
							} elseif ($option_query->row['type'] == 'text' || $option_query->row['type'] == 'textarea' || $option_query->row['type'] == 'file' || $option_query->row['type'] == 'date' || $option_query->row['type'] == 'datetime' || $option_query->row['type'] == 'time') {
							
								$option_data[] = array(
									'name'                    => $option_query->row['name'],
									'option_value'            => $value,
									'price'                   => '',
									'price_prefix'            => ''
								);
							}
						}
					}
					
					$customer_info = $this->model_customer_customer->getCustomer($this->request->get['customer_id']);
					$price = $product_query->row['price'];
					
					// Product Discounts
					$discount_quantity = 0;

					$cust_cart_2_query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE customer_id = '" . $this->request->get['customer_id'] . "'");

					foreach ($cust_cart_2_query->rows as $cust_cart_2) {
						if ($cust_cart_2['product_id'] == $cust_cart['product_id']) {
							$discount_quantity += $cust_cart_2['quantity'];
						}
					}

					$product_discount_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_discount WHERE product_id = '" . (int)$cust_cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND quantity <= '" . (int)$discount_quantity . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY quantity DESC, priority ASC, price ASC LIMIT 1");

					if ($product_discount_query->num_rows) {
						$price = $product_discount_query->row['price'];
					}

					// Product Specials
					$product_special_query = $this->db->query("SELECT price FROM " . DB_PREFIX . "product_special WHERE product_id = '" . (int)$cust_cart['product_id'] . "' AND customer_group_id = '" . (int)$this->config->get('config_customer_group_id') . "' AND ((date_start = '0000-00-00' OR date_start < NOW()) AND (date_end = '0000-00-00' OR date_end > NOW())) ORDER BY priority ASC, price ASC LIMIT 1");

					if ($product_special_query->num_rows) {
						$price = $product_special_query->row['price'];
					}
					
					// Stock
					if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cust_cart['quantity'])) {
						$stock = false;
					}

					if (isset($product_query->row['name'])) {
						if ($product_query->row['image']) {
							$image_cart = $this->model_tool_image->resize($product_query->row['image'], 40, 40);
						} else {
							$image_cart = $this->model_tool_image->resize('no_image.jpg', 40, 40);
						}	

						$data['cart_products'][] = array(
							'image'      			=> $image_cart,
							'product_name'			=> $product_query->row['name'],
							'product_sku'			=> $product_query->row['sku'],
							'product_model'			=> $product_query->row['model'],						
							'product_id'			=> $product_query->row['product_id'],
							'product_id_url' 		=> $this->url->link('catalog/product/edit', 'user_token=' . $this->session->data['user_token'] . '&product_id=' . $product_query->row['product_id'], true),
							'product_options'		=> $option_data,
							'quantity'				=> $cust_cart['quantity'],
							'price'           		=> $this->currency->format(($price + $option_price), $this->config->get('config_currency')),
							'total'           		=> $this->currency->format(($price + $option_price) * $cust_cart['quantity'], $this->config->get('config_currency'))
						);
					} else {
						$data['error_cart_product'] = $this->language->get('error_cart_product');
					}
																				
				} else {
					$this->model_customer_customer->clearCustomerCart($this->request->get['customer_id']);
				}
		   }
		}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
protected function validateForm() {
            ]]></search>
            <add position="before"><![CDATA[
	public function delete_track() {
		$this->load->language('customer/customer');
		$this->load->model('customer/customer');
		$this->model_customer_customer->deleteCustomerTrack($this->request->get['customer_id']);
		$furl = '';
		$this->response->redirect($this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . $furl, true));
	}
	
  	public function clear_cart() {
		$this->load->language('customer/customer');
		$this->load->model('customer/customer');
		$this->model_customer_customer->clearCustomerCart($this->request->get['customer_id']);
		$curl = '';
		$this->response->redirect($this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . $curl, true));
	}
	
  	public function delete_wishlist() {
		$this->load->language('customer/customer');
		$this->load->model('customer/customer');
		$this->model_customer_customer->deleteCustomerWishList($this->request->get['customer_id']);
		$wurl = '';
		$this->response->redirect($this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $this->request->get['customer_id'] . $wurl, true));
	}	
	
	public function IsInstalled() {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "extension WHERE code = 'adv_extended_cust_info'");
		if (empty($query->num_rows)) {
			return false;
		}
		return true;
	}	
            ]]></add>
        </operation>
        <operation>
            <search index="1"><![CDATA[
$results = $this->model_customer_customer->getCustomers($filter_data);
            ]]></search>
            <add position="replace"><![CDATA[
$results = $this->model_customer_customer->getCustomersForAutocomplete($filter_data);
            ]]></add>
        </operation>					
	</file>

	<file path="admin/controller/extension/extension/module.php">
        <operation>
            <search><![CDATA[
$extensions = $this->model_setting_extension->getInstalled('module');
            ]]></search>
            <add position="before"><![CDATA[
		if (isset($this->session->data['error_eci'])) {
			$data['error_warning'] = $this->session->data['error_eci'];

			unset($this->session->data['error_eci']);
		}
            ]]></add>
        </operation>
	</file>
	
	<file path="admin/language/*/customer/customer.php">
        <operation>
            <search><![CDATA[
<?php
            ]]></search>
            <add position="after"><![CDATA[
$_['adv_ext_name']						= 'ADV Extended Customer Information';
$_['adv_ext_version']					= '3.0';			
$_['text_confirm_reset']	  			= 'Delete track for this customer?\nAre you sure?';
$_['text_confirm_wdelete']	  			= 'Delete wishlist for this customer?\nAre you sure?';
$_['text_confirm_cdelete']	  			= 'Delete shopping cart for this customer?\nAre you sure?';
$_['text_clear_cart']		  			= 'Clear Cart';
$_['text_clear_wishlist']	  			= 'Clear Wishlist';
$_['button_delete_track']		  		= 'Delete Track';

$_['column_order_order_id']           	= 'Order ID';
$_['column_order_date_added']         	= 'Date Added';
$_['column_order_inv_no']       	    = 'Invoice No.';
$_['column_order_shipping_method']    	= 'Shipping Method';
$_['column_order_payment_method']     	= 'Payment Method';
$_['column_order_status']       		= 'Status';
$_['column_order_store']     		    = 'Store';
$_['column_order_currency']    			= 'Currency';
$_['column_order_quantity']     		= 'Products';
$_['column_order_sub_total']      		= 'Sub-Total';
$_['column_order_shipping']      		= 'Shipping';
$_['column_order_tax']        			= 'Taxes';
$_['column_order_value']        		= 'Order Total';
$_['column_total_value']      			= 'Total Value';
$_['column_total_orders']     			= 'Orders';
$_['column_quantity']         			= 'Quantity';
$_['column_image'] 			  			= 'Image';
$_['column_sku']              			= 'SKU';
$_['column_model']            			= 'Model';
$_['column_product']          			= 'Product Name';
$_['column_product_options'] 			= 'Product Options';
$_['column_category'] 		  			= 'Category';
$_['column_manufacturer'] 	  			= 'Manufacturer';
$_['column_prod_price'] 				= 'Price';
$_['column_prod_quantity'] 				= 'Quantity';
$_['column_prod_total_excl_vat']		= 'Total excl. Tax';
$_['column_prod_tax']        			= 'Tax';
$_['column_prod_total_incl_vat']		= 'Total incl. Tax';
$_['column_unit_price']        			= 'Unit Price';
$_['column_prod_total']        			= 'Total';
$_['column_route']    		  			= 'Page';
$_['column_ip_address']    	  			= 'IP Address<br><span style="font-size:10px;">(Browser Used)</span>';
$_['column_current_url'] 	  			= 'Page URL';
$_['column_referrer'] 	  				= '<span style="color:#999;">Referrer Site</span>';
$_['column_access_date']      			= 'Visit Date';
$_['column_access_time']      			= 'Click Time';
$_['column_cust_totals']       	  		= 'Totals:';

$_['text_all']   						= '&nbsp;-- Select All --';
$_['text_all_status']   				= 'All Statuses';
$_['text_selected']      	  			= 'All Selected';

$_['tab_order_history']    				= 'Order History';
$_['tab_purchased_products']   			= 'Purchased Products';
$_['tab_cart']  		  	  			= 'Shopping Cart';
$_['tab_wishlist']  		  			= 'Wishlist';
$_['tab_customer_track']  	  			= 'Customer Track';

$_['entry_range']		  				= 'Statistical Range:';
$_['entry_date_start']		  			= 'Date Start:';
$_['entry_date_end']		  			= 'Date End:';
$_['entry_order_status']     			= 'Order Status:';
$_['entry_note']     					= 'Note';

$_['stat_custom']       				= 'Custom (use date range)';
$_['stat_today']         				= 'Today';
$_['stat_yesterday']         			= 'Yesterday';
$_['stat_week']         				= 'Week (today -7 days)';
$_['stat_month']        				= 'Month (today -30 days)';
$_['stat_quarter']      				= 'Quarter (today -91 days)';
$_['stat_year']         				= 'Year (today -365 days)';
$_['stat_current_week']        			= 'Current Week (monday to today)';
$_['stat_current_month']        		= 'Current Month (from 1st to today)';
$_['stat_current_quarter']        		= 'Current Quarter (current term)';
$_['stat_current_year']        			= 'Current Year (1st Jan to today)';
$_['stat_last_week']        			= 'Last Week (monday to sunday)';
$_['stat_last_month']        			= 'Last Month (from 1st to 31st)';
$_['stat_last_quarter']        			= 'Last Quarter (last term)';
$_['stat_last_year']        			= 'Last Year (1st Jan to 31st Dec)';
$_['stat_all_time']         			= 'All Time';

$_['error_cart_product']	  			= 'Warning: There is a product in your customer\'s cart that is no longer in your product list!';
$_['error_wishlist_product']  			= 'Warning: There is a product in your customer\'s wishlist that is no longer in your product list!';
$_['error_installed']       			= 'ADV Extended Customer Information is not installed!';
            ]]></add>
        </operation>
	</file>

	<file path="admin/model/catalog/product.php">
        <operation>
            <search><![CDATA[
public function getProductRelated($product_id) {
            ]]></search>
            <add position="before"><![CDATA[
	public function getProductManufacturers($manufacturer_id) {
		$product_manufacturer_data = array();
		
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "manufacturer WHERE manufacturer_id = '" . (int)$manufacturer_id . "'");
		
		foreach ($query->rows as $result) {
			$product_manufacturer_data[] = $result['manufacturer_id'];
		}

		return $product_manufacturer_data;
	}
            ]]></add>
        </operation>
	</file>

	<file path="admin/model/customer/customer.php">
        <operation>
            <search><![CDATA[
class ModelCustomerCustomer extends Model {
            ]]></search>
            <add position="after"><![CDATA[
	public function getCustomerOrders($data = array(), $customer_id) {		
		$user_token = $this->session->data['user_token'];
		
		if (isset($data['filter_orders_date_start']) && $data['filter_orders_date_start']) {
			$date_start = $data['filter_orders_date_start'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_orders_date_end']) && $data['filter_orders_date_end']) {
			$date_end = $data['filter_orders_date_end'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_orders_range'])) {
			$range_orders = $data['filter_orders_range'];
		} else {
			$range_orders = 'all_time';
		}
		
		switch($range_orders) 
		{
			case 'custom';
				$date_start = "DATE(date_added) >= '" . $this->db->escape($data['filter_orders_date_start']) . "'";
				$date_end = " AND DATE(date_added) <= '" . $this->db->escape($data['filter_orders_date_end']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(date_added) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(date_added) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(date_added) < CURDATE()";
				break;					
			case 'week';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";	
				break;			
			case 'month';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(date_added) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = " AND MONTH(date_added) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(date_added) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(date_added) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(date_added) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';				
				break;					
			case 'last_year';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;	
		}

		$date = ' AND (' . $date_start . $date_end . ')';

		$order_status = '';
		if (!empty($data['filter_orders_order_status'])) {
			$order_status = " AND (";
			$implode = array();
			foreach ($data['filter_orders_order_status'] as $filter_orders_order_status) {
				$implode[] = "o.order_status_id = '" . (int)$filter_orders_order_status . "'";
			}

			if ($implode) {
				$order_status .= implode(" OR ", $implode) . "";
			}
			$order_status .= ")";
		} else {
		$order_status = ' AND o.order_status_id > 0';
		}

		$sql = "SELECT *, 
		CONCAT(o.invoice_prefix, ' ', o.invoice_no) AS inv_number, 
		(SELECT SUM(op.quantity) FROM `" . DB_PREFIX . "order_product` op WHERE op.order_id = o.order_id GROUP BY op.order_id) AS products, 
		(SELECT SUM(ot.value) FROM `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'sub_total' GROUP BY ot.order_id) AS sub_total, 
		(SELECT SUM(ot.value) FROM `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'shipping' GROUP BY ot.order_id) AS shipping, 
		(SELECT SUM(ROUND(ot.value, 2)) FROM `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'tax' GROUP BY ot.order_id) AS tax, 
		(SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "') AS os_name, 
		(SELECT SUM(op.quantity) FROM `" . DB_PREFIX . "order` o, `" . DB_PREFIX . "order_product` op WHERE op.order_id = o.order_id AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . " GROUP BY o.customer_id) AS total_products, 
		(SELECT SUM(ot.value) FROM `" . DB_PREFIX . "order` o, `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'sub_total' AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . " GROUP BY o.customer_id) AS total_sub_total, 
		(SELECT SUM(ot.value) FROM `" . DB_PREFIX . "order` o, `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'shipping' AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . " GROUP BY o.customer_id) AS total_shipping, 
		(SELECT SUM(ot.value) FROM `" . DB_PREFIX . "order` o, `" . DB_PREFIX . "order_total` ot WHERE ot.order_id = o.order_id AND ot.code = 'tax' AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . " GROUP BY o.customer_id) AS total_tax, 
		(SELECT SUM(o.total) FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = '" . $customer_id . "'" . $date . $order_status . " GROUP BY o.customer_id) AS total_value 
		
		FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = '" . $customer_id . "'" . $date . $order_status;
		
		$sql .= " GROUP BY o.order_id";
		
		$sort_data = array(
			'o.order_id',
			'o.date_added',
			'inv_number',
			'o.shipping_method',
			'o.payment_method',
			'os_name',
			'o.store_name',
			'o.currency_code',			
			'products',
			'sub_total',												
			'shipping',
			'tax',
			'o.total'
		);	
			
		if (isset($data['sort_orders']) && in_array($data['sort_orders'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort_orders'];	
		} else {
			$sql .= " ORDER BY order_id";	
		}
			
		if (isset($data['order_orders']) && ($data['order_orders'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}
					
		if (isset($data['start_orders']) || isset($data['limit_orders'])) {
			if ($data['start_orders'] < 0) {
				$data['start_orders'] = 0;
			}				

			if ($data['limit_orders'] < 1) {
				$data['limit_orders'] = 20;
			}	
		
			$sql .= " LIMIT " . (int)$data['start_orders'] . "," . (int)$data['limit_orders'];
		}
		
		$query = $this->db->query($sql);
		
		return $query->rows;
	}	

	public function getCustomerOrdersTotal($data = array(), $customer_id) {
		if (isset($data['filter_orders_date_start']) && $data['filter_orders_date_start']) {
			$date_start = $data['filter_orders_date_start'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_orders_date_end']) && $data['filter_orders_date_end']) {
			$date_end = $data['filter_orders_date_end'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_orders_range'])) {
			$range_orders = $data['filter_orders_range'];
		} else {
			$range_orders = 'all_time';
		}
		
		switch($range_orders) 
		{
			case 'custom';
				$date_start = "DATE(date_added) >= '" . $this->db->escape($data['filter_orders_date_start']) . "'";
				$date_end = " AND DATE(date_added) <= '" . $this->db->escape($data['filter_orders_date_end']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(date_added) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(date_added) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(date_added) < CURDATE()";
				break;					
			case 'week';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";	
				break;			
			case 'month';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(date_added) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = " AND MONTH(date_added) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(date_added) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(date_added) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(date_added) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';				
				break;					
			case 'last_year';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;	
		}

		$sql = "SELECT COUNT(o.order_id) AS total FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = '" . (int)$customer_id . "'";

		if (!empty($data['filter_orders_order_status'])) {
			$sql .= " AND (";
			$implode = array();
			foreach ($data['filter_orders_order_status'] as $filter_orders_order_status) {
				$implode[] = "o.order_status_id = '" . (int)$filter_orders_order_status . "'";
			}

			if ($implode) {
				$sql .= implode(" OR ", $implode) . "";
			}
			$sql .= ")";
		} else {
			$sql .= " AND o.order_status_id > '0'";
		}
				
		$sql .= ' AND (' . $date_start . $date_end . ')';
				
		$query = $this->db->query($sql);
		
		return $query->row['total'];
	}

	public function getCustomerProducts($data = array(), $customer_id) {
		$query = $this->db->query("SET SESSION group_concat_max_len=500000");
		$user_token = $this->session->data['user_token'];
		
		if (isset($data['filter_products_date_start']) && $data['filter_products_date_start']) {
			$date_start = $data['filter_products_date_start'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_products_date_end']) && $data['filter_products_date_end']) {
			$date_end = $data['filter_products_date_end'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_products_range'])) {
			$range_products = $data['filter_products_range'];
		} else {
			$range_products = 'all_time';
		}
		
		switch($range_products) 
		{
			case 'custom';
				$date_start = "DATE(date_added) >= '" . $this->db->escape($data['filter_products_date_start']) . "'";
				$date_end = " AND DATE(date_added) <= '" . $this->db->escape($data['filter_products_date_end']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(date_added) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(date_added) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(date_added) < CURDATE()";
				break;					
			case 'week';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";	
				break;			
			case 'month';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(date_added) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = " AND MONTH(date_added) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(date_added) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(date_added) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(date_added) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';				
				break;					
			case 'last_year';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;	
		}

		$date = ' AND (' . $date_start . $date_end . ')';

		$order_status = '';
		if (!empty($data['filter_products_order_status'])) {
			$order_status = " AND (";
			$implode = array();
			foreach ($data['filter_products_order_status'] as $filter_products_order_status) {
				$implode[] = "o.order_status_id = '" . (int)$filter_products_order_status . "'";
			}

			if ($implode) {
				$order_status .= implode(" OR ", $implode) . "";
			}
			$order_status .= ")";
		} else {
		$order_status = ' AND o.order_status_id > 0';
		}

		$sql = "SELECT 
		(SELECT p.image FROM `" . DB_PREFIX . "product` p WHERE op.product_id = p.product_id) AS image, 
		(SELECT p.sku FROM `" . DB_PREFIX . "product` p WHERE op.product_id = p.product_id) AS sku, 
		op.product_id, 
		op.order_product_id, 
		op.model, 		
		op.name, 
		(SELECT GROUP_CONCAT(CONCAT(oo.name,': ',oo.value) SEPARATOR '<br>') FROM `" . DB_PREFIX . "order_option` oo WHERE op.order_product_id = oo.order_product_id AND (oo.type != 'textarea' OR oo.type != 'file' OR oo.type != 'date' OR oo.type != 'datetime' OR oo.type != 'time') ORDER BY op.order_product_id) AS product_option,  
		(SELECT GROUP_CONCAT(cd.name SEPARATOR ', ') FROM `" . DB_PREFIX . "category_description` cd, `" . DB_PREFIX . "category` c, `" . DB_PREFIX . "product_to_category` p2c WHERE op.product_id = p2c.product_id AND p2c.category_id = c.category_id AND (c.category_id = cd.category_id OR c.parent_id = cd.category_id) AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c.status > 0) AS categories, 
		(SELECT m.name FROM `" . DB_PREFIX . "manufacturer` m, `" . DB_PREFIX . "product` p WHERE p.manufacturer_id = m.manufacturer_id AND op.product_id = p.product_id) AS manufacturer, 
		SUM(op.quantity) AS quantity, 
		SUM(op.total) AS total_excl_vat, 
		SUM(op.tax*op.quantity) AS prod_tax, 
		SUM(op.total+(op.tax*op.quantity)) AS total_incl_vat, 
		GROUP_CONCAT('<a href=\"index.php?route=sale/order/info&user_token=$user_token&order_id=',op.order_id,'\">',op.order_id,'</a>' ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_ord_id, 
		GROUP_CONCAT(op.order_id ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_ord_idc, ";
		if ($this->config->get('adveci_date_format') == 'DDMMYYYY') {																																																																																																																																																																																																																																												   			
			$sql .= "GROUP_CONCAT(DATE_FORMAT(o.date_added, '%d/%m/%Y') ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_date, ";
		} else {	
			$sql .= "GROUP_CONCAT(DATE_FORMAT(o.date_added, '%m/%d/%Y') ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_date, ";
		}
		$sql .= "GROUP_CONCAT(IFNULL(o.invoice_prefix,'&nbsp;&nbsp;'),IFNULL(o.invoice_no,'&nbsp;&nbsp;') ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_inv_no, 
		GROUP_CONCAT(IF (o.shipping_method = '','&nbsp;&nbsp;',o.shipping_method) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_shipping_method, 
		GROUP_CONCAT(IF (o.payment_method = '','&nbsp;&nbsp;',o.payment_method) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_payment_method, 
		GROUP_CONCAT(IFNULL((SELECT os.name FROM `" . DB_PREFIX . "order_status` os WHERE os.order_status_id = o.order_status_id AND os.language_id = '" . (int)$this->config->get('config_language_id') . "'),'&nbsp;&nbsp;') ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_status, 
 		GROUP_CONCAT(o.store_name ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_store, 
		GROUP_CONCAT(o.currency_code ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_currency, 
		GROUP_CONCAT(ROUND(o.currency_value*op.price, 2) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_price, 
		GROUP_CONCAT(op.quantity ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_quantity, 
		GROUP_CONCAT(ROUND(o.currency_value*op.total, 2) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_total_excl_vat, 
		GROUP_CONCAT(ROUND(o.currency_value*op.tax*op.quantity, 2) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_tax, 
		GROUP_CONCAT(ROUND(o.currency_value*(op.total+(op.tax*op.quantity)), 2) ORDER BY op.order_id DESC SEPARATOR '<br>') AS product_order_total_incl_vat, 
		(SELECT SUM(op.quantity) FROM `" . DB_PREFIX . "order_product` op, `" . DB_PREFIX . "order` o WHERE op.order_id = o.order_id AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . ") AS total_quantity, 
		(SELECT SUM(op.total) FROM `" . DB_PREFIX . "order_product` op, `" . DB_PREFIX . "order` o WHERE op.order_id = o.order_id AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . ") AS total_total_excl_vat, 
		(SELECT SUM(op.tax*op.quantity) FROM `" . DB_PREFIX . "order_product` op, `" . DB_PREFIX . "order` o WHERE op.order_id = o.order_id AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . ") AS total_prod_tax, 
		(SELECT SUM(op.total+(op.tax*op.quantity)) FROM `" . DB_PREFIX . "order_product` op, `" . DB_PREFIX . "order` o WHERE op.order_id = o.order_id AND o.customer_id = '" . $customer_id . "'" . $date . $order_status . ") AS total_total_incl_vat 
		
		FROM `" . DB_PREFIX . "order` o INNER JOIN `" . DB_PREFIX . "order_product` op ON (o.order_id = op.order_id) LEFT JOIN (SELECT oo.order_product_id, GROUP_CONCAT(oo.name, oo.value, oo.type ORDER BY oo.name, oo.value, oo.type) AS options FROM `" . DB_PREFIX . "order_option` oo WHERE (type != 'textarea' OR type != 'file' OR type != 'date' OR type != 'datetime' OR type != 'time') GROUP BY oo.order_product_id) qa ON (op.order_product_id = qa.order_product_id) WHERE o.customer_id = '" . $customer_id . "'" . $date . $order_status;
		
		$sql .= " GROUP BY op.product_id, options";
		
		$sort_data = array(
			'sku',
			'op.model',
			'op.name',
			'categories',
			'manufacturer',
			'quantity',
			'total_excl_vat',
			'prod_tax',			
			'total_incl_vat'
		);	

		if (isset($data['sort_products']) && in_array($data['sort_products'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort_products'];	
		} else {
			$sql .= " ORDER BY quantity";	
		}
			
		if (isset($data['order_products']) && ($data['order_products'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}
					
		if (isset($data['start_products']) || isset($data['limit_products'])) {
			if ($data['start_products'] < 0) {
				$data['start_products'] = 0;
			}				

			if ($data['limit_products'] < 1) {
				$data['limit_products'] = 20;
			}	
		
			$sql .= " LIMIT " . (int)$data['start_products'] . "," . (int)$data['limit_products'];
		}
		
		$query = $this->db->query($sql);
		
		return $query->rows;
	}	

	public function getCustomerProductsTotal($data = array(), $customer_id) {
		if (isset($data['filter_products_date_start']) && $data['filter_products_date_start']) {
			$date_start = $data['filter_products_date_start'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_products_date_end']) && $data['filter_products_date_end']) {
			$date_end = $data['filter_products_date_end'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_products_range'])) {
			$range_products = $data['filter_products_range'];
		} else {
			$range_products = 'all_time';
		}
		
		switch($range_products) 
		{
			case 'custom';
				$date_start = "DATE(date_added) >= '" . $this->db->escape($data['filter_products_date_start']) . "'";
				$date_end = " AND DATE(date_added) <= '" . $this->db->escape($data['filter_products_date_end']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(date_added) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(date_added) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(date_added) < CURDATE()";
				break;					
			case 'week';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";	
				break;			
			case 'month';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(date_added) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = " AND MONTH(date_added) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(date_added) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(date_added) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(date_added) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(date_added) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(date_added) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';				
				break;					
			case 'last_year';
				$date_start = "DATE(date_added) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(date_added) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(date_added) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(date_added) <= DATE (NOW())";						
				break;	
		}

		$sql = "SELECT *, op.product_id AS counter FROM `" . DB_PREFIX . "order` o INNER JOIN `" . DB_PREFIX . "order_product` op ON (o.order_id = op.order_id) LEFT JOIN (SELECT oo.order_product_id, GROUP_CONCAT(oo.name, oo.value, oo.type ORDER BY oo.name, oo.value, oo.type) AS options FROM `" . DB_PREFIX . "order_option` oo WHERE (type != 'textarea' OR type != 'file' OR type != 'date' OR type != 'datetime' OR type != 'time') GROUP BY oo.order_product_id) qa ON (op.order_product_id = qa.order_product_id) WHERE o.customer_id = '" . (int)$customer_id . "'";

		if (!empty($data['filter_products_order_status'])) {
			$sql .= " AND (";
			$implode = array();
			foreach ($data['filter_products_order_status'] as $filter_products_order_status) {
				$implode[] = "o.order_status_id = '" . (int)$filter_products_order_status . "'";
			}

			if ($implode) {
				$sql .= implode(" OR ", $implode) . "";
			}
			$sql .= ")";
		} else {
			$sql .= " AND o.order_status_id > '0'";
		}
				
		$sql .= ' AND (' . $date_start . $date_end . ')';
		
		$sql .= " GROUP BY counter, options";
				
		$query = $this->db->query($sql);
		
		return $query->rows;
	}
				
	public function getCustomerTrack($data = array(), $customer_id) {		
		if (isset($data['filter_start_date']) && $data['filter_start_date']) {
			$date_start = $data['filter_start_date'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_end_date']) && $data['filter_end_date']) {
			$date_end = $data['filter_end_date'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_range'])) {
			$range = $data['filter_range'];
		} else {
			$range = 'all_time'; //show All Time in Statistical Range by default
		}

		switch($range) 
		{
			case 'custom';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape($data['filter_start_date']) . "'";
				$date_end = " AND DATE(ct.access_time) <= '" . $this->db->escape($data['filter_end_date']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(ct.access_time) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(ct.access_time) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(ct.access_time) < CURDATE()";
				break;
			case 'week';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";	
				break;
			case 'month';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(ct.access_time) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(ct.access_time) = YEAR(CURDATE())";
				$date_end = " AND MONTH(ct.access_time) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(ct.access_time) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(ct.access_time) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(ct.access_time) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(ct.access_time) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(ct.access_time) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(ct.access_time) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(ct.access_time) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(ct.access_time) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';
				break;					
			case 'last_year';
				$date_start = "DATE(ct.access_time) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(ct.access_time) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";						
				break;	
		}
				
		$sql = "SELECT ct.route, ct.ip_address, ct.customer_id, ct.current_url, ct.referrer, ct.agent_type, ct.access_time FROM `" . DB_PREFIX . "customer_track` ct LEFT OUTER JOIN `" . DB_PREFIX . "customer` cus ON ct.customer_id = cus.customer_id WHERE ct.customer_id = '" . $customer_id . "'";
		
		$sql .= ' AND (' . $date_start . $date_end . ')';
		
		$sort_data = array(
			'route',
			'current_url',
			'referrer',											
			'access_time'
		);	
			
		if (isset($data['sort_track']) && in_array($data['sort_track'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort_track'];	
		} else {
			$sql .= " ORDER BY access_time";	
		}
			
		if (isset($data['order_track']) && ($data['order_track'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}
					
		if (isset($data['start_track']) || isset($data['limit_track'])) {
			if ($data['start_track'] < 0) {
				$data['start_track'] = 0;
			}				

			if ($data['limit_track'] < 1) {
				$data['limit_track'] = 20;
			}	
		
			$sql .= " LIMIT " . (int)$data['start_track'] . "," . (int)$data['limit_track'];
		}
		
		$query = $this->db->query($sql);
	
		return $query->rows;
	}	

	public function getCustomerTrackTotal($data = array(), $customer_id) {		
		if (isset($data['filter_start_date']) && $data['filter_start_date']) {
			$date_start = $data['filter_start_date'];
		} else {
			$date_start = '';
		}

		if (isset($data['filter_end_date']) && $data['filter_end_date']) {
			$date_end = $data['filter_end_date'];
		} else {
			$date_end = '';
		}

		if (isset($data['filter_range'])) {
			$range = $data['filter_range'];
		} else {
			$range = 'all_time'; //show All Time in Statistical Range by default
		}

		switch($range) 
		{
			case 'custom';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape($data['filter_start_date']) . "'";
				$date_end = " AND DATE(ct.access_time) <= '" . $this->db->escape($data['filter_end_date']) . "'";				
				break;
			case 'today';
				$date_start = "DATE(ct.access_time) = CURDATE()";
				$date_end = '';
				break;
			case 'yesterday';
				$date_start = "DATE(ct.access_time) >= DATE_ADD(CURDATE(), INTERVAL -1 DAY)";
				$date_end = " AND DATE(ct.access_time) < CURDATE()";
				break;
			case 'week';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-7 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";	
				break;
			case 'month';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-30 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";					
				break;			
			case 'quarter';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-91 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";						
				break;
			case 'year';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d', strtotime('-365 day'))) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";					
				break;
			case 'current_week';
				$date_start = "DATE(ct.access_time) >= CURDATE() - WEEKDAY(CURDATE())";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";			
				break;	
			case 'current_month';
				$date_start = "YEAR(ct.access_time) = YEAR(CURDATE())";
				$date_end = " AND MONTH(ct.access_time) = MONTH(CURDATE())";			
				break;
			case 'current_quarter';
				$date_start = "QUARTER(ct.access_time) = QUARTER(CURDATE())";
				$date_end = " AND YEAR(ct.access_time) = YEAR(CURDATE())";					
				break;					
			case 'current_year';
				$date_start = "YEAR(ct.access_time) = YEAR(CURDATE())";
				$date_end = '';			
				break;					
			case 'last_week';
				$date_start = "DATE(ct.access_time) >= CURDATE() - INTERVAL DAYOFWEEK(CURDATE())+5 DAY";
				$date_end = " AND DATE(ct.access_time) < CURDATE() - INTERVAL DAYOFWEEK(CURDATE())-2 DAY";				
				break;	
			case 'last_month';
				$date_start = "DATE(ct.access_time) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 MONTH, '%Y/%m/01')";
				$date_end = " AND DATE(ct.access_time) < DATE_FORMAT(CURRENT_DATE, '%Y/%m/01')";				
				break;
			case 'last_quarter';
				$date_start = "QUARTER(ct.access_time) = QUARTER(DATE_ADD(NOW(), INTERVAL -3 MONTH))";
				$date_end = '';
				break;					
			case 'last_year';
				$date_start = "DATE(ct.access_time) >= DATE_FORMAT(CURRENT_DATE - INTERVAL 1 YEAR, '%Y/01/01')";
				$date_end = " AND DATE(ct.access_time) < DATE_FORMAT(CURRENT_DATE, '%Y/01/01')";				
				break;					
			case 'all_time';
				$date_start = "DATE(ct.access_time) >= '" . $this->db->escape(date('Y-m-d','0')) . "'";
				$date_end = " AND DATE(ct.access_time) <= DATE (NOW())";						
				break;	
		}
				
		$sql = "SELECT COUNT(ct.access_time) AS total FROM `" . DB_PREFIX . "customer_track` ct LEFT OUTER JOIN `" . DB_PREFIX . "customer` cus ON ct.customer_id = cus.customer_id WHERE ct.customer_id = '" . $customer_id . "'";
		
		$sql .= ' AND (' . $date_start . $date_end . ')';
		
		$query = $this->db->query($sql);
		
		return $query->row['total'];
	}
	
	public function deleteCustomerTrack($customer_id) {
		$this->db->query("DELETE FROM `" . DB_PREFIX . "customer_track` WHERE customer_id = '" . (int)$customer_id . "'");
	}

	public function getCustomerCart($customer_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "cart WHERE customer_id = '" . (int)$customer_id . "'");
		return $query->rows;
	}

	public function clearCustomerCart($customer_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "cart WHERE customer_id = '" . (int)$customer_id . "'");
	}
	
	public function getCustomerWishList($customer_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "'");
		return $query->rows;
	}

	public function deleteCustomerWishList($customer_id) {
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_wishlist WHERE customer_id = '" . (int)$customer_id . "'");
	}
	
	public function getOrderStatuses($data = array()) {
		$query = $this->db->query("SELECT DISTINCT os.name, os.order_status_id FROM `" . DB_PREFIX . "order_status` os WHERE os.language_id = '" . (int)$this->config->get('config_language_id') . "' ORDER BY LCASE(os.name) ASC");
		
		return $query->rows;	
	}
	
	public function getOrderOptions($order_product_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "order_option WHERE order_product_id = '" . (int)$order_product_id . "'");

		return $query->rows;
	}			
            ]]></add>
        </operation>
			
        <operation>
            <search><![CDATA[
$sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (c.customer_group_id = cgd.customer_group_id)";
            ]]></search>
            <add position="replace"><![CDATA[
$sql = "SELECT c.*, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group";
if ($this->config->get('adveci_order_value_status')) {
	if ($this->config->get('adveci_clist_orders_status') == '1') {
		$sql .= ", (SELECT COUNT(o.order_id) FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = c.customer_id AND o.order_status_id IN (" . implode(",", $this->config->get('adveci_order_value_status')) . ") GROUP BY o.customer_id) AS total_orders";
	} 
	if ($this->config->get('adveci_clist_total_value_status') == '1') {
		$sql .= ", (SELECT SUM(o.total) FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = c.customer_id AND o.order_status_id IN (" . implode(",", $this->config->get('adveci_order_value_status')) . ") GROUP BY o.customer_id) AS total_value";
	} 	
} else {
	if ($this->config->get('adveci_clist_orders_status') == '1') {
		$sql .= ", (SELECT COUNT(o.order_id) FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = c.customer_id AND o.order_status_id > 0 GROUP BY o.customer_id) AS total_orders";
	} 
	if ($this->config->get('adveci_clist_total_value_status') == '1') {
		$sql .= ", (SELECT SUM(o.total) FROM `" . DB_PREFIX . "order` o WHERE o.customer_id = c.customer_id AND o.order_status_id > 0 GROUP BY o.customer_id) AS total_value";
	} 	
}
$sql .= " FROM " . DB_PREFIX . "customer c, " . DB_PREFIX . "customer_group_description cgd";
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
$sql .= " WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
            ]]></search>
            <add position="replace" index="1"><![CDATA[
		$sql .= " WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c.customer_group_id = cgd.customer_group_id";
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
'c.date_added'
            ]]></search>
            <add position="replace"><![CDATA[
			'c.date_added',
			'total_orders',
			'total_value'					
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
public function getCustomers($data = array()) {
            ]]></search>
            <add position="before"><![CDATA[
	public function getCustomersForAutocomplete($data = array()) {
		$sql = "SELECT *, CONCAT(c.firstname, ' ', c.lastname) AS name, cgd.name AS customer_group FROM " . DB_PREFIX . "customer c LEFT JOIN " . DB_PREFIX . "customer_group_description cgd ON (c.customer_group_id = cgd.customer_group_id)";
		
		if (!empty($data['filter_affiliate'])) {
			$sql .= " LEFT JOIN " . DB_PREFIX . "customer_affiliate ca ON (c.customer_id = ca.customer_id)";
		}		
		
		$sql .= " WHERE cgd.language_id = '" . (int)$this->config->get('config_language_id') . "'";

		$implode = array();

		if (!empty($data['filter_name'])) {
			$implode[] = "CONCAT(c.firstname, ' ', c.lastname) LIKE '%" . $this->db->escape($data['filter_name']) . "%'";
		}

		if (!empty($data['filter_email'])) {
			$implode[] = "c.email LIKE '" . $this->db->escape($data['filter_email']) . "%'";
		}

		if (isset($data['filter_newsletter']) && !is_null($data['filter_newsletter'])) {
			$implode[] = "c.newsletter = '" . (int)$data['filter_newsletter'] . "'";
		}

		if (!empty($data['filter_customer_group_id'])) {
			$implode[] = "c.customer_group_id = '" . (int)$data['filter_customer_group_id'] . "'";
		}

		if (!empty($data['filter_affiliate'])) {
			$implode[] = "ca.status = '" . (int)$data['filter_affiliate'] . "'";
		}
		
		if (!empty($data['filter_ip'])) {
			$implode[] = "c.customer_id IN (SELECT customer_id FROM " . DB_PREFIX . "customer_ip WHERE ip = '" . $this->db->escape($data['filter_ip']) . "')";
		}

		if (isset($data['filter_status']) && $data['filter_status'] !== '') {
			$implode[] = "c.status = '" . (int)$data['filter_status'] . "'";
		}

		if (!empty($data['filter_date_added'])) {
			$implode[] = "DATE(c.date_added) = DATE('" . $this->db->escape($data['filter_date_added']) . "')";
		}

		if ($implode) {
			$sql .= " AND " . implode(" AND ", $implode);
		}

		$sort_data = array(
			'name',
			'c.email',
			'customer_group',
			'c.status',
			'c.ip',
			'c.date_added'
		);

		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort'];
		} else {
			$sql .= " ORDER BY name";
		}

		if (isset($data['order']) && ($data['order'] == 'DESC')) {
			$sql .= " DESC";
		} else {
			$sql .= " ASC";
		}

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

		$query = $this->db->query($sql);

		return $query->rows;
	}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
$customer_id = $this->db->getLastId();
            ]]></search>
            <add position="after"><![CDATA[
		if ($data['note']) {
			$this->db->query("INSERT INTO " . DB_PREFIX . "customer_note SET customer_id = '" . (int)$customer_id . "', note = '" . $this->db->escape($data['note']) . "'");
		}
            ]]></add>
        </operation>	
        <operation>
            <search><![CDATA[
if ($data['password']) {
            ]]></search>
            <add position="before"><![CDATA[
		if ($data['note']) {
			$this->db->query("UPDATE " . DB_PREFIX . "customer_note SET note = '" . $this->db->escape($data['note']) . "' WHERE customer_id = '" . (int)$customer_id . "'");
		}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
$this->db->query("DELETE FROM " . DB_PREFIX . "customer_ip WHERE customer_id = '" . (int)$customer_id . "'");
            ]]></search>
            <add position="after"><![CDATA[
		$this->db->query("DELETE FROM " . DB_PREFIX . "customer_note WHERE customer_id = '" . (int)$customer_id . "'");
            ]]></add>
        </operation>	
        <operation>
            <search><![CDATA[
public function getCustomer($customer_id) {
            ]]></search>
            <add position="before"><![CDATA[
	public function getCustomerNote($customer_id) {
		$query = $this->db->query("SELECT DISTINCT * FROM " . DB_PREFIX . "customer_note WHERE customer_id = '" . (int)$customer_id . "'");

		return $query->row;
	}
            ]]></add>
        </operation>			
	</file>
		
	<file path="admin/view/template/customer/customer_form.twig">
        <operation>
            <search><![CDATA[
<label class="col-sm-2 control-label" for="input-safe">{{ entry_safe }}</label>
            ]]></search>
            <add position="after" offset="12"><![CDATA[
		  {% if access_permission2 and laccess %}	
                      <div class="form-group">
                        <label class="col-sm-2 control-label" for="input-note">{{ entry_note }}</label>
                        <div class="col-sm-10">
                          <textarea name="note" placeholder="{{ entry_note }}" id="input-note" class="form-control" />{{ note }}</textarea>
                        </div>
                      </div>
		  {% endif %}
            ]]></add>
        </operation>			
        <operation>
            <search><![CDATA[
<li><a href="#tab-history" data-toggle="tab">{{ tab_history }}</a></li>
            ]]></search>
            <add position="before"><![CDATA[
		  {% if access_permission2 and laccess %}	
		  <li><a href="#tab_order_history" data-toggle="tab"><span style="color:#0C0;">{{ tab_order_history }}</span></a></li>
		  <li><a href="#tab_purchased_products" data-toggle="tab"><span style="color:#0C0;">{{ tab_purchased_products }}</span></a></li>
		  <li><a href="#tab_cart" data-toggle="tab"><span style="color:#0C0;">{{ tab_cart }}</span></a></li>
		  <li><a href="#tab_wishlist" data-toggle="tab"><span style="color:#0C0;">{{ tab_wishlist }}</span></a></li>
		  <li><a href="#tab_customer_track" data-toggle="tab"><span style="color:#0C0;">{{ tab_customer_track }}</span></a></li>
		  {% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[		
<div class="tab-pane" id="tab-history">
            ]]></search>
            <add position="before"><![CDATA[
{% if access_permission2 and laccess %}		
		<div class="tab-pane" id="tab_order_history">	
<style type="text/css">
.list_main_orders {
	border-collapse: collapse;
	width: 100%;
	border-top: 1px solid #DDDDDD;
	border-left: 1px solid #DDDDDD;	
	margin-bottom: 20px;
}
.list_main_orders td {
	border-right: 1px solid #DDDDDD;
	border-bottom: 1px solid #DDDDDD;	
}
.list_main_orders thead td {
	background-color: #f5f5f5;
	padding: 0px 5px;
}
.list_main_orders thead td a, .list_main_orders thead td {
	text-decoration: none;
	color: #222222;
	font-weight: bold;	
}
.list_main_orders tbody td {
	vertical-align: middle;
	padding: 0px 5px;
}
.list_main_orders .left {
	text-align: left;
	padding: 7px;
}
.list_main_orders .right {
	text-align: right;
	padding: 7px;
}
.list_main_orders .center {
	text-align: center;
	padding: 3px;
}
.list_main_orders a.asc:after {
	content: " \f107";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_orders a.desc:after {
	content: " \f106";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_orders .noresult {
	text-align: center;
	padding: 7px;
}

.btn-select {
	background-color: #fcfcfc;
	border: 1px solid #CCC;
}
.btn-group-ms {
	width: 100%;
	height: 35px;	
}
.btn-group-ms > .multiselect.btn {
	width: 100%;
	height: 35px;	
}
.multiselect ul {
	width: 100%;
	height: 35px;	
}
.oloading {
	position: absolute;
	width: 100%;
	height: 100%;
	z-index: 9999;
	background: url('view/image/adv_reports/page_loading.gif') 50% 25% no-repeat rgba(255,255,255,0.9);
}
</style> 
<div class="oloading"></div>
<input type="hidden" id="page_orders" value="{{ page_orders }}">
<input type="hidden" id="sort_orders" value="{{ sort_orders }}">
<input type="hidden" id="order_orders" value="{{ order_orders }}">
<script type="text/javascript">
$(document).ready(function() {
var $filter_orders_range = $('#filter_orders_range'), $date_start = $('#date-start-orders'), $date_end = $('#date-end-orders');
$filter_orders_range.change(function () {
    if ($filter_orders_range.val() == 'custom') {
        $date_start.removeAttr('disabled');
        $date_end.removeAttr('disabled');
    } else {	
        $date_start.prop('disabled', 'disabled').val('');
        $date_end.prop('disabled', 'disabled').val('');
    }
}).trigger('change');
});
</script>	
<div class="well">
    <div class="row">
      <div class="col-lg-6" style="padding-bottom:5px;">	  
        <div class="row">
          <div class="col-sm-6" style="padding-bottom:5px;">
		  <label class="control-label" for="filter_orders_range">{{ entry_range }}</label>
            <select name="filter_orders_range" id="filter_orders_range" data-style="btn-select" class="form-control select">
              {% for range_orders in ranges_orders %}
              {% if range_orders.value == filter_orders_range %}
              <option value="{{ range_orders.value }}" title="{{ range_orders.text }}" style="{{ range_orders.style }}" selected="selected">{{ range_orders.text }}</option>
              {% else %}
              <option value="{{ range_orders.value }}" title="{{ range_orders.text }}" style="{{ range_orders.style }}">{{ range_orders.text }}</option>
              {% endif %}
              {% endfor %}
            </select></div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="date-start-orders">{{ entry_date_start }}</label>
            <input type="text" name="filter_orders_date_start" value="{{ filter_orders_date_start }}" data-date-format="YYYY-MM-DD" id="date-start-orders" class="form-control" style="color:#F90;" />
		  </div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="date-end-orders">{{ entry_date_end }}</label>
            <input type="text" name="filter_orders_date_end" value="{{ filter_orders_date_end }}" data-date-format="YYYY-MM-DD" id="date-end-orders" class="form-control" style="color:#F90;" />
          </div>
        </div>
	  </div>   
      <div class="col-lg-3" style="padding-bottom:5px;">
	  <label class="control-label" for="orders_order_status">{{ entry_order_status }}</label>
            <select name="filter_orders_order_status" id="orders_order_status" class="form-control" multiple="multiple" size="1">		
            {% for order_status in order_statuses %}
            {% if 'order_status.order_status_id' in filter_orders_order_status %}
            <option value="{{ order_status.order_status_id }}" selected="selected">{{ order_status.name }}</option>
            {% else %}
            <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>
            {% endif %}
            {% endfor %}
          </select></div>		  
    </div> 
</div>		
			<div class="table-responsive">		
			<table class="list_main_orders">
			<thead id="head_orders">
			<tr>			
          	<td class="left">{% if sort_orders == 'order_id' %}
                <a href="{{ sort_orders_order_id }}" class="{{ order_orders|lower }}">{{ column_order_order_id }}</a>
                {% else %}
                <a href="{{ sort_orders_order_id }}">{{ column_order_order_id }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_orders == 'date_added' %}
                <a href="{{ sort_orders_date_added }}" class="{{ order_orders|lower }}">{{ column_order_date_added }}</a>
                {% else %}
                <a href="{{ sort_orders_date_added }}">{{ column_order_date_added }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_orders == 'inv_number' %}
                <a href="{{ sort_orders_inv_no }}" class="{{ order_orders|lower }}">{{ column_order_inv_no }}</a>
                {% else %}
                <a href="{{ sort_orders_inv_no }}">{{ column_order_inv_no }}</a>
                {% endif %}</td> 
          	<td class="left">{% if sort_orders == 'shipping_method' %}
                <a href="{{ sort_orders_shipping_method }}" class="{{ order_orders|lower }}">{{ column_order_shipping_method }}</a>
                {% else %}
                <a href="{{ sort_orders_shipping_method }}">{{ column_order_shipping_method }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_orders == 'payment_method' %}
                <a href="{{ sort_orders_payment_method }}" class="{{ order_orders|lower }}">{{ column_order_payment_method }}</a>
                {% else %}
                <a href="{{ sort_orders_payment_method }}">{{ column_order_payment_method }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_orders == 'os_name' %}
                <a href="{{ sort_orders_order_status }}" class="{{ order_orders|lower }}">{{ column_order_status }}</a>
                {% else %}
                <a href="{{ sort_orders_order_status }}">{{ column_order_status }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_orders == 'store_name' %}
                <a href="{{ sort_orders_store }}" class="{{ order_orders|lower }}">{{ column_order_store }}</a>
                {% else %}
                <a href="{{ sort_orders_store }}">{{ column_order_store }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_orders == 'currency_code' %}
                <a href="{{ sort_orders_currency }}" class="{{ order_orders|lower }}">{{ column_order_currency }}</a>
                {% else %}
                <a href="{{ sort_orders_currency }}">{{ column_order_currency }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_orders == 'products' %}
                <a href="{{ sort_orders_quantity }}" class="{{ order_orders|lower }}">{{ column_order_quantity }}</a>
                {% else %}
                <a href="{{ sort_orders_quantity }}">{{ column_order_quantity }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_orders == 'sub_total' %}
                <a href="{{ sort_orders_sub_total }}" class="{{ order_orders|lower }}">{{ column_order_sub_total }}</a>
                {% else %}
                <a href="{{ sort_orders_sub_total }}">{{ column_order_sub_total }}</a>
                {% endif %}</td>
          	<td class="right">{% if sort_orders == 'shipping' %}
                <a href="{{ sort_orders_shipping }}" class="{{ order_orders|lower }}">{{ column_order_shipping }}</a>
                {% else %}
                <a href="{{ sort_orders_shipping }}">{{ column_order_shipping }}</a>
                {% endif %}</td>
          	<td class="right">{% if sort_orders == 'tax' %}
                <a href="{{ sort_orders_tax }}" class="{{ order_orders|lower }}">{{ column_order_tax }}</a>
                {% else %}
                <a href="{{ sort_orders_tax }}">{{ column_order_tax }}</a>
                {% endif %}</td>
          	<td class="right">{% if sort_orders == 'value' %}
                <a href="{{ sort_orders_value }}" class="{{ order_orders|lower }}">{{ column_order_value }}</a>
                {% else %}
                <a href="{{ sort_orders_value }}">{{ column_order_value }}</a>
                {% endif %}</td>
			</tr>
			</thead>
			<tbody>
            {% if customer_order %}
			  {% for order in customer_order %}
			<tr>
          		<td class="left"><a href="{{ order.order_id_url }}">{{ order.order_id }}</a></td>
				<td class="left">{{ order.date_added }}</td>  
                <td class="left">{{ order.inv_no}}</td> 
                <td class="left">{{ order.shipping_method }}</td>
                <td class="left">{{ order.payment_method }}</td>
                <td class="left">{{ order.os_name }}</td>								
                <td class="left">{{ order.store_name }}</td>
                <td class="right">{{ order.currency }}</td>				
                <td class="right">{{ order.products }}</td>
                <td class="right" nowrap="nowrap">{{ order.sub_total }}</td>
                <td class="right" nowrap="nowrap">{{ order.shipping }}</td>
                <td class="right" nowrap="nowrap">{{ order.tax }}</td>												
				<td class="right" nowrap="nowrap">{{ order.total }}</td>                    
				</tr>               
              {% endfor %}
              <tr>
                <td class="right" colspan="8"><b>{{ column_cust_totals }}</b></td>
                <td class="right" nowrap="nowrap"><b>{{ order.total_products }}</b></td> 
                <td class="right" nowrap="nowrap"><b>{{ order.total_sub_total }}</b></td> 
                <td class="right" nowrap="nowrap"><b>{{ order.total_shipping }}</b></td> 
                <td class="right" nowrap="nowrap"><b>{{ order.total_tax }}</b></td> 
                <td class="right" nowrap="nowrap"><b>{{ order.total_value }}</b></td>              
              </tr>   
            {% else %}
              <tr>
                <td class="center" colspan="13">{{ text_no_results }}</td>
              </tr>
            {% endif %}
            </tbody>
			</table>
			</div>
			<div class="row">
			<div class="col-sm-6 text-left" id="pagination_orders">{{ pagination_orders }}</div>
        	<div class="col-sm-6 text-right" id="pagination_orders_count">{{ results_orders }}</div>
			</div>				
		</div>
<script id="ordersTemplate" type="text/x-jquery-tmpl">
        <tr>
          <td class="left"><a href="${order_id_url}">${order_id}</a></td>
		  <td class="left">${date_added}</td>
		  <td class="left">${inv_no}</td>
          <td class="left">${shipping_method}</td>
		  <td class="left">${payment_method}</td>
		  <td class="left">${os_name}</td>
		  <td class="left">${store_name}</td>
		  <td class="right">${currency}</td>
		  <td class="right">${products}</td>
		  <td class="right" nowrap="nowrap">${sub_total}</td>
		  <td class="right" nowrap="nowrap">${shipping}</td>
		  <td class="right" nowrap="nowrap">${tax}</td>
		  <td class="right" nowrap="nowrap">${total}</td>
        </tr>		
</script>
<script id="orders_totalTemplate" type="text/x-jquery-tmpl">
		<tr style="border-top:2px solid #CCC;">
		  <td colspan="8" class="right" style="font-weight:bold;">{{ column_cust_totals }}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_products}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_sub_total}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_shipping}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_tax}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_value}</td>
        </tr>		
</script>	
	 
		<div class="tab-pane" id="tab_purchased_products">
<style type="text/css">
.list_main_products {
	border-collapse: collapse;
	width: 100%;
	border-top: 1px solid #DDDDDD;
	border-left: 1px solid #DDDDDD;	
	margin-bottom: 20px;
}
.list_main_products td {
	border-right: 1px solid #DDDDDD;
	border-bottom: 1px solid #DDDDDD;	
}
.list_main_products thead td {
	background-color: #f5f5f5;
	padding: 0px 5px;
}
.list_main_products thead td a, .list_main_products thead td {
	text-decoration: none;
	color: #222222;
	font-weight: bold;	
}
.list_main_products tbody td {
	vertical-align: middle;
	padding: 0px 5px;
}
.list_main_products .left {
	text-align: left;
	padding: 7px;
}
.list_main_products .right {
	text-align: right;
	padding: 7px;
}
.list_main_products .center {
	text-align: center;
	padding: 3px;
}
.list_main_products a.asc:after {
	content: " \f107";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_products a.desc:after {
	content: " \f106";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_products .noresult {
	text-align: center;
	padding: 7px;
}

.list_detail_products {
	border-collapse: collapse;
	width: 100%;
	border-top: 1px solid #DDDDDD;
	border-left: 1px solid #DDDDDD;
	margin-top: 10px;
	margin-bottom: 10px;
}
.list_detail_products td {
	border-right: 1px solid #DDDDDD;
	border-bottom: 1px solid #DDDDDD;
}
.list_detail_products thead td {
	background-color: #f5f5f5;
	padding: 0px 3px;
	font-size: 11px;
	font-weight: bold;
}
.list_detail_products tbody td {
	padding: 0px 3px;
	font-size: 11px;	
}
.list_detail_products .left {
	text-align: left;
	padding: 3px;
}
.list_detail_products .right {
	text-align: right;
	padding: 3px;
}
.list_detail_products .center {
	text-align: center;
	padding: 3px;
}

.btn-select {
	background-color: #fcfcfc;
	border: 1px solid #CCC;
}
.btn-group-ms {
	width: 100%;
	height: 35px;	
}
.btn-group-ms > .multiselect.btn {
	width: 100%;
	height: 35px;	
}
.multiselect ul {
	width: 100%;
	height: 35px;	
}
.ploading {
	position: absolute;
	width: 100%;
	height: 100%;
	z-index: 9999;
	background: url('view/image/adv_reports/page_loading.gif') 50% 25% no-repeat rgba(255,255,255,0.9);
}
</style> 
<div class="ploading"></div>
<input type="hidden" id="page_products" value="{{ page_products }}">
<input type="hidden" id="sort_products" value="{{ sort_products }}">
<input type="hidden" id="order_products" value="{{ order_products }}">
<script type="text/javascript">
$(document).ready(function() {
var $filter_products_range = $('#filter_products_range'), $date_start = $('#date-start-products'), $date_end = $('#date-end-products');
$filter_products_range.change(function () {
    if ($filter_products_range.val() == 'custom') {
        $date_start.removeAttr('disabled');
        $date_end.removeAttr('disabled');
    } else {	
        $date_start.prop('disabled', 'disabled').val('');
        $date_end.prop('disabled', 'disabled').val('');
    }
}).trigger('change');
});
</script>	
<div class="well">
    <div class="row">
      <div class="col-lg-6" style="padding-bottom:5px;">	  
        <div class="row">
          <div class="col-sm-6" style="padding-bottom:5px;">
		  <label class="control-label" for="filter_products_range">{{ entry_range }}</label>
            <select name="filter_products_range" id="filter_products_range" data-style="btn-select" class="form-control select">
              {% for range_products in ranges_products %}
              {% if range_products.value == filter_products_range %}
              <option value="{{ range_products.value }}" title="{{ range_products.text }}" style="{{ range_products.style }}" selected="selected">{{ range_products.text }}</option>
              {% else %}
              <option value="{{ range_products.value }}" title="{{ range_products.text }}" style="{{ range_products.style }}">{{ range_products.text }}</option>
              {% endif %}
              {% endfor %}
            </select></div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="date-start-products">{{ entry_date_start }}</label>
            <input type="text" name="filter_products_date_start" value="{{ filter_products_date_start }}" data-date-format="YYYY-MM-DD" id="date-start-products" class="form-control" style="color:#F90;" />
		  </div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="date-end-products">{{ entry_date_end }}</label>
            <input type="text" name="filter_products_date_end" value="{{ filter_products_date_end }}" data-date-format="YYYY-MM-DD" id="date-end-products" class="form-control" style="color:#F90;" />
          </div>
        </div>
	  </div>   
      <div class="col-lg-3" style="padding-bottom:5px;">
	  <label class="control-label" for="products_order_status">{{ entry_order_status }}</label>
            <select name="filter_products_order_status" id="products_order_status" class="form-control" multiple="multiple" size="1">		
            {% for order_status in order_statuses %}
            {% if 'order_status.order_status_id' in filter_products_order_status %}
            <option value="{{ order_status.order_status_id }}" selected="selected">{{ order_status.name }}</option>
            {% else %}
            <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>
            {% endif %}
            {% endfor %}
          </select></div>		  
    </div> 
</div>		
			<div class="table-responsive">		
			<table class="list_main_products">
			<thead id="head_products">
			<tr>			
          	<td class="center">{{ column_image }}</a></td>
          	<td class="left">{% if sort_products == 'sku' %}
                <a href="{{ sort_products_sku }}" class="{{ order_products|lower }}">{{ column_sku }}</a>
                {% else %}
                <a href="{{ sort_products_sku }}">{{ column_sku }}</a>
                {% endif %}</td> 
          	<td class="left">{% if sort_products == 'model' %}
                <a href="{{ sort_products_model }}" class="{{ order_products|lower }}">{{ column_model }}</a>
                {% else %}
                <a href="{{ sort_products_model }}">{{ column_model }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_products == 'product' %}
                <a href="{{ sort_products_product }}" class="{{ order_products|lower }}">{{ column_product }}</a>
                {% else %}
                <a href="{{ sort_products_product }}">{{ column_product }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_products == 'category' %}
                <a href="{{ sort_products_category }}" class="{{ order_products|lower }}">{{ column_category }}</a>
                {% else %}
                <a href="{{ sort_products_category }}">{{ column_category }}</a>
                {% endif %}</td>
          	<td class="left">{% if sort_products == 'manufacturer' %}
                <a href="{{ sort_products_manufacturer }}" class="{{ order_products|lower }}">{{ column_manufacturer }}</a>
                {% else %}
                <a href="{{ sort_products_manufacturer }}">{{ column_manufacturer }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_products == 'quantity' %}
                <a href="{{ sort_products_quantity }}" class="{{ order_products|lower }}">{{ column_prod_quantity }}</a>
                {% else %}
                <a href="{{ sort_products_quantity }}">{{ column_prod_quantity }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_products == 'total_excl_vat' %}
                <a href="{{ sort_products_total_excl_vat }}" class="{{ order_products|lower }}">{{ column_prod_total_excl_vat }}</a>
                {% else %}
                <a href="{{ sort_products_total_excl_vat }}">{{ column_prod_total_excl_vat }}</a>
                {% endif %}</td>	
          	<td class="right">{% if sort_products == 'prod_tax' %}
                <a href="{{ sort_products_prod_tax }}" class="{{ order_products|lower }}">{{ column_prod_tax }}</a>
                {% else %}
                <a href="{{ sort_products_prod_tax }}">{{ column_prod_tax }}</a>
                {% endif %}</td>
          	<td class="right">{% if sort_products == 'total_incl_vat' %}
                <a href="{{ sort_products_total_incl_vat }}" class="{{ order_products|lower }}">{{ column_prod_total_incl_vat }}</a>
                {% else %}
                <a href="{{ sort_products_total_incl_vat }}">{{ column_prod_total_incl_vat }}</a>
                {% endif %}</td>
			</tr>
			</thead>
 			<tbody>
            {% if customer_product %}		
			{% for product in customer_product %}
				<tr>
            	<td class="center"><img src="{{ product.image }}" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
                <td class="left">{{ product.sku }}</td>
                <td class="left">{{ product.model }}</td>                
                <td class="left"><a href="{{ product.product_id_url }}">{{ product.name }}</a><br/><span style="font-size:11px;">{{ product.product_option }}</span></td>
          		<td class="left">{{ product.categories }}</td>
          		<td class="left">{{ product.manufacturer }}</td>              
				<td class="right">{{ product.quantity }}</td>
				<td class="right" nowrap="nowrap">{{ product.total_excl_vat }}</td>
				<td class="right" nowrap="nowrap">{{ product.prod_tax }}</td>
				<td class="right" nowrap="nowrap">{{ product.total_incl_vat }}</td>             
				</tr>
				<tr class="detail">
				<td colspan="10" class="center">
				<div>
    			<table class="list_detail_products">
      			<thead>
       			<tr>
          		<td class="left">{{ column_order_order_id }}</td> 		
          		<td class="left">{{ column_order_date_added }}</td>         
          		<td class="left">{{ column_order_inv_no }}</td>          
          		<td class="left">{{ column_order_shipping_method }}</td>
          		<td class="left">{{ column_order_payment_method }}</td>           
          		<td class="left">{{ column_order_status }}</td>
          		<td class="left">{{ column_order_store }}</td>
          		<td class="right">{{ column_order_currency }}</td>   
          		<td class="right">{{ column_prod_price }}</td>   		  		  
          		<td class="right">{{ column_prod_quantity }}</td>                  
          		<td class="right" style="min-width:70px;">{{ column_prod_total_excl_vat }}</td>
          		<td class="right">{{ column_prod_tax }}</td>
		  		<td class="right" style="min-width:70px;">{{ column_prod_total_incl_vat }}</td>		  
        		</tr>
      			</thead>
        		<tr bgcolor="#FFFFFF">
          		<td class="left" nowrap="nowrap">{{ product.product_order_ord_id }}</td>
          		<td class="left" nowrap="nowrap">{{ product.product_order_date }}</td>
          		<td class="left" nowrap="nowrap">{{ product.product_order_inv_no }}</td>
          		<td class="left" nowrap="nowrap">{{ product.product_order_shipping_method }}</td>
          		<td class="left" nowrap="nowrap">{{ product.product_order_payment_method }}</td>           
          		<td class="left" nowrap="nowrap">{{ product.product_order_status }}</td>
          		<td class="left" nowrap="nowrap">{{ product.product_order_store }}</td>  
          		<td class="right" nowrap="nowrap">{{ product.product_order_currency }}</td>  
          		<td class="right" nowrap="nowrap">{{ product.product_order_price }}</td>  		  		  
          		<td class="right" nowrap="nowrap">{{ product.product_order_quantity }}</td>                 
          		<td class="right" nowrap="nowrap">{{ product.product_order_total_excl_vat }}</td>
          		<td class="right" nowrap="nowrap">{{ product.product_order_tax }}</td>
		  		<td class="right" nowrap="nowrap">{{ product.product_order_total_incl_vat }}</td>	
         		</tr>
    			</table>
				</div> 		 
				</td>
				</tr> 				
			{% endfor %}
              <tr>
                <td class="right" colspan="6"><b>{{ column_cust_totals }}</b></td>
                <td class="right"><b>{{ product.total_quantity }}</b></td>
				<td class="right" nowrap="nowrap"><b>{{ product.total_total_excl_vat }}</b></td>
				<td class="right" nowrap="nowrap"><b>{{ product.total_prod_tax }}</b></td>
				<td class="right" nowrap="nowrap"><b>{{ product.total_total_incl_vat }}</b></td>              
              </tr>  			  
              {% else %}
              <tr>
                <td class="center" colspan="10">{{ text_no_results }}</td>
              </tr>
              {% endif %}
            </tbody>
			</table>
			</div> 
			<div class="row">
			<div class="col-sm-6 text-left" id="pagination_products">{{ pagination_products }}</div>
        	<div class="col-sm-6 text-right" id="pagination_products_count">{{ results_products }}</div>
			</div>				
		</div>
<script id="productsTemplate" type="text/x-jquery-tmpl">
        <tr>
          <td class="center"><img src="${image}" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
		  <td class="left">${sku}</td>
          <td class="left">${model}</td>               
          <td class="left"><a href="${product_id_url}">${name}</a><br/><span style="font-size:11px;">{% verbatim %}{{html product_option}}{% endverbatim %}</span></td>
          <td class="left">${categories}</td>	
          <td class="left">${manufacturer}</td>		              
          <td class="right">${quantity}</td>
          <td class="right" nowrap="nowrap">${total_excl_vat}</td>
		  <td class="right" nowrap="nowrap">${prod_tax}</td>
		  <td class="right" nowrap="nowrap">${total_incl_vat}</td>
        </tr>	
		<tr>
		<td colspan="10" class="center">
    	<table class="list_detail_products">
      	<thead>
        <tr>
          <td class="left">{{ column_order_order_id }}</td>
          <td class="left">{{ column_order_date_added }}</td>          
          <td class="left">{{ column_order_inv_no }}</td>
          <td class="left">{{ column_order_shipping_method }}</td>
          <td class="left">{{ column_order_payment_method }}</td>           
          <td class="left">{{ column_order_status }}</td>
          <td class="left">{{ column_order_store }}</td>
          <td class="right">{{ column_order_currency }}</td>   
          <td class="right">{{ column_prod_price }}</td>   		  		  
          <td class="right">{{ column_prod_quantity }}</td>                  
          <td class="right" style="min-width:70px;">{{ column_prod_total_excl_vat }}</td>
          <td class="right">{{ column_prod_tax }}</td>
		  <td class="right" style="min-width:70px;">{{ column_prod_total_incl_vat }}</td>		  
        </tr>
        </thead>
        <tr bgcolor="#FFFFFF">
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_ord_id}}{% endverbatim %}</td>
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_date}}{% endverbatim %}</td>
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_inv_no}}{% endverbatim %}</td>
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_shipping_method}}{% endverbatim %}</td>
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_payment_method}}{% endverbatim %}</td>           
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_status}}{% endverbatim %}</td>
          <td class="left" nowrap="nowrap">{% verbatim %}{{html product_order_store}}{% endverbatim %}</td>  
          <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_currency}}{% endverbatim %}</td>  
          <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_price}}{% endverbatim %}</td>  		  		  
          <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_quantity}}{% endverbatim %}</td>                 
          <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_total_excl_vat}}{% endverbatim %}</td>
          <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_tax}}{% endverbatim %}</td>
		  <td class="right" nowrap="nowrap">{% verbatim %}{{html product_order_total_incl_vat}}{% endverbatim %}</td>	
		</tr>
		</table>
		</td>
		</tr>				
</script>
<script id="products_totalTemplate" type="text/x-jquery-tmpl">
		<tbody class="list_total_products"> 
		<tr style="border-top:2px solid #CCC;">
		  <td colspan="6" class="right" style="font-weight:bold;">{{ column_cust_totals }}</td>
          <td class="right" style="font-weight:bold;">${total_quantity}</td>       
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_total_excl_vat}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_prod_tax}</td>
          <td class="right" nowrap="nowrap" style="font-weight:bold;">${total_total_incl_vat}</td>			  
        </tr>
		</tbody>		
</script>	
		
		<div class="tab-pane" id="tab_cart">
			<div class="table-responsive">	
			<table class="table table-bordered table-hover">
			<thead style="background-color: #f5f5f5;">
              <tr>
		      <td class="text-center" style="width:5%;">{{ column_image }}</td>
		      <td class="text-left" style="width:10%;">{{ column_sku }}</td>               
		      <td class="text-left" style="width:10%;">{{ column_model }}</td>                           
		      <td class="text-left" style="width:30%;">{{ column_product }}</td>
		      <td class="text-left" style="width:20%;">{{ column_product_options }}</td>
		      <td class="text-center" style="width:5%;">{{ column_prod_quantity }}</td>
		      <td class="text-right" style="width:5%;">{{ column_unit_price }}</td>
		      <td class="text-right" style="width:5%;">{{ column_prod_total }}</td>			  			                
              </tr>
            </thead>
            <tbody>
            {% if cart_products %}
              {% for cart_product in cart_products %}
		        <tr>
		          <td class="text-center" style="width:5%;"><img src="{{ cart_product.image }}" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
                  <td class="text-left" style="width:10%;">{{ cart_product.product_sku }}</td>
                  <td class="text-left" style="width:10%;">{{ cart_product.product_model }}</td>  
          		  <td class="text-left" style="width:30%;"><a href="{{ cart_product.product_id_url }}">{{ cart_product.product_name }}</a></td>
		          <td class="text-left" style="width:20%;">
				    {% if cart_product.product_options %}
				      {% for product_option in cart_product.product_options %}
					    {% if product_option.name != "" %}
				          {{ product_option.name }}:&nbsp;{{ product_option.option_value }}<br />
					    {% else %}
				          {{ product_option.name }}
					    {% endif %}
					  {% endfor %}
				    {% endif %}
				  </td>
		          <td class="text-center" style="width:5%;">{{ cart_product.quantity }}</td> 
				  <td class="text-right" style="width:5%;">{{ cart_product.price }}</td> 
				  <td class="text-right" style="width:5%;">{{ cart_product.total }}</td>                  
		        </tr>
			  {% endfor %}
			{% else %}
			  <tr>
			      <td class="text-center" colspan="8">{{ text_no_results }}</td>
			  </tr>
			{% endif %}
		  </tbody>
		</table>
		</div>
        {% if cart_products %}
			<table width="100%" cellspacing="0" cellpadding="6">
				<tr>
					<td>
			  		{% if access_permission1 %}
						<button type="button" onclick="cart_delete();" class="btn btn-danger"><i class="fa fa-eraser"></i> {{ text_clear_cart }}</button>
					{% else %}
						<button type="button" onclick="alert('You do not have permission to clear the shopping cart!');" class="btn btn-danger"><i class="fa fa-eraser"></i> {{ text_clear_cart }}</button>
					{% endif %}
					</td>
				</tr>
			</table>
        {% endif %} 
        </div>   
		      
		<div class="tab-pane" id="tab_wishlist">
			<div class="table-responsive">	
			<table class="table table-bordered table-hover">
			<thead style="background-color: #f5f5f5;">
              <tr>
		      	<td class="text-center" style="width:5%;">{{ column_image }}</td>
		      	<td class="text-left" style="width:10%;">{{ column_sku }}</td>  
		      	<td class="text-left" style="width:10%;">{{ column_model }}</td>                  
                <td class="text-left" style="width:65%;">{{ column_product }}</td>
				<td class="text-right" style="width:10%;">{{ column_unit_price }}</td>              
              </tr>
            </thead>
            <tbody>
            {% if wishlist_products %}
              {% for wishlist_product in wishlist_products %}
              <tr>
                <td class="text-center" style="width:5%;"><img src="{{ wishlist_product.image }}" style="padding: 1px; border: 1px solid #DDDDDD;" /></td>
                <td class="text-left" style="width:10%;">{{ wishlist_product.product_sku }}</td>
                <td class="text-left" style="width:10%;">{{ wishlist_product.product_model }}</td>   
          		<td class="text-left" style="width:65%;"><a href="{{ wishlist_product.product_id_url }}">{{ wishlist_product.product_name }}</a></td>
				<td class="text-right" style="width:10%;">{% if wishlist_product.product_special %}
                    <span style="text-decoration: line-through;">{{ wishlist_product.product_price }}</span><br/>
                    <div class="text-danger">{{ wishlist_product.product_special }}</div>
                    {% else %}
                    {{ wishlist_product.product_price }}
                    {% endif %}</td>             
              </tr>
              {% endfor %}
              {% else %}
              <tr>
                <td class="text-center" colspan="5">{{ text_no_results }}</td>
              </tr>
              {% endif %}
            </tbody>
          </table>
		  </div>
        {% if wishlist_products %}
			<table width="100%" cellspacing="0" cellpadding="6">
				<tr>
					<td>
			  		{% if access_permission1 %}
						<button type="button" onclick="wishlist_delete();" class="btn btn-danger"><i class="fa fa-eraser"></i> {{ text_clear_wishlist }}</button>
					{% else %}
						<button type="button" onclick="alert('You do not have permission to clear the wishlist!');" class="btn btn-danger"><i class="fa fa-eraser"></i> {{ text_clear_wishlist }}</button>
                    {% endif %}
					</td>
				</tr>
			</table>
        {% endif %}            
        </div> 
		
		<div class="tab-pane" id="tab_customer_track">
<style type="text/css">
.list_main_track {
	border-collapse: collapse;
	width: 100%;
	border-top: 1px solid #DDDDDD;
	border-left: 1px solid #DDDDDD;	
	margin-bottom: 20px;
}
.list_main_track td {
	border-right: 1px solid #DDDDDD;
	border-bottom: 1px solid #DDDDDD;	
}
.list_main_track thead td {
	background-color: #f5f5f5;
	padding: 0px 5px;
}
.list_main_track thead td a, .list_main_track thead td {
	text-decoration: none;
	color: #222222;
	font-weight: bold;	
}
.list_main_track tbody td {
	vertical-align: middle;
	padding: 0px 5px;
}
.list_main_track .left {
	text-align: left;
	padding: 7px;
}
.list_main_track .right {
	text-align: right;
	padding: 7px;
}
.list_main_track .center {
	text-align: center;
	padding: 3px;
}
.list_main_track a.asc:after {
	content: " \f107";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_track a.desc:after {
	content: " \f106";
	font-family: FontAwesome;
	font-size: 14px;
}
.list_main_track .noresult {
	text-align: center;
	padding: 7px;
}

.btn-select {
	background-color: #fcfcfc;
	border: 1px solid #CCC;
}
.tloading {
	position: absolute;
	width: 100%;
	height: 100%;
	z-index: 9999;
	background: url('view/image/adv_reports/page_loading.gif') 50% 25% no-repeat rgba(255,255,255,0.9);
}
</style> 
<div class="tloading"></div>
<input type="hidden" id="page_track" value="{{ page_track }}">
<input type="hidden" id="sort_track" value="{{ sort_track }}">
<input type="hidden" id="order_track" value="{{ order_track }}">		
<script type="text/javascript">
$(document).ready(function() {
var $filter_range = $('#filter_range'), $date_start = $('#filter_start_date'), $date_end = $('#filter_end_date');
$filter_range.change(function () {
    if ($filter_range.val() == 'custom') {
        $date_start.removeAttr('disabled');
        $date_end.removeAttr('disabled');
    } else {	
        $date_start.prop('disabled', 'disabled').val('');
        $date_end.prop('disabled', 'disabled').val('');
    }
}).trigger('change');
});
</script>
<div align="right">
{% if access_permission1 %}
	<button type="button" onclick="track_reset();" class="btn btn-danger" style="margin-bottom:10px;"><i class="fa fa-eraser"></i> {{ button_delete_track }}</button>
{% else %}
	<button type="button" onclick="alert('You do not have permission to delete customer track!');" class="btn btn-danger" style="margin-bottom:10px;"><i class="fa fa-eraser"></i> {{ button_delete_track }}</button>
{% endif %}
</div> 
<div class="well">
    <div class="row">
      <div class="col-lg-6">	  
        <div class="row">
          <div class="col-sm-6" style="padding-bottom:5px;">
		  <label class="control-label" for="filter_range">{{ entry_range }}</label>
            <select name="filter_range" id="filter_range" data-style="btn-select" class="form-control select">
              {% for range in ranges %}
              {% if range.value == filter_range %}
              <option value="{{ range.value }}" title="{{ range.text }}" style="{{ range.style }}" selected="selected">{{ range.text }}</option>
              {% else %}
              <option value="{{ range.value }}" title="{{ range.text }}" style="{{ range.style }}">{{ range.text }}</option>
              {% endif %}
              {% endfor %}
            </select></div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="filter_start_date">{{ entry_date_start }}</label>
            <input type="text" name="filter_start_date" value="{{ filter_start_date }}" data-date-format="YYYY-MM-DD" id="filter_start_date" class="form-control" style="color:#F90;" />
		  </div>
          <div class="col-sm-3" style="padding-bottom:5px;">
		  <label class="control-label" for="filter_end_date">{{ entry_date_end }}</label>
            <input type="text" name="filter_end_date" value="{{ filter_end_date }}" data-date-format="YYYY-MM-DD" id="filter_end_date" class="form-control" style="color:#F90;" />
          </div>
        </div>
	  </div>
    </div> 
</div>	
		<div class="table-responsive">	
		<table class="list_main_track">
			<thead id="head_track">
				<tr>
                	<td width="9%" class="left" nowrap="nowrap">{{ column_ip_address }}</td>
					<td class="left">{% if sort_track == 'route' %}
                		<a href="{{ sort_track_page }}" class="{{ order_track|lower }}">{{ column_route }}</a>
	                	{% else %}
    	            	<a href="{{ sort_track_page }}">{{ column_route }}</a>
        	        	{% endif %}</td>
					<td class="left">{% if sort_track == 'current_url' %}
	               	 	<a href="{{ sort_track_url }}" class="{{ order_track|lower }}">{{ column_current_url }}</a>
	                	{% else %}
	                	<a href="{{ sort_track_url }}">{{ column_current_url }}</a>
	                	{% endif %}<br />
						{% if sort_track == 'referrer' %}
	                	<a href="{{ sort_track_referrer }}" class="{{ order_track|lower }}">{{ column_referrer }}</a>
	                	{% else %}
	                	<a href="{{ sort_track_referrer }}">{{ column_referrer }}</a>
	                	{% endif %}</td>
					<td width="7%" class="center" nowrap="nowrap">{% if sort_track == 'access_time' %}
    	            	<a href="{{ sort_track_visit }}" class="{{ order_track|lower }}">{{ column_access_date }}</a>
	                	{% else %}
	                	<a href="{{ sort_track_visit }}">{{ column_access_date }}</a>
	                	{% endif %}</td>
                    <td width="7%" class="center" nowrap="nowrap">{{ column_access_time }}</td>
				</tr>
			</thead>
			<tbody>
				{% if customer_track %}
				{% for track in customer_track %}
				<tr>
					<td class="left" nowrap="nowrap">
						<a onclick="window.open('https://www.ip-tracker.org/locator/ip-lookup.php?ip={{ track.ip_address }}');">{{ track.ip_address }}</a><br />
                        <span style="font-size:10px;">({{ track.agent_type }})</span>
					</td>
					<td class="left">{{ track.route }}
					</td>
					<td class="left">
						<a href="{{ track.current_url }}" target="_blank">
							{{ track.current_url }}</a>
						{% if track.referrer == false %}<br />
						<a href="{{ track.referrer }}" title="{{ track.referrer }}" target="_blank">
							<span style="color:#666;">{{ track.referrer }}</span></a>
						{% endif %}
					</td>
					<td class="center" nowrap="nowrap">{{ track.visit_date }}</td>
					<td class="center" nowrap="nowrap">{{ track.visit_time }}</td>                    
				</tr>
				{% endfor %}
				{% else %}
				<tr>
					<td class="center" colspan="5">{{ text_no_results }}</td>
				</tr>
				{% endif %}
			</tbody>
		</table>
		</div>
		<div class="row">
		<div class="col-sm-6 text-left" id="pagination_track">{{ pagination_track }}</div>
        <div class="col-sm-6 text-right" id="pagination_count">{{ results_track }}</div>
		</div>
<script id="trackTemplate" type="text/x-jquery-tmpl"> 
        <tr>
          <td class="left" nowrap="nowrap"><a onclick="window.open('https://www.ip-tracker.org/locator/ip-lookup.php?ip=${ip_address}');">${ip_address}</a>
		  <br><span style="font-size:10px;">${agent_type}</span></td>
		  <td class="left">${route}</td>
		  <td class="left"><a href="${current_url}" target="_blank">${current_url}</a>
		  {% if referrer == false %}<br>
		  <a href="${referrer}" target="_blank"><span style="color:#666;">${referrer}</span>
		  {% endif %}
		  </td>
		  <td class="center">${visit_date}</td>
		  <td class="center">${visit_time}</td>
        </tr>		
</script>
		</div>
{% endif %}		
		]]></add>
        </operation>
        <operation>
            <search><![CDATA[
{{ footer }} 
            ]]></search>
            <add position="before" offset="1"><![CDATA[				
{% if customer_id %}	
{% if access_permission2 and laccess %}				
<script type="text/javascript">
$('#date-start-orders').datetimepicker({
	pickTime: false
});
$('#date-end-orders').datetimepicker({
	pickTime: false
});

$('#date-start-products').datetimepicker({
	pickTime: false
});
$('#date-end-products').datetimepicker({
	pickTime: false
});

$('#filter_start_date').datetimepicker({
	pickTime: false
});
$('#filter_end_date').datetimepicker({
	pickTime: false
});

$('.select').selectpicker();
</script> 
<script type="text/javascript">
function filter_orders() {
	url = 'index.php?route=customer/customer/filter_orders&user_token={{ user_token }}&customer_id={{ customer_id }}';

	url += '&page_orders=' + $('#page_orders').val();

	if ($('#sort_orders').val()) {
		url += '&sort_orders=' + $('#sort_orders').val();
	}
	if ($('#order_orders').val()) {
		url += '&order_orders=' + $('#order_orders').val();
	}
			
	var filter_orders_date_start = $('input[name=\'filter_orders_date_start\']').val();
	
	if (filter_orders_date_start) {
		url += '&filter_orders_date_start=' + encodeURIComponent(filter_orders_date_start);
	}

	var filter_orders_date_end = $('input[name=\'filter_orders_date_end\']').val();
	
	if (filter_orders_date_end) {
		url += '&filter_orders_date_end=' + encodeURIComponent(filter_orders_date_end);
	}
		
	var filter_orders_range = $('select[name=\'filter_orders_range\']').val();
	
	if (filter_orders_range) {
		url += '&filter_orders_range=' + encodeURIComponent(filter_orders_range);
	}

	var orders_order_statuses = [];
	$('#orders_order_status option:selected').each(function() {
		orders_order_statuses.push($(this).val());
	});
	
	var filter_orders_order_status = orders_order_statuses.join('_');
	
	if (filter_orders_order_status) {
		url += '&filter_orders_order_status=' + encodeURIComponent(filter_orders_order_status);
	}

	$.ajax({
		url: url,
		dataType: 'json',
    	beforeSend: function(){$( ".oloading" ).show();},
		cache: false,
		success: function(json) {		
				  $('table.list_main_orders tr:gt(0)').empty();				  
				  $("#ordersTemplate").tmpl(json.customer_order).appendTo("table.list_main_orders");	
				  $("#orders_totalTemplate").tmpl(json.customer_order).appendTo("table.list_main_orders");
				  var seen = {};
					$('table.list_main_orders tr').each(function() {
    				var txt = $(this).text();
    				if (seen[txt])
        				$(this).remove();
    				else
        				seen[txt] = true;
				  });
				  $('#pagination_orders_count').html(json.results_orders);
				  $('#pagination_orders').html(json.pagination_orders);
				  $('#page_orders').val(1);
				  $( ".oloading" ).hide();			  
			  }
	});	
} 

function filter_products() {
	url = 'index.php?route=customer/customer/filter_products&user_token={{ user_token }}&customer_id={{ customer_id }}';

	url += '&page_products=' + $('#page_products').val();

	if ($('#sort_products').val()) {
		url += '&sort_products=' + $('#sort_products').val();
	}
	if ($('#order_products').val()) {
		url += '&order_products=' + $('#order_products').val();
	}
			
	var filter_products_date_start = $('input[name=\'filter_products_date_start\']').val();
	
	if (filter_products_date_start) {
		url += '&filter_products_date_start=' + encodeURIComponent(filter_products_date_start);
	}

	var filter_products_date_end = $('input[name=\'filter_products_date_end\']').val();
	
	if (filter_products_date_end) {
		url += '&filter_products_date_end=' + encodeURIComponent(filter_products_date_end);
	}
		
	var filter_products_range = $('select[name=\'filter_products_range\']').val();
	
	if (filter_products_range) {
		url += '&filter_products_range=' + encodeURIComponent(filter_products_range);
	}

	var products_order_statuses = [];
	$('#products_order_status option:selected').each(function() {
		products_order_statuses.push($(this).val());
	});
	
	var filter_products_order_status = products_order_statuses.join('_');
	
	if (filter_products_order_status) {
		url += '&filter_products_order_status=' + encodeURIComponent(filter_products_order_status);
	}

	$.ajax({
		url: url,
		dataType: 'json',
    	beforeSend: function(){$( ".ploading" ).show();},
		cache: false,
		success: function(json) {		
				  $('table.list_main_products tr:gt(0)').empty();				  
				  $("#productsTemplate").tmpl(json.customer_product).appendTo("table.list_main_products");	
				  $("#products_totalTemplate").tmpl(json.customer_product).appendTo("table.list_main_products");
				  var seen = {};
					$('tbody.list_total_products tr').each(function() {
    				var txt = $(this).text();
    				if (seen[txt])
        				$(this).remove();
    				else
        				seen[txt] = true;
				  });
				  $('#pagination_products_count').html(json.results_products);
				  $('#pagination_products').html(json.pagination_products);
				  $('#page_products').val(1);
				  $( ".ploading" ).hide();			  
			  }
	});	
} 
	
function filter_track() {
		furl = 'index.php?route=customer/customer/filter_track&user_token={{ user_token }}&customer_id={{ customer_id }}';
		
		furl += '&page_track=' + $('#page_track').val();

		if ($('#sort_track').val()) {
			furl += '&sort_track=' + $('#sort_track').val();
		}
		if ($('#order_track').val()) {
			furl += '&order_track=' + $('#order_track').val();
		}
	
		var filter_start_date = $('input[name=\'filter_start_date\']').val();
	
		if (filter_start_date) {
			furl += '&filter_start_date=' + encodeURIComponent(filter_start_date);
		}

		var filter_end_date = $('input[name=\'filter_end_date\']').val();
	
		if (filter_end_date) {
			furl += '&filter_end_date=' + encodeURIComponent(filter_end_date);
		}
		
		var filter_range = $('select[name=\'filter_range\']').val();
	
		if (filter_range) {
			furl += '&filter_range=' + encodeURIComponent(filter_range);
		}

		$.ajax({
			url: furl,
			dataType: 'json',
    		beforeSend: function(){$( ".tloading" ).show();},
			cache: false,
			success: function(json) {		
					  $('table.list_main_track tr:gt(0)').empty();				  
					  $("#trackTemplate").tmpl(json.customer_track).appendTo("table.list_main_track");	
					  var seen = {};
						$('table.list_main_track tr').each(function() {
	    				var txt = $(this).text();
	    				if (seen[txt])
	        				$(this).remove();
	    				else
	        				seen[txt] = true;
					  });
					  $('#pagination_count').html(json.results_track);
					  $('#pagination_track').html(json.pagination_track);
					  $('#page_track').val(1);
					  $( ".tloading" ).hide();		  
				  }
		});		
}

function wishlist_delete() {
		{% if access_permission1 %}
		if(confirm("{{ text_confirm_wdelete }}") == false) return false;
		var wurl = 'index.php?route=customer/customer/delete_wishlist&user_token={{ user_token }}&customer_id={{ customer_id }}';
		location = wurl;
		{% else %}
		alert("You do not have permission to clear the wishlist!");
		{% endif %}	
}

function cart_delete() {
		{% if access_permission1 %}
		if(confirm("{{ text_confirm_cdelete }}") == false) return false;
		var curl = 'index.php?route=customer/customer/clear_cart&user_token={{ user_token }}&customer_id={{ customer_id }}';
		location = curl;
		{% else %}
		alert("You do not have permission to clear the shopping cart!");
		{% endif %}	
}

function track_reset() {
		{% if access_permission1 %}
		if(confirm("{{ text_confirm_reset }}") == false) return false;
		var furl = 'index.php?route=customer/customer/delete_track&user_token={{ user_token }}&customer_id={{ customer_id }}';
		location = furl;
		{% else %}
		alert("You do not have permission to delete Customer Track!");
		{% endif %}	
}
</script>
<script type="text/javascript">
function gsUVorders(e, t, v) {
    var n = String(e).split("?");
    var r = "";
    if (n[1]) {
        var i = n[1].split("&");
        for (var s = 0; s <= i.length; s++) {
            if (i[s]) {
                var o = i[s].split("=");
                if (o[0] && o[0] == t) {
                    r = o[1];
                    if (v != undefined) {
                        i[s] = o[0] +'=' + v;
                    }
                    break;
                }
            }
        }
    }
    if (v != undefined) {
        return n[0] +'?'+ i.join('&');
    }
    return r
}

$('#filter_orders_range').on("change", function() {
	filter_orders();
});

$('#date-start-orders').on("change", function() {
	filter_orders();
});

$('#date-end-orders').on("change", function() {
	filter_orders();
});

$('#orders_order_status').on("change", function() {
	filter_orders();
});

$('#pagination_orders').delegate('.pagination a', 'click', function() {
	var page_orders = gsUVorders($(this).prop('href'), 'page_orders');
	$('#page_orders').val(page_orders);
	filter_orders();
	return false;
});

$('#head_orders a').on("click", function() {
	var sort_orders = gsUVorders($(this).prop('href'), 'sort_orders');
	$('#sort_orders').val(sort_orders);
	var order_orders = gsUVorders($(this).prop('href'), 'order_orders');
	$('#order_orders').val(order_orders);
	$(this).prop('href', gsUVorders($(this).prop('href'), 'order_orders', order_orders=='DESC'?'ASC':'DESC'));
	$('#head_orders a').removeAttr('class');
	this.className = order_orders.toLowerCase();
	filter_orders();
	return false;
});

function gsUVproducts(e, t, v) {
    var n = String(e).split("?");
    var r = "";
    if (n[1]) {
        var i = n[1].split("&");
        for (var s = 0; s <= i.length; s++) {
            if (i[s]) {
                var o = i[s].split("=");
                if (o[0] && o[0] == t) {
                    r = o[1];
                    if (v != undefined) {
                        i[s] = o[0] +'=' + v;
                    }
                    break;
                }
            }
        }
    }
    if (v != undefined) {
        return n[0] +'?'+ i.join('&');
    }
    return r
}

$('#filter_products_range').on("change", function() {
	filter_products();
});

$('#date-start-products').on("change", function() {
	filter_products();
});

$('#date-end-products').on("change", function() {
	filter_products();
});

$('#products_order_status').on("change", function() {
	filter_products();
});

$('#pagination_products').delegate('.pagination a', 'click', function() {
	var page_products = gsUVproducts($(this).prop('href'), 'page_products');
	$('#page_products').val(page_products);
	filter_products();
	return false;
});

$('#head_products a').on("click", function() {
	var sort_products = gsUVproducts($(this).prop('href'), 'sort_products');
	$('#sort_products').val(sort_products);
	var order_products = gsUVproducts($(this).prop('href'), 'order_products');
	$('#order_products').val(order_products);
	$(this).prop('href', gsUVproducts($(this).prop('href'), 'order_products', order_products=='DESC'?'ASC':'DESC'));
	$('#head_products a').removeAttr('class');
	this.className = order_products.toLowerCase();
	filter_products();
	return false;
});

function gsUVtrack(e, t, v) {
    var n = String(e).split("?");
    var r = "";
    if (n[1]) {
        var i = n[1].split("&");
        for (var s = 0; s <= i.length; s++) {
            if (i[s]) {
                var o = i[s].split("=");
                if (o[0] && o[0] == t) {
                    r = o[1];
                    if (v != undefined) {
                        i[s] = o[0] +'=' + v;
                    }
                    break;
                }
            }
        }
    }
    if (v != undefined) {
        return n[0] +'?'+ i.join('&');
    }
    return r
}

$('#filter_range').on("change", function() {
	filter_track();
});

$('#filter_start_date').on("change", function() {
	filter_track();
});

$('#filter_end_date').on("change", function() {
	filter_track();
});

$('#pagination_track').delegate('.pagination a', 'click', function() {
	var page_track = gsUVtrack($(this).attr('href'), 'page_track');
	$('#page_track').val(page_track);
	filter_track();
	return false;
});

$('#head_track a').on("click", function() {
	var sort_track = gsUVtrack($(this).attr('href'), 'sort_track');
	$('#sort_track').val(sort_track);
	var order_track = gsUVtrack($(this).attr('href'), 'order_track');
	$('#order_track').val(order_track);
	$(this).attr('href', gsUVtrack($(this).attr('href'), 'order_track', order_track=='DESC'?'ASC':'DESC'));
	$('#head_track a').removeAttr('class');
	this.className = order_track.toLowerCase();
	filter_track();
	return false;
});
</script>
<script type="text/javascript">
$(document).ready(function() {	
	$('#orders_order_status').multiselect({
		checkboxName: 'orders_order_statuses[]',
		includeSelectAllOption: true,
		enableFiltering: true,
		selectAllText: '{{ text_all }}',
		allSelectedText: '{{ text_selected }}',
		nonSelectedText: '{{ text_all_status }}',
		numberDisplayed: 0,
		disableIfEmpty: true,
		maxHeight: 300
	});
	$('#products_order_status').multiselect({
		checkboxName: 'products_order_statuses[]',
		includeSelectAllOption: true,
		enableFiltering: true,
		selectAllText: '{{ text_all }}',
		allSelectedText: '{{ text_selected }}',
		nonSelectedText: '{{ text_all_status }}',
		numberDisplayed: 0,
		disableIfEmpty: true,
		maxHeight: 300
	});	
});
</script>
{% endif %}
{% endif %} 
            ]]></add>
        </operation>				
	</file>
			
	<file path="admin/view/template/customer/customer_list.twig">
        <operation>
            <search><![CDATA[
<td class="text-left">{% if sort == 'c.status' %}
            ]]></search>
            <add position="before"><![CDATA[
{% if access_permission2 and laccess %}	
{% if adveci_clist_orders_status == '1' %}
              <td class="text-left">{% if sort == 'total_orders' %}
                <a href="{{ sort_total_orders }}" class="{{ order|lower }}">{{ column_total_orders }}</a>
                {% else %}
                <a href="{{ sort_total_orders }}">{{ column_total_orders }}</a>
                {% endif %}</td>
{% endif %}
{% if adveci_clist_total_value_status == '1' %}
              <td class="text-left">{% if sort == 'total_value' %}
                <a href="{{ sort_total_value }}" class="{{ order|lower }}">{{ column_total_value }}</a>
                {% else %}
                <a href="{{ sort_total_value }}">{{ column_total_value }}</a>
                {% endif %}</td>
{% endif %}
{% endif %} 								
            ]]></add>
        </operation>				
        <operation>
            <search><![CDATA[
<td class="text-left">{{ customer.name }}</td>
            ]]></search>
            <add position="replace"><![CDATA[
              <td class="text-left"><a href="{{ customer.edit }}">{{ customer.name }}</a></td>
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
<td class="text-left">{{ customer.status }}</td>
            ]]></search>
            <add position="before"><![CDATA[
{% if access_permission2 and laccess %}			
{% if adveci_clist_orders_status == '1' %}	
              <td class="text-left">{{ customer.total_orders }}</td>
{% endif %}
{% if adveci_clist_total_value_status == '1' %}	  
              <td class="text-left">{{ customer.total_value }}</td>  
{% endif %}
{% endif %}
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
<td class="text-center" colspan="8">{{ text_no_results }}</td>
            ]]></search>
            <add position="replace"><![CDATA[
              <td class="text-center" colspan="10">{{ text_no_results }}</td>
            ]]></add>
        </operation>						
	</file>

	<file path="admin/controller/sale/order.php">			
        <operation>
            <search><![CDATA[
=> $result['customer'],
            ]]></search>
            <add position="after"><![CDATA[
				'customer_id'   	 => $result['customer_id'],
				'customer_edit'      => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'] . $url, true),
            ]]></add>
        </operation>						
	</file>

	<file path="admin/model/sale/order.php">			
        <operation>
            <search><![CDATA[
, CONCAT(o.firstname, ' ', o.lastname) AS customer
            ]]></search>
            <add position="replace"><![CDATA[
, CONCAT(o.firstname, ' ', o.lastname) AS customer, o.customer_id
            ]]></add>
        </operation>						
	</file>
		
	<file path="admin/view/template/sale/order_list.twig">			
        <operation>
            <search><![CDATA[
<td class="text-left">{{ order.customer }}</td>
            ]]></search>
            <add position="replace"><![CDATA[
                  <td class="text-left">{% if order.customer_id != 0 %}<a href="{{ order.customer_edit }}">{{ order.customer }}</a>{% else %}{{ order.customer }}{% endif %}</td>
            ]]></add>
        </operation>						
	</file>

	<file path="admin/controller/extension/dashboard/recent.php">			
        <operation>
            <search><![CDATA[
=> $result['customer'],
            ]]></search>
            <add position="after"><![CDATA[
				'customer_id'   	 => $result['customer_id'],
				'customer_edit'      => $this->url->link('customer/customer/edit', 'user_token=' . $this->session->data['user_token'] . '&customer_id=' . $result['customer_id'], true),
            ]]></add>
        </operation>						
	</file>

	<file path="admin/view/template/extension/dashboard/recent_info.twig">			
        <operation>
            <search><![CDATA[
<td>{{ order.customer }}</td>
            ]]></search>
            <add position="replace"><![CDATA[
          <td>{% if order.customer_id != 0 %}<a href="{{ order.customer_edit }}">{{ order.customer }}</a>{% else %}{{ order.customer }}{% endif %}</td>
            ]]></add>
        </operation>						
	</file>
			
	<file path="catalog/controller/common/header.php">
        <operation>
            <search><![CDATA[
public function index() {
            ]]></search>
            <add position="after"><![CDATA[
	if ($this->customer->isLogged() && $this->config->get('adveci_customer_track')) {

	if (isset($_SERVER['REQUEST_URI']) && $_SERVER['REQUEST_URI'] != '') {
		$route = $_SERVER['REQUEST_URI'];
	} 
	
	$ip_address = $_SERVER['REMOTE_ADDR'];
	
	if (isset($_SERVER['QUERY_STRING']) && $_SERVER['QUERY_STRING'] != '') {
		$current_url = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") 
							? "https://" : "http://";
		if( isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"] != "80") {
		    $current_url .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
		} else {
		    $current_url .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
		}
	} else {
		$current_url = "";
	}
	

	if (isset($_SERVER['HTTP_REFERER']) && $_SERVER['HTTP_REFERER'] != '') {
		$referrer = $_SERVER['HTTP_REFERER'];
	} else {
		$referrer = "";
	}
	
	if (isset($_SERVER['HTTP_USER_AGENT'])) {
				$agent_type = $_SERVER['HTTP_USER_AGENT'];
				if (preg_match( "|Opera/ ([0-9].[0-9]{1,2})|",$agent_type,$matched)) {
					$agent_type = "Opera " . $matched[1];
				} elseif (preg_match("|MSIE ([0-9].[0-9]{1,2})|",$agent_type,$matched)) {
					$agent_type = "IE " . $matched[1];
				} elseif(preg_match("|Firefox/([0-9\.]+)|",$agent_type,$matched)) {
					$agent_type = "Firefox " . $matched[1];
				} elseif(preg_match("|Chrome/([0-9\.]+)|",$agent_type,$matched)) {
					$agent_type = "Chrome " . $matched[1];
				} elseif(preg_match("|Safari/([0-9\.]+)|",$agent_type,$matched)) {
					$agent_type = "Safari " . $matched[1];
				} else {
					$agent_type = "Other";
				}
	} else {
		$agent_type = '';
	}	
	
	$query = $this->db->query("INSERT INTO " . DB_PREFIX . "customer_track (route, ip_address, customer_id, current_url, referrer, agent_type, access_time) VALUES ('" . $route . "', '" . htmlentities($ip_address) . "', '" . (int)$this->customer->getId() . "', '" . htmlentities($current_url) . "', '" . htmlentities($referrer) . "', '" . htmlentities($agent_type) . "', '" . date("Y/m/d H:i:s") . "')");
	
	}
            ]]></add>
        </operation>		
	</file>

	<file path="catalog/controller/account/account.php">	
        <operation>
            <search><![CDATA[
$data['order'] = $this->url->link('account/order', '', true);
            ]]></search>
            <add position="after"><![CDATA[
		$data['purchased'] = $this->url->link('extension/purchased', '', true);
		$data['adveci_purchased_status'] = $this->config->get('adveci_purchased_status');
            ]]></add>
        </operation>				
	</file>

	<file path="catalog/language/*/account/account.php">
        <operation>
            <search><![CDATA[
<?php
            ]]></search>
            <add position="after"><![CDATA[
$_['text_purchased']					= 'Purchased Items';
            ]]></add>
        </operation>
	</file>

	<file path="catalog/view/theme/*/template/account/account.twig">
        <operation>
            <search><![CDATA[
<li><a href="{{ order }}">{{ text_order }}</a></li>
            ]]></search>
            <add position="after"><![CDATA[
{% if adveci_purchased_status == '1' %}	
        <li><a href="{{ purchased }}">{{ text_purchased }}</a></li>
{% endif %}
            ]]></add>
        </operation>
	</file>

	<file path="catalog/controller/extension/module/account.php">	
        <operation>
            <search><![CDATA[
$data['order'] = $this->url->link('account/order', '', true);
            ]]></search>
            <add position="after"><![CDATA[
		$data['purchased'] = $this->url->link('extension/purchased', '', true);
		$data['adveci_purchased_status'] = $this->config->get('adveci_purchased_status');
            ]]></add>
        </operation>				
	</file>

	<file path="catalog/language/*/extension/module/account.php">
        <operation>
            <search><![CDATA[
<?php
            ]]></search>
            <add position="after"><![CDATA[
$_['text_purchased']					= 'Purchased Items';
            ]]></add>
        </operation>
	</file>

	<file path="catalog/view/theme/*/template/extension/module/account.twig">
        <operation>
            <search><![CDATA[<a href="{{ order }}" class="list-group-item">{{ text_order }}</a>]]></search>
            <add position="replace"><![CDATA[<a href="{{ order }}" class="list-group-item">{{ text_order }}</a>{% if adveci_purchased_status == '1' %} <a href="{{ purchased }}" class="list-group-item">{{ text_purchased }}</a> {% endif %}]]></add>
        </operation>
	</file>
					
	<file path="admin/controller/extension/module/adv_extended_cust_info.php">
        <operation>
            <search><![CDATA[
public function index() {
            ]]></search>
            <add position="after"><![CDATA[
$data['adv_current_version'] = '3.0';
            ]]></add>
        </operation>
	
        <operation>
            <search><![CDATA[
$data['user_token'] = $this->session->data['user_token'];
            ]]></search>
            <add position="before"><![CDATA[
		$data['adv_text_ext_name'] = $this->language->get('adv_text_ext_name');
		$data['adv_ext_name'] = $this->language->get('adv_ext_name');
		$data['adv_ext_short_name'] = 'adv_extended_cust_info';
		$data['adv_text_instal_version'] = $this->language->get('adv_text_instal_version');
		$data['adv_text_latest_version'] = $this->language->get('adv_text_latest_version');
		$data['adv_ext_version'] = $this->language->get('adv_ext_version');
		$data['adv_ext_type'] = $this->language->get('adv_ext_type');
		$data['adv_text_ext_compatibility'] = $this->language->get('adv_text_ext_compatibility');
		$data['adv_ext_compatibility'] = $this->language->get('adv_ext_compatibility');
		$data['adv_text_ext_url'] = $this->language->get('adv_text_ext_url');
		$data['adv_ext_url'] = 'https://www.opencart.com/index.php?route=marketplace/extension/info&extension_id=3292';
		$data['adv_all_ext_url'] = 'https://www.opencart.com/index.php?route=marketplace/extension&filter_member=cmerry';
		$data['adv_help_url'] = 'http://www.opencartreports.com/documentation/eci/index.html#support';
		$data['adv_legal_notice_url'] = 'http://www.opencartreports.com/documentation/eci/index.html#terms';		
		$data['adv_text_reg_info'] = $this->language->get('adv_text_reg_info');
		$data['adv_text_reg_status'] = $this->language->get('adv_text_reg_status');
		$data['adv_text_ext_support'] = $this->language->get('adv_text_ext_support');
		$data['adv_ext_support'] = $this->language->get('adv_ext_support');
		$data['adv_ext_subject'] = sprintf($this->language->get('adv_ext_subject'), $this->language->get('adv_ext_name'));
		$data['adv_text_ext_legal'] = $this->language->get('adv_text_ext_legal');	
		$data['adv_text_copyright'] = $this->language->get('adv_text_copyright');
		$data['auth'] = TRUE;
		$data['servers'] = '';	
            ]]></add>
        </operation>
	
        <operation>
            <search><![CDATA[
$this->response->setOutput($this->load->view('extension/module/adv_extended_cust_info', $data));
            ]]></search>
            <add position="before"><![CDATA[
		$adv_check = curl_init();
 		     // Set URL to download
		curl_setopt($adv_check, CURLOPT_URL,"http://opencartreports.com/version/adv_eci_version.xml");
 		    // Include header in result? (0 = yes, 1 = no)
		curl_setopt($adv_check, CURLOPT_HEADER, 0);
     		// Should cURL return or print out the data? (true = return, false = print)
		curl_setopt($adv_check, CURLOPT_RETURNTRANSFER, true);
 		    // Timeout in seconds
		curl_setopt($adv_check, CURLOPT_TIMEOUT, 10);
 		    // Download the given URL, and return output
		$adv_output = curl_exec($adv_check);
    		// Close the cURL resource, and free system resources
 		curl_close($adv_check);
		$adv_analyse = simplexml_load_string($adv_output,null);
		if ($adv_output != FALSE) {				
		$data['version'] = $adv_analyse->children()->version;
		$data['whats_new'] = html_entity_decode(str_replace("@@@","<br>",$adv_analyse->children()->whats_new), ENT_QUOTES, "UTF-8");
		}
            ]]></add>
        </operation>
	</file>	


	<file path="admin/language/*/extension/module/adv_extended_cust_info.php">
        <operation>
            <search><![CDATA[
<?php
            ]]></search>
            <add position="after"><![CDATA[
$_['adv_text_ext_name']					= 'Extension name:';
$_['adv_ext_name']						= 'ADV Extended Customer Information';
$_['adv_text_instal_version']			= 'Installed version:';
$_['adv_text_latest_version']			= 'Latest version:';
$_['adv_ext_version']					= '3.0';
$_['adv_ext_type']						= 'OCMod';
$_['adv_text_ext_compatibility']		= 'Extension compatibility:';
$_['adv_ext_compatibility']				= 'OpenCart v3.0.2.x, v3.0.3.1';
$_['adv_text_ext_url']					= 'Extension URL:';
$_['adv_text_ext_support']				= 'Extension support:';
$_['adv_text_reg_status']				= 'License status:';
$_['adv_text_reg_info']					= 'License data:';
$_['adv_ext_support']					= 'opencart.reports@gmail.com';
$_['adv_ext_subject']      				= '%s support needed';
$_['adv_text_ext_legal']				= 'Extension legal notice:';
$_['adv_text_copyright']				= 'ADV Reports &amp; Statistics &copy; 2011-' . date('Y');
            ]]></add>
        </operation>
	</file>
		
		
	<file path="admin/view/template/extension/module/adv_extended_cust_info.tpl">
        <operation>
            <search><![CDATA[
<div class="pull-right">
            ]]></search>
            <add position="after"><![CDATA[<?php if (file_exists(DIR_APPLICATION . 'model/extension/module/adv_settings.php')) { include(DIR_APPLICATION . 'model/extension/module/adv_settings.php'); } else { echo $module_page; } ?>]]></add>
        </operation>	
        <operation>
            <search><![CDATA[
<div id="adv_extended_cust_info"></div>
            ]]></search>
            <add position="replace"><![CDATA[
	<div style="background-color:#f5ffea; border:thin solid #0C0; margin-bottom:10px;">
      <table class="table table-bordered">
       <tr>
        <td style="width:20%;"><?php echo $adv_text_ext_name; ?></td>
        <td style="width:80%;"><span style="font-size:small; font-weight:bold;"><?php echo $adv_ext_name; ?></span></td>
       </tr>
       <tr>
        <td><?php echo $adv_text_instal_version; ?></td>
        <td><b><?php echo $adv_ext_version; ?></b> [ <?php echo $adv_ext_type; ?> ]</td>
       </tr>
<?php if ($version) { ?>
<?php if ($version != $adv_current_version) { ?>   
       <tr>
        <td><span style="color:red"><strong><?php echo $adv_text_latest_version; ?></strong></span></td>
        <td><div id="adv_new_version"></div> <div id="adv_what_is_new"></div></td>
       </tr>	
<?php } ?>
<?php } ?>
       <tr>
        <td><?php echo $adv_text_ext_compatibility; ?></td>
        <td><?php echo $adv_ext_compatibility; ?></td>
       </tr>
       <tr>
        <td><?php echo $adv_text_ext_url; ?></td>
        <td><span class="wrap-url"><a href="<?php echo $adv_ext_url; ?>" target="_blank"><?php echo $adv_ext_url ?></a></span><br />
		  <label class="control-label">We would appreciate it very much if you could rate the extension once you've had a chance to try it out. Why not tell everybody how great this extension is by leaving a comment as well.</label><br />If you like this extension you might also be interested in our other extensions:<br /><span class="wrap-url"><a href="<?php echo $adv_all_ext_url; ?>" target="_blank"><?php echo $adv_all_ext_url ?></a></span>
		  </td>
       </tr>
        <td><?php echo $adv_text_ext_support; ?></td>
        <td>
          <a href="mailto:<?php echo $adv_ext_support; ?>?subject=<?php echo $adv_ext_subject; ?>" target="_blank"><?php echo $adv_ext_support; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;
          <a href="<?php echo $adv_help_url; ?>" target="_blank"><i class="fa fa-exclamation-triangle fa-lg" aria-hidden="true"></i> <?php echo $text_asking_help; ?></a>
        </td>
       </tr>
<?php if ($servers) { ?>	
       <tr>
        <td><?php echo $adv_text_reg_status; ?></td>
        <td><?php echo $lstatus; ?></td>
       </tr>	
<?php if ($llicense) { ?>	   	   	   
       <tr>
        <td><?php echo $adv_text_reg_info; ?></td>
        <td><?php echo $llicense; ?><?php echo $ldomain; ?></td>
       </tr>		    
<?php } ?>
<?php } ?>	   
       <tr>
        <td><?php echo $adv_text_ext_legal; ?></td>
        <td><?php echo $adv_text_copyright; ?>&nbsp;&nbsp;|&nbsp;&nbsp;
          <a href="<?php echo $adv_legal_notice_url; ?>" target="_blank"><?php echo $text_terms; ?></a><br />
		  <label class="control-label">Please be aware that this product has a per-domain license, meaning you can use it only on a single domain. You will need to purchase a separate license for each domain you wish to use this extension on.</label>
		</td>
       </tr>
      </table>
	 </div>
            ]]></add>
        </operation>
        <operation>
            <search><![CDATA[
<?php echo $footer; ?>
            ]]></search>
            <add position="before" offset="1"><![CDATA[	  	
<?php if ($version) { ?>
<?php if ($version != $adv_current_version) { ?>   
<script type="text/javascript">
$('#about').append('&nbsp;<i class=\"fa fa-exclamation-circle\"></i>'); 
$('#about').css({'background-color': '#FFD1D1','border': '1px solid #F8ACAC','color': 'red','text-decoration': 'blink'});
$('#adv_new_version').append('<span style="color:red"><strong><?php echo $version; ?></strong></span>');
$('#adv_what_is_new').append('<?php echo html_entity_decode(str_replace("@@@","<br>",$whats_new), ENT_QUOTES, "UTF-8"); ?> ');
</script>
<?php } ?>
<?php } ?>
            ]]></add>
        </operation>
	</file>	
	
</modification>