4 * Copyright 1999-2000 (c) The SourceForge Crew
5 * Copyright 2010 (c) Franck Villaume - Capgemini
6 * http://fusionforge.org
8 * This file is part of FusionForge. FusionForge is free software;
9 * you can redistribute it and/or modify it under the terms of the
10 * GNU General Public License as published by the Free Software
11 * Foundation; either version 2 of the Licence, or (at your option)
14 * FusionForge is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 require_once '../env.inc.php';
25 require_once $gfcommon.'include/pre.php';
26 require_once $gfwww.'admin/admin_utils.php';
28 // user must be forge admin to proceed
29 session_require_global_perm ('forge_admin');
32 * performAction() - Updates the indicated user status
34 * @param string $newStatus - the new user status
35 * @param string $statusString - the status string to display
36 * @param string $user_id - the user id to act upon
38 function performAction($newStatus, $statusString, $user_id) {
41 $u = user_get_object($user_id);
42 if (!$u || !is_object($u)) {
43 exit_error(_('Could Not Get User'),'home');
44 } elseif ($u->isError()) {
45 exit_error($u->getErrorMessage(),'home');
48 if(!$u->setStatus($newStatus)) {
49 exit_error($u->getErrorMessage(),'home');
51 if(!$u->delete(true)) {
52 exit_error($u->getErrorMessage(),'home');
55 if(!$u->setStatus($newStatus)) {
56 exit_error($u->getErrorMessage(),'home');
58 if(!$u->setUnixStatus($newStatus)) {
59 exit_error($u->getErrorMessage(),'home');
62 $feedback = sprintf(_('User updated to %1$s status'), $statusString);
65 function show_users_list ($users, $filter='', $sortorder='realname') {
66 echo '<p>' ._('Status') .': '.
67 util_make_link('/admin/userlist.php', _('All')). '
68 <span class="active">'.util_make_link('/admin/userlist.php?status=A'.'&sortorder='.$sortorder,_('Active')). '</span>
69 <span class="deleted">'.util_make_link('/admin/userlist.php?status=D'.'&sortorder='.$sortorder,_('Deleted')).'</span>
70 <span class="suspended">'.util_make_link('/admin/userlist.php?status=S'.'&sortorder='.$sortorder,_('Suspended')).'</span>
71 <span class="pending">'.util_make_link('/admin/userlist.php?status=P'.'&sortorder='.$sortorder,_('(*)Pending')).'</span>'.'</p>';
74 echo '<div class="warning_msg">'._('No user found matching selected criteria.').'</div>';
89 '/admin/userlist.php?sortorder=user_name'.$filter,
90 '/admin/userlist.php?sortorder=add_date'.$filter,
98 echo $GLOBALS['HTML']->listTableTop($headers, $headerLinks);
100 $res = db_query_params('SELECT * FROM users WHERE user_id = ANY ($1) ORDER BY '.$sortorder,
101 array(db_int_array_to_any_clause($users)));
103 while ($arr = db_fetch_array($res)) {
104 $u = new GFUser($arr['user_id'], $arr);
105 print '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($count) . '><td class="';
106 if ($u->getStatus() == 'A') print "active";
107 if ($u->getStatus() == 'D') print "deleted";
108 if ($u->getStatus() == 'S') print "suspended";
109 if ($u->getStatus() == 'P') print "pending";
110 print '"><a href="useredit.php?user_id='.$u->getID().'">';
111 if ($u->getStatus() == 'P') print "*";
112 echo $u->getRealName().' ('.$u->getUnixName().')</a>';
114 echo '<td width="15%" class="align-center">';
115 echo ($u->getAddDate() ? date(_('Y-m-d H:i'), $u->getAddDate()) : '-');
117 echo '<td width="15%" style="text-align:center">'.util_make_link ('/developer/?form_dev='.$u->getID(),_('User Profile')).'</td>';
118 echo '<td width="15%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=activate&user_id='.$u->getID().$filter,_('Activate')).'</td>';
119 echo '<td width="15%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=delete&user_id='.$u->getID().$filter,_('Delete')).'</td>';
120 echo '<td width="15%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=suspend&user_id='.$u->getID().$filter,_('Suspend')).'</td>';
121 echo '<td width="12%" style="text-align:center">'.util_make_link ('/admin/passedit.php?user_id='.$u->getID().$filter,_('Change Password')).'</td>';
126 echo $GLOBALS['HTML']->listTableBottom();
130 // Administrative functions
132 $group_id = getIntFromRequest('group_id');
133 $action = getStringFromRequest('action');
134 $user_id = getIntFromRequest('user_id');
135 $status = getStringFromRequest('status');
136 $usingplugin = getStringFromRequest('usingplugin');
138 if ($action=='delete') {
139 performAction('D', "DELETED", $user_id);
140 } elseif ($action=='activate') {
141 performAction('A', "ACTIVE", $user_id);
142 } elseif ($action=='suspend') {
143 performAction('S', "SUSPENDED", $user_id);
146 $HTML->header(array('title'=>_('User List')));
148 // Show list of users
150 echo "<p>"._('Users that use plugin'). " <strong>".$usingplugin."</strong></p>\n";
151 $res = db_query_params ('SELECT u.user_id FROM plugins p, user_plugin up, users u WHERE p.plugin_name = $1 and up.user_id = u.user_id and p.plugin_id = up.plugin_id', array($usingplugin));
152 show_users_list(user_get_objects(util_result_column_to_array($res,0)));
154 } elseif (!$group_id) {
155 $user_name_search = getStringFromRequest('user_name_search');
157 if ($user_name_search) {
158 $res = db_query_params ('SELECT user_id FROM users WHERE lower(user_name) LIKE $1 OR lower(lastname) LIKE $1',
159 array (strtolower("$user_name_search%")));
160 $list_id = util_result_column_to_array($res,0);
161 $msg = sprintf(_('User list beginning with ā%sā for all projects'), $user_name_search);
163 $msg = _('User list for all projects');
165 print "<p><strong>$msg</strong></p>\n";
168 $res = db_query_params ('SELECT user_id FROM users WHERE status = $1',
170 if (isset($list_id)) {
171 $list_id = array_merge($list_id, util_result_column_to_array($res,0));
174 $list_id = util_result_column_to_array($res,0);
177 if (! isset($list_id)) {
178 $res = db_query_params('SELECT user_id FROM users',
180 $list_id = util_result_column_to_array($res,0);
183 if (in_array($status,array('D','A','S','P'))) {
184 $filter = '&status='.$status;
186 $sort_order = getStringFromRequest('sortorder', 'realname');
187 util_ensure_value_in_set ($sort_order,
188 array('realname','user_name','lastname','firstname','user_id','status','add_date')) ;
189 show_users_list ($list_id, $filter, $sort_order);
192 Show list for one project
194 $project = group_get_object($group_id) ;
195 print "<p>" ._('User list for project: ') . "<strong>" . $project->getPublicName() . "</strong></p>";
196 $users = $project->getUsers();
198 foreach ($project->getUsers() as $user) {
199 $users_id[] = $user->getID();
201 $filter = '&group_id='.$group_id;
202 $sort_order = getStringFromRequest('sortorder', 'realname');
203 util_ensure_value_in_set ($sort_order,
204 array('realname','user_name','lastname','firstname','user_id','status','add_date')) ;
205 show_users_list ($users_id, $filter, $sort_order);
208 echo '<p>'._('No user in this project').'</p>';
212 $HTML->footer(array());
216 // c-file-style: "bsd"