<?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.1.1.2.8.1 2004/09/26 10:21:27 kazuyan Exp $ */

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

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

	$chan_name = urldecode(get_var('channel',array('GET','POST')));
	$channel   = $GLOBALS['phpgw']->db->db_addslashes( $chan_name );
	$action    = get_var('action',array('GET','POST'));
	$location  = get_var('location',array('GET','POST'));
	$message   = $GLOBALS['phpgw']->db->db_addslashes( 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','" . $message."','1','"
			. $now . "')", __LINE__, __FILE__);
		}
		else
		{
			$GLOBALS['phpgw']->db->query("INSERT INTO phpgw_chat_privatechat "
				. "(user1,user2,sentby,"
				. "message, messagetype,"
				. "timesent) values ('$loginid',"
				. "'$channel','$loginid','" . $message."','1','"
				. $now . "')", __LINE__, __FILE__);
		}
	}

	$tpl = &$GLOBALS['phpgw']->template;
	$tpl->set_file(array('sendmsg' => 'sendmsg.tpl'));
	
  $tplvars['link'] = $GLOBALS['phpgw']->link('/chat/sendmsg.php');
  $tplvars['message_link'] = $GLOBALS['phpgw']->link('/chat/messages.php',array(
		'channel' => urlencode($channel),
		'action'  => $action,
		'location'=> $location
	)) . '#bottom';
	$tplvars['c_name'] = $chan_name;
	$tplvars['locat'] = $location;
	$tplvars['send_message'] = lang('Send Message');
		
	$tpl->set_var($tplvars);
	$tpl->pfp('out','sendmsg');
?>
