1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-11-06 21:12:59 +0000 (Sat, 06 Nov 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 593 $ |
---|
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 | define('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 | 'recent_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['maxwidth_error'] ); |
---|
57 | } |
---|
58 | if ( $_POST['maxheight'] |
---|
59 | and ( !preg_match( $int_pattern, $_POST['maxheight'] ) |
---|
60 | or $_POST['maxheight'] < 50 ) ) |
---|
61 | { |
---|
62 | array_push( $errors, $lang['maxheight_error'] ); |
---|
63 | } |
---|
64 | // periods must be integer values, they represents number of days |
---|
65 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
66 | or $_POST['recent_period'] <= 0) |
---|
67 | { |
---|
68 | array_push( $errors, $lang['periods_error'] ); |
---|
69 | } |
---|
70 | $mail_error = validate_mail_address( $_POST['mail_address'] ); |
---|
71 | if ( $mail_error != '' ) array_push( $errors, $mail_error ); |
---|
72 | // password must be the same as its confirmation |
---|
73 | if ( isset( $_POST['use_new_pwd'] ) |
---|
74 | and $_POST['password'] != $_POST['passwordConf'] ) |
---|
75 | array_push( $errors, $lang['reg_err_pass'] ); |
---|
76 | |
---|
77 | if ( count( $errors ) == 0 ) |
---|
78 | { |
---|
79 | $query = 'UPDATE '.USERS_TABLE; |
---|
80 | $query.= ' SET '; |
---|
81 | foreach ( $infos as $i => $info ) { |
---|
82 | if ( $i > 0 ) $query.= ','; |
---|
83 | $query.= $info; |
---|
84 | $query.= ' = '; |
---|
85 | if ( $_POST[$info] == '' ) $query.= 'NULL'; |
---|
86 | else $query.= "'".$_POST[$info]."'"; |
---|
87 | } |
---|
88 | $query.= ' WHERE id = '.$user['id']; |
---|
89 | $query.= ';'; |
---|
90 | pwg_query( $query ); |
---|
91 | |
---|
92 | if ( isset( $_POST['use_new_pwd'] ) ) |
---|
93 | { |
---|
94 | $query = 'UPDATE '.USERS_TABLE; |
---|
95 | $query.= " SET password = '".md5( $_POST['password'] )."'"; |
---|
96 | $query.= ' WHERE id = '.$user['id']; |
---|
97 | $query.= ';'; |
---|
98 | pwg_query( $query ); |
---|
99 | } |
---|
100 | if ( isset( $_POST['create_cookie'] ) ) |
---|
101 | { |
---|
102 | setcookie( 'id',$page['session_id'],$_POST['cookie_expiration'], |
---|
103 | cookie_path() ); |
---|
104 | // update the expiration date of the session |
---|
105 | $query = 'UPDATE '.SESSIONS_TABLE; |
---|
106 | $query.= ' SET expiration = '.$_POST['cookie_expiration']; |
---|
107 | $query.= " WHERE id = '".$page['session_id']."'"; |
---|
108 | $query.= ';'; |
---|
109 | pwg_query( $query ); |
---|
110 | } |
---|
111 | // redirection |
---|
112 | $url = 'category.php'; |
---|
113 | if ( !isset($_POST['create_cookie']) ) $url = add_session_id( $url,true ); |
---|
114 | redirect( $url ); |
---|
115 | } |
---|
116 | } |
---|
117 | //----------------------------------------------------- template initialization |
---|
118 | $expand = ($user['expand']=='true')?'EXPAND_TREE_YES':'EXPAND_TREE_NO'; |
---|
119 | $nb_comments = ($user['show_nb_comments']=='true')?'NB_COMMENTS_YES':'NB_COMMENTS_NO'; |
---|
120 | |
---|
121 | $title = $lang['customize_page_title']; |
---|
122 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
123 | |
---|
124 | $template->set_filenames(array('profile'=>'profile.tpl')); |
---|
125 | |
---|
126 | $template->assign_vars(array( |
---|
127 | 'LANG_SELECT'=>language_select($user['language'], 'language'), |
---|
128 | 'NB_IMAGE_LINE'=>$user['nb_image_line'], |
---|
129 | 'NB_ROW_PAGE'=>$user['nb_line_page'], |
---|
130 | 'STYLE_SELECT'=>style_select($user['template'], 'template'), |
---|
131 | 'RECENT_PERIOD'=>$user['recent_period'], |
---|
132 | |
---|
133 | $expand=>'checked="checked"', |
---|
134 | $nb_comments=>'checked="checked"', |
---|
135 | |
---|
136 | 'L_TITLE' => $lang['customize_title'], |
---|
137 | 'L_PASSWORD' => $lang['password'], |
---|
138 | 'L_NEW' => $lang['new'], |
---|
139 | 'L_CONFIRM' => $lang['reg_confirm'], |
---|
140 | 'L_COOKIE' => $lang['create_cookie'], |
---|
141 | 'L_LANG_SELECT'=>$lang['language'], |
---|
142 | 'L_NB_IMAGE_LINE'=>$lang['nb_image_per_row'], |
---|
143 | 'L_NB_ROW_PAGE'=>$lang['nb_row_per_page'], |
---|
144 | 'L_STYLE_SELECT'=>$lang['theme'], |
---|
145 | 'L_RECENT_PERIOD'=>$lang['recent_period'], |
---|
146 | 'L_EXPAND_TREE'=>$lang['auto_expand'], |
---|
147 | 'L_NB_COMMENTS'=>$lang['show_nb_comments'], |
---|
148 | 'L_YES'=>$lang['yes'], |
---|
149 | 'L_NO'=>$lang['no'], |
---|
150 | 'L_SUBMIT'=>$lang['submit'], |
---|
151 | |
---|
152 | 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'profile.php'), |
---|
153 | |
---|
154 | 'U_RETURN' => add_session_id(PHPWG_ROOT_PATH.'category.php?'.$_SERVER['QUERY_STRING']) |
---|
155 | )); |
---|
156 | |
---|
157 | //-------------------------------------------------------------- errors display |
---|
158 | if ( sizeof( $errors ) != 0 ) |
---|
159 | { |
---|
160 | $template->assign_block_vars('errors',array()); |
---|
161 | for ( $i = 0; $i < sizeof( $errors ); $i++ ) |
---|
162 | { |
---|
163 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
164 | } |
---|
165 | } |
---|
166 | |
---|
167 | $template->assign_block_vars('text',array( |
---|
168 | 'F_LABEL'=>$lang['maxwidth'], |
---|
169 | 'F_NAME'=>'maxwidth', |
---|
170 | 'F_VALUE'=>$user['maxwidth'] |
---|
171 | )); |
---|
172 | |
---|
173 | $template->assign_block_vars('text',array( |
---|
174 | 'F_LABEL'=>$lang['maxheight'], |
---|
175 | 'F_NAME'=>'maxheight', |
---|
176 | 'F_VALUE'=>$user['maxheight'] |
---|
177 | )); |
---|
178 | |
---|
179 | $template->assign_block_vars('text',array( |
---|
180 | 'F_LABEL'=>$lang['mail_address'], |
---|
181 | 'F_NAME'=>'mail_address', |
---|
182 | 'F_VALUE'=>$user['mail_address'] |
---|
183 | )); |
---|
184 | |
---|
185 | //----------------------------------------------------------- html code display |
---|
186 | $template->pparse('profile'); |
---|
187 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
188 | ?> |
---|