admin_forum_manager.php

来自「php 开发的内容管理系统」· PHP 代码 · 共 524 行 · 第 1/2 页

PHP
524
字号
<?php
// $Id: admin_forum_manager.php,v 1.3 2005/10/19 17:20:32 phppp Exp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System                      //
// Copyright (c) 2000 XOOPS.org                           //
// <http://www.xoops.org/>                             //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify     //
// it under the terms of the GNU General Public License as published by     //
// the Free Software Foundation; either version 2 of the License, or        //
// (at your option) any later version.                                      //
// //
// You may not change or alter any portion of this comment or credits       //
// of supporting developers from this source code or any supporting         //
// source code which is considered copyrighted (c) material of the          //
// original comment or credit authors.                                      //
// //
// This program is distributed in the hope that it will be useful,          //
// but WITHOUT ANY WARRANTY; without even the implied warranty of           //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
// GNU General Public License for more details.                             //
// //
// You should have received a copy of the GNU General Public License        //
// along with this program; if not, write to the Free Software              //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
// ------------------------------------------------------------------------ //
// Author: Kazumi Ono (AKA onokazu)                                          //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project                                                //
// ------------------------------------------------------------------------- //
include 'admin_header.php';
include XOOPS_ROOT_PATH . "/class/xoopstree.php";
include_once XOOPS_ROOT_PATH . "/class/pagenav.php";

$op = '';
$confirm = '';

if (isset($_GET['op'])) $op = $_GET['op'];
if (isset($_POST['op'])) $op = $_POST['op'];
if (isset($_POST['default'])) $op = 'default';
if (isset($_GET['forum'])) $forum = $_GET['forum'];
if (isset($_POST['forum'])) $forum = $_POST['forum'];

$forum_handler =& xoops_getmodulehandler('forum', 'newbb');
/**
 * newForum()
 *
 * @param integer $catid
 * @return
 */
function newForum($parent_forum = 0)
{
    editForum(null, $parent_forum);
}

/**
 * editForum()
 *
 * @param integer $catid
 * @return
 */
