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