b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/views/_user_list.view.php - 474 lines - 15078 bytes - Summary - Text - Print

Description: This file implements the UI view for the user/group list for user/group editing. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UI view for the user/group list for user/group editing.
   4   *
   5   * This file is part of the evoCore framework - {@link http://evocore.net/}
   6   * See also {@link http://sourceforge.net/projects/evocms/}.
   7   *
   8   * @copyright (c)2003-2014 by Francois Planque - {@link http://fplanque.com/}
   9   *
  10   * {@internal License choice
  11   * - If you have received this file as part of a package, please find the license.txt file in
  12   *   the same folder or the closest folder above for complete license terms.
  13   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  14   *   then you must choose one of the following licenses before using the file:
  15   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  16   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  17   * }}
  18   *
  19   * {@internal Open Source relicensing agreement:
  20   * }}
  21   *
  22   * @package admin
  23   *
  24   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  25   * @author fplanque: Francois PLANQUE
  26   *
  27   * @version $Id: _user_list.view.php 6136 2014-03-08 07:59:48Z manuel $
  28   */
  29  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  30  
  31  load_class( 'users/model/_userlist.class.php', 'UserList' );
  32  
  33  /**
  34   * @var User
  35   */
  36  global $current_User;
  37  /**
  38   * @var GeneralSettings
  39   */
  40  global $Settings;
  41  /**
  42   * @var UserSettings
  43   */
  44  global $UserSettings;
  45  /**
  46   * @var DB
  47   */
  48  global $DB;
  49  
  50  global $collections_Module, $admin_url, $action;
  51  
  52  if( !isset( $display_params ) )
  53  { // init display_params
  54      $display_params = array();
  55  }
  56  
  57  // query which groups have users (in order to prevent deletion of groups which have users)
  58  global $usedgroups;    // We need this in a callback below
  59  $usedgroups = $DB->get_col( 'SELECT grp_ID
  60                               FROM T_groups INNER JOIN T_users ON user_grp_ID = grp_ID
  61                               GROUP BY grp_ID');
  62  
  63  $UserList = new UserList( 'admin', $UserSettings->get('results_per_page'), 'users_', array( 'join_city' => false ) );
  64  
  65  $default_filters = array( 'order' => '/user_lastseen_ts/D' );
  66  
  67  $UserList->title = T_('Groups & Users').get_manual_link('users_and_groups');
  68  
  69  /*
  70   * Table icons:
  71   */
  72  if( $current_User->check_perm( 'users', 'edit', false ) )
  73  {    // create new user/group link
  74      $UserList->global_icon( T_('Refresh users list...'), 'refresh', '?ctrl=users&amp;filter=refresh', T_('Refresh').' &raquo;', 3, 4 );
  75      $UserList->global_icon( T_('Create a new user...'), 'new', '?ctrl=user&amp;action=new&amp;user_tab=profile', T_('Add user').' &raquo;', 3, 4 );
  76      $UserList->global_icon( T_('Create a new group...'), 'new', '?ctrl=groups&amp;action=new', T_('Add group').' &raquo;', 3, 4 );
  77  }
  78  
  79  
  80  $UserList->set_default_filters( $default_filters );
  81  $UserList->load_from_Request();
  82  
  83  
  84  if( $UserList->filters['group'] != -1 )
  85  { // List is grouped
  86  
  87      /*
  88       * Grouping params:
  89       */
  90      $UserList->group_by = 'grp_ID';
  91  
  92  
  93      /*
  94       * Group columns:
  95       */
  96      $UserList->grp_cols[] = array(
  97                              'td_class' => 'firstcol'.($current_User->check_perm( 'users', 'edit', false ) ? '' : ' lastcol' ),
  98                              'td_colspan' => -1,  // nb_colds - 1
  99                              'td' => '<a href="?ctrl=groups&amp;grp_ID=$grp_ID$">$grp_name$</a>'
 100                                              .'~conditional( (#grp_ID# == '.$Settings->get('newusers_grp_ID').'), \' <span class="notes">('.T_('default group for new users').')</span>\' )~',
 101                          );
 102  
 103  	function grp_actions( & $row )
 104      {
 105          global $usedgroups, $Settings, $current_User;
 106  
 107          $r = '';
 108          if( $current_User->check_perm( 'users', 'edit', false ) )
 109          {
 110              $r = action_icon( T_('Edit this group...'), 'edit', regenerate_url( 'ctrl,action', 'ctrl=groups&amp;action=edit&amp;grp_ID='.$row->grp_ID ) );
 111  
 112              $r .= action_icon( T_('Duplicate this group...'), 'copy', regenerate_url( 'ctrl,action', 'ctrl=groups&amp;action=new&amp;grp_ID='.$row->grp_ID ) );
 113  
 114              if( ($row->grp_ID != 1) && ($row->grp_ID != $Settings->get('newusers_grp_ID')) && !in_array( $row->grp_ID, $usedgroups ) )
 115              { // delete
 116                  $r .= action_icon( T_('Delete this group!'), 'delete', regenerate_url( 'ctrl,action', 'ctrl=groups&amp;action=delete&amp;grp_ID='.$row->grp_ID.'&amp;'.url_crumb('group') ) );
 117              }
 118              else
 119              {
 120                  $r .= get_icon( 'delete', 'noimg' );
 121              }
 122          }
 123          return $r;
 124      }
 125      $UserList->grp_cols[] = array(
 126                              'td_class' => 'shrinkwrap',
 127                              'td' => '%grp_actions( {row} )%',
 128                          );
 129  
 130  }
 131  
 132  /*
 133   * Data columns:
 134   */
 135  $UserList->cols[] = array(
 136                          'th' => T_('ID'),
 137                          'th_class' => 'shrinkwrap small',
 138                          'td_class' => 'shrinkwrap small',
 139                          'order' => 'user_ID',
 140                          'td' => '$user_ID$',
 141                      );
 142  
 143  if( $Settings->get('allow_avatars') )
 144  {
 145  	function user_avatar( $user_ID )
 146      {
 147          global $Blog;
 148  
 149          $UserCache = & get_UserCache();
 150          $User = & $UserCache->get_by_ID( $user_ID );
 151  
 152          return $User->get_identity_link( array(
 153              'link_text' => 'only_avatar',
 154              'thumb_size' => 'crop-top-48x48',
 155              ) );
 156      }
 157      $UserList->cols[] = array(
 158                              'th' => T_('Picture'),
 159                              'th_class' => 'shrinkwrap small',
 160                              'td_class' => 'shrinkwrap center small',
 161                              'order' => 'has_picture',
 162                              'default_dir' => 'D',
 163                              'td' => '%user_avatar( #user_ID#, #user_avatar_file_ID# )%',
 164                          );
 165  }
 166  
 167  $UserList->cols[] = array(
 168                          'th' => T_('Login'),
 169                          'th_class' => 'shrinkwrap small',
 170                          'td_class' => 'small',
 171                          'order' => 'user_login',
 172                          'td' => '%get_user_identity_link( #user_login#, #user_ID#, "profile", "text" )%',
 173                      );
 174  
 175  $nickname_editing = $Settings->get( 'nickname_editing' );
 176  if( $nickname_editing != 'hidden' && $current_User->check_perm( 'users', 'edit' ) )
 177  {
 178      $UserList->cols[] = array(
 179                              'th' => T_('Nickname'),
 180                              'th_class' => 'shrinkwrap small',
 181                              'td_class' => 'small',
 182                              'order' => 'user_nickname',
 183                              'td' => '$user_nickname$',
 184                          );
 185  }
 186  
 187  $UserList->cols[] = array(
 188                          'th' => T_('Name'),
 189                          'th_class' => 'small',
 190                          'td_class' => 'small',
 191                          'order' => 'user_lastname, user_firstname',
 192                          'td' => '$user_firstname$ $user_lastname$',
 193                      );
 194  
 195  $UserList->cols[] = array(
 196                          'th' => T_('Gender'),
 197                          'th_class' => 'shrinkwrap small',
 198                          'td_class' => 'shrinkwrap small',
 199                          'order' => 'user_gender',
 200                          'td' => '$user_gender$',
 201                      );
 202  
 203  $UserList->cols[] = array(
 204                          'th' => T_('Country'),
 205                          'th_class' => 'shrinkwrap small',
 206                          'td_class' => 'shrinkwrap small',
 207                          'order' => 'c.ctry_name',
 208                          'td' => '%country_flag( #ctry_code#, #ctry_name#, "w16px", "flag", "", false, true, "", false )% $ctry_name$',
 209                      );
 210  
 211  function user_mailto( $email )
 212  {
 213      if( empty( $email ) )
 214      {
 215          return '&nbsp;';
 216      }
 217      return action_icon( T_('Email').': '.$email, 'email', 'mailto:'.$email, T_('Email') );
 218  }
 219  
 220  function user_pm ( $user_ID, $user_login )
 221  {
 222      global $current_User;
 223  
 224      if( $user_ID == $current_User->ID )
 225      {
 226          return '&nbsp;';
 227      }
 228  
 229      $UserCache = & get_UserCache();
 230      $User = & $UserCache->get_by_ID( $user_ID );
 231      if( $User && ( $User->get_msgform_possibility() == 'PM' ) )
 232      { // return new pm link only, if current User may send private message to User
 233          return action_icon( T_('Private Message').': '.$user_login, 'comments', '?ctrl=threads&action=new&user_login='.$user_login );
 234      }
 235  
 236      return '';
 237  }
 238  
 239  function user_status( $user_status, $user_ID )
 240  {
 241      global $current_User;
 242  
 243      $user_status_icons = get_user_status_icons( true );
 244      $status_content = $user_status_icons[ $user_status ];
 245  
 246      if( is_admin_page() && ( $current_User->check_perm( 'users', 'edit' ) ) )
 247      { // current User is an administrator and view is displayed on admin interface, return link to user admin tab
 248          return '<a href="'.get_user_identity_url( $user_ID, 'admin' ).'">'.$status_content.'</a>';
 249      }
 250  
 251      return $status_content;
 252  }
 253  
 254  if( isset($collections_Module) )
 255  {    // We are handling blogs:
 256      $UserList->cols[] = array(
 257                              'th' => T_('Blogs'),
 258                              'order' => 'nb_blogs',
 259                              'th_class' => 'shrinkwrap small',
 260                              'td_class' => 'center small',
 261                              'td' => '~conditional( (#nb_blogs# > 0), \'<a href="admin.php?ctrl=user&amp;user_tab=activity&amp;user_ID=$user_ID$" title="'.format_to_output( T_('View personal blogs'), 'htmlattr' ).'">$nb_blogs$</a>\', \'&nbsp;\' )~',
 262                          );
 263  }
 264  
 265  if( $current_User->check_perm( 'users', 'edit', false ) )
 266  {
 267      $UserList->cols[] = array(
 268                          'th' => T_('Source'),
 269                          'th_class' => 'shrinkwrap small',
 270                          'td_class' => 'center small',
 271                          'order' => 'user_source',
 272                          'default_dir' => 'D',
 273                          'td' => '$user_source$',
 274                      );
 275  }
 276  
 277  $UserList->cols[] = array(
 278                      'th' => T_('Registered'),
 279                      'th_class' => 'shrinkwrap small',
 280                      'td_class' => 'center small',
 281                      'order' => 'user_created_datetime',
 282                      'default_dir' => 'D',
 283                      'td' => '%mysql2localedate( #user_created_datetime#, "M-d" )%',
 284                  );
 285  
 286  /**
 287   * Get a flag of registration country with a link to user's sessions page
 288   *
 289   * @param integer User ID
 290   * @param string Country code
 291   * @param string Country name
 292   * @return string
 293  */
 294  function user_reg_country( $user_ID, $country_code, $country_name )
 295  {
 296      global $current_User, $admin_url;
 297  
 298      $flag = country_flag( $country_code, $country_name, 'w16px', 'flag', '', false, true, '', false );
 299      if( empty( $flag ) )
 300      { // No flag or registration country
 301          $flag = '?';
 302      }
 303  
 304      if( $current_User->check_perm( 'users', 'edit' ) )
 305      { // Only users with edit all users permission can see the 'Sessions' tab
 306          $flag = '<a href="'.$admin_url.'?ctrl=user&amp;user_tab=sessions&amp;user_ID='.$user_ID.'">'.$flag.'</a>';
 307      }
 308  
 309      return $flag;
 310  }
 311  $UserList->cols[] = array(
 312                      'th' => T_('RC'),
 313                      'th_title' => T_('Registration country'),
 314                      'th_class' => 'shrinkwrap small',
 315                      'td_class' => 'shrinkwrap small',
 316                      'order' => 'rc.ctry_name',
 317                      'td' => '%user_reg_country( #user_ID#, #reg_ctry_code#, #reg_ctry_name# )%',
 318                  );
 319  
 320  $UserList->cols[] = array(
 321                      'th' => T_('Profile update'),
 322                      'th_class' => 'shrinkwrap small',
 323                      'td_class' => 'center small',
 324                      'order' => 'user_profileupdate_date',
 325                      'default_dir' => 'D',
 326                      'td' => '%mysql2localedate( #user_profileupdate_date#, "M-d" )%',
 327                  );
 328  $UserList->cols[] = array(
 329                      'th' => T_('Last Visit'),
 330                      'th_class' => 'shrinkwrap small',
 331                      'td_class' => 'center small',
 332                      'order' => 'user_lastseen_ts',
 333                      'default_dir' => 'D',
 334                      'td' => '%mysql2localedate( #user_lastseen_ts#, "M-d" )%',
 335                  );
 336  
 337  $UserList->cols[] = array(
 338                      'th' => T_('Contact'),
 339                      'th_class' => 'shrinkwrap small',
 340                      'td_class' => 'shrinkwrap small',
 341                      'td' => '%user_mailto( #user_email# )%
 342                      %user_pm( #user_ID#, #user_login# )%'.
 343                      ('~conditional( (#user_url# != \'http://\') && (#user_url# != \'\'), \' <a href="$user_url$" target="_blank" title="'.format_to_output( T_('Website'), 'htmlattr' ).': $user_url$">'
 344                              .get_icon( 'www', 'imgtag', array( 'class' => 'middle', 'title' => format_to_output( T_('Website'), 'htmlattr' ).': $user_url$' ) ).'</a>\', \'&nbsp;\' )~'),
 345                  );
 346  
 347  $filter_reported = param( 'reported', 'integer' );
 348  if( $filter_reported )
 349  {    // Filter is set to 'Reported users'
 350      $userlist_col_reputaion = array(
 351                          'th' => T_('Rep'),
 352                          'th_class' => 'shrinkwrap small',
 353                          'td_class' => 'shrinkwrap small',
 354                          'order' => 'user_rep',
 355                          'default_dir' => 'D',
 356                          'td' => '$user_rep$',
 357                      );
 358  }
 359  
 360  if( $UserList->filters['group'] == -1 )
 361  { // List is ungrouped, Display column with group name
 362      $UserList->cols[] = array(
 363              'th' => T_('Group'),
 364              'th_class' => 'shrinkwrap small',
 365              'td_class' => 'shrinkwrap small',
 366              'order' => 'grp_name',
 367              'td' => '$grp_name$',
 368          );
 369  }
 370  
 371  if( ! $current_User->check_perm( 'users', 'edit', false ) )
 372  {
 373      if( $filter_reported )
 374      {
 375          $UserList->cols[] = $userlist_col_reputaion;
 376      }
 377  
 378      $UserList->cols[] = array(
 379                          'th' => T_('Level'),
 380                          'th_class' => 'shrinkwrap small',
 381                          'td_class' => 'shrinkwrap small',
 382                          'order' => 'user_level',
 383                          'default_dir' => 'D',
 384                          'td' => '$user_level$',
 385                      );
 386  }
 387  else
 388  {
 389      $UserList->cols[] = array(
 390                          'th' => /* TRANS: Account status */ T_( 'Status' ),
 391                          'th_class' => 'shrinkwrap small',
 392                          'td_class' => 'shrinkwrap small',
 393                          'order' => 'user_status',
 394                          'default_dir' => 'D',
 395                          'td' => '%user_status( #user_status#, #user_ID# )%'
 396                      );
 397  
 398      if( $filter_reported )
 399      {
 400          $UserList->cols[] = $userlist_col_reputaion;
 401      }
 402  
 403      $UserList->cols[] = array(
 404                          'th' => T_('Level'),
 405                          'th_class' => 'shrinkwrap small',
 406                          'td_class' => 'shrinkwrap user_level_edit small',
 407                          'order' => 'user_level',
 408                          'default_dir' => 'D',
 409                          'td' => '<a href="#" rel="$user_level$">$user_level$</a>',
 410                      );
 411  
 412      $UserList->cols[] = array(
 413                          'th' => T_('Actions'),
 414                          'th_class' => 'small',
 415                          'td_class' => 'shrinkwrap small',
 416                          'td' => action_icon( T_('Edit this user...'), 'edit', '%regenerate_url( \'ctrl,action\', \'ctrl=user&amp;user_ID=$user_ID$&amp;user_tab=profile\' )%' )
 417                                          .action_icon( T_('Duplicate this user...'), 'copy', '%regenerate_url( \'ctrl,action\', \'ctrl=user&amp;action=new&amp;user_ID=$user_ID$&amp;user_tab=profile\' )%' )
 418                                          .'~conditional( (#user_ID# != 1) && (#user_ID# != '.$current_User->ID.'), \''
 419                                              .action_icon( T_('Delete this user!'), 'delete',
 420                                                  '%regenerate_url( \'action\', \'action=delete&amp;user_ID=$user_ID$&amp;'.url_crumb('user').'\' )%' ).'\', \''
 421                          .get_icon( 'delete', 'noimg' ).'\' )~'
 422                      );
 423  }
 424  
 425  if( $action == 'show_recent' )
 426  { // Sort an users list by "Registered" field
 427      $UserList->set_order( 'user_created_datetime' );
 428  }
 429  
 430  // Execute query
 431  $UserList->query();
 432  
 433  
 434  $filter_presets = array(
 435          'all' => array( T_('All users'), get_dispctrl_url( 'users&amp;filter=new' ) ),
 436          'men' => array( T_('Men'), get_dispctrl_url( 'users', 'gender_men=1&amp;filter=new' ) ),
 437          'women' => array( T_('Women'), get_dispctrl_url( 'users', 'gender_women=1&amp;filter=new' ) ),
 438      );
 439  
 440  if( is_admin_page() )
 441  { // Add show only activated users filter only on admin interface
 442      $filter_presets['activated'] = array( T_('Activated users'), get_dispctrl_url( 'users', 'status_activated=1&amp;filter=new' ) );
 443      if( $current_User->check_perm( 'users', 'edit' ) )
 444      { // Show "Reported Users" filter only for users with edit user permission
 445          $filter_presets['reported'] = array( T_('Reported users'), get_dispctrl_url( 'users', 'reported=1&amp;filter=new' ) );
 446      }
 447  }
 448  
 449  if( $UserList->is_filtered() )
 450  {    // Display link to reset filters only if some filter is applied
 451      $filter_presets['reset'] = array( T_('Reset Filters'), get_dispctrl_url( 'users&amp;filter=reset' ), 'class="floatright"' );
 452  }
 453  
 454  $UserList->filter_area = array(
 455      'callback' => 'callback_filter_userlist',
 456      'url_ignore' => 'users_paged,u_paged,keywords',
 457      'presets' => $filter_presets,
 458      );
 459  
 460  
 461  // Display result :
 462  $UserList->display( $display_params );
 463  
 464  
 465  if( $current_User->check_perm( 'users', 'edit' ) && $UserList->result_num_rows > 0 )
 466  {    // Newsletter button
 467      echo '<p class="center">';
 468      echo '<input type="button" value="'.T_('Send newsletter to the current selection').'" onclick="location.href=\''.$admin_url.'?ctrl=newsletter\'" />';
 469      echo '</p>';
 470  }
 471  
 472  load_funcs( 'users/model/_user_js.funcs.php' );
 473  
 474  ?>

title

Description

title

Description

title

Description

title

title

Body