From 3b06ee0d381dc1be5f40ca98ad4278046d869d21 Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Sun, 17 Nov 2019 20:57:39 +0100 Subject: checked in initial customized verison for Archlinux32 --- admin_groups.php | 645 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 645 insertions(+) create mode 100644 admin_groups.php (limited to 'admin_groups.php') diff --git a/admin_groups.php b/admin_groups.php new file mode 100644 index 0000000..db205d7 --- /dev/null +++ b/admin_groups.php @@ -0,0 +1,645 @@ +query('SELECT * FROM '.$db->prefix.'groups ORDER BY g_id') or error('Unable to fetch user groups', __FILE__, __LINE__, $db->error()); +$groups = array(); +while ($cur_group = $db->fetch_assoc($result)) + $groups[$cur_group['g_id']] = $cur_group; + +// Add/edit a group (stage 1) +if (isset($_POST['add_group']) || isset($_GET['edit_group'])) +{ + if (isset($_POST['add_group'])) + { + $base_group = intval($_POST['base_group']); + $group = $groups[$base_group]; + + $mode = 'add'; + } + else // We are editing a group + { + $group_id = intval($_GET['edit_group']); + if ($group_id < 1 || !isset($groups[$group_id])) + message($lang_common['Bad request'], false, '404 Not Found'); + + $group = $groups[$group_id]; + + $mode = 'edit'; + } + + + $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']); + $required_fields = array('req_title' => $lang_admin_groups['Group title label']); + $focus_element = array('groups2', 'req_title'); + define('PUN_ACTIVE_PAGE', 'admin'); + require PUN_ROOT.'header.php'; + + generate_admin_menu('groups'); + +?> +
+

+
+
+

+
+ + + +
+ +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ +
+ + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + + +
+ + +
+ + +
+ + +
+ + +
+

+
+
+
+

