Ignore:
Timestamp:
May 10, 2005, 12:34:21 AM (20 years ago)
Author:
plg
Message:
  • user list : links to profile page and permissions page are represented by icons (more compact)
  • user list : ability to associate to a group or to dissociate from a group a list of selected users
  • user list : ability to set user properties in "batch" mode (a selection of users at once)
  • user list : alternate background color for each line
  • (not in ChangeLog) temporary commented code to update current user language if $_POSTlanguage is set (see include/user.inc.php for details)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/user_list.php

    r786 r787  
    5353
    5454// +-----------------------------------------------------------------------+
     55// |                       preferences form submission                     |
     56// +-----------------------------------------------------------------------+
     57
     58$errors = array();
     59
     60if (isset($_POST['pref_submit']))
     61{
     62  $collection = array();
     63 
     64  switch ($_POST['target'])
     65  {
     66    case 'all' :
     67    {
     68      $query = '
     69SELECT id
     70  FROM '.USERS_TABLE.'
     71  WHERE id != 2
     72;';
     73      $collection = array_from_query($query, 'id');
     74      break;
     75    }
     76    case 'selection' :
     77    {
     78      $collection = $_POST['selection'];
     79      break;
     80    }
     81  }
     82
     83  if (-1 != $_POST['associate'])
     84  {
     85    $datas = array();
     86
     87    $query = '
     88SELECT user_id
     89  FROM '.USER_GROUP_TABLE.'
     90  WHERE group_id = '.$_POST['associate'].'
     91;';
     92    $associated = array_from_query($query, 'user_id');
     93
     94    // TODO : if $associable array is empty, no further actions
     95    $associable = array_diff($collection, $associated);
     96   
     97    foreach ($associable as $item)
     98    {
     99      array_push($datas,
     100                 array('group_id'=>$_POST['associate'],
     101                       'user_id'=>$item));
     102    }
     103 
     104    mass_inserts(USER_GROUP_TABLE,
     105                 array('group_id', 'user_id'),
     106                 $datas);
     107  }
     108
     109  if (-1 != $_POST['dissociate'])
     110  {
     111    $query = '
     112DELETE FROM '.USER_GROUP_TABLE.'
     113  WHERE group_id = '.$_POST['dissociate'].'
     114  AND user_id IN ('.implode(',', $collection).')
     115';
     116    pwg_query($query);
     117  }
     118
     119  // properties to set for the collection (a user list)
     120  $datas = array();
     121  $dbfields = array('primary' => array('id'), 'update' => array());
     122
     123  $formfields = array('nb_image_line', 'nb_line_page', 'template', 'language',
     124                      'recent_period', 'expand', 'show_nb_comments',
     125                      'maxwidth', 'maxheight', 'status');
     126 
     127  foreach ($formfields as $formfield)
     128  {
     129    if ($_POST[$formfield.'_action'] != 'leave')
     130    {
     131      array_push($dbfields['update'], $formfield);
     132    }
     133  }
     134 
     135  // updating elements is useful only if needed...
     136  if (count($dbfields['update']) > 0)
     137  {
     138    $datas = array();
     139   
     140    foreach ($collection as $user_id)
     141    {
     142      $data = array();
     143      $data['id'] = $user_id;
     144
     145      // TODO : verify if submited values are semanticaly correct
     146      foreach ($dbfields['update'] as $dbfield)
     147      {
     148        // if the action is 'unset', the key won't be in row and
     149        // mass_updates function will set this field to NULL
     150        if ('set' == $_POST[$dbfield.'_action'])
     151        {
     152          $data[$dbfield] = $_POST[$dbfield];
     153        }
     154      }
     155
     156      // Webmaster (user_id = 1) status must not be changed
     157      if (1 == $user_id and isset($data['status']))
     158      {
     159        $data['status'] = 'admin';
     160      }
     161
     162      array_push($datas, $data);
     163    }
     164
     165//     echo '<pre>'; print_r($dbfields); echo '</pre>';
     166//     echo '<pre>'; print_r($datas); echo '</pre>';
     167    mass_updates(USERS_TABLE, $dbfields, $datas);
     168  }
     169}
     170
     171// +-----------------------------------------------------------------------+
     172// |                              groups list                              |
     173// +-----------------------------------------------------------------------+
     174
     175$groups = array();
     176
     177$query = '
     178SELECT id, name
     179  FROM '.GROUPS_TABLE.'
     180;';
     181$result = pwg_query($query);
     182
     183while ($row = mysql_fetch_array($result))
     184{
     185  $groups[$row['id']] = $row['name'];
     186}
     187
     188// +-----------------------------------------------------------------------+
    55189// |                             template init                             |
    56190// +-----------------------------------------------------------------------+
     
    84218    'L_PERMISSIONS' => $lang['permissions'],
    85219    'L_USERS_LIST' => $lang['title_liste_users'],
     220    'L_LANGUAGE' => $lang['language'],
     221    'L_NB_IMAGE_LINE' => $lang['nb_image_per_row'],
     222    'L_NB_LINE_PAGE' => $lang['nb_row_per_page'],
     223    'L_TEMPLATE' => $lang['theme'],
     224    'L_RECENT_PERIOD' => $lang['recent_period'],
     225    'L_EXPAND' => $lang['auto_expand'],
     226    'L_SHOW_NB_COMMENTS' => $lang['show_nb_comments'],
     227    'L_MAXWIDTH' => $lang['maxwidth'],
     228    'L_MAXHEIGHT' => $lang['maxheight'],
     229    'L_YES' => $lang['yes'],
     230    'L_NO' => $lang['no'],
     231    'L_SUBMIT' => $lang['submit'],
     232    'L_RESET' => $lang['reset'],
     233    'L_DELETE' => $lang['user_delete'],
     234    'L_DELETE_HINT' => $lang['user_delete_hint'],
    86235   
    87236    'F_ADD_ACTION' => $base_url,
     
    137286    ));
    138287
    139 $query = '
    140 SELECT id, name
    141   FROM '.GROUPS_TABLE.'
    142 ;';
    143 $result = pwg_query($query);
    144 
    145 while ($row = mysql_fetch_array($result))
    146 {
    147   $selected = (isset($_GET['group']) and $_GET['group'] == $row['id']) ?
     288foreach ($groups as $group_id => $group_name)
     289{
     290  $selected = (isset($_GET['group']) and $_GET['group'] == $group_id) ?
    148291    'selected="selected"' : '';
    149292  $template->assign_block_vars(
    150293    $blockname,
    151294    array(
    152       'VALUE' => $row['id'],
    153       'CONTENT' => $row['name'],
     295      'VALUE' => $group_id,
     296      'CONTENT' => $group_name,
    154297      'SELECTED' => $selected
    155298      ));
     
    179322}
    180323
     324// ---
     325//   $user['template'] = $conf['default_template'];
     326//   $user['nb_image_line'] = $conf['nb_image_line'];
     327//   $user['nb_line_page'] = $conf['nb_line_page'];
     328//   $user['language'] = $conf['default_language'];
     329//   $user['maxwidth'] = $conf['default_maxwidth'];
     330//   $user['maxheight'] = $conf['default_maxheight'];
     331//   $user['recent_period'] = $conf['recent_period'];
     332//   $user['expand'] = $conf['auto_expand'];
     333//   $user['show_nb_comments'] = $conf['show_nb_comments'];
     334// ---
     335
     336if (isset($_POST['pref_submit']))
     337{
     338//  echo '<pre>'; print_r($_POST); echo '</pre>';
     339  $template->assign_vars(
     340    array(
     341      'NB_IMAGE_LINE' => $_POST['nb_image_line'],
     342      'NB_LINE_PAGE' => $_POST['nb_line_page'],
     343      'MAXWIDTH' => $_POST['maxwidth'],
     344      'MAXHEIGHT' => $_POST['maxheight'],
     345      'RECENT_PERIOD' => $_POST['recent_period'],
     346      'EXPAND_YES' => 'true' == $_POST['expand'] ? 'checked="checked"' : '',
     347      'EXPAND_NO' => 'false' == $_POST['expand'] ? 'checked="checked"' : '',
     348      'SHOW_NB_COMMENTS_YES' =>
     349        'true' == $_POST['show_nb_comments'] ? 'checked="checked"' : '',
     350      'SHOW_NB_COMMENTS_NO' =>
     351        'false' == $_POST['show_nb_comments'] ? 'checked="checked"' : ''
     352      ));
     353}
     354else
     355{
     356  $template->assign_vars(
     357    array(
     358      'NB_IMAGE_LINE' => $conf['nb_image_line'],
     359      'NB_LINE_PAGE' => $conf['nb_line_page'],
     360      'MAXWIDTH' => @$conf['default_maxwidth'],
     361      'MAXHEIGHT' => @$conf['default_maxheight'],
     362      'RECENT_PERIOD' => $conf['recent_period'],
     363      'EXPAND_YES' => $conf['auto_expand'] ? 'checked="checked"' : '',
     364      'EXPAND_NO' => !$conf['auto_expand'] ? 'checked="checked"' : '',
     365      'SHOW_NB_COMMENTS_YES' =>
     366        $conf['show_nb_comments'] ? 'checked="checked"' : '',
     367      'SHOW_NB_COMMENTS_NO' =>
     368        !$conf['show_nb_comments'] ? 'checked="checked"' : ''
     369      ));
     370}
     371
     372$blockname = 'template_option';
     373
     374foreach (get_templates() as $pwg_template)
     375{
     376  if (isset($_POST['pref_submit']))
     377  {
     378    $selected = $_POST['template']==$pwg_template ? 'selected="selected"' : '';
     379  }
     380  else if ($conf['default_template'] == $pwg_template)
     381  {
     382    $selected = 'selected="selected"';
     383  }
     384  else
     385  {
     386    $selected = '';
     387  }
     388 
     389  $template->assign_block_vars(
     390    $blockname,
     391    array(
     392      'VALUE'=> $pwg_template,
     393      'CONTENT' => $pwg_template,
     394      'SELECTED' => $selected
     395      ));
     396}
     397
     398$blockname = 'language_option';
     399
     400foreach (get_languages() as $language_code => $language_name)
     401{
     402  if (isset($_POST['pref_submit']))
     403  {
     404    $selected = $_POST['language']==$language_code ? 'selected="selected"':'';
     405  }
     406  else if ($conf['default_language'] == $language_code)
     407  {
     408    $selected = 'selected="selected"';
     409  }
     410  else
     411  {
     412    $selected = '';
     413  }
     414 
     415  $template->assign_block_vars(
     416    $blockname,
     417    array(
     418      'VALUE'=> $language_code,
     419      'CONTENT' => $language_name,
     420      'SELECTED' => $selected
     421      ));
     422}
     423
     424$blockname = 'pref_status_option';
     425
     426foreach (get_enums(USERS_TABLE, 'status') as $status)
     427{
     428  if (isset($_POST['pref_submit']))
     429  {
     430    $selected = $_POST['status'] == $status ? 'selected="selected"' : '';
     431  }
     432  else if ('guest' == $status)
     433  {
     434    $selected = 'selected="selected"';
     435  }
     436  else
     437  {
     438    $selected = '';
     439  }
     440 
     441  $template->assign_block_vars(
     442    $blockname,
     443    array(
     444      'VALUE' => $status,
     445      'CONTENT' => $lang['user_status_'.$status],
     446      'SELECTED' => $selected
     447      ));
     448}
     449
     450// associate
     451$blockname = 'associate_option';
     452
     453$template->assign_block_vars(
     454  $blockname,
     455  array(
     456    'VALUE'=> -1,
     457    'CONTENT' => '------------',
     458    'SELECTED' => ''
     459    ));
     460
     461foreach ($groups as $group_id => $group_name)
     462{
     463  if (isset($_POST['pref_submit']))
     464  {
     465    $selected = $_POST['associate'] == $group_id ? 'selected="selected"' : '';
     466  }
     467  else
     468  {
     469    $selected = '';
     470  }
     471   
     472  $template->assign_block_vars(
     473    $blockname,
     474    array(
     475      'VALUE' => $group_id,
     476      'CONTENT' => $group_name,
     477      'SELECTED' => $selected
     478      ));
     479}
     480
     481// dissociate
     482$blockname = 'dissociate_option';
     483
     484$template->assign_block_vars(
     485  $blockname,
     486  array(
     487    'VALUE'=> -1,
     488    'CONTENT' => '------------',
     489    'SELECTED' => ''
     490    ));
     491
     492foreach ($groups as $group_id => $group_name)
     493{
     494  if (isset($_POST['pref_submit']))
     495  {
     496    $selected = $_POST['dissociate'] == $group_id ? 'selected="selected"' : '';
     497  }
     498  else
     499  {
     500    $selected = '';
     501  }
     502   
     503  $template->assign_block_vars(
     504    $blockname,
     505    array(
     506      'VALUE' => $group_id,
     507      'CONTENT' => $group_name,
     508      'SELECTED' => $selected
     509      ));
     510}
     511
    181512// +-----------------------------------------------------------------------+
    182513// |                                 filter                                |
     
    262593$users = array();
    263594$user_ids = array();
    264 $groups_content = array();
    265595
    266596$order_by = 'id';
     
    312642{
    313643  $query = '
    314 SELECT user_id, group_id, name
    315   FROM '.USER_GROUP_TABLE.' INNER JOIN '.GROUPS_TABLE.' ON group_id = id
     644SELECT user_id, group_id
     645  FROM '.USER_GROUP_TABLE.'
    316646  WHERE user_id IN ('.implode(',', $user_ids).')
    317647;';
     
    319649  while ($row = mysql_fetch_array($result))
    320650  {
    321     $groups_content[$row['group_id']] = $row['name'];
    322651    array_push($user_groups[$row['user_id']], $row['group_id']);
    323652  }
    324653
    325   foreach ($users as $item)
    326   {
    327     $groups = preg_replace('/(\d+)/e',
    328                            "\$groups_content['$1']",
    329                            implode(', ', $user_groups[$item['id']]));
     654  foreach ($users as $num => $item)
     655  {
     656    $groups_string = preg_replace('/(\d+)/e',
     657                                  "\$groups['$1']",
     658                                  implode(', ', $user_groups[$item['id']]));
     659
     660    if (isset($_POST['pref_submit'])
     661        and isset($_POST['selection'])
     662        and in_array($item['id'], $_POST['selection']))
     663    {
     664      $checked = 'checked="checked"';
     665    }
     666    else
     667    {
     668      $checked = '';
     669    }
    330670   
    331671    $template->assign_block_vars(
    332672      'user',
    333673      array(
     674        'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1',
     675        'ID'=>$item['id'],
     676        'CHECKED'=>$checked,
    334677        'U_MOD'=>add_session_id($profile_url.$item['id']),
    335678        'U_PERM'=>add_session_id($perm_url.$item['id']),
     
    337680        'STATUS'=>$lang['user_status_'.$item['status']],
    338681        'EMAIL'=>isset($item['mail_address']) ? $item['mail_address'] : '',
    339         'GROUPS'=>$groups
     682        'GROUPS'=>$groups_string
    340683        ));
    341684  }
Note: See TracChangeset for help on using the changeset viewer.