<?php
/***************************************************************************
 *                                                                          *
 * Copyright (c) 2005 ISPG Technologies (I) Pvt Ltd. All rights reserved.   *
 *                                                                          *
 * This  is  commercial  software,  only  users  who have purchased a valid *
 * license  and  accept  to the terms of the  License Agreement can install *
 * and use this program.                                                    *
 *                                                                          *
 ****************************************************************************
 * PLEASE READ THE FULL TEXT  OF THE SOFTWARE  LICENSE   AGREEMENT  IN  THE *
 * "copyright.txt" FILE PROVIDED WITH THIS DISTRIBUTION PACKAGE.            *
 ****************************************************************************/
//
//$Id: ThemeModel.php, v 1.0 2011/06/14 20:52:11
// * To change this template, choose Tools | Templates
//* and open the template in the editor.
//
class ThemeModel extends Model {
    public function getPageLayout($themeKey) {
        $sql = "			SELECT 
								* 
							FROM 
								" . DB_PREFIX . "page_layout 
							WHERE  
								themeKey='" . $themeKey . "'";
        return $this->ObjDatabase->readValues($sql);
    }
    public function activateLayout($POST) {
        $insertStringArr = array();
        foreach ($POST['layout'] as $key => $page) {
            array_push($insertStringArr, "('" . $this->escape($POST['themeKey']) . "','" . $page . "','" . $key . "')");
        }
        $sql             = "
							DELETE FROM 
								" . DB_PREFIX . "page_layout 
							WHERE
								themeKey='" . $this->escape($POST['themeKey']) . "'";
        $resDeleteLayout = $this->ObjDatabase->setQuery($sql);
        $sql             = "
							INSERT INTO 
								" . DB_PREFIX . "page_layout 
							(themeKey,tplName,layoutKey)
								VALUES
							" . implode(",", $insertStringArr);
        $resInsertLayout = $this->ObjDatabase->setQuery($sql);
    }
    public function getTplFile($themeKey, $pageLayoutKey) {
        $sql             = "
							SELECT 
								* 
							FROM 
								" . DB_PREFIX . "page_layout 
							WHERE  
								themeKey='" . $themeKey . "' 
								AND 
								layoutKey='" . $pageLayoutKey . "'";
        $resSelectLayout = $this->ObjDatabase->readValue($sql);
        return $resSelectLayout['tplName'];
    }
    public function getCMSLayout($menuItemID) {
        $sqlSelectLayout = "
							SELECT 
								params
							FROM 
								" . DB_PREFIX . "menu_item 
							WHERE 
								menuItemID='" . $menuItemID . "'";
        $resSelectLayout = $this->ObjDatabase->readValueSlave($sqlSelectLayout);
        return $resSelectLayout['params'];
    }
    public function listTplFiles($themeKey) {
        $sql = "
							SELECT 
								* 
							FROM 
								" . DB_PREFIX . "page_layout 
							WHERE  
								themeKey='" . $themeKey . "'";
        
        return $this->ObjDatabase->readValues($sql, MYSQLI_ASSOC);
    }
}
