2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
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.
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
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 \*=====================================================================*/
22 $fetchtemplates = array(
28 define('SVN', '$Id$');
30 $focus['user'] = 'focus';
32 require_once('./global.php');
33 require_once('./includes/class_api_error.php');
34 require_once('./includes/api_user.php');
36 if (!bugdar
::$userinfo['userid'])
38 $message->errorPermission();
41 $userapi = new UserAPI($bugsys);
42 $userapi->set('userid', bugdar
::$userinfo['userid']);
43 $userapi->setCondition();
45 $userinfo = bugdar
::$userinfo;
47 // ###################################################################
49 if (empty($_REQUEST['do']))
51 $_REQUEST['do'] = 'modify';
54 // ###################################################################
56 if ($_POST['do'] == 'killsearch')
58 $search = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input->inputClean('searchid', TYPE_UINT
) . " AND userid = " . bugdar
::$userinfo['userid']);
61 $message->errorPermission();
64 $db->query("DELETE FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input->in
['searchid']);
66 $message->redirect(T('This saved search has been removed from your list.'), 'userctrl.php');
69 // ###################################################################
71 if ($_REQUEST['do'] == 'deletesearch')
73 $search = $db->queryFirst("SELECT * FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input->inputClean('searchid', TYPE_UINT
) . " AND userid = " . bugdar
::$userinfo['userid']);
76 $message->errorPermission();
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']));
82 // ###################################################################
84 if ($_POST['do'] == 'update')
86 // -------------------------------------------------------------------
88 if (!empty($input->in
['password_change']) OR !empty($input->in
['email_change']))
90 if (empty($input->in
['validate']))
92 $message->addError(T('You need to enter your current password to change your email or password'));
96 if (md5(md5($input->in
['validate']) . md5(bugdar
::$userinfo['salt'])) != bugdar
::$userinfo['password'])
98 $message->addError(T('Your authentication password does not match the one in our records'));
103 // -------------------------------------------------------------------
105 if (!empty($input->in
['email_change']))
107 if (!empty($input->in
['email_change']) AND empty($input->in
['email_confirm']))
109 $message->addError(T('You need to enter both the email and confirm email fields to change your address'));
112 if ($input->in
['email_change'] != $input->in
['email_confirm'])
114 $message->addError(T('Your email and confirm email addresses do not match'));
117 $userapi->set('email', $input->in
['email_change']);
120 // -------------------------------------------------------------------
121 // password validation
122 if (!empty($input->in
['password_change']))
124 if (!empty($input->in
['password_change']) AND empty($input->in
['password_confirm']))
126 $message->addError(T('You need to enter both the password and confirm password fields to change your password'));
130 if ($input->in
['password_change'] != $input->in
['password_confirm'])
132 $message->addError(T('Your password and confirm password do not match'));
136 $userapi->set('password', $input->in
['password_change']);
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
));
150 // -------------------------------------------------------------------
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'];
163 $email = $input->in
['email_change'];
164 $email_confirm = $input->in
['email_confirm'];
166 // -------------------------------------------------------------------
168 if ($message->hasErrors())
170 $show['errors'] = true
;
171 $_REQUEST['do'] = 'modify';
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']))
181 foreach ($input->in
['emailopts'] AS $relation => $bitarr)
184 if (is_array($bitarr))
186 foreach ($bitarr AS $option => $yes)
188 $bitmask +
= $option * $yes;
191 $db->query("INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . bugdar
::$userinfo['userid'] . ", $relation, $bitmask)");
195 $message->redirect(T('The changes to your account have been made.'), 'userctrl.php');
199 // ###################################################################
201 if ($_REQUEST['do'] == 'modify')
203 $langselect = construct_datastore_select('language', 'title', 'languageid', $userinfo['languageid']);
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);
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']);
211 foreach ($datef->fetch_timezone_list() as $value => $label)
213 $tpl = new BSTemplate('selectoption');
217 'selected' => ($value == $userinfo['timezone'])
219 $tzselect .= $tpl->evaluate()->getTemplate();
223 if (!is_array($input->in
['emailopts']))
225 $options = $db->query("SELECT * FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . bugdar
::$userinfo['userid']);
226 foreach ($options as $opt)
228 foreach ($bugsys->emailoptions
['notifications'] AS $name => $notif)
230 foreach ($bugsys->emailoptions
['relations'] AS $name => $relation)
232 if ($opt['mask'] & $notif AND $opt['relation'] == $relation)
234 $checked["$relation"]["$notif"] = HTML_CHECKED
;
242 $checked = $input->in
['emailopts'];
243 foreach ($checked AS $key1 => $value1)
245 foreach ($value1 AS $key2 => $value2)
249 $checked["$key1"]["$key2"] = HTML_CHECKED
;
257 require_once('./includes/class_sort.php');
258 if (!is_array($input->in
['columnoptions']))
260 foreach (ListSorter
::fetch_by_text(false
) AS $column => $name)
262 if (is_array(bugdar
::$userinfo['columnoptions']))
264 $columns["$column"] = bugdar
::$userinfo['columnoptions']["$column"];
268 $columns["$column"] = bugdar
::$options['columnoptions']["$column"];
270 $tpl = new BSTemplate('userctrl_column');
272 'columns' => $columns,
276 $columnOptions .= $tpl->evaluate()->getTemplate();
281 $columns = $input->in
['columnoptions'];
282 foreach (ListSorter
::fetch_by_text(false
) as $column => $name)
284 $tpl = new BSTemplate('userctrl_column');
286 'columns' => $columns,
290 $columnOptions .= $tpl->evaluate()->getTemplate();
296 $searchesFetch = $db->query("SELECT * FROM " . TABLE_PREFIX
. "search WHERE name IS NOT NULL AND userid = " . bugdar
::$userinfo['userid']);
297 foreach ($searchesFetch as $search)
299 $tpl = new BSTemplate('userctrl_search');
300 $tpl->vars
= array('search' => $search);
301 $searches .= $tpl->evaluate()->getTemplate();
304 $tpl = new BSTemplate('userctrl');
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
317 $tpl->evaluate()->flush();
320 /*=====================================================================*\
321 || ###################################################################
324 || ###################################################################
325 \*=====================================================================*/