diff options
author | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-27 00:32:00 +0000 |
---|---|---|
committer | Paul S. Owen <psotfx@users.sourceforge.net> | 2003-08-27 00:32:00 +0000 |
commit | 3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f (patch) | |
tree | ce96b57281689798f99c76e08f7c2b28d1b900b5 | |
parent | b61ea7da257dd762799956ee842f66c4be4841cb (diff) | |
download | forums-3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f.tar forums-3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f.tar.gz forums-3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f.tar.bz2 forums-3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f.tar.xz forums-3de3b9e9cfe9a5fa258f2c3e6f32cec2ecd7207f.zip |
Move presently implemented group functions to ... functions
git-svn-id: file:///svn/phpbb/trunk@4438 89ea8834-ac86-4346-8a33-228a782c2dd0
-rw-r--r-- | phpBB/adm/admin_groups.php | 345 | ||||
-rw-r--r-- | phpBB/includes/functions_user.php | 397 |
2 files changed, 423 insertions, 319 deletions
diff --git a/phpBB/adm/admin_groups.php b/phpBB/adm/admin_groups.php index ea8016d434..de010196a3 100644 --- a/phpBB/adm/admin_groups.php +++ b/phpBB/adm/admin_groups.php @@ -11,7 +11,6 @@ // // ------------------------------------------------------------- - if (!empty($setmodules)) { if (!$auth->acl_get('a_group')) @@ -30,6 +29,7 @@ define('IN_PHPBB', 1); $phpbb_root_path = '../'; $phpEx = substr(strrchr(__FILE__, '.'), 1); require('pagestart.' . $phpEx); +include($phpbb_root_path . 'includes/functions_user.'.$phpEx); // Do we have general permissions? if (!$auth->acl_get('a_group') ) @@ -37,16 +37,19 @@ if (!$auth->acl_get('a_group') ) trigger_error($user->lang['NO_ADMIN']); } - - // Check and set some common vars $update = (isset($_POST['update'])) ? true : false; -$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : ''; -$group_id = (isset($_REQUEST['g'])) ? intval($_REQUEST['g']) : ''; +$mode = (isset($_REQUEST['mode'])) ? htmlspecialchars($_REQUEST['mode']) : false; +$group_id = (isset($_REQUEST['g'])) ? intval($_REQUEST['g']) : false; +$mark_ary = (!empty($_POST['mark'])) ? array_map('intval', $_POST['mark']) : false; +$name_ary = (!empty($_POST['usernames'])) ? array_unique(explode("\n", $_POST['usernames'])) : false; +$start = (isset($_GET['start']) && $action == 'member') ? intval($_GET['start']) : 0; +$start_mod = (isset($_GET['start']) && $action == 'leader') ? intval($_GET['start']) : 0; +$group_type = $group_name = $group_desc = $group_colour = $group_rank = $group_avatar = false; -if (isset($_POST['addgroup'])) +if (isset($_POST['add'])) { - $action = 'addgroup'; + $action = 'add'; } else if (isset($_POST['addleaders']) || isset($_POST['addusers'])) { @@ -57,13 +60,8 @@ else $action = (isset($_REQUEST['action'])) ? htmlspecialchars($_REQUEST['action']) : ''; } -$start = (isset($_GET['start']) && $action == 'member') ? intval($_GET['start']) : 0; -$start_mod = (isset($_GET['start']) && $action == 'leader') ? intval($_GET['start']) : 0; - - -// Grab basic data for group, if group_id is set since it's used -// in several places below +// Grab basic data for group, if group_id is set and exists if ($group_id) { $sql = 'SELECT * @@ -78,8 +76,6 @@ if ($group_id) $db->sql_freeresult($result); } - - switch ($mode) { case 'manage': @@ -94,109 +90,41 @@ switch ($mode) { trigger_error($user->lang['NO_GROUP']); } + + break; - case 'approve': + case 'deleteusers': if (!$group_id) { trigger_error($user->lang['NO_GROUP']); } - if (!empty($_POST['mark'])) - { - $id_ary = array_map('intval', $_POST['mark']); - - $sql = 'UPDATE ' . USER_GROUP_TABLE . ' - SET user_pending = 1 - WHERE user_id IN (' . implode(', ', $id_ary) . ") - AND group_id = $group_id"; - $db->sql_query($sql); - - $sql = 'SELECT username - FROM ' . USERS_TABLE . ' - WHERE user_id IN (' . implode(', ', $id_ary) . ')'; - $result = $db->sql_query($sql); - - $usernames = array(); - while ($row = $db->sql_fetchrow($result)) - { - $usernames[] = $row['username']; - } - $db->sql_freeresult($result); - - add_log('admin', 'LOG_GROUP_APPROVE', $group_name, implode(', ', $usernames)); - unset($usernames); - trigger_error($user->lang['USERS_APPROVED']); - } break; - case 'default': + case 'approve': if (!$group_id) { trigger_error($user->lang['NO_GROUP']); } - $id_ary = (!empty($_POST['mark'])) ? array_map('intval', $_POST['mark']) : false; + approve_user($group_id, $mark_ary, false, $group_name); + trigger_error($user->lang['USERS_APPROVED']); + break; - switch (SQL_LAYER) + case 'default': + if (!$group_id) { - case 'mysql': - case 'mysql4': - $start = 0; - do - { - $sql = 'SELECT user_id - FROM ' . USER_GROUP_TABLE . " - WHERE group_id = $group_id - ORDER BY user_id - LIMIT $start, 200"; - $result = $db->sql_query($sql); - - $user_id_ary = array(); - if ($row = $db->sql_fetchrow($result)) - { - do - { - $user_id_ary[] = $row['user_id']; - } - while ($row = $db->sql_fetchrow($result)); - - $sql = 'UPDATE ' . USERS_TABLE . " - SET group_id = $group_id, user_colour = '$group_colour', user_rank = $group_rank - WHERE user_id IN (" . implode(', ', $user_id_ary) . ')'; - $db->sql_query($sql); - - $start = (sizeof($user_id_ary) < 200) ? 0 : $start + 200; - } - else - { - $start = 0; - } - $db->sql_freeresult($result); - } - while ($start); - break; - - default: - $sql = 'UPDATE ' . USERS_TABLE . " - SET group_id = $group_id, user_colour = '$group_color', user_rank = $group_rank - WHERE user_id IN ( - SELECT user_id - FROM " . USER_GROUP_TABLE . " - WHERE group_id = $group_id - )"; - $db->sql_query($sql); - break; + trigger_error($user->lang['NO_GROUP']); } - add_log('admin', 'LOG_GROUP_DEFAULTS', $group_name); - + set_default_group($group_id, $mark_ary, false, $group_name, $group_colour, $group_rank, false, false); trigger_error($user->lang['GROUP_DEFS_UPDATED']); break; case 'edit': - case 'addgroup': + case 'add': if ($action == 'edit' && !$group_id) { trigger_error($user->lang['NO_GROUP']); @@ -205,69 +133,11 @@ switch ($mode) // Did we submit? if ($update) { - if ($group_type != GROUP_SPECIAL) - { - $group_name = (!empty($_POST['group_name'])) ? stripslashes(htmlspecialchars($_POST['group_name'])) : ''; - $group_type = (!empty($_POST['group_type'])) ? intval($_POST['group_type']) : ''; - } - $group_description = (!empty($_POST['group_description'])) ? stripslashes(htmlspecialchars($_POST['group_description'])) : ''; - $group_colour2 = (!empty($_POST['group_colour'])) ? stripslashes(htmlspecialchars($_POST['group_colour'])) : ''; - $group_avatar2 = (!empty($_POST['group_avatar'])) ? stripslashes(htmlspecialchars($_POST['group_avatar'])) : ''; - $group_rank2 = (isset($_POST['group_rank'])) ? intval($_POST['group_rank']) : ''; - - // Check data - if (!strlen($group_name) || strlen($group_name) > 40) - { - $error[] = (!strlen($group_name)) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG']; - } - - if (strlen($group_description) > 255) - { - $error[] = $user->lang['GROUP_ERR_DESC_LONG']; - } - - if ($group_type < GROUP_OPEN || $group_type > GROUP_FREE) - { - $error[] = $user->lang['GROUP_ERR_TYPE']; - } - - // Update DB - if (!sizeof($error)) + if (!($error = create_group($action, $group_id, $group_type, $group_name, $group_description, $group_colour, $group_rank, $group_avatar))) { - // Update group preferences - $sql_ary = array( - 'group_name' => (string) $group_name, - 'group_description' => (string) $group_description, - 'group_type' => (int) $group_type, - 'group_rank' => (int) $group_rank2, - 'group_colour' => (string) $group_colour2, - ); - - $sql = ($action == 'edit') ? 'UPDATE ' . GROUPS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE group_id = $group_id" : 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); - $db->sql_query($sql); - - if ($group_id && ($group_colour != $group_colour2 || $group_rank != $group_rank2 || $group_avatar != $group_avatar2)) - { - $sql_ary = array( - 'user_rank' => (string) $group_rank2, - 'user_colour' => (string) $group_colour2, - ); - - $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE group_id = $group_id"; - $db->sql_query($sql); - } - - $log = ($action == 'edit') ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED'; - add_log('admin', $log, $group_name); - $message = ($action == 'edit') ? 'GROUP_UPDATED' : 'GROUP_CREATED'; trigger_error($message); } - - $group_colour = &$group_colour2; - $group_rank = &$group_rank2; - $group_avatar = &$group_avatar2; } else if (!$group_id) { @@ -278,7 +148,7 @@ switch ($mode) ?> -<h1><?php echo $user->lang['MANAGE'] . ' : <i>' . $group_name . '</i>'; ?></h1> +<h1><?php echo $user->lang['MANAGE']; ?></h1> <p><?php echo $user->lang['GROUP_EDIT_EXPLAIN']; ?></p> @@ -408,154 +278,19 @@ function swatch() trigger_error($user->lang['NO_GROUP']); } - $username_ary = (!empty($_POST['usernames'])) ? array_unique(explode("\n", $_POST['usernames'])) : ''; - if (!$username_ary) - { - trigger_error($user->lang['NO_USERS']); - } - - $sql_where = array(); - foreach ($username_ary as $username) - { - if ($username = trim($username)) - { - $sql_where[] = "'$username'"; - } - } - unset($username_ary); - - // Grab the user ids - $sql = 'SELECT user_id, username - FROM ' . USERS_TABLE . ' - WHERE username IN (' . implode(', ', $sql_where) . ')'; - $result = $db->sql_query($sql); - - if (!($row = $db->sql_fetchrow($result))) + if (!$name_ary) { trigger_error($user->lang['NO_USERS']); } - $id_ary = $username_ary = array(); - do - { - $username_ary[$row['user_id']] = $row['username']; - $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, group_leader - FROM ' . USER_GROUP_TABLE . ' - WHERE user_id IN (' . implode(', ', $id_ary) . ") - AND group_id = $group_id"; - $result = $db->sql_query($sql); - - $add_id_ary = $update_id_ary = array(); - if ($row = $db->sql_fetchrow($result)) - { - do - { - $add_id_ary[] = $row['user_id']; - - if ($action == 'addleaders' && !$row['group_leader']) - { - $update_id_ary[] = $row['user_id']; - } - } - while ($row = $db->sql_fetchrow($result)); - } - $db->sql_freeresult($result); - - // Do all the users exist in this group? - $add_id_ary = array_diff($id_ary, $add_id_ary); - unset($id_ary); - - // If we have no users - if (!sizeof($add_id_ary) && !sizeof($update_id_ary)) - { - trigger_error($user->lang['GROUP_USERS_EXIST']); - } - - if (sizeof($add_id_ary)) - { - $group_leader = ($action == 'addleaders') ? 1 : 0; - - // Insert the new users - switch (SQL_LAYER) - { - case 'mysql': - case 'mysql4': - $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) - VALUES " . implode(', ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $group_leader)", $add_id_ary)); - $db->sql_query($sql); - break; - - case 'mssql': - case 'sqlite': - $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) - " . implode(' UNION ALL ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $group_leader)", $add_id_ary)); - $db->sql_query($sql); - break; - - default: - foreach ($add_id_ary as $user_id) - { - $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) - VALUES ($user_id, $group_id, $group_leader)"; - $db->sql_query($sql); - } - break; - } - - $sql = 'UPDATE ' . USERS_TABLE . " - SET user_permissions = '' - WHERE user_id IN (" . implode(', ', $add_id_ary) . ')'; - $db->sql_query($sql); - } - - $usernames = array(); - if (sizeof($update_id_ary)) - { - $sql = 'UPDATE ' . USER_GROUP_TABLE . ' - SET group_leader = 1 - WHERE user_id IN (' . implode(', ', $update_id_ary) . ") - AND group_id = $group_id"; - $db->sql_query($sql); - - foreach ($update_id_ary as $id) - { - $usernames[] = $username_ary[$id]; - } - } - else - { - foreach ($add_id_ary as $id) - { - $usernames[] = $username_ary[$id]; - } - } - unset($username_ary); - - // Update user settings (color, rank) if applicable - // TODO - // Do not update users who are not approved - if (!empty($_POST['default'])) + // Add user/s to group + if ($error = add_to_group($action, $group_id, false, $name_ary, $group_colour, $group_rank, $group_avatar, $group_avatar_type)) { - $sql = 'UPDATE ' . USERS_TABLE . " - SET group_id = $group_id, user_colour = '$group_colour', user_rank = " . intval($group_rank) . " - WHERE user_id IN (" . implode(', ', array_merge($add_id_ary, $update_id_ary)) . ")"; - $db->sql_query($sql); + trigger_error($user->lang[$error]); } - unset($update_id_ary); - unset($add_id_ary); - $log = ($mode == 'addleaders') ? 'LOG_MODS_ADDED' : 'LOG_USERS_ADDED'; - add_log('admin', $log, $group_name, implode(', ', $usernames)); - - $message = ($mode == 'addleaders') ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; + $message = ($action == 'addleaders') ? 'GROUP_MODS_ADDED' : 'GROUP_USERS_ADDED'; trigger_error($user->lang[$message]); - break; @@ -675,7 +410,7 @@ function swatch() ?> <tr> - <td class="cat" colspan="5" align="right">Select option: <select name="action"><option value="approve">Approve</option><option value="default">Default</option><option value="delete">Delete</option></select> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE_MARKED']; ?>" /> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE_ALL']; ?>" /> </td> + <td class="cat" colspan="5" align="right">Select option: <select name="action"><option value="default">Default</option><option value="delete">Delete</option></select> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE']; ?>" /> </td> </tr> </table> @@ -785,7 +520,7 @@ function swatch() ?> <tr> - <td class="cat" colspan="5" align="right">Select option: <select name="action"><option value="approve">Approve</option><option value="default">Default</option><option value="delete">Delete</option></select> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE_MARKED']; ?>" /> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE_ALL']; ?>" /> </td> + <td class="cat" colspan="5" align="right">Select option: <select name="action"><option value="approve">Approve</option><option value="default">Default</option><option value="delete">Delete</option></select> <input class="btnmain" type="submit" name="update" value="<?php echo $user->lang['UPDATE']; ?>" /> </td> </tr> </table> @@ -872,7 +607,7 @@ function swatch() ?> <tr> - <td class="cat" colspan="5" align="right">Create new group: <input class="post" type="text" name="group_name" maxlength="30" /> <input class="btnmain" type="submit" name="addgroup" value="<?php echo $user->lang['SUBMIT']; ?>" /></td> + <td class="cat" colspan="5" align="right">Create new group: <input class="post" type="text" name="group_name" maxlength="30" /> <input class="btnmain" type="submit" name="add" value="<?php echo $user->lang['SUBMIT']; ?>" /></td> </tr> </table> @@ -905,7 +640,7 @@ function swatch() <td class="<?php echo $row_class; ?>" align="center" nowrap="nowrap"> <a href="<?php echo "admin_groups.$phpEx$SID&mode=$mode&action=edit&g=$group_id"; ?>"><?php echo $user->lang['EDIT']; ?></a> </td> <td class="<?php echo $row_class; ?>" align="center" nowrap="nowrap"> <?php - echo ($row['group_type'] != GROUP_SPECIAL) ? "<a href=\"admin_groups.$phpEx$SID&mode=$mode&&action=delete&g=$group_id\">" . $user->lang['DELETE'] . '</a>' : $user->lang['DELETE']; + echo ($row['group_type'] != GROUP_SPECIAL) ? "<a href=\"admin_groups.$phpEx$SID&mode=$mode&action=delete&g=$group_id\">" . $user->lang['DELETE'] . '</a>' : $user->lang['DELETE']; ?> </td> </tr> @@ -1096,4 +831,16 @@ adm_page_footer(); */ + +function delete_group() +{ + +} + +function remove_from_group($type, $id, $user_id) +{ + +} + + ?>
\ No newline at end of file diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index ed811f5a7c..cf2614cce3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -1,24 +1,19 @@ <?php -/*************************************************************************** - * functions_ucp.php - * ------------------- - * begin : Saturday, Feb 13, 2001 - * copyright : (C) 2001 The phpBB Group - * email : support@phpbb.com - * - * $Id$ - * - ***************************************************************************/ - -/*************************************************************************** - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - ***************************************************************************/ - +// ------------------------------------------------------------- +// +// $Id$ +// +// FILENAME : functions_user.php +// STARTED : Sat Dec 16, 2000 +// COPYRIGHT : © 2001, 2003 phpBB Group +// WWW : http://www.phpbb.com/ +// LICENCE : GPL vs2.0 [ see /docs/COPYING ] +// +// ------------------------------------------------------------- + +// +// User functions +// // Generates an alphanumeric random string of given length function gen_rand_string($num_chars) @@ -334,4 +329,366 @@ function avatar_upload(&$data) return false; } +// +// Usergroup functions +// + +function add_to_group($action, $group_id, $user_id_ary, $username_ary, $colour, $rank, $avatar, $avatar_type) +{ + global $db; + + $which_ary = ($user_id_ary) ? 'user_id_ary' : 'username_ary'; + + if ($$which_ary && !is_array($$which_ary )) + { + $user_id_ary = array($user_id_ary); + } + + $sql_in = array(); + foreach ($$which_ary as $v) + { + if ($v = trim($v)) + { + $sql_in[] = ($which_ary == 'user_id_ary') ? $v : "'$v'"; + } + } + unset($$which_ary); + + // Grab the user id/username records + $sql_where = ($which_ary == 'user_id_ary') ? 'user_id' : 'username'; + $sql = 'SELECT user_id, username + FROM ' . USERS_TABLE . " + WHERE $sql_where IN (" . implode(', ', $sql_in) . ')'; + $result = $db->sql_query($sql); + + if (!($row = $db->sql_fetchrow($result))) + { + return 'NO_USERS'; + } + + $id_ary = $username_ary = array(); + do + { + $username_ary[$row['user_id']] = $row['username']; + $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, group_leader + FROM ' . USER_GROUP_TABLE . ' + WHERE user_id IN (' . implode(', ', $id_ary) . ") + AND group_id = $group_id"; + $result = $db->sql_query($sql); + + $add_id_ary = $update_id_ary = array(); + if ($row = $db->sql_fetchrow($result)) + { + do + { + $add_id_ary[] = $row['user_id']; + + if ($action == 'addleaders' && !$row['group_leader']) + { + $update_id_ary[] = $row['user_id']; + } + } + while ($row = $db->sql_fetchrow($result)); + } + $db->sql_freeresult($result); + + // Do all the users exist in this group? + $add_id_ary = array_diff($id_ary, $add_id_ary); + unset($id_ary); + + // If we have no users + if (!sizeof($add_id_ary) && !sizeof($update_id_ary)) + { + return 'GROUP_USERS_EXIST'; + } + + if (sizeof($add_id_ary)) + { + $group_leader = ($action == 'addleaders') ? 1 : 0; + + // Insert the new users + switch (SQL_LAYER) + { + case 'mysql': + case 'mysql4': + $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) + VALUES " . implode(', ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $group_leader)", $add_id_ary)); + $db->sql_query($sql); + break; + + case 'mssql': + case 'sqlite': + $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) + " . implode(' UNION ALL ', preg_replace('#^([0-9]+)$#', "(\\1, $group_id, $group_leader)", $add_id_ary)); + $db->sql_query($sql); + break; + + default: + foreach ($add_id_ary as $user_id) + { + $sql = 'INSERT INTO ' . USER_GROUP_TABLE . " (user_id, group_id, group_leader) + VALUES ($user_id, $group_id, $group_leader)"; + $db->sql_query($sql); + } + break; + } + + $sql = 'UPDATE ' . USERS_TABLE . " + SET user_permissions = '' + WHERE user_id IN (" . implode(', ', $add_id_ary) . ')'; + $db->sql_query($sql); + } + + $usernames = array(); + if (sizeof($update_id_ary)) + { + $sql = 'UPDATE ' . USER_GROUP_TABLE . ' + SET group_leader = 1 + WHERE user_id IN (' . implode(', ', $update_id_ary) . ") + AND group_id = $group_id"; + $db->sql_query($sql); + + foreach ($update_id_ary as $id) + { + $usernames[] = $username_ary[$id]; + } + } + else + { + foreach ($add_id_ary as $id) + { + $usernames[] = $username_ary[$id]; + } + } + unset($username_ary); + + // Update user settings (color, rank) if applicable + // TODO + // Do not update users who are not approved + if (!empty($_POST['default'])) + { + $sql = 'UPDATE ' . USERS_TABLE . " + SET group_id = $group_id, user_colour = '$color', user_rank = " . intval($rank) . " + WHERE user_id IN (" . implode(', ', array_merge($add_id_ary, $update_id_ary)) . ")"; + $db->sql_query($sql); + } + unset($update_id_ary); + unset($add_id_ary); + + if (!function_exists('add_log')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); + } + + $log = ($action == 'addleaders') ? 'LOG_MODS_ADDED' : 'LOG_USERS_ADDED'; + add_log('admin', $log, $group_name, implode(', ', $usernames)); + + return false; +} + +function create_group($action, $group_id, &$type, &$name, &$desc, &$colour, &$rank, &$avatar) +{ + global $db, $user; + + $error = array(); + + if (isset($type) && $type != GROUP_SPECIAL) + { + $name = (!empty($_POST['group_name'])) ? stripslashes(htmlspecialchars($_POST['group_name'])) : ''; + $type = (!empty($_POST['group_type'])) ? intval($_POST['group_type']) : ''; + } + $desc = (!empty($_POST['group_description'])) ? stripslashes(htmlspecialchars($_POST['group_description'])) : ''; + $colour2 = (!empty($_POST['group_colour'])) ? stripslashes(htmlspecialchars($_POST['group_colour'])) : ''; + $avatar2 = (!empty($_POST['group_avatar'])) ? stripslashes(htmlspecialchars($_POST['group_avatar'])) : ''; + $rank2 = (isset($_POST['group_rank'])) ? intval($_POST['group_rank']) : ''; + + // Check data + if (!strlen($name) || strlen($name) > 40) + { + $error[] = (!strlen($name)) ? $user->lang['GROUP_ERR_USERNAME'] : $user->lang['GROUP_ERR_USER_LONG']; + } + + if (strlen($desc) > 255) + { + $error[] = $user->lang['GROUP_ERR_DESC_LONG']; + } + + if ($type < GROUP_OPEN || $type > GROUP_FREE) + { + $error[] = $user->lang['GROUP_ERR_TYPE']; + } + + // Update DB + if (!sizeof($error)) + { + // Update group preferences + $sql_ary = array( + 'group_name' => (string) $name, + 'group_description' => (string) $desc, + 'group_type' => (int) $type, + 'group_rank' => (int) $rank2, + 'group_colour' => (string) $colour2, + ); + + $sql = ($action == 'edit' && $group_id) ? 'UPDATE ' . GROUPS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " WHERE group_id = $group_id" : 'INSERT INTO ' . GROUPS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); + $db->sql_query($sql); + + if ($group_id && ($colour != $colour2 || $rank != $rank2 || $avatar != $avatar2)) + { + $sql_ary = array( + 'user_rank' => (string) $rank2, + 'user_colour' => (string) $colour2, + ); + + $sql = 'UPDATE ' . USERS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " + WHERE group_id = $group_id"; + $db->sql_query($sql); + } + + if (!function_exists('add_log')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); + } + + $log = ($action == 'edit') ? 'LOG_GROUP_UPDATED' : 'LOG_GROUP_CREATED'; + add_log('admin', $log, $group_name); + } + + $colour = $colour2; + $rank = $rank2; + $avatar = $avatar2; + + return (sizeof($error)) ? $error : false; +} + + +function set_default_group($id, $user_id_ary, $username_ary, &$name, &$colour, &$rank, $avatar, $avatar_type) +{ + global $db; + + if (!is_array($$which_ary)) + { + $$which_ary = array($$which_ary); + } + + if (is_array($user_id_ary) || is_array($username_ary)) + { + $sql_where = ($user_id_ary) ? 'user_id IN (' . implode(', ', $user_id_ary) . ')' : 'username IN (' . implode(', ', $username_ary) . ')'; + + $sql = 'UPDATE ' . USERS_TABLE . " + SET group_id = $id, user_colour = '$colour', user_rank = $rank + WHERE $sql_where"; + $db->sql_query($sql); + } + else + { + switch (SQL_LAYER) + { + case 'mysql': + case 'mysql4': + // With no subselect we do mysql updates in batches to ward off + // potential issues with large groups + + $start = 0; + do + { + $sql = 'SELECT user_id + FROM ' . USER_GROUP_TABLE . " + WHERE group_id = $id + ORDER BY user_id + LIMIT $start, 200"; + $result = $db->sql_query($sql); + + $user_id_ary = array(); + if ($row = $db->sql_fetchrow($result)) + { + do + { + $user_id_ary[] = $row['user_id']; + } + while ($row = $db->sql_fetchrow($result)); + + $sql = 'UPDATE ' . USERS_TABLE . " + SET group_id = $id, user_colour = '$colour', user_rank = $rank + WHERE user_id IN (" . implode(', ', $user_id_ary) . ')'; + $db->sql_query($sql); + + $start = (sizeof($user_id_ary) < 200) ? 0 : $start + 200; + } + else + { + $start = 0; + } + $db->sql_freeresult($result); + } + while ($start); + break; + + default: + $sql = 'UPDATE ' . USERS_TABLE . " + SET group_id = $id, user_colour = '$colour', user_rank = $rank + WHERE user_id IN ( + SELECT user_id + FROM " . USER_GROUP_TABLE . " + WHERE group_id = $id + )"; + $db->sql_query($sql); + break; + } + } + + if (!function_exists('add_log')) + { + global $phpbb_root_path, $phpEx; + include($phpbb_root_path . 'includes/functions_admin.'.$phpEx); + } + + add_log('admin', 'LOG_GROUP_DEFAULTS', $name); + + return false; +} + +// TODO +// approve group +function approve_user($group_id, $user_id_ary, $username_ary, &$group_name) +{ + global $db; + + $sql_where = ($user_id_ary) ? 'user_id IN (' . implode(', ', $user_id_ary) . ')' : 'username IN (' . implode(', ', $username_ary) . ')'; + + $sql = 'SELECT user_id, username + FROM ' . USERS_TABLE . " + WHERE $sql_where"; + $result = $db->sql_query($sql); + + $usernames = array(); + while ($row = $db->sql_fetchrow($result)) + { + $username_ary[] = $row['username']; + $user_id_ary[] = $row['user_id']; + } + $db->sql_freeresult($result); + + $sql = 'UPDATE ' . USER_GROUP_TABLE . ' + SET user_pending = 0 + WHERE user_id IN (' . implode(', ', $user_id_ary) . ") + AND group_id = $group_id"; + $db->sql_query($sql); + + add_log('admin', 'LOG_GROUP_APPROVE', $group_name, implode(', ', $username_ary)); + + unset($username_ary); + unset($user_id_ary); + + return false; +} + ?>
\ No newline at end of file |