<?php
// $Id: response.php 85 2006-09-01 01:22:59Z yosha_01 $
/**
 * @package discuss
 *
 * Class for rendering XML Response
 * this handler doesn't have objects to handle.
 * an utility class to rendar view.
 */
class DiscussResponseHandler
{
    var $response = "";
	
	function DiscussResponseHandler()
	{
		$this->response = "";
	}
	
	function render()
	{
		header('Content-type: text/xml; charset=utf-8');
		echo "<" . "?xml version=\"1.0\" encoding=\"utf-8\" ?" . ">";
		echo "<response>";
		echo $this->response;
		echo "</response>";
	}

	function addMessageXML($message_objects)
	{
		//@todo : should write error handling code.
	    $this->response .= "<message_objects>";
		foreach ($message_objects as $message_object) {			
			$this->response .= "<message_object>";
				$this->response .= "<message_id>".$message_object->getVar('message_id')."</message_id>";
				//@yosha no way.
				$this->response .= "<uname>".DiscussEncoder::toUtf8($message_object->getVar('uname'))."</uname>";
                //@yosha 'e' option is used to get simply escaped value (ilogical).
				$this->response .= "<message>".DiscussEncoder::toUtf8($message_object->getVar('message','e'))."</message>";
				$this->response .= "<color>".$message_object->getVar('color')."</color>";
				//@yosha the code bellow (logic) seems to feel out of place :(
				$pattern = $GLOBALS['xoopsModuleConfig']['dateformat'];
				if (isset($pattern) && trim($pattern) != '' ){
				    $this->response .= "<timestamp>".formatTimestamp($message_object->getVar('timestamp'), $pattern)."</timestamp>";
				} else {
                    $this->response .= "<timestamp>-</timestamp>";
				}
			$this->response .= "</message_object>";
		}
		$this->response .= "</message_objects>";		
	}	
	
	function addAttendeeXML($attendees)
	{
		//@todo : should write error handling code.
		$this->response .= "<attendee_objects>";
		$uid_arr =array();
			foreach($attendees as $attendee){
			$this->response .= "<attendee_object>";
				$this->response .= "<attendee_id>".$attendee->getVar('attendee_id')."</attendee_id>";
				$this->response .= "<uid>".$attendee->getVar('uid')."</uid>";
				$this->response .= "<attendee_uname>".DiscussEncoder::toUtf8($attendee->getVar('uname'))."</attendee_uname>";
			$this->response .= "</attendee_object>";
			}
		$this->response .= "</attendee_objects>";		
	}
	
	function addCommandXML($commands)
	{
	    // send command XML to discuss client.
	    // discuss client parse and process command from server.
	}
}

?>