2003-05-09 14:42:42 +02:00
|
|
|
<?php
|
2004-02-07 12:50:26 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2004-11-06 22:12:59 +01:00
|
|
|
// | PhpWebGallery - a PHP based picture gallery |
|
|
|
|
// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
|
2007-01-13 04:13:40 +01:00
|
|
|
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
|
2004-02-07 12:50:26 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2007-01-13 04:13:40 +01:00
|
|
|
// | file : $Id$
|
2004-02-07 12:50:26 +01:00
|
|
|
// | last update : $Date$
|
|
|
|
// | last modifier : $Author$
|
|
|
|
// | revision : $Revision$
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | This program is free software; you can redistribute it and/or modify |
|
|
|
|
// | it under the terms of the GNU General Public License as published by |
|
2004-02-07 20:36:44 +01:00
|
|
|
// | the Free Software Foundation |
|
|
|
|
// | |
|
|
|
|
// | This program is distributed in the hope that it will be useful, but |
|
|
|
|
// | WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
|
|
|
// | General Public License for more details. |
|
|
|
|
// | |
|
|
|
|
// | You should have received a copy of the GNU General Public License |
|
|
|
|
// | along with this program; if not, write to the Free Software |
|
|
|
|
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
|
|
|
|
// | USA. |
|
2004-02-07 12:50:26 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
2003-05-09 14:42:42 +02:00
|
|
|
|
|
|
|
// customize appearance of the site for a user
|
2004-12-03 17:30:12 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | initialization |
|
|
|
|
// +-----------------------------------------------------------------------+
|
2004-12-28 20:12:57 +01:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
if (!defined('PHPWG_ROOT_PATH'))
|
|
|
|
{//direct script access
|
|
|
|
define('PHPWG_ROOT_PATH','./');
|
|
|
|
include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
|
2006-02-12 22:52:16 +01:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | Check Access and exit when user status is not ok |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
check_status(ACCESS_CLASSIC);
|
|
|
|
|
|
|
|
$userdata = $user;
|
|
|
|
|
2008-03-01 16:29:29 +01:00
|
|
|
trigger_action('loc_begin_profile');
|
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
save_profile_from_post($userdata, $errors);
|
2006-03-09 23:46:28 +01:00
|
|
|
|
2007-05-15 22:23:09 +02:00
|
|
|
$title= l10n('customize_page_title');
|
2007-01-25 03:18:56 +01:00
|
|
|
$page['body_id'] = 'theProfilePage';
|
|
|
|
include(PHPWG_ROOT_PATH.'include/page_header.php');
|
|
|
|
|
|
|
|
load_profile_in_template(
|
|
|
|
get_root_url().'profile.php', // action
|
|
|
|
make_index_url(), // for redirect
|
|
|
|
$userdata );
|
|
|
|
|
2008-03-03 18:49:52 +01:00
|
|
|
$template->assign('U_HOME', make_index_url());
|
2007-01-25 03:18:56 +01:00
|
|
|
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
// | errors display |
|
|
|
|
// +-----------------------------------------------------------------------+
|
|
|
|
if (count($errors) != 0)
|
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('errors', $errors);
|
2007-01-25 03:18:56 +01:00
|
|
|
}
|
|
|
|
$template->set_filename('profile', 'profile.tpl');
|
2008-03-01 16:29:29 +01:00
|
|
|
trigger_action('loc_end_profile');
|
2007-01-25 03:18:56 +01:00
|
|
|
$template->parse('profile');
|
|
|
|
include(PHPWG_ROOT_PATH.'include/page_tail.php');
|
|
|
|
}
|
2005-08-08 22:52:19 +02:00
|
|
|
|
|
|
|
//------------------------------------------------------ update & customization
|
2007-01-25 03:18:56 +01:00
|
|
|
function save_profile_from_post(&$userdata, &$errors)
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
global $conf;
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if (!isset($_POST['validate']))
|
|
|
|
{
|
2007-03-28 21:57:00 +02:00
|
|
|
return false;
|
2007-01-25 03:18:56 +01:00
|
|
|
}
|
|
|
|
|
2003-07-21 21:47:14 +02:00
|
|
|
$int_pattern = '/^\d+$/';
|
2006-02-15 21:44:33 +01:00
|
|
|
if (empty($_POST['nb_image_line'])
|
|
|
|
or (!preg_match($int_pattern, $_POST['nb_image_line'])))
|
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('nb_image_line_error');
|
2006-02-15 21:44:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($_POST['nb_line_page'])
|
|
|
|
or (!preg_match($int_pattern, $_POST['nb_line_page'])))
|
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('nb_line_page_error');
|
2006-02-15 21:44:33 +01:00
|
|
|
}
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2004-12-28 20:12:57 +01:00
|
|
|
if ($_POST['maxwidth'] != ''
|
|
|
|
and (!preg_match($int_pattern, $_POST['maxwidth'])
|
|
|
|
or $_POST['maxwidth'] < 50))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('maxwidth_error');
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-12-28 20:12:57 +01:00
|
|
|
if ($_POST['maxheight']
|
|
|
|
and (!preg_match($int_pattern, $_POST['maxheight'])
|
|
|
|
or $_POST['maxheight'] < 50))
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('maxheight_error');
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2003-07-21 21:47:14 +02:00
|
|
|
// periods must be integer values, they represents number of days
|
2004-07-09 23:00:00 +02:00
|
|
|
if (!preg_match($int_pattern, $_POST['recent_period'])
|
|
|
|
or $_POST['recent_period'] <= 0)
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('periods_error') ;
|
2004-12-28 20:12:57 +01:00
|
|
|
}
|
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
if (isset($_POST['mail_address']))
|
2004-12-28 20:12:57 +01:00
|
|
|
{
|
2007-10-06 08:41:18 +02:00
|
|
|
// if $_POST and $userdata have are same email
|
|
|
|
// validate_mail_address allows, however, to check email
|
|
|
|
$mail_error = validate_mail_address($userdata['id'], $_POST['mail_address']);
|
2007-03-28 21:57:00 +02:00
|
|
|
if (!empty($mail_error))
|
|
|
|
{
|
|
|
|
$errors[] = $mail_error;
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2005-08-08 22:52:19 +02:00
|
|
|
if (!empty($_POST['use_new_pwd']))
|
2004-12-02 16:42:57 +01:00
|
|
|
{
|
2005-08-08 22:52:19 +02:00
|
|
|
// password must be the same as its confirmation
|
|
|
|
if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
|
2004-12-02 16:42:57 +01:00
|
|
|
{
|
2007-01-25 03:18:56 +01:00
|
|
|
$errors[] = l10n('New password confirmation does not correspond');
|
2004-12-02 16:42:57 +01:00
|
|
|
}
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
if ( !defined('IN_ADMIN') )
|
|
|
|
{// changing password requires old password
|
|
|
|
$query = '
|
|
|
|
SELECT '.$conf['user_fields']['password'].' AS password
|
|
|
|
FROM '.USERS_TABLE.'
|
|
|
|
WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
|
|
|
|
;';
|
|
|
|
list($current_password) = mysql_fetch_row(pwg_query($query));
|
|
|
|
|
|
|
|
if ($conf['pass_convert']($_POST['password']) != $current_password)
|
|
|
|
{
|
|
|
|
$errors[] = l10n('Current password is wrong');
|
|
|
|
}
|
2004-12-28 20:12:57 +01:00
|
|
|
}
|
2004-12-03 17:30:12 +01:00
|
|
|
}
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2004-12-28 20:12:57 +01:00
|
|
|
if (count($errors) == 0)
|
2003-05-09 14:42:42 +02:00
|
|
|
{
|
2005-08-08 22:52:19 +02:00
|
|
|
// mass_updates function
|
|
|
|
include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
if (isset($_POST['mail_address']))
|
|
|
|
{
|
|
|
|
// update common user informations
|
|
|
|
$fields = array($conf['user_fields']['email']);
|
2005-08-08 22:52:19 +02:00
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
$data = array();
|
|
|
|
$data{$conf['user_fields']['id']} = $_POST['userid'];
|
|
|
|
$data{$conf['user_fields']['email']} = $_POST['mail_address'];
|
2003-05-09 14:42:42 +02:00
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
// password is updated only if filled
|
|
|
|
if (!empty($_POST['use_new_pwd']))
|
|
|
|
{
|
|
|
|
array_push($fields, $conf['user_fields']['password']);
|
|
|
|
// password is encrpyted with function $conf['pass_convert']
|
|
|
|
$data{$conf['user_fields']['password']} =
|
|
|
|
$conf['pass_convert']($_POST['use_new_pwd']);
|
|
|
|
}
|
|
|
|
mass_updates(USERS_TABLE,
|
|
|
|
array('primary' => array($conf['user_fields']['id']),
|
|
|
|
'update' => $fields),
|
|
|
|
array($data));
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2005-08-08 22:52:19 +02:00
|
|
|
// update user "additional" informations (specific to PhpWebGallery)
|
|
|
|
$fields = array(
|
|
|
|
'nb_image_line', 'nb_line_page', 'language', 'maxwidth', 'maxheight',
|
2007-01-28 21:56:10 +01:00
|
|
|
'expand', 'show_nb_comments', 'show_nb_hits', 'recent_period', 'template'
|
2005-08-08 22:52:19 +02:00
|
|
|
);
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2005-08-08 22:52:19 +02:00
|
|
|
$data = array();
|
2006-02-15 21:44:33 +01:00
|
|
|
$data['user_id'] = $_POST['userid'];
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2005-08-08 22:52:19 +02:00
|
|
|
foreach ($fields as $field)
|
2004-12-03 17:30:12 +01:00
|
|
|
{
|
2005-08-08 22:52:19 +02:00
|
|
|
if (isset($_POST[$field]))
|
2005-04-26 11:46:33 +02:00
|
|
|
{
|
2006-02-15 21:44:33 +01:00
|
|
|
$data[$field] = $_POST[$field];
|
2005-04-26 11:46:33 +02:00
|
|
|
}
|
2004-12-03 17:30:12 +01:00
|
|
|
}
|
2005-08-08 22:52:19 +02:00
|
|
|
mass_updates(USER_INFOS_TABLE,
|
|
|
|
array('primary' => array('user_id'), 'update' => $fields),
|
|
|
|
array($data));
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2007-06-30 03:40:19 +02:00
|
|
|
trigger_action( 'loc_user_profile_updated', $_POST['userid'] );
|
|
|
|
|
2007-03-28 21:57:00 +02:00
|
|
|
if (!empty($_POST['redirect']))
|
|
|
|
{
|
|
|
|
redirect($_POST['redirect']);
|
|
|
|
}
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2007-03-28 21:57:00 +02:00
|
|
|
return true;
|
2003-05-09 14:42:42 +02:00
|
|
|
}
|
2004-12-28 20:12:57 +01:00
|
|
|
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
function load_profile_in_template($url_action, $url_redirect, $userdata)
|
|
|
|
{
|
2007-06-06 00:01:15 +02:00
|
|
|
global $template, $conf;
|
2005-08-08 22:52:19 +02:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
$template->set_filename('profile_content', 'profile_content.tpl');
|
2006-11-29 05:18:11 +01:00
|
|
|
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('radio_options',
|
|
|
|
array(
|
|
|
|
'true' => l10n('yes'),
|
|
|
|
'false' => l10n('no')));
|
2005-08-27 02:24:31 +02:00
|
|
|
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign(
|
2005-08-27 02:24:31 +02:00
|
|
|
array(
|
2007-01-25 03:18:56 +01:00
|
|
|
'USERNAME'=>$userdata['username'],
|
|
|
|
'USERID'=>$userdata['id'],
|
2008-02-29 14:10:58 +01:00
|
|
|
'EMAIL'=>get_email_address_as_display_text(@$userdata['email']),
|
2007-01-25 03:18:56 +01:00
|
|
|
'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
|
|
|
|
'NB_ROW_PAGE'=>$userdata['nb_line_page'],
|
|
|
|
'RECENT_PERIOD'=>$userdata['recent_period'],
|
|
|
|
'MAXWIDTH'=>@$userdata['maxwidth'],
|
|
|
|
'MAXHEIGHT'=>@$userdata['maxheight'],
|
2008-03-03 18:07:55 +01:00
|
|
|
'EXPAND' =>$userdata['expand'] ? 'true' : 'false',
|
|
|
|
'NB_COMMENTS'=>$userdata['show_nb_comments'] ? 'true' : 'false',
|
|
|
|
'NB_HITS'=>$userdata['show_nb_hits'] ? 'true' : 'false',
|
2007-01-25 03:18:56 +01:00
|
|
|
'REDIRECT' => $url_redirect,
|
|
|
|
'F_ACTION'=>$url_action,
|
2005-08-27 02:24:31 +02:00
|
|
|
));
|
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
foreach (get_pwg_themes() as $pwg_template)
|
2005-08-27 02:24:31 +02:00
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
if (isset($_POST['submit'])
|
|
|
|
or $userdata['template'].'/'.$userdata['theme'] == $pwg_template)
|
2007-01-25 03:18:56 +01:00
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('template_selection', $pwg_template);
|
2007-01-25 03:18:56 +01:00
|
|
|
}
|
2008-03-03 18:07:55 +01:00
|
|
|
$template_options[$pwg_template] = $pwg_template;
|
2005-08-27 02:24:31 +02:00
|
|
|
}
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('template_options', $template_options);
|
2005-08-27 02:24:31 +02:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
foreach (get_languages() as $language_code => $language_name)
|
2005-02-13 20:53:07 +01:00
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
if (isset($_POST['submit']) or $userdata['language'] == $language_code)
|
2007-01-25 03:18:56 +01:00
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('language_selection', $language_code);
|
2007-01-25 03:18:56 +01:00
|
|
|
}
|
2008-03-03 18:07:55 +01:00
|
|
|
$language_options[$language_code] = $language_name;
|
2005-02-13 20:53:07 +01:00
|
|
|
}
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('language_options', $language_options);
|
2007-03-28 21:57:00 +02:00
|
|
|
|
2007-06-06 00:01:15 +02:00
|
|
|
if (!(in_array($userdata['id'], array($conf['guest_id'], $conf['default_user_id']))))
|
2007-01-25 03:18:56 +01:00
|
|
|
{
|
2008-03-03 18:07:55 +01:00
|
|
|
$template->assign('not_special_user', true);
|
|
|
|
$template->assign('in_admin', defined('IN_ADMIN'));
|
2007-01-25 03:18:56 +01:00
|
|
|
}
|
2007-03-28 21:57:00 +02:00
|
|
|
|
2007-01-25 03:18:56 +01:00
|
|
|
$template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
|
2005-02-13 20:53:07 +01:00
|
|
|
}
|
2004-02-12 00:20:38 +01:00
|
|
|
?>
|