<?php
#############################################################################
#                              Site@School Chat module
# Site@School is a website management system designed for schools.
# This is a chat module which can be used in Site@School.
#
# coded by Fred Stuurman (fc.stuurman@hccnet.nl)
#############################################################################
#		based on 	CHATNESS v2		 see http://www.chatness.us/
#		BY: Stephen Craton
#   Altered for Site@School with consent of the author
#############################################################################
# post.php: last changed 05/10/2006  , version: 2.4.10
#              by Fred Stuurman (fc.stuurman@hccnet.nl)
#$Id: post.php,v 1.2 2006/10/15 19:08:53 fstuurman Exp $
############################################################################
#                        LICENSE INFORMATION
#
# 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.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
##############################################################################
define('IN_SAS', true);

include ("../../configuration/database.inc.php");
mysql_connect("$db_server", "$db_username", "$db_password");
mysql_select_db("$db_name");
require ("../../core/session.php"); //build a session

if (IsSet ($_SESSION['Chat_Username']))
{

	if (IsSet ($_POST['user']))
	{
		$user = $_POST['user'];
	}
	$user = htmlspecialchars(strip_tags($user)); //remove html tags

	if (IsSet ($_POST['message']))
	{
		$message = $_POST['message'];
	}
	$message = htmlspecialchars(strip_tags($message)); //remove html tags

	if (IsSet ($_POST['font']))
	{
		$font = $_POST['font'];
	}
	$font = htmlspecialchars(strip_tags($font)); //remove html tags

	if (IsSet ($_POST['to']))
	{
		$to = $_POST['to'];
	}
	$to = htmlspecialchars(strip_tags($to)); //remove html tags

	if (IsSet ($_POST['fontsize']))
	{
		$fontsize = $_POST['fontsize'];
	}
	$fontsize = htmlspecialchars(strip_tags($fontsize)); //remove html tags

	if (IsSet ($_POST['color']))
	{
		$color = $_POST['color'];
	}
	$color = htmlspecialchars(strip_tags($color)); //remove html tags

	$chats_usertable = $dbprefix . "m_chat_users";
	$chats_messagetable = $dbprefix . "m_chat_log";

	$ip = getenv('REMOTE_ADDR');

	$query = "SELECT status FROM $chats_usertable WHERE user='" . $user . "'";
	$result = mysql_query($query);
	$status = mysql_result($result, 0);
	$post = 1;

	if ($status != 'booted')
	{
		if (!empty ($message))
		{
			$query = "INSERT INTO $chats_messagetable SET user='" . $user . "', font='" . $font . "', color='" . $color . "', 
						size='" . $fontsize . "', text='" . $message . "', toperson='" . $to . "', posted=NOW(), room='$_SESSION[Chat_ID]', ip='$ip'";
			mysql_query($query);
			if ($status == 'idle')
			{
				$query = "UPDATE $chats_usertable SET status='', joined=NOW() WHERE user='" . $user . "'";
				mysql_query($query);
				$post = 2;
			}
		}
	}
	$_SESSION['font'] = @ $_POST['font'];
	$_SESSION['color'] = @ $_POST['color'];
	$_SESSION['fontsize'] = @ $_POST['fontsize'];
	$_SESSION['to'] = @ $_POST['to'];
	@ ob_end_clean();
	header("Location: message.php?user=" . $_POST['user'] . '&show_time=' . $_POST['show_time'] . '&post=' . $post . '&message=' . urlencode($_POST['message']));
}
?>
