From 70cd3101974c0d56d1788b87f6fb8005395f55cb Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Fri, 31 Jan 2003 15:38:13 +0000 Subject: [PATCH] Some initial re-working ... git-svn-id: file:///svn/phpbb/trunk@3440 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/admin/admin_groups.php | 578 +++++++++++++++-------------------- 1 file changed, 245 insertions(+), 333 deletions(-) diff --git a/phpBB/admin/admin_groups.php b/phpBB/admin/admin_groups.php index 94771d4fe6..ad682f7cf4 100644 --- a/phpBB/admin/admin_groups.php +++ b/phpBB/admin/admin_groups.php @@ -19,402 +19,314 @@ * ***************************************************************************/ -if( !empty($setmodules) ) +if (!empty($setmodules) ) { - if ( !$auth->acl_get('a_group') ) + if (!$auth->acl_get('a_group') ) { return; } - $filename = basename(__FILE__); - $module['GROUP']['CREATE'] = $filename . "$SID&mode=create"; - $module['GROUP']['MANAGE'] = $filename . "$SID&mode=manage"; + $module['GROUP']['MANAGE'] = basename(__FILE__) . "$SID"; return; } define('IN_PHPBB', 1); -// // Include files -// $phpbb_root_path = '../'; require($phpbb_root_path . 'extension.inc'); require('pagestart.' . $phpEx); -// // Do we have general permissions? -// -if ( !$auth->acl_get('a_group') ) +if (!$auth->acl_get('a_group') ) { - message_die(MESSAGE, $user->lang['No_admin']); + trigger_error($user->lang['NO_ADMIN']); } -if( isset($_POST[POST_GROUPS_URL]) || isset($_GET[POST_GROUPS_URL]) ) + +// Check and set some common vars +$action = (isset($_REQUEST['action']))? $_REQUEST['action'] : ((isset($_POST['addgroup'])) ? 'addgroup' : ''); +$group_id = (isset($_REQUEST['g']))? intval($_REQUEST['g']) : ''; + +// Which page? +page_header($user->lang['MANAGE']); + +switch ($action) { - $group_id = ( isset($_POST[POST_GROUPS_URL]) ) ? intval($_POST[POST_GROUPS_URL]) : intval($_GET[POST_GROUPS_URL]); -} -else -{ - $group_id = ''; -} + case 'edit': + case 'addgroup': -// -// Mode setting -// -if( isset($_POST['mode']) || isset($_GET['mode']) ) -{ - $mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode']; -} -else -{ - $mode = ""; -} - -if( isset($_POST['edit']) || isset($_POST['new']) ) -{ - // - // Ok they are editing a group or creating a new group - // - $template->set_filenames(array( - "body" => "admin/group_edit_body.tpl") - ); - - if ( isset($_POST['edit']) ) - { - // - // They're editing. Grab the vars. - // - $sql = "SELECT * - FROM " . GROUPS_TABLE . " - WHERE group_single_user <> " . TRUE . " - AND group_id = $group_id"; - if(!$result = $db->sql_query($sql)) + if (isset($_POST['submit'])) { - message_die(GENERAL_ERROR, "Error getting group information", "", __LINE__, __FILE__, $sql); + $group_name = $_POST['group_name']; + $group_description = $_POST['group_description']; + } - if( !$db->sql_numrows($result) ) + if ($action == 'edit' && empty($_POST['submit'])) { - message_die(GENERAL_MESSAGE, $user->lang['Group_not_exist']); - } - - $group_info = $db->sql_fetchrow($result); - - $mode = "editgroup"; - $template->assign_block_vars("group_edit", array()); - - } - else if( isset($_POST['new']) ) - { - $group_info = array ( - "group_name" => "", - "group_description" => "", - "group_moderator" => "", - "group_type" => GROUP_OPEN); - $group_open = "checked=\"checked\""; - - $mode = "newgroup"; - - } - // - // Ok, now we know everything about them, let's show the page. - // - $sql = "SELECT user_id, username - FROM " . USERS_TABLE . " - WHERE user_id <> " . ANONYMOUS . " - ORDER BY username"; - $u_result = $db->sql_query($sql); - if( !$u_result ) - { - message_die(GENERAL_ERROR, "Couldn't obtain user info for moderator list", "", __LINE__, __FILE__, $sql); - } - - $user_list = $db->sql_fetchrowset($u_result); - - for($i = 0; $i < count($user_list); $i++) - { - if( $user_list[$i]['user_id'] == $group_info['group_moderator'] ) - { - $group_moderator = $user_list[$i]['username']; - } - } - - $group_open = ( $group_info['group_type'] == GROUP_OPEN ) ? "checked=\"checked\"" : ""; - $group_closed = ( $group_info['group_type'] == GROUP_CLOSED ) ? "checked=\"checked\"" : ""; - $group_hidden = ( $group_info['group_type'] == GROUP_HIDDEN ) ? "checked=\"checked\"" : ""; - - $s_hidden_fields = ''; - - $template->assign_vars(array( - "GROUP_NAME" => $group_info['group_name'], - "GROUP_DESCRIPTION" => $group_info['group_description'], - "GROUP_MODERATOR" => $group_moderator, - - "L_GROUP_TITLE" => $user->lang['Group_administration'], - "L_GROUP_EDIT_DELETE" => ( isset($_POST['new']) ) ? $user->lang['New_group'] : $user->lang['Edit_group'], - "L_GROUP_NAME" => $user->lang['group_name'], - "L_GROUP_DESCRIPTION" => $user->lang['group_description'], - "L_GROUP_MODERATOR" => $user->lang['group_moderator'], - "L_FIND_USERNAME" => $user->lang['Find_username'], - "L_GROUP_STATUS" => $user->lang['group_status'], - "L_GROUP_OPEN" => $user->lang['group_open'], - "L_GROUP_CLOSED" => $user->lang['group_closed'], - "L_GROUP_HIDDEN" => $user->lang['group_hidden'], - "L_GROUP_DELETE" => $user->lang['group_delete'], - "L_GROUP_DELETE_CHECK" => $user->lang['group_delete_check'], - "L_SUBMIT" => $user->lang['Submit'], - "L_RESET" => $user->lang['Reset'], - "L_DELETE_MODERATOR" => $user->lang['delete_group_moderator'], - "L_DELETE_MODERATOR_EXPLAIN" => $user->lang['delete_moderator_explain'], - "L_YES" => $user->lang['Yes'], - - "U_SEARCH_USER" => append_sid("../search.$phpEx?mode=searchuser"), - - "S_GROUP_OPEN_TYPE" => GROUP_OPEN, - "S_GROUP_CLOSED_TYPE" => GROUP_CLOSED, - "S_GROUP_HIDDEN_TYPE" => GROUP_HIDDEN, - "S_GROUP_OPEN_CHECKED" => $group_open, - "S_GROUP_CLOSED_CHECKED" => $group_closed, - "S_GROUP_HIDDEN_CHECKED" => $group_hidden, - "S_GROUP_ACTION" => append_sid("admin_groups.$phpEx"), - "S_HIDDEN_FIELDS" => $s_hidden_fields) - ); - - $template->pparse('body'); - -} -else if( isset($_POST['group_update']) ) -{ - // - // Ok, they are submitting a group, let's save the data based on if it's new or editing - // - if( isset($_POST['group_delete']) ) - { - $sql = "DELETE FROM " . GROUPS_TABLE . " - WHERE group_id = " . $group_id; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't update group", "", __LINE__, __FILE__, $sql); - } - - $sql = "DELETE FROM " . USER_GROUP_TABLE . " - WHERE group_id = " . $group_id; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't update user_group", "", __LINE__, __FILE__, $sql); - } - - $sql = "DELETE FROM " . AUTH_ACCESS_TABLE . " - WHERE group_id = " . $group_id; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't update auth_access", "", __LINE__, __FILE__, $sql); - } - - $message = $user->lang['Deleted_group'] . "

