<?php
/*********************************************
*骑士猎头顾问列表
* *******************************************/
function tpl_function_qishi_hunter($params, &$smarty)
{
	global $db,$_CFG;
	$arrset=explode(',',$params['set']);
	foreach($arrset as $str)
	{
	$a=explode(':',$str);
		switch ($a[0])
		{
		case "列表名":
			$aset['listname'] = $a[1];
			break;
		case '猎头ID':
			$aset['id'] = $a[1];
			break;
		}
	}
	$aset=array_map("get_smarty_request",$aset);
	$aset['listname']=isset($aset['listname'])?$aset['listname']:"show";
	$aset['listpage']=isset($aset['listpage'])?$aset['listpage']:"QS_hunter_show";
	$aset['id']=$aset['id']?intval($aset['id']):0;
	$h_sql="select * from ".table("hunter_profile")." where id=$aset[id] limit 1";
	$hunter=$db->getone($h_sql);
	if(empty($hunter))
	{
		header("HTTP/1.1 404 Not Found"); 
		$smarty->display("404.htm");
		exit();
	}
	else
	{
		$db->query("update ".table("hunter_profile")." set click=click+1 where id=$hunter[id] ");
		$time=time();
		$orderbysql=" order by refreshtime desc ";
		$wheresql=" where audit=1 AND deadline>{$time} AND display=1 and company_id=$hunter[id]";
		require_once(QISHI_ROOT_PATH.'include/page.class.php');
		$perpage=5;
		$total_sql="SELECT COUNT(*) AS num FROM ".table('jobs').$wheresql.$orderbysql;
		$total_val=$db->get_total($total_sql);
		$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
		$offset=($page->nowindex-1)*$perpage;
		if($total_val>$perpage)
		{
			$smarty->assign('page',$page->show(7));
		}
		$jobs_list=$db->getall("SELECT * from ".table('jobs').$wheresql.$orderbysql." limit $offset,$perpage ");

		// 查找合作过的企业
		$hunter['collaborative_list']=get_hunter_collaborative($hunter['uid']);
		$hunter['jobs']=$jobs_list;
		$smarty->assign($aset['listname'],$hunter);
	}
}
function get_hunter_collaborative($uid)
{
	global $db;
	$uid=intval($uid);
	$sql="select * from ".table("hunter_collaborative")." where hunter_uid=$uid ORDER by id desc limit 6 ";
	$arr=$db->getall($sql);
	foreach ($arr as $key => $value)
	{
		$value["company_name_"]=cut_str($value['company_name'],10,0,'...');
		$arr[$key]=$value;
	}
	return $arr;
}
?>