Verzeichnisstruktur phpBB-3.0.0
- Veröffentlicht
- 12.12.2007
So funktioniert es
|
Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück |
Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis. |
|
(Beispiel Datei-Icons)
|
Auf das Icon klicken um den Quellcode anzuzeigen |
acp_forums.php
0001 <?php
0002 /**
0003 *
0004 * @package acp
0005 * @version $Id$
0006 * @copyright (c) 2005 phpBB Group
0007 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
0008 *
0009 */
0010
0011 /**
0012 * @ignore
0013 */
0014 if (!defined('IN_PHPBB'))
0015 {
0016 exit;
0017 }
0018
0019 /**
0020 * @package acp
0021 */
0022 class acp_forums
0023 {
0024 var $u_action;
0025 var $parent_id = 0;
0026
0027 function main($id, $mode)
0028 {
0029 global $db, $user, $auth, $template, $cache;
0030 global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
0031
0032 $user->add_lang('acp/forums');
0033 $this->tpl_name = 'acp_forums';
0034 $this->page_title = 'ACP_MANAGE_FORUMS';
0035
0036 $form_key = 'acp_forums';
0037 add_form_key($form_key);
0038
0039 $action = request_var('action', '');
0040 $update = (isset($_POST['update'])) ? true : false;
0041 $forum_id = request_var('f', 0);
0042
0043 $this->parent_id = request_var('parent_id', 0);
0044 $forum_data = $errors = array();
0045 if ($update && !check_form_key($form_key))
0046 {
0047 $update = false;
0048 $errors[] = $user->lang['FORM_INVALID'];
0049 }
0050
0051 // Check additional permissions
0052 switch ($action)
0053 {
0054 case 'progress_bar':
0055 $start = request_var('start', 0);
0056 $total = request_var('total', 0);
0057
0058 $this->display_progress_bar($start, $total);
0059 exit_handler();
0060 break;
0061
0062 case 'delete':
0063
0064 if (!$auth->acl_get('a_forumdel'))
0065 {
0066 trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0067 }
0068
0069 break;
0070
0071 case 'add':
0072
0073 if (!$auth->acl_get('a_forumadd'))
0074 {
0075 trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0076 }
0077
0078 break;
0079 }
0080
0081 // Major routines
0082 if ($update)
0083 {
0084 switch ($action)
0085 {
0086 case 'delete':
0087 $action_subforums = request_var('action_subforums', '');
0088 $subforums_to_id = request_var('subforums_to_id', 0);
0089 $action_posts = request_var('action_posts', '');
0090 $posts_to_id = request_var('posts_to_id', 0);
0091
0092 $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
0093
0094 if (sizeof($errors))
0095 {
0096 break;
0097 }
0098
0099 $auth->acl_clear_prefetch();
0100 $cache->destroy('sql', FORUMS_TABLE);
0101
0102 trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
0103
0104 break;
0105
0106 case 'edit':
0107 $forum_data = array(
0108 'forum_id' => $forum_id
0109 );
0110
0111 // No break here
0112
0113 case 'add':
0114
0115 $forum_data += array(
0116 'parent_id' => request_var('forum_parent_id', $this->parent_id),
0117 'forum_type' => request_var('forum_type', FORUM_POST),
0118 'type_action' => request_var('type_action', ''),
0119 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
0120 'forum_parents' => '',
0121 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
0122 'forum_link' => request_var('forum_link', ''),
0123 'forum_link_track' => request_var('forum_link_track', false),
0124 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
0125 'forum_desc_uid' => '',
0126 'forum_desc_options' => 7,
0127 'forum_desc_bitfield' => '',
0128 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
0129 'forum_rules_uid' => '',
0130 'forum_rules_options' => 7,
0131 'forum_rules_bitfield' => '',
0132 'forum_rules_link' => request_var('forum_rules_link', ''),
0133 'forum_image' => request_var('forum_image', ''),
0134 'forum_style' => request_var('forum_style', 0),
0135 'display_on_index' => request_var('display_on_index', false),
0136 'forum_topics_per_page' => request_var('topics_per_page', 0),
0137 'enable_indexing' => request_var('enable_indexing', true),
0138 'enable_icons' => request_var('enable_icons', false),
0139 'enable_prune' => request_var('enable_prune', false),
0140 'enable_post_review' => request_var('enable_post_review', true),
0141 'prune_days' => request_var('prune_days', 7),
0142 'prune_viewed' => request_var('prune_viewed', 7),
0143 'prune_freq' => request_var('prune_freq', 1),
0144 'prune_old_polls' => request_var('prune_old_polls', false),
0145 'prune_announce' => request_var('prune_announce', false),
0146 'prune_sticky' => request_var('prune_sticky', false),
0147 'forum_password' => request_var('forum_password', '', true),
0148 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
0149 'forum_password_unset' => request_var('forum_password_unset', false),
0150 );
0151
0152 // Use link_display_on_index setting if forum type is link
0153 if ($forum_data['forum_type'] == FORUM_LINK)
0154 {
0155 $forum_data['display_on_index'] = request_var('link_display_on_index', false);
0156
0157 // Linked forums are not able to be locked...
0158 $forum_data['forum_status'] = ITEM_UNLOCKED;
0159 }
0160
0161 $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', false) : request_var('display_active', false);
0162
0163 // Get data for forum rules if specified...
0164 if ($forum_data['forum_rules'])
0165 {
0166 generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_parse_bbcode', false), request_var('rules_parse_urls', false), request_var('rules_parse_smilies', false));
0167 }
0168
0169 // Get data for forum description if specified
0170 if ($forum_data['forum_desc'])
0171 {
0172 generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_parse_bbcode', false), request_var('desc_parse_urls', false), request_var('desc_parse_smilies', false));
0173 }
0174
0175 $errors = $this->update_forum_data($forum_data);
0176
0177 if (!sizeof($errors))
0178 {
0179 $forum_perm_from = request_var('forum_perm_from', 0);
0180
0181 // Copy permissions?
0182 if ($forum_perm_from && !empty($forum_perm_from) && $forum_perm_from != $forum_data['forum_id'] &&
0183 (($action != 'edit') || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))))
0184 {
0185 // if we edit a forum delete current permissions first
0186 if ($action == 'edit')
0187 {
0188 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
0189 WHERE forum_id = ' . (int) $forum_data['forum_id'];
0190 $db->sql_query($sql);
0191
0192 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
0193 WHERE forum_id = ' . (int) $forum_data['forum_id'];
0194 $db->sql_query($sql);
0195 }
0196
0197 // From the mysql documentation:
0198 // Prior to MySQL 4.0.14, the target table of the INSERT statement cannot appear in the FROM clause of the SELECT part of the query. This limitation is lifted in 4.0.14.
0199 // Due to this we stay on the safe side if we do the insertion "the manual way"
0200
0201 // Copy permisisons from/to the acl users table (only forum_id gets changed)
0202 $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting
0203 FROM ' . ACL_USERS_TABLE . '
0204 WHERE forum_id = ' . $forum_perm_from;
0205 $result = $db->sql_query($sql);
0206
0207 $users_sql_ary = array();
0208 while ($row = $db->sql_fetchrow($result))
0209 {
0210 $users_sql_ary[] = array(
0211 'user_id' => (int) $row['user_id'],
0212 'forum_id' => (int) $forum_data['forum_id'],
0213 'auth_option_id' => (int) $row['auth_option_id'],
0214 'auth_role_id' => (int) $row['auth_role_id'],
0215 'auth_setting' => (int) $row['auth_setting']
0216 );
0217 }
0218 $db->sql_freeresult($result);
0219
0220 // Copy permisisons from/to the acl groups table (only forum_id gets changed)
0221 $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting
0222 FROM ' . ACL_GROUPS_TABLE . '
0223 WHERE forum_id = ' . $forum_perm_from;
0224 $result = $db->sql_query($sql);
0225
0226 $groups_sql_ary = array();
0227 while ($row = $db->sql_fetchrow($result))
0228 {
0229 $groups_sql_ary[] = array(
0230 'group_id' => (int) $row['group_id'],
0231 'forum_id' => (int) $forum_data['forum_id'],
0232 'auth_option_id' => (int) $row['auth_option_id'],
0233 'auth_role_id' => (int) $row['auth_role_id'],
0234 'auth_setting' => (int) $row['auth_setting']
0235 );
0236 }
0237 $db->sql_freeresult($result);
0238
0239 // Now insert the data
0240 $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary);
0241 $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary);
0242 cache_moderators();
0243 }
0244
0245 $auth->acl_clear_prefetch();
0246 $cache->destroy('sql', FORUMS_TABLE);
0247
0248 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
0249
0250 $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
0251
0252 // Redirect to permissions
0253 if ($auth->acl_get('a_fauth'))
0254 {
0255 $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
0256 }
0257
0258 // redirect directly to permission settings screen if authed
0259 if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth'))
0260 {
0261 meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
0262 }
0263
0264 trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
0265 }
0266
0267 break;
0268 }
0269 }
0270
0271 switch ($action)
0272 {
0273 case 'move_up':
0274 case 'move_down':
0275
0276 if (!$forum_id)
0277 {
0278 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0279 }
0280
0281 $sql = 'SELECT *
0282 FROM ' . FORUMS_TABLE . "
0283 WHERE forum_id = $forum_id";
0284 $result = $db->sql_query($sql);
0285 $row = $db->sql_fetchrow($result);
0286 $db->sql_freeresult($result);
0287
0288 if (!$row)
0289 {
0290 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0291 }
0292
0293 $move_forum_name = $this->move_forum_by($row, $action, 1);
0294
0295 if ($move_forum_name !== false)
0296 {
0297 add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
0298 $cache->destroy('sql', FORUMS_TABLE);
0299 }
0300
0301 break;
0302
0303 case 'sync':
0304 if (!$forum_id)
0305 {
0306 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0307 }
0308
0309 @set_time_limit(0);
0310
0311 $sql = 'SELECT forum_name, forum_topics_real
0312 FROM ' . FORUMS_TABLE . "
0313 WHERE forum_id = $forum_id";
0314 $result = $db->sql_query($sql);
0315 $row = $db->sql_fetchrow($result);
0316 $db->sql_freeresult($result);
0317
0318 if (!$row)
0319 {
0320 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0321 }
0322
0323 if ($row['forum_topics_real'])
0324 {
0325 $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
0326 FROM ' . TOPICS_TABLE . '
0327 WHERE forum_id = ' . $forum_id;
0328 $result = $db->sql_query($sql);
0329 $row2 = $db->sql_fetchrow($result);
0330 $db->sql_freeresult($result);
0331
0332 // Typecast to int if there is no data available
0333 $row2['min_topic_id'] = (int) $row2['min_topic_id'];
0334 $row2['max_topic_id'] = (int) $row2['max_topic_id'];
0335
0336 $start = request_var('start', $row2['min_topic_id']);
0337
0338 $batch_size = 2000;
0339 $end = $start + $batch_size;
0340
0341 // Sync all topics in batch mode...
0342 sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
0343 sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
0344
0345 if ($end < $row2['max_topic_id'])
0346 {
0347 // We really need to find a way of showing statistics... no progress here
0348 $sql = 'SELECT COUNT(topic_id) as num_topics
0349 FROM ' . TOPICS_TABLE . '
0350 WHERE forum_id = ' . $forum_id . '
0351 AND topic_id BETWEEN ' . $start . ' AND ' . $end;
0352 $result = $db->sql_query($sql);
0353 $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
0354 $db->sql_freeresult($result);
0355
0356 $start += $batch_size;
0357
0358 $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync&start=$start&topics_done=$topics_done&total={$row['forum_topics_real']}";
0359
0360 meta_refresh(0, $url);
0361
0362 $template->assign_vars(array(
0363 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}",
0364 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"),
0365 'S_CONTINUE_SYNC' => true,
0366 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
0367 );
0368
0369 return;
0370 }
0371 }
0372
0373 $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
0374 meta_refresh(0, $url);
0375
0376 $template->assign_vars(array(
0377 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
0378 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
0379 'S_CONTINUE_SYNC' => true,
0380 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
0381 );
0382
0383 return;
0384
0385 break;
0386
0387 case 'sync_forum':
0388
0389 $sql = 'SELECT forum_name, forum_type
0390 FROM ' . FORUMS_TABLE . "
0391 WHERE forum_id = $forum_id";
0392 $result = $db->sql_query($sql);
0393 $row = $db->sql_fetchrow($result);
0394 $db->sql_freeresult($result);
0395
0396 if (!$row)
0397 {
0398 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0399 }
0400
0401 sync('forum', 'forum_id', $forum_id, false, true);
0402
0403 add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
0404 $cache->destroy('sql', FORUMS_TABLE);
0405
0406 $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
0407
0408 break;
0409
0410 case 'add':
0411 case 'edit':
0412
0413 if ($update)
0414 {
0415 $forum_data['forum_flags'] = 0;
0416 $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
0417 $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
0418 $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
0419 $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
0420 $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
0421 $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
0422 }
0423
0424 // Show form to create/modify a forum
0425 if ($action == 'edit')
0426 {
0427 $this->page_title = 'EDIT_FORUM';
0428 $row = $this->get_forum_info($forum_id);
0429 $old_forum_type = $row['forum_type'];
0430
0431 if (!$update)
0432 {
0433 $forum_data = $row;
0434 }
0435 else
0436 {
0437 $forum_data['left_id'] = $row['left_id'];
0438 $forum_data['right_id'] = $row['right_id'];
0439 }
0440
0441 // Make sure no direct child forums are able to be selected as parents.
0442 $exclude_forums = array();
0443 foreach (get_forum_branch($forum_id, 'children') as $row)
0444 {
0445 $exclude_forums[] = $row['forum_id'];
0446 }
0447
0448 $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
0449
0450 $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
0451 }
0452 else
0453 {
0454 $this->page_title = 'CREATE_FORUM';
0455
0456 $forum_id = $this->parent_id;
0457 $parents_list = make_forum_select($this->parent_id, false, false, false, false);
0458
0459 // Fill forum data with default values
0460 if (!$update)
0461 {
0462 $forum_data = array(
0463 'parent_id' => $this->parent_id,
0464 'forum_type' => FORUM_POST,
0465 'forum_status' => ITEM_UNLOCKED,
0466 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
0467 'forum_link' => '',
0468 'forum_link_track' => false,
0469 'forum_desc' => '',
0470 'forum_rules' => '',
0471 'forum_rules_link' => '',
0472 'forum_image' => '',
0473 'forum_style' => 0,
0474 'display_on_index' => false,
0475 'forum_topics_per_page' => 0,
0476 'enable_indexing' => true,
0477 'enable_icons' => false,
0478 'enable_prune' => false,
0479 'prune_days' => 7,
0480 'prune_viewed' => 7,
0481 'prune_freq' => 1,
0482 'forum_flags' => FORUM_FLAG_POST_REVIEW,
0483 'forum_password' => '',
0484 'forum_password_confirm'=> '',
0485 );
0486 }
0487 }
0488
0489 $forum_rules_data = array(
0490 'text' => $forum_data['forum_rules'],
0491 'allow_bbcode' => true,
0492 'allow_smilies' => true,
0493 'allow_urls' => true
0494 );
0495
0496 $forum_desc_data = array(
0497 'text' => $forum_data['forum_desc'],
0498 'allow_bbcode' => true,
0499 'allow_smilies' => true,
0500 'allow_urls' => true
0501 );
0502
0503 $forum_rules_preview = '';
0504
0505 // Parse rules if specified
0506 if ($forum_data['forum_rules'])
0507 {
0508 if (!isset($forum_data['forum_rules_uid']))
0509 {
0510 // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
0511 $forum_data['forum_rules_uid'] = '';
0512 $forum_data['forum_rules_bitfield'] = '';
0513 $forum_data['forum_rules_options'] = 0;
0514
0515 generate_text_for_storage($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options'], request_var('rules_allow_bbcode', false), request_var('rules_allow_urls', false), request_var('rules_allow_smilies', false));
0516 }
0517
0518 // Generate preview content
0519 $forum_rules_preview = generate_text_for_display($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_bitfield'], $forum_data['forum_rules_options']);
0520
0521 // decode...
0522 $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
0523 }
0524
0525 // Parse desciption if specified
0526 if ($forum_data['forum_desc'])
0527 {
0528 if (!isset($forum_data['forum_desc_uid']))
0529 {
0530 // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
0531 $forum_data['forum_desc_uid'] = '';
0532 $forum_data['forum_desc_bitfield'] = '';
0533 $forum_data['forum_desc_options'] = 0;
0534
0535 generate_text_for_storage($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_bitfield'], $forum_data['forum_desc_options'], request_var('desc_allow_bbcode', false), request_var('desc_allow_urls', false), request_var('desc_allow_smilies', false));
0536 }
0537
0538 // decode...
0539 $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
0540 }
0541
0542 $forum_type_options = '';
0543 $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
0544
0545 foreach ($forum_type_ary as $value => $lang)
0546 {
0547 $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
0548 }
0549
0550 $styles_list = style_select($forum_data['forum_style'], true);
0551
0552 $statuslist = '<option value="' . ITEM_UNLOCKED . '"' . (($forum_data['forum_status'] == ITEM_UNLOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['UNLOCKED'] . '</option><option value="' . ITEM_LOCKED . '"' . (($forum_data['forum_status'] == ITEM_LOCKED) ? ' selected="selected"' : '') . '>' . $user->lang['LOCKED'] . '</option>';
0553
0554 $sql = 'SELECT forum_id
0555 FROM ' . FORUMS_TABLE . '
0556 WHERE forum_type = ' . FORUM_POST . "
0557 AND forum_id <> $forum_id";
0558 $result = $db->sql_query($sql);
0559
0560 if ($db->sql_fetchrow($result))
0561 {
0562 $template->assign_vars(array(
0563 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
0564 );
0565 }
0566 $db->sql_freeresult($result);
0567
0568 // Subforum move options
0569 if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
0570 {
0571 $subforums_id = array();
0572 $subforums = get_forum_branch($forum_id, 'children');
0573
0574 foreach ($subforums as $row)
0575 {
0576 $subforums_id[] = $row['forum_id'];
0577 }
0578
0579 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
0580
0581 $sql = 'SELECT forum_id
0582 FROM ' . FORUMS_TABLE . '
0583 WHERE forum_type = ' . FORUM_POST . "
0584 AND forum_id <> $forum_id";
0585 $result = $db->sql_query($sql);
0586
0587 if ($db->sql_fetchrow($result))
0588 {
0589 $template->assign_vars(array(
0590 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
0591 );
0592 }
0593 $db->sql_freeresult($result);
0594
0595 $template->assign_vars(array(
0596 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
0597 'S_FORUMS_LIST' => $forums_list)
0598 );
0599 }
0600
0601 $s_show_display_on_index = false;
0602
0603 if ($forum_data['parent_id'] > 0)
0604 {
0605 // if this forum is a subforum put the "display on index" checkbox
0606 if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
0607 {
0608 if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
0609 {
0610 $s_show_display_on_index = true;
0611 }
0612 }
0613 }
0614
0615 if (strlen($forum_data['forum_password']) == 32)
0616 {
0617 $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
0618 }
0619
0620 $template->assign_vars(array(
0621 'S_EDIT_FORUM' => true,
0622 'S_ERROR' => (sizeof($errors)) ? true : false,
0623 'S_PARENT_ID' => $this->parent_id,
0624 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
0625 'S_ADD_ACTION' => ($action == 'add') ? true : false,
0626
0627 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
0628 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
0629
0630 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
0631 'L_TITLE' => $user->lang[$this->page_title],
0632 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
0633
0634 'FORUM_NAME' => $forum_data['forum_name'],
0635 'FORUM_DATA_LINK' => $forum_data['forum_link'],
0636 'FORUM_IMAGE' => $forum_data['forum_image'],
0637 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
0638 'FORUM_POST' => FORUM_POST,
0639 'FORUM_LINK' => FORUM_LINK,
0640 'FORUM_CAT' => FORUM_CAT,
0641 'PRUNE_FREQ' => $forum_data['prune_freq'],
0642 'PRUNE_DAYS' => $forum_data['prune_days'],
0643 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
0644 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
0645 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
0646 'FORUM_RULES' => $forum_data['forum_rules'],
0647 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
0648 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
0649 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
0650 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
0651 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
0652 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
0653
0654 'FORUM_DESC' => $forum_desc_data['text'],
0655 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
0656 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
0657 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
0658
0659 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
0660 'S_STATUS_OPTIONS' => $statuslist,
0661 'S_PARENT_OPTIONS' => $parents_list,
0662 'S_STYLES_OPTIONS' => $styles_list,
0663 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
0664 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
0665 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
0666 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
0667 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
0668 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
0669 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
0670 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
0671 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
0672 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
0673 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
0674 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
0675 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
0676 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
0677 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
0678 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
0679 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
0680 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
0681 'S_CAN_COPY_PERMISSIONS' => ($action != 'edit' || empty($forum_id) || ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))) ? true : false,
0682 ));
0683
0684 return;
0685
0686 break;
0687
0688 case 'delete':
0689
0690 if (!$forum_id)
0691 {
0692 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
0693 }
0694
0695 $forum_data = $this->get_forum_info($forum_id);
0696
0697 $subforums_id = array();
0698 $subforums = get_forum_branch($forum_id, 'children');
0699
0700 foreach ($subforums as $row)
0701 {
0702 $subforums_id[] = $row['forum_id'];
0703 }
0704
0705 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
0706
0707 $sql = 'SELECT forum_id
0708 FROM ' . FORUMS_TABLE . '
0709 WHERE forum_type = ' . FORUM_POST . "
0710 AND forum_id <> $forum_id";
0711 $result = $db->sql_query($sql);
0712
0713 if ($db->sql_fetchrow($result))
0714 {
0715 $template->assign_vars(array(
0716 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
0717 );
0718 }
0719 $db->sql_freeresult($result);
0720
0721 $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
0722
0723 $template->assign_vars(array(
0724 'S_DELETE_FORUM' => true,
0725 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
0726 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
0727
0728 'FORUM_NAME' => $forum_data['forum_name'],
0729 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
0730 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
0731 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
0732 'S_FORUMS_LIST' => $forums_list,
0733 'S_ERROR' => (sizeof($errors)) ? true : false,
0734 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
0735 );
0736
0737 return;
0738 break;
0739 }
0740
0741 // Default management page
0742 if (!$this->parent_id)
0743 {
0744 $navigation = $user->lang['FORUM_INDEX'];
0745 }
0746 else
0747 {
0748 $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
0749
0750 $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
0751 foreach ($forums_nav as $row)
0752 {
0753 if ($row['forum_id'] == $this->parent_id)
0754 {
0755 $navigation .= ' -> ' . $row['forum_name'];
0756 }
0757 else
0758 {
0759 $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
0760 }
0761 }
0762 }
0763
0764 // Jumpbox
0765 $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
0766
0767 if ($action == 'sync' || $action == 'sync_forum')
0768 {
0769 $template->assign_var('S_RESYNCED', true);
0770 }
0771
0772 $sql = 'SELECT *
0773 FROM ' . FORUMS_TABLE . "
0774 WHERE parent_id = $this->parent_id
0775 ORDER BY left_id";
0776 $result = $db->sql_query($sql);
0777
0778 if ($row = $db->sql_fetchrow($result))
0779 {
0780 do
0781 {
0782 $forum_type = $row['forum_type'];
0783
0784 if ($row['forum_status'] == ITEM_LOCKED)
0785 {
0786 $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
0787 }
0788 else
0789 {
0790 switch ($forum_type)
0791 {
0792 case FORUM_LINK:
0793 $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
0794 break;
0795
0796 default:
0797 $folder_image = ($row['left_id'] + 1 != $row['right_id']) ? '<img src="images/icon_subfolder.gif" alt="' . $user->lang['SUBFORUM'] . '" />' : '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />';
0798 break;
0799 }
0800 }
0801
0802 $url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
0803
0804 $forum_title = ($forum_type != FORUM_LINK) ? '<a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' : '';
0805 $forum_title .= $row['forum_name'];
0806 $forum_title .= ($forum_type != FORUM_LINK) ? '</a>' : '';
0807
0808 $template->assign_block_vars('forums', array(
0809 'FOLDER_IMAGE' => $folder_image,
0810 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
0811 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
0812 'FORUM_NAME' => $row['forum_name'],
0813 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
0814 'FORUM_TOPICS' => $row['forum_topics'],
0815 'FORUM_POSTS' => $row['forum_posts'],
0816
0817 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
0818 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
0819
0820 'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
0821 'U_MOVE_UP' => $url . '&action=move_up',
0822 'U_MOVE_DOWN' => $url . '&action=move_down',
0823 'U_EDIT' => $url . '&action=edit',
0824 'U_DELETE' => $url . '&action=delete',
0825 'U_SYNC' => $url . '&action=sync')
0826 );
0827 }
0828 while ($row = $db->sql_fetchrow($result));
0829 }
0830 else if ($this->parent_id)
0831 {
0832 $row = $this->get_forum_info($this->parent_id);
0833
0834 $url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
0835
0836 $template->assign_vars(array(
0837 'S_NO_FORUMS' => true,
0838
0839 'U_EDIT' => $url . '&action=edit',
0840 'U_DELETE' => $url . '&action=delete',
0841 'U_SYNC' => $url . '&action=sync')
0842 );
0843 }
0844 $db->sql_freeresult($result);
0845
0846 $template->assign_vars(array(
0847 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
0848 'NAVIGATION' => $navigation,
0849 'FORUM_BOX' => $forum_box,
0850 'U_SEL_ACTION' => $this->u_action,
0851 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
0852
0853 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
0854 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
0855 ));
0856 }
0857
0858 /**
0859 * Get forum details
0860 */
0861 function get_forum_info($forum_id)
0862 {
0863 global $db;
0864
0865 $sql = 'SELECT *
0866 FROM ' . FORUMS_TABLE . "
0867 WHERE forum_id = $forum_id";
0868 $result = $db->sql_query($sql);
0869 $row = $db->sql_fetchrow($result);
0870 $db->sql_freeresult($result);
0871
0872 if (!$row)
0873 {
0874 trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
0875 }
0876
0877 return $row;
0878 }
0879
0880 /**
0881 * Update forum data
0882 */
0883 function update_forum_data(&$forum_data)
0884 {
0885 global $db, $user, $cache;
0886
0887 $errors = array();
0888
0889 if (!$forum_data['forum_name'])
0890 {
0891 $errors[] = $user->lang['FORUM_NAME_EMPTY'];
0892 }
0893
0894 if (utf8_strlen($forum_data['forum_desc']) > 4000)
0895 {
0896 $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
0897 }
0898
0899 if (utf8_strlen($forum_data['forum_rules']) > 4000)
0900 {
0901 $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
0902 }
0903
0904 if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
0905 {
0906 if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
0907 {
0908 $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
0909 $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
0910 }
0911 }
0912
0913 if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
0914 {
0915 $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
0916 $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
0917 }
0918
0919 // Set forum flags
0920 // 1 = link tracking
0921 // 2 = prune old polls
0922 // 4 = prune announcements
0923 // 8 = prune stickies
0924 // 16 = show active topics
0925 // 32 = enable post review
0926 $forum_data['forum_flags'] = 0;
0927 $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
0928 $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
0929 $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
0930 $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
0931 $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
0932 $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
0933
0934 // Unset data that are not database fields
0935 $forum_data_sql = $forum_data;
0936
0937 unset($forum_data_sql['forum_link_track']);
0938 unset($forum_data_sql['prune_old_polls']);
0939 unset($forum_data_sql['prune_announce']);
0940 unset($forum_data_sql['prune_sticky']);
0941 unset($forum_data_sql['show_active']);
0942 unset($forum_data_sql['enable_post_review']);
0943 unset($forum_data_sql['forum_password_confirm']);
0944
0945 // What are we going to do tonight Brain? The same thing we do everynight,
0946 // try to take over the world ... or decide whether to continue update
0947 // and if so, whether it's a new forum/cat/link or an existing one
0948 if (sizeof($errors))
0949 {
0950 return $errors;
0951 }
0952
0953 // As we don't know the old password, it's kinda tricky to detect changes
0954 if ($forum_data_sql['forum_password_unset'])
0955 {
0956 $forum_data_sql['forum_password'] = '';
0957 }
0958 else if (empty($forum_data_sql['forum_password']))
0959 {
0960 unset($forum_data_sql['forum_password']);
0961 }
0962 else
0963 {
0964 $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
0965 }
0966 unset($forum_data_sql['forum_password_unset']);
0967
0968 if (!isset($forum_data_sql['forum_id']))
0969 {
0970 // no forum_id means we're creating a new forum
0971 unset($forum_data_sql['type_action']);
0972
0973 if ($forum_data_sql['parent_id'])
0974 {
0975 $sql = 'SELECT left_id, right_id, forum_type
0976 FROM ' . FORUMS_TABLE . '
0977 WHERE forum_id = ' . $forum_data_sql['parent_id'];
0978 $result = $db->sql_query($sql);
0979 $row = $db->sql_fetchrow($result);
0980 $db->sql_freeresult($result);
0981
0982 if (!$row)
0983 {
0984 trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&' . $this->parent_id), E_USER_WARNING);
0985 }
0986
0987 if ($row['forum_type'] == FORUM_LINK)
0988 {
0989 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
0990 return $errors;
0991 }
0992
0993 $sql = 'UPDATE ' . FORUMS_TABLE . '
0994 SET left_id = left_id + 2, right_id = right_id + 2
0995 WHERE left_id > ' . $row['right_id'];
0996 $db->sql_query($sql);
0997
0998 $sql = 'UPDATE ' . FORUMS_TABLE . '
0999 SET right_id = right_id + 2
1000 WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
1001 $db->sql_query($sql);
1002
1003 $forum_data_sql['left_id'] = $row['right_id'];
1004 $forum_data_sql['right_id'] = $row['right_id'] + 1;
1005 }
1006 else
1007 {
1008 $sql = 'SELECT MAX(right_id) AS right_id
1009 FROM ' . FORUMS_TABLE;
1010 $result = $db->sql_query($sql);
1011 $row = $db->sql_fetchrow($result);
1012 $db->sql_freeresult($result);
1013
1014 $forum_data_sql['left_id'] = $row['right_id'] + 1;
1015 $forum_data_sql['right_id'] = $row['right_id'] + 2;
1016 }
1017
1018 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
1019 $db->sql_query($sql);
1020
1021 $forum_data['forum_id'] = $db->sql_nextid();
1022
1023 add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
1024 }
1025 else
1026 {
1027 $row = $this->get_forum_info($forum_data_sql['forum_id']);
1028
1029 if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
1030 {
1031 // Has subforums and want to change into a link?
1032 if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
1033 {
1034 $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
1035 return $errors;
1036 }
1037
1038 // we're turning a postable forum into a non-postable forum
1039 if ($forum_data_sql['type_action'] == 'move')
1040 {
1041 $to_forum_id = request_var('to_forum_id', 0);
1042
1043 if ($to_forum_id)
1044 {
1045 $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
1046 }
1047 else
1048 {
1049 return array($user->lang['NO_DESTINATION_FORUM']);
1050 }
1051 }
1052 else if ($forum_data_sql['type_action'] == 'delete')
1053 {
1054 $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
1055 }
1056 else
1057 {
1058 return array($user->lang['NO_FORUM_ACTION']);
1059 }
1060
1061 $forum_data_sql['forum_posts'] = $forum_data_sql['forum_topics'] = $forum_data_sql['forum_topics_real'] = $forum_data_sql['forum_last_post_id'] = $forum_data_sql['forum_last_poster_id'] = $forum_data_sql['forum_last_post_time'] = 0;
1062 $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
1063 }
1064 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
1065 {
1066 // Has subforums?
1067 if ($row['right_id'] - $row['left_id'] > 1)
1068 {
1069 // We are turning a category into a link - but need to decide what to do with the subforums.
1070 $action_subforums = request_var('action_subforums', '');
1071 $subforums_to_id = request_var('subforums_to_id', 0);
1072
1073 if ($action_subforums == 'delete')
1074 {
1075 $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
1076
1077 foreach ($rows as $_row)
1078 {
1079 // Do not remove the forum id we are about to change. ;)
1080 if ($_row['forum_id'] == $row['forum_id'])
1081 {
1082 continue;
1083 }
1084
1085 $forum_ids[] = $_row['forum_id'];
1086 $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
1087 }
1088
1089 if (sizeof($errors))
1090 {
1091 return $errors;
1092 }
1093
1094 if (sizeof($forum_ids))
1095 {
1096 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1097 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1098 $db->sql_query($sql);
1099
1100 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1101 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1102 $db->sql_query($sql);
1103
1104 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1105 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1106 $db->sql_query($sql);
1107
1108 // Delete forum ids from extension groups table
1109 $sql = 'SELECT group_id, allowed_forums
1110 FROM ' . EXTENSION_GROUPS_TABLE;
1111 $result = $db->sql_query($sql);
1112
1113 while ($_row = $db->sql_fetchrow($result))
1114 {
1115 if (!$_row['allowed_forums'])
1116 {
1117 continue;
1118 }
1119
1120 $allowed_forums = unserialize(trim($_row['allowed_forums']));
1121 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1122
1123 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1124 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1125 WHERE group_id = {$_row['group_id']}";
1126 $db->sql_query($sql);
1127 }
1128 $db->sql_freeresult($result);
1129
1130 $cache->destroy('_extensions');
1131 }
1132 }
1133 else if ($action_subforums == 'move')
1134 {
1135 if (!$subforums_to_id)
1136 {
1137 return array($user->lang['NO_DESTINATION_FORUM']);
1138 }
1139
1140 $sql = 'SELECT forum_name
1141 FROM ' . FORUMS_TABLE . '
1142 WHERE forum_id = ' . $subforums_to_id;
1143 $result = $db->sql_query($sql);
1144 $_row = $db->sql_fetchrow($result);
1145 $db->sql_freeresult($result);
1146
1147 if (!$_row)
1148 {
1149 return array($user->lang['NO_FORUM']);
1150 }
1151
1152 $subforums_to_name = $_row['forum_name'];
1153
1154 $sql = 'SELECT forum_id
1155 FROM ' . FORUMS_TABLE . "
1156 WHERE parent_id = {$row['forum_id']}";
1157 $result = $db->sql_query($sql);
1158
1159 while ($_row = $db->sql_fetchrow($result))
1160 {
1161 $this->move_forum($_row['forum_id'], $subforums_to_id);
1162 }
1163 $db->sql_freeresult($result);
1164
1165 $sql = 'UPDATE ' . FORUMS_TABLE . "
1166 SET parent_id = $subforums_to_id
1167 WHERE parent_id = {$row['forum_id']}";
1168 $db->sql_query($sql);
1169 }
1170
1171 // Adjust the left/right id
1172 $sql = 'UPDATE ' . FORUMS_TABLE . '
1173 SET right_id = left_id + 1
1174 WHERE forum_id = ' . $row['forum_id'];
1175 $db->sql_query($sql);
1176 }
1177 }
1178 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
1179 {
1180 // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
1181 $forum_data_sql['forum_posts'] = 0;
1182 $forum_data_sql['forum_topics'] = 0;
1183 $forum_data_sql['forum_topics_real'] = 0;
1184 $forum_data_sql['forum_last_post_id'] = 0;
1185 $forum_data_sql['forum_last_post_subject'] = '';
1186 $forum_data_sql['forum_last_post_time'] = 0;
1187 $forum_data_sql['forum_last_poster_id'] = 0;
1188 $forum_data_sql['forum_last_poster_name'] = '';
1189 $forum_data_sql['forum_last_poster_colour'] = '';
1190 }
1191
1192 if (sizeof($errors))
1193 {
1194 return $errors;
1195 }
1196
1197 if ($row['parent_id'] != $forum_data_sql['parent_id'])
1198 {
1199 $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
1200 }
1201
1202 if (sizeof($errors))
1203 {
1204 return $errors;
1205 }
1206
1207 unset($forum_data_sql['type_action']);
1208
1209 if ($row['forum_name'] != $forum_data_sql['forum_name'])
1210 {
1211 // the forum name has changed, clear the parents list of all forums (for safety)
1212 $sql = 'UPDATE ' . FORUMS_TABLE . "
1213 SET forum_parents = ''";
1214 $db->sql_query($sql);
1215 }
1216
1217 // Setting the forum id to the forum id is not really received well by some dbs. ;)
1218 $forum_id = $forum_data_sql['forum_id'];
1219 unset($forum_data_sql['forum_id']);
1220
1221 $sql = 'UPDATE ' . FORUMS_TABLE . '
1222 SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
1223 WHERE forum_id = ' . $forum_id;
1224 $db->sql_query($sql);
1225
1226 // Add it back
1227 $forum_data['forum_id'] = $forum_id;
1228
1229 add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
1230 }
1231
1232 return $errors;
1233 }
1234
1235 /**
1236 * Move forum
1237 */
1238 function move_forum($from_id, $to_id)
1239 {
1240 global $db, $user;
1241
1242 $to_data = $moved_ids = $errors = array();
1243
1244 // Check if we want to move to a parent with link type
1245 if ($to_id > 0)
1246 {
1247 $to_data = $this->get_forum_info($to_id);
1248
1249 if ($to_data['forum_type'] == FORUM_LINK)
1250 {
1251 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1252 return $errors;
1253 }
1254 }
1255
1256 $moved_forums = get_forum_branch($from_id, 'children', 'descending');
1257 $from_data = $moved_forums[0];
1258 $diff = sizeof($moved_forums) * 2;
1259
1260 $moved_ids = array();
1261 for ($i = 0; $i < sizeof($moved_forums); ++$i)
1262 {
1263 $moved_ids[] = $moved_forums[$i]['forum_id'];
1264 }
1265
1266 // Resync parents
1267 $sql = 'UPDATE ' . FORUMS_TABLE . "
1268 SET right_id = right_id - $diff, forum_parents = ''
1269 WHERE left_id < " . $from_data['right_id'] . "
1270 AND right_id > " . $from_data['right_id'];
1271 $db->sql_query($sql);
1272
1273 // Resync righthand side of tree
1274 $sql = 'UPDATE ' . FORUMS_TABLE . "
1275 SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
1276 WHERE left_id > " . $from_data['right_id'];
1277 $db->sql_query($sql);
1278
1279 if ($to_id > 0)
1280 {
1281 // Retrieve $to_data again, it may have been changed...
1282 $to_data = $this->get_forum_info($to_id);
1283
1284 // Resync new parents
1285 $sql = 'UPDATE ' . FORUMS_TABLE . "
1286 SET right_id = right_id + $diff, forum_parents = ''
1287 WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
1288 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1289 $db->sql_query($sql);
1290
1291 // Resync the righthand side of the tree
1292 $sql = 'UPDATE ' . FORUMS_TABLE . "
1293 SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
1294 WHERE left_id > " . $to_data['right_id'] . '
1295 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1296 $db->sql_query($sql);
1297
1298 // Resync moved branch
1299 $to_data['right_id'] += $diff;
1300
1301 if ($to_data['right_id'] > $from_data['right_id'])
1302 {
1303 $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
1304 }
1305 else
1306 {
1307 $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
1308 }
1309 }
1310 else
1311 {
1312 $sql = 'SELECT MAX(right_id) AS right_id
1313 FROM ' . FORUMS_TABLE . '
1314 WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
1315 $result = $db->sql_query($sql);
1316 $row = $db->sql_fetchrow($result);
1317 $db->sql_freeresult($result);
1318
1319 $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
1320 }
1321
1322 $sql = 'UPDATE ' . FORUMS_TABLE . "
1323 SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
1324 WHERE " . $db->sql_in_set('forum_id', $moved_ids);
1325 $db->sql_query($sql);
1326
1327 return $errors;
1328 }
1329
1330 /**
1331 * Move forum content from one to another forum
1332 */
1333 function move_forum_content($from_id, $to_id, $sync = true)
1334 {
1335 global $db;
1336
1337 $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
1338
1339 foreach ($table_ary as $table)
1340 {
1341 $sql = "UPDATE $table
1342 SET forum_id = $to_id
1343 WHERE forum_id = $from_id";
1344 $db->sql_query($sql);
1345 }
1346 unset($table_ary);
1347
1348 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
1349
1350 foreach ($table_ary as $table)
1351 {
1352 $sql = "DELETE FROM $table
1353 WHERE forum_id = $from_id";
1354 $db->sql_query($sql);
1355 }
1356
1357 if ($sync)
1358 {
1359 // Delete ghost topics that link back to the same forum then resync counters
1360 sync('topic_moved');
1361 sync('forum', 'forum_id', $to_id, false, true);
1362 }
1363
1364 return array();
1365 }
1366
1367 /**
1368 * Remove complete forum
1369 */
1370 function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
1371 {
1372 global $db, $user, $cache;
1373
1374 $forum_data = $this->get_forum_info($forum_id);
1375
1376 $errors = array();
1377 $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
1378 $forum_ids = array($forum_id);
1379
1380 if ($action_posts == 'delete')
1381 {
1382 $log_action_posts = 'POSTS';
1383 $errors = array_merge($errors, $this->delete_forum_content($forum_id));
1384 }
1385 else if ($action_posts == 'move')
1386 {
1387 if (!$posts_to_id)
1388 {
1389 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1390 }
1391 else
1392 {
1393 $log_action_posts = 'MOVE_POSTS';
1394
1395 $sql = 'SELECT forum_name
1396 FROM ' . FORUMS_TABLE . '
1397 WHERE forum_id = ' . $posts_to_id;
1398 $result = $db->sql_query($sql);
1399 $row = $db->sql_fetchrow($result);
1400 $db->sql_freeresult($result);
1401
1402 if (!$row)
1403 {
1404 $errors[] = $user->lang['NO_FORUM'];
1405 }
1406 else
1407 {
1408 $posts_to_name = $row['forum_name'];
1409 $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
1410 }
1411 }
1412 }
1413
1414 if (sizeof($errors))
1415 {
1416 return $errors;
1417 }
1418
1419 if ($action_subforums == 'delete')
1420 {
1421 $log_action_forums = 'FORUMS';
1422 $rows = get_forum_branch($forum_id, 'children', 'descending', false);
1423
1424 foreach ($rows as $row)
1425 {
1426 $forum_ids[] = $row['forum_id'];
1427 $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
1428 }
1429
1430 if (sizeof($errors))
1431 {
1432 return $errors;
1433 }
1434
1435 $diff = sizeof($forum_ids) * 2;
1436
1437 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1438 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1439 $db->sql_query($sql);
1440
1441 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1442 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1443 $db->sql_query($sql);
1444
1445 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1446 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1447 $db->sql_query($sql);
1448 }
1449 else if ($action_subforums == 'move')
1450 {
1451 if (!$subforums_to_id)
1452 {
1453 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1454 }
1455 else
1456 {
1457 $log_action_forums = 'MOVE_FORUMS';
1458
1459 $sql = 'SELECT forum_name
1460 FROM ' . FORUMS_TABLE . '
1461 WHERE forum_id = ' . $subforums_to_id;
1462 $result = $db->sql_query($sql);
1463 $row = $db->sql_fetchrow($result);
1464 $db->sql_freeresult($result);
1465
1466 if (!$row)
1467 {
1468 $errors[] = $user->lang['NO_FORUM'];
1469 }
1470 else
1471 {
1472 $subforums_to_name = $row['forum_name'];
1473
1474 $sql = 'SELECT forum_id
1475 FROM ' . FORUMS_TABLE . "
1476 WHERE parent_id = $forum_id";
1477 $result = $db->sql_query($sql);
1478
1479 while ($row = $db->sql_fetchrow($result))
1480 {
1481 $this->move_forum($row['forum_id'], $subforums_to_id);
1482 }
1483 $db->sql_freeresult($result);
1484
1485 // Grab new forum data for correct tree updating later
1486 $forum_data = $this->get_forum_info($forum_id);
1487
1488 $sql = 'UPDATE ' . FORUMS_TABLE . "
1489 SET parent_id = $subforums_to_id
1490 WHERE parent_id = $forum_id";
1491 $db->sql_query($sql);
1492
1493 $diff = 2;
1494 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1495 WHERE forum_id = $forum_id";
1496 $db->sql_query($sql);
1497
1498 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1499 WHERE forum_id = $forum_id";
1500 $db->sql_query($sql);
1501
1502 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1503 WHERE forum_id = $forum_id";
1504 $db->sql_query($sql);
1505 }
1506 }
1507
1508 if (sizeof($errors))
1509 {
1510 return $errors;
1511 }
1512 }
1513 else
1514 {
1515 $diff = 2;
1516 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1517 WHERE forum_id = $forum_id";
1518 $db->sql_query($sql);
1519
1520 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1521 WHERE forum_id = $forum_id";
1522 $db->sql_query($sql);
1523
1524 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1525 WHERE forum_id = $forum_id";
1526 $db->sql_query($sql);
1527 }
1528
1529 // Resync tree
1530 $sql = 'UPDATE ' . FORUMS_TABLE . "
1531 SET right_id = right_id - $diff
1532 WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
1533 $db->sql_query($sql);
1534
1535 $sql = 'UPDATE ' . FORUMS_TABLE . "
1536 SET left_id = left_id - $diff, right_id = right_id - $diff
1537 WHERE left_id > {$forum_data['right_id']}";
1538 $db->sql_query($sql);
1539
1540 // Delete forum ids from extension groups table
1541 $sql = 'SELECT group_id, allowed_forums
1542 FROM ' . EXTENSION_GROUPS_TABLE;
1543 $result = $db->sql_query($sql);
1544
1545 while ($row = $db->sql_fetchrow($result))
1546 {
1547 if (!$row['allowed_forums'])
1548 {
1549 continue;
1550 }
1551
1552 $allowed_forums = unserialize(trim($row['allowed_forums']));
1553 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1554
1555 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1556 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1557 WHERE group_id = {$row['group_id']}";
1558 $db->sql_query($sql);
1559 }
1560 $db->sql_freeresult($result);
1561
1562 $cache->destroy('_extensions');
1563
1564 $log_action = implode('_', array($log_action_posts, $log_action_forums));
1565
1566 switch ($log_action)
1567 {
1568 case 'MOVE_POSTS_MOVE_FORUMS':
1569 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
1570 break;
1571
1572 case 'MOVE_POSTS_FORUMS':
1573 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
1574 break;
1575
1576 case 'POSTS_MOVE_FORUMS':
1577 add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1578 break;
1579
1580 case '_MOVE_FORUMS':
1581 add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1582 break;
1583
1584 case 'MOVE_POSTS_':
1585 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
1586 break;
1587
1588 case 'POSTS_FORUMS':
1589 add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
1590 break;
1591
1592 case '_FORUMS':
1593 add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
1594 break;
1595
1596 case 'POSTS_':
1597 add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
1598 break;
1599
1600 default:
1601 add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
1602 break;
1603 }
1604
1605 return $errors;
1606 }
1607
1608 /**
1609 * Delete forum content
1610 */
1611 function delete_forum_content($forum_id)
1612 {
1613 global $db, $config, $phpbb_root_path, $phpEx;
1614
1615 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1616
1617 $db->sql_transaction('begin');
1618
1619 // Select then delete all attachments
1620 $sql = 'SELECT a.topic_id
1621 FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
1622 WHERE p.forum_id = $forum_id
1623 AND a.in_message = 0
1624 AND a.topic_id = p.topic_id";
1625 $result = $db->sql_query($sql);
1626
1627 $topic_ids = array();
1628 while ($row = $db->sql_fetchrow($result))
1629 {
1630 $topic_ids[] = $row['topic_id'];
1631 }
1632 $db->sql_freeresult($result);
1633
1634 delete_attachments('topic', $topic_ids, false);
1635
1636 // Before we remove anything we make sure we are able to adjust the post counts later. ;)
1637 $sql = 'SELECT poster_id
1638 FROM ' . POSTS_TABLE . '
1639 WHERE forum_id = ' . $forum_id . '
1640 AND post_postcount = 1';
1641 $result = $db->sql_query($sql);
1642
1643 $post_counts = array();
1644 while ($row = $db->sql_fetchrow($result))
1645 {
1646 $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
1647 }
1648 $db->sql_freeresult($result);
1649
1650 switch ($db->sql_layer)
1651 {
1652 case 'mysql4':
1653 case 'mysqli':
1654
1655 // Delete everything else and thank MySQL for offering multi-table deletion
1656 $tables_ary = array(
1657 SEARCH_WORDMATCH_TABLE => 'post_id',
1658 REPORTS_TABLE => 'post_id',
1659 WARNINGS_TABLE => 'post_id',
1660 BOOKMARKS_TABLE => 'topic_id',
1661 TOPICS_WATCH_TABLE => 'topic_id',
1662 TOPICS_POSTED_TABLE => 'topic_id',
1663 POLL_OPTIONS_TABLE => 'topic_id',
1664 POLL_VOTES_TABLE => 'topic_id',
1665 );
1666
1667 $sql = 'DELETE ' . POSTS_TABLE;
1668 $sql_using = "\nFROM " . POSTS_TABLE;
1669 $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
1670
1671 foreach ($tables_ary as $table => $field)
1672 {
1673 $sql .= ", $table ";
1674 $sql_using .= ", $table ";
1675 $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
1676 }
1677
1678 $db->sql_query($sql . $sql_using . $sql_where);
1679
1680 break;
1681
1682 default:
1683
1684 // Delete everything else and curse your DB for not offering multi-table deletion
1685 $tables_ary = array(
1686 'post_id' => array(
1687 SEARCH_WORDMATCH_TABLE,
1688 REPORTS_TABLE,
1689 WARNINGS_TABLE,
1690 ),
1691
1692 'topic_id' => array(
1693 BOOKMARKS_TABLE,
1694 TOPICS_WATCH_TABLE,
1695 TOPICS_POSTED_TABLE,
1696 POLL_OPTIONS_TABLE,
1697 POLL_VOTES_TABLE,
1698 )
1699 );
1700
1701 foreach ($tables_ary as $field => $tables)
1702 {
1703 $start = 0;
1704
1705 do
1706 {
1707 $sql = "SELECT $field
1708 FROM " . POSTS_TABLE . '
1709 WHERE forum_id = ' . $forum_id;
1710 $result = $db->sql_query_limit($sql, 500, $start);
1711
1712 $ids = array();
1713 while ($row = $db->sql_fetchrow($result))
1714 {
1715 $ids[] = $row[$field];
1716 }
1717 $db->sql_freeresult($result);
1718
1719 if (sizeof($ids))
1720 {
1721 $start += sizeof($ids);
1722
1723 foreach ($tables as $table)
1724 {
1725 $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
1726 }
1727 }
1728 }
1729 while ($row);
1730 }
1731 unset($ids);
1732
1733 break;
1734 }
1735
1736 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
1737
1738 foreach ($table_ary as $table)
1739 {
1740 $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
1741 }
1742
1743 // Set forum ids to 0
1744 $table_ary = array(DRAFTS_TABLE);
1745
1746 foreach ($table_ary as $table)
1747 {
1748 $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
1749 }
1750
1751 // Adjust users post counts
1752 if (sizeof($post_counts))
1753 {
1754 foreach ($post_counts as $poster_id => $substract)
1755 {
1756 $sql = 'UPDATE ' . USERS_TABLE . '
1757 SET user_posts = 0
1758 WHERE user_id = ' . $poster_id . '
1759 AND user_posts < ' . $substract;
1760 $db->sql_query($sql);
1761 $sql = 'UPDATE ' . USERS_TABLE . '
1762 SET user_posts = user_posts - ' . $substract . '
1763 WHERE user_id = ' . $poster_id . '
1764 AND user_posts >= ' . $substract;
1765 $db->sql_query($sql);
1766 }
1767 }
1768
1769 $db->sql_transaction('commit');
1770
1771 // Make sure the overall post/topic count is correct...
1772 $sql = 'SELECT COUNT(post_id) AS stat
1773 FROM ' . POSTS_TABLE . '
1774 WHERE post_approved = 1';
1775 $result = $db->sql_query($sql);
1776 $row = $db->sql_fetchrow($result);
1777 $db->sql_freeresult($result);
1778
1779 set_config('num_posts', (int) $row['stat'], true);
1780
1781 $sql = 'SELECT COUNT(topic_id) AS stat
1782 FROM ' . TOPICS_TABLE . '
1783 WHERE topic_approved = 1';
1784 $result = $db->sql_query($sql);
1785 $row = $db->sql_fetchrow($result);
1786 $db->sql_freeresult($result);
1787
1788 set_config('num_topics', (int) $row['stat'], true);
1789
1790 $sql = 'SELECT COUNT(attach_id) as stat
1791 FROM ' . ATTACHMENTS_TABLE;
1792 $result = $db->sql_query($sql);
1793 $row = $db->sql_fetchrow($result);
1794 $db->sql_freeresult($result);
1795
1796 set_config('num_files', (int) $row['stat'], true);
1797
1798 $sql = 'SELECT SUM(filesize) as stat
1799 FROM ' . ATTACHMENTS_TABLE;
1800 $result = $db->sql_query($sql);
1801 $row = $db->sql_fetchrow($result);
1802 $db->sql_freeresult($result);
1803
1804 set_config('upload_dir_size', (int) $row['stat'], true);
1805
1806 return array();
1807 }
1808
1809 /**
1810 * Move forum position by $steps up/down
1811 */
1812 function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
1813 {
1814 global $db;
1815
1816 /**
1817 * Fetch all the siblings between the module's current spot
1818 * and where we want to move it to. If there are less than $steps
1819 * siblings between the current spot and the target then the
1820 * module will move as far as possible
1821 */
1822 $sql = 'SELECT forum_id, forum_name, left_id, right_id
1823 FROM ' . FORUMS_TABLE . "
1824 WHERE parent_id = {$forum_row['parent_id']}
1825 AND " . (($action == 'move_up') ? "right_id < {$forum_row['right_id']} ORDER BY right_id DESC" : "left_id > {$forum_row['left_id']} ORDER BY left_id ASC");
1826 $result = $db->sql_query_limit($sql, $steps);
1827
1828 $target = array();
1829 while ($row = $db->sql_fetchrow($result))
1830 {
1831 $target = $row;
1832 }
1833 $db->sql_freeresult($result);
1834
1835 if (!sizeof($target))
1836 {
1837 // The forum is already on top or bottom
1838 return false;
1839 }
1840
1841 /**
1842 * $left_id and $right_id define the scope of the nodes that are affected by the move.
1843 * $diff_up and $diff_down are the values to substract or add to each node's left_id
1844 * and right_id in order to move them up or down.
1845 * $move_up_left and $move_up_right define the scope of the nodes that are moving
1846 * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
1847 */
1848 if ($action == 'move_up')
1849 {
1850 $left_id = $target['left_id'];
1851 $right_id = $forum_row['right_id'];
1852
1853 $diff_up = $forum_row['left_id'] - $target['left_id'];
1854 $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1855
1856 $move_up_left = $forum_row['left_id'];
1857 $move_up_right = $forum_row['right_id'];
1858 }
1859 else
1860 {
1861 $left_id = $forum_row['left_id'];
1862 $right_id = $target['right_id'];
1863
1864 $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1865 $diff_down = $target['right_id'] - $forum_row['right_id'];
1866
1867 $move_up_left = $forum_row['right_id'] + 1;
1868 $move_up_right = $target['right_id'];
1869 }
1870
1871 // Now do the dirty job
1872 $sql = 'UPDATE ' . FORUMS_TABLE . "
1873 SET left_id = left_id + CASE
1874 WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1875 ELSE {$diff_down}
1876 END,
1877 right_id = right_id + CASE
1878 WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1879 ELSE {$diff_down}
1880 END,
1881 forum_parents = ''
1882 WHERE
1883 left_id BETWEEN {$left_id} AND {$right_id}
1884 AND right_id BETWEEN {$left_id} AND {$right_id}";
1885 $db->sql_query($sql);
1886
1887 return $target['forum_name'];
1888 }
1889
1890 /**
1891 * Display progress bar for syncinc forums
1892 */
1893 function display_progress_bar($start, $total)
1894 {
1895 global $template, $user;
1896
1897 adm_page_header($user->lang['SYNC_IN_PROGRESS']);
1898
1899 $template->set_filenames(array(
1900 'body' => 'progress_bar.html')
1901 );
1902
1903 $template->assign_vars(array(
1904 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
1905 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
1906 );
1907
1908 adm_page_footer();
1909 }
1910 }
1911
1912 ?>