1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/includes/acp/acp_forums.php Wed Mar 07 16:41:10 2012 +0400
1.3 @@ -0,0 +1,1950 @@
1.4 +<?php
1.5 +/**
1.6 +*
1.7 +* @package acp
1.8 +* @version $Id$
1.9 +* @copyright (c) 2005 phpBB Group
1.10 +* @license http://opensource.org/licenses/gpl-license.php GNU Public License
1.11 +*
1.12 +*/
1.13 +
1.14 +/**
1.15 +* @ignore
1.16 +*/
1.17 +if (!defined('IN_PHPBB'))
1.18 +{
1.19 + exit;
1.20 +}
1.21 +
1.22 +/**
1.23 +* @package acp
1.24 +*/
1.25 +class acp_forums
1.26 +{
1.27 + var $u_action;
1.28 + var $parent_id = 0;
1.29 +
1.30 + function main($id, $mode)
1.31 + {
1.32 + global $db, $user, $auth, $template, $cache;
1.33 + global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
1.34 +
1.35 + $user->add_lang('acp/forums');
1.36 + $this->tpl_name = 'acp_forums';
1.37 + $this->page_title = 'ACP_MANAGE_FORUMS';
1.38 +
1.39 + $form_key = 'acp_forums';
1.40 + add_form_key($form_key);
1.41 +
1.42 + $action = request_var('action', '');
1.43 + $update = (isset($_POST['update'])) ? true : false;
1.44 + $forum_id = request_var('f', 0);
1.45 +
1.46 + $this->parent_id = request_var('parent_id', 0);
1.47 + $forum_data = $errors = array();
1.48 + if ($update && !check_form_key($form_key))
1.49 + {
1.50 + $update = false;
1.51 + $errors[] = $user->lang['FORM_INVALID'];
1.52 + }
1.53 +
1.54 + // Check additional permissions
1.55 + switch ($action)
1.56 + {
1.57 + case 'progress_bar':
1.58 + $start = request_var('start', 0);
1.59 + $total = request_var('total', 0);
1.60 +
1.61 + $this->display_progress_bar($start, $total);
1.62 + exit;
1.63 + break;
1.64 +
1.65 + case 'delete':
1.66 +
1.67 + if (!$auth->acl_get('a_forumdel'))
1.68 + {
1.69 + trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.70 + }
1.71 +
1.72 + break;
1.73 +
1.74 + case 'add':
1.75 +
1.76 + if (!$auth->acl_get('a_forumadd'))
1.77 + {
1.78 + trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.79 + }
1.80 +
1.81 + break;
1.82 + }
1.83 +
1.84 + // Major routines
1.85 + if ($update)
1.86 + {
1.87 + switch ($action)
1.88 + {
1.89 + case 'delete':
1.90 + $action_subforums = request_var('action_subforums', '');
1.91 + $subforums_to_id = request_var('subforums_to_id', 0);
1.92 + $action_posts = request_var('action_posts', '');
1.93 + $posts_to_id = request_var('posts_to_id', 0);
1.94 +
1.95 + $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
1.96 +
1.97 + if (sizeof($errors))
1.98 + {
1.99 + break;
1.100 + }
1.101 +
1.102 + $auth->acl_clear_prefetch();
1.103 + $cache->destroy('sql', FORUMS_TABLE);
1.104 +
1.105 + trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
1.106 +
1.107 + break;
1.108 +
1.109 + case 'edit':
1.110 + $forum_data = array(
1.111 + 'forum_id' => $forum_id
1.112 + );
1.113 +
1.114 + // No break here
1.115 +
1.116 + case 'add':
1.117 +
1.118 + $forum_data += array(
1.119 + 'parent_id' => request_var('forum_parent_id', $this->parent_id),
1.120 + 'forum_type' => request_var('forum_type', FORUM_POST),
1.121 + 'type_action' => request_var('type_action', ''),
1.122 + 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
1.123 + 'forum_parents' => '',
1.124 + 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
1.125 + 'forum_link' => request_var('forum_link', ''),
1.126 + 'forum_link_track' => request_var('forum_link_track', false),
1.127 + 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
1.128 + 'forum_desc_uid' => '',
1.129 + 'forum_desc_options' => 7,
1.130 + 'forum_desc_bitfield' => '',
1.131 + 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
1.132 + 'forum_rules_uid' => '',
1.133 + 'forum_rules_options' => 7,
1.134 + 'forum_rules_bitfield' => '',
1.135 + 'forum_rules_link' => request_var('forum_rules_link', ''),
1.136 + 'forum_image' => request_var('forum_image', ''),
1.137 + 'forum_style' => request_var('forum_style', 0),
1.138 + 'display_subforum_list' => request_var('display_subforum_list', false),
1.139 + 'display_on_index' => request_var('display_on_index', false),
1.140 + 'forum_topics_per_page' => request_var('topics_per_page', 0),
1.141 + 'enable_indexing' => request_var('enable_indexing', true),
1.142 + 'enable_icons' => request_var('enable_icons', false),
1.143 + 'enable_prune' => request_var('enable_prune', false),
1.144 + 'enable_post_review' => request_var('enable_post_review', true),
1.145 + 'enable_quick_reply' => request_var('enable_quick_reply', false),
1.146 + 'prune_days' => request_var('prune_days', 7),
1.147 + 'prune_viewed' => request_var('prune_viewed', 7),
1.148 + 'prune_freq' => request_var('prune_freq', 1),
1.149 + 'prune_old_polls' => request_var('prune_old_polls', false),
1.150 + 'prune_announce' => request_var('prune_announce', false),
1.151 + 'prune_sticky' => request_var('prune_sticky', false),
1.152 + 'forum_password' => request_var('forum_password', '', true),
1.153 + 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
1.154 + 'forum_password_unset' => request_var('forum_password_unset', false),
1.155 + );
1.156 +
1.157 + // On add, add empty forum_options... else do not consider it (not updating it)
1.158 + if ($action == 'add')
1.159 + {
1.160 + $forum_data['forum_options'] = 0;
1.161 + }
1.162 +
1.163 + // Use link_display_on_index setting if forum type is link
1.164 + if ($forum_data['forum_type'] == FORUM_LINK)
1.165 + {
1.166 + $forum_data['display_on_index'] = request_var('link_display_on_index', false);
1.167 + }
1.168 +
1.169 + // Linked forums and categories are not able to be locked...
1.170 + if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
1.171 + {
1.172 + $forum_data['forum_status'] = ITEM_UNLOCKED;
1.173 + }
1.174 +
1.175 + $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', false);
1.176 +
1.177 + // Get data for forum rules if specified...
1.178 + if ($forum_data['forum_rules'])
1.179 + {
1.180 + 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));
1.181 + }
1.182 +
1.183 + // Get data for forum description if specified
1.184 + if ($forum_data['forum_desc'])
1.185 + {
1.186 + 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));
1.187 + }
1.188 +
1.189 + $errors = $this->update_forum_data($forum_data);
1.190 +
1.191 + if (!sizeof($errors))
1.192 + {
1.193 + $forum_perm_from = request_var('forum_perm_from', 0);
1.194 + $cache->destroy('sql', FORUMS_TABLE);
1.195 +
1.196 + $copied_permissions = false;
1.197 + // Copy permissions?
1.198 + if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
1.199 + ($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'))))
1.200 + {
1.201 + copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
1.202 + cache_moderators();
1.203 + $copied_permissions = true;
1.204 + }
1.205 +/* Commented out because of questionable UI workflow - re-visit for 3.0.7
1.206 + else if (!$this->parent_id && $action != 'edit' && $auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth'))
1.207 + {
1.208 + $this->copy_permission_page($forum_data);
1.209 + return;
1.210 + }
1.211 +*/
1.212 + $auth->acl_clear_prefetch();
1.213 +
1.214 + $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
1.215 +
1.216 + $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
1.217 +
1.218 + // redirect directly to permission settings screen if authed
1.219 + if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
1.220 + {
1.221 + $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
1.222 +
1.223 + meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
1.224 + }
1.225 +
1.226 + trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
1.227 + }
1.228 +
1.229 + break;
1.230 + }
1.231 + }
1.232 +
1.233 + switch ($action)
1.234 + {
1.235 + case 'move_up':
1.236 + case 'move_down':
1.237 +
1.238 + if (!$forum_id)
1.239 + {
1.240 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.241 + }
1.242 +
1.243 + $sql = 'SELECT *
1.244 + FROM ' . FORUMS_TABLE . "
1.245 + WHERE forum_id = $forum_id";
1.246 + $result = $db->sql_query($sql);
1.247 + $row = $db->sql_fetchrow($result);
1.248 + $db->sql_freeresult($result);
1.249 +
1.250 + if (!$row)
1.251 + {
1.252 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.253 + }
1.254 +
1.255 + $move_forum_name = $this->move_forum_by($row, $action, 1);
1.256 +
1.257 + if ($move_forum_name !== false)
1.258 + {
1.259 + add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
1.260 + $cache->destroy('sql', FORUMS_TABLE);
1.261 + }
1.262 +
1.263 + break;
1.264 +
1.265 + case 'sync':
1.266 + if (!$forum_id)
1.267 + {
1.268 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.269 + }
1.270 +
1.271 + @set_time_limit(0);
1.272 +
1.273 + $sql = 'SELECT forum_name, forum_topics_real
1.274 + FROM ' . FORUMS_TABLE . "
1.275 + WHERE forum_id = $forum_id";
1.276 + $result = $db->sql_query($sql);
1.277 + $row = $db->sql_fetchrow($result);
1.278 + $db->sql_freeresult($result);
1.279 +
1.280 + if (!$row)
1.281 + {
1.282 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.283 + }
1.284 +
1.285 + if ($row['forum_topics_real'])
1.286 + {
1.287 + $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
1.288 + FROM ' . TOPICS_TABLE . '
1.289 + WHERE forum_id = ' . $forum_id;
1.290 + $result = $db->sql_query($sql);
1.291 + $row2 = $db->sql_fetchrow($result);
1.292 + $db->sql_freeresult($result);
1.293 +
1.294 + // Typecast to int if there is no data available
1.295 + $row2['min_topic_id'] = (int) $row2['min_topic_id'];
1.296 + $row2['max_topic_id'] = (int) $row2['max_topic_id'];
1.297 +
1.298 + $start = request_var('start', $row2['min_topic_id']);
1.299 +
1.300 + $batch_size = 2000;
1.301 + $end = $start + $batch_size;
1.302 +
1.303 + // Sync all topics in batch mode...
1.304 + sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
1.305 + sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
1.306 +
1.307 + if ($end < $row2['max_topic_id'])
1.308 + {
1.309 + // We really need to find a way of showing statistics... no progress here
1.310 + $sql = 'SELECT COUNT(topic_id) as num_topics
1.311 + FROM ' . TOPICS_TABLE . '
1.312 + WHERE forum_id = ' . $forum_id . '
1.313 + AND topic_id BETWEEN ' . $start . ' AND ' . $end;
1.314 + $result = $db->sql_query($sql);
1.315 + $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
1.316 + $db->sql_freeresult($result);
1.317 +
1.318 + $start += $batch_size;
1.319 +
1.320 + $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']}";
1.321 +
1.322 + meta_refresh(0, $url);
1.323 +
1.324 + $template->assign_vars(array(
1.325 + 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}",
1.326 + 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"),
1.327 + 'S_CONTINUE_SYNC' => true,
1.328 + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
1.329 + );
1.330 +
1.331 + return;
1.332 + }
1.333 + }
1.334 +
1.335 + $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
1.336 + meta_refresh(0, $url);
1.337 +
1.338 + $template->assign_vars(array(
1.339 + 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
1.340 + 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
1.341 + 'S_CONTINUE_SYNC' => true,
1.342 + 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
1.343 + );
1.344 +
1.345 + return;
1.346 +
1.347 + break;
1.348 +
1.349 + case 'sync_forum':
1.350 +
1.351 + $sql = 'SELECT forum_name, forum_type
1.352 + FROM ' . FORUMS_TABLE . "
1.353 + WHERE forum_id = $forum_id";
1.354 + $result = $db->sql_query($sql);
1.355 + $row = $db->sql_fetchrow($result);
1.356 + $db->sql_freeresult($result);
1.357 +
1.358 + if (!$row)
1.359 + {
1.360 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.361 + }
1.362 +
1.363 + sync('forum', 'forum_id', $forum_id, false, true);
1.364 +
1.365 + add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
1.366 + $cache->destroy('sql', FORUMS_TABLE);
1.367 +
1.368 + $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
1.369 +
1.370 + break;
1.371 +
1.372 + case 'add':
1.373 + case 'edit':
1.374 +
1.375 + if ($update)
1.376 + {
1.377 + $forum_data['forum_flags'] = 0;
1.378 + $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
1.379 + $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
1.380 + $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
1.381 + $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
1.382 + $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
1.383 + $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
1.384 + $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
1.385 + }
1.386 +
1.387 + // Show form to create/modify a forum
1.388 + if ($action == 'edit')
1.389 + {
1.390 + $this->page_title = 'EDIT_FORUM';
1.391 + $row = $this->get_forum_info($forum_id);
1.392 + $old_forum_type = $row['forum_type'];
1.393 +
1.394 + if (!$update)
1.395 + {
1.396 + $forum_data = $row;
1.397 + }
1.398 + else
1.399 + {
1.400 + $forum_data['left_id'] = $row['left_id'];
1.401 + $forum_data['right_id'] = $row['right_id'];
1.402 + }
1.403 +
1.404 + // Make sure no direct child forums are able to be selected as parents.
1.405 + $exclude_forums = array();
1.406 + foreach (get_forum_branch($forum_id, 'children') as $row)
1.407 + {
1.408 + $exclude_forums[] = $row['forum_id'];
1.409 + }
1.410 +
1.411 + $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
1.412 +
1.413 + $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
1.414 + }
1.415 + else
1.416 + {
1.417 + $this->page_title = 'CREATE_FORUM';
1.418 +
1.419 + $forum_id = $this->parent_id;
1.420 + $parents_list = make_forum_select($this->parent_id, false, false, false, false);
1.421 +
1.422 + // Fill forum data with default values
1.423 + if (!$update)
1.424 + {
1.425 + $forum_data = array(
1.426 + 'parent_id' => $this->parent_id,
1.427 + 'forum_type' => FORUM_POST,
1.428 + 'forum_status' => ITEM_UNLOCKED,
1.429 + 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
1.430 + 'forum_link' => '',
1.431 + 'forum_link_track' => false,
1.432 + 'forum_desc' => '',
1.433 + 'forum_rules' => '',
1.434 + 'forum_rules_link' => '',
1.435 + 'forum_image' => '',
1.436 + 'forum_style' => 0,
1.437 + 'display_subforum_list' => true,
1.438 + 'display_on_index' => false,
1.439 + 'forum_topics_per_page' => 0,
1.440 + 'enable_indexing' => true,
1.441 + 'enable_icons' => false,
1.442 + 'enable_prune' => false,
1.443 + 'prune_days' => 7,
1.444 + 'prune_viewed' => 7,
1.445 + 'prune_freq' => 1,
1.446 + 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
1.447 + 'forum_options' => 0,
1.448 + 'forum_password' => '',
1.449 + 'forum_password_confirm'=> '',
1.450 + );
1.451 + }
1.452 + }
1.453 +
1.454 + $forum_rules_data = array(
1.455 + 'text' => $forum_data['forum_rules'],
1.456 + 'allow_bbcode' => true,
1.457 + 'allow_smilies' => true,
1.458 + 'allow_urls' => true
1.459 + );
1.460 +
1.461 + $forum_desc_data = array(
1.462 + 'text' => $forum_data['forum_desc'],
1.463 + 'allow_bbcode' => true,
1.464 + 'allow_smilies' => true,
1.465 + 'allow_urls' => true
1.466 + );
1.467 +
1.468 + $forum_rules_preview = '';
1.469 +
1.470 + // Parse rules if specified
1.471 + if ($forum_data['forum_rules'])
1.472 + {
1.473 + if (!isset($forum_data['forum_rules_uid']))
1.474 + {
1.475 + // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
1.476 + $forum_data['forum_rules_uid'] = '';
1.477 + $forum_data['forum_rules_bitfield'] = '';
1.478 + $forum_data['forum_rules_options'] = 0;
1.479 +
1.480 + 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));
1.481 + }
1.482 +
1.483 + // Generate preview content
1.484 + $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']);
1.485 +
1.486 + // decode...
1.487 + $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
1.488 + }
1.489 +
1.490 + // Parse desciption if specified
1.491 + if ($forum_data['forum_desc'])
1.492 + {
1.493 + if (!isset($forum_data['forum_desc_uid']))
1.494 + {
1.495 + // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
1.496 + $forum_data['forum_desc_uid'] = '';
1.497 + $forum_data['forum_desc_bitfield'] = '';
1.498 + $forum_data['forum_desc_options'] = 0;
1.499 +
1.500 + 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));
1.501 + }
1.502 +
1.503 + // decode...
1.504 + $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
1.505 + }
1.506 +
1.507 + $forum_type_options = '';
1.508 + $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
1.509 +
1.510 + foreach ($forum_type_ary as $value => $lang)
1.511 + {
1.512 + $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
1.513 + }
1.514 +
1.515 + $styles_list = style_select($forum_data['forum_style'], true);
1.516 +
1.517 + $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>';
1.518 +
1.519 + $sql = 'SELECT forum_id
1.520 + FROM ' . FORUMS_TABLE . '
1.521 + WHERE forum_type = ' . FORUM_POST . "
1.522 + AND forum_id <> $forum_id";
1.523 + $result = $db->sql_query_limit($sql, 1);
1.524 +
1.525 + $postable_forum_exists = false;
1.526 + if ($db->sql_fetchrow($result))
1.527 + {
1.528 + $postable_forum_exists = true;
1.529 + }
1.530 + $db->sql_freeresult($result);
1.531 +
1.532 + // Subforum move options
1.533 + if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
1.534 + {
1.535 + $subforums_id = array();
1.536 + $subforums = get_forum_branch($forum_id, 'children');
1.537 +
1.538 + foreach ($subforums as $row)
1.539 + {
1.540 + $subforums_id[] = $row['forum_id'];
1.541 + }
1.542 +
1.543 + $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
1.544 +
1.545 + if ($postable_forum_exists)
1.546 + {
1.547 + $template->assign_vars(array(
1.548 + 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
1.549 + );
1.550 + }
1.551 +
1.552 + $template->assign_vars(array(
1.553 + 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
1.554 + 'S_FORUMS_LIST' => $forums_list)
1.555 + );
1.556 + }
1.557 + else if ($postable_forum_exists)
1.558 + {
1.559 + $template->assign_vars(array(
1.560 + 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
1.561 + );
1.562 + }
1.563 +
1.564 + $s_show_display_on_index = false;
1.565 +
1.566 + if ($forum_data['parent_id'] > 0)
1.567 + {
1.568 + // if this forum is a subforum put the "display on index" checkbox
1.569 + if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
1.570 + {
1.571 + if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
1.572 + {
1.573 + $s_show_display_on_index = true;
1.574 + }
1.575 + }
1.576 + }
1.577 +
1.578 + if (strlen($forum_data['forum_password']) == 32)
1.579 + {
1.580 + $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
1.581 + }
1.582 +
1.583 + $template->assign_vars(array(
1.584 + 'S_EDIT_FORUM' => true,
1.585 + 'S_ERROR' => (sizeof($errors)) ? true : false,
1.586 + 'S_PARENT_ID' => $this->parent_id,
1.587 + 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
1.588 + 'S_ADD_ACTION' => ($action == 'add') ? true : false,
1.589 +
1.590 + 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
1.591 + 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
1.592 +
1.593 + 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
1.594 + 'L_TITLE' => $user->lang[$this->page_title],
1.595 + 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
1.596 +
1.597 + 'FORUM_NAME' => $forum_data['forum_name'],
1.598 + 'FORUM_DATA_LINK' => $forum_data['forum_link'],
1.599 + 'FORUM_IMAGE' => $forum_data['forum_image'],
1.600 + 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
1.601 + 'FORUM_POST' => FORUM_POST,
1.602 + 'FORUM_LINK' => FORUM_LINK,
1.603 + 'FORUM_CAT' => FORUM_CAT,
1.604 + 'PRUNE_FREQ' => $forum_data['prune_freq'],
1.605 + 'PRUNE_DAYS' => $forum_data['prune_days'],
1.606 + 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
1.607 + 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
1.608 + 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
1.609 + 'FORUM_RULES' => $forum_data['forum_rules'],
1.610 + 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
1.611 + 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
1.612 + 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
1.613 + 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
1.614 + 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
1.615 + 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
1.616 +
1.617 + 'FORUM_DESC' => $forum_desc_data['text'],
1.618 + 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
1.619 + 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
1.620 + 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
1.621 +
1.622 + 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
1.623 + 'S_STATUS_OPTIONS' => $statuslist,
1.624 + 'S_PARENT_OPTIONS' => $parents_list,
1.625 + 'S_STYLES_OPTIONS' => $styles_list,
1.626 + 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
1.627 + 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
1.628 + 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
1.629 + 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
1.630 + 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
1.631 + 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
1.632 + 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
1.633 + 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
1.634 + 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
1.635 + 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
1.636 + 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
1.637 + 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
1.638 + 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
1.639 + 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
1.640 + 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
1.641 + 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
1.642 + 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
1.643 + 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
1.644 + 'S_ENABLE_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
1.645 + 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
1.646 + 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
1.647 + '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,
1.648 + ));
1.649 +
1.650 + return;
1.651 +
1.652 + break;
1.653 +
1.654 + case 'delete':
1.655 +
1.656 + if (!$forum_id)
1.657 + {
1.658 + trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.659 + }
1.660 +
1.661 + $forum_data = $this->get_forum_info($forum_id);
1.662 +
1.663 + $subforums_id = array();
1.664 + $subforums = get_forum_branch($forum_id, 'children');
1.665 +
1.666 + foreach ($subforums as $row)
1.667 + {
1.668 + $subforums_id[] = $row['forum_id'];
1.669 + }
1.670 +
1.671 + $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
1.672 +
1.673 + $sql = 'SELECT forum_id
1.674 + FROM ' . FORUMS_TABLE . '
1.675 + WHERE forum_type = ' . FORUM_POST . "
1.676 + AND forum_id <> $forum_id";
1.677 + $result = $db->sql_query_limit($sql, 1);
1.678 +
1.679 + if ($db->sql_fetchrow($result))
1.680 + {
1.681 + $template->assign_vars(array(
1.682 + 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
1.683 + );
1.684 + }
1.685 + $db->sql_freeresult($result);
1.686 +
1.687 + $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
1.688 +
1.689 + $template->assign_vars(array(
1.690 + 'S_DELETE_FORUM' => true,
1.691 + 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
1.692 + 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
1.693 +
1.694 + 'FORUM_NAME' => $forum_data['forum_name'],
1.695 + 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
1.696 + 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
1.697 + 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
1.698 + 'S_FORUMS_LIST' => $forums_list,
1.699 + 'S_ERROR' => (sizeof($errors)) ? true : false,
1.700 + 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
1.701 + );
1.702 +
1.703 + return;
1.704 + break;
1.705 +
1.706 + case 'copy_perm':
1.707 + $forum_perm_from = request_var('forum_perm_from', 0);
1.708 +
1.709 + // Copy permissions?
1.710 + if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
1.711 + {
1.712 + copy_forum_permissions($forum_perm_from, $forum_id, true);
1.713 + cache_moderators();
1.714 + $auth->acl_clear_prefetch();
1.715 + $cache->destroy('sql', FORUMS_TABLE);
1.716 +
1.717 + $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_id;
1.718 +
1.719 + $message = $user->lang['FORUM_UPDATED'];
1.720 +
1.721 + // Redirect to permissions
1.722 + if ($auth->acl_get('a_fauth'))
1.723 + {
1.724 + $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
1.725 + }
1.726 +
1.727 + trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
1.728 + }
1.729 +
1.730 + break;
1.731 + }
1.732 +
1.733 + // Default management page
1.734 + if (!$this->parent_id)
1.735 + {
1.736 + $navigation = $user->lang['FORUM_INDEX'];
1.737 + }
1.738 + else
1.739 + {
1.740 + $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
1.741 +
1.742 + $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
1.743 + foreach ($forums_nav as $row)
1.744 + {
1.745 + if ($row['forum_id'] == $this->parent_id)
1.746 + {
1.747 + $navigation .= ' -> ' . $row['forum_name'];
1.748 + }
1.749 + else
1.750 + {
1.751 + $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
1.752 + }
1.753 + }
1.754 + }
1.755 +
1.756 + // Jumpbox
1.757 + $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
1.758 +
1.759 + if ($action == 'sync' || $action == 'sync_forum')
1.760 + {
1.761 + $template->assign_var('S_RESYNCED', true);
1.762 + }
1.763 +
1.764 + $sql = 'SELECT *
1.765 + FROM ' . FORUMS_TABLE . "
1.766 + WHERE parent_id = $this->parent_id
1.767 + ORDER BY left_id";
1.768 + $result = $db->sql_query($sql);
1.769 +
1.770 + if ($row = $db->sql_fetchrow($result))
1.771 + {
1.772 + do
1.773 + {
1.774 + $forum_type = $row['forum_type'];
1.775 +
1.776 + if ($row['forum_status'] == ITEM_LOCKED)
1.777 + {
1.778 + $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
1.779 + }
1.780 + else
1.781 + {
1.782 + switch ($forum_type)
1.783 + {
1.784 + case FORUM_LINK:
1.785 + $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
1.786 + break;
1.787 +
1.788 + default:
1.789 + $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'] . '" />';
1.790 + break;
1.791 + }
1.792 + }
1.793 +
1.794 + $url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
1.795 +
1.796 + $template->assign_block_vars('forums', array(
1.797 + 'FOLDER_IMAGE' => $folder_image,
1.798 + 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
1.799 + 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
1.800 + 'FORUM_NAME' => $row['forum_name'],
1.801 + 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
1.802 + 'FORUM_TOPICS' => $row['forum_topics'],
1.803 + 'FORUM_POSTS' => $row['forum_posts'],
1.804 +
1.805 + 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
1.806 + 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
1.807 +
1.808 + 'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
1.809 + 'U_MOVE_UP' => $url . '&action=move_up',
1.810 + 'U_MOVE_DOWN' => $url . '&action=move_down',
1.811 + 'U_EDIT' => $url . '&action=edit',
1.812 + 'U_DELETE' => $url . '&action=delete',
1.813 + 'U_SYNC' => $url . '&action=sync')
1.814 + );
1.815 + }
1.816 + while ($row = $db->sql_fetchrow($result));
1.817 + }
1.818 + else if ($this->parent_id)
1.819 + {
1.820 + $row = $this->get_forum_info($this->parent_id);
1.821 +
1.822 + $url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
1.823 +
1.824 + $template->assign_vars(array(
1.825 + 'S_NO_FORUMS' => true,
1.826 +
1.827 + 'U_EDIT' => $url . '&action=edit',
1.828 + 'U_DELETE' => $url . '&action=delete',
1.829 + 'U_SYNC' => $url . '&action=sync')
1.830 + );
1.831 + }
1.832 + $db->sql_freeresult($result);
1.833 +
1.834 + $template->assign_vars(array(
1.835 + 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
1.836 + 'NAVIGATION' => $navigation,
1.837 + 'FORUM_BOX' => $forum_box,
1.838 + 'U_SEL_ACTION' => $this->u_action,
1.839 + 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
1.840 +
1.841 + 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
1.842 + 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
1.843 + ));
1.844 + }
1.845 +
1.846 + /**
1.847 + * Get forum details
1.848 + */
1.849 + function get_forum_info($forum_id)
1.850 + {
1.851 + global $db;
1.852 +
1.853 + $sql = 'SELECT *
1.854 + FROM ' . FORUMS_TABLE . "
1.855 + WHERE forum_id = $forum_id";
1.856 + $result = $db->sql_query($sql);
1.857 + $row = $db->sql_fetchrow($result);
1.858 + $db->sql_freeresult($result);
1.859 +
1.860 + if (!$row)
1.861 + {
1.862 + trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
1.863 + }
1.864 +
1.865 + return $row;
1.866 + }
1.867 +
1.868 + /**
1.869 + * Update forum data
1.870 + */
1.871 + function update_forum_data(&$forum_data)
1.872 + {
1.873 + global $db, $user, $cache, $phpbb_root_path;
1.874 +
1.875 + $errors = array();
1.876 +
1.877 + if ($forum_data['forum_name'] == '')
1.878 + {
1.879 + $errors[] = $user->lang['FORUM_NAME_EMPTY'];
1.880 + }
1.881 +
1.882 + if (utf8_strlen($forum_data['forum_desc']) > 4000)
1.883 + {
1.884 + $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
1.885 + }
1.886 +
1.887 + if (utf8_strlen($forum_data['forum_rules']) > 4000)
1.888 + {
1.889 + $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
1.890 + }
1.891 +
1.892 + if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
1.893 + {
1.894 + if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
1.895 + {
1.896 + $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
1.897 + $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
1.898 + }
1.899 + }
1.900 +
1.901 + if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
1.902 + {
1.903 + $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
1.904 + $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
1.905 + }
1.906 +
1.907 + $range_test_ary = array(
1.908 + array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
1.909 + );
1.910 +
1.911 + if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
1.912 + {
1.913 + $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
1.914 + }
1.915 +
1.916 + validate_range($range_test_ary, $errors);
1.917 +
1.918 + // Set forum flags
1.919 + // 1 = link tracking
1.920 + // 2 = prune old polls
1.921 + // 4 = prune announcements
1.922 + // 8 = prune stickies
1.923 + // 16 = show active topics
1.924 + // 32 = enable post review
1.925 + $forum_data['forum_flags'] = 0;
1.926 + $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
1.927 + $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
1.928 + $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
1.929 + $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
1.930 + $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
1.931 + $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
1.932 + $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
1.933 +
1.934 + // Unset data that are not database fields
1.935 + $forum_data_sql = $forum_data;
1.936 +
1.937 + unset($forum_data_sql['forum_link_track']);
1.938 + unset($forum_data_sql['prune_old_polls']);
1.939 + unset($forum_data_sql['prune_announce']);
1.940 + unset($forum_data_sql['prune_sticky']);
1.941 + unset($forum_data_sql['show_active']);
1.942 + unset($forum_data_sql['enable_post_review']);
1.943 + unset($forum_data_sql['enable_quick_reply']);
1.944 + unset($forum_data_sql['forum_password_confirm']);
1.945 +
1.946 + // What are we going to do tonight Brain? The same thing we do everynight,
1.947 + // try to take over the world ... or decide whether to continue update
1.948 + // and if so, whether it's a new forum/cat/link or an existing one
1.949 + if (sizeof($errors))
1.950 + {
1.951 + return $errors;
1.952 + }
1.953 +
1.954 + // As we don't know the old password, it's kinda tricky to detect changes
1.955 + if ($forum_data_sql['forum_password_unset'])
1.956 + {
1.957 + $forum_data_sql['forum_password'] = '';
1.958 + }
1.959 + else if (empty($forum_data_sql['forum_password']))
1.960 + {
1.961 + unset($forum_data_sql['forum_password']);
1.962 + }
1.963 + else
1.964 + {
1.965 + $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
1.966 + }
1.967 + unset($forum_data_sql['forum_password_unset']);
1.968 +
1.969 + if (!isset($forum_data_sql['forum_id']))
1.970 + {
1.971 + // no forum_id means we're creating a new forum
1.972 + unset($forum_data_sql['type_action']);
1.973 +
1.974 + if ($forum_data_sql['parent_id'])
1.975 + {
1.976 + $sql = 'SELECT left_id, right_id, forum_type
1.977 + FROM ' . FORUMS_TABLE . '
1.978 + WHERE forum_id = ' . $forum_data_sql['parent_id'];
1.979 + $result = $db->sql_query($sql);
1.980 + $row = $db->sql_fetchrow($result);
1.981 + $db->sql_freeresult($result);
1.982 +
1.983 + if (!$row)
1.984 + {
1.985 + trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
1.986 + }
1.987 +
1.988 + if ($row['forum_type'] == FORUM_LINK)
1.989 + {
1.990 + $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1.991 + return $errors;
1.992 + }
1.993 +
1.994 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.995 + SET left_id = left_id + 2, right_id = right_id + 2
1.996 + WHERE left_id > ' . $row['right_id'];
1.997 + $db->sql_query($sql);
1.998 +
1.999 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.1000 + SET right_id = right_id + 2
1.1001 + WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
1.1002 + $db->sql_query($sql);
1.1003 +
1.1004 + $forum_data_sql['left_id'] = $row['right_id'];
1.1005 + $forum_data_sql['right_id'] = $row['right_id'] + 1;
1.1006 + }
1.1007 + else
1.1008 + {
1.1009 + $sql = 'SELECT MAX(right_id) AS right_id
1.1010 + FROM ' . FORUMS_TABLE;
1.1011 + $result = $db->sql_query($sql);
1.1012 + $row = $db->sql_fetchrow($result);
1.1013 + $db->sql_freeresult($result);
1.1014 +
1.1015 + $forum_data_sql['left_id'] = $row['right_id'] + 1;
1.1016 + $forum_data_sql['right_id'] = $row['right_id'] + 2;
1.1017 + }
1.1018 +
1.1019 + $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
1.1020 + $db->sql_query($sql);
1.1021 +
1.1022 + $forum_data['forum_id'] = $db->sql_nextid();
1.1023 +
1.1024 + add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
1.1025 + }
1.1026 + else
1.1027 + {
1.1028 + $row = $this->get_forum_info($forum_data_sql['forum_id']);
1.1029 +
1.1030 + if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
1.1031 + {
1.1032 + // Has subforums and want to change into a link?
1.1033 + if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
1.1034 + {
1.1035 + $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
1.1036 + return $errors;
1.1037 + }
1.1038 +
1.1039 + // we're turning a postable forum into a non-postable forum
1.1040 + if ($forum_data_sql['type_action'] == 'move')
1.1041 + {
1.1042 + $to_forum_id = request_var('to_forum_id', 0);
1.1043 +
1.1044 + if ($to_forum_id)
1.1045 + {
1.1046 + $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
1.1047 + }
1.1048 + else
1.1049 + {
1.1050 + return array($user->lang['NO_DESTINATION_FORUM']);
1.1051 + }
1.1052 + }
1.1053 + else if ($forum_data_sql['type_action'] == 'delete')
1.1054 + {
1.1055 + $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
1.1056 + }
1.1057 + else
1.1058 + {
1.1059 + return array($user->lang['NO_FORUM_ACTION']);
1.1060 + }
1.1061 +
1.1062 + $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;
1.1063 + $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
1.1064 + }
1.1065 + else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
1.1066 + {
1.1067 + // Has subforums?
1.1068 + if ($row['right_id'] - $row['left_id'] > 1)
1.1069 + {
1.1070 + // We are turning a category into a link - but need to decide what to do with the subforums.
1.1071 + $action_subforums = request_var('action_subforums', '');
1.1072 + $subforums_to_id = request_var('subforums_to_id', 0);
1.1073 +
1.1074 + if ($action_subforums == 'delete')
1.1075 + {
1.1076 + $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
1.1077 +
1.1078 + foreach ($rows as $_row)
1.1079 + {
1.1080 + // Do not remove the forum id we are about to change. ;)
1.1081 + if ($_row['forum_id'] == $row['forum_id'])
1.1082 + {
1.1083 + continue;
1.1084 + }
1.1085 +
1.1086 + $forum_ids[] = $_row['forum_id'];
1.1087 + $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
1.1088 + }
1.1089 +
1.1090 + if (sizeof($errors))
1.1091 + {
1.1092 + return $errors;
1.1093 + }
1.1094 +
1.1095 + if (sizeof($forum_ids))
1.1096 + {
1.1097 + $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1.1098 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1099 + $db->sql_query($sql);
1.1100 +
1.1101 + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1.1102 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1103 + $db->sql_query($sql);
1.1104 +
1.1105 + $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1.1106 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1107 + $db->sql_query($sql);
1.1108 +
1.1109 + // Delete forum ids from extension groups table
1.1110 + $sql = 'SELECT group_id, allowed_forums
1.1111 + FROM ' . EXTENSION_GROUPS_TABLE;
1.1112 + $result = $db->sql_query($sql);
1.1113 +
1.1114 + while ($_row = $db->sql_fetchrow($result))
1.1115 + {
1.1116 + if (!$_row['allowed_forums'])
1.1117 + {
1.1118 + continue;
1.1119 + }
1.1120 +
1.1121 + $allowed_forums = unserialize(trim($_row['allowed_forums']));
1.1122 + $allowed_forums = array_diff($allowed_forums, $forum_ids);
1.1123 +
1.1124 + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1.1125 + SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1.1126 + WHERE group_id = {$_row['group_id']}";
1.1127 + $db->sql_query($sql);
1.1128 + }
1.1129 + $db->sql_freeresult($result);
1.1130 +
1.1131 + $cache->destroy('_extensions');
1.1132 + }
1.1133 + }
1.1134 + else if ($action_subforums == 'move')
1.1135 + {
1.1136 + if (!$subforums_to_id)
1.1137 + {
1.1138 + return array($user->lang['NO_DESTINATION_FORUM']);
1.1139 + }
1.1140 +
1.1141 + $sql = 'SELECT forum_name
1.1142 + FROM ' . FORUMS_TABLE . '
1.1143 + WHERE forum_id = ' . $subforums_to_id;
1.1144 + $result = $db->sql_query($sql);
1.1145 + $_row = $db->sql_fetchrow($result);
1.1146 + $db->sql_freeresult($result);
1.1147 +
1.1148 + if (!$_row)
1.1149 + {
1.1150 + return array($user->lang['NO_FORUM']);
1.1151 + }
1.1152 +
1.1153 + $subforums_to_name = $_row['forum_name'];
1.1154 +
1.1155 + $sql = 'SELECT forum_id
1.1156 + FROM ' . FORUMS_TABLE . "
1.1157 + WHERE parent_id = {$row['forum_id']}";
1.1158 + $result = $db->sql_query($sql);
1.1159 +
1.1160 + while ($_row = $db->sql_fetchrow($result))
1.1161 + {
1.1162 + $this->move_forum($_row['forum_id'], $subforums_to_id);
1.1163 + }
1.1164 + $db->sql_freeresult($result);
1.1165 +
1.1166 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1167 + SET parent_id = $subforums_to_id
1.1168 + WHERE parent_id = {$row['forum_id']}";
1.1169 + $db->sql_query($sql);
1.1170 + }
1.1171 +
1.1172 + // Adjust the left/right id
1.1173 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.1174 + SET right_id = left_id + 1
1.1175 + WHERE forum_id = ' . $row['forum_id'];
1.1176 + $db->sql_query($sql);
1.1177 + }
1.1178 + }
1.1179 + else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
1.1180 + {
1.1181 + // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
1.1182 + $forum_data_sql['forum_posts'] = 0;
1.1183 + $forum_data_sql['forum_topics'] = 0;
1.1184 + $forum_data_sql['forum_topics_real'] = 0;
1.1185 + $forum_data_sql['forum_last_post_id'] = 0;
1.1186 + $forum_data_sql['forum_last_post_subject'] = '';
1.1187 + $forum_data_sql['forum_last_post_time'] = 0;
1.1188 + $forum_data_sql['forum_last_poster_id'] = 0;
1.1189 + $forum_data_sql['forum_last_poster_name'] = '';
1.1190 + $forum_data_sql['forum_last_poster_colour'] = '';
1.1191 + }
1.1192 +
1.1193 + if (sizeof($errors))
1.1194 + {
1.1195 + return $errors;
1.1196 + }
1.1197 +
1.1198 + if ($row['parent_id'] != $forum_data_sql['parent_id'])
1.1199 + {
1.1200 + if ($row['forum_id'] != $forum_data_sql['parent_id'])
1.1201 + {
1.1202 + $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
1.1203 + }
1.1204 + else
1.1205 + {
1.1206 + $forum_data_sql['parent_id'] = $row['parent_id'];
1.1207 + }
1.1208 + }
1.1209 +
1.1210 + if (sizeof($errors))
1.1211 + {
1.1212 + return $errors;
1.1213 + }
1.1214 +
1.1215 + unset($forum_data_sql['type_action']);
1.1216 +
1.1217 + if ($row['forum_name'] != $forum_data_sql['forum_name'])
1.1218 + {
1.1219 + // the forum name has changed, clear the parents list of all forums (for safety)
1.1220 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1221 + SET forum_parents = ''";
1.1222 + $db->sql_query($sql);
1.1223 + }
1.1224 +
1.1225 + // Setting the forum id to the forum id is not really received well by some dbs. ;)
1.1226 + $forum_id = $forum_data_sql['forum_id'];
1.1227 + unset($forum_data_sql['forum_id']);
1.1228 +
1.1229 + $sql = 'UPDATE ' . FORUMS_TABLE . '
1.1230 + SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
1.1231 + WHERE forum_id = ' . $forum_id;
1.1232 + $db->sql_query($sql);
1.1233 +
1.1234 + // Add it back
1.1235 + $forum_data['forum_id'] = $forum_id;
1.1236 +
1.1237 + add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
1.1238 + }
1.1239 +
1.1240 + return $errors;
1.1241 + }
1.1242 +
1.1243 + /**
1.1244 + * Move forum
1.1245 + */
1.1246 + function move_forum($from_id, $to_id)
1.1247 + {
1.1248 + global $db, $user;
1.1249 +
1.1250 + $to_data = $moved_ids = $errors = array();
1.1251 +
1.1252 + // Check if we want to move to a parent with link type
1.1253 + if ($to_id > 0)
1.1254 + {
1.1255 + $to_data = $this->get_forum_info($to_id);
1.1256 +
1.1257 + if ($to_data['forum_type'] == FORUM_LINK)
1.1258 + {
1.1259 + $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1.1260 + return $errors;
1.1261 + }
1.1262 + }
1.1263 +
1.1264 + $moved_forums = get_forum_branch($from_id, 'children', 'descending');
1.1265 + $from_data = $moved_forums[0];
1.1266 + $diff = sizeof($moved_forums) * 2;
1.1267 +
1.1268 + $moved_ids = array();
1.1269 + for ($i = 0; $i < sizeof($moved_forums); ++$i)
1.1270 + {
1.1271 + $moved_ids[] = $moved_forums[$i]['forum_id'];
1.1272 + }
1.1273 +
1.1274 + // Resync parents
1.1275 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1276 + SET right_id = right_id - $diff, forum_parents = ''
1.1277 + WHERE left_id < " . $from_data['right_id'] . "
1.1278 + AND right_id > " . $from_data['right_id'];
1.1279 + $db->sql_query($sql);
1.1280 +
1.1281 + // Resync righthand side of tree
1.1282 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1283 + SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
1.1284 + WHERE left_id > " . $from_data['right_id'];
1.1285 + $db->sql_query($sql);
1.1286 +
1.1287 + if ($to_id > 0)
1.1288 + {
1.1289 + // Retrieve $to_data again, it may have been changed...
1.1290 + $to_data = $this->get_forum_info($to_id);
1.1291 +
1.1292 + // Resync new parents
1.1293 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1294 + SET right_id = right_id + $diff, forum_parents = ''
1.1295 + WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
1.1296 + AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1.1297 + $db->sql_query($sql);
1.1298 +
1.1299 + // Resync the righthand side of the tree
1.1300 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1301 + SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
1.1302 + WHERE left_id > " . $to_data['right_id'] . '
1.1303 + AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1.1304 + $db->sql_query($sql);
1.1305 +
1.1306 + // Resync moved branch
1.1307 + $to_data['right_id'] += $diff;
1.1308 +
1.1309 + if ($to_data['right_id'] > $from_data['right_id'])
1.1310 + {
1.1311 + $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
1.1312 + }
1.1313 + else
1.1314 + {
1.1315 + $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
1.1316 + }
1.1317 + }
1.1318 + else
1.1319 + {
1.1320 + $sql = 'SELECT MAX(right_id) AS right_id
1.1321 + FROM ' . FORUMS_TABLE . '
1.1322 + WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
1.1323 + $result = $db->sql_query($sql);
1.1324 + $row = $db->sql_fetchrow($result);
1.1325 + $db->sql_freeresult($result);
1.1326 +
1.1327 + $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
1.1328 + }
1.1329 +
1.1330 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1331 + SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
1.1332 + WHERE " . $db->sql_in_set('forum_id', $moved_ids);
1.1333 + $db->sql_query($sql);
1.1334 +
1.1335 + return $errors;
1.1336 + }
1.1337 +
1.1338 + /**
1.1339 + * Move forum content from one to another forum
1.1340 + */
1.1341 + function move_forum_content($from_id, $to_id, $sync = true)
1.1342 + {
1.1343 + global $db;
1.1344 +
1.1345 + $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
1.1346 +
1.1347 + foreach ($table_ary as $table)
1.1348 + {
1.1349 + $sql = "UPDATE $table
1.1350 + SET forum_id = $to_id
1.1351 + WHERE forum_id = $from_id";
1.1352 + $db->sql_query($sql);
1.1353 + }
1.1354 + unset($table_ary);
1.1355 +
1.1356 + $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
1.1357 +
1.1358 + foreach ($table_ary as $table)
1.1359 + {
1.1360 + $sql = "DELETE FROM $table
1.1361 + WHERE forum_id = $from_id";
1.1362 + $db->sql_query($sql);
1.1363 + }
1.1364 +
1.1365 + if ($sync)
1.1366 + {
1.1367 + // Delete ghost topics that link back to the same forum then resync counters
1.1368 + sync('topic_moved');
1.1369 + sync('forum', 'forum_id', $to_id, false, true);
1.1370 + }
1.1371 +
1.1372 + return array();
1.1373 + }
1.1374 +
1.1375 + /**
1.1376 + * Remove complete forum
1.1377 + */
1.1378 + function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
1.1379 + {
1.1380 + global $db, $user, $cache;
1.1381 +
1.1382 + $forum_data = $this->get_forum_info($forum_id);
1.1383 +
1.1384 + $errors = array();
1.1385 + $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
1.1386 + $forum_ids = array($forum_id);
1.1387 +
1.1388 + if ($action_posts == 'delete')
1.1389 + {
1.1390 + $log_action_posts = 'POSTS';
1.1391 + $errors = array_merge($errors, $this->delete_forum_content($forum_id));
1.1392 + }
1.1393 + else if ($action_posts == 'move')
1.1394 + {
1.1395 + if (!$posts_to_id)
1.1396 + {
1.1397 + $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1.1398 + }
1.1399 + else
1.1400 + {
1.1401 + $log_action_posts = 'MOVE_POSTS';
1.1402 +
1.1403 + $sql = 'SELECT forum_name
1.1404 + FROM ' . FORUMS_TABLE . '
1.1405 + WHERE forum_id = ' . $posts_to_id;
1.1406 + $result = $db->sql_query($sql);
1.1407 + $row = $db->sql_fetchrow($result);
1.1408 + $db->sql_freeresult($result);
1.1409 +
1.1410 + if (!$row)
1.1411 + {
1.1412 + $errors[] = $user->lang['NO_FORUM'];
1.1413 + }
1.1414 + else
1.1415 + {
1.1416 + $posts_to_name = $row['forum_name'];
1.1417 + $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
1.1418 + }
1.1419 + }
1.1420 + }
1.1421 +
1.1422 + if (sizeof($errors))
1.1423 + {
1.1424 + return $errors;
1.1425 + }
1.1426 +
1.1427 + if ($action_subforums == 'delete')
1.1428 + {
1.1429 + $log_action_forums = 'FORUMS';
1.1430 + $rows = get_forum_branch($forum_id, 'children', 'descending', false);
1.1431 +
1.1432 + foreach ($rows as $row)
1.1433 + {
1.1434 + $forum_ids[] = $row['forum_id'];
1.1435 + $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
1.1436 + }
1.1437 +
1.1438 + if (sizeof($errors))
1.1439 + {
1.1440 + return $errors;
1.1441 + }
1.1442 +
1.1443 + $diff = sizeof($forum_ids) * 2;
1.1444 +
1.1445 + $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1.1446 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1447 + $db->sql_query($sql);
1.1448 +
1.1449 + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1.1450 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1451 + $db->sql_query($sql);
1.1452 +
1.1453 + $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1.1454 + WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1.1455 + $db->sql_query($sql);
1.1456 + }
1.1457 + else if ($action_subforums == 'move')
1.1458 + {
1.1459 + if (!$subforums_to_id)
1.1460 + {
1.1461 + $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1.1462 + }
1.1463 + else
1.1464 + {
1.1465 + $log_action_forums = 'MOVE_FORUMS';
1.1466 +
1.1467 + $sql = 'SELECT forum_name
1.1468 + FROM ' . FORUMS_TABLE . '
1.1469 + WHERE forum_id = ' . $subforums_to_id;
1.1470 + $result = $db->sql_query($sql);
1.1471 + $row = $db->sql_fetchrow($result);
1.1472 + $db->sql_freeresult($result);
1.1473 +
1.1474 + if (!$row)
1.1475 + {
1.1476 + $errors[] = $user->lang['NO_FORUM'];
1.1477 + }
1.1478 + else
1.1479 + {
1.1480 + $subforums_to_name = $row['forum_name'];
1.1481 +
1.1482 + $sql = 'SELECT forum_id
1.1483 + FROM ' . FORUMS_TABLE . "
1.1484 + WHERE parent_id = $forum_id";
1.1485 + $result = $db->sql_query($sql);
1.1486 +
1.1487 + while ($row = $db->sql_fetchrow($result))
1.1488 + {
1.1489 + $this->move_forum($row['forum_id'], $subforums_to_id);
1.1490 + }
1.1491 + $db->sql_freeresult($result);
1.1492 +
1.1493 + // Grab new forum data for correct tree updating later
1.1494 + $forum_data = $this->get_forum_info($forum_id);
1.1495 +
1.1496 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1497 + SET parent_id = $subforums_to_id
1.1498 + WHERE parent_id = $forum_id";
1.1499 + $db->sql_query($sql);
1.1500 +
1.1501 + $diff = 2;
1.1502 + $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1.1503 + WHERE forum_id = $forum_id";
1.1504 + $db->sql_query($sql);
1.1505 +
1.1506 + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1.1507 + WHERE forum_id = $forum_id";
1.1508 + $db->sql_query($sql);
1.1509 +
1.1510 + $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1.1511 + WHERE forum_id = $forum_id";
1.1512 + $db->sql_query($sql);
1.1513 + }
1.1514 + }
1.1515 +
1.1516 + if (sizeof($errors))
1.1517 + {
1.1518 + return $errors;
1.1519 + }
1.1520 + }
1.1521 + else
1.1522 + {
1.1523 + $diff = 2;
1.1524 + $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1.1525 + WHERE forum_id = $forum_id";
1.1526 + $db->sql_query($sql);
1.1527 +
1.1528 + $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1.1529 + WHERE forum_id = $forum_id";
1.1530 + $db->sql_query($sql);
1.1531 +
1.1532 + $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1.1533 + WHERE forum_id = $forum_id";
1.1534 + $db->sql_query($sql);
1.1535 + }
1.1536 +
1.1537 + // Resync tree
1.1538 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1539 + SET right_id = right_id - $diff
1.1540 + WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
1.1541 + $db->sql_query($sql);
1.1542 +
1.1543 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1544 + SET left_id = left_id - $diff, right_id = right_id - $diff
1.1545 + WHERE left_id > {$forum_data['right_id']}";
1.1546 + $db->sql_query($sql);
1.1547 +
1.1548 + // Delete forum ids from extension groups table
1.1549 + $sql = 'SELECT group_id, allowed_forums
1.1550 + FROM ' . EXTENSION_GROUPS_TABLE;
1.1551 + $result = $db->sql_query($sql);
1.1552 +
1.1553 + while ($row = $db->sql_fetchrow($result))
1.1554 + {
1.1555 + if (!$row['allowed_forums'])
1.1556 + {
1.1557 + continue;
1.1558 + }
1.1559 +
1.1560 + $allowed_forums = unserialize(trim($row['allowed_forums']));
1.1561 + $allowed_forums = array_diff($allowed_forums, $forum_ids);
1.1562 +
1.1563 + $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1.1564 + SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1.1565 + WHERE group_id = {$row['group_id']}";
1.1566 + $db->sql_query($sql);
1.1567 + }
1.1568 + $db->sql_freeresult($result);
1.1569 +
1.1570 + $cache->destroy('_extensions');
1.1571 +
1.1572 + $log_action = implode('_', array($log_action_posts, $log_action_forums));
1.1573 +
1.1574 + switch ($log_action)
1.1575 + {
1.1576 + case 'MOVE_POSTS_MOVE_FORUMS':
1.1577 + add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
1.1578 + break;
1.1579 +
1.1580 + case 'MOVE_POSTS_FORUMS':
1.1581 + add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
1.1582 + break;
1.1583 +
1.1584 + case 'POSTS_MOVE_FORUMS':
1.1585 + add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1.1586 + break;
1.1587 +
1.1588 + case '_MOVE_FORUMS':
1.1589 + add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1.1590 + break;
1.1591 +
1.1592 + case 'MOVE_POSTS_':
1.1593 + add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
1.1594 + break;
1.1595 +
1.1596 + case 'POSTS_FORUMS':
1.1597 + add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
1.1598 + break;
1.1599 +
1.1600 + case '_FORUMS':
1.1601 + add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
1.1602 + break;
1.1603 +
1.1604 + case 'POSTS_':
1.1605 + add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
1.1606 + break;
1.1607 +
1.1608 + default:
1.1609 + add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
1.1610 + break;
1.1611 + }
1.1612 +
1.1613 + return $errors;
1.1614 + }
1.1615 +
1.1616 + /**
1.1617 + * Delete forum content
1.1618 + */
1.1619 + function delete_forum_content($forum_id)
1.1620 + {
1.1621 + global $db, $config, $phpbb_root_path, $phpEx;
1.1622 +
1.1623 + include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1.1624 +
1.1625 + $db->sql_transaction('begin');
1.1626 +
1.1627 + // Select then delete all attachments
1.1628 + $sql = 'SELECT a.topic_id
1.1629 + FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
1.1630 + WHERE p.forum_id = $forum_id
1.1631 + AND a.in_message = 0
1.1632 + AND a.topic_id = p.topic_id";
1.1633 + $result = $db->sql_query($sql);
1.1634 +
1.1635 + $topic_ids = array();
1.1636 + while ($row = $db->sql_fetchrow($result))
1.1637 + {
1.1638 + $topic_ids[] = $row['topic_id'];
1.1639 + }
1.1640 + $db->sql_freeresult($result);
1.1641 +
1.1642 + delete_attachments('topic', $topic_ids, false);
1.1643 +
1.1644 + // Delete shadow topics pointing to topics in this forum
1.1645 + delete_topic_shadows($forum_id);
1.1646 +
1.1647 + // Before we remove anything we make sure we are able to adjust the post counts later. ;)
1.1648 + $sql = 'SELECT poster_id
1.1649 + FROM ' . POSTS_TABLE . '
1.1650 + WHERE forum_id = ' . $forum_id . '
1.1651 + AND post_postcount = 1
1.1652 + AND post_approved = 1';
1.1653 + $result = $db->sql_query($sql);
1.1654 +
1.1655 + $post_counts = array();
1.1656 + while ($row = $db->sql_fetchrow($result))
1.1657 + {
1.1658 + $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
1.1659 + }
1.1660 + $db->sql_freeresult($result);
1.1661 +
1.1662 + switch ($db->sql_layer)
1.1663 + {
1.1664 + case 'mysql4':
1.1665 + case 'mysqli':
1.1666 +
1.1667 + // Delete everything else and thank MySQL for offering multi-table deletion
1.1668 + $tables_ary = array(
1.1669 + SEARCH_WORDMATCH_TABLE => 'post_id',
1.1670 + REPORTS_TABLE => 'post_id',
1.1671 + WARNINGS_TABLE => 'post_id',
1.1672 + BOOKMARKS_TABLE => 'topic_id',
1.1673 + TOPICS_WATCH_TABLE => 'topic_id',
1.1674 + TOPICS_POSTED_TABLE => 'topic_id',
1.1675 + POLL_OPTIONS_TABLE => 'topic_id',
1.1676 + POLL_VOTES_TABLE => 'topic_id',
1.1677 + );
1.1678 +
1.1679 + $sql = 'DELETE ' . POSTS_TABLE;
1.1680 + $sql_using = "\nFROM " . POSTS_TABLE;
1.1681 + $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
1.1682 +
1.1683 + foreach ($tables_ary as $table => $field)
1.1684 + {
1.1685 + $sql .= ", $table ";
1.1686 + $sql_using .= ", $table ";
1.1687 + $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
1.1688 + }
1.1689 +
1.1690 + $db->sql_query($sql . $sql_using . $sql_where);
1.1691 +
1.1692 + break;
1.1693 +
1.1694 + default:
1.1695 +
1.1696 + // Delete everything else and curse your DB for not offering multi-table deletion
1.1697 + $tables_ary = array(
1.1698 + 'post_id' => array(
1.1699 + SEARCH_WORDMATCH_TABLE,
1.1700 + REPORTS_TABLE,
1.1701 + WARNINGS_TABLE,
1.1702 + ),
1.1703 +
1.1704 + 'topic_id' => array(
1.1705 + BOOKMARKS_TABLE,
1.1706 + TOPICS_WATCH_TABLE,
1.1707 + TOPICS_POSTED_TABLE,
1.1708 + POLL_OPTIONS_TABLE,
1.1709 + POLL_VOTES_TABLE,
1.1710 + )
1.1711 + );
1.1712 +
1.1713 + // Amount of rows we select and delete in one iteration.
1.1714 + $batch_size = 500;
1.1715 +
1.1716 + foreach ($tables_ary as $field => $tables)
1.1717 + {
1.1718 + $start = 0;
1.1719 +
1.1720 + do
1.1721 + {
1.1722 + $sql = "SELECT $field
1.1723 + FROM " . POSTS_TABLE . '
1.1724 + WHERE forum_id = ' . $forum_id;
1.1725 + $result = $db->sql_query_limit($sql, $batch_size, $start);
1.1726 +
1.1727 + $ids = array();
1.1728 + while ($row = $db->sql_fetchrow($result))
1.1729 + {
1.1730 + $ids[] = $row[$field];
1.1731 + }
1.1732 + $db->sql_freeresult($result);
1.1733 +
1.1734 + if (sizeof($ids))
1.1735 + {
1.1736 + $start += sizeof($ids);
1.1737 +
1.1738 + foreach ($tables as $table)
1.1739 + {
1.1740 + $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
1.1741 + }
1.1742 + }
1.1743 + }
1.1744 + while (sizeof($ids) == $batch_size);
1.1745 + }
1.1746 + unset($ids);
1.1747 +
1.1748 + break;
1.1749 + }
1.1750 +
1.1751 + $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
1.1752 +
1.1753 + foreach ($table_ary as $table)
1.1754 + {
1.1755 + $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
1.1756 + }
1.1757 +
1.1758 + // Set forum ids to 0
1.1759 + $table_ary = array(DRAFTS_TABLE);
1.1760 +
1.1761 + foreach ($table_ary as $table)
1.1762 + {
1.1763 + $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
1.1764 + }
1.1765 +
1.1766 + // Adjust users post counts
1.1767 + if (sizeof($post_counts))
1.1768 + {
1.1769 + foreach ($post_counts as $poster_id => $substract)
1.1770 + {
1.1771 + $sql = 'UPDATE ' . USERS_TABLE . '
1.1772 + SET user_posts = 0
1.1773 + WHERE user_id = ' . $poster_id . '
1.1774 + AND user_posts < ' . $substract;
1.1775 + $db->sql_query($sql);
1.1776 +
1.1777 + $sql = 'UPDATE ' . USERS_TABLE . '
1.1778 + SET user_posts = user_posts - ' . $substract . '
1.1779 + WHERE user_id = ' . $poster_id . '
1.1780 + AND user_posts >= ' . $substract;
1.1781 + $db->sql_query($sql);
1.1782 + }
1.1783 + }
1.1784 +
1.1785 + $db->sql_transaction('commit');
1.1786 +
1.1787 + // Make sure the overall post/topic count is correct...
1.1788 + $sql = 'SELECT COUNT(post_id) AS stat
1.1789 + FROM ' . POSTS_TABLE . '
1.1790 + WHERE post_approved = 1';
1.1791 + $result = $db->sql_query($sql);
1.1792 + $row = $db->sql_fetchrow($result);
1.1793 + $db->sql_freeresult($result);
1.1794 +
1.1795 + set_config('num_posts', (int) $row['stat'], true);
1.1796 +
1.1797 + $sql = 'SELECT COUNT(topic_id) AS stat
1.1798 + FROM ' . TOPICS_TABLE . '
1.1799 + WHERE topic_approved = 1';
1.1800 + $result = $db->sql_query($sql);
1.1801 + $row = $db->sql_fetchrow($result);
1.1802 + $db->sql_freeresult($result);
1.1803 +
1.1804 + set_config('num_topics', (int) $row['stat'], true);
1.1805 +
1.1806 + $sql = 'SELECT COUNT(attach_id) as stat
1.1807 + FROM ' . ATTACHMENTS_TABLE;
1.1808 + $result = $db->sql_query($sql);
1.1809 + $row = $db->sql_fetchrow($result);
1.1810 + $db->sql_freeresult($result);
1.1811 +
1.1812 + set_config('num_files', (int) $row['stat'], true);
1.1813 +
1.1814 + $sql = 'SELECT SUM(filesize) as stat
1.1815 + FROM ' . ATTACHMENTS_TABLE;
1.1816 + $result = $db->sql_query($sql);
1.1817 + $row = $db->sql_fetchrow($result);
1.1818 + $db->sql_freeresult($result);
1.1819 +
1.1820 + set_config('upload_dir_size', (float) $row['stat'], true);
1.1821 +
1.1822 + return array();
1.1823 + }
1.1824 +
1.1825 + /**
1.1826 + * Move forum position by $steps up/down
1.1827 + */
1.1828 + function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
1.1829 + {
1.1830 + global $db;
1.1831 +
1.1832 + /**
1.1833 + * Fetch all the siblings between the module's current spot
1.1834 + * and where we want to move it to. If there are less than $steps
1.1835 + * siblings between the current spot and the target then the
1.1836 + * module will move as far as possible
1.1837 + */
1.1838 + $sql = 'SELECT forum_id, forum_name, left_id, right_id
1.1839 + FROM ' . FORUMS_TABLE . "
1.1840 + WHERE parent_id = {$forum_row['parent_id']}
1.1841 + 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");
1.1842 + $result = $db->sql_query_limit($sql, $steps);
1.1843 +
1.1844 + $target = array();
1.1845 + while ($row = $db->sql_fetchrow($result))
1.1846 + {
1.1847 + $target = $row;
1.1848 + }
1.1849 + $db->sql_freeresult($result);
1.1850 +
1.1851 + if (!sizeof($target))
1.1852 + {
1.1853 + // The forum is already on top or bottom
1.1854 + return false;
1.1855 + }
1.1856 +
1.1857 + /**
1.1858 + * $left_id and $right_id define the scope of the nodes that are affected by the move.
1.1859 + * $diff_up and $diff_down are the values to substract or add to each node's left_id
1.1860 + * and right_id in order to move them up or down.
1.1861 + * $move_up_left and $move_up_right define the scope of the nodes that are moving
1.1862 + * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
1.1863 + */
1.1864 + if ($action == 'move_up')
1.1865 + {
1.1866 + $left_id = $target['left_id'];
1.1867 + $right_id = $forum_row['right_id'];
1.1868 +
1.1869 + $diff_up = $forum_row['left_id'] - $target['left_id'];
1.1870 + $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1.1871 +
1.1872 + $move_up_left = $forum_row['left_id'];
1.1873 + $move_up_right = $forum_row['right_id'];
1.1874 + }
1.1875 + else
1.1876 + {
1.1877 + $left_id = $forum_row['left_id'];
1.1878 + $right_id = $target['right_id'];
1.1879 +
1.1880 + $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1.1881 + $diff_down = $target['right_id'] - $forum_row['right_id'];
1.1882 +
1.1883 + $move_up_left = $forum_row['right_id'] + 1;
1.1884 + $move_up_right = $target['right_id'];
1.1885 + }
1.1886 +
1.1887 + // Now do the dirty job
1.1888 + $sql = 'UPDATE ' . FORUMS_TABLE . "
1.1889 + SET left_id = left_id + CASE
1.1890 + WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1.1891 + ELSE {$diff_down}
1.1892 + END,
1.1893 + right_id = right_id + CASE
1.1894 + WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1.1895 + ELSE {$diff_down}
1.1896 + END,
1.1897 + forum_parents = ''
1.1898 + WHERE
1.1899 + left_id BETWEEN {$left_id} AND {$right_id}
1.1900 + AND right_id BETWEEN {$left_id} AND {$right_id}";
1.1901 + $db->sql_query($sql);
1.1902 +
1.1903 + return $target['forum_name'];
1.1904 + }
1.1905 +
1.1906 + /**
1.1907 + * Display progress bar for syncinc forums
1.1908 + */
1.1909 + function display_progress_bar($start, $total)
1.1910 + {
1.1911 + global $template, $user;
1.1912 +
1.1913 + adm_page_header($user->lang['SYNC_IN_PROGRESS']);
1.1914 +
1.1915 + $template->set_filenames(array(
1.1916 + 'body' => 'progress_bar.html')
1.1917 + );
1.1918 +
1.1919 + $template->assign_vars(array(
1.1920 + 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
1.1921 + 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
1.1922 + );
1.1923 +
1.1924 + adm_page_footer();
1.1925 + }
1.1926 +
1.1927 + /**
1.1928 + * Display copy permission page
1.1929 + * Not used at the moment - we will have a look at it for 3.0.7
1.1930 + */
1.1931 + function copy_permission_page($forum_data)
1.1932 + {
1.1933 + global $phpEx, $phpbb_admin_path, $template, $user;
1.1934 +
1.1935 + $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
1.1936 + $action = append_sid($this->u_action . "&parent_id={$this->parent_id}&f={$forum_data['forum_id']}&action=copy_perm");
1.1937 +
1.1938 + $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
1.1939 +
1.1940 + $this->tpl_name = 'acp_forums_copy_perm';
1.1941 +
1.1942 + $template->assign_vars(array(
1.1943 + 'U_ACL' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
1.1944 + 'L_ACL_LINK' => $l_acl,
1.1945 + 'L_BACK_LINK' => adm_back_link($this->u_action . '&parent_id=' . $this->parent_id),
1.1946 + 'S_COPY_ACTION' => $action,
1.1947 + 'S_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
1.1948 + ));
1.1949 + }
1.1950 +
1.1951 +}
1.1952 +
1.1953 +?>
1.1954 \ No newline at end of file