r1339: Changing the javscript version of the column options system to use simple...
[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 $userapi->set('columnoptions', $bugsys->input_clean('columnoptions', TYPE_UINT));
122
123 // -------------------------------------------------------------------
124 // copy fields
125 $userinfo['displayname'] = $bugsys->in['displayname'];
126 $userinfo['showemail'] = $bugsys->in['showemail'];
127 $userinfo['showcolors'] = $bugsys->in['showcolors'];
128 $userinfo['languageid'] = $bugsys->in['languageid'];
129 $userinfo['timezone'] = $bugsys->in['timezone'];
130 $userinfo['usedst'] = $bugsys->in['usedst'];
131 $userinfo['hidestatuses'] = $bugsys->in['hidestatuses'];
132 $userinfo['defaultsorkey'] = $bugsys->in['defaultsorkey'];
133 $userinfo['defaultsortas'] = $bugsys->in['defaultsortas'];
134 $userinfo['columnoptions'] = $bugsys->in['columnoptions'];
135
136 $email = $bugsys->in['email_change'];
137 $email_confirm = $bugsys->in['email_confirm'];
138
139 // -------------------------------------------------------------------
140 // error handling
141 if ($message->items)
142 {
143 $message->error_list_process();
144
145 $show['errors'] = true;
146 $_REQUEST['do'] = 'modify';
147 }
148 else
149 {
150 $userapi->update();
151
152 if (can_perform('canbeassignedto'))
153 {
154 require_once('./includes/functions_datastore.php');
155 build_assignedto();
156 }
157
158 $db->query("DELETE FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $bugsys->userinfo['userid']);
159 $bugsys->input_clean('emailopts', TYPE_INT);
160 if (is_array($bugsys->in['emailopts']))
161 {
162 foreach ($bugsys->in['emailopts'] AS $relation => $bitarr)
163 {
164 $bitmask = 0;
165 if (is_array($bitarr))
166 {
167 foreach ($bitarr AS $option => $yes)
168 {
169 $bitmask += $option * $yes;
170 }
171 }
172 $db->query("INSERT INTO " . TABLE_PREFIX . "useremail (userid, relation, mask) VALUES (" . $bugsys->userinfo['userid'] . ", $relation, $bitmask)");
173 }
174 }
175
176 $message->redirect(_('The changes to your account have been made.'), 'userctrl.php');
177 }
178 }
179
180 // ###################################################################
181
182 if ($_REQUEST['do'] == 'modify')
183 {
184 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
185
186 $hidestatuses = construct_datastore_select('status', 'status', 'statusid', (!is_array($userinfo['hidestatuses']) ? explode(',', $userinfo['hidestatuses']) : $userinfo['hidestatuses']), 0);
187 $hidestatusesnum = (sizeof($bugsys->datastore['status']) < 8 ? sizeof($bugsys->datastore['status']) + 1 : 8);
188
189 $defaultsortkey = construct_option_select('defaultsortkey', ListSorter::fetch_by_text(false), $userinfo['defaultsortkey']);
190 $defaultsortas = construct_option_select('defaultsortas', ListSorter::fetch_as_text(false), $userinfo['defaultsortas']);
191
192 foreach ($datef->fetch_timezone_list() AS $value => $label)
193 {
194 $selected = ($value == $userinfo['timezone']);
195 eval('$tzselect .= "' . $template->fetch('selectoption') . '";');
196 }
197
198 $checked = array();
199 if (!is_array($bugsys->in['emailopts']))
200 {
201 $options = $db->query("SELECT * FROM " . TABLE_PREFIX . "useremail WHERE userid = " . $bugsys->userinfo['userid']);
202 while ($opt = $db->fetch_array($options))
203 {
204 foreach ($bugsys->emailoptions['notifications'] AS $name => $notif)
205 {
206 foreach ($bugsys->emailoptions['relations'] AS $name => $relation)
207 {
208 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
209 {
210 $checked["$relation"]["$notif"] = HTML_CHECKED;
211 }
212 }
213 }
214 }
215 }
216 else
217 {
218 $checked = $bugsys->in['emailopts'];
219 foreach ($checked AS $key1 => $value1)
220 {
221 foreach ($value1 AS $key2 => $value2)
222 {
223 if ($value2)
224 {
225 $checked["$key1"]["$key2"] = HTML_CHECKED;
226 }
227 }
228 }
229 }
230
231 $columns = array();
232 $columnOptions = '';
233 if (!is_array($bugsys->in['columnoptions']))
234 {
235 foreach ($bugsys->columns AS $column => $mask)
236 {
237 if (is_array($bugsys->userinfo['columnoptions']))
238 {
239 $columns["$column"] = $bugsys->userinfo['columnoptions']["$column"];
240 }
241 else
242 {
243 $columns["$column"] = $bugsys->options['columnoptions']["$colunn"];
244 }
245 eval('$columnOptions .= "' . $template->fetch('userctrl_column') . '";');
246 }
247 }
248 else
249 {
250 $columns = $bugsys->in['columnoptions'];
251 foreach ($bugsys->columns AS $column => $mask)
252 {
253 eval('$columnOptions .= "' . $template->fetch('userctrl_column') . '";');
254 }
255 }
256
257 eval('$template->flush("' . $template->fetch('userctrl') . '");');
258 }
259
260 /*=====================================================================*\
261 || ###################################################################
262 || # $HeadURL$
263 || # $Id$
264 || ###################################################################
265 \*=====================================================================*/
266 ?>