Файл: spuff.ru/forum/index.php
Строк: 67
<?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:
echo '<div class="title">Форум</div>';
echo '<div class="raz"><a href="?act=newposts">Новые сообщения</a></div>';
$cats_r = mysql_query("SELECT `id`, `name` FROM `forum_cats` ORDER BY `order`, `name`");
if (mysql_num_rows($cats_r)) {
while ($cat = mysql_fetch_assoc($cats_r)) {
$f_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_cat` = '$cat[id]'"), 0);
$f_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_cat` = '$cat[id]'"), 0);
echo '<div class="rega"
><img src="../images/forum_cat.png" alt="forum_cat" /> <a href="?act=cat&id='.$cat['id'].'">'.$cat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br /></div>';
$view_topics = mysql_query("select * from `forum_subcats` where `id_cat` = '$cat[id]' order by `id` desc limit 5");
while($v = mysql_fetch_assoc($view_topics)){
$f_t = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$v[id]'"), 0);
$f_m = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_subcat` = '$v[id]'"), 0);
echo '<div class="raz"><img src="/img/forum_t.png"><a href="?act=subcat&id='.$v['id'].'">'.$v['name'].'</a> ('.$f_t.'/'.$f_m.')<br /></div>';
}
}
} else {
echo '<div class="error">Нет категорий</div>';
}
break;
case 'newposts':
tp('<a href="?">Форум</a>» Новые сообщения');
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `time` > '".(TIME-43200)."'"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$forum_msg = mysql_query("SELECT * FROM `forum_msg` WHERE `time` > '".(TIME-43200)."' ORDER BY `time` DESC LIMIT $begin, $config[onpage]");
while($msg = mysql_fetch_assoc($forum_msg)){
$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$t[id]'"), 0);
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$t[id_cat]'"));
$lastuser = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$t[id]' ORDER BY `time` DESC limit 1"));
echo '<div class="row"><b>Сообщение:</b> <a href="topic.php?act=end&id='.$msg['id_topic'].'">'.bb($msg['text']).'</a><br/><b>Написал(a):</b> <a href="/other/profile.php?id='.$msg['id_user'].'">'.username($msg['id_user']).'</a><br/><b>Время:</b> '.ccdate($msg['time'], 0).'</div>';
}
navig($page, '?act=newposts&', $pages);
} else {
echo '<div class="error">Новых сообщений еще нет</div>';
}
break;
case 'cat':
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$id'"));
if ($cat['name']) {
tp('<a href="?">Форум</a> » '.$cat['name']);
$subcats_r = mysql_query("SELECT `id`, `name` FROM `forum_subcats` WHERE `id_cat` = '$id' ORDER BY `order`, `name`");
if (mysql_num_rows($subcats_r)) {
while ($subcat = mysql_fetch_assoc($subcats_r)) {
$f_topics = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$subcat[id]'"), 0);
$f_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_subcat` = '$subcat[id]'"), 0);
echo '<div class="raz"><img src="/img/forum_t.png"> <a href="?act=subcat&id='.$subcat['id'].'">'.$subcat['name'].'</a> ('.$f_topics.'/'.$f_msg.')</div>';
}
} else {
echo '<div class="error">Нет субкатегорий</div>';
}
} else {
redirect('?');
}
break;
case 'subcat':
$subcat = mysql_fetch_assoc(mysql_query("SELECT `id_cat`, `name` FROM `forum_subcats` WHERE `id` = '$id'"));
if ($subcat['name']) {
$cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$subcat[id_cat]'"));
tp('<a href="?">Форум</a>» <a href="?act=cat&id='.$subcat['id_cat'].'">'.$cat['name'].'</a>» '.$subcat['name']);
$total = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_topics` WHERE `id_subcat` = '$id'"), 0);
if ($total > 0) {
$pages = ceil($total / $config['onpage']);
if ($page > $pages or $page == 0) {
$page = 1;
}
$begin = ($page - 1) * $config['onpage'];
$topics_r = mysql_query("SELECT * FROM `forum_topics` WHERE `id_subcat` = '$id' ORDER BY `stuck` DESC, `last_time` DESC LIMIT $begin, $config[onpage]");
while ($topic = mysql_fetch_assoc($topics_r)) {
echo '<div class="raz">';
if ($topic['stuck']) {
echo '<img src="../images/forum_tstuck.gif" alt="forum_tstuck" />';
} elseif($topic['closed'] == 1 and empty($topic['stuck'])) {
echo '<img src="../images/forum_tclosed.png" alt="forum_tclosed" />';
} else {
echo '<img src="../images/forum_t.gif" alt="forum_t" />';
}
$t_msg = mysql_result(mysql_query("SELECT COUNT(`id`) FROM `forum_msg` WHERE `id_topic` = '$topic[id]'"), 0);
$lastuser = mysql_fetch_assoc(mysql_query("SELECT `id_user` FROM `forum_msg` WHERE `id_topic` = '$topic[id]' ORDER BY `time` DESC limit 1"));
echo ' <a href="topic.php?id='.$topic['id'].'">'.$topic['title'].'</a> ('.$t_msg.') <a href="topic.php?act=end&id='.$topic['id'].'">»</a><br/><b>Последний:</b> <a href="/other/profile.php?id='.$lastuser['id_user'].'">'.username($lastuser['id_user'], 2).'</a></div>';
}
} else {
echo '<div class="error">Темы ещё не созданы</div>';
}
echo '<div class="rega"><a href="topic.php?act=add&id='.$id.'">Создать новую тему</a></div>';
navig($page, '?act=subcat&id='.$id.'&', $pages);
} else {
redirect('?');
}
break;
case 'vote':
if ($u['id']) {
$p = abs(intval($_GET['p']));
$msg_r = mysql_query("SELECT `id`, `id_topic`, `id_user` FROM `forum_msg` WHERE `id` = '$id'");
$msg = mysql_fetch_assoc($msg_r);
if ($msg['id']) {
if ($msg['id_user'] != $u['id']) {
$query = mysql_query("SELECT `id` FROM `voting` WHERE `type` = 'forum' and `id_who` = '$u[id]' and `id_for` = '$id'");
if (!mysql_num_rows($query)) {
mysql_query("UPDATE `forum_msg` SET `votes` = (`votes`+1) WHERE `id` = '$id'");
mysql_query("INSERT INTO `voting` SET `type` = 'forum', `id_who` = '$u[id]', `id_for` = '$id'");
mysql_query("UPDATE `users` SET `karma` = (`karma`+1) WHERE `id` = '$msg[id_user]'");
}
}
header('location: ?act=topic&id='.$msg[id_topic].'&p='.$p);
exit;
} else {
header('location: ?');
exit;
}
} else {
header('location: login.php');
exit;
}
break;
}
require_once '../includes/tail.php';
?>