1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | profile.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 362 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | // customize appearance of the site for a user |
---|
29 | //----------------------------------------------------------- include |
---|
30 | $phpwg_root_path = './'; |
---|
31 | include_once( $phpwg_root_path.'include/common.inc.php' ); |
---|
32 | //-------------------------------------------------- access authorization check |
---|
33 | check_login_authorization(); |
---|
34 | if ( $user['is_the_guest'] ) |
---|
35 | { |
---|
36 | echo '<div style="text-align:center;">'.$lang['only_members'].'<br />'; |
---|
37 | echo '<a href="./identification.php">'.$lang['ident_title'].'</a></div>'; |
---|
38 | exit(); |
---|
39 | } |
---|
40 | //------------------------------------------------------ update & customization |
---|
41 | $infos = array( 'nb_image_line', 'nb_line_page', 'language', |
---|
42 | 'maxwidth', 'maxheight', 'expand', 'show_nb_comments', |
---|
43 | 'short_period', 'long_period', 'template', 'mail_address' ); |
---|
44 | // mise à jour dans la base de données des valeurs |
---|
45 | // des paramètres pour l'utilisateur courant |
---|
46 | // - on teste si chacune des variables est passée en argument à la page |
---|
47 | // - ce qui signifie que l'on doit venir de la page de personnalisation |
---|
48 | $errors = array(); |
---|
49 | if ( isset( $_POST['submit'] ) ) |
---|
50 | { |
---|
51 | $int_pattern = '/^\d+$/'; |
---|
52 | if ( $_POST['maxwidth'] != '' |
---|
53 | and ( !preg_match( $int_pattern, $_POST['maxwidth'] ) |
---|
54 | or $_POST['maxwidth'] < 50 ) ) |
---|
55 | { |
---|
56 | array_push( $errors, $lang['err_maxwidth'] ); |
---|
57 | } |
---|
58 | if ( $_POST['maxheight'] |
---|
59 | and ( !preg_match( $int_pattern, $_POST['maxheight'] ) |
---|
60 | or $_POST['maxheight'] < 50 ) ) |
---|
61 | { |
---|
62 | array_push( $errors, $lang['err_maxheight'] ); |
---|
63 | } |
---|
64 | // periods must be integer values, they represents number of days |
---|
65 | if ( !preg_match( $int_pattern, $_POST['short_period'] ) |
---|
66 | or !preg_match( $int_pattern, $_POST['long_period'] ) ) |
---|
67 | { |
---|
68 | array_push( $errors, $lang['err_periods'] ); |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | // long period must be longer than short period |
---|
73 | if ( $_POST['long_period'] <= $_POST['short_period'] |
---|
74 | or $_POST['short_period'] <= 0 ) |
---|
75 | { |
---|
76 | array_push( $errors, $lang['err_periods_2'] ); |
---|
77 | } |
---|
78 | } |
---|
79 | $mail_error = validate_mail_address( $_POST['mail_address'] ); |
---|
80 | if ( $mail_error != '' ) array_push( $errors, $mail_error ); |
---|
81 | // password must be the same as its confirmation |
---|
82 | if ( isset( $_POST['use_new_pwd'] ) |
---|
83 | and $_POST['password'] != $_POST['passwordConf'] ) |
---|
84 | array_push( $errors, $lang['reg_err_pass'] ); |
---|
85 | |
---|
86 | if ( count( $errors ) == 0 ) |
---|
87 | { |
---|
88 | $query = 'UPDATE '.PREFIX_TABLE.'users'; |
---|
89 | $query.= ' SET '; |
---|
90 | foreach ( $infos as $i => $info ) { |
---|
91 | if ( $i > 0 ) $query.= ','; |
---|
92 | $query.= $info; |
---|
93 | $query.= ' = '; |
---|
94 | if ( $_POST[$info] == '' ) $query.= 'NULL'; |
---|
95 | else $query.= "'".$_POST[$info]."'"; |
---|
96 | } |
---|
97 | $query.= ' WHERE id = '.$user['id']; |
---|
98 | $query.= ';'; |
---|
99 | mysql_query( $query ); |
---|
100 | |
---|
101 | if ( isset( $_POST['use_new_pwd'] ) ) |
---|
102 | { |
---|
103 | $query = 'UPDATE '.PREFIX_TABLE.'users'; |
---|
104 | $query.= " SET password = '".md5( $_POST['password'] )."'"; |
---|
105 | $query.= ' WHERE id = '.$user['id']; |
---|
106 | $query.= ';'; |
---|
107 | mysql_query( $query ); |
---|
108 | } |
---|
109 | if ( isset( $_POST['create_cookie'] ) ) |
---|
110 | { |
---|
111 | setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'], |
---|
112 | cookie_path() ); |
---|
113 | // update the expiration date of the session |
---|
114 | $query = 'UPDATE '.PREFIX_TABLE.'sessions'; |
---|
115 | $query.= ' SET expiration = '.$_POST['cookie_expiration']; |
---|
116 | $query.= " WHERE id = '".$page['session_id']."'"; |
---|
117 | $query.= ';'; |
---|
118 | mysql_query( $query ); |
---|
119 | } |
---|
120 | // redirection |
---|
121 | $url = 'category.php'; |
---|
122 | if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true ); |
---|
123 | header( 'Request-URI: '.$url ); |
---|
124 | header( 'Content-Location: '.$url ); |
---|
125 | header( 'Location: '.$url ); |
---|
126 | exit(); |
---|
127 | } |
---|
128 | } |
---|
129 | //----------------------------------------------------- template initialization |
---|
130 | // |
---|
131 | // Start output of page |
---|
132 | // |
---|
133 | $title = $lang['customize_page_title']; |
---|
134 | include('include/page_header.php'); |
---|
135 | |
---|
136 | $handle = $vtp->Open( './template/'.$user['template'].'/profile.vtp' ); |
---|
137 | initialize_template(); |
---|
138 | $tpl = array( 'customize_title','password','new', |
---|
139 | 'reg_confirm','submit','create_cookie' ); |
---|
140 | templatize_array( $tpl, 'lang', $handle ); |
---|
141 | //----------------------------------------------------------------- form action |
---|
142 | $url = './profile.php'; |
---|
143 | $vtp->setGlobalVar( $handle, 'form_action', add_session_id( $url ) ); |
---|
144 | //-------------------------------------------------------------- errors display |
---|
145 | if ( count( $errors ) != 0 ) |
---|
146 | { |
---|
147 | $vtp->addSession( $handle, 'errors' ); |
---|
148 | foreach ( $errors as $error ) { |
---|
149 | $vtp->addSession( $handle, 'li' ); |
---|
150 | $vtp->setVar( $handle, 'li.li', $error ); |
---|
151 | $vtp->closeSession( $handle, 'li' ); |
---|
152 | } |
---|
153 | $vtp->closeSession( $handle, 'errors' ); |
---|
154 | } |
---|
155 | //---------------------------------------------------- number of images per row |
---|
156 | if ( in_array( 'nb_image_line', $infos ) ) |
---|
157 | { |
---|
158 | $vtp->addSession( $handle, 'line' ); |
---|
159 | $vtp->setVar( $handle, 'line.name', $lang['customize_nb_image_per_row'] ); |
---|
160 | $vtp->addSession( $handle, 'select' ); |
---|
161 | $vtp->setVar( $handle, 'select.name', 'nb_image_line' ); |
---|
162 | for ( $i = 0; $i < sizeof( $conf['nb_image_row'] ); $i++ ) |
---|
163 | { |
---|
164 | $vtp->addSession( $handle, 'option' ); |
---|
165 | $vtp->setVar( $handle, 'option.option', $conf['nb_image_row'][$i] ); |
---|
166 | if ( $conf['nb_image_row'][$i] == $user['nb_image_line'] ) |
---|
167 | { |
---|
168 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
169 | } |
---|
170 | $vtp->closeSession( $handle, 'option' ); |
---|
171 | } |
---|
172 | $vtp->closeSession( $handle, 'select' ); |
---|
173 | $vtp->closeSession( $handle, 'line' ); |
---|
174 | } |
---|
175 | //------------------------------------------------------ number of row per page |
---|
176 | if ( in_array( 'nb_line_page', $infos ) ) |
---|
177 | { |
---|
178 | $vtp->addSession( $handle, 'line' ); |
---|
179 | $vtp->setVar( $handle, 'line.name', $lang['customize_nb_row_per_page'] ); |
---|
180 | $vtp->addSession( $handle, 'select' ); |
---|
181 | $vtp->setVar( $handle, 'select.name', 'nb_line_page' ); |
---|
182 | for ( $i = 0; $i < sizeof( $conf['nb_row_page'] ); $i++ ) |
---|
183 | { |
---|
184 | $vtp->addSession( $handle, 'option' ); |
---|
185 | $vtp->setVar( $handle, 'option.option', $conf['nb_row_page'][$i] ); |
---|
186 | if ( $conf['nb_row_page'][$i] == $user['nb_line_page'] ) |
---|
187 | { |
---|
188 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
189 | } |
---|
190 | $vtp->closeSession( $handle, 'option' ); |
---|
191 | } |
---|
192 | $vtp->closeSession( $handle, 'select' ); |
---|
193 | $vtp->closeSession( $handle, 'line' ); |
---|
194 | } |
---|
195 | //-------------------------------------------------------------------- template |
---|
196 | if ( in_array( 'template', $infos ) ) |
---|
197 | { |
---|
198 | $vtp->addSession( $handle, 'line' ); |
---|
199 | $vtp->setVar( $handle, 'line.name', $lang['customize_template'] ); |
---|
200 | $vtp->addSession( $handle, 'select' ); |
---|
201 | $vtp->setVar( $handle, 'select.name', 'template' ); |
---|
202 | $option = get_dirs( './template' ); |
---|
203 | for ( $i = 0; $i < sizeof( $option ); $i++ ) |
---|
204 | { |
---|
205 | $vtp->addSession( $handle, 'option' ); |
---|
206 | $vtp->setVar( $handle, 'option.option', $option[$i] ); |
---|
207 | if ( $option[$i] == $user['template'] ) |
---|
208 | { |
---|
209 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
210 | } |
---|
211 | $vtp->closeSession( $handle, 'option' ); |
---|
212 | } |
---|
213 | $vtp->closeSession( $handle, 'select' ); |
---|
214 | $vtp->closeSession( $handle, 'line' ); |
---|
215 | } |
---|
216 | //-------------------------------------------------------------------- language |
---|
217 | if ( in_array( 'language', $infos ) ) |
---|
218 | { |
---|
219 | $vtp->addSession( $handle, 'line' ); |
---|
220 | $vtp->setVar( $handle, 'line.name', $lang['customize_language'] ); |
---|
221 | $vtp->addSession( $handle, 'select' ); |
---|
222 | $vtp->setVar( $handle, 'select.name', 'language' ); |
---|
223 | $option = get_languages( './language/' ); |
---|
224 | for ( $i = 0; $i < sizeof( $option ); $i++ ) |
---|
225 | { |
---|
226 | $vtp->addSession( $handle, 'option' ); |
---|
227 | $vtp->setVar( $handle, 'option.option', $option[$i] ); |
---|
228 | if( $option[$i] == $user['language'] ) |
---|
229 | { |
---|
230 | $vtp->setVar( $handle, 'option.selected', ' selected="selected"' ); |
---|
231 | } |
---|
232 | $vtp->closeSession( $handle, 'option' ); |
---|
233 | } |
---|
234 | $vtp->closeSession( $handle, 'select' ); |
---|
235 | $vtp->closeSession( $handle, 'line' ); |
---|
236 | } |
---|
237 | //---------------------------------------------------------------- short period |
---|
238 | if ( in_array( 'short_period', $infos ) ) |
---|
239 | { |
---|
240 | $vtp->addSession( $handle, 'line' ); |
---|
241 | $vtp->setVar( $handle, 'line.name', $lang['customize_short_period'] ); |
---|
242 | $vtp->addSession( $handle, 'text' ); |
---|
243 | $vtp->setVar( $handle, 'text.name', 'short_period' ); |
---|
244 | $vtp->setVar( $handle, 'text.value', $user['short_period'] ); |
---|
245 | $vtp->closeSession( $handle, 'text' ); |
---|
246 | $vtp->closeSession( $handle, 'line' ); |
---|
247 | } |
---|
248 | //----------------------------------------------------------------- long period |
---|
249 | if ( in_array( 'long_period', $infos ) ) |
---|
250 | { |
---|
251 | $vtp->addSession( $handle, 'line' ); |
---|
252 | $vtp->setVar( $handle, 'line.name', $lang['customize_long_period'] ); |
---|
253 | $vtp->addSession( $handle, 'text' ); |
---|
254 | $vtp->setVar( $handle, 'text.name', 'long_period' ); |
---|
255 | $vtp->setVar( $handle, 'text.value', $user['long_period'] ); |
---|
256 | $vtp->closeSession( $handle, 'text' ); |
---|
257 | $vtp->closeSession( $handle, 'line' ); |
---|
258 | } |
---|
259 | //--------------------------------------------------------- max displayed width |
---|
260 | if ( in_array( 'maxwidth', $infos ) ) |
---|
261 | { |
---|
262 | $vtp->addSession( $handle, 'line' ); |
---|
263 | $vtp->setVar( $handle, 'line.name', $lang['maxwidth'] ); |
---|
264 | $vtp->addSession( $handle, 'text' ); |
---|
265 | $vtp->setVar( $handle, 'text.name', 'maxwidth' ); |
---|
266 | $vtp->setVar( $handle, 'text.value', $user['maxwidth'] ); |
---|
267 | $vtp->closeSession( $handle, 'text' ); |
---|
268 | $vtp->closeSession( $handle, 'line' ); |
---|
269 | } |
---|
270 | //-------------------------------------------------------- max displayed height |
---|
271 | if ( in_array( 'maxheight', $infos ) ) |
---|
272 | { |
---|
273 | $vtp->addSession( $handle, 'line' ); |
---|
274 | $vtp->setVar( $handle, 'line.name', $lang['maxheight'] ); |
---|
275 | $vtp->addSession( $handle, 'text' ); |
---|
276 | $vtp->setVar( $handle, 'text.name', 'maxheight' ); |
---|
277 | $vtp->setVar( $handle, 'text.value', $user['maxheight'] ); |
---|
278 | $vtp->closeSession( $handle, 'text' ); |
---|
279 | $vtp->closeSession( $handle, 'line' ); |
---|
280 | } |
---|
281 | //---------------------------------------------------------------- mail address |
---|
282 | if ( in_array( 'mail_address', $infos ) ) |
---|
283 | { |
---|
284 | $vtp->addSession( $handle, 'line' ); |
---|
285 | $vtp->setVar( $handle, 'line.name', $lang['mail_address'] ); |
---|
286 | $vtp->addSession( $handle, 'text' ); |
---|
287 | $vtp->setVar( $handle, 'text.name', 'mail_address' ); |
---|
288 | $vtp->setVar( $handle, 'text.value', $user['mail_address'] ); |
---|
289 | $vtp->closeSession( $handle, 'text' ); |
---|
290 | $vtp->closeSession( $handle, 'line' ); |
---|
291 | } |
---|
292 | //----------------------------------------------------- expand all categories ? |
---|
293 | if ( in_array( 'expand', $infos ) ) |
---|
294 | { |
---|
295 | $vtp->addSession( $handle, 'line' ); |
---|
296 | $vtp->setVar( $handle, 'line.name', $lang['customize_expand'] ); |
---|
297 | $vtp->addSession( $handle, 'group' ); |
---|
298 | $vtp->addSession( $handle, 'radio' ); |
---|
299 | $vtp->setVar( $handle, 'radio.name', 'expand' ); |
---|
300 | $vtp->setVar( $handle, 'radio.value', 'true' ); |
---|
301 | $checked = ''; |
---|
302 | if ( $user['expand'] ) |
---|
303 | { |
---|
304 | $checked = ' checked="checked"'; |
---|
305 | } |
---|
306 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
307 | $vtp->setVar( $handle, 'radio.option', $lang['yes'] ); |
---|
308 | $vtp->closeSession( $handle, 'radio' ); |
---|
309 | $vtp->addSession( $handle, 'radio' ); |
---|
310 | $vtp->setVar( $handle, 'radio.name', 'expand' ); |
---|
311 | $vtp->setVar( $handle, 'radio.value', 'false' ); |
---|
312 | $checked = ''; |
---|
313 | if ( !$user['expand'] ) |
---|
314 | { |
---|
315 | $checked = ' checked="checked"'; |
---|
316 | } |
---|
317 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
318 | $vtp->setVar( $handle, 'radio.option', $lang['no'] ); |
---|
319 | $vtp->closeSession( $handle, 'radio' ); |
---|
320 | $vtp->closeSession( $handle, 'group' ); |
---|
321 | $vtp->closeSession( $handle, 'line' ); |
---|
322 | } |
---|
323 | //---------------------------------- show number of comments on thumbnails page |
---|
324 | if ( in_array( 'show_nb_comments', $infos ) ) |
---|
325 | { |
---|
326 | $vtp->addSession( $handle, 'line' ); |
---|
327 | $vtp->setVar( $handle, 'line.name', $lang['customize_show_nb_comments'] ); |
---|
328 | $vtp->addSession( $handle, 'group' ); |
---|
329 | $vtp->addSession( $handle, 'radio' ); |
---|
330 | $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' ); |
---|
331 | $vtp->setVar( $handle, 'radio.value', 'true' ); |
---|
332 | $checked = ''; |
---|
333 | if ( $user['show_nb_comments'] ) |
---|
334 | { |
---|
335 | $checked = ' checked="checked"'; |
---|
336 | } |
---|
337 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
338 | $vtp->setVar( $handle, 'radio.option', $lang['yes'] ); |
---|
339 | $vtp->closeSession( $handle, 'radio' ); |
---|
340 | $vtp->addSession( $handle, 'radio' ); |
---|
341 | $vtp->setVar( $handle, 'radio.name', 'show_nb_comments' ); |
---|
342 | $vtp->setVar( $handle, 'radio.value', 'false' ); |
---|
343 | $checked = ''; |
---|
344 | if ( !$user['show_nb_comments'] ) |
---|
345 | { |
---|
346 | $checked = ' checked="checked"'; |
---|
347 | } |
---|
348 | $vtp->setVar( $handle, 'radio.checked', $checked ); |
---|
349 | $vtp->setVar( $handle, 'radio.option', $lang['no'] ); |
---|
350 | $vtp->closeSession( $handle, 'radio' ); |
---|
351 | $vtp->closeSession( $handle, 'group' ); |
---|
352 | $vtp->closeSession( $handle, 'line' ); |
---|
353 | } |
---|
354 | //--------------------------------------------------------------- create cookie |
---|
355 | if ( $conf['authorize_cookies'] ) |
---|
356 | { |
---|
357 | $vtp->addSession( $handle, 'cookie' ); |
---|
358 | $options = array( |
---|
359 | array( 'message' => '1 '.$lang['customize_day'], |
---|
360 | 'value' => time() + 24*60*60 ), |
---|
361 | array( 'message' => '1 '.$lang['customize_week'], |
---|
362 | 'value' => time() + 7*24*60*60 ), |
---|
363 | array( 'message' => '1 '.$lang['customize_month'], |
---|
364 | 'value' => time() + 30*24*60*60 ), |
---|
365 | array( 'message' => '1 '.$lang['customize_year'], |
---|
366 | 'value' => time() + 365*24*60*60 ) |
---|
367 | ); |
---|
368 | foreach ( $options as $option ) { |
---|
369 | $vtp->addSession( $handle, 'expiration_option' ); |
---|
370 | $vtp->setVar( $handle, 'expiration_option.option', $option['message'] ); |
---|
371 | $vtp->setVar( $handle, 'expiration_option.value', $option['value'] ); |
---|
372 | $vtp->closeSession( $handle, 'expiration_option' ); |
---|
373 | } |
---|
374 | $vtp->closeSession( $handle, 'cookie' ); |
---|
375 | } |
---|
376 | //----------------------------------------------------------- html code display |
---|
377 | $code = $vtp->Display( $handle, 0 ); |
---|
378 | echo $code; |
---|
379 | include('include/page_tail.php'); |
---|
380 | ?> |
---|