<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

/***************************************************************************
 *	PROJECT: ZokiSoft Smart Catalog
 *
 *	This program is a commercial software and any kind of using
 *	it must agree to ZokiSoft License Agreement.
 *
 *	This notice may not be removed from the code.
 *
 *	Copyright 2007-2008 ZokiSoft
 *	http://www.zokisoft.com/
 ***************************************************************************/

class Catalog_grmodel extends Model {


	function Catalog_grmodel()
	{
		// Call the Model constructor
		parent::Model();
	}


	function isCategoryViewAllowed($aGrValue, $sValue )
	{

		// NOTE: '$aGrValue' is list of RESTRICTED id's
		
		if ( 0 == count($aGrValue) )
			return true;
		
		// get id of all categories up to requested one
		$this->db->where('`Id` = \''.(int)$sValue.'\'');
		$rRes = $this->db->get('`zok_category`');
		$aCategory = $rRes->row_array();
			
		$aParentCateg = explode('/',@$aCategory['BreadCramb']);

		$aForbadeId = array_intersect($aGrValue,$aParentCateg);

		if ( empty($aForbadeId) )
			return true;
		else
			return false;

	}
	
	
	function isCategoryAddAllowed($aGrValue, $sValue )
	{

		// NOTE: '$aGrValue' is list of ALLOWED id's
		
		// adding to root catergory
		if ( 0 == $sValue )
		{
			$aParentCateg = array(0);
		}
		else
		{
		// get id of all categories up to requested one
		$this->db->where('`Id` = \''.(int)$sValue.'\'');
		$rRes = $this->db->get('`zok_category`');
		$aCategory = $rRes->row_array();
			
			$aParentCateg = explode('/',@$aCategory['BreadCramb']);		
		}

		$aForbadeId = array_intersect($aGrValue,$aParentCateg);
		
		if ( empty($aForbadeId) )
			return false;
		else
			return true;

	}
	
	
	function isPostAddAllowed($aGrValue, $sValue )
	{

		// NOTE: '$aGrValue' is list of ALLOWED id's
		
		// get id of all categories up to requested one
		$this->db->where('`Id` = \''.(int)$sValue.'\'');
		$rRes = $this->db->get('`zok_category`');
		$aCategory = $rRes->row_array();
				
		$aParentCateg = explode('/',@$aCategory['BreadCramb']);

		$aForbadeId = array_intersect($aGrValue,$aParentCateg);
		
		if ( empty($aForbadeId) )
			return false;
		else
			return true;

	}
	
	
}