<?php
include(dirname(__file__)."/../includes.php");

//留言板基础api函数
function msgboard_read_base($fields="*",$condition="",$by_col="",$order="",$num="",$cache="",$cache_key=""){
	global $tablePreStr;
	$uid=get_sess_userid();
	$t_msgboard=$tablePreStr."msgboard";
	$plugin_rs=array();
	$dbo=new dbex;
  dbplugin('r');
  if($num==''||$num >= 1000){
  	$limit=" limit 1000 ";
  }else{
  	$limit=" limit $num ";
  }
  if($by_col!=''){
  	$by_col=" order by $by_col ";
  }
  $sql=" select $fields from $t_msgboard where to_user_id = $uid $condition $by_col $order $limit ";
  if($cache==1&&in_array($num,array(10,20,50))&&$cache_key!=''){
		$key=$cache_key.$uid.'_'.$num;
		$key_mt=$cache_key.'mt_'.$uid.'_'.$num;
		$plugin_rs=model_cache($key,$key_mt,$dbo,$sql);
	}
	if(empty($plugin_rs)){
		$plugin_rs=$dbo->getRs($sql);
	}
	return $plugin_rs;
}

function msgboard_self_get_mine($fields="*",$date="",$is_read="",$from_id="",$num=10){
	$is_read=intval($is_read);
	$from_id_str=filt_num_array($from_id);
	$fields=filt_fields($fields);
	$condition="";
	$cache=1;
	if($date!=''){
		$condition.=str_replace("{date}","add_time",date_filter($date));
	}
	if($is_read!=''){
		$condition.=" and readed = $is_read ";
	}
	if($from_id!=''){
		$condition.=" and from_user_id in ($from_id_str) ";
		$cache = 0;
	}
	return msgboard_read_base($fields,$condition,"add_time","desc",$num,$cache,"msgboard_");
}

?>