r1309: It'd be good if we changed the settings of the user we are editing and not...
[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('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']);
96 $user->insert();
97
98 $bugsys->input_clean('emailopts', TYPE_INT);
99 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
100 {
101 $bitmask = 0;
102 foreach ($bitarr AS $option => $yes)
103 {
104 $bitmask += $option * $yes;
105 }
106 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->insertid . ", $relation, $bitmask)");
107 }
108
109 $admin->redirect('user.php?do=edit&userid=' . $user->insertid);
110 }
111
112 // ###################################################################
113
114 if ($_POST['do'] == 'update')
115 {
116 $user = new UserAPI($bugsys);
117 $user->set('userid', $bugsys->in['userid']);
118 $user->set_condition();
119 $user->set('displayname', $bugsys->in['displayname']);
120 $user->set('email', $bugsys->in['email']);
121 $user->set('showemail', $bugsys->in['showemail']);
122 $user->set('showcolors', $bugsys->in['showcolors']);
123 $user->set('usergroupid', $bugsys->in['usergroupid']);
124 $user->set('languageid', $bugsys->in['languageid']);
125 $user->set('timezone', $bugsys->in['timezone']);
126 $user->set('usedst', $bugsys->in['usedst']);
127 $user->set('password', $bugsys->in['password']);
128 $user->set('hidestatuses', $bugsys->in['hidestatuses']);
129 $user->set('defaultsortkey', $bugsys->in['defaultsortkey']);
130 $user->set('defaultsortas', $bugsys->in['defaultsortas']);
131 $user->update();
132
133 $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->values['userid']);
134 $bugsys->input_clean('emailopts', TYPE_INT);
135 if (is_array($bugsys->in['emailopts']))
136 {
137 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
138 {
139 $bitmask = 0;
140 foreach ($bitarr AS $option => $yes)
141 {
142 $bitmask += $option * $yes;
143 }
144 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $user->values['userid'] . ", $relation, $bitmask)");
145 }
146 }
147
148 $admin->redirect('user.php?do=edit&userid=' . $user->objdata['userid']);
149 }
150
151 // ###################################################################
152
153 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
154 {
155 $add = ($_REQUEST['do'] == 'add');
156 $edit = (!$add);
157
158 if ($edit)
159 {
160 NavLinks::usersEdit($bugsys->in['userid']);
161 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
162
163 $user = new UserAPI($bugsys);
164 $user->set('userid', $bugsys->in['userid']);
165 $user->set_condition();
166 $user->fetch();
167 }
168 else
169 {
170 NavLinks::usersAdd();
171 $navigator->set_focus('link', 'users-add', 'users');
172 }
173
174 $admin->page_start(($add ? _('Add User') : _('Edit User')));
175
176 $admin->form_start('user.php', ($add ? 'insert' : 'update'));
177
178 if ($edit)
179 {
180 $admin->form_hidden_field('userid', $user->objdata['userid']);
181 }
182
183 $admin->table_start();
184
185 $admin->table_head(($add ? _('Add User') : sprintf(_('Edit User (userid: %1$s)'), $user->objdata['userid'])));
186
187 $admin->row_input(_('Display Name'), 'displayname', $user->objdata['displayname']);
188 $admin->row_input(_('Email'), 'email', $user->objdata['email']);
189 $admin->row_input(($add ? _('Password') : _('Password (Leave blank for no change)')), 'password');
190
191 foreach ($bugsys->datastore['usergroup'] AS $group)
192 {
193 $admin->list_item($group['title'], $group['usergroupid'], ($user->objdata['usergroupid'] == $group['usergroupid']));
194 }
195 $admin->row_list(_('Usergroup'), 'usergroupid');
196
197 $admin->row_yesno(_('Show Email Publicly'), 'showemail', $user->objdata['showemail']);
198 $admin->row_yesno(_('Show Status Colors on Bug Listings'), 'showcolors', $user->objdata['showcolors']);
199
200 foreach ($bugsys->datastore['language'] AS $language)
201 {
202 $admin->list_item($language['title'], $language['languageid'], ($user->objdata['languageid'] == $language['languageid']));
203 }
204 $admin->row_list(_('Language'), 'languageid');
205
206 foreach ($datef->fetch_timezone_list() AS $value => $string)
207 {
208 $admin->list_item($string, $value, ($user->objdata['timezone'] == $value));
209 }
210 $admin->row_list(_('Timezone'), 'timezone');
211
212 $admin->row_yesno(_('Observe Daylight Savings Time (DST)'), 'usedst', $user->objdata['usedst']);
213 $admin->row_text(_('Hidden Statuses on Bug Listing'), construct_option_select('hidestatuses', $bugsys->datastore['status'], $user->objdata['hidestatuses'], 'statusid', 'status', 0, true));
214 $admin->row_text(_('Default Sort Order Column'), construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $user->objdata['defaultsortkey']));
215 $admin->row_text(_('Default Sort Order Direction'), construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $user->objdata['defaultsortas']));
216
217 $admin->table_end();
218
219 // -------------------------------------------------------------------
220 $admin->table_start(false);
221 $admin->table_head(_('Email Options'), 6);
222
223 $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $user->objdata['userid']);
224 while ($opt = $db->fetch_array($options))
225 {
226 foreach ($bugsys->emailoptions['notifications'] AS $name => $notif)
227 {
228 foreach ($bugsys->emailoptions['relations'] AS $name => $relation)
229 {
230 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
231 {
232 $checked["$relation"]["$notif"] = HTML_CHECKED;
233 }
234 }
235 }
236 }
237
238 $admin->table_column_head(array('', _('Reporter'), _('Assignee'), _('Favorite'), _('Voter'), _('Commenter')));
239
240 // -------------------------------------------------------------------
241
242 $admin->row_text(_('New bug is added'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][2048]', $checked[0][2048]) . '</div>', 'top', 6);
243
244 $admin->row_text(_('I am made the assignee'), '<div style="text-align: center">' . draw_checkbox('emailopts[0][32]', $checked[0][32]) . '</div>', 'top', 6);
245
246 $admin->row_multi_item(array(
247 _('Status or resolution changes') => 'l',
248 draw_checkbox('emailopts[1][64]', $checked[1][64]) => 'c',
249 draw_checkbox('emailopts[2][64]', $checked[2][64]) => 'c',
250 draw_checkbox('emailopts[4][64]', $checked[4][64]) => 'c',
251 draw_checkbox('emailopts[8][64]', $checked[8][64]) => 'c',
252 draw_checkbox('emailopts[16][64]', $checked[16][64]) => 'c',
253 ));
254
255 $admin->row_multi_item(array(
256 _("'Duplicates' field is changed") => 'l',
257 draw_checkbox('emailopts[1][128]', $checked[1][128]) => 'c',
258 draw_checkbox('emailopts[2][128]', $checked[2][128]) => 'c',
259 draw_checkbox('emailopts[4][128]', $checked[4][128]) => 'c',
260 draw_checkbox('emailopts[8][128]', $checked[8][128]) => 'c',
261 draw_checkbox('emailopts[16][128]', $checked[16][128]) => 'c',
262 ));
263
264 $admin->row_multi_item(array(
265 _('A new comment is added') => 'l',
266 draw_checkbox('emailopts[1][256]', $checked[1][256]) => 'c',
267 draw_checkbox('emailopts[2][256]', $checked[2][256]) => 'c',
268 draw_checkbox('emailopts[4][256]', $checked[4][256]) => 'c',
269 draw_checkbox('emailopts[8][256]', $checked[8][256]) => 'c',
270 draw_checkbox('emailopts[16][256]', $checked[16][256]) => 'c',
271 ));
272
273 $admin->row_multi_item(array(
274 _('A new attachment is added') => 'l',
275 draw_checkbox('emailopts[1][512]', $checked[1][512]) => 'c',
276 draw_checkbox('emailopts[2][512]', $checked[2][512]) => 'c',
277 draw_checkbox('emailopts[4][512]', $checked[4][512]) => 'c',
278 draw_checkbox('emailopts[8][512]', $checked[8][512]) => 'c',
279 draw_checkbox('emailopts[16][512]', $checked[16][512]) => 'c',
280 ));
281
282 $admin->row_multi_item(array(
283 _('Any other field changes') => 'l',
284 draw_checkbox('emailopts[1][1024]', $checked[1][1024]) => 'c',
285 draw_checkbox('emailopts[2][1024]', $checked[2][1024]) => 'c',
286 draw_checkbox('emailopts[4][1024]', $checked[4][1024]) => 'c',
287 draw_checkbox('emailopts[8][1024]', $checked[8][1024]) => 'c',
288 draw_checkbox('emailopts[16][1024]', $checked[16][1024]) => 'c',
289 ));
290
291 // -------------------------------------------------------------------
292 $admin->row_submit(null, ':save:', ':reset:', 6);
293
294 $admin->table_end();
295 $admin->form_end();
296
297 $admin->page_end();
298 }
299
300 // ###################################################################
301
302 if ($_REQUEST['do'] == 'search')
303 {
304 $fail = false;
305
306 NavLinks::usersAdd();
307 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
308
309 if (is_numeric($bugsys->in['userdata']))
310 {
311 $bugsys->input_clean('userdata', TYPE_UINT);
312 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . $bugsys->in['userdata']))
313 {
314 header('Location: user.php?do=edit&userid=' . $bugsys->in['userdata']);
315 }
316 else
317 {
318 $fail = true;
319 }
320 }
321 else
322 {
323 $bugsys->in['userdata'] = str_replace('%', '\%', $bugsys->in['userdata']);
324 $results = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE email LIKE '%" . $bugsys->input_escape('userdata') . "%' OR displayname LIKE '%" . $bugsys->input_escape('userdata') . "%'");
325
326 if ($db->num_rows($results) < 1)
327 {
328 $fail = true;
329 }
330 else
331 {
332 $admin->page_start(_('Search Results'));
333
334 $admin->table_start();
335 $admin->table_head(_('Search Results'), 4);
336 $admin->table_column_head(array(_('Display Name'), _('Email'), _('User ID'), _('Actions')));
337
338 while ($row = $db->fetch_array($results))
339 {
340 $admin->row_multi_item(array(
341 $row['displayname'] => 'l',
342 $row['email'] => 'c',
343 $row['userid'] => 'c',
344 '<a href="user.php?do=edit&amp;userid=' . $row['userid'] . '">[' . _('Edit') . ']</a>' => 'c'
345 ));
346 }
347
348 $admin->table_end();
349
350 $admin->page_end();
351 }
352 }
353
354 if ($fail)
355 {
356 $admin->error(_('Sorry, we could not find any users that matched your criteria.'));
357 }
358 }
359
360 // ###################################################################
361
362 if ($_REQUEST['do'] == 'modify')
363 {
364 NavLinks::usersAdd();
365 $navigator->set_focus('link', 'users-pages-users', 'users-pages');
366
367 $admin->page_start(_('User Search'));
368
369 $admin->form_start('user.php', 'search');
370 $admin->table_start(true, '45%');
371
372 $admin->table_head(_('User Search'));
373 $admin->row_input(_('Name/Email/ID'), 'userdata');
374
375 $admin->row_submit('', ':save:', '');
376
377 $admin->table_end();
378 $admin->form_end();
379
380 $admin->page_end();
381 }
382
383 /*=====================================================================*\
384 || ###################################################################
385 || # $HeadURL$
386 || # $Id$
387 || ###################################################################
388 \*=====================================================================*/
389 ?>