2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
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');
24 require_once('./includes/class_sort.php');
26 require_once('./includes/class_api_error.php');
27 APIError(array(new API_Error_Handler($admin), 'admin_error'));
29 NavLinks
::usersPages();
30 $navigator->set_focus('tab', 'users', null
);
32 if (!can_perform('canadminusers'))
37 // ###################################################################
39 * Generate an inline checkbox
44 * @param bool Checked?
46 * @return string HTML checkbxo
48 function draw_checkbox($name, $checked)
50 return "<input type=\"checkbox\" class=\"button\" name=\"{$name}\" value=\"1\"" . ($checked == true ?
' checked="checked"' : '') . " />";
53 // ###################################################################
55 if (empty($_REQUEST['do']))
57 $_REQUEST['do'] = 'modify';
60 // ###################################################################
62 if ($_REQUEST['do'] == 'kill')
64 $user = new UserAPI($bugsys);
65 $user->set('userid', $bugsys->in
['userid']);
66 $user->set_condition();
69 $admin->redirect('user.php');
72 // ###################################################################
74 if ($_REQUEST['do'] == 'delete')
76 $admin->page_confirm(_('Are you sure you want to delete this user?'), 'user.php', 'kill', array('userid' => $bugsys->input_clean('userid', TYPE_UINT
)));
79 // ###################################################################
81 if ($_POST['do'] == 'insert')
83 $user = new UserAPI($bugsys);
84 $user->set('displayname', $bugsys->in
['displayname']);
85 $user->set('email', $bugsys->in
['email']);
86 $user->set('showemail', $bugsys->in
['showemail']);
87 $user->set('showcolors', $bugsys->in
['showcolors']);
88 $user->set('usergroupid', $bugsys->in
['usergroupid']);
89 $user->set('languageid', $bugsys->in
['languageid']);
90 $user->set('timezone', $bugsys->in
['timezone']);
91 $user->set('usedst', $bugsys->in
['usedst']);
92 $user->set('password', $bugsys->in
['password']);
93 $user->set('hidestatuses', $bugsys->in
['hidestatuses']);
94 $user->set('defaultsortkey', $bugsys->in
['defaultsortkey']);
95 $user->set('defaultsortas', $bugsys->in
['defaultsortas']);
98 // post_insert will set the email options... so we now have to dump them
99 $db->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->insertid
);
101 $bugsys->input_clean('emailopts', TYPE_INT
);
102 foreach ($bugsys->in
['emailopts'] AS $relation => $bitarr)
105 foreach ($bitarr AS $option => $yes)
107 $bitmask +
= $option * $yes;
109 $db->query("INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user->insertid
. ", $relation, $bitmask)");
112 $admin->redirect('user.php?do=edit&userid=' . $user->insertid
);
115 // ###################################################################
117 if ($_POST['do'] == 'update')
119 $user = new UserAPI($bugsys);
120 $user->set('userid', $bugsys->in
['userid']);
121 $user->set_condition();
122 $user->set('displayname', $bugsys->in
['displayname']);
123 $user->set('email', $bugsys->in
['email']);
124 $user->set('showemail', $bugsys->in
['showemail']);
125 $user->set('showcolors', $bugsys->in
['showcolors']);
126 $user->set('usergroupid', $bugsys->in
['usergroupid']);
127 $user->set('languageid', $bugsys->in
['languageid']);
128 $user->set('timezone', $bugsys->in
['timezone']);
129 $user->set('usedst', $bugsys->in
['usedst']);
130 $user->set('password', $bugsys->in
['password']);
131 $user->set('hidestatuses', $bugsys->in
['hidestatuses']);
132 $user->set('defaultsortkey', $bugsys->in
['defaultsortkey']);
133 $user->set('defaultsortas', $bugsys->in
['defaultsortas']);
136 $db->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->values
['userid']);
137 $bugsys->input_clean('emailopts', TYPE_INT
);
138 if (is_array($bugsys->in
['emailopts']))
140 foreach ($bugsys->in
['emailopts'] AS $relation => $bitarr)
143 foreach ($bitarr AS $option => $yes)
145 $bitmask +
= $option * $yes;
147 $db->query("INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user->values
['userid'] . ", $relation, $bitmask)");
151 $admin->redirect('user.php?do=edit&userid=' . $user->objdata
['userid']);
154 // ###################################################################
156 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
158 $add = ($_REQUEST['do'] == 'add');
163 NavLinks
::usersEdit($bugsys->in
['userid']);
164 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
166 $user = new UserAPI($bugsys);
167 $user->set('userid', $bugsys->in
['userid']);
168 $user->set_condition();
173 NavLinks
::usersAdd();
174 $navigator->set_focus('link', 'users-add', 'users');
177 $admin->page_start(($add ?
_('Add User') : _('Edit User')));
179 $admin->form_start('user.php', ($add ?
'insert' : 'update'));
183 $admin->form_hidden_field('userid', $user->objdata
['userid']);
186 $admin->table_start();
188 $admin->table_head(($add ?
_('Add User') : sprintf(_('Edit User (userid: %1$s)'), $user->objdata
['userid'])));
190 $admin->row_input(_('Display Name'), 'displayname', $user->objdata
['displayname']);
191 $admin->row_input(_('Email'), 'email', $user->objdata
['email']);
192 $admin->row_input(($add ?
_('Password') : _('Password (Leave blank for no change)')), 'password');
194 foreach ($bugsys->datastore
['usergroup'] AS $group)
196 $admin->list_item($group['title'], $group['usergroupid'], ($user->objdata
['usergroupid'] == $group['usergroupid']));
198 $admin->row_list(_('Usergroup'), 'usergroupid');
200 $admin->row_yesno(_('Show Email Publicly'), 'showemail', $user->objdata
['showemail']);
201 $admin->row_yesno(_('Show Status Colors on Bug Listings'), 'showcolors', $user->objdata
['showcolors']);
203 foreach ($bugsys->datastore
['language'] AS $language)
205 $admin->list_item($language['title'], $language['languageid'], ($user->objdata
['languageid'] == $language['languageid']));
207 $admin->row_list(_('Language'), 'languageid');
209 foreach ($datef->fetch_timezone_list() AS $value => $string)
211 $admin->list_item($string, $value, ($user->objdata
['timezone'] == $value));
213 $admin->row_list(_('Timezone'), 'timezone');
215 $admin->row_yesno(_('Observe Daylight Savings Time (DST)'), 'usedst', $user->objdata
['usedst']);
216 $admin->row_text(_('Hidden Statuses on Bug Listing'), construct_option_select('hidestatuses', $bugsys->datastore
['status'], $user->objdata
['hidestatuses'], 'statusid', 'status', 0, true
));
217 $admin->row_text(_('Default Sort Order Column'), construct_option_select('defaultsortkey', ListSorter
::fetch_by_text(false
), $user->objdata
['defaultsortkey']));
218 $admin->row_text(_('Default Sort Order Direction'), construct_option_select('defaultsortas', ListSorter
::fetch_as_text(false
), $user->objdata
['defaultsortas']));
222 // -------------------------------------------------------------------
223 $admin->table_start(false
);
224 $admin->table_head(_('Email Options'), 6);
226 if ($user->objdata
['userid'])
228 $options = $db->query("SELECT * FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->objdata
['userid']);
229 while ($opt = $db->fetch_array($options))
231 foreach ($bugsys->emailoptions
['notifications'] AS $name => $notif)
233 foreach ($bugsys->emailoptions
['relations'] AS $name => $relation)
235 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
237 $checked["$relation"]["$notif"] = HTML_CHECKED
;
244 $admin->table_column_head(array('', _('Reporter'), _('Assignee'), _('Favorite'), _('Voter'), _('Commenter')));
246 // -------------------------------------------------------------------
248 $admin->row_text(_('New bug is added'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][2048]', $checked[0][2048]) . '</div>', 'top', 6);
250 $admin->row_text(_('I am made the assignee'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][32]', $checked[0][32]) . '</div>', 'top', 6);
252 $admin->row_multi_item(array(
253 _('Status or resolution changes') => 'l',
254 draw_checkbox('emailopts[1][64]', $checked[1][64]) => 'c',
255 draw_checkbox('emailopts[2][64]', $checked[2][64]) => 'c',
256 draw_checkbox('emailopts[4][64]', $checked[4][64]) => 'c',
257 draw_checkbox('emailopts[8][64]', $checked[8][64]) => 'c',
258 draw_checkbox('emailopts[16][64]', $checked[16][64]) => 'c',
261 $admin->row_multi_item(array(
262 _("'Duplicates' field is changed") => 'l',
263 draw_checkbox('emailopts[1][128]', $checked[1][128]) => 'c',
264 draw_checkbox('emailopts[2][128]', $checked[2][128]) => 'c',
265 draw_checkbox('emailopts[4][128]', $checked[4][128]) => 'c',
266 draw_checkbox('emailopts[8][128]', $checked[8][128]) => 'c',
267 draw_checkbox('emailopts[16][128]', $checked[16][128]) => 'c',
270 $admin->row_multi_item(array(
271 _('A new comment is added') => 'l',
272 draw_checkbox('emailopts[1][256]', $checked[1][256]) => 'c',
273 draw_checkbox('emailopts[2][256]', $checked[2][256]) => 'c',
274 draw_checkbox('emailopts[4][256]', $checked[4][256]) => 'c',
275 draw_checkbox('emailopts[8][256]', $checked[8][256]) => 'c',
276 draw_checkbox('emailopts[16][256]', $checked[16][256]) => 'c',
279 $admin->row_multi_item(array(
280 _('A new attachment is added') => 'l',
281 draw_checkbox('emailopts[1][512]', $checked[1][512]) => 'c',
282 draw_checkbox('emailopts[2][512]', $checked[2][512]) => 'c',
283 draw_checkbox('emailopts[4][512]', $checked[4][512]) => 'c',
284 draw_checkbox('emailopts[8][512]', $checked[8][512]) => 'c',
285 draw_checkbox('emailopts[16][512]', $checked[16][512]) => 'c',
288 $admin->row_multi_item(array(
289 _('Any other field changes') => 'l',
290 draw_checkbox('emailopts[1][1024]', $checked[1][1024]) => 'c',
291 draw_checkbox('emailopts[2][1024]', $checked[2][1024]) => 'c',
292 draw_checkbox('emailopts[4][1024]', $checked[4][1024]) => 'c',
293 draw_checkbox('emailopts[8][1024]', $checked[8][1024]) => 'c',
294 draw_checkbox('emailopts[16][1024]', $checked[16][1024]) => 'c',
297 // -------------------------------------------------------------------
298 $admin->row_submit(null
, ':save:', ':reset:', 6);
306 // ###################################################################
308 if ($_REQUEST['do'] == 'search')
312 NavLinks
::usersAdd();
313 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
315 if (is_numeric($bugsys->in
['userdata']))
317 $bugsys->input_clean('userdata', TYPE_UINT
);
318 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $bugsys->in
['userdata']))
320 header('Location: user.php?do=edit&userid=' . $bugsys->in
['userdata']);
329 $bugsys->in
['userdata'] = str_replace('%', '\%', $bugsys->in
['userdata']);
330 $results = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email LIKE '%" . $bugsys->input_escape('userdata') . "%' OR displayname LIKE '%" . $bugsys->input_escape('userdata') . "%'");
332 if ($db->num_rows($results) < 1)
338 $admin->page_start(_('Search Results'));
340 $admin->table_start();
341 $admin->table_head(_('Search Results'), 4);
342 $admin->table_column_head(array(_('Display Name'), _('Email'), _('User ID'), _('Actions')));
344 while ($row = $db->fetch_array($results))
346 $admin->row_multi_item(array(
347 $row['displayname'] => 'l',
348 $row['email'] => 'c',
349 $row['userid'] => 'c',
350 '<a href="user.php?do=edit&userid=' . $row['userid'] . '">[' . _('Edit') . ']</a>' => 'c'
362 $admin->error(_('Sorry, we could not find any users that matched your criteria.'));
366 // ###################################################################
368 if ($_REQUEST['do'] == 'showall')
370 NavLinks
::usersAdd();
371 $navigator->set_focus('link', 'users-showall', 'users');
373 LoadPaginationFramework();
374 $pagination->setBitProcessor('AdminPageNavigatorBitCallback');
375 $pagination->setNavigatorProcessor('AdminPageNavigatorCallback');
377 $admin->page_start(_('Show All Users'));
378 $admin->table_start();
379 $admin->table_head(_('Show All Users'), 4);
380 $admin->table_column_head(array(_('Display Name'), _('Email'), _('User ID'), _('Actions')));
382 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user");
383 $pagination->setTotal($count['count']);
384 $pagination->splitPages();
386 $users = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user ORDER BY userid ASC LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage());
387 while ($user = $db->fetch_array($users))
389 $admin->row_multi_item(array(
390 $user['displayname'] => 'l',
391 $user['email'] => 'c',
392 $user['userid'] => 'c',
393 '<a href="user.php?do=edit&userid=' . $user['userid'] . '">[' . _('Edit') . ']</a>' => 'c'
399 $admin->page_code($pagination->constructPageNav('user.php?do=showall'));
404 // ###################################################################
406 if ($_REQUEST['do'] == 'modify')
408 NavLinks
::usersAdd();
409 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
411 $admin->page_start(_('User Search'));
413 $admin->form_start('user.php', 'search');
414 $admin->table_start(true
, '45%');
416 $admin->table_head(_('User Search'));
417 $admin->row_input(_('Name/Email/ID'), 'userdata');
419 $admin->row_submit('', ':save:', '');
427 /*=====================================================================*\
428 || ###################################################################
431 || ###################################################################
432 \*=====================================================================*/