<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>So Tools</name>
    <code>So-Tools</code>
    <version>1.1.1</version>
    <author>OpencartWorks</author>
    <link>http://www.opencartworks.com/</link>
    
    <file path="catalog/controller/product/product.php">
		<operation>
			<search><![CDATA[$this->load->model('catalog/manufacturer');]]></search>
			<add position="after"><![CDATA[
			    $so_recent_products = array();
			    if (isset($this->request->cookie['sorecentproduct'])) {
				    $so_recent_products = explode(',', $this->request->cookie['sorecentproduct']);
			    } else if (isset($this->session->data['sorecentproduct'])) {
				    $so_recent_products = $this->session->data['sorecentproduct'];
			    }
			    
    			if (isset($this->request->get['route']) && $this->request->get['route'] == 'product/product') {
    				$product_id = $this->request->get['product_id'];   
    				$so_recent_products = array_diff($so_recent_products, array($product_id));
    				array_unshift($so_recent_products, $product_id);
    				setcookie('sorecentproduct', implode(',', $so_recent_products), time() + 60 * 60 * 24 * 30, '/', $this->request->server['HTTP_HOST']);
    				if (!isset($this->session->data['sorecentproduct']) || $this->session->data['sorecentproduct'] != $so_recent_products) {
    					$this->session->data['sorecentproduct'] = $so_recent_products;
    				}
    			}
			]]></add>
		</operation>
	</file>

    <file path="admin/controller/design/layout.php">
        <operation>
            <search>
                <![CDATA[public function index() {]]>
            </search>
            <add position="after">
                <![CDATA[$this->check_All_Pages();]]>
            </add>
        </operation>
    </file>
    
    <file path="admin/controller/design/layout.php">
        <operation>
            <search>
                <![CDATA[public function add() {]]>
            </search>
            <add position="before">
                <![CDATA[
                public function check_All_Pages()
                {
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout WHERE LOWER(name) LIKE '%all pages%' LIMIT 1");
                    if ($query->num_rows) {
                    
                    }else{
                        $sql = "INSERT INTO ".DB_PREFIX."layout SET `name`='All Pages'";
                        $query = $this->db->query( $sql );
                    }
                }
                ]]>
            </add>
        </operation>
    </file>
    
    <file path="catalog/model/design/layout.php">
        <operation>
            <search>
                <![CDATA[
                $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");
                ]]>
            </search>
            <add position="replace">
                <![CDATA[
                    $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout WHERE LOWER(name) LIKE '%all pages%' LIMIT 1");
                    if ($query->num_rows) {
                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE (layout_id = '" . (int)$layout_id . "' OR layout_id = '" . (int)$query->row['layout_id'] . "') AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");
                    } else {
                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "layout_module WHERE layout_id = '" . (int)$layout_id . "' AND position = '" . $this->db->escape($position) . "' ORDER BY sort_order");
                    }
                ]]>
            </add>
        </operation>
    </file>
</modification>