Changeset 880


Ignore:
Timestamp:
Oct 5, 2005, 9:41:37 PM (19 years ago)
Author:
plg
Message:
  • bug 160 fixed: (part one of the bug) hard coded column name of users table had to be replaced by the configurable column name. This correction was made by a full rewrite of filtered users list management. The other bug (not submited in bugtracker) that needed this rewrite was that when you choose "all" as target for mass users modification, you expected to apply modification on filtered users, not all users.
  • bug 160 fixed: (part two of the bug) hard coded column name for primary key in mass_updates function.
  • modification: configuration parameter users_page is now located in the correct file (include/config_default.inc.php instead of admin/user_list.php)
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r865 r880  
    709709(
    710710'.implode(",\n", $columns).',
    711 PRIMARY KEY (id)
     711PRIMARY KEY ('.implode(',', $dbfields['primary']).')
    712712)
    713713;';
  • trunk/admin/user_list.php

    r865 r880  
    3131
    3232// +-----------------------------------------------------------------------+
     33// |                              functions                                |
     34// +-----------------------------------------------------------------------+
     35
     36/**
     37 * returns a list of users depending on page filters (in $_GET)
     38 *
     39 * Each user comes with his related informations : id, username, mail
     40 * address, list of groups.
     41 *
     42 * @return array
     43 */
     44function get_filtered_user_list()
     45{
     46  global $conf, $page;
     47
     48  $users = array();
     49 
     50  // filter
     51  $filter = array();
     52 
     53  if (isset($_GET['username']) and !empty($_GET['username']))
     54  {
     55    $username = str_replace('*', '%', $_GET['username']);
     56    if (function_exists('mysql_real_escape_string'))
     57    {
     58      $filter['username'] = mysql_real_escape_string($username);
     59    }
     60    else
     61    {
     62      $filter['username'] = mysql_escape_string($username);
     63    }
     64  }
     65
     66  if (isset($_GET['group'])
     67      and -1 != $_GET['group']
     68      and is_numeric($_GET['group']))
     69  {
     70    $filter['group'] = $_GET['group'];
     71  }
     72
     73  if (isset($_GET['status'])
     74      and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status')))
     75  {
     76    $filter['status'] = $_GET['status'];
     77  }
     78
     79  // how to order the list?
     80  $order_by = 'id';
     81  if (isset($_GET['order_by'])
     82      and in_array($_GET['order_by'], array_keys($page['order_by_items'])))
     83  {
     84    $order_by = $_GET['order_by'];
     85  }
     86 
     87  $direction = 'ASC';
     88  if (isset($_GET['direction'])
     89      and in_array($_GET['direction'], array_keys($page['direction_items'])))
     90  {
     91    $direction = strtoupper($_GET['direction']);
     92  }
     93
     94  // search users depending on filters and order
     95  $query = '
     96SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
     97                u.'.$conf['user_fields']['username'].' AS username,
     98                u.'.$conf['user_fields']['email'].' AS email,
     99                ui.status
     100  FROM '.USERS_TABLE.' AS u
     101    INNER JOIN '.USER_INFOS_TABLE.' AS ui
     102      ON u.'.$conf['user_fields']['id'].' = ui.user_id
     103    LEFT JOIN '.USER_GROUP_TABLE.' AS ug
     104      ON u.'.$conf['user_fields']['id'].' = ug.user_id
     105  WHERE u.'.$conf['user_fields']['id'].' != '.$conf['guest_id'];
     106  if (isset($filter['username']))
     107  {
     108    $query.= '
     109  AND u.'.$conf['user_fields']['username'].' LIKE \''.$filter['username'].'\'';
     110  }
     111  if (isset($filter['group']))
     112  {
     113    $query.= '
     114    AND ug.group_id = '.$filter['group'];
     115  }
     116  if (isset($filter['status']))
     117  {
     118    $query.= '
     119    AND ui.status = \''.$filter['status']."'";
     120  }
     121  $query.= '
     122  ORDER BY '.$order_by.' '.$direction.'
     123;';
     124
     125  $result = pwg_query($query);
     126  while ($row = mysql_fetch_array($result))
     127  {
     128    $user = $row;
     129    $user['groups'] = array();
     130
     131    array_push($users, $user);
     132  }
     133
     134  // add group lists
     135  $user_ids = array();
     136  foreach ($users as $i => $user)
     137  {
     138    $user_ids[$i] = $user['id'];
     139  }
     140  $user_nums = array_flip($user_ids);
     141 
     142  if (count($user_ids) > 0)
     143  {
     144    $query = '
     145SELECT user_id, group_id
     146  FROM '.USER_GROUP_TABLE.'
     147  WHERE user_id IN ('.implode(',', $user_ids).')
     148;';
     149    $result = pwg_query($query);
     150    while ($row = mysql_fetch_array($result))
     151    {
     152      array_push(
     153        $users[$user_nums[$row['user_id']]]['groups'],
     154        $row['group_id']
     155        );
     156    }
     157  }
     158   
     159  return $users;
     160}
     161
     162// +-----------------------------------------------------------------------+
    33163// |                           initialization                              |
    34164// +-----------------------------------------------------------------------+
     
    40170include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php');
    41171
     172$page['order_by_items'] = array(
     173  'id' => $lang['registration_date'],
     174  'username' => $lang['Username']
     175  );
     176
     177$page['direction_items'] = array(
     178  'asc' => $lang['ascending'],
     179  'desc' => $lang['descending']
     180  );
     181
     182$page['filtered_users'] = get_filtered_user_list();
     183
    42184// +-----------------------------------------------------------------------+
    43185// |                              add a user                               |
     
    61203    case 'all' :
    62204    {
    63       $query = '
    64 SELECT id
    65   FROM '.USERS_TABLE.'
    66   WHERE id != '.$conf['guest_id'].'
    67 ;';
    68       $collection = array_from_query($query, 'id');
     205      foreach($page['filtered_users'] as $local_user)
     206      {
     207        array_push($collection, $local_user['id']);
     208      }
    69209      break;
    70210    }
     
    254394
    255395$base_url = add_session_id(PHPWG_ROOT_PATH.'admin.php?page=user_list');
    256 
    257 $conf['users_page'] = 20;
    258396
    259397if (isset($_GET['start']) and is_numeric($_GET['start']))
     
    307445}
    308446
    309 $order_by_items = array('id' => $lang['registration_date'],
    310                         'username' => $lang['login']);
    311 
    312 foreach ($order_by_items as $item => $label)
     447foreach ($page['order_by_items'] as $item => $label)
    313448{
    314449  $selected = (isset($_GET['order_by']) and $_GET['order_by'] == $item) ?
     
    323458}
    324459
    325 $direction_items = array('asc' => $lang['ascending'],
    326                          'desc' => $lang['descending']);
    327 
    328 foreach ($direction_items as $item => $label)
     460foreach ($page['direction_items'] as $item => $label)
    329461{
    330462  $selected = (isset($_GET['direction']) and $_GET['direction'] == $item) ?
     
    568700
    569701// +-----------------------------------------------------------------------+
    570 // |                                 filter                                |
    571 // +-----------------------------------------------------------------------+
    572 
    573 $filter = array();
    574 
    575 if (isset($_GET['username']) and !empty($_GET['username']))
    576 {
    577   $username = str_replace('*', '%', $_GET['username']);
    578   if (function_exists('mysql_real_escape_string'))
    579   {
    580     $username = mysql_real_escape_string($username);
    581   }
    582   else
    583   {
    584     $username = mysql_escape_string($username);
    585   }
    586 
    587   if (!empty($username))
    588   {
    589     $filter['username'] = $username;
    590   }
    591 }
    592 
    593 if (isset($_GET['group'])
    594     and -1 != $_GET['group']
    595     and is_numeric($_GET['group']))
    596 {
    597   $filter['group'] = $_GET['group'];
    598 }
    599 
    600 if (isset($_GET['status'])
    601     and in_array($_GET['status'], get_enums(USER_INFOS_TABLE, 'status')))
    602 {
    603   $filter['status'] = $_GET['status'];
    604 }
    605 
    606 // +-----------------------------------------------------------------------+
    607702// |                            navigation bar                             |
    608703// +-----------------------------------------------------------------------+
    609704
    610 $query = '
    611 SELECT COUNT(DISTINCT u.'.$conf['user_fields']['id'].')
    612   FROM '.USERS_TABLE.' AS u
    613     INNER JOIN '.USER_INFOS_TABLE.' AS ui
    614       ON u.'.$conf['user_fields']['id'].' = ui.user_id
    615     LEFT JOIN '.USER_GROUP_TABLE.' AS ug
    616       ON u.'.$conf['user_fields']['id'].' = ug.user_id
    617   WHERE u.'.$conf['user_fields']['id'].' != '.$conf['guest_id'];
    618 if (isset($filter['username']))
    619 {
    620   $query.= '
    621   AND u.'.$conf['user_fields']['username'].' LIKE \''.$filter['username'].'\'';
    622 }
    623 if (isset($filter['group']))
    624 {
    625   $query.= '
    626     AND ug.group_id = '.$filter['group'];
    627 }
    628 if (isset($filter['status']))
    629 {
    630   $query.= '
    631     AND ui.status = \''.$filter['status']."'";
    632 }
    633 $query.= '
    634 ;';
    635 list($counter) = mysql_fetch_row(pwg_query($query));
    636 
    637705$url = PHPWG_ROOT_PATH.'admin.php'.get_query_string_diff(array('start'));
    638706
    639 $navbar = create_navigation_bar($url,
    640                                 $counter,
    641                                 $start,
    642                                 $conf['users_page'],
    643                                 '');
     707$navbar = create_navigation_bar(
     708  $url,
     709  count($page['filtered_users']),
     710  $start,
     711  $conf['users_page'],
     712  ''
     713  );
    644714
    645715$template->assign_vars(array('NAVBAR' => $navbar));
     
    652722$perm_url = PHPWG_ROOT_PATH.'admin.php?page=user_perm&user_id=';
    653723
    654 $users = array();
    655 $user_ids = array();
    656 
    657 $order_by = 'id';
    658 if (isset($_GET['order_by'])
    659     and in_array($_GET['order_by'], array_keys($order_by_items)))
    660 {
    661   $order_by = $_GET['order_by'];
    662 }
    663 
    664 $direction = 'ASC';
    665 if (isset($_GET['direction'])
    666     and in_array($_GET['direction'], array_keys($direction_items)))
    667 {
    668   $direction = strtoupper($_GET['direction']);
    669 }
    670 
    671 $query = '
    672 SELECT DISTINCT u.'.$conf['user_fields']['id'].' AS id,
    673                 u.'.$conf['user_fields']['username'].' AS username,
    674                 u.'.$conf['user_fields']['email'].' AS email,
    675                 ui.status
    676   FROM '.USERS_TABLE.' AS u
    677     INNER JOIN '.USER_INFOS_TABLE.' AS ui
    678       ON u.'.$conf['user_fields']['id'].' = ui.user_id
    679     LEFT JOIN '.USER_GROUP_TABLE.' AS ug
    680       ON u.'.$conf['user_fields']['id'].' = ug.user_id
    681   WHERE u.'.$conf['user_fields']['id'].' != '.$conf['guest_id'];
    682 if (isset($filter['username']))
    683 {
    684   $query.= '
    685   AND u.'.$conf['user_fields']['username'].' LIKE \''.$filter['username'].'\'';
    686 }
    687 if (isset($filter['group']))
    688 {
    689   $query.= '
    690     AND ug.group_id = '.$filter['group'];
    691 }
    692 if (isset($filter['status']))
    693 {
    694   $query.= '
    695     AND ui.status = \''.$filter['status']."'";
    696 }
    697 $query.= '
    698   ORDER BY '.$order_by.' '.$direction.'
    699   LIMIT '.$start.', '.$conf['users_page'].'
    700 ;';
    701 $result = pwg_query($query);
    702 while ($row = mysql_fetch_array($result))
    703 {
    704   array_push($users, $row);
    705   array_push($user_ids, $row['id']);
    706   $user_groups[$row['id']] = array();
    707 }
    708 
    709 if (count($user_ids) > 0)
    710 {
    711   $query = '
    712 SELECT user_id, group_id
    713   FROM '.USER_GROUP_TABLE.'
    714   WHERE user_id IN ('.implode(',', $user_ids).')
    715 ;';
    716   $result = pwg_query($query);
    717   while ($row = mysql_fetch_array($result))
    718   {
    719     array_push($user_groups[$row['user_id']], $row['group_id']);
    720   }
    721 
    722   foreach ($users as $num => $item)
    723   {
    724     $groups_string = preg_replace('/(\d+)/e',
    725                                   "\$groups['$1']",
    726                                   implode(', ', $user_groups[$item['id']]));
    727 
    728     if (isset($_POST['pref_submit'])
    729         and isset($_POST['selection'])
    730         and in_array($item['id'], $_POST['selection']))
    731     {
    732       $checked = 'checked="checked"';
    733     }
    734     else
    735     {
    736       $checked = '';
    737     }
    738    
    739     $template->assign_block_vars(
    740       'user',
    741       array(
    742         'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1',
    743         'ID'=>$item['id'],
    744         'CHECKED'=>$checked,
    745         'U_MOD'=>add_session_id($profile_url.$item['id']),
    746         'U_PERM'=>add_session_id($perm_url.$item['id']),
    747         'USERNAME'=>$item['username'],
    748         'STATUS'=>$lang['user_status_'.$item['status']],
    749         'EMAIL'=>isset($item['email']) ? $item['email'] : '',
    750         'GROUPS'=>$groups_string
    751         ));
    752   }
     724foreach ($page['filtered_users'] as $num => $local_user)
     725{
     726  // simulate LIMIT $start, $conf['users_page']
     727  if ($num < $start)
     728  {
     729    continue;
     730  }
     731  if ($num >= $start + $conf['users_page'])
     732  {
     733    break;
     734  }
     735
     736  $groups_string = preg_replace(
     737    '/(\d+)/e',
     738    "\$groups['$1']",
     739    implode(
     740      ', ',
     741      $local_user['groups']
     742      )
     743    );
     744
     745  if (isset($_POST['pref_submit'])
     746      and isset($_POST['selection'])
     747      and in_array($local_user['id'], $_POST['selection']))
     748  {
     749    $checked = 'checked="checked"';
     750  }
     751  else
     752  {
     753    $checked = '';
     754  }
     755   
     756  $template->assign_block_vars(
     757    'user',
     758    array(
     759      'CLASS' => ($num % 2 == 1) ? 'row2' : 'row1',
     760      'ID' => $local_user['id'],
     761      'CHECKED' => $checked,
     762      'U_MOD' => add_session_id($profile_url.$local_user['id']),
     763      'U_PERM' => add_session_id($perm_url.$local_user['id']),
     764      'USERNAME' => $local_user['username'],
     765      'STATUS' => $lang['user_status_'.$local_user['status']],
     766      'EMAIL' => isset($local_user['email']) ? $local_user['email'] : '',
     767      'GROUPS' => $groups_string
     768      )
     769    );
    753770}
    754771
  • trunk/doc/ChangeLog

    r879 r880  
     12005-10-05 Pierrick LE GALL
     2
     3        * bug 160 fixed: (part one of the bug) hard coded column name of
     4        users table had to be replaced by the configurable column
     5        name. This correction was made by a full rewrite of filtered users
     6        list management. The other bug (not submited in bugtracker) that
     7        needed this rewrite was that when you choose "all" as target for
     8        mass users modification, you expected to apply modification on
     9        filtered users, not all users.
     10
     11        * bug 160 fixed: (part two of the bug) hard coded column name for
     12        primary key in mass_updates function.
     13
     14        * modification: configuration parameter users_page is now located
     15        in the correct file (include/config_default.inc.php instead of
     16        admin/user_list.php)
     17
    1182005-09-27 Pierrick LE GALL
    219       
  • trunk/include/config_default.inc.php

    r870 r880  
    181181$conf['prefix_thumbnail'] = 'TN-';
    182182
     183// users_page: how many users to display in screen
     184// Administration>Identification>Users?
     185$conf['users_page'] = 20;
     186
    183187// +-----------------------------------------------------------------------+
    184188// |                               metadata                                |
Note: See TracChangeset for help on using the changeset viewer.