6 * @copyright (c) 2005 phpBB Group
7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
14 if (!defined('IN_PHPBB'))
27 function main($id, $mode)
29 global $db, $user, $auth, $template, $cache;
30 global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx;
32 $user->add_lang('acp/forums');
33 $this->tpl_name = 'acp_forums';
34 $this->page_title = 'ACP_MANAGE_FORUMS';
36 $form_key = 'acp_forums';
37 add_form_key($form_key);
39 $action = request_var('action', '');
40 $update = (isset($_POST['update'])) ? true : false;
41 $forum_id = request_var('f', 0);
43 $this->parent_id = request_var('parent_id', 0);
44 $forum_data = $errors = array();
45 if ($update && !check_form_key($form_key))
48 $errors[] = $user->lang['FORM_INVALID'];
51 // Check additional permissions
55 $start = request_var('start', 0);
56 $total = request_var('total', 0);
58 $this->display_progress_bar($start, $total);
64 if (!$auth->acl_get('a_forumdel'))
66 trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
73 if (!$auth->acl_get('a_forumadd'))
75 trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
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);
92 $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id);
99 $auth->acl_clear_prefetch();
100 $cache->destroy('sql', FORUMS_TABLE);
102 trigger_error($user->lang['FORUM_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
108 'forum_id' => $forum_id
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),
154 // On add, add empty forum_options... else do not consider it (not updating it)
155 if ($action == 'add')
157 $forum_data['forum_options'] = 0;
160 // Use link_display_on_index setting if forum type is link
161 if ($forum_data['forum_type'] == FORUM_LINK)
163 $forum_data['display_on_index'] = request_var('link_display_on_index', false);
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)
169 $forum_data['forum_status'] = ITEM_UNLOCKED;
172 $forum_data['show_active'] = ($forum_data['forum_type'] == FORUM_POST) ? request_var('display_recent', true) : request_var('display_active', false);
174 // Get data for forum rules if specified...
175 if ($forum_data['forum_rules'])
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));
180 // Get data for forum description if specified
181 if ($forum_data['forum_desc'])
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));
186 $errors = $this->update_forum_data($forum_data);
188 if (!sizeof($errors))
190 $forum_perm_from = request_var('forum_perm_from', 0);
191 $cache->destroy('sql', FORUMS_TABLE);
193 $copied_permissions = false;
195 if ($forum_perm_from && $forum_perm_from != $forum_data['forum_id'] &&
196 ($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'))))
198 copy_forum_permissions($forum_perm_from, $forum_data['forum_id'], ($action == 'edit') ? true : false);
200 $copied_permissions = true;
202 /* Commented out because of questionable UI workflow - re-visit for 3.0.7
203 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'))
205 $this->copy_permission_page($forum_data);
209 $auth->acl_clear_prefetch();
211 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
213 $message = ($action == 'add') ? $user->lang['FORUM_CREATED'] : $user->lang['FORUM_UPDATED'];
215 // redirect directly to permission settings screen if authed
216 if ($action == 'add' && !$copied_permissions && $auth->acl_get('a_fauth'))
218 $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
220 meta_refresh(4, append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url));
223 trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
237 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
241 FROM ' . FORUMS_TABLE . "
242 WHERE forum_id = $forum_id";
243 $result = $db->sql_query($sql);
244 $row = $db->sql_fetchrow($result);
245 $db->sql_freeresult($result);
249 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
252 $move_forum_name = $this->move_forum_by($row, $action, 1);
254 if ($move_forum_name !== false)
256 add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name);
257 $cache->destroy('sql', FORUMS_TABLE);
265 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
270 $sql = 'SELECT forum_name, forum_topics_real
271 FROM ' . FORUMS_TABLE . "
272 WHERE forum_id = $forum_id";
273 $result = $db->sql_query($sql);
274 $row = $db->sql_fetchrow($result);
275 $db->sql_freeresult($result);
279 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
282 if ($row['forum_topics_real'])
284 $sql = 'SELECT MIN(topic_id) as min_topic_id, MAX(topic_id) as max_topic_id
285 FROM ' . TOPICS_TABLE . '
286 WHERE forum_id = ' . $forum_id;
287 $result = $db->sql_query($sql);
288 $row2 = $db->sql_fetchrow($result);
289 $db->sql_freeresult($result);
291 // Typecast to int if there is no data available
292 $row2['min_topic_id'] = (int) $row2['min_topic_id'];
293 $row2['max_topic_id'] = (int) $row2['max_topic_id'];
295 $start = request_var('start', $row2['min_topic_id']);
298 $end = $start + $batch_size;
300 // Sync all topics in batch mode...
301 sync('topic_approved', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, false);
302 sync('topic', 'range', 'topic_id BETWEEN ' . $start . ' AND ' . $end, true, true);
304 if ($end < $row2['max_topic_id'])
306 // We really need to find a way of showing statistics... no progress here
307 $sql = 'SELECT COUNT(topic_id) as num_topics
308 FROM ' . TOPICS_TABLE . '
309 WHERE forum_id = ' . $forum_id . '
310 AND topic_id BETWEEN ' . $start . ' AND ' . $end;
311 $result = $db->sql_query($sql);
312 $topics_done = request_var('topics_done', 0) + (int) $db->sql_fetchfield('num_topics');
313 $db->sql_freeresult($result);
315 $start += $batch_size;
317 $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']}";
319 meta_refresh(0, $url);
321 $template->assign_vars(array(
322 'U_PROGRESS_BAR' => $this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}",
323 'UA_PROGRESS_BAR' => addslashes($this->u_action . "&action=progress_bar&start=$topics_done&total={$row['forum_topics_real']}"),
324 'S_CONTINUE_SYNC' => true,
325 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $topics_done, $row['forum_topics_real']))
332 $url = $this->u_action . "&parent_id={$this->parent_id}&f=$forum_id&action=sync_forum";
333 meta_refresh(0, $url);
335 $template->assign_vars(array(
336 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
337 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
338 'S_CONTINUE_SYNC' => true,
339 'L_PROGRESS_EXPLAIN' => sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], 0, $row['forum_topics_real']))
348 $sql = 'SELECT forum_name, forum_type
349 FROM ' . FORUMS_TABLE . "
350 WHERE forum_id = $forum_id";
351 $result = $db->sql_query($sql);
352 $row = $db->sql_fetchrow($result);
353 $db->sql_freeresult($result);
357 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
360 sync('forum', 'forum_id', $forum_id, false, true);
362 add_log('admin', 'LOG_FORUM_SYNC', $row['forum_name']);
363 $cache->destroy('sql', FORUMS_TABLE);
365 $template->assign_var('L_FORUM_RESYNCED', sprintf($user->lang['FORUM_RESYNCED'], $row['forum_name']));
374 $forum_data['forum_flags'] = 0;
375 $forum_data['forum_flags'] += (request_var('forum_link_track', false)) ? FORUM_FLAG_LINK_TRACK : 0;
376 $forum_data['forum_flags'] += (request_var('prune_old_polls', false)) ? FORUM_FLAG_PRUNE_POLL : 0;
377 $forum_data['forum_flags'] += (request_var('prune_announce', false)) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
378 $forum_data['forum_flags'] += (request_var('prune_sticky', false)) ? FORUM_FLAG_PRUNE_STICKY : 0;
379 $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
380 $forum_data['forum_flags'] += (request_var('enable_post_review', true)) ? FORUM_FLAG_POST_REVIEW : 0;
381 $forum_data['forum_flags'] += (request_var('enable_quick_reply', false)) ? FORUM_FLAG_QUICK_REPLY : 0;
384 // Show form to create/modify a forum
385 if ($action == 'edit')
387 $this->page_title = 'EDIT_FORUM';
388 $row = $this->get_forum_info($forum_id);
389 $old_forum_type = $row['forum_type'];
397 $forum_data['left_id'] = $row['left_id'];
398 $forum_data['right_id'] = $row['right_id'];
401 // Make sure no direct child forums are able to be selected as parents.
402 $exclude_forums = array();
403 foreach (get_forum_branch($forum_id, 'children') as $row)
405 $exclude_forums[] = $row['forum_id'];
408 $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false);
410 $forum_data['forum_password_confirm'] = $forum_data['forum_password'];
414 $this->page_title = 'CREATE_FORUM';
416 $forum_id = $this->parent_id;
417 $parents_list = make_forum_select($this->parent_id, false, false, false, false);
419 // Fill forum data with default values
423 'parent_id' => $this->parent_id,
424 'forum_type' => FORUM_POST,
425 'forum_status' => ITEM_UNLOCKED,
426 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)),
428 'forum_link_track' => false,
431 'forum_rules_link' => '',
434 'display_subforum_list' => true,
435 'display_on_index' => false,
436 'forum_topics_per_page' => 0,
437 'enable_indexing' => true,
438 'enable_icons' => false,
439 'enable_prune' => false,
443 'forum_flags' => FORUM_FLAG_POST_REVIEW + FORUM_FLAG_ACTIVE_TOPICS,
444 'forum_options' => 0,
445 'forum_password' => '',
446 'forum_password_confirm'=> '',
451 $forum_rules_data = array(
452 'text' => $forum_data['forum_rules'],
453 'allow_bbcode' => true,
454 'allow_smilies' => true,
458 $forum_desc_data = array(
459 'text' => $forum_data['forum_desc'],
460 'allow_bbcode' => true,
461 'allow_smilies' => true,
465 $forum_rules_preview = '';
467 // Parse rules if specified
468 if ($forum_data['forum_rules'])
470 if (!isset($forum_data['forum_rules_uid']))
472 // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
473 $forum_data['forum_rules_uid'] = '';
474 $forum_data['forum_rules_bitfield'] = '';
475 $forum_data['forum_rules_options'] = 0;
477 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 // Generate preview content
481 $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 $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']);
487 // Parse desciption if specified
488 if ($forum_data['forum_desc'])
490 if (!isset($forum_data['forum_desc_uid']))
492 // Before we are able to display the preview and plane text, we need to parse our request_var()'d value...
493 $forum_data['forum_desc_uid'] = '';
494 $forum_data['forum_desc_bitfield'] = '';
495 $forum_data['forum_desc_options'] = 0;
497 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));
501 $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']);
504 $forum_type_options = '';
505 $forum_type_ary = array(FORUM_CAT => 'CAT', FORUM_POST => 'FORUM', FORUM_LINK => 'LINK');
507 foreach ($forum_type_ary as $value => $lang)
509 $forum_type_options .= '<option value="' . $value . '"' . (($value == $forum_data['forum_type']) ? ' selected="selected"' : '') . '>' . $user->lang['TYPE_' . $lang] . '</option>';
512 $styles_list = style_select($forum_data['forum_style'], true);
514 $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>';
516 $sql = 'SELECT forum_id
517 FROM ' . FORUMS_TABLE . '
518 WHERE forum_type = ' . FORUM_POST . "
519 AND forum_id <> $forum_id";
520 $result = $db->sql_query_limit($sql, 1);
522 $postable_forum_exists = false;
523 if ($db->sql_fetchrow($result))
525 $postable_forum_exists = true;
527 $db->sql_freeresult($result);
529 // Subforum move options
530 if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT)
532 $subforums_id = array();
533 $subforums = get_forum_branch($forum_id, 'children');
535 foreach ($subforums as $row)
537 $subforums_id[] = $row['forum_id'];
540 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
542 if ($postable_forum_exists)
544 $template->assign_vars(array(
545 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id)) // , false, true, false???
549 $template->assign_vars(array(
550 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
551 'S_FORUMS_LIST' => $forums_list)
554 else if ($postable_forum_exists)
556 $template->assign_vars(array(
557 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))
561 $s_show_display_on_index = false;
563 if ($forum_data['parent_id'] > 0)
565 // if this forum is a subforum put the "display on index" checkbox
566 if ($parent_info = $this->get_forum_info($forum_data['parent_id']))
568 if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT)
570 $s_show_display_on_index = true;
575 if (strlen($forum_data['forum_password']) == 32)
577 $errors[] = $user->lang['FORUM_PASSWORD_OLD'];
580 $template->assign_vars(array(
581 'S_EDIT_FORUM' => true,
582 'S_ERROR' => (sizeof($errors)) ? true : false,
583 'S_PARENT_ID' => $this->parent_id,
584 'S_FORUM_PARENT_ID' => $forum_data['parent_id'],
585 'S_ADD_ACTION' => ($action == 'add') ? true : false,
587 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
588 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action=$action&f=$forum_id",
590 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'],
591 'L_TITLE' => $user->lang[$this->page_title],
592 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
594 'FORUM_NAME' => $forum_data['forum_name'],
595 'FORUM_DATA_LINK' => $forum_data['forum_link'],
596 'FORUM_IMAGE' => $forum_data['forum_image'],
597 'FORUM_IMAGE_SRC' => ($forum_data['forum_image']) ? $phpbb_root_path . $forum_data['forum_image'] : '',
598 'FORUM_POST' => FORUM_POST,
599 'FORUM_LINK' => FORUM_LINK,
600 'FORUM_CAT' => FORUM_CAT,
601 'PRUNE_FREQ' => $forum_data['prune_freq'],
602 'PRUNE_DAYS' => $forum_data['prune_days'],
603 'PRUNE_VIEWED' => $forum_data['prune_viewed'],
604 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'],
605 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'],
606 'FORUM_RULES' => $forum_data['forum_rules'],
607 'FORUM_RULES_PREVIEW' => $forum_rules_preview,
608 'FORUM_RULES_PLAIN' => $forum_rules_data['text'],
609 'S_BBCODE_CHECKED' => ($forum_rules_data['allow_bbcode']) ? true : false,
610 'S_SMILIES_CHECKED' => ($forum_rules_data['allow_smilies']) ? true : false,
611 'S_URLS_CHECKED' => ($forum_rules_data['allow_urls']) ? true : false,
612 'S_FORUM_PASSWORD_SET' => (empty($forum_data['forum_password'])) ? false : true,
614 'FORUM_DESC' => $forum_desc_data['text'],
615 'S_DESC_BBCODE_CHECKED' => ($forum_desc_data['allow_bbcode']) ? true : false,
616 'S_DESC_SMILIES_CHECKED' => ($forum_desc_data['allow_smilies']) ? true : false,
617 'S_DESC_URLS_CHECKED' => ($forum_desc_data['allow_urls']) ? true : false,
619 'S_FORUM_TYPE_OPTIONS' => $forum_type_options,
620 'S_STATUS_OPTIONS' => $statuslist,
621 'S_PARENT_OPTIONS' => $parents_list,
622 'S_STYLES_OPTIONS' => $styles_list,
623 'S_FORUM_OPTIONS' => make_forum_select(($action == 'add') ? $forum_data['parent_id'] : false, ($action == 'edit') ? $forum_data['forum_id'] : false, false, false, false),
624 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index,
625 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
626 'S_FORUM_ORIG_POST' => (isset($old_forum_type) && $old_forum_type == FORUM_POST) ? true : false,
627 'S_FORUM_ORIG_CAT' => (isset($old_forum_type) && $old_forum_type == FORUM_CAT) ? true : false,
628 'S_FORUM_ORIG_LINK' => (isset($old_forum_type) && $old_forum_type == FORUM_LINK) ? true : false,
629 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
630 'S_FORUM_CAT' => ($forum_data['forum_type'] == FORUM_CAT) ? true : false,
631 'S_ENABLE_INDEXING' => ($forum_data['enable_indexing']) ? true : false,
632 'S_TOPIC_ICONS' => ($forum_data['enable_icons']) ? true : false,
633 'S_DISPLAY_SUBFORUM_LIST' => ($forum_data['display_subforum_list']) ? true : false,
634 'S_DISPLAY_ON_INDEX' => ($forum_data['display_on_index']) ? true : false,
635 'S_PRUNE_ENABLE' => ($forum_data['enable_prune']) ? true : false,
636 'S_FORUM_LINK_TRACK' => ($forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK) ? true : false,
637 'S_PRUNE_OLD_POLLS' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL) ? true : false,
638 'S_PRUNE_ANNOUNCE' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE) ? true : false,
639 'S_PRUNE_STICKY' => ($forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY) ? true : false,
640 'S_DISPLAY_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_POST) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : true,
641 'S_ENABLE_ACTIVE_TOPICS' => ($forum_data['forum_type'] == FORUM_CAT) ? ($forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS) : false,
642 'S_ENABLE_POST_REVIEW' => ($forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW) ? true : false,
643 'S_ENABLE_QUICK_REPLY' => ($forum_data['forum_flags'] & FORUM_FLAG_QUICK_REPLY) ? true : false,
644 '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,
655 trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
658 $forum_data = $this->get_forum_info($forum_id);
660 $subforums_id = array();
661 $subforums = get_forum_branch($forum_id, 'children');
663 foreach ($subforums as $row)
665 $subforums_id[] = $row['forum_id'];
668 $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id);
670 $sql = 'SELECT forum_id
671 FROM ' . FORUMS_TABLE . '
672 WHERE forum_type = ' . FORUM_POST . "
673 AND forum_id <> $forum_id";
674 $result = $db->sql_query_limit($sql, 1);
676 if ($db->sql_fetchrow($result))
678 $template->assign_vars(array(
679 'S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true)) // , false, true, false???
682 $db->sql_freeresult($result);
684 $parent_id = ($this->parent_id == $forum_id) ? 0 : $this->parent_id;
686 $template->assign_vars(array(
687 'S_DELETE_FORUM' => true,
688 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f=$forum_id",
689 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id,
691 'FORUM_NAME' => $forum_data['forum_name'],
692 'S_FORUM_POST' => ($forum_data['forum_type'] == FORUM_POST) ? true : false,
693 'S_FORUM_LINK' => ($forum_data['forum_type'] == FORUM_LINK) ? true : false,
694 'S_HAS_SUBFORUMS' => ($forum_data['right_id'] - $forum_data['left_id'] > 1) ? true : false,
695 'S_FORUMS_LIST' => $forums_list,
696 'S_ERROR' => (sizeof($errors)) ? true : false,
697 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '')
704 $forum_perm_from = request_var('forum_perm_from', 0);
707 if (!empty($forum_perm_from) && $forum_perm_from != $forum_id)
709 copy_forum_permissions($forum_perm_from, $forum_id, true);
711 $auth->acl_clear_prefetch();
712 $cache->destroy('sql', FORUMS_TABLE);
714 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_id;
716 $message = $user->lang['FORUM_UPDATED'];
718 // Redirect to permissions
719 if ($auth->acl_get('a_fauth'))
721 $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
724 trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id));
730 // Default management page
731 if (!$this->parent_id)
733 $navigation = $user->lang['FORUM_INDEX'];
737 $navigation = '<a href="' . $this->u_action . '">' . $user->lang['FORUM_INDEX'] . '</a>';
739 $forums_nav = get_forum_branch($this->parent_id, 'parents', 'descending');
740 foreach ($forums_nav as $row)
742 if ($row['forum_id'] == $this->parent_id)
744 $navigation .= ' -> ' . $row['forum_name'];
748 $navigation .= ' -> <a href="' . $this->u_action . '&parent_id=' . $row['forum_id'] . '">' . $row['forum_name'] . '</a>';
754 $forum_box = make_forum_select($this->parent_id, false, false, false, false); //make_forum_select($this->parent_id);
756 if ($action == 'sync' || $action == 'sync_forum')
758 $template->assign_var('S_RESYNCED', true);
762 FROM ' . FORUMS_TABLE . "
763 WHERE parent_id = $this->parent_id
765 $result = $db->sql_query($sql);
767 if ($row = $db->sql_fetchrow($result))
771 $forum_type = $row['forum_type'];
773 if ($row['forum_status'] == ITEM_LOCKED)
775 $folder_image = '<img src="images/icon_folder_lock.gif" alt="' . $user->lang['LOCKED'] . '" />';
782 $folder_image = '<img src="images/icon_folder_link.gif" alt="' . $user->lang['LINK'] . '" />';
786 $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'] . '" />';
791 $url = $this->u_action . "&parent_id=$this->parent_id&f={$row['forum_id']}";
793 $template->assign_block_vars('forums', array(
794 'FOLDER_IMAGE' => $folder_image,
795 'FORUM_IMAGE' => ($row['forum_image']) ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '',
796 'FORUM_IMAGE_SRC' => ($row['forum_image']) ? $phpbb_root_path . $row['forum_image'] : '',
797 'FORUM_NAME' => $row['forum_name'],
798 'FORUM_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']),
799 'FORUM_TOPICS' => $row['forum_topics'],
800 'FORUM_POSTS' => $row['forum_posts'],
802 'S_FORUM_LINK' => ($forum_type == FORUM_LINK) ? true : false,
803 'S_FORUM_POST' => ($forum_type == FORUM_POST) ? true : false,
805 'U_FORUM' => $this->u_action . '&parent_id=' . $row['forum_id'],
806 'U_MOVE_UP' => $url . '&action=move_up',
807 'U_MOVE_DOWN' => $url . '&action=move_down',
808 'U_EDIT' => $url . '&action=edit',
809 'U_DELETE' => $url . '&action=delete',
810 'U_SYNC' => $url . '&action=sync')
813 while ($row = $db->sql_fetchrow($result));
815 else if ($this->parent_id)
817 $row = $this->get_forum_info($this->parent_id);
819 $url = $this->u_action . '&parent_id=' . $this->parent_id . '&f=' . $row['forum_id'];
821 $template->assign_vars(array(
822 'S_NO_FORUMS' => true,
824 'U_EDIT' => $url . '&action=edit',
825 'U_DELETE' => $url . '&action=delete',
826 'U_SYNC' => $url . '&action=sync')
829 $db->sql_freeresult($result);
831 $template->assign_vars(array(
832 'ERROR_MSG' => (sizeof($errors)) ? implode('<br />', $errors) : '',
833 'NAVIGATION' => $navigation,
834 'FORUM_BOX' => $forum_box,
835 'U_SEL_ACTION' => $this->u_action,
836 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id,
838 'U_PROGRESS_BAR' => $this->u_action . '&action=progress_bar',
839 'UA_PROGRESS_BAR' => addslashes($this->u_action . '&action=progress_bar'),
846 function get_forum_info($forum_id)
851 FROM ' . FORUMS_TABLE . "
852 WHERE forum_id = $forum_id";
853 $result = $db->sql_query($sql);
854 $row = $db->sql_fetchrow($result);
855 $db->sql_freeresult($result);
859 trigger_error("Forum #$forum_id does not exist", E_USER_ERROR);
868 function update_forum_data(&$forum_data)
870 global $db, $user, $cache, $phpbb_root_path;
874 if ($forum_data['forum_name'] == '')
876 $errors[] = $user->lang['FORUM_NAME_EMPTY'];
879 if (utf8_strlen($forum_data['forum_desc']) > 4000)
881 $errors[] = $user->lang['FORUM_DESC_TOO_LONG'];
884 if (utf8_strlen($forum_data['forum_rules']) > 4000)
886 $errors[] = $user->lang['FORUM_RULES_TOO_LONG'];
889 if ($forum_data['forum_password'] || $forum_data['forum_password_confirm'])
891 if ($forum_data['forum_password'] != $forum_data['forum_password_confirm'])
893 $forum_data['forum_password'] = $forum_data['forum_password_confirm'] = '';
894 $errors[] = $user->lang['FORUM_PASSWORD_MISMATCH'];
898 if ($forum_data['prune_days'] < 0 || $forum_data['prune_viewed'] < 0 || $forum_data['prune_freq'] < 0)
900 $forum_data['prune_days'] = $forum_data['prune_viewed'] = $forum_data['prune_freq'] = 0;
901 $errors[] = $user->lang['FORUM_DATA_NEGATIVE'];
904 $range_test_ary = array(
905 array('lang' => 'FORUM_TOPICS_PAGE', 'value' => $forum_data['forum_topics_per_page'], 'column_type' => 'TINT:0'),
908 if (!empty($forum_data['forum_image']) && !file_exists($phpbb_root_path . $forum_data['forum_image']))
910 $errors[] = $user->lang['FORUM_IMAGE_NO_EXIST'];
913 validate_range($range_test_ary, $errors);
917 // 2 = prune old polls
918 // 4 = prune announcements
919 // 8 = prune stickies
920 // 16 = show active topics
921 // 32 = enable post review
922 $forum_data['forum_flags'] = 0;
923 $forum_data['forum_flags'] += ($forum_data['forum_link_track']) ? FORUM_FLAG_LINK_TRACK : 0;
924 $forum_data['forum_flags'] += ($forum_data['prune_old_polls']) ? FORUM_FLAG_PRUNE_POLL : 0;
925 $forum_data['forum_flags'] += ($forum_data['prune_announce']) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0;
926 $forum_data['forum_flags'] += ($forum_data['prune_sticky']) ? FORUM_FLAG_PRUNE_STICKY : 0;
927 $forum_data['forum_flags'] += ($forum_data['show_active']) ? FORUM_FLAG_ACTIVE_TOPICS : 0;
928 $forum_data['forum_flags'] += ($forum_data['enable_post_review']) ? FORUM_FLAG_POST_REVIEW : 0;
929 $forum_data['forum_flags'] += ($forum_data['enable_quick_reply']) ? FORUM_FLAG_QUICK_REPLY : 0;
931 // Unset data that are not database fields
932 $forum_data_sql = $forum_data;
934 unset($forum_data_sql['forum_link_track']);
935 unset($forum_data_sql['prune_old_polls']);
936 unset($forum_data_sql['prune_announce']);
937 unset($forum_data_sql['prune_sticky']);
938 unset($forum_data_sql['show_active']);
939 unset($forum_data_sql['enable_post_review']);
940 unset($forum_data_sql['enable_quick_reply']);
941 unset($forum_data_sql['forum_password_confirm']);
943 // What are we going to do tonight Brain? The same thing we do everynight,
944 // try to take over the world ... or decide whether to continue update
945 // and if so, whether it's a new forum/cat/link or an existing one
951 // As we don't know the old password, it's kinda tricky to detect changes
952 if ($forum_data_sql['forum_password_unset'])
954 $forum_data_sql['forum_password'] = '';
956 else if (empty($forum_data_sql['forum_password']))
958 unset($forum_data_sql['forum_password']);
962 $forum_data_sql['forum_password'] = phpbb_hash($forum_data_sql['forum_password']);
964 unset($forum_data_sql['forum_password_unset']);
966 if (!isset($forum_data_sql['forum_id']))
968 // no forum_id means we're creating a new forum
969 unset($forum_data_sql['type_action']);
971 if ($forum_data_sql['parent_id'])
973 $sql = 'SELECT left_id, right_id, forum_type
974 FROM ' . FORUMS_TABLE . '
975 WHERE forum_id = ' . $forum_data_sql['parent_id'];
976 $result = $db->sql_query($sql);
977 $row = $db->sql_fetchrow($result);
978 $db->sql_freeresult($result);
982 trigger_error($user->lang['PARENT_NOT_EXIST'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING);
985 if ($row['forum_type'] == FORUM_LINK)
987 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
991 $sql = 'UPDATE ' . FORUMS_TABLE . '
992 SET left_id = left_id + 2, right_id = right_id + 2
993 WHERE left_id > ' . $row['right_id'];
994 $db->sql_query($sql);
996 $sql = 'UPDATE ' . FORUMS_TABLE . '
997 SET right_id = right_id + 2
998 WHERE ' . $row['left_id'] . ' BETWEEN left_id AND right_id';
999 $db->sql_query($sql);
1001 $forum_data_sql['left_id'] = $row['right_id'];
1002 $forum_data_sql['right_id'] = $row['right_id'] + 1;
1006 $sql = 'SELECT MAX(right_id) AS right_id
1007 FROM ' . FORUMS_TABLE;
1008 $result = $db->sql_query($sql);
1009 $row = $db->sql_fetchrow($result);
1010 $db->sql_freeresult($result);
1012 $forum_data_sql['left_id'] = $row['right_id'] + 1;
1013 $forum_data_sql['right_id'] = $row['right_id'] + 2;
1016 $sql = 'INSERT INTO ' . FORUMS_TABLE . ' ' . $db->sql_build_array('INSERT', $forum_data_sql);
1017 $db->sql_query($sql);
1019 $forum_data['forum_id'] = $db->sql_nextid();
1021 add_log('admin', 'LOG_FORUM_ADD', $forum_data['forum_name']);
1025 $row = $this->get_forum_info($forum_data_sql['forum_id']);
1027 if ($row['forum_type'] == FORUM_POST && $row['forum_type'] != $forum_data_sql['forum_type'])
1029 // Has subforums and want to change into a link?
1030 if ($row['right_id'] - $row['left_id'] > 1 && $forum_data_sql['forum_type'] == FORUM_LINK)
1032 $errors[] = $user->lang['FORUM_WITH_SUBFORUMS_NOT_TO_LINK'];
1036 // we're turning a postable forum into a non-postable forum
1037 if ($forum_data_sql['type_action'] == 'move')
1039 $to_forum_id = request_var('to_forum_id', 0);
1043 $errors = $this->move_forum_content($forum_data_sql['forum_id'], $to_forum_id);
1047 return array($user->lang['NO_DESTINATION_FORUM']);
1050 else if ($forum_data_sql['type_action'] == 'delete')
1052 $errors = $this->delete_forum_content($forum_data_sql['forum_id']);
1056 return array($user->lang['NO_FORUM_ACTION']);
1059 $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;
1060 $forum_data_sql['forum_last_poster_name'] = $forum_data_sql['forum_last_poster_colour'] = '';
1062 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_LINK)
1065 if ($row['right_id'] - $row['left_id'] > 1)
1067 // We are turning a category into a link - but need to decide what to do with the subforums.
1068 $action_subforums = request_var('action_subforums', '');
1069 $subforums_to_id = request_var('subforums_to_id', 0);
1071 if ($action_subforums == 'delete')
1073 $rows = get_forum_branch($row['forum_id'], 'children', 'descending', false);
1075 foreach ($rows as $_row)
1077 // Do not remove the forum id we are about to change. ;)
1078 if ($_row['forum_id'] == $row['forum_id'])
1083 $forum_ids[] = $_row['forum_id'];
1084 $errors = array_merge($errors, $this->delete_forum_content($_row['forum_id']));
1087 if (sizeof($errors))
1092 if (sizeof($forum_ids))
1094 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1095 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1096 $db->sql_query($sql);
1098 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1099 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1100 $db->sql_query($sql);
1102 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1103 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1104 $db->sql_query($sql);
1106 // Delete forum ids from extension groups table
1107 $sql = 'SELECT group_id, allowed_forums
1108 FROM ' . EXTENSION_GROUPS_TABLE;
1109 $result = $db->sql_query($sql);
1111 while ($_row = $db->sql_fetchrow($result))
1113 if (!$_row['allowed_forums'])
1118 $allowed_forums = unserialize(trim($_row['allowed_forums']));
1119 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1121 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1122 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1123 WHERE group_id = {$_row['group_id']}";
1124 $db->sql_query($sql);
1126 $db->sql_freeresult($result);
1128 $cache->destroy('_extensions');
1131 else if ($action_subforums == 'move')
1133 if (!$subforums_to_id)
1135 return array($user->lang['NO_DESTINATION_FORUM']);
1138 $sql = 'SELECT forum_name
1139 FROM ' . FORUMS_TABLE . '
1140 WHERE forum_id = ' . $subforums_to_id;
1141 $result = $db->sql_query($sql);
1142 $_row = $db->sql_fetchrow($result);
1143 $db->sql_freeresult($result);
1147 return array($user->lang['NO_FORUM']);
1150 $subforums_to_name = $_row['forum_name'];
1152 $sql = 'SELECT forum_id
1153 FROM ' . FORUMS_TABLE . "
1154 WHERE parent_id = {$row['forum_id']}";
1155 $result = $db->sql_query($sql);
1157 while ($_row = $db->sql_fetchrow($result))
1159 $this->move_forum($_row['forum_id'], $subforums_to_id);
1161 $db->sql_freeresult($result);
1163 $sql = 'UPDATE ' . FORUMS_TABLE . "
1164 SET parent_id = $subforums_to_id
1165 WHERE parent_id = {$row['forum_id']}";
1166 $db->sql_query($sql);
1169 // Adjust the left/right id
1170 $sql = 'UPDATE ' . FORUMS_TABLE . '
1171 SET right_id = left_id + 1
1172 WHERE forum_id = ' . $row['forum_id'];
1173 $db->sql_query($sql);
1176 else if ($row['forum_type'] == FORUM_CAT && $forum_data_sql['forum_type'] == FORUM_POST)
1178 // Changing a category to a forum? Reset the data (you can't post directly in a cat, you must use a forum)
1179 $forum_data_sql['forum_posts'] = 0;
1180 $forum_data_sql['forum_topics'] = 0;
1181 $forum_data_sql['forum_topics_real'] = 0;
1182 $forum_data_sql['forum_last_post_id'] = 0;
1183 $forum_data_sql['forum_last_post_subject'] = '';
1184 $forum_data_sql['forum_last_post_time'] = 0;
1185 $forum_data_sql['forum_last_poster_id'] = 0;
1186 $forum_data_sql['forum_last_poster_name'] = '';
1187 $forum_data_sql['forum_last_poster_colour'] = '';
1190 if (sizeof($errors))
1195 if ($row['parent_id'] != $forum_data_sql['parent_id'])
1197 if ($row['forum_id'] != $forum_data_sql['parent_id'])
1199 $errors = $this->move_forum($forum_data_sql['forum_id'], $forum_data_sql['parent_id']);
1203 $forum_data_sql['parent_id'] = $row['parent_id'];
1207 if (sizeof($errors))
1212 unset($forum_data_sql['type_action']);
1214 if ($row['forum_name'] != $forum_data_sql['forum_name'])
1216 // the forum name has changed, clear the parents list of all forums (for safety)
1217 $sql = 'UPDATE ' . FORUMS_TABLE . "
1218 SET forum_parents = ''";
1219 $db->sql_query($sql);
1222 // Setting the forum id to the forum id is not really received well by some dbs. ;)
1223 $forum_id = $forum_data_sql['forum_id'];
1224 unset($forum_data_sql['forum_id']);
1226 $sql = 'UPDATE ' . FORUMS_TABLE . '
1227 SET ' . $db->sql_build_array('UPDATE', $forum_data_sql) . '
1228 WHERE forum_id = ' . $forum_id;
1229 $db->sql_query($sql);
1232 $forum_data['forum_id'] = $forum_id;
1234 add_log('admin', 'LOG_FORUM_EDIT', $forum_data['forum_name']);
1243 function move_forum($from_id, $to_id)
1247 $to_data = $moved_ids = $errors = array();
1249 // Check if we want to move to a parent with link type
1252 $to_data = $this->get_forum_info($to_id);
1254 if ($to_data['forum_type'] == FORUM_LINK)
1256 $errors[] = $user->lang['PARENT_IS_LINK_FORUM'];
1261 $moved_forums = get_forum_branch($from_id, 'children', 'descending');
1262 $from_data = $moved_forums[0];
1263 $diff = sizeof($moved_forums) * 2;
1265 $moved_ids = array();
1266 for ($i = 0; $i < sizeof($moved_forums); ++$i)
1268 $moved_ids[] = $moved_forums[$i]['forum_id'];
1272 $sql = 'UPDATE ' . FORUMS_TABLE . "
1273 SET right_id = right_id - $diff, forum_parents = ''
1274 WHERE left_id < " . $from_data['right_id'] . "
1275 AND right_id > " . $from_data['right_id'];
1276 $db->sql_query($sql);
1278 // Resync righthand side of tree
1279 $sql = 'UPDATE ' . FORUMS_TABLE . "
1280 SET left_id = left_id - $diff, right_id = right_id - $diff, forum_parents = ''
1281 WHERE left_id > " . $from_data['right_id'];
1282 $db->sql_query($sql);
1286 // Retrieve $to_data again, it may have been changed...
1287 $to_data = $this->get_forum_info($to_id);
1289 // Resync new parents
1290 $sql = 'UPDATE ' . FORUMS_TABLE . "
1291 SET right_id = right_id + $diff, forum_parents = ''
1292 WHERE " . $to_data['right_id'] . ' BETWEEN left_id AND right_id
1293 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1294 $db->sql_query($sql);
1296 // Resync the righthand side of the tree
1297 $sql = 'UPDATE ' . FORUMS_TABLE . "
1298 SET left_id = left_id + $diff, right_id = right_id + $diff, forum_parents = ''
1299 WHERE left_id > " . $to_data['right_id'] . '
1300 AND ' . $db->sql_in_set('forum_id', $moved_ids, true);
1301 $db->sql_query($sql);
1303 // Resync moved branch
1304 $to_data['right_id'] += $diff;
1306 if ($to_data['right_id'] > $from_data['right_id'])
1308 $diff = '+ ' . ($to_data['right_id'] - $from_data['right_id'] - 1);
1312 $diff = '- ' . abs($to_data['right_id'] - $from_data['right_id'] - 1);
1317 $sql = 'SELECT MAX(right_id) AS right_id
1318 FROM ' . FORUMS_TABLE . '
1319 WHERE ' . $db->sql_in_set('forum_id', $moved_ids, true);
1320 $result = $db->sql_query($sql);
1321 $row = $db->sql_fetchrow($result);
1322 $db->sql_freeresult($result);
1324 $diff = '+ ' . ($row['right_id'] - $from_data['left_id'] + 1);
1327 $sql = 'UPDATE ' . FORUMS_TABLE . "
1328 SET left_id = left_id $diff, right_id = right_id $diff, forum_parents = ''
1329 WHERE " . $db->sql_in_set('forum_id', $moved_ids);
1330 $db->sql_query($sql);
1336 * Move forum content from one to another forum
1338 function move_forum_content($from_id, $to_id, $sync = true)
1342 $table_ary = array(LOG_TABLE, POSTS_TABLE, TOPICS_TABLE, DRAFTS_TABLE, TOPICS_TRACK_TABLE);
1344 foreach ($table_ary as $table)
1346 $sql = "UPDATE $table
1347 SET forum_id = $to_id
1348 WHERE forum_id = $from_id";
1349 $db->sql_query($sql);
1353 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, MODERATOR_CACHE_TABLE);
1355 foreach ($table_ary as $table)
1357 $sql = "DELETE FROM $table
1358 WHERE forum_id = $from_id";
1359 $db->sql_query($sql);
1364 // Delete ghost topics that link back to the same forum then resync counters
1365 sync('topic_moved');
1366 sync('forum', 'forum_id', $to_id, false, true);
1373 * Remove complete forum
1375 function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0)
1377 global $db, $user, $cache;
1379 $forum_data = $this->get_forum_info($forum_id);
1382 $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = '';
1383 $forum_ids = array($forum_id);
1385 if ($action_posts == 'delete')
1387 $log_action_posts = 'POSTS';
1388 $errors = array_merge($errors, $this->delete_forum_content($forum_id));
1390 else if ($action_posts == 'move')
1394 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1398 $log_action_posts = 'MOVE_POSTS';
1400 $sql = 'SELECT forum_name
1401 FROM ' . FORUMS_TABLE . '
1402 WHERE forum_id = ' . $posts_to_id;
1403 $result = $db->sql_query($sql);
1404 $row = $db->sql_fetchrow($result);
1405 $db->sql_freeresult($result);
1409 $errors[] = $user->lang['NO_FORUM'];
1413 $posts_to_name = $row['forum_name'];
1414 $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id));
1419 if (sizeof($errors))
1424 if ($action_subforums == 'delete')
1426 $log_action_forums = 'FORUMS';
1427 $rows = get_forum_branch($forum_id, 'children', 'descending', false);
1429 foreach ($rows as $row)
1431 $forum_ids[] = $row['forum_id'];
1432 $errors = array_merge($errors, $this->delete_forum_content($row['forum_id']));
1435 if (sizeof($errors))
1440 $diff = sizeof($forum_ids) * 2;
1442 $sql = 'DELETE FROM ' . FORUMS_TABLE . '
1443 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1444 $db->sql_query($sql);
1446 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . '
1447 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1448 $db->sql_query($sql);
1450 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . '
1451 WHERE ' . $db->sql_in_set('forum_id', $forum_ids);
1452 $db->sql_query($sql);
1454 else if ($action_subforums == 'move')
1456 if (!$subforums_to_id)
1458 $errors[] = $user->lang['NO_DESTINATION_FORUM'];
1462 $log_action_forums = 'MOVE_FORUMS';
1464 $sql = 'SELECT forum_name
1465 FROM ' . FORUMS_TABLE . '
1466 WHERE forum_id = ' . $subforums_to_id;
1467 $result = $db->sql_query($sql);
1468 $row = $db->sql_fetchrow($result);
1469 $db->sql_freeresult($result);
1473 $errors[] = $user->lang['NO_FORUM'];
1477 $subforums_to_name = $row['forum_name'];
1479 $sql = 'SELECT forum_id
1480 FROM ' . FORUMS_TABLE . "
1481 WHERE parent_id = $forum_id";
1482 $result = $db->sql_query($sql);
1484 while ($row = $db->sql_fetchrow($result))
1486 $this->move_forum($row['forum_id'], $subforums_to_id);
1488 $db->sql_freeresult($result);
1490 // Grab new forum data for correct tree updating later
1491 $forum_data = $this->get_forum_info($forum_id);
1493 $sql = 'UPDATE ' . FORUMS_TABLE . "
1494 SET parent_id = $subforums_to_id
1495 WHERE parent_id = $forum_id";
1496 $db->sql_query($sql);
1499 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1500 WHERE forum_id = $forum_id";
1501 $db->sql_query($sql);
1503 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1504 WHERE forum_id = $forum_id";
1505 $db->sql_query($sql);
1507 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1508 WHERE forum_id = $forum_id";
1509 $db->sql_query($sql);
1513 if (sizeof($errors))
1521 $sql = 'DELETE FROM ' . FORUMS_TABLE . "
1522 WHERE forum_id = $forum_id";
1523 $db->sql_query($sql);
1525 $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "
1526 WHERE forum_id = $forum_id";
1527 $db->sql_query($sql);
1529 $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "
1530 WHERE forum_id = $forum_id";
1531 $db->sql_query($sql);
1535 $sql = 'UPDATE ' . FORUMS_TABLE . "
1536 SET right_id = right_id - $diff
1537 WHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}";
1538 $db->sql_query($sql);
1540 $sql = 'UPDATE ' . FORUMS_TABLE . "
1541 SET left_id = left_id - $diff, right_id = right_id - $diff
1542 WHERE left_id > {$forum_data['right_id']}";
1543 $db->sql_query($sql);
1545 // Delete forum ids from extension groups table
1546 $sql = 'SELECT group_id, allowed_forums
1547 FROM ' . EXTENSION_GROUPS_TABLE;
1548 $result = $db->sql_query($sql);
1550 while ($row = $db->sql_fetchrow($result))
1552 if (!$row['allowed_forums'])
1557 $allowed_forums = unserialize(trim($row['allowed_forums']));
1558 $allowed_forums = array_diff($allowed_forums, $forum_ids);
1560 $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "
1561 SET allowed_forums = '" . ((sizeof($allowed_forums)) ? serialize($allowed_forums) : '') . "'
1562 WHERE group_id = {$row['group_id']}";
1563 $db->sql_query($sql);
1565 $db->sql_freeresult($result);
1567 $cache->destroy('_extensions');
1569 $log_action = implode('_', array($log_action_posts, $log_action_forums));
1571 switch ($log_action)
1573 case 'MOVE_POSTS_MOVE_FORUMS':
1574 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']);
1577 case 'MOVE_POSTS_FORUMS':
1578 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']);
1581 case 'POSTS_MOVE_FORUMS':
1582 add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1585 case '_MOVE_FORUMS':
1586 add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']);
1590 add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']);
1593 case 'POSTS_FORUMS':
1594 add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']);
1598 add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']);
1602 add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']);
1606 add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']);
1614 * Delete forum content
1616 function delete_forum_content($forum_id)
1618 global $db, $config, $phpbb_root_path, $phpEx;
1620 include_once($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
1622 $db->sql_transaction('begin');
1624 // Select then delete all attachments
1625 $sql = 'SELECT a.topic_id
1626 FROM ' . POSTS_TABLE . ' p, ' . ATTACHMENTS_TABLE . " a
1627 WHERE p.forum_id = $forum_id
1628 AND a.in_message = 0
1629 AND a.topic_id = p.topic_id";
1630 $result = $db->sql_query($sql);
1632 $topic_ids = array();
1633 while ($row = $db->sql_fetchrow($result))
1635 $topic_ids[] = $row['topic_id'];
1637 $db->sql_freeresult($result);
1639 delete_attachments('topic', $topic_ids, false);
1641 // Delete shadow topics pointing to topics in this forum
1642 delete_topic_shadows($forum_id);
1644 // Before we remove anything we make sure we are able to adjust the post counts later. ;)
1645 $sql = 'SELECT poster_id
1646 FROM ' . POSTS_TABLE . '
1647 WHERE forum_id = ' . $forum_id . '
1648 AND post_postcount = 1
1649 AND post_approved = 1';
1650 $result = $db->sql_query($sql);
1652 $post_counts = array();
1653 while ($row = $db->sql_fetchrow($result))
1655 $post_counts[$row['poster_id']] = (!empty($post_counts[$row['poster_id']])) ? $post_counts[$row['poster_id']] + 1 : 1;
1657 $db->sql_freeresult($result);
1659 switch ($db->sql_layer)
1664 // Delete everything else and thank MySQL for offering multi-table deletion
1665 $tables_ary = array(
1666 SEARCH_WORDMATCH_TABLE => 'post_id',
1667 REPORTS_TABLE => 'post_id',
1668 WARNINGS_TABLE => 'post_id',
1669 BOOKMARKS_TABLE => 'topic_id',
1670 TOPICS_WATCH_TABLE => 'topic_id',
1671 TOPICS_POSTED_TABLE => 'topic_id',
1672 POLL_OPTIONS_TABLE => 'topic_id',
1673 POLL_VOTES_TABLE => 'topic_id',
1676 $sql = 'DELETE ' . POSTS_TABLE;
1677 $sql_using = "\nFROM " . POSTS_TABLE;
1678 $sql_where = "\nWHERE " . POSTS_TABLE . ".forum_id = $forum_id\n";
1680 foreach ($tables_ary as $table => $field)
1682 $sql .= ", $table ";
1683 $sql_using .= ", $table ";
1684 $sql_where .= "\nAND $table.$field = " . POSTS_TABLE . ".$field";
1687 $db->sql_query($sql . $sql_using . $sql_where);
1693 // Delete everything else and curse your DB for not offering multi-table deletion
1694 $tables_ary = array(
1696 SEARCH_WORDMATCH_TABLE,
1701 'topic_id' => array(
1704 TOPICS_POSTED_TABLE,
1710 // Amount of rows we select and delete in one iteration.
1713 foreach ($tables_ary as $field => $tables)
1719 $sql = "SELECT $field
1720 FROM " . POSTS_TABLE . '
1721 WHERE forum_id = ' . $forum_id;
1722 $result = $db->sql_query_limit($sql, $batch_size, $start);
1725 while ($row = $db->sql_fetchrow($result))
1727 $ids[] = $row[$field];
1729 $db->sql_freeresult($result);
1733 $start += sizeof($ids);
1735 foreach ($tables as $table)
1737 $db->sql_query("DELETE FROM $table WHERE " . $db->sql_in_set($field, $ids));
1741 while (sizeof($ids) == $batch_size);
1748 $table_ary = array(FORUMS_ACCESS_TABLE, FORUMS_TRACK_TABLE, FORUMS_WATCH_TABLE, LOG_TABLE, MODERATOR_CACHE_TABLE, POSTS_TABLE, TOPICS_TABLE, TOPICS_TRACK_TABLE);
1750 foreach ($table_ary as $table)
1752 $db->sql_query("DELETE FROM $table WHERE forum_id = $forum_id");
1755 // Set forum ids to 0
1756 $table_ary = array(DRAFTS_TABLE);
1758 foreach ($table_ary as $table)
1760 $db->sql_query("UPDATE $table SET forum_id = 0 WHERE forum_id = $forum_id");
1763 // Adjust users post counts
1764 if (sizeof($post_counts))
1766 foreach ($post_counts as $poster_id => $substract)
1768 $sql = 'UPDATE ' . USERS_TABLE . '
1770 WHERE user_id = ' . $poster_id . '
1771 AND user_posts < ' . $substract;
1772 $db->sql_query($sql);
1774 $sql = 'UPDATE ' . USERS_TABLE . '
1775 SET user_posts = user_posts - ' . $substract . '
1776 WHERE user_id = ' . $poster_id . '
1777 AND user_posts >= ' . $substract;
1778 $db->sql_query($sql);
1782 $db->sql_transaction('commit');
1784 // Make sure the overall post/topic count is correct...
1785 $sql = 'SELECT COUNT(post_id) AS stat
1786 FROM ' . POSTS_TABLE . '
1787 WHERE post_approved = 1';
1788 $result = $db->sql_query($sql);
1789 $row = $db->sql_fetchrow($result);
1790 $db->sql_freeresult($result);
1792 set_config('num_posts', (int) $row['stat'], true);
1794 $sql = 'SELECT COUNT(topic_id) AS stat
1795 FROM ' . TOPICS_TABLE . '
1796 WHERE topic_approved = 1';
1797 $result = $db->sql_query($sql);
1798 $row = $db->sql_fetchrow($result);
1799 $db->sql_freeresult($result);
1801 set_config('num_topics', (int) $row['stat'], true);
1803 $sql = 'SELECT COUNT(attach_id) as stat
1804 FROM ' . ATTACHMENTS_TABLE;
1805 $result = $db->sql_query($sql);
1806 $row = $db->sql_fetchrow($result);
1807 $db->sql_freeresult($result);
1809 set_config('num_files', (int) $row['stat'], true);
1811 $sql = 'SELECT SUM(filesize) as stat
1812 FROM ' . ATTACHMENTS_TABLE;
1813 $result = $db->sql_query($sql);
1814 $row = $db->sql_fetchrow($result);
1815 $db->sql_freeresult($result);
1817 set_config('upload_dir_size', (float) $row['stat'], true);
1823 * Move forum position by $steps up/down
1825 function move_forum_by($forum_row, $action = 'move_up', $steps = 1)
1830 * Fetch all the siblings between the module's current spot
1831 * and where we want to move it to. If there are less than $steps
1832 * siblings between the current spot and the target then the
1833 * module will move as far as possible
1835 $sql = 'SELECT forum_id, forum_name, left_id, right_id
1836 FROM ' . FORUMS_TABLE . "
1837 WHERE parent_id = {$forum_row['parent_id']}
1838 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");
1839 $result = $db->sql_query_limit($sql, $steps);
1842 while ($row = $db->sql_fetchrow($result))
1846 $db->sql_freeresult($result);
1848 if (!sizeof($target))
1850 // The forum is already on top or bottom
1855 * $left_id and $right_id define the scope of the nodes that are affected by the move.
1856 * $diff_up and $diff_down are the values to substract or add to each node's left_id
1857 * and right_id in order to move them up or down.
1858 * $move_up_left and $move_up_right define the scope of the nodes that are moving
1859 * up. Other nodes in the scope of ($left_id, $right_id) are considered to move down.
1861 if ($action == 'move_up')
1863 $left_id = $target['left_id'];
1864 $right_id = $forum_row['right_id'];
1866 $diff_up = $forum_row['left_id'] - $target['left_id'];
1867 $diff_down = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1869 $move_up_left = $forum_row['left_id'];
1870 $move_up_right = $forum_row['right_id'];
1874 $left_id = $forum_row['left_id'];
1875 $right_id = $target['right_id'];
1877 $diff_up = $forum_row['right_id'] + 1 - $forum_row['left_id'];
1878 $diff_down = $target['right_id'] - $forum_row['right_id'];
1880 $move_up_left = $forum_row['right_id'] + 1;
1881 $move_up_right = $target['right_id'];
1884 // Now do the dirty job
1885 $sql = 'UPDATE ' . FORUMS_TABLE . "
1886 SET left_id = left_id + CASE
1887 WHEN left_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1890 right_id = right_id + CASE
1891 WHEN right_id BETWEEN {$move_up_left} AND {$move_up_right} THEN -{$diff_up}
1896 left_id BETWEEN {$left_id} AND {$right_id}
1897 AND right_id BETWEEN {$left_id} AND {$right_id}";
1898 $db->sql_query($sql);
1900 return $target['forum_name'];
1904 * Display progress bar for syncinc forums
1906 function display_progress_bar($start, $total)
1908 global $template, $user;
1910 adm_page_header($user->lang['SYNC_IN_PROGRESS']);
1912 $template->set_filenames(array(
1913 'body' => 'progress_bar.html')
1916 $template->assign_vars(array(
1917 'L_PROGRESS' => $user->lang['SYNC_IN_PROGRESS'],
1918 'L_PROGRESS_EXPLAIN' => ($start && $total) ? sprintf($user->lang['SYNC_IN_PROGRESS_EXPLAIN'], $start, $total) : $user->lang['SYNC_IN_PROGRESS'])
1925 * Display copy permission page
1926 * Not used at the moment - we will have a look at it for 3.0.7
1928 function copy_permission_page($forum_data)
1930 global $phpEx, $phpbb_admin_path, $template, $user;
1932 $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id'];
1933 $action = append_sid($this->u_action . "&parent_id={$this->parent_id}&f={$forum_data['forum_id']}&action=copy_perm");
1935 $l_acl = sprintf($user->lang['COPY_TO_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url) . '">', '</a>');
1937 $this->tpl_name = 'acp_forums_copy_perm';
1939 $template->assign_vars(array(
1940 'U_ACL' => append_sid("{$phpbb_admin_path}index.$phpEx", 'i=permissions' . $acl_url),
1941 'L_ACL_LINK' => $l_acl,
1942 'L_BACK_LINK' => adm_back_link($this->u_action . '&parent_id=' . $this->parent_id),
1943 'S_COPY_ACTION' => $action,
1944 'S_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_data['forum_id'], false, false, false),