<?php
require 'inc.php';
$obj_tab_apply=new cls_tab_hr_job_apply();

if(!isset($get_s_addtime1)) $get_s_addtime1="";
if(!isset($get_s_addtime2)) $get_s_addtime2="";
if(!isset($get_s_name)) $get_s_name="";

$page_footer_info=<<<HTML
HTML;

if($get_act=="del"){
	$arr_return=$obj_tab_apply->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_apply->on_del($get_pageid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
//分页
$str_where=" where 1";
$get_issearch=0;
if($get_s_name!=""){
	$get_s_name=str_replace(" ","%",$get_s_name);
	$get_issearch="1";
	//查企业
	$arr_s_uid=array();
	$arr_x_where=array();
	$obj_result = $obj_db->query("SELECT company_user_id FROM ".DB_PRE."hr_company where company_name like '%".$get_s_name."%'");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_s_uid[]=$obj_rs["company_user_id"];
	}
	if(count($arr_s_uid)>0){
		$str_s_company_uid=implode(",",$arr_s_uid);
		$arr_x_where[]="apply_company_user_id in(".$str_s_company_uid.")";
	}
	//查简历
	$arr_s_uid=array();
	$obj_result = $obj_db->query("SELECT resume_user_id FROM ".DB_PRE."hr_resume where resume_name like '%".$get_s_name."%'");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_s_uid[]=$obj_rs["resume_user_id"];
	}
	if(count($arr_s_uid)>0){
		$str_s_uid=implode(",",$arr_s_uid);
		$arr_x_where[]="apply_user_id in(".$str_s_uid.")";
	}
	//查职位
	$arr_s_uid=array();
	$obj_result = $obj_db->query("SELECT job_id FROM ".DB_PRE."hr_job where job_name like '%".$get_s_name."%'");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_s_uid[]=$obj_rs["job_id"];
	}
	if(count($arr_s_uid)>0){
		$str_s_job_id=implode(",",$arr_s_uid);
		$arr_x_where[]="apply_job_id in(".$str_s_job_id.")";
	}
	$str_x_where="";
	if(count($arr_x_where)>1){
		$str_x_where=" and (".implode(" or ",$arr_x_where).")";
	}else if(count($arr_x_where)>0){
		$str_x_where=" and ".$arr_x_where[0];
	}else{
		$str_x_where=" and 0";
	}
	$str_where.=$str_x_where;
}
if(is_date($get_s_addtime1)){
	$str_where.=" and FROM_UNIXTIME(apply_addtime)>='".$get_s_addtime1."'";
	$get_issearch="1";
}
if(is_date($get_s_addtime2)){
	$lng_x=format_date_int($get_s_addtime2)+86400;
	$str_s_regtime2=format_date($lng_x,"Y-m-d");
	$str_where.=" and FROM_UNIXTIME(apply_addtime)<'".$str_s_regtime2."'";
	$get_issearch="1";
}
if(isset($get_fz_id) && intval($get_fz_id)>=0){
	$str_where.=" and apply_fz_id='".$get_fz_id."'";
}

$arr_apply=array();
$arr_jobid=array();
$arr_userid=array();
$arr_company_userid=array();
$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_job_apply".$str_where);
$int_total=$obj_rs["num"];
$int_pages= ceil($int_total/$int_pagesize);
$get_page = min($int_pages, $get_page);
$get_page = max($get_page, 1);
$page_split_page=get_pages($int_total, $get_page, $int_pagesize);
$int_offset = $int_pagesize*($get_page-1);
$str_limit = " limit ".$int_offset.",".$int_pagesize;
$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_job_apply".$str_where." order by apply_addtime desc".$str_limit);
while($obj_rs = $obj_db->fetch_array($obj_result))
{
	$arr_jobid[]=$obj_rs["apply_job_id"];
	$arr_userid[]=$obj_rs["apply_user_id"];
	$arr_company_userid[]=$obj_rs["apply_company_user_id"];
	$obj_rs["apply_addtime"]=format_date($obj_rs["apply_addtime"],"Y-m-d H:i");
	$arr_resume["id_".$obj_rs["apply_user_id"]]="";
	$arr_apply[] = $obj_rs;
}
if(count($arr_jobid)>0){
	$str_jobid=implode(",",$arr_jobid);
	$obj_result = $obj_db->query("SELECT job_id,job_name FROM ".DB_PRE."hr_job where job_id in(".$str_jobid.")");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_job["id_".$obj_rs["job_id"]]=$obj_rs["job_name"];
	}
	$str_userid=implode(",",$arr_userid);
	$obj_result = $obj_db->query("SELECT resume_user_id,resume_name FROM ".DB_PRE."hr_resume where resume_user_id in(".$str_userid.")");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_resume["id_".$obj_rs["resume_user_id"]]=$obj_rs["resume_name"];
	}
	$str_company_userid=implode(",",$arr_company_userid);
	$obj_result = $obj_db->query("SELECT company_user_id,company_name FROM ".DB_PRE."hr_company where company_user_id in(".$str_company_userid.")");
	while($obj_rs = $obj_db->fetch_array($obj_result))
	{
		$arr_company["id_".$obj_rs["company_user_id"]]=$obj_rs["company_name"];
	}
}
include "tpl/job_apply.tpl.php";


?>