<?php
session_start();
header("Content-type: text/html; charset=windows-1251");
define("PATH", $_SERVER['DOCUMENT_ROOT']);
include(PATH."/core/func.php");
include(PATH."/core/db.php");
include(PATH."/core/set.php");
include(PATH."/core/define.php");

if(isset($_SESSION["login"]) AND $_POST["chat-msg"] != NULL){
	db_connect();
	//$_POST["chat-msg"] = str_replace("gif*", "gif'>", $_POST["chat-msg"]);
	//$_POST["chat-msg"] = str_replace("*", "<img src='img/cabinet/smiles/", $_POST["chat-msg"]);
	db_query("INSERT INTO `".DBpref."chat` (`login`, `text`, `dat`) VALUES ('".iconv("utf-8", "windows-1251", db_string($_SESSION["login"]))."', '".iconv("utf-8", "windows-1251", db_string($_POST["chat-msg"]))."', '".date("Y-m-d H:i:s")."')");
	
			$res = db_query("SELECT `id` FROM `".DBpref."chat` ORDER BY `id` DESC LIMIT 50");
			while($row = db_assoc($res)) $i = $row["id"];
			db_query("DELETE FROM `".DBpref."chat` WHERE `id` < ".$i);
	
	$res = db_query("SELECT `id` FROM `".DBpref."chat` ORDER BY `id` LIMIT 50");
	$row = db_assoc($res);
	
	db_close();
}

?>