Просмотр файла znwap/chat.php

Размер файла: 3.45Kb
<?php
// добавление в чат
if ($mode=='chatadd') {
	$r=delhtml(@$_REQUEST['r']);
$body=insertsmiles(delhtml($_POST['body']));
if ((trim($body)!="") && checkantirep()) {
	mysql_query("INSERT INTO zn_chat VALUES(NULL, '$login', '$body', CURRENT_TIMESTAMP(), '$r')");
}
$mode='chat';
unset($_REQUEST['body']);
}
//------------------------------------------------------------------------------------
if ($mode=='chatrooms') {
	$res=mysql_query("SELECT * FROM zn_rooms ORDER BY id");
	while ($ra=mysql_fetch_array($res)) {
		list($oc)=mysql_fetch_row(mysql_query("SELECT COUNT(*) FROM zn_anket WHERE room='$ra[id]' AND online='1'"));
		echo "&#187;<a href=\"$workdir/?mode=chat&amp;r=$ra[id]\">$ra[title]</a> ($oc)<br/>";
	}
	echo "&#187; <a href=\"$workdir/?mode=menu\"><b>Меню</b></a>";
}
//------------------------------------------------------------------------------------
if ($mode=='chatwrite') {
	$r=delhtml(@$_REQUEST['r']);
if (isset($_REQUEST['body'])) {$body=delhtml($_REQUEST['body']);} else {$body="";}
echo "<form action=\"$workdir/\" method=\"post\">
<input type=\"hidden\" name=\"mode\" value=\"chatadd\"/>".getantirep()."
<input type=\"hidden\" name=\"r\" value=\"$r\"/>
<textarea rows=\"3\" cols=\"20\" name=\"body\">$body</textarea>&nbsp;<br/>
<input type=\"submit\" name=\"submit\" value=\"Отправить\"/>&nbsp;<br/>
</form>
&#187; <a href=\"$workdir/?mode=smiles\">Смайлы</a><br/>
&#187; <a href=\"$workdir/?mode=chat&amp;r=$r\">Назад</a><br/>
&#187; <a href=\"$workdir/?mode=menu\"><b>Меню</b></a>";
}
//------------------------------------------------------------------------------------
// вывод чата
if ($mode=='chat') {
if (isset($_REQUEST['n'])) {$n=intval($_REQUEST['n']);} else {$n=0;}
$r=delhtml(@$_REQUEST['r']);
if (isset($_REQUEST['body'])) {$body=delhtml($_REQUEST['body']);} else {$body="";}
$redirecturl="http://$_SERVER[HTTP_HOST]$workdir/?mode=chat&amp;n=$n&amp;r=$r&amp;sid=".session_id();

echo "&#187; <a href=\"$workdir/?mode=chatwrite&amp;r=$r\">Написать</a><br/>";
echo "&#187; <a href=\"$workdir/?mode=chat&amp;r=$r\">Обновить</a><br/>";
echo "</div><div class=\"b\">\n";


$a=mysql_fetch_array(mysql_query("SELECT COUNT(*) AS c FROM zn_chat WHERE r='$r'"));
$c=$a['c'];

$res=mysql_query("SELECT *, DATE_FORMAT(date, '%d.%m.%y %H:%i') AS date FROM zn_chat WHERE r='$r' ORDER BY id DESC LIMIT $n,$mesonpage");
for ($i=0; $i<mysql_num_rows($res); $i++) {
	$a=mysql_fetch_array($res);
	echo "<b>$a[date]</b> ";
	echo "<a href=\"$workdir/?mode=showanket&amp;chat=1&amp;r=$r&amp;l=".urlencode($a['fromn'])."\">$a[fromn]</a>";
	if (in_array($login, $adminlogin)) {
		echo " [<a href=\"$workdir/?mode=adminchatdel&amp;id=$a[id]&amp;r=$r\">del</a>]";
	}
	echo "<br/>";
	echo "$a[body]<br/></div><div class=\"b\">";
}

if ($c>$mesonpage) {
	if ($n>0) {
		$pp=$n-$mesonpage;
		if ($pp<0) {$pp=0;}
		echo "<a href=\"$workdir/?mode=chat&amp;n=$pp&amp;r=$r\">&lt;&lt;&lt;</a> ";
	}
	if ($n<$c) {
		$np=$n+$mesonpage;
		if ($np<=$c) {
			echo "<a href=\"$workdir/?mode=chat&amp;n=$np&amp;r=$r\">&gt;&gt;&gt;</a>";
		}
	}
	echo "<br/>";
}

echo "&#187; <a href=\"$workdir/?mode=chatwrite&amp;r=$r\">Написать</a><br/>";
echo "&#187; <a href=\"$workdir/?mode=chat&amp;r=$r\">Обновить</a><br/>";
echo "&#187; <a href=\"$workdir/?mode=chatrooms\">Комнаты</a><br/>";
echo "&#187; <a href=\"$workdir/?mode=menu\"><b>Меню</b></a>";

}

?>