2 /***************************************************************************
5 * begin : Thursday, Jul 12, 2001
6 * copyright : (C) 2001 The phpBB Group
7 * email : support@phpbb.com
9 * $Id: admin_forums.php,v 1.40.2.13 2006/03/09 21:55:09 grahamje Exp $
11 ***************************************************************************/
13 /***************************************************************************
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.
20 ***************************************************************************/
22 define('IN_PHPBB', 1);
24 if( !empty($setmodules) )
26 $file = basename(__FILE__);
27 $module['Forums']['Manage'] = $file;
32 // Load default header
34 $phpbb_root_path = "./../";
35 require($phpbb_root_path . 'extension.inc');
36 require('./pagestart.' . $phpEx);
37 include($phpbb_root_path . 'includes/functions_admin.'.$phpEx);
39 $forum_auth_ary = array(
40 "auth_view" => AUTH_ALL,
41 "auth_read" => AUTH_ALL,
42 "auth_post" => AUTH_REG,
43 "auth_reply" => AUTH_REG,
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
55 if( isset($HTTP_POST_VARS['mode']) || isset($HTTP_GET_VARS['mode']) )
57 $mode = ( isset($HTTP_POST_VARS['mode']) ) ? $HTTP_POST_VARS['mode'] : $HTTP_GET_VARS['mode'];
58 $mode = htmlspecialchars($mode);
66 // Begin function block
68 function get_info($mode, $id)
75 $table = CATEGORIES_TABLE;
77 $namefield = 'cat_title';
81 $table = FORUMS_TABLE;
82 $idfield = 'forum_id';
83 $namefield = 'forum_name';
87 message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
90 $sql = "SELECT count(*) as total
92 if( !$result = $db->sql_query($sql) )
94 message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
96 $count = $db->sql_fetchrow($result);
97 $count = $count['total'];
101 WHERE $idfield = $id";
103 if( !$result = $db->sql_query($sql) )
105 message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
108 if( $db->sql_numrows($result) != 1 )
110 message_die(GENERAL_ERROR, "Forum/Category doesn't exist or multiple forums/categories with ID $id", "", __LINE__, __FILE__);
113 $return = $db->sql_fetchrow($result);
114 $return['number'] = $count;
118 function get_list($mode, $id, $select)
125 $table = CATEGORIES_TABLE;
127 $namefield = 'cat_title';
131 $table = FORUMS_TABLE;
132 $idfield = 'forum_id';
133 $namefield = 'forum_name';
137 message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
145 $sql .= " WHERE $idfield <> $id";
148 if( !$result = $db->sql_query($sql) )
150 message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
155 while( $row = $db->sql_fetchrow($result) )
158 if ($row[$idfield] == $id)
160 $s = " selected=\"selected\"";
162 $catlist .= "<option value=\"$row[$idfield]\"$s>" . $row[$namefield] . "</option>\n";
168 function renumber_order($mode, $cat = 0)
175 $table = CATEGORIES_TABLE;
177 $orderfield = 'cat_order';
182 $table = FORUMS_TABLE;
183 $idfield = 'forum_id';
184 $orderfield = 'forum_order';
185 $catfield = 'cat_id';
189 message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
193 $sql = "SELECT * FROM $table";
196 $sql .= " WHERE $catfield = $cat";
198 $sql .= " ORDER BY $orderfield ASC";
201 if( !$result = $db->sql_query($sql) )
203 message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
209 while( $row = $db->sql_fetchrow($result) )
211 $sql = "UPDATE $table
213 WHERE $idfield = " . $row[$idfield];
214 if( !$db->sql_query($sql) )
216 message_die(GENERAL_ERROR, "Couldn't update order fields", "", __LINE__, __FILE__, $sql);
223 // End function block
224 // ------------------
227 // Begin program proper
229 if( isset($HTTP_POST_VARS['addforum']) || isset($HTTP_POST_VARS['addcategory']) )
231 $mode = ( isset($HTTP_POST_VARS['addforum']) ) ? "addforum" : "addcat";
233 if( $mode == "addforum" )
235 list($cat_id) = each($HTTP_POST_VARS['addforum']);
236 $cat_id = intval($cat_id);
238 // stripslashes needs to be run on this because slashes are added when the forum name is posted
240 $forumname = stripslashes($HTTP_POST_VARS['forumname'][$cat_id]);
251 // Show form to create/modify a forum
253 if ($mode == 'editforum')
255 // $newmode determines if we are going to INSERT or UPDATE after posting?
257 $l_title = $lang['Edit_forum'];
258 $newmode = 'modforum';
259 $buttonvalue = $lang['Update'];
261 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
263 $row = get_info('forum', $forum_id);
265 $cat_id = $row['cat_id'];
266 $forumname = $row['forum_name'];
267 $forumdesc = $row['forum_desc'];
268 $forumstatus = $row['forum_status'];
271 // start forum prune stuff.
273 if( $row['prune_enable'] )
275 $prune_enabled = "checked=\"checked\"";
277 FROM " . PRUNE_TABLE . "
278 WHERE forum_id = $forum_id";
279 if(!$pr_result = $db->sql_query($sql))
281 message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
284 $pr_row = $db->sql_fetchrow($pr_result);
293 $l_title = $lang['Create_forum'];
294 $newmode = 'createforum';
295 $buttonvalue = $lang['Create_forum'];
298 $forumstatus = FORUM_UNLOCKED;
303 $catlist = get_list('category', $cat_id, TRUE);
305 $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = "selected=\"selected\"" : $forumunlocked = "selected=\"selected\"";
307 // These two options ($lang['Status_unlocked'] and $lang['Status_locked']) seem to be missing from
308 // the language files.
309 $lang['Status_unlocked'] = isset($lang['Status_unlocked']) ? $lang['Status_unlocked'] : 'Unlocked';
310 $lang['Status_locked'] = isset($lang['Status_locked']) ? $lang['Status_locked'] : 'Locked';
312 $statuslist = "<option value=\"" . FORUM_UNLOCKED . "\" $forumunlocked>" . $lang['Status_unlocked'] . "</option>\n";
313 $statuslist .= "<option value=\"" . FORUM_LOCKED . "\" $forumlocked>" . $lang['Status_locked'] . "</option>\n";
315 $template->set_filenames(array(
316 "body" => "admin/forum_edit_body.tpl")
319 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode .'" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
321 $template->assign_vars(array(
322 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
323 'S_HIDDEN_FIELDS' => $s_hidden_fields,
324 'S_SUBMIT_VALUE' => $buttonvalue,
325 'S_CAT_LIST' => $catlist,
326 'S_STATUS_LIST' => $statuslist,
327 'S_PRUNE_ENABLED' => $prune_enabled,
329 'L_FORUM_TITLE' => $l_title,
330 'L_FORUM_EXPLAIN' => $lang['Forum_edit_delete_explain'],
331 'L_FORUM_SETTINGS' => $lang['Forum_settings'],
332 'L_FORUM_NAME' => $lang['Forum_name'],
333 'L_CATEGORY' => $lang['Category'],
334 'L_FORUM_DESCRIPTION' => $lang['Forum_desc'],
335 'L_FORUM_STATUS' => $lang['Forum_status'],
336 'L_AUTO_PRUNE' => $lang['Forum_pruning'],
337 'L_ENABLED' => $lang['Enabled'],
338 'L_PRUNE_DAYS' => $lang['prune_days'],
339 'L_PRUNE_FREQ' => $lang['prune_freq'],
340 'L_DAYS' => $lang['Days'],
342 'PRUNE_DAYS' => ( isset($pr_row['prune_days']) ) ? $pr_row['prune_days'] : 7,
343 'PRUNE_FREQ' => ( isset($pr_row['prune_freq']) ) ? $pr_row['prune_freq'] : 1,
344 'FORUM_NAME' => $forumname,
345 'DESCRIPTION' => $forumdesc)
347 $template->pparse("body");
352 // Create a forum in the DB
354 if( trim($HTTP_POST_VARS['forumname']) == "" )
356 message_die(GENERAL_ERROR, "Can't create a forum without a name");
359 $sql = "SELECT MAX(forum_order) AS max_order
360 FROM " . FORUMS_TABLE . "
361 WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
362 if( !$result = $db->sql_query($sql) )
364 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
366 $row = $db->sql_fetchrow($result);
368 $max_order = $row['max_order'];
369 $next_order = $max_order + 10;
371 $sql = "SELECT MAX(forum_id) AS max_id
372 FROM " . FORUMS_TABLE;
373 if( !$result = $db->sql_query($sql) )
375 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
377 $row = $db->sql_fetchrow($result);
379 $max_id = $row['max_id'];
380 $next_id = $max_id + 1;
383 // Default permissions of public ::
387 while( list($field, $value) = each($forum_auth_ary) )
389 $field_sql .= ", $field";
390 $value_sql .= ", $value";
394 // There is no problem having duplicate forum names so we won't check for it.
395 $sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ")
396 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 . ")";
397 if( !$result = $db->sql_query($sql) )
399 message_die(GENERAL_ERROR, "Couldn't insert row in forums table", "", __LINE__, __FILE__, $sql);
402 if( $HTTP_POST_VARS['prune_enable'] )
405 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "")
407 message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
410 $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
411 VALUES('" . $next_id . "', " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
412 if( !$result = $db->sql_query($sql) )
414 message_die(GENERAL_ERROR, "Couldn't insert row in prune table", "", __LINE__, __FILE__, $sql);
418 $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>");
420 message_die(GENERAL_MESSAGE, $message);
425 // Modify a forum in the DB
426 if( isset($HTTP_POST_VARS['prune_enable']))
428 if( $HTTP_POST_VARS['prune_enable'] != 1 )
430 $HTTP_POST_VARS['prune_enable'] = 0;
434 $sql = "UPDATE " . FORUMS_TABLE . "
435 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']) . "
436 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
437 if( !$result = $db->sql_query($sql) )
439 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
442 if( $HTTP_POST_VARS['prune_enable'] == 1 )
444 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "" )
446 message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
450 FROM " . PRUNE_TABLE . "
451 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
452 if( !$result = $db->sql_query($sql) )
454 message_die(GENERAL_ERROR, "Couldn't get forum Prune Information","",__LINE__, __FILE__, $sql);
457 if( $db->sql_numrows($result) > 0 )
459 $sql = "UPDATE " . PRUNE_TABLE . "
460 SET prune_days = " . intval($HTTP_POST_VARS['prune_days']) . ", prune_freq = " . intval($HTTP_POST_VARS['prune_freq']) . "
461 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
465 $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
466 VALUES(" . intval($HTTP_POST_VARS[POST_FORUM_URL]) . ", " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
469 if( !$result = $db->sql_query($sql) )
471 message_die(GENERAL_ERROR, "Couldn't Update Forum Prune Information","",__LINE__, __FILE__, $sql);
475 $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>");
477 message_die(GENERAL_MESSAGE, $message);
482 // Create a category in the DB
483 if( trim($HTTP_POST_VARS['categoryname']) == '')
485 message_die(GENERAL_ERROR, "Can't create a category without a name");
488 $sql = "SELECT MAX(cat_order) AS max_order
489 FROM " . CATEGORIES_TABLE;
490 if( !$result = $db->sql_query($sql) )
492 message_die(GENERAL_ERROR, "Couldn't get order number from categories table", "", __LINE__, __FILE__, $sql);
494 $row = $db->sql_fetchrow($result);
496 $max_order = $row['max_order'];
497 $next_order = $max_order + 10;
500 // There is no problem having duplicate forum names so we won't check for it.
502 $sql = "INSERT INTO " . CATEGORIES_TABLE . " (cat_title, cat_order)
503 VALUES ('" . str_replace("\'", "''", $HTTP_POST_VARS['categoryname']) . "', $next_order)";
504 if( !$result = $db->sql_query($sql) )
506 message_die(GENERAL_ERROR, "Couldn't insert row in categories table", "", __LINE__, __FILE__, $sql);
509 $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>");
511 message_die(GENERAL_MESSAGE, $message);
517 // Show form to edit a category
520 $buttonvalue = $lang['Update'];
522 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
524 $row = get_info('category', $cat_id);
525 $cat_title = $row['cat_title'];
527 $template->set_filenames(array(
528 "body" => "admin/category_edit_body.tpl")
531 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="' . POST_CAT_URL . '" value="' . $cat_id . '" />';
533 $template->assign_vars(array(
534 'CAT_TITLE' => $cat_title,
536 'L_EDIT_CATEGORY' => $lang['Edit_Category'],
537 'L_EDIT_CATEGORY_EXPLAIN' => $lang['Edit_Category_explain'],
538 'L_CATEGORY' => $lang['Category'],
540 'S_HIDDEN_FIELDS' => $s_hidden_fields,
541 'S_SUBMIT_VALUE' => $buttonvalue,
542 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"))
545 $template->pparse("body");
549 // Modify a category in the DB
550 $sql = "UPDATE " . CATEGORIES_TABLE . "
551 SET cat_title = '" . str_replace("\'", "''", $HTTP_POST_VARS['cat_title']) . "'
552 WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
553 if( !$result = $db->sql_query($sql) )
555 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
558 $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>");
560 message_die(GENERAL_MESSAGE, $message);
565 // Show form to delete a forum
566 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
568 $select_to = '<select name="to_id">';
569 $select_to .= "<option value=\"-1\"$s>" . $lang['Delete_all_posts'] . "</option>\n";
570 $select_to .= get_list('forum', $forum_id, 0);
571 $select_to .= '</select>';
573 $buttonvalue = $lang['Move_and_Delete'];
575 $newmode = 'movedelforum';
577 $foruminfo = get_info('forum', $forum_id);
578 $name = $foruminfo['forum_name'];
580 $template->set_filenames(array(
581 "body" => "admin/forum_delete_body.tpl")
584 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $forum_id . '" />';
586 $template->assign_vars(array(
589 'L_FORUM_DELETE' => $lang['Forum_delete'],
590 'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'],
591 'L_MOVE_CONTENTS' => $lang['Move_contents'],
592 'L_FORUM_NAME' => $lang['Forum_name'],
594 "S_HIDDEN_FIELDS" => $s_hidden_fields,
595 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
596 'S_SELECT_TO' => $select_to,
597 'S_SUBMIT_VALUE' => $buttonvalue)
600 $template->pparse("body");
605 // Move or delete a forum in the DB
607 $from_id = intval($HTTP_POST_VARS['from_id']);
608 $to_id = intval($HTTP_POST_VARS['to_id']);
609 $delete_old = intval($HTTP_POST_VARS['delete_old']);
611 // Either delete or move all posts in a forum
614 // Delete polls in this forum
615 $sql = "SELECT v.vote_id
616 FROM " . VOTE_DESC_TABLE . " v, " . TOPICS_TABLE . " t
617 WHERE t.forum_id = $from_id
618 AND v.topic_id = t.topic_id";
619 if (!($result = $db->sql_query($sql)))
621 message_die(GENERAL_ERROR, "Couldn't obtain list of vote ids", "", __LINE__, __FILE__, $sql);
624 if ($row = $db->sql_fetchrow($result))
629 $vote_ids = (($vote_ids != '') ? ', ' : '') . $row['vote_id'];
631 while ($row = $db->sql_fetchrow($result));
633 $sql = "DELETE FROM " . VOTE_DESC_TABLE . "
634 WHERE vote_id IN ($vote_ids)";
635 $db->sql_query($sql);
637 $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
638 WHERE vote_id IN ($vote_ids)";
639 $db->sql_query($sql);
641 $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
642 WHERE vote_id IN ($vote_ids)";
643 $db->sql_query($sql);
645 $db->sql_freeresult($result);
647 include($phpbb_root_path . "includes/prune.$phpEx");
648 prune($from_id, 0, true); // Delete everything from forum
653 FROM " . FORUMS_TABLE . "
654 WHERE forum_id IN ($from_id, $to_id)";
655 if( !$result = $db->sql_query($sql) )
657 message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
660 if($db->sql_numrows($result) != 2)
662 message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
664 $sql = "UPDATE " . TOPICS_TABLE . "
665 SET forum_id = $to_id
666 WHERE forum_id = $from_id";
667 if( !$result = $db->sql_query($sql) )
669 message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
671 $sql = "UPDATE " . POSTS_TABLE . "
672 SET forum_id = $to_id
673 WHERE forum_id = $from_id";
674 if( !$result = $db->sql_query($sql) )
676 message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
678 sync('forum', $to_id);
681 // Alter Mod level if appropriate - 2.0.4
682 $sql = "SELECT ug.user_id
683 FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug
684 WHERE a.forum_id <> $from_id
686 AND ug.group_id = a.group_id";
687 if( !$result = $db->sql_query($sql) )
689 message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
692 if ($row = $db->sql_fetchrow($result))
697 $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
699 while ($row = $db->sql_fetchrow($result));
701 $sql = "SELECT ug.user_id
702 FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug
703 WHERE a.forum_id = $from_id
705 AND ug.group_id = a.group_id
706 AND ug.user_id NOT IN ($user_ids)";
707 if( !$result2 = $db->sql_query($sql) )
709 message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
712 if ($row = $db->sql_fetchrow($result2))
717 $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
719 while ($row = $db->sql_fetchrow($result2));
721 $sql = "UPDATE " . USERS_TABLE . "
722 SET user_level = " . USER . "
723 WHERE user_id IN ($user_ids)
724 AND user_level <> " . ADMIN;
725 $db->sql_query($sql);
727 $db->sql_freeresult($result);
730 $db->sql_freeresult($result2);
732 $sql = "DELETE FROM " . FORUMS_TABLE . "
733 WHERE forum_id = $from_id";
734 if( !$result = $db->sql_query($sql) )
736 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
739 $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
740 WHERE forum_id = $from_id";
741 if( !$result = $db->sql_query($sql) )
743 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
746 $sql = "DELETE FROM " . PRUNE_TABLE . "
747 WHERE forum_id = $from_id";
748 if( !$result = $db->sql_query($sql) )
750 message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
753 $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>");
755 message_die(GENERAL_MESSAGE, $message);
761 // Show form to delete a category
763 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
765 $buttonvalue = $lang['Move_and_Delete'];
766 $newmode = 'movedelcat';
767 $catinfo = get_info('category', $cat_id);
768 $name = $catinfo['cat_title'];
770 if ($catinfo['number'] == 1)
772 $sql = "SELECT count(*) as total
773 FROM ". FORUMS_TABLE;
774 if( !$result = $db->sql_query($sql) )
776 message_die(GENERAL_ERROR, "Couldn't get Forum count", "", __LINE__, __FILE__, $sql);
778 $count = $db->sql_fetchrow($result);
779 $count = $count['total'];
783 message_die(GENERAL_ERROR, $lang['Must_delete_forums']);
787 $select_to = $lang['Nowhere_to_move'];
792 $select_to = '<select name="to_id">';
793 $select_to .= get_list('category', $cat_id, 0);
794 $select_to .= '</select>';
797 $template->set_filenames(array(
798 "body" => "admin/forum_delete_body.tpl")
801 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $cat_id . '" />';
803 $template->assign_vars(array(
806 'L_FORUM_DELETE' => $lang['Forum_delete'],
807 'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'],
808 'L_MOVE_CONTENTS' => $lang['Move_contents'],
809 'L_FORUM_NAME' => $lang['Forum_name'],
811 'S_HIDDEN_FIELDS' => $s_hidden_fields,
812 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
813 'S_SELECT_TO' => $select_to,
814 'S_SUBMIT_VALUE' => $buttonvalue)
817 $template->pparse("body");
822 // Move or delete a category in the DB
824 $from_id = intval($HTTP_POST_VARS['from_id']);
825 $to_id = intval($HTTP_POST_VARS['to_id']);
830 FROM " . CATEGORIES_TABLE . "
831 WHERE cat_id IN ($from_id, $to_id)";
832 if( !$result = $db->sql_query($sql) )
834 message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
836 if($db->sql_numrows($result) != 2)
838 message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
841 $sql = "UPDATE " . FORUMS_TABLE . "
843 WHERE cat_id = $from_id";
844 if( !$result = $db->sql_query($sql) )
846 message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
850 $sql = "DELETE FROM " . CATEGORIES_TABLE ."
851 WHERE cat_id = $from_id";
853 if( !$result = $db->sql_query($sql) )
855 message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
858 $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>");
860 message_die(GENERAL_MESSAGE, $message);
866 // Change order of forums in the DB
868 $move = intval($HTTP_GET_VARS['move']);
869 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
871 $forum_info = get_info('forum', $forum_id);
873 $cat_id = $forum_info['cat_id'];
875 $sql = "UPDATE " . FORUMS_TABLE . "
876 SET forum_order = forum_order + $move
877 WHERE forum_id = $forum_id";
878 if( !$result = $db->sql_query($sql) )
880 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
883 renumber_order('forum', $forum_info['cat_id']);
890 // Change order of categories in the DB
892 $move = intval($HTTP_GET_VARS['move']);
893 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
895 $sql = "UPDATE " . CATEGORIES_TABLE . "
896 SET cat_order = cat_order + $move
897 WHERE cat_id = $cat_id";
898 if( !$result = $db->sql_query($sql) )
900 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
903 renumber_order('category');
909 sync('forum', intval($HTTP_GET_VARS[POST_FORUM_URL]));
915 message_die(GENERAL_MESSAGE, $lang['No_mode']);
919 if ($show_index != TRUE)
921 include('./page_footer_admin.'.$phpEx);
929 $template->set_filenames(array(
930 "body" => "admin/forum_admin_body.tpl")
933 $template->assign_vars(array(
934 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
935 'L_FORUM_TITLE' => $lang['Forum_admin'],
936 'L_FORUM_EXPLAIN' => $lang['Forum_admin_explain'],
937 'L_CREATE_FORUM' => $lang['Create_forum'],
938 'L_CREATE_CATEGORY' => $lang['Create_category'],
939 'L_EDIT' => $lang['Edit'],
940 'L_DELETE' => $lang['Delete'],
941 'L_MOVE_UP' => $lang['Move_up'],
942 'L_MOVE_DOWN' => $lang['Move_down'],
943 'L_RESYNC' => $lang['Resync'])
946 $sql = "SELECT cat_id, cat_title, cat_order
947 FROM " . CATEGORIES_TABLE . "
949 if( !$q_categories = $db->sql_query($sql) )
951 message_die(GENERAL_ERROR, "Could not query categories list", "", __LINE__, __FILE__, $sql);
954 if( $total_categories = $db->sql_numrows($q_categories) )
956 $category_rows = $db->sql_fetchrowset($q_categories);
959 FROM " . FORUMS_TABLE . "
960 ORDER BY cat_id, forum_order";
961 if(!$q_forums = $db->sql_query($sql))
963 message_die(GENERAL_ERROR, "Could not query forums information", "", __LINE__, __FILE__, $sql);
966 if( $total_forums = $db->sql_numrows($q_forums) )
968 $forum_rows = $db->sql_fetchrowset($q_forums);
972 // Okay, let's build the index
976 for($i = 0; $i < $total_categories; $i++)
978 $cat_id = $category_rows[$i]['cat_id'];
980 $template->assign_block_vars("catrow", array(
981 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]",
982 'S_ADD_FORUM_NAME' => "forumname[$cat_id]",
985 'CAT_DESC' => $category_rows[$i]['cat_title'],
987 'U_CAT_EDIT' => append_sid("admin_forums.$phpEx?mode=editcat&" . POST_CAT_URL . "=$cat_id"),
988 'U_CAT_DELETE' => append_sid("admin_forums.$phpEx?mode=deletecat&" . POST_CAT_URL . "=$cat_id"),
989 'U_CAT_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=cat_order&move=-15&" . POST_CAT_URL . "=$cat_id"),
990 'U_CAT_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=cat_order&move=15&" . POST_CAT_URL . "=$cat_id"),
991 'U_VIEWCAT' => append_sid($phpbb_root_path."index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
994 for($j = 0; $j < $total_forums; $j++)
996 $forum_id = $forum_rows[$j]['forum_id'];
998 if ($forum_rows[$j]['cat_id'] == $cat_id)
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'],
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&" . POST_FORUM_URL . "=$forum_id"),
1010 'U_FORUM_DELETE' => append_sid("admin_forums.$phpEx?mode=deleteforum&" . POST_FORUM_URL . "=$forum_id"),
1011 'U_FORUM_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=forum_order&move=-15&" . POST_FORUM_URL . "=$forum_id"),
1012 'U_FORUM_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=forum_order&move=15&" . POST_FORUM_URL . "=$forum_id"),
1013 'U_FORUM_RESYNC' => append_sid("admin_forums.$phpEx?mode=forum_sync&" . POST_FORUM_URL . "=$forum_id"))
1016 }// if ... forumid == catid
1020 } // for ... categories
1022 }// if ... total_categories
1024 $template->pparse("body");
1026 include('./page_footer_admin.'.$phpEx);