+
+
+
+
+ += 0) ? intval($_POST['post_flood']) : '0'; + $search_flood = (isset($_POST['search_flood']) && $_POST['search_flood'] >= 0) ? intval($_POST['search_flood']) : '0'; + $email_flood = (isset($_POST['email_flood']) && $_POST['email_flood'] >= 0) ? intval($_POST['email_flood']) : '0'; + $report_flood = (isset($_POST['report_flood']) && $_POST['report_flood'] >= 0) ? intval($_POST['report_flood']) : '0'; + + if ($title == '') + message($lang_admin_groups['Must enter title message']); + + $user_title = ($user_title != '') ? '\''.$db->escape($user_title).'\'' : 'NULL'; + + if ($_POST['mode'] == 'add') + { + $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\'') or error('Unable to check group title collision', __FILE__, __LINE__, $db->error()); + if ($db->num_rows($result)) + message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title))); + + $db->query('INSERT INTO '.$db->prefix.'groups (g_title, g_user_title, g_promote_min_posts, g_promote_next_group, g_moderator, g_mod_edit_users, g_mod_rename_users, g_mod_change_passwords, g_mod_ban_users, g_mod_promote_users, g_read_board, g_view_users, g_post_replies, g_post_topics, g_edit_posts, g_delete_posts, g_delete_topics, g_post_links, g_set_title, g_search, g_search_users, g_send_email, g_post_flood, g_search_flood, g_email_flood, g_report_flood) VALUES(\''.$db->escape($title).'\', '.$user_title.', '.$promote_min_posts.', '.$promote_next_group.', '.$moderator.', '.$mod_edit_users.', '.$mod_rename_users.', '.$mod_change_passwords.', '.$mod_ban_users.', '.$mod_promote_users.', '.$read_board.', '.$view_users.', '.$post_replies.', '.$post_topics.', '.$edit_posts.', '.$delete_posts.', '.$delete_topics.', '.$post_links.', '.$set_title.', '.$search.', '.$search_users.', '.$send_email.', '.$post_flood.', '.$search_flood.', '.$email_flood.', '.$report_flood.')') or error('Unable to add group', __FILE__, __LINE__, $db->error()); + $new_group_id = $db->insert_id(); + + // Now lets copy the forum specific permissions from the group which this group is based on + $result = $db->query('SELECT forum_id, read_forum, post_replies, post_topics FROM '.$db->prefix.'forum_perms WHERE group_id='.intval($_POST['base_group'])) or error('Unable to fetch group forum permission list', __FILE__, __LINE__, $db->error()); + while ($cur_forum_perm = $db->fetch_assoc($result)) + $db->query('INSERT INTO '.$db->prefix.'forum_perms (group_id, forum_id, read_forum, post_replies, post_topics) VALUES('.$new_group_id.', '.$cur_forum_perm['forum_id'].', '.$cur_forum_perm['read_forum'].', '.$cur_forum_perm['post_replies'].', '.$cur_forum_perm['post_topics'].')') or error('Unable to insert group forum permissions', __FILE__, __LINE__, $db->error()); + } + else + { + $result = $db->query('SELECT 1 FROM '.$db->prefix.'groups WHERE g_title=\''.$db->escape($title).'\' AND g_id!='.intval($_POST['group_id'])) or error('Unable to check group title collision', __FILE__, __LINE__, $db->error()); + if ($db->num_rows($result)) + message(sprintf($lang_admin_groups['Title already exists message'], pun_htmlspecialchars($title))); + + $db->query('UPDATE '.$db->prefix.'groups SET g_title=\''.$db->escape($title).'\', g_user_title='.$user_title.', g_promote_min_posts='.$promote_min_posts.', g_promote_next_group='.$promote_next_group.', g_moderator='.$moderator.', g_mod_edit_users='.$mod_edit_users.', g_mod_rename_users='.$mod_rename_users.', g_mod_change_passwords='.$mod_change_passwords.', g_mod_ban_users='.$mod_ban_users.', g_mod_promote_users='.$mod_promote_users.', g_read_board='.$read_board.', g_view_users='.$view_users.', g_post_replies='.$post_replies.', g_post_topics='.$post_topics.', g_edit_posts='.$edit_posts.', g_delete_posts='.$delete_posts.', g_delete_topics='.$delete_topics.', g_post_links='.$post_links.', g_set_title='.$set_title.', g_search='.$search.', g_search_users='.$search_users.', g_send_email='.$send_email.', g_post_flood='.$post_flood.', g_search_flood='.$search_flood.', g_email_flood='.$email_flood.', g_report_flood='.$report_flood.' WHERE g_id='.intval($_POST['group_id'])) or error('Unable to update group', __FILE__, __LINE__, $db->error()); + + // Promote all users who would be promoted to this group on their next post + if ($promote_next_group) + $db->query('UPDATE '.$db->prefix.'users SET group_id = '.$promote_next_group.' WHERE group_id = '.intval($_POST['group_id']).' AND num_posts >= '.$promote_min_posts) or error('Unable to auto-promote existing users', __FILE__, __LINE__, $db->error()); + } + + // Regenerate the quick jump cache + if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) + require PUN_ROOT.'include/cache.php'; + + $group_id = $_POST['mode'] == 'add' ? $new_group_id : intval($_POST['group_id']); + generate_quickjump_cache($group_id); + + if ($_POST['mode'] == 'edit') + redirect('admin_groups.php', $lang_admin_groups['Group edited redirect']); + else + redirect('admin_groups.php', $lang_admin_groups['Group added redirect']); +} + + +// Set default group +else if (isset($_POST['set_default_group'])) +{ + confirm_referrer('admin_groups.php'); + + $group_id = intval($_POST['default_group']); + + // Make sure it's not the admin or guest groups + if ($group_id == PUN_ADMIN || $group_id == PUN_GUEST) + message($lang_common['Bad request'], false, '404 Not Found'); + + // Make sure it's not a moderator group + if ($groups[$group_id]['g_moderator'] != 0) + message($lang_common['Bad request'], false, '404 Not Found'); + + $db->query('UPDATE '.$db->prefix.'config SET conf_value='.$group_id.' WHERE conf_name=\'o_default_user_group\'') or error('Unable to update board config', __FILE__, __LINE__, $db->error()); + + // Regenerate the config cache + if (!defined('FORUM_CACHE_FUNCTIONS_LOADED')) + require PUN_ROOT.'include/cache.php'; + + generate_config_cache(); + + redirect('admin_groups.php', $lang_admin_groups['Default group redirect']); +} + + +// Remove a group +else if (isset($_GET['del_group'])) +{ + confirm_referrer('admin_groups.php'); + + $group_id = isset($_POST['group_to_delete']) ? intval($_POST['group_to_delete']) : intval($_GET['del_group']); + if ($group_id < 5) + message($lang_common['Bad request'], false, '404 Not Found'); + + // Make sure we don't remove the default group + if ($group_id == $pun_config['o_default_user_group']) + message($lang_admin_groups['Cannot remove default message']); + + // Check if this group has any members + $result = $db->query('SELECT g.g_title, COUNT(u.id) FROM '.$db->prefix.'groups AS g INNER JOIN '.$db->prefix.'users AS u ON g.g_id=u.group_id WHERE g.g_id='.$group_id.' GROUP BY g.g_id, g_title') or error('Unable to fetch group info', __FILE__, __LINE__, $db->error()); + + // If the group doesn't have any members or if we've already selected a group to move the members to + if (!$db->num_rows($result) || isset($_POST['del_group'])) + { + if (isset($_POST['del_group_comply']) || isset($_POST['del_group'])) + { + if (isset($_POST['del_group'])) + { + $move_to_group = intval($_POST['move_to_group']); + $db->query('UPDATE '.$db->prefix.'users SET group_id='.$move_to_group.' WHERE group_id='.$group_id) or error('Unable to move users into group', __FILE__, __LINE__, $db->error()); + } + + // Delete the group and any forum specific permissions + $db->query('DELETE FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to delete group', __FILE__, __LINE__, $db->error()); + $db->query('DELETE FROM '.$db->prefix.'forum_perms WHERE group_id='.$group_id) or error('Unable to delete group forum permissions', __FILE__, __LINE__, $db->error()); + + // Don't let users be promoted to this group + $db->query('UPDATE '.$db->prefix.'groups SET g_promote_next_group=0 WHERE g_promote_next_group='.$group_id) or error('Unable to remove group as promotion target', __FILE__, __LINE__, $db->error()); + + redirect('admin_groups.php', $lang_admin_groups['Group removed redirect']); + } + else + { + $result = $db->query('SELECT g_title FROM '.$db->prefix.'groups WHERE g_id='.$group_id) or error('Unable to fetch group title', __FILE__, __LINE__, $db->error()); + $group_title = $db->result($result); + + $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']); + define('PUN_ACTIVE_PAGE', 'admin'); + require PUN_ROOT.'header.php'; + + generate_admin_menu('groups'); + +?> +
+

+
+
+
+ +
+ +
+

+

+
+
+
+

+
+
+
+
+ +fetch_row($result); + + $page_title = array(pun_htmlspecialchars($pun_config['o_board_title']), $lang_admin_common['Admin'], $lang_admin_common['User groups']); + define('PUN_ACTIVE_PAGE', 'admin'); + require PUN_ROOT.'header.php'; + + generate_admin_menu('groups'); + +?> +
+

+
+
+
+
+ +
+

+ +
+
+
+

+
+
+
+
+ + +
+

+
+
+
+
+ +
+ + + + + +
+ + +
+
+
+
+
+
+ +
+ + + + + +
+ + +
+
+
+
+
+
+ +

+
+
+
+
+ +
+

+ +'."\n"; + +?> +
'.$lang_admin_groups['Edit link'].''.(($cur_group['g_id'] > PUN_MEMBER) ? ' | '.$lang_admin_groups['Delete link'].'' : '').''.pun_htmlspecialchars($cur_group['g_title']).'
+
+
+
+
+
+
+
+ +