]>
src.bluestatic.org Git - bugdar.git/blob - userctrl.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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 (
29 $focus [ 'user' ] = 'focus' ;
31 require_once ( './global.php' );
32 require_once ( './includes/api_user.php' );
34 if (! bugdar
:: $userinfo [ 'userid' ])
36 $message- > errorPermission ();
39 $userapi = new UserAPI ();
40 $userapi- > set ( 'userid' , bugdar
:: $userinfo [ 'userid' ]);
41 $userapi- > setCondition ();
43 $userinfo = bugdar
:: $userinfo ;
45 // ###################################################################
47 if ( empty ( $_REQUEST [ 'do' ]))
49 $_REQUEST [ 'do' ] = 'modify' ;
52 // ###################################################################
54 if ( $_POST [ 'do' ] == 'killsearch' )
56 $search = $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input- > inputClean ( 'searchid' , TYPE_UINT
) . " AND userid = " . bugdar
:: $userinfo [ 'userid' ]);
59 $message- > errorPermission ();
62 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input- > in
[ 'searchid' ]);
64 $message- > redirect ( T ( 'This saved search has been removed from your list.' ), 'userctrl.php' );
67 // ###################################################################
69 if ( $_REQUEST [ 'do' ] == 'deletesearch' )
71 $search = $db- > queryFirst ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE searchid = " . $input- > inputClean ( 'searchid' , TYPE_UINT
) . " AND userid = " . bugdar
:: $userinfo [ 'userid' ]);
74 $message- > errorPermission ();
77 $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 // ###################################################################
82 if ( $_POST [ 'do' ] == 'update' )
84 // -------------------------------------------------------------------
86 if (! empty ( $input- > in
[ 'password_change' ]) OR ! empty ( $input- > in
[ 'email_change' ]))
88 if ( empty ( $input- > in
[ 'validate' ]))
90 $message- > addError ( T ( 'You need to enter your current password to change your email or password' ));
94 if ( md5 ( md5 ( $input- > in
[ 'validate' ]) . md5 ( bugdar
:: $userinfo [ 'salt' ])) != bugdar
:: $userinfo [ 'password' ])
96 $message- > addError ( T ( 'Your authentication password does not match the one in our records' ));
101 // -------------------------------------------------------------------
103 if (! empty ( $input- > in
[ 'email_change' ]))
105 if (! empty ( $input- > in
[ 'email_change' ]) AND empty ( $input- > in
[ 'email_confirm' ]))
107 $message- > addError ( T ( 'You need to enter both the email and confirm email fields to change your address' ));
110 if ( $input- > in
[ 'email_change' ] != $input- > in
[ 'email_confirm' ])
112 $message- > addError ( T ( 'Your email and confirm email addresses do not match' ));
115 $userapi- > set ( 'email' , $input- > in
[ 'email_change' ]);
118 // -------------------------------------------------------------------
119 // password validation
120 if (! empty ( $input- > in
[ 'password_change' ]))
122 if (! empty ( $input- > in
[ 'password_change' ]) AND empty ( $input- > in
[ 'password_confirm' ]))
124 $message- > addError ( T ( 'You need to enter both the password and confirm password fields to change your password' ));
128 if ( $input- > in
[ 'password_change' ] != $input- > in
[ 'password_confirm' ])
130 $message- > addError ( T ( 'Your password and confirm password do not match' ));
134 $userapi- > set ( 'password' , $input- > in
[ 'password_change' ]);
137 $userapi- > set ( 'displayname' , $input- > in
[ 'displayname' ]);
138 $userapi- > set ( 'showemail' , $input- > in
[ 'showemail' ]);
139 $userapi- > set ( 'showcolors' , $input- > in
[ 'showcolors' ]);
140 $userapi- > set ( 'languageid' , $input- > in
[ 'languageid' ]);
141 $userapi- > set ( 'timezone' , $input- > in
[ 'timezone' ]);
142 $userapi- > set ( 'usedst' , $input- > in
[ 'usedst' ]);
143 $userapi- > set ( 'hidestatuses' , $input- > in
[ 'hidestatuses' ]);
144 $userapi- > set ( 'defaultsortkey' , $input- > in
[ 'defaultsortkey' ]);
145 $userapi- > set ( 'defaultsortas' , $input- > in
[ 'defaultsortas' ]);
146 $userapi- > set ( 'columnoptions' , $input- > inputClean ( 'columnoptions' , TYPE_UINT
));
148 // -------------------------------------------------------------------
150 $userinfo [ 'displayname' ] = $input- > in
[ 'displayname' ];
151 $userinfo [ 'showemail' ] = $input- > in
[ 'showemail' ];
152 $userinfo [ 'showcolors' ] = $input- > in
[ 'showcolors' ];
153 $userinfo [ 'languageid' ] = $input- > in
[ 'languageid' ];
154 $userinfo [ 'timezone' ] = $input- > in
[ 'timezone' ];
155 $userinfo [ 'usedst' ] = $input- > in
[ 'usedst' ];
156 $userinfo [ 'hidestatuses' ] = $input- > in
[ 'hidestatuses' ];
157 $userinfo [ 'defaultsorkey' ] = $input- > in
[ 'defaultsorkey' ];
158 $userinfo [ 'defaultsortas' ] = $input- > in
[ 'defaultsortas' ];
159 $userinfo [ 'columnoptions' ] = $input- > in
[ 'columnoptions' ];
161 $email = $input- > in
[ 'email_change' ];
162 $email_confirm = $input- > in
[ 'email_confirm' ];
164 // -------------------------------------------------------------------
166 if ( $message- > hasErrors ())
168 $show [ 'errors' ] = true ;
169 $_REQUEST [ 'do' ] = 'modify' ;
175 $db- > query ( "DELETE FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . bugdar
:: $userinfo [ 'userid' ]);
176 $input- > inputClean ( 'emailopts' , TYPE_INT
);
177 if ( is_array ( $input- > in
[ 'emailopts' ]))
179 foreach ( $input- > in
[ 'emailopts' ] AS $relation => $bitarr )
182 if ( is_array ( $bitarr ))
184 foreach ( $bitarr AS $option => $yes )
186 $bitmask +
= $option * $yes ;
189 $db- > query ( "INSERT INTO " . TABLE_PREFIX
. "useremail (userid, relation, mask) VALUES (" . bugdar
:: $userinfo [ 'userid' ] . ", $relation , $bitmask )" );
193 $message- > redirect ( T ( 'The changes to your account have been made.' ), 'userctrl.php' );
197 // ###################################################################
199 if ( $_REQUEST [ 'do' ] == 'modify' )
201 $langselect = construct_datastore_select ( 'language' , 'title' , 'languageid' , $userinfo [ 'languageid' ]);
203 $hidestatuses = construct_datastore_select ( 'status' , 'status' , 'statusid' , (! is_array ( $userinfo [ 'hidestatuses' ]) ? explode ( ',' , $userinfo [ 'hidestatuses' ]) : $userinfo [ 'hidestatuses' ]), 0 );
204 $hidestatusesnum = ( sizeof ( bugdar
:: $datastore [ 'status' ]) < 8 ? sizeof ( bugdar
:: $datastore [ 'status' ]) +
1 : 8 );
206 $defaultsortkey = construct_option_select ( 'defaultsortkey' , ListSorter
:: fetch_by_text ( false ), $userinfo [ 'defaultsortkey' ]);
207 $defaultsortas = construct_option_select ( 'defaultsortas' , ListSorter
:: fetch_as_text ( false ), $userinfo [ 'defaultsortas' ]);
209 foreach ( $datef- > fetch_timezone_list () as $value => $label )
211 $tpl = new BSTemplate ( 'selectoption' );
215 'selected' => ( $value == $userinfo [ 'timezone' ])
217 $tzselect .= $tpl- > evaluate ()-> getTemplate ();
221 if (! is_array ( $input- > in
[ 'emailopts' ]))
223 $options = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "useremail WHERE userid = " . bugdar
:: $userinfo [ 'userid' ]);
224 foreach ( $options as $opt )
226 foreach ( bugdar
:: $emailOptions [ 'notifications' ] AS $name => $notif )
228 foreach ( bugdar
:: $emailOptions [ 'relations' ] AS $name => $relation )
230 if ( $opt [ 'mask' ] & $notif AND $opt [ 'relation' ] == $relation )
232 $checked [ " $relation" ][" $notif" ] = HTML_CHECKED
;
240 $checked = $input- > in
[ 'emailopts' ];
241 foreach ( $checked AS $key1 => $value1 )
243 foreach ( $value1 AS $key2 => $value2 )
247 $checked [ " $key1" ][" $key2" ] = HTML_CHECKED
;
255 require_once ( './includes/class_sort.php' );
256 if (! is_array ( $input- > in
[ 'columnoptions' ]))
258 foreach ( ListSorter
:: fetch_by_text ( false ) AS $column => $name )
260 if ( is_array ( bugdar
:: $userinfo [ 'columnoptions' ]))
262 $columns [ " $column" ] = bugdar:: $userinfo ['columnoptions'][" $column" ];
266 $columns [ " $column" ] = bugdar:: $options ['columnoptions'][" $column" ];
268 $tpl = new BSTemplate ( 'userctrl_column' );
270 'columns' => $columns ,
274 $columnOptions .= $tpl- > evaluate ()-> getTemplate ();
279 $columns = $input- > in
[ 'columnoptions' ];
280 foreach ( ListSorter
:: fetch_by_text ( false ) as $column => $name )
282 $tpl = new BSTemplate ( 'userctrl_column' );
284 'columns' => $columns ,
288 $columnOptions .= $tpl- > evaluate ()-> getTemplate ();
294 $searchesFetch = $db- > query ( "SELECT * FROM " . TABLE_PREFIX
. "search WHERE name IS NOT NULL AND userid = " . bugdar
:: $userinfo [ 'userid' ]);
295 foreach ( $searchesFetch as $search )
297 $tpl = new BSTemplate ( 'userctrl_search' );
298 $tpl- > vars
= array ( 'search' => $search );
299 $searches .= $tpl- > evaluate ()-> getTemplate ();
302 $tpl = new BSTemplate ( 'userctrl' );
304 'checked' => $checked ,
305 'userinfo' => $userinfo ,
306 'searches' => $searches ,
307 'defaultsortkey' => $defaultsortkey ,
308 'hidestatusesnum' => $hidestatusesnum ,
309 'hidestatuses' => $hidestatuses ,
310 'defaultsortas' => $defaultsortas ,
311 'columnOptions' => $columnOptions ,
312 'langselect' => $langselect ,
313 'tzselect' => $tzselect
315 $tpl- > evaluate ()-> flush ();