2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 require_once('./global.php');
23 require_once('./includes/api_user.php');
25 if (!can_perform('canadminusers'))
30 // ###################################################################
32 if (empty($_REQUEST['do']))
34 $_REQUEST['do'] = 'modify';
37 // ###################################################################
39 if ($_REQUEST['do'] == 'kill')
41 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $bugsys->input_clean('userid', TYPE_UINT
));
44 $admin->error($lang->getlex('error_invalid_id'));
47 if ($user['userid'] == $bugsys->userinfo
['userid'])
49 $admin->error($lang->string('You cannot delete your own account!'));
52 if ($user['usergroupid'] == 6)
54 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> $user[userid]");
55 if ($count['count'] < 1)
57 $admin->error($lang->string('At least one other administrator needs to be present before you can delete this user'));
61 $db->query("DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = $user[userid]");
62 $db->query("DELETE FROM " . TABLE_PREFIX
. "favourite WHERE userid = $user[userid]");
63 $db->query("DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = $user[userid]");
65 $admin->redirect('user.php');
68 // ###################################################################
70 if ($_REQUEST['do'] == 'delete')
72 $admin->page_confirm($lang->string('Are you sure you want to delete this user?'), 'user.php?do=kill&userid=' . $bugsys->input_clean('userid', TYPE_UINT
));
75 // ###################################################################
77 if ($_POST['do'] == 'insert')
79 $user = new UserAPI($bugsys);
80 $user->set('dispayname', $bugsys->in
['displayname']);
81 $user->set('email', $bugsys->in
['email']);
82 $user->set('showemail', $bugsys->in
['showemail']);
83 $user->set('showcolours', $bugsys->in
['showcolours']);
84 $user->set('usergroupid', $bugsys->in
['usergroupid']);
85 $user->set('languageid', $bugsys->in
['languageid']);
86 $user->set('timezone', $bugsys->in
['timezone']);
87 $user->set('password', $bugsys->in
['password']);
92 $admin->redirect('user.php?do=edit&userid=' . $db->insert_id());
95 // ###################################################################
97 if ($_POST['do'] == 'update')
99 $user = new UserAPI($bugsys);
100 $user->set('userid', $bugsys->in
['userid']);
101 $user->set_condition();
102 $user->set('dispayname', $bugsys->in
['displayname']);
103 $user->set('email', $bugsys->in
['email']);
104 $user->set('showemail', $bugsys->in
['showemail']);
105 $user->set('showcolours', $bugsys->in
['showcolours']);
106 $user->set('usergroupid', $bugsys->in
['usergroupid']);
107 $user->set('languageid', $bugsys->in
['languageid']);
108 $user->set('timezone', $bugsys->in
['timezone']);
109 $user->set('password', $bugsys->in
['password']);
114 $admin->redirect('user.php?do=edit&userid=' . $user['userid']);
117 // ###################################################################
119 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
121 $add = ($_REQUEST['do'] == 'add');
126 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $bugsys->input_clean('userid', TYPE_UINT
));
129 $admin->error($lang->getlex('error_invalid_id'));
133 $admin->page_start(($add ?
$lang->string('Add User') : $lang->string('Edit User')), 2, 'user_manage');
135 $admin->form_start('user.php', ($add ?
'insert' : 'update'));
139 $admin->form_hidden_field('userid', $user['userid']);
142 $admin->table_start();
144 $admin->table_head(($add ?
$lang->string('Add User') : sprintf($lang->string('Edit User (userid: %1$s)'), $user['userid'])));
146 $admin->row_input($lang->string('Display Name'), 'displayname', $user['displayname']);
147 $admin->row_input($lang->string('Email'), 'email', $user['email']);
148 $admin->row_input(($add ?
$lang->string('Password') : $lang->string('Password (Leave blank for no change)')), 'password');
150 foreach ($bugsys->datastore
['usergroup'] AS $group)
152 $admin->list_item($group['title'], $group['usergroupid'], ($user['usergroupid'] == $group['usergroupid']));
154 $admin->row_list($lang->string('Usergroup'), 'usergroupid');
156 $admin->row_yesno($lang->string('Show Email Publicly'), 'showemail', $user['showemail']);
157 $admin->row_yesno($lang->string('Show Status Colours on Bug Listings'), 'showcolours', $user['showcolours']);
159 foreach ($bugsys->datastore
['language'] AS $language)
161 $admin->list_item($language['title'], $language['languageid'], ($user['languageid'] == $language['languageid']));
163 $admin->row_list($lang->string('Language'), 'languageid');
165 foreach ($datef->fetch_timezone_list() AS $value => $string)
167 $admin->list_item($string, $value, ($user['timezone'] == $value));
169 $admin->row_list($lang->string('Timezone'), 'timezone');
171 $admin->row_submit(($edit ?
'<a href="user.php?do=delete&userid=' . $user['userid'] . '">[' . $lang->string('Delete') . ']</a>' : ''), ':save:', ':reset:', 4);
179 // ###################################################################
181 if ($_REQUEST['do'] == 'search')
185 if (is_numeric($bugsys->in
['userdata']))
187 $bugsys->input_clean('userdata', TYPE_UINT
);
188 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $bugsys->in
['userdata']))
190 header('Location: user.php?do=edit&userid=' . $bugsys->in
['userdata']);
199 $bugsys->in
['userdata'] = str_replace('%', '\%', $bugsys->in
['userdata']);
200 $results = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email LIKE '%" . $bugsys->input_escape('userdata') . "%' OR displayname LIKE '%" . $bugsys->input_escape('userdata') . "%'");
202 if ($db->num_rows($results) < 1)
208 $admin->page_start($lang->string('Search Results'));
210 $admin->table_start();
211 $admin->table_head($lang->string('Search Results'), 4);
212 $admin->table_column_head(array($lang->string('Display Name'), $lang->string('Email'), $lang->string('User ID'), $lang->string('Actions')));
214 while ($row = $db->fetch_array($results))
216 $admin->row_multi_item(array(
217 $row['displayname'] => 'l',
218 $row['email'] => 'c',
219 $row['userid'] => 'c',
220 '<a href="user.php?do=edit&userid=' . $row['userid'] . '">[' . $lang->string('Edit') . ']</a>' => 'c'
232 $admin->error($lang->string('Sorry, we could not find any users that matched your criteria.'));
236 // ###################################################################
238 if ($_REQUEST['do'] == 'modify')
240 $admin->page_start($lang->string('User Search'));
242 $admin->form_start('user.php', 'search');
243 $admin->table_start(true
, '45%');
245 $admin->table_head($lang->string('User Search'), 2, 'user_manage');
246 $admin->row_input($lang->string('Name/Email/ID'), 'userdata');
248 $admin->row_submit('', ':save:', '');
256 /*=====================================================================*\
257 || ###################################################################
260 || ###################################################################
261 \*=====================================================================*/