<?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_deliverytype($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($params['id'] && settype($params['id'],"integer")){
			$wheres = " and id='".$params['id']."'";
		}
		$weight = 0;
		if($params['weight'] && is_int($params['weight'])){
			$weight = $params['weight'];
		}else if($params['weight']=="cartInfo"){
			$pm = new PurchaseModel();
			$weight = $pm->cartInfoWeight();
		}
		if(isset($params['iStatus']) && $params['iStatus']!="" && settype($params['iStatus'],"integer") && intval($params['iStatus'])){
			$iStatus = $params['iStatus'];
			$wheres .= "and iStatus='$iStatus'";
		}
		$res = $GLOBALS['db']->getAll("select * from qk_delivery_type where 1=1 $wheres order by id desc");
		load_class("delivery");
		$dm = new DeliveryModel();
		$i = 0;
		foreach($res as $k=>$v){
			if($weight){
				$res[$i]['price'] = $dm->getPrice($weight,$v['id']);
			}
			$i++;
		}
		
		$smarty->block_data[$dataindex]=$res;
	}
	if(is_array($smarty->block_data[$dataindex]) && $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;
}

?>