<?php
/**
 * copyright :b2bbuilder
 * Powered by :b2bbuilder
 * Auther:brad
 * Date: 2008-11-04
 * Des:非公共免费代码，没有得到b2bbuilder许可，禁止传播，复制。
 */
//===================
include_once("arrcache_class.php");
$cache     = new ArrCache('cache/apidata/');
$cachetime = $config['cacheTime'];//数据调用缓存时间。
//===================
function insert_label($ar)
{
	global $tpl,$config;
	$type=$ar['type'];
	$arr=explode('_',$type);
	if(file_exists("$config[webroot]/includes/label/".$arr[0]."_label.php"))
		include_once("$config[webroot]/includes/label/".$arr[0]."_label.php");
	else
		include_once("module/".$arr[0]."/label.php");
	$con=$type($ar);
	$tpl->caching=false;
	if($tpl->statu)
		$tpl->template_dir=$tpl->statu;
	else
		$tpl->template_dir = $config['webroot']."/templates/".$config['temp']."/";
	return $con;
}
//=========================
//公司调用
function insert_getUser($ar)
{
	global $cache,$cachetime,$dpid,$dcid;
	$ar[$dpid]=$dpid;
	$ar[$dcid]=$dcid;
	if(strlen($str=$cache->str_begin($ar,$cachetime))<=0)
	{	
		global $db,$config;
		
		$field=$ar['field'];
		$filter=$ar['filter'];
		$limit=$ar['limit'];
		$leng=$ar['leng'];
		$logo = $ar['logo'];
		$groupid=$ar['ugroupid'];
		$cid=$ar['catid'];
		$is_name=$ar['is_name']?false:true;
		$heig=$ar['height'];
		if (empty($heig))
             $heig=80;
		$width=$ar['width']?$ar['width']:"80";

		if(!empty($dpid))
			$sql=" and province='$dpid' ";
		if(!empty($dcid))
			$sql=" and city='$dcid' ";

		if(!empty($groupid))
			$sql=" and ifpay='$groupid' ";
		if(!empty($logo))
			$sql=" and logo != '' ";

		if(!empty($cid))
			$sql=" and catid like '%,$cid%'";
		if($filter=="new")
			$sql.=" order by uptime desc ";
		elseif($filter=="old")
			$sql.=" order by uptime asc ";
		elseif($filter=="rand")
			$sql.=" order by rand() ";
		elseif($filter=="rec")
			$sql.=" and statu=1 order by rank desc";
		elseif($filter=="star")
			$sql.=" and statu=2 order by rank desc";
		else
			$sql.=" order by uptime desc ";

		$sql="select company_id,domain,logo,$field from ".COMPANY." where company!='' $sql limit 0,".$limit;
		
		$db->query($sql);
		$fileds=explode(",",$field);
		$res=$db->getRows();
		foreach($res as $num=>$k)
		{
			$str.="<li class='fore".($num+1)."'>";
					if(!empty($logo))
					{
						if(empty($k['logo']))
							$str.="<a href='".geturl($k['company_id'],$k['domain'],$k['company'])."' title='' target='_blank'><img width=".$width." height=".$heig." src='$config[weburl]/image/default/nopic.gif'>";
						else
				     		$str.="<a href='".geturl($k['company_id'],$k['domain'],$k['company'])."' title='' target='_blank'><img width=\"".$width."\" height=\"".$heig."\" src='$k[logo]'>";
					}
					else
					{
						$str.="<a href='".geturl($k['company_id'],$k['domain'],$k['company'])."' title='' target='_blank'>";
					}
					if($is_name)
					{
					   foreach($fileds as $key=>$v)
					   {
						   	$str.="</br >";
							$str.=csubstr($k[$v],0,$leng)."&nbsp;";
					   }
					}
			$str.="</a></li>";
		}
	}
	$cache->str_end($str);
	return $str;
}
//公告调用
function insert_getNotice($ar)
{
	global $cache,$cachetime;
	if(strlen($str=$cache->str_begin($ar,$cachetime))<=0)
	{	
		global $db,$config;
		$limit=$ar['limit'];	//条数
		$leng = $ar['leng'];	//标题长度
		$flag_id=md5(implode(".",$ar));
		if(empty($limit))
			$limit=5;
		if(empty($leng))
            $leng=30;
		$nt=strtotime(date("Y-m-d"));
		$sql="SELECT * from ".NOTICE." where endtime>$nt order by sort asc,id desc limit 0,".$limit;
		$db->query($sql);
		$re=$db->getRows();
		if($mqu=="true")
		   $str='<div id='.$flag_id.' ><ul>';
		else
		   $str='';
		foreach($re as $v)
		{
			 if($v['type']=="1")
			{
			      $str.='<li><a href="'.$config['weburl'].'/?m=announcement&s=detail&id='.$v['id'].'" target="_blank" title="'.$v['title'].'" >'.csubstr($v['title'],0,$leng).'</a></li>';
			}
			 else
			{
				  $conurl=str_replace("<p>",'',$v['content']);
                  $conurl=str_replace("</p>",'',$conurl);
			      $str.='<li><a href="'.$conurl.'" target="_blank" title="'.$v['title'].'" >'.csubstr($v['title'],0,$leng).'</a></li>';
			}
		}
	}
	$cache->str_end($str);
	return $str;
}
function insert_getseach($ar)
{
	global $db,$cache,$cachetime,$config,$buid;
	$notkey=explode(',',$ar['notkey']);
	$va=$ar['va'];
	$urlr="";
	
	if($va!='')
		$urlr=$notkey[0]."=".urlencode(trim($va));	
	
	$notvar=array('','firstRow','totalRows');
	$notvar=array_merge($notkey,$notvar);
		
	if(is_array($_GET))
	{
		foreach($_GET as $key=>$val)
		{
			if(!in_array($key,$notvar)&&($val!='index'))
				$urlr.=(!empty($urlr)?"&":'')."$key=".urlencode(trim($val));
		}
	}
	return $urlr;
}
?>