/** * Store user input * * @param $event */ public function acp_manage_forums_request_data($event) { $sort_topics_by = $this->request->variable('sk', $this->default_sort_by); $sort_topics_order = $this->request->variable('sd', $this->default_sort_order); $sort_topics_subforums = $this->request->variable('sort_topics_subforums', false); $sort_options = array('sort_topics_by' => $sort_topics_by, 'sort_topics_order' => $sort_topics_order); $event['forum_data'] = array_merge($event['forum_data'], $sort_options); // Apply this forum's sorting to all sub-forums if ($event['action'] == 'edit' && $sort_topics_subforums) { $subforum_ids = array(); foreach (get_forum_branch($event['forum_data']['forum_id'], 'children', 'descending', false) as $subforum) { $subforum_ids[] = (int) $subforum['forum_id']; } if ($subforum_ids) { $sql = 'UPDATE ' . FORUMS_TABLE . ' SET ' . $this->db->sql_build_array('UPDATE', $sort_options) . ' WHERE ' . $this->db->sql_in_set('forum_id', $subforum_ids); $this->db->sql_query($sql); } } }
/** * Store user input * * Event: core.acp_manage_forums_request_data */ public function acp_manage_forums_request_data($event) { $sort_topics_by = $this->request->variable('sk', $this->default_sort_by); $sort_topics_order = $this->request->variable('sd', $this->default_sort_order); $sort_topics_subforums = $this->request->variable('sort_topics_subforums', 0); $event['forum_data'] = array_merge($event['forum_data'], array('sort_topics_by' => $sort_topics_by, 'sort_topics_order' => $sort_topics_order)); // Apply this forum's sorting to all sub-forums if ($sort_topics_subforums) { $subforum_ids = array(); foreach (get_forum_branch($event['forum_data']['forum_id'], 'children', 'descending', false) as $subforum) { $subforum_ids[] = (int) $subforum['forum_id']; } if (!empty($subforum_ids)) { $this->db->sql_transaction('begin'); foreach ($subforum_ids as $subforum_id) { $sql_ary = 'UPDATE ' . FORUMS_TABLE . ' SET ' . sprintf("sort_topics_by = '%s', sort_topics_order = '%s'", $sort_topics_by, $sort_topics_order) . ' WHERE forum_id = ' . (int) $subforum_id; $this->db->sql_query($sql_ary); } $this->db->sql_transaction('commit'); } } }
/** * Event: core.acp_manage_forums_request_data */ public function acp_manage_forums_request_data($event) { $move_topics = $this->request->variable('move_topics_when_locked', 0); $move_topics_to = $this->request->variable('move_topics_when_locked_to', 0); $event['forum_data'] = array_merge($event['forum_data'], array('move_topics_when_locked' => $move_topics, 'move_topics_when_locked_to' => $move_topics_to)); // Apply this forum's preferences to all sub-forums if ($this->request->variable('move_topics_when_locked_subforums', 0)) { $subforum_ids = array(); foreach (get_forum_branch($event['forum_data']['forum_id'], 'children', 'descending', false) as $subforum) { $subforum_ids[] = (int) $subforum['forum_id']; } if (!empty($subforum_ids)) { $this->db->sql_transaction('begin'); foreach ($subforum_ids as $subforum_id) { $sql_ary = 'UPDATE ' . FORUMS_TABLE . ' SET move_topics_when_locked = ' . (int) $move_topics . ', move_topics_when_locked_to = ' . (int) $move_topics_to . ' WHERE forum_id = ' . (int) $subforum_id; $this->db->sql_query($sql_ary); } $this->db->sql_transaction('commit'); } } }
function main($id, $mode) { global $db, $user, $auth, $template, $phpbb_container, $request; global $config, $phpbb_root_path, $phpEx; if (!function_exists('user_get_id_name')) { include $phpbb_root_path . 'includes/functions_user.' . $phpEx; } if (!class_exists('auth_admin')) { include $phpbb_root_path . 'includes/acp/auth.' . $phpEx; } $this->permissions = $phpbb_container->get('acl.permissions'); $auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); add_permission_language(); $this->tpl_name = 'acp_permissions'; // Trace has other vars if ($mode == 'trace') { $user_id = $request->variable('u', 0); $forum_id = $request->variable('f', 0); $permission = $request->variable('auth', ''); $this->tpl_name = 'permission_trace'; if ($user_id && isset($auth_admin->acl_options['id'][$permission]) && $auth->acl_get('a_viewauth')) { $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $this->permissions->get_permission_lang($permission)); $this->permission_trace($user_id, $forum_id, $permission); return; } trigger_error('NO_MODE', E_USER_ERROR); } // Copy forum permissions if ($mode == 'setting_forum_copy') { $this->tpl_name = 'permission_forum_copy'; if ($auth->acl_get('a_fauth') && $auth->acl_get('a_authusers') && $auth->acl_get('a_authgroups') && $auth->acl_get('a_mauth')) { $this->page_title = 'ACP_FORUM_PERMISSIONS_COPY'; $this->copy_forum_permissions(); return; } trigger_error('NO_MODE', E_USER_ERROR); } // Set some vars $action = $request->variable('action', array('' => 0)); $action = key($action); $action = isset($_POST['psubmit']) ? 'apply_permissions' : $action; $all_forums = $request->variable('all_forums', 0); $subforum_id = $request->variable('subforum_id', 0); $forum_id = $request->variable('forum_id', array(0)); $username = $request->variable('username', array(''), true); $usernames = $request->variable('usernames', '', true); $user_id = $request->variable('user_id', array(0)); $group_id = $request->variable('group_id', array(0)); $select_all_groups = $request->variable('select_all_groups', 0); $form_name = 'acp_permissions'; add_form_key($form_name); // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen) if ($select_all_groups) { // Add default groups to selection $sql_and = !$config['coppa_enable'] ? " AND group_name <> 'REGISTERED_COPPA'" : ''; $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_type = ' . GROUP_SPECIAL . "\n\t\t\t\t{$sql_and}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $group_id[] = $row['group_id']; } $db->sql_freeresult($result); } // Map usernames to ids and vice versa if ($usernames) { $username = explode("\n", $usernames); } unset($usernames); if (sizeof($username) && !sizeof($user_id)) { user_get_id_name($user_id, $username); if (!sizeof($user_id)) { trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action), E_USER_WARNING); } } unset($username); // Build forum ids (of all forums are checked or subforum listing used) if ($all_forums) { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id'; $result = $db->sql_query($sql); $forum_id = array(); while ($row = $db->sql_fetchrow($result)) { $forum_id[] = (int) $row['forum_id']; } $db->sql_freeresult($result); } else { if ($subforum_id) { $forum_id = array(); foreach (get_forum_branch($subforum_id, 'children') as $row) { $forum_id[] = (int) $row['forum_id']; } } } // Define some common variables for every mode $permission_scope = strpos($mode, '_global') !== false ? 'global' : 'local'; // Showing introductionary page? if ($mode == 'intro') { $this->page_title = 'ACP_PERMISSIONS'; $template->assign_vars(array('S_INTRO' => true)); return; } switch ($mode) { case 'setting_user_global': case 'setting_group_global': $this->permission_dropdown = array('u_', 'm_', 'a_'); $permission_victim = $mode == 'setting_user_global' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_global' ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS'; break; case 'setting_user_local': case 'setting_group_local': $this->permission_dropdown = array('f_', 'm_'); $permission_victim = $mode == 'setting_user_local' ? array('user', 'forums') : array('group', 'forums'); $this->page_title = $mode == 'setting_user_local' ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS'; break; case 'setting_admin_global': case 'setting_mod_global': $this->permission_dropdown = strpos($mode, '_admin_') !== false ? array('a_') : array('m_'); $permission_victim = array('usergroup'); $this->page_title = $mode == 'setting_admin_global' ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS'; break; case 'setting_mod_local': case 'setting_forum_local': $this->permission_dropdown = $mode == 'setting_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup'); $this->page_title = $mode == 'setting_mod_local' ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS'; break; case 'view_admin_global': case 'view_user_global': case 'view_mod_global': $this->permission_dropdown = $mode == 'view_admin_global' ? array('a_') : ($mode == 'view_user_global' ? array('u_') : array('m_')); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_admin_global' ? 'ACP_VIEW_ADMIN_PERMISSIONS' : ($mode == 'view_user_global' ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS'); break; case 'view_mod_local': case 'view_forum_local': $this->permission_dropdown = $mode == 'view_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup_view'); $this->page_title = $mode == 'view_mod_local' ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS'; break; default: trigger_error('NO_MODE', E_USER_ERROR); break; } $template->assign_vars(array('L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])); // Get permission type $permission_type = $request->variable('type', $this->permission_dropdown[0]); if (!in_array($permission_type, $this->permission_dropdown)) { trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action), E_USER_WARNING); } // Handle actions if (strpos($mode, 'setting_') === 0 && $action) { switch ($action) { case 'delete': if (confirm_box(true)) { // All users/groups selected? $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if ($all_users || $all_groups) { $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; } else { if ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; } } } if (sizeof($user_id) || sizeof($group_id)) { $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id); } else { trigger_error($user->lang['NO_USER_GROUP_SELECTED'] . adm_back_link($this->u_action), E_USER_WARNING); } } else { if (isset($_POST['cancel'])) { $u_redirect = $this->u_action . '&type=' . $permission_type; foreach ($forum_id as $fid) { $u_redirect .= '&forum_id[]=' . $fid; } redirect($u_redirect); } $s_hidden_fields = array('i' => $id, 'mode' => $mode, 'action' => array($action => 1), 'user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type); if (isset($_POST['all_users'])) { $s_hidden_fields['all_users'] = 1; } if (isset($_POST['all_groups'])) { $s_hidden_fields['all_groups'] = 1; } confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields($s_hidden_fields)); } break; case 'apply_permissions': if (!isset($_POST['setting'])) { send_status_line(403, 'Forbidden'); trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; case 'apply_all_permissions': if (!isset($_POST['setting'])) { send_status_line(403, 'Forbidden'); trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action), E_USER_WARNING); } if (!check_form_key($form_name)) { trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); } $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; } } // Go through the screens/options needed and present them in correct order foreach ($permission_victim as $victim) { switch ($victim) { case 'forum_dropdown': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))); break; case 'forums': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $forum_list = make_forum_select(false, false, true, false, false, false, true); // Build forum options $s_forum_options = ''; foreach ($forum_list as $f_id => $f_row) { $s_forum_options .= '<option value="' . $f_id . '"' . ($f_row['selected'] ? ' selected="selected"' : '') . ($f_row['disabled'] ? ' disabled="disabled" class="disabled-option"' : '') . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>'; } // Build subforum options $s_subforum_options = $this->build_subforum_options($forum_list); $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => $s_forum_options, 'S_SUBFORUM_OPTIONS' => $s_subforum_options, 'S_FORUM_ALL' => true, 'S_FORUM_MULTIPLE' => true)); break; case 'user': if (sizeof($user_id)) { $this->check_existence('user', $user_id); continue 2; } $template->assign_vars(array('S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_victim&field=username&select_single=true'))); break; case 'group': if (sizeof($group_id)) { $this->check_existence('group', $group_id); continue 2; } $template->assign_vars(array('S_SELECT_GROUP' => true, 'S_GROUP_OPTIONS' => group_select_options(false, false, false))); break; case 'usergroup': case 'usergroup_view': $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if (sizeof($user_id) && !$all_users || sizeof($group_id) && !$all_groups) { if (sizeof($user_id)) { $this->check_existence('user', $user_id); } if (sizeof($group_id)) { $this->check_existence('group', $group_id); } continue 2; } // Now we check the users... because the "all"-selection is different here (all defined users/groups) $items = $this->retrieve_defined_user_groups($permission_scope, $forum_id, $permission_type); if ($all_users && sizeof($items['user_ids'])) { $user_id = $items['user_ids']; continue 2; } if ($all_groups && sizeof($items['group_ids'])) { $group_id = $items['group_ids']; continue 2; } $template->assign_vars(array('S_SELECT_USERGROUP' => $victim == 'usergroup' ? true : false, 'S_SELECT_USERGROUP_VIEW' => $victim == 'usergroup_view' ? true : false, 'S_DEFINED_USER_OPTIONS' => $items['user_ids_options'], 'S_DEFINED_GROUP_OPTIONS' => $items['group_ids_options'], 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $items['group_ids'], false), 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=add_user&field=username&select_single=true'))); break; } // The S_ALLOW_SELECT parameter below is a measure to lower memory usage. // If there are more than 5 forums selected the admin is not able to select all users/groups too. // We need to see if the number of forums can be increased or need to be decreased. // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_VICTIM' => true, 'S_ALLOW_ALL_SELECT' => sizeof($forum_id) > 5 ? false : true, 'S_CAN_SELECT_USER' => $auth->acl_get('a_authusers') ? true : false, 'S_CAN_SELECT_GROUP' => $auth->acl_get('a_authgroups') ? true : false, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // Let the forum names being displayed if (sizeof($forum_id)) { $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_id) . ' ORDER BY left_id ASC'; $result = $db->sql_query($sql); $forum_names = array(); while ($row = $db->sql_fetchrow($result)) { $forum_names[] = $row['forum_name']; } $db->sql_freeresult($result); $template->assign_vars(array('S_FORUM_NAMES' => sizeof($forum_names) ? true : false, 'FORUM_NAMES' => implode($user->lang['COMMA_SEPARATOR'], $forum_names))); } return; } // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); // Do not allow forum_ids being set and no other setting defined (will bog down the server too much) if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id)) { trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action), E_USER_WARNING); } $template->assign_vars(array('S_PERMISSION_DROPDOWN' => sizeof($this->permission_dropdown) > 1 ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type, $permission_scope) : false, 'L_PERMISSION_TYPE' => $this->permissions->get_type_lang($permission_type), 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); if (strpos($mode, 'setting_') === 0) { $template->assign_vars(array('S_SETTING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('set', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO); $auth_admin->display_mask('set', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } else { $template->assign_vars(array('S_VIEWING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('view', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NEVER); $auth_admin->display_mask('view', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } }
/** * Remove complete forum */ function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0) { global $db, $user, $cache; $forum_data = $this->get_forum_info($forum_id); $errors = array(); $log_action_posts = $log_action_forums = $posts_to_name = $subforums_to_name = ''; $forum_ids = array($forum_id); if ($action_posts == 'delete') { $log_action_posts = 'POSTS'; $errors = array_merge($errors, $this->delete_forum_content($forum_id)); } else { if ($action_posts == 'move') { if (!$posts_to_id) { $errors[] = $user->lang['NO_DESTINATION_FORUM']; } else { $log_action_posts = 'MOVE_POSTS'; $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $posts_to_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { $errors[] = $user->lang['NO_FORUM']; } else { $posts_to_name = $row['forum_name']; $errors = array_merge($errors, $this->move_forum_content($forum_id, $posts_to_id)); } } } } if (sizeof($errors)) { return $errors; } if ($action_subforums == 'delete') { $log_action_forums = 'FORUMS'; $rows = get_forum_branch($forum_id, 'children', 'descending', false); foreach ($rows as $row) { $forum_ids[] = $row['forum_id']; $errors = array_merge($errors, $this->delete_forum_content($row['forum_id'])); } if (sizeof($errors)) { return $errors; } $diff = sizeof($forum_ids) * 2; $sql = 'DELETE FROM ' . FORUMS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids); $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids); $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_USERS_TABLE . ' WHERE ' . $db->sql_in_set('forum_id', $forum_ids); $db->sql_query($sql); } else { if ($action_subforums == 'move') { if (!$subforums_to_id) { $errors[] = $user->lang['NO_DESTINATION_FORUM']; } else { $log_action_forums = 'MOVE_FORUMS'; $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id = ' . $subforums_to_id; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { $errors[] = $user->lang['NO_FORUM']; } else { $subforums_to_name = $row['forum_name']; $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\tWHERE parent_id = {$forum_id}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $this->move_forum($row['forum_id'], $subforums_to_id); } $db->sql_freeresult($result); // Grab new forum data for correct tree updating later $forum_data = $this->get_forum_info($forum_id); $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\t\t\t\tSET parent_id = {$subforums_to_id}\n\t\t\t\t\t\tWHERE parent_id = {$forum_id}"; $db->sql_query($sql); $diff = 2; $sql = 'DELETE FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); } } if (sizeof($errors)) { return $errors; } } else { $diff = 2; $sql = 'DELETE FROM ' . FORUMS_TABLE . "\n\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . "\n\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_USERS_TABLE . "\n\t\t\t\tWHERE forum_id = {$forum_id}"; $db->sql_query($sql); } } // Resync tree $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\tSET right_id = right_id - {$diff}\n\t\t\tWHERE left_id < {$forum_data['right_id']} AND right_id > {$forum_data['right_id']}"; $db->sql_query($sql); $sql = 'UPDATE ' . FORUMS_TABLE . "\n\t\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\t\tWHERE left_id > {$forum_data['right_id']}"; $db->sql_query($sql); // Delete forum ids from extension groups table $sql = 'SELECT group_id, allowed_forums FROM ' . EXTENSION_GROUPS_TABLE; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { if (!$row['allowed_forums']) { continue; } $allowed_forums = unserialize(trim($row['allowed_forums'])); $allowed_forums = array_diff($allowed_forums, $forum_ids); $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . "\n\t\t\t\tSET allowed_forums = '" . (sizeof($allowed_forums) ? serialize($allowed_forums) : '') . "'\n\t\t\t\tWHERE group_id = {$row['group_id']}"; $db->sql_query($sql); } $db->sql_freeresult($result); $cache->destroy('_extensions'); $log_action = implode('_', array($log_action_posts, $log_action_forums)); switch ($log_action) { case 'MOVE_POSTS_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_data['forum_name']); break; case 'MOVE_POSTS_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_data['forum_name']); break; case 'POSTS_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']); break; case '_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_data['forum_name']); break; case 'MOVE_POSTS_': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_data['forum_name']); break; case 'POSTS_FORUMS': add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_data['forum_name']); break; case '_FORUMS': add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_data['forum_name']); break; case 'POSTS_': add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_data['forum_name']); break; default: add_log('admin', 'LOG_FORUM_DEL_FORUM', $forum_data['forum_name']); break; } return $errors; }
function main($id, $mode) { global $db, $user, $auth, $template, $cache; global $config, $phpbb_admin_path, $phpbb_root_path, $phpEx; $user->add_lang('acp/forums'); $user->add_lang('acp/site'); $this->tpl_name = 'acp_bugs'; $this->page_title = 'ACP_BUG_TRACKER'; /** * Projects (also creating forums) */ if ($mode == 'projects') { $this->parent_id = BUGS_FORUM_ID; $action = request_var('action', ''); $update = isset($_POST['update']) ? true : false; $forum_id = request_var('f', 0); // This is just a shame copy of acp_forums, use acp_forus whenever possible (for functions) include "{$phpbb_root_path}includes/acp/acp_forums.{$phpEx}"; $this->parent = new acp_forums(); $forum_data = $errors = array(); // Check additional permissions /*switch ($action) { case 'delete': if (!$auth->acl_get('a_forumdel')) { trigger_error($user->lang['NO_PERMISSION_FORUM_DELETE'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } break; case 'add': if (!$auth->acl_get('a_forumadd')) { trigger_error($user->lang['NO_PERMISSION_FORUM_ADD'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } break; }*/ // Major routines if ($update) { switch ($action) { case 'delete': $action_subforums = request_var('action_subforums', ''); $subforums_to_id = request_var('subforums_to_id', 0); $action_posts = request_var('action_posts', ''); $posts_to_id = request_var('posts_to_id', 0); $errors = $this->delete_forum($forum_id, $action_posts, $action_subforums, $posts_to_id, $subforums_to_id); if (sizeof($errors)) { break; } $auth->acl_clear_prefetch(); $cache->destroy('sql', FORUMS_TABLE); trigger_error($user->lang['PROJECT_DELETED'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); break; case 'edit': $forum_data = array('forum_id' => $forum_id); // No break here // No break here case 'add': $forum_data += array('parent_id' => BUGS_FORUM_ID, 'forum_type' => FORUM_POST, 'type_action' => request_var('type_action', ''), 'forum_status' => request_var('forum_status', ITEM_UNLOCKED), 'forum_parents' => '', 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)), 'project_idname' => request_var('project_idname', ''), 'forum_link' => '', 'forum_link_track' => false, 'forum_desc' => utf8_normalize_nfc(request_var('forum_desc', '', true)), 'forum_desc_uid' => '', 'forum_desc_options' => 7, 'forum_desc_bitfield' => '', 'forum_rules' => utf8_normalize_nfc(request_var('forum_rules', '', true)), 'forum_rules_uid' => '', 'forum_rules_options' => 7, 'forum_rules_bitfield' => '', 'forum_rules_link' => request_var('forum_rules_link', ''), 'forum_image' => request_var('forum_image', ''), 'forum_style' => request_var('forum_style', 0), 'display_on_index' => request_var('display_on_index', false), 'forum_topics_per_page' => request_var('topics_per_page', 0), 'enable_indexing' => request_var('enable_indexing', true), 'enable_icons' => request_var('enable_icons', false), 'enable_prune' => request_var('enable_prune', false), 'enable_post_review' => request_var('enable_post_review', true), 'prune_days' => request_var('prune_days', 7), 'prune_viewed' => request_var('prune_viewed', 7), 'prune_freq' => request_var('prune_freq', 1), 'prune_old_polls' => request_var('prune_old_polls', false), 'prune_announce' => request_var('prune_announce', false), 'prune_sticky' => request_var('prune_sticky', false), 'forum_password' => request_var('forum_password', '', true), 'forum_password_confirm' => request_var('forum_password_confirm', '', true)); $forum_data['show_active'] = $forum_data['forum_type'] == FORUM_POST ? request_var('display_recent', false) : request_var('display_active', false); // Get data for forum rules if specified... if ($forum_data['forum_rules']) { 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)); } // Get data for forum description if specified if ($forum_data['forum_desc']) { 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)); } $errors = $this->update_forum_data($forum_data); if (!sizeof($errors)) { $forum_perm_from = request_var('forum_perm_from', 0); // Copy permissions? if ($forum_perm_from && !empty($forum_perm_from) && $forum_perm_from != $forum_data['forum_id']) { // if we edit a forum delete current permissions first if ($action == 'edit') { $sql = 'DELETE FROM ' . ACL_USERS_TABLE . ' WHERE forum_id = ' . (int) $forum_data['forum_id']; $db->sql_query($sql); $sql = 'DELETE FROM ' . ACL_GROUPS_TABLE . ' WHERE forum_id = ' . (int) $forum_data['forum_id']; $db->sql_query($sql); } // From the mysql documentation: // 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. // Due to this we stay on the safe side if we do the insertion "the manual way" // Copy permisisons from/to the acl users table (only forum_id gets changed) $sql = 'SELECT user_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_USERS_TABLE . ' WHERE forum_id = ' . $forum_perm_from; $result = $db->sql_query($sql); $users_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $users_sql_ary[] = array('user_id' => (int) $row['user_id'], 'forum_id' => (int) $forum_data['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Copy permisisons from/to the acl groups table (only forum_id gets changed) $sql = 'SELECT group_id, auth_option_id, auth_role_id, auth_setting FROM ' . ACL_GROUPS_TABLE . ' WHERE forum_id = ' . $forum_perm_from; $result = $db->sql_query($sql); $groups_sql_ary = array(); while ($row = $db->sql_fetchrow($result)) { $groups_sql_ary[] = array('group_id' => (int) $row['group_id'], 'forum_id' => (int) $forum_data['forum_id'], 'auth_option_id' => (int) $row['auth_option_id'], 'auth_role_id' => (int) $row['auth_role_id'], 'auth_setting' => (int) $row['auth_setting']); } $db->sql_freeresult($result); // Now insert the data $db->sql_multi_insert(ACL_USERS_TABLE, $users_sql_ary); $db->sql_multi_insert(ACL_GROUPS_TABLE, $groups_sql_ary); } $auth->acl_clear_prefetch(); $cache->destroy('sql', FORUMS_TABLE); $acl_url = '&mode=setting_forum_local&forum_id[]=' . $forum_data['forum_id']; $message = $action == 'add' ? $user->lang['PROJECT_CREATED'] : $user->lang['PROJECT_UPDATED']; // Redirect to permissions if ($auth->acl_get('a_fauth')) { $message .= '<br /><br />' . sprintf($user->lang['REDIRECT_ACL'], '<a href="' . append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions' . $acl_url) . '">', '</a>'); } // redirect directly to permission settings screen if authed if ($action == 'add' && !$forum_perm_from && $auth->acl_get('a_fauth')) { meta_refresh(4, append_sid("{$phpbb_admin_path}index.{$phpEx}", 'i=permissions' . $acl_url)); } trigger_error($message . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id)); } break; } } switch ($action) { case 'move_up': case 'move_down': if (!$forum_id) { trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $sql = 'SELECT * FROM ' . FORUMS_TABLE . "\n\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$row) { trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $move_forum_name = $this->parent->move_forum_by($row, $action, 1); if ($move_forum_name !== false) { add_log('admin', 'LOG_FORUM_' . strtoupper($action), $row['forum_name'], $move_forum_name); $cache->destroy('sql', FORUMS_TABLE); } break; case 'add': case 'edit': if ($update) { $forum_data['forum_flags'] = 0; $forum_data['forum_flags'] += request_var('forum_link_track', false) ? FORUM_FLAG_LINK_TRACK : 0; $forum_data['forum_flags'] += request_var('prune_old_polls', false) ? FORUM_FLAG_PRUNE_POLL : 0; $forum_data['forum_flags'] += request_var('prune_announce', false) ? FORUM_FLAG_PRUNE_ANNOUNCE : 0; $forum_data['forum_flags'] += request_var('prune_sticky', false) ? FORUM_FLAG_PRUNE_STICKY : 0; $forum_data['forum_flags'] += $forum_data['show_active'] ? FORUM_FLAG_ACTIVE_TOPICS : 0; $forum_data['forum_flags'] += request_var('enable_post_review', true) ? FORUM_FLAG_POST_REVIEW : 0; } // Show form to create/modify a forum if ($action == 'edit') { $this->page_title = 'EDIT_PROJECT'; $row = $this->parent->get_forum_info($forum_id); $old_forum_type = $row['forum_type']; // Get the project's id name $sql = 'SELECT project_name FROM ' . BUGS_PROJECTS_TABLE . "\n\t\t\t\t\t\t\tWHERE forum_id = {$forum_id}"; $result = $db->sql_query($sql); $row['project_idname'] = $db->sql_fetchfield('project_name', false, $result); $db->sql_freeresult($result); if (!$update) { $forum_data = $row; } else { $forum_data['left_id'] = $row['left_id']; $forum_data['right_id'] = $row['right_id']; } // Make sure no direct child forums are able to be selected as parents. $exclude_forums = array(); foreach (get_forum_branch($forum_id, 'children') as $row) { $exclude_forums[] = $row['forum_id']; } $parents_list = make_forum_select($forum_data['parent_id'], $exclude_forums, false, false, false); $forum_data['forum_password_confirm'] = $forum_data['forum_password']; } else { $this->page_title = 'CREATE_PROJECT'; $forum_id = BUGS_FORUM_ID; // Fill forum data with default values if (!$update) { $forum_data = array('parent_id' => BUGS_FORUM_ID, 'forum_type' => FORUM_POST, 'forum_status' => ITEM_UNLOCKED, 'forum_name' => utf8_normalize_nfc(request_var('forum_name', '', true)), 'project_idname' => '', 'forum_link' => '', 'forum_link_track' => false, 'forum_desc' => '', 'forum_rules' => '', 'forum_rules_link' => '', 'forum_image' => '', 'forum_style' => 0, 'display_on_index' => false, 'forum_topics_per_page' => 0, 'enable_indexing' => true, 'enable_icons' => false, 'enable_prune' => false, 'prune_days' => 7, 'prune_viewed' => 7, 'prune_freq' => 1, 'forum_flags' => FORUM_FLAG_POST_REVIEW, 'forum_password' => '', 'forum_password_confirm' => ''); } } $forum_rules_data = array('text' => $forum_data['forum_rules'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $forum_desc_data = array('text' => $forum_data['forum_desc'], 'allow_bbcode' => true, 'allow_smilies' => true, 'allow_urls' => true); $forum_rules_preview = ''; // Parse rules if specified if ($forum_data['forum_rules']) { if (!isset($forum_data['forum_rules_uid'])) { // Before we are able to display the preview and plane text, we need to parse our request_var()'d value... $forum_data['forum_rules_uid'] = ''; $forum_data['forum_rules_bitfield'] = ''; $forum_data['forum_rules_options'] = 0; 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)); } // Generate preview content $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']); // decode... $forum_rules_data = generate_text_for_edit($forum_data['forum_rules'], $forum_data['forum_rules_uid'], $forum_data['forum_rules_options']); } // Parse desciption if specified if ($forum_data['forum_desc']) { if (!isset($forum_data['forum_desc_uid'])) { // Before we are able to display the preview and plane text, we need to parse our request_var()'d value... $forum_data['forum_desc_uid'] = ''; $forum_data['forum_desc_bitfield'] = ''; $forum_data['forum_desc_options'] = 0; 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)); } // decode... $forum_desc_data = generate_text_for_edit($forum_data['forum_desc'], $forum_data['forum_desc_uid'], $forum_data['forum_desc_options']); } $styles_list = style_select($forum_data['forum_style'], true); $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>'; $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . "\n\t\t\t\t\t\t\tAND forum_id <> {$forum_id}"; $result = $db->sql_query($sql); if ($db->sql_fetchrow($result)) { $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $forum_id, false, true, false))); } $db->sql_freeresult($result); // Subforum move options if ($action == 'edit' && $forum_data['forum_type'] == FORUM_CAT) { $subforums_id = array(); $subforums = get_forum_branch($forum_id, 'children'); foreach ($subforums as $row) { $subforums_id[] = $row['forum_id']; } $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id); $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . "\n\t\t\t\t\t\t\t\tAND forum_id <> {$forum_id}"; $result = $db->sql_query($sql); if ($db->sql_fetchrow($result)) { $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id))); } $db->sql_freeresult($result); $template->assign_vars(array('S_HAS_SUBFORUMS' => $forum_data['right_id'] - $forum_data['left_id'] > 1 ? true : false, 'S_FORUMS_LIST' => $forums_list)); } $s_show_display_on_index = false; if ($forum_data['parent_id'] > 0) { // if this forum is a subforum put the "display on index" checkbox if ($parent_info = $this->parent->get_forum_info($forum_data['parent_id'])) { if ($parent_info['parent_id'] > 0 || $parent_info['forum_type'] == FORUM_CAT) { $s_show_display_on_index = true; } } } $template->assign_vars(array('S_EDIT_FORUM' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_PARENT_ID' => BUGS_FORUM_ID, 'S_FORUM_PARENT_ID' => $forum_data['parent_id'], 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, 'U_EDIT_ACTION' => $this->u_action . "&parent_id={$this->parent_id}&action={$action}&f={$forum_id}", 'L_COPY_PERMISSIONS_EXPLAIN' => $user->lang['COPY_PERMISSIONS_' . strtoupper($action) . '_EXPLAIN'], 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'FORUM_NAME' => $forum_data['forum_name'], 'PROJECT_IDNAME' => $forum_data['project_idname'], 'FORUM_DATA_LINK' => $forum_data['forum_link'], 'FORUM_IMAGE' => $forum_data['forum_image'], 'FORUM_IMAGE_SRC' => $forum_data['forum_image'] ? $phpbb_root_path . $forum_data['forum_image'] : '', 'FORUM_POST' => FORUM_POST, 'FORUM_LINK' => FORUM_LINK, 'FORUM_CAT' => FORUM_CAT, 'PRUNE_FREQ' => $forum_data['prune_freq'], 'PRUNE_DAYS' => $forum_data['prune_days'], 'PRUNE_VIEWED' => $forum_data['prune_viewed'], 'TOPICS_PER_PAGE' => $forum_data['forum_topics_per_page'], 'FORUM_PASSWORD' => $forum_data['forum_password'], 'FORUM_PASSWORD_CONFIRM' => $forum_data['forum_password_confirm'], 'FORUM_RULES_LINK' => $forum_data['forum_rules_link'], 'FORUM_RULES' => $forum_data['forum_rules'], 'FORUM_RULES_PREVIEW' => $forum_rules_preview, 'FORUM_RULES_PLAIN' => $forum_rules_data['text'], 'S_BBCODE_CHECKED' => $forum_rules_data['allow_bbcode'] ? true : false, 'S_SMILIES_CHECKED' => $forum_rules_data['allow_smilies'] ? true : false, 'S_URLS_CHECKED' => $forum_rules_data['allow_urls'] ? true : false, 'FORUM_DESC' => $forum_desc_data['text'], 'S_DESC_BBCODE_CHECKED' => $forum_desc_data['allow_bbcode'] ? true : false, 'S_DESC_SMILIES_CHECKED' => $forum_desc_data['allow_smilies'] ? true : false, 'S_DESC_URLS_CHECKED' => $forum_desc_data['allow_urls'] ? true : false, 'S_STATUS_OPTIONS' => $statuslist, 'S_STYLES_OPTIONS' => $styles_list, 'S_FORUM_OPTIONS' => make_forum_select($action == 'add' ? $forum_data['parent_id'] : false, $action == 'edit' ? $forum_data['forum_id'] : false, false, false, false), 'S_SHOW_DISPLAY_ON_INDEX' => $s_show_display_on_index, 'S_FORUM_POST' => $forum_data['forum_type'] == FORUM_POST ? true : false, 'S_FORUM_ORIG_POST' => isset($old_forum_type) && $old_forum_type == FORUM_POST ? true : false, 'S_FORUM_ORIG_CAT' => isset($old_forum_type) && $old_forum_type == FORUM_CAT ? true : false, 'S_FORUM_ORIG_LINK' => isset($old_forum_type) && $old_forum_type == FORUM_LINK ? true : false, 'S_FORUM_LINK' => $forum_data['forum_type'] == FORUM_LINK ? true : false, 'S_FORUM_CAT' => $forum_data['forum_type'] == FORUM_CAT ? true : false, 'S_ENABLE_INDEXING' => $forum_data['enable_indexing'] ? true : false, 'S_TOPIC_ICONS' => $forum_data['enable_icons'] ? true : false, 'S_DISPLAY_ON_INDEX' => $forum_data['display_on_index'] ? true : false, 'S_PRUNE_ENABLE' => $forum_data['enable_prune'] ? true : false, 'S_FORUM_LINK_TRACK' => $forum_data['forum_flags'] & FORUM_FLAG_LINK_TRACK ? true : false, 'S_PRUNE_OLD_POLLS' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_POLL ? true : false, 'S_PRUNE_ANNOUNCE' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_ANNOUNCE ? true : false, 'S_PRUNE_STICKY' => $forum_data['forum_flags'] & FORUM_FLAG_PRUNE_STICKY ? true : false, 'S_DISPLAY_ACTIVE_TOPICS' => $forum_data['forum_flags'] & FORUM_FLAG_ACTIVE_TOPICS ? true : false, 'S_ENABLE_POST_REVIEW' => $forum_data['forum_flags'] & FORUM_FLAG_POST_REVIEW ? true : false)); return; break; case 'delete': if (!$forum_id) { trigger_error($user->lang['NO_FORUM'] . adm_back_link($this->u_action . '&parent_id=' . $this->parent_id), E_USER_WARNING); } $forum_data = $this->parent->get_forum_info($forum_id); $subforums_id = array(); $subforums = get_forum_branch($forum_id, 'children'); foreach ($subforums as $row) { $subforums_id[] = $row['forum_id']; } $forums_list = make_forum_select($forum_data['parent_id'], $subforums_id); $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' WHERE forum_type = ' . FORUM_POST . "\n\t\t\t\t\t\t\tAND forum_id <> {$forum_id}"; $result = $db->sql_query($sql); if ($db->sql_fetchrow($result)) { $template->assign_vars(array('S_MOVE_FORUM_OPTIONS' => make_forum_select($forum_data['parent_id'], $subforums_id, false, true))); } $db->sql_freeresult($result); $parent_id = $this->parent_id == $forum_id ? 0 : $this->parent_id; $template->assign_vars(array('S_DELETE_FORUM' => true, 'U_ACTION' => $this->u_action . "&parent_id={$parent_id}&action=delete&f={$forum_id}", 'U_BACK' => $this->u_action . '&parent_id=' . $this->parent_id, 'FORUM_NAME' => $forum_data['forum_name'], 'S_FORUM_POST' => $forum_data['forum_type'] == FORUM_POST ? true : false, 'S_FORUM_LINK' => $forum_data['forum_type'] == FORUM_LINK ? true : false, 'S_HAS_SUBFORUMS' => $forum_data['right_id'] - $forum_data['left_id'] > 1 ? true : false, 'S_FORUMS_LIST' => $forums_list, 'S_ERROR' => sizeof($errors) ? true : false, 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '')); return; break; } $navigation = $user->lang['BUG_TRACKER']; $this->page_title = 'BUG_TRACKER_PROJECTS'; $sql = 'SELECT bp.*, f.* FROM ' . BUGS_PROJECTS_TABLE . " bp,\n\t\t\t\t\t" . FORUMS_TABLE . " f \n\t\t\t\tWHERE bp.forum_id = f.forum_id\n\t\t\t\tORDER BY f.left_id"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { do { $url = $this->u_action . "&parent_id={$this->parent_id}&f={$row['forum_id']}"; $template->assign_block_vars('projects', array('FOLDER_IMAGE' => '<img src="images/icon_folder.gif" alt="' . $user->lang['FOLDER'] . '" />', 'PROJECT_IMAGE' => $row['forum_image'] ? '<img src="' . $phpbb_root_path . $row['forum_image'] . '" alt="" />' : '', 'PROJECT_IMAGE_SRC' => $row['forum_image'] ? $phpbb_root_path . $row['forum_image'] : '', 'PROJECT_NAME' => $row['forum_name'], 'PROJECT_DESCRIPTION' => generate_text_for_display($row['forum_desc'], $row['forum_desc_uid'], $row['forum_desc_bitfield'], $row['forum_desc_options']), 'PROJECT_TOPICS' => $row['forum_topics'], 'PROJECT_POSTS' => $row['forum_posts'], 'U_PROJECT' => $this->u_action . '&parent_id=' . $row['forum_id'], 'U_MOVE_UP' => $url . '&action=move_up', 'U_MOVE_DOWN' => $url . '&action=move_down', 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete')); } while ($row = $db->sql_fetchrow($result)); } $db->sql_freeresult($result); $template->assign_vars(array('ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'NAVIGATION' => $navigation, 'U_SEL_ACTION' => $this->u_action, 'U_ACTION' => $this->u_action . '&parent_id=' . $this->parent_id)); } elseif ($mode == 'statuses') { $action = request_var('action', ''); $update = isset($_POST['update']) ? true : false; $status_id = request_var('st', 0); if ($action == 'add' || $action == 'edit') { $errors = array(); $status_data = array('status_title' => utf8_normalize_nfc(request_var('status_title', '', true)), 'status_closed' => intval((bool) request_var('status_closed', 0))); if ($action == 'add') { $this->page_title = 'ADD_STATUS'; if ($update) { $sql = 'INSERT INTO ' . BUGS_STATUSES_TABLE . ' ' . $db->sql_build_array('INSERT', $status_data); $db->sql_query($sql); trigger_error($user->lang['STATUS_ADDED'] . adm_back_link($this->u_action)); } } elseif ($action == 'edit') { $this->page_title = 'EDIT_STATUS'; if ($update) { $sql = 'UPDATE ' . BUGS_STATUSES_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $status_data) . ' WHERE status_id = ' . $status_id; $result = $db->sql_query($sql); trigger_error($user->lang['STATUS_EDITED'] . adm_back_link($this->u_action)); } else { // Query the status details $sql = 'SELECT * FROM ' . BUGS_STATUSES_TABLE . " WHERE status_id = '{$status_id}'"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $status_data['status_closed'] = $row['status_closed']; $status_data['status_title'] = $row['status_title']; } else { trigger_error($user->lang['NO_STATUS'] . adm_back_link($this->u_action), E_USER_WARNING); } } } $template->assign_vars(array('S_EDIT_STATUS' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action, 'U_EDIT_ACTION' => $this->u_action . "&action={$action}&st={$status_id}", 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'STATUS_TITLE' => $status_data['status_title'], 'S_STATUS_CLOSED' => $status_data['status_closed'] ? true : false)); return; } switch ($action) { case 'add': $template->assign_vars(array('S_STATUS_ADD' => true, 'U_ACTION' => $this->u_action)); return; break; case 'edit': $template->assign_vars(array('S_STATUS_EDIT' => true, 'U_ACTION' => $this->u_action)); return; break; } if ($action == 'delete') { // Make sure the status exists $sql = 'SELECT status_id FROM ' . BUGS_STATUSES_TABLE . ' WHERE status_id = ' . $status_id; $result = $db->sql_query($sql); if (!$db->sql_fetchrow($result)) { trigger_error('NO_STATUS', E_USER_WARNING); } if (confirm_box(true)) { // Bugs having this status assigned will have a status id of 1 $sql = 'UPDATE ' . BUGS_REPORTS_TABLE . " \n\t\t\t\t\t\tSET report_status = '1'\n\t\t\t\t\t\tWHERE report_status = '{$status_id}'"; $result = $db->sql_query($sql); // Now, remove the status $sql = 'DELETE FROM ' . BUGS_STATUSES_TABLE . " \n\t\t\t\t\t\tWHERE status_id = '{$status_id}'"; $result = $db->sql_query($sql); trigger_error($user->lang['STATUS_DELETED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('st' => $status_id, 'mode' => $mode, 'action' => $action))); } } $this->page_title = 'BUG_TRACKER_STATUSES'; // Query the statuses $sql = 'SELECT * FROM ' . BUGS_STATUSES_TABLE . ' ORDER BY status_closed ASC, status_title ASC'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $url = $this->u_action . '&st=' . $row['status_id']; $template->assign_block_vars('statuses', array('STATUS_TITLE' => $row['status_title'], 'STATUS_CLOSED' => $row['status_closed'] ? $user->lang['STATUS_CLOSED'] : $user->lang['STATUS_OPEN'], 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete')); } $template->assign_vars(array('S_STATUSES' => true, 'U_ACTION' => $this->u_action)); } elseif ($mode == 'versions') { $action = request_var('action', ''); $update = isset($_POST['update']) ? true : false; $version_id = request_var('v', 0); if ($action == 'add' || $action == 'edit') { $errors = array(); $version_data = array('project_id' => request_var('project_id', 0), 'version_title' => utf8_normalize_nfc(request_var('version_title', '', true)), 'accept_new' => intval((bool) request_var('accept_new', 1))); if ($action == 'add') { $this->page_title = 'ADD_VERSION'; if ($update) { // Validate project $sql = 'SELECT project_id FROM ' . BUGS_PROJECTS_TABLE . ' WHERE project_id = ' . $version_data['project_id']; $result = $db->sql_query($sql); if (!$db->sql_fetchrow($result)) { trigger_error($user->lang['NO_PROJECT'] . adm_back_link($this->u_action)); } $sql = 'INSERT INTO ' . BUGS_VERSIONS_TABLE . ' ' . $db->sql_build_array('INSERT', $version_data); $db->sql_query($sql); trigger_error($user->lang['VERSION_ADDED'] . adm_back_link($this->u_action)); } } elseif ($action == 'edit') { $this->page_title = 'EDIT_VERSION'; if ($update) { unset($version_data['project_id']); // Do not update that - versions cannot be transferred to other projects $sql = 'UPDATE ' . BUGS_VERSIONS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $version_data) . ' WHERE version_id = ' . $version_id; $result = $db->sql_query($sql); trigger_error($user->lang['VERSION_EDITED'] . adm_back_link($this->u_action)); } else { // Query the version details $sql = 'SELECT v.*, p.project_title FROM ' . BUGS_VERSIONS_TABLE . ' v LEFT JOIN ' . BUGS_PROJECTS_TABLE . " p ON v.project_id = p.project_id\n\t\t\t\t\t\t\tWHERE version_id = '{$version_id}'"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $version_data['version_title'] = $row['version_title']; $version_data['project_id'] = $row['project_id']; $version_data['project_title'] = $row['project_title']; $version_data['accept_new'] = $row['accept_new']; } else { trigger_error($user->lang['NO_VERSION'] . adm_back_link($this->u_action), E_USER_WARNING); } } } $projects_list = ''; $sql = 'SELECT project_id, project_title FROM ' . BUGS_PROJECTS_TABLE . ' ORDER BY project_title'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $projects_list .= '<option value="' . $row['project_id'] . '" ' . ($row['project_id'] == $version_data['project_id'] ? ' selected="selected"' : '') . '>' . $row['project_title'] . '</option>'; } $template->assign_vars(array('S_EDIT_VERSION' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action, 'U_EDIT_ACTION' => $this->u_action . "&action={$action}&v={$version_id}", 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'VERSION_TITLE' => $version_data['version_title'], 'S_PROJECT_OPTIONS' => $projects_list, 'S_ACCEPT_NEW' => $version_data['accept_new'] ? true : false)); } switch ($action) { case 'add': $template->assign_vars(array('S_VERSION_ADD' => true, 'U_ACTION' => $this->u_action)); return; break; case 'edit': $template->assign_vars(array('PROJECT_TITLE' => $version_data['project_title'], 'S_VERSION_EDIT' => true, 'U_ACTION' => $this->u_action)); return; break; } if ($action == 'delete') { // Make sure the version exists $sql = 'SELECT version_id FROM ' . BUGS_VERSIONS_TABLE . ' WHERE version_id = ' . $version_id; $result = $db->sql_query($sql); if (!$db->sql_fetchrow($result)) { trigger_error('NO_VERSION', E_USER_WARNING); } if (confirm_box(true)) { // Bugs having this version assigned will have a version id of 1 $sql = 'UPDATE ' . BUGS_REPORTS_TABLE . " \n\t\t\t\t\t\tSET report_version = 1\n\t\t\t\t\t\tWHERE report_version = '{$version_id}'"; $result = $db->sql_query($sql); // Now, remove the version $sql = 'DELETE FROM ' . BUGS_VERSIONS_TABLE . " \n\t\t\t\t\t\tWHERE version_id = '{$version_id}'"; $result = $db->sql_query($sql); if (!$result) { trigger_error('NO_VERSION', E_USER_WARNING); } trigger_error($user->lang['VERSION_DELETED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('v' => $version_id, 'mode' => $mode, 'action' => $action))); } } $this->page_title = 'BUG_TRACKER_VERSIONS'; $sql = $db->sql_build_query('SELECT', array('SELECT' => 'v.*, p.project_title', 'FROM' => array(BUGS_VERSIONS_TABLE => 'v'), 'LEFT_JOIN' => array(array('FROM' => array(BUGS_PROJECTS_TABLE => 'p'), 'ON' => 'v.project_id = p.project_id')), 'ORDER_BY' => 'p.project_title, v.version_id')); $result = $db->sql_query($sql); $cur_project = 0; while ($row = $db->sql_fetchrow($result)) { if ($row['project_id'] != $cur_project) { $template->assign_block_vars('projects', array('PROJECT_TITLE' => sprintf($user->lang['PROJECT_NAMED'], $row['project_title']))); $cur_project = $row['project_id']; } $url = $this->u_action . '&v=' . $row['version_id']; $template->assign_block_vars('projects.versions', array('VERSION_TITLE' => $row['version_title'], 'VERSION_ACCEPT_NEW' => $row['accept_new'] ? $user->lang['YES'] : $user->lang['NO'], 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete')); } $template->assign_vars(array('S_VERSIONS' => true, 'U_ACTION' => $this->u_action)); } elseif ($mode == 'components') { $action = request_var('action', ''); $update = isset($_POST['update']) ? true : false; $component_id = request_var('c', 0); if ($action == 'add' || $action == 'edit') { $errors = array(); $component_data = array('project_id' => request_var('project_id', 0), 'component_title' => utf8_normalize_nfc(request_var('component_title', '', true))); if ($action == 'add') { $this->page_title = 'ADD_COMPONENT'; if ($update) { // Validate project $sql = 'SELECT project_id FROM ' . BUGS_PROJECTS_TABLE . ' WHERE project_id = ' . $component_data['project_id']; $result = $db->sql_query($sql); if (!$db->sql_fetchrow($result)) { trigger_error($user->lang['NO_PROJECT'] . adm_back_link($this->u_action)); } $sql = 'INSERT INTO ' . BUGS_COMPONENTS_TABLE . ' ' . $db->sql_build_array('INSERT', $component_data); $db->sql_query($sql); trigger_error($user->lang['COMPONENT_ADDED'] . adm_back_link($this->u_action)); } } elseif ($action == 'edit') { $this->page_title = 'EDIT_COMPONENT'; if ($update) { unset($component_data['project_id']); // Do not update that - components cannot be transferred to other projects $sql = 'UPDATE ' . BUGS_COMPONENTS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $component_data) . ' WHERE component_id = ' . $component_id; $result = $db->sql_query($sql); trigger_error($user->lang['COMPONENT_EDITED'] . adm_back_link($this->u_action)); } else { // Query the component details $sql = 'SELECT c.*, p.project_title FROM ' . BUGS_COMPONENTS_TABLE . ' c LEFT JOIN ' . BUGS_PROJECTS_TABLE . " p ON c.project_id = p.project_id\n\t\t\t\t\t\t\tWHERE component_id = '{$component_id}'"; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result)) { $component_data['component_title'] = $row['component_title']; $component_data['project_id'] = $row['project_id']; $component_data['project_title'] = $row['project_title']; } else { trigger_error($user->lang['NO_COMPONENT'] . adm_back_link($this->u_action), E_USER_WARNING); } } } $projects_list = ''; $sql = 'SELECT project_id, project_title FROM ' . BUGS_PROJECTS_TABLE . ' ORDER BY project_title'; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $projects_list .= '<option value="' . $row['project_id'] . '" ' . ($row['project_id'] == $component_data['project_id'] ? ' selected="selected"' : '') . '>' . $row['project_title'] . '</option>'; } $template->assign_vars(array('S_EDIT_COMPONENT' => true, 'S_ERROR' => sizeof($errors) ? true : false, 'S_ADD_ACTION' => $action == 'add' ? true : false, 'U_BACK' => $this->u_action, 'U_EDIT_ACTION' => $this->u_action . "&action={$action}&c={$component_id}", 'L_TITLE' => $user->lang[$this->page_title], 'ERROR_MSG' => sizeof($errors) ? implode('<br />', $errors) : '', 'COMPONENT_TITLE' => $component_data['component_title'], 'S_PROJECT_OPTIONS' => $projects_list)); } switch ($action) { case 'add': $template->assign_vars(array('S_COMPONENT_ADD' => true, 'U_ACTION' => $this->u_action)); return; break; case 'edit': $template->assign_vars(array('PROJECT_TITLE' => $component_data['project_title'], 'S_COMPONENT_EDIT' => true, 'U_ACTION' => $this->u_action)); return; break; } if ($action == 'delete') { // Make sure the component exists $sql = 'SELECT component_id FROM ' . BUGS_COMPONENTS_TABLE . ' WHERE component_id = ' . $component_id; $result = $db->sql_query($sql); if (!$db->sql_fetchrow($result)) { trigger_error('NO_COMPONENT', E_USER_WARNING); } if (confirm_box(true)) { // Bugs having this component assigned will have a component id of 1 $sql = 'UPDATE ' . BUGS_REPORTS_TABLE . " \n\t\t\t\t\t\tSET report_component = 1\n\t\t\t\t\t\tWHERE report_component = '{$component_id}'"; $result = $db->sql_query($sql); // Now, remove the version $sql = 'DELETE FROM ' . BUGS_COMPONENTS_TABLE . " \n\t\t\t\t\t\tWHERE component_id = '{$component_id}'"; $result = $db->sql_query($sql); if (!$result) { trigger_error('NO_COMPONENT', E_USER_WARNING); } trigger_error($user->lang['COMPONENT_DELETED'] . adm_back_link($this->u_action)); } else { confirm_box(false, $user->lang['CONFIRM_OPERATION'], build_hidden_fields(array('c' => $component_id, 'mode' => $mode, 'action' => $action))); } } $this->page_title = 'BUG_TRACKER_COMPONENTS'; $sql = $db->sql_build_query('SELECT', array('SELECT' => 'c.*, p.project_title', 'FROM' => array(BUGS_COMPONENTS_TABLE => 'c'), 'LEFT_JOIN' => array(array('FROM' => array(BUGS_PROJECTS_TABLE => 'p'), 'ON' => 'c.project_id = p.project_id')), 'ORDER_BY' => 'p.project_title, c.component_title')); $result = $db->sql_query($sql); $cur_project = 0; while ($row = $db->sql_fetchrow($result)) { if ($row['project_id'] != $cur_project) { $template->assign_block_vars('projects', array('PROJECT_TITLE' => sprintf($user->lang['PROJECT_NAMED'], $row['project_title']))); $cur_project = $row['project_id']; } $url = $this->u_action . '&c=' . $row['component_id']; $template->assign_block_vars('projects.components', array('COMPONENT_TITLE' => $row['component_title'], 'U_EDIT' => $url . '&action=edit', 'U_DELETE' => $url . '&action=delete')); } $template->assign_vars(array('S_COMPONENTS' => true, 'U_ACTION' => $this->u_action)); } }
/** * Returns an array containing all IDs of the forum's sub-forums (and their sub-forums) * * @param int $forum_id * @return array */ protected function get_subforum_ids($forum_id) { $subforum_ids = array(); foreach (get_forum_branch((int) $forum_id, 'children', 'descending', false) as $subforum) { $subforum_ids[] = (int) $subforum['forum_id']; } return $subforum_ids; }
function delete_forum($forum_id, $action_posts = 'delete', $action_subforums = 'delete', $posts_to_id = 0, $subforums_to_id = 0) { global $_CLASS; $row = get_forum_info($forum_id); extract($row); $errors = array(); $log_action_posts = $log_action_forums = ''; if ($action_posts == 'delete') { $_CLASS['core_db']->query('UPDATE ' . FORUMS_FORUMS_TABLE . ' SET forum_status = ' . ITEM_DELETING . ' WHERE forum_id = ' . $forum_id); $log_action_posts = 'POSTS'; if ($delete_error = delete_forum_content($forum_id)) { $errors[] = $delete_error; } } elseif ($action_posts == 'move') { if (!$posts_to_id) { $errors[] = $_CLASS['core_user']->lang['NO_DESTINATION_FORUM']; } else { $log_action_posts = 'MOVE_POSTS'; $sql = 'SELECT forum_name FROM ' . FORUMS_FORUMS_TABLE . ' WHERE forum_id = ' . $posts_to_id; $result = $_CLASS['core_db']->query($sql); if (!($row = $_CLASS['core_db']->fetch_row_assoc($result))) { $errors[] = $_CLASS['core_user']->lang['NO_FORUM']; } else { $posts_to_name = $row['forum_name']; unset($row); $errors[] = move_forum_content($forum_id, $subforums_to_id); } } } if (count($errors)) { return $errors; } if ($action_subforums == 'delete') { $log_action_forums = 'FORUMS'; $forum_ids = array($forum_id); $rows = get_forum_branch($forum_id, 'children', 'descending', FALSE); // Maybe add feild to the get_forum_branch foreach ($rows as $row) { $forum_ids[] = $row['forum_id']; } unset($rows); $_CLASS['core_db']->query('UPDATE ' . FORUMS_FORUMS_TABLE . ' SET forum_status = ' . ITEM_DELETING . ' WHERE forum_id IN (' . implode(', ', $forum_ids) . ')'); foreach ($forum_ids as $forum_id) { if ($delete_error = delete_forum_content($forum_id)) { $errors[] = $delete_error; } } if (count($errors)) { return $errors; } $diff = count($forum_ids) * 2; $sql = 'DELETE FROM ' . FORUMS_FORUMS_TABLE . ' WHERE forum_id IN (' . implode(', ', $forum_ids) . ')'; $_CLASS['core_db']->query($sql); } elseif ($action_subforums == 'move') { if (!$subforums_to_id) { $errors[] = $_CLASS['core_user']->lang['NO_DESTINATION_FORUM']; } else { $log_action_forums = 'MOVE_FORUMS'; $sql = 'SELECT forum_name FROM ' . FORUMS_FORUMS_TABLE . ' WHERE forum_id = ' . $subforums_to_id; $result = $_CLASS['core_db']->query($sql); if (!($row = $_CLASS['core_db']->fetch_row_assoc($result))) { $errors[] = $_CLASS['core_user']->lang['NO_FORUM']; } else { $subforums_to_name = $row['forum_name']; unset($row); $sql = 'SELECT forum_id FROM ' . FORUMS_FORUMS_TABLE . "\n\t\t\t\t\tWHERE parent_id = {$forum_id}"; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { move_forum($row['forum_id'], intval($_POST['subforums_to_id'])); } $_CLASS['core_db']->free_result($result); $sql = 'UPDATE ' . FORUMS_FORUMS_TABLE . "\n\t\t\t\t\tSET parent_id = {$subforums_to_id}\n\t\t\t\t\tWHERE parent_id = {$forum_id}"; $_CLASS['core_db']->query($sql); $diff = 2; $sql = 'DELETE FROM ' . FORUMS_FORUMS_TABLE . "\n\t\t\t\t\tWHERE forum_id = {$forum_id}"; $_CLASS['core_db']->query($sql); } } if (count($errors)) { return $errors; } } else { $diff = 2; $sql = 'DELETE FROM ' . FORUMS_FORUMS_TABLE . "\n\t\t\tWHERE forum_id = {$forum_id}"; $_CLASS['core_db']->query($sql); } // Resync tree $sql = 'UPDATE ' . FORUMS_FORUMS_TABLE . "\n\t\tSET right_id = right_id - {$diff}\n\t\tWHERE left_id < {$right_id} AND right_id > {$right_id}"; $_CLASS['core_db']->query($sql); $sql = 'UPDATE ' . FORUMS_FORUMS_TABLE . "\n\t\tSET left_id = left_id - {$diff}, right_id = right_id - {$diff}\n\t\tWHERE left_id > {$right_id}"; $_CLASS['core_db']->query($sql); if (!is_array($forum_ids)) { $forum_ids = array($forum_id); } // Delete forum ids from extension groups table $sql = 'SELECT group_id, allowed_forums FROM ' . EXTENSION_GROUPS_TABLE . "\n\t\tWHERE allowed_forums <> ''"; $result = $_CLASS['core_db']->query($sql); while ($row = $_CLASS['core_db']->fetch_row_assoc($result)) { $allowed_forums = unserialize(trim($row['allowed_forums'])); $allowed_forums = array_diff($allowed_forums, $forum_ids); $sql = 'UPDATE ' . EXTENSION_GROUPS_TABLE . " \n\t\t\tSET allowed_forums = '" . (sizeof($allowed_forums) ? serialize($allowed_forums) : '') . "'\n\t\t\tWHERE group_id = {$row['group_id']}"; $_CLASS['core_db']->query($sql); } $_CLASS['core_cache']->destroy('extensions'); $log_action = implode('_', array($log_action_posts, $log_action_forums)); switch ($log_action) { case 'MOVE_POSTS_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_MOVE_FORUMS', $posts_to_name, $subforums_to_name, $forum_name); break; case 'MOVE_POSTS_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS_FORUMS', $posts_to_name, $forum_name); break; case 'POSTS_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_POSTS_MOVE_FORUMS', $subforums_to_name, $forum_name); break; case '_MOVE_FORUMS': add_log('admin', 'LOG_FORUM_DEL_MOVE_FORUMS', $subforums_to_name, $forum_name); break; case 'MOVE_POSTS_': add_log('admin', 'LOG_FORUM_DEL_MOVE_POSTS', $posts_to_name, $forum_name); break; case 'POSTS_FORUMS': add_log('admin', 'LOG_FORUM_DEL_POSTS_FORUMS', $forum_name); break; case '_FORUMS': add_log('admin', 'LOG_FORUM_DEL_FORUMS', $forum_name); break; case 'POSTS_': add_log('admin', 'LOG_FORUM_DEL_POSTS', $forum_name); break; } return $errors; }
function main($id, $mode) { global $db, $user, $auth, $template, $cache; global $config, $phpbb_root_path, $phpbb_admin_path, $phpEx; include_once $phpbb_root_path . 'includes/functions_user.' . $phpEx; include_once $phpbb_root_path . 'includes/acp/auth.' . $phpEx; $auth_admin = new auth_admin(); $user->add_lang('acp/permissions'); $user->add_lang('acp/permissions_phpbb'); $this->tpl_name = 'acp_permissions'; // Trace has other vars if ($mode == 'trace') { $user_id = request_var('u', 0); $forum_id = request_var('f', 0); $permission = request_var('auth', ''); $this->tpl_name = 'permission_trace'; if ($user_id && isset($auth_admin->option_ids[$permission]) && $auth->acl_get('a_viewauth')) { $this->page_title = sprintf($user->lang['TRACE_PERMISSION'], $user->lang['acl_' . $permission]['lang']); $this->permission_trace($user_id, $forum_id, $permission); return; } trigger_error('NO_MODE'); } // Set some vars $action = request_var('action', array('' => 0)); $action = key($action); $action = isset($_POST['psubmit']) ? 'apply_permissions' : $action; $all_forums = request_var('all_forums', 0); $subforum_id = request_var('subforum_id', 0); $forum_id = request_var('forum_id', array(0)); $username = request_var('username', array(''), true); $usernames = request_var('usernames', '', true); $user_id = request_var('user_id', array(0)); $group_id = request_var('group_id', array(0)); $select_all_groups = request_var('select_all_groups', 0); // If select all groups is set, we pre-build the group id array (this option is used for other screens to link to the permission settings screen) if ($select_all_groups) { // Add default groups to selection $sql_and = $config['coppa_hide_groups'] ? " AND group_name NOT IN ('INACTIVE_COPPA', 'REGISTERED_COPPA')" : ''; $sql = 'SELECT group_id FROM ' . GROUPS_TABLE . ' WHERE group_type = ' . GROUP_SPECIAL . "\n\t\t\t\t{$sql_and}"; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { $group_id[] = $row['group_id']; } $db->sql_freeresult($result); } // Map usernames to ids and vice versa if ($usernames) { $username = explode("\n", $usernames); } unset($usernames); if (sizeof($username) && !sizeof($user_id)) { user_get_id_name($user_id, $username); if (!sizeof($user_id)) { trigger_error($user->lang['SELECTED_USER_NOT_EXIST'] . adm_back_link($this->u_action)); } } unset($username); // Build forum ids (of all forums are checked or subforum listing used) if ($all_forums) { $sql = 'SELECT forum_id FROM ' . FORUMS_TABLE . ' ORDER BY left_id'; $result = $db->sql_query($sql); $forum_id = array(); while ($row = $db->sql_fetchrow($result)) { $forum_id[] = $row['forum_id']; } $db->sql_freeresult($result); } else { if ($subforum_id) { $forum_id = array(); foreach (get_forum_branch($subforum_id, 'children') as $row) { $forum_id[] = $row['forum_id']; } } } // Define some common variables for every mode $error = array(); $permission_scope = strpos($mode, '_global') !== false ? 'global' : 'local'; // Showing introductionary page? if ($mode == 'intro') { $this->page_title = 'ACP_PERMISSIONS'; $template->assign_vars(array('S_INTRO' => true)); return; } switch ($mode) { case 'setting_user_global': case 'setting_group_global': $this->permission_dropdown = array('u_', 'm_', 'a_'); $permission_victim = $mode == 'setting_user_global' ? array('user') : array('group'); $this->page_title = $mode == 'setting_user_global' ? 'ACP_USERS_PERMISSIONS' : 'ACP_GROUPS_PERMISSIONS'; break; case 'setting_user_local': case 'setting_group_local': $this->permission_dropdown = array('f_', 'm_'); $permission_victim = $mode == 'setting_user_local' ? array('user', 'forums') : array('group', 'forums'); $this->page_title = $mode == 'setting_user_local' ? 'ACP_USERS_FORUM_PERMISSIONS' : 'ACP_GROUPS_FORUM_PERMISSIONS'; break; case 'setting_admin_global': case 'setting_mod_global': $this->permission_dropdown = strpos($mode, '_admin_') !== false ? array('a_') : array('m_'); $permission_victim = array('usergroup'); $this->page_title = $mode == 'setting_admin_global' ? 'ACP_ADMINISTRATORS' : 'ACP_GLOBAL_MODERATORS'; break; case 'setting_mod_local': case 'setting_forum_local': $this->permission_dropdown = $mode == 'setting_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup'); $this->page_title = $mode == 'setting_mod_local' ? 'ACP_FORUM_MODERATORS' : 'ACP_FORUM_PERMISSIONS'; break; case 'view_admin_global': case 'view_user_global': case 'view_mod_global': $this->permission_dropdown = $mode == 'view_admin_global' ? array('a_') : ($mode == 'view_user_global' ? array('u_') : array('m_')); $permission_victim = array('usergroup_view'); $this->page_title = $mode == 'view_admin_global' ? 'ACP_VIEW_ADMIN_PERMISSIONS' : ($mode == 'view_user_global' ? 'ACP_VIEW_USER_PERMISSIONS' : 'ACP_VIEW_GLOBAL_MOD_PERMISSIONS'); break; case 'view_mod_local': case 'view_forum_local': $this->permission_dropdown = $mode == 'view_mod_local' ? array('m_') : array('f_'); $permission_victim = array('forums', 'usergroup_view'); $this->page_title = $mode == 'view_mod_local' ? 'ACP_VIEW_FORUM_MOD_PERMISSIONS' : 'ACP_VIEW_FORUM_PERMISSIONS'; break; default: trigger_error('INVALID_MODE'); } $template->assign_vars(array('L_TITLE' => $user->lang[$this->page_title], 'L_EXPLAIN' => $user->lang[$this->page_title . '_EXPLAIN'])); // Get permission type $permission_type = request_var('type', $this->permission_dropdown[0]); if (!in_array($permission_type, $this->permission_dropdown)) { trigger_error($user->lang['WRONG_PERMISSION_TYPE'] . adm_back_link($this->u_action)); } // Handle actions if (strpos($mode, 'setting_') === 0 && $action) { switch ($action) { case 'delete': $this->remove_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id, $forum_id); break; case 'apply_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action)); } $this->set_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; case 'apply_all_permissions': if (!isset($_POST['setting'])) { trigger_error($user->lang['NO_AUTH_SETTING_FOUND'] . adm_back_link($this->u_action)); } $this->set_all_permissions($mode, $permission_type, $auth_admin, $user_id, $group_id); break; } } // Setting permissions screen $s_hidden_fields = build_hidden_fields(array('user_id' => $user_id, 'group_id' => $group_id, 'forum_id' => $forum_id, 'type' => $permission_type)); // Go through the screens/options needed and present them in correct order foreach ($permission_victim as $victim) { switch ($victim) { case 'forum_dropdown': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => make_forum_select(false, false, true, false, false))); break; case 'forums': if (sizeof($forum_id)) { $this->check_existence('forum', $forum_id); continue 2; } $forum_list = make_forum_select(false, false, true, false, false, true); // Build forum options $s_forum_options = ''; foreach ($forum_list as $f_id => $f_row) { $s_forum_options .= '<option value="' . $f_id . '"' . $f_row['selected'] . '>' . $f_row['padding'] . $f_row['forum_name'] . '</option>'; } // Build subforum options $s_subforum_options = $this->build_subforum_options($forum_list); $template->assign_vars(array('S_SELECT_FORUM' => true, 'S_FORUM_OPTIONS' => $s_forum_options, 'S_SUBFORUM_OPTIONS' => $s_subforum_options, 'S_FORUM_ALL' => true, 'S_FORUM_MULTIPLE' => true)); break; case 'user': if (sizeof($user_id)) { $this->check_existence('user', $user_id); continue 2; } $template->assign_vars(array('S_SELECT_USER' => true, 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=select_victim&field=username'))); break; case 'group': if (sizeof($group_id)) { $this->check_existence('group', $group_id); continue 2; } $template->assign_vars(array('S_SELECT_GROUP' => true, 'S_GROUP_OPTIONS' => group_select_options(false))); break; case 'usergroup': case 'usergroup_view': if (sizeof($user_id) || sizeof($group_id)) { if (sizeof($user_id)) { $this->check_existence('user', $user_id); } if (sizeof($group_id)) { $this->check_existence('group', $group_id); } continue 2; } $sql_forum_id = $permission_scope == 'global' ? 'AND a.forum_id = 0' : (sizeof($forum_id) ? 'AND a.forum_id IN (' . implode(', ', $forum_id) . ')' : 'AND a.forum_id <> 0'); $sql_permission_option = "AND o.auth_option LIKE '" . $db->sql_escape($permission_type) . "%'"; $sql = $db->sql_build_query('SELECT_DISTINCT', array('SELECT' => 'u.username, u.user_regdate, u.user_id', 'FROM' => array(USERS_TABLE => 'u', ACL_OPTIONS_TABLE => 'o', ACL_USERS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)\n\t\t\t\t\t\t\t{$sql_permission_option}\n\t\t\t\t\t\t\t{$sql_forum_id}\n\t\t\t\t\t\t\tAND u.user_id = a.user_id", 'ORDER_BY' => 'u.username, u.user_regdate ASC')); $result = $db->sql_query($sql); $s_defined_user_options = ''; $defined_user_ids = array(); while ($row = $db->sql_fetchrow($result)) { $s_defined_user_options .= '<option value="' . $row['user_id'] . '">' . $row['username'] . '</option>'; $defined_user_ids[] = $row['user_id']; } $db->sql_freeresult($result); $sql = $db->sql_build_query('SELECT_DISTINCT', array('SELECT' => 'g.group_type, g.group_name, g.group_id', 'FROM' => array(GROUPS_TABLE => 'g', ACL_OPTIONS_TABLE => 'o', ACL_GROUPS_TABLE => 'a'), 'LEFT_JOIN' => array(array('FROM' => array(ACL_ROLES_DATA_TABLE => 'r'), 'ON' => 'a.auth_role_id = r.role_id')), 'WHERE' => "(a.auth_option_id = o.auth_option_id OR r.auth_option_id = o.auth_option_id)\n\t\t\t\t\t\t\t{$sql_permission_option}\n\t\t\t\t\t\t\t{$sql_forum_id}\n\t\t\t\t\t\t\tAND g.group_id = a.group_id", 'ORDER_BY' => 'g.group_type DESC, g.group_name ASC')); $result = $db->sql_query($sql); $s_defined_group_options = ''; $defined_group_ids = array(); while ($row = $db->sql_fetchrow($result)) { $s_defined_group_options .= '<option' . ($row['group_type'] == GROUP_SPECIAL ? ' class="sep"' : '') . ' value="' . $row['group_id'] . '">' . ($row['group_type'] == GROUP_SPECIAL ? $user->lang['G_' . $row['group_name']] : $row['group_name']) . '</option>'; $defined_group_ids[] = $row['group_id']; } $db->sql_freeresult($result); // Now we check the users... because the "all"-selection is different here (all defined users/groups) $all_users = isset($_POST['all_users']) ? true : false; $all_groups = isset($_POST['all_groups']) ? true : false; if ($all_users && sizeof($defined_user_ids)) { $user_id = $defined_user_ids; continue 2; } if ($all_groups && sizeof($defined_group_ids)) { $group_id = $defined_group_ids; continue 2; } $template->assign_vars(array('S_SELECT_USERGROUP' => $victim == 'usergroup' ? true : false, 'S_SELECT_USERGROUP_VIEW' => $victim == 'usergroup_view' ? true : false, 'S_DEFINED_USER_OPTIONS' => $s_defined_user_options, 'S_DEFINED_GROUP_OPTIONS' => $s_defined_group_options, 'S_ADD_GROUP_OPTIONS' => group_select_options(false, $defined_group_ids), 'U_FIND_USERNAME' => append_sid("{$phpbb_root_path}memberlist.{$phpEx}", 'mode=searchuser&form=add_user&field=username'))); break; } $template->assign_vars(array('U_ACTION' => $this->u_action, 'ANONYMOUS_USER_ID' => ANONYMOUS, 'S_SELECT_VICTIM' => true, 'S_CAN_SELECT_USER' => $auth->acl_get('a_authusers') ? true : false, 'S_CAN_SELECT_GROUP' => $auth->acl_get('a_authgroups') ? true : false, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); // Let the forum names being displayed if (sizeof($forum_id)) { $sql = 'SELECT forum_name FROM ' . FORUMS_TABLE . ' WHERE forum_id IN (' . implode(', ', $forum_id) . ') ORDER BY forum_name ASC'; $result = $db->sql_query($sql); $forum_names = array(); while ($row = $db->sql_fetchrow($result)) { $forum_names[] = $row['forum_name']; } $db->sql_freeresult($result); $template->assign_vars(array('S_FORUM_NAMES' => sizeof($forum_names) ? true : false, 'FORUM_NAMES' => implode(', ', $forum_names))); } return; } // Do not allow forum_ids being set and no other setting defined (will bog down the server too much) if (sizeof($forum_id) && !sizeof($user_id) && !sizeof($group_id)) { trigger_error($user->lang['ONLY_FORUM_DEFINED'] . adm_back_link($this->u_action)); } $template->assign_vars(array('S_PERMISSION_DROPDOWN' => sizeof($this->permission_dropdown) > 1 ? $this->build_permission_dropdown($this->permission_dropdown, $permission_type) : false, 'L_PERMISSION_TYPE' => $user->lang['ACL_TYPE_' . strtoupper($permission_type)], 'U_ACTION' => $this->u_action, 'S_HIDDEN_FIELDS' => $s_hidden_fields)); if (strpos($mode, 'setting_') === 0) { $template->assign_vars(array('S_SETTING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('set', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_UNSET); $auth_admin->display_mask('set', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } else { $template->assign_vars(array('S_VIEWING_PERMISSIONS' => true)); $hold_ary = $auth_admin->get_mask('view', sizeof($user_id) ? $user_id : false, sizeof($group_id) ? $group_id : false, sizeof($forum_id) ? $forum_id : false, $permission_type, $permission_scope, ACL_NO); $auth_admin->display_mask('view', $permission_type, $hold_ary, sizeof($user_id) ? 'user' : 'group', $permission_scope == 'local' ? true : false); } }
?> " value="*"<?php echo $selected_ignore; ?> /></td> <?php } ?> </tr> <?php } // If we're setting forum or moderator options and a single forum has // been selected then look to see if any subforums exist. If they do // give user the option of cascading permissions to them if (($mode == 'forum' || $mode == 'mod') && empty($submode) && sizeof($forum_id[$which_mode]) == 1) { $children = get_forum_branch($forum_id[$which_mode][0], 'children', 'descending', false); if (!empty($children)) { ?> <tr> <th colspan="<?php echo $colspan; ?> "><?php echo $_CLASS['core_user']->lang['ACL_SUBFORUMS']; ?> </th> </tr> <tr> <td class="row1" colspan="<?php echo $colspan; ?>