]> src.bluestatic.org Git - bugdar.git/blob - admin/user.php
r1522: Adding a PHP4 constructor to the Authentication class
[bugdar.git] / admin / user.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar [#]version[#]
5 || # Copyright ©2002-[#]year[#] Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 require_once('./global.php');
23 require_once('./includes/api_user.php');
24 require_once('./includes/class_sort.php');
25
26 require_once('./includes/class_api_error.php');
27 APIError(array(new API_Error_Handler($admin), 'admin_error'));
28
29 NavLinks::usersPages();
30 $navigator->set_focus('tab', 'users', null);
31
32 if (!can_perform('canadminusers'))
33 {
34 admin_login();
35 }
36
37 // ###################################################################
38 /**
39 * Generate an inline checkbox
40 *
41 * @access public
42 *
43 * @param string Name
44 * @param bool Checked?
45 *
46 * @return string HTML checkbxo
47 */
48 function draw_checkbox($name, $checked)
49 {
50 return "<input type=\"checkbox\" class=\"button\" name=\"{$name}\" value=\"1\"" . ($checked == true ? ' checked="checked"' : '') . " />";
51 }
52
53 // ###################################################################
54
55 if (empty($_REQUEST['do']))
56 {
57 $_REQUEST['do'] = 'modify';
58 }
59
60 // ###################################################################
61
62 if ($_REQUEST['do'] == 'kill')
63 {
64 $user = new UserAPI($bugsys);
65 $user->set('userid', $bugsys->in['userid']);
66 $user->set_condition();
67 $user->delete();
68
69 $admin->redirect('user.php');
70 }
71
72 // ###################################################################
73
74 if ($_REQUEST['do'] == 'delete')
75 {
76 $admin->page_confirm(_('Are you sure you want to delete this user?'), 'user.php', 'kill', array('userid' => $bugsys->input_clean('userid', TYPE_UINT)));
77 }
78
79 // ###################################################################
80
81 if ($_POST['do'] == 'insert')
82 {
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']);
97 $user->insert();
98
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);
101
102 $bugsys->input_clean('emailopts', TYPE_INT);
103 if (is_array($bugsys->in['emailopts']))
104 {
105 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
106 {
107 $bitmask = 0;
108 foreach ($bitarr AS $option => $yes)
109 {
110 $bitmask += $option * $yes;
111 }
112 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->insertid . ", $relation, $bitmask)");
113 }
114 }
115
116 $admin->redirect('user.php?do=edit&userid=' . $user->insertid);
117 }
118
119 // ###################################################################
120
121 if ($_POST['do'] == 'update')
122 {
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']);
139 $user->update();
140
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']))
144 {
145 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
146 {
147 $bitmask = 0;
148 foreach ($bitarr AS $option => $yes)
149 {
150 $bitmask += $option * $yes;
151 }
152 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->values['userid'] . ", $relation, $bitmask)");
153 }
154 }
155
156 $admin->redirect('user.php?do=edit&userid=' . $user->objdata['userid']);
157 }
158
159 // ###################################################################
160
161 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
162 {
163 $add = ($_REQUEST['do'] == 'add');
164 $edit = (!$add);
165
166 if ($edit)
167 {
168 NavLinks::usersEdit($bugsys->in['userid']);
169 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
170
171 $user = new UserAPI($bugsys);
172 $user->set('userid', $bugsys->in['userid']);
173 $user->set_condition();
174 $user->fetch();
175 }
176 else
177 {
178 NavLinks::usersAdd();
179 $navigator->set_focus('link', 'users-add', 'users');
180 }
181
182 $admin->page_start(($add ? _('Add User') : _('Edit User')));
183
184 $admin->form_start('user.php', ($add ? 'insert' : 'update'));
185
186 if ($edit)
187 {
188 $admin->form_hidden_field('userid', $user->objdata['userid']);
189 }
190
191 $admin->table_start();
192
193 $admin->table_head(($add ? _('Add User') : sprintf(_('Edit User (userid: %1$s)'), $user->objdata['userid'])));
194
195 $admin->row_input(_('Display Name'), 'displayname', $user->objdata['displayname']);
196 $admin->row_input(_('Email'), 'email', $user->objdata['email']);
197 $admin->row_input(($add ? _('Password') : _('Password (Leave blank for no change)')), 'password');
198
199 foreach ($bugsys->datastore['usergroup'] AS $group)
200 {
201 $admin->list_item($group['title'], $group['usergroupid'], ($user->objdata['usergroupid'] == $group['usergroupid']));
202 }
203 $admin->row_list(_('Primary Usergroup'), 'usergroupid');
204
205 $ids = explode(',', $user->objdata['groupids']);
206 foreach ($bugsys->datastore['usergroup'] AS $id => $group)
207 {
208 if ($id == $user->objdata['usergroupid'])
209 {
210 continue;
211 }
212 $admin->list_item($group['title'], $group['usergroupid'], in_array($id, $ids));
213 }
214 $admin->row_checkbox(_('Secondary Usergroups'), 'groupids');
215
216 $admin->row_yesno(_('Show Email Publicly'), 'showemail', $user->objdata['showemail']);
217 $admin->row_yesno(_('Show Status Colors on Bug Listings'), 'showcolors', $user->objdata['showcolors']);
218
219 foreach ($bugsys->datastore['language'] AS $language)
220 {
221 $admin->list_item($language['title'], $language['languageid'], ($user->objdata['languageid'] == $language['languageid']));
222 }
223 $admin->row_list(_('Language'), 'languageid');
224
225 foreach ($datef->fetch_timezone_list() AS $value => $string)
226 {
227 $admin->list_item($string, $value, ($user->objdata['timezone'] == $value));
228 }
229 $admin->row_list(_('Timezone'), 'timezone');
230
231 $admin->row_yesno(_('Observe Daylight Savings Time (DST)'), 'usedst', $user->objdata['usedst']);
232 $admin->row_text(_('Hidden Statuses on Bug Listing'), construct_option_select('hidestatuses', $bugsys->datastore['status'], $user->objdata['hidestatuses'], 'statusid', 'status', 0, true));
233 $admin->row_text(_('Default Sort Order Column'), construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $user->objdata['defaultsortkey']));
234 $admin->row_text(_('Default Sort Order Direction'), construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $user->objdata['defaultsortas']));
235
236 $admin->table_end();
237
238 // -------------------------------------------------------------------
239 $admin->table_start(false);
240 $admin->table_head(_('Email Options'), 6);
241
242 if ($user->objdata['userid'])
243 {
244 $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->objdata['userid']);
245 while ($opt = $db->fetch_array($options))
246 {
247 foreach ($bugsys->emailoptions['notifications'] AS $name => $notif)
248 {
249 foreach ($bugsys->emailoptions['relations'] AS $name => $relation)
250 {
251 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
252 {
253 $checked["$relation"]["$notif"] = HTML_CHECKED;
254 }
255 }
256 }
257 }
258 }
259
260 $admin->table_column_head(array('', _('Reporter'), _('Assignee'), _('Favorite'), _('Voter'), _('Commenter')));
261
262 // -------------------------------------------------------------------
263
264 $admin->row_text(_('New bug is added'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][2048]', $checked[0][2048]) . '</div>', 'top', 6);
265
266 $admin->row_text(_('I am made the assignee'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][32]', $checked[0][32]) . '</div>', 'top', 6);
267
268 $admin->row_multi_item(array(
269 _('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',
275 ));
276
277 $admin->row_multi_item(array(
278 _("'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',
284 ));
285
286 $admin->row_multi_item(array(
287 _('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',
293 ));
294
295 $admin->row_multi_item(array(
296 _('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',
302 ));
303
304 $admin->row_multi_item(array(
305 _('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',
311 ));
312
313 // -------------------------------------------------------------------
314 $admin->row_submit(null, ':save:', ':reset:', 6);
315
316 $admin->table_end();
317 $admin->form_end();
318
319 $admin->page_end();
320 }
321
322 // ###################################################################
323
324 if ($_REQUEST['do'] == 'search')
325 {
326 $fail = false;
327
328 NavLinks::usersAdd();
329 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
330
331 if (is_numeric($bugsys->in['userdata']))
332 {
333 $bugsys->input_clean('userdata', TYPE_UINT);
334 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $bugsys->in['userdata']))
335 {
336 header('Location: user.php?do=edit&userid=' . $bugsys->in['userdata']);
337 }
338 else
339 {
340 $fail = true;
341 }
342 }
343 else
344 {
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') . "%'");
347
348 if ($db->num_rows($results) < 1)
349 {
350 $fail = true;
351 }
352 else
353 {
354 $admin->page_start(_('Search Results'));
355
356 $admin->table_start();
357 $admin->table_head(_('Search Results'), 4);
358 $admin->table_column_head(array(_('Display Name'), _('Email'), _('User ID'), _('Actions')));
359
360 while ($row = $db->fetch_array($results))
361 {
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&amp;userid=' . $row['userid'] . '">[' . _('Edit') . ']</a>' => 'c'
367 ));
368 }
369
370 $admin->table_end();
371
372 $admin->page_end();
373 }
374 }
375
376 if ($fail)
377 {
378 $admin->error(_('Sorry, we could not find any users that matched your criteria.'));
379 }
380 }
381
382 // ###################################################################
383
384 if ($_REQUEST['do'] == 'showall')
385 {
386 NavLinks::usersAdd();
387 $navigator->set_focus('link', 'users-showall', 'users');
388
389 LoadPaginationFramework();
390 $pagination->setBitProcessor('AdminPageNavigatorBitCallback');
391 $pagination->setNavigatorProcessor('AdminPageNavigatorCallback');
392
393 $admin->page_start(_('Show All Users'));
394 $admin->table_start();
395 $admin->table_head(_('Show All Users'), 4);
396 $admin->table_column_head(array(_('Display Name'), _('Email'), _('User ID'), _('Actions')));
397
398 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user");
399 $pagination->setTotal($count['count']);
400 $pagination->splitPages();
401
402 $users = $db->query("SELECT * FROM " . TABLE_PREFIX . "user ORDER BY userid ASC LIMIT " . $pagination->fetchLimit($pagination->getPage() - 1) . ", " . $pagination->getPerPage());
403 while ($user = $db->fetch_array($users))
404 {
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&amp;userid=' . $user['userid'] . '">[' . _('Edit') . ']</a>' => 'c'
410 ));
411 }
412
413 $admin->table_end();
414
415 $admin->page_code($pagination->constructPageNav('user.php?do=showall'));
416
417 $admin->page_end();
418 }
419
420 // ###################################################################
421
422 if ($_REQUEST['do'] == 'modify')
423 {
424 NavLinks::usersAdd();
425 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
426
427 $admin->page_start(_('User Search'));
428
429 $admin->form_start('user.php', 'search');
430 $admin->table_start(true, '45%');
431
432 $admin->table_head(_('User Search'));
433 $admin->row_input(_('Name/Email/ID'), 'userdata');
434
435 $admin->row_submit('', ':save:', '');
436
437 $admin->table_end();
438 $admin->form_end();
439
440 $admin->page_end();
441 }
442
443 /*=====================================================================*\
444 || ###################################################################
445 || # $HeadURL$
446 || # $Id$
447 || ###################################################################
448 \*=====================================================================*/
449 ?>