function editForum($ff = null, $parent_forum = 0)
{
    global $myts, $xoopsDB, $xoopsModule;;

    $forum_handler = &xoops_getmodulehandler('forum', 'newbb');
    if ($ff == null) {
        $ff =& $forum_handler->create();
        $new = true;
        $forum = 0;
    } else {
        $forum = $ff->getVar('forum_id');
        $new = false;
    }
    if ($parent_forum > 0) {
        $pf =& $forum_handler->get($parent_forum);
    }

    $mytree = new XoopsTree($xoopsDB->prefix("bb_categories"), "cat_id", "0");

	include_once XOOPS_ROOT_PATH."/modules/".$xoopsModule->getVar("dirname")."/class/xoopsformloader.php";
    if ($forum) {
        $sform = new XoopsThemeForm(_AM_NEWBB_EDITTHISFORUM . " " . $ff->getVar('forum_name'), "op", xoops_getenv('PHP_SELF'));
    } else {
        $sform = new XoopsThemeForm(_AM_NEWBB_CREATENEWFORUM, "op", xoops_getenv('PHP_SELF'));

        $ff->setVar('parent_forum', $parent_forum);
        $ff->setVar('forum_order', 0);
        $ff->setVar('forum_name', '');
        $ff->setVar('forum_desc', '');
        $ff->setVar('forum_moderator', array(1));

        $ff->setVar('forum_type', 0);
        $ff->setVar('allow_html', 1);
        $ff->setVar('allow_sig', 1);
        $ff->setVar('allow_polls', 1);
        $ff->setVar('allow_subject_prefix', 1);
        $ff->setVar('hot_threshold', 10);
        //$ff->setVar('allow_attachments', 1);
        $ff->setVar('attach_maxkb', 1000);
        $ff->setVar('attach_ext', 'zip|gif|jpg');
    }

    $sform->addElement(new XoopsFormText(_AM_NEWBB_FORUMNAME, 'forum_name', 50, 80, $ff->getVar('forum_name', 'E')), true);
    $sform->addElement(new XoopsFormDhtmlTextArea(_AM_NEWBB_FORUMDESCRIPTION, 'forum_desc', $ff->getVar('forum_desc', 'E'), 10, 60), false);

    $sform->addElement(new XoopsFormHidden('parent_forum', $ff->getVar('parent_forum')));
    if ($parent_forum == 0) {
        ob_start();
        if ($new) {
        	$mytree->makeMySelBox("cat_title", "cat_id", @$_GET['cat_id']);
        } else {
        	$mytree->makeMySelBox("cat_title", "cat_id", $ff->getVar('cat_id'));
        }
        $sform->addElement(new XoopsFormLabel(_AM_NEWBB_CATEGORY, ob_get_contents()));
        ob_end_clean();
    } else {
        $sform->addElement(new XoopsFormHidden('cat_id', $pf->getVar('cat_id')));
    }

    $sform->addElement(new XoopsFormText(_AM_NEWBB_SET_FORUMORDER, 'forum_order', 5, 10, $ff->getVar('forum_order')), false);
    $status_select = new XoopsFormSelect(_AM_NEWBB_STATE, "forum_type", $ff->getVar('forum_type'));
    $status_select->addOptionArray(array('0' => _AM_NEWBB_ACTIVE, '1' => _AM_NEWBB_INACTIVE));
    $sform->addElement($status_select);

    $allowhtml_radio = new XoopsFormRadioYN(_AM_NEWBB_ALLOWHTML, 'allow_html', $ff->getVar('allow_html'), '' . _YES . '', ' ' . _NO . '');
    $sform->addElement($allowhtml_radio);

    $allowsig_radio = new XoopsFormRadioYN(_AM_NEWBB_ALLOWSIGNATURES, 'allow_sig', $ff->getVar('allow_sig'), '' . _YES . '', ' ' . _NO . '');
    $sform->addElement($allowsig_radio);

    $allowpolls_radio = new XoopsFormRadioYN(_AM_NEWBB_ALLOWPOLLS, 'allow_polls', $ff->getVar('allow_polls'), '' . _YES . '', ' ' . _NO . '');
    $sform->addElement($allowpolls_radio);

    $allowprefix_radio = new XoopsFormRadioYN(_AM_NEWBB_ALLOW_SUBJECT_PREFIX, 'allow_subject_prefix', $ff->getVar('allow_subject_prefix'), '' . _YES . '', ' ' . _NO . '');
    $sform->addElement($allowprefix_radio);

    $sform->addElement(new XoopsFormText(_AM_NEWBB_HOTTOPICTHRESHOLD, 'hot_threshold', 5, 10, $ff->getVar('hot_threshold')), true);

    /*
    $allowattach_radio = new XoopsFormRadioYN(_AM_NEWBB_ALLOW_ATTACHMENTS, 'allow_attachments', $ff->getVar('allow_attachments'), '' . _YES . '', ' ' . _NO . '');
    $sform->addElement($allowattach_radio);
    */
    $sform->addElement(new XoopsFormText(_AM_NEWBB_ATTACHMENT_SIZE, 'attach_maxkb', 5, 10, $ff->getVar('attach_maxkb')), true);
    $sform->addElement(new XoopsFormText(_AM_NEWBB_ALLOWED_EXTENSIONS, 'attach_ext', 50, 512, $ff->getVar('attach_ext')), true);
   	$sform->addElement(new XoopsFormSelectUser(_AM_NEWBB_MODERATOR, 'forum_moderator', false, $ff->getVar("forum_moderator"), 5, true));

    $perm_tray = new XoopsFormElementTray(_AM_NEWBB_PERMISSIONS_TO_THIS_FORUM, '');
	$perm_checkbox = new XoopsFormCheckBox('', 'perm_template', $ff->isNew());
	$perm_checkbox->addOption(1, _AM_NEWBB_PERM_TEMPLATEAPP);
	$perm_tray->addElement($perm_checkbox);
	$perm_tray->addElement(new XoopsFormLabel('', '<a href="admin_permissions.php?action=template" target="_blank">'._AM_NEWBB_PERM_TEMPLATE.'</a>'));
    $sform->addElement($perm_tray);
   	
    $sform->addElement(new XoopsFormHidden('forum', $forum));
    $sform->addElement(new XoopsFormHidden('op', "save"));

    $button_tray = new XoopsFormElementTray('', '');
    $button_tray->addElement(new XoopsFormButton('', '', _SUBMIT, 'submit'));

    $button_tray->addElement(new XoopsFormButton('', '', _AM_NEWBB_CLEAR, 'reset'));

    $butt_cancel = new XoopsFormButton('', '', _CANCEL, 'button');
    $butt_cancel->setExtra('onclick="history.go(-1)"');
    $button_tray->addElement($butt_cancel);

    $sform->addElement($button_tray);
    $sform->display();
}
xoops_cp_header();
switch ($op) {
    case 'moveforum':
        loadModuleAdminMenu(2, "");

        if(!empty($_POST['dest'])) {
            if (!empty($_GET['forum'])) $forum_id = intval($_GET['forum']);
            if (!empty($_POST['forum'])) $forum_id = intval($_POST['forum']);

            $dest = $_POST['dest'];
            if($dest{0}=="f"){
	            $pid = substr($dest, 1);
            	$forum = &$forum_handler->get(intval($pid));
            	$cid = $forum->getVar("cat_id");
            	unset($forum);
            }else{
	            $cid = intval($dest);
	            $pid = 0;
            }
            $bMoved = 0;
            $errString = '';
            $value = "cat_id=" . $cid.", parent_forum=" . $pid;
            $sql_move = "UPDATE " . $xoopsDB->prefix('bb_forums') . " SET " . $value . " WHERE forum_id=$forum_id";
            if ($result = $xoopsDB->queryF($sql_move)){
                $bMoved = 1;
            	$sql = "UPDATE " . $xoopsDB->prefix('bb_forums') . " SET parent_forum = 0 WHERE parent_forum=$forum_id";
            	$result = $xoopsDB->queryF($sql);
            }

            if (!$bMoved) {
                redirect_header('./admin_forum_manager.php?op=manage', 2, _AM_NEWBB_MSG_ERR_FORUM_MOVED);
            } else {
                redirect_header('./admin_forum_manager.php?op=manage', 2, _AM_NEWBB_MSG_FORUM_MOVED);
            }
            exit();
        } else {
            //loadModuleAdminMenu(2, "");

            if (!empty($_POST['forum'])) $forum_id = intval($_POST['forum']);
            if (!empty($_GET['forum'])) $forum_id = intval($_GET['forum']);
            //$forum = &$forum_handler->get($forum_id);
           
	        $box = '<select name="dest">';
            $box .= '<option value=0 selected>' . _AM_NEWBB_SELECT . '</option>';
	
			$category_handler =& xoops_getmodulehandler('category', 'newbb');
		    $categories = $category_handler->getAllCats('', true);
		    $forums = $forum_handler->getForumsByCategory(array_keys($categories), '', false);
		
			if(count($categories)>0 && count($forums)>0){
				foreach(array_keys($forums) as $key){
		            $box .= "<option value=".$key."'>".$categories[$key]->getVar('cat_title')."</option>";
		            foreach ($forums[$key] as $forumid=>$_forum) {
		                $box .= "<option value='f".$forumid."'>-- ".$_forum['title']."</option>";
		            }
				}
		    }
	    	unset($forums, $categories);
            $box .= '</select>';

            echo '<form action="./admin_forum_manager.php" method="post" name="forummove" id="forummove">';
            echo '<input type="hidden" name="op" value="moveforum" />';
            echo '<input type="hidden" name="forum" value=' . $forum_id . ' />';
            echo '<table border="0" cellpadding="1" cellspacing="0" align="center" valign="top" width="95%"><tr>';
            echo '<td class="bg2" align="center"><strong>' . _AM_NEWBB_MOVETHISFORUM . '</strong></td>';
            echo '</tr>';
            echo '<tr><td class="bg1" align="center">' . $box . '</td></tr>';
            echo '<tr><td align="center"><input type="submit" name="save" value=' . _GO . ' class="button" /></td></tr>';
            echo '</table></form>';
        }
        break;

    case 'mergeforum':
        loadModuleAdminMenu(2, "");

        if (!empty($_POST['dest_forum'])) {
            if (isset($_GET['forum'])) $forum_id = intval($_GET['forum']);
            if (isset($_POST['forum'])) $forum_id = intval($_POST['forum']);

            $sql = "UPDATE " . $xoopsDB->prefix('bb_posts') . " SET forum_id=" . $_POST['dest_forum'] . " WHERE forum_id=$forum";
            $result = $xoopsDB->queryF($sql);
            $sql = "UPDATE " . $xoopsDB->prefix('bb_topics') . " SET forum_id=" . $_POST['dest_forum'] . " WHERE forum_id=$forum";
            $result = $xoopsDB->queryF($sql);
            $sql = "UPDATE " . $xoopsDB->prefix('bb_forums') . " SET parent_forum = 0 WHERE parent_forum=$forum_id";
            $result = $xoopsDB->queryF($sql);

            $sql = "SELECT COUNT(*) AS count FROM " . $xoopsDB->prefix('bb_posts') . " WHERE WHERE forum_id=$forum_id";
            $result = $xoopsDB->query($sql);
            list($post_count) = $xoopsDB->fetchArray($result);
            $sql = "SELECT COUNT(*) AS count FROM " . $xoopsDB->prefix('bb_topics') . " WHERE WHERE forum_id=$forum_id";
            $result = $xoopsDB->query($sql);
            list($topic_count) = $xoopsDB->fetchArray($result);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?