" . sprintf($user->lang['Click_return_groupsadmin'], "", "") . "

" . sprintf($user->lang['Click_return_admin_index'], "", "");; - - message_die(GENERAL_MESSAGE, $message); - } - else - { - $group_type = isset($_POST['group_type']) ? intval($_POST['group_type']) : GROUP_OPEN; - $group_name = isset($_POST['group_name']) ? trim($_POST['group_name']) : ""; - $group_description = isset($_POST['group_description']) ? trim($_POST['group_description']) : ""; - $group_moderator = isset($_POST['username']) ? $_POST['username'] : ""; - $delete_old_moderator = isset($_POST['delete_old_moderator']) ? intval($_POST['delete_old_moderator']) : ""; - - if( $group_name == "" ) - { - message_die(GENERAL_MESSAGE, $user->lang['No_group_name']); - } - else if( $group_moderator == "" ) - { - message_die(GENERAL_MESSAGE, $user->lang['No_group_moderator']); - } - - $this_userdata = get_userdata($group_moderator); - $group_moderator = $this_userdata['user_id']; - - if( !$group_moderator ) - { - message_die(GENERAL_MESSAGE, $user->lang['No_group_moderator']); - } - - if( $mode == "editgroup" ) - { - $sql = "SELECT * - FROM " . GROUPS_TABLE . " - WHERE group_single_user <> " . TRUE . " - AND group_id = " . $group_id; - if(!$result = $db->sql_query($sql)) - { - message_die(GENERAL_ERROR, "Error getting group information", "", __LINE__, __FILE__, $sql); - } - if( !$db->sql_numrows($result) ) - { - message_die(GENERAL_MESSAGE, $user->lang['Group_not_exist']); - } - $group_info = $db->sql_fetchrow($result); - - if ( $group_info['group_moderator'] != $group_moderator ) - { - if ( $delete_old_moderator != "" ) - { - $sql = "DELETE FROM " . USER_GROUP_TABLE . " - WHERE user_id = " . $group_info['group_moderator'] . " - AND group_id = " . $group_id; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't update group moderator", "", __LINE__, __FILE__, $sql); - } - } - $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) - VALUES (" . $group_id . ", " . $group_moderator . ", 0)"; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't update group moderator", "", __LINE__, __FILE__, $sql); - } - } - $sql = "UPDATE " . GROUPS_TABLE . " - SET group_type = $group_type, group_name = '" . str_replace("\'", "''", $group_name) . "', group_description = '" . str_replace("\'", "''", $group_description) . "', group_moderator = $group_moderator + $sql = "SELECT * + FROM " . GROUPS_TABLE . " WHERE group_id = $group_id"; - if ( !$result = $db->sql_query($sql) ) + $result = $db->sql_query($sql); + + if (!extract($db->sql_fetchrow($result))) { - message_die(GENERAL_ERROR, "Couldn't update group", "", __LINE__, __FILE__, $sql); + trigger_error($user->lang['NO_GROUP']); } - - $message = $user->lang['Updated_group'] . "

