<?php
/*
 * 74cms 猎头会员中心 
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/hunter_common.php');
$act=trim($_GET["act"])?trim($_GET["act"]):"recommend_by_resume";
// 按简历查看
if($act == "recommend_by_resume")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=2 and e.state=1 ";
	$orderbysql = " order by e.addtime desc ";
	// 求职状态
	$current_id= $_GET['current_id'];
	if($current_id!='')
	{
		$current_id=intval($current_id);
		$wheresql.=" and r.current=$current_id ";
	}
	// 个人学历
	$education= $_GET['education'];
	if($education!='')
	{
		$education=intval($education);
		$wheresql.=" and r.education=$education ";
	}
	// 工作经验
	$experience= $_GET['experience'];
	if($experience!='')
	{
		$experience=intval($experience);
		$wheresql.=" and r.experience=$experience ";
	}
	// 所在地区 需要修改
	if (isset($_GET['district'])  && $_GET['district']<>'' && isset($_GET['sdistrict'])  && $_GET['sdistrict']<>'')
	{
		
		$residence  = trim($_GET['district']).'.'.trim($_GET['sdistrict']);
		$wheresql.=" AND r.residence =".trim($residence);
	}
	// 申请时间
	$addtime_start = $_GET['star_time'];
	$addtime_end = $_GET['end_time'];
	if($addtime_start && $addtime_end)
	{
		$addtime_start=strtotime($addtime_start);
		$addtime_end=strtotime($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("entrust_hunter")." as e on e.resume_id=r.id ";
	//分页
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('resume')." as r ".$joinsql.$wheresql.$orderbysql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('page',$page->show(7));
	// 获取列表
	$sql="SELECT r.*,e.id entrust_id,e.entrust_type,e.is_apply,e.state,e.addtime entrust_time FROM ".table('resume')." as r ".$joinsql.$wheresql.$orderbysql;
	$row = $db->getall($sql);
	foreach ($row as $key => $value)
	{ 	
		$value['resume_url']=url_rewrite('QS_resumeshow',array('id'=>$value['id']));
		$value['fullname_']=$value['fullname'];
		$value['fullname']=cut_str($value['fullname'],3,0,'...');
		$value['district_cn_']=cut_str($value['district_cn'],6,0);
		$value['current_cn_']=cut_str($value['current_cn'],6,0);
		// 统计推荐职位数
		$resume_sql="select count(*) as num from ".table("hunter_recommend")." where resume_id=$value[id] and uid=$uid ";
		$num=$db->getone($resume_sql);
		$value['recommend_num']=$num['num'];
		$row[$key]=$value;
	}
	$smarty->assign('recommend_list',$row);
	$smarty->assign('title',' 推荐记录简历 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->display('member_hunter/recommend_by_resume.htm');
}
elseif($act == "recommend_by_jobs")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=1 and e.state=1 ";
	$orderbysql = " order by e.addtime desc ";
	//职位类型
	$jobs_type = $_GET['jobtype'];
	if($jobs_type!='')
	{	
		$jobs_type=intval($jobs_type);
		$wheresql.=" and j.jobs_type=$jobs_type ";
	}
	// 职位赏金
	$reward=$_GET['reward'];
	if($reward)
	{	
		$rewardarr=explode("-",$reward);
		$rewardarr=array_map(intval(), $rewardarr);
		$wheresql.=" and j.reward>=$rewardarr[0] and j.reward<=$rewardarr[1] ";
	}
	// 所在地区 需要修改
	if (isset($_GET['district'])  && $_GET['district']<>'')
	{
		if (strpos($_GET['district'],"-"))
		{
			$or=$orsql="";
			$arr=explode("-",$_GET['district']);
			$arr=array_unique($arr);
			if (count($arr)>20) exit();
			$sqlin=implode(",",$arr);
			if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
			{
				$wheresql.=" AND j.district IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND j.district =".intval($_GET['district']);
		}
	}
	if (isset($_GET['sdistrict'])  && $_GET['sdistrict']<>'')
	{
		if (strpos($_GET['sdistrict'],"-"))
		{
			$or=$orsql="";
			$arr=explode("-",$_GET['sdistrict']);
			$arr=array_unique($arr);
			if (count($arr)>10) exit();
			$sqlin=implode(",",$arr);
			if (preg_match("/^(\d{1,10},)*(\d{1,10})$/",$sqlin))
			{
				$wheresql.=" AND j.sdistrict IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND j.sdistrict =".intval($_GET['sdistrict']);
		}
	}	
	// 申请时间
	$addtime_start = $_GET['star_time'];
	$addtime_end = $_GET['end_time'];
	if($addtime_start && $addtime_end)
	{
		$addtime_start=strtotime($addtime_start);
		$addtime_end=strtotime($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("entrust_hunter")." as e on e.jobs_id=j.id ";
	//分页
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('jobs')." as j ".$joinsql.$wheresql.$orderbysql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('page',$page->show(7));
	// 获取列表
	$sql="SELECT j.*,e.id entrust_id,e.entrust_type,e.is_apply,e.state,e.addtime entrust_time FROM ".table('jobs')." as j ".$joinsql.$wheresql.$orderbysql;
	$row = $db->getall($sql);
	foreach ($row as $key => $value)
	{ 	
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		if($value['display']==1 && $value["audit"]==1 && $value["deadline"]>time())
		{
			$value['jobs_state']="正在招聘中";
		}
		if($value['display']==2 || $value['deadline']<time() || $value['setmeal_deadline']<time() || $value["audit"]!=1)
		{
			$value['jobs_state']="已经结束招聘";
		}
		// 统计推荐职位数
		$resume_sql="select count(*) as num from ".table("hunter_recommend")." where jobs_id=$value[id] and uid=$uid ";
		$num=$db->getone($resume_sql);
		$value['recommend_num']=$num['num'];
		$row[$key]=$value;
	}
	$smarty->assign('recommend_list', $row);
	$smarty->assign('title'," 推荐记录职位 - 猎头会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_hunter/recommend_by_jobs.htm');
}
// 推荐记录详细
elseif($act == "recommend_show")
{
	$entrust_type=intval($_GET['entrust_type']);
	$id=intval($_GET['id']);//职位id或者简历id
	$uid=intval($_SESSION['uid']);
	if($entrust_type==1)
	{
		$table="jobs";
		$wheresql=" and h.jobs_id=$id ";
		$joinsql=" left join ".table("resume")." as rj on rj.id=h.resume_id ";

	}else
	{
		$table="resume";
		$wheresql=" and h.resume_id=$id ";
		$joinsql=" left join ".table("jobs")." as rj on rj.id=h.jobs_id ";
	}
	$sql="select * from ".table($table)." where id=$id ";
	$row=$db->getone($sql);
	$recommend_sql="select rj.*,h.did,h.recommend_addtime,h.recommend_state from ".table("hunter_recommend")." as h ".$joinsql." where h.uid=$uid".$wheresql;
	$recommend_rst=$db->getall($recommend_sql);
	foreach ($recommend_rst as $key => $value)
	{
		$Y=date("Y",time());
		$value['age']=$Y-$value['birthdate'];
		$value['fullname_']=$value['fullname'];
		$value['fullname']=cut_str($value['fullname'],3,0);
		$value['district_cn_']=$value['district_cn'];
		$value['district_cn']=cut_str($value['district_cn'],5,0,'...');
		$value['jobs_name_']=$value['jobs_name'];
		$value['jobs_name']=cut_str($value['jobs_name'],10,0);
		$value['companyname_']=$value['companyname'];
		$value['companyname']=cut_str($value['companyname'],13,0);
		$value['current_cn_']=$value['current_cn'];
		$value['current_cn']=cut_str($value['current_cn'],6,0);
		$value['resume_url']=url_rewrite('QS_resumeshow',array('id'=>$value['id']));
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		$recommend_rst[$key]=$value;
	}
	$row['recommend_list']=$recommend_rst;
	if($row['birthdate'])
	{
		$Y=date("Y",time());
		$row['age']=$Y-$row['birthdate'];
	}
	$smarty->assign('recommend_show',$row);
	$smarty->assign('title'," 推荐记录详细 - 猎头会员中心 - ".$_CFG['site_name']);
	if($entrust_type==1)
	{
		$smarty->display('member_hunter/recommend_show_jobs.htm');
	}
	else
	{
		$smarty->display('member_hunter/recommend_show_resume.htm');
	}
}
// 删除推荐记录
elseif($act == "recommend_del")
{
	// $yid =!empty($_GET['y_id'])?$_GET['y_id']:$_POST['y_id'];//entrust_id
	$uid=intval($_SESSION['uid']);
	if($n=del_recommend($yid,$uid))
		{
			showmsg("删除成功！共删除 {$n} 行",2);
		}
		else
		{
			showmsg("删除失败！",0);
		}
}
unset($smarty);
?>