From 615e676b0241fab7c4ab92ed5963c2769e34b7e1 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Tue, 11 Feb 2003 17:12:52 +0000 Subject: [PATCH] Basic ability to add users to group and group moderators git-svn-id: file:///svn/phpbb/trunk@3468 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/admin/admin_groups.php | 281 ++++++++++++++++++++++++++----- phpBB/language/en/lang_admin.php | 6 +- phpBB/language/en/lang_main.php | 2 +- 3 files changed, 243 insertions(+), 46 deletions(-) diff --git a/phpBB/admin/admin_groups.php b/phpBB/admin/admin_groups.php index 0411c32959..5874679552 100644 --- a/phpBB/admin/admin_groups.php +++ b/phpBB/admin/admin_groups.php @@ -45,13 +45,49 @@ if (!$auth->acl_get('a_group') ) // Check and set some common vars -$action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ((isset($_POST['addgroup'])) ? 'addgroup' : ''); +$mode = (isset($_REQUEST['mode'])) ? $_REQUEST['mode'] : ''; +if (isset($_POST['addgroup'])) +{ + $action = 'addgroup'; +} +else if (isset($_POST['delete'])) +{ + $action = 'delete'; +} +else if (isset($_POST['add'])) +{ + $action = 'add'; +} +else +{ + $action = (isset($_REQUEST['action'])) ? $_REQUEST['action'] : ''; +} $group_id = (isset($_REQUEST['g'])) ? intval($_REQUEST['g']) : ''; -$start = (isset($_GET['start'])) ? intval($_GET['start']) : 0; -// Which page? +$start = (isset($_GET['start']) && $mode == 'member') ? intval($_GET['start']) : 0; +$start_mod = (isset($_GET['start']) && $mode == 'mod') ? intval($_GET['start']) : 0; +$start_pend = (isset($_GET['start']) && $mode == 'pend') ? intval($_GET['start']) : 0; + +// Grab basic data for group, if group_id is set since it's used +// in several places below +if (!empty($group_id)) +{ + $sql = "SELECT * + FROM " . GROUPS_TABLE . " + WHERE group_id = $group_id"; + $result = $db->sql_query($sql); + + if (!extract($db->sql_fetchrow($result))) + { + trigger_error($user->lang['NO_GROUP']); + } + $db->sql_freeresult($result); +} + +// Page header page_header($user->lang['MANAGE']); +// Which page? switch ($action) { case 'edit': @@ -59,21 +95,6 @@ switch ($action) $error = ''; - // Grab data, even when submitting updates - if ($action == 'edit') - { - $sql = "SELECT * - FROM " . GROUPS_TABLE . " - WHERE group_id = $group_id"; - $result = $db->sql_query($sql); - - if (!extract($db->sql_fetchrow($result))) - { - trigger_error($user->lang['NO_GROUP']); - } - $db->sql_freeresult($result); - } - // Did we submit? if (isset($_POST['submit']) || isset($_POST['submitprefs'])) { @@ -340,16 +361,7 @@ function swatch() lang['DISABLED']; ?>   lang['ENABLED']; ?>   lang['USER_DEFAULT']; ?> -   +   @@ -359,11 +371,112 @@ function swatch() break; + case 'deletegroup': + + break; + case 'add': + + if (empty($_POST['usernames'])) + { + trigger_error($user->lang['NO_USERS']); + } + $users = explode("\n", $_POST['usernames']); + + $table_sql = ($mode == 'mod' ) ? GROUPS_MODERATOR_TABLE : USER_GROUP_TABLE; + + // Grab the user ids + $sql = "SELECT user_id + FROM " . USERS_TABLE . " + WHERE username IN (" . implode(', ', preg_replace('#^[\s]*?(.*?)[\s]*?$#', "'\\1'", $users)) . ")"; + $result = $db->sql_query($sql); + + if (!($row = $db->sql_fetchrow($result))) + { + trigger_error($user->lang['NO_USERS']); + } + + $user_id_ary = array(); + do + { + $user_id_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + $db->sql_freeresult($result); + + // Remove users who are already members of this group + $sql = "SELECT user_id + FROM $table_sql + WHERE user_id IN (" . implode(', ', $user_id_ary) . ") + AND group_id = $group_id"; + $result = $db->sql_query($sql); + + if ($row = $db->sql_fetchrow($result)) + { + $old_user_id_ary = array(); + do + { + $old_user_id_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + + $user_id_ary = array_diff($user_id_ary, $old_user_id_ary); + } + $db->sql_freeresult($result); + + // Insert the new users + switch (SQL_LAYER) + { + case 'postgresql': + case 'msaccess': + case 'mssql-odbc': + case 'oracle': + case 'db2': + foreach ($user_id_ary as $user_id) + { + $sql = "INSERT INTO $table_sql (user_id, group_id) + VALUES ($user_id, $group_id)"; + $db->sql_query($sql); + } + + break; + + case 'mysql': + case 'mysql4': + $sql = "INSERT INTO $table_sql (user_id, group_id) + VALUES " . implode(', ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id)", $user_id_ary)); + $db->sql_query($sql); + break; + + case 'mssql': + $sql = "INSERT INTO $table_sql (user_id, group_id) + VALUES " . implode(' UNION ALL ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id)", $user_id_ary)); + $db->sql_query($sql); + break; + } + + // Update user settings (color, rank) if applicable + if (!empty($_POST['settings'])) + { + $sql = "UPDATE " . USERS_TABLE ." + SET user_colour = '$group_colour', user_rank = " . intval($group_rank) . " + WHERE user_id IN (" . implode(', ', $user_id_ary) . ")"; + $db->sql_query($sql); + } + +// add_log(); + + $message = ($mode == 'mod') ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; + trigger_error($user->lang[$message]); + break; case 'delete': - case 'deletegroup': + + break; + + case 'approve': + break; case 'list': @@ -395,7 +508,7 @@ function swatch()

