<?php
/*********************************************
*通讯录详细信息
* *******************************************/
function tpl_function_qishi_list_show($params, &$smarty)
{
	global $db,$timestamp,$_CFG;
	$arr=explode(',',$params['set']);
	foreach($arr as $str)
	{
	$a=explode(':',$str);
		switch ($a[0])
		{
		case "通讯录ID":
			$aset['id'] = $a[1];
			break;
		case "列表名":
			$aset['listname'] = $a[1];
			break;
		}
	}
	$aset=array_map("get_smarty_request",$aset);
	$aset['id']=$aset['id']?intval($aset['id']):0;
	$aset['listname']=$aset['listname']?$aset['listname']:"list";
	$wheresql=" WHERE id={$aset['id']} ";
	$sql = "select * from ".table('list').$wheresql." LIMIT 1";
	$val=$db->getone($sql);
	if (empty($val))
	{
		header("HTTP/1.1 404 Not Found"); 
		$smarty->display("404.htm");
		exit();
	}
	else
	{
		$db->query("update ".table('list')." set click=click+1 where id=".$val['id']);
		$val['title_'] = $val['title'];
		$val['title'] = cut_str($val['title'],20,0,"...");
		$val['number']=$val['number']=="0"?'若干':$val['number'];
		$profile=GetCompanyHunterProfile($val['uid'],$val['utype']);
		$val['belong'] = $profile;
		$val['list_time']=date('Y',$val['list_time']);
		$val['file_size']=filesizerange($val['file_size']);
		$val['addtime']=daterange(time(),$val['addtime'],'Y-m-d',"#FF3300");
		if(intval($val['number'])>999)
		{
			$val['number']='999+';
		}
		$down_num = get_click_num($val['id']);
		$val['down_num']=intval($down_num);
		$user_down = get_user_down($val['id']);
		foreach ($user_down as $key => $value) 
		{
			$email_result = explode('@', $value['email']);
			$email_result[0] =substr($email_result[0], 0,3);
			$value['email'] = $email_result[0]."***@".$email_result[1];
			$value['down_time'] = date('Y-m-d',$value['down_time']);
			$user_down[$key] =$value; 
		}
		$val['user'] = $user_down;
		if(intval($val['utype'])==1)
		{
			$val['belong_url']=url_rewrite('QS_companyshow',array('id'=>$profile['id']));
			if($profile['logo'])
			{
				$val['belong']['logo']=$_CFG['site_dir']."data/logo/".$profile['logo'];
			}
			else
			{
				$val['belong']['logo']=$_CFG['site_dir']."data/logo/no_logo.gif";
			}
		}
		elseif(intval($val['utype'])==3)
		{
			$val['belong_url']=url_rewrite('QS_hunter_show',array('id'=>$profile['id']));
			if($profile['avatars'])
			{
				$val['belong']['logo']=$_CFG['site_dir']."data/hunter/photo_img".$profile['avatars'];
			}
			else
			{
				$val['belong']['logo']=$_CFG['site_dir']."data/hunter/photo_img/no_photo.gif";
			}
		}
	}
$smarty->assign($aset['listname'],$val);
}
function GetCompanyHunterProfile($uid,$utype)
{
	global $db;
	$utype = intval($utype);
	if($utype==1)
	{
		$sql = "select * from ".table('company_profile')." where uid=".intval($uid)." LIMIT 1 ";
	}
	elseif($utype==3)
	{
		$sql = "select * from ".table('hunter_profile')." where uid=".intval($uid)." LIMIT 1 ";
	}
	return $db->getone($sql);
}
function get_click_num($id)
{
	global $db;
	$uid=intval($uid);
	$sql = "SELECT  COUNT(*) AS num  FROM ".table('down_list')."  WHERE id='{$id}' ";
	return $db->get_total($sql);
}
function get_user_down($id)
{
	global $db;
	$id=intval($id);
	$sql = "SELECT  d.*,m.email  FROM ".table('down_list')." AS d  INNER  JOIN ".table("members")." as  m on d.uid=m.uid WHERE d.id='{$id}'  ORDER BY down_time DESC LIMIT 4";
	return $db->getall($sql);
}
?>