]> git.vanrenterghem.biz Git - www.vanrenterghem.biz.git/blob - phpBB2_old/admin/admin_forums.php
3340c720a6c250794faf386ebad640a239f81c4e
[www.vanrenterghem.biz.git] / phpBB2_old / admin / admin_forums.php
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.11 2004/03/25 15:57:19 acydburn Exp $
10  *
11  ***************************************************************************/
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  ***************************************************************************/
22 define('IN_PHPBB', 1);
24 if( !empty($setmodules) )
25 {
26         $file = basename(__FILE__);
27         $module['Forums']['Manage'] = $file;
28         return;
29 }
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);
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
50 );
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         $mode = htmlspecialchars($mode);
59 }
60 else
61 {
62         $mode = "";
63 }
65 // ------------------
66 // Begin function block
67 //
68 function get_info($mode, $id)
69 {
70         global $db;
72         switch($mode)
73         {
74                 case 'category':
75                         $table = CATEGORIES_TABLE;
76                         $idfield = 'cat_id';
77                         $namefield = 'cat_title';
78                         break;
80                 case 'forum':
81                         $table = FORUMS_TABLE;
82                         $idfield = 'forum_id';
83                         $namefield = 'forum_name';
84                         break;
86                 default:
87                         message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
88                         break;
89         }
90         $sql = "SELECT count(*) as total
91                 FROM $table";
92         if( !$result = $db->sql_query($sql) )
93         {
94                 message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
95         }
96         $count = $db->sql_fetchrow($result);
97         $count = $count['total'];
99         $sql = "SELECT *
100                 FROM $table
101                 WHERE $idfield = $id"; 
103         if( !$result = $db->sql_query($sql) )
104         {
105                 message_die(GENERAL_ERROR, "Couldn't get Forum/Category information", "", __LINE__, __FILE__, $sql);
106         }
108         if( $db->sql_numrows($result) != 1 )
109         {
110                 message_die(GENERAL_ERROR, "Forum/Category doesn't exist or multiple forums/categories with ID $id", "", __LINE__, __FILE__);
111         }
113         $return = $db->sql_fetchrow($result);
114         $return['number'] = $count;
115         return $return;
118 function get_list($mode, $id, $select)
120         global $db;
122         switch($mode)
123         {
124                 case 'category':
125                         $table = CATEGORIES_TABLE;
126                         $idfield = 'cat_id';
127                         $namefield = 'cat_title';
128                         break;
130                 case 'forum':
131                         $table = FORUMS_TABLE;
132                         $idfield = 'forum_id';
133                         $namefield = 'forum_name';
134                         break;
136                 default:
137                         message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
138                         break;
139         }
141         $sql = "SELECT *
142                 FROM $table";
143         if( $select == 0 )
144         {
145                 $sql .= " WHERE $idfield <> $id";
146         }
148         if( !$result = $db->sql_query($sql) )
149         {
150                 message_die(GENERAL_ERROR, "Couldn't get list of Categories/Forums", "", __LINE__, __FILE__, $sql);
151         }
153         $cat_list = "";
155         while( $row = $db->sql_fetchrow($result) )
156         {
157                 $s = "";
158                 if ($row[$idfield] == $id)
159                 {
160                         $s = " selected=\"selected\"";
161                 }
162                 $catlist .= "<option value=\"$row[$idfield]\"$s>" . $row[$namefield] . "</option>\n";
163         }
165         return($catlist);
168 function renumber_order($mode, $cat = 0)
170         global $db;
172         switch($mode)
173         {
174                 case 'category':
175                         $table = CATEGORIES_TABLE;
176                         $idfield = 'cat_id';
177                         $orderfield = 'cat_order';
178                         $cat = 0;
179                         break;
181                 case 'forum':
182                         $table = FORUMS_TABLE;
183                         $idfield = 'forum_id';
184                         $orderfield = 'forum_order';
185                         $catfield = 'cat_id';
186                         break;
188                 default:
189                         message_die(GENERAL_ERROR, "Wrong mode for generating select list", "", __LINE__, __FILE__);
190                         break;
191         }
193         $sql = "SELECT * FROM $table";
194         if( $cat != 0)
195         {
196                 $sql .= " WHERE $catfield = $cat";
197         }
198         $sql .= " ORDER BY $orderfield ASC";
201         if( !$result = $db->sql_query($sql) )
202         {
203                 message_die(GENERAL_ERROR, "Couldn't get list of Categories", "", __LINE__, __FILE__, $sql);
204         }
206         $i = 10;
207         $inc = 10;
209         while( $row = $db->sql_fetchrow($result) )
210         {
211                 $sql = "UPDATE $table
212                         SET $orderfield = $i
213                         WHERE $idfield = " . $row[$idfield];
214                 if( !$db->sql_query($sql) )
215                 {
216                         message_die(GENERAL_ERROR, "Couldn't update order fields", "", __LINE__, __FILE__, $sql);
217                 }
218                 $i += 10;
219         }
222 //
223 // End function block
224 // ------------------
226 //
227 // Begin program proper
228 //
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" )
234         {
235                 list($cat_id) = each($HTTP_POST_VARS['addforum']);
236                 // 
237                 // stripslashes needs to be run on this because slashes are added when the forum name is posted
238                 //
239                 $forumname = stripslashes($HTTP_POST_VARS['forumname'][$cat_id]);
240         }
243 if( !empty($mode) ) 
245         switch($mode)
246         {
247                 case 'addforum':
248                 case 'editforum':
249                         //
250                         // Show form to create/modify a forum
251                         //
252                         if ($mode == 'editforum')
253                         {
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'];
269                                 //
270                                 // start forum prune stuff.
271                                 //
272                                 if( $row['prune_enable'] )
273                                 {
274                                         $prune_enabled = "checked=\"checked\"";
275                                         $sql = "SELECT *
276                                 FROM " . PRUNE_TABLE . "
277                                 WHERE forum_id = $forum_id";
278                                         if(!$pr_result = $db->sql_query($sql))
279                                         {
280                                                  message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
281                                 }
283                                         $pr_row = $db->sql_fetchrow($pr_result);
284                                 }
285                                 else
286                                 {
287                                         $prune_enabled = '';
288                                 }
289                         }
290                         else
291                         {
292                                 $l_title = $lang['Create_forum'];
293                                 $newmode = 'createforum';
294                                 $buttonvalue = $lang['Create_forum'];
296                                 $forumdesc = '';
297                                 $forumstatus = FORUM_UNLOCKED;
298                                 $forum_id = ''; 
299                                 $prune_enabled = '';
300                         }
302                         $catlist = get_list('category', $cat_id, TRUE);
304                         $forumstatus == ( FORUM_LOCKED ) ? $forumlocked = "selected=\"selected\"" : $forumunlocked = "selected=\"selected\"";
305                         
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';
310                         
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")
316                         );
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)
345                         );
346                         $template->pparse("body");
347                         break;
349                 case 'createforum':
350                         //
351                         // Create a forum in the DB
352                         //
353                         if( trim($HTTP_POST_VARS['forumname']) == "" )
354                         {
355                                 message_die(GENERAL_ERROR, "Can't create a forum without a name");
356                         }
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) )
362                         {
363                                 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
364                         }
365                         $row = $db->sql_fetchrow($result);
367                         $max_order = $row['max_order'];
368                         $next_order = $max_order + 10;
369                         
370                         $sql = "SELECT MAX(forum_id) AS max_id
371                                 FROM " . FORUMS_TABLE;
372                         if( !$result = $db->sql_query($sql) )
373                         {
374                                 message_die(GENERAL_ERROR, "Couldn't get order number from forums table", "", __LINE__, __FILE__, $sql);
375                         }
376                         $row = $db->sql_fetchrow($result);
378                         $max_id = $row['max_id'];
379                         $next_id = $max_id + 1;
381                         //
382                         // Default permissions of public :: 
383                         //
384                         $field_sql = "";
385                         $value_sql = "";
386                         while( list($field, $value) = each($forum_auth_ary) )
387                         {
388                                 $field_sql .= ", $field";
389                                 $value_sql .= ", $value";
391                         }
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) )
397                         {
398                                 message_die(GENERAL_ERROR, "Couldn't insert row in forums table", "", __LINE__, __FILE__, $sql);
399                         }
401                         if( $HTTP_POST_VARS['prune_enable'] )
402                         {
404                                 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "")
405                                 {
406                                         message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
407                                 }
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) )
412                                 {
413                                         message_die(GENERAL_ERROR, "Couldn't insert row in prune table", "", __LINE__, __FILE__, $sql);
414                                 }
415                         }
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);
421                         break;
423                 case 'modforum':
424                         // Modify a forum in the DB
425                         if( isset($HTTP_POST_VARS['prune_enable']))
426                         {
427                                 if( $HTTP_POST_VARS['prune_enable'] != 1 )
428                                 {
429                                         $HTTP_POST_VARS['prune_enable'] = 0;
430                                 }
431                         }
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) )
437                         {
438                                 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
439                         }
441                         if( $HTTP_POST_VARS['prune_enable'] == 1 )
442                         {
443                                 if( $HTTP_POST_VARS['prune_days'] == "" || $HTTP_POST_VARS['prune_freq'] == "" )
444                                 {
445                                         message_die(GENERAL_MESSAGE, $lang['Set_prune_data']);
446                                 }
448                                 $sql = "SELECT *
449                                         FROM " . PRUNE_TABLE . "
450                                         WHERE forum_id = " . intval($HTTP_POST_VARS[POST_FORUM_URL]);
451                                 if( !$result = $db->sql_query($sql) )
452                                 {
453                                         message_die(GENERAL_ERROR, "Couldn't get forum Prune Information","",__LINE__, __FILE__, $sql);
454                                 }
456                                 if( $db->sql_numrows($result) > 0 )
457                                 {
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]);
461                                 }
462                                 else
463                                 {
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']) . ")";
466                                 }
468                                 if( !$result = $db->sql_query($sql) )
469                                 {
470                                         message_die(GENERAL_ERROR, "Couldn't Update Forum Prune Information","",__LINE__, __FILE__, $sql);
471                                 }
472                         }
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);
478                         break;
479                         
480                 case 'addcat':
481                         // Create a category in the DB
482                         if( trim($HTTP_POST_VARS['categoryname']) == '')
483                         {
484                                 message_die(GENERAL_ERROR, "Can't create a category without a name");
485                         }
487                         $sql = "SELECT MAX(cat_order) AS max_order
488                                 FROM " . CATEGORIES_TABLE;
489                         if( !$result = $db->sql_query($sql) )
490                         {
491                                 message_die(GENERAL_ERROR, "Couldn't get order number from categories table", "", __LINE__, __FILE__, $sql);
492                         }
493                         $row = $db->sql_fetchrow($result);
495                         $max_order = $row['max_order'];
496                         $next_order = $max_order + 10;
498                         //
499                         // There is no problem having duplicate forum names so we won't check for it.
500                         //
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) )
504                         {
505                                 message_die(GENERAL_ERROR, "Couldn't insert row in categories table", "", __LINE__, __FILE__, $sql);
506                         }
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);
512                         break;
513                         
514                 case 'editcat':
515                         //
516                         // Show form to edit a category
517                         //
518                         $newmode = 'modcat';
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")
528                         );
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"))
542                         );
544                         $template->pparse("body");
545                         break;
547                 case 'modcat':
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) )
553                         {
554                                 message_die(GENERAL_ERROR, "Couldn't update forum information", "", __LINE__, __FILE__, $sql);
555                         }
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);
561                         break;
562                         
563                 case 'deleteforum':
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")
581                         );
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(
586                                 'NAME' => $name, 
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)
597                         );
599                         $template->pparse("body");
600                         break;
602                 case 'movedelforum':
603                         //
604                         // Move or delete a forum in the DB
605                         //
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
611                         if($to_id == -1)
612                         {
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)))
619                                 {
620                                         message_die(GENERAL_ERROR, "Couldn't obtain list of vote ids", "", __LINE__, __FILE__, $sql);
621                                 }
623                                 if ($row = $db->sql_fetchrow($result))
624                                 {
625                                         $vote_ids = '';
626                                         do
627                                         {
628                                                 $vote_ids = (($vote_ids != '') ? ', ' : '') . $row['vote_id'];
629                                         }
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);
643                                 }
644                                 $db->sql_freeresult($result);
645                                 
646                                 include($phpbb_root_path . "includes/prune.$phpEx");
647                                 prune($from_id, 0, true); // Delete everything from forum
648                         }
649                         else
650                         {
651                                 $sql = "SELECT *
652                                         FROM " . FORUMS_TABLE . "
653                                         WHERE forum_id IN ($from_id, $to_id)";
654                                 if( !$result = $db->sql_query($sql) )
655                                 {
656                                         message_die(GENERAL_ERROR, "Couldn't verify existence of forums", "", __LINE__, __FILE__, $sql);
657                                 }
659                                 if($db->sql_numrows($result) != 2)
660                                 {
661                                         message_die(GENERAL_ERROR, "Ambiguous forum ID's", "", __LINE__, __FILE__);
662                                 }
663                                 $sql = "UPDATE " . TOPICS_TABLE . "
664                                         SET forum_id = $to_id
665                                         WHERE forum_id = $from_id";
666                                 if( !$result = $db->sql_query($sql) )
667                                 {
668                                         message_die(GENERAL_ERROR, "Couldn't move topics to other forum", "", __LINE__, __FILE__, $sql);
669                                 }
670                                 $sql = "UPDATE " . POSTS_TABLE . "
671                                         SET     forum_id = $to_id
672                                         WHERE forum_id = $from_id";
673                                 if( !$result = $db->sql_query($sql) )
674                                 {
675                                         message_die(GENERAL_ERROR, "Couldn't move posts to other forum", "", __LINE__, __FILE__, $sql);
676                                 }
677                                 sync('forum', $to_id);
678                         }
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 
684                                         AND a.auth_mod = 1
685                                         AND ug.group_id = a.group_id";
686                         if( !$result = $db->sql_query($sql) )
687                         {
688                                 message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
689                         }
691                         if ($row = $db->sql_fetchrow($result))
692                         {
693                                 $user_ids = '';
694                                 do
695                                 {
696                                         $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
697                                 }
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 
703                                                 AND a.auth_mod = 1 
704                                                 AND ug.group_id = a.group_id
705                                                 AND ug.user_id NOT IN ($user_ids)";
706                                 if( !$result2 = $db->sql_query($sql) )
707                                 {
708                                         message_die(GENERAL_ERROR, "Couldn't obtain moderator list", "", __LINE__, __FILE__, $sql);
709                                 }
710                                         
711                                 if ($row = $db->sql_fetchrow($result2))
712                                 {
713                                         $user_ids = '';
714                                         do
715                                         {
716                                                 $user_ids .= (($user_ids != '') ? ', ' : '' ) . $row['user_id'];
717                                         }
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);
725                                 }
726                                 $db->sql_freeresult($result);
728                         }
729                         $db->sql_freeresult($result2);
731                         $sql = "DELETE FROM " . FORUMS_TABLE . "
732                                 WHERE forum_id = $from_id";
733                         if( !$result = $db->sql_query($sql) )
734                         {
735                                 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
736                         }
737                         
738                         $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . "
739                                 WHERE forum_id = $from_id";
740                         if( !$result = $db->sql_query($sql) )
741                         {
742                                 message_die(GENERAL_ERROR, "Couldn't delete forum", "", __LINE__, __FILE__, $sql);
743                         }
744                         
745                         $sql = "DELETE FROM " . PRUNE_TABLE . "
746                                 WHERE forum_id = $from_id";
747                         if( !$result = $db->sql_query($sql) )
748                         {
749                                 message_die(GENERAL_ERROR, "Couldn't delete forum prune information!", "", __LINE__, __FILE__, $sql);
750                         }
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);
756                         break;
757                         
758                 case 'deletecat':
759                         //
760                         // Show form to delete a category
761                         //
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)
770                         {
771                                 $sql = "SELECT count(*) as total
772                                         FROM ". FORUMS_TABLE;
773                                 if( !$result = $db->sql_query($sql) )
774                                 {
775                                         message_die(GENERAL_ERROR, "Couldn't get Forum count", "", __LINE__, __FILE__, $sql);
776                                 }
777                                 $count = $db->sql_fetchrow($result);
778                                 $count = $count['total'];
780                                 if ($count > 0)
781                                 {
782                                         message_die(GENERAL_ERROR, $lang['Must_delete_forums']);
783                                 }
784                                 else
785                                 {
786                                         $select_to = $lang['Nowhere_to_move'];
787                                 }
788                         }
789                         else
790                         {
791                                 $select_to = '<select name="to_id">';
792                                 $select_to .= get_list('category', $cat_id, 0);
793                                 $select_to .= '</select>';
794                         }
796                         $template->set_filenames(array(
797                                 "body" => "admin/forum_delete_body.tpl")
798                         );
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(
803                                 'NAME' => $name, 
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'], 
809                                 
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)
814                         );
816                         $template->pparse("body");
817                         break;
819                 case 'movedelcat':
820                         //
821                         // Move or delete a category in the DB
822                         //
823                         $from_id = intval($HTTP_POST_VARS['from_id']);
824                         $to_id = intval($HTTP_POST_VARS['to_id']);
826                         if (!empty($to_id))
827                         {
828                                 $sql = "SELECT *
829                                         FROM " . CATEGORIES_TABLE . "
830                                         WHERE cat_id IN ($from_id, $to_id)";
831                                 if( !$result = $db->sql_query($sql) )
832                                 {
833                                         message_die(GENERAL_ERROR, "Couldn't verify existence of categories", "", __LINE__, __FILE__, $sql);
834                                 }
835                                 if($db->sql_numrows($result) != 2)
836                                 {
837                                         message_die(GENERAL_ERROR, "Ambiguous category ID's", "", __LINE__, __FILE__);
838                                 }
840                                 $sql = "UPDATE " . FORUMS_TABLE . "
841                                         SET cat_id = $to_id
842                                         WHERE cat_id = $from_id";
843                                 if( !$result = $db->sql_query($sql) )
844                                 {
845                                         message_die(GENERAL_ERROR, "Couldn't move forums to other category", "", __LINE__, __FILE__, $sql);
846                                 }
847                         }
849                         $sql = "DELETE FROM " . CATEGORIES_TABLE ."
850                                 WHERE cat_id = $from_id";
851                                 
852                         if( !$result = $db->sql_query($sql) )
853                         {
854                                 message_die(GENERAL_ERROR, "Couldn't delete category", "", __LINE__, __FILE__, $sql);
855                         }
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);
861                         break;
863                 case 'forum_order':
864                         //
865                         // Change order of forums in the DB
866                         //
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) )
878                         {
879                                 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
880                         }
882                         renumber_order('forum', $forum_info['cat_id']);
883                         $show_index = TRUE;
885                         break;
886                         
887                 case 'cat_order':
888                         //
889                         // Change order of categories in the DB
890                         //
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) )
898                         {
899                                 message_die(GENERAL_ERROR, "Couldn't change category order", "", __LINE__, __FILE__, $sql);
900                         }
902                         renumber_order('category');
903                         $show_index = TRUE;
905                         break;
907                 case 'forum_sync':
908                         sync('forum', intval($HTTP_GET_VARS[POST_FORUM_URL]));
909                         $show_index = TRUE;
911                         break;
913                 default:
914                         message_die(GENERAL_MESSAGE, $lang['No_mode']);
915                         break;
916         }
918         if ($show_index != TRUE)
919         {
920                 include('./page_footer_admin.'.$phpEx);
921                 exit;
922         }
925 //
926 // Start page proper
927 //
928 $template->set_filenames(array(
929         "body" => "admin/forum_admin_body.tpl")
930 );
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'])
943 );
945 $sql = "SELECT cat_id, cat_title, cat_order
946         FROM " . CATEGORIES_TABLE . "
947         ORDER BY cat_order";
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);
957         $sql = "SELECT *
958                 FROM " . FORUMS_TABLE . "
959                 ORDER BY cat_id, forum_order";
960         if(!$q_forums = $db->sql_query($sql))
961         {
962                 message_die(GENERAL_ERROR, "Could not query forums information", "", __LINE__, __FILE__, $sql);
963         }
965         if( $total_forums = $db->sql_numrows($q_forums) )
966         {
967                 $forum_rows = $db->sql_fetchrowset($q_forums);
968         }
970         //
971         // Okay, let's build the index
972         //
973         $gen_cat = array();
975         for($i = 0; $i < $total_categories; $i++)
976         {
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]", 
983                         'CAT_ID' => $cat_id,
984                         'CAT_DESC' => $category_rows[$i]['cat_title'],
986                         'U_CAT_EDIT' => append_sid("admin_forums.$phpEx?mode=editcat&amp;" . POST_CAT_URL . "=$cat_id"),
987                         'U_CAT_DELETE' => append_sid("admin_forums.$phpEx?mode=deletecat&amp;" . POST_CAT_URL . "=$cat_id"),
988                         'U_CAT_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=-15&amp;" . POST_CAT_URL . "=$cat_id"),
989                         'U_CAT_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=cat_order&amp;move=15&amp;" . POST_CAT_URL . "=$cat_id"),
990                         'U_VIEWCAT' => append_sid($phpbb_root_path."index.$phpEx?" . POST_CAT_URL . "=$cat_id"))
991                 );
993                 for($j = 0; $j < $total_forums; $j++)
994                 {
995                         $forum_id = $forum_rows[$j]['forum_id'];
996                         
997                         if ($forum_rows[$j]['cat_id'] == $cat_id)
998                         {
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&amp;" . POST_FORUM_URL . "=$forum_id"),
1009                                         'U_FORUM_DELETE' => append_sid("admin_forums.$phpEx?mode=deleteforum&amp;" . POST_FORUM_URL . "=$forum_id"),
1010                                         'U_FORUM_MOVE_UP' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=-15&amp;" . POST_FORUM_URL . "=$forum_id"),
1011                                         'U_FORUM_MOVE_DOWN' => append_sid("admin_forums.$phpEx?mode=forum_order&amp;move=15&amp;" . POST_FORUM_URL . "=$forum_id"),
1012                                         'U_FORUM_RESYNC' => append_sid("admin_forums.$phpEx?mode=forum_sync&amp;" . POST_FORUM_URL . "=$forum_id"))
1013                                 );
1015                         }// if ... forumid == catid
1016                         
1017                 } // for ... forums
1019         } // for ... categories
1021 }// if ... total_categories
1023 $template->pparse("body");
1025 include('./page_footer_admin.'.$phpEx);
1027 ?>