Changeset 805


Ignore:
Timestamp:
Jul 17, 2005, 5:09:24 PM (19 years ago)
Author:
plg
Message:
  • bug fixed : in admin/user_list, if target is "selection" and that no user is selected, an error occurs
Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_list.php

    r792 r805  
    7474    case 'selection' :
    7575    {
    76       $collection = $_POST['selection'];
     76      if (isset($_POST['selection']))
     77      {
     78        $collection = $_POST['selection'];
     79      }
    7780      break;
    7881    }
    7982  }
    8083
    81   if (-1 != $_POST['associate'])
    82   {
    83     $datas = array();
    84 
    85     $query = '
     84  if (count($collection) > 0)
     85  {
     86    if (-1 != $_POST['associate'])
     87    {
     88      $datas = array();
     89
     90      $query = '
    8691SELECT user_id
    8792  FROM '.USER_GROUP_TABLE.'
    8893  WHERE group_id = '.$_POST['associate'].'
    8994;';
    90     $associated = array_from_query($query, 'user_id');
    91 
    92     // TODO : if $associable array is empty, no further actions
    93     $associable = array_diff($collection, $associated);
    94    
    95     foreach ($associable as $item)
     95      $associated = array_from_query($query, 'user_id');
     96
     97      $associable = array_diff($collection, $associated);
     98
     99      if (count($associable) > 0)
     100      {
     101        foreach ($associable as $item)
     102        {
     103          array_push($datas,
     104                     array('group_id'=>$_POST['associate'],
     105                           'user_id'=>$item));
     106        }
     107       
     108        mass_inserts(USER_GROUP_TABLE,
     109                     array('group_id', 'user_id'),
     110                     $datas);
     111      }
     112    }
     113
     114    if (-1 != $_POST['dissociate'])
    96115    {
    97       array_push($datas,
    98                  array('group_id'=>$_POST['associate'],
    99                        'user_id'=>$item));
    100     }
    101  
    102     mass_inserts(USER_GROUP_TABLE,
    103                  array('group_id', 'user_id'),
    104                  $datas);
    105   }
    106 
    107   if (-1 != $_POST['dissociate'])
    108   {
    109     $query = '
     116      $query = '
    110117DELETE FROM '.USER_GROUP_TABLE.'
    111118  WHERE group_id = '.$_POST['dissociate'].'
    112119  AND user_id IN ('.implode(',', $collection).')
    113120';
    114     pwg_query($query);
    115   }
    116 
    117   // properties to set for the collection (a user list)
    118   $datas = array();
    119   $dbfields = array('primary' => array('id'), 'update' => array());
    120 
    121   $formfields = array('nb_image_line', 'nb_line_page', 'template', 'language',
    122                       'recent_period', 'expand', 'show_nb_comments',
    123                       'maxwidth', 'maxheight', 'status');
     121      pwg_query($query);
     122    }
     123
     124    // properties to set for the collection (a user list)
     125    $datas = array();
     126    $dbfields = array('primary' => array('id'), 'update' => array());
     127   
     128    $formfields =
     129      array('nb_image_line', 'nb_line_page', 'template', 'language',
     130            'recent_period', 'expand', 'show_nb_comments', 'maxwidth',
     131            'maxheight', 'status');
    124132 
    125   foreach ($formfields as $formfield)
    126   {
    127     if ($_POST[$formfield.'_action'] != 'leave')
     133    foreach ($formfields as $formfield)
    128134    {
    129       array_push($dbfields['update'], $formfield);
     135      if ($_POST[$formfield.'_action'] != 'leave')
     136      {
     137        array_push($dbfields['update'], $formfield);
     138      }
    130139    }
    131   }
    132  
    133   // updating elements is useful only if needed...
    134   if (count($dbfields['update']) > 0)
    135   {
    136     $datas = array();
    137140   
    138     foreach ($collection as $user_id)
     141    // updating elements is useful only if needed...
     142    if (count($dbfields['update']) > 0)
    139143    {
    140       $data = array();
    141       $data['id'] = $user_id;
    142 
    143       // TODO : verify if submited values are semanticaly correct
    144       foreach ($dbfields['update'] as $dbfield)
     144      $datas = array();
     145     
     146      foreach ($collection as $user_id)
    145147      {
    146         // if the action is 'unset', the key won't be in row and
    147         // mass_updates function will set this field to NULL
    148         if ('set' == $_POST[$dbfield.'_action'])
     148        $data = array();
     149        $data['id'] = $user_id;
     150       
     151        // TODO : verify if submited values are semanticaly correct
     152        foreach ($dbfields['update'] as $dbfield)
    149153        {
    150           $data[$dbfield] = $_POST[$dbfield];
     154          // if the action is 'unset', the key won't be in row and
     155          // mass_updates function will set this field to NULL
     156          if ('set' == $_POST[$dbfield.'_action'])
     157          {
     158            $data[$dbfield] = $_POST[$dbfield];
     159          }
    151160        }
     161       
     162        // Webmaster (user_id = 1) status must not be changed
     163        if (1 == $user_id and isset($data['status']))
     164        {
     165          $data['status'] = 'admin';
     166        }
     167       
     168        array_push($datas, $data);
    152169      }
    153170
    154       // Webmaster (user_id = 1) status must not be changed
    155       if (1 == $user_id and isset($data['status']))
    156       {
    157         $data['status'] = 'admin';
    158       }
    159 
    160       array_push($datas, $data);
     171      mass_updates(USERS_TABLE, $dbfields, $datas);
    161172    }
    162 
    163 //     echo '<pre>'; print_r($dbfields); echo '</pre>';
    164 //     echo '<pre>'; print_r($datas); echo '</pre>';
    165     mass_updates(USERS_TABLE, $dbfields, $datas);
     173  }
     174  else
     175  {
     176    array_push($page['errors'], l10n('Select at least one user'));
    166177  }
    167178}
  • trunk/doc/ChangeLog

    r804 r805  
     12005-07-17 Pierrick LE GALL
     2
     3        * bug fixed : in admin/user_list, if target is "selection" and
     4        that no user is selected, an error occurs
     5
    162005-07-17 Pierrick LE GALL
    27
Note: See TracChangeset for help on using the changeset viewer.