Changeset 1753 for trunk/profile.php


Ignore:
Timestamp:
Jan 25, 2007, 3:18:56 AM (17 years ago)
Author:
rvelices
Message:
  • user profiles available from admin page
  • user creation from admin page with email (bug 514)
  • some language cleanup
  • small template enhancements
  • php syntax corrections (my mistake)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/profile.php

    r1719 r1753  
    3131// +-----------------------------------------------------------------------+
    3232
    33 define('PHPWG_ROOT_PATH','./');
    34 include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
    35 
    36 // +-----------------------------------------------------------------------+
    37 // | Check Access and exit when user status is not ok                      |
    38 // +-----------------------------------------------------------------------+
    39 check_status(ACCESS_CLASSIC);
    40 
    41 $userdata = $user;
     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_RETURN', 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}
    4273
    4374//------------------------------------------------------ update & customization
    44 $errors = array();
    45 if (isset($_POST['validate']))
     75function save_profile_from_post(&$userdata, &$errors)
    4676{
     77  global $conf;
     78  $errors = array();
     79 
     80  if (!isset($_POST['validate']))
     81  {
     82    return;
     83  }
     84
    4785  $int_pattern = '/^\d+$/';
    4886  if (empty($_POST['nb_image_line'])
    4987      or (!preg_match($int_pattern, $_POST['nb_image_line'])))
    5088  {
    51     array_push($errors, $lang['nb_image_line_error']);
     89    $errors[] = l10n('nb_image_line_error');
    5290  }
    5391
     
    5593      or (!preg_match($int_pattern, $_POST['nb_line_page'])))
    5694  {
    57     array_push($errors, $lang['nb_line_page_error']);
     95    $errors[] = l10n('nb_line_page_error');
    5896  }
    5997
     
    62100           or $_POST['maxwidth'] < 50))
    63101  {
    64     array_push($errors, $lang['maxwidth_error']);
     102    $errors[] = l10n('maxwidth_error');
    65103  }
    66104  if ($_POST['maxheight']
     
    68106             or $_POST['maxheight'] < 50))
    69107  {
    70     array_push($errors, $lang['maxheight_error']);
     108    $errors[] = l10n('maxheight_error');
    71109  }
    72110  // periods must be integer values, they represents number of days
     
    74112      or $_POST['recent_period'] <= 0)
    75113  {
    76     array_push($errors, $lang['periods_error']);
     114    $errors[] = l10n('periods_error') ;
    77115  }
    78116
     
    80118  if (!empty($mail_error))
    81119  {
    82     array_push($errors, $mail_error);
     120    $errors[] = $mail_error;
    83121  }
    84122
     
    88126    if ($_POST['use_new_pwd'] != $_POST['passwordConf'])
    89127    {
    90       array_push($errors,
    91                  l10n('New password confirmation does not correspond'));
    92     }
    93 
    94     // changing password requires old password
    95     $query = '
    96 SELECT '.$conf['user_fields']['password'].' AS password
    97   FROM '.USERS_TABLE.'
    98   WHERE '.$conf['user_fields']['id'].' = \''.$userdata['id'].'\'
    99 ;';
    100     list($current_password) = mysql_fetch_row(pwg_query($query));
    101 
    102     if ($conf['pass_convert']($_POST['password']) != $current_password)
    103     {
    104       array_push($errors, l10n('Current password is wrong'));
     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      }
    105144    }
    106145  }
     
    152191
    153192    // redirection
    154     redirect(make_index_url());
     193    redirect($_POST['redirect']);
    155194  }
    156195}
    157 // +-----------------------------------------------------------------------+
    158 // |                       page header and options                         |
    159 // +-----------------------------------------------------------------------+
    160 
    161 $title= $lang['customize_page_title'];
    162 $page['body_id'] = 'theProfilePage';
    163 include(PHPWG_ROOT_PATH.'include/page_header.php');
    164 
    165 $url_action = PHPWG_ROOT_PATH.'profile.php';
    166 
    167 //----------------------------------------------------- template initialization
    168 $template->set_filenames(array('profile_body'=>'profile.tpl'));
    169 
    170 $expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
    171 
    172 $nb_comments =
    173 ($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
    174 
    175 $template->assign_vars(
    176   array(
    177     'USERNAME'=>$userdata['username'],
    178     'USERID'=>$userdata['id'],
    179     'EMAIL'=>@$userdata['email'],
    180     'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
    181     'NB_ROW_PAGE'=>$userdata['nb_line_page'],
    182     'RECENT_PERIOD'=>$userdata['recent_period'],
    183     'MAXWIDTH'=>@$userdata['maxwidth'],
    184     'MAXHEIGHT'=>@$userdata['maxheight'],
    185 
    186     $expand=>'checked="checked"',
    187     $nb_comments=>'checked="checked"',
    188 
    189     'U_RETURN' => make_index_url(),
    190 
    191     'F_ACTION'=>$url_action,
    192     ));
    193 
    194 $blockname = 'template_option';
    195 
    196 foreach (get_pwg_themes() as $pwg_template)
     196
     197
     198function load_profile_in_template($url_action, $url_redirect, $userdata)
    197199{
    198   if (isset($_POST['submit']))
    199   {
    200     $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
    201   }
    202   else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
    203   {
    204     $selected = 'selected="selected"';
    205   }
    206   else
    207   {
    208     $selected = '';
    209   }
    210 
    211   $template->assign_block_vars(
    212     $blockname,
     200  global $template;
     201
     202  $template->set_filename('profile_content', 'profile_content.tpl');
     203
     204  $expand = ($userdata['expand'] == 'true') ? 'EXPAND_TREE_YES':'EXPAND_TREE_NO';
     205
     206  $nb_comments =
     207    ($userdata['show_nb_comments'] == 'true') ? 'NB_COMMENTS_YES':'NB_COMMENTS_NO';
     208
     209  $template->assign_vars(
    213210    array(
    214       'VALUE'=> $pwg_template,
    215       'CONTENT' => $pwg_template,
    216       'SELECTED' => $selected
     211      'USERNAME'=>$userdata['username'],
     212      'USERID'=>$userdata['id'],
     213      'EMAIL'=>@$userdata['email'],
     214      'NB_IMAGE_LINE'=>$userdata['nb_image_line'],
     215      'NB_ROW_PAGE'=>$userdata['nb_line_page'],
     216      'RECENT_PERIOD'=>$userdata['recent_period'],
     217      'MAXWIDTH'=>@$userdata['maxwidth'],
     218      'MAXHEIGHT'=>@$userdata['maxheight'],
     219 
     220      $expand=>'checked="checked"',
     221      $nb_comments=>'checked="checked"',
     222 
     223      'REDIRECT' => $url_redirect,
     224 
     225      'F_ACTION'=>$url_action,
    217226      ));
     227
     228  $blockname = 'template_option';
     229
     230  foreach (get_pwg_themes() as $pwg_template)
     231  {
     232    if (isset($_POST['submit']))
     233    {
     234      $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
     235    }
     236    else if ($userdata['template'].'/'.$userdata['theme'] == $pwg_template)
     237    {
     238      $selected = 'selected="selected"';
     239    }
     240    else
     241    {
     242      $selected = '';
     243    }
     244 
     245    $template->assign_block_vars(
     246      $blockname,
     247      array(
     248        'VALUE'=> $pwg_template,
     249        'CONTENT' => $pwg_template,
     250        'SELECTED' => $selected
     251        ));
     252  }
     253
     254  $blockname = 'language_option';
     255
     256  foreach (get_languages() as $language_code => $language_name)
     257  {
     258    if (isset($_POST['submit']))
     259    {
     260      $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
     261    }
     262    else if ($userdata['language'] == $language_code)
     263    {
     264      $selected = 'selected="selected"';
     265    }
     266    else
     267    {
     268      $selected = '';
     269    }
     270 
     271    $template->assign_block_vars(
     272      $blockname,
     273      array(
     274        'VALUE'=> $language_code,
     275        'CONTENT' => $language_name,
     276        'SELECTED' => $selected
     277        ));
     278  }
     279  if ( !defined('IN_ADMIN') )
     280  {
     281    $template->assign_block_vars( 'not_admin', array() );
     282  }
     283  $template->assign_var_from_handle('PROFILE_CONTENT', 'profile_content');
    218284}
    219 
    220 $blockname = 'language_option';
    221 
    222 foreach (get_languages() as $language_code => $language_name)
    223 {
    224   if (isset($_POST['submit']))
    225   {
    226     $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
    227   }
    228   else if ($userdata['language'] == $language_code)
    229   {
    230     $selected = 'selected="selected"';
    231   }
    232   else
    233   {
    234     $selected = '';
    235   }
    236 
    237   $template->assign_block_vars(
    238     $blockname,
    239     array(
    240       'VALUE'=> $language_code,
    241       'CONTENT' => $language_name,
    242       'SELECTED' => $selected
    243       ));
    244 }
    245 
    246 // +-----------------------------------------------------------------------+
    247 // |                             errors display                            |
    248 // +-----------------------------------------------------------------------+
    249 if (count($errors) != 0)
    250 {
    251   $template->assign_block_vars('errors',array());
    252   foreach ($errors as $error)
    253   {
    254     $template->assign_block_vars('errors.error', array('ERROR'=>$error));
    255   }
    256 }
    257 // +-----------------------------------------------------------------------+
    258 // |                           html code display                           |
    259 // +-----------------------------------------------------------------------+
    260 $template->assign_block_vars('profile',array());
    261 $template->parse('profile_body');
    262 include(PHPWG_ROOT_PATH.'include/page_tail.php');
    263285?>
Note: See TracChangeset for help on using the changeset viewer.