<?php
function exportExcel($filename,$content)
{ 
	header("Content-type:text/csv"); 
	header("Content-Disposition:attachment;filename=".$filename); 
	header('Cache-Control:must-revalidate,post-check=0,pre-check=0'); 
	header('Expires:0'); 
	header('Pragma:public'); 
	echo $content;    
} 
function geticonv($str)
{
	return  iconv('utf-8','gb2312',$str); 
}
function get_country($id)
{
	global $db;
	$sql="select cname from ".COUNTRY." where id='$id'";
	$db->query($sql);
	return $db->fetchField('cname');
}
$get=$_GET;
unset($get['userid']);unset($get['s']);
$getstr=implode('&',convert($get));
if(!empty($_GET['ordrby']))
	$ordrby='u.'.$_GET['ordrby'];
else
	$ordrby='u.uptime';	
if(!empty($_GET['keyword']))
{
	if($_GET['category']=='email')
		$scl.=" and a.email='$_GET[keyword]' ";
	else
		$scl.=" and (u.$_GET[category] regexp '$_GET[keyword]')  ";
}
if(!empty($_GET['only']))
	$scl.=" and u.ifpay='".$_GET['only']."'";
if($_SESSION['province'])
	$scl.=" and u.province='$_SESSION[province]'";
if($_SESSION['city'])
	$scl.=" and u.city='$_SESSION[city]'";
if(!empty($_GET['catid']))
	$scl.=" and u.catid like '%,$_GET[catid]%'";
if($_GET['country']!='')
	$scl.=" and u.country='$_GET[country]'";
if(!empty($_GET['identity']))
	$scl.=" and u.identity='$_GET[identity]'";
if(!empty($_GET['invite']))
	$scl.=" and au.invite='$_GET[invite]'";
if(!empty($_GET['is_tel']))
	$scl.=" and u.tel!='' ";
//==================================
$sql="SELECT u.*,au.email,au.invite from ".COMPANY." u  left join ".ALLUSER." au  on u.company_id=au.userid  WHERE 1 $scl";
if($_GET['order']) 
   $sql.=" order by $ordrby asc";  
else 
   $sql.=" order by $ordrby desc ";
$db->query($sql); 
$str = iconv('utf-8','gb2312',$str); 
$str=geticonv("会员帐号\t企业名称\t国家\t省份\t城市\t联系地址\t联系电话\t传真\t邮箱\t邀请人\t企业类型\t联系人\t主营行业\t主营产品\t更新时间\t信息完善度\n"); 
$re=$db->getRows();
include_once($config['webroot'].'/module/company/includes/companyfen_class.php');
$companyfen=new companyfen();
foreach($re as $v)
{    
	//----------------------COMPANYCAT------------------
	if (!empty($com["catid"]))
	{
		$strcat=explode(",",$com["catid"]);
		$st=implode("','",$strcat);
		$sqlo="select cat  from ".COMPANYCAT." where catid in ('".$st."')";
		$this ->db ->query($sqlo);
		$catn=$this ->db->getRows();
		$v["catname"]='';
		foreach($catn as $vc)
		{
			$v["catname"].=$vc['cat'].'&nbsp;|&nbsp;';
		}
	}
	//--------------------------------------------------
	$v['country']=get_country($v['country']);
	$tm1=date("Y-m-d",$v['uptime']);
	$msg=$companyfen->get_all($v['userid']);
	$str .= geticonv("$v[user]\t$v[company]\t$v[country]\t$v[province]\t$v[city]\t$v[addr]\t$v[tel]\t$v[fax]\t$v[email]\t$v[invite]\t$v[ctype]\t$v[contact]\t$v[catname]\t$v[main_pro]\t$tm1\t$msg/100\n");
} 
$filename = date('Ymd').'.xls'; 
exportExcel($filename,$str); 
?>