| 1 | <?php
|
|---|
| 2 | /**
|
|---|
| 3 | *
|
|---|
| 4 | * @package acp
|
|---|
| 5 | * @version $Id$
|
|---|
| 6 | * @copyright (c) 2005 phpBB Group
|
|---|
| 7 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License
|
|---|
| 8 | *
|
|---|
| 9 | */
|
|---|
| 10 |
|
|---|
| 11 | /**
|
|---|
| 12 | * @ignore
|
|---|
| 13 | */
|
|---|
| 14 | if (!defined('IN_PHPBB'))
|
|---|
| 15 | {
|
|---|
| 16 | exit;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | /**
|
|---|
| 20 | * @package acp
|
|---|
| 21 | */
|
|---|
| 22 | class acp_forums
|
|---|
| 23 | {
|
|---|
| 24 | var $u_action;
|
|---|
| 25 | var $parent_id = 0;
|
|---|
| 26 |
|
|---|
| 27 | function main($id, $mode)
|
|---|
| 28 | {
|
|---|
| 29 | global $db, $user, $auth, $template, $cache;
|
|---|
| 30 | global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
|
|---|
| 31 |
|
|---|
| 32 | $user->add_lang('acp/forums');
|
|---|
| 33 | $this->tpl_name = 'acp_forums';
|
|---|
| 34 | $this->page_title = 'ACP_MANAGE_FORUMS';
|
|---|
| 35 |
|
|---|
| 36 | $form_key = 'acp_forums';
|
|---|
| 37 | add_form_key($form_key);
|
|---|
| 38 |
|
|---|
| 39 | $action = request_var('action', '');
|
|---|
| 40 | $update = (isset($_POST['update'])) ? true : false;
|
|---|
| 41 | $forum_id = request_var('f', 0);
|
|---|
| 42 |
|
|---|
| 43 | $this->parent_id = request_var('parent_id', 0);
|
|---|
| 44 | $forum_data = $errors = array();
|
|---|
| 45 | if ($update && !check_form_key($form_key))
|
|---|
| 46 | {
|
|---|
| 47 | $update = false;
|
|---|
| 48 | $errors[] = $user->lang['FORM_INVALID'];
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | // Check additional permissions
|
|---|
| 52 | switch ($action)
|
|---|
| 53 | {
|
|---|
| 54 | case 'progress_bar':
|
|---|
| 55 | $start = request_var('start', 0);
|
|---|
| 56 | $total = request_var('total', 0);
|
|---|
| 57 |
|
|---|
| 58 | $this->display_progress_bar($start, $total);
|
|---|
| 59 | exit;
|
|---|
| 60 | break;
|
|---|
| 61 |
|
|---|
| 62 | case 'delete':
|
|---|
| 63 |
|
|---|
| 64 | if (!$auth->acl_get('a_forumdel'))
|
|---|
| 65 | {
|
|---|
| 66 | trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 67 | }
|
|---|
| 68 |
|
|---|
| 69 | break;
|
|---|
| 70 |
|
|---|
| 71 | case 'add':
|
|---|
| 72 |
|
|---|
| 73 | if (!$auth->acl_get('a_forumadd'))
|
|---|
| 74 | {
|
|---|
| 75 | trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | break;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | // Major routines
|
|---|
| 82 | if ($update)
|
|---|
| 83 | {
|
|---|
| 84 | switch ($action)
|
|---|
| 85 | {
|
|---|
| 86 | case 'delete':
|
|---|
| 87 | $action_subforums = request_var('action_subforums', '');
|
|---|
| 88 | $subforums_to_id = request_var('subforums_to_id', 0);
|
|---|
| 89 | $action_posts = request_var('action_posts', '');
|
|---|
| 90 | $posts_to_id = request_var('posts_to_id', 0);
|
|---|
| 91 |
|
|---|
| 92 | $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
|
|---|
| 93 |
|
|---|
| 94 | if (sizeof($errors))
|
|---|
| 95 | {
|
|---|
| 96 | break;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | $auth->acl_clear_prefetch();
|
|---|
| 100 | $cache->destroy('sql', FORUMS_TABLE);
|
|---|
| 101 |
|
|---|
| 102 | trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
|
|---|
| 103 |
|
|---|
| 104 | break;
|
|---|
| 105 |
|
|---|
| 106 | case 'edit':
|
|---|
| 107 | $forum_data = array(
|
|---|
| 108 | 'forum_id' => $forum_id
|
|---|
| 109 | );
|
|---|
| 110 |
|
|---|
| 111 | // No break here
|
|---|
| 112 |
|
|---|
| 113 | case 'add':
|
|---|
| 114 |
|
|---|
| 115 | $forum_data += array(
|
|---|
| 116 | 'parent_id' => request_var('forum_parent_id', $this->parent_id),
|
|---|
| 117 | 'forum_type' => request_var('forum_type', FORUM_POST),
|
|---|
| 118 | 'type_action' => request_var('type_action', ''),
|
|---|
| 119 | 'forum_status' => request_var('forum_status', ITEM_UNLOCKED),
|
|---|
| 120 | 'forum_parents' => '',
|
|---|
| 121 | 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
|
|---|
| 122 | 'forum_link' => request_var('forum_link', ''),
|
|---|
| 123 | 'forum_link_track' => request_var('forum_link_track', false),
|
|---|
| 124 | 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)),
|
|---|
| 125 | 'forum_desc_uid' => '',
|
|---|
| 126 | 'forum_desc_options' => 7,
|
|---|
| 127 | 'forum_desc_bitfield' => '',
|
|---|
| 128 | 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)),
|
|---|
| 129 | 'forum_rules_uid' => '',
|
|---|
| 130 | 'forum_rules_options' => 7,
|
|---|
| 131 | 'forum_rules_bitfield' => '',
|
|---|
| 132 | 'forum_rules_link' => request_var('forum_rules_link', ''),
|
|---|
| 133 | 'forum_image' => request_var('forum_image', ''),
|
|---|
| 134 | 'forum_style' => request_var('forum_style', 0),
|
|---|
| 135 | 'display_subforum_list' => request_var('display_subforum_list', false),
|
|---|
| 136 | 'display_on_index' => request_var('display_on_index', false),
|
|---|
| 137 | 'forum_topics_per_page' => request_var('topics_per_page', 0),
|
|---|
| 138 | 'enable_indexing' => request_var('enable_indexing', true),
|
|---|
| 139 | 'enable_icons' => request_var('enable_icons', false),
|
|---|
| 140 | 'enable_prune' => request_var('enable_prune', false),
|
|---|
| 141 | 'enable_post_review' => request_var('enable_post_review', true),
|
|---|
| 142 | 'enable_quick_reply' => request_var('enable_quick_reply', false),
|
|---|
| 143 | 'prune_days' => request_var('prune_days', 7),
|
|---|
| 144 | 'prune_viewed' => request_var('prune_viewed', 7),
|
|---|
| 145 | 'prune_freq' => request_var('prune_freq', 1),
|
|---|
| 146 | 'prune_old_polls' => request_var('prune_old_polls', false),
|
|---|
| 147 | 'prune_announce' => request_var('prune_announce', false),
|
|---|
| 148 | 'prune_sticky' => request_var('prune_sticky', false),
|
|---|
| 149 | 'forum_password' => request_var('forum_password', '', true),
|
|---|
| 150 | 'forum_password_confirm'=> request_var('forum_password_confirm', '', true),
|
|---|
| 151 | 'forum_password_unset' => request_var('forum_password_unset', false),
|
|---|
| 152 | );
|
|---|
| 153 |
|
|---|
| 154 | // On add, add empty forum_options... else do not consider it (not updating it)
|
|---|
| 155 | if ($action == 'add')
|
|---|
| 156 | {
|
|---|
| 157 | $forum_data['forum_options'] = 0;
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 | // Use link_display_on_index setting if forum type is link
|
|---|
| 161 | if ($forum_data['forum_type'] == FORUM_LINK)
|
|---|
| 162 | {
|
|---|
| 163 | $forum_data['display_on_index'] = request_var('link_display_on_index', false);
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | // Linked forums and categories are not able to be locked...
|
|---|
| 167 | if ($forum_data['forum_type'] == FORUM_LINK || $forum_data['forum_type'] == FORUM_CAT)
|
|---|
| 168 | {
|
|---|
| 169 | $forum_data['forum_status'] = ITEM_UNLOCKED;
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', true);
|
|---|
| 173 |
|
|---|
| 174 | // Get data for forum rules if specified...
|
|---|
| 175 | if ($forum_data['forum_rules'])
|
|---|
| 176 | {
|
|---|
| 177 | 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));
|
|---|
| 178 | }
|
|---|
| 179 |
|
|---|
| 180 | // Get data for forum description if specified
|
|---|
| 181 | if ($forum_data['forum_desc'])
|
|---|
| 182 | {
|
|---|
| 183 | 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));
|
|---|
| 184 | }
|
|---|
| 185 |
|
|---|
| 186 | $errors = $this->update_forum_data($forum_data);
|
|---|
| 187 |
|
|---|
| 188 | if (!sizeof($errors))
|
|---|
| 189 | {
|
|---|
| 190 | $forum_perm_from = request_var('forum_perm_from', 0);
|
|---|
| 191 | $cache->destroy('sql', FORUMS_TABLE);
|
|---|
| 192 |
|
|---|
| 193 | // Copy permissions?
|
|---|
| 194 | if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
|
|---|
| 195 | ($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'))))
|
|---|
| 196 | {
|
|---|
| 197 | copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
|
|---|
| 198 | cache_moderators();
|
|---|
| 199 | }
|
|---|
| 200 | /* Commented out because of questionable UI workflow - re-visit for 3.0.7
|
|---|
| 201 | 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'))
|
|---|
| 202 | {
|
|---|
| 203 | $this->copy_permission_page($forum_data);
|
|---|
| 204 | return;
|
|---|
| 205 | }
|
|---|
| 206 | */
|
|---|
| 207 | $auth->acl_clear_prefetch();
|
|---|
| 208 |
|
|---|
| 209 | $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
|
|---|
| 210 |
|
|---|
| 211 | $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
|
|---|
| 212 |
|
|---|
| 213 | // Redirect to permissions
|
|---|
| 214 | if ($auth->acl_get('a_fauth'))
|
|---|
| 215 | {
|
|---|
| 216 | $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
|
|---|
| 217 | }
|
|---|
| 218 |
|
|---|
| 219 | // redirect directly to permission settings screen if authed
|
|---|
| 220 | if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth'))
|
|---|
| 221 | {
|
|---|
| 222 | meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
|
|---|
| 223 | }
|
|---|
| 224 |
|
|---|
| 225 | trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
|
|---|
| 226 | }
|
|---|
| 227 |
|
|---|
| 228 | break;
|
|---|
| 229 | }
|
|---|
| 230 | }
|
|---|
| 231 |
|
|---|
| 232 | switch ($action)
|
|---|
| 233 | {
|
|---|
| 234 | case 'move_up':
|
|---|
| 235 | case 'move_down':
|
|---|
| 236 |
|
|---|
| 237 | if (!$forum_id)
|
|---|
| 238 | {
|
|---|
| 239 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 240 | }
|
|---|
| 241 |
|
|---|
| 242 | $sql = 'SELECT *
|
|---|
| 243 | FROM ' . FORUMS_TABLE . "
|
|---|
| 244 | WHERE forum_id = $forum_id";
|
|---|
| 245 | $result = $db->sql_query($sql);
|
|---|
| 246 | $row = $db->sql_fetchrow($result);
|
|---|
| 247 | $db->sql_freeresult($result);
|
|---|
| 248 |
|
|---|
| 249 | if (!$row)
|
|---|
| 250 | {
|
|---|
| 251 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 252 | }
|
|---|
| 253 |
|
|---|
| 254 | $move_forum_name = $this->move_forum_by($row, $action, 1);
|
|---|
| 255 |
|
|---|
| 256 | if ($move_forum_name !== false)
|
|---|
| 257 | {
|
|---|
| 258 | add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
|
|---|
| 259 | $cache->destroy('sql', FORUMS_TABLE);
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | break;
|
|---|
| 263 |
|
|---|
| 264 | case 'sync':
|
|---|
| 265 | if (!$forum_id)
|
|---|
| 266 | {
|
|---|
| 267 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 268 | }
|
|---|
| 269 |
|
|---|
| 270 | @set_time_limit(0);
|
|---|
| 271 |
|
|---|
| 272 | $sql = 'SELECT forum_name, forum_topics_real
|
|---|
| 273 | FROM ' . FORUMS_TABLE . "
|
|---|
| 274 | WHERE forum_id = $forum_id";
|
|---|
| 275 | $result = $db->sql_query($sql);
|
|---|
| 276 | $row = $db->sql_fetchrow($result);
|
|---|
| 277 | $db->sql_freeresult($result);
|
|---|
| 278 |
|
|---|
| 279 | if (!$row)
|
|---|
| 280 | {
|
|---|
| 281 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 282 | }
|
|---|
| 283 |
|
|---|
| 284 | if ($row['forum_topics_real'])
|
|---|
| 285 | {
|
|---|
| 286 | $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
|
|---|
| 287 | FROM ' . TOPICS_TABLE . '
|
|---|
| 288 | WHERE forum_id = ' . $forum_id;
|
|---|
| 289 | $result = $db->sql_query($sql);
|
|---|
| 290 | $row2 = $db->sql_fetchrow($result);
|
|---|
| 291 | $db->sql_freeresult($result);
|
|---|
| 292 |
|
|---|
| 293 | // Typecast to int if there is no data available
|
|---|
| 294 | $row2['min_topic_id'] = (int) $row2['min_topic_id'];
|
|---|
| 295 | $row2['max_topic_id'] = (int) $row2['max_topic_id'];
|
|---|
| 296 |
|
|---|
| 297 | $start = request_var('start', $row2['min_topic_id']);
|
|---|
| 298 |
|
|---|
| 299 | $batch_size = 2000;
|
|---|
| 300 | $end = $start + $batch_size;
|
|---|
| 301 |
|
|---|
| 302 | // Sync all topics in batch mode...
|
|---|
| 303 | sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
|
|---|
| 304 | sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
|
|---|
| 305 |
|
|---|
| 306 | if ($end < $row2['max_topic_id'])
|
|---|
| 307 | {
|
|---|
| 308 | // We really need to find a way of showing statistics... no progress here
|
|---|
| 309 | $sql = 'SELECT COUNT(topic_id) as num_topics
|
|---|
| 310 | FROM ' . TOPICS_TABLE . '
|
|---|
| 311 | WHERE forum_id = ' . $forum_id . '
|
|---|
| 312 | AND topic_id BETWEEN ' . $start . ' AND ' . $end;
|
|---|
| 313 | $result = $db->sql_query($sql);
|
|---|
| 314 | $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
|
|---|
| 315 | $db->sql_freeresult($result);
|
|---|
| 316 |
|
|---|
| 317 | $start += $batch_size;
|
|---|
| 318 |
|
|---|
| 319 | $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']}";
|
|---|
| 320 |
|
|---|
| 321 | meta_refresh(0, $url);
|
|---|
| 322 |
|
|---|
| 323 | $template->assign_vars(array(
|
|---|
| 324 | 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}",
|
|---|
| 325 | 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"),
|
|---|
| 326 | 'S_CONTINUE_SYNC' => true,
|
|---|
| 327 | 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
|
|---|
| 328 | );
|
|---|
| 329 |
|
|---|
| 330 | return;
|
|---|
| 331 | }
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
|
|---|
| 335 | meta_refresh(0, $url);
|
|---|
| 336 |
|
|---|
| 337 | $template->assign_vars(array(
|
|---|
| 338 | 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
|
|---|
| 339 | 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
|
|---|
| 340 | 'S_CONTINUE_SYNC' => true,
|
|---|
| 341 | 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
|
|---|
| 342 | );
|
|---|
| 343 |
|
|---|
| 344 | return;
|
|---|
| 345 |
|
|---|
| 346 | break;
|
|---|
| 347 |
|
|---|
| 348 | case 'sync_forum':
|
|---|
| 349 |
|
|---|
| 350 | $sql = 'SELECT forum_name, forum_type
|
|---|
| 351 | FROM ' . FORUMS_TABLE . "
|
|---|
| 352 | WHERE forum_id = $forum_id";
|
|---|
| 353 | $result = $db->sql_query($sql);
|
|---|
| 354 | $row = $db->sql_fetchrow($result);
|
|---|
| 355 | $db->sql_freeresult($result);
|
|---|
| 356 |
|
|---|
| 357 | if (!$row)
|
|---|
| 358 | {
|
|---|
| 359 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 360 | }
|
|---|
| 361 |
|
|---|
| 362 | sync('forum', 'forum_id', $forum_id, false, true);
|
|---|
| 363 |
|
|---|
| 364 | add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
|
|---|
| 365 | $cache->destroy('sql', FORUMS_TABLE);
|
|---|
| 366 |
|
|---|
| 367 | $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
|
|---|
| 368 |
|
|---|
| 369 | break;
|
|---|
| 370 |
|
|---|
| 371 | case 'add':
|
|---|
| 372 | case 'edit':
|
|---|
| 373 |
|
|---|
| 374 | if ($update)
|
|---|
| 375 | {
|
|---|
| 376 | $forum_data['forum_flags'] = 0;
|
|---|
| 377 | $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
|
|---|
| 378 | $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
|
|---|
| 379 | $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
|
|---|
| 380 | $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
|
|---|
| 381 | $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
|
|---|
| 382 | $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
|
|---|
| 383 | $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | // Show form to create/modify a forum
|
|---|
| 387 | if ($action == 'edit')
|
|---|
| 388 | {
|
|---|
| 389 | $this->page_title = 'EDIT_FORUM';
|
|---|
| 390 | $row = $this->get_forum_info($forum_id);
|
|---|
| 391 | $old_forum_type = $row['forum_type'];
|
|---|
| 392 |
|
|---|
| 393 | if (!$update)
|
|---|
| 394 | {
|
|---|
| 395 | $forum_data = $row;
|
|---|
| 396 | }
|
|---|
| 397 | else
|
|---|
| 398 | {
|
|---|
| 399 | $forum_data['left_id'] = $row['left_id'];
|
|---|
| 400 | $forum_data['right_id'] = $row['right_id'];
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 | // Make sure no direct child forums are able to be selected as parents.
|
|---|
| 404 | $exclude_forums = array();
|
|---|
| 405 | foreach (get_forum_branch($forum_id, 'children') as $row)
|
|---|
| 406 | {
|
|---|
| 407 | $exclude_forums[] = $row['forum_id'];
|
|---|
| 408 | }
|
|---|
| 409 |
|
|---|
| 410 | $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
|
|---|
| 411 |
|
|---|
| 412 | $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
|
|---|
| 413 | }
|
|---|
| 414 | else
|
|---|
| 415 | {
|
|---|
| 416 | $this->page_title = 'CREATE_FORUM';
|
|---|
| 417 |
|
|---|
| 418 | $forum_id = $this->parent_id;
|
|---|
| 419 | $parents_list = make_forum_select($this->parent_id, false, false, false, false);
|
|---|
| 420 |
|
|---|
| 421 | // Fill forum data with default values
|
|---|
| 422 | if (!$update)
|
|---|
| 423 | {
|
|---|
| 424 | $forum_data = array(
|
|---|
| 425 | 'parent_id' => $this->parent_id,
|
|---|
| 426 | 'forum_type' => FORUM_POST,
|
|---|
| 427 | 'forum_status' => ITEM_UNLOCKED,
|
|---|
| 428 | 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
|
|---|
| 429 | 'forum_link' => '',
|
|---|
| 430 | 'forum_link_track' => false,
|
|---|
| 431 | 'forum_desc' => '',
|
|---|
| 432 | 'forum_rules' => '',
|
|---|
| 433 | 'forum_rules_link' => '',
|
|---|
| 434 | 'forum_image' => '',
|
|---|
| 435 | 'forum_style' => 0,
|
|---|
| 436 | 'display_subforum_list' => true,
|
|---|
| 437 | 'display_on_index' => false,
|
|---|
| 438 | 'forum_topics_per_page' => 0,
|
|---|
| 439 | 'enable_indexing' => true,
|
|---|
| 440 | 'enable_icons' => false,
|
|---|
| 441 | 'enable_prune' => false,
|
|---|
| 442 | 'prune_days' => 7,
|
|---|
| 443 | 'prune_viewed' => 7,
|
|---|
| 444 | 'prune_freq' => 1,
|
|---|
| 445 | 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
|
|---|
| 446 | 'forum_options' => 0,
|
|---|
| 447 | 'forum_password' => '',
|
|---|
| 448 | 'forum_password_confirm'=> '',
|
|---|
| 449 | );
|
|---|
| 450 | }
|
|---|
| 451 | }
|
|---|
| 452 |
|
|---|
| 453 | $forum_rules_data = array(
|
|---|
| 454 | 'text' => $forum_data['forum_rules'],
|
|---|
| 455 | 'allow_bbcode' => true,
|
|---|
| 456 | 'allow_smilies' => true,
|
|---|
| 457 | 'allow_urls' => true
|
|---|
| 458 | );
|
|---|
| 459 |
|
|---|
| 460 | $forum_desc_data = array(
|
|---|
| 461 | 'text' => $forum_data['forum_desc'],
|
|---|
| 462 | 'allow_bbcode' => true,
|
|---|
| 463 | 'allow_smilies' => true,
|
|---|
| 464 | 'allow_urls' => true
|
|---|
| 465 | );
|
|---|
| 466 |
|
|---|
| 467 | $forum_rules_preview = '';
|
|---|
| 468 |
|
|---|
| 469 | // Parse rules if specified
|
|---|
| 470 | if ($forum_data['forum_rules'])
|
|---|
| 471 | {
|
|---|
| 472 | if (!isset($forum_data['forum_rules_uid']))
|
|---|
| 473 | {
|
|---|
| 474 | // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
|
|---|
| 475 | $forum_data['forum_rules_uid'] = '';
|
|---|
| 476 | $forum_data['forum_rules_bitfield'] = '';
|
|---|
| 477 | $forum_data['forum_rules_options'] = 0;
|
|---|
| 478 |
|
|---|
| 479 | 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));
|
|---|
| 480 | }
|
|---|
| 481 |
|
|---|
| 482 | // Generate preview content
|
|---|
| 483 | $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']);
|
|---|
| 484 |
|
|---|
| 485 | // decode...
|
|---|
| 486 | $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
|
|---|
| 487 | }
|
|---|
| 488 |
|
|---|
| 489 | // Parse desciption if specified
|
|---|
| 490 | if ($forum_data['forum_desc'])
|
|---|
| 491 | {
|
|---|
| 492 | if (!isset($forum_data['forum_desc_uid']))
|
|---|
| 493 | {
|
|---|
| 494 | // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
|
|---|
| 495 | $forum_data['forum_desc_uid'] = '';
|
|---|
| 496 | $forum_data['forum_desc_bitfield'] = '';
|
|---|
| 497 | $forum_data['forum_desc_options'] = 0;
|
|---|
| 498 |
|
|---|
| 499 | 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));
|
|---|
| 500 | }
|
|---|
| 501 |
|
|---|
| 502 | // decode...
|
|---|
| 503 | $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
|
|---|
| 504 | }
|
|---|
| 505 |
|
|---|
| 506 | $forum_type_options = '';
|
|---|
| 507 | $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
|
|---|
| 508 |
|
|---|
| 509 | foreach ($forum_type_ary as $value => $lang)
|
|---|
| 510 | {
|
|---|
| 511 | $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | $styles_list = style_select($forum_data['forum_style'], true);
|
|---|
| 515 |
|
|---|
| 516 | $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>';
|
|---|
| 517 |
|
|---|
| 518 | $sql = 'SELECT forum_id
|
|---|
| 519 | FROM ' . FORUMS_TABLE . '
|
|---|
| 520 | WHERE forum_type = ' . FORUM_POST . "
|
|---|
| 521 | AND forum_id <> $forum_id";
|
|---|
| 522 | $result = $db->sql_query_limit($sql, 1);
|
|---|
| 523 |
|
|---|
| 524 | $postable_forum_exists = false;
|
|---|
| 525 | if ($db->sql_fetchrow($result))
|
|---|
| 526 | {
|
|---|
| 527 | $postable_forum_exists = true;
|
|---|
| 528 | }
|
|---|
| 529 | $db->sql_freeresult($result);
|
|---|
| 530 |
|
|---|
| 531 | // Subforum move options
|
|---|
| 532 | if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
|
|---|
| 533 | {
|
|---|
| 534 | $subforums_id = array();
|
|---|
| 535 | $subforums = get_forum_branch($forum_id, 'children');
|
|---|
| 536 |
|
|---|
| 537 | foreach ($subforums as $row)
|
|---|
| 538 | {
|
|---|
| 539 | $subforums_id[] = $row['forum_id'];
|
|---|
| 540 | }
|
|---|
| 541 |
|
|---|
| 542 | $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
|
|---|
| 543 |
|
|---|
| 544 | if ($postable_forum_exists)
|
|---|
| 545 | {
|
|---|
| 546 | $template->assign_vars(array(
|
|---|
| 547 | 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
|
|---|
| 548 | );
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | $template->assign_vars(array(
|
|---|
| 552 | 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
|
|---|
| 553 | 'S_FORUMS_LIST' => $forums_list)
|
|---|
| 554 | );
|
|---|
| 555 | }
|
|---|
| 556 | else if ($postable_forum_exists)
|
|---|
| 557 | {
|
|---|
| 558 | $template->assign_vars(array(
|
|---|
| 559 | 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
|
|---|
| 560 | );
|
|---|
| 561 | }
|
|---|
| 562 |
|
|---|
| 563 | $s_show_display_on_index = false;
|
|---|
| 564 |
|
|---|
| 565 | if ($forum_data['parent_id'] > 0)
|
|---|
| 566 | {
|
|---|
| 567 | // if this forum is a subforum put the "display on index" checkbox
|
|---|
| 568 | if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
|
|---|
| 569 | {
|
|---|
| 570 | if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
|
|---|
| 571 | {
|
|---|
| 572 | $s_show_display_on_index = true;
|
|---|
| 573 | }
|
|---|
| 574 | }
|
|---|
| 575 | }
|
|---|
| 576 |
|
|---|
| 577 | if (strlen($forum_data['forum_password']) == 32)
|
|---|
| 578 | {
|
|---|
| 579 | $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
|
|---|
| 580 | }
|
|---|
| 581 |
|
|---|
| 582 | $template->assign_vars(array(
|
|---|
| 583 | 'S_EDIT_FORUM' => true,
|
|---|
| 584 | 'S_ERROR' => (sizeof($errors)) ? true : false,
|
|---|
| 585 | 'S_PARENT_ID' => $this->parent_id,
|
|---|
| 586 | 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
|
|---|
| 587 | 'S_ADD_ACTION' => ($action == 'add') ? true : false,
|
|---|
| 588 |
|
|---|
| 589 | 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|---|
| 590 | 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
|
|---|
| 591 |
|
|---|
| 592 | 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
|
|---|
| 593 | 'L_TITLE' => $user->lang[$this->page_title],
|
|---|
| 594 | 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
|
|---|
| 595 |
|
|---|
| 596 | 'FORUM_NAME' => $forum_data['forum_name'],
|
|---|
| 597 | 'FORUM_DATA_LINK' => $forum_data['forum_link'],
|
|---|
| 598 | 'FORUM_IMAGE' => $forum_data['forum_image'],
|
|---|
| 599 | 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
|
|---|
| 600 | 'FORUM_POST' => FORUM_POST,
|
|---|
| 601 | 'FORUM_LINK' => FORUM_LINK,
|
|---|
| 602 | 'FORUM_CAT' => FORUM_CAT,
|
|---|
| 603 | 'PRUNE_FREQ' => $forum_data['prune_freq'],
|
|---|
| 604 | 'PRUNE_DAYS' => $forum_data['prune_days'],
|
|---|
| 605 | 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
|
|---|
| 606 | 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
|
|---|
| 607 | 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
|
|---|
| 608 | 'FORUM_RULES' => $forum_data['forum_rules'],
|
|---|
| 609 | 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
|
|---|
| 610 | 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
|
|---|
| 611 | 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
|
|---|
| 612 | 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
|
|---|
| 613 | 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
|
|---|
| 614 | 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
|
|---|
| 615 |
|
|---|
| 616 | 'FORUM_DESC' => $forum_desc_data['text'],
|
|---|
| 617 | 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
|
|---|
| 618 | 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
|
|---|
| 619 | 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
|
|---|
| 620 |
|
|---|
| 621 | 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
|
|---|
| 622 | 'S_STATUS_OPTIONS' => $statuslist,
|
|---|
| 623 | 'S_PARENT_OPTIONS' => $parents_list,
|
|---|
| 624 | 'S_STYLES_OPTIONS' => $styles_list,
|
|---|
| 625 | 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
|
|---|
| 626 | 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
|
|---|
| 627 | 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
|
|---|
| 628 | 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
|
|---|
| 629 | 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
|
|---|
| 630 | 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
|
|---|
| 631 | 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
|
|---|
| 632 | 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
|
|---|
| 633 | 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
|
|---|
| 634 | 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
|
|---|
| 635 | 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
|
|---|
| 636 | 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
|
|---|
| 637 | 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
|
|---|
| 638 | 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
|
|---|
| 639 | 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
|
|---|
| 640 | 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
|
|---|
| 641 | 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
|
|---|
| 642 | 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) ? true : false,
|
|---|
| 643 | 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
|
|---|
| 644 | 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
|
|---|
| 645 | '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,
|
|---|
| 646 | ));
|
|---|
| 647 |
|
|---|
| 648 | return;
|
|---|
| 649 |
|
|---|
| 650 | break;
|
|---|
| 651 |
|
|---|
| 652 | case 'delete':
|
|---|
| 653 |
|
|---|
| 654 | if (!$forum_id)
|
|---|
| 655 | {
|
|---|
| 656 | trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | $forum_data = $this->get_forum_info($forum_id);
|
|---|
| 660 |
|
|---|
| 661 | $subforums_id = array();
|
|---|
| 662 | $subforums = get_forum_branch($forum_id, 'children');
|
|---|
| 663 |
|
|---|
| 664 | foreach ($subforums as $row)
|
|---|
| 665 | {
|
|---|
| 666 | $subforums_id[] = $row['forum_id'];
|
|---|
| 667 | }
|
|---|
| 668 |
|
|---|
| 669 | $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
|
|---|
| 670 |
|
|---|
| 671 | $sql = 'SELECT forum_id
|
|---|
| 672 | FROM ' . FORUMS_TABLE . '
|
|---|
| 673 | WHERE forum_type = ' . FORUM_POST . "
|
|---|
| 674 | AND forum_id <> $forum_id";
|
|---|
| 675 | $result = $db->sql_query_limit($sql, 1);
|
|---|
| 676 |
|
|---|
| 677 | if ($db->sql_fetchrow($result))
|
|---|
| 678 | {
|
|---|
| 679 | $template->assign_vars(array(
|
|---|
| 680 | 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
|
|---|
| 681 | );
|
|---|
| 682 | }
|
|---|
| 683 | $db->sql_freeresult($result);
|
|---|
| 684 |
|
|---|
| 685 | $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
|
|---|
| 686 |
|
|---|
| 687 | $template->assign_vars(array(
|
|---|
| 688 | 'S_DELETE_FORUM' => true,
|
|---|
| 689 | 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
|
|---|
| 690 | 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|---|
| 691 |
|
|---|
| 692 | 'FORUM_NAME' => $forum_data['forum_name'],
|
|---|
| 693 | 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
|
|---|
| 694 | 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
|
|---|
| 695 | 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
|
|---|
| 696 | 'S_FORUMS_LIST' => $forums_list,
|
|---|
| 697 | 'S_ERROR' => (sizeof($errors)) ? true : false,
|
|---|
| 698 | 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
|
|---|
| 699 | );
|
|---|
| 700 |
|
|---|
| 701 | return;
|
|---|
| 702 | break;
|
|---|
| 703 |
|
|---|
| 704 | case 'copy_perm':
|
|---|
| 705 | $forum_perm_from = request_var('forum_perm_from', 0);
|
|---|
| 706 |
|
|---|
| 707 | // Copy permissions?
|
|---|
| 708 | if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
|
|---|
| 709 | {
|
|---|
| 710 | copy_forum_permissions($forum_perm_from, $forum_id, true);
|
|---|
| 711 | cache_moderators();
|
|---|
| 712 | $auth->acl_clear_prefetch();
|
|---|
| 713 | $cache->destroy('sql', FORUMS_TABLE);
|
|---|
| 714 |
|
|---|
| 715 | $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_id;
|
|---|
| 716 |
|
|---|
| 717 | $message = $user->lang['FORUM_UPDATED'];
|
|---|
| 718 |
|
|---|
| 719 | // Redirect to permissions
|
|---|
| 720 | if ($auth->acl_get('a_fauth'))
|
|---|
| 721 | {
|
|---|
| 722 | $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
|
|---|
| 723 | }
|
|---|
| 724 |
|
|---|
| 725 | trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
|
|---|
| 726 | }
|
|---|
| 727 |
|
|---|
| 728 | break;
|
|---|
| 729 | }
|
|---|
| 730 |
|
|---|
| 731 | // Default management page
|
|---|
| 732 | if (!$this->parent_id)
|
|---|
| 733 | {
|
|---|
| 734 | $navigation = $user->lang['FORUM_INDEX'];
|
|---|
| 735 | }
|
|---|
| 736 | else
|
|---|
| 737 | {
|
|---|
| 738 | $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
|
|---|
| 739 |
|
|---|
| 740 | $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
|
|---|
| 741 | foreach ($forums_nav as $row)
|
|---|
| 742 | {
|
|---|
| 743 | if ($row['forum_id'] == $this->parent_id)
|
|---|
| 744 | {
|
|---|
| 745 | $navigation .= ' -> ' . $row['forum_name'];
|
|---|
| 746 | }
|
|---|
| 747 | else
|
|---|
| 748 | {
|
|---|
| 749 | $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
|
|---|
| 750 | }
|
|---|
| 751 | }
|
|---|
| 752 | }
|
|---|
| 753 |
|
|---|
| 754 | // Jumpbox
|
|---|
| 755 | $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
|
|---|
| 756 |
|
|---|
| 757 | if ($action == 'sync' || $action == 'sync_forum')
|
|---|
| 758 | {
|
|---|
| 759 | $template->assign_var('S_RESYNCED', true);
|
|---|
| 760 | }
|
|---|
| 761 |
|
|---|
| 762 | $sql = 'SELECT *
|
|---|
| 763 | FROM ' . FORUMS_TABLE . "
|
|---|
| 764 | WHERE parent_id = $this->parent_id
|
|---|
| 765 | ORDER BY left_id";
|
|---|
| 766 | $result = $db->sql_query($sql);
|
|---|
| 767 |
|
|---|
| 768 | if ($row = $db->sql_fetchrow($result))
|
|---|
| 769 | {
|
|---|
| 770 | do
|
|---|
| 771 | {
|
|---|
| 772 | $forum_type = $row['forum_type'];
|
|---|
| 773 |
|
|---|
| 774 | if ($row['forum_status'] == ITEM_LOCKED)
|
|---|
| 775 | {
|
|---|
| 776 | $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
|
|---|
| 777 | }
|
|---|
| 778 | else
|
|---|
| 779 | {
|
|---|
| 780 | switch ($forum_type)
|
|---|
| 781 | {
|
|---|
| 782 | case FORUM_LINK:
|
|---|
| 783 | $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
|
|---|
| 784 | break;
|
|---|
| 785 |
|
|---|
| 786 | default:
|
|---|
| 787 | $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'] . '" />';
|
|---|
| 788 | break;
|
|---|
| 789 | }
|
|---|
| 790 | }
|
|---|
| 791 |
|
|---|
| 792 | $url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
|
|---|
| 793 |
|
|---|
| 794 | $template->assign_block_vars('forums', array(
|
|---|
| 795 | 'FOLDER_IMAGE' => $folder_image,
|
|---|
| 796 | 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
|
|---|
| 797 | 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
|
|---|
| 798 | 'FORUM_NAME' => $row['forum_name'],
|
|---|
| 799 | 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
|
|---|
| 800 | 'FORUM_TOPICS' => $row['forum_topics'],
|
|---|
| 801 | 'FORUM_POSTS' => $row['forum_posts'],
|
|---|
| 802 |
|
|---|
| 803 | 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
|
|---|
| 804 | 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
|
|---|
| 805 |
|
|---|
| 806 | 'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
|
|---|
| 807 | 'U_MOVE_UP' => $url . '&action=move_up',
|
|---|
| 808 | 'U_MOVE_DOWN' => $url . '&action=move_down',
|
|---|
| 809 | 'U_EDIT' => $url . '&action=edit',
|
|---|
| 810 | 'U_DELETE' => $url . '&action=delete',
|
|---|
| 811 | 'U_SYNC' => $url . '&action=sync')
|
|---|
| 812 | );
|
|---|
| 813 | }
|
|---|
| 814 | while ($row = $db->sql_fetchrow($result));
|
|---|
| 815 | }
|
|---|
| 816 | else if ($this->parent_id)
|
|---|
| 817 | {
|
|---|
| 818 | $row = $this->get_forum_info($this->parent_id);
|
|---|
| 819 |
|
|---|
| 820 | $url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
|
|---|
| 821 |
|
|---|
| 822 | $template->assign_vars(array(
|
|---|
| 823 | 'S_NO_FORUMS' => true,
|
|---|
| 824 |
|
|---|
| 825 | 'U_EDIT' => $url . '&action=edit',
|
|---|
| 826 | 'U_DELETE' => $url . '&action=delete',
|
|---|
| 827 | 'U_SYNC' => $url . '&action=sync')
|
|---|
| 828 | );
|
|---|
| 829 | }
|
|---|
| 830 | $db->sql_freeresult($result);
|
|---|
| 831 |
|
|---|
| 832 | $template->assign_vars(array(
|
|---|
| 833 | 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
|
|---|
| 834 | 'NAVIGATION' => $navigation,
|
|---|
| 835 | 'FORUM_BOX' => $forum_box,
|
|---|
| 836 | 'U_SEL_ACTION' => $this->u_action,
|
|---|
| 837 | 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
|
|---|
| 838 |
|
|---|
| 839 | 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
|
|---|
| 840 | 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
|
|---|
| 841 | ));
|
|---|
| 842 | }
|
|---|
| 843 |
|
|---|
| 844 | /**
|
|---|
| 845 | * Get forum details
|
|---|
| 846 | */
|
|---|
| 847 | function get_forum_info($forum_id)
|
|---|
| 848 | {
|
|---|
| 849 | global $db;
|
|---|
| 850 |
|
|---|
| 851 | $sql = 'SELECT *
|
|---|
| 852 | FROM ' . FORUMS_TABLE . "
|
|---|
| 853 | WHERE forum_id = $forum_id";
|
|---|
| 854 | $result = $db->sql_query($sql);
|
|---|
| 855 | $row = $db->sql_fetchrow($result);
|
|---|
| 856 | $db->sql_freeresult($result);
|
|---|
| 857 |
|
|---|
| 858 | if (!$row)
|
|---|
| 859 | {
|
|---|
| 860 | trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
|
|---|
| 861 | }
|
|---|
| 862 |
|
|---|
| 863 | return $row;
|
|---|
| 864 | }
|
|---|
| 865 |
|
|---|
| 866 | /**
|
|---|
| 867 | * Update forum data
|
|---|
| 868 | */
|
|---|
| 869 | function update_forum_data(&$forum_data)
|
|---|
| 870 | {
|
|---|
| 871 | global $db, $user, $cache, $phpbb_root_path;
|
|---|
| 872 |
|
|---|
| 873 | $errors = array();
|
|---|
| 874 |
|
|---|
| 875 | if (!$forum_data['forum_name'])
|
|---|
| 876 | {
|
|---|
| 877 | $errors[] = $user->lang['FORUM_NAME_EMPTY'];
|
|---|
| 878 | }
|
|---|
| 879 |
|
|---|
| 880 | if (utf8_strlen($forum_data['forum_desc']) > 4000)
|
|---|
| 881 | {
|
|---|
| 882 | $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
|
|---|
| 883 | }
|
|---|
| 884 |
|
|---|
| 885 | if (utf8_strlen($forum_data['forum_rules']) > 4000)
|
|---|
| 886 | {
|
|---|
| 887 | $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
|
|---|
| 888 | }
|
|---|
| 889 |
|
|---|
| 890 | if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
|
|---|
| 891 | {
|
|---|
| 892 | if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
|
|---|
| 893 | {
|
|---|
| 894 | $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
|
|---|
| 895 | $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
|
|---|
| 896 | }
|
|---|
| 897 | }
|
|---|
| 898 |
|
|---|
| 899 | if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
|
|---|
| 900 | {
|
|---|
| 901 | $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
|
|---|
| 902 | $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | $range_test_ary = array(
|
|---|
| 906 | array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
|
|---|
| 907 | );
|
|---|
| 908 |
|
|---|
| 909 | if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
|
|---|
| 910 | {
|
|---|
| 911 | $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
|
|---|
| 912 | }
|
|---|
| 913 |
|
|---|
| 914 | validate_range($range_test_ary, $errors);
|
|---|
| 915 |
|
|---|
| 916 | // Set forum flags
|
|---|
| 917 | // 1 = link tracking
|
|---|
| 918 | // 2 = prune old polls
|
|---|
| 919 | // 4 = prune announcements
|
|---|
| 920 | // 8 = prune stickies
|
|---|
| 921 | // 16 = show active topics
|
|---|
| 922 | // 32 = enable post review
|
|---|
| 923 | $forum_data['forum_flags'] = 0;
|
|---|
| 924 | $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
|
|---|
| 925 | $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
|
|---|
| 926 | $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
|
|---|
| 927 | $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
|
|---|
| 928 | $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
|
|---|
| 929 | $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
|
|---|
| 930 | $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
|
|---|
| 931 |
|
|---|
| 932 | // Unset data that are not database fields
|
|---|
| 933 | $forum_data_sql = $forum_data;
|
|---|
| 934 |
|
|---|
| 935 | unset($forum_data_sql['forum_link_track']);
|
|---|
| 936 | unset($forum_data_sql['prune_old_polls']);
|
|---|
| 937 | unset($forum_data_sql['prune_announce']);
|
|---|
| 938 | unset($forum_data_sql['prune_sticky']);
|
|---|
| 939 | unset($forum_data_sql['show_active']);
|
|---|
| 940 | unset($forum_data_sql['enable_post_review']);
|
|---|
| 941 | unset($forum_data_sql['enable_quick_reply']);
|
|---|
| 942 | unset($forum_data_sql['forum_password_confirm']);
|
|---|
| 943 |
|
|---|
| 944 | // What are we going to do tonight Brain? The same thing we do everynight,
|
|---|
| 945 | // try to take over the world ... or decide whether to continue update
|
|---|
| 946 | // and if so, whether it's a new forum/cat/link or an existing one
|
|---|
| 947 | if (sizeof($errors))
|
|---|
| 948 | {
|
|---|
| 949 | return $errors;
|
|---|
| 950 | }
|
|---|
| 951 |
|
|---|
| 952 | // As we don't know the old password, it's kinda tricky to detect changes
|
|---|
| 953 | if ($forum_data_sql['forum_password_unset'])
|
|---|
| 954 | {
|
|---|
| 955 | $forum_data_sql['forum_password'] = '';
|
|---|
| 956 | }
|
|---|
| 957 | else if (empty($forum_data_sql['forum_password']))
|
|---|
| 958 | {
|
|---|
| 959 | unset($forum_data_sql['forum_password']);
|
|---|
| 960 | }
|
|---|
| 961 | else
|
|---|
| 962 | {
|
|---|
| 963 | $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
|
|---|
| 964 | }
|
|---|
| 965 | unset($forum_data_sql['forum_password_unset']);
|
|---|
| 966 |
|
|---|
| 967 | if (!isset($forum_data_sql['forum_id']))
|
|---|
| 968 | {
|
|---|
| 969 | // no forum_id means we're creating a new forum
|
|---|
| 970 | unset($forum_data_sql['type_action']);
|
|---|
| 971 |
|
|---|
| 972 | if ($forum_data_sql['parent_id'])
|
|---|
| 973 | {
|
|---|
| 974 | $sql = 'SELECT left_id, right_id, forum_type
|
|---|
| 975 | FROM ' . FORUMS_TABLE . '
|
|---|
| 976 | WHERE forum_id = ' . $forum_data_sql['parent_id'];
|
|---|
| 977 | $result = $db->sql_query($sql);
|
|---|
| 978 | $row = $db->sql_fetchrow($result);
|
|---|
| 979 | $db->sql_freeresult($result);
|
|---|
| 980 |
|
|---|
| 981 | if (!$row)
|
|---|
| 982 | {
|
|---|
| 983 | trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&' . $this->parent_id), E_USER_WARNING);
|
|---|
| 984 | }
|
|---|
| 985 |
|
|---|
| 986 | if ($row['forum_type'] == FORUM_LINK)
|
|---|
| 987 | {
|
|---|
| 988 | $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
|
|---|
| 989 | return $errors;
|
|---|
| 990 | }
|
|---|
| 991 |
|
|---|
| 992 | $sql = 'UPDATE ' . FORUMS_TABLE . '
|
|---|
| 993 | SET left_id = left_id + 2, right_id = right_id + 2
|
|---|
| 994 | WHERE left_id > ' . $row['right_id'];
|
|---|
| 995 | $db->sql_query($sql);
|
|---|
| 996 |
|
|---|
| 997 | $sql = 'UPDATE ' . FORUMS_TABLE . '
|
|---|
| 998 | SET right_id = right_id + 2
|
|---|
| 999 | WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
|
|---|
| 1000 | $db->sql_query($sql);
|
|---|
| 1001 |
|
|---|
| 1002 | $forum_data_sql['left_id'] = $row['right_id'];
|
|---|
| 1003 | $forum_data_sql['right_id'] = $row['right_id'] + 1;
|
|---|
| 1004 | }
|
|---|
| 1005 | else
|
|---|
| 1006 | {
|
|---|
| 1007 | $sql = 'SELECT MAX(right_id) AS right_id
|
|---|
| 1008 | FROM ' . FORUMS_TABLE;
|
|---|
| 1009 | $result = $db->sql_query($sql);
|
|---|
| 1010 | $row = $db->sql_fetchrow($result);
|
|---|
| 1011 | $db->sql_freeresult($result);
|
|---|
| 1012 |
|
|---|
| 1013 | $forum_data_sql['left_id'] = $row['right_id'] + 1;
|
|---|
| 1014 | $forum_data_sql['right_id'] = $row['right_id'] + 2;
|
|---|
| 1015 | }
|
|---|
| 1016 |
|
|---|
| 1017 | $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
|
|---|
| 1018 | $db->sql_query($sql);
|
|---|
| 1019 |
|
|---|
| 1020 | $forum_data['forum_id'] = $db->sql_nextid();
|
|---|
| 1021 |
|
|---|
| 1022 | add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
|
|---|
| 1023 | }
|
|---|
| 1024 | else
|
|---|
| 1025 | {
|
|---|
| 1026 | $row = $this->get_forum_info($forum_data_sql['forum_id']);
|
|---|
| 1027 |
|
|---|
| 1028 | if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
|
|---|
| 1029 | {
|
|---|
| 1030 | // Has subforums and want to change into a link?
|
|---|
| 1031 | if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
|
|---|
| 1032 | {
|
|---|
| 1033 | $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
|
|---|
| 1034 | return $errors;
|
|---|
| 1035 | }
|
|---|
| 1036 |
|
|---|
| 1037 | // we're turning a postable forum into a non-postable forum
|
|---|
| 1038 | if ($forum_data_sql['type_action'] == 'move')
|
|---|
| 1039 | {
|
|---|
| 1040 | $to_forum_id = request_var('to_forum_id', 0);
|
|---|
| 1041 |
|
|---|
| 1042 | if ($to_forum_id)
|
|---|
| 1043 | {
|
|---|
| 1044 | $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
|
|---|
| 1045 | }
|
|---|
| 1046 | else
|
|---|
| 1047 | {
|
|---|
| 1048 | return array($user->lang['NO_DESTINATION_FORUM']);
|
|---|
| 1049 | }
|
|---|
| 1050 | }
|
|---|
| 1051 | else if ($forum_data_sql['type_action'] == 'delete')
|
|---|
| 1052 | {
|
|---|
| 1053 | $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
|
|---|
| 1054 | }
|
|---|
| 1055 | else
|
|---|
| 1056 | {
|
|---|
| 1057 | return array($user->lang['NO_FORUM_ACTION']);
|
|---|
| 1058 | }
|
|---|
| 1059 |
|
|---|
| 1060 | $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;
|
|---|
| 1061 | $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
|
|---|
| 1062 | }
|
|---|
| 1063 | else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
|
|---|
| 1064 | {
|
|---|
| 1065 | // Has subforums?
|
|---|
| 1066 | if ($row['right_id'] - $row['left_id'] > 1)
|
|---|
| 1067 | {
|
|---|
| 1068 | // We are turning a category into a link - but need to decide what to do with the subforums.
|
|---|
| 1069 | $action_subforums = request_var('action_subforums', '');
|
|---|
| 1070 | $subforums_to_id = request_var('subforums_to_id', 0);
|
|---|
| 1071 |
|
|---|
| 1072 | if ($action_subforums == 'delete')
|
|---|
| 1073 | {
|
|---|
| 1074 | $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
|
|---|
| 1075 |
|
|---|
| 1076 | foreach ($rows as $_row)
|
|---|
| 1077 | {
|
|---|
| 1078 | // Do not remove the forum id we are about to change. ;)
|
|---|
| 1079 | if ($_row['forum_id'] == $row['forum_id'])
|
|---|
| 1080 | {
|
|---|
| 1081 | continue;
|
|---|
| 1082 | }
|
|---|
| 1083 |
|
|---|
| 1084 | $forum_ids[] = $_row['forum_id'];
|
|---|
| 1085 | $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
|
|---|
| 1086 | }
|
|---|
| 1087 |
|
|---|
| 1088 | if (sizeof($errors))
|
|---|
| 1089 | {
|
|---|
| 1090 | return $errors;
|
|---|
| 1091 | }
|
|---|
| 1092 |
|
|---|
| 1093 | if (sizeof($forum_ids))
|
|---|
| 1094 | {
|
|---|
| 1095 | $sql = 'DELETE FROM ' . FORUMS_TABLE . '
|
|---|
| 1096 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1097 | $db->sql_query($sql);
|
|---|
| 1098 |
|
|---|
| 1099 | $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|---|
| 1100 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1101 | $db->sql_query($sql);
|
|---|
| 1102 |
|
|---|
| 1103 | $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|---|
| 1104 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1105 | $db->sql_query($sql);
|
|---|
| 1106 |
|
|---|
| 1107 | // Delete forum ids from extension groups table
|
|---|
| 1108 | $sql = 'SELECT group_id, allowed_forums
|
|---|
| 1109 | FROM ' . EXTENSION_GROUPS_TABLE;
|
|---|
| 1110 | $result = $db->sql_query($sql);
|
|---|
| 1111 |
|
|---|
| 1112 | while ($_row = $db->sql_fetchrow($result))
|
|---|
| 1113 | {
|
|---|
| 1114 | if (!$_row['allowed_forums'])
|
|---|
| 1115 | {
|
|---|
| 1116 | continue;
|
|---|
| 1117 | }
|
|---|
| 1118 |
|
|---|
| 1119 | $allowed_forums = unserialize(trim($_row['allowed_forums']));
|
|---|
| 1120 | $allowed_forums = array_diff($allowed_forums, $forum_ids);
|
|---|
| 1121 |
|
|---|
| 1122 | $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
|
|---|
| 1123 | SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
|
|---|
| 1124 | WHERE group_id = {$_row['group_id']}";
|
|---|
| 1125 | $db->sql_query($sql);
|
|---|
| 1126 | }
|
|---|
| 1127 | $db->sql_freeresult($result);
|
|---|
| 1128 |
|
|---|
| 1129 | $cache->destroy('_extensions');
|
|---|
| 1130 | }
|
|---|
| 1131 | }
|
|---|
| 1132 | else if ($action_subforums == 'move')
|
|---|
| 1133 | {
|
|---|
| 1134 | if (!$subforums_to_id)
|
|---|
| 1135 | {
|
|---|
| 1136 | return array($user->lang['NO_DESTINATION_FORUM']);
|
|---|
| 1137 | }
|
|---|
| 1138 |
|
|---|
| 1139 | $sql = 'SELECT forum_name
|
|---|
| 1140 | FROM ' . FORUMS_TABLE . '
|
|---|
| 1141 | WHERE forum_id = ' . $subforums_to_id;
|
|---|
| 1142 | $result = $db->sql_query($sql);
|
|---|
| 1143 | $_row = $db->sql_fetchrow($result);
|
|---|
| 1144 | $db->sql_freeresult($result);
|
|---|
| 1145 |
|
|---|
| 1146 | if (!$_row)
|
|---|
| 1147 | {
|
|---|
| 1148 | return array($user->lang['NO_FORUM']);
|
|---|
| 1149 | }
|
|---|
| 1150 |
|
|---|
| 1151 | $subforums_to_name = $_row['forum_name'];
|
|---|
| 1152 |
|
|---|
| 1153 | $sql = 'SELECT forum_id
|
|---|
| 1154 | FROM ' . FORUMS_TABLE . "
|
|---|
| 1155 | WHERE parent_id = {$row['forum_id']}";
|
|---|
| 1156 | $result = $db->sql_query($sql);
|
|---|
| 1157 |
|
|---|
| 1158 | while ($_row = $db->sql_fetchrow($result))
|
|---|
| 1159 | {
|
|---|
| 1160 | $this->move_forum($_row['forum_id'], $subforums_to_id);
|
|---|
| 1161 | }
|
|---|
| 1162 | $db->sql_freeresult($result);
|
|---|
| 1163 |
|
|---|
| 1164 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1165 | SET parent_id = $subforums_to_id
|
|---|
| 1166 | WHERE parent_id = {$row['forum_id']}";
|
|---|
| 1167 | $db->sql_query($sql);
|
|---|
| 1168 | }
|
|---|
| 1169 |
|
|---|
| 1170 | // Adjust the left/right id
|
|---|
| 1171 | $sql = 'UPDATE ' . FORUMS_TABLE . '
|
|---|
| 1172 | SET right_id = left_id + 1
|
|---|
| 1173 | WHERE forum_id = ' . $row['forum_id'];
|
|---|
| 1174 | $db->sql_query($sql);
|
|---|
| 1175 | }
|
|---|
| 1176 | }
|
|---|
| 1177 | else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
|
|---|
| 1178 | {
|
|---|
| 1179 | // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
|
|---|
| 1180 | $forum_data_sql['forum_posts'] = 0;
|
|---|
| 1181 | $forum_data_sql['forum_topics'] = 0;
|
|---|
| 1182 | $forum_data_sql['forum_topics_real'] = 0;
|
|---|
| 1183 | $forum_data_sql['forum_last_post_id'] = 0;
|
|---|
| 1184 | $forum_data_sql['forum_last_post_subject'] = '';
|
|---|
| 1185 | $forum_data_sql['forum_last_post_time'] = 0;
|
|---|
| 1186 | $forum_data_sql['forum_last_poster_id'] = 0;
|
|---|
| 1187 | $forum_data_sql['forum_last_poster_name'] = '';
|
|---|
| 1188 | $forum_data_sql['forum_last_poster_colour'] = '';
|
|---|
| 1189 | }
|
|---|
| 1190 |
|
|---|
| 1191 | if (sizeof($errors))
|
|---|
| 1192 | {
|
|---|
| 1193 | return $errors;
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | if ($row['parent_id'] != $forum_data_sql['parent_id'])
|
|---|
| 1197 | {
|
|---|
| 1198 | if ($row['forum_id'] != $forum_data_sql['parent_id'])
|
|---|
| 1199 | {
|
|---|
| 1200 | $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
|
|---|
| 1201 | }
|
|---|
| 1202 | else
|
|---|
| 1203 | {
|
|---|
| 1204 | $forum_data_sql['parent_id'] = $row['parent_id'];
|
|---|
| 1205 | }
|
|---|
| 1206 | }
|
|---|
| 1207 |
|
|---|
| 1208 | if (sizeof($errors))
|
|---|
| 1209 | {
|
|---|
| 1210 | return $errors;
|
|---|
| 1211 | }
|
|---|
| 1212 |
|
|---|
| 1213 | unset($forum_data_sql['type_action']);
|
|---|
| 1214 |
|
|---|
| 1215 | if ($row['forum_name'] != $forum_data_sql['forum_name'])
|
|---|
| 1216 | {
|
|---|
| 1217 | // the forum name has changed, clear the parents list of all forums (for safety)
|
|---|
| 1218 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1219 | SET forum_parents = ''";
|
|---|
| 1220 | $db->sql_query($sql);
|
|---|
| 1221 | }
|
|---|
| 1222 |
|
|---|
| 1223 | // Setting the forum id to the forum id is not really received well by some dbs. ;)
|
|---|
| 1224 | $forum_id = $forum_data_sql['forum_id'];
|
|---|
| 1225 | unset($forum_data_sql['forum_id']);
|
|---|
| 1226 |
|
|---|
| 1227 | $sql = 'UPDATE ' . FORUMS_TABLE . '
|
|---|
| 1228 | SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
|
|---|
| 1229 | WHERE forum_id = ' . $forum_id;
|
|---|
| 1230 | $db->sql_query($sql);
|
|---|
| 1231 |
|
|---|
| 1232 | // Add it back
|
|---|
| 1233 | $forum_data['forum_id'] = $forum_id;
|
|---|
| 1234 |
|
|---|
| 1235 | add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
|
|---|
| 1236 | }
|
|---|
| 1237 |
|
|---|
| 1238 | return $errors;
|
|---|
| 1239 | }
|
|---|
| 1240 |
|
|---|
| 1241 | /**
|
|---|
| 1242 | * Move forum
|
|---|
| 1243 | */
|
|---|
| 1244 | function move_forum($from_id, $to_id)
|
|---|
| 1245 | {
|
|---|
| 1246 | global $db, $user;
|
|---|
| 1247 |
|
|---|
| 1248 | $to_data = $moved_ids = $errors = array();
|
|---|
| 1249 |
|
|---|
| 1250 | // Check if we want to move to a parent with link type
|
|---|
| 1251 | if ($to_id > 0)
|
|---|
| 1252 | {
|
|---|
| 1253 | $to_data = $this->get_forum_info($to_id);
|
|---|
| 1254 |
|
|---|
| 1255 | if ($to_data['forum_type'] == FORUM_LINK)
|
|---|
| 1256 | {
|
|---|
| 1257 | $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
|
|---|
| 1258 | return $errors;
|
|---|
| 1259 | }
|
|---|
| 1260 | }
|
|---|
| 1261 |
|
|---|
| 1262 | $moved_forums = get_forum_branch($from_id, 'children', 'descending');
|
|---|
| 1263 | $from_data = $moved_forums[0];
|
|---|
| 1264 | $diff = sizeof($moved_forums) * 2;
|
|---|
| 1265 |
|
|---|
| 1266 | $moved_ids = array();
|
|---|
| 1267 | for ($i = 0; $i < sizeof($moved_forums); ++$i)
|
|---|
| 1268 | {
|
|---|
| 1269 | $moved_ids[] = $moved_forums[$i]['forum_id'];
|
|---|
| 1270 | }
|
|---|
| 1271 |
|
|---|
| 1272 | // Resync parents
|
|---|
| 1273 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1274 | SET right_id = right_id - $diff, forum_parents = ''
|
|---|
| 1275 | WHERE left_id < " . $from_data['right_id'] . "
|
|---|
| 1276 | AND right_id > " . $from_data['right_id'];
|
|---|
| 1277 | $db->sql_query($sql);
|
|---|
| 1278 |
|
|---|
| 1279 | // Resync righthand side of tree
|
|---|
| 1280 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1281 | SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
|
|---|
| 1282 | WHERE left_id > " . $from_data['right_id'];
|
|---|
| 1283 | $db->sql_query($sql);
|
|---|
| 1284 |
|
|---|
| 1285 | if ($to_id > 0)
|
|---|
| 1286 | {
|
|---|
| 1287 | // Retrieve $to_data again, it may have been changed...
|
|---|
| 1288 | $to_data = $this->get_forum_info($to_id);
|
|---|
| 1289 |
|
|---|
| 1290 | // Resync new parents
|
|---|
| 1291 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1292 | SET right_id = right_id + $diff, forum_parents = ''
|
|---|
| 1293 | WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
|
|---|
| 1294 | AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|---|
| 1295 | $db->sql_query($sql);
|
|---|
| 1296 |
|
|---|
| 1297 | // Resync the righthand side of the tree
|
|---|
| 1298 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1299 | SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
|
|---|
| 1300 | WHERE left_id > " . $to_data['right_id'] . '
|
|---|
| 1301 | AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|---|
| 1302 | $db->sql_query($sql);
|
|---|
| 1303 |
|
|---|
| 1304 | // Resync moved branch
|
|---|
| 1305 | $to_data['right_id'] += $diff;
|
|---|
| 1306 |
|
|---|
| 1307 | if ($to_data['right_id'] > $from_data['right_id'])
|
|---|
| 1308 | {
|
|---|
| 1309 | $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
|
|---|
| 1310 | }
|
|---|
| 1311 | else
|
|---|
| 1312 | {
|
|---|
| 1313 | $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
|
|---|
| 1314 | }
|
|---|
| 1315 | }
|
|---|
| 1316 | else
|
|---|
| 1317 | {
|
|---|
| 1318 | $sql = 'SELECT MAX(right_id) AS right_id
|
|---|
| 1319 | FROM ' . FORUMS_TABLE . '
|
|---|
| 1320 | WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
|
|---|
| 1321 | $result = $db->sql_query($sql);
|
|---|
| 1322 | $row = $db->sql_fetchrow($result);
|
|---|
| 1323 | $db->sql_freeresult($result);
|
|---|
| 1324 |
|
|---|
| 1325 | $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
|
|---|
| 1326 | }
|
|---|
| 1327 |
|
|---|
| 1328 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1329 | SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
|
|---|
| 1330 | WHERE " . $db->sql_in_set('forum_id', $moved_ids);
|
|---|
| 1331 | $db->sql_query($sql);
|
|---|
| 1332 |
|
|---|
| 1333 | return $errors;
|
|---|
| 1334 | }
|
|---|
| 1335 |
|
|---|
| 1336 | /**
|
|---|
| 1337 | * Move forum content from one to another forum
|
|---|
| 1338 | */
|
|---|
| 1339 | function move_forum_content($from_id, $to_id, $sync = true)
|
|---|
| 1340 | {
|
|---|
| 1341 | global $db;
|
|---|
| 1342 |
|
|---|
| 1343 | $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
|
|---|
| 1344 |
|
|---|
| 1345 | foreach ($table_ary as $table)
|
|---|
| 1346 | {
|
|---|
| 1347 | $sql = "UPDATE $table
|
|---|
| 1348 | SET forum_id = $to_id
|
|---|
| 1349 | WHERE forum_id = $from_id";
|
|---|
| 1350 | $db->sql_query($sql);
|
|---|
| 1351 | }
|
|---|
| 1352 | unset($table_ary);
|
|---|
| 1353 |
|
|---|
| 1354 | $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
|
|---|
| 1355 |
|
|---|
| 1356 | foreach ($table_ary as $table)
|
|---|
| 1357 | {
|
|---|
| 1358 | $sql = "DELETE FROM $table
|
|---|
| 1359 | WHERE forum_id = $from_id";
|
|---|
| 1360 | $db->sql_query($sql);
|
|---|
| 1361 | }
|
|---|
| 1362 |
|
|---|
| 1363 | if ($sync)
|
|---|
| 1364 | {
|
|---|
| 1365 | // Delete ghost topics that link back to the same forum then resync counters
|
|---|
| 1366 | sync('topic_moved');
|
|---|
| 1367 | sync('forum', 'forum_id', $to_id, false, true);
|
|---|
| 1368 | }
|
|---|
| 1369 |
|
|---|
| 1370 | return array();
|
|---|
| 1371 | }
|
|---|
| 1372 |
|
|---|
| 1373 | /**
|
|---|
| 1374 | * Remove complete forum
|
|---|
| 1375 | */
|
|---|
| 1376 | function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
|
|---|
| 1377 | {
|
|---|
| 1378 | global $db, $user, $cache;
|
|---|
| 1379 |
|
|---|
| 1380 | $forum_data = $this->get_forum_info($forum_id);
|
|---|
| 1381 |
|
|---|
| 1382 | $errors = array();
|
|---|
| 1383 | $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
|
|---|
| 1384 | $forum_ids = array($forum_id);
|
|---|
| 1385 |
|
|---|
| 1386 | if ($action_posts == 'delete')
|
|---|
| 1387 | {
|
|---|
| 1388 | $log_action_posts = 'POSTS';
|
|---|
| 1389 | $errors = array_merge($errors, $this->delete_forum_content($forum_id));
|
|---|
| 1390 | }
|
|---|
| 1391 | else if ($action_posts == 'move')
|
|---|
| 1392 | {
|
|---|
| 1393 | if (!$posts_to_id)
|
|---|
| 1394 | {
|
|---|
| 1395 | $errors[] = $user->lang['NO_DESTINATION_FORUM'];
|
|---|
| 1396 | }
|
|---|
| 1397 | else
|
|---|
| 1398 | {
|
|---|
| 1399 | $log_action_posts = 'MOVE_POSTS';
|
|---|
| 1400 |
|
|---|
| 1401 | $sql = 'SELECT forum_name
|
|---|
| 1402 | FROM ' . FORUMS_TABLE . '
|
|---|
| 1403 | WHERE forum_id = ' . $posts_to_id;
|
|---|
| 1404 | $result = $db->sql_query($sql);
|
|---|
| 1405 | $row = $db->sql_fetchrow($result);
|
|---|
| 1406 | $db->sql_freeresult($result);
|
|---|
| 1407 |
|
|---|
| 1408 | if (!$row)
|
|---|
| 1409 | {
|
|---|
| 1410 | $errors[] = $user->lang['NO_FORUM'];
|
|---|
| 1411 | }
|
|---|
| 1412 | else
|
|---|
| 1413 | {
|
|---|
| 1414 | $posts_to_name = $row['forum_name'];
|
|---|
| 1415 | $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
|
|---|
| 1416 | }
|
|---|
| 1417 | }
|
|---|
| 1418 | }
|
|---|
| 1419 |
|
|---|
| 1420 | if (sizeof($errors))
|
|---|
| 1421 | {
|
|---|
| 1422 | return $errors;
|
|---|
| 1423 | }
|
|---|
| 1424 |
|
|---|
| 1425 | if ($action_subforums == 'delete')
|
|---|
| 1426 | {
|
|---|
| 1427 | $log_action_forums = 'FORUMS';
|
|---|
| 1428 | $rows = get_forum_branch($forum_id, 'children', 'descending', false);
|
|---|
| 1429 |
|
|---|
| 1430 | foreach ($rows as $row)
|
|---|
| 1431 | {
|
|---|
| 1432 | $forum_ids[] = $row['forum_id'];
|
|---|
| 1433 | $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
|
|---|
| 1434 | }
|
|---|
| 1435 |
|
|---|
| 1436 | if (sizeof($errors))
|
|---|
| 1437 | {
|
|---|
| 1438 | return $errors;
|
|---|
| 1439 | }
|
|---|
| 1440 |
|
|---|
| 1441 | $diff = sizeof($forum_ids) * 2;
|
|---|
| 1442 |
|
|---|
| 1443 | $sql = 'DELETE FROM ' . FORUMS_TABLE . '
|
|---|
| 1444 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1445 | $db->sql_query($sql);
|
|---|
| 1446 |
|
|---|
| 1447 | $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
|
|---|
| 1448 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1449 | $db->sql_query($sql);
|
|---|
| 1450 |
|
|---|
| 1451 | $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
|
|---|
| 1452 | WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
|
|---|
| 1453 | $db->sql_query($sql);
|
|---|
| 1454 | }
|
|---|
| 1455 | else if ($action_subforums == 'move')
|
|---|
| 1456 | {
|
|---|
| 1457 | if (!$subforums_to_id)
|
|---|
| 1458 | {
|
|---|
| 1459 | $errors[] = $user->lang['NO_DESTINATION_FORUM'];
|
|---|
| 1460 | }
|
|---|
| 1461 | else
|
|---|
| 1462 | {
|
|---|
| 1463 | $log_action_forums = 'MOVE_FORUMS';
|
|---|
| 1464 |
|
|---|
| 1465 | $sql = 'SELECT forum_name
|
|---|
| 1466 | FROM ' . FORUMS_TABLE . '
|
|---|
| 1467 | WHERE forum_id = ' . $subforums_to_id;
|
|---|
| 1468 | $result = $db->sql_query($sql);
|
|---|
| 1469 | $row = $db->sql_fetchrow($result);
|
|---|
| 1470 | $db->sql_freeresult($result);
|
|---|
| 1471 |
|
|---|
| 1472 | if (!$row)
|
|---|
| 1473 | {
|
|---|
| 1474 | $errors[] = $user->lang['NO_FORUM'];
|
|---|
| 1475 | }
|
|---|
| 1476 | else
|
|---|
| 1477 | {
|
|---|
| 1478 | $subforums_to_name = $row['forum_name'];
|
|---|
| 1479 |
|
|---|
| 1480 | $sql = 'SELECT forum_id
|
|---|
| 1481 | FROM ' . FORUMS_TABLE . "
|
|---|
| 1482 | WHERE parent_id = $forum_id";
|
|---|
| 1483 | $result = $db->sql_query($sql);
|
|---|
| 1484 |
|
|---|
| 1485 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1486 | {
|
|---|
| 1487 | $this->move_forum($row['forum_id'], $subforums_to_id);
|
|---|
| 1488 | }
|
|---|
| 1489 | $db->sql_freeresult($result);
|
|---|
| 1490 |
|
|---|
| 1491 | // Grab new forum data for correct tree updating later
|
|---|
| 1492 | $forum_data = $this->get_forum_info($forum_id);
|
|---|
| 1493 |
|
|---|
| 1494 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1495 | SET parent_id = $subforums_to_id
|
|---|
| 1496 | WHERE parent_id = $forum_id";
|
|---|
| 1497 | $db->sql_query($sql);
|
|---|
| 1498 |
|
|---|
| 1499 | $diff = 2;
|
|---|
| 1500 | $sql = 'DELETE FROM ' . FORUMS_TABLE . "
|
|---|
| 1501 | WHERE forum_id = $forum_id";
|
|---|
| 1502 | $db->sql_query($sql);
|
|---|
| 1503 |
|
|---|
| 1504 | $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
|
|---|
| 1505 | WHERE forum_id = $forum_id";
|
|---|
| 1506 | $db->sql_query($sql);
|
|---|
| 1507 |
|
|---|
| 1508 | $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
|
|---|
| 1509 | WHERE forum_id = $forum_id";
|
|---|
| 1510 | $db->sql_query($sql);
|
|---|
| 1511 | }
|
|---|
| 1512 | }
|
|---|
| 1513 |
|
|---|
| 1514 | if (sizeof($errors))
|
|---|
| 1515 | {
|
|---|
| 1516 | return $errors;
|
|---|
| 1517 | }
|
|---|
| 1518 | }
|
|---|
| 1519 | else
|
|---|
| 1520 | {
|
|---|
| 1521 | $diff = 2;
|
|---|
| 1522 | $sql = 'DELETE FROM ' . FORUMS_TABLE . "
|
|---|
| 1523 | WHERE forum_id = $forum_id";
|
|---|
| 1524 | $db->sql_query($sql);
|
|---|
| 1525 |
|
|---|
| 1526 | $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
|
|---|
| 1527 | WHERE forum_id = $forum_id";
|
|---|
| 1528 | $db->sql_query($sql);
|
|---|
| 1529 |
|
|---|
| 1530 | $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
|
|---|
| 1531 | WHERE forum_id = $forum_id";
|
|---|
| 1532 | $db->sql_query($sql);
|
|---|
| 1533 | }
|
|---|
| 1534 |
|
|---|
| 1535 | // Resync tree
|
|---|
| 1536 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1537 | SET right_id = right_id - $diff
|
|---|
| 1538 | WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
|
|---|
| 1539 | $db->sql_query($sql);
|
|---|
| 1540 |
|
|---|
| 1541 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1542 | SET left_id = left_id - $diff, right_id = right_id - $diff
|
|---|
| 1543 | WHERE left_id > {$forum_data['right_id']}";
|
|---|
| 1544 | $db->sql_query($sql);
|
|---|
| 1545 |
|
|---|
| 1546 | // Delete forum ids from extension groups table
|
|---|
| 1547 | $sql = 'SELECT group_id, allowed_forums
|
|---|
| 1548 | FROM ' . EXTENSION_GROUPS_TABLE;
|
|---|
| 1549 | $result = $db->sql_query($sql);
|
|---|
| 1550 |
|
|---|
| 1551 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1552 | {
|
|---|
| 1553 | if (!$row['allowed_forums'])
|
|---|
| 1554 | {
|
|---|
| 1555 | continue;
|
|---|
| 1556 | }
|
|---|
| 1557 |
|
|---|
| 1558 | $allowed_forums = unserialize(trim($row['allowed_forums']));
|
|---|
| 1559 | $allowed_forums = array_diff($allowed_forums, $forum_ids);
|
|---|
| 1560 |
|
|---|
| 1561 | $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
|
|---|
| 1562 | SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
|
|---|
| 1563 | WHERE group_id = {$row['group_id']}";
|
|---|
| 1564 | $db->sql_query($sql);
|
|---|
| 1565 | }
|
|---|
| 1566 | $db->sql_freeresult($result);
|
|---|
| 1567 |
|
|---|
| 1568 | $cache->destroy('_extensions');
|
|---|
| 1569 |
|
|---|
| 1570 | $log_action = implode('_', array($log_action_posts, $log_action_forums));
|
|---|
| 1571 |
|
|---|
| 1572 | switch ($log_action)
|
|---|
| 1573 | {
|
|---|
| 1574 | case 'MOVE_POSTS_MOVE_FORUMS':
|
|---|
| 1575 | add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
|
|---|
| 1576 | break;
|
|---|
| 1577 |
|
|---|
| 1578 | case 'MOVE_POSTS_FORUMS':
|
|---|
| 1579 | add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
|
|---|
| 1580 | break;
|
|---|
| 1581 |
|
|---|
| 1582 | case 'POSTS_MOVE_FORUMS':
|
|---|
| 1583 | add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
|
|---|
| 1584 | break;
|
|---|
| 1585 |
|
|---|
| 1586 | case '_MOVE_FORUMS':
|
|---|
| 1587 | add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
|
|---|
| 1588 | break;
|
|---|
| 1589 |
|
|---|
| 1590 | case 'MOVE_POSTS_':
|
|---|
| 1591 | add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
|
|---|
| 1592 | break;
|
|---|
| 1593 |
|
|---|
| 1594 | case 'POSTS_FORUMS':
|
|---|
| 1595 | add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
|
|---|
| 1596 | break;
|
|---|
| 1597 |
|
|---|
| 1598 | case '_FORUMS':
|
|---|
| 1599 | add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
|
|---|
| 1600 | break;
|
|---|
| 1601 |
|
|---|
| 1602 | case 'POSTS_':
|
|---|
| 1603 | add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
|
|---|
| 1604 | break;
|
|---|
| 1605 |
|
|---|
| 1606 | default:
|
|---|
| 1607 | add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
|
|---|
| 1608 | break;
|
|---|
| 1609 | }
|
|---|
| 1610 |
|
|---|
| 1611 | return $errors;
|
|---|
| 1612 | }
|
|---|
| 1613 |
|
|---|
| 1614 | /**
|
|---|
| 1615 | * Delete forum content
|
|---|
| 1616 | */
|
|---|
| 1617 | function delete_forum_content($forum_id)
|
|---|
| 1618 | {
|
|---|
| 1619 | global $db, $config, $phpbb_root_path, $phpEx;
|
|---|
| 1620 |
|
|---|
| 1621 | include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
|
|---|
| 1622 |
|
|---|
| 1623 | $db->sql_transaction('begin');
|
|---|
| 1624 |
|
|---|
| 1625 | // Select then delete all attachments
|
|---|
| 1626 | $sql = 'SELECT a.topic_id
|
|---|
| 1627 | FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
|
|---|
| 1628 | WHERE p.forum_id = $forum_id
|
|---|
| 1629 | AND a.in_message = 0
|
|---|
| 1630 | AND a.topic_id = p.topic_id";
|
|---|
| 1631 | $result = $db->sql_query($sql);
|
|---|
| 1632 |
|
|---|
| 1633 | $topic_ids = array();
|
|---|
| 1634 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1635 | {
|
|---|
| 1636 | $topic_ids[] = $row['topic_id'];
|
|---|
| 1637 | }
|
|---|
| 1638 | $db->sql_freeresult($result);
|
|---|
| 1639 |
|
|---|
| 1640 | delete_attachments('topic', $topic_ids, false);
|
|---|
| 1641 |
|
|---|
| 1642 | // Before we remove anything we make sure we are able to adjust the post counts later. ;)
|
|---|
| 1643 | $sql = 'SELECT poster_id
|
|---|
| 1644 | FROM ' . POSTS_TABLE . '
|
|---|
| 1645 | WHERE forum_id = ' . $forum_id . '
|
|---|
| 1646 | AND post_postcount = 1
|
|---|
| 1647 | AND post_approved = 1';
|
|---|
| 1648 | $result = $db->sql_query($sql);
|
|---|
| 1649 |
|
|---|
| 1650 | $post_counts = array();
|
|---|
| 1651 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1652 | {
|
|---|
| 1653 | $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
|
|---|
| 1654 | }
|
|---|
| 1655 | $db->sql_freeresult($result);
|
|---|
| 1656 |
|
|---|
| 1657 | switch ($db->sql_layer)
|
|---|
| 1658 | {
|
|---|
| 1659 | case 'mysql4':
|
|---|
| 1660 | case 'mysqli':
|
|---|
| 1661 |
|
|---|
| 1662 | // Delete everything else and thank MySQL for offering multi-table deletion
|
|---|
| 1663 | $tables_ary = array(
|
|---|
| 1664 | SEARCH_WORDMATCH_TABLE => 'post_id',
|
|---|
| 1665 | REPORTS_TABLE => 'post_id',
|
|---|
| 1666 | WARNINGS_TABLE => 'post_id',
|
|---|
| 1667 | BOOKMARKS_TABLE => 'topic_id',
|
|---|
| 1668 | TOPICS_WATCH_TABLE => 'topic_id',
|
|---|
| 1669 | TOPICS_POSTED_TABLE => 'topic_id',
|
|---|
| 1670 | POLL_OPTIONS_TABLE => 'topic_id',
|
|---|
| 1671 | POLL_VOTES_TABLE => 'topic_id',
|
|---|
| 1672 | );
|
|---|
| 1673 |
|
|---|
| 1674 | $sql = 'DELETE ' . POSTS_TABLE;
|
|---|
| 1675 | $sql_using = "\nFROM " . POSTS_TABLE;
|
|---|
| 1676 | $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
|
|---|
| 1677 |
|
|---|
| 1678 | foreach ($tables_ary as $table => $field)
|
|---|
| 1679 | {
|
|---|
| 1680 | $sql .= ", $table ";
|
|---|
| 1681 | $sql_using .= ", $table ";
|
|---|
| 1682 | $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
|
|---|
| 1683 | }
|
|---|
| 1684 |
|
|---|
| 1685 | $db->sql_query($sql . $sql_using . $sql_where);
|
|---|
| 1686 |
|
|---|
| 1687 | break;
|
|---|
| 1688 |
|
|---|
| 1689 | default:
|
|---|
| 1690 |
|
|---|
| 1691 | // Delete everything else and curse your DB for not offering multi-table deletion
|
|---|
| 1692 | $tables_ary = array(
|
|---|
| 1693 | 'post_id' => array(
|
|---|
| 1694 | SEARCH_WORDMATCH_TABLE,
|
|---|
| 1695 | REPORTS_TABLE,
|
|---|
| 1696 | WARNINGS_TABLE,
|
|---|
| 1697 | ),
|
|---|
| 1698 |
|
|---|
| 1699 | 'topic_id' => array(
|
|---|
| 1700 | BOOKMARKS_TABLE,
|
|---|
| 1701 | TOPICS_WATCH_TABLE,
|
|---|
| 1702 | TOPICS_POSTED_TABLE,
|
|---|
| 1703 | POLL_OPTIONS_TABLE,
|
|---|
| 1704 | POLL_VOTES_TABLE,
|
|---|
| 1705 | )
|
|---|
| 1706 | );
|
|---|
| 1707 |
|
|---|
| 1708 | foreach ($tables_ary as $field => $tables)
|
|---|
| 1709 | {
|
|---|
| 1710 | $start = 0;
|
|---|
| 1711 |
|
|---|
| 1712 | do
|
|---|
| 1713 | {
|
|---|
| 1714 | $sql = "SELECT $field
|
|---|
| 1715 | FROM " . POSTS_TABLE . '
|
|---|
| 1716 | WHERE forum_id = ' . $forum_id;
|
|---|
| 1717 | $result = $db->sql_query_limit($sql, 500, $start);
|
|---|
| 1718 |
|
|---|
| 1719 | $ids = array();
|
|---|
| 1720 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1721 | {
|
|---|
| 1722 | $ids[] = $row[$field];
|
|---|
| 1723 | }
|
|---|
| 1724 | $db->sql_freeresult($result);
|
|---|
| 1725 |
|
|---|
| 1726 | if (sizeof($ids))
|
|---|
| 1727 | {
|
|---|
| 1728 | $start += sizeof($ids);
|
|---|
| 1729 |
|
|---|
| 1730 | foreach ($tables as $table)
|
|---|
| 1731 | {
|
|---|
| 1732 | $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
|
|---|
| 1733 | }
|
|---|
| 1734 | }
|
|---|
| 1735 | }
|
|---|
| 1736 | while ($row);
|
|---|
| 1737 | }
|
|---|
| 1738 | unset($ids);
|
|---|
| 1739 |
|
|---|
| 1740 | break;
|
|---|
| 1741 | }
|
|---|
| 1742 |
|
|---|
| 1743 | $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
|
|---|
| 1744 |
|
|---|
| 1745 | foreach ($table_ary as $table)
|
|---|
| 1746 | {
|
|---|
| 1747 | $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
|
|---|
| 1748 | }
|
|---|
| 1749 |
|
|---|
| 1750 | // Set forum ids to 0
|
|---|
| 1751 | $table_ary = array(DRAFTS_TABLE);
|
|---|
| 1752 |
|
|---|
| 1753 | foreach ($table_ary as $table)
|
|---|
| 1754 | {
|
|---|
| 1755 | $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
|
|---|
| 1756 | }
|
|---|
| 1757 |
|
|---|
| 1758 | // Adjust users post counts
|
|---|
| 1759 | if (sizeof($post_counts))
|
|---|
| 1760 | {
|
|---|
| 1761 | foreach ($post_counts as $poster_id => $substract)
|
|---|
| 1762 | {
|
|---|
| 1763 | $sql = 'UPDATE ' . USERS_TABLE . '
|
|---|
| 1764 | SET user_posts = 0
|
|---|
| 1765 | WHERE user_id = ' . $poster_id . '
|
|---|
| 1766 | AND user_posts < ' . $substract;
|
|---|
| 1767 | $db->sql_query($sql);
|
|---|
| 1768 |
|
|---|
| 1769 | $sql = 'UPDATE ' . USERS_TABLE . '
|
|---|
| 1770 | SET user_posts = user_posts - ' . $substract . '
|
|---|
| 1771 | WHERE user_id = ' . $poster_id . '
|
|---|
| 1772 | AND user_posts >= ' . $substract;
|
|---|
| 1773 | $db->sql_query($sql);
|
|---|
| 1774 | }
|
|---|
| 1775 | }
|
|---|
| 1776 |
|
|---|
| 1777 | $db->sql_transaction('commit');
|
|---|
| 1778 |
|
|---|
| 1779 | // Make sure the overall post/topic count is correct...
|
|---|
| 1780 | $sql = 'SELECT COUNT(post_id) AS stat
|
|---|
| 1781 | FROM ' . POSTS_TABLE . '
|
|---|
| 1782 | WHERE post_approved = 1';
|
|---|
| 1783 | $result = $db->sql_query($sql);
|
|---|
| 1784 | $row = $db->sql_fetchrow($result);
|
|---|
| 1785 | $db->sql_freeresult($result);
|
|---|
| 1786 |
|
|---|
| 1787 | set_config('num_posts', (int) $row['stat'], true);
|
|---|
| 1788 |
|
|---|
| 1789 | $sql = 'SELECT COUNT(topic_id) AS stat
|
|---|
| 1790 | FROM ' . TOPICS_TABLE . '
|
|---|
| 1791 | WHERE topic_approved = 1';
|
|---|
| 1792 | $result = $db->sql_query($sql);
|
|---|
| 1793 | $row = $db->sql_fetchrow($result);
|
|---|
| 1794 | $db->sql_freeresult($result);
|
|---|
| 1795 |
|
|---|
| 1796 | set_config('num_topics', (int) $row['stat'], true);
|
|---|
| 1797 |
|
|---|
| 1798 | $sql = 'SELECT COUNT(attach_id) 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('num_files', (int) $row['stat'], true);
|
|---|
| 1805 |
|
|---|
| 1806 | $sql = 'SELECT SUM(filesize) as stat
|
|---|
| 1807 | FROM ' . ATTACHMENTS_TABLE;
|
|---|
| 1808 | $result = $db->sql_query($sql);
|
|---|
| 1809 | $row = $db->sql_fetchrow($result);
|
|---|
| 1810 | $db->sql_freeresult($result);
|
|---|
| 1811 |
|
|---|
| 1812 | set_config('upload_dir_size', (float) $row['stat'], true);
|
|---|
| 1813 |
|
|---|
| 1814 | return array();
|
|---|
| 1815 | }
|
|---|
| 1816 |
|
|---|
| 1817 | /**
|
|---|
| 1818 | * Move forum position by $steps up/down
|
|---|
| 1819 | */
|
|---|
| 1820 | function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
|
|---|
| 1821 | {
|
|---|
| 1822 | global $db;
|
|---|
| 1823 |
|
|---|
| 1824 | /**
|
|---|
| 1825 | * Fetch all the siblings between the module's current spot
|
|---|
| 1826 | * and where we want to move it to. If there are less than $steps
|
|---|
| 1827 | * siblings between the current spot and the target then the
|
|---|
| 1828 | * module will move as far as possible
|
|---|
| 1829 | */
|
|---|
| 1830 | $sql = 'SELECT forum_id, forum_name, left_id, right_id
|
|---|
| 1831 | FROM ' . FORUMS_TABLE . "
|
|---|
| 1832 | WHERE parent_id = {$forum_row['parent_id']}
|
|---|
| 1833 | 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");
|
|---|
| 1834 | $result = $db->sql_query_limit($sql, $steps);
|
|---|
| 1835 |
|
|---|
| 1836 | $target = array();
|
|---|
| 1837 | while ($row = $db->sql_fetchrow($result))
|
|---|
| 1838 | {
|
|---|
| 1839 | $target = $row;
|
|---|
| 1840 | }
|
|---|
| 1841 | $db->sql_freeresult($result);
|
|---|
| 1842 |
|
|---|
| 1843 | if (!sizeof($target))
|
|---|
| 1844 | {
|
|---|
| 1845 | // The forum is already on top or bottom
|
|---|
| 1846 | return false;
|
|---|
| 1847 | }
|
|---|
| 1848 |
|
|---|
| 1849 | /**
|
|---|
| 1850 | * $left_id and $right_id define the scope of the nodes that are affected by the move.
|
|---|
| 1851 | * $diff_up and $diff_down are the values to substract or add to each node's left_id
|
|---|
| 1852 | * and right_id in order to move them up or down.
|
|---|
| 1853 | * $move_up_left and $move_up_right define the scope of the nodes that are moving
|
|---|
| 1854 | * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
|
|---|
| 1855 | */
|
|---|
| 1856 | if ($action == 'move_up')
|
|---|
| 1857 | {
|
|---|
| 1858 | $left_id = $target['left_id'];
|
|---|
| 1859 | $right_id = $forum_row['right_id'];
|
|---|
| 1860 |
|
|---|
| 1861 | $diff_up = $forum_row['left_id'] - $target['left_id'];
|
|---|
| 1862 | $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
|
|---|
| 1863 |
|
|---|
| 1864 | $move_up_left = $forum_row['left_id'];
|
|---|
| 1865 | $move_up_right = $forum_row['right_id'];
|
|---|
| 1866 | }
|
|---|
| 1867 | else
|
|---|
| 1868 | {
|
|---|
| 1869 | $left_id = $forum_row['left_id'];
|
|---|
| 1870 | $right_id = $target['right_id'];
|
|---|
| 1871 |
|
|---|
| 1872 | $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
|
|---|
| 1873 | $diff_down = $target['right_id'] - $forum_row['right_id'];
|
|---|
| 1874 |
|
|---|
| 1875 | $move_up_left = $forum_row['right_id'] + 1;
|
|---|
| 1876 | $move_up_right = $target['right_id'];
|
|---|
| 1877 | }
|
|---|
| 1878 |
|
|---|
| 1879 | // Now do the dirty job
|
|---|
| 1880 | $sql = 'UPDATE ' . FORUMS_TABLE . "
|
|---|
| 1881 | SET left_id = left_id + CASE
|
|---|
| 1882 | WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
|
|---|
| 1883 | ELSE {$diff_down}
|
|---|
| 1884 | END,
|
|---|
| 1885 | right_id = right_id + CASE
|
|---|
| 1886 | WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
|
|---|
| 1887 | ELSE {$diff_down}
|
|---|
| 1888 | END,
|
|---|
| 1889 | forum_parents = ''
|
|---|
| 1890 | WHERE
|
|---|
| 1891 | left_id BETWEEN {$left_id} AND {$right_id}
|
|---|
| 1892 | AND right_id BETWEEN {$left_id} AND {$right_id}";
|
|---|
| 1893 | $db->sql_query($sql);
|
|---|
| 1894 |
|
|---|
| 1895 | return $target['forum_name'];
|
|---|
| 1896 | }
|
|---|
| 1897 |
|
|---|
| 1898 | /**
|
|---|
| 1899 | * Display progress bar for syncinc forums
|
|---|
| 1900 | */
|
|---|
| 1901 | function display_progress_bar($start, $total)
|
|---|
| 1902 | {
|
|---|
| 1903 | global $template, $user;
|
|---|
| 1904 |
|
|---|
| 1905 | adm_page_header($user->lang['SYNC_IN_PROGRESS']);
|
|---|
| 1906 |
|
|---|
| 1907 | $template->set_filenames(array(
|
|---|
| 1908 | 'body' => 'progress_bar.html')
|
|---|
| 1909 | );
|
|---|
| 1910 |
|
|---|
| 1911 | $template->assign_vars(array(
|
|---|
| 1912 | 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
|
|---|
| 1913 | 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
|
|---|
| 1914 | );
|
|---|
| 1915 |
|
|---|
| 1916 | adm_page_footer();
|
|---|
| 1917 | }
|
|---|
| 1918 |
|
|---|
| 1919 | /**
|
|---|
| 1920 | * Display copy permission page
|
|---|
| 1921 | * Not used at the moment - we will have a look at it for 3.0.7
|
|---|
| 1922 | */
|
|---|
| 1923 | function copy_permission_page($forum_data)
|
|---|
| 1924 | {
|
|---|
| 1925 | global $phpEx, $phpbb_admin_path, $template, $user;
|
|---|
| 1926 |
|
|---|
| 1927 | $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
|
|---|
| 1928 | $action = append_sid($this->u_action . "&parent_id={$this->parent_id}&f={$forum_data['forum_id']}&action=copy_perm");
|
|---|
| 1929 |
|
|---|
| 1930 | $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
|
|---|
| 1931 |
|
|---|
| 1932 | $this->tpl_name = 'acp_forums_copy_perm';
|
|---|
| 1933 |
|
|---|
| 1934 | $template->assign_vars(array(
|
|---|
| 1935 | 'U_ACL' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
|
|---|
| 1936 | 'L_ACL_LINK' => $l_acl,
|
|---|
| 1937 | 'L_BACK_LINK' => adm_back_link($this->u_action . '&parent_id=' . $this->parent_id),
|
|---|
| 1938 | 'S_COPY_ACTION' => $action,
|
|---|
| 1939 | 'S_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),
|
|---|
| 1940 | ));
|
|---|
| 1941 | }
|
|---|
| 1942 |
|
|---|
| 1943 | }
|
|---|
| 1944 |
|
|---|
| 1945 | ?>
|
|---|