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');
24 if (!can_perform('canadminusers'))
29 // ###################################################################
31 if (empty($_REQUEST['do']))
33 $_REQUEST['do'] = 'modify';
36 // ###################################################################
38 if ($_REQUEST['do'] == 'kill')
40 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . intval($bugsys->in
['userid']));
43 $admin->error($lang->getlex('error_invalid_id'));
46 if ($user['userid'] == $bugsys->userinfo
['userid'])
48 $admin->error($lang->string('You cannot delete your own account!'));
51 if ($user['usergroupid'] == 6)
53 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user WHERE usergroupid = 6 AND userid <> $user[userid]");
54 if ($count['count'] < 1)
56 $admin->error($lang->string('At least one other administrator needs to be present before you can delete this user'));
60 $db->query("DELETE FROM " . TABLE_PREFIX
. "user WHERE userid = $user[userid]");
61 $db->query("DELETE FROM " . TABLE_PREFIX
. "favourite WHERE userid = $user[userid]");
62 $db->query("DELETE FROM " . TABLE_PREFIX
. "useractivation WHERE userid = $user[userid]");
64 $admin->redirect('user.php');
67 // ###################################################################
69 if ($_REQUEST['do'] == 'delete')
71 $admin->page_confirm($lang->string('Are you sure you want to delete this user?'), 'user.php?do=kill&userid=' . intval($bugsys->in
['userid']));
74 // ###################################################################
76 if ($_POST['do'] == 'insert')
78 $salt = $funct->rand(15);
81 INSERT INTO " . TABLE_PREFIX
. "user
82 (email, displayname, password, salt, authkey, showemail, showcolours, languageid, usergroupid, timezone)
84 ('" . $bugsys->in
['email'] . "',
85 '" . $bugsys->in
['displayname'] . "',
86 '" . md5(md5($bugsys->in
['password']) . md5($salt)) . "',
88 '" . $funct->rand() . "',
89 " . intval($bugsys->in
['showemail']) . ",
90 " . intval($bugsys->in
['showcolours']) . ",
91 " . intval($bugsys->in
['languageid']) . ",
92 " . intval($bugsys->in
['usergroupid']) . ",
93 " . intval($bugsys->in
['timezone']) . "
99 $admin->redirect('user.php?do=edit&userid=' . $db->insert_id());
102 // ###################################################################
104 if ($_POST['do'] == 'update')
106 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . intval($bugsys->in
['userid']));
109 $admin->error($lang->getlex('error_invalid_id'));
113 UPDATE " . TABLE_PREFIX
. "user
114 SET displayname = '" . $bugsys->in
['displayname'] . "',
115 email = '" . $bugsys->in
['email'] . "',
116 showcolours = " . intval($bugsys->in
['showcolours']) . ",
117 usergroupid = " . intval($bugsys->in
['usergroupid']) . ",
118 languageid = " . intval($bugsys->in
['languageid']) . ",
119 timezone = " . intval($bugsys->in
['timezone']) . ($bugsys->in
['password'] ?
",
120 password = '" . md5(md5($bugsys->in
['password']) . md5($user['salt'])) . "'" : '') . "
121 WHERE userid = $user[userid]"
126 $admin->redirect('user.php?do=edit&userid=' . $user['userid']);
129 // ###################################################################
131 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
133 $add = ($_REQUEST['do'] == 'add');
138 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . intval($bugsys->in
['userid']));
141 $admin->error($lang->getlex('error_invalid_id'));
145 $admin->page_start(($add ?
$lang->string('Add User') : $lang->string('Edit User')), 2, 'user_manage');
147 $admin->form_start('user.php', ($add ?
'insert' : 'update'));
151 $admin->form_hidden_field('userid', $user['userid']);
154 $admin->table_start();
156 $admin->table_head(($add ?
$lang->string('Add User') : sprintf($lang->string('Edit User (userid: %1$s)'), $user['userid'])));
158 $admin->row_input($lang->string('Display Name'), 'displayname', $user['displayname']);
159 $admin->row_input($lang->string('Email'), 'email', $user['email']);
160 $admin->row_input(($add ?
$lang->string('Password') : $lang->string('Password (Leave blank for no change)')), 'password');
162 foreach ($bugsys->datastore
['usergroup'] AS $group)
164 $admin->list_item($group['title'], $group['usergroupid'], ($user['usergroupid'] == $group['usergroupid']));
166 $admin->row_list($lang->string('Usergroup'), 'usergroupid');
168 $admin->row_yesno($lang->string('Show Email Publicly'), 'showemail', $user['showemail']);
169 $admin->row_yesno($lang->string('Show Status Colours on Bug Listings'), 'showcolours', $user['showcolours']);
171 foreach ($bugsys->datastore
['language'] AS $language)
173 $admin->list_item($language['title'], $language['languageid'], ($user['languageid'] == $language['languageid']));
175 $admin->row_list($lang->string('Language'), 'languageid');
177 foreach ($datef->fetch_timezone_list() AS $value => $string)
179 $admin->list_item($string, $value, ($user['timezone'] == $value));
181 $admin->row_list($lang->string('Timezone'), 'timezone');
183 $admin->row_submit(($edit ?
'<a href="user.php?do=delete&userid=' . $user['userid'] . '">[' . $lang->string('Delete') . ']</a>' : ''), ':save:', ':reset:', 4);
191 // ###################################################################
193 if ($_REQUEST['do'] == 'search')
197 if (is_numeric($bugsys->in
['userdata']))
199 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . intval($bugsys->in
['userdata'])))
201 header('Location: user.php?do=edit&userid=' . intval($bugsys->in
['userdata']));
210 $bugsys->in
['userdata'] = str_replace('%', '\%', $bugsys->in
['userdata']);
211 $results = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email LIKE '%" . $bugsys->in
['userdata'] . "%' OR displayname LIKE '%" . $bugsys->in
['userdata'] . "%'");
213 if ($db->num_rows($results) < 1)
219 $admin->page_start($lang->string('Search Results'));
221 $admin->table_start();
222 $admin->table_head($lang->string('Search Results'), 4);
223 $admin->table_column_head(array($lang->string('Display Name'), $lang->string('Email'), $lang->string('User ID'), $lang->string('Actions')));
225 while ($row = $db->fetch_array($results))
227 $admin->row_multi_item(array(
228 $row['displayname'] => 'l',
229 $row['email'] => 'c',
230 $row['userid'] => 'c',
231 '<a href="user.php?do=edit&userid=' . $row['userid'] . '">[' . $lang->string('Edit') . ']</a>' => 'c'
243 $admin->error($lang->string('Sorry, we could not find any users that matched your criteria.'));
247 // ###################################################################
249 if ($_REQUEST['do'] == 'modify')
251 $admin->page_start($lang->string('User Search'));
253 $admin->form_start('user.php', 'search');
254 $admin->table_start(true
, '45%');
256 $admin->table_head($lang->string('User Search'), 2, 'user_manage');
257 $admin->row_input($lang->string('Name/Email/ID'), 'userdata');
259 $admin->row_submit('', ':save:', '');
267 /*=====================================================================*\
268 || ###################################################################
271 || ###################################################################
272 \*=====================================================================*/