<?php

//-----Создаем титл страницы-----//
$title = 'Гостевая книга';
//-----Подключаем функции-----//
require_once ('../system/function.php');
//-----Подключаем вверх-----//
require_once ('../system/header.php');
$id = abs(intval($_GET['id']));
$ank = mysql_fetch_assoc(mysql_query("SELECT * FROM `users` WHERE `id` = '".$id."'"));
switch($_GET['act'])
{
default:
echo '<div class="title">Гостевая книга</div>';
if(isset($_REQUEST['ok']))
{
if($user['id'])
{
$msg = strong($_POST['msg']);
if(empty($msg) or mb_strlen($msg) < 3)
{
echo '<div class="podmenu"><center><b>Ошибка ввода,минимум 3 символа!</b></center></div>';
require_once ('../system/footer.php');
exit();
}
$tim = mysql_query("SELECT * FROM `guest` WHERE `avtor` = '".$user['id']."' ORDER BY `time` DESC");
while($ncm2 = mysql_fetch_assoc($tim)){
$news_antispam = mysql_fetch_assoc(mysql_query("SELECT * FROM `antispam` WHERE `guest` "));
$ncm_timeout = $ncm2['time'];
if((time()-$ncm_timeout) < $news_antispam['guest']) {
echo '<div class="podmenu"><center><b>Пишите не чаще чем раз в '.$news_antispam['guest'].' секунд!</b></center></div>';
require_once ('../system/footer.php');
exit();
}
}
mysql_query("INSERT INTO `guest` SET `msg` = '".$msg."', `avtorlogin` = '".$user['login']."', `avtor` = '".$user['id']."', `time` = '".time()."'");
header('Location: '.$HOME.'/guest/');
exit();
}
}
echo '<div class="podmenu"><center><a href="'.$HOME.'/guest/">Обновить</a> | <a href="'.$HOME.'/smile/">Смайлы</a> | <a href="'.$HOME.'/bb.php">BB коды</a></center></div>';
if($user['id'])
{
echo '<div class="podmenu"><form action="" name="message" method="POST" >';
require_once ('../system/bbcode.php');
echo '<textarea name="msg" placeholder="Вводите сообщение..."></textarea><br />
<input type="submit" name="ok" value="Написать" name="add" />
</form></div>';


}else{
echo '<div class="podmenu">
<textarea name="msg" placeholder="Вводите сообщение..." disabled="disabled""></textarea>
<br /><a href="'.$HOME.'/registr.php"><input type="submit" value="Зарегистрируйтесь" /></a></div>';
}
if (empty($user['max'])) $user['max']=10;
$max = $user['max'];
$k_post = mysql_result(mysql_query("SELECT COUNT(id) FROM `guest`"),0);
$k_page = k_page($k_post,$max);
$page = page($k_page);
$start = $max*$page-$max;
$guest = mysql_query("SELECT * FROM `guest` ORDER BY `time` DESC LIMIT $start, $max");
while($g = mysql_fetch_assoc($guest))
{
echo '<div class= "links">'.nick($g['avtor']).'';
echo ''.user($g['avtor']).' '.vremja($g['time']).' <br />';
if($user['level'] >= 1 or $user['id'] == $g['avtor'])
{
echo '[<a href="'.$HOME.'/guest/delmsg'.$g['id'].'">уд</a>]';
}
if($user['id'] != $g['avtor']) {
echo '[<a href="'.$HOME.'/guest/otvet'.$g['id'].'">отв</a>]';
}
echo '</div>
<div class="podmenu">'.bb(smile($g['msg'])).'</div>';
}
if($k_post < 1)
{
echo '<div class="podmenu"><center><b>Пока пусто,будешь первым!</b></center></div>';
}
if ($k_page > 1) {
echo str(''.$HOME.'/guest/?',$k_page,$page); // Вывод страниц
}else{
echo '<div class="links"><a href="'.$HOME.'/">Назад на главную</a></div>';
}
break;

case 'delmsg':
$id = abs(intval($_GET['id']));
$gg = mysql_fetch_assoc(mysql_query("SELECT * FROM `guest` WHERE `id` = '".$id."'"));
if(isset($gg['id']))
{
if($user['level'] > 1 or $user['id'] == $gg['avtor'])
{
mysql_query("DELETE FROM `guest` WHERE `id` = '".$id."'");
header('Location: '.$HOME.'/guest/');
exit();
}else{
header('Location: '.$HOME.'/guest/');
}
}else{
echo '<div class="title"><a href="'.$HOME.'/guest/">Гостевая книга</a> | Ошибка</div>';
echo '<div class="podmenu"><center><b>Такого сообщения не существует!</b></center></div>';
}
break;
case 'otvet':
echo '<div class="title">Гостевая книга</div>';
$id = abs(intval($_GET['id']));
$gg = mysql_fetch_assoc(mysql_query("SELECT * FROM `guest` WHERE `id` = '".$id."'"));
if($user['id'] == $gg['avtor']) {
header('Location: '.$HOME.'/guest/');
}
if(isset($gg['id']))
{
if(isset($_REQUEST['ok']))
{
$msg = strong($_POST['msg']);
if(empty($msg) or mb_strlen($msg) < 3)
{
echo '<div class="podmenu"><center><b>Ошибка ввода,минимум 3 символа!</b></center></div>';
require_once ('../system/footer.php');
exit();
}
if($user['id'] != $gg['avtor']) {
mysql_query("INSERT INTO `lenta` SET `readlen` = '0', `time` = '".time()."', `komy` = '".$gg['avtor']."', `kto` = '".$user['id']."', `text` = 'ответил на ваше сообщение в [url=".$HOME."/guest] гостевой[/url]'");
}
mysql_query("INSERT INTO `guest` SET `msg` = '[b]".$gg['avtorlogin'].",[/b]".$msg."', `avtorlogin` = '".$user['login']."', `avtor` = '".$user['id']."', `time` = '".time()."'");
header('Location: '.$HOME.'/guest/');

exit();
}

echo '<div class="podmenu">';
echo 'Ответ на сообщение: '.nick($gg['avtor']).'';
echo $gg["msg"];
echo '</div>';
echo '<div class="podmenu"><form action="" name="message" method="POST" >';
require_once ('../system/bbcode.php');
echo '<textarea name="msg" value="'.$gg[avtor].'" placeholder="Вводите сообщение..."></textarea><br />
<input type="submit" name="ok" value="Написать" name="add" />
</form></div>';


}
break;
}
//-----Подключаем низ-----//
require_once ('../system/footer.php');
?>
