<?php
require 'inc.php';
$obj_tab_msgbook=new cls_tab_other_msgbook();
if(!isset($int_pagesize)) $int_pagesize=10;
if(!isset($get_act)) $get_act="";
if(!isset($get_pannel)) $get_pannel="";
(!isset($get_page))? $get_page=0:$get_page=intval($get_page);
$page_footer_info=<<<HTML
<script>
</script>
HTML;
if($get_act=="del"){
	$arr_return=$obj_tab_msgbook->on_del($get_id);
	if($arr_return["err"]!=""){
		$obj_msg->alert($arr_return["err"]);
	}
}
if($get_act=="del_sel"){
	$arr_return=$obj_tab_msgbook->on_del($get_msgid);
	if($arr_return["err"]!=""){
		$obj_msg->alert($arr_return["err"]);
	}
}
if($get_act=="save"){
		$arr_fields=array();
		$arr_fields["msg_id"]=$get_id;
		$arr_fields["msg_remsg"]=$get_msg_remsg;
		$arr_fields["msg_retime"]=TIME;
		$arr_return=$obj_tab_msgbook->on_save($arr_fields);
	if($arr_return["err"]!=""){
		$obj_msg->alert($arr_return["err"]);
	}else{
		$get_act="edit";
	}
}
switch($get_act)
{
	case "edit":
	{
		$arr_msgbook = array();
		$obj_result = $obj_db->query("SELECT * FROM ".DB_PRE."other_msgbook where msg_id='".$get_id."'");
		if($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["msg_addtime"]=date("Y-m-d H:i",$obj_rs["msg_addtime"]);
			$obj_rs["msg_retime"]=date("Y-m-d H:i",$obj_rs["msg_retime"]);
			$obj_rs["uname"]="";
			if($obj_rs["msg_user_id"]>0){
				$obj_tab_sys_user=new cls_tab_sys_user();
				$arr_uname=$obj_tab_sys_user->get_user_name($obj_rs["msg_user_id"]);
				$obj_rs["uname"]=$arr_uname["id_".$obj_rs["msg_user_id"]];
			}
			$arr_msgbook = $obj_rs;
		}
		include 'tpl/msgbook.return.tpl.php';
		break;
	}
	default:
	{
		$str_where="";
		$arr_msgid=array();
		$arr_msgbook = array();
		$obj_rs  = $obj_db->get_one("SELECT count(*) as num FROM ".DB_PRE."other_msgbook".$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."other_msgbook ".$str_where." order by msg_addtime desc".$str_limit);
		while($obj_rs = $obj_db->fetch_array($obj_result))
		{
			$obj_rs["msg_addtime"]=date("Y-m-d H:i",$obj_rs["msg_addtime"]);
			$obj_rs["msg_retime"]=date("Y-m-d H:i",$obj_rs["msg_retime"]);
			if(empty($obj_rs["msg_state"])) $arr_msgid[]=$obj_rs["msg_id"];
			$arr_msgbook[] = $obj_rs;
		}
		if(count($arr_msgid)>0){
			$str_ids=implode(",",$arr_msgid);
			$obj_db->execute("update ".DB_PRE."other_msgbook set msg_state=1 where msg_id in(".$str_ids.")");
		}
		include 'tpl/msgbook.tpl.php';
	}
}

?>
