Просмотр файла forum/index.php

Размер файла: 7.81Kb
<?php
// by Mike O. (mides), coolcms.org
$title = 'Форум';
require_once '../includes/sys.php';
require_once '../includes/header.php';

switch ($act) {
    default:
        tp($lang['forum']);
		echo '<div class="body">';
        $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 '<img src="../images/forum_cat.png" alt="forum_cat" /> <a href="index.php?act=cat&amp;id='.$cat['id'].'">'.$cat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br />';
            }
        } else {
			echo $lang['there_are_no_categories'];
        }
        echo '<br /><form name="form" action="index.php?act=newposts" method="post">
        <input name="submit" type="submit" value="Новые сообщения" />
        </form>
		</div>';
    break;
	
    case 'newposts':
		tp('<a href="?">Форум</a>&raquo; Новые сообщения');
        $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"><a href="topic.php?act=end&amp;id='.$msg['id_topic'].'">'.bb($msg['text']).'<br />Написал(a) '.username($msg['id_user']).', '.ccdate($msg['time'], 0).'</a></div>';

            }
			echo '<div class="body">';
            navig($page, '?act=newposts&amp;', $pages);
        } else {
			echo '<div class="body">';
            echo 'Новых сообщений еще нет<br /><br />';
        }
		echo '<a href="?">В форум</a></div>';
    break;
	
    case 'cat':
        $cat = mysql_fetch_assoc(mysql_query("SELECT `name` FROM `forum_cats` WHERE `id` = '$id'"));
        if ($cat['name']) {
            tp('<a href="?">'.$lang['forum'].'</a>&raquo; '.$cat['name']);
			echo '<div class="body">';
            $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 '<a href="index.php?act=subcat&amp;id='.$subcat['id'].'">'.$subcat['name'].'</a> ('.$f_topics.'/'.$f_msg.')<br />';
                }
            } else {
                echo $lang['no_subcategories_yet'];
            }
			echo '<br /><a href="?">'.$lang['forum'].'</a>&raquo; '.$cat['name'].'</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="?">'.$lang['forum'].'</a>&raquo; <a href="?act=cat&amp;id='.$subcat['id_cat'].'">'.$cat['name'].'</a>&raquo; '.$subcat['name']);
			echo '<div class="body">';
            $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)) {

                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.') '.username($lastuser['id_user'], 2).'<a href="topic.php?act=end&amp;id='.$topic['id'].'">&raquo;&raquo;</a><br />';
                }
            } else {
                echo $lang['no_topics_yet'].'<br />';
            }
            echo '<br /><form name="form" action="topic.php?act=add&amp;id='.$id.'" method="post">
            <input name="" type="submit" value="Создать новую тему">
            </form>';
            navig($page, '?act=subcat&amp;id='.$id.'&amp;', $pages);
            echo '<a href="?">'.$lang['forum'].'</a>&raquo; <a href="?act=cat&amp;id='.$subcat['id_cat'].'">'.$cat['name'].'</a>&raquo; '.$subcat['name'].'</div>';
        } 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';
?>