r1338: Incomplete JavaScript implementation of column ordering options
[bugdar.git] / userctrl.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 $fetchtemplates = array(
23 'userctrl',
24 'userctrl_column'
25 );
26
27 define('SVN', '$Id$');
28
29 $focus['user'] = 'focus';
30
31 require_once('./global.php');
32 require_once('./includes/class_api_error.php');
33 require_once('./includes/api_user.php');
34
35 APIError(array(new API_Error_Handler($message), 'user_cumulative'));
36
37 if (!$bugsys->userinfo['userid'])
38 {
39 $message->error_permission();
40 }
41
42 $userapi = new UserAPI($bugsys);
43 $userapi->set('userid', $bugsys->userinfo['userid']);
44 $userapi->set_condition();
45
46 $userinfo = $bugsys->userinfo;
47
48 // ###################################################################
49
50 if (empty($_REQUEST['do']))
51 {
52 $_REQUEST['do'] = 'modify';
53 }
54
55 // ###################################################################
56
57 if ($_POST['do'] == 'update')
58 {
59 // -------------------------------------------------------------------
60 // authentication
61 if (!empty($bugsys->in['password_change']) OR !empty($bugsys->in['email_change']))
62 {
63 if (empty($bugsys->in['validate']))
64 {
65 $message->add_error(_('You need to enter your current password to change your email or password'));
66 }
67 else
68 {
69 if (md5(md5($bugsys->in['validate']) . md5($bugsys->userinfo['salt'])) != $bugsys->userinfo['password'])
70 {
71 $message->add_error(_('Your authentication password does not match the one in our records'));
72 }
73 }
74 }
75
76 // -------------------------------------------------------------------
77 // email validation
78 if (!empty($bugsys->in['email_change']))
79 {
80 if (!empty($bugsys->in['email_change']) AND empty($bugsys->in['email_confirm']))
81 {
82 $message->add_error(_('You need to enter both the email and confirm email fields to change your address'));
83 }
84
85 if ($bugsys->in['email_change'] != $bugsys->in['email_confirm'])
86 {
87 $message->add_error(_('Your email and confirm email addresses do not match'));
88 }
89
90 $userapi->set('email', $bugsys->in['email_change']);
91 }
92
93 // -------------------------------------------------------------------
94 // password validation
95 if (!empty($bugsys->in['password_change']))
96 {
97 if (!empty($bugsys->in['password_change']) AND empty($bugsys->in['password_confirm']))
98 {
99 $message->add_error(_('You need to enter both the password and confirm password fields to change your password'));
100 }
101 else
102 {
103 if ($bugsys->in['password_change'] != $bugsys->in['password_confirm'])
104 {
105 $message->add_error(_('Your password and confirm password do not match'));
106 }
107 }
108
109 $userapi->set('password', $bugsys->in['password_change']);
110 }
111
112 $userapi->set('displayname', $bugsys->in['displayname']);
113 $userapi->set('showemail', $bugsys->in['showemail']);
114 $userapi->set('showcolors', $bugsys->in['showcolors']);
115 $userapi->set('languageid', $bugsys->in['languageid']);
116 $userapi->set('timezone', $bugsys->in['timezone']);
117 $userapi->set('usedst', $bugsys->in['usedst']);
118 $userapi->set('hidestatuses', $bugsys->in['hidestatuses']);
119 $userapi->set('defaultsortkey', $bugsys->in['defaultsortkey']);
120 $userapi->set('defaultsortas', $bugsys->in['defaultsortas']);
121
122 // -------------------------------------------------------------------
123 // copy fields
124 $userinfo['displayname'] = $bugsys->in['displayname'];
125 $userinfo['showemail'] = $bugsys->in['showemail'];
126 $userinfo['showcolors'] = $bugsys->in['showcolors'];
127 $userinfo['languageid'] = $bugsys->in['languageid'];
128 $userinfo['timezone'] = $bugsys->in['timezone'];
129 $userinfo['usedst'] = $bugsys->in['usedst'];
130 $userinfo['hidestatuses'] = $bugsys->in['hidestatuses'];
131 $userinfo['defaultsorkey'] = $bugsys->in['defaultsorkey'];
132 $userinfo['defaultsortas'] = $bugsys->in['defaultsortas'];
133
134 $email = $bugsys->in['email_change'];
135 $email_confirm = $bugsys->in['email_confirm'];
136
137 // -------------------------------------------------------------------
138 // error handling
139 if ($message->items)
140 {
141 $message->error_list_process();
142
143 $show['errors'] = true;
144 $_REQUEST['do'] = 'modify';
145 }
146 else
147 {
148 $userapi->update();
149
150 if (can_perform('canbeassignedto'))
151 {
152 require_once('./includes/functions_datastore.php');
153 build_assignedto();
154 }
155
156 $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $bugsys->userinfo['userid']);
157 $bugsys->input_clean('emailopts', TYPE_INT);
158 if (is_array($bugsys->in['emailopts']))
159 {
160 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
161 {
162 $bitmask = 0;
163 if (is_array($bitarr))
164 {
165 foreach ($bitarr AS $option => $yes)
166 {
167 $bitmask += $option * $yes;
168 }
169 }
170 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $bugsys->userinfo['userid'] . ", $relation, $bitmask)");
171 }
172 }
173
174 $message->redirect(_('The changes to your account have been made.'), 'userctrl.php');
175 }
176 }
177
178 // ###################################################################
179
180 if ($_REQUEST['do'] == 'modify')
181 {
182 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
183
184 $hidestatuses = construct_datastore_select('status', 'status', 'statusid', (!is_array($userinfo['hidestatuses']) ? explode(',', $userinfo['hidestatuses']) : $userinfo['hidestatuses']), 0);
185 $hidestatusesnum = (sizeof($bugsys->datastore['status']) < 8 ? sizeof($bugsys->datastore['status']) + 1 : 8);
186
187 $defaultsortkey = construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $userinfo['defaultsortkey']);
188 $defaultsortas = construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $userinfo['defaultsortas']);
189
190 foreach ($datef->fetch_timezone_list() AS $value => $label)
191 {
192 $selected = ($value == $userinfo['timezone']);
193 eval('$tzselect .= "' . $template->fetch('selectoption') . '";');
194 }
195
196 $checked = array();
197 if (!is_array($bugsys->in['emailopts']))
198 {
199 $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $bugsys->userinfo['userid']);
200 while ($opt = $db->fetch_array($options))
201 {
202 foreach ($bugsys->emailoptions['notifications'] AS $name => $notif)
203 {
204 foreach ($bugsys->emailoptions['relations'] AS $name => $relation)
205 {
206 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
207 {
208 $checked["$relation"]["$notif"] = HTML_CHECKED;
209 }
210 }
211 }
212 }
213 }
214 else
215 {
216 $checked = $bugsys->in['emailopts'];
217 foreach ($checked AS $key1 => $value1)
218 {
219 foreach ($value1 AS $key2 => $value2)
220 {
221 if ($value2)
222 {
223 $checked["$key1"]["$key2"] = HTML_CHECKED;
224 }
225 }
226 }
227 }
228
229 $position = 0;
230 $columns = '{ ';
231 $array = ((is_array($bugsys->userinfo['columnoptions']) AND sizeof($bugsys->userinfo['columnoptions']) == sizeof($bugsys->columns)) ? $bugsys->userinfo['columnoptions'] : $bugsys->columns);
232 foreach ($array AS $column => $mask)
233 {
234 $columnName = $bugsys->columnNames["$column"];
235 eval('$columnOptions .= "' . $template->fetch('userctrl_column') . '";');
236 $columns = '';
237 $position++;
238 }
239
240 $columns = array();
241 if (!is_array($bugsys->in['columns']))
242 {
243 $columns = '{"' . implode('": "', $bugsys->userinfo['columnoptions']) . '"}';
244 }
245
246 eval('$template->flush("' . $template->fetch('userctrl') . '");');
247 }
248
249 /*=====================================================================*\
250 || ###################################################################
251 || # $HeadURL$
252 || # $Id$
253 || ###################################################################
254 \*=====================================================================*/
255 ?>