Show votes on showreport.php
[bugdar.git] / userctrl.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 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 2 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 $fetchtemplates = array(
23 'userctrl',
24 'userctrl_column',
25 'userctrl_search'
26 );
27
28 define('SVN', '$Id$');
29
30 $focus['user'] = 'focus';
31
32 require_once('./global.php');
33 require_once('./includes/class_api_error.php');
34 require_once('./includes/api_user.php');
35
36 if (!bugdar::$userinfo['userid'])
37 {
38 $message->errorPermission();
39 }
40
41 $userapi = new UserAPI($bugsys);
42 $userapi->set('userid', bugdar::$userinfo['userid']);
43 $userapi->setCondition();
44
45 $userinfo = bugdar::$userinfo;
46
47 // ###################################################################
48
49 if (empty($_REQUEST['do']))
50 {
51 $_REQUEST['do'] = 'modify';
52 }
53
54 // ###################################################################
55
56 if ($_POST['do'] == 'killsearch')
57 {
58 $search = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $input->inputClean('searchid', TYPE_UINT) . " AND userid = " . bugdar::$userinfo['userid']);
59 if (!$search)
60 {
61 $message->errorPermission();
62 }
63
64 $db->query("DELETE FROM " . TABLE_PREFIX . "search WHERE searchid = " . $input->in['searchid']);
65
66 $message->redirect(T('This saved search has been removed from your list.'), 'userctrl.php');
67 }
68
69 // ###################################################################
70
71 if ($_REQUEST['do'] == 'deletesearch')
72 {
73 $search = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX . "search WHERE searchid = " . $input->inputClean('searchid', TYPE_UINT) . " AND userid = " . bugdar::$userinfo['userid']);
74 if (!$search)
75 {
76 $message->errorPermission();
77 }
78
79 $message->confirm(T('Are you sure you want to delete this saved search?'), 'userctrl.php', 'killsearch', T('Delete'), T('Cancel'), array('searchid' => $input->in['searchid']));
80 }
81
82 // ###################################################################
83
84 if ($_POST['do'] == 'update')
85 {
86 // -------------------------------------------------------------------
87 // authentication
88 if (!empty($input->in['password_change']) OR !empty($input->in['email_change']))
89 {
90 if (empty($input->in['validate']))
91 {
92 $message->addError(T('You need to enter your current password to change your email or password'));
93 }
94 else
95 {
96 if (md5(md5($input->in['validate']) . md5(bugdar::$userinfo['salt'])) != bugdar::$userinfo['password'])
97 {
98 $message->addError(T('Your authentication password does not match the one in our records'));
99 }
100 }
101 }
102
103 // -------------------------------------------------------------------
104 // email validation
105 if (!empty($input->in['email_change']))
106 {
107 if (!empty($input->in['email_change']) AND empty($input->in['email_confirm']))
108 {
109 $message->addError(T('You need to enter both the email and confirm email fields to change your address'));
110 }
111
112 if ($input->in['email_change'] != $input->in['email_confirm'])
113 {
114 $message->addError(T('Your email and confirm email addresses do not match'));
115 }
116
117 $userapi->set('email', $input->in['email_change']);
118 }
119
120 // -------------------------------------------------------------------
121 // password validation
122 if (!empty($input->in['password_change']))
123 {
124 if (!empty($input->in['password_change']) AND empty($input->in['password_confirm']))
125 {
126 $message->addError(T('You need to enter both the password and confirm password fields to change your password'));
127 }
128 else
129 {
130 if ($input->in['password_change'] != $input->in['password_confirm'])
131 {
132 $message->addError(T('Your password and confirm password do not match'));
133 }
134 }
135
136 $userapi->set('password', $input->in['password_change']);
137 }
138
139 $userapi->set('displayname', $input->in['displayname']);
140 $userapi->set('showemail', $input->in['showemail']);
141 $userapi->set('showcolors', $input->in['showcolors']);
142 $userapi->set('languageid', $input->in['languageid']);
143 $userapi->set('timezone', $input->in['timezone']);
144 $userapi->set('usedst', $input->in['usedst']);
145 $userapi->set('hidestatuses', $input->in['hidestatuses']);
146 $userapi->set('defaultsortkey', $input->in['defaultsortkey']);
147 $userapi->set('defaultsortas', $input->in['defaultsortas']);
148 $userapi->set('columnoptions', $input->inputClean('columnoptions', TYPE_UINT));
149
150 // -------------------------------------------------------------------
151 // copy fields
152 $userinfo['displayname'] = $input->in['displayname'];
153 $userinfo['showemail'] = $input->in['showemail'];
154 $userinfo['showcolors'] = $input->in['showcolors'];
155 $userinfo['languageid'] = $input->in['languageid'];
156 $userinfo['timezone'] = $input->in['timezone'];
157 $userinfo['usedst'] = $input->in['usedst'];
158 $userinfo['hidestatuses'] = $input->in['hidestatuses'];
159 $userinfo['defaultsorkey'] = $input->in['defaultsorkey'];
160 $userinfo['defaultsortas'] = $input->in['defaultsortas'];
161 $userinfo['columnoptions'] = $input->in['columnoptions'];
162
163 $email = $input->in['email_change'];
164 $email_confirm = $input->in['email_confirm'];
165
166 // -------------------------------------------------------------------
167 // error handling
168 if ($message->hasErrors())
169 {
170 $show['errors'] = true;
171 $_REQUEST['do'] = 'modify';
172 }
173 else
174 {
175 $userapi->update();
176
177 $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . bugdar::$userinfo['userid']);
178 $input->inputClean('emailopts', TYPE_INT);
179 if (is_array($input->in['emailopts']))
180 {
181 foreach ($input->in['emailopts'] AS $relation => $bitarr)
182 {
183 $bitmask = 0;
184 if (is_array($bitarr))
185 {
186 foreach ($bitarr AS $option => $yes)
187 {
188 $bitmask += $option * $yes;
189 }
190 }
191 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . bugdar::$userinfo['userid'] . ", $relation, $bitmask)");
192 }
193 }
194
195 $message->redirect(T('The changes to your account have been made.'), 'userctrl.php');
196 }
197 }
198
199 // ###################################################################
200
201 if ($_REQUEST['do'] == 'modify')
202 {
203 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
204
205 $hidestatuses = construct_datastore_select('status', 'status', 'statusid', (!is_array($userinfo['hidestatuses']) ? explode(',', $userinfo['hidestatuses']) : $userinfo['hidestatuses']), 0);
206 $hidestatusesnum = (sizeof(bugdar::$datastore['status']) < 8 ? sizeof(bugdar::$datastore['status']) + 1 : 8);
207
208 $defaultsortkey = construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $userinfo['defaultsortkey']);
209 $defaultsortas = construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $userinfo['defaultsortas']);
210
211 foreach ($datef->fetch_timezone_list() as $value => $label)
212 {
213 $tpl = new BSTemplate('selectoption');
214 $tpl->vars = array(
215 'value' => $value,
216 'label' => $label,
217 'selected' => ($value == $userinfo['timezone'])
218 );
219 $tzselect .= $tpl->evaluate()->getTemplate();
220 }
221
222 $checked = array();
223 if (!is_array($input->in['emailopts']))
224 {
225 $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . bugdar::$userinfo['userid']);
226 foreach ($options as $opt)
227 {
228 foreach ($bugsys->emailoptions['notifications'] AS $name => $notif)
229 {
230 foreach ($bugsys->emailoptions['relations'] AS $name => $relation)
231 {
232 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
233 {
234 $checked["$relation"]["$notif"] = HTML_CHECKED;
235 }
236 }
237 }
238 }
239 }
240 else
241 {
242 $checked = $input->in['emailopts'];
243 foreach ($checked AS $key1 => $value1)
244 {
245 foreach ($value1 AS $key2 => $value2)
246 {
247 if ($value2)
248 {
249 $checked["$key1"]["$key2"] = HTML_CHECKED;
250 }
251 }
252 }
253 }
254
255 $columns = array();
256 $columnOptions = '';
257 require_once('./includes/class_sort.php');
258 if (!is_array($input->in['columnoptions']))
259 {
260 foreach (ListSorter::fetch_by_text(false) AS $column => $name)
261 {
262 if (is_array(bugdar::$userinfo['columnoptions']))
263 {
264 $columns["$column"] = bugdar::$userinfo['columnoptions']["$column"];
265 }
266 else
267 {
268 $columns["$column"] = bugdar::$options['columnoptions']["$column"];
269 }
270 $tpl = new BSTemplate('userctrl_column');
271 $tpl->vars = array(
272 'columns' => $columns,
273 'column' => $column,
274 'name' => $name
275 );
276 $columnOptions .= $tpl->evaluate()->getTemplate();
277 }
278 }
279 else
280 {
281 $columns = $input->in['columnoptions'];
282 foreach (ListSorter::fetch_by_text(false) as $column => $name)
283 {
284 $tpl = new BSTemplate('userctrl_column');
285 $tpl->vars = array(
286 'columns' => $columns,
287 'column' => $column,
288 'name' => $name
289 );
290 $columnOptions .= $tpl->evaluate()->getTemplate();
291 }
292 }
293
294 // searches
295 $searches = '';
296 $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX . "search WHERE name IS NOT NULL AND userid = " . bugdar::$userinfo['userid']);
297 foreach ($searchesFetch as $search)
298 {
299 $tpl = new BSTemplate('userctrl_search');
300 $tpl->vars = array('search' => $search);
301 $searches .= $tpl->evaluate()->getTemplate();
302 }
303
304 $tpl = new BSTemplate('userctrl');
305 $tpl->vars = array(
306 'checked' => $checked,
307 'userinfo' => $userinfo,
308 'searches' => $searches,
309 'defaultsortkey' => $defaultsortkey,
310 'hidestatusesnum' => $hidestatusesnum,
311 'hidestatuses' => $hidestatuses,
312 'defaultsortas' => $defaultsortas,
313 'columnOptions' => $columnOptions,
314 'langselect' => $langselect,
315 'tzselect' => $tzselect
316 );
317 $tpl->evaluate()->flush();
318 }
319
320 /*=====================================================================*\
321 || ###################################################################
322 || # $HeadURL$
323 || # $Id$
324 || ###################################################################
325 \*=====================================================================*/
326 ?>