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.11 2004/03/25 15:57:19 acydburn 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_ALL,
43 "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
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']);
237 // stripslashes needs to be run on this because slashes are added when the forum name is posted
239 $forumname = stripslashes($HTTP_POST_VARS['forumname'][$cat_id]);
250 // Show form to create/modify a forum
252 if ($mode == 'editforum')
254 // $newmode determines if we are going to INSERT or UPDATE after posting?
256 $l_title = $lang['Edit_forum'];
257 $newmode = 'modforum';
258 $buttonvalue = $lang['Update'];
260 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
262 $row = get_info('forum', $forum_id);
264 $cat_id = $row['cat_id'];
265 $forumname = $row['forum_name'];
266 $forumdesc = $row['forum_desc'];
267 $forumstatus = $row['forum_status'];
270 // start forum prune stuff.
272 if( $row['prune_enable'] )
274 $prune_enabled = "checked=\"checked\"";
276 FROM " . PRUNE_TABLE . "
277 WHERE forum_id = $forum_id";
278 if(!$pr_result = $db->sql_query($sql))
280 message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
283 $pr_row = $db->sql_fetchrow($pr_result);
292 $l_title = $lang['Create_forum'];
293 $newmode = 'createforum';
294 $buttonvalue = $lang['Create_forum'];
297 $forumstatus = FORUM_UNLOCKED;
302 $catlist = get_list('category', $cat_id, TRUE);
304 $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = "selected=\"selected\"" : $forumunlocked = "selected=\"selected\"";
306 // These two options ($lang['Status_unlocked'] and $lang['Status_locked']) seem to be missing from
307 // the language files.
308 $lang['Status_unlocked'] = isset($lang['Status_unlocked']) ? $lang['Status_unlocked'] : 'Unlocked';
309 $lang['Status_locked'] = isset($lang['Status_locked']) ? $lang['Status_locked'] : 'Locked';
311 $statuslist = "<option value=\"" . FORUM_UNLOCKED . "\" $forumunlocked>" . $lang['Status_unlocked'] . "</option>\n";
312 $statuslist .= "<option value=\"" . FORUM_LOCKED . "\" $forumlocked>" . $lang['Status_locked'] . "</option>\n";
314 $template->set_filenames(array(
315 "body" => "admin/forum_edit_body.tpl")
318 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode .'" /><input type="hidden" name="' . POST_FORUM_URL . '" value="' . $forum_id . '" />';
320 $template->assign_vars(array(
321 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
322 'S_HIDDEN_FIELDS' => $s_hidden_fields,
323 'S_SUBMIT_VALUE' => $buttonvalue,
324 'S_CAT_LIST' => $catlist,
325 'S_STATUS_LIST' => $statuslist,
326 'S_PRUNE_ENABLED' => $prune_enabled,
328 'L_FORUM_TITLE' => $l_title,
329 'L_FORUM_EXPLAIN' => $lang['Forum_edit_delete_explain'],
330 'L_FORUM_SETTINGS' => $lang['Forum_settings'],
331 'L_FORUM_NAME' => $lang['Forum_name'],
332 'L_CATEGORY' => $lang['Category'],
333 'L_FORUM_DESCRIPTION' => $lang['Forum_desc'],
334 'L_FORUM_STATUS' => $lang['Forum_status'],
335 'L_AUTO_PRUNE' => $lang['Forum_pruning'],
336 'L_ENABLED' => $lang['Enabled'],
337 'L_PRUNE_DAYS' => $lang['prune_days'],
338 'L_PRUNE_FREQ' => $lang['prune_freq'],
339 'L_DAYS' => $lang['Days'],
341 'PRUNE_DAYS' => ( isset($pr_row['prune_days']) ) ? $pr_row['prune_days'] : 7,
342 'PRUNE_FREQ' => ( isset($pr_row['prune_freq']) ) ? $pr_row['prune_freq'] : 1,
343 'FORUM_NAME' => $forumname,
344 'DESCRIPTION' => $forumdesc)
346 $template->pparse("body");
351 // Create a forum in the DB
353 if( trim($HTTP_POST_VARS['forumname']) == "" )
355 message_die(GENERAL_ERROR, "Can't create a forum without a name");
358 $sql = "SELECT MAX(forum_order) AS max_order
359 FROM " . FORUMS_TABLE . "
360 WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
361 if( !$result = $db->sql_query($sql) )
363 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
365 $row = $db->sql_fetchrow($result);
367 $max_order = $row['max_order'];
368 $next_order = $max_order + 10;
370 $sql = "SELECT MAX(forum_id) AS max_id
371 FROM " . FORUMS_TABLE;
372 if( !$result = $db->sql_query($sql) )
374 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
376 $row = $db->sql_fetchrow($result);
378 $max_id = $row['max_id'];
379 $next_id = $max_id + 1;
382 // Default permissions of public ::
386 while( list($field, $value) = each($forum_auth_ary) )
388 $field_sql .= ", $field";
389 $value_sql .= ", $value";
393 // There is no problem having duplicate forum names so we won't check for it.
394 $sql = "INSERT INTO " . FORUMS_TABLE . " (forum_id, forum_name, cat_id, forum_desc, forum_order, forum_status, prune_enable" . $field_sql . ")
395 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 . ")";
396 if( !$result = $db->sql_query($sql) )
398 message_die(GENERAL_ERROR, "Couldn't insert row in forums table", "", __LINE__, __FILE__, $sql);
401 if( $HTTP_POST_VARS['prune_enable'] )
404 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "")
406 message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
409 $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
410 VALUES('" . $next_id . "', " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
411 if( !$result = $db->sql_query($sql) )
413 message_die(GENERAL_ERROR, "Couldn't insert row in prune table", "", __LINE__, __FILE__, $sql);
417 $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>");
419 message_die(GENERAL_MESSAGE, $message);
424 // Modify a forum in the DB
425 if( isset($HTTP_POST_VARS['prune_enable']))
427 if( $HTTP_POST_VARS['prune_enable'] != 1 )
429 $HTTP_POST_VARS['prune_enable'] = 0;
433 $sql = "UPDATE " . FORUMS_TABLE . "
434 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']) . "
435 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
436 if( !$result = $db->sql_query($sql) )
438 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
441 if( $HTTP_POST_VARS['prune_enable'] == 1 )
443 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "" )
445 message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
449 FROM " . PRUNE_TABLE . "
450 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
451 if( !$result = $db->sql_query($sql) )
453 message_die(GENERAL_ERROR, "Couldn't get forum Prune Information","",__LINE__, __FILE__, $sql);
456 if( $db->sql_numrows($result) > 0 )
458 $sql = "UPDATE " . PRUNE_TABLE . "
459 SET prune_days = " . intval($HTTP_POST_VARS['prune_days']) . ", prune_freq = " . intval($HTTP_POST_VARS['prune_freq']) . "
460 WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
464 $sql = "INSERT INTO " . PRUNE_TABLE . " (forum_id, prune_days, prune_freq)
465 VALUES(" . intval($HTTP_POST_VARS[POST_FORUM_URL]) . ", " . intval($HTTP_POST_VARS['prune_days']) . ", " . intval($HTTP_POST_VARS['prune_freq']) . ")";
468 if( !$result = $db->sql_query($sql) )
470 message_die(GENERAL_ERROR, "Couldn't Update Forum Prune Information","",__LINE__, __FILE__, $sql);
474 $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>");
476 message_die(GENERAL_MESSAGE, $message);
481 // Create a category in the DB
482 if( trim($HTTP_POST_VARS['categoryname']) == '')
484 message_die(GENERAL_ERROR, "Can't create a category without a name");
487 $sql = "SELECT MAX(cat_order) AS max_order
488 FROM " . CATEGORIES_TABLE;
489 if( !$result = $db->sql_query($sql) )
491 message_die(GENERAL_ERROR, "Couldn't get order number from categories table", "", __LINE__, __FILE__, $sql);
493 $row = $db->sql_fetchrow($result);
495 $max_order = $row['max_order'];
496 $next_order = $max_order + 10;
499 // There is no problem having duplicate forum names so we won't check for it.
501 $sql = "INSERT INTO " . CATEGORIES_TABLE . " (cat_title, cat_order)
502 VALUES ('" . str_replace("\'", "''", $HTTP_POST_VARS['categoryname']) . "', $next_order)";
503 if( !$result = $db->sql_query($sql) )
505 message_die(GENERAL_ERROR, "Couldn't insert row in categories table", "", __LINE__, __FILE__, $sql);
508 $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>");
510 message_die(GENERAL_MESSAGE, $message);
516 // Show form to edit a category
519 $buttonvalue = $lang['Update'];
521 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
523 $row = get_info('category', $cat_id);
524 $cat_title = $row['cat_title'];
526 $template->set_filenames(array(
527 "body" => "admin/category_edit_body.tpl")
530 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="' . POST_CAT_URL . '" value="' . $cat_id . '" />';
532 $template->assign_vars(array(
533 'CAT_TITLE' => $cat_title,
535 'L_EDIT_CATEGORY' => $lang['Edit_Category'],
536 'L_EDIT_CATEGORY_EXPLAIN' => $lang['Edit_Category_explain'],
537 'L_CATEGORY' => $lang['Category'],
539 'S_HIDDEN_FIELDS' => $s_hidden_fields,
540 'S_SUBMIT_VALUE' => $buttonvalue,
541 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"))
544 $template->pparse("body");
548 // Modify a category in the DB
549 $sql = "UPDATE " . CATEGORIES_TABLE . "
550 SET cat_title = '" . str_replace("\'", "''", $HTTP_POST_VARS['cat_title']) . "'
551 WHERE cat_id = " . intval($HTTP_POST_VARS[POST_CAT_URL]);
552 if( !$result = $db->sql_query($sql) )
554 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
557 $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>");
559 message_die(GENERAL_MESSAGE, $message);
564 // Show form to delete a forum
565 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
567 $select_to = '<select name="to_id">';
568 $select_to .= "<option value=\"-1\"$s>" . $lang['Delete_all_posts'] . "</option>\n";
569 $select_to .= get_list('forum', $forum_id, 0);
570 $select_to .= '</select>';
572 $buttonvalue = $lang['Move_and_Delete'];
574 $newmode = 'movedelforum';
576 $foruminfo = get_info('forum', $forum_id);
577 $name = $foruminfo['forum_name'];
579 $template->set_filenames(array(
580 "body" => "admin/forum_delete_body.tpl")
583 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $forum_id . '" />';
585 $template->assign_vars(array(
588 'L_FORUM_DELETE' => $lang['Forum_delete'],
589 'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'],
590 'L_MOVE_CONTENTS' => $lang['Move_contents'],
591 'L_FORUM_NAME' => $lang['Forum_name'],
593 "S_HIDDEN_FIELDS" => $s_hidden_fields,
594 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
595 'S_SELECT_TO' => $select_to,
596 'S_SUBMIT_VALUE' => $buttonvalue)
599 $template->pparse("body");
604 // Move or delete a forum in the DB
606 $from_id = intval($HTTP_POST_VARS['from_id']);
607 $to_id = intval($HTTP_POST_VARS['to_id']);
608 $delete_old = intval($HTTP_POST_VARS['delete_old']);
610 // Either delete or move all posts in a forum
613 // Delete polls in this forum
614 $sql = "SELECT v.vote_id
615 FROM " . VOTE_DESC_TABLE . " v, " . TOPICS_TABLE . " t
616 WHERE t.forum_id = $from_id
617 AND v.topic_id = t.topic_id";
618 if (!($result = $db->sql_query($sql)))
620 message_die(GENERAL_ERROR, "Couldn't obtain list of vote ids", "", __LINE__, __FILE__, $sql);
623 if ($row = $db->sql_fetchrow($result))
628 $vote_ids = (($vote_ids != '') ? ', ' : '') . $row['vote_id'];
630 while ($row = $db->sql_fetchrow($result));
632 $sql = "DELETE FROM " . VOTE_DESC_TABLE . "
633 WHERE vote_id IN ($vote_ids)";
634 $db->sql_query($sql);
636 $sql = "DELETE FROM " . VOTE_RESULTS_TABLE . "
637 WHERE vote_id IN ($vote_ids)";
638 $db->sql_query($sql);
640 $sql = "DELETE FROM " . VOTE_USERS_TABLE . "
641 WHERE vote_id IN ($vote_ids)";
642 $db->sql_query($sql);
644 $db->sql_freeresult($result);
646 include($phpbb_root_path . "includes/prune.$phpEx");
647 prune($from_id, 0, true); // Delete everything from forum
652 FROM " . FORUMS_TABLE . "
653 WHERE forum_id IN ($from_id, $to_id)";
654 if( !$result = $db->sql_query($sql) )
656 message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
659 if($db->sql_numrows($result) != 2)
661 message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
663 $sql = "UPDATE " . TOPICS_TABLE . "
664 SET forum_id = $to_id
665 WHERE forum_id = $from_id";
666 if( !$result = $db->sql_query($sql) )
668 message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
670 $sql = "UPDATE " . POSTS_TABLE . "
671 SET forum_id = $to_id
672 WHERE forum_id = $from_id";
673 if( !$result = $db->sql_query($sql) )
675 message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
677 sync('forum', $to_id);
680 // Alter Mod level if appropriate - 2.0.4
681 $sql = "SELECT ug.user_id
682 FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug
683 WHERE a.forum_id <> $from_id
685 AND ug.group_id = a.group_id";
686 if( !$result = $db->sql_query($sql) )
688 message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
691 if ($row = $db->sql_fetchrow($result))
696 $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
698 while ($row = $db->sql_fetchrow($result));
700 $sql = "SELECT ug.user_id
701 FROM " . AUTH_ACCESS_TABLE . " a, " . USER_GROUP_TABLE . " ug
702 WHERE a.forum_id = $from_id
704 AND ug.group_id = a.group_id
705 AND ug.user_id NOT IN ($user_ids)";
706 if( !$result2 = $db->sql_query($sql) )
708 message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
711 if ($row = $db->sql_fetchrow($result2))
716 $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
718 while ($row = $db->sql_fetchrow($result2));
720 $sql = "UPDATE " . USERS_TABLE . "
721 SET user_level = " . USER . "
722 WHERE user_id IN ($user_ids)
723 AND user_level <> " . ADMIN;
724 $db->sql_query($sql);
726 $db->sql_freeresult($result);
729 $db->sql_freeresult($result2);
731 $sql = "DELETE FROM " . FORUMS_TABLE . "
732 WHERE forum_id = $from_id";
733 if( !$result = $db->sql_query($sql) )
735 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
738 $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
739 WHERE forum_id = $from_id";
740 if( !$result = $db->sql_query($sql) )
742 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
745 $sql = "DELETE FROM " . PRUNE_TABLE . "
746 WHERE forum_id = $from_id";
747 if( !$result = $db->sql_query($sql) )
749 message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
752 $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>");
754 message_die(GENERAL_MESSAGE, $message);
760 // Show form to delete a category
762 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
764 $buttonvalue = $lang['Move_and_Delete'];
765 $newmode = 'movedelcat';
766 $catinfo = get_info('category', $cat_id);
767 $name = $catinfo['cat_title'];
769 if ($catinfo['number'] == 1)
771 $sql = "SELECT count(*) as total
772 FROM ". FORUMS_TABLE;
773 if( !$result = $db->sql_query($sql) )
775 message_die(GENERAL_ERROR, "Couldn't get Forum count", "", __LINE__, __FILE__, $sql);
777 $count = $db->sql_fetchrow($result);
778 $count = $count['total'];
782 message_die(GENERAL_ERROR, $lang['Must_delete_forums']);
786 $select_to = $lang['Nowhere_to_move'];
791 $select_to = '<select name="to_id">';
792 $select_to .= get_list('category', $cat_id, 0);
793 $select_to .= '</select>';
796 $template->set_filenames(array(
797 "body" => "admin/forum_delete_body.tpl")
800 $s_hidden_fields = '<input type="hidden" name="mode" value="' . $newmode . '" /><input type="hidden" name="from_id" value="' . $cat_id . '" />';
802 $template->assign_vars(array(
805 'L_FORUM_DELETE' => $lang['Forum_delete'],
806 'L_FORUM_DELETE_EXPLAIN' => $lang['Forum_delete_explain'],
807 'L_MOVE_CONTENTS' => $lang['Move_contents'],
808 'L_FORUM_NAME' => $lang['Forum_name'],
810 'S_HIDDEN_FIELDS' => $s_hidden_fields,
811 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
812 'S_SELECT_TO' => $select_to,
813 'S_SUBMIT_VALUE' => $buttonvalue)
816 $template->pparse("body");
821 // Move or delete a category in the DB
823 $from_id = intval($HTTP_POST_VARS['from_id']);
824 $to_id = intval($HTTP_POST_VARS['to_id']);
829 FROM " . CATEGORIES_TABLE . "
830 WHERE cat_id IN ($from_id, $to_id)";
831 if( !$result = $db->sql_query($sql) )
833 message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
835 if($db->sql_numrows($result) != 2)
837 message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
840 $sql = "UPDATE " . FORUMS_TABLE . "
842 WHERE cat_id = $from_id";
843 if( !$result = $db->sql_query($sql) )
845 message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
849 $sql = "DELETE FROM " . CATEGORIES_TABLE ."
850 WHERE cat_id = $from_id";
852 if( !$result = $db->sql_query($sql) )
854 message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
857 $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>");
859 message_die(GENERAL_MESSAGE, $message);
865 // Change order of forums in the DB
867 $move = intval($HTTP_GET_VARS['move']);
868 $forum_id = intval($HTTP_GET_VARS[POST_FORUM_URL]);
870 $forum_info = get_info('forum', $forum_id);
872 $cat_id = $forum_info['cat_id'];
874 $sql = "UPDATE " . FORUMS_TABLE . "
875 SET forum_order = forum_order + $move
876 WHERE forum_id = $forum_id";
877 if( !$result = $db->sql_query($sql) )
879 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
882 renumber_order('forum', $forum_info['cat_id']);
889 // Change order of categories in the DB
891 $move = intval($HTTP_GET_VARS['move']);
892 $cat_id = intval($HTTP_GET_VARS[POST_CAT_URL]);
894 $sql = "UPDATE " . CATEGORIES_TABLE . "
895 SET cat_order = cat_order + $move
896 WHERE cat_id = $cat_id";
897 if( !$result = $db->sql_query($sql) )
899 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
902 renumber_order('category');
908 sync('forum', intval($HTTP_GET_VARS[POST_FORUM_URL]));
914 message_die(GENERAL_MESSAGE, $lang['No_mode']);
918 if ($show_index != TRUE)
920 include('./page_footer_admin.'.$phpEx);
928 $template->set_filenames(array(
929 "body" => "admin/forum_admin_body.tpl")
932 $template->assign_vars(array(
933 'S_FORUM_ACTION' => append_sid("admin_forums.$phpEx"),
934 'L_FORUM_TITLE' => $lang['Forum_admin'],
935 'L_FORUM_EXPLAIN' => $lang['Forum_admin_explain'],
936 'L_CREATE_FORUM' => $lang['Create_forum'],
937 'L_CREATE_CATEGORY' => $lang['Create_category'],
938 'L_EDIT' => $lang['Edit'],
939 'L_DELETE' => $lang['Delete'],
940 'L_MOVE_UP' => $lang['Move_up'],
941 'L_MOVE_DOWN' => $lang['Move_down'],
942 'L_RESYNC' => $lang['Resync'])
945 $sql = "SELECT cat_id, cat_title, cat_order
946 FROM " . CATEGORIES_TABLE . "
948 if( !$q_categories = $db->sql_query($sql) )
950 message_die(GENERAL_ERROR, "Could not query categories list", "", __LINE__, __FILE__, $sql);
953 if( $total_categories = $db->sql_numrows($q_categories) )
955 $category_rows = $db->sql_fetchrowset($q_categories);
958 FROM " . FORUMS_TABLE . "
959 ORDER BY cat_id, forum_order";
960 if(!$q_forums = $db->sql_query($sql))
962 message_die(GENERAL_ERROR, "Could not query forums information", "", __LINE__, __FILE__, $sql);
965 if( $total_forums = $db->sql_numrows($q_forums) )
967 $forum_rows = $db->sql_fetchrowset($q_forums);
971 // Okay, let's build the index
975 for($i = 0; $i < $total_categories; $i++)
977 $cat_id = $category_rows[$i]['cat_id'];
979 $template->assign_block_vars("catrow", array(
980 'S_ADD_FORUM_SUBMIT' => "addforum[$cat_id]",
981 'S_ADD_FORUM_NAME' => "forumname[$cat_id]",
984 'CAT_DESC' => $category_rows[$i]['cat_title'],
986 'U_CAT_EDIT' => append_sid("admin_forums.$phpEx?mode=editcat&" . POST_CAT_URL . "=$cat_id"),
987 'U_CAT_DELETE' => append_sid("admin_forums.$phpEx?mode=deletecat&" . POST_CAT_URL . "=$cat_id"),
988 'U_CAT_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=cat_order&move=-15&" . POST_CAT_URL . "=$cat_id"),
989 'U_CAT_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=cat_order&move=15&" . POST_CAT_URL . "=$cat_id"),
990 'U_VIEWCAT' => append_sid($phpbb_root_path."index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
993 for($j = 0; $j < $total_forums; $j++)
995 $forum_id = $forum_rows[$j]['forum_id'];
997 if ($forum_rows[$j]['cat_id'] == $cat_id)
1000 $template->assign_block_vars("catrow.forumrow", array(
1001 'FORUM_NAME' => $forum_rows[$j]['forum_name'],
1002 'FORUM_DESC' => $forum_rows[$j]['forum_desc'],
1003 'ROW_COLOR' => $row_color,
1004 'NUM_TOPICS' => $forum_rows[$j]['forum_topics'],
1005 'NUM_POSTS' => $forum_rows[$j]['forum_posts'],
1007 'U_VIEWFORUM' => append_sid($phpbb_root_path."viewforum.$phpEx?" . POST_FORUM_URL . "=$forum_id"),
1008 'U_FORUM_EDIT' => append_sid("admin_forums.$phpEx?mode=editforum&" . POST_FORUM_URL . "=$forum_id"),
1009 'U_FORUM_DELETE' => append_sid("admin_forums.$phpEx?mode=deleteforum&" . POST_FORUM_URL . "=$forum_id"),
1010 'U_FORUM_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=forum_order&move=-15&" . POST_FORUM_URL . "=$forum_id"),
1011 'U_FORUM_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=forum_order&move=15&" . POST_FORUM_URL . "=$forum_id"),
1012 'U_FORUM_RESYNC' => append_sid("admin_forums.$phpEx?mode=forum_sync&" . POST_FORUM_URL . "=$forum_id"))
1015 }// if ... forumid == catid
1019 } // for ... categories
1021 }// if ... total_categories
1023 $template->pparse("body");
1025 include('./page_footer_admin.'.$phpEx);