<?php
require 'inc.php';
$tab_resume=DB_PRE."hr_resume";
$tab_jobhistory=DB_PRE."hr_job_history";
$obj_tab_resume=new cls_tab_hr_resume();

$this_is_resume_html=$obj_tab_resume->ishtml;

if(!isset($int_pagesize)) $int_pagesize=10;
if(!isset($get_act)) $get_act="";
(!isset($get_page))? $get_page=0:$get_page=intval($get_page);
if(!isset($get_pannel)) $get_pannel="";
if(!isset($get_s_addtime1)) $get_s_addtime1="";
if(!isset($get_s_addtime2)) $get_s_addtime2="";
if(!isset($get_s_name)) $get_s_name="";
if(!isset($get_s_state)) $get_s_state=-101;

$page_footer_info=<<<HTML
<input type="hidden" name="pannel" value="$get_pannel">
HTML;
$arr_state=$obj_tab_resume->state;
if($get_act=='del_sel')
{
	$arr_msg=$obj_tab_resume->on_del($get_resumeids);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
if($get_act=='state'&&isset($get_state_val))
{
	$arr_msg=$obj_tab_resume->on_state($get_resumeids,$get_state_val);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
if($get_act=='photo'&&isset($get_photo_val))
{
	$arr_msg=$obj_tab_resume->on_photo($get_resumeids,$get_photo_val);
	if($arr_msg["err"]!="")
	{
		$obj_msg->alert($arr_msg["err"]);
	}

}
switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		$arr_fields["resume_id"]=$get_id;
		$arr_fields["resume_name"]=$get_resume_name;
		$arr_fields["resume_photo"]=$get_resume_photo;
		$arr_fields["resume_sex"]=$get_resume_sex;
		$arr_fields["resume_national"]=$get_resume_national;
		$arr_fields["resume_birthday"]=$get_resume_birthday;
		$arr_fields["resume_vouchertype"]=$get_resume_vouchertype;
		$arr_fields["resume_voucherid"]=$get_resume_voucherid;
		$arr_fields["resume_height"]=$get_resume_height;
		$arr_fields["resume_weight"]=$get_resume_weight;
		$arr_fields["resume_marry"]=$get_resume_marry;
		$arr_fields["resume_household"]=$get_resume_household;
		$arr_fields["resume_area"]=$get_resume_area;
		$arr_fields["resume_experience"]=$get_resume_experience;

		$arr_fields["resume_degree"]=$get_resume_degree;
		$arr_fields["resume_school"]=$get_resume_school;
		$arr_fields["resume_major"]=$get_resume_major;
		$arr_fields["resume_leaveschool"]=$get_resume_leaveschool;

		$arr_fields["resume_eduhistory"]=$get_resume_eduhistory;
		$arr_fields["resume_trainhistory"]=$get_resume_trainhistory;
		$arr_fields["resume_workhistory"]=$get_resume_workhistory;

		$arr_fields["resume_skill"]=$get_resume_skill;
		$arr_fields["resume_result"]=$get_resume_result;
		$arr_fields["resume_favorite"]=$get_resume_favorite;
		$arr_fields["resume_intro"]=$get_resume_intro;

		$arr_fields["resume_jobtype"]=$get_resume_jobtype;
		$arr_fields["resume_jobcategory"]=$get_resume_jobcategory;
		$arr_fields["resume_jobarea"]=$get_resume_jobarea;
		$arr_fields["resume_jobname"]=$get_resume_jobname;
		$arr_fields["resume_jobpay"]=$get_resume_jobpay;
		$arr_fields["resume_availability"]=$get_resume_availability;

		$arr_fields["resume_tel"]=$get_resume_tel;
		$arr_fields["resume_tel2"]=$get_resume_tel2;
		$arr_fields["resume_email"]=$get_resume_email;
		$arr_fields["resume_weburl"]=$get_resume_weburl;
		$arr_fields["resume_qq"]=$get_resume_qq;
		$arr_fields["resume_address"]=$get_resume_address;
		$arr_msg=$obj_tab_resume->on_save($arr_fields);
		if($arr_msg["err"]=="") $get_id=$arr_msg["id"];
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'add':
	{
		$arr_resumetrip=array();
		include 'temp/resume.add.tpl.php';
		break;
	}
	case 'edit':
	{
		$arr_resume=array();
		$arr_history=array();
		$obj_tab_area=new cls_tab_sys_area();
		$obj_tab_jobcategory=new cls_tab_hr_job_category();
		$obj_result = $obj_db->query("SELECT * FROM ".$tab_resume." where resume_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["resume_birthday"]=format_date($obj_rs["resume_birthday"],"Y-m-d");
			$obj_rs["resume_jobarea"]=$obj_tab_area->get_select_area("resume_jobarea",$obj_rs["resume_jobarea"]);
			$obj_rs["resume_jobcategory"]=$obj_tab_jobcategory->get_select_category("resume_jobcategory",$obj_rs["resume_jobcategory"]);
			$obj_rs["resume_jobpay"]=get_select_html($obj_tab_resume->jobpay,$obj_rs["resume_jobpay"]);
			$obj_rs["resume_degree"]=get_select_html($obj_tab_resume->degree,$obj_rs["resume_degree"]);
			$obj_rs["resume_availability"]=get_radio_html($obj_tab_resume->availability,"resume_availability",$obj_rs["resume_availability"],"<br>");
			$obj_rs["resume_vouchertype"]=get_select_html($obj_tab_resume->vouchertype,$obj_rs["resume_vouchertype"]);
			$obj_rs["resume_national"]=get_select_html($obj_tab_resume->national,$obj_rs["resume_national"]);
			$obj_rs["resume_jobtype"]=get_radio_html($obj_tab_resume->jobtype,"resume_jobtype",$obj_rs["resume_jobtype"]);
			$obj_rs["resume_marry"]=get_radio_html($obj_tab_resume->marry,"resume_marry",$obj_rs["resume_marry"]);
			$arr_resume = $obj_rs;
		}
		include 'tpl/resume.edit.tpl.php';
		break;
	}
	case "html_exe":
	{
		//·ÖÒ³
		$int_pagesize=100;
		$arr_resume=array();
		$str_resumeid="";
		$str_where=" where 1";
		if(isset($get_resumeids)){
			if(is_array($get_resumeids)){
				$str_resumeid=get_arr_id($get_resumeids);
			}else{
				$arr_x=explode(",",$get_resumeids);
				$arr_y=array();
				foreach($arr_x as $item){
					if(!is_numeric($item)) continue;
					$arr_y[]=$item;
				}
				$str_resumeid=implode(",",$arr_y);
			}
			if($str_resumeid!=""){
				$str_where.=" and resume_id in(".$str_resumeid.")";
			}
		}
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_resume".$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 resume_id FROM ".DB_PRE."hr_resume".$str_where." order by resume_id desc".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_resume[]=$obj_rs;
		}
		include 'tpl/resume.html.tpl.php';
		break;
	}
	default:
	{
		$get_issearch=0;
		$str_where=" where 1";
		$get_issearch=0;
		if($get_s_name!=""){
			$get_s_name=str_replace(" ","%",$get_s_name);
			$str_x_where="resume_name like '%".$get_s_name."%'";
			$get_issearch="1";
			$arr_s_uid=array();
			$obj_result = $obj_db->query("SELECT user_id FROM ".DB_PRE."sys_user where user_name like '%".$get_s_name."%'");
			while($obj_rs = $obj_db->fetch_array($obj_result))
			{
				$arr_s_uid[]=$obj_rs["user_id"];
			}
			if(count($arr_s_uid)>0){
				$str_s_uid=implode(",",$arr_s_uid);
				$str_where.=" and (".$str_x_where." or resume_user_id in(".$str_s_uid."))";
			}else{
				$str_where.=" and ".$str_x_where;
			}
		}
		if(is_date($get_s_addtime1)){
			$str_where.=" and FROM_UNIXTIME(resume_updatetime)>='".$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(resume_updatetime)<'".$str_s_regtime2."'";
			$get_issearch="1";
		}
		if($get_s_state!=-101){
			$str_where.=" and resume_state='".$get_s_state."'";
			$get_issearch="1";
		}
		if($get_pannel!=""){
			$str_where.=" and resume_photo!=''";
		}
		if(isset($get_fz_id) && intval($get_fz_id)>=0){
			$str_where.=" and resume_fz_id='".$get_fz_id."'";
		}
		$arr_resume = array();
		$arr_uid=array();
		$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".$tab_resume.$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 ".$tab_resume.$str_where.$str_limit);
		$lng_year=format_date(TIME,"Y");
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			if($obj_rs["resume_birthday"]!=0){
			$lng_year2=format_date($obj_rs["resume_birthday"]);
				$obj_rs["age"]=$lng_year-$lng_year2;
			}else{
				$obj_rs["age"]=0;
			}

			$obj_rs["state"]=array_search($obj_rs["resume_state"],$arr_state);
			if($obj_rs["resume_state"]<=0){
				$obj_rs["state"]="<font color='#ff0000'>".$obj_rs["state"]."</font>";
			}
			$obj_rs["age"]="";
			$lng_year_now=format_date(TIME,"Y");
			$lng_year=format_date($obj_rs["resume_birthday"],"Y");
			if($lng_year>0) $obj_rs["age"]=$lng_year_now-$lng_year;
			$obj_rs["addtime"]=format_date($obj_rs["resume_addtime"],"Y-m-d H:i");
			$obj_rs["updatetime"]=format_date($obj_rs["resume_updatetime"],"Y-m-d H:i");
			if($obj_rs["resume_photo"]!=""){
				$obj_rs["resume_photo"]=get_html_url($obj_rs["resume_photo"]);
				if($obj_rs["resume_photo_state"]==1){
					$obj_rs["photo_state"]="<font color='#0000ff'>ÉóºË</font>";
				}else{
					$obj_rs["photo_state"]="<font color='#ff0000'>´ýÉó</font>";
				}
			}
			$arr_resume[] = $obj_rs;
			$arr_uid[]=$obj_rs["resume_user_id"];
		}
		$arr_uname=$obj_ctl_user->get_user_name($arr_uid);
		foreach($arr_uid as $item){
			if(!isset($arr_uname["id_".$item])) $arr_uname["id_".$item]="";
		}
		if($get_pannel=="photo"){
			include 'tpl/resume.photo.tpl.php';
		}else{
			include 'tpl/resume.tpl.php';
		}
	}
}


?>
