<?php
/*********************************************
*企业简介
* *******************************************/
function tpl_function_qishi_jobs_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']} and audit=1 AND display=1 AND (deadline>$timestamp or deadline=0) AND (setmeal_deadline>$timestamp or setmeal_deadline=0)";
	$sql = "select * from ".table('jobs').$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('jobs')." set click=click+1 where id=".$val['id']);
			$db->query("update ".table('jobs_search_hot')." set click=click+1 where id=".$val['id']);
			if ($val['setmeal_deadline']<time() && $val['setmeal_deadline']<>"0" && $val['add_mode']=="2")
			{
			$val['deadline']=$val['setmeal_deadline'];
			}
			$val['company_url']=$val['company_url'];
			$val['amount']=$val['amount']=="0"?'若干':$val['amount'];
			$profile=GetJobsCompanyProfile($val['company_id']);
			$val['company']=$profile;
			$val['expire']=sub_day($val['deadline'],time());		
			$val['company_url']=url_rewrite('QS_companyshow',array('id'=>$val['company_id']));
			if ($val['company']['logo'])
			{
			$val['company']['logo']=$_CFG['site_dir']."data/logo/".$val['company']['logo'];
			}
			else
			{
			$val['company']['logo']=$_CFG['site_dir']."data/logo/no_logo.gif";
			}
			$val['refreshtime_cn']=daterange(time(),$val['refreshtime'],'Y-m-d',"#FF3300");
			if($_SESSION['utype']==3)
			{
				$arr=get_entrust_hunter($val['id'],$_SESSION['uid']);
				if(!empty($arr))
				{
					$val['entrust_hunter']=1;//委托过
				}else
				{
					$val['entrust_hunter']=2;//未委托
				}
			}
			if ($val['tag'])
			{
				$tag=explode('|',$val['tag']);
				$taglist=array();
				if (!empty($tag) && is_array($tag))
				{
					foreach($tag as $t)
					{
					$tli=explode(',',$t);
					$taglist[]=array($tli[0],$tli[1]);
					}
				}
				$val['tag']=$taglist;
			}
			else
			{
			$val['tag']=array();
			}
			$setmeal=get_user_setmeal(intval($_SESSION['parentuid']));
			$setmeal['setmeal_name'] = cut_str($setmeal['setmeal_name'],3,0);
			$smarty->assign('setmeal',$setmeal);
	}
$smarty->assign($aset['listname'],$val);
}
function GetJobsCompanyProfile($id)
{
	global $db;
	$sql = "select * from ".table('company_profile')." where id=".intval($id)." LIMIT 1 ";
	return $db->getone($sql);
}
function get_user_setmeal($uid)
{
	global $db;
	$uid=intval($uid);
	$sql = "select * from ".table('members_setmeal')."  WHERE uid='{$uid}' AND  effective=1 LIMIT 1";
	return $db->getone($sql);
}
// 是否委托过某个猎头
function get_entrust_hunter($jobs_id,$hunter_id)
{
	global $db;
	$jobs_id=intval($jobs_id);
	$hunter_id=intval($hunter_id);

	$sql = "select * from ".table('entrust_hunter')."  WHERE hunter_uid='{$hunter_id}' AND  jobs_id=$jobs_id AND state=1 LIMIT 1";
	return $db->getone($sql);
}
?>