<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>So Categories</name>
    <code>so-categories-modification</code>
    <version>2.2.0</version>
    <author>OpenCartWorks</author>
    <link>http://www.opencartworks.com</link>
    <file path="admin/view/template/catalog/category_form.twig">
        <operation>
          <search>
            <![CDATA[<div class="tab-pane" id="tab-data">]]>
          </search>
          <add position="after">
            <![CDATA[
              <div class="form-group">
                <label class="col-sm-2 control-label">{{ entry_banner }}</label>
                <div class="col-sm-10"><a href="" id="thumb-banner" data-toggle="image" class="img-thumbnail"><img src="{{ thumb_banner }}" alt="" title="" data-placeholder="{{ placeholder }}" /></a>
                  <input type="hidden" name="banner" value="{{ banner }}" id="input-banner" />
                </div>
              </div>
            ]]>
          </add>
        </operation>
    </file>
    <file path="admin/controller/catalog/category.php">
        <operation>
          <search>
            <![CDATA[if (isset($this->request->post['image'])) {]]>
          </search>
          <add position="before">
            <![CDATA[
				if (isset($this->request->post['banner'])) {
					$data['banner'] = $this->request->post['banner'];
				} elseif (!empty($category_info)) {
					$chk = $this->db->query("SHOW COLUMNS FROM `" . DB_PREFIX . "category` WHERE `Field` = 'banner'");

					if (!$chk->num_rows) {

					$this->db->query("ALTER TABLE `" . DB_PREFIX . "category` ADD COLUMN  `banner` varchar(255) NOT NULL");

					}
					$data['banner'] = $category_info['banner'];
				} else {
					$data['banner'] = '';
				}

				$this->load->model('tool/image');

				if (isset($this->request->post['banner']) && is_file(DIR_IMAGE . $this->request->post['banner'])) {
					$data['thumb_banner'] = $this->model_tool_image->resize($this->request->post['banner'], 100, 100);
				} elseif (!empty($category_info) && is_file(DIR_IMAGE . $category_info['banner'])) {
					$data['thumb_banner'] = $this->model_tool_image->resize($category_info['banner'], 100, 100);
				} else {
					$data['thumb_banner'] = $this->model_tool_image->resize('no_image.png', 100, 100);
				}
            ]]>
          </add>
        </operation>
      </file>
    <file path="admin/model/catalog/category.php">
        <operation>
          <search>
            <![CDATA[if (isset($data['image'])) {]]>
          </search>
          <add position="before">
            <![CDATA[
				if (isset($data['banner'])) {
					$this->db->query("UPDATE " . DB_PREFIX . "category SET banner = '" . $this->db->escape($data['banner']) . "' WHERE category_id = '" . (int)$category_id . "'");
				}
            ]]>
          </add>
        </operation>
      </file>  
    <file path="admin/language/*/catalog/category.php">
        <operation>
          <search>
            <![CDATA[$_['entry_image']            = 'Image';]]>
          </search>
          <add position="after">
            <![CDATA[$_['entry_banner']            = 'Banner';]]>
          </add>
        </operation>
      </file>   
    
</modification> 