<?php
/*
 * 74cms 猎头会员中心
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/hunter_common.php');
$smarty->assign('nav',"recruitment");
$act=trim($_GET["act"])?trim($_GET["act"]):"apply_jobs";
if ($act=='apply_jobs')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$joinsql=" LEFT JOIN  ".table('resume')." AS r  ON  a.resume_id=r.id ";
	$wheresql=" WHERE a.belong_uid='{$_SESSION['uid']}' ";
	$current=intval($_GET['current']);
	if($current>0)$wheresql.=" AND r.current='{$current}'";
	$job_id=intval($_GET['job_id']);
	$sex_id=$_GET['sex_id'];
	$name=trim($_GET['name']);
	$age_start=intval($_GET['age_start']);
	$age_end=intval($_GET['age_end']);
	$education_id=intval($_GET['education_id']);
	$experience_id=intval($_GET['experience_id']);
	$nowcity_id=trim($_GET['nowcity_id']);
	$nowpage = intval($_GET['page'])==0?1:intval($_GET['page']);
	if($job_id>0){
		$wheresql.=" AND a.jobs_id='{$job_id}' ";
		$sql="select jobs_name from ".table("jobs")." where id=".intval($_GET['job_id'])." ";
		$row=$db->getone($sql);
		$smarty->assign('jobs_name',$row["jobs_name"]);
	}
	if($name!=""){
		$wheresql.=" AND a.resume_name='{$name}' ";
	}
	if($age_start>0){
		$year = date("Y")-$age_start;
		$wheresql.=" AND r.birthdate<={$year} ";
	}
	if($age_end>0){
		$year = date("Y")-$age_end;
		$wheresql.=" AND r.birthdate>={$year} ";
	}
	if($education_id>0){
		$wheresql.=" AND r.education={$education_id} ";
	}
	if($experience_id>0){
		$wheresql.=" AND r.experience={$experience_id} ";
	}
	if($sex_id!='')
	{
		$sex_id=intval($sex_id);
		$wheresql.=" AND r.sex={$sex_id} ";
	}
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('personal_jobs_apply')." AS a  {$joinsql}{$wheresql} ";
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$page->nowindex = $nowpage;
	$offset=($page->nowindex-1)*$perpage;
	$jobs_apply = get_apply_hunterjobs($offset,$perpage,$joinsql.$wheresql);
	$jobs_arr = get_apply_hunterjobs_jobs_arr($offset,$perpage,$joinsql.$wheresql);
	$smarty->assign('act',$act);
	$smarty->assign('title','正在应聘 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('jobs_apply',$jobs_apply);
	$smarty->assign('jobs_arr',$jobs_arr);
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->assign('count',count_hunterjobs_apply($_SESSION['uid'],0,$jobsid));
	$smarty->assign('count1',count_hunterjobs_apply($_SESSION['uid'],1,$jobsid));
	$smarty->assign('count2',count_hunterjobs_apply($_SESSION['uid'],2,$jobsid));
	$smarty->assign('jobs',get_auditjobs($_SESSION['uid']));	
	$smarty->display('member_hunter/hunter_apply_jobs.htm');
}
elseif ($act=='set_apply_jobs')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择任何项目！",1);
	set_apply($yid,$_SESSION['uid'],2)?showmsg("设置成功！",2):showmsg("设置失败！",0);
}
elseif ($act=='apply_jobs_del')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择项目！",1);
	if ($n=del_apply_jobs($yid,$_SESSION['uid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	showmsg("失败！",0);
	}
}
elseif ($act=='down_resume_list')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$joinsql=" LEFT JOIN  ".table('resume')." as r ON d.resume_id=r.id ";
	$wheresql=" WHERE  d.hunter_uid='".intval($_SESSION['uid'])."' ";
	$id = intval($_GET['id']);
	$fullname = trim($_GET['fullname']);
	$starttime = strtotime($_GET['starttime']);
	$endtime = strtotime($_GET['endtime']);
	$nowpage = intval($_GET['page'])==0?1:intval($_GET['page']);
	if($id>0)
	{
	$wheresql.=" AND d.resume_id={$id} ";
	}
	if($fullname!="")
	{
	$wheresql.=" AND d.resume_fullname='".$fullname."' ";
	}
	if($starttime>0)
	{
	$wheresql.=" AND d.down_addtime>".$starttime." ";
	}
	if($endtime>0)
	{
	$wheresql.=" AND d.down_addtime<".$endtime." ";
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('hunter_down_resume')." as d".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$page->nowindex = $nowpage;
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$smarty->assign('title','已下载的简历 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('act',$act);
	$smarty->assign('list',get_hunter_down_resume($offset,$perpage,$joinsql.$wheresql));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->display('member_hunter/hunter_down_resume.htm');
}
elseif ($act=='down_resume_del')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if ($n=del_down_resume($yid,$_SESSION['uid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	showmsg("失败！",0);
	}
}
elseif ($act=='perform')
{
	$id =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if(!empty($_REQUEST['shift'])){
		$num=down_to_favorites($id,$_SESSION['uid']);
		if ($num==='full')
		{
		showmsg("人才库已满!",1);
		}
		elseif($num>0)
		{
		showmsg("添加成功，共添加 {$num} 条",2);
		}
		else
		{
		showmsg("添加失败,已经存在！",1);
		}
	}elseif(!empty($_REQUEST['attention_shift'])){
		$num=attention_to_favorites($id,$_SESSION['uid']);
		if ($num==='full')
		{
		showmsg("人才库已满!",1);
		}
		elseif($num>0)
		{
		showmsg("添加成功，共添加 {$num} 条",2);
		}
		else
		{
		showmsg("添加失败,已经存在！",1);
		}
	}
}
elseif ($act=='favorites_list')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$joinsql=" LEFT JOIN  ".table('resume')." AS r ON  f.resume_id=r.id ";

	$wheresql= " WHERE f.hunter_uid='".intval($_SESSION['uid'])."' ";

	$id = intval($_GET['id']);
	$trade_id = intval($_GET['trade_id']);
	$education_id = intval($_GET['education_id']);
	$experience_id = intval($_GET['experience_id']);
	$starttime = strtotime($_GET['starttime']);
	$endtime = strtotime($_GET['endtime']);
	$nowpage = intval($_GET['page'])==0?1:intval($_GET['page']);

	if($id!=""){
		$wheresql.=" AND f.resume_id='{$id}' ";
	}
	if($trade_id>0){
		$wheresql.=" AND find_in_set('{$trade_id}',r.trade) ";
	}
	if($education_id>0){
		$wheresql.=" AND r.education={$education_id} ";
	}
	if($experience_id>0){
		$wheresql.=" AND r.experience={$experience_id} ";
	}
	if($starttime>0){
		$wheresql.=" AND f.favorites_addtime>{$starttime} ";
	}
	if($endtime>0){
		$endtime = $endtime+24*3600;
		$wheresql.=" AND f.favorites_addtime<{$endtime} ";
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('hunter_favorites')." AS f ".$joinsql.$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$page->nowindex = $nowpage;
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('title','我的人才库 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('act',$act);
	$smarty->assign('favorites',get_favorites($offset, $perpage,$joinsql.$wheresql));

	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$aa=get_hunter_favorites_trade(intval($_SESSION['uid']));

	$smarty->assign('trade_arr',get_hunter_favorites_trade(intval($_SESSION['uid'])));
	$smarty->display('member_hunter/hunter_favorites.htm');
}
elseif ($act=='favorites_del')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if ($n=del_favorites($yid,$_SESSION['uid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	showmsg("失败！",0);
	}
}
// 导出简历 
elseif($act =="export_resume")
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if(!export_resume($yid)){
		showmsg("导出失败！",0);
	}
}
//邀请面试列表
elseif ($act=='interview_list')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$joinsql=" LEFT JOIN ".table('resume')." as r ON i.resume_id=r.id ";
	$uid=intval($_SESSION['uid']);	
	$wheresql=" WHERE i.belong_uid=".$uid." ";
	//搜索条件(面试职位/简历编号/姓名/面试时间)
	$job_id = intval($_GET['job_id']);
	if($job_id>0)
	{
	$wheresql.=" AND i.jobs_id='".$job_id."' ";
	}
	$fullname = trim($_GET['fullname']);
	if($fullname!="")
	{
	$wheresql.=" AND i.resume_name='".$fullname."' ";
	}
	$id = intval($_GET['id']);
	if($id>0)
	{
	$wheresql.=" AND i.resume_id={$id} ";
	}
	$date_interview = strtotime($_GET['date_interview']);
	if($date_interview>0)
	{
	$start=$date_interview;
	$end=$start+24*3600;
	$wheresql.=" AND i.interview_addtime>".$start." and i.interview_addtime<".$end." ";
	}
	$nowpage = intval($_GET['page'])==0?1:intval($_GET['page']);
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_interview')." as i ".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$page->nowindex = $nowpage;
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$smarty->assign('act',$act);
	//得到猎头正在发布中的职位
	$smarty->assign('jobs',get_auditjobs($_SESSION['uid']));
	$smarty->assign('title','我发起的面试邀请 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('resume',get_interview($offset, $perpage,$joinsql.$wheresql));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->display('member_hunter/hunter_interview.htm');
}
//删除面试邀请信息
elseif ($act=='interview_del')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择项目！",1);
	!del_interview($yid,$_SESSION['uid'],$did)?showmsg("删除失败！",0):showmsg("删除成功！",2);
}
elseif ($act=='my_attention')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$joinsql=" LEFT JOIN  ".table('resume')." AS r  ON  a.resumeid=r.id ";
	$wheresql=" WHERE a.uid='{$_SESSION['uid']}' ";
	$id = intval($_GET['id']);
	$sex_id = intval($_GET['sex_id']);
	$starttime = strtotime($_GET['starttime']);
	$endtime = strtotime($_GET['endtime']);
	$nowpage = intval($_GET['page'])==0?1:intval($_GET['page']);
	if($id>0)
	{
	$wheresql.=" AND a.resumeid={$id} ";
	}
	if($sex_id>0)
	{
	$wheresql.=" AND r.sex={$sex_id} ";
	}
	if($starttime>0)
	{
	$wheresql.=" AND a.addtime>".$starttime." ";
	}
	if($endtime>0)
	{
	$wheresql.=" AND a.addtime<".$endtime." ";
	}
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('view_resume')." AS a  {$joinsql} {$wheresql} ";
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$page->nowindex = $nowpage;
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('title','浏览过的简历 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('resume_list',get_my_attention($offset,$perpage,$joinsql.$wheresql));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}	
	$smarty->display('member_hunter/hunter_my_attention.htm');
}
elseif($act == 'del_my_attention')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择项目！",1);
	!del_my_attention($yid,$_SESSION['uid'])?showmsg("删除失败！",0):showmsg("删除成功！",2);
}
//查看 "谁看过我的职位" 信息
elseif ($act=='view_jobs_log')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	if(intval($_GET['jobsid'])>0){
		$wheresql=" WHERE `jobsid`=".intval($_GET['jobsid'])." ";
		$sql="select jobs_name from ".table("jobs")." where id=".intval($_GET['jobsid'])." ";
		$row=$db->getone($sql);
		$smarty->assign('jobs_name',$row["jobs_name"]);
	}else{
		$my_jobs = get_my_jobs(intval($_SESSION['uid']));
		if(empty($my_jobs)){
			$wheresql=" WHERE 0";
		}
		else{
			$wheresql=" WHERE `jobsid` in(".$my_jobs.") ";
		}
		
	}
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table('view_jobs')." {$wheresql} ";
	$page = new page(array('total'=>$db->get_total($total_sql), 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;
	$smarty->assign('title','浏览记录 - 猎头会员中心 - '.$_CFG['site_name']);
	$smarty->assign('jobs',get_auditjobs($_SESSION['uid']));	
	$smarty->assign('user_list',get_view_users($offset,$perpage,$wheresql));
	$smarty->assign('page',$page->show(7));	
	$smarty->display('member_company/company_view_jobs.htm');
}
//删除 "谁看过我的职位" 记录
elseif($act == 'del_view_jobs'){
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择项目！",1);
	$delete =$_POST['delete'];
	$delete?(!del_view_jobs($yid)?showmsg("删除失败！",0):showmsg("删除成功！",2)):'';
}
unset($smarty);
?>