<?php
require 'inc.php';
$obj_tab_temp=new cls_tab_temp();
$arr_state=$obj_tab_temp->state;
$arr_fields_type=$obj_tab_temp->fields_type;
$arr_industry=$obj_tab_temp->industry;
if($get_act=="del"){
	$arr_return=$obj_tab_temp->on_del($get_id);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_temp->on_del($get_fzid);
	if($arr_return["err"]!="") $obj_msg->alert($arr_return["err"]);
}
switch($get_act)
{	
	case 'save':
	{
		$arr_fields=array();
		$arr_fields["temp_id"]=$get_id;
		$arr_fields["temp_industry"]=$get_temp_industry;
		$arr_fields["temp_title"]=$get_temp_title;
		$arr_fields["temp_price"]=$get_temp_price;
		$arr_fields["temp_path"]=$get_temp_path;
		$arr_fields["temp_state"]=$get_temp_state;
		$arr_fields["temp_pic"]=$get_temp_pic;
		$arr_fields["temp_fields_cont"]="";
		$arr_fields["temp_limit"]=(int)$get_temp_limit;
		$arr_fields["temp_unique"]=(int)$get_temp_unique;

		$arr_msg["err"]="";
		if(isset($get_fields_name) && is_array($get_fields_name) ){
			$arr_fields_cont=array();
			$arr_x_name=array();
			$lng_x=count($get_fields_name);
			for($i=0;$i<$lng_x;$i++){
				if(empty($get_fields_name[$i])) continue;
				if(in_array($get_fields_name[$i],$arr_x_name)){
					$arr_msg["err"]="Ìí¼Ó×Ö¶Î ".$get_fields_name[$i]." ÓÐÖØ¸´";
					break;
				}
				$arr_x=array();
				$arr_x["name"]=$get_fields_name[$i];
				$arr_x["type"]=$get_fields_type[$i];
				$arr_x["len"]=$get_fields_len[$i];
				$arr_x["notnull"]=$get_fields_notnull[$i];
				$arr_x["value"]=$get_fields_value[$i];
				$arr_fields_cont[]=$arr_x;
				$arr_x_name[]=$arr_x["name"];
			}
			if(count($arr_fields_cont)>0){
				$arr_fields["temp_fields_cont"]=serialize($arr_fields_cont);
			}
		}
		if($arr_msg["err"]==""){
			$arr_msg=$obj_tab_temp->on_save($arr_fields);
		}
		/*
		$arr_fields["temp_sort"]=$get_temp_sort;
		$arr_fields["temp_fields_cont"]=$get_temp_fields_cont;
		$arr_fields["temp_fields_temp"]=$get_temp_fields_temp;
		*/
		include 'tpl/_msg.tpl.php';
	    break;
	}
	case 'edit':
	{
		$arr_temp=array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."temp where temp_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["fields_cont"]=array();
			if(!empty($obj_rs["temp_fields_cont"])){
				$obj_rs["fields_cont"]=unserialize($obj_rs["temp_fields_cont"]);
			}
			$arr_temp = $obj_rs;
		}else{
			$arr_temp = $obj_db->get_fields(DB_PRE."temp",true);
			$arr_temp["fields_cont"]=array();
		}
		include 'tpl/temp.edit.tpl.php';
		break;
	}
	default:
	{
		//·ÖÒ³
		$str_where="";
		$arr_temp=array();
		$obj_rs   = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."temp".$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."temp".$str_where.$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["pic"]=get_html_url($obj_rs["temp_pic"]);
			$obj_rs["addtime"]=date("Y-m-d",$obj_rs["temp_addtime"]);
			$obj_rs["state"]=array_search($obj_rs["temp_state"],$arr_state);
			$arr_temp[] = $obj_rs;
		}
		include "tpl/temp.tpl.php";

	}
}

?>
