b2evolution PHP Cross Reference Blogging Systems

Source: /inc/messaging/views/_contact_list.view.php - 538 lines - 16261 bytes - Summary - Text - Print

Description: This file is part of b2evolution - {@link http://b2evolution.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file is part of b2evolution - {@link http://b2evolution.net/}
   4   * See also {@link http://sourceforge.net/projects/evocms/}.
   5   *
   6   * @copyright (c)2009-2014 by Francois PLANQUE - {@link http://fplanque.net/}
   7   * Parts of this file are copyright (c)2009 by The Evo Factory - {@link http://www.evofactory.com/}.
   8   *
   9   * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  10   *
  11   * {@internal Open Source relicensing agreement:
  12   * The Evo Factory grants Francois PLANQUE the right to license
  13   * The Evo Factory's contributions to this file and the b2evolution project
  14   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  15   * }}
  16   *
  17   * @package messaging
  18   *
  19   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  20   * @author efy-maxim: Evo Factory / Maxim.
  21   * @author fplanque: Francois Planque.
  22   *
  23   * @version $Id: _contact_list.view.php 6136 2014-03-08 07:59:48Z manuel $
  24   */
  25  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  26  
  27  global $dispatcher;
  28  global $current_User, $Settings;
  29  global $unread_messages_count;
  30  global $DB;
  31  
  32  if( !isset( $display_params ) )
  33  {
  34      $display_params = array();
  35  }
  36  $display_params = array_merge( array(
  37      'show_only_date' => 0,
  38      'show_columns' => 'login,nickname,name',
  39      ), $display_params );
  40  
  41  // show following optional colums
  42  $show_columns = explode( ',', $display_params['show_columns'] );
  43  
  44  // Create SELECT query
  45  $select_SQL = new SQL();
  46  $select_SQL->SELECT(     'mc.mct_to_user_ID, mc.mct_blocked, mc.mct_last_contact_datetime,
  47                          u.user_login AS mct_to_user_login, u.user_nickname AS mct_to_user_nickname,
  48                          CONCAT_WS( " ", u.user_firstname, u.user_lastname ) AS mct_to_user_name,
  49                          u.user_email AS mct_to_user_email, u.user_status AS mct_to_user_status' );
  50  
  51  $select_SQL->FROM( 'T_messaging__contact mc
  52                          INNER JOIN T_users u
  53                          ON mc.mct_to_user_ID = u.user_ID' );
  54  
  55  $select_SQL->WHERE( 'mc.mct_from_user_ID = '.$current_User->ID );
  56  
  57  // Create COUNT quiery
  58  
  59  $count_SQL = new SQL();
  60  
  61  $count_SQL->SELECT( 'COUNT(*)' );
  62  $count_SQL->FROM( 'T_messaging__contact' );
  63  $count_SQL->WHERE( 'mct_from_user_ID = '.$current_User->ID );
  64  
  65  // Get params from request
  66  $s = param( 's', 'string', '', true );
  67  $g = param( 'g', 'integer', 0, true );
  68  $item_ID = param( 'item_ID', 'integer', 0, true );
  69  
  70  if( !empty( $s ) )
  71  {    // Filter by keyword
  72      $select_SQL->WHERE_and( 'CONCAT_WS( " ", u.user_login, u.user_firstname, u.user_lastname, u.user_nickname ) LIKE "%'.$DB->escape($s).'%"' );
  73  
  74      $count_SQL->FROM_add( 'INNER JOIN T_users ON mct_to_user_ID = user_ID' );
  75      $count_SQL->WHERE_and( 'CONCAT_WS( " ", user_login, user_firstname, user_lastname, user_nickname ) LIKE "%'.$DB->escape($s).'%"' );
  76  }
  77  
  78  if( !empty( $g ) )
  79  {    // Filter by group
  80      $select_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groupusers ON cgu_user_ID = mct_to_user_ID' );
  81      $select_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groups ON cgr_ID = cgu_cgr_ID' );
  82      $select_SQL->WHERE_and( 'cgu_cgr_ID = '.$DB->quote( $g ) );
  83      $select_SQL->WHERE_and( 'cgr_user_ID = '.$current_User->ID );
  84  
  85      $count_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groupusers ON cgu_user_ID = mct_to_user_ID' );
  86      $count_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groups ON cgr_ID = cgu_cgr_ID' );
  87      $count_SQL->WHERE_and( 'cgu_cgr_ID = '.$DB->quote( $g ) );
  88      $count_SQL->WHERE_and( 'cgr_user_ID = '.$current_User->ID );
  89  
  90      // Get info of filtered group
  91      $group_filtered_SQL = new SQL();
  92      $group_filtered_SQL->SELECT( 'cgr_ID AS ID, cgr_name AS name, COUNT(cgu_user_ID) AS count_users' );
  93      $group_filtered_SQL->FROM( 'T_messaging__contact_groups' );
  94      $group_filtered_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groupusers ON cgu_cgr_ID = cgr_ID' );
  95      $group_filtered_SQL->WHERE( 'cgr_ID = '.$DB->quote( $g ) );
  96      $group_filtered_SQL->WHERE_and( 'cgr_user_ID = '.$current_User->ID );
  97      $group_filtered_SQL->GROUP_BY( 'cgr_ID' );
  98  
  99      $group_filtered = $DB->get_row( $group_filtered_SQL->get() );
 100  }
 101  
 102  // Create result set:
 103  if( $Settings->get('allow_avatars') )
 104  {
 105      $default_order = '--A';
 106  }
 107  else
 108  {
 109      $default_order = '-A';
 110  }
 111  
 112  
 113  $Results = new Results( $select_SQL->get(), 'mct_', $default_order, NULL, $count_SQL->get() );
 114  
 115  $Results->title = T_('Contacts list');
 116  
 117  /**
 118   * Callback to add filters on top of the result set
 119   *
 120   * @param Form
 121   */
 122  function filter_contacts( & $Form )
 123  {
 124      global $item_ID;
 125  
 126      $Form->text( 's', get_param('s'), 30, T_('Search'), '', 255 );
 127  
 128      $Form->select_input( 'g', get_param('g'), 'get_contacts_groups_options', T_('Group') );
 129  
 130      if( $item_ID > 0 )
 131      {    // Save item ID for the filter request
 132          $Form->hidden( 'item_ID', $item_ID );
 133      }
 134  }
 135  
 136  // Get all groups of current user
 137  $user_groups_SQL = new SQL();
 138  $user_groups_SQL->SELECT( 'cgr_ID AS ID, cgr_name AS name' );
 139  $user_groups_SQL->FROM( 'T_messaging__contact_groups' );
 140  $user_groups_SQL->WHERE( 'cgr_user_ID = '.$current_User->ID );
 141  $user_groups_SQL->ORDER_BY( 'cgr_ID' );
 142  $user_groups = $DB->get_results( $user_groups_SQL->get() );
 143  
 144  if( $item_ID > 0 )
 145  {    // Save item ID in the filter url
 146      $filter_url = url_add_param( get_dispctrl_url( 'contacts' ), 'item_ID='.$item_ID );
 147  }
 148  else
 149  {
 150      $filter_url = get_dispctrl_url( 'contacts' );
 151  }
 152  
 153  $filter_presets = array(
 154          'all' => array( T_('All'), $filter_url ),
 155      );
 156  foreach( $user_groups as $g => $group )
 157  {    // Set user groups to quick filter
 158      $filter_presets[] = array( $group->name, url_add_param( $filter_url, 'g='.$group->ID ) );
 159      if( $g >= 6 )
 160      {    // Use only first 7 groups
 161          break;
 162      }
 163  }
 164  
 165  $Results->filter_area = array(
 166      'callback' => 'filter_contacts',
 167      'presets' => $filter_presets
 168      );
 169  
 170  /**
 171   * Get block/unblock icon
 172   *
 173   * @param block value
 174   * @param user ID
 175   * @return icon
 176   */
 177  function contact_block( $block, $user_ID, $user_status )
 178  {
 179      if( $user_status == 'closed' )
 180      {
 181          return '';
 182      }
 183  
 184      // set action url
 185      $action_url = regenerate_url();
 186      if( !is_admin_page() )
 187      { // in front office the action will be processed by messaging module handle_htsrv_action() through action.php
 188          $action_url = get_samedomain_htsrv_url().'action.php?mname=messaging&disp=contacts&redirect_to='.rawurlencode( $action_url );
 189      }
 190  
 191      if( $block == 0 )
 192      {
 193          return action_icon( T_('Block contact'), 'file_allowed', $action_url.'&action=block&user_ID='.$user_ID.'&amp;'.url_crumb('messaging_contacts') );
 194      }
 195      else
 196      {
 197          return action_icon( T_('Unblock contact'), 'file_not_allowed', $action_url.'&action=unblock&user_ID='.$user_ID.'&amp;'.url_crumb('messaging_contacts') );
 198      }
 199  }
 200  
 201  function contacts_checkbox( $user_ID, $user_status )
 202  {
 203      if( $user_status == 'closed' )
 204      { // contact account was closed
 205          return '<input type="checkbox" name="contacts[]" title="'.T_('This contact is closed').'" value="'.$user_ID.'" disabled="disabled"/>';
 206      }
 207  
 208      $selected_users = explode( ',', param( 'users', 'string', '' ) );
 209      if( in_array( $user_ID, $selected_users ) )
 210      {
 211          $checked = ' checked="checked"';
 212      }
 213      else
 214      {
 215          $checked = '';
 216      }
 217      return '<input type="checkbox" name="contacts[]" title="'.T_('Select this contact').'" value="'.$user_ID.'"'.$checked.' />';
 218  }
 219  $Results->cols[] = array(
 220                      'th' => '',
 221                      'th_class' => 'shrinkwrap',
 222                      'td_class' => 'shrinkwrap',
 223                      'td' => '%contacts_checkbox( #mct_to_user_ID#, #mct_to_user_status# )%',
 224                      );
 225  
 226  if( $Settings->get('allow_avatars') )
 227  {
 228      /**
 229       * Get user avatar
 230       *
 231       * @param integer user ID
 232       * @return string
 233       */
 234  	function user_avatar( $user_ID )
 235      {
 236          global $Blog;
 237  
 238          $UserCache = & get_UserCache();
 239          $User = & $UserCache->get_by_ID( $user_ID, false, false );
 240          if( $User )
 241          {
 242              if( empty( $Blog ) )
 243              {
 244                  $avatar_size = 'crop-top-32x32';
 245              }
 246              else
 247              {
 248                  $avatar_size = $Blog->get_setting('image_size_messaging');
 249              }
 250              $avatar_tag = $User->get_avatar_imgtag( $avatar_size );
 251              $identity_url = get_user_identity_url( $user_ID );
 252              if( !empty( $avatar_tag ) )
 253              {
 254                  if( empty( $identity_url ) )
 255                  { // current_User has no permission to view user settings, and Blog is empty
 256                      return $avatar_tag;
 257                  }
 258                  return '<a href="'.$identity_url.'">'.$avatar_tag.'</a>';
 259              }
 260          }
 261          return '';
 262      }
 263      $Results->cols[] = array(
 264                          'th' => T_('Picture'),
 265                          'th_class' => 'shrinkwrap',
 266                          'td_class' => 'shrinkwrap',
 267                          'td' => '%user_avatar( #mct_to_user_ID# )%',
 268                          );
 269  }
 270  
 271  if( in_array( 'login', $show_columns ) )
 272  {
 273  	function user_login( $user_ID, $link = true )
 274      {
 275          $UserCache = & get_UserCache();
 276          $User = & $UserCache->get_by_ID( $user_ID, false, false );
 277          if( $User )
 278          {
 279              if( $link )
 280              {
 281                  $login_text = get_user_identity_link( $User->login, $User->ID, 'user', 'text' );
 282                  if( $User->check_status( 'is_closed' ) )
 283                  { // add (closed account) note to corresponding contacts!
 284                      $login_text .= '<span class="note">('.T_( 'closed account' ).')</span>';
 285                  }
 286                  return $login_text;
 287              }
 288              return $User->login;
 289          }
 290          return '';
 291      }
 292      $Results->cols[] = array(
 293                          'th' => T_('Login'),
 294                          'order' => 'mct_to_user_login',
 295                          'td' => '%user_login( #mct_to_user_ID# )%',
 296                          );
 297  }
 298  
 299  $Results->cols[] = array(
 300                      'th' => T_('S'),
 301                      'th_title' => T_('Status'),
 302                      'order' => 'mct_blocked',
 303                      'th_class' => 'shrinkwrap',
 304                      'td_class' => 'shrinkwrap',
 305                      'td' => '%contact_block( #mct_blocked#, #mct_to_user_ID#, #mct_to_user_status# )%',
 306                      );
 307  
 308  if( in_array( 'nickname', $show_columns ) )
 309  {
 310  $Results->cols[] = array(
 311                      'th' => T_('Nickname'),
 312                      'order' => 'mct_to_user_nickname',
 313                      'th_class' => 'shrinkwrap',
 314                      'td_class' => 'shrinkwrap',
 315                      'td' => '$mct_to_user_nickname$',
 316                      );
 317  }
 318  
 319  if( in_array( 'name', $show_columns ) )
 320  {
 321  $Results->cols[] = array(
 322                      'th' => T_('Name'),
 323                      'order' => 'mct_to_user_name',
 324                      'th_class' => 'shrinkwrap',
 325                      'td_class' => 'shrinkwrap',
 326                      'td' => '$mct_to_user_name$',
 327                      );
 328  }
 329  
 330  
 331  /**
 332   * Get user email
 333   *
 334   * @param email
 335   * @return string
 336   */
 337  function user_mailto( $email )
 338  {
 339      if( !empty( $email ) )
 340      {
 341          return action_icon( T_('Email').': '.$email, 'email', 'mailto:'.$email, T_('Email') );
 342      }
 343      return '';
 344  }
 345  
 346  function last_contact( $date, $show_only_date, $user_ID )
 347  {
 348      //global $show_only_date;
 349      if( $show_only_date )
 350      {
 351          $data = mysql2localedate( $date );
 352      }
 353      else
 354      {
 355          $data = mysql2localedatetime( $date );
 356      }
 357  
 358      $login = user_login( $user_ID, false );
 359      if( $login != '' )
 360      {
 361          $threads_url = get_dispctrl_url( 'threads', 'colselect_submit=Filter+list&amp;u='.$login );
 362          $data = '<a href="'.$threads_url.'">'.$data.'</a>';
 363      }
 364  
 365      return $data;
 366  }
 367  
 368  $Results->cols[] = array(
 369      'th' => /* TRANS: time related */ T_('Last contact'),
 370      'th_class' => 'shrinkwrap',
 371      'td_class' => 'shrinkwrap',
 372      'td' => '%last_contact(#mct_last_contact_datetime#, '.$display_params[ 'show_only_date' ].', #mct_to_user_ID#)%'
 373  );
 374  
 375  
 376  function contacts_groups( $user_ID )
 377  {
 378      global $current_User, $DB, $cache_user_contacts_groups;
 379  
 380      if( !is_array( $cache_user_contacts_groups ) )
 381      {    // Execute only first time to init cache
 382          $cache_user_contacts_groups = array();
 383  
 384          // Get contacts of current user
 385          $groups_SQL = new SQL();
 386          $groups_SQL->SELECT( 'cgr_ID AS ID, cgu_user_ID AS user_ID, cgr_name AS name' );
 387          $groups_SQL->FROM( 'T_messaging__contact_groupusers' );
 388          $groups_SQL->FROM_add( 'LEFT JOIN T_messaging__contact_groups ON cgu_cgr_ID = cgr_ID' );
 389          $groups_SQL->WHERE( 'cgr_user_ID = '.$current_User->ID );
 390          $groups_SQL->ORDER_BY( 'cgr_name' );
 391          $groups = $DB->get_results( $groups_SQL->get() );
 392  
 393          $remove_link = url_add_param( get_dispctrl_url( 'contacts' ), 'action=remove_user&amp;view=contacts&amp;'.url_crumb( 'messaging_contacts' ) );
 394  
 395          foreach( $groups as $group )
 396          {    // Init cache for groups for each contact of current user
 397              $group_name = $group->name.action_icon( T_('Remove user from this group'), 'remove', url_add_param( $remove_link, 'user_ID='.$group->user_ID.'&amp;group_ID='.$group->ID ) );
 398              if( isset( $cache_user_contacts_groups[$group->user_ID] ) )
 399              {    // nth group of this user
 400                  $cache_user_contacts_groups[$group->user_ID] .= '<br />'.$group_name;
 401              }
 402              else
 403              {    // first group of this user
 404                  $cache_user_contacts_groups[$group->user_ID] = $group_name;
 405              }
 406          }
 407      }
 408  
 409      if( isset( $cache_user_contacts_groups[$user_ID] ) )
 410      {    // user has groups
 411          echo $cache_user_contacts_groups[$user_ID];
 412      }
 413  }
 414  
 415  $Results->cols[] = array(
 416                      'th' => T_('Groups'),
 417                      'th_class' => 'shrinkwrap',
 418                      'td_class' => 'left nowrap',
 419                      'td' => '%contacts_groups( #mct_to_user_ID# )%',
 420                      );
 421  
 422  $Results->display( $display_params );
 423  
 424  if( count( $Results->rows ) > 0 )
 425  {    // Display actions buttons
 426      global $module_contacts_list_params;
 427      modules_call_method( 'get_contacts_list_params' );
 428  
 429      $Form = new Form( get_dispctrl_url( 'contacts' ), 'add_group_contacts' );
 430  
 431      $multi_action_icon = get_icon( 'multi_action', 'imgtag', array( 'style' => 'margin:0 2px 0 14px;position:relative;top:-5px;') );
 432  
 433      $Form->button_input( array(
 434              'type'    => 'button',
 435              'value'   => $module_contacts_list_params['title_selected'],
 436              'onclick' => 'location.href=\''.$module_contacts_list_params['recipients_link'].'\'',
 437              'id'      => 'send_selected_recipients',
 438              'input_prefix' => $multi_action_icon
 439          ) );
 440  
 441      $Form->switch_layout( 'none' );
 442      $Form->switch_template_parts( array(
 443              'formstart'  => '<div class="form_add_contacts">',
 444              'labelstart' => '<span class="label">',
 445              'labelend'   => '</span> <span class="controls">',
 446              'formend'    => '</span></div>',
 447      ) );
 448  
 449      $Form->begin_form();
 450  
 451      $Form->add_crumb( 'messaging_contacts' );
 452      $Form->hidden( 'users', '' );
 453      if( isset( $module_contacts_list_params['form_hiddens'] ) && !empty( $module_contacts_list_params['form_hiddens'] ) )
 454      {    // Append the hidden input elements from module
 455          foreach( $module_contacts_list_params['form_hiddens'] as $hidden_input )
 456          {
 457              $Form->hidden( $hidden_input['name'], $hidden_input['value'] );
 458          }
 459      }
 460  
 461      $Form->combo_box( 'group', param( 'group_combo', 'string', '' ), get_contacts_groups_options( param( 'group', 'string', '-1' ), false ), $multi_action_icon.T_('Add all selected contacts to this group'), array( 'new_field_size' => '8' ) );
 462  
 463      $Form->buttons( array( array( 'submit', 'actionArray[add_group]', T_('Add'), 'SaveButton' ) ) );
 464  
 465      if( isset( $group_filtered ) )
 466      {    // Contacts list is filtered by group
 467          echo '<div id="edit_group_contacts" style="white-space:normal">';
 468  
 469          $Form->hidden( 'group_ID', $group_filtered->ID );
 470  
 471          echo '<p class="center">'.sprintf( T_( 'Selected group: <b>%s</b>' ), $group_filtered->name ).'</p>';
 472  
 473          echo '<input id="send_group_recipients" type="button" onclick="location.href=\''.$module_contacts_list_params['recipients_link'].'&amp;group_ID='.$group_filtered->ID.'\'" value="'.sprintf( $module_contacts_list_params['title_group'], $group_filtered->count_users, $group_filtered->name ).'" style="margin: 1ex 0" /><br />';
 474  
 475          $Form->text_input( 'name', $group_filtered->name, 20, T_('Rename this group to') );
 476  
 477          $Form->button_input( array(
 478                  'name' => 'actionArray[rename_group]',
 479                  'value' => T_('Rename'),
 480                  'class' => 'SaveButton'
 481              ) );
 482          echo ' &nbsp; <b class="nowrap" style="padding-top:1em;line-height:32px">'.T_('or').' &nbsp; ';
 483          $Form->button_input( array(
 484                  'name' => 'actionArray[delete_group]',
 485                  'value' => T_('Delete this group'),
 486                  'class' => 'SaveButton',
 487                  'onclick' => 'return confirm("'.TS_('Are you sure want to delete this group?').'")'
 488              ) );
 489          echo '</b>';
 490  
 491          echo '</div>';
 492      }
 493  
 494      $Form->end_form();
 495      $Form->switch_layout( NULL );
 496  
 497  ?>
 498  <script type="text/javascript">
 499  jQuery( '#send_selected_recipients' ).click( function()
 500  {    // Add selected users to this link
 501      var recipients_param = '';
 502      var recipients = get_selected_users();
 503      if( recipients.length > 0 )
 504      {
 505          recipients_param = '&recipients=' + recipients;
 506      }
 507      location.href = '<?php echo str_replace( '&amp;', '&', $module_contacts_list_params['recipients_link'] ); ?>' + recipients_param;
 508      return false;
 509  } );
 510  
 511  jQuery( '#add_group_contacts' ).submit( function()
 512  {
 513      jQuery( 'input[name=users]' ).val( get_selected_users() );
 514  } );
 515  
 516  function get_selected_users()
 517  {
 518      var users = '';
 519      jQuery( 'input[name^=contacts]' ).each( function()
 520      {
 521          if( jQuery( this ).attr( 'checked' ) )
 522          {
 523              users += jQuery( this ).val() + ',';
 524          }
 525      } );
 526  
 527      if( users.length > 0 )
 528      {    // Delete last comma
 529          users = users.substr( 0, users.length-1 );
 530      }
 531  
 532      return users;
 533  }
 534  </script>
 535  <?php
 536  }
 537  
 538  ?>

title

Description

title

Description

title

Description

title

title

Body