" . sprintf($user->lang['Click_return_groupsadmin'], "", "") . "

" . sprintf($user->lang['Click_return_admin_index'], "", "");; - - message_die(GENERAL_MESSAGE, $message); } - else if( $mode == "newgroup" ) - { - $sql = "SELECT MAX(group_id) AS new_group_id - FROM " . GROUPS_TABLE; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't insert new group", "", __LINE__, __FILE__, $sql); - } - $row = $db->sql_fetchrow($result); - - $new_group_id = $row['new_group_id'] + 1; - - $sql = "INSERT INTO " . GROUPS_TABLE . " (group_id, group_type, group_name, group_description, group_moderator, group_single_user) - VALUES ($new_group_id, $group_type, '" . str_replace("\'", "''", $group_name) . "', '" . str_replace("\'", "''", $group_description) . "', $group_moderator, '0')"; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't insert new group", "", __LINE__, __FILE__, $sql); - } - - $sql = "INSERT INTO " . USER_GROUP_TABLE . " (group_id, user_id, user_pending) - VALUES ($new_group_id, $group_moderator, 0)"; - if ( !$result = $db->sql_query($sql) ) - { - message_die(GENERAL_ERROR, "Couldn't insert new user-group info", "", __LINE__, __FILE__, $sql); - } - - $message = $user->lang['Added_new_group'] . "

" . sprintf($user->lang['Click_return_groupsadmin'], "", "") . "

" . sprintf($user->lang['Click_return_admin_index'], "", "");; - - message_die(GENERAL_MESSAGE, $message); - - } - else - { - message_die(GENERAL_MESSAGE, $user->lang['Group_mode_not_selected']); - } - } -} - -page_header($user->lang['Manage']); ?> -

lang['Manage']; ?>

+

lang['MANAGE'] . ' : ' . $group_name . ''; ?>

-

lang['Group_manage_explain']; ?>

+

lang['GROUP_EDIT_EXPLAIN']; ?>