lang['GROUP_MODS_EXPLAIN']; ?>

-
"> +">
@@ -405,10 +518,21 @@ function swatch() sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $total_members = $row['total_members']; + + $sql = "SELECT u.user_id, u.username, u.user_regdate, u.user_posts FROM " . USERS_TABLE . " u, " . GROUPS_MODERATOR_TABLE . " gm WHERE gm.group_id = $group_id - ORDER BY u.user_id"; + AND u.user_id = gm.user_id + ORDER BY u.username + LIMIT $start_mod, " . $config['topics_per_page']; $result = $db->sql_query($sql); $db->sql_freeresult($result); @@ -417,7 +541,17 @@ function swatch() { do { - + + $row_class = ($row_class == 'row1') ? 'row2' : 'row1'; + +?> + + + + + + +sql_fetchrow($result) ); @@ -440,18 +574,46 @@ function swatch() ?> - + + + + + + + + + + + +
lang['USERNAME']; ?> lang['JOINED']; ?>
" target="_profile">format_date($row['user_regdate'], $user->lang['DATE_FORMAT']); ?>
lang['ADD_USERS']; ?>
  &mode=searchuser&form=mod&field=usernames', '_phpbbsearch', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=740');return false;" />
+ + + + +
lang['MARK_ALL']; ?> :: lang['UNMARK_ALL']; ?> 
sql_query($sql); + + $row = $db->sql_fetchrow($result); + $db->sql_freeresult($result); + $total_members = $row['total_members']; + + $sql = "SELECT u.user_id, u.username, u.user_regdate, u.user_posts + FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug + WHERE ug.group_id = $group_id + AND ug.user_pending = 1 AND u.user_id = ug.user_id - ORDER BY ug.group_id, u.user_id"; + ORDER BY u.username + LIMIT $start_pend, " . $config['topics_per_page']; $result = $db->sql_query($sql); if ($row = $db->sql_fetchrow($result) ) @@ -462,7 +624,7 @@ function swatch()

lang['GROUP_PENDING_EXPLAIN']; ?>

-
"> +">
@@ -474,6 +636,8 @@ function swatch() do { + $row_class = ($row_class == 'row1') ? 'row2' : 'row1'; + ?> @@ -487,6 +651,25 @@ function swatch() while ($row = $db->sql_fetchrow($result) ); ?> + + + + + + + + + + + + +
lang['USERNAME']; ?> lang['JOINED']; ?>
" target="_profile">
lang['ADD_USERS']; ?>
  &mode=searchuser&form=pend&field=usernames', '_phpbbsearch', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=740');return false;" />
