b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/views/_subregion_list.view.php - 278 lines - 8934 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: _subregion_list.view.php 13 2011-10-24 23:42:53Z fplanque $

  31   */
  32  
  33  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  34  
  35  global $dispatcher;
  36  
  37  // Get params from request

  38  $s = param( 's', 'string', '', true ); // Search keyword

  39  $c = param( 'c', 'integer', 0, true ); // Country

  40  $r = param( 'r', 'integer', 0, true ); // Region

  41  
  42  // Create query

  43  $SQL = new SQL();
  44  $SQL->SELECT( 'subrg_ID, subrg_code, subrg_name, subrg_enabled, subrg_preferred, ctry_ID, ctry_name, rgn_ID, rgn_name' );
  45  $SQL->FROM( 'T_regional__subregion' );
  46  $SQL->FROM_add( 'LEFT JOIN T_regional__region ON subrg_rgn_ID=rgn_ID' );
  47  $SQL->FROM_add( 'LEFT JOIN T_regional__country ON rgn_ctry_ID=ctry_ID' );
  48  $SQL->ORDER_BY( '*, ctry_name, rgn_name' );
  49  
  50  $sql_where = array();
  51  if( !empty($s) )
  52  {    // We want to filter on search keyword:
  53      // Note: we use CONCAT_WS (Concat With Separator) because CONCAT returns NULL if any arg is NULL

  54      $sql_where[] = 'CONCAT_WS( " ", subrg_code, subrg_name ) LIKE "%'.$DB->escape($s).'%"';
  55  }
  56  if( $c > 0 )
  57  {    // Filter by country:
  58      $sql_where[] = 'ctry_ID = "'.$DB->escape($c).'"';
  59  }
  60  if( $r > 0 )
  61  {    // Filter by region:
  62      $sql_where[] = 'subrg_rgn_ID = "'.$DB->escape($r).'"';
  63  }
  64  
  65  if( count( $sql_where ) > 0 )
  66  {    // Some filters are applied
  67      $SQL->WHERE( implode( ' AND ', $sql_where ) );
  68  }
  69  
  70  // Create result set:

  71  $Results = new Results( $SQL->get(), 'subrg_', '-D' );
  72  
  73  $Results->title = T_('Sub-regions/Departments/Counties').get_manual_link('countries_list');
  74  
  75  /*

  76   * STATUS TD:

  77   */
  78  function subrg_td_enabled( $subrg_enabled, $subrg_ID )
  79  {
  80  
  81      global $dispatcher;
  82  
  83      $r = '';
  84  
  85      if( $subrg_enabled == true )
  86      {
  87          $r .= action_icon( T_('Disable the sub-region!'), 'bullet_full',
  88                                          regenerate_url( 'action', 'action=disable_subregion&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
  89      }
  90      else
  91      {
  92          $r .= action_icon( T_('Enable the sub-region!'), 'bullet_empty',
  93                                          regenerate_url( 'action', 'action=enable_subregion&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
  94      }
  95      return $r;
  96  
  97  }
  98  
  99  function subrg_td_preferred( $subrg_preferred, $subrg_ID )
 100  {
 101  
 102      global $dispatcher;
 103  
 104      $r = '';
 105  
 106      if( $subrg_preferred == true )
 107      {
 108          $r .= action_icon( T_('Remove from preferred sub-regions'), 'bullet_full',
 109                                          regenerate_url( 'action', 'action=disable_subregion_pref&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
 110      }
 111      else
 112      {
 113          $r .= action_icon( T_('Add to preferred sub-regions'), 'bullet_empty',
 114                                          regenerate_url( 'action', 'action=enable_subregion_pref&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
 115      }
 116      return $r;
 117  
 118  }
 119  
 120  
 121  
 122  $Results->cols[] = array(
 123          'th' => /* TRANS: shortcut for enabled */ T_('En'),
 124          'th_title' => T_('Enabled'),
 125          'order' => 'subrg_enabled',
 126          'td' => '%subrg_td_enabled( #subrg_enabled#, #subrg_ID# )%',
 127          'th_class' => 'shrinkwrap',
 128          'td_class' => 'shrinkwrap'
 129      );
 130  
 131  $Results->cols[] = array(
 132          'th' => /* TRANS: shortcut for preferred */ T_('Pref'),
 133          'th_title' => T_('Preferred'),
 134          'order' => 'subrg_preferred',
 135          'default_dir' => 'D',
 136          'td' => '%subrg_td_preferred( #subrg_preferred# , #subrg_ID# )%',
 137          'th_class' => 'shrinkwrap',
 138          'td_class' => 'shrinkwrap'
 139      );
 140  
 141  
 142  /**

 143   * Callback to add filters on top of the result set

 144   *

 145   * @param Form

 146   */
 147  function filter_subregions( & $Form )
 148  {
 149      load_class( 'regional/model/_country.class.php', 'Country' );
 150      $CountryCache = & get_CountryCache( T_('All') );
 151      $Form->select_country( 'c', get_param('c'), $CountryCache, T_('Country'), array( 'allow_none' => true ) );
 152      
 153      $Form->select_input_options( 'r', get_regions_option_list( get_param('c'), get_param('r') ), T_('Region') );
 154  
 155      $Form->text( 's', get_param('s'), 30, T_('Search'), '', 255 );
 156  }
 157  
 158  $Results->filter_area = array(
 159      'callback' => 'filter_subregions',
 160      'presets' => array(
 161          'all' => array( T_('All'), '?ctrl=subregions' ),
 162          )
 163      );
 164  
 165  
 166  if( $current_User->check_perm( 'options', 'edit', false ) )
 167  { // We have permission to modify:
 168      $Results->cols[] = array(
 169                              'th' => T_('Country'),
 170                              'order' => 'ctry_name',
 171                              'td' => '<a href="?ctrl=countries&amp;ctry_ID=$ctry_ID$&amp;action=edit" title="'.T_('Edit this country...').'"><strong>$ctry_name$</strong></a>',
 172                          );
 173      $Results->cols[] = array(
 174                              'th' => T_('Region'),
 175                              'order' => 'rgn_name',
 176                              'td' => '<a href="?ctrl=regions&amp;rgn_ID=$rgn_ID$&amp;action=edit" title="'.T_('Edit this region...').'"><strong>$rgn_name$</strong></a>',
 177                          );
 178  }
 179  else
 180  {    // View only:
 181      $Results->cols[] = array(
 182                              'th' => T_('Country'),
 183                              'order' => 'ctry_name',
 184                              'td' => '$ctry_name$',
 185                          );
 186      $Results->cols[] = array(
 187                              'th' => T_('Region'),
 188                              'order' => 'rgn_name',
 189                              'td' => '$rgn_name$',
 190                          );
 191  }
 192  
 193  
 194  $Results->cols[] = array(
 195                          'th' => T_('Code'),
 196                          'td_class' => 'center',
 197                          'order' => 'subrg_code',
 198                          'td' => '<strong>$subrg_code$</strong>',
 199                          'th_class' => 'shrinkwrap',
 200                          'td_class' => 'shrinkwrap'
 201                      );
 202  
 203  
 204  if( $current_User->check_perm( 'options', 'edit', false ) )
 205  { // We have permission to modify:
 206      $Results->cols[] = array(
 207                              'th' => T_('Name'),
 208                              'order' => 'subrg_name',
 209                              'td' => '<a href="?ctrl=subregions&amp;subrg_ID=$subrg_ID$&amp;action=edit" title="'.T_('Edit this sub-region...').'"><strong>$subrg_name$</strong></a>',
 210                          );
 211  }
 212  else
 213  {    // View only:
 214      $Results->cols[] = array(
 215                              'th' => T_('Name'),
 216                              'order' => 'subrg_name',
 217                              'td' => '$subrg_name$',
 218                          );
 219  
 220  }
 221  
 222  /*

 223   * ACTIONS TD:

 224   */
 225  function subrg_td_actions($subrg_enabled, $subrg_ID )
 226  {
 227      global $dispatcher;
 228  
 229      $r = '';
 230  
 231      if( $subrg_enabled == true )
 232      {
 233          $r .= action_icon( T_('Disable the sub-region!'), 'deactivate', 
 234                                          regenerate_url( 'action', 'action=disable_subregion&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
 235      }
 236      else
 237      {
 238          $r .= action_icon( T_('Enable the sub-region!'), 'activate',
 239                                          regenerate_url( 'action', 'action=enable_subregion&amp;subrg_ID='.$subrg_ID.'&amp;'.url_crumb('subregion') ) );
 240      }
 241      $r .= action_icon( T_('Edit this sub-region...'), 'edit',
 242                                          regenerate_url( 'action', 'subrg_ID='.$subrg_ID.'&amp;action=edit' ) );
 243      $r .= action_icon( T_('Duplicate this sub-region...'), 'copy',
 244                                          regenerate_url( 'action', 'subrg_ID='.$subrg_ID.'&amp;action=new' ) );
 245      $r .= action_icon( T_('Delete this sub-region!'), 'delete',
 246                                          regenerate_url( 'action', 'subrg_ID='.$subrg_ID.'&amp;action=delete&amp;'.url_crumb('subregion') ) );
 247  
 248      return $r;
 249  }
 250  if( $current_User->check_perm( 'options', 'edit', false ) )
 251  {
 252      $Results->cols[] = array(
 253              'th' => T_('Actions'),
 254              'td' => '%subrg_td_actions( #subrg_enabled#, #subrg_ID# )%',
 255              'td_class' => 'shrinkwrap',
 256          );
 257  
 258      $Results->global_icon( T_('Create a new sub-region...'), 'new',
 259                  regenerate_url( 'action', 'action=new'), T_('New sub-region').' &raquo;', 3, 4  );
 260  }
 261  
 262  $Results->display();
 263  
 264  ?>
 265  <script type="text/javascript">
 266  jQuery( '#c' ).change( function ()
 267  {    // Load option list with regions for seleted country
 268      jQuery.ajax( {
 269      type: 'POST',
 270      url: '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php',
 271      data: 'action=get_regions_option_list&ctry_id=' + jQuery( this ).val(),
 272      success: function( result )
 273          {
 274              jQuery( '#r' ).html( ajax_debug_clear( result ) );
 275          }
 276      } );
 277  } );
 278  </script>

title

Description

title

Description

title

Description

title

title

Body