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