2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 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 2 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(T('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('groupids', $bugsys->in
['groupids']);
90 $user->set('languageid', $bugsys->in
['languageid']);
91 $user->set('timezone', $bugsys->in
['timezone']);
92 $user->set('usedst', $bugsys->in
['usedst']);
93 $user->set('password', $bugsys->in
['password']);
94 $user->set('hidestatuses', $bugsys->in
['hidestatuses']);
95 $user->set('defaultsortkey', $bugsys->in
['defaultsortkey']);
96 $user->set('defaultsortas', $bugsys->in
['defaultsortas']);
99 // post_insert will set the email options... so we now have to dump them
100 $db->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->insertid
);
102 $bugsys->input_clean('emailopts', TYPE_INT
);
103 if (is_array($bugsys->in
['emailopts']))
105 foreach ($bugsys->in
['emailopts'] AS $relation => $bitarr)
108 foreach ($bitarr AS $option => $yes)
110 $bitmask +
= $option * $yes;
112 $db->query("INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user->insertid
. ", $relation, $bitmask)");
116 $admin->redirect('user.php?do=edit&userid=' . $user->insertid
);
119 // ###################################################################
121 if ($_POST['do'] == 'update')
123 $user = new UserAPI($bugsys);
124 $user->set('userid', $bugsys->in
['userid']);
125 $user->set_condition();
126 $user->set('displayname', $bugsys->in
['displayname']);
127 $user->set('email', $bugsys->in
['email']);
128 $user->set('showemail', $bugsys->in
['showemail']);
129 $user->set('showcolors', $bugsys->in
['showcolors']);
130 $user->set('usergroupid', $bugsys->in
['usergroupid']);
131 $user->set('groupids', $bugsys->in
['groupids']);
132 $user->set('languageid', $bugsys->in
['languageid']);
133 $user->set('timezone', $bugsys->in
['timezone']);
134 $user->set('usedst', $bugsys->in
['usedst']);
135 $user->set('password', $bugsys->in
['password']);
136 $user->set('hidestatuses', $bugsys->in
['hidestatuses']);
137 $user->set('defaultsortkey', $bugsys->in
['defaultsortkey']);
138 $user->set('defaultsortas', $bugsys->in
['defaultsortas']);
141 $db->query("DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->values
['userid']);
142 $bugsys->input_clean('emailopts', TYPE_INT
);
143 if (is_array($bugsys->in
['emailopts']))
145 foreach ($bugsys->in
['emailopts'] AS $relation => $bitarr)
148 foreach ($bitarr AS $option => $yes)
150 $bitmask +
= $option * $yes;
152 $db->query("INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . $user->values
['userid'] . ", $relation, $bitmask)");
156 $admin->redirect('user.php?do=edit&userid=' . $user->objdata
['userid']);
159 // ###################################################################
161 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
163 $add = ($_REQUEST['do'] == 'add');
168 NavLinks
::usersEdit($bugsys->in
['userid']);
169 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
171 $user = new UserAPI($bugsys);
172 $user->set('userid', $bugsys->in
['userid']);
173 $user->set_condition();
178 NavLinks
::usersAdd();
179 $navigator->set_focus('link', 'users-add', 'users');
182 $admin->page_start(($add ?
T('Add User') : T('Edit User')));
184 $admin->form_start('user.php', ($add ?
'insert' : 'update'));
188 $admin->form_hidden_field('userid', $user->objdata
['userid']);
191 $admin->table_start();
193 $admin->table_head(($add ?
T('Add User') : sprintf(T('Edit User (userid: %1$s)'), $user->objdata
['userid'])));
195 $admin->row_input(T('Display Name'), 'displayname', $user->objdata
['displayname']);
196 $admin->row_input(T('Email'), 'email', $user->objdata
['email']);
197 $admin->row_input(($add ?
T('Password') : T('Password (Leave blank for no change)')), 'password');
199 foreach (bugdar
::$datastore['usergroup'] AS $group)
201 $admin->list_item($group['title'], $group['usergroupid'], ($user->objdata
['usergroupid'] == $group['usergroupid']));
203 $admin->row_list(T('Primary Usergroup'), 'usergroupid');
205 $ids = explode(',', $user->objdata
['groupids']);
206 foreach (bugdar
::$datastore['usergroup'] AS $id => $group)
208 if ($id == $user->objdata
['usergroupid'])
212 $admin->list_item($group['title'], $group['usergroupid'], in_array($id, $ids));
214 $admin->row_checkbox(T('Secondary Usergroups'), 'groupids');
216 $admin->row_yesno(T('Show Email Publicly'), 'showemail', $user->objdata
['showemail']);
217 $admin->row_yesno(T('Show Status Colors on Bug Listings'), 'showcolors', $user->objdata
['showcolors']);
219 foreach (bugdar
::$datastore['language'] AS $language)
221 $admin->list_item($language['title'], $language['languageid'], ($user->objdata
['languageid'] == $language['languageid']));
223 $admin->row_list(T('Language'), 'languageid');
225 foreach ($datef->fetch_timezone_list() AS $value => $string)
227 $admin->list_item($string, $value, ($user->objdata
['timezone'] == $value));
229 $admin->row_list(T('Timezone'), 'timezone');
231 $admin->row_yesno(T('Observe Daylight Savings Time (DST)'), 'usedst', $user->objdata
['usedst']);
232 $admin->row_text(T('Hidden Statuses on Bug Listing'), construct_option_select('hidestatuses', bugdar
::$datastore['status'], $user->objdata
['hidestatuses'], 'statusid', 'status', 0, true
));
233 $admin->row_text(T('Default Sort Order Column'), construct_option_select('defaultsortkey', ListSorter
::fetch_by_text(false
), $user->objdata
['defaultsortkey']));
234 $admin->row_text(T('Default Sort Order Direction'), construct_option_select('defaultsortas', ListSorter
::fetch_as_text(false
), $user->objdata
['defaultsortas']));
238 // -------------------------------------------------------------------
239 $admin->table_start(false
);
240 $admin->table_head(T('Email Options'), 6);
242 if ($user->objdata
['userid'])
244 $options = $db->query("SELECT * FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . $user->objdata
['userid']);
245 foreach ($options as $opt)
247 foreach ($bugsys->emailoptions
['notifications'] AS $name => $notif)
249 foreach ($bugsys->emailoptions
['relations'] AS $name => $relation)
251 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
253 $checked["$relation"]["$notif"] = HTML_CHECKED
;
260 $admin->table_column_head(array('', T('Reporter'), T('Assignee'), T('Favorite'), T('Voter'), T('Commenter')));
262 // -------------------------------------------------------------------
264 $admin->row_text(T('New bug is added'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][2048]', $checked[0][2048]) . '</div>', 'top', 6);
266 $admin->row_text(T('I am made the assignee'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][32]', $checked[0][32]) . '</div>', 'top', 6);
268 $admin->row_multi_item(array(
269 T('Status or resolution changes') => 'l',
270 draw_checkbox('emailopts[1][64]', $checked[1][64]) => 'c',
271 draw_checkbox('emailopts[2][64]', $checked[2][64]) => 'c',
272 draw_checkbox('emailopts[4][64]', $checked[4][64]) => 'c',
273 draw_checkbox('emailopts[8][64]', $checked[8][64]) => 'c',
274 draw_checkbox('emailopts[16][64]', $checked[16][64]) => 'c',
277 $admin->row_multi_item(array(
278 T("'Duplicates' field is changed") => 'l',
279 draw_checkbox('emailopts[1][128]', $checked[1][128]) => 'c',
280 draw_checkbox('emailopts[2][128]', $checked[2][128]) => 'c',
281 draw_checkbox('emailopts[4][128]', $checked[4][128]) => 'c',
282 draw_checkbox('emailopts[8][128]', $checked[8][128]) => 'c',
283 draw_checkbox('emailopts[16][128]', $checked[16][128]) => 'c',
286 $admin->row_multi_item(array(
287 T('A new comment is added') => 'l',
288 draw_checkbox('emailopts[1][256]', $checked[1][256]) => 'c',
289 draw_checkbox('emailopts[2][256]', $checked[2][256]) => 'c',
290 draw_checkbox('emailopts[4][256]', $checked[4][256]) => 'c',
291 draw_checkbox('emailopts[8][256]', $checked[8][256]) => 'c',
292 draw_checkbox('emailopts[16][256]', $checked[16][256]) => 'c',
295 $admin->row_multi_item(array(
296 T('A new attachment is added') => 'l',
297 draw_checkbox('emailopts[1][512]', $checked[1][512]) => 'c',
298 draw_checkbox('emailopts[2][512]', $checked[2][512]) => 'c',
299 draw_checkbox('emailopts[4][512]', $checked[4][512]) => 'c',
300 draw_checkbox('emailopts[8][512]', $checked[8][512]) => 'c',
301 draw_checkbox('emailopts[16][512]', $checked[16][512]) => 'c',
304 $admin->row_multi_item(array(
305 T('Any other field changes') => 'l',
306 draw_checkbox('emailopts[1][1024]', $checked[1][1024]) => 'c',
307 draw_checkbox('emailopts[2][1024]', $checked[2][1024]) => 'c',
308 draw_checkbox('emailopts[4][1024]', $checked[4][1024]) => 'c',
309 draw_checkbox('emailopts[8][1024]', $checked[8][1024]) => 'c',
310 draw_checkbox('emailopts[16][1024]', $checked[16][1024]) => 'c',
313 // -------------------------------------------------------------------
314 $admin->row_submit(null
, ':save:', ':reset:', 6);
322 // ###################################################################
324 if ($_REQUEST['do'] == 'search')
328 NavLinks
::usersAdd();
329 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
331 if (is_numeric($bugsys->in
['userdata']))
333 $bugsys->input_clean('userdata', TYPE_UINT
);
334 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX
. "user WHERE userid = " . $bugsys->in
['userdata']))
336 header('Location: user.php?do=edit&userid=' . $bugsys->in
['userdata']);
345 $bugsys->in
['userdata'] = str_replace('%', '\%', $bugsys->in
['userdata']);
346 $results = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user WHERE email LIKE '%" . $bugsys->input_escape('userdata') . "%' OR displayname LIKE '%" . $bugsys->input_escape('userdata') . "%'");
348 if ($db->num_rows($results) < 1)
354 $admin->page_start(T('Search Results'));
356 $admin->table_start();
357 $admin->table_head(T('Search Results'), 4);
358 $admin->table_column_head(array(T('Display Name'), T('Email'), T('User ID'), T('Actions')));
360 foreach ($results as $row)
362 $admin->row_multi_item(array(
363 $row['displayname'] => 'l',
364 $row['email'] => 'c',
365 $row['userid'] => 'c',
366 '<a href="user.php?do=edit&userid=' . $row['userid'] . '">[' . T('Edit') . ']</a>' => 'c'
378 $admin->error(T('Sorry, we could not find any users that matched your criteria.'));
382 // ###################################################################
384 if ($_REQUEST['do'] == 'showall')
386 NavLinks
::usersAdd();
387 $navigator->set_focus('link', 'users-showall', 'users');
389 LoadPaginationFramework();
390 $pagination->setBitProcessor('AdminPageNavigatorBitCallback');
391 $pagination->setNavigatorProcessor('AdminPageNavigatorCallback');
393 $admin->page_start(T('Show All Users'));
394 $admin->table_start();
395 $admin->table_head(T('Show All Users'), 4);
396 $admin->table_column_head(array(T('Display Name'), T('Email'), T('User ID'), T('Actions')));
398 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX
. "user");
399 $pagination->setTotal($count['count']);
400 $pagination->splitPages();
402 $users = $db->query("SELECT * FROM " . TABLE_PREFIX
. "user ORDER BY userid ASC LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage());
403 foreach ($users as $user)
405 $admin->row_multi_item(array(
406 $user['displayname'] => 'l',
407 $user['email'] => 'c',
408 $user['userid'] => 'c',
409 '<a href="user.php?do=edit&userid=' . $user['userid'] . '">[' . T('Edit') . ']</a>' => 'c'
415 $admin->page_code($pagination->constructPageNav('user.php?do=showall'));
420 // ###################################################################
422 if ($_REQUEST['do'] == 'modify')
424 NavLinks
::usersAdd();
425 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
427 $admin->page_start(T('User Search'));
429 $admin->form_start('user.php', 'search');
430 $admin->table_start(true
, '45%');
432 $admin->table_head(T('User Search'));
433 $admin->row_input(T('Name/Email/ID'), 'userdata');
435 $admin->row_submit('', ':save:', '');
443 /*=====================================================================*\
444 || ###################################################################
447 || ###################################################################
448 \*=====================================================================*/