<?php

/*
 * Copyright (C) xgcms.com
 */

class message extends base_model {
	function __construct(&$conf) {
		parent::__construct($conf);
		$this->table = 'message';
		$this->primarykey = array('messageid');
		$this->maxcol = 'messageid';
	}
		// 取list
	public function get_message_list($where,$start='0',$pagesize='15') {
		$list = $this->index_fetch($where, array('message_time'=>2),$start,$pagesize);
		return $list;
	}
	// 用来显示给用户
	public function format(&$msg) {
		if(empty($msg)) return;
		$msg['message_time']=misc::minidate($msg['message_time'], $this->conf['timeoffset']);

	}

	public function _delete($id) {
		$return = $this->delete($id);
		return $return;
	}
	
	public function add_message($tousername,$username,$subject,$content){
			$message = array ();
			$message['send_from_id'] = $username;
			$message['send_to_id'] = $tousername;
			$message['subject'] = $subject;
			$message['content'] = $content;
			$message['message_time'] = $_SERVER['time'];
			$message['status'] = '1';
			$message['folder'] = 'inbox';

			if($message['send_from_id']==""){
				$message['send_from_id'] = $this->userinfo['name'];
			}
			if(empty($message['content'])){
				$this->message('发信内空不能为空！');
			}
			$messageid = $this->create($message);
			if(!$messageid){
				return FALSE;
			}else {
			    $this->member_newpms($tousername,1);
				return $messageid;
			}
		
	}
	public function member_newpms($username,$newpms){
		$recvuser=$this->member->get_user_by_username($username);
		if(empty($recvuser)) return false;
		$recvuser['newpms']+=$newpms;
		$recvuser['newpms']<0&&$recvuser['newpms']=0;
		$this->member->update($recvuser);
	}
}
?>
	
	