Location: PHPKode > projects > PhpMyForum > phpmyforum_4_1_1/board.php
<?php
define('PMF_INCLUDE', 1);
require('head.php');

// keine ID übergeben ?
if (!is_numeric($_GET['id'])) msg('error_board_fault', 'index.php');


#
#
### Rechte überprüfen
// Forum nicht vorhanden !
if (empty($forum['show_forum'])) {
    msg('error_board_fault', 'index.php');
// keine Rechte !
} elseif ($forum['show_forum'] == 0 || empty($_user['access']['board'])) {
    $goto = !empty($_user['id']) ? 'index.php' : '';
    msg('error_access', $goto);
}


#
#
### Abo ?
if (!empty($_user['id']) && is_numeric($_user['id'])) {
    $abo = $_db->fetch_first('SELECT board_id AS abo
                              FROM `'.$_cfg['DB_PREFIX'].'board_abo`
                              WHERE board_id = '.$_GET['id'].'
                                AND user_id = '.$_user['id']);
    $forum = (!empty($abo) && is_array($abo)) ? array_merge($forum, $abo) : $forum;
}


#
#
### Standard - Templates Vorbereiten
$_style->prefill('goto', goto_list(array('board' => $_GET['id'])), 0);
if (!empty($_config['FOOTER_RULES'])) $_style->prefill('footer_rules', footer_rulez(), 0);


#
#
### versteckte Kategorien ?
$_hidden = unserialize($_COOKIE['pmfHidden']);
if (isset($_GET['hide']) && is_numeric($_GET['hide'])) {
    $_hidden[$_GET['hide']] = 1;
    cookie('pmfHidden', serialize($_hidden));
    
} elseif (isset($_GET['show']) && is_numeric($_GET['show'])) {
    $_hidden[$_GET['show']] = 0;
    cookie('pmfHidden', serialize($_hidden));
}


### Unterforen - IDs
$child_boards = get_child_boards($forum['id']);

#
#
### Forum hat Unterforen ?
if (!empty($child_boards)) {
    
    ### ungelesene Themen
    $_unread_topics = get_unread_topics($child_boards);
    
    ### Mods
    $result = $_db->query('SELECT m.user_id, m.board_id, u.name
                           FROM `'.$_cfg['DB_PREFIX'].'board_mod` AS m,
                                `'.$_cfg['DB_PREFIX'].'user` AS u
                           WHERE u.id = m.user_id
                             AND m.board_id IN ('.implode(',', $child_boards).')');
    $_mods = array();
    while ($Mod = $_db->fetch_array($result)) {
        $_mods[$Mod['board_id']][] = array('id' => $Mod['user_id'],
                                           'name' => $Mod['name']);
    }
    
    ### Unterforen
    $boards = makeboardline($_GET['id'], 1);

    
#
#
### keine Unterforen --> Template löschen
} else {
    $_style->del('board_subboards');
}


#
#
### Navigation
$boardnav = makenavline($forum['parent_id']);


#
#
### Sortier - Feld
$sql = array();
if (!empty($_GET['sortfield']) && in_array($_GET['sortfield'], array('name','posts','views'))) {
    $sortfield[$_GET['sortfield']] = ' selected="selected"';
    $sql['field'] = 't.'.$_GET['sortfield'];
} elseif ($_GET['sortfield'] == 'post_date') {
    $sortfield['post_date'] = ' selected="selected"';
    $sql['field'] = 'p.post_date';
} else {
    $_config['TOPIC_SORT_FIELD'] = !empty($forum['sortfield']) ? $forum['sortfield'] : $_config['TOPIC_SORT_FIELD'];
    if ($_config['TOPIC_SORT_FIELD'] == 'post_date') {
        $sortfield['post_date'] = ' selected="selected"';
        $sql['field'] = 'p.post_date';
    } else {
        $sortfield[$_config['TOPIC_SORT_FIELD']] = ' selected="selected"';
        $sql['field'] = 't.'.$_config['TOPIC_SORT_FIELD'];
    }
}

#
#
### Sortier - Reihenfolge
if ($_GET['sortorder'] == 'ASC' || $_GET['sortorder'] == 'DESC') {
    $sortorder[$_GET['sortorder']] = ' selected="selected"';
    $sql['order'] = $_GET['sortorder'];
} else {
    $_config['TOPIC_SORT_ORDER'] = !empty($forum['sortorder']) ? $forum['sortorder'] : $_config['TOPIC_SORT_ORDER'];
    $sortorder[$_config['TOPIC_SORT_ORDER']] = ' selected="selected"';
    $sql['order'] = $_config['TOPIC_SORT_ORDER'];
}

#
#
### Sortier - Anzahl Themen
// von Anfang an
if ($_GET['sorttopics'] == '1000' || $forum['sorttopics'] == '1000' || $_user['topic_days'] == '1000') {
    $sorttopics['1000'] = ' selected="selected"';
    $sql['topics'] = 'p.post_date > 0';
// seit letzten Besuch
} elseif ($_user['topic_days'] == '0' || $_GET['sorttopics'] == '0') {
    $sorttopics['0'] = ' selected="selected"';
    $sql['topics'] = 'p.post_date > \''.$_user['last_login'].'\'';
// x Tage (per GET)
} elseif (!empty($_GET['sorttopics']) && is_numeric($_GET['sorttopics']) && $_GET['sorttopics'] != '1500') {
    $sorttopics[$_GET['sorttopics']] = ' selected="selected"';
    $topics = PMF_TIME-($_GET['sorttopics']*86400);
    $sql['topics'] = 'p.post_date >= \''.$topics.'\'';
// User - Settings
} elseif (!empty($_user['topic_days']) && $_user['topic_days'] && $_user['topic_days'] != '1500') {
    $sorttopics[$_user['topic_days']] = ' selected="selected"';
    $topics = PMF_TIME-($_user['topic_days']*86400);
    $sql['topics'] = 'p.post_date >= \''.$topics.'\'';
// $_config
} else {
    $_config['TOPIC_SORT_ANZ'] = ($forum['sorttopics'] != '1500') ? $forum['sorttopics'] : $_config['TOPIC_SORT_ANZ'];
    $sorttopics['1500'] = ' selected="selected"';
    $topics = PMF_TIME-($_config['TOPIC_SORT_ANZ']*86400);
    $sql['topics'] = 'p.post_date >= \''.$topics.'\'';
}


#
#
### wenn keine Page übergeben wurde
$_GET['page'] = (!empty($_GET['page']) && is_numeric($_GET['page'])) ? $_GET['page'] : 1;


#
#
##### Themen zusammenstellen (nur wenn Forum; nicht bei Kategorie)
if ($forum['is_board'] == 1) {
    
    ### Anzahl Themen
    $Topic_anz = implode('', $_db->fetch_first('SELECT COUNT(`id`)
                                                FROM `'.$_cfg['DB_PREFIX'].'topic` AS p
                                                WHERE `board_id` = '.$_GET['id'].'
                                                  AND `show_topic` = 1
                                                  AND '.$sql['topics']));
    ### Limit
    // LIMIT
    $_config['ANZ_TOPIC'] = (!empty($forum['anz_topic']) && empty($_user['id'])) ? $forum['anz_topic'] : $_config['ANZ_TOPIC'];
    if ($Topic_anz > $_config['ANZ_TOPIC']) {
        $L_AB = $_config['ANZ_TOPIC']*($_GET['page']-1);
    }
    // LIMIT
    $L_AB = ($L_AB > 0) ? $L_AB : 0;
    
    ### Navigation
    $navi = navi($_GET['page'], $Topic_anz, $_config['ANZ_TOPIC'], 'board.php?id='.$_GET['id'].'&amp;sortfield='.$_GET['sortfield'].'&amp;sortorder='.$_GET['sortorder'].'&amp;sorttopics='.$_GET['sorttopics']);

    ### Themen
    $result = $_db->query('SELECT t.id,
                                  t.name,
                                  t.prefix,
                                  t.user_id,
                                  t.old_board_id,
                                  t.views,
                                  t.closed,
                                  t.top,
                                  t.posts,
                                  t.show_topic,
                                  t.attachments,
                                  u1.id AS poster_id,
                                  u1.name AS poster_name,
                                  u2.id AS last_id,
                                  u2.name AS last_name,
                                  p.post_date,
                                  poll.id AS poll
                           FROM `'.$_cfg['DB_PREFIX'].'topic` AS t
                                LEFT JOIN `'.$_cfg['DB_PREFIX'].'user` AS u1 ON u1.id = t.user_id
                                LEFT JOIN `'.$_cfg['DB_PREFIX'].'poll` AS poll ON poll.topic_id = t.id,
                                `'.$_cfg['DB_PREFIX'].'post` AS p,
                                `'.$_cfg['DB_PREFIX'].'user` AS u2
                           WHERE ((t.board_id = '.$_GET['id'].' OR t.old_board_id = '.$_GET['id'].') OR t.top = 3)
                             AND p.id = t.last_post
                             AND u2.id = p.user_id
                             AND (('.$sql['topics'].') OR t.top > 0)
                             '.(empty($_style->mod) ? 'AND t.show_topic = 1' : '').'
                           GROUP BY t.id
                           ORDER BY t.top DESC, '.$sql['field'].' '.$sql['order'].'
                           LIMIT '.$L_AB.', '.$_config['ANZ_TOPIC']);
    $topics = '';
    $top_topics = '';
    while ($Daten = $_db->fetch_array($result)) {
        $onoff = status_topic($Daten['id'], $Daten['post_date'], $Daten['closed'], $Daten['posts'], $forum['hot'], $Daten['top'], $Daten['show_topic']);
        $Daten['post_time'] = pmf_time($Daten['post_date']);
        $Daten['post_date'] = pmf_date($Daten['post_date']);
        // Top || Announce ?
        switch ($Daten['top']) {
            case 0:
                $Daten['top'] = '';
                $top = false;
                break;
            case 1:
                $Daten['top'] = eval('return("'.$_style->get_lang('topic_prefix_top').'");');
                $top = true;
                break;
            default:
                $Daten['top'] = eval('return("'.$_style->get_lang('topic_prefix_announce').'");');
                $top = true;
                break;
        }
        // Umfrage ???
        if ($Daten['poll']) {
            $Daten['poll'] = eval('return("'.$_style->get_lang('topic_prefix_poll').'");');
        } else {
            $Daten['poll'] = '';
        }
        // Verschoben ?
        $Daten['moved'] = (!empty($Daten['old_board_id']) && $Daten['old_board_id'] == $_GET['id']) ? eval('return("'.$_style->get_lang('topic_prefix_moved').'");') : '';
        
        // Multipagew
        $multipage = ($_config['NAV_ANZ_TOPIC_LINE'] > 0) ? navi_topic_line($Daten['posts']+1, $_user['cfg']['posts'], 'topic.php?id='.$Daten['id'].'&amp;'.$_sess['url']) : '';

        // Top || Announce ?
        if (empty($top)) {
            $topics .= eval ('return ("'.$_style->get('board_topic_line').'");');
        } else {
            $top_topics .= eval ('return ("'.$_style->get('board_topic_line').'");');
        }
    }

#
#
### nur Kategorie --> keine Themen anzeigen
} else {
    $_style->del('board_topics');
}

eval ('echo "'.$_style->get('board').'";');
footer();
?>
Return current item: PhpMyForum