Файл: pages/forum/topics.php
Строк: 109
<?php
include ('../../system/mysql.php');
include ('../../system/sys_func.php');
$forum_id = intval($_GET['forum']);
$cat_id = intval($_GET['cat']);
// Если категории не существует...
if (isset($_GET['forum']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `forum` WHERE `id` = '". intval($_GET['forum']) ."'"),0) != 1 || isset($_GET['cat']) && mysql_result(mysql_query("SELECT COUNT(*) FROM `f_category` WHERE `id` = '". intval($_GET['cat']) ."'"),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="category.php?forum='. $forum_id .'">← Назад</a>';
foot();
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>';
foot();
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>n";
} elseif (strlen($name) > 64) {
$error = true;
$errort .= "<div class='err'>Длина заголовка должна быть не более 64-х символов.</div>n";
}
if (strlen($msg) < 1) {
$error = true;
$errort .= "<div class='err'>Длина сообщения должна быть не менее 1-ого символа.</div>n";
} elseif (strlen($msg) > 20000) {
$error = true;
$errort .= "<div class='err'>Длина сообщения должна быть не более 20 000 символов.</div>n";
}
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) {
$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?forum=$forum_id&cat=$cat_id&them=". $insert);
exit;
}
}
$forum = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '$forum_id'"));
$cat = mysql_fetch_array(mysql_query("SELECT * FROM `f_category` WHERE `id` = '". $cat_id ."' AND `forum_id` = '". $forum_id ."'"));
$title = 'Форум/'. $cat['name'] .'/Создание темы';
include ('../../system/head.php');
echo '<div class="title"><a href="index.php">Форум</a> / <a href="/forum/category.php?forum='. $forum['id'] .'">'. $forum['name'] .'</a> / <a href="/forum/category.php?forum='. $forum['id'] .'&cat='. $cat['id'] .'">'. $cat['name'] .'</a> / Создание темы</div>';
echo $errort;
echo '<form method="post" name="message">
<b>Имя темы</b>:<br><input type="text" name="name"><br>
<b>Сообщение темы</b>:<br>
<textarea cols="20" rows="2" name="msg"></textarea><br>
<input value="Создать" type="submit" name="create" />
</form>';
echo '<a class="link" href="topics.php?forum='. $forum_id .'&cat='. $cat_id .'">← Назад</a>';
foot();
break;
default:
$forum = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '$forum_id'"));
$cat = mysql_fetch_array(mysql_query("SELECT * FROM `f_category` WHERE `id` = '". $cat_id ."' AND `forum_id` = '". $forum_id ."'"));
$title = "Форум/". $cat['name'];
include ('../../system/head.php');
echo '<div class="title"><a href="index.php">Форум</a> / <a href="category.php?forum='. $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 ($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");
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?forum='. $forum_id .'&cat='. $cat_id .'&them='. $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 " <span style='color:#666'>$ank2[login] (". ptime($them['time']) .")</span>";
} else {
echo ' <a href="/pages/users/user.php?name='. $ank2['login'] .'">'. $ank2['login'] .'</a> <span style="color:#666">('. ptime($post2['time']) .')</span>';
}
} else {
echo online($ank['id']);
echo ' <span style="color:#666">'. $ank['login'] .' ('. ptime($them['time']) .'</span>';
}
echo '</div>';
}
if (isset($user)) {
echo '<a class="link" href="?forum='. $forum_id .'&cat='. $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>';
}
$forum = mysql_fetch_array(mysql_query("SELECT * FROM `forum` WHERE `id` = '$forum_id'"));
echo '<a class="link" href="category.php?forum='. $forum['id'] .'">← '. $forum['name'] .'</a>
<a class="link" href="index.php">← Разделы</a>';
foot();
break;
}
?>