Changeset 4004


Ignore:
Timestamp:
Oct 9, 2009, 10:52:20 AM (15 years ago)
Author:
patdenice
Message:

merge r4001-4003 from trunk to branch 2.0
Issue 1079: re-refactoring of code ;-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2.0/profile.php

    r3996 r4004  
    4444  if (isset($_POST['reset_to_default']))
    4545  {
    46         global $conf;
     46    // mass_updates function
     47    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     48
     49    $fields = array(
     50      'nb_image_line', 'nb_line_page', 'maxwidth', 'maxheight', 'expand',
     51      'show_nb_comments', 'show_nb_hits', 'recent_period', 'show_nb_hits'
     52      );
     53
    4754    // Get the Guest custom settings
    48                 $query = 'SELECT * FROM '.USER_INFOS_TABLE.
    49             ' WHERE user_id = '.$conf['default_user_id'].';';
    50 
     55    $query = '
     56SELECT '.implode(',', $fields).'
     57  FROM '.USER_INFOS_TABLE.'
     58  WHERE user_id = '.$conf['default_user_id'].'
     59;';
    5160    $result = pwg_query($query);
    52    
    53     $cache['default_user'] = mysql_fetch_assoc($result);
    54    
    55                 $default_user = array();
    56    
    57                 foreach ($cache['default_user'] as $name => $value)
    58     {
    59                 // If the field is true or false, the variable is transformed into a
    60         // boolean value.
    61         if ($value == 'true' or $value == 'false')
    62       {
    63         $default_user[$name] = get_boolean($value);
    64         }
    65       else
    66       {
    67         $default_user[$name] = $value;
    68       }
    69         }
    70                 // Changing $userdata array values with default ones   
    71                 foreach ($userdata as $key => $valeur)
    72                 {
    73                         if ($key == 'nb_image_line')
    74                         {
    75                                 $userdata[$key] = $default_user['nb_image_line'];
    76                                 $_POST['nb_image_line'] = $userdata['nb_image_line'];
    77                         }
    78                         if ($key == 'nb_line_page')
    79                         {
    80                                 $userdata[$key] = $default_user['nb_line_page'];
    81                                 $_POST['nb_line_page'] = $userdata['nb_line_page'];
    82                         }
    83                         if ($key == 'maxwidth')
    84                         {
    85                                 $userdata[$key] = $default_user['maxwidth'];
    86                                 $_POST['maxwidth'] = $userdata['maxheight'];
    87                         }
    88                         if ($key == 'maxheight')
    89                         {
    90                                 $userdata[$key] = $default_user['maxheight'];
    91                                 $_POST['maxheight'] = $userdata['maxheight'];
    92                         }
    93                         if ($key == 'expand')
    94                         {
    95                                 $userdata[$key] = $default_user['expand'];
    96                                 $_POST['expand'] = $userdata['expand'];
    97                         }
    98                         if ($key == 'show_nb_comments')
    99                         {
    100                                 $userdata[$key] = $default_user['show_nb_comments'];
    101                                 $_POST['show_nb_comments'] = $userdata['show_nb_comments'];
    102                         }
    103                         if ($key == 'recent_period')
    104                         {
    105                                 $userdata[$key] = $default_user['recent_period'];
    106                                 $_POST['recent_period'] = $userdata['recent_period'];
    107                         }
    108                         if ($key == 'show_nb_hits')
    109                         {
    110                                 $userdata[$key] = $default_user['show_nb_hits'];
    111                                 $_POST['show_nb_hits'] = $userdata['show_nb_hits'];
    112                         }
    113                 }
    114         }
    115        
     61    $default_user = mysql_fetch_assoc($result);
     62    $userdata = array_merge($userdata, $default_user);
     63
     64    mass_updates(
     65      USER_INFOS_TABLE,
     66      array('primary' => array('user_id'), 'update' => $fields),
     67      array($userdata)
     68      );
     69  }
     70
    11671  save_profile_from_post($userdata, $errors);
    11772
Note: See TracChangeset for help on using the changeset viewer.