<?xml version="1.0" encoding="UTF-8"?>
<modification>
	<name>CountryZone Manager - Zone</name>
	<version>1.05</version>
	<author>AlexDW</author>
	<link>https://www.opencart.com/index.php?route=marketplace/extension&amp;filter_member=AlexDW</link>
	<code>zonemanager</code>
	<file path="admin/view/template/localisation/zone_list.twig">
		<operation error="skip">
			<search><![CDATA[
<h1>{{ heading_title }}</h1>
			]]></search>
			<add position="replace"><![CDATA[
<!-- ZoneManager -->
      <h1>ZoneManager</h1>
<!-- ZoneManager -->
			]]></add>
		</operation>
	</file>
	<file path="admin/view/template/localisation/zone_list.twig">
		<operation error="abort">
			<search><![CDATA[
<div class="pull-right"><a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
			]]></search>
			<add position="replace"><![CDATA[
<!-- ZoneManager -->
      <div class="pull-right">
		<span style="padding-right:20px;">
		<a href="https://www.opencart.com/index.php?route=marketplace/extension&filter_member=AlexDW" target="_blank" data-toggle="tooltip" title="Get more extensions" class="btn btn-info"><i class="fa fa-download"></i></a></span>
        <button type="button" data-toggle="tooltip" title="{{ button_enable_zone }}" class="btn btn-success" onclick="$('#form-zone').attr('action', '{{ enable_zone }}'); $('#form-zone').submit();"><i class="fa fa-plus"></i></button>
        <button type="button" data-toggle="tooltip" title="{{ button_disable_zone }}" class="btn btn-danger" onclick="$('#form-zone').attr('action', '{{ disable_zone }}'); $('#form-zone').submit();"><i class="fa fa-minus"></i></button>
	  <a href="{{ enable_all }}" data-toggle="tooltip" title="{{ button_enable_all }}" class="btn btn-success" data-confirm="{{ button_enable_all }}"><i class="fa fa-globe fa-2x"></i></a>
	  <a href="{{ disable_all }}" data-toggle="tooltip" title="{{ button_disable_all }}" class="btn btn-danger" data-confirm="{{ button_disable_all }}"><i class="fa fa-globe fa-2x"></i></a>
	  <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
<!-- ZoneManager -->
			]]></add>
		</operation>	
		<operation error="abort">
			<search><![CDATA[
<td class="text-left">{% if sort == 'c.name' %}
			]]></search>
			<add position="before"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left" width="60px">{% if sort == 'z.country_id' %}
                <a href="{{ sort_country_id }}" class="{{ order|lower }}">cID</a>
                {% else %}
                <a href="{{ sort_country_id }}">cID</a>
                {% endif %}</td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<td class="text-left">{% if sort == 'z.name' %}
			]]></search>
			<add position="before"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left">{{ entry_country_status }}</td>
              <td class="text-left" width="60px">{% if sort == 'z.zone_id' %}
                <a href="{{ sort_zone_id }}" class="{{ order|lower }}">zID</a>
                {% else %}
                <a href="{{ sort_zone_id }}">zID</a>
                {% endif %}</td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<td class="text-right">{{ column_action }}</td>
			]]></search>
			<add position="before"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left">{{ entry_zone_status }}</td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<div class="panel-body">
			]]></search>
			<add position="after"><![CDATA[
<!-- ZoneManager -->
        <div class="well">
          <div class="row">
            <div class="col-sm-4">
              <div class="form-group">
                <label class="control-label" for="input-country">{{ entry_country }}</label>
                <input type="text" name="filter_country" value="{{ filter_country }}" placeholder="{{ entry_country }}" id="input-country" class="form-control" />
              </div>
            </div>
            <div class="col-sm-4">
              <div class="form-group">
                <label class="control-label" for="input-zone">{{ entry_name }}</label>
                <input type="text" name="filter_zone" value="{{ filter_zone }}" placeholder="{{ entry_name }}" id="input-zone" class="form-control" />
              </div>
            </div>
            <div class="col-sm-4">
              <div class="form-group">
                <label class="control-label" for="input-zone_status">{{ entry_zone_status }}</label>
                <select name="filter_zone_status" id="input-zone_status" class="form-control">
                  <option value="*"></option>
                  {% if filter_zone_status == 1 %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  {% endif %}
                  {% if filter_zone_status == 2 %}
                  <option value="2" selected="selected">{{ text_disabled }}</option>
                  {% else %}
                  <option value="2">{{ text_disabled }}</option>
                  {% endif %}
                </select>
              </div>
            </div>
            <div class="col-sm-2">
              <div class="form-group">
                <label class="control-label" for="input-country_id">CountryID</label>
                <input type="text" name="filter_country_id" value="{{ filter_country_id }}" placeholder="CountryID" id="input-country_id" class="form-control" />
              </div>
            </div>
            <div class="col-sm-2">
              <div class="form-group">
                <label class="control-label" for="input-zone_id">ZoneID</label>
                <input type="text" name="filter_zone_id" value="{{ filter_zone_id }}" placeholder="ZoneID" id="input-zone_id" class="form-control" />
              </div>
            </div>
            <div class="col-sm-4">
              <div class="form-group">
                <label class="control-label" for="input-code">{{ entry_code }}</label>
                <input type="text" name="filter_code" value="{{ filter_code }}" placeholder="{{ entry_code }}" id="input-code" class="form-control" />
              </div>
            </div>
            <div class="col-sm-4">
              <div class="form-group">
                <label class="control-label" for="input-country_status">{{ entry_country_status }}</label>
                <select name="filter_country_status" id="input-country_status" class="form-control">
                  <option value="*"></option>
                  {% if filter_country_status == 1 %}
                  <option value="1" selected="selected">{{ text_enabled }}</option>
                  {% else %}
                  <option value="1">{{ text_enabled }}</option>
                  {% endif %}
                  {% if filter_country_status == 2 %}
                  <option value="2" selected="selected">{{ text_disabled }}</option>
                  {% else %}
                  <option value="2">{{ text_disabled }}</option>
                  {% endif %}
                </select>
              </div>
            </div>
            <div class="col-sm-12">
			<div class="pull-right">
              <button type="button" id="button-clear" class="btn btn-info"><i class="fa fa-eraser"></i> Clear</button>
			  <button type="button" id="button-filter" class="btn btn-primary"><i class="fa fa-search"></i> Filter</button>
            </div>
            </div>
          </div>
        </div>
        <div class="row" style="padding-bottom: 10px;">
          <div class="col-sm-6 text-left">{{ pagination }}</div>
          <div class="col-sm-6 text-right">{{ results }}</div>
        </div>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<td class="text-left">{{ zone.country }}</td>
			]]></search>
			<add position="before"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left">{{ zone.country_id }}</td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<td class="text-left">{{ zone.name }}</td>
			]]></search>
			<add position="before"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left">
			  	{% if zone.country_status > 0 %}
                    <span style="font-size: 90%;" class="label label-success">{{ text_enabled }}</span>
                {% else %}
                    <span style="font-size: 90%;" class="label label-warning">{{ text_disabled }}</span>
                {% endif %}
			  </td>
			  <td class="text-left">{{ zone.zone_id }}</td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
