<?php
/*********************************************
*骑士通讯录列表
* *******************************************/
function tpl_function_qishi_list($params, &$smarty)
{
global $db,$_CFG;
$arr=explode(',',$params['set']);
foreach($arr as $str)
{
$a=explode(':',$str);
	switch ($a[0])
	{
	case "列表名":
		$aset['listname'] = $a[1];
		break;
	case "标题长度":
		$aset['titlelen'] = $a[1];
		break;
	case "关键字":
		$aset['key'] = $a[1];
		break;
	case "行业":
		$aset['trade'] = $a[1];
		break;
	case "行业长度":
		$aset['tradelen'] = $a[1];
		break;
	case "填补字符":
		$aset['dot'] = $a[1];
		break;
	case "年份":
		$aset['list_time'] = $a[1];
		break;
	case "手机":
		$aset['mobile'] = $a[1];
		break;
	case "邮箱":
		$aset['email'] = $a[1];
		break;
	case "分页显示":
		$aset['page'] = $a[1];
		break;
	case "开始位置":
		$aset['start'] = $a[1];
		break;
	case "显示数目":
		$aset['row'] = $a[1];
		break;
	case "排序":
		$aset['displayorder'] = $a[1];
		break;
	}
}
if (is_array($aset)) $aset=array_map("get_smarty_request",$aset);
$aset['listname']=isset($aset['listname'])?$aset['listname']:"list";
$aset['titlelen']=isset($aset['titlelen'])?intval($aset['titlelen']):40;
$aset['tradelen']=isset($aset['tradelen'])?intval($aset['tradelen']):35;
$aset['dot']=isset($aset['dot'])?$aset['dot']:'...';
$aset['row']=intval($aset['row'])>0?intval($aset['row']):10;
if ($aset['row']>30)$aset['row']=30;
$aset['start']=isset($aset['start'])?intval($aset['start']):0;
$listtable = table('list');
//排序
if (isset($aset['displayorder']))
{
	$arr=explode('>',$aset['displayorder']);
	$arr[1]=preg_match('/asc|desc/',$arr[1])?$arr[1]:"desc";
	if ($arr[0]=="click")
	{
		$orderbysql=" ORDER BY click {$arr[1]}";
	}
	else
	{
		$orderbysql=" ORDER BY price {$arr[1]}";
	}
}else{
	$orderbysql=" ORDER BY addtime desc";
}
//关键字--搜索
if (isset($aset['key']) && !empty($aset['key']))
{
	$key=trim($aset['key']);
	$akey=explode(' ',$key);
	if (count($akey)>1)
	{
	$akey=array_filter($akey);   			//array_filter() 将删除 参数 中所有值为 FALSE 或者 NULL的条目
	$akey=array_slice($akey,0,2);			//返回根据 offset 和 length 参数所指定的 array 数组中的一段序列。 
	$akey=array_map("fulltextpad",$akey);	//返回一个数组，该数组包含了 akey 中的所有单元经过 fulltextpad 作用过之后的单元。
	$key='+'.implode(' +',$akey);
	$mode=' IN BOOLEAN MODE';
	}
	else
	{
	$key=fulltextpad($key);
	$mode=' ';
	}
	$wheresql = " MATCH (l.`key`) AGAINST ('{$key}'{$mode}) ";
}
//行业
if (isset($aset['trade']) && $aset['trade']<>'')
{
	$wheresql .= "  AND l.trade={$aset['trade']} ";
}
//年份
if (isset($aset['list_time']) && $aset['list_time']<>'')
{
	$list_time=intval($aset['list_time']);
	if ($list_time>0)
	{
	$list_val=intval(strtotime($aset['list_time']."-01-01"));
	$wheresql.=" AND l.list_time=".$list_val;
	}
}
//手机
if (isset($aset['mobile']) && $aset['mobile']<>'')
{
	$wheresql .= "  AND l.mobile={$aset['mobile']} ";
}
//邮箱
if (isset($aset['email']) && $aset['email']<>'')
{
	$wheresql .= "  AND l.email={$aset['email']} ";
}
$wheresql .= "  AND l.audit=1 ";
if (!empty($wheresql))
{
$wheresql=" WHERE ".ltrim(ltrim($wheresql),'AND');
}
//分页
if (isset($aset['page']))
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$total_sql="SELECT  COUNT(*) AS num  FROM  {$listtable} as l ".$wheresql;
	$total_count=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_count, 'perpage'=>$aset['row']));
	$currenpage=$page->nowindex;
	$aset['start']=abs($currenpage-1)*$aset['row'];
	$smarty->assign('page',$page->show(7));
	$smarty->assign('pagemin',$page->show(6));
	$total_count = $total_count>3000?$total_count."+":$total_count;
	$smarty->assign('total',$total_count);
}
$limit=" LIMIT {$aset['start']} , {$aset['row']}";
$list = $id = array();
$list_sql = $db->query("SELECT l.* FROM ".table('list')." as l ".$wheresql.$orderbysql.$limit);
while($row = $db->fetch_array($list_sql))
{
	//上传人 （根据不同的会员类型（企业/猎头）得到相应的上传人）
	if($row['utype']=='1')
	{
		$result = $db->getone("SELECT * FROM ".table('members')."  WHERE  uid=".$row['uid']." LIMIT 1");
		$row['fullname_']=$result['fullname'];
		$row['fullname']=cut_str($result['fullname'],5,0,$aset['dot']);
	}
	else
	{
		$result = $db->getone("SELECT * FROM ".table('hunter_profile')."  WHERE  uid=".$row['uid']." LIMIT 1");
		$row['fullname_']=$result['fullname'];
		$row['fullname']=cut_str($result['fullname'],5,0,$aset['dot']);
	}
	$row['title_']=$row['title'];
	$row['title']=cut_str($row['title'],$aset['titlelen'],0,$aset['dot']);
	$row['title_url']=url_rewrite('QS_list_show',array('id'=>$row['id']));
	$row['addtime']=daterange(time(),$row['addtime'],'Y-m-d',"#FF3300");
	$row['list_time']=date('Y',$row['list_time']);
	//下载次数
	$row['down_num']=$db->get_total("SELECT COUNT(*) AS num FROM ".table('down_list')." WHERE list_id=".$row['id']);
	$list[] = $row;
}
$smarty->assign($aset['listname'],$list);
}
?>