+ + + + + +
lang['MARK_ALL']; ?> :: lang['UNMARK_ALL']; ?> 
sql_freeresult($result); } + // Existing members $sql = "SELECT COUNT(user_id) AS total_members FROM " . USER_GROUP_TABLE . " - WHERE group_id = $group_id"; + WHERE group_id = $group_id + AND user_pending = 0"; $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); $db->sql_freeresult($result); $total_members = $row['total_members']; - // Existing members $sql = "SELECT u.user_id, u.username, u.user_regdate, u.user_posts FROM " . USERS_TABLE . " u, " . USER_GROUP_TABLE . " ug WHERE ug.group_id = $group_id @@ -525,7 +709,7 @@ function swatch() -
"> +">
@@ -553,14 +737,23 @@ function swatch() ?> - + + + + + + + + + +
lang['USERNAME']; ?> lang['JOINED']; ?>
lang['ADD_USERS']; ?>

lang['USER_GETS_GROUP_SET']; ?> lang['YES']; ?>   lang['NO']; ?>
  &mode=searchuser&form=list&field=usernames', '_phpbbsearch', 'HEIGHT=500,resizable=yes,scrollbars=yes,WIDTH=740');return false;" />
- +
lang['MARK_ALL']; ?> :: lang['UNMARK_ALL']; ?> 
lang['MARK_ALL']; ?> :: lang['UNMARK_ALL']; ?> 
diff --git a/phpBB/language/en/lang_admin.php b/phpBB/language/en/lang_admin.php index 58704b4f10..2e32b42b14 100644 --- a/phpBB/language/en/lang_admin.php +++ b/phpBB/language/en/lang_admin.php @@ -203,7 +203,7 @@ $lang = array_merge($lang, array( 'GROUP_PERMISSIONS_EXPLAIN' => 'Here you can set usergroup based permissions. These include capabilities such as the use of avatars, sending private messages, etc. To alter these settings for single users the User permissions system is the prefered method.', 'LOOK_UP_GROUP' => 'Look up Usergroup', 'Manage_users' => 'Manage Users', - 'Add_users' => 'Add Users', + 'ADD_USERS' => 'Add Users', 'Manage_groups' => 'Manage Groups', 'Add_groups' => 'Add Groups', 'Admin_group' => 'Administrators', @@ -223,6 +223,7 @@ $lang = array_merge($lang, array( 'Inherit' => 'Inherit', 'Deny' => 'Deny', 'Basic' => 'Basic', + 'USER_PRESETS' => 'User presets', 'ALL_ALLOW' => 'All Allow', 'ALL_DENY' => 'All Deny', 'ALL_INHERIT' => 'All Inherit', @@ -652,12 +653,15 @@ $lang = array_merge($lang, array( 'GROUP_TIMEZONE' => 'Group timezone', 'GROUP_DST' => 'Group daylight savings', 'USER_DEFAULT' => 'User default', + 'USER_GETS_GROUP_SET' => 'Users inherit group settings', 'GROUPS_NO_MODS' => 'No group moderators defined', 'GROUP_ERR_USERNAME' => 'No group name specified.', 'GROUP_ERR_USER_LONG' => 'Group name too long.', 'GROUP_ERR_DESC_LONG' => 'Group description too long.', 'GROUP_ERR_TYPE' => 'Inappropriate group type specified.', 'GROUP_UPDATED' => 'Group preferences updated successfully.', + 'GROUP_USERS_ADDED' => 'New users added to group successfully.', + 'GROUP_MODS_ADDED' => 'New group moderators added successfully.', 'FORUM_PRUNE_EXPLAIN' => 'This will delete any topic which has not been posted to within the number of days you select. If you do not enter a number then all topics will be deleted. It will not remove topics in which polls are still running nor will it remove announcements. You will need to remove these topics manually.', diff --git a/phpBB/language/en/lang_main.php b/phpBB/language/en/lang_main.php index 6090927599..534fe9b466 100644 --- a/phpBB/language/en/lang_main.php +++ b/phpBB/language/en/lang_main.php @@ -417,7 +417,7 @@ $lang = array_merge($lang, array( 'Send_a_reply' => 'Reply to a private message', 'Edit_message' => 'Edit private message', 'Notification_subject' => 'New Private Message has arrived', - 'Find_username' => 'Find a username', + 'FIND_USERNAME' => 'Find a username', 'Find' => 'Find', 'No_match' => 'No matches found', 'No_such_folder' => 'No such folder exists',