b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/views/_country_list.view.php - 247 lines - 7313 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 efy-maxim: Evo Factory / Maxim.
  28   * @author fplanque: Francois Planque.
  29   *
  30   * @version $Id: _country_list.view.php 6136 2014-03-08 07:59:48Z manuel $
  31   */
  32  
  33  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  34  
  35  load_class( 'regional/model/_currency.class.php', 'Currency' );
  36  load_funcs( 'regional/model/_regional.funcs.php' );
  37  
  38  global $dispatcher;
  39  
  40  // Get params from request
  41  $s = param( 's', 'string', '', true );
  42  
  43  // Create query
  44  $SQL = new SQL();
  45  $SQL->SELECT( 'ctry_ID, ctry_code, ctry_name, curr_shortcut, curr_code, ctry_enabled, ctry_preferred' );
  46  $SQL->FROM( 'T_regional__country' );
  47  $SQL->FROM_add( 'LEFT JOIN T_regional__currency ON ctry_curr_ID=curr_ID' );
  48  $SQL->ORDER_BY( '*, ctry_code ASC' );
  49  
  50  if( !empty($s) )
  51  {    // We want to filter on search keyword:
  52      // Note: we use CONCAT_WS (Concat With Separator) because CONCAT returns NULL if any arg is NULL
  53      $SQL->WHERE( 'CONCAT_WS( " ", ctry_code, ctry_name, curr_code ) LIKE "%'.$DB->escape($s).'%"' );
  54  }
  55  
  56  // Create result set:
  57  $Results = new Results( $SQL->get(), 'ctry_', '-D' );
  58  
  59  $Results->title = T_('Countries').get_manual_link('countries_list');
  60  
  61  /*
  62   * STATUS TD:
  63   */
  64  function ctry_td_enabled( $ctry_enabled, $ctry_ID )
  65  {
  66  
  67      global $dispatcher;
  68  
  69      $r = '';
  70  
  71      if( $ctry_enabled == true )
  72      {
  73          $r .= action_icon( T_('Disable the country!'), 'bullet_full',
  74                                          regenerate_url( 'action', 'action=disable_country&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
  75      }
  76      else
  77      {
  78          $r .= action_icon( T_('Enable the country!'), 'bullet_empty',
  79                                          regenerate_url( 'action', 'action=enable_country&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
  80      }
  81      return $r;
  82  
  83  }
  84  
  85  function ctry_td_preferred( $ctry_preferred, $ctry_ID )
  86  {
  87  
  88      global $dispatcher;
  89  
  90      $r = '';
  91  
  92      if( $ctry_preferred == true )
  93      {
  94          $r .= action_icon( T_('Remove from preferred countries'), 'bullet_full',
  95                                          regenerate_url( 'action', 'action=disable_country_pref&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
  96      }
  97      else
  98      {
  99          $r .= action_icon( T_('Add to preferred countries'), 'bullet_empty',
 100                                          regenerate_url( 'action', 'action=enable_country_pref&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
 101      }
 102      return $r;
 103  
 104  }
 105  
 106  
 107  
 108  $Results->cols[] = array(
 109          'th' => /* TRANS: shortcut for enabled */ T_('En'),
 110          'th_title' => T_('Enabled'),
 111          'order' => 'ctry_enabled',
 112          'td' => '%ctry_td_enabled( #ctry_enabled#, #ctry_ID# )%',
 113          'th_class' => 'shrinkwrap',
 114          'td_class' => 'shrinkwrap'
 115      );
 116  
 117  $Results->cols[] = array(
 118          'th' => /* TRANS: shortcut for preferred */ T_('Pref'),
 119          'th_title' => T_('Preferred'),
 120          'order' => 'ctry_preferred',
 121          'default_dir' => 'D',
 122          'td' => '%ctry_td_preferred( #ctry_preferred# , #ctry_ID# )%',
 123          'th_class' => 'shrinkwrap',
 124          'td_class' => 'shrinkwrap'
 125      );
 126  
 127  
 128  /**
 129   * Callback to add filters on top of the result set
 130   *
 131   * @param Form
 132   */
 133  function filter_countries( & $Form )
 134  {
 135      $Form->text( 's', get_param('s'), 30, T_('Search'), '', 255 );
 136  }
 137  
 138  $Results->filter_area = array(
 139      'callback' => 'filter_countries',
 140      'presets' => array(
 141          'all' => array( T_('All'), '?ctrl=countries' ),
 142          )
 143      );
 144  
 145  $Results->cols[] = array(
 146                          'th' => T_('Code'),
 147                          'td_class' => 'center',
 148                          'order' => 'ctry_code',
 149                          'td' => '<strong>$ctry_code$</strong>',
 150                      );
 151  
 152  
 153  if( $current_User->check_perm( 'options', 'edit', false ) )
 154  { // We have permission to modify:
 155      $Results->cols[] = array(
 156                              'th' => T_('Name'),
 157                              'order' => 'ctry_name',
 158                              'td' => '<a href="?ctrl=countries&amp;ctry_ID=$ctry_ID$&amp;action=edit" title="'.T_('Edit this country...').'">
 159                                      %country_flag( #ctry_code#, #ctry_name# )% <strong>$ctry_name$</strong>
 160                                  </a>',
 161                          );
 162  }
 163  else
 164  {    // View only:
 165      $Results->cols[] = array(
 166                              'th' => T_('Name'),
 167                              'order' => 'ctry_name',
 168                              'td' => '%country_flag( #ctry_code#, #ctry_name# )% $ctry_name$',
 169                          );
 170  
 171  }
 172  
 173  function country_regions_count( $country_ID )
 174  {
 175      global $DB, $admin_url;
 176      
 177      $regions_count = $DB->get_var( '
 178          SELECT COUNT(rgn_ID)
 179            FROM T_regional__region
 180           WHERE rgn_ctry_ID = "'.$country_ID.'"' );
 181      
 182      if( $regions_count > 0 )
 183      {
 184          $regions_count = '<a href="'.$admin_url.'?ctrl=regions&amp;c='.$country_ID.'">'.$regions_count.'</a>';
 185      }
 186  
 187      return $regions_count;
 188  }
 189  
 190  $Results->cols[] = array(
 191                          'th' => T_('Regions'),
 192                          'td_class' => 'center',
 193                          'td' => '%country_regions_count( #ctry_ID# )%',
 194                          'th_class' => 'shrinkwrap',
 195                          'td_class' => 'shrinkwrap'
 196                      );
 197  
 198  $Results->cols[] = array(
 199                          'th' => T_('Default Currency'),
 200                          'td_class' => 'center',
 201                          'order' => 'curr_code',
 202                          'td' => '$curr_shortcut$ $curr_code$',
 203                      );
 204  
 205  /*
 206   * ACTIONS TD:
 207   */
 208  function ctry_td_actions($ctry_enabled, $ctry_ID )
 209  {
 210      global $dispatcher;
 211  
 212      $r = '';
 213  
 214      if( $ctry_enabled == true )
 215      {
 216          $r .= action_icon( T_('Disable the country!'), 'deactivate', 
 217                                          regenerate_url( 'action', 'action=disable_country&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
 218      }
 219      else
 220      {
 221          $r .= action_icon( T_('Enable the country!'), 'activate',
 222                                          regenerate_url( 'action', 'action=enable_country&amp;ctry_ID='.$ctry_ID.'&amp;'.url_crumb('country') ) );
 223      }
 224      $r .= action_icon( T_('Edit this country...'), 'edit',
 225                                          regenerate_url( 'action', 'ctry_ID='.$ctry_ID.'&amp;action=edit' ) );
 226      $r .= action_icon( T_('Duplicate this country...'), 'copy',
 227                                          regenerate_url( 'action', 'ctry_ID='.$ctry_ID.'&amp;action=new' ) );
 228      $r .= action_icon( T_('Delete this country!'), 'delete',
 229                                          regenerate_url( 'action', 'ctry_ID='.$ctry_ID.'&amp;action=delete&amp;'.url_crumb('country') ) );
 230  
 231      return $r;
 232  }
 233  if( $current_User->check_perm( 'options', 'edit', false ) )
 234  {
 235      $Results->cols[] = array(
 236              'th' => T_('Actions'),
 237              'td' => '%ctry_td_actions( #ctry_enabled#, #ctry_ID# )%',
 238              'td_class' => 'shrinkwrap',
 239          );
 240  
 241      $Results->global_icon( T_('Create a new country ...'), 'new',
 242                  regenerate_url( 'action', 'action=new'), T_('New country').' &raquo;', 3, 4  );
 243  }
 244  
 245  $Results->display();
 246  
 247  ?>

title

Description

title

Description

title

Description

title

title

Body