b2evolution PHP Cross Reference Blogging Systems

Source: /inc/users/views/_userfields.view.php - 276 lines - 8765 bytes - Summary - Text - Print

Description: 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 is part of the evoCore framework - {@link http://evocore.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   * {@internal License choice
  10   * - If you have received this file as part of a package, please find the license.txt file in
  11   *   the same folder or the closest folder above for complete license terms.
  12   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
  13   *   then you must choose one of the following licenses before using the file:
  14   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
  15   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
  16   * }}
  17   *
  18   * {@internal Open Source relicensing agreement:
  19   * The Evo Factory grants Francois PLANQUE the right to license
  20   * The Evo Factory's contributions to this file and the b2evolution project
  21   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  22   * }}
  23   *
  24   * @package evocore
  25   *
  26   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  27   * @author evofactory-test
  28   * @author fplanque: Francois Planque.
  29   *
  30   * @version  $Id: _userfields.view.php 6136 2014-03-08 07:59:48Z manuel $
  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  load_class( 'users/model/_userfield.class.php', 'Userfield' );
  35  
  36  global $dispatcher;
  37  
  38  // query which groups have user field definitions (in order to prevent deletion of groups which have user field definitions)
  39  global $usedgroups;    // We need this in a callback below
  40  $usedgroups = $DB->get_col( 'SELECT ufgp_ID
  41              FROM T_users__fieldgroups INNER JOIN T_users__fielddefs ON ufdf_ufgp_ID = ufgp_ID
  42              GROUP BY ufgp_ID' );
  43  
  44  // Get IDs of userfields that first/last in the own group, to hide action icon "move up/down"
  45  global $userfields_group_sides;
  46  $userfields_group_sides = array();
  47  $userfields_group_sides['first'] = $DB->get_col( 'SELECT ufdf_ID
  48              FROM T_users__fielddefs f1
  49              WHERE ufdf_order =
  50                      ( SELECT MIN(f2.ufdf_order)
  51                          FROM T_users__fielddefs f2
  52                          WHERE f2.ufdf_ufgp_ID = f1.ufdf_ufgp_ID )
  53              GROUP BY ufdf_ufgp_ID' );
  54  $userfields_group_sides['last'] = $DB->get_col( 'SELECT ufdf_ID
  55              FROM T_users__fielddefs f1
  56              WHERE ufdf_order =
  57                      ( SELECT MAX(f2.ufdf_order)
  58                          FROM T_users__fielddefs f2
  59                          WHERE f2.ufdf_ufgp_ID = f1.ufdf_ufgp_ID )
  60              GROUP BY ufdf_ufgp_ID' );
  61  
  62  // Get params from request
  63  $s = param( 's', 'string', '', true );
  64  $s_type = param( 's_type', 'string', '', true );
  65  
  66  // Create query
  67  $SQL = new SQL();
  68  $SQL->SELECT( '*' );
  69  $SQL->FROM( 'T_users__fielddefs RIGHT JOIN T_users__fieldgroups ON ufdf_ufgp_ID = ufgp_ID' );
  70  
  71  $where_clause = '';
  72  
  73  if( !empty($s) )
  74  {    // We want to filter on search keyword:
  75      // Note: we use CONCAT_WS (Concat With Separator) because CONCAT returns NULL if any arg is NULL
  76      $where_clause = 'CONCAT_WS( " ", ufdf_name ) LIKE "%'.$DB->escape($s).'%"';
  77  }
  78  
  79  if( !empty( $s_type ) )
  80  {    // We want to filter on user field type:
  81      $where_clause = 'ufdf_type LIKE "%'.$DB->escape($s_type).'%"';
  82  }
  83  
  84  if( $where_clause != '' )
  85  {
  86      $SQL->WHERE_and( $where_clause );
  87  }
  88  $SQL->GROUP_BY( 'ufdf_ID, ufgp_ID' );
  89  $SQL->ORDER_BY( 'ufgp_order, ufgp_name, ufdf_order' );
  90  
  91  $count_sql = 'SELECT COUNT(*)
  92                                FROM T_users__fielddefs';
  93  if( $where_clause != '' )
  94  {
  95      $count_sql .= ' WHERE '.$where_clause;
  96  }
  97  
  98  // Create result set:
  99  $Results = new Results( $SQL->get(), 'ufdf_', 'A', NULL, $count_sql );
 100  
 101  $Results->title = T_('User fields').get_manual_link('user-fields-list');
 102  
 103  /**
 104   * Callback to enumerate possible user field types
 105   *
 106   */
 107  function enumerate_types( $selected = '' ) {
 108      $options = '<option value="">All</option>';
 109      foreach( Userfield::get_types() as $type_code => $type_name ) {
 110          $options .= '<option value="'.$type_code.'" ';
 111          if( $type_code == $selected ) $options .= '"selected" ';
 112          $options .= '>'.$type_name.'</option>';
 113      }
 114      return $options;
 115  }
 116  
 117  /**
 118   * Callback to add filters on top of the result set
 119   *
 120   * @param Form
 121   */
 122  function filter_userfields( & $Form )
 123  {
 124      $Form->text( 's', get_param('s'), 30, T_('Search'), '', 255 );
 125      $Form->select( 's_type', get_param( 's_type' ), 'enumerate_types', T_('Type'), '', ''  );
 126  }
 127  
 128  $Results->filter_area = array(
 129      'callback' => 'filter_userfields',
 130      'presets' => array(
 131          'all' => array( T_('All'), '?ctrl=userfields' ),
 132          )
 133      );
 134  
 135  
 136  /*
 137   * Grouping params:
 138   */
 139  $Results->group_by = 'ufgp_ID';
 140  $Results->ID_col = 'ufdf_ID';
 141  
 142  
 143  /*
 144   * Group columns:
 145   */
 146  $group_td_colspan = $current_User->check_perm( 'users', 'edit', false ) ? -2 : 0;
 147  $Results->grp_cols[] = array(
 148                          'td_colspan' => $group_td_colspan,
 149                          'td' => '<a href="?ctrl=userfieldsgroups&amp;action=edit&amp;ufgp_ID=$ufgp_ID$">$ufgp_name$</a>',
 150                      );
 151  if( $current_User->check_perm( 'users', 'edit', false ) )
 152  {    // We have permission to modify:
 153      $Results->grp_cols[] = array(
 154                              'td' => '$ufgp_order$',
 155                              'td_class' => 'center',
 156                          );
 157  
 158  	function grp_actions( & $row )
 159      {
 160          global $usedgroups, $current_User;
 161  
 162          $r = '';
 163          if( $current_User->check_perm( 'users', 'edit', false ) )
 164          {
 165              $r = action_icon( T_('Edit this group...'), 'edit', regenerate_url( 'ctrl,action', 'ctrl=userfieldsgroups&amp;action=edit&amp;ufgp_ID='.$row->ufgp_ID ) )
 166                      .action_icon( T_('Duplicate this group...'), 'copy', regenerate_url( 'ctrl,action', 'ctrl=userfieldsgroups&amp;action=new&amp;ufgp_ID='.$row->ufgp_ID ) );
 167  
 168              if( !in_array( $row->ufgp_ID, $usedgroups ) )
 169              { // delete
 170                  $r .= action_icon( T_('Delete this group!'), 'delete', regenerate_url( 'ctrl,action', 'ctrl=userfieldsgroups&amp;action=delete&amp;ufgp_ID='.$row->ufgp_ID.'&amp;'.url_crumb('userfieldgroup') ) );
 171              }
 172              else
 173              {
 174                  $r .= get_icon( 'delete', 'noimg' );
 175              }
 176          }
 177          return $r;
 178      }
 179      $Results->grp_cols[] = array(
 180                              'td_class' => 'shrinkwrap',
 181                              'td' => '%grp_actions( {row} )%',
 182                          );
 183  }
 184  
 185  
 186  /*
 187   * Data columns:
 188   */
 189  $Results->cols[] = array(
 190          'th' => T_('Name'),
 191          'td' => '<a href="%regenerate_url( \'action\', \'ufdf_ID=$ufdf_ID$&amp;action=edit\' )%"><strong>%T_(#ufdf_name#)%</strong></a>',
 192      );
 193  
 194  $Results->cols[] = array(
 195      'th' => T_('Type'),
 196      'td' => '%T_(#ufdf_type#)%',
 197  );
 198  
 199  $Results->cols[] = array(
 200          'th' => T_('Required?'),
 201          'td' => '%get_userfield_required( #ufdf_required# )%',
 202          'td_class' => 'center',
 203      );
 204  
 205  $Results->cols[] = array(
 206          'th' => T_('Multiple values'),
 207          'td' => '$ufdf_duplicated$',
 208          'td_class' => 'center',
 209      );
 210  
 211  if( $current_User->check_perm( 'users', 'edit', false ) )
 212  {    // We have permission to modify:
 213  	function order_actions( & $row )
 214      {
 215          global $userfields_group_sides;
 216  
 217          $r = '';
 218  
 219          if( in_array( $row->ufdf_ID, $userfields_group_sides['first'] ) )
 220          {    // First record, no change ordering, print blank icon
 221              $r .= get_icon( 'move_down', 'noimg' );
 222          }
 223          else
 224          {
 225              $r .= action_icon( T_('Move up'), 'move_up',
 226                      regenerate_url( 'ctrl,action', 'ctrl=userfields&amp;ufdf_ID='.$row->ufdf_ID.'&amp;action=move_up&amp;'.url_crumb('userfield') ) );
 227          }
 228  
 229          if( in_array( $row->ufdf_ID, $userfields_group_sides['last'] ) )
 230          {    // Last record, no change ordering, print blank icon
 231              $r .= get_icon( 'move_down', 'noimg' );
 232          }
 233          else
 234          {
 235              $r .= action_icon( T_('Move down'), 'move_down',
 236                      regenerate_url( 'ctrl,action', 'ctrl=userfields&amp;ufdf_ID='.$row->ufdf_ID.'&amp;action=move_down&amp;'.url_crumb('userfield') ) );
 237          }
 238  
 239          return $r;
 240      }
 241  
 242      $Results->cols[] = array(
 243              'th' => T_('Order'),
 244              'td' => '%order_actions( {row} )%',
 245              'td_class' => 'shrinkwrap',
 246          );
 247  
 248  	function fld_actions( & $row )
 249      {
 250          $r = action_icon( T_('Edit this user field...'), 'edit',
 251                      regenerate_url( 'ctrl,action', 'ctrl=userfields&amp;ufdf_ID='.$row->ufdf_ID.'&amp;action=edit') )
 252                  .action_icon( T_('Duplicate this user field...'), 'copy',
 253                      regenerate_url( 'ctrl,action', 'ctrl=userfields&amp;ufdf_ID='.$row->ufdf_ID.'&amp;action=new') )
 254                  .action_icon( T_('Delete this user field!'), 'delete',
 255                      regenerate_url( 'ctrl,action', 'ctrl=userfields&amp;ufdf_ID='.$row->ufdf_ID.'&amp;action=delete&amp;'.url_crumb('userfield') ) );
 256  
 257          return $r;
 258      }
 259  
 260      $Results->cols[] = array(
 261                              'th' => T_('Actions'),
 262                              'td_class' => 'shrinkwrap',
 263                              'td' => '%fld_actions( {row} )%',
 264                          );
 265  
 266      $Results->global_icon( T_('Create a new user field...'), 'new',
 267                  '?ctrl=userfields&action=new', T_('New user field').' &raquo;', 3, 4 );
 268      $Results->global_icon( T_('Create a new user field group...'), 'new',
 269                  '?ctrl=userfieldsgroups&action=new', T_('New user field group').' &raquo;', 3, 4 );
 270  }
 271  
 272  
 273  // Display results:
 274  $Results->display();
 275  
 276  ?>

title

Description

title

Description

title

Description

title

title

Body