Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

admin_forums.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 30.18 KiB


 0001  <?php
 0002  /***************************************************************************
 0003   *                             admin_forums.php
 0004   *                            -------------------
 0005   *   begin                : Thursday, Jul 12, 2001
 0006   *   copyright            : (C) 2001 The phpBB Group
 0007   *   email                : support@phpbb.com
 0008   *
 0009   *   $Id$
 0010   *
 0011   ***************************************************************************/
 0012   
 0013  /***************************************************************************
 0014   *
 0015   *   This program is free software; you can redistribute it and/or modify
 0016   *   it under the terms of the GNU General Public License as published by
 0017   *   the Free Software Foundation; either version 2 of the License, or
 0018   *   (at your option) any later version.
 0019   *
 0020   ***************************************************************************/
 0021   
 0022  define('IN_PHPBB', 1);
 0023   
 0024  if( !empty($setmodules) )
 0025  {
 0026      $file = basename(__FILE__);
 0027      $module['Forums']['Manage'] = $file;
 0028      return;
 0029  }
 0030   
 0031  //
 0032  // Load default header
 0033  //
 0034  $phpbb_root_path = "./../";
 0035  require($phpbb_root_path . 'extension.inc');
 0036  require('./pagestart.' . $phpEx);
 0037  include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
 0038   
 0039  $forum_auth_ary = array(
 0040      "auth_view" => AUTH_ALL, 
 0041      "auth_read" => AUTH_ALL, 
 0042      "auth_post" => AUTH_REG, 
 0043      "auth_reply" => AUTH_REG, 
 0044      "auth_edit" => AUTH_REG, 
 0045      "auth_delete" => AUTH_REG, 
 0046      "auth_sticky" => AUTH_MOD, 
 0047      "auth_announce" => AUTH_MOD, 
 0048      "auth_vote" => AUTH_REG, 
 0049      "auth_pollcreate" => AUTH_REG
 0050  );
 0051   
 0052  //
 0053  // Mode setting
 0054  //
 0055  if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
 0056  {
 0057      $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
 0058      $mode = htmlspecialchars($mode);
 0059  }
 0060  else
 0061  {
 0062      $mode = "";
 0063  }
 0064   
 0065  // ------------------
 0066  // Begin function block
 0067  //
 0068  function get_info($mode, $id)
 0069  {
 0070      global $db;
 0071   
 0072      switch($mode)
 0073      {
 0074          case 'category':
 0075              $table = CATEGORIES_TABLE;
 0076              $idfield = 'cat_id';
 0077              $namefield = 'cat_title';
 0078              break;
 0079   
 0080          case 'forum':
 0081              $table = FORUMS_TABLE;
 0082              $idfield = 'forum_id';
 0083              $namefield = 'forum_name';
 0084              break;
 0085   
 0086          default:
 0087              message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
 0088              break;
 0089      }
 0090      $sql = "SELECT count(*) as total
 0091          FROM $table";
 0092      if( !$result = $db->sql_query($sql) )
 0093      {
 0094          message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
 0095      }
 0096      $count = $db->sql_fetchrow($result);
 0097      $count = $count['total'];
 0098   
 0099      $sql = "SELECT *
 0100          FROM $table
 0101          WHERE $idfield = $id"; 
 0102   
 0103      if( !$result = $db->sql_query($sql) )
 0104      {
 0105          message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
 0106      }
 0107   
 0108      if( $db->sql_numrows($result) != 1 )
 0109      {
 0110          message_die(GENERAL_ERROR, "Forum/Category doesn't exist or multiple forums/categories with ID $id", "", __LINE__, __FILE__);
 0111      }
 0112   
 0113      $return = $db->sql_fetchrow($result);
 0114      $return['number'] = $count;
 0115      return $return;
 0116  }
 0117   
 0118  function get_list($mode, $id, $select)
 0119  {
 0120      global $db;
 0121   
 0122      switch($mode)
 0123      {
 0124          case 'category':
 0125              $table = CATEGORIES_TABLE;
 0126              $idfield = 'cat_id';
 0127              $namefield = 'cat_title';
 0128              break;
 0129   
 0130          case 'forum':
 0131              $table = FORUMS_TABLE;
 0132              $idfield = 'forum_id';
 0133              $namefield = 'forum_name';
 0134              break;
 0135   
 0136          default:
 0137              message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
 0138              break;
 0139      }
 0140   
 0141      $sql = "SELECT *
 0142          FROM $table";
 0143      if( $select == 0 )
 0144      {
 0145          $sql .= " WHERE $idfield <> $id";
 0146      }
 0147   
 0148      if( !$result = $db->sql_query($sql) )
 0149      {
 0150          message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
 0151      }
 0152   
 0153      $cat_list = "";
 0154   
 0155      while( $row = $db->sql_fetchrow($result) )
 0156      {
 0157          $s = "";
 0158          if ($row[$idfield] == $id)
 0159          {
 0160              $s = " selected=\"selected\"";
 0161          }
 0162          $catlist .= "<option value=\"$row[$idfield]\"$s>" . $row[$namefield] . "</option>\n";
 0163      }
 0164   
 0165      return($catlist);
 0166  }
 0167   
 0168  function renumber_order($mode, $cat = 0)
 0169  {
 0170      global $db;
 0171   
 0172      switch($mode)
 0173      {
 0174          case 'category':
 0175              $table = CATEGORIES_TABLE;
 0176              $idfield = 'cat_id';
 0177              $orderfield = 'cat_order';
 0178              $cat = 0;
 0179              break;
 0180   
 0181          case 'forum':
 0182              $table = FORUMS_TABLE;
 0183              $idfield = 'forum_id';
 0184              $orderfield = 'forum_order';
 0185              $catfield = 'cat_id';
 0186              break;
 0187   
 0188          default:
 0189              message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
 0190              break;
 0191      }
 0192   
 0193      $sql = "SELECT * FROM $table";
 0194      if( $cat != 0)
 0195      {
 0196          $sql .= " WHERE $catfield = $cat";
 0197      }
 0198      $sql .= " ORDER BY $orderfield ASC";
 0199   
 0200   
 0201      if( !$result = $db->sql_query($sql) )
 0202      {
 0203          message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
 0204      }
 0205   
 0206      $i = 10;
 0207      $inc = 10;
 0208   
 0209      while( $row = $db->sql_fetchrow($result) )
 0210      {
 0211          $sql = "UPDATE $table
 0212              SET $orderfield = $i
 0213              WHERE $idfield = " . $row[$idfield];
 0214          if( !$db->sql_query($sql) )
 0215          {
 0216              message_die(GENERAL_ERROR, "Couldn't update order fields", "", __LINE__, __FILE__, $sql);
 0217          }
 0218          $i += 10;
 0219      }
 0220   
 0221  }
 0222  //
 0223  // End function block
 0224  // ------------------
 0225   
 0226  //
 0227  // Begin program proper
 0228  //
 0229  if( isset($HTTP_POST_VARS['addforum']) || isset($HTTP_POST_VARS['addcategory']) )
 0230  {
 0231      $mode = ( isset($HTTP_POST_VARS['addforum']) ) ? "addforum" : "addcat";
 0232   
 0233      if( $mode == "addforum" )
 0234      {
 0235          list($cat_id) = each($HTTP_POST_VARS['addforum']);
 0236          $cat_id = intval($cat_id);
 0237          // 
 0238          // stripslashes needs to be run on this because slashes are added when the forum name is posted
 0239          //
 0240          $forumname = stripslashes($HTTP_POST_VARS['forumname'][$cat_id]);
 0241      }
 0242  }
 0243   
 0244  if( !empty($mode) ) 
 0245  {
 0246      switch($mode)
 0247      {
 0248          case 'addforum':
 0249          case 'editforum':
 0250              //
 0251              // Show form to create/modify a forum
 0252              //
 0253              if ($mode == 'editforum')
 0254              {
 0255                  // $newmode determines if we are going to INSERT or UPDATE after posting?
 0256   
 0257                  $l_title = $lang['Edit_forum'];
 0258                  $newmode = 'modforum';
 0259                  $buttonvalue = $lang['Update'];
 0260   
 0261                  $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 0262   
 0263                  $row = get_info('forum', $forum_id);
 0264   
 0265                  $cat_id = $row['cat_id'];
 0266                  $forumname = $row['forum_name'];
 0267                  $forumdesc = $row['forum_desc'];
 0268                  $forumstatus = $row['forum_status'];
 0269   
 0270                  //
 0271                  // start forum prune stuff.
 0272                  //
 0273                  if( $row['prune_enable'] )
 0274                  {
 0275                      $prune_enabled = "checked=\"checked\"";
 0276                      $sql = "SELECT *
 0277                             FROM " . PRUNE_TABLE . "
 0278                             WHERE forum_id = $forum_id";
 0279                      if(!$pr_result = $db->sql_query($sql))
 0280                      {
 0281                           message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
 0282                      }
 0283   
 0284                      $pr_row = $db->sql_fetchrow($pr_result);
 0285                  }
 0286                  else
 0287                  {
 0288                      $prune_enabled = '';
 0289                  }
 0290              }
 0291              else
 0292              {
 0293                  $l_title = $lang['Create_forum'];
 0294                  $newmode = 'createforum';
 0295                  $buttonvalue = $lang['Create_forum'];
 0296   
 0297                  $forumdesc = '';
 0298                  $forumstatus = FORUM_UNLOCKED;
 0299                  $forum_id = ''; 
 0300                  $prune_enabled = '';
 0301              }
 0302   
 0303              $catlist = get_list('category', $cat_id, TRUE);
 0304   
 0305              $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = "selected=\"selected\"" : $forumunlocked = "selected=\"selected\"";
 0306              
 0307              // These two options ($lang['Status_unlocked'] and $lang['Status_locked']) seem to be missing from
 0308              // the language files.
 0309              $lang['Status_unlocked'] = isset($lang['Status_unlocked']) ? $lang['Status_unlocked'] : 'Unlocked';
 0310              $lang['Status_locked'] = isset($lang['Status_locked']) ? $lang['Status_locked'] : 'Locked';
 0311              
 0312              $statuslist = "<option value=\"" . FORUM_UNLOCKED . "\" $forumunlocked>" . $lang['Status_unlocked'] . "</option>\n";
 0313              $statuslist .= "<option value=\"" . FORUM_LOCKED . "\" $forumlocked>" . $lang['Status_locked'] . "</option>\n"; 
 0314   
 0315              $template->set_filenames(array(
 0316                  "body" => "admin/forum_edit_body.tpl")
 0317              );
 0318   
 0319              $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode .'" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
 0320   
 0321              $template->assign_vars(array(
 0322                  'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
 0323                  'S_HIDDEN_FIELDS' => $s_hidden_fields,
 0324                  'S_SUBMIT_VALUE' => $buttonvalue, 
 0325                  'S_CAT_LIST' => $catlist,
 0326                  'S_STATUS_LIST' => $statuslist,
 0327                  'S_PRUNE_ENABLED' => $prune_enabled,
 0328   
 0329                  'L_FORUM_TITLE' => $l_title, 
 0330                  'L_FORUM_EXPLAIN' => $lang['Forum_edit_delete_explain'], 
 0331                  'L_FORUM_SETTINGS' => $lang['Forum_settings'], 
 0332                  'L_FORUM_NAME' => $lang['Forum_name'], 
 0333                  'L_CATEGORY' => $lang['Category'], 
 0334                  'L_FORUM_DESCRIPTION' => $lang['Forum_desc'],
 0335                  'L_FORUM_STATUS' => $lang['Forum_status'],
 0336                  'L_AUTO_PRUNE' => $lang['Forum_pruning'],
 0337                  'L_ENABLED' => $lang['Enabled'],
 0338                  'L_PRUNE_DAYS' => $lang['prune_days'],
 0339                  'L_PRUNE_FREQ' => $lang['prune_freq'],
 0340                  'L_DAYS' => $lang['Days'],
 0341   
 0342                  'PRUNE_DAYS' => ( isset($pr_row['prune_days']) ) ? $pr_row['prune_days'] : 7,
 0343                  'PRUNE_FREQ' => ( isset($pr_row['prune_freq']) ) ? $pr_row['prune_freq'] : 1,
 0344                  'FORUM_NAME' => $forumname,
 0345                  'DESCRIPTION' => $forumdesc)
 0346              );
 0347              $template->pparse("body");
 0348              break;
 0349   
 0350          case 'createforum':
 0351              //
 0352              // Create a forum in the DB
 0353              //
 0354              if( trim($HTTP_POST_VARS['forumname']) == "" )
 0355              {
 0356                  message_die(GENERAL_ERROR, "Can't create a forum without a name");
 0357              }
 0358   
 0359              $sql = "SELECT MAX(forum_order) AS max_order
 0360                  FROM " . FORUMS_TABLE . "
 0361                  WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
 0362              if( !$result = $db->sql_query($sql) )
 0363              {
 0364                  message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
 0365              }
 0366              $row = $db->sql_fetchrow($result);
 0367   
 0368              $max_order = $row['max_order'];
 0369              $next_order = $max_order + 10;
 0370              
 0371              $sql = "SELECT MAX(forum_id) AS max_id
 0372                  FROM " . FORUMS_TABLE;
 0373              if( !$result = $db->sql_query($sql) )
 0374              {
 0375                  message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
 0376              }
 0377              $row = $db->sql_fetchrow($result);
 0378   
 0379              $max_id = $row['max_id'];
 0380              $next_id = $max_id + 1;
 0381   
 0382              //
 0383              // Default permissions of public :: 
 0384              //
 0385              $field_sql = "";
 0386              $value_sql = "";
 0387              while( list($field, $value) = each($forum_auth_ary) )
 0388              {
 0389                  $field_sql .= ", $field";
 0390                  $value_sql .= ", $value";
 0391   
 0392              }
 0393   
 0394              // There is no problem having duplicate forum names so we won't check for it.
 0395              $sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ")
 0396                  VALUES ('" . $next_id . "', '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', $next_order, " . intval($HTTP_POST_VARS['forumstatus']) . ", " . intval($HTTP_POST_VARS['prune_enable']) . $value_sql . ")";
 0397              if( !$result = $db->sql_query($sql) )
 0398              {
 0399                  message_die(GENERAL_ERROR, "Couldn't insert row in forums table", "", __LINE__, __FILE__, $sql);
 0400              }
 0401   
 0402              if( $HTTP_POST_VARS['prune_enable'] )
 0403              {
 0404   
 0405                  if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "")
 0406                  {
 0407                      message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
 0408                  }
 0409   
 0410                  $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
 0411                      VALUES('" . $next_id . "', " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
 0412                  if( !$result = $db->sql_query($sql) )
 0413                  {
 0414                      message_die(GENERAL_ERROR, "Couldn't insert row in prune table", "", __LINE__, __FILE__, $sql);
 0415                  }
 0416              }
 0417   
 0418              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0419   
 0420              message_die(GENERAL_MESSAGE, $message);
 0421   
 0422              break;
 0423   
 0424          case 'modforum':
 0425              // Modify a forum in the DB
 0426              if( isset($HTTP_POST_VARS['prune_enable']))
 0427              {
 0428                  if( $HTTP_POST_VARS['prune_enable'] != 1 )
 0429                  {
 0430                      $HTTP_POST_VARS['prune_enable'] = 0;
 0431                  }
 0432              }
 0433   
 0434              $sql = "UPDATE " . FORUMS_TABLE . "
 0435                  SET forum_name = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumname']) . "', cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]) . ", forum_desc = '" . str_replace("\'", "''", $HTTP_POST_VARS['forumdesc']) . "', forum_status = " . intval($HTTP_POST_VARS['forumstatus']) . ", prune_enable = " . intval($HTTP_POST_VARS['prune_enable']) . "
 0436                  WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 0437              if( !$result = $db->sql_query($sql) )
 0438              {
 0439                  message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
 0440              }
 0441   
 0442              if( $HTTP_POST_VARS['prune_enable'] == 1 )
 0443              {
 0444                  if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "" )
 0445                  {
 0446                      message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
 0447                  }
 0448   
 0449                  $sql = "SELECT *
 0450                      FROM " . PRUNE_TABLE . "
 0451                      WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 0452                  if( !$result = $db->sql_query($sql) )
 0453                  {
 0454                      message_die(GENERAL_ERROR, "Couldn't get forum Prune Information","",__LINE__, __FILE__, $sql);
 0455                  }
 0456   
 0457                  if( $db->sql_numrows($result) > 0 )
 0458                  {
 0459                      $sql = "UPDATE " . PRUNE_TABLE . "
 0460                          SET    prune_days = " . intval($HTTP_POST_VARS['prune_days']) . ",    prune_freq = " . intval($HTTP_POST_VARS['prune_freq']) . "
 0461                           WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 0462                  }
 0463                  else
 0464                  {
 0465                      $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
 0466                          VALUES(" . intval($HTTP_POST_VARS[POST_FORUM_URL]) . ", " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
 0467                  }
 0468   
 0469                  if( !$result = $db->sql_query($sql) )
 0470                  {
 0471                      message_die(GENERAL_ERROR, "Couldn't Update Forum Prune Information","",__LINE__, __FILE__, $sql);
 0472                  }
 0473              }
 0474   
 0475              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0476   
 0477              message_die(GENERAL_MESSAGE, $message);
 0478   
 0479              break;
 0480              
 0481          case 'addcat':
 0482              // Create a category in the DB
 0483              if( trim($HTTP_POST_VARS['categoryname']) == '')
 0484              {
 0485                  message_die(GENERAL_ERROR, "Can't create a category without a name");
 0486              }
 0487   
 0488              $sql = "SELECT MAX(cat_order) AS max_order
 0489                  FROM " . CATEGORIES_TABLE;
 0490              if( !$result = $db->sql_query($sql) )
 0491              {
 0492                  message_die(GENERAL_ERROR, "Couldn't get order number from categories table", "", __LINE__, __FILE__, $sql);
 0493              }
 0494              $row = $db->sql_fetchrow($result);
 0495   
 0496              $max_order = $row['max_order'];
 0497              $next_order = $max_order + 10;
 0498   
 0499              //
 0500              // There is no problem having duplicate forum names so we won't check for it.
 0501              //
 0502              $sql = "INSERT INTO " . CATEGORIES_TABLE . " (cat_title, cat_order)
 0503                  VALUES ('" . str_replace("\'", "''", $HTTP_POST_VARS['categoryname']) . "', $next_order)";
 0504              if( !$result = $db->sql_query($sql) )
 0505              {
 0506                  message_die(GENERAL_ERROR, "Couldn't insert row in categories table", "", __LINE__, __FILE__, $sql);
 0507              }
 0508   
 0509              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0510   
 0511              message_die(GENERAL_MESSAGE, $message);
 0512   
 0513              break;
 0514              
 0515          case 'editcat':
 0516              //
 0517              // Show form to edit a category
 0518              //
 0519              $newmode = 'modcat';
 0520              $buttonvalue = $lang['Update'];
 0521   
 0522              $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 0523   
 0524              $row = get_info('category', $cat_id);
 0525              $cat_title = $row['cat_title'];
 0526   
 0527              $template->set_filenames(array(
 0528                  "body" => "admin/category_edit_body.tpl")
 0529              );
 0530   
 0531              $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="' . POST_CAT_URL . '" value="' . $cat_id . '" />';
 0532   
 0533              $template->assign_vars(array(
 0534                  'CAT_TITLE' => $cat_title,
 0535   
 0536                  'L_EDIT_CATEGORY' => $lang['Edit_Category'], 
 0537                  'L_EDIT_CATEGORY_EXPLAIN' => $lang['Edit_Category_explain'], 
 0538                  'L_CATEGORY' => $lang['Category'], 
 0539   
 0540                  'S_HIDDEN_FIELDS' => $s_hidden_fields, 
 0541                  'S_SUBMIT_VALUE' => $buttonvalue, 
 0542                  'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"))
 0543              );
 0544   
 0545              $template->pparse("body");
 0546              break;
 0547   
 0548          case 'modcat':
 0549              // Modify a category in the DB
 0550              $sql = "UPDATE " . CATEGORIES_TABLE . "
 0551                  SET cat_title = '" . str_replace("\'", "''", $HTTP_POST_VARS['cat_title']) . "'
 0552                  WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
 0553              if( !$result = $db->sql_query($sql) )
 0554              {
 0555                  message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
 0556              }
 0557   
 0558              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0559   
 0560              message_die(GENERAL_MESSAGE, $message);
 0561   
 0562              break;
 0563              
 0564          case 'deleteforum':
 0565              // Show form to delete a forum
 0566              $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 0567   
 0568              $select_to = '<select name="to_id">';
 0569              $select_to .= "<option value=\"-1\"$s>" . $lang['Delete_all_posts'] . "</option>\n";
 0570              $select_to .= get_list('forum', $forum_id, 0);
 0571              $select_to .= '</select>';
 0572   
 0573              $buttonvalue = $lang['Move_and_Delete'];
 0574   
 0575              $newmode = 'movedelforum';
 0576   
 0577              $foruminfo = get_info('forum', $forum_id);
 0578              $name = $foruminfo['forum_name'];
 0579   
 0580              $template->set_filenames(array(
 0581                  "body" => "admin/forum_delete_body.tpl")
 0582              );
 0583   
 0584              $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $forum_id . '" />';
 0585   
 0586              $template->assign_vars(array(
 0587                  'NAME' => $name, 
 0588   
 0589                  'L_FORUM_DELETE' => $lang['Forum_delete'], 
 0590                  'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'], 
 0591                  'L_MOVE_CONTENTS' => $lang['Move_contents'], 
 0592                  'L_FORUM_NAME' => $lang['Forum_name'], 
 0593   
 0594                  "S_HIDDEN_FIELDS" => $s_hidden_fields,
 0595                  'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"), 
 0596                  'S_SELECT_TO' => $select_to,
 0597                  'S_SUBMIT_VALUE' => $buttonvalue)
 0598              );
 0599   
 0600              $template->pparse("body");
 0601              break;
 0602   
 0603          case 'movedelforum':
 0604              //
 0605              // Move or delete a forum in the DB
 0606              //
 0607              $from_id = intval($HTTP_POST_VARS['from_id']);
 0608              $to_id = intval($HTTP_POST_VARS['to_id']);
 0609              $delete_old = intval($HTTP_POST_VARS['delete_old']);
 0610   
 0611              // Either delete or move all posts in a forum
 0612              if($to_id == -1)
 0613              {
 0614                  // Delete polls in this forum
 0615                  $sql = "SELECT v.vote_id 
 0616                      FROM " . VOTE_DESC_TABLE . " v, " . TOPICS_TABLE . " t 
 0617                      WHERE t.forum_id = $from_id 
 0618                          AND v.topic_id = t.topic_id";
 0619                  if (!($result = $db->sql_query($sql)))
 0620                  {
 0621                      message_die(GENERAL_ERROR, "Couldn't obtain list of vote ids", "", __LINE__, __FILE__, $sql);
 0622                  }
 0623   
 0624                  if ($row = $db->sql_fetchrow($result))
 0625                  {
 0626                      $vote_ids = '';
 0627                      do
 0628                      {
 0629                          $vote_ids .= (($vote_ids != '') ? ', ' : '') . $row['vote_id'];
 0630                      }
 0631                      while ($row = $db->sql_fetchrow($result));
 0632   
 0633                      $sql = "DELETE FROM " . VOTE_DESC_TABLE . " 
 0634                          WHERE vote_id IN ($vote_ids)";
 0635                      $db->sql_query($sql);
 0636   
 0637                      $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " 
 0638                          WHERE vote_id IN ($vote_ids)";
 0639                      $db->sql_query($sql);
 0640   
 0641                      $sql = "DELETE FROM " . VOTE_USERS_TABLE . " 
 0642                          WHERE vote_id IN ($vote_ids)";
 0643                      $db->sql_query($sql);
 0644                  }
 0645                  $db->sql_freeresult($result);
 0646                  
 0647                  include($phpbb_root_path . "includes/prune.$phpEx");
 0648                  prune($from_id, 0, true); // Delete everything from forum
 0649              }
 0650              else
 0651              {
 0652                  $sql = "SELECT *
 0653                      FROM " . FORUMS_TABLE . "
 0654                      WHERE forum_id IN ($from_id, $to_id)";
 0655                  if( !$result = $db->sql_query($sql) )
 0656                  {
 0657                      message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
 0658                  }
 0659   
 0660                  if($db->sql_numrows($result) != 2)
 0661                  {
 0662                      message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
 0663                  }
 0664                  $sql = "UPDATE " . TOPICS_TABLE . "
 0665                      SET forum_id = $to_id
 0666                      WHERE forum_id = $from_id";
 0667                  if( !$result = $db->sql_query($sql) )
 0668                  {
 0669                      message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
 0670                  }
 0671                  $sql = "UPDATE " . POSTS_TABLE . "
 0672                      SET    forum_id = $to_id
 0673                      WHERE forum_id = $from_id";
 0674                  if( !$result = $db->sql_query($sql) )
 0675                  {
 0676                      message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
 0677                  }
 0678                  sync('forum', $to_id);
 0679              }
 0680   
 0681              // Alter Mod level if appropriate - 2.0.4
 0682              $sql = "SELECT ug.user_id 
 0683                  FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug 
 0684                  WHERE a.forum_id <> $from_id 
 0685                      AND a.auth_mod = 1
 0686                      AND ug.group_id = a.group_id";
 0687              if( !$result = $db->sql_query($sql) )
 0688              {
 0689                  message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
 0690              }
 0691   
 0692              if ($row = $db->sql_fetchrow($result))
 0693              {
 0694                  $user_ids = '';
 0695                  do
 0696                  {
 0697                      $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
 0698                  }
 0699                  while ($row = $db->sql_fetchrow($result));
 0700   
 0701                  $sql = "SELECT ug.user_id 
 0702                      FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug 
 0703                      WHERE a.forum_id = $from_id 
 0704                          AND a.auth_mod = 1 
 0705                          AND ug.group_id = a.group_id
 0706                          AND ug.user_id NOT IN ($user_ids)";
 0707                  if( !$result2 = $db->sql_query($sql) )
 0708                  {
 0709                      message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
 0710                  }
 0711                      
 0712                  if ($row = $db->sql_fetchrow($result2))
 0713                  {
 0714                      $user_ids = '';
 0715                      do
 0716                      {
 0717                          $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
 0718                      }
 0719                      while ($row = $db->sql_fetchrow($result2));
 0720   
 0721                      $sql = "UPDATE " . USERS_TABLE . " 
 0722                          SET user_level = " . USER . " 
 0723                          WHERE user_id IN ($user_ids) 
 0724                              AND user_level <> " . ADMIN;
 0725                      $db->sql_query($sql);
 0726                  }
 0727                  $db->sql_freeresult($result);
 0728   
 0729              }
 0730              $db->sql_freeresult($result2);
 0731   
 0732              $sql = "DELETE FROM " . FORUMS_TABLE . "
 0733                  WHERE forum_id = $from_id";
 0734              if( !$result = $db->sql_query($sql) )
 0735              {
 0736                  message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
 0737              }
 0738              
 0739              $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
 0740                  WHERE forum_id = $from_id";
 0741              if( !$result = $db->sql_query($sql) )
 0742              {
 0743                  message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
 0744              }
 0745              
 0746              $sql = "DELETE FROM " . PRUNE_TABLE . "
 0747                  WHERE forum_id = $from_id";
 0748              if( !$result = $db->sql_query($sql) )
 0749              {
 0750                  message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
 0751              }
 0752   
 0753              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0754   
 0755              message_die(GENERAL_MESSAGE, $message);
 0756   
 0757              break;
 0758              
 0759          case 'deletecat':
 0760              //
 0761              // Show form to delete a category
 0762              //
 0763              $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 0764   
 0765              $buttonvalue = $lang['Move_and_Delete'];
 0766              $newmode = 'movedelcat';
 0767              $catinfo = get_info('category', $cat_id);
 0768              $name = $catinfo['cat_title'];
 0769   
 0770              if ($catinfo['number'] == 1)
 0771              {
 0772                  $sql = "SELECT count(*) as total
 0773                      FROM ". FORUMS_TABLE;
 0774                  if( !$result = $db->sql_query($sql) )
 0775                  {
 0776                      message_die(GENERAL_ERROR, "Couldn't get Forum count", "", __LINE__, __FILE__, $sql);
 0777                  }
 0778                  $count = $db->sql_fetchrow($result);
 0779                  $count = $count['total'];
 0780   
 0781                  if ($count > 0)
 0782                  {
 0783                      message_die(GENERAL_ERROR, $lang['Must_delete_forums']);
 0784                  }
 0785                  else
 0786                  {
 0787                      $select_to = $lang['Nowhere_to_move'];
 0788                  }
 0789              }
 0790              else
 0791              {
 0792                  $select_to = '<select name="to_id">';
 0793                  $select_to .= get_list('category', $cat_id, 0);
 0794                  $select_to .= '</select>';
 0795              }
 0796   
 0797              $template->set_filenames(array(
 0798                  "body" => "admin/forum_delete_body.tpl")
 0799              );
 0800   
 0801              $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $cat_id . '" />';
 0802   
 0803              $template->assign_vars(array(
 0804                  'NAME' => $name, 
 0805   
 0806                  'L_FORUM_DELETE' => $lang['Forum_delete'], 
 0807                  'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'], 
 0808                  'L_MOVE_CONTENTS' => $lang['Move_contents'], 
 0809                  'L_FORUM_NAME' => $lang['Forum_name'], 
 0810                  
 0811                  'S_HIDDEN_FIELDS' => $s_hidden_fields,
 0812                  'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"), 
 0813                  'S_SELECT_TO' => $select_to,
 0814                  'S_SUBMIT_VALUE' => $buttonvalue)
 0815              );
 0816   
 0817              $template->pparse("body");
 0818              break;
 0819   
 0820          case 'movedelcat':
 0821              //
 0822              // Move or delete a category in the DB
 0823              //
 0824              $from_id = intval($HTTP_POST_VARS['from_id']);
 0825              $to_id = intval($HTTP_POST_VARS['to_id']);
 0826   
 0827              if (!empty($to_id))
 0828              {
 0829                  $sql = "SELECT *
 0830                      FROM " . CATEGORIES_TABLE . "
 0831                      WHERE cat_id IN ($from_id, $to_id)";
 0832                  if( !$result = $db->sql_query($sql) )
 0833                  {
 0834                      message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
 0835                  }
 0836                  if($db->sql_numrows($result) != 2)
 0837                  {
 0838                      message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
 0839                  }
 0840   
 0841                  $sql = "UPDATE " . FORUMS_TABLE . "
 0842                      SET cat_id = $to_id
 0843                      WHERE cat_id = $from_id";
 0844                  if( !$result = $db->sql_query($sql) )
 0845                  {
 0846                      message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
 0847                  }
 0848              }
 0849   
 0850              $sql = "DELETE FROM " . CATEGORIES_TABLE ."
 0851                  WHERE cat_id = $from_id";
 0852                  
 0853              if( !$result = $db->sql_query($sql) )
 0854              {
 0855                  message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
 0856              }
 0857   
 0858              $message = $lang['Forums_updated'] . "<br /><br />" . sprintf($lang['Click_return_forumadmin'], "<a href=\"" . append_sid("admin_forums.$phpEx") . "\">", "</a>") . "<br /><br />" . sprintf($lang['Click_return_admin_index'], "<a href=\"" . append_sid("index.$phpEx?pane=right") . "\">", "</a>");
 0859   
 0860              message_die(GENERAL_MESSAGE, $message);
 0861   
 0862              break;
 0863   
 0864          case 'forum_order':
 0865              //
 0866              // Change order of forums in the DB
 0867              //
 0868              $move = intval($HTTP_GET_VARS['move']);
 0869              $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 0870   
 0871              $forum_info = get_info('forum', $forum_id);
 0872   
 0873              $cat_id = $forum_info['cat_id'];
 0874   
 0875              $sql = "UPDATE " . FORUMS_TABLE . "
 0876                  SET forum_order = forum_order + $move
 0877                  WHERE forum_id = $forum_id";
 0878              if( !$result = $db->sql_query($sql) )
 0879              {
 0880                  message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
 0881              }
 0882   
 0883              renumber_order('forum', $forum_info['cat_id']);
 0884              $show_index = TRUE;
 0885   
 0886              break;
 0887              
 0888          case 'cat_order':
 0889              //
 0890              // Change order of categories in the DB
 0891              //
 0892              $move = intval($HTTP_GET_VARS['move']);
 0893              $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 0894   
 0895              $sql = "UPDATE " . CATEGORIES_TABLE . "
 0896                  SET cat_order = cat_order + $move
 0897                  WHERE cat_id = $cat_id";
 0898              if( !$result = $db->sql_query($sql) )
 0899              {
 0900                  message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
 0901              }
 0902   
 0903              renumber_order('category');
 0904              $show_index = TRUE;
 0905   
 0906              break;
 0907   
 0908          case 'forum_sync':
 0909              sync('forum', intval($HTTP_GET_VARS[POST_FORUM_URL]));
 0910              $show_index = TRUE;
 0911   
 0912              break;
 0913   
 0914          default:
 0915              message_die(GENERAL_MESSAGE, $lang['No_mode']);
 0916              break;
 0917      }
 0918   
 0919      if ($show_index != TRUE)
 0920      {
 0921          include('./page_footer_admin.'.$phpEx);
 0922          exit;
 0923      }
 0924  }
 0925   
 0926  //
 0927  // Start page proper
 0928  //
 0929  $template->set_filenames(array(
 0930      "body" => "admin/forum_admin_body.tpl")
 0931  );
 0932   
 0933  $template->assign_vars(array(
 0934      'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
 0935      'L_FORUM_TITLE' => $lang['Forum_admin'], 
 0936      'L_FORUM_EXPLAIN' => $lang['Forum_admin_explain'], 
 0937      'L_CREATE_FORUM' => $lang['Create_forum'], 
 0938      'L_CREATE_CATEGORY' => $lang['Create_category'], 
 0939      'L_EDIT' => $lang['Edit'], 
 0940      'L_DELETE' => $lang['Delete'], 
 0941      'L_MOVE_UP' => $lang['Move_up'], 
 0942      'L_MOVE_DOWN' => $lang['Move_down'], 
 0943      'L_RESYNC' => $lang['Resync'])
 0944  );
 0945   
 0946  $sql = "SELECT cat_id, cat_title, cat_order
 0947      FROM " . CATEGORIES_TABLE . "
 0948      ORDER BY cat_order";
 0949  if( !$q_categories = $db->sql_query($sql) )
 0950  {
 0951      message_die(GENERAL_ERROR, "Could not query categories list", "", __LINE__, __FILE__, $sql);
 0952  }
 0953   
 0954  if( $total_categories = $db->sql_numrows($q_categories) )
 0955  {
 0956      $category_rows = $db->sql_fetchrowset($q_categories);
 0957   
 0958      $sql = "SELECT *
 0959          FROM " . FORUMS_TABLE . "
 0960          ORDER BY cat_id, forum_order";
 0961      if(!$q_forums = $db->sql_query($sql))
 0962      {
 0963          message_die(GENERAL_ERROR, "Could not query forums information", "", __LINE__, __FILE__, $sql);
 0964      }
 0965   
 0966      if( $total_forums = $db->sql_numrows($q_forums) )
 0967      {
 0968          $forum_rows = $db->sql_fetchrowset($q_forums);
 0969      }
 0970   
 0971      //
 0972      // Okay, let's build the index
 0973      //
 0974      $gen_cat = array();
 0975   
 0976      for($i = 0; $i < $total_categories; $i++)
 0977      {
 0978          $cat_id = $category_rows[$i]['cat_id'];
 0979   
 0980          $template->assign_block_vars("catrow", array( 
 0981              'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]", 
 0982              'S_ADD_FORUM_NAME' => "forumname[$cat_id]", 
 0983   
 0984              'CAT_ID' => $cat_id,
 0985              'CAT_DESC' => $category_rows[$i]['cat_title'],
 0986   
 0987              'U_CAT_EDIT' => append_sid("admin_forums.$phpEx?mode=editcat&amp;" . POST_CAT_URL . "=$cat_id"),
 0988              'U_CAT_DELETE' => append_sid("admin_forums.$phpEx?mode=deletecat&amp;" . POST_CAT_URL . "=$cat_id"),
 0989              'U_CAT_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=-15&amp;" . POST_CAT_URL . "=$cat_id"),
 0990              'U_CAT_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=15&amp;" . POST_CAT_URL . "=$cat_id"),
 0991              'U_VIEWCAT' => append_sid($phpbb_root_path."index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
 0992          );
 0993   
 0994          for($j = 0; $j < $total_forums; $j++)
 0995          {
 0996              $forum_id = $forum_rows[$j]['forum_id'];
 0997              
 0998              if ($forum_rows[$j]['cat_id'] == $cat_id)
 0999              {
 1000   
 1001                  $template->assign_block_vars("catrow.forumrow",    array(
 1002                      'FORUM_NAME' => $forum_rows[$j]['forum_name'],
 1003                      'FORUM_DESC' => $forum_rows[$j]['forum_desc'],
 1004                      'ROW_COLOR' => $row_color,
 1005                      'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
 1006                      'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
 1007   
 1008                      'U_VIEWFORUM' => append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
 1009                      'U_FORUM_EDIT' => append_sid("admin_forums.$phpEx?mode=editforum&amp;" . POST_FORUM_URL . "=$forum_id"),
 1010                      'U_FORUM_DELETE' => append_sid("admin_forums.$phpEx?mode=deleteforum&amp;" . POST_FORUM_URL . "=$forum_id"),
 1011                      'U_FORUM_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=-15&amp;" . POST_FORUM_URL . "=$forum_id"),
 1012                      'U_FORUM_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=15&amp;" . POST_FORUM_URL . "=$forum_id"),
 1013                      'U_FORUM_RESYNC' => append_sid("admin_forums.$phpEx?mode=forum_sync&amp;" . POST_FORUM_URL . "=$forum_id"))
 1014                  );
 1015   
 1016              }// if ... forumid == catid
 1017              
 1018          } // for ... forums
 1019   
 1020      } // for ... categories
 1021   
 1022  }// if ... total_categories
 1023   
 1024  $template->pparse("body");
 1025   
 1026  include('./page_footer_admin.'.$phpEx);
 1027   
 1028  ?>