(file) Return to admin_forums.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2 / admin

   1 rizwank 1.1 <?php
   2             /***************************************************************************
   3              *                             admin_forums.php
   4              *                            -------------------
   5              *   begin                : Thursday, Jul 12, 2001
   6              *   copyright            : (C) 2001 The phpBB Group
   7              *   email                : support@phpbb.com
   8              *
   9              *   $Id: admin_forums.php,v 1.40.2.10 2003/01/05 02:36:00 psotfx Exp $
  10              *
  11              ***************************************************************************/
  12             
  13             /***************************************************************************
  14              *
  15              *   This program is free software; you can redistribute it and/or modify
  16              *   it under the terms of the GNU General Public License as published by
  17              *   the Free Software Foundation; either version 2 of the License, or
  18              *   (at your option) any later version.
  19              *
  20              ***************************************************************************/
  21             
  22 rizwank 1.1 define('IN_PHPBB', 1);
  23             
  24             if( !empty($setmodules) )
  25             {
  26             	$file = basename(__FILE__);
  27             	$module['Forums']['Manage'] = $file;
  28             	return;
  29             }
  30             
  31             //
  32             // Load default header
  33             //
  34             $phpbb_root_path = "./../";
  35             require($phpbb_root_path . 'extension.inc');
  36             require('./pagestart.' . $phpEx);
  37             include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
  38             
  39             $forum_auth_ary = array(
  40             	"auth_view" => AUTH_ALL, 
  41             	"auth_read" => AUTH_ALL, 
  42             	"auth_post" => AUTH_ALL, 
  43 rizwank 1.1 	"auth_reply" => AUTH_ALL, 
  44             	"auth_edit" => AUTH_REG, 
  45             	"auth_delete" => AUTH_REG, 
  46             	"auth_sticky" => AUTH_MOD, 
  47             	"auth_announce" => AUTH_MOD, 
  48             	"auth_vote" => AUTH_REG, 
  49             	"auth_pollcreate" => AUTH_REG
  50             );
  51             
  52             //
  53             // Mode setting
  54             //
  55             if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
  56             {
  57             	$mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
  58             }
  59             else
  60             {
  61             	$mode = "";
  62             }
  63             
  64 rizwank 1.1 // ------------------
  65             // Begin function block
  66             //
  67             function get_info($mode, $id)
  68             {
  69             	global $db;
  70             
  71             	switch($mode)
  72             	{
  73             		case 'category':
  74             			$table = CATEGORIES_TABLE;
  75             			$idfield = 'cat_id';
  76             			$namefield = 'cat_title';
  77             			break;
  78             
  79             		case 'forum':
  80             			$table = FORUMS_TABLE;
  81             			$idfield = 'forum_id';
  82             			$namefield = 'forum_name';
  83             			break;
  84             
  85 rizwank 1.1 		default:
  86             			message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
  87             			break;
  88             	}
  89             	$sql = "SELECT count(*) as total
  90             		FROM $table";
  91             	if( !$result = $db->sql_query($sql) )
  92             	{
  93             		message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
  94             	}
  95             	$count = $db->sql_fetchrow($result);
  96             	$count = $count['total'];
  97             
  98             	$sql = "SELECT *
  99             		FROM $table
 100             		WHERE $idfield = $id"; 
 101             
 102             	if( !$result = $db->sql_query($sql) )
 103             	{
 104             		message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
 105             	}
 106 rizwank 1.1 
 107             	if( $db->sql_numrows($result) != 1 )
 108             	{
 109             		message_die(GENERAL_ERROR, "Forum/Category doesn't exist or multiple forums/categories with ID $id", "", __LINE__, __FILE__);
 110             	}
 111             
 112             	$return = $db->sql_fetchrow($result);
 113             	$return['number'] = $count;
 114             	return $return;
 115             }
 116             
 117             function get_list($mode, $id, $select)
 118             {
 119             	global $db;
 120             
 121             	switch($mode)
 122             	{
 123             		case 'category':
 124             			$table = CATEGORIES_TABLE;
 125             			$idfield = 'cat_id';
 126             			$namefield = 'cat_title';
 127 rizwank 1.1 			break;
 128             
 129             		case 'forum':
 130             			$table = FORUMS_TABLE;
 131             			$idfield = 'forum_id';
 132             			$namefield = 'forum_name';
 133             			break;
 134             
 135             		default:
 136             			message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
 137             			break;
 138             	}
 139             
 140             	$sql = "SELECT *
 141             		FROM $table";
 142             	if( $select == 0 )
 143             	{
 144             		$sql .= " WHERE $idfield <> $id";
 145             	}
 146             
 147             	if( !$result = $db->sql_query($sql) )
 148 rizwank 1.1 	{
 149             		message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
 150             	}
 151             
 152             	$cat_list = "";
 153             
 154             	while( $row = $db->sql_fetchrow($result) )
 155             	{
 156             		$s = "";
 157             		if ($row[$idfield] == $id)
 158             		{
 159             			$s = " selected=\"selected\"";
 160             		}
 161             		$catlist .= "<option value=\"$row[$idfield]\"$s>" . $row[$namefield] . "</option>\n";
 162             	}
 163             
 164             	return($catlist);
 165             }
 166             
 167             function renumber_order($mode, $cat = 0)
 168             {
 169 rizwank 1.1 	global $db;
 170             
 171             	switch($mode)
 172             	{
 173             		case 'category':
 174             			$table = CATEGORIES_TABLE;
 175             			$idfield = 'cat_id';
 176             			$orderfield = 'cat_order';
 177             			$cat = 0;
 178             			break;
 179             
 180             		case 'forum':
 181             			$table = FORUMS_TABLE;
 182             			$idfield = 'forum_id';
 183             			$orderfield = 'forum_order';
 184             			$catfield = 'cat_id';
 185             			break;
 186             
 187             		default:
 188             			message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
 189             			break;
 190 rizwank 1.1 	}
 191             
 192             	$sql = "SELECT * FROM $table";
 193             	if( $cat != 0)
 194             	{
 195             		$sql .= " WHERE $catfield = $cat";
 196             	}
 197             	$sql .= " ORDER BY $orderfield ASC";
 198             
 199             
 200             	if( !$result = $db->sql_query($sql) )
 201             	{
 202             		message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
 203             	}
 204             
 205             	$i = 10;
 206             	$inc = 10;
 207             
 208             	while( $row = $db->sql_fetchrow($result) )
 209             	{
 210             		$sql = "UPDATE $table
 211 rizwank 1.1 			SET $orderfield = $i
 212             			WHERE $idfield = " . $row[$idfield];
 213             		if( !$db->sql_query($sql) )
 214             		{
 215             			message_die(GENERAL_ERROR, "Couldn't update order fields", "", __LINE__, __FILE__, $sql);
 216             		}
 217             		$i += 10;
 218             	}
 219             
 220             }
 221             //
 222             // End function block
 223             // ------------------
 224             
 225             //
 226             // Begin program proper
 227             //
 228             if( isset($HTTP_POST_VARS['addforum']) || isset($HTTP_POST_VARS['addcategory']) )
 229             {
 230             	$mode = ( isset($HTTP_POST_VARS['addforum']) ) ? "addforum" : "addcat";
 231             
 232 rizwank 1.1 	if( $mode == "addforum" )
 233             	{
 234             		list($cat_id) = each($HTTP_POST_VARS['addforum']);
 235             		// 
 236             		// stripslashes needs to be run on this because slashes are added when the forum name is posted
 237             		//
 238             		$forumname = stripslashes($HTTP_POST_VARS['forumname'][$cat_id]);
 239             	}
 240             }
 241             
 242             if( !empty($mode) ) 
 243             {
 244             	switch($mode)
 245             	{
 246             		case 'addforum':
 247             		case 'editforum':
 248             			//
 249             			// Show form to create/modify a forum
 250             			//
 251             			if ($mode == 'editforum')
 252             			{
 253 rizwank 1.1 				// $newmode determines if we are going to INSERT or UPDATE after posting?
 254             
 255             				$l_title = $lang['Edit_forum'];
 256             				$newmode = 'modforum';
 257             				$buttonvalue = $lang['Update'];
 258             
 259             				$forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 260             
 261             				$row = get_info('forum', $forum_id);
 262             
 263             				$cat_id = $row['cat_id'];
 264             				$forumname = $row['forum_name'];
 265             				$forumdesc = $row['forum_desc'];
 266             				$forumstatus = $row['forum_status'];
 267             
 268             				//
 269             				// start forum prune stuff.
 270             				//
 271             				if( $row['prune_enable'] )
 272             				{
 273             					$prune_enabled = "checked=\"checked\"";
 274 rizwank 1.1 					$sql = "SELECT *
 275                            			FROM " . PRUNE_TABLE . "
 276                            			WHERE forum_id = $forum_id";
 277             					if(!$pr_result = $db->sql_query($sql))
 278             					{
 279             						 message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
 280                     			}
 281             
 282             					$pr_row = $db->sql_fetchrow($pr_result);
 283             				}
 284             				else
 285             				{
 286             					$prune_enabled = '';
 287             				}
 288             			}
 289             			else
 290             			{
 291             				$l_title = $lang['Create_forum'];
 292             				$newmode = 'createforum';
 293             				$buttonvalue = $lang['Create_forum'];
 294             
 295 rizwank 1.1 				$forumdesc = '';
 296             				$forumstatus = FORUM_UNLOCKED;
 297             				$forum_id = ''; 
 298             				$prune_enabled = '';
 299             			}
 300             
 301             			$catlist = get_list('category', $cat_id, TRUE);
 302             
 303             			$forumstatus == ( FORUM_LOCKED ) ? $forumlocked = "selected=\"selected\"" : $forumunlocked = "selected=\"selected\"";
 304             			
 305             			// These two options ($lang['Status_unlocked'] and $lang['Status_locked']) seem to be missing from
 306             			// the language files.
 307             			$lang['Status_unlocked'] = isset($lang['Status_unlocked']) ? $lang['Status_unlocked'] : 'Unlocked';
 308             			$lang['Status_locked'] = isset($lang['Status_locked']) ? $lang['Status_locked'] : 'Locked';
 309             			
 310             			$statuslist = "<option value=\"" . FORUM_UNLOCKED . "\" $forumunlocked>" . $lang['Status_unlocked'] . "</option>\n";
 311             			$statuslist .= "<option value=\"" . FORUM_LOCKED . "\" $forumlocked>" . $lang['Status_locked'] . "</option>\n"; 
 312             
 313             			$template->set_filenames(array(
 314             				"body" => "admin/forum_edit_body.tpl")
 315             			);
 316 rizwank 1.1 
 317             			$s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode .'" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
 318             
 319             			$template->assign_vars(array(
 320             				'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
 321             				'S_HIDDEN_FIELDS' => $s_hidden_fields,
 322             				'S_SUBMIT_VALUE' => $buttonvalue, 
 323             				'S_CAT_LIST' => $catlist,
 324             				'S_STATUS_LIST' => $statuslist,
 325             				'S_PRUNE_ENABLED' => $prune_enabled,
 326             
 327             				'L_FORUM_TITLE' => $l_title, 
 328             				'L_FORUM_EXPLAIN' => $lang['Forum_edit_delete_explain'], 
 329             				'L_FORUM_SETTINGS' => $lang['Forum_settings'], 
 330             				'L_FORUM_NAME' => $lang['Forum_name'], 
 331             				'L_CATEGORY' => $lang['Category'], 
 332             				'L_FORUM_DESCRIPTION' => $lang['Forum_desc'],
 333             				'L_FORUM_STATUS' => $lang['Forum_status'],
 334             				'L_AUTO_PRUNE' => $lang['Forum_pruning'],
 335             				'L_ENABLED' => $lang['Enabled'],
 336             				'L_PRUNE_DAYS' => $lang['prune_days'],
 337 rizwank 1.1 				'L_PRUNE_FREQ' => $lang['prune_freq'],
 338             				'L_DAYS' => $lang['Days'],
 339             
 340             				'PRUNE_DAYS' => ( isset($pr_row['prune_days']) ) ? $pr_row['prune_days'] : 7,
 341             				'PRUNE_FREQ' => ( isset($pr_row['prune_freq']) ) ? $pr_row['prune_freq'] : 1,
 342             				'FORUM_NAME' => $forumname,
 343             				'DESCRIPTION' => $forumdesc)
 344             			);
 345             			$template->pparse("body");
 346             			break;
 347             
 348             		case 'createforum':
 349             			//
 350             			// Create a forum in the DB
 351             			//
 352             			if( trim($HTTP_POST_VARS['forumname']) == "" )
 353             			{
 354             				message_die(GENERAL_ERROR, "Can't create a forum without a name");
 355             			}
 356             
 357             			$sql = "SELECT MAX(forum_order) AS max_order
 358 rizwank 1.1 				FROM " . FORUMS_TABLE . "
 359             				WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
 360             			if( !$result = $db->sql_query($sql) )
 361             			{
 362             				message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
 363             			}
 364             			$row = $db->sql_fetchrow($result);
 365             
 366             			$max_order = $row['max_order'];
 367             			$next_order = $max_order + 10;
 368             			
 369             			$sql = "SELECT MAX(forum_id) AS max_id
 370             				FROM " . FORUMS_TABLE;
 371             			if( !$result = $db->sql_query($sql) )
 372             			{
 373             				message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
 374             			}
 375             			$row = $db->sql_fetchrow($result);
 376             
 377             			$max_id = $row['max_id'];
 378             			$next_id = $max_id + 1;
 379 rizwank 1.1 
 380             			//
 381             			// Default permissions of public :: 
 382             			//
 383             			$field_sql = "";
 384             			$value_sql = "";
 385             			while( list($field, $value) = each($forum_auth_ary) )
 386             			{
 387             				$field_sql .= ", $field";
 388             				$value_sql .= ", $value";
 389             
 390             			}
 391             
 392             			// There is no problem having duplicate forum names so we won't check for it.
 393             			$sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ")
 394             				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 . ")";
 395             			if( !$result = $db->sql_query($sql) )
 396             			{
 397             				message_die(GENERAL_ERROR, "Couldn't insert row in forums table", "", __LINE__, __FILE__, $sql);
 398             			}
 399             
 400 rizwank 1.1 			if( $HTTP_POST_VARS['prune_enable'] )
 401             			{
 402             
 403             				if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "")
 404             				{
 405             					message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
 406             				}
 407             
 408             				$sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
 409             					VALUES('" . $next_id . "', " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
 410             				if( !$result = $db->sql_query($sql) )
 411             				{
 412             					message_die(GENERAL_ERROR, "Couldn't insert row in prune table", "", __LINE__, __FILE__, $sql);
 413             				}
 414             			}
 415             
 416             			$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>");
 417             
 418             			message_die(GENERAL_MESSAGE, $message);
 419             
 420             			break;
 421 rizwank 1.1 
 422             		case 'modforum':
 423             			// Modify a forum in the DB
 424             			if( isset($HTTP_POST_VARS['prune_enable']))
 425             			{
 426             				if( $HTTP_POST_VARS['prune_enable'] != 1 )
 427             				{
 428             					$HTTP_POST_VARS['prune_enable'] = 0;
 429             				}
 430             			}
 431             
 432             			$sql = "UPDATE " . FORUMS_TABLE . "
 433             				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']) . "
 434             				WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 435             			if( !$result = $db->sql_query($sql) )
 436             			{
 437             				message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
 438             			}
 439             
 440             			if( $HTTP_POST_VARS['prune_enable'] == 1 )
 441             			{
 442 rizwank 1.1 				if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "" )
 443             				{
 444             					message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
 445             				}
 446             
 447             				$sql = "SELECT *
 448             					FROM " . PRUNE_TABLE . "
 449             					WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 450             				if( !$result = $db->sql_query($sql) )
 451             				{
 452             					message_die(GENERAL_ERROR, "Couldn't get forum Prune Information","",__LINE__, __FILE__, $sql);
 453             				}
 454             
 455             				if( $db->sql_numrows($result) > 0 )
 456             				{
 457             					$sql = "UPDATE " . PRUNE_TABLE . "
 458             						SET	prune_days = " . intval($HTTP_POST_VARS['prune_days']) . ",	prune_freq = " . intval($HTTP_POST_VARS['prune_freq']) . "
 459             				 		WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
 460             				}
 461             				else
 462             				{
 463 rizwank 1.1 					$sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
 464             						VALUES(" . intval($HTTP_POST_VARS[POST_FORUM_URL]) . ", " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
 465             				}
 466             
 467             				if( !$result = $db->sql_query($sql) )
 468             				{
 469             					message_die(GENERAL_ERROR, "Couldn't Update Forum Prune Information","",__LINE__, __FILE__, $sql);
 470             				}
 471             			}
 472             
 473             			$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>");
 474             
 475             			message_die(GENERAL_MESSAGE, $message);
 476             
 477             			break;
 478             			
 479             		case 'addcat':
 480             			// Create a category in the DB
 481             			if( trim($HTTP_POST_VARS['categoryname']) == '')
 482             			{
 483             				message_die(GENERAL_ERROR, "Can't create a category without a name");
 484 rizwank 1.1 			}
 485             
 486             			$sql = "SELECT MAX(cat_order) AS max_order
 487             				FROM " . CATEGORIES_TABLE;
 488             			if( !$result = $db->sql_query($sql) )
 489             			{
 490             				message_die(GENERAL_ERROR, "Couldn't get order number from categories table", "", __LINE__, __FILE__, $sql);
 491             			}
 492             			$row = $db->sql_fetchrow($result);
 493             
 494             			$max_order = $row['max_order'];
 495             			$next_order = $max_order + 10;
 496             
 497             			//
 498             			// There is no problem having duplicate forum names so we won't check for it.
 499             			//
 500             			$sql = "INSERT INTO " . CATEGORIES_TABLE . " (cat_title, cat_order)
 501             				VALUES ('" . str_replace("\'", "''", $HTTP_POST_VARS['categoryname']) . "', $next_order)";
 502             			if( !$result = $db->sql_query($sql) )
 503             			{
 504             				message_die(GENERAL_ERROR, "Couldn't insert row in categories table", "", __LINE__, __FILE__, $sql);
 505 rizwank 1.1 			}
 506             
 507             			$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>");
 508             
 509             			message_die(GENERAL_MESSAGE, $message);
 510             
 511             			break;
 512             			
 513             		case 'editcat':
 514             			//
 515             			// Show form to edit a category
 516             			//
 517             			$newmode = 'modcat';
 518             			$buttonvalue = $lang['Update'];
 519             
 520             			$cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 521             
 522             			$row = get_info('category', $cat_id);
 523             			$cat_title = $row['cat_title'];
 524             
 525             			$template->set_filenames(array(
 526 rizwank 1.1 				"body" => "admin/category_edit_body.tpl")
 527             			);
 528             
 529             			$s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="' . POST_CAT_URL . '" value="' . $cat_id . '" />';
 530             
 531             			$template->assign_vars(array(
 532             				'CAT_TITLE' => $cat_title,
 533             
 534             				'L_EDIT_CATEGORY' => $lang['Edit_Category'], 
 535             				'L_EDIT_CATEGORY_EXPLAIN' => $lang['Edit_Category_explain'], 
 536             				'L_CATEGORY' => $lang['Category'], 
 537             
 538             				'S_HIDDEN_FIELDS' => $s_hidden_fields, 
 539             				'S_SUBMIT_VALUE' => $buttonvalue, 
 540             				'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"))
 541             			);
 542             
 543             			$template->pparse("body");
 544             			break;
 545             
 546             		case 'modcat':
 547 rizwank 1.1 			// Modify a category in the DB
 548             			$sql = "UPDATE " . CATEGORIES_TABLE . "
 549             				SET cat_title = '" . str_replace("\'", "''", $HTTP_POST_VARS['cat_title']) . "'
 550             				WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
 551             			if( !$result = $db->sql_query($sql) )
 552             			{
 553             				message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
 554             			}
 555             
 556             			$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>");
 557             
 558             			message_die(GENERAL_MESSAGE, $message);
 559             
 560             			break;
 561             			
 562             		case 'deleteforum':
 563             			// Show form to delete a forum
 564             			$forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 565             
 566             			$select_to = '<select name="to_id">';
 567             			$select_to .= "<option value=\"-1\"$s>" . $lang['Delete_all_posts'] . "</option>\n";
 568 rizwank 1.1 			$select_to .= get_list('forum', $forum_id, 0);
 569             			$select_to .= '</select>';
 570             
 571             			$buttonvalue = $lang['Move_and_Delete'];
 572             
 573             			$newmode = 'movedelforum';
 574             
 575             			$foruminfo = get_info('forum', $forum_id);
 576             			$name = $foruminfo['forum_name'];
 577             
 578             			$template->set_filenames(array(
 579             				"body" => "admin/forum_delete_body.tpl")
 580             			);
 581             
 582             			$s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $forum_id . '" />';
 583             
 584             			$template->assign_vars(array(
 585             				'NAME' => $name, 
 586             
 587             				'L_FORUM_DELETE' => $lang['Forum_delete'], 
 588             				'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'], 
 589 rizwank 1.1 				'L_MOVE_CONTENTS' => $lang['Move_contents'], 
 590             				'L_FORUM_NAME' => $lang['Forum_name'], 
 591             
 592             				"S_HIDDEN_FIELDS" => $s_hidden_fields,
 593             				'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"), 
 594             				'S_SELECT_TO' => $select_to,
 595             				'S_SUBMIT_VALUE' => $buttonvalue)
 596             			);
 597             
 598             			$template->pparse("body");
 599             			break;
 600             
 601             		case 'movedelforum':
 602             			//
 603             			// Move or delete a forum in the DB
 604             			//
 605             			$from_id = intval($HTTP_POST_VARS['from_id']);
 606             			$to_id = intval($HTTP_POST_VARS['to_id']);
 607             			$delete_old = intval($HTTP_POST_VARS['delete_old']);
 608             
 609             			// Either delete or move all posts in a forum
 610 rizwank 1.1 			if($to_id == -1)
 611             			{
 612             				// Delete polls in this forum
 613             				$sql = "SELECT v.vote_id 
 614             					FROM " . VOTE_DESC_TABLE . " v, " . TOPICS_TABLE . " t 
 615             					WHERE t.forum_id = $from_id 
 616             						AND v.topic_id = t.topic_id";
 617             				if (!($result = $db->sql_query($sql)))
 618             				{
 619             					message_die(GENERAL_ERROR, "Couldn't obtain list of vote ids", "", __LINE__, __FILE__, $sql);
 620             				}
 621             
 622             				if ($row = $db->sql_fetchrow($result))
 623             				{
 624             					$vote_ids = '';
 625             					do
 626             					{
 627             						$vote_ids = (($vote_ids != '') ? ', ' : '') . $row['vote_id'];
 628             					}
 629             					while ($row = $db->sql_fetchrow($result));
 630             
 631 rizwank 1.1 					$sql = "DELETE FROM " . VOTE_DESC_TABLE . " 
 632             						WHERE vote_id IN ($vote_ids)";
 633             					$db->sql_query($sql);
 634             
 635             					$sql = "DELETE FROM " . VOTE_RESULTS_TABLE . " 
 636             						WHERE vote_id IN ($vote_ids)";
 637             					$db->sql_query($sql);
 638             
 639             					$sql = "DELETE FROM " . VOTE_USERS_TABLE . " 
 640             						WHERE vote_id IN ($vote_ids)";
 641             					$db->sql_query($sql);
 642             				}
 643             				$db->sql_freeresult($result);
 644             				
 645             				include($phpbb_root_path . "includes/prune.$phpEx");
 646             				prune($from_id, 0, true); // Delete everything from forum
 647             			}
 648             			else
 649             			{
 650             				$sql = "SELECT *
 651             					FROM " . FORUMS_TABLE . "
 652 rizwank 1.1 					WHERE forum_id IN ($from_id, $to_id)";
 653             				if( !$result = $db->sql_query($sql) )
 654             				{
 655             					message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
 656             				}
 657             
 658             				if($db->sql_numrows($result) != 2)
 659             				{
 660             					message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
 661             				}
 662             				$sql = "UPDATE " . TOPICS_TABLE . "
 663             					SET forum_id = $to_id
 664             					WHERE forum_id = $from_id";
 665             				if( !$result = $db->sql_query($sql) )
 666             				{
 667             					message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
 668             				}
 669             				$sql = "UPDATE " . POSTS_TABLE . "
 670             					SET	forum_id = $to_id
 671             					WHERE forum_id = $from_id";
 672             				if( !$result = $db->sql_query($sql) )
 673 rizwank 1.1 				{
 674             					message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
 675             				}
 676             				sync('forum', $to_id);
 677             			}
 678             
 679             			// Alter Mod level if appropriate - 2.0.4
 680             			$sql = "SELECT ug.user_id 
 681             				FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug 
 682             				WHERE a.forum_id <> $from_id 
 683             					AND a.auth_mod = 1
 684             					AND ug.group_id = a.group_id";
 685             			if( !$result = $db->sql_query($sql) )
 686             			{
 687             				message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
 688             			}
 689             
 690             			if ($row = $db->sql_fetchrow($result))
 691             			{
 692             				$user_ids = '';
 693             				do
 694 rizwank 1.1 				{
 695             					$user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
 696             				}
 697             				while ($row = $db->sql_fetchrow($result));
 698             
 699             				$sql = "SELECT ug.user_id 
 700             					FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug 
 701             					WHERE a.forum_id = $from_id 
 702             						AND a.auth_mod = 1 
 703             						AND ug.group_id = a.group_id
 704             						AND ug.user_id NOT IN ($user_ids)";
 705             				if( !$result2 = $db->sql_query($sql) )
 706             				{
 707             					message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
 708             				}
 709             					
 710             				if ($row = $db->sql_fetchrow($result2))
 711             				{
 712             					$user_ids = '';
 713             					do
 714             					{
 715 rizwank 1.1 						$user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
 716             					}
 717             					while ($row = $db->sql_fetchrow($result2));
 718             
 719             					$sql = "UPDATE " . USERS_TABLE . " 
 720             						SET user_level = " . USER . " 
 721             						WHERE user_id IN ($user_ids) 
 722             							AND user_level <> " . ADMIN;
 723             					$db->sql_query($sql);
 724             				}
 725             				$db->sql_freeresult($result);
 726             
 727             			}
 728             			$db->sql_freeresult($result2);
 729             
 730             			$sql = "DELETE FROM " . FORUMS_TABLE . "
 731             				WHERE forum_id = $from_id";
 732             			if( !$result = $db->sql_query($sql) )
 733             			{
 734             				message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
 735             			}
 736 rizwank 1.1 			
 737             			$sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
 738             				WHERE forum_id = $from_id";
 739             			if( !$result = $db->sql_query($sql) )
 740             			{
 741             				message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
 742             			}
 743             			
 744             			$sql = "DELETE FROM " . PRUNE_TABLE . "
 745             				WHERE forum_id = $from_id";
 746             			if( !$result = $db->sql_query($sql) )
 747             			{
 748             				message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
 749             			}
 750             
 751             			$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>");
 752             
 753             			message_die(GENERAL_MESSAGE, $message);
 754             
 755             			break;
 756             			
 757 rizwank 1.1 		case 'deletecat':
 758             			//
 759             			// Show form to delete a category
 760             			//
 761             			$cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 762             
 763             			$buttonvalue = $lang['Move_and_Delete'];
 764             			$newmode = 'movedelcat';
 765             			$catinfo = get_info('category', $cat_id);
 766             			$name = $catinfo['cat_title'];
 767             
 768             			if ($catinfo['number'] == 1)
 769             			{
 770             				$sql = "SELECT count(*) as total
 771             					FROM ". FORUMS_TABLE;
 772             				if( !$result = $db->sql_query($sql) )
 773             				{
 774             					message_die(GENERAL_ERROR, "Couldn't get Forum count", "", __LINE__, __FILE__, $sql);
 775             				}
 776             				$count = $db->sql_fetchrow($result);
 777             				$count = $count['total'];
 778 rizwank 1.1 
 779             				if ($count > 0)
 780             				{
 781             					message_die(GENERAL_ERROR, $lang['Must_delete_forums']);
 782             				}
 783             				else
 784             				{
 785             					$select_to = $lang['Nowhere_to_move'];
 786             				}
 787             			}
 788             			else
 789             			{
 790             				$select_to = '<select name="to_id">';
 791             				$select_to .= get_list('category', $cat_id, 0);
 792             				$select_to .= '</select>';
 793             			}
 794             
 795             			$template->set_filenames(array(
 796             				"body" => "admin/forum_delete_body.tpl")
 797             			);
 798             
 799 rizwank 1.1 			$s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $cat_id . '" />';
 800             
 801             			$template->assign_vars(array(
 802             				'NAME' => $name, 
 803             
 804             				'L_FORUM_DELETE' => $lang['Forum_delete'], 
 805             				'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'], 
 806             				'L_MOVE_CONTENTS' => $lang['Move_contents'], 
 807             				'L_FORUM_NAME' => $lang['Forum_name'], 
 808             				
 809             				'S_HIDDEN_FIELDS' => $s_hidden_fields,
 810             				'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"), 
 811             				'S_SELECT_TO' => $select_to,
 812             				'S_SUBMIT_VALUE' => $buttonvalue)
 813             			);
 814             
 815             			$template->pparse("body");
 816             			break;
 817             
 818             		case 'movedelcat':
 819             			//
 820 rizwank 1.1 			// Move or delete a category in the DB
 821             			//
 822             			$from_id = intval($HTTP_POST_VARS['from_id']);
 823             			$to_id = intval($HTTP_POST_VARS['to_id']);
 824             
 825             			if (!empty($to_id))
 826             			{
 827             				$sql = "SELECT *
 828             					FROM " . CATEGORIES_TABLE . "
 829             					WHERE cat_id IN ($from_id, $to_id)";
 830             				if( !$result = $db->sql_query($sql) )
 831             				{
 832             					message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
 833             				}
 834             				if($db->sql_numrows($result) != 2)
 835             				{
 836             					message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
 837             				}
 838             
 839             				$sql = "UPDATE " . FORUMS_TABLE . "
 840             					SET cat_id = $to_id
 841 rizwank 1.1 					WHERE cat_id = $from_id";
 842             				if( !$result = $db->sql_query($sql) )
 843             				{
 844             					message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
 845             				}
 846             			}
 847             
 848             			$sql = "DELETE FROM " . CATEGORIES_TABLE ."
 849             				WHERE cat_id = $from_id";
 850             				
 851             			if( !$result = $db->sql_query($sql) )
 852             			{
 853             				message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
 854             			}
 855             
 856             			$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>");
 857             
 858             			message_die(GENERAL_MESSAGE, $message);
 859             
 860             			break;
 861             
 862 rizwank 1.1 		case 'forum_order':
 863             			//
 864             			// Change order of forums in the DB
 865             			//
 866             			$move = intval($HTTP_GET_VARS['move']);
 867             			$forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
 868             
 869             			$forum_info = get_info('forum', $forum_id);
 870             
 871             			$cat_id = $forum_info['cat_id'];
 872             
 873             			$sql = "UPDATE " . FORUMS_TABLE . "
 874             				SET forum_order = forum_order + $move
 875             				WHERE forum_id = $forum_id";
 876             			if( !$result = $db->sql_query($sql) )
 877             			{
 878             				message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
 879             			}
 880             
 881             			renumber_order('forum', $forum_info['cat_id']);
 882             			$show_index = TRUE;
 883 rizwank 1.1 
 884             			break;
 885             			
 886             		case 'cat_order':
 887             			//
 888             			// Change order of categories in the DB
 889             			//
 890             			$move = intval($HTTP_GET_VARS['move']);
 891             			$cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
 892             
 893             			$sql = "UPDATE " . CATEGORIES_TABLE . "
 894             				SET cat_order = cat_order + $move
 895             				WHERE cat_id = $cat_id";
 896             			if( !$result = $db->sql_query($sql) )
 897             			{
 898             				message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
 899             			}
 900             
 901             			renumber_order('category');
 902             			$show_index = TRUE;
 903             
 904 rizwank 1.1 			break;
 905             
 906             		case 'forum_sync':
 907             			sync('forum', intval($HTTP_GET_VARS[POST_FORUM_URL]));
 908             			$show_index = TRUE;
 909             
 910             			break;
 911             
 912             		default:
 913             			message_die(GENERAL_MESSAGE, $lang['No_mode']);
 914             			break;
 915             	}
 916             
 917             	if ($show_index != TRUE)
 918             	{
 919             		include('./page_footer_admin.'.$phpEx);
 920             		exit;
 921             	}
 922             }
 923             
 924             //
 925 rizwank 1.1 // Start page proper
 926             //
 927             $template->set_filenames(array(
 928             	"body" => "admin/forum_admin_body.tpl")
 929             );
 930             
 931             $template->assign_vars(array(
 932             	'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
 933             	'L_FORUM_TITLE' => $lang['Forum_admin'], 
 934             	'L_FORUM_EXPLAIN' => $lang['Forum_admin_explain'], 
 935             	'L_CREATE_FORUM' => $lang['Create_forum'], 
 936             	'L_CREATE_CATEGORY' => $lang['Create_category'], 
 937             	'L_EDIT' => $lang['Edit'], 
 938             	'L_DELETE' => $lang['Delete'], 
 939             	'L_MOVE_UP' => $lang['Move_up'], 
 940             	'L_MOVE_DOWN' => $lang['Move_down'], 
 941             	'L_RESYNC' => $lang['Resync'])
 942             );
 943             
 944             $sql = "SELECT cat_id, cat_title, cat_order
 945             	FROM " . CATEGORIES_TABLE . "
 946 rizwank 1.1 	ORDER BY cat_order";
 947             if( !$q_categories = $db->sql_query($sql) )
 948             {
 949             	message_die(GENERAL_ERROR, "Could not query categories list", "", __LINE__, __FILE__, $sql);
 950             }
 951             
 952             if( $total_categories = $db->sql_numrows($q_categories) )
 953             {
 954             	$category_rows = $db->sql_fetchrowset($q_categories);
 955             
 956             	$sql = "SELECT *
 957             		FROM " . FORUMS_TABLE . "
 958             		ORDER BY cat_id, forum_order";
 959             	if(!$q_forums = $db->sql_query($sql))
 960             	{
 961             		message_die(GENERAL_ERROR, "Could not query forums information", "", __LINE__, __FILE__, $sql);
 962             	}
 963             
 964             	if( $total_forums = $db->sql_numrows($q_forums) )
 965             	{
 966             		$forum_rows = $db->sql_fetchrowset($q_forums);
 967 rizwank 1.1 	}
 968             
 969             	//
 970             	// Okay, let's build the index
 971             	//
 972             	$gen_cat = array();
 973             
 974             	for($i = 0; $i < $total_categories; $i++)
 975             	{
 976             		$cat_id = $category_rows[$i]['cat_id'];
 977             
 978             		$template->assign_block_vars("catrow", array( 
 979             			'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]", 
 980             			'S_ADD_FORUM_NAME' => "forumname[$cat_id]", 
 981             
 982             			'CAT_ID' => $cat_id,
 983             			'CAT_DESC' => $category_rows[$i]['cat_title'],
 984             
 985             			'U_CAT_EDIT' => append_sid("admin_forums.$phpEx?mode=editcat&amp;" . POST_CAT_URL . "=$cat_id"),
 986             			'U_CAT_DELETE' => append_sid("admin_forums.$phpEx?mode=deletecat&amp;" . POST_CAT_URL . "=$cat_id"),
 987             			'U_CAT_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=-15&amp;" . POST_CAT_URL . "=$cat_id"),
 988 rizwank 1.1 			'U_CAT_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=15&amp;" . POST_CAT_URL . "=$cat_id"),
 989             			'U_VIEWCAT' => append_sid($phpbb_root_path."index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
 990             		);
 991             
 992             		for($j = 0; $j < $total_forums; $j++)
 993             		{
 994             			$forum_id = $forum_rows[$j]['forum_id'];
 995             			
 996             			if ($forum_rows[$j]['cat_id'] == $cat_id)
 997             			{
 998             
 999             				$template->assign_block_vars("catrow.forumrow",	array(
1000             					'FORUM_NAME' => $forum_rows[$j]['forum_name'],
1001             					'FORUM_DESC' => $forum_rows[$j]['forum_desc'],
1002             					'ROW_COLOR' => $row_color,
1003             					'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
1004             					'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
1005             
1006             					'U_VIEWFORUM' => append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1007             					'U_FORUM_EDIT' => append_sid("admin_forums.$phpEx?mode=editforum&amp;" . POST_FORUM_URL . "=$forum_id"),
1008             					'U_FORUM_DELETE' => append_sid("admin_forums.$phpEx?mode=deleteforum&amp;" . POST_FORUM_URL . "=$forum_id"),
1009 rizwank 1.1 					'U_FORUM_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=-15&amp;" . POST_FORUM_URL . "=$forum_id"),
1010             					'U_FORUM_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=15&amp;" . POST_FORUM_URL . "=$forum_id"),
1011             					'U_FORUM_RESYNC' => append_sid("admin_forums.$phpEx?mode=forum_sync&amp;" . POST_FORUM_URL . "=$forum_id"))
1012             				);
1013             
1014             			}// if ... forumid == catid
1015             			
1016             		} // for ... forums
1017             
1018             	} // for ... categories
1019             
1020             }// if ... total_categories
1021             
1022             $template->pparse("body");
1023             
1024             include('./page_footer_admin.'.$phpEx);
1025             
1026             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2