<td class="text-left">{{ zone.code }}</td>
			]]></search>
			<add position="after"><![CDATA[
<!-- ZoneManager -->
              <td class="text-left">
			  	{% if zone.status > 0 %}
                    <span style="font-size: 90%;" class="label label-success">{{ text_enabled }}</span>
                {% else %}
                    <span style="font-size: 90%;" class="label label-warning">{{ text_disabled }}</span>
                {% endif %}
			  </td>
<!-- ZoneManager -->
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
{{ footer }}
			]]></search>
			<add position="after"><![CDATA[
<!-- ZoneManager -->
<script type="text/javascript"><!--
$(document).ready(function() {
	$('a[data-confirm]').click(function(ev) {
		var href = $(this).attr('href');
		if (!$('#dataConfirmModal').length) {
			$('body').append('<div id="dataConfirmModal" class="modal" role="dialog" aria-labelledby="dataConfirmLabel" aria-hidden="true"><div class="modal-dialog"><div class="modal-content"><div class="modal-body"></div><div class="modal-footer"><button class="btn btn-default" data-dismiss="modal" aria-hidden="true">{{ text_no }}</button><a class="btn btn-danger" id="dataConfirmOK">{{ text_yes }}</a></div></div></div></div>');
		} 
		$('#dataConfirmModal').find('.modal-body').text($(this).attr('data-confirm')+' ?');
		$('#dataConfirmOK').attr('href', href);
		$('#dataConfirmModal').modal({show:true});
		return false;
	});
});

function filter() {
	url = 'index.php?route=localisation/zone&user_token={{ user_token }}';

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

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

	var filter_country_status = $('select[name=\'filter_country_status\']').val();
	
	if (filter_country_status !='*') {
		url += '&filter_country_status=' + encodeURIComponent(filter_country_status);
	}

	var filter_zone_status = $('select[name=\'filter_zone_status\']').val();
	
	if (filter_zone_status !='*') {
		url += '&filter_zone_status=' + encodeURIComponent(filter_zone_status);
	}

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

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

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

	location = url;
}

function clear_filter() {
	$('select[class=\'form-control\']').val('*');
	$('input[class=\'form-control\']').val('');
	filter();
	return false;
}
//--></script>  
<script type="text/javascript"><!--
$('input[class=\'form-control\']').keydown(function(e) {
	if (e.keyCode == 13) {
		filter();
	}
});

$('#button-filter').on('click', function() {
		filter();
});

$('#button-clear').on('click', function() {
		clear_filter();
});
//--></script>
			]]></add>
		</operation>
	</file>

	<file path="admin/controller/localisation/zone.php">		
		<operation error="abort">
			<search><![CDATA[
$url .= '&sort=' . $this->request->get['sort'];
			]]></search>
			<add position="after" offset="1"><![CDATA[
			// ZoneManager
			if (isset($this->request->get['filter_zone_id'])) {
				$url .= '&filter_zone_id=' . $this->request->get['filter_zone_id'];
			}

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

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

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

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

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

			if (isset($this->request->get['filter_country_id'])) {
				$url .= '&filter_country_id=' . $this->request->get['filter_country_id'];
			}
			// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
function getList() {
			]]></search>
			<add position="after"><![CDATA[
		// ZoneManager
		if (isset($this->request->get['filter_zone_id'])) {
			$filter_zone_id = $this->request->get['filter_zone_id'];
		} else {
			$filter_zone_id = null;
		}

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

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

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

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

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

		if (isset($this->request->get['filter_country_id'])) {
			$filter_country_id = $this->request->get['filter_country_id'];
		} else {
			$filter_country_id = null;
		}
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
'sort'  => $sort,
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
			'filter_zone_id'    => $filter_zone_id,
			'filter_zone'    	=> $filter_zone,
			'filter_country'    => $filter_country,
			'filter_country_status' => $filter_country_status,
			'filter_zone_status'    => $filter_zone_status,
			'filter_code'       => $filter_code,
			'filter_country_id' => $filter_country_id,
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
$data['sort'] = $sort;
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
			$data['filter_zone_id'] = $filter_zone_id;
			$data['filter_zone'] 	  = $filter_zone;
			$data['filter_country'] = $filter_country;
			$data['filter_country_status'] = $filter_country_status;
			$data['filter_zone_status'] = $filter_zone_status;
			$data['filter_code'] 	 = $filter_code;
			$data['filter_country_id'] = $filter_country_id;
			$data['user_token'] = $this->session->data['user_token'];
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
if ($order == 'ASC') {
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
			if (isset($this->request->get['filter_zone_id'])) {
				$url .= '&filter_zone_id=' . $this->request->get['filter_zone_id'];
			}

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

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

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

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

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

			if (isset($this->request->get['filter_country_id'])) {
				$url .= '&filter_country_id=' . $this->request->get['filter_country_id'];
			}
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
$zone_total = $this->model_localisation_zone->getTotalZones();
			]]></search>
			<add position="replace"><![CDATA[
		// ZoneManager
			$results = $this->model_localisation_zone->getZoneManager($filter_data);
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
$results = $this->model_localisation_zone->getZones($filter_data);
			]]></search>
			<add position="replace"><![CDATA[
		// ZoneManager
			$zone_total = $this->model_localisation_zone->getTotalZM($filter_data);
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
$data['sort_name'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.name' . $url, true);
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
			$data['sort_country_id'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.country_id' . $url, true);
			$data['sort_zone_id'] = $this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . '&sort=z.zone_id' . $url, true);
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
$data['delete'] = $this->url->link(
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
			$data['enable_all'] = $this->url->link('localisation/zone/enable_all', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['disable_all'] = $this->url->link('localisation/zone/disable_all', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['enable_zone'] = $this->url->link('localisation/zone/enable_zone', 'user_token=' . $this->session->data['user_token'] . $url, true);
			$data['disable_zone'] = $this->url->link('localisation/zone/disable_zone', 'user_token=' . $this->session->data['user_token'] . $url, true);
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
'zone_id' => $result['zone_id'],
			]]></search>
			<add position="after"><![CDATA[
		// ZoneManager
			'country_id' => $result['country_id'],
			'status' => $result['status'],
			'country_status' => $result['country_status'],
		// ZoneManager end
			]]></add>
		</operation>
		<operation error="abort">
			<search><![CDATA[
public function delete() {
			]]></search>
			<add position="before"><![CDATA[
		// ZoneManager
	public function disable_all() {
		$this->language->load('localisation/zone');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('localisation/zone');

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

		} else {
			
			$this->model_localisation_zone->disableAllZone();
			
			$this->session->data['success'] = $this->language->get('text_success');

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

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

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

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

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

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

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

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

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

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

			$this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function enable_all() {
		$this->language->load('localisation/zone');
 
		$this->document->setTitle($this->language->get('heading_title'));
		
		$this->load->model('localisation/zone');

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

		} else {
			
			$this->model_localisation_zone->enableAllZone();
			
			$this->session->data['success'] = $this->language->get('text_success');

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

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

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

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

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

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

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

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

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

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

			$this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function enable_zone() {
		$this->language->load('localisation/zone');

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

		$this->load->model('localisation/zone');

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

		} elseif (isset($this->request->post['selected'])) {

			foreach ($this->request->post['selected'] as $zone_id) {
				$this->model_localisation_zone->enableZone($zone_id);
			}

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

			$url = '';

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

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

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

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

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

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

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

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

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

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

			$this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}

	public function disable_zone() {
		$this->language->load('localisation/zone');

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

		$this->load->model('localisation/zone');

		if (!$this->user->hasPermission('modify', 'localisation/zone')) {
			$this->error['warning'] = $this->language->get('error_permission');
		} elseif (isset($this->request->post['selected'])) {

			foreach ($this->request->post['selected'] as $zone_id) {
				$this->model_localisation_zone->disableZone($zone_id);
			}

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

			$url = '';

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

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

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

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

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

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

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

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

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

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

			$this->response->redirect($this->url->link('localisation/zone', 'user_token=' . $this->session->data['user_token'] . $url, true));
		}

		$this->getList();
	}
		// ZoneManager end
			]]></add>
		</operation>
	</file>

	<file path="admin/model/localisation/zone.php">		
		<operation error="abort">
			<search><![CDATA[
public function getTotalZones() {
			]]></search>
			<add position="before"><![CDATA[
	// ZoneManager
		public function enableZone($zone_id) {
			$this->db->query("UPDATE " . DB_PREFIX . "zone SET `status`='1' WHERE zone_id = '" . (int)$zone_id . "'");
			$this->cache->delete('zone');	
		}

		public function disableZone($zone_id) {
			$this->db->query("UPDATE " . DB_PREFIX . "zone SET `status`='0' WHERE zone_id = '" . (int)$zone_id . "'");
			$this->cache->delete('zone');	
		}

		public function disableAllZone() {
			$query = $this->db->query("UPDATE " . DB_PREFIX . "zone SET `status`='0' ");
			$this->cache->delete('zone');
		}

		public function enableAllZone() {
			$query = $this->db->query("UPDATE " . DB_PREFIX . "zone SET `status`='1' ");
			$this->cache->delete('zone');
		}

	public function getZoneManager($data = array()) {
		$sql = "SELECT z.*, c.status AS country_status, c.name AS country FROM " . DB_PREFIX . "zone z LEFT JOIN " . DB_PREFIX . "country c ON (z.country_id = c.country_id)";
			
		$sort_data = array(

			'z.zone_id',
			'z.country_id',
			'c.name',
			'z.name',
			'z.code'
		);	
			

			$sql .= " WHERE z.name <> 'AlexDW' ";
		if (isset($data['filter_zone_id'])) {
			$sql .= " AND z.zone_id LIKE '%" . (int)$data['filter_zone_id'] . "%'";
		}

		if (isset($data['filter_country_status'])) {
		if (($data['filter_country_status']) == 1) {
			$sql .= " AND c.status = '1'";
		} else {
			$sql .= " AND c.status <> '1'";
		}
		}

		if (isset($data['filter_zone_status'])) {
		if (($data['filter_zone_status']) == 1) {
			$sql .= " AND z.status = '1'";
		} else {
			$sql .= " AND z.status <> '1'";
		}
		}

		if (isset($data['filter_country'])) {
			$sql .= " AND c.name LIKE '%" . $this->db->escape($data['filter_country']) . "%'";
		}

		if (isset($data['filter_zone'])) {
			$sql .= " AND z.name LIKE '%" . $this->db->escape($data['filter_zone']) . "%'";
		}

		if (isset($data['filter_code'])) {
			$sql .= " AND z.code LIKE '%" . $this->db->escape($data['filter_code']) . "%'";
		}

		if (isset($data['filter_country_id'])) {
			$sql .= " AND z.country_id LIKE '%" . (int)$data['filter_country_id'] . "%'";
		}
			
		if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
			$sql .= " ORDER BY " . $data['sort'];	
		} else {
			$sql .= " ORDER BY c.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;
	}

	public function getTotalZM($data = array()) {
		$sql = "SELECT COUNT(DISTINCT z.zone_id) AS total FROM " . DB_PREFIX . "zone z LEFT JOIN " . DB_PREFIX . "country c ON (z.country_id = c.country_id)";
		$sql .= " WHERE z.name <> 'AlexDW' ";

		if (isset($data['filter_zone_id'])) {
			$sql .= " AND z.zone_id LIKE '%" . (int)$data['filter_zone_id'] . "%'";
		}

		if (isset($data['filter_country_status'])) {
		if (($data['filter_country_status']) == 1) {
			$sql .= " AND c.status = '1'";
		} else {
			$sql .= " AND c.status <> '1'";
		}
		}

		if (isset($data['filter_zone_status'])) {
		if (($data['filter_zone_status']) == 1) {
			$sql .= " AND z.status = '1'";
		} else {
			$sql .= " AND z.status <> '1'";
		}
		}

		if (isset($data['filter_country'])) {
			$sql .= " AND c.name LIKE '%" . $this->db->escape($data['filter_country']) . "%'";
		}

		if (isset($data['filter_zone'])) {
			$sql .= " AND z.name LIKE '%" . $this->db->escape($data['filter_zone']) . "%'";
		}

		if (isset($data['filter_code'])) {
			$sql .= " AND z.code LIKE '%" . $this->db->escape($data['filter_code']) . "%'";
		}

		if (isset($data['filter_country_id'])) {
			$sql .= " AND z.country_id LIKE '%" . (int)$data['filter_country_id'] . "%'";
		}

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

		return $query->row['total'];
	}
	// ZoneManager end
			]]></add>
		</operation>
	</file>

	<file path="admin/language/en-gb/localisation/zone.php">		
		<operation error="skip">
			<search><![CDATA[
<?php
			]]></search>
			<add position="after"><![CDATA[
			// ZoneManager
				$_['button_enable_all']    = 'Enable All Zones';
				$_['button_disable_all']   = 'Disable All Zones';
				$_['button_enable_zone']   = 'Enable Selected';
				$_['button_disable_zone']  = 'Disable Selected';
				$_['entry_country_status'] = 'Country status';
				$_['entry_zone_status']    = 'Zone status';
				$_['text_yes']    		   = 'Yes';
				$_['text_no']    		   = 'No';
			// ZoneManager end
			]]></add>
		</operation>
	</file>

	<file path="admin/language/ru-ru/localisation/zone.php">		
		<operation error="skip">
			<search><![CDATA[
<?php
			]]></search>
			<add position="after"><![CDATA[
			// ZoneManager
				$_['button_enable_all']    = 'Включить все регионы';
				$_['button_disable_all']   = 'Отключить все регионы';
				$_['button_enable_zone']   = 'Включить выбранные';
				$_['button_disable_zone']  = 'Отключить выбранные';
				$_['entry_country_status'] = 'Статус страны';
				$_['entry_zone_status']    = 'Статус региона';
				$_['text_yes']    		   = 'Да';
				$_['text_no']    		   = 'Нет';
			// ZoneManager end
			]]></add>
		</operation>
	</file>

</modification>