<?php
	/**************************************************************************\
	* phpGroupWare - Chat                                                      *
	* http://www.phpgroupware.org                                              *
	* This application written by Joseph Engo <jengo@phpgroupware.org>         *
	* --------------------------------------------                             *
	*  This program is free software; you can redistribute it and/or modify it *
	*  under the terms of the GNU General Public License as published by the   *
	*  Free Software Foundation; either version 2 of the License, or (at your  *
	*  option) any later version.                                              *
	\**************************************************************************/

	/* $Id: sendmsg.php,v 1.7.2.2 2002/11/24 15:02:03 ralfbecker Exp $ */

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

	function get_var($name,$from)	// a simple version
	{
		if (!is_array($from)) $from = explode(',',$from);
		while ((list(,$f) = each($from)) && !isset($GLOBALS['HTTP_'.$f.'_VARS'][$name])) ;
		$ret = $GLOBALS['HTTP_'.$f.'_VARS'][$name];
		//echo "HTTP_$f"."_VARS[$name]=$ret<br>\n";
		return $ret;
	}

	$loginid = $GLOBALS['phpgw_info']['user']['userid'];

	$cannel   = get_var('channel',array('GET','POST'));
	$action   = get_var('action',array('GET','POST'));
	$location = get_var('location',array('GET','POST'));
	$message    = get_var('message',array('POST','GET'));

	if ($action=='post' && !empty($message))
	{
		$now = $GLOBALS['phpgw']->datetime->gmtnow;

		if ($location=='public')
		{
			$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_chat_messages (channel,"
				."loginid, message, messagetype,"
				."timesent) values ('$channel',"
				."'$loginid','" . addslashes($message)."','1','"
			. $now . "')");
		}
		else
		{
			$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_chat_privatechat "
				. "(user1,user2,sentby,"
				. "message, messagetype,"
				. "timesent) values ('$loginid',"
				. "'$channel','$loginid','" . addslashes($message)."','1','"
				. $now . "')");
		}
	}

	echo '<html><body onLoad="document.forms[0].message.focus();"><center>'."\n";
	echo '<form  name="sendmsg" method="post" action="' . $GLOBALS['phpgw']->link('/chat/sendmsg.php') . '">'."\n";
	echo '<input type="hidden" name="channel" value="' . $channel . '">'."\n";
	echo '<input type="hidden" name="action" value="post">'."\n";
	echo '<input type="hidden" name="location" value="' . $location . '">'."\n";
	echo '<input type="text"   size="50" name="message"><br>'."\n";
	echo '<input type="submit" value="' . lang('Send Message') . '">';
	echo "</form>\n</center>\n";
	echo "</body>\n</html>\n";
?>
