Файл: book/comes.php
Строк: 87
<?php
define('ROOT','../');
define('GCMS',true);
require_once (ROOT.'system/power.php');
if ($aut) {
switch($mode) {
case 'write':
$fp = $db -> dbcount('COUNT(*)','forum_posts',"`user` = '".$ya['id']."'");
if ($ya['balls']>=$nastr['obcom']) {
$page = isset($_GET['page']) ? (int)$_GET['page'] : '1';
$text = shit($_POST['text']);
$te = $db -> query("SELECT * FROM `comes` WHERE `where`='books' and `idwh` = '".(int)$id."' and `user` = '".(int)$ya['id']."' LIMIT 1");
if (mb_strlen($text) < 3) {
$diz -> head('Ошибка');
$diz -> title('Ошибка');
echo '<div class="fon">Короткий комментарий!</div>';
header('refresh: 3; url=comments'.$id.'');
$diz -> out($msg);
}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`='books', `user` = '".(int)$ya['id']."', `idwh` = '".$id."',`text` = '".$text."',`time` = '".time()."'");
$page = isset($_GET['page']) ? (int)$_GET['page'] : '1';
header('location: comes.php?id='.(int)$id.'&page='.(int)$page);
}else{
$diz -> head('Ошибка');
$diz -> title('Ошибка');
echo '<div class="fon">Следующий комментарий можно оставить через '.$nastr['floodkom'].' сек.</div>';
header('refresh: 3; url=comments'.$id.'');
$diz -> out($msg);
}
}
}else{
$diz -> head('Ошибка');
$diz -> title('Ошибка');
echo '<div class="fon">Извините,но вы пока что не можете комментировать!</div>';
header('refresh: 3; url=comments'.$id.'');
$diz -> out($msg);
}
break;
case 'del':
$page = isset($_GET['page']) ? $_GET['page'] : '1';
if ($aut == true and $id != false) {
$sql = $db -> query("SELECT * FROM `comes` WHERE `id` = '".$sid."' and `where`='books' LIMIT 1");
if ($sql -> num_rows > 0) {
$ass = $sql -> fetch_assoc();
if ($ya['level']>4) {
$db -> query("DELETE FROM `comes` WHERE `id` = '".$sid."' and `where`='books' LIMIT 1");
header('location: comes.php?id='.(int)$ass['idwh'].'&page='.(int)$page);
} else header('location: comes.php?id='.(int)$ass['idwh'].'&page='.(int)$page);
} else header('location: comes.php?id='.(int)$ass['idwh'].'&page='.(int)$page);
} else header('location: comes.php?id='.(int)$ass['idwh'].'&page='.(int)$page);
break;
default:
$diz -> head('Комментарии');
$new = $db -> query("SELECT `id`,`name` FROM `books` WHERE `id` = '".$id."' LIMIT 1")-> fetch_assoc();
$diz -> title("<a href='./book$new[id]'>".$new['name']."</a>/<b>Комментарии</b>");
$count = $db -> dbcount('COUNT(`id`)','comes',"`idwh` = '".(int)$id."' and `where`='books'");
$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;
if ($count>0){
$for = $db -> query("SELECT * FROM `comes` WHERE `idwh` = '".(int)$id."' and `where`='books' ORDER BY `id` DESC LIMIT ".$start.",".$num);
while ($assoc = $for -> fetch_assoc()) {
$dop = null;
if ($aut) {
if ((int)$ya['level'] > 4) {
$dop = '<a href="comes.php?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->nick($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>';
}
}else echo '<div class="fon">Комментариев пока нет!</div>';
if ($aut == true) {
echo '<div class="fon">
<form action="comes.php?id='.$id.'&mode=write&page='.$page.'" method="post">
Комментарий:<br/>
<textarea name="text" rows="3" cols="15"></textarea><br/>
<input type="submit" value="Написать!"/>
</div></form>';}
$act = 'comes.php?id='.(int)$id;
echo ''.$func -> pagenav($act,$page,$total).'';
}
echo '<div class="levo"><a href="/index.php" class="levo_tuch">'.$diz -> img('home.png').' На главную</a></div>';
#####Копирайт#######
$diz -> out($msg);
} else header('location: /aut.php');
?>