Файл: pages/forum/topics.php
Строк: 135
<?php
include '../../system/mysql.php';
include '../../system/sys_func.php';
$cat = mysql_fetch_array(mysql_query("SELECT * FROM `f_category` WHERE `id` = '". intval($_GET['id']) ."'"));
$forum = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '". $cat['forum_id'] ."'"));
// Если категории не существует...
if (!isset($_GET['id']) || isset($_GET['id']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `f_category` WHERE `id` = '". intval($_GET['id']) ."'"), 0) != 1) {
$title = 'Форум/Ошибка';
include '../../system/head.php';
echo '<div class="title"><a href="/pages/forum/">Форум</a> / Ошибка</div>
<div class="err">Такой категории не существует!</div>
<a class="link" href="index.php"><img src="/design/imgs/arr_b.png" align="center"> Форум</a>';
include '../../system/foot.php';
exit;
}
switch (@$_GET['menu']) {
case 'create':
$error = false;
$errort = '';
if (!isset($user)) {
$title = 'Форум/Ошибка';
include '../../system/head.php';
echo '<div class="err">Чтобы просматривать данную страницу вы должны <a href="/pages/registration/">зарегистрироваться</a> или <a href="/pages/registration/?menu=login">авторизоваться</a>!</div>';
include '../../system/foot.php';
exit;
}
if (isset($_POST['create'])) {
$name = htmlspecialchars(mysql_real_escape_string($_POST['name']));
$msg = htmlspecialchars(mysql_real_escape_string($_POST['msg']));
if (strlen($name) < 1) {
$error = true;
$errort .= '<div class="err">Длина заголовка должна быть не менее 1-ого символа.</div>';
} elseif (strlen($name) > 64) {
$error = true;
$errort .= '<div class="err">Длина заголовка должна быть не более 64-х символов.</div>';
}
if (strlen($msg) < 1) {
$error = true;
$errort .= '<div class="err">Длина сообщения должна быть не менее 1-ого символа.</div>';
} elseif (strlen($msg) > 20000) {
$error = true;
$errort .= '<div class="err">Длина сообщения должна быть не более 20 000 символов.</div>';
}
if (mysql_result(mysql_query("SELECT COUNT(*) FROM `f_theme` WHERE `name` = '$name' AND `msg` = '$msg' LIMIT 1"), 0) != 0) {
$error = true;
$errort .= 'Такая тема уже существует.';
}
if (!$error) {
$bon_rand = rand(1, 10);
mysql_query("UPDATE `users` SET `bonus` = '". ($user['bonus']+$bon_rand) ."' WHERE `id` = '". $user['id'] ."'");
$them = mysql_query("SELECT * FROM `f_theme` WHERE `forum_id` = '". $forum['id'] ."' AND `cat_id` = '". $cat['id'] ."'");
mysql_query("INSERT INTO `f_theme` (`forum_id`, `cat_id`, `id_user`, `name`, `msg`, `time`) values('". $forum['id'] ."', '". $cat['id'] ."', '$user[id]', '$name', '$msg', '". time() ."')");
$insert = mysql_insert_id();
mysql_query("UPDATE `f_theme` SET `forum_id` = '". $forum['id'] ."', `cat_id` = '". $cat['id'] ."', `last_post` = '". time() ."' WHERE `id` = '". $insert ."'");
header('Location: topic.php?id='. $insert);
exit;
}
}
$title = 'Форум/'. $cat['name'] .'/Создание темы';
include '../../system/head.php';
echo '<div class="title"><a href="index.php">Форум</a> / <a href="category.php?id='. $forum['id'] .'">'. $forum['name'] .'</a> / <a href="topics.php?id='. $cat['id'] .'">'. $cat['name'] .'</a> / Создание темы</div>';
echo $errort;
echo '<form method="post" name="message">
<b>Имя темы</b>:<br><input type="text" name="name"><br>';
include '../../system/bbcodes.php';
echo '<textarea class="resize" name="msg"></textarea><br>';
include '../../system/smiles.php';
echo '<input value="Создать" type="submit" name="create" />
</form>';
echo '<a class="link" href="topics.php?id='. $cat['id'] .'"><img src="/design/imgs/arr_b.png" align="center"> Назад</a>';
include '../../system/foot.php';
break;
default:
$title = 'Форум/'. $cat['name'];
include '../../system/head.php';
echo '<div class="title"><a href="index.php">Форум</a> / <a href="category.php?id='. $forum['id'] .'">'. $forum['name'] .'</a> / '. $cat['name'] .'</div>';
$c_t = mysql_result(mysql_query("SELECT COUNT(*) FROM `f_theme` WHERE `forum_id` = '". $forum['id'] ."' AND `cat_id` = '". $cat['id'] ."'"), 0);
if (isset($user)) $p_page = $user['p_page'];
else $p_page = '10';
$k_page = k_page($c_t, $p_page);
$page = page($k_page);
$start = $p_page*$page-$p_page;
if ($c_t == 0) {
echo '<div class="post">
Нет тем!
</div>';
}
$q = mysql_query("SELECT * FROM `f_theme` WHERE `forum_id` = '". $forum['id'] ."' AND `cat_id` = '". $cat['id'] ."' ORDER BY `fix` DESC, `time` DESC LIMIT $start, ". $p_page);
while ($them = mysql_fetch_assoc($q)) {
echo '<div class="post">
<span class="c_date">'. ptime($them['time']) .'</span>';
if ($them['fix'] == 1) {
echo '<img src="/design/imgs/stick.gif" alt="top" /> ';
}
echo '<a href="topic.php?id='. $them['id'] .'">'. $them['name'] .'</a>
('. mysql_result(mysql_query("SELECT COUNT(*) FROM `f_post` WHERE `forum_id` = '". $forum['id'] ."' AND `cat_id` = '". $cat['id'] ."' AND `them_id` = '$them[id]'"), 0) .')';
if ($them['close'] == 1) {
echo ' <img src="/design/imgs/topic_locked.gif" alt="top" />';
}
$ank = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$them[id_user]'"));
echo '<br>';
echo online($ank['id']);
echo ' <a href="/pages/users/user.php?name='. $ank['login'] .'">'. $ank['login'] .'</a> / ';
$post2 = mysql_fetch_assoc(mysql_query("SELECT * FROM `f_post` WHERE `them_id` = '$them[id]' AND `cat_id` = '". $cat['id'] ."' AND `forum_id` = '". $forum['id'] ."' ORDER BY `time` DESC LIMIT 1"));
$ank2 = mysql_fetch_array(mysql_query("SELECT * FROM `users` WHERE `id` = '$post2[id_user]'"));
if (isset($post2['id_user'])) {
echo online($ank2['id']);
if ($ank['login'] == $ank2['login']) {
echo ' '. $ank2['login'] .' ('. ptime($them["time"]) .')';
} else {
echo ' <a href="/pages/users/user.php?name='. $ank2['login'] .'">'. $ank2['login'] .'</a> ('. ptime($post2['time']) .')';
}
} else {
echo online($ank['id']);
echo ' <span style="color:#666">'. $ank['login'] .' ('. ptime($them['time']) .'</span>';
}
echo '</div>';
}
if ($k_page > 1) str('?id='. $cat['id'] .'&', $k_page, $page);
if ($user['position'] == 'admin' || $user['position'] == 'mod_f') {
echo ' <a class="link" href="category.php?id='. $forum['id'] .'&edit='. $cat['id'] .'"><img src="/design/imgs/edit.png"> Редактировать текущую категорию</a>';
}
if (isset($user)) {
echo '<a class="link" href="?id='. $cat['id'] .'&menu=create"><img src="/design/imgs/add.png"> Новая тема</a>';
} else {
echo '<div class="err">Чтобы писать темы, вы должны <a href="/pages/registration/">зарегистрироваться</a> или <a href="/pages/registration/?menu=login">авторизоваться</a>!</div>';
}
echo '<a class="link" href="category.php?id='. $forum['id'] .'"><img src="/design/imgs/arr_b.png" align="center"> '. $forum['name'] .'</a>
<a class="link" href="index.php"><img src="/design/imgs/arr_b.png" align="center"> Разделы</a>';
include '../../system/foot.php';
break;
}
?>