<?php
/*
 * 74cms 个人会员中心
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/

define('IN_QISHI', true);
require_once(dirname(__FILE__).'/personal_common.php');
require_once(dirname(__FILE__).'/../../include/fun_user.php'); 
$smarty->assign('nav','hunter_service');
$act=trim($_GET["act"])?trim($_GET["act"]):"hunter_service";
// 猎头服务-->合作猎头
if ($act=='hunter_service')
{
	$uid = intval($_SESSION['uid']);
	$pid = intval(get_pid($uid));
	$wheresql=" where state=1 and resume_uid={$uid} and resume_id={$pid}";
	$smarty->assign('title','猎头服务 - 合作猎头 - 个人会员中心 - '.$_CFG['site_name']);
	$smarty->assign('hunter_list',get_personal_hunter($uid));	//获取个人合作猎头列表
	//搜索条件 : 委托猎头   合作日期
	if($_GET['hunter_id'])
	{
		if($_GET['hunter_id']!="all")
		{
			$hunter_id=intval($_GET["hunter_id"]);
			$wheresql.=" and hunter_uid=$hunter_id ";
		}
	}
	if($_GET['star_time'] && $_GET['end_time'])
	{
		$star_time=strtotime($_GET['star_time']);
		$end_time=strtotime($_GET['end_time'])+3600*24;
		$wheresql.=" and addtime>=$star_time and addtime<=$end_time ";
	}
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table("entrust_hunter").$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;
	$time= intval(time());
	$sql="select * from ".table("entrust_hunter").$wheresql." LIMIT {$offset},{$perpage} ";
	$list=$db->getall($sql);
	if($list){
		foreach ($list as $key => $value)
		{
			// 猎头信息
			$hunter_sql="select * from ".table("hunter_profile")." where uid=$value[hunter_uid] ";
			$hunter_row=$db->getone($hunter_sql);
			$value['hunter_level_meal']=$hunter_row['level_meal'];
			$value['hunter_level']=$hunter_row['level'];
			$value['hunter_last_login_time']=$hunter_row['last_login_time'];
			$value['hunter_work']=date("Y",time())-$hunter_row['worktime'];
			// 统计 猎头发布中的职位数
			$jobs_sql="select count(*) num from ".table("jobs")." where uid={$value['hunter_uid']} and utype=3 and  audit=1 and deadline>{$time} and display=1 and setmeal_deadline>{$time} ";
			$jobs_row=$db->getone($jobs_sql); 
			$value['jobs_num']=$jobs_row['num'];
			// 统计 推荐记录 推荐职位数
			$resume_sql="select count(*) num from ".table("hunter_recommend")." where uid={$value['hunter_uid']} and personal_uid={$uid} and resume_id={$pid}";
			$resume_row=$db->getone($resume_sql);
			$value['recommend_jobs_num']=$resume_row['num'];
			$list[$key]=$value;
		}
	}
	$smarty->assign('service_list',$list);
	if($total_val>$perpage)
	{
		$smarty->assign('page',$page->show(7));
	}
	$smarty->assign('utype',$_SESSION['utype']);
	$smarty->display('member_personal/personal_hunter_service.htm');
}
// 推荐列表
elseif($act == "recommend_list")
{
	$id=intval($_GET['id']);//简历id
	$uid=intval($_SESSION['uid']);

	$table="resume";
	$wheresql=" and h.resume_id=$id ";
	$joinsql=" left join ".table("jobs")." as rj on rj.id=h.jobs_id left join ".table("hunter_profile")." as p on p.uid=h.uid";

	$sql="select * from ".table($table)." where id=$id ";
	$row=$db->getone($sql);
	$recommend_sql="select rj.*,h.did,h.recommend_addtime,h.recommend_state,p.fullname,p.id hid from ".table("hunter_recommend")." as h ".$joinsql." where h.personal_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['current_cn_']=cut_str($value['current_cn'],6,0);
		$value['jobs_url']=url_rewrite('QS_jobsshow',array('id'=>$value['id']));
		$value['com_url']=url_rewrite('QS_companyshow',array('id'=>$value['company_id']));
		$value['hun_url']=url_rewrite('QS_hunter_show',array('id'=>$value['hid']));
		$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']);
	$smarty->display('member_personal/personal_recommend_list.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("删除失败！",2);
		}
}
// 个人收到 猎头 的申请
elseif($act == "entrust_me_hunter")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.resume_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 ";
	}
	// 猎头等级
	$hunter_level_meal=$_GET['level_meal'];
	if($hunter_level_meal!='')
	{
		$hunter_level_meal=intval($hunter_level_meal);
		$wheresql.=" and h.level_meal=$hunter_level_meal ";
	}
	// 姓名
	$hunter_name=trim($_GET['hunter_name']);
	if($hunter_name)
	{
		$wheresql.=" and e.hunter_name='$hunter_name' ";
	}
	// 所在地区 需要修改
	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 r.district IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND r.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 r.sdistrict IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND r.sdistrict =".intval($_GET['sdistrict']);
		}
	}	
	// 申请时间
	$addtime_start = $_GET['star_time'];
	$addtime_end = $_GET['end_time'];
	if($addtime_start && $addtime_end)
	{
		$addtime_start=time($addtime_start);
		$addtime_end=time($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("resume")." as r on e.resume_id=r.id left join ".table("hunter_profile")." h on h.uid=e.hunter_uid ";
	//分页
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('entrust_hunter')." as e ".$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,e.hunter_name,h.worktime,h.level_meal,h.id hunter_id,h.district_cn h_district_cn FROM ".table('entrust_hunter')." as e ".$joinsql.$wheresql.$orderbysql;
	
	$row = $db->getall($sql);
	foreach ($row as $key => $value)
	{
		$Y=date("Y");
		$value['worktime']=$Y-$value['worktime'];
		$value['hunter_url']=url_rewrite('QS_hunter_show',array('id'=>$value['hunter_id']));
		$value['hunter_name_']=$value['hunter_name'];
		$value['hunter_name']=cut_str($value['hunter_name'],3,0,'...');
		$row[$key]=$value;
	}
	$smarty->assign('entrust_list', $row);
	$smarty->assign('title'," 收到的申请 - 个人会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_personal/entrust_me_hunter.htm');
}
// 个人 申请的猎头
elseif($act == "my_entrust_hunter")
{
	$uid=intval($_SESSION['uid']);
	$wheresql=" where e.resume_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 ";
	}
	// 猎头等级
	$hunter_level_meal=$_GET['level_meal'];
	if($hunter_level_meal!='')
	{
		$hunter_level_meal=intval($hunter_level_meal);
		$wheresql.=" and h.level_meal=$hunter_level_meal ";
	}
	// 姓名
	$hunter_name=trim($_GET['hunter_name']);
	if($hunter_name)
	{
		$wheresql.=" and e.hunter_name='$hunter_name' ";
	}
	// 所在地区 需要修改
	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 h.district IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND h.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 h.sdistrict IN  ({$sqlin}) ";
			}
		}
		else
		{
			$wheresql.=" AND h.sdistrict =".intval($_GET['sdistrict']);
		}
	}	
	// 申请时间
	$addtime_start = $_GET['star_time'];
	$addtime_end = $_GET['end_time'];
	if($addtime_start && $addtime_end)
	{
		$addtime_start=time($addtime_start);
		$addtime_end=time($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("resume")." as r on e.resume_id=r.id left join ".table("hunter_profile")." h on h.uid=e.hunter_uid ";
	//分页
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('entrust_hunter')." as e ".$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,e.hunter_name,h.worktime,h.level_meal,h.id hunter_id,h.district_cn h_district_cn FROM ".table('entrust_hunter')." as e ".$joinsql.$wheresql.$orderbysql;
	$row = $db->getall($sql);
	foreach ($row as $key => $value)
	{
		$Y=date("Y");
		$value['worktime']=$Y-$value['worktime'];
		$value['hunter_name_']=$value['hunter_name'];
		$value['hunter_name']=cut_str($value['hunter_name'],5,0,'...');
		$value['hunter_url']=url_rewrite('QS_hunter_show',array('id'=>$value['hunter_id']));
		$row[$key]=$value;
	}
	$smarty->assign('entrust_list', $row);
	$smarty->assign('title'," 发出的申请 - 个人会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_personal/my_entrust_hunter.htm');
}
//  我进行同意操作
elseif($act == "entrust_me_agree")
{
	$state=intval($_GET['state']);
	$entrust_id=intval($_GET['entrust_id']);
	$resume_uid=intval($_SESSION['uid']);
	$sql="update ".table("entrust_hunter")." set state=$state where id=$entrust_id and resume_uid=$resume_uid ";
	!$db->query($sql)?showmsg("操作失败！",1):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);
?>