<?php
require 'inc.php';
$obj_tab_domain=new cls_tab_sys_domain();
$arr_state=$obj_tab_domain->state;
$page_footer_info=<<<HTML
HTML;


if($get_act=="del"){
	$arr_return=$obj_tab_domain->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_domain->on_del($get_vipid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		if(!isset($get_vip_viewresume)) $get_vip_viewresume=0;
		(isset($get_domain_starttime) && is_date($get_domain_starttime))? $get_domain_starttime=strtotime($get_domain_starttime) : $get_domain_starttime=0;
		(isset($get_domain_endtime) && is_date($get_domain_endtime))? $get_domain_endtime=strtotime($get_domain_endtime) : $get_domain_endtime=0;
		$arr_fields["domain_id"]=$get_id;
		$arr_fields["domain_source_id"]=$get_domain_source_id;
		$arr_fields["domain_url"]=$get_domain_url;
		$arr_fields["domain_starttime"]=$get_domain_starttime;
		$arr_fields["domain_endtime"]=$get_domain_endtime;
		$arr_fields["domain_state"]=$get_domain_state;
		$arr_msg=$obj_tab_domain->on_save($arr_fields);
		if($arr_msg["err"]=="") $get_id=$arr_msg["id"];
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'edit':
	{
		$arr_vip=array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."sys_domain where domain_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_result2 = $obj_db->query("SELECT company_name,company_user_id FROM ".DB_PRE."hr_company where company_id=".$obj_rs["domain_source_id"]);
			if($obj_rs2 = $obj_db->fetch_array($obj_result2))
			{
				$obj_rs["company_name"]=$obj_rs2["company_name"];
			}
			$obj_rs["domain_endtime"]=date("Y-m-d",$obj_rs["domain_endtime"]);
			$obj_rs["domain_starttime"]=date("Y-m-d",$obj_rs["domain_starttime"]);
			$arr_domain = $obj_rs;
		}else{
			$arr_domain = $obj_db->get_fields(DB_PRE."sys_domain",true);
			$arr_domain["company_name"]="";
		}
		include 'tpl/domain.edit.tpl.php';
		break;
	}
	default:
	{
		//·ÖÒ³
		$str_where=" where domain_type='company'";
		$arr_source_id=array();
		$arr_vip=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."sys_domain".$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_domain".$str_where.$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["starttime"]=date("Y-m-d",$obj_rs["domain_starttime"]);
			$obj_rs["endtime"]=date("Y-m-d",$obj_rs["domain_endtime"]);
			$obj_rs["state"]=array_search($obj_rs["domain_state"],$arr_state);
			$arr_source_id[]=$obj_rs["domain_source_id"];
			$arr_vip[] = $obj_rs;
		}
		if(count($arr_source_id)){
			$str_ids=implode(",",$arr_source_id);
			$obj_result=$obj_db->query("select company_name,company_id from ".DB_PRE."hr_company where company_id in(".$str_ids.")");
			while($obj_rs=$obj_db->fetch_array($obj_result)){
				$arr_company["id_".$obj_rs["company_id"]]=$obj_rs["company_name"];
			}
		}
		include "tpl/domain.tpl.php";

	}
}


?>