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

#
#
### Foren
$_boards = array();
$result = $_db->query('SELECT *
                       FROM `'.$_cfg['DB_PREFIX'].'board`
                       ORDER BY `parent_id` ASC,
                                `rang` ASC');
while ($board = $_db->fetch_array($result)) {
    $_boards[$board['parent_id']][$board['id']] = $board;
}
$_db->free_result($result);


/**
 * @return string
 * @param id int
 * @param depth int
 * @desc Admin - Foren-Liste
 */
function makeadminboardline($id, $depth=1) {
    global $_boards, $_config, $_style, $_db, $_cfg, $_sess;
    
    reset($_boards);
    $return = '';
    if (is_array($_boards[$id])) {
        foreach ($_boards[$id] AS $board_id => $board) {
            $cols = '';
            $rang = '';
            for ($n = 0; $n < $depth-1; $n++) {
                $cols .= eval ('return ("'.$_style->get('acp_board_line_col').'");');
            }
            for ($n = 1; $n <= count($_boards[$id]); $n++) {
                $rang .= '<option value="'.$n.'"';
                $rang .= ($n == $board['rang']) ? ' selected="selected"' : '';
                $rang .= '>'.$n.'</option>';
            }
            $return .= eval ('return ("'.$_style->get('acp_board_line').'");');
            
            ### "Kinder" Foren / Kategorien ?
            if ($board['childs']) {
                $return .= makeadminboardline($board_id, $depth+1);
            }
        }
    }
    return $return;
}



#
#
### Forum Liste (form)
if (!$_GET['action'] && !$_POST) {
    $board_lines = makeadminboardline(0,1);
    eval ('echo "'.$_style->get('acp_board').'";');



#
#
### Forum hinzufügen / bearbeiten
} elseif ($_GET['action'] == 'edit' || $_GET['action'] == 'add') {
    ### bearbeiten
    if ($_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
        // Forum
        $Daten = $_db->fetch_first('SELECT *
                                    FROM `'.$_cfg['DB_PREFIX'].'board`
                                    WHERE id = '.$_GET['id']);
        // Werte anpassen
        $Daten['name'] = htmlentities($Daten['name'], ENT_QUOTES);
        $Daten['info'] = htmlentities($Daten['info'], ENT_QUOTES);
        $Daten['prefix_list'] = htmlentities($Daten['prefix_list'], ENT_QUOTES);
        $Daten['redirect_url'] = htmlentities($Daten['redirect_url'], ENT_QUOTES);
        $Daten['redirect_target'] = htmlentities($Daten['redirect_target'], ENT_QUOTES);
        $is_board[$Daten['is_board']] = ' selected="selected"';
        $is_hidden[$Daten['is_hidden']] = $_style->cfg['template_choice'];
        $show_forum[$Daten['show_forum']] = ' selected="selected"';
        $count_posts[$Daten['count_posts']] = $_style->cfg['template_choice'];
        $mod_new_topic[$Daten['mod_new_topic']] = $_style->cfg['template_choice'];
        $sortfield[$Daten['sortfield']] = ' selected="selected"';
        $sortorder[$Daten['sortorder']] = ' selected="selected"';
        $sorttopics[$Daten['sorttopics']] = ' selected="selected"';
        $Daten['anz_topic'] = intval($Daten['anz_topic']);
        $Daten['anz_post'] = intval($Daten['anz_post']);
    }
    ### Übergeordnete Foren
    $forums = footer_list_boards(array(), 0, 0, $Daten['parent_id'], 0);
    # Kinder Foren löschen
    $childs = get_child_boards($_GET['id']);
    $childs[] = $_GET['id'];
    if (is_array($childs)) {
        foreach ($childs AS $val) {
            unset($forums[$val]);
        }
    }
    $Daten['forums'] = implode("\n", $forums);
    
    ### Styles
    $result = $_db->query('SELECT `id`, `name`
                           FROM `'.$_cfg['DB_PREFIX'].'style`
                           ORDER BY `name`');
    $Daten['styles'] = '';
    while ($style = $_db->fetch_array($result)) {
        $Daten['styles'] .= '<option value="'.$style['id'].'"';
        $Daten['styles'] .= ($Daten['style_id'] == $style['id']) ? ' selected="selected"' : '';
        $Daten['styles'] .= '>'.$style['name'].'</option>';
    }
    
    eval ('echo "'.$_style->get('acp_board_'.$_GET['action']).'";');



#
#
### Forum speichern
} elseif ($_GET['action'] == 'save') {
    
    $_POST['parent_id'] = intval($_POST['parent_id']);
    
    ### hinzufügen
    if (!$_POST['id']) {
        # max. Rang Abfragen
        $rang = $_db->num_rows( $_db->query('SELECT `id`
                                             FROM `'.$_cfg['DB_PREFIX'].'board`
                                             WHERE `parent_id` = '.$_POST['parent_id']))+1;
        
        # insert
        $_db->query('INSERT INTO `'.$_cfg['DB_PREFIX'].'board` (`name`,`info`,`rang`,`is_board`,`is_hidden`,`parent_id`,`show_forum`,`style_id`,`prefix_list`,`hot`,`count_posts`,`mod_new_topic`,`sortfield`,`sortorder`,`sorttopics`,`anz_topic`,`anz_post`,`redirect_url`,`redirect_target`)
                     VALUES (\''.gpc_addslashes($_POST['name']).'\',\''.gpc_addslashes($_POST['info']).'\','.intval($rang).','.intval($_POST['is_board']).','.intval($_POST['is_hidden']).','.intval($_POST['parent_id']).','.intval($_POST['show_forum']).',
                             '.intval($_POST['style_id']).',\''.gpc_addslashes($_POST['prefix_list']).'\','.intval($_POST['hot']).','.intval($_POST['count_posts']).','.intval($_POST['mod_new_topic']).',\''.gpc_addslashes($_POST['sortfield']).'\',
                             \''.gpc_addslashes($_POST['sortorder']).'\','.intval($_POST['sorttopics']).','.intval($_POST['anz_topic']).','.intval($_POST['anz_post']).',\''.gpc_addslashes($_POST['redirect_url']).'\',\''.gpc_addslashes($_POST['redirect_target']).'\')');
        
        # Eltern Forum Update
        if ($_POST['parent_id'] > 0) {
            $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board` SET `childs` = 1 WHERE `id` = '.$_POST['parent_id']);
        }
        
        
    ### bearbeiten
    } else {
        $_POST['id'] = intval($_POST['id']);
        
        # andere "Eltern" ?
        $old = $_db->fetch_first('SELECT `parent_id`
                                  FROM `'.$_cfg['DB_PREFIX'].'board`
                                  WHERE `id` = '.$_POST['id']);
        if ($old['parent_id'] != $_POST['parent_id']) {
            $childs = $_db->fetch_first('SELECT COUNT(*) AS `anz`
                                         FROM `'.$_cfg['DB_PREFIX'].'board`
                                         WHERE `parent_id` = '.intval($old['parent_id']).'
                                           AND `id` != '.$_POST['id']);
            // altes Eltern-Forum
            $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board`
                           SET `childs` = '.(($childs['anz'] > 0) ? 1 : 0).'
                           WHERE `id` = '.intval($old['parent_id']));
            // neues Eltern-Forum
            $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board`
                           SET `childs` = 1
                           WHERE `id` = '.intval($_POST['parent_id']));
        }
        
        # Update
        $_db->query('UPDATE `'.$_cfg['DB_PREFIX'].'board`
                     SET `name` = \''.gpc_addslashes($_POST['name']).'\',
                         `info` = \''.gpc_addslashes($_POST['info']).'\',
                         `is_board` = '.intval($_POST['is_board']).',
                         `is_hidden` = '.intval($_POST['is_hidden']).',
                         `parent_id` = '.intval($_POST['parent_id']).',
                         `show_forum` = '.intval($_POST['show_forum']).',
                         `style_id` = '.intval($_POST['style_id']).',
                         `prefix_list` = \''.gpc_addslashes($_POST['prefix_list']).'\',
                         `hot` = '.intval($_POST['hot']).',
                         `count_posts` = '.intval($_POST['count_posts']).',
                         `mod_new_topic` = '.intval($_POST['mod_new_topic']).',
                         `sortfield` = \''.gpc_addslashes($_POST['sortfield']).'\',
                         `sortorder` = \''.gpc_addslashes($_POST['sortorder']).'\',
                         `sorttopics` = '.intval($_POST['sorttopics']).',
                         `anz_topic` = '.intval($_POST['anz_topic']).',
                         `anz_post` = '.intval($_POST['anz_post']).',
                         `redirect_url` = \''.gpc_addslashes($_POST['redirect_url']).'\',
                         `redirect_target` = \''.gpc_addslashes($_POST['redirect_target']).'\'
                     WHERE `id` = '.$_POST['id']);
    }
    
    msg('error_acp_save', 'board.php?'.$_sess['url']);



#
#
### Forum löschen
} elseif ($_GET['action'] == 'del') {
    
    $_GET['id'] = intval($_GET['id']);
    $Daten = $_db->fetch_first('SELECT *
                                FROM `'.$_cfg['DB_PREFIX'].'board`
                                WHERE `id` = '.$_GET['id']);
    
    ### Formular anzeigen
    if (!$_GET['ok']) {
        eval ('echo "'.$_style->get('acp_board_del').'";');
        
        
    ### wirklich löschen
    } else {
        # Eltern Forum: Kinder anpassen
        $childs = $_db->fetch_first('SELECT COUNT(*) AS `anz`
                                     FROM `'.$_cfg['DB_PREFIX'].'board`
                                     WHERE `parent_id` = '.$Daten['parent_id'].'
                                       AND `id` != '.$Daten['id']);
        $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board`
                       SET `childs` = '.(($childs['anz'] > 0) ? 1 : 0).'
                       WHERE `id` = '.intval($Daten['parent_id']));
        
        # Foren einlesen & löschen
        $boards = get_child_boards($Daten['id']);
        $boards[] = $Daten['id'];
        $boards_implode = implode(',', $boards);
        $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'board`
                       WHERE `id` IN ('.$boards_implode.')');
        
        # Foren-Abo's löschen
        $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'board_abo`
                       WHERE `board_id` IN ('.$boards_implode.')');
        
        # Foren-Rechte löschen
        $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'group_value`
                       WHERE `board_id` IN ('.$boards_implode.')');
        
        # Moderatoren löschen
        $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'board_mod`
                       WHERE `board_id` IN ('.$boards_implode.')');
        
        # Topics einlesen
        $result = $_db->query('SELECT `id`
                               FROM `'.$_cfg['DB_PREFIX'].'topic`
                               WHERE `board_id` IN ('.$boards_implode.')');
        $topics = array();
        while ($d = $_db->fetch_array($result)) {
            $topics[] = $d['id'];
        }
        // Themen gefunden
        if (count($topics) > 0) {
            $topics_implode = implode(',', $topics);
            $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'topic`
                           WHERE `board_id` IN ('.$boards_implode.')');
            $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'topic`
                           SET `old_board_id` = 0
                           WHERE `board_id` IN ('.$boards_implode.')');
            $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'topic_abo`
                           WHERE `topic_id` IN ('.$topics_implode.')');
            
            # Attachments löschen
            $result = $_db->query('SELECT a.`id`
                                   FROM `'.$_cfg['DB_PREFIX'].'post` AS p
                                        LEFT JOIN `'.$_cfg['DB_PREFIX'].'attachment` AS a ON a.`post_id` = p.`id`
                                   WHERE p.`topic_id` IN ('.$topics_implode.')
                                     AND a.`id` IS NOT NULL');
            $files = array();
            while ($d = $_db->fetch_array($result)) {
                $files[] = $d['id'];
                @unlink($_cfg['MAIN'].'/attachments/'.$d['id']);
            }
            if (count($files) > 0) {
                $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'attachment`
                               WHERE `id` IN ('.implode(',', $files).')');
            }
            unset($files);
            // Beiträge löschen
            $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'post`
                           WHERE `topic_id` IN ('.$topics_implode.')');
            
            # Umfragen löschen
            $result = $_db->query('SELECT `id`
                                   FROM `'.$_cfg['DB_PREFIX'].'poll`
                                   WHERE `topic_id` IN ('.$topics_implode.')');
            $polls = array();
            while ($d = $_db->fetch_array($result)) {
                $polls[] = $d['id'];
            }
            // Umfragen-Optionen löschen
            if (count($polls) > 0) {
                $polls_implode = implode(',', $polls);
                $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'poll`
                               WHERE `id` IN ('.$polls_implode.')');
                
                $result = $_db->query('SELECT `id`
                                       FROM `'.$_cfg['DB_PREFIX'].'poll_option`
                                       WHERE `poll_id` IN ('.$polls_implode.')');
                $poll_options = array();
                while ($d = $_db->fetch_array($result)) {
                    $poll_options[] = $d['id'];
                }
                // Votes
                if (count($poll_options) > 0) {
                    $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'poll_option`
                                   WHERE `poll_id` IN ('.$polls_implode.')');
                    
                    $_db->u_query('DELETE FROM `'.$_cfg['DB_PREFIX'].'poll_vote`
                                   WHERE `option_id` IN ('.implode(',', $poll_options).')');
                }
            }

        }
        
        msg('error_acp_del', 'board.php?'.$_sess['url']);
    }



#
#
### Reihenfolge speichern
} elseif ($_POST['action'] == 'rang') {
    foreach ($_POST['rang'] AS $id => $rang) {
        $_db->u_query('UPDATE `'.$_cfg['DB_PREFIX'].'board` SET `rang` = '.intval($rang).' WHERE `id` = '.intval($id));
    }
    msg('error_acp_save', 'board.php?'.$_sess['url']);
}
?>
Return current item: PhpMyForum