1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | // customize appearance of the site for a user |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | // | initialization | |
---|
27 | // +-----------------------------------------------------------------------+ |
---|
28 | |
---|
29 | if (!defined('PHPWG_ROOT_PATH')) |
---|
30 | {//direct script access |
---|
31 | define('PHPWG_ROOT_PATH','./'); |
---|
32 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
33 | |
---|
34 | // +-----------------------------------------------------------------------+ |
---|
35 | // | Check Access and exit when user status is not ok | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | check_status(ACCESS_CLASSIC); |
---|
38 | |
---|
39 | $userdata = $user; |
---|
40 | |
---|
41 | trigger_action('loc_begin_profile'); |
---|
42 | |
---|
43 | save_profile_from_post($userdata, $errors); |
---|
44 | |
---|
45 | $title= l10n('customize_page_title'); |
---|
46 | $page['body_id'] = 'theProfilePage'; |
---|
47 | include(PHPWG_ROOT_PATH.'include/page_header.php'); |
---|
48 | |
---|
49 | load_profile_in_template( |
---|
50 | get_root_url().'profile.php', // action |
---|
51 | make_index_url(), // for redirect |
---|
52 | $userdata ); |
---|
53 | |
---|
54 | // +-----------------------------------------------------------------------+ |
---|
55 | // | errors display | |
---|
56 | // +-----------------------------------------------------------------------+ |
---|
57 | if (count($errors) != 0) |
---|
58 | { |
---|
59 | $template->assign('errors', $errors); |
---|
60 | } |
---|
61 | $template->set_filename('profile', 'profile.tpl'); |
---|
62 | trigger_action('loc_end_profile'); |
---|
63 | $template->parse('profile'); |
---|
64 | include(PHPWG_ROOT_PATH.'include/page_tail.php'); |
---|
65 | } |
---|
66 | |
---|
67 | //------------------------------------------------------ update & customization |
---|
68 | function save_profile_from_post($userdata, &$errors) |
---|
69 | { |
---|
70 | global $conf; |
---|
71 | $errors = array(); |
---|
72 | |
---|
73 | if (!isset($_POST['validate'])) |
---|
74 | { |
---|
75 | return false; |
---|
76 | } |
---|
77 | |
---|
78 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
79 | if ($special_user) |
---|
80 | { |
---|
81 | unset($_POST['mail_address'], |
---|
82 | $_POST['password'], |
---|
83 | $_POST['use_new_pwd'], |
---|
84 | $_POST['passwordConf'] |
---|
85 | ); |
---|
86 | } |
---|
87 | |
---|
88 | $int_pattern = '/^\d+$/'; |
---|
89 | if (empty($_POST['nb_image_line']) |
---|
90 | or (!preg_match($int_pattern, $_POST['nb_image_line']))) |
---|
91 | { |
---|
92 | $errors[] = l10n('nb_image_line_error'); |
---|
93 | } |
---|
94 | |
---|
95 | if (empty($_POST['nb_line_page']) |
---|
96 | or (!preg_match($int_pattern, $_POST['nb_line_page']))) |
---|
97 | { |
---|
98 | $errors[] = l10n('nb_line_page_error'); |
---|
99 | } |
---|
100 | |
---|
101 | if ($_POST['maxwidth'] != '' |
---|
102 | and (!preg_match($int_pattern, $_POST['maxwidth']) |
---|
103 | or $_POST['maxwidth'] < 50)) |
---|
104 | { |
---|
105 | $errors[] = l10n('maxwidth_error'); |
---|
106 | } |
---|
107 | if ($_POST['maxheight'] |
---|
108 | and (!preg_match($int_pattern, $_POST['maxheight']) |
---|
109 | or $_POST['maxheight'] < 50)) |
---|
110 | { |
---|
111 | $errors[] = l10n('maxheight_error'); |
---|
112 | } |
---|
113 | // periods must be integer values, they represents number of days |
---|
114 | if (!preg_match($int_pattern, $_POST['recent_period']) |
---|
115 | or $_POST['recent_period'] <= 0) |
---|
116 | { |
---|
117 | $errors[] = l10n('periods_error') ; |
---|
118 | } |
---|
119 | |
---|
120 | if (isset($_POST['mail_address'])) |
---|
121 | { |
---|
122 | // if $_POST and $userdata have are same email |
---|
123 | // validate_mail_address allows, however, to check email |
---|
124 | $mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']); |
---|
125 | if (!empty($mail_error)) |
---|
126 | { |
---|
127 | $errors[] = $mail_error; |
---|
128 | } |
---|
129 | } |
---|
130 | |
---|
131 | if (!empty($_POST['use_new_pwd'])) |
---|
132 | { |
---|
133 | // password must be the same as its confirmation |
---|
134 | if ($_POST['use_new_pwd'] != $_POST['passwordConf']) |
---|
135 | { |
---|
136 | $errors[] = l10n('New password confirmation does not correspond'); |
---|
137 | } |
---|
138 | |
---|
139 | if ( !defined('IN_ADMIN') ) |
---|
140 | {// changing password requires old password |
---|
141 | $query = ' |
---|
142 | SELECT '.$conf['user_fields']['password'].' AS password |
---|
143 | FROM '.USERS_TABLE.' |
---|
144 | WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\' |
---|
145 | ;'; |
---|
146 | list($current_password) = mysql_fetch_row(pwg_query($query)); |
---|
147 | |
---|
148 | if ($conf['pass_convert']($_POST['password']) != $current_password) |
---|
149 | { |
---|
150 | $errors[] = l10n('Current password is wrong'); |
---|
151 | } |
---|
152 | } |
---|
153 | } |
---|
154 | |
---|
155 | if (count($errors) == 0) |
---|
156 | { |
---|
157 | // mass_updates function |
---|
158 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
159 | |
---|
160 | if (isset($_POST['mail_address'])) |
---|
161 | { |
---|
162 | // update common user informations |
---|
163 | $fields = array($conf['user_fields']['email']); |
---|
164 | |
---|
165 | $data = array(); |
---|
166 | $data{$conf['user_fields']['id']} = $userdata['id']; |
---|
167 | $data{$conf['user_fields']['email']} = $_POST['mail_address']; |
---|
168 | |
---|
169 | // password is updated only if filled |
---|
170 | if (!empty($_POST['use_new_pwd'])) |
---|
171 | { |
---|
172 | array_push($fields, $conf['user_fields']['password']); |
---|
173 | // password is encrpyted with function $conf['pass_convert'] |
---|
174 | $data{$conf['user_fields']['password']} = |
---|
175 | $conf['pass_convert']($_POST['use_new_pwd']); |
---|
176 | } |
---|
177 | mass_updates(USERS_TABLE, |
---|
178 | array('primary' => array($conf['user_fields']['id']), |
---|
179 | 'update' => $fields), |
---|
180 | array($data)); |
---|
181 | } |
---|
182 | |
---|
183 | // update user "additional" informations (specific to PhpWebGallery) |
---|
184 | $fields = array( |
---|
185 | 'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight', |
---|
186 | 'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template' |
---|
187 | ); |
---|
188 | |
---|
189 | $data = array(); |
---|
190 | $data['user_id'] = $userdata['id']; |
---|
191 | |
---|
192 | foreach ($fields as $field) |
---|
193 | { |
---|
194 | if (isset($_POST[$field])) |
---|
195 | { |
---|
196 | $data[$field] = $_POST[$field]; |
---|
197 | } |
---|
198 | } |
---|
199 | mass_updates(USER_INFOS_TABLE, |
---|
200 | array('primary' => array('user_id'), 'update' => $fields), |
---|
201 | array($data)); |
---|
202 | |
---|
203 | trigger_action( 'save_profile_from_post', $userdata['id'] ); |
---|
204 | |
---|
205 | if (!empty($_POST['redirect'])) |
---|
206 | { |
---|
207 | redirect($_POST['redirect']); |
---|
208 | } |
---|
209 | } |
---|
210 | return true; |
---|
211 | } |
---|
212 | |
---|
213 | |
---|
214 | function load_profile_in_template($url_action, $url_redirect, $userdata) |
---|
215 | { |
---|
216 | global $template, $conf; |
---|
217 | |
---|
218 | $template->set_filename('profile_content', 'profile_content.tpl'); |
---|
219 | |
---|
220 | $template->assign('radio_options', |
---|
221 | array( |
---|
222 | 'true' => l10n('Yes'), |
---|
223 | 'false' => l10n('No'))); |
---|
224 | |
---|
225 | $template->assign( |
---|
226 | array( |
---|
227 | 'USERNAME'=>$userdata['username'], |
---|
228 | 'EMAIL'=>get_email_address_as_display_text(@$userdata['email']), |
---|
229 | 'NB_IMAGE_LINE'=>$userdata['nb_image_line'], |
---|
230 | 'NB_ROW_PAGE'=>$userdata['nb_line_page'], |
---|
231 | 'RECENT_PERIOD'=>$userdata['recent_period'], |
---|
232 | 'MAXWIDTH'=>@$userdata['maxwidth'], |
---|
233 | 'MAXHEIGHT'=>@$userdata['maxheight'], |
---|
234 | 'EXPAND' =>$userdata['expand'] ? 'true' : 'false', |
---|
235 | 'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false', |
---|
236 | 'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false', |
---|
237 | 'REDIRECT' => $url_redirect, |
---|
238 | 'F_ACTION'=>$url_action, |
---|
239 | )); |
---|
240 | |
---|
241 | foreach (get_pwg_themes() as $pwg_template) |
---|
242 | { |
---|
243 | if (isset($_POST['submit']) |
---|
244 | or $userdata['template'].'/'.$userdata['theme'] == $pwg_template) |
---|
245 | { |
---|
246 | $template->assign('template_selection', $pwg_template); |
---|
247 | } |
---|
248 | $template_options[$pwg_template] = $pwg_template; |
---|
249 | } |
---|
250 | $template->assign('template_options', $template_options); |
---|
251 | |
---|
252 | foreach (get_languages() as $language_code => $language_name) |
---|
253 | { |
---|
254 | if (isset($_POST['submit']) or $userdata['language'] == $language_code) |
---|
255 | { |
---|
256 | $template->assign('language_selection', $language_code); |
---|
257 | } |
---|
258 | $language_options[$language_code] = $language_name; |
---|
259 | } |
---|
260 | $template->assign('language_options', $language_options); |
---|
261 | |
---|
262 | $special_user = in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id'])); |
---|
263 | $template->assign('SPECIAL_USER', $special_user); |
---|
264 | $template->assign('IN_ADMIN', defined('IN_ADMIN')); |
---|
265 | |
---|
266 | // allow plugins to add their own form data to content |
---|
267 | trigger_action( 'load_profile_in_template', $userdata ); |
---|
268 | |
---|
269 | $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content'); |
---|
270 | } |
---|
271 | ?> |
---|