<?xml version="1.0" encoding="utf-8"?>
<modification>

	<id>Export Excel Product </id>
	<version>2.0</version>
	<vqmver>2.4.1</vqmver>
	<author>IRSSOFT</author>
  
<!-- Product Returns -->
	<!-- Language -->

	<file path="admin/language/english/default.php">
		<operation>
			<search position="after"><![CDATA[$_['button_approve']                = 'Approve';]]></search>
			<add><![CDATA[$_['button_export']                = 'Export';]]></add>
		</operation>
	</file>
  
    <!-- Controller -->  
    <file path="admin/controller/catalog/product.php">
		
    <operation>
			<search position="before"><![CDATA[$data['button_filter'] = $this->language->get('button_filter');]]></search>
            <add><![CDATA[$data['button_export'] = $this->language->get('button_export');
			$data['export'] = $this->url->link('catalog/product/export', 'token=' . $this->session->data['token'] .$url, 'SSL');
			]]></add>
		</operation>    
        	
        	<operation>
			<search position="before"><![CDATA[public function index() {]]></search>
            <add><![CDATA[
			public function export() {
			
			if (isset($this->request->get['filter_name'])) {
			$filter_name = $this->request->get['filter_name'];
		} else {
			$filter_name = null;
		}

		if (isset($this->request->get['filter_model'])) {
			$filter_model = $this->request->get['filter_model'];
		} else {
			$filter_model = null;
		}

		if (isset($this->request->get['filter_price'])) {
			$filter_price = $this->request->get['filter_price'];
		} else {
			$filter_price = null;
		}

		if (isset($this->request->get['filter_quantity'])) {
			$filter_quantity = $this->request->get['filter_quantity'];
		} else {
			$filter_quantity = null;
		}

		if (isset($this->request->get['filter_status'])) {
			$filter_status = $this->request->get['filter_status'];
		} else {
			$filter_status = null;
		}

		if (isset($this->request->get['sort'])) {
			$sort = $this->request->get['sort'];
		} else {
			$sort = 'pd.name';
		}

		if (isset($this->request->get['order'])) {
			$order = $this->request->get['order'];
		} else {
			$order = 'ASC';
		}

		if (isset($this->request->get['page'])) {
			$page = $this->request->get['page'];
		} else {
			$page = 1;
		}
		
		$data = array();		
				
		$this->load->model('catalog/product');
		
		$data['products'] = array();

		$returns= array();

		$results = $this->model_catalog_product->getProducts($data);

		foreach ($results as $result) {
		
			$special = false;

			$product_specials = $this->model_catalog_product->getProductSpecials($result['product_id']);

			foreach ($product_specials  as $product_special) {
				if (($product_special['date_start'] == '0000-00-00' || $product_special['date_start'] < date('Y-m-d')) && ($product_special['date_end'] == '0000-00-00' || $product_special['date_end'] > date('Y-m-d'))) {
					$special = $product_special['price'];

					break;
				}					
			}

			$products[] = array(
				'product_id' => $result['product_id'],
				'name'       => $result['name'],
				'description' => $this->cleanString($result['description']),
				'model'      => $result['model'],
				'price'      => $result['price'],
				'special'    => $special,
				'quantity'   => $result['quantity'],
				'status'     => ($result['status'] ? $this->language->get('text_enabled') : $this->language->get('text_disabled'))
			);
				}	
						
						$products_data = array();
						
						$products_column=array();
						
						$products_column = array('Product ID', 'Product Name', 'Product Description', 'Model', 'Price', 'Special', 'Quantity', 'Status');
							
						$products_data[0]=   $products_column;   
						
						foreach($products as $products_row)
						{
							$products_data[]=   $products_row;            
						}     
						require_once(DIR_SYSTEM . 'library/excel_xml.php');
						$xls = new Excel_XML('UTF-8', false, 'Product List');
						
						$xls->addArray($products_data);
						
						$xls->generateXML('product_list_'.date('Y-m-d _ H:i:s'));	

					}
					public function cleanString($text) {
						// 1) convert á ô => a o
						$text = preg_replace("/[áàâãªä]/u","a",$text);
						$text = preg_replace("/[ÁÀÂÃÄ]/u","A",$text);
						$text = preg_replace("/[ÍÌÎÏ]/u","I",$text);
						$text = preg_replace("/[íìîï]/u","i",$text);
						$text = preg_replace("/[éèêë]/u","e",$text);
						$text = preg_replace("/[ÉÈÊË]/u","E",$text);
						$text = preg_replace("/[óòôõºö]/u","o",$text);
						$text = preg_replace("/[ÓÒÔÕÖ]/u","O",$text);
						$text = preg_replace("/[úùûü]/u","u",$text);
						$text = preg_replace("/[ÚÙÛÜ]/u","U",$text);
						$text = preg_replace("/[’‘‹›‚]/u","'",$text);
						$text = preg_replace("/[“”«»„]/u",'"',$text);
						$text = str_replace("–","-",$text);
						$text = str_replace(" "," ",$text);
						$text = str_replace("ç","c",$text);
						$text = str_replace("Ç","C",$text);
						$text = str_replace("ñ","n",$text);
						$text = str_replace("Ñ","N",$text);
					 
						//2) Translation CP1252. &ndash; => -
						$trans = get_html_translation_table(HTML_ENTITIES); 
						$trans[chr(130)] = '&sbquo;';    // Single Low-9 Quotation Mark 
						$trans[chr(131)] = '&fnof;';    // Latin Small Letter F With Hook 
						$trans[chr(132)] = '&bdquo;';    // Double Low-9 Quotation Mark 
						$trans[chr(133)] = '&hellip;';    // Horizontal Ellipsis 
						$trans[chr(134)] = '&dagger;';    // Dagger 
						$trans[chr(135)] = '&Dagger;';    // Double Dagger 
						$trans[chr(136)] = '&circ;';    // Modifier Letter Circumflex Accent 
						$trans[chr(137)] = '&permil;';    // Per Mille Sign 
						$trans[chr(138)] = '&Scaron;';    // Latin Capital Letter S With Caron 
						$trans[chr(139)] = '&lsaquo;';    // Single Left-Pointing Angle Quotation Mark 
						$trans[chr(140)] = '&OElig;';    // Latin Capital Ligature OE 
						$trans[chr(145)] = '&lsquo;';    // Left Single Quotation Mark 
						$trans[chr(146)] = '&rsquo;';    // Right Single Quotation Mark 
						$trans[chr(147)] = '&ldquo;';    // Left Double Quotation Mark 
						$trans[chr(148)] = '&rdquo;';    // Right Double Quotation Mark 
						$trans[chr(149)] = '&bull;';    // Bullet 
						$trans[chr(150)] = '&ndash;';    // En Dash 
						$trans[chr(151)] = '&mdash;';    // Em Dash 
						$trans[chr(152)] = '&tilde;';    // Small Tilde 
						$trans[chr(153)] = '&trade;';    // Trade Mark Sign 
						$trans[chr(154)] = '&scaron;';    // Latin Small Letter S With Caron 
						$trans[chr(155)] = '&rsaquo;';    // Single Right-Pointing Angle Quotation Mark 
						$trans[chr(156)] = '&oelig;';    // Latin Small Ligature OE 
						$trans[chr(159)] = '&Yuml;';    // Latin Capital Letter Y With Diaeresis 
						$trans['euro'] = '&euro;';    // euro currency symbol 
						ksort($trans); 
						 
						foreach ($trans as $k => $v) {
							$text = str_replace($v, $k, $text);
						}
					 
						// 3) remove <p>, <br/> ...
						$text = strip_tags($text); 
						 
						// 4) &amp; => & &quot; => '
						$text = html_entity_decode($text);
						 
						// 5) remove Windows-1252 symbols like "TradeMark", "Euro"...
						$text = preg_replace('/[^(\x20-\x7F)]*/','', $text); 
						 
						$targets=array('\r\n','\n','\r','\t');
						$results=array(" "," "," ","");
						$text = str_replace($targets,$results,$text);
					 
						//XML compatible
						/*
						$text = str_replace("&", "and", $text);
						$text = str_replace("<", ".", $text);
						$text = str_replace(">", ".", $text);
						$text = str_replace("\\", "-", $text);
						$text = str_replace("/", "-", $text);
						*/
						 
						return ($text);
					}
					]]></add>
		</operation>
	</file>
<!-- View -->

	<file path="admin/view/template/catalog/product_list.tpl">
		<operation>
			<search position="replace"><![CDATA[<div class="pull-right"><a href="<?php echo $add; ?>" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus"></i></a>]]></search>
			<add><![CDATA[<div class="pull-right"><a href="<?php echo $export; ?>" data-toggle="tooltip" title="<?php echo $button_export; ?>" class="btn btn-success"><i class="glyphicon glyphicon-export"></i></a> <a href="<?php echo $add; ?>" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus"></i></a>]]></add>
		</operation>
	</file>
	
	
<!-- Catalog -->  
    <!-- Controller --> 

    <file path="admin/controller/catalog/category.php">
		
    <operation>
			<search position="before"><![CDATA[$data['button_add'] = $this->language->get('button_add');]]></search>
            <add><![CDATA[$data['button_export'] = $this->language->get('button_export');
			$data['export'] = $this->url->link('catalog/category/export', 'token=' . $this->session->data['token'], 'SSL');]]></add>
		</operation>    
        	
        	<operation>
			<search position="before"><![CDATA[public function index() {]]></search>
            <add><![CDATA[public function export() {
			
				$this->load->model('catalog/category');
				
				$categories= array();
				
				$data =array();
		
				$results = $this->model_catalog_category->getCategories($data);

				foreach ($results as $result) {
		
					$categories[] = array(
						'category_id' => $result['category_id'],
						'name'        => $result['name'],
						'sort_order'  => $result['sort_order']
					);
				}	
						
						$categories_data = array();
						
						$categories_column=array();
						
						$categories_column = array('Category ID', 'Category Name', 'Sort Order');
							
						$categories_data[0]=   $categories_column;   
						
						foreach($categories as $categories_row)
						{
							$categories_data[]=   $categories_row;            
						}     
						require_once(DIR_SYSTEM . 'library/excel_xml.php');
						$xls = new Excel_XML('UTF-8', false, 'Category List');
						
						$xls->addArray($categories_data);
						
						$xls->generateXML('category_list_'.date('Y-m-d _ H:i:s'));	

					}]]></add>
		</operation>
	</file>
<!-- View -->

	<file path="admin/view/template/catalog/category_list.tpl">
		<operation>
			<search position="replace"><![CDATA[<div class="pull-right"><a href="<?php echo $add; ?>" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus"></i></a> <a href="<?php echo $repair; ?>" data-toggle="tooltip" title="<?php echo $button_rebuild; ?>" class="btn btn-default"><i class="fa fa-refresh"></i></a>]]></search>
			<add><![CDATA[<div class="pull-right"><a href="<?php echo $export; ?>" data-toggle="tooltip" title="<?php echo $button_export; ?>" class="btn btn-success"><i class="glyphicon glyphicon-export"></i></a> <a href="<?php echo $add; ?>" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus"></i></a> <a href="<?php echo $repair; ?>" data-toggle="tooltip" title="<?php echo $button_rebuild; ?>" class="btn btn-default"><i class="fa fa-refresh"></i></a>]]></add>
		</operation>
	</file>
	
</modification>
