<?php
require 'inc.php';
$obj_tab_meet=new cls_tab_hr_meet();
$arr_state=$obj_tab_meet->state;

if(!isset($get_s_key)) $get_s_key="";
(isset($get_s_state))? $get_s_state=(int)$get_s_state:$get_s_state=-101;
if(!isset($get_s_date1)) $get_s_date1="";
if(!isset($get_s_date2)) $get_s_date2="";
$get_issearch=0;

if($get_act=="del"){
	$arr_return=$obj_tab_meet->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_meet->on_del($get_meetids);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="state" && isset($get_state_val)){
	$arr_return=$obj_tab_meet->on_state($get_meetids,$get_state_val);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_join_sel" && isset($get_joinids)){
	require SYS_ROOT.'/cls_tab/tab.hr.meet.join.php';
	$obj_tab_meet_join=new cls_tab_hr_meet_join();
	$arr_return=$obj_tab_meet_join->on_del($get_joinids);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}

switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		$arr_fields["meet_id"]=$get_id;
		$arr_fields["meet_date"]=$get_meet_date;
		$arr_fields["meet_title"]=$get_meet_title;
		$arr_fields["meet_address"]=$get_meet_address;
		$arr_fields["meet_state"]=$get_meet_state;
		$arr_fields["meet_content"]=$get_meet_content;
		$arr_msg=$obj_tab_meet->on_save($arr_fields);
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'edit':
	{
		$arr_meet=array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."hr_meet where meet_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$arr_meet = $obj_rs;
		}else{
			$get_id=0;
			$arr_meet = $obj_db->get_fields(DB_PRE."hr_meet",true);
		}
		include 'tpl/meet.edit.tpl.php';
		break;
	}
	case 'add':
	{
		$arr_meet=array();
		$get_id=0;
		$arr_meet = $obj_db->get_fields(DB_PRE."hr_meet",true);
		include 'tpl/meet.edit.tpl.php';
		break;
	}
	case "join":
	{
		$str_where=" where 1=1";
		$arr_join=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_meet_join".$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_meet_join a left join ".DB_PRE."hr_company b on a.join_company_id=b.company_id".$str_where.$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["addtime"]=date("Y-m-d H:i",$obj_rs["join_addtime"]);
			$arr_join[] = $obj_rs;
		}
		include "tpl/meet.join.tpl.php";
		break;
	}
	default:
	{
		//·ÖÒ³
		$str_where=" where 1=1";
		if(isset($get_s_state) && $get_s_state!=-101){
			$str_where.=" and meet_state='".intval($get_s_state)."'";
			$get_issearch=1;
		}
		if(isset($get_s_date1) && is_date($get_s_date1)){
			$str_where.=" and meet_date>='".$get_s_date1."'";
			$get_issearch=1;
		}
		if(isset($get_s_date2) && is_date($get_s_date2)){
			$str_where.=" and meet_date=<'".$get_s_date2."'";
			$get_issearch=1;
		}
		if(isset($get_s_key) && !empty($get_s_key)){
			$str_where.=" and meet_title like '%".$get_s_key."%'";
			$get_issearch=1;
		}
		$arr_meet=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."hr_meet".$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_meet".$str_where.$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["state"]=array_search($obj_rs["meet_state"],$arr_state);
			$obj_rs["addtime"]=date("Y-m-d",$obj_rs["meet_addtime"]);
			$arr_meet[] = $obj_rs;
		}
		include "tpl/meet.tpl.php";

	}
}

?>
