<?php
/*
 * 74cms 企业会员中心
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/company_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 ";
	if($parentuid==$uid){
		$wheresql=" WHERE a.belong_parentuid=".$parentuid." ";
		$smarty->assign('jobs',get_auditjobs($parentuid,1));
	}else{
		$wheresql=" WHERE a.belong_uid=".$uid." ";
		$smarty->assign('jobs',get_auditjobs($uid));
	}
	
	$current=intval($_GET['current']);
	$job_id=intval($_GET['job_id']);
	$name=trim($_GET['name']);
	$sex_id=trim($_GET['sex_id']);
	$age_min=intval($_GET['age_min']);
	$age_max=intval($_GET['age_max']);
	$education_id=intval($_GET['education_id']);
	$experience_id=intval($_GET['experience_id']);
	if($job_id>0){
		$wheresql.=" AND a.jobs_id='{$job_id}' ";
	}
	if($name!=""){
		$wheresql.=" AND a.resume_name='{$name}' ";
	}
	if($sex_id>0){
		$wheresql.=" AND r.sex='{$sex_id}' ";
	}
	if($age_min>0){
		$start_year = date("Y")-$age_min;
		$wheresql.=" AND r.birthdate<={$start_year} ";
	}
	if($age_max>0){
		$end_year = date("Y")-$age_max;
		$wheresql.=" AND r.birthdate>={$end_year} ";
	}
	if($education_id>0){
		$wheresql.=" AND r.education={$education_id} ";
	}
	if($experience_id>0){
		$wheresql.=" AND r.experience={$experience_id} ";
	}
	if($current>0){
		$wheresql.=" AND r.current={$current} ";
	}
	$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));
	$offset=($page->nowindex-1)*$perpage;
	$jobs_apply = get_apply_jobs($offset,$perpage,$joinsql.$wheresql);
	$smarty->assign('act',$act);
	$smarty->assign('title','正在应聘 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('jobs_apply',$jobs_apply);
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->assign('count',count_jobs_apply($_SESSION['uid'],0,$jobsid));
	$smarty->assign('count1',count_jobs_apply($_SESSION['uid'],1,$jobsid));
	$smarty->assign('count2',count_jobs_apply($_SESSION['uid'],2,$jobsid));
	$smarty->display('member_company/company_apply_jobs.htm');
}
elseif($act=='apply_del'){
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择任何项目！",1);
	if ($n=del_apply_jobs($yid,$_SESSION['uid'],$_SESSION['parentuid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	showmsg("失败！",0);
	}
}
//推荐简历列表
elseif ($act=='recommend_resume_list')
{
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$joinsql=" LEFT JOIN ".table('resume')." as r ON c.resume_id=r.id ";
	if($parentuid==$uid){
		$wheresql=" WHERE c.company_puid=".$parentuid." ";
		$smarty->assign('jobs',get_auditjobs($parentuid,1));
	}else{
		$wheresql=" WHERE c.company_uid=".$uid." ";
		$smarty->assign('jobs',get_auditjobs($uid));
	}
	
	$id = intval($_GET['id']);
	$hunter_id = intval($_GET['hunter_id']);
	$job_id = intval($_GET['job_id']);
	if($id>0)
	{
	$wheresql.=" AND c.resume_id='".$id."' ";
	}
	if($hunter_id>0)
	{
	$wheresql.=" AND c.uid='".$hunter_id."' ";
	}
	if($job_id>0)
	{
	$wheresql.=" AND c.jobs_id='".$job_id."' ";
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('hunter_recommend')." as c ".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$recommend_person_arr = get_recommend_person_arr($_SESSION['uid']);
	$smarty->assign('recommend_person_arr',$recommend_person_arr);
	$smarty->assign('act',$act);
	$smarty->assign('title','推荐简历 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('resume',get_recommend_resume($offset, $perpage,$joinsql.$wheresql));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->display('member_company/company_recommend_resume_list.htm');
}
// 同意推荐 操作
elseif($act == "recommend_agree")
{
	$state=intval($_GET['state']);
	$did=intval($_GET['did']);
	$uid=intval($_SESSION['uid']);
	$sql="update ".table("hunter_recommend")." set recommend_state=$state where did=$did and company_uid=$uid ";
	!$db->query($sql)?showmsg("操作失败！",0):showmsg("操作成功！",2);
}
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.company_parentuid=".$parentuid." ";
	
	$id = intval($_GET['id']);
	$fullname = trim($_GET['fullname']);
	$starttime = strtotime($_GET['starttime']);
	$endtime = strtotime($_GET['endtime']);
	if($id>0)
	{
	$wheresql.=" AND d.resume_id={$id} ";
	}
	if($fullname!="")
	{
	$wheresql.=" AND d.resume_name='".$fullname."' ";
	}
	if($starttime>0)
	{
	$wheresql.=" AND d.down_addtime>".$starttime." ";
	}
	if($endtime>0)
	{
	$endtime = $endtime+3600*24;
	$wheresql.=" AND d.down_addtime<".$endtime." ";
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_down_resume')." as d".$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$smarty->assign('title','主动下载 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('act',$act);
	$smarty->assign('list',get_down_resume($offset,$perpage,$joinsql.$wheresql));
	if($total_val>$perpage){
		$smarty->assign('page',$page->show(7));
	}
	$smarty->display('member_company/company_down_resume.htm');
}
elseif($act=='down_del'){
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if ($n=del_down_resume($yid,$_SESSION['uid'],$_SESSION['parentuid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	showmsg("失败！",0);
	}
}
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 ";
	if($parentuid==$uid){
		$wheresql= " WHERE f.company_parentuid=".$parentuid." ";
	}else{
		$wheresql= " WHERE f.company_uid=".$uid." ";
	}
	
	$id = intval($_GET['id']);
	$fullname = trim($_GET['fullname']);
	$current = trim($_GET['current']);
	if($id>0){
		$wheresql.=" AND f.resume_id='{$id}' ";
	}
	if($fullname!="")
	{
	$wheresql.=" AND r.fullname='".$fullname."' ";
	}
	if($current>0){
	$wheresql.=" AND r.current='{$current}' ";
	}
	$total_sql="SELECT COUNT(*) AS num FROM ".table('company_favorites')." AS f ".$joinsql.$wheresql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$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));
	}
	$smarty->display('member_company/company_favorites.htm');
}
elseif ($act=='favorites_del')
{
	// $yid =!empty($_REQUEST['d_id'])?$_REQUEST['d_id']:showmsg("你没有选择简历！",1);
	if ($n=del_favorites($yid,$_SESSION['uid'],$_SESSION['parentuid']))
	{
	showmsg("删除成功！共删除 {$n} 行",2);
	}
	else
	{
	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']);	
	$parentuid = intval($_SESSION['parentuid']);
	if($parentuid==$uid){
		$wheresql=" WHERE i.belong_parentuid=".$parentuid." ";
		$smarty->assign('jobs',get_auditjobs($parentuid,1));
	}else{
		$wheresql=" WHERE i.belong_uid=".$uid." ";
		$smarty->assign('jobs',get_auditjobs($uid));
	}
	
	$id = intval($_GET['id']);
	$fullname = trim($_GET['fullname']);
	$date_interview = strtotime($_GET['date_interview']);
	$job_id = intval($_GET['job_id']);
	if($job_id>0)
	{
	$wheresql.=" AND i.jobs_id='".$job_id."' ";
	}
	if($id>0)
	{
	$wheresql.=" AND i.resume_id={$id} ";
	}
	if($fullname!="")
	{
	$wheresql.=" AND i.resume_name='".$fullname."' ";
	}
	if($date_interview>0)
	{
	$starttime = $date_interview;
	$endtime = $starttime+3600*24;
	$wheresql.=" AND i.interview_addtime>".$starttime." AND i.interview_addtime<".$endtime." ";
	}
	$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));
	$currenpage=$page->nowindex;
	$offset=($currenpage-1)*$perpage;
	$smarty->assign('act',$act);
	$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_company/company_interview.htm');
}
//删除面试邀请信息
elseif ($act=='interview_del')
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择项目！",1);
	!del_interview($yid,$_SESSION['uid'],$_SESSION['parentuid'])?showmsg("删除失败！",0):showmsg("删除成功！",2);
}
// 导出简历 
elseif($act =="export_resume")
{
	$yid =!empty($_REQUEST['y_id'])?$_REQUEST['y_id']:showmsg("你没有选择简历！",1);
	if(!export_resume($yid)){
		showmsg("导出失败！",0);
	}
}
unset($smarty);
?>