Файл: public_html/forum/topic.php
Строк: 119
<?php
$title = 'Просмотр темы';
require_once '../includes/sys.php';
require_once '../includes/header.php';
if (!$u['id']) {
echo '<div class="row">Форум доступен только зарегистрированным пользователям</div>';
require_once '../includes/tail.php';
exit();
}
switch ($act) {
default:
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
if (isset($topic['id'])) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_subcats` WHERE `id` = '$topic[id_subcat]'"));
echo '<div class="title"><b><a href="index.php?act=subcat&id='.$topic['id_subcat'].'">'.$subcat['name'].'</a>» '.$topic['title'].'</b></div><div class="rega">';
if ($u['access'] > 0) {
echo $topic['closed'] == 1 ? '<a href="?act=open&id='.$id.'">Открыть</a>' : '<a href="?act=close&id='.$id.'">Закрыть</a>';
echo '|<a href="?act=edit&id='.$topic['id'].'">Параметры темы</a>';
if ($u['access'] > 1) echo '|<a href="?act=del&id='.$id.'">Удалить</a></div>';
}
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$id'"), 0);
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$msg_r = mysql_query("SELECT * FROM `forum_msg` WHERE `id_topic` = '$id' ORDER BY `time` LIMIT $begin, $config[onpage]");
while ($msg = mysql_fetch_assoc($msg_r)) {
echo '</div><div class="raz"><a href="../other/profile.php?id='.$msg['id_user'].'">'.username($msg['id_user'], 2).'</a> '.ccdate($msg['time'], $msg['id_user']).' ';
if ($u['id']) {
if ($msg['votes'] > 0) {
echo '+'.$msg['votes'];
}
echo '<b>'.$msg['rating'].'</b><a href="?act=rate&id='.$msg['id'].'"> -</a> / <a href="?act=rate&id='.$msg['id'].'&ok=1""> + </a><br /></div><div class="lst">';
}
echo ''.bb($msg['text']);
if($msg['file']) echo '<br><b>Прикрепленный файл:</b> <a href="/forum/file.php?id='.$msg['id'].'">'.htmlspecialchars($msg['file'], ENT_QUOTES).'</a> ('.(round(filesize($_SERVER['DOCUMENT_ROOT'].'/forum/files/'.$msg['file'])/1024)).' Кб)';
echo '<br></div><div class="row"><div class="right">[<a href="posting.php?act=reply&id='.$msg['id'].'">Отв</a>][<a href="posting.php?act=quote&id='.$msg['id'].'">Цит</a>]';
if ($u['access'] > 0 or $u['id'] == $msg['id_user'] and TIME - $msg['time'] < $config['edit_time']) echo '[<a href="posting.php?act=edit&id='.$msg['id'].'">Ред</a>]';
if ($u['access'] > 1) echo '[<a href="posting.php?act=del&id='.$msg['id'].'">Уд</a>]</div></div>';
echo '</div>';
}
echo' </div>';
navig($page, '?act=topic&id='.$id.'&', $pages);
if ($u['id']) {
if ($topic['closed'] == 0) {
echo '
</div> <div class="row"><b>Сообщение:</b><br/><form name="form" enctype="multipart/form-data" action="posting.php?act=add&id='.$id.'" method="post">
<textarea name="text" cols="" rows="3"></textarea>
<br/><b>Файл:</b><br/><input type="file" name="file" style="width: 99%"><br/>';
echo '<input name="" type="submit" value="Написать">
</form></div>';
} else {
echo '<div class="rega">Тема закрыта для обсуждений.<br /></div>';
}
} else {
echo 'Вы не <a href="../other/login.php">авторизованы</a> для добавления сообщений.<br />';
}
} else {
redirect('index.php?');
}
break;
case 'rate':
$type = 'forum_msg';
require_once '../includes/rate.php';
break;
case 'add':
if ($u['id']) {
$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `name` FROM `forum_subcats` WHERE `id` = '$id'"));
if ($subcat['id_cat']) {
if (TIME > $antispam) {
if ($ok) {
$title = check($_POST['title']);
$text = check($_POST['text']);
if ($title and $text) {
mb_internal_encoding('UTF-8');
if (mb_strlen($text) <= 2500) {
mysql_query("INSERT INTO `forum_topics` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$id', `title` = '$title', `id_user` = '$u[id]', `last_time` = '".time()."', `stuck` = '$stuck', `closed` = '$closed'");
$id_topic = mysql_insert_id();
mysql_query("INSERT INTO `forum_msg` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$id', `id_topic` = '$id_topic', `id_user` = '$u[id]', `text` = '$text', `time` = '".TIME."'");
$_SESSION['antispam'] = TIME + $config['antispam'];
redirect('?act=topic&id='.$id_topic);
} else {
error('Слишком длинный текст.');
nav('?act=add&id='.$id);
}
} else {
echo '<div class="title">Ошибка</div>';
if (strlen($title == 0)){echo '<div class="error">Не заполнен заголовок темы</div>';}
if (strlen($text == 0)){echo '<div class="error">Не заполнен текст</div>';}
}
} else {
tp('<a href="?act=subcat&id='.$id.'">'.$subcat['name'].'</a>» Создать тему');
echo '<div class="body"><form name="form" action="?act=add&id='.$id.'&ok=1" method="post">
<b>Заголовок(max50):</b><br /><input name="title" type="text" maxlength="50" /><br />
<b>Сообщение(max750):</b><br /> '.bbpanel('form', 'text').'<textarea name="text" cols="" rows="4"></textarea><br />
<input name="submit" type="submit" value="Создать" /></form></div>';
}
} else {
error('Антиспам. Разрешено пиcать раз в '.$config['antispam'].' сек.');
nav2('?act=subcat&id='.$id);
}
}
} else {
redirect('login.php');
}
break;
case 'edit':
if (access(1)) {
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
if (isset($topic['id'])) {
if ($ok) {
$title = check($_POST['title']);
$text = check($_POST['text']);
if ($title and $text) {
$subcat_id = abs(intval($_POST['subcat']));
$subcat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$subcat_id'"));
$stuck = abs(intval($_POST['stuck']));
$closed = abs(intval($_POST['closed']));
mysql_query("UPDATE `forum_topics` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$subcat[id]', `title` = '$title', `stuck` = '$stuck', `closed` = '$closed' WHERE `id` = '$id'");
mysql_query("UPDATE `forum_msg` SET `text` = '$text' WHERE `id_topic` = '$id' ORDER BY `id` LIMIT 1");
$msg_r = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_topic` = '$id'");
while ($msg = mysql_fetch_assoc($msg_r)) {
mysql_query("UPDATE `forum_msg` SET `id_cat` = '$subcat[id_cat]', `id_subcat` = '$subcat[id]' WHERE `id` = '$msg[id]'");
}
redirect('?id='.$id);
} else {
redirect('?act=edit&id='.$id);
}
} else {
$msg_r = mysql_query("SELECT `text` FROM `forum_msg` WHERE `id_topic` = '$id' ORDER BY `id` LIMIT 1");
$msg = mysql_fetch_assoc($msg_r);
tp('Редактирование темы');
echo '<div class="body"><form name="form" action="?act=edit&id='.$id.'&ok=1" method="post">
<b>Раздел:</b><br/><select name="subcat" style="width: 99%">';
$subcat_r1 = mysql_query("SELECT * FROM `forum_subcats` WHERE `id` = '$topic[id_subcat]'");
$subcat1 = mysql_fetch_assoc($subcat_r1);
$cat1 = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '$subcat1[id_cat]'"));
echo '<option value="'.$subcat1['id'].'">'.$cat1['name'].' > '.$subcat1['name'].'</option>';
$subcat_r = mysql_query("SELECT * FROM `forum_subcats` WHERE `id` != '$topic[id_subcat]' ORDER BY `id_cat`, `name`");
while ($subcat = mysql_fetch_assoc($subcat_r)) {
$cat = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_cats` WHERE `id` = '$subcat[id_cat]'"));
echo '<option value="'.$subcat['id'].'">'.$cat['name'].' > '.$subcat['name'].'</option>';
}
echo '</select><br />
<b>Заголовок(max50):</b><br /><input name="title" type="text" value="'.$topic['title'].'" maxlength="50" /><br />
<b>Текст:</b><br /> '.bbpanel('form', 'text').'<textarea name="text" cols="" rows="5">'.$msg['text'].'</textarea><br />';
echo $topic['stuck'] == 1 ? '<input name="stuck" type="checkbox" value="1" checked />' : '<input name="stuck" type="checkbox" value="1" />';
echo ' закрепить<br />';
echo $topic['closed'] == 1 ? '<input name="closed" type="checkbox" value="1" checked />' : '<input name="closed" type="checkbox" value="1" />';
echo ' закрыть<br />';
echo '<input name="submit" type="submit" value="Ok" />
</form></div>';
}
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'close':
if ($u['access'] > 0) {
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
if ($topic['id']) {
mysql_query("UPDATE `forum_topics` SET `closed` = 1 WHERE `id` = '$id'");
mysql_query("INSERT INTO `forum_msg` SET `id_cat` = '$topic[id_cat]', `id_subcat` = '$topic[id_subcat]', `id_topic` = '$topic[id]', `id_user` = '$u[id]', `text` = '[b]Тема закрыта для обсуждения :-)[/b]', `time` = '".TIME."'");
redirect('?act=topic&id='.$id);
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'open':
if ($u['access'] > 0) {
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
if ($topic['id']) {
mysql_query("UPDATE `forum_topics` SET `closed` = 0 WHERE `id` = '$id'");
mysql_query("INSERT INTO `forum_msg` SET `id_cat` = '$topic[id_cat]', `id_subcat` = '$topic[id_subcat]', `id_topic` = '$topic[id]', `id_user` = '$u[id]', `text` = '[b]Тема открыта для обсуждения :-)[/b]', `time` = '".TIME."'");
header('location: ?act=topic&id='.$id);
exit;
} else {
redirect('?');
}
} else {
redirect('?');
}
break;
case 'del':
if (access(2)) {
$topic = mysql_fetch_assoc(mysql_query("SELECT * FROM `forum_topics` WHERE `id` = '$id'"));
if ($topic['id']) {
if ($ok) {
$forum_msg_r = mysql_query("SELECT `id` FROM `forum_msg` WHERE `id_topic` = '$id'");
while ($forum_msg = mysql_fetch_assoc($forum_msg_r) ) {
mysql_query("DELETE FROM `voting` WHERE `type` = 'forum' and `id_for` = '$forum_msg[id]'");
}
mysql_query("DELETE FROM `forum_msg` WHERE `id_topic` = '$id'");
mysql_query("DELETE FROM `forum_topics` WHERE `id` = '$id'");
redirect('index.php?act=subcat&id='.$topic['id_subcat']);
} else {
tp('Подтверждение');
echo '<div class="body"><form name="form" action="?act=del&id='.$id.'&ok=1" method="post">
Вы действительно хотите удалить тему "'.$topic['title'].'"?<br />
<input name="submit" type="submit" value="Да" />
</form></div>
';
}
} else {
redirect('index.php?');
}
} else {
redirect('index.php?');
}
break;
case 'end':
$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$id'"), 0);
if ($t_msg > 0) {
$last_page = ceil($t_msg / $config['onpage']);
redirect('?id='.$id.'&p='.$last_page);
} else {
redirect('index.php');
}
break;
}
require_once '../includes/tail.php';
?>