-
"> +sql_query($sql); + + $rank_options = ''; + if ($row = $db->sql_fetchrow($result)) + { + do + { + $selected = (!empty($group_rank) && $row['rank_id'] == $group_rank) ? ' selected="selected"' : ''; + $rank_options .= ''; + } + while ($row = $db->sql_fetchrow($result)); + } + + $type_open = ($group_type == GROUP_OPEN) ? ' checked="checked"' : ''; + $type_closed = ($group_type == GROUP_CLOSED) ? ' checked="checked"' : ''; + $type_hidden = ($group_type == GROUP_HIDDEN) ? ' checked="checked"' : ''; + $type_free = ($group_type == GROUP_FREE) ? ' checked="checked"' : ''; + + $sql = "SELECT u.user_id, u.username + FROM " . GROUPS_MODERATOR_TABLE . " gm, " . USERS_TABLE . " u + WHERE gm.group_id = $group_id + AND u.user_id = gm.user_id"; +// $result = $db->sql_query($sql); + +?> + +">
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
lang['Manage']; ?>lang['GROUP_DETAILS']; ?>
lang['GROUP_NAME']; ?>:
lang['GROUP_DESC']; ?>:
lang['GROUP_TYPE']; ?>:
lang['GROUP_TYPE_EXPLAIN']; ?>
/> lang['GROUP_OPEN']; ?>   /> lang['GROUP_REQUEST']; ?>   /> lang['GROUP_CLOSED']; ?>   /> lang['GROUP_HIDDEN']; ?>
lang['GROUP_SETTINGS_SAVE']; ?>
lang['GROUP_SETTINGS_SAVE_EXPLAIN']; ?>
lang['GROUP_COLOR']; ?>:
lang['GROUP_COLOR_EXPLAIN']; ?>
lang['GROUP_RANK']; ?>:
lang['GROUP_SETTINGS']; ?>
lang['GROUP_SETTINGS_EXPLAIN']; ?>
lang['GROUP_LANG']; ?>:
lang['GROUP_TIMEZONE']; ?>:
lang['GROUP_DST']; ?>: lang['DISABLED']; ?>   lang['ENABLED']; ?>   lang['USER_DEFAULT']; ?>
lang['GROUP_FORCE_SET']; ?>:
lang['GROUP_FORCE_SET_EXPLAIN']; ?>
lang['YES']; ?>   lang['NO']; ?>
 
+ + + +

lang['GROUP_MEMBERS']; ?>

+ +

lang['GROUP_LIST_EXPLAIN']; ?>

+ +
"> + + + +
lang['']; ?>
+ + + +

lang['MANAGE']; ?>

+ +

lang['GROUP_MANAGE_EXPLAIN']; ?>

+ +

lang['USER_DEF_GROUPS']; ?>

+ +

lang['USER_DEF_GROUPS_EXPLAIN']; ?>

+ +
"> + + + sql_query($sql); + $sql = "SELECT ug.group_id, u.user_id, u.username + FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug, " . GROUPS_TABLE . " g + WHERE ug.user_pending = 1 + AND g.group_type = " . GROUP_SPECIAL . " + AND u.user_id = ug.user_id + ORDER BY ug.group_id, u.user_id"; + $result = $db->sql_query($sql); - $groups = array(); - if ( $row = $db->sql_fetchrow($result) ) - { - do + $pending = array(); + if ($row = $db->sql_fetchrow($result) ) { - $groups[] = $row; + do + { + $pending[$row['group_id']][] = $row; + } + while ($row = $db->sql_fetchrow($result) ); } - while ( $row = $db->sql_fetchrow($result) ); - } + $db->sql_freeresult($result); - $sql = "SELECT ug.group_id, u.user_id, u.username - FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug - WHERE ug.user_pending = 1 - AND u.user_id = ug.user_id - ORDER BY ug.group_id"; - $result = $db->sql_query($sql); + $sql = "SELECT group_id, group_name, group_type + FROM " . GROUPS_TABLE . " + ORDER BY group_type ASC, group_name"; + $result = $db->sql_query($sql); - $pending = array(); - if ( $row = $db->sql_fetchrow($result) ) - { - do + $special_toggle = false; + if ($row = $db->sql_fetchrow($result) ) { - $pending[$row['group_id']][] = $row; - } - while ( $row = $db->sql_fetchrow($result) ); - } + do + { - foreach ( $groups as $group_ary ) - { - $group_id = $group_ary['group_id']; - $group_name = ( !empty($user->lang[$group_ary['group_name']]) ) ? $user->lang[$group_ary['group_name']] : $group_ary['group_name']; + if ($row['group_type'] == GROUP_SPECIAL && !$special_toggle) + { + $special_toggle = true; ?> - - - + + +
lang['MANAGE']; ?>lang['ACTION']; ?>
    
+ +

lang['SPECIAL_GROUPS']; ?>

+ +

lang['SPECIAL_GROUPS_EXPLAIN']; ?>

+ + + + + lang[$row['group_name']]))? $user->lang[$row['group_name']] : $row['group_name']; + +?> + + + + + - - - - - - + sql_fetchrow($result) ); } - } + $db->sql_freeresult($result); ?>
lang['MANAGE']; ?>lang['ACTION']; ?>
"> ">lang['ADD']; ?> | ">lang['EDIT']; ?> | ">lang['DELETE']; ?> 
No pending users  
+?> \ No newline at end of file