Файл: chat.php
Строк: 64
<?php
define('ROOT','./');
define('GCMS',true);
require_once (ROOT.'system/power.php');
$diz -> head('Мини чат');
$diz -> title('Мини чат');
switch($mode) {
case 'write':
$func->aut();
$text = shit($_POST['text']);
$te = $db -> query("SELECT * FROM `comes` WHERE `where`='minichat' and `idwh` = '".(int)$id."' and `user` = '".(int)$ya['id']."' LIMIT 1");
if (mb_strlen($text) < 3) {
echo '<div class="fon">Короткое сообщение!</div>';
header('refresh: 3; url=?');
}else{
$mtime = $db -> query("SELECT * FROM `comes` WHERE `user` = '".$ya['id']."' order by `time` DESC")->fetch_assoc();
if($mtime['time']+$nastr['floodkom']<=time()){
$db -> query("UPDATE `users` SET `balls` = balls+$nastr[bcoms] WHERE `id` = '".$ya['id']."'");
$db -> query("INSERT INTO `comes` SET `where`='minichat', `user` = '".$ya['id']."', `idwh` = '".$id."',`text` = '".$text."',`time` = '".time()."'");
header('location: ?page='.$page);
}else{
echo '<div class="fon">Следующее сообщение можно оставить через '.$nastr['floodkom'].' сек.</div>';
header('refresh: 3; url=?');
}
}
break;
case 'del':
$func->aut();
$sql = $db -> query("SELECT * FROM `comes` WHERE `id` = '".$sid."' and `where`='minichat' LIMIT 1");
if ($sql -> num_rows > 0) {
$ass = $sql -> fetch_assoc();
if ($ya['level']>4 or $ass['user']==$ya['id']) {
$db -> query("DELETE FROM `comes` WHERE `id` = '".$sid."' and `where`='minichat' LIMIT 1");
header('location: ?&page='.$page);
} else header('location: ?page='.$page);
} else header('location: ./');
break;
default:
$count = $db -> dbcount('COUNT(`id`)','comes',"`idwh` = '".$id."' and `where`='minichat'");
if($count>0){
$num = isset($ya['num']) ? $ya['num'] : 10;
$total = intval(($count - 1) / $num) + 1;
if (!isset($_GET['page']) || !is_numeric($_GET['page']) || $_GET['page'] < 1 )
{
$page = 1;
} elseif($_GET['page'] > $total)
{ $page = $total;
} else $page = (int)$_GET['page'];
$start = $page * $num - $num;
////------------------/////
$for = $db -> query("SELECT * FROM `comes` where `idwh` = '".$id."' and `where`='minichat' order by `time` DESC LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$dop = null;
if ($ya['level'] > 1 or $assoc['user']==$ya['id']) {
$dop = '<a href="?id='.$id.'&sid='.$assoc['id'].'&mode=del&page='.$page.'">[Удалить]</a>';
}
echo '<div class="fon">
<table><tr valign="top"><td>'.$func->avatar($assoc['user']).'</td>
<td style="padding-left:5px;">'.$func->famname($assoc['user']).' '.$func -> times(date('d m Y в H:i',$assoc['time'])).'</br>
'.$func -> tags($func -> smiles($assoc['text'])).'<br/>'.$dop.'</td>
</tr></table></div>';
}
$act = '?';
echo ''.$func -> pagenav($act,$page,$total).'';
}else echo '<div class="fon">Сообщений пока нет.</div>';
if ($aut == true) {
echo '<div class="fon"><form action="?mode=write&page='.$page.'" method="post">
Комментарий:<br/>
<textarea name="text" rows="3" cols="15"></textarea><br/>
<input type="submit" value="Написать!"/>
</form></div>';}
}
echo '<div class="levo"><a href="/index.php" class="levo_tuch">'.$diz -> img('home.png').' На главную</a></div>';
#####Копирайт#######
$diz -> out($msg);
?>