<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<id>Import\Export из Excel</id>
	<name>Import\Export из Excel</name>
	<code>import_export</code>
	<version>1.0</version>
	<vqmver>1.0</vqmver>
	<author>author</author>
  <link></link>
  
	<!--1.5-->
	<file path="admin/view/template/common/header.tpl" error="skip">
		<operation error="skip">
			<search position="after"><![CDATA[<li><a href="<?php echo $feed; ?>">]]></search>
			<add position="after"><![CDATA[
			<?php $this->load->model('setting/extension'); if(in_array('universal_import', $this->model_setting_extension->getInstalled('module'))){ ?>
			<li><a href="<?php echo $this->url->link('module/universal_import', 'token=' . $this->session->data['token'], 'SSL'); ?>">Import\Export из Excel</a></li>
			<?php }else{ ?>
			<li><a href="<?php echo $this->url->link('extension/module/install', 'extension=universal_import&token=' . $this->session->data['token'], 'SSL'); ?>"> Установить Import\Export из Excel</a></li>
			<?php } ?>
			]]></add>
		</operation>
	</file>
  
	<!--2.0-->
<!-- 	<file path="admin/controller/common/menu.php" error="skip">
		<operation error="skip">
			<search position="after"><![CDATA[$this->load->language('common/menu');]]></search>
			<add position="after"><![CDATA[
			$this->load->model('extension/extension');
			if (in_array('universal_import', $this->model_extension_extension->getInstalled('module'))) {
				$data['text_univimportpro'] = 'Import\Export из Excel';
				$data['link_univimportpro'] = $this->url->link('module/universal_import', 'token=' . $this->session->data['token'], 'SSL');
			} else {
				$data['text_univimportpro'] = 'Установить Import\Export из Excel';
				$data['link_univimportpro'] = $this->url->link('extension/module/install', 'extension=universal_import&token=' . $this->session->data['token'], 'SSL');
			}
			]]></add>
		</operation>
	</file>
  
	<file path="admin/view/template/common/menu.tpl" error="skip">
		<operation error="skip">
			<search position="after"><![CDATA[<li><a href="<?php echo $feed; ?>"><?php echo $text_feed; ?></a></li>]]></search>
			<add position="after"><![CDATA[
			<li><a href="<?php echo $link_univimportpro; ?>"> <?php echo $text_univimportpro; ?></a></li>
			]]></add>
		</operation>
	</file> -->
  
  <file path="admin/model/customer/customer.php" error="skip">
		<operation error="skip">
			<search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "customer SET]]></search>
			<add position="replace"><![CDATA[
      // handle item id for universal import
      if (!empty($data['customer_id']) && defined('GKD_UNIV_IMPORT')) {
        $univimp_item_id = 'customer_id = "' . (int) $data['customer_id'] . '", ';
      } else {
        $univimp_item_id = '';
      }
      
			$this->db->query("INSERT INTO " . DB_PREFIX . "customer SET " . $univimp_item_id . "]]></add>
		</operation>
	</file>
  
  <file path="admin/model/catalog/category.php">
		<operation error="skip">
			<search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "category SET]]></search>
			<add position="replace"><![CDATA[
      // handle item id for universal import
      if (!empty($data['category_id']) && defined('GKD_UNIV_IMPORT')) {
        $univimp_item_id = 'category_id = "' . (int) $data['category_id'] . '", ';
      } else {
        $univimp_item_id = '';
      }
      
			$this->db->query("INSERT INTO " . DB_PREFIX . "category SET " . $univimp_item_id . "]]></add>
		</operation>
	</file>
  
  <file path="admin/controller/catalog/product.php">
		<operation error="skip">
			<search position="after"><![CDATA[protected function getList() {]]></search>
			<add position="after"><![CDATA[
    // univ import filter by batch label
    $importLabels = $this->db->query("SELECT import_batch FROM " . DB_PREFIX . "product WHERE import_batch <> '' GROUP BY import_batch")->rows;
    
    $data['importLabels'] = array();
    
    foreach ($importLabels as $importLabel) {
      $data['importLabels'][] = $importLabel['import_batch'];
    }
    
    if (isset($this->request->get['filter_import_batch'])) {
			$filter_import_batch = $this->request->get['filter_import_batch'];
		} else {
			$filter_import_batch = null;
		}
    
    $data['filter_import_batch'] = $filter_import_batch;
      ]]></add>
		</operation>
    
    <operation error="skip">
			<search position="before" offset="1"><![CDATA[$url .= '&filter_name=']]></search>
			<add position="before" offset="1"><![CDATA[
    if (isset($this->request->get['filter_import_batch'])) {
      $url .= '&filter_import_batch=' . urlencode(html_entity_decode($this->request->get['filter_import_batch'], ENT_QUOTES, 'UTF-8'));
    }
      ]]></add>
		</operation>
    
    <operation error="skip">
			<search position="after"><![CDATA['filter_name'	  => $filter_name,]]></search>
			<add position="after"><![CDATA[     'filter_import_batch'	  => $filter_import_batch,]]></add>
		</operation>
  </file>
  <file path="admin/view/template/catalog/product_list.tpl" error="skip">
		<operation error="skip">
			<search position="before"><![CDATA[<button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa]]></search>
			<add position="before"><![CDATA[
          <div class="form-group">
            <label class="control-label" for="input-import-batch"><?php echo 'Import'; ?></label>
            <select name="filter_import_batch" id="input-import-batch" class="form-control">
              <option value="*"></option>
              <?php foreach ($importLabels as $importLabel) { ?>
              <option value="<?php echo $importLabel; ?>" <?php if ($filter_import_batch == $importLabel) echo 'selected="selected"'; ?>><?php echo $importLabel; ?></option>
              <?php } ?>
            </select>
          </div>
      ]]></add>
		</operation>
    
    <operation error="skip">
			<search position="before"><![CDATA[var filter_name = $('input[name=\'filter_name\']').val();]]></search>
			<add position="before"><![CDATA[ var filter_import_batch = $('select[name=\'filter_import_batch\']').val();

  if (filter_import_batch != '*') {
		url += '&filter_import_batch=' + encodeURIComponent(filter_import_batch);
	}
      ]]></add>
		</operation>
  </file>
  
  <file path="admin/model/catalog/product.php">
		<operation error="skip">
			<search position="after"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_filter SET]]></search>
			<add position="after"><![CDATA[
      // Universal Import/Export - apply filters to cateogories
        if (!empty($data['uiep_filter_to_category'])) {
          if (!empty($data['product_filter']) && !empty($data['product_category'])) {
            foreach ($data['product_category'] as $category_id) {
              foreach ($data['product_filter'] as $filter_id) {
                $this->db->query("INSERT IGNORE INTO " . DB_PREFIX . "category_filter SET category_id = '" . (int)$category_id . "', filter_id = '" . (int)$filter_id . "'");
              }
            }
          }
  			}
      ]]></add>
		</operation>
    
    <operation error="skip">
			<search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product SET]]></search>
			<add position="replace"><![CDATA[
      // handle item id and batch name for universal import
      $univimp_extra = '';
      
      if (!empty($data['product_id']) && defined('GKD_UNIV_IMPORT')) {
        $univimp_extra .= 'product_id = "' . (int) $data['product_id'] . '", ';
      }
      
      if (!empty($data['import_batch']) && defined('GKD_UNIV_IMPORT')) {
        $univimp_extra .= 'import_batch = "' . $this->db->escape($data['import_batch']) . '", ';
      }
      
      if (!empty($data['gkd_extra_fields']) && defined('GKD_UNIV_IMPORT')) {
        foreach ($data['gkd_extra_fields'] as $extra_field) {
          if (isset($data[$extra_field])) {
            $univimp_extra .= '`' . $this->db->escape($extra_field) .'` = "' . $this->db->escape($data[$extra_field]) . '", ';
          }
        }
      }
      
			$this->db->query("INSERT INTO " . DB_PREFIX . "product SET " . $univimp_extra . "]]></add>
		</operation>
    
    <operation error="skip">
			<search position="replace"><![CDATA[$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "',]]></search>
			<add position="replace"><![CDATA[
      // handle item id and batch name for universal import
      $univimp_extra = '';
      
      if (!empty($data['import_batch']) && defined('GKD_UNIV_IMPORT')) {
        $univimp_extra .= 'import_batch = "' . $this->db->escape($data['import_batch']) . '", ';
      }
      
      if (!empty($data['gkd_extra_fields']) && defined('GKD_UNIV_IMPORT')) {
        foreach ($data['gkd_extra_fields'] as $extra_field) {
          if (isset($data[$extra_field])) {
            $univimp_extra .= '`' . $this->db->escape($extra_field) .'` = "' . $this->db->escape($data[$extra_field]) . '", ';
          }
        }
      }
      
			$this->db->query("UPDATE " . DB_PREFIX . "product SET model = '" . $this->db->escape($data['model']) . "', " . $univimp_extra . "]]></add>
		</operation>
    
    <operation error="skip">
			<search position="replace"><![CDATA[$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET]]></search>
			<add position="replace"><![CDATA[
      // handle item id and batch name for universal import
      $univimp_extra_desc = '';

      if (!empty($data['gkd_extra_desc_fields']) && defined('GKD_UNIV_IMPORT')) {
        foreach ($data['gkd_extra_desc_fields'] as $extra_field) {
          if (isset($value[$extra_field])) {
            $univimp_extra_desc .= '`' . $this->db->escape($extra_field) .'` = "' . $this->db->escape($value[$extra_field]) . '", ';
          }
        }
      }
      
			$this->db->query("INSERT INTO " . DB_PREFIX . "product_description SET " . $univimp_extra_desc . "]]></add>
		</operation>
    
    <!--operation error="skip">
			<search position="before"><![CDATA[$this->db->query("DELETE FROM " . DB_PREFIX . "product_description WHERE product_id = '" . (int)$product_id . "'");]]></search>
			<add position="before"><![CDATA[
      // handle batch name for universal import
      if (!empty($data['import_batch']) && defined('GKD_UNIV_IMPORT')) {
        $this->db->query("UPDATE " . DB_PREFIX . "product SET import_batch = '" . $this->db->escape($data['import_batch']) . "' WHERE product_id = '" . (int)$product_id . "'");
      }
      ]]></add>
		</operation-->
    
    <operation error="skip">
			<search position="before"><![CDATA[SET product_option_id = '" . (int)$product_option['product_option_id'] . "',]]></search>
			<add position="before"><![CDATA[
        $gkd_prod_opt_id = defined('GKD_UNIV_IMPORT') && !empty($product_option['product_option_id']) ? "product_option_id = '" . (int) $product_option['product_option_id'] . "'," : '';
        $gkd_prod_opt_val_id = defined('GKD_UNIV_IMPORT') && !empty($product_option['product_option_value_id']) ? "product_option_value_id = '" . (int) $product_option['product_option_value_id'] . "'," : '';
      ]]></add>
		</operation>
    
    <operation error="skip">
			<search position="replace"><![CDATA[product_option_id = '" . (int)$product_option['product_option_id'] . "',]]></search>
			<add position="replace"><![CDATA[".$gkd_prod_opt_id."]]></add>
		</operation>
    
    <operation error="skip">
			<search position="replace"><![CDATA[product_option_value_id = '" . (int)$product_option_value['product_option_value_id'] . "',]]></search>
			<add position="replace"><![CDATA[".$gkd_prod_opt_id."]]></add>
		</operation>
    
    <operation error="skip">
			<search position="before"><![CDATA[if (!empty($data['filter_name'])) {]]></search>
			<add position="before"><![CDATA[
    if (!empty($data['filter_import_batch'])) {
			$sql .= " AND p.import_batch = '" . $this->db->escape($data['filter_import_batch']) . "'";
		}
      ]]></add>
		</operation>
    
	</file>
  
  <file path="admin/model/customer/customer.php" error="skip">
  
    <operation error="skip">
			<search position="replace"><![CDATA[$this->db->escape(sha1($salt . sha1($salt . sha1($data['password']))))]]></search>
			<add position="replace"><![CDATA[((defined('GKD_UNIV_IMPORT') && !empty($data['salt'])) ? $this->db->escape($data['password']) : $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))))]]></add>
		</operation>
    
    <operation error="skip" v="2.x">
			<search position="replace"><![CDATA[$this->db->escape($salt = token(9))]]></search>
			<add position="replace"><![CDATA[((defined('GKD_UNIV_IMPORT') && !empty($data['salt'])) ? $this->db->escape($salt = $data['salt']) : $this->db->escape($salt = token(9)))]]></add>
		</operation>

	</file>
  
  <!-- <file path="admin/model/sale/customer.php" error="skip">
  
    <operation error="skip">
			<search position="replace"><![CDATA[$this->db->escape(sha1($salt . sha1($salt . sha1($data['password']))))]]></search>
			<add position="replace"><![CDATA[((defined('GKD_UNIV_IMPORT') && !empty($data['salt'])) ? $this->db->escape($data['password']) : $this->db->escape(sha1($salt . sha1($salt . sha1($data['password'])))))]]></add>
		</operation>
    
    <operation error="skip" v="2.x">
			<search position="replace"><![CDATA[$this->db->escape($salt = token(9))]]></search>
			<add position="replace"><![CDATA[((defined('GKD_UNIV_IMPORT') && !empty($data['salt'])) ? $this->db->escape($salt = $data['salt']) : $this->db->escape($salt = token(9)))]]></add>
		</operation>
    
		<operation error="skip" v="1.5">
			<search position="replace"><![CDATA[$this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9))]]></search>
			<add position="replace"><![CDATA[((defined('GKD_UNIV_IMPORT') && !empty($data['salt'])) ? $this->db->escape($salt = $data['salt']) : $this->db->escape($salt = substr(md5(uniqid(rand(), true)), 0, 9)))]]></add>
		</operation>
    
	</file> -->
  <file path="admin/controller/common/column_left.php" error="skip" v="2.3">
  
    <operation error="skip">
      <search position="before"><![CDATA[if ($this->user->hasPermission('access', 'extension/event')) {]]></search>
      <add position="before"><![CDATA[
      $this->load->model('extension/extension');
      
      if (!in_array('universal_import', $this->model_extension_extension->getInstalled('module'))) {
        $extension[] = array(
					'name'	   => ' Установить Import\Export из Excel',
					'href'     => $this->url->link('extension/extension/module/install', 'extension=universal_import&redir=1&token=' . $this->session->data['token'], true),
					'children' => array()		
				);
      } else if ($this->user->hasPermission('access', 'module/universal_import')) {
				$extension[] = array(
					'name'	   => ' Import\Export из Excel',
					'href'     => $this->url->link('module/universal_import', 'token=' . $this->session->data['token'], true),
					'children' => array()		
				);
			}
      ]]></add>
    </operation>
    
  </file>
  
<!--   <file path="admin/controller/extension/extension/module.php" error="skip">
  
    <operation error="skip">
			<search position="after"><![CDATA[$files = glob(DIR_APPLICATION . 'controller/extension/module/*.php');]]></search>
			<add position="after"><![CDATA[
    if (version_compare(VERSION, '3', '>=')) {
      $files[] = 'universal_import';
    }
			]]></add>
		</operation>
    
  </file> -->
  <file path="admin/controller/extension/extension/module.php" i="fix 2.3 link" error="skip">
  
    <operation error="skip">
			<search position="before" index="0"><![CDATA[$data['extensions'][] = array(]]></search>
			<add position="before" index="0"><![CDATA[
        if ($extension == 'universal_import') {
          ${'data'}['extensions'][] = array(
            'name'      => (version_compare(VERSION, '3', '>=') ? $this->language->get('extension')->get('heading_title') : $this->language->get('heading_title')),
            'module'    => $module_data,
            'install'   => $this->url->link('extension/extension/module/install', (isset($this->session->data['user_token']) ? 'user_token='.$this->session->data['user_token'] : 'token='.$this->session->data['token']) . '&extension=' . $extension, true),
            'uninstall' => $this->url->link('extension/extension/module/uninstall', (isset($this->session->data['user_token']) ? 'user_token='.$this->session->data['user_token'] : 'token='.$this->session->data['token']) . '&extension=' . $extension, true),
            'installed' => in_array($extension, $extensions),
            'edit'      => $this->url->link('module/' . $extension, (isset($this->session->data['user_token']) ? 'user_token='.$this->session->data['user_token'] : 'token='.$this->session->data['token']), true)
          );
          continue;
        }
			]]></add>
		</operation>
		
	</file>
  
</modification>