<?php

if (!defined('XOOPS_ROOT_PATH')) exit();

/**
 * To one user, From one user, No CC, No attach.
 */
class PrivateMessage
{
	var $mToUsers=array();
	var $mFromUsers=array();
	var $mSubject=null;
	var $mMessage=null;
	
	function PrivateMessage()
	{
	}
	
	function setToUsers(&$users)
	{
		if(is_array($users))
			$user=&$users[0];
		else $user=&$users;
		
		$this->_setToUser($user);
	}
	
	function _setToUser(&$user)
	{
		$this->mToUsers[0]=&$user;
	}
	
	function setFromUsers(&$users)
	{
		if(is_array($users))
			$user=&$users[0];
		else
			$user=&$users;
		
		$this->_setFromUser($user);
	}
	
	function _setFromUser(&$user)
	{
		$this->mFromUsers[0]=&$user;
	}
	
	function setSubject($subject)
	{
		$this->mSubject=$subject;
	}
	
	function setMessage($message)
	{
		$this->mMessage=$message;
	}
	
	/**
	 * @return bool
	 */
	function send()
	{
		$pmHandler=&xoops_gethandler('privmessage');
		$pm=&$pmHandler->create();
		$pm->setVar("to_userid",$this->mToUsers[0]->getVar('uid'));
		$pm->setVar("from_userid",$this->mFromUsers[0]->getVar('uid'));
		$pm->setVar("subject",$this->mSubject);
		$pm->setVar("msg_text",$this->mMessage);

		return $pmHandler->insert($pm);
	}
}

// Wmm...
class PrivateMessageManager
{
	function &create()
	{
		$instance=new PrivateMessage();
		return $instance;
	}
}


?>