<?php
 /**
 *      [XCECP] (C) COLNET Inc.
 *      This is NOT a freeware, use is subject to license terms
 */
if(!defined("IN_QKWEB")){exit("Access Denied");}
function smarty_block_config($params, $content, $smarty, &$repeat)
{ 
  	if(!isset($params['name']) || $params['name']==""){
		$params['name'] = "item";
	}
	$dataindex = md5(__FUNCTION__ . md5(serialize($params)));
	if(!isset($smarty->block_data)){$smarty->block_data=array();}
	if(!isset($smarty->block_data[$dataindex])){

		if(isset($params['iStatus']) && $params['iStatus']!=""){
			$iStatus = $params['iStatus'];
			$wheres.= " and iStatus = '".$iStatus."'";
		}
		if(isset($params['id']) && $params['id']!="" && is_numeric($params['id'])){
			$id = $params['id'];
			$wheres.= " and id = '".$id."'";
		}

		if(isset($params['name']) && $params['name']!="" && $params['name']!="item"){
			$name = $params['name'];
			$wheres.= " and name = '".$name."'";
		}
		if(defined('SITE_ID')){$wheres .= " and (siteId='".SITE_ID."' or siteId=0)";}
		$sql = "select * from qk_config where 1=1 $wheres order by id asc";//echo $sql;print_r($res);exit;
		$res = $GLOBALS['db']->getAll($sql);
		$i = 0;
		foreach($res as $k=>$v){
			$res[$i]['configArr'] = unserialize($v['config']);
			$res[$i]['configItem'] = getConfig($v['name']);
			$i++;
		}
	//print_r($res);exit;
		$smarty->block_data[$dataindex]=$res;
	}
	if(is_array($smarty->block_data[$dataindex])){
		$item = array_shift($smarty->block_data[$dataindex]);
		$smarty->assign($params['name'], $item);
		if(count($smarty->block_data[$dataindex])==0){
			$smarty->block_data[$dataindex] = false;
		}
		$repeat= true;
	}else{
		unset($smarty->block_data[$dataindex]);
		$repeat = false;
	}
	echo $content;
}
?>