<?php
require 'inc.php';
require_once(SYS_ROOT.'/cls_tab/tab.sys.area.php');
$obj_tab_area=new cls_tab_sys_area();
$obj_tab_user=new cls_tab_sys_user();
if($get_act=="del"){
	$arr_return=$obj_tab_user->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_user->on_del($get_userid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="state"){
	$arr_return=$obj_tab_user->on_state($get_userid,$get_state_val);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
$arr_type=$obj_tab_user->type;
$arr_state=$obj_tab_user->state;

if(!isset($get_s_regtime1)) $get_s_regtime1="";
if(!isset($get_s_regtime2)) $get_s_regtime2="";
if(!isset($get_s_logintime1)) $get_s_logintime1="";
if(!isset($get_s_logintime2)) $get_s_logintime2="";
if(!isset($get_s_name)) $get_s_name="";
if(!isset($get_s_state)) $get_s_state=-101;
if(!isset($get_s_type)) $get_s_type="";

switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		$arr_fields["user_id"]=$get_id;
		$arr_fields["user_name"]=$get_user_name;
		if($get_id<1) $arr_fields["user_type"]=$get_user_type;
		$arr_fields["user_pwd"]=$get_user_pwd;
		$arr_fields["user_email"]=$get_user_email;
		$arr_msg=$obj_tab_user->on_save($arr_fields);
		if($arr_msg["err"]==""){
			if((isset($arr_fields["user_type"])&&$arr_fields["user_type"]=="company")||isset($get_company_id)&&$get_company_id>0){
				//注册企业信息
				require_once(SYS_ROOT.'/cls_tab/tab.hr.company.php');
				$obj_tab_company=new cls_tab_hr_company();
				$arr_fields2=array();
				if(isset($get_company_id)) $arr_fields2["company_id"]=$get_company_id;
				$arr_fields2["company_name"]=$get_company_name;
				if(isset($get_company_area)) $arr_fields2["company_area"]=$get_company_area;
				$arr_fields2["company_linkname"]=$get_company_linkname;
				$arr_fields2["company_tel"]=$get_company_tel;
				$arr_fields2["company_address"]=$get_company_address;
				$arr_fields2["company_user_id"]=$arr_msg["id"];
				$arr_msg2=$obj_tab_company->on_save($arr_fields2);
				if($arr_msg2["err"]!=""){
					$obj_msg->alert($arr_msg2["err"]);
				}
			}
			if(isset($arr_fields["user_type"])&&$arr_fields["user_type"]=="personal"||isset($get_resume_id)&&$get_resume_id>0){
				//注册个人信息
				require_once(SYS_ROOT.'/cls_tab/tab.hr.resume.php');
				$obj_tab_resume=new cls_tab_hr_resume();
				$arr_fields2=array();
				if(isset($get_resume_id)) $arr_fields2["resume_id"]=$get_resume_id;
				$arr_fields2["resume_name"]=$get_resume_name;
				$arr_fields2["resume_sex"]=$get_resume_sex;
				$arr_fields2["resume_birthday"]=$get_resume_birthday;
				$arr_fields2["resume_user_id"]=$arr_msg["id"];
				$arr_msg2=$obj_tab_resume->on_save($arr_fields2);
				if($arr_msg2["err"]!=""){
					$obj_msg->alert($arr_msg2["err"]);
				}
			}
			$get_id=$arr_msg["id"];
			$arr_msg["act_info"]="成功注册用户！";
			$arr_msg["act_act"]="<a href=\"javascript:frmExecute('add');\">添加</a> <a href=\"javascript:frmExecute('');\">管理</a>";

		}
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'add':
	{
		$get_id=0;
		$this_company_area=$obj_tab_area->get_select_area("company_area");
		include "tpl/user.add.tpl.php";
		break;
	}
	case 'edit':
	{
		$arr_user=array();
		$arr_company=array();
		$arr_resume=array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_user where user_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_user = $obj_rs;
			if($arr_user["user_type"]=="company"){
				$obj_result2 = $obj_db->query("SELECT * FROM ".DB_PRE."hr_company where company_user_id='".$get_id."'");
				if($obj_rs2 = $obj_db->fetch_array($obj_result2))
				{
					$this_company_area=$obj_tab_area->get_select_area("company_area",$obj_rs2["company_area"]);
					$arr_company=$obj_rs2;
				}
			}
			if($arr_user["user_type"]=="personal"){
				$obj_result2 = $obj_db->query("SELECT resume_id,resume_name,resume_birthday,resume_sex FROM ".DB_PRE."hr_resume where resume_user_id='".$get_id."'");
				if($obj_rs2 = $obj_db->fetch_array($obj_result2))
				{
					$obj_rs2["resume_birthday"]=format_date($obj_rs2["resume_birthday"],"Y-m-d");
					$arr_resume=$obj_rs2;
				}
			}
		}
		include 'tpl/user.edit.tpl.php';
		break;
	}
	default:
	{
		//分页
		$str_where=" where 1";
		$get_issearch=0;
		if($get_s_name!=""){
			$get_s_name=str_replace(" ","%",$get_s_name);
			$str_where.=" and (user_name like '%".$get_s_name."%' or user_email like '%".$get_s_name."%')";
			$get_issearch="1";
		}
		if($get_s_state!=-101){
			$get_s_state=intval($get_s_state);
			$str_where.=" and user_state='".$get_s_state."'";
			$get_issearch="1";
		}
		if($get_s_type!=""){
			$str_where.=" and user_type='".$get_s_type."'";
			$get_issearch="1";
		}
		if(is_date($get_s_regtime1)){
			$str_where.=" and FROM_UNIXTIME(user_regtime)>='".$get_s_regtime1."'";
			$get_issearch="1";
		}
		if(is_date($get_s_regtime2)){
			$lng_x=format_date_int($get_s_regtime2)+86400;
			$str_s_regtime2=format_date($lng_x,"Y-m-d");
			$str_where.=" and FROM_UNIXTIME(user_regtime)<'".$str_s_regtime2."'";
			$get_issearch="1";
		}
		if(is_date($get_s_logintime1)){
			$str_where.=" and FROM_UNIXTIME(user_logintime)>='".$get_s_logintime1."'";
			$get_issearch="1";
		}
		if(is_date($get_s_logintime2)){
			$str_where.=" and FROM_UNIXTIME(user_logintime)<='".$get_s_logintime2."'";
			$get_issearch="1";
		}
		$arr_user=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."sys_user".$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."sys_user".$str_where." order by user_id".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["state"]=array_search($obj_rs["user_state"],$arr_state);
			if($obj_rs["user_state"]<1) $obj_rs["state"]="<font color='#ff0000'>".$obj_rs["state"]."</font";
			$obj_rs["type"]=array_search($obj_rs["user_type"],$arr_type);
			$obj_rs["user_regtime"] = format_date($obj_rs["user_regtime"]);
			if($obj_rs["user_logintime"]>0){
				$obj_rs["user_logintime"] = format_date($obj_rs["user_logintime"]);
			}else{
				$obj_rs["user_logintime"]="";
			}
			$arr_user[] = $obj_rs;
		}
		include "tpl/user.tpl.php";

	}
}


?>
