<?php
/*
 * 74cms 猎头会员中心 
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/hunter_common.php');
$act=trim($_GET["act"])?trim($_GET["act"]):"my_entrust_jobs";
// 我申请的企业职位
if($act == "my_entrust_jobs")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=1 and e.is_apply=1 ";
	$orderbysql = " order by e.addtime desc ";
	//职位类型
	$jobs_type = $_GET['jobtype'];
	if(isset($jobs_type) && $jobs_type<>'')
	{	
		$jobs_type=intval($jobs_type);
		$wheresql.=" and j.jobs_type=$jobs_type ";
	}
	//处理状态
	$state= $_GET['state'];
	if($state!='')
	{
		$state=intval($state);
		$wheresql.=" and e.state=$state ";
	}
	// 职位赏金
	$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);
		$addtime_end= intval($addtime_end)+86400;
		$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_name"]=cut_str($value['jobs_name'],9,0,'...');
		$value["companyname"]=cut_str($value['companyname'],10,0,'...');
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		$row[$key]=$value;
	}
	$smarty->assign('list', $row);
	$smarty->assign('title'," 我申请的职位 - 猎头会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_hunter/my_entrust_jobs.htm');
}
// 我申请的个人简历
elseif($act == "my_entrust_resume")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=2 and e.is_apply=1 ";
	$orderbysql = " order by e.addtime desc ";
	//处理状态
	$state= $_GET['state'];
	if($state!='')
	{
		$state=intval($state);
		$wheresql.=" and e.state=$state ";
	}
	// 个人学历
	$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']<>'')
	{
		if(intval($_GET['sdistrict'])==0)
		{
			$district = trim($_GET['district']);
			$wheresql.=" AND r.district like '%".$district."%'";
		}
		else
		{
			$district = trim($_GET['district']).'.'.trim($_GET['sdistrict']);
			$wheresql.=" AND r.district like '%".$district."%'";
		}
	}
	// 求职状态
	$current_id= $_GET['current_id'];
	if($current_id!='')
	{
		$current_id=intval($current_id);
		$wheresql.=" and r.current=$current_id ";
	}
	// 申请时间
	$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);
		$addtime_end= intval($addtime_end)+86400;
		$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['district_cn_']=cut_str($value['district_cn'],6,0);
		$value['current_cn_']=cut_str($value['current_cn'],6,0);
		$row[$key]=$value;
	}
	$smarty->assign('resume_list',$row);
	$smarty->assign('title',' 我申请的简历 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->display('member_hunter/my_entrust_resume.htm');
}
// 委托我的企业
elseif($act == "entrust_me_company")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=1 and e.is_apply=0 ";
	$orderbysql = " order by e.addtime desc ";
	//职位类型
	$jobs_type = $_GET['jobtype'];
	if(isset($jobs_type) && $jobs_type<>'')
	{	
		$jobs_type=intval($jobs_type);
		$wheresql.=" and j.jobs_type=$jobs_type ";
	}
	//处理状态
	$state= $_GET['state'];
	if($state!='')
	{
		$state=intval($state);
		$wheresql.=" and e.state=$state ";
	}
	// 职位赏金
	$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_name_"] = $value["jobs_name"];
		$value["jobs_name"]=cut_str($value['jobs_name'],8,0,'...');
		$value["companyname_"] = $value["companyname"];
		$value["companyname"]=cut_str($value['companyname'],12,0,'...');
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		$row[$key]=$value;
	}
	$smarty->assign('list', $row);
	$smarty->assign('title'," 收到企业的委托 - 猎头会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_hunter/entrust_me_company.htm');
}
// 委托我的个人
elseif($act == "entrust_me_personal")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.hunter_uid=$uid and e.entrust_type=2 and e.is_apply=0 ";
	$orderbysql = " order by e.addtime desc ";
	//处理状态
	$state= $_GET['state'];
	if($state!='')
	{
		$state=intval($state);
		$wheresql.=" and e.state=$state ";
	}
	// 个人学历
	$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 ";
	}
	// 求职状态
	$current_id= $_GET['current_id'];
	if($current_id!='')
	{
		$current_id=intval($current_id);
		$wheresql.=" and r.current=$current_id ";
	}
	// 申请时间
	$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'],4,0);
		$value['district_cn_']=cut_str($value['district_cn'],6,0);
		$value['current_cn_']=cut_str($value['current_cn'],6,0);
		$row[$key]=$value;
	}
	$smarty->assign('resume_list',$row);
	$smarty->assign('title'," 收到个人的委托 - 猎头会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_hunter/entrust_me_personal.htm');
}
// 委托我的企业,个人 我进行同意操作
elseif($act == "entrust_me_agree")
{
	// $state=intval($_GET['state']);
	$entrust_id=intval($_GET['entrust_id']);
	$hunter_uid=intval($_SESSION['uid']);
	$entrust_arr=$db->getone("SELECT * from ".table("entrust_hunter")." where id=$entrust_id and hunter_uid=$hunter_uid");
	$sql="update ".table("entrust_hunter")." set state=$state where id=$entrust_id and hunter_uid=$hunter_uid ";
	if($entrust_arr['entrust_type']==2 && $state==1)
	{
		add_favorites($entrust_arr['resume_id'],$hunter_uid);
	}
	!$db->query($sql)?showmsg("操作失败！",0):showmsg("操作成功！",2);
}
// 删除信息
elseif($act == "entrust_del")
{
	// $yid =!empty($_GET['y_id'])?$_GET['y_id']:$_POST['y_id'];//entrust_id
	$uid=intval($_SESSION['uid']);
	if($n=del_entrust($yid,$uid))
		{
			showmsg("删除成功！共删除 {$n} 行",2);
		}
		else
		{
			showmsg("删除失败！",0);
		}
}
unset($smarty);
?>