File size: 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 "»<a href=\"$workdir/?mode=chat&r=$ra[id]\">$ra[title]</a> ($oc)<br/>";
}
echo "» <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> <br/>
<input type=\"submit\" name=\"submit\" value=\"Отправить\"/> <br/>
</form>
» <a href=\"$workdir/?mode=smiles\">Смайлы</a><br/>
» <a href=\"$workdir/?mode=chat&r=$r\">Назад</a><br/>
» <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&n=$n&r=$r&sid=".session_id();
echo "» <a href=\"$workdir/?mode=chatwrite&r=$r\">Написать</a><br/>";
echo "» <a href=\"$workdir/?mode=chat&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&chat=1&r=$r&l=".urlencode($a['fromn'])."\">$a[fromn]</a>";
if (in_array($login, $adminlogin)) {
echo " [<a href=\"$workdir/?mode=adminchatdel&id=$a[id]&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&n=$pp&r=$r\"><<<</a> ";
}
if ($n<$c) {
$np=$n+$mesonpage;
if ($np<=$c) {
echo "<a href=\"$workdir/?mode=chat&n=$np&r=$r\">>>></a>";
}
}
echo "<br/>";
}
echo "» <a href=\"$workdir/?mode=chatwrite&r=$r\">Написать</a><br/>";
echo "» <a href=\"$workdir/?mode=chat&r=$r\">Обновить</a><br/>";
echo "» <a href=\"$workdir/?mode=chatrooms\">Комнаты</a><br/>";
echo "» <a href=\"$workdir/?mode=menu\"><b>Меню</b></a>";
}
?>