r665: Renaming product from "BugStrike" to "Bugdar"
[bugdar.git] / admin / user.php
1 <?php
2 /*=====================================================================*\
3 || ################################################################### ||
4 || # Bugdar [#]version[#]
5 || # --------------------------------------------------------------- # ||
6 || # Copyright ©2002-[#]year[#] by Iris Studios, Inc. All Rights Reserved. # ||
7 || # This file may not be reproduced in any way without permission. # ||
8 || # --------------------------------------------------------------- # ||
9 || # User License Agreement at http://www.iris-studios.com/license/ # ||
10 || ################################################################### ||
11 \*=====================================================================*/
12
13 require_once('./global.php');
14
15 if (!can_perform('canadminusers'))
16 {
17 admin_login();
18 }
19
20 // ###################################################################
21
22 if (empty($_REQUEST['do']))
23 {
24 $_REQUEST['do'] = 'modify';
25 }
26
27 // ###################################################################
28
29 if ($_REQUEST['do'] == 'kill')
30 {
31 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
32 if (!$user)
33 {
34 $admin->error($lang->getlex('error_invalid_id'));
35 }
36
37 if ($user['userid'] == $bugsys->userinfo['userid'])
38 {
39 $admin->error($lang->string('You cannot delete your own account!'));
40 }
41
42 if ($user['usergroupid'] == 6)
43 {
44 $count = $db->query_first("SELECT COUNT(*) AS count FROM " . TABLE_PREFIX . "user WHERE usergroupid = 6 AND userid <> $user[userid]");
45 if ($count['count'] < 1)
46 {
47 $admin->error($lang->string('At least one other administrator needs to be present before you can delete this user'));
48 }
49 }
50
51 $db->query("DELETE FROM user WHERE userid = $user[userid]");
52 $db->query("DELETE FROM favourite WHERE userid = $user[userid]");
53 $db->query("DELETE FROM useractivation WHERE userid = $user[userid]");
54
55 $admin->redirect('user.php');
56 }
57
58 // ###################################################################
59
60 if ($_REQUEST['do'] == 'delete')
61 {
62 $admin->page_confirm($lang->string('Are you sure you want to delete this user?'), 'user.php?do=kill&amp;userid=' . intval($bugsys->in['userid']));
63 }
64
65 // ###################################################################
66
67 if ($_POST['do'] == 'insert')
68 {
69 $salt = $funct->rand(15);
70
71 $db->query("
72 INSERT INTO " . TABLE_PREFIX . "user
73 (email, displayname, password, salt, authkey, showemail, showcolours, languageid, usergroupid, timezone)
74 VALUES
75 ('" . $bugsys->in['email'] . "',
76 '" . $bugsys->in['displayname'] . "',
77 '" . md5(md5($bugsys->in['password']) . md5($salt)) . "',
78 '$salt',
79 '" . $funct->rand() . "',
80 " . intval($bugsys->in['showemail']) . ",
81 " . intval($bugsys->in['showcolours']) . ",
82 " . intval($bugsys->in['languageid']) . ",
83 " . intval($bugsys->in['usergroupid']) . ",
84 " . intval($bugsys->in['timezone']) . "
85 )"
86 );
87
88 $admin->redirect('user.php?do=edit&userid=' . $db->insert_id());
89 }
90
91 // ###################################################################
92
93 if ($_POST['do'] == 'update')
94 {
95 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
96 if (!$user)
97 {
98 $admin->error($lang->getlex('error_invalid_id'));
99 }
100
101 $db->query("
102 UPDATE " . TABLE_PREFIX . "user
103 SET displayname = '" . $bugsys->in['displayname'] . "',
104 email = '" . $bugsys->in['email'] . "',
105 showcolours = " . intval($bugsys->in['showcolours']) . ",
106 usergroupid = " . intval($bugsys->in['usergroupid']) . ",
107 languageid = " . intval($bugsys->in['languageid']) . ",
108 timezone = " . intval($bugsys->in['timezone']) . ($bugsys->in['password'] ? ",
109 password = '" . md5(md5($bugsys->in['password']) . md5($user['salt'])) . "'" : '') . "
110 WHERE userid = $user[userid]"
111 );
112
113 $admin->redirect('user.php?do=edit&userid=' . $user['userid']);
114 }
115
116 // ###################################################################
117
118 if ($_REQUEST['do'] == 'edit' OR $_REQUEST['do'] == 'add')
119 {
120 $add = ($_REQUEST['do'] == 'add');
121 $edit = (!$add);
122
123 if ($edit)
124 {
125 $user = $db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userid']));
126 if (!$user)
127 {
128 $admin->error($lang->getlex('error_invalid_id'));
129 }
130 }
131
132 $admin->page_start(($add ? $lang->string('Add User') : $lang->string('Edit User')), 2, 'user_manage');
133
134 $admin->form_start('user.php', ($add ? 'insert' : 'update'));
135
136 if ($edit)
137 {
138 $admin->form_hidden_field('userid', $user['userid']);
139 }
140
141 $admin->table_start();
142
143 $admin->table_head(($add ? $lang->string('Add User') : sprintf($lang->string('Edit User (userid: %1$s)'), $user['userid'])));
144
145 $admin->row_input($lang->string('Display Name'), 'displayname', $user['displayname']);
146 $admin->row_input($lang->string('Email'), 'email', $user['email']);
147 $admin->row_input(($add ? $lang->string('Password') : $lang->string('Password (Leave blank for no change)')), 'password');
148
149 foreach ($bugsys->datastore['usergroup'] AS $group)
150 {
151 $admin->list_item($group['title'], $group['usergroupid'], ($user['usergroupid'] == $group['usergroupid']));
152 }
153 $admin->row_list($lang->string('Usergroup'), 'usergroupid');
154
155 $admin->row_yesno($lang->string('Show Email Publicly'), 'showemail', $user['showemail']);
156 $admin->row_yesno($lang->string('Show Status Colours on Bug Listings'), 'showcolours', $user['showcolours']);
157
158 foreach ($bugsys->datastore['language'] AS $language)
159 {
160 $admin->list_item($language['title'], $language['languageid'], ($user['languageid'] == $language['languageid']));
161 }
162 $admin->row_list($lang->string('Language'), 'languageid');
163
164 foreach ($datef->fetch_timezone_list() AS $value => $string)
165 {
166 $admin->list_item($string, $value, ($user['timezone'] == $value));
167 }
168 $admin->row_list($lang->string('Timezone'), 'timezone');
169
170 $admin->row_submit(($edit ? '<a href="user.php?do=delete&amp;userid=' . $user['userid'] . '">[' . $lang->string('Delete') . ']</a>' : ''), ':save:', ':reset:', 4);
171
172 $admin->table_end();
173 $admin->form_end();
174
175 $admin->page_end();
176 }
177
178 // ###################################################################
179
180 if ($_REQUEST['do'] == 'search')
181 {
182 $fail = false;
183
184 if (is_numeric($bugsys->in['userdata']))
185 {
186 if ($db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE userid = " . intval($bugsys->in['userdata'])))
187 {
188 header('Location: user.php?do=edit&userid=' . intval($bugsys->in['userdata']));
189 }
190 else
191 {
192 $fail = true;
193 }
194 }
195 else
196 {
197 $bugsys->in['userdata'] = str_replace('%', '\%', $bugsys->in['userdata']);
198 $results = $db->query("SELECT * FROM " . TABLE_PREFIX . "user WHERE email LIKE '%" . $bugsys->in['userdata'] . "%' OR displayname LIKE '%" . $bugsys->in['userdata'] . "%'");
199
200 if ($db->num_rows($results) < 1)
201 {
202 $fail = true;
203 }
204 else
205 {
206 $admin->page_start($lang->string('Search Results'));
207
208 $admin->table_start();
209 $admin->table_head($lang->string('Search Results'), 4);
210 $admin->table_column_head(array($lang->string('Display Name'), $lang->string('Email'), $lang->string('User ID'), $lang->string('Actions')));
211
212 while ($row = $db->fetch_array($results))
213 {
214 $admin->row_multi_item(array(
215 $row['displayname'] => 'l',
216 $row['email'] => 'c',
217 $row['userid'] => 'c',
218 '<a href="user.php?do=edit&amp;userid=' . $row['userid'] . '">[' . $lang->string('Edit') . ']</a>' => 'c'
219 ));
220 }
221
222 $admin->table_end();
223
224 $admin->page_end();
225 }
226 }
227
228 if ($fail)
229 {
230 $admin->error($lang->string('Sorry, we could not find any users that matched your criteria.'));
231 }
232 }
233
234 // ###################################################################
235
236 if ($_REQUEST['do'] == 'modify')
237 {
238 $admin->page_start($lang->string('User Search'));
239
240 $admin->form_start('user.php', 'search');
241 $admin->table_start(true, '45%');
242
243 $admin->table_head($lang->string('User Search'), 2, 'user_manage');
244 $admin->row_input($lang->string('Name/Email/ID'), 'userdata');
245
246 $admin->row_submit('', ':save:', '');
247
248 $admin->table_end();
249 $admin->form_end();
250
251 $admin->page_end();
252 }
253
254 /*=====================================================================*\
255 || ###################################################################
256 || # $HeadURL$
257 || # $Id$
258 || ###################################################################
259 \*=====================================================================*/
260 ?>