<?php



/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/



// +----------------------------------------------------------------------+



// | PHP version 4/5                                                      |



// +----------------------------------------------------------------------+



// | Copyright (c) 2004-2010 ARMIA INC                                    |



// +----------------------------------------------------------------------+



// | This source file is a part of iScripts VistaCart                     |



// +----------------------------------------------------------------------+



// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |



// +----------------------------------------------------------------------+



class Homelayout extends AppModel



{



   var $name = 'Homelayout';	



	



	    ############ Function to get the layout of home page .............................



		function getLayout($opt){



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$layouttbl = $Db->fullTableName('homelayouts');				



			$res=$this->query("SELECT * FROM $layouttbl ly WHERE section ='".$opt."' order by ordering asc");



			return $res;



		}



		



		 ############ Function to get the layout of home page .............................



		function getStatus($opt){



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$layouttbl = $Db->fullTableName('homelayouts');	

			$layouttbl = str_replace('`','',$layouttbl)	;		



			$res=$this->query("SELECT status FROM $layouttbl WHERE prod_type ='".$opt."'");						



		    return $res[0][$layouttbl]["status"];



		}



	



		############ Function to update the layout of home page .............................



		function updateLayout($mdl_cnts,$rght_cnts){



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$layouttbl = $Db->fullTableName('homelayouts');				



			$mdl_cnts=explode(",",$mdl_cnts);			



			$rght_cnts=explode(",",$rght_cnts);			



			$chkbox='';$i=0;



			foreach($mdl_cnts as $val)



			{



			  $i++;			



			  $this->query("UPDATE $layouttbl SET section ='middle', ordering = '".$i."' WHERE prod_type= '".trim($val)."'");	



			}  



			$i=0;



			foreach($rght_cnts as $val)



			{



			  $i++;			 



			  $this->query("UPDATE $layouttbl SET section ='right', ordering = '".$i."' WHERE prod_type= '".trim($val)."'");						 			  



			}



			$this->query("UPDATE $layouttbl SET status ='Y'");				  



			return true;



		}



		



		############ Function to update the status of a product display block .............................



		function updateBlockStatus($opt,$newstatus){



			$Db = ConnectionManager::getDataSource($this->useDbConfig);



			$layouttbl = $Db->fullTableName('homelayouts');							



			if($newstatus=='enable')



			$status_str='Y'; else $status_str='N';		



			$this->query("UPDATE $layouttbl SET status ='".$status_str."' WHERE prod_type= '".trim($opt)."'");							 			  



			return true;



		}

            function updateBlockItem($prodType,$status,$section,$order){

                $Db = ConnectionManager::getDataSource($this->useDbConfig);

                $layouttbl = $Db->fullTableName('homelayouts');

		$this->query("UPDATE $layouttbl SET status ='".$status."', section='".$section."',ordering='".$order."'  WHERE prod_type= '".trim($prodType)."'");

		return true;

            }



}		



?>