<?php
/*
 * Powered by b2bbuilder 
 * Auther:Brad zhang;
 * Date:2008-11-7
 * copyright:http://www.b2b-builder.com
 * Des:企业类别页面，已做缓存处理
 */
//==============================================
if(empty($_GET['m'])||empty($_GET['s']))
	die('forbiden;');
useCahe();
$flag=md5($dpid.$dcid.$config["temp"].$_COOKIE["langtw"]);
if(!$tpl->is_cached("company_index.htm",$flag))
{	
	include_once("config/usergroup.php");
	include_once("includes/page_utf_class.php");
	//=====================================
	$id=isset($_GET['id'])?$_GET['id']:NULL;
	$key=!empty($_GET['key'])?trim($_GET['key']):NULL;
	$firstRow=!empty($_GET['firstRow'])?$_GET['firstRow']:NULL;
	$totalRows=!empty($_GET['totalRows'])?$_GET['totalRows']:NULL;

	function GetCat($id)
	{
		global $db;
		if($id&&is_numeric($id))
			$sql=" and catid<='".$id."99' and catid>'".$id."00'";	
		else
			$sql=" and catid<=9999";
		$sql="SELECT catid,cat FROM ".COMPANYCAT." WHERE 1 $sql ORDER BY nums ASC";
		$db->query($sql);
		return $db->getRows();
	}
	$tpl->assign("guide",GetCatName($id)?GetCatName($id):"");
	$tpl->assign("cat",GetCat($id)?GetCat($id):GetCat(substr($id,0,-2)));
	$tpl->assign("companyType",explode('|',$config['companyType']));
	$sql='';
	if(!empty($_GET['province']))
		$sql=" and province='$_GET[province]'";
	if(!empty($dpid))
		$sql.=" and province='$dpid'";
	if(!empty($dcid))
		$sql.=" and city='$dcid'";
	if(!empty($id))
		$sql.="and catid like '%$_GET[id]%'";
	if(!empty($key))
		$sql.=" and (company regexp '".trim($key)."') ";
	if(!empty($_GET['ct']))
		$sql.=" and ctype='$_GET[ct]' ";
	if(isset($_GET['country']))
		$sql.=" and country='$_GET[country]' ";
	if(isset($_GET['ifpay']))
		$sql.=" and ifpay>1";
	if(isset($_GET['statu']))
		$sql.=" and statu=1";
	//------------------------
	$sql="SELECT  company,main_pro,company_id,domain,ctype,tel,contact,province,city,country,staff_num,logo,turnover,ifpay,addr,registered_capital,earnest FROM ".COMPANY." WHERE company!='' and shop_statu=1 $sql order by rank desc,ifpay desc,uptime desc"; 
	//------------------------
	$page = new Page;
	$page->listRows=10;
	$page->url=$config['weburl'];
	if(!$page->__get('totalRows'))
	{
		$db->query($sql);
		$page->totalRows = $db->num_rows();
	}
	$sql .= "  limit ".$page->firstRow.",".$page->listRows;
	//----------------------
	$db->query($sql);
	$coml=$db->getRows();
	foreach($coml as $key=>$v)
	{
		$ifpay=$v['ifpay'];
		if(!empty($group[$ifpay]['minilogo']))
			$coml[$key]['user_type']="<img height=20 src='".$group[$ifpay]['minilogo']."' alt='".$group[$ifpay]['name']."' >";
		else
			$coml[$key]['user_type']='['.$group[$ifpay]['name'].']';
			
		$sqlo="select flag from ".COUNTRY." where id='".$v['country']."'";
		$db->query($sqlo);
		$coml[$key]['country']=$db->fetchField('flag');
	}
	$infos['list']=$coml;
	$infos['pages']=$page->prompt();
	$tpl->assign("info",$infos);
}	
//=========================================
$tpl->assign("current","company");
include_once("footer.php"); 
$out=tplfetch("company_index.htm",$flag);
?>