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

define('IN_QISHI', true);
require_once(dirname(__FILE__).'/company_common.php');
$smarty->assign('nav','hunter_service');
$act=trim($_GET["act"])?trim($_GET["act"]):"hunter_service";
// 猎头服务
if ($act=='hunter_service')
{
	if($puid==$uid){
		$wheresql=" WHERE company_puid=".$puid." ";
		$smarty->assign('jobs_list',get_auditjobs($puid,1));//获取企业有效职位
	}else{
		$wheresql=" where company_uid=".$uid." ";
		$smarty->assign('jobs_list',get_auditjobs($uid));//获取企业有效职位
	}
	
	$smarty->assign('title','猎头服务 - 合作猎头 - 企业会员中心 - '.$_CFG['site_name']);
	$smarty->assign('hunter_list',get_company_hunter($puid));//获取企业合作猎头列表
	$job_id = intval($_GET['job_id']);
	$hunter_id = intval($_GET['hunter_id']);
	$startime = strtotime($_GET['startime']);
	$endtime = strtotime($_GET['endtime']);
	if($job_id>0)
	{
		$wheresql.=" and jobs_id=$job_id ";
	}
	if($hunter_id>0)
	{
		$wheresql.=" and hunter_id=$hunter_id ";
	}
	if($startime>0)
	{
		$wheresql.=" and addtime>$startime ";
	}
	if($endtime>0)
	{
		$endtime = $endtime+3600*24;
		$wheresql.=" and addtime<$endtime ";
	}
	$statesql=" and state=1 ";
	require_once(QISHI_ROOT_PATH.'include/page.class.php');
	$perpage=10;
	$total_sql="SELECT COUNT(*) AS num FROM ".table("entrust_hunter").$wheresql.$statesql;
	$total_val=$db->get_total($total_sql);
	$page = new page(array('total'=>$total_val, 'perpage'=>$perpage));
	$offset=($page->nowindex-1)*$perpage;

	$sql="select * from ".table("entrust_hunter").$wheresql.$statesql."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_name_']=$value['hunter_name'];
			$value["hunter_name"]=cut_str($value['hunter_name'],5,0,'...');
			$value['hunter_level_meal']=$hunter_row['level_meal'];
			$value['hunter_last_login_time']=$hunter_row['last_login_time'];
			$value['hunter_work']=date("Y")-$hunter_row['worktime'];
			// 职位信息
			$jobs_sql="select * from ".table("jobs")." where id=".$value['jobs_id']." limit 1 ";
			$jobs_row=$db->getone($jobs_sql);
			$value['jobs_amount']=$hunter_row['amount'];
			// 推荐记录
			$resume_sql="select count(*) num from ".table("hunter_recommend")." where jobs_id=".$value['jobs_id']." and uid=".$value['hunter_uid'];
			$resume_row=$db->getone($resume_sql);
			$value['resume_num']=$resume_row['num'];
			$list[$key]=$value;
		}
	}
	$smarty->assign('service_list',$list);
	if($total_val>$perpage)
	{
		$smarty->assign('page',$page->show(7));
	}
	$smarty->display('member_company/company_hunter_service.htm');
}
// 企业收到 猎头 的申请
elseif($act == "entrust_me_hunter")
{
	if($puid==$uid){
		$wheresql=" WHERE company_puid=".$puid." ";
		$smarty->assign('jobs_list',get_auditjobs($puid,1));//获取企业有效职位
	}else{
		$wheresql=" where company_uid=".$uid." ";
		$smarty->assign('jobs_list',get_auditjobs($uid));//获取企业有效职位
	}
	$wheresql=" where e.company_uid=$uid and e.entrust_type=1 and e.is_apply=1 ";
	$orderbysql = " order by e.addtime desc ";
	//职位类型
	$job_id = intval($_GET['job_id']);
	if($job_id>0)
	{
		$wheresql.=" and j.jobs_id=$job_id ";
	}
	//处理状态
	$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 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=time($addtime_start);
		$addtime_end=time($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("jobs")." as j on e.jobs_id=j.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 j.*,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 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['jobs_name_']=cut_str($value['jobs_name'],6,0);
		$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_company/entrust_me_hunter.htm');
}
// 企业 申请的猎头
elseif($act == "my_entrust_hunter")
{
	if($puid==$uid){
		$wheresql=" WHERE company_puid=".$puid." ";
		$smarty->assign('jobs_list',get_auditjobs($puid,1));//获取企业有效职位
	}else{
		$wheresql=" where company_uid=".$uid." ";
		$smarty->assign('jobs_list',get_auditjobs($uid));//获取企业有效职位
	}
	$wheresql=" where e.company_uid=$uid and e.entrust_type=1 and e.is_apply=0 ";
	$orderbysql = " order by e.addtime desc ";
	//职位类型
	$job_id = intval($_GET['job_id']);
	if($job_id>0)
	{
		$wheresql.=" and j.jobs_id=$job_id ";
	}
	//处理状态
	$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 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=time($addtime_start);
		$addtime_end=time($addtime_end);
		$wheresql.=" and e.addtime>=$addtime_start and e.addtime<=$addtime_end ";
	}
	$joinsql=" left join ".table("jobs")." as j on e.jobs_id=j.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 j.*,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 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'],3,0,'...');
		$value['hunter_url']=url_rewrite('QS_hunter_show',array('id'=>$value['hunter_id']));
		$value['jobs_name_']=cut_str($value['jobs_name'],6,0);
		$row[$key]=$value;
	}
	$smarty->assign('entrust_list', $row);
	$smarty->assign('title'," 发出的申请 - 企业会员中心 - ".$_CFG['site_name']);
	$smarty->display('member_company/my_entrust_hunter.htm');
}
//  我进行同意操作
elseif($act == "entrust_me_agree")
{
	// $state=intval($_GET['state']);
	$entrust_id=intval($_GET['entrust_id']);
	$company_uid=intval($_SESSION['uid']);
	$sql="update ".table("entrust_hunter")." set state=$state where id=$entrust_id and company_uid=$company_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);
?>