source: trunk/profile.php @ 1855

Last change on this file since 1855 was 1788, checked in by rub, 18 years ago

Issue 0000639: Force selected page on index.php

When page index.php is called without defined section, redirect to a page selected by random on a user list.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.0 KB
Line 
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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $Id: profile.php 1788 2007-02-07 23:08:04Z rub $
9// | last update   : $Date: 2007-02-07 23:08:04 +0000 (Wed, 07 Feb 2007) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1788 $
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// +-----------------------------------------------------------------------+
30// |                           initialization                              |
31// +-----------------------------------------------------------------------+
32
33if (!defined('PHPWG_ROOT_PATH'))
34{//direct script access
35  define('PHPWG_ROOT_PATH','./');
36  include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
37
38  // +-----------------------------------------------------------------------+
39  // | Check Access and exit when user status is not ok                      |
40  // +-----------------------------------------------------------------------+
41  check_status(ACCESS_CLASSIC);
42
43  $userdata = $user;
44
45  save_profile_from_post($userdata, $errors);
46
47  $title= $lang['customize_page_title'];
48  $page['body_id'] = 'theProfilePage';
49  include(PHPWG_ROOT_PATH.'include/page_header.php');
50
51  load_profile_in_template(
52    get_root_url().'profile.php', // action
53    make_index_url(), // for redirect
54    $userdata );
55
56  $template->assign_var('U_HOME', make_index_url() );
57
58  // +-----------------------------------------------------------------------+
59  // |                             errors display                            |
60  // +-----------------------------------------------------------------------+
61  if (count($errors) != 0)
62  {
63    $template->assign_block_vars('errors',array());
64    foreach ($errors as $error)
65    {
66      $template->assign_block_vars('errors.error', array('ERROR'=>$error));
67    }
68  }
69  $template->set_filename('profile', 'profile.tpl');
70  $template->parse('profile');
71  include(PHPWG_ROOT_PATH.'include/page_tail.php');
72}
73
74//------------------------------------------------------ update & customization
75function save_profile_from_post(&$userdata, &$errors)
76{
77  global $conf;
78  $errors = array();
79 
80  if (!isset($_POST['validate']))
81  {
82    return;
83  }
84
85  $int_pattern = '/^\d+$/';
86  if (empty($_POST['nb_image_line'])
87      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
88  {
89    $errors[] = l10n('nb_image_line_error');
90  }
91
92  if (empty($_POST['nb_line_page'])
93      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
94  {
95    $errors[] = l10n('nb_line_page_error');
96  }
97
98  if ($_POST['maxwidth'] != ''
99      and (!preg_match($int_pattern, $_POST['maxwidth'])
100           or $_POST['maxwidth'] < 50))
101  {
102    $errors[] = l10n('maxwidth_error');
103  }
104  if ($_POST['maxheight']
105       and (!preg_match($int_pattern, $_POST['maxheight'])
106             or $_POST['maxheight'] < 50))
107  {
108    $errors[] = l10n('maxheight_error');
109  }
110  // periods must be integer values, they represents number of days
111  if (!preg_match($int_pattern, $_POST['recent_period'])
112      or $_POST['recent_period'] <= 0)
113  {
114    $errors[] = l10n('periods_error') ;
115  }
116
117  $mail_error = validate_mail_address($_POST['mail_address']);
118  if (!empty($mail_error))
119  {
120    $errors[] = $mail_error;
121  }
122
123  if (!empty($_POST['use_new_pwd']))
124  {
125    // password must be the same as its confirmation
126    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
127    {
128      $errors[] = l10n('New password confirmation does not correspond');
129    }
130
131    if ( !defined('IN_ADMIN') )
132    {// changing password requires old password
133      $query = '
134  SELECT '.$conf['user_fields']['password'].' AS password
135    FROM '.USERS_TABLE.'
136    WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
137  ;';
138      list($current_password) = mysql_fetch_row(pwg_query($query));
139 
140      if ($conf['pass_convert']($_POST['password']) != $current_password)
141      {
142        $errors[] = l10n('Current password is wrong');
143      }
144    }
145  }
146
147  if (count($errors) == 0)
148  {
149    // mass_updates function
150    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
151
152    // update common user informations
153    $fields = array($conf['user_fields']['email']);
154
155    $data = array();
156    $data{$conf['user_fields']['id']} = $_POST['userid'];
157    $data{$conf['user_fields']['email']} = $_POST['mail_address'];
158
159    // password is updated only if filled
160    if (!empty($_POST['use_new_pwd']))
161    {
162      array_push($fields, $conf['user_fields']['password']);
163      // password is encrpyted with function $conf['pass_convert']
164      $data{$conf['user_fields']['password']} =
165        $conf['pass_convert']($_POST['use_new_pwd']);
166    }
167    mass_updates(USERS_TABLE,
168                 array('primary' => array($conf['user_fields']['id']),
169                       'update' => $fields),
170                 array($data));
171
172    // update user "additional" informations (specific to PhpWebGallery)
173    $fields = array(
174      'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
175      'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template'
176      );
177
178    $data = array();
179    $data['user_id'] = $_POST['userid'];
180
181    foreach ($fields as $field)
182    {
183      if (isset($_POST[$field]))
184      {
185        $data[$field] = $_POST[$field];
186      }
187    }
188    mass_updates(USER_INFOS_TABLE,
189                 array('primary' => array('user_id'), 'update' => $fields),
190                 array($data));
191
192    // redirection
193    redirect($_POST['redirect']);
194  }
195}
196
197
198function load_profile_in_template($url_action, $url_redirect, $userdata)
199{
200  global $template;
201
202  $template->set_filename('profile_content', 'profile_content.tpl');
203
204  $expand = ($userdata['expand'] == 'true') ? 
205            'EXPAND_TREE_YES':'EXPAND_TREE_NO';
206
207  $nb_comments =
208    ($userdata['show_nb_comments'] == 'true') ? 
209               'NB_COMMENTS_YES':'NB_COMMENTS_NO';
210
211  $nb_hits =
212    ($userdata['show_nb_hits'] == 'true') ? 
213               'NB_HITS_YES':'NB_HITS_NO';
214
215  $template->assign_vars(
216    array(
217      'USERNAME'=>$userdata['username'],
218      'USERID'=>$userdata['id'],
219      'EMAIL'=>@$userdata['email'],
220      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
221      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
222      'RECENT_PERIOD'=>$userdata['recent_period'],
223      'MAXWIDTH'=>@$userdata['maxwidth'],
224      'MAXHEIGHT'=>@$userdata['maxheight'],
225 
226      $expand=>'checked="checked"',
227      $nb_comments=>'checked="checked"',
228      $nb_hits=>'checked="checked"',
229 
230      'REDIRECT' => $url_redirect,
231 
232      'F_ACTION'=>$url_action,
233      ));
234
235  $blockname = 'template_option';
236
237  foreach (get_pwg_themes() as $pwg_template)
238  {
239    if (isset($_POST['submit']))
240    {
241      $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
242    }
243    else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
244    {
245      $selected = 'selected="selected"';
246    }
247    else
248    {
249      $selected = '';
250    }
251 
252    $template->assign_block_vars(
253      $blockname,
254      array(
255        'VALUE'=> $pwg_template,
256        'CONTENT' => $pwg_template,
257        'SELECTED' => $selected
258        ));
259  }
260
261  $blockname = 'language_option';
262
263  foreach (get_languages() as $language_code => $language_name)
264  {
265    if (isset($_POST['submit']))
266    {
267      $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
268    }
269    else if ($userdata['language'] == $language_code)
270    {
271      $selected = 'selected="selected"';
272    }
273    else
274    {
275      $selected = '';
276    }
277 
278    $template->assign_block_vars(
279      $blockname,
280      array(
281        'VALUE'=> $language_code,
282        'CONTENT' => $language_name,
283        'SELECTED' => $selected
284        ));
285  }
286  if ( !defined('IN_ADMIN') )
287  {
288    $template->assign_block_vars( 'not_admin', array() );
289  }
290  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
291}
292?>
Note: See TracBrowser for help on using the repository browser.