<?php

	$phpgw_info["flags"] = array(
		"currentapp" => "chat",
		"noheader"   => True,
		"nonavbar"   => True
	);
	include("../header.inc.php");

	$loginid = $phpgw_info["user"]["userid"];
	$refresh = 3;

	$phpgw->db->query("SELECT * FROM chat_messages WHERE channel='$channel'");
	$phpgw->db->next_record();
	$status = $phpgw->db->f("status");
	$title = $phpgw->db->f("title");
	$user2 = $channel;

	// below line is abusively bad HTML form, but works in NS so far.
	echo "<head><META HTTP-EQUIV='Refresh' Content='10'\"".$phpgw_info["user"]["preferences"]["chat"]["chat_refresh"].";URL=#bottom\"></head><body>";

	echo "<center><strong>$loginid in $channel</strong></center>";
	if ($location == "public")
	{
		$phpgw->db->query("SELECT * FROM chat_messages WHERE channel='$channel' AND timesent>'" . $phpgw_info["user"]["logintime"]. "' ORDER BY timesent");
		$phpgw->db->next_record();
		for ($i = 0; $i < $phpgw->db->nf(); $i++)
		{
			echo "<font color='blue'>" . $phpgw->db->f("loginid") . " (" . $phpgw->common->show_date($phpgw->db->f("timesent"),"H:i.s") . "):  </font><font color='red'>" . $phpgw->db->f("message") . "</font><br>";
			$phpgw->db->next_record();
		}
	}
	if ($location == "private")
	{
		$phpgw->db->query("SELECT * FROM chat_privatechat WHERE (user1='$loginid' AND user2='$user2') OR (user1='$user2' AND user2='$loginid') ORDER BY timesent");
		$phpgw->db->next_record();
		for ($i = 0; $i < $phpgw->db->nf(); $i++)
		{
			echo "<font color='blue'>" . $phpgw->db->f("sentby") . " (" . $phpgw->common->show_date($phpgw->db->f("timesent"),"H:i.s") . "):  </font><font color='red'>" . $phpgw->db->f("message") . "</font><br>";
			$phpgw->db->next_record();
		}		
	}

	echo "<a name='bottom'></a>";
	echo "</body></html>";
?>
