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>';
88 '/admin/userlist.php?sortorder=user_name'.$filter,
89 '/admin/userlist.php?sortorder=add_date'.$filter,
97 echo $GLOBALS['HTML']->listTableTop($headers, $headerLinks);
99 $res = db_query_params('SELECT * FROM users WHERE user_id = ANY ($1) ORDER BY '.$sortorder,
100 array(db_int_array_to_any_clause($users)));
102 while ($arr = db_fetch_array($res)) {
103 $u = new GFUser($arr['user_id'], $arr);
104 print '<tr '. $GLOBALS['HTML']->boxGetAltRowStyle($count) . '><td class="';
105 if ($u->getStatus() == 'A') print "active";
106 if ($u->getStatus() == 'D') print "deleted";
107 if ($u->getStatus() == 'S') print "suspended";
108 if ($u->getStatus() == 'P') print "pending";
109 print '"><a href="useredit.php?user_id='.$u->getID().'">';
110 if ($u->getStatus() == 'P') print "*";
111 echo $u->getRealName().' ('.$u->getUnixName().')</a>';
113 echo '<td width="15%" class="align-center">';
114 echo ($u->getAddDate() ? date(_('Y-m-d H:i'), $u->getAddDate()) : '-');
116 echo '<td width="12%" style="text-align:center">'.util_make_link ('/developer/?form_dev='.$u->getID(),_('[DevProfile]')).'</td>';
117 echo '<td width="12%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=activate&user_id='.$u->getID().$filter,_('[Activate]')).'</td>';
118 echo '<td width="12%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=delete&user_id='.$u->getID().$filter,_('[Delete]')).'</td>';
119 echo '<td width="12%" style="text-align:center">'.util_make_link ('/admin/userlist.php?action=suspend&user_id='.$u->getID().$filter,_('[Suspend]')).'</td>';
120 echo '<td width="12%" style="text-align:center">'.util_make_link ('/admin/passedit.php?user_id='.$u->getID().$filter,_('[Change PW]')).'</td>';
125 echo $GLOBALS['HTML']->listTableBottom();
129 // Administrative functions
131 $group_id = getIntFromRequest('group_id');
132 $action = getStringFromRequest('action');
133 $user_id = getIntFromRequest('user_id');
134 $status = getStringFromRequest('status');
135 $usingplugin = getStringFromRequest('usingplugin');
137 if ($action=='delete') {
138 performAction('D', "DELETED", $user_id);
139 } else if ($action=='activate') {
140 performAction('A', "ACTIVE", $user_id);
141 } else if ($action=='suspend') {
142 performAction('S', "SUSPENDED", $user_id);
145 $HTML->header(array('title'=>_('User List')));
147 // Show list of users
149 echo "<p>"._('Users that use plugin'). " <strong>".$usingplugin."</strong></p>\n";
150 $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));
151 show_users_list(user_get_objects(util_result_column_to_array($res,0)));
153 } else if (!$group_id) {
154 $user_name_search = getStringFromRequest('user_name_search');
156 print "<p>" ._('User list for ') . "<strong>" ._('All Projects'). "</strong></p>";
158 if ($user_name_search) {
159 $res = db_query_params ('SELECT user_id FROM users WHERE lower(user_name) LIKE $1 OR lower(lastname) LIKE $1',
160 array (strtolower("$user_name_search%")));
161 $list_id = util_result_column_to_array($res,0);
164 $res = db_query_params ('SELECT user_id FROM users WHERE status = $1',
166 if (isset($list_id)) {
167 $list_id = array_merge($list_id, util_result_column_to_array($res,0));
170 $list_id = util_result_column_to_array($res,0);
173 if (! isset($list_id)) {
174 $res = db_query_params('SELECT user_id FROM users',
176 $list_id = util_result_column_to_array($res,0);
179 if (in_array($status,array('D','A','S','P'))) {
180 $filter = '&status='.$status;
182 $sortorder = getStringFromRequest('sortorder', 'realname');
183 util_ensure_value_in_set ($sortorder,
184 array('realname','user_name','lastname','firstname','user_id','status','add_date')) ;
185 show_users_list ($list_id, $filter, $sortorder);
188 Show list for one project
190 $project = group_get_object($group_id) ;
191 print "<p>" ._('User list for project: ') . "<strong>" . $project->getPublicName() . "</strong></p>";
192 $users = $project->getUsers();
194 foreach ($project->getUsers() as $user) {
195 $users_id[] = $user->getID();
197 $filter = '&group_id='.$group_id;
198 $sortorder = getStringFromRequest('sortorder', 'realname');
199 util_ensure_value_in_set ($sortorder,
200 array('realname','user_name','lastname','firstname','user_id','status','add_date')) ;
201 show_users_list ($users_id, $filter, $sortorder);
204 echo '<p>'._('No user in this project').'</p>';
208 $HTML->footer(array());
212 // c-file-style: "bsd"