b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/views/_city_list.view.php - 322 lines - 10313 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: _city_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  $sr = param( 'sr', 'integer', 0, true ); // Sub-region

  42  
  43  // Create query

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

  56      $sql_where[] = 'CONCAT_WS( " ", city_postcode, city_name ) LIKE "%'.$DB->escape($s).'%"';
  57  }
  58  if( $c > 0 )
  59  {    // Filter by country:
  60      $sql_where[] = 'ctry_ID = "'.$DB->escape($c).'"';
  61  }
  62  if( $r > 0 )
  63  {    // Filter by region:
  64      $sql_where[] = 'rgn_ID = "'.$DB->escape($r).'"';
  65  }
  66  if( $sr > 0 )
  67  {    // Filter by sub-region:
  68      $sql_where[] = 'subrg_ID = "'.$DB->escape($sr).'"';
  69  }
  70  
  71  if( count( $sql_where ) > 0 )
  72  {    // Some filters are applied
  73      $SQL->WHERE( implode( ' AND ', $sql_where ) );
  74  }
  75  
  76  // Create result set:

  77  //echo $SQL->get();

  78  $Results = new Results( $SQL->get(), 'city_', '-----A' );
  79  
  80  $Results->title = T_('Cities').get_manual_link('countries_list');
  81  
  82  /*

  83   * STATUS TD:

  84   */
  85  function city_td_enabled( $city_enabled, $city_ID )
  86  {
  87  
  88      global $dispatcher;
  89  
  90      $r = '';
  91  
  92      if( $city_enabled == true )
  93      {
  94          $r .= action_icon( T_('Disable the city!'), 'bullet_full',
  95                                          regenerate_url( 'action', 'action=disable_city&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
  96      }
  97      else
  98      {
  99          $r .= action_icon( T_('Enable the city!'), 'bullet_empty',
 100                                          regenerate_url( 'action', 'action=enable_city&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
 101      }
 102      return $r;
 103  
 104  }
 105  
 106  function city_td_preferred( $city_preferred, $city_ID )
 107  {
 108  
 109      global $dispatcher;
 110  
 111      $r = '';
 112  
 113      if( $city_preferred == true )
 114      {
 115          $r .= action_icon( T_('Remove from preferred cities'), 'bullet_full',
 116                                          regenerate_url( 'action', 'action=disable_city_pref&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
 117      }
 118      else
 119      {
 120          $r .= action_icon( T_('Add to preferred cities'), 'bullet_empty',
 121                                          regenerate_url( 'action', 'action=enable_city_pref&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
 122      }
 123      return $r;
 124  
 125  }
 126  
 127  
 128  
 129  $Results->cols[] = array(
 130          'th' => /* TRANS: shortcut for enabled */ T_('En'),
 131          'th_title' => T_('Enabled'),
 132          'order' => 'city_enabled',
 133          'td' => '%city_td_enabled( #city_enabled#, #city_ID# )%',
 134          'th_class' => 'shrinkwrap',
 135          'td_class' => 'shrinkwrap'
 136      );
 137  
 138  $Results->cols[] = array(
 139          'th' => /* TRANS: shortcut for preferred */ T_('Pref'),
 140          'th_title' => T_('Preferred'),
 141          'order' => 'city_preferred',
 142          'default_dir' => 'D',
 143          'td' => '%city_td_preferred( #city_preferred# , #city_ID# )%',
 144          'th_class' => 'shrinkwrap',
 145          'td_class' => 'shrinkwrap'
 146      );
 147  
 148  
 149  /**

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

 151   *

 152   * @param Form

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

 242   * ACTIONS TD:

 243   */
 244  function city_td_actions($city_enabled, $city_ID )
 245  {
 246      global $dispatcher;
 247  
 248      $r = '';
 249  
 250      if( $city_enabled == true )
 251      {
 252          $r .= action_icon( T_('Disable the city!'), 'deactivate', 
 253                                          regenerate_url( 'action', 'action=disable_city&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
 254      }
 255      else
 256      {
 257          $r .= action_icon( T_('Enable the city!'), 'activate',
 258                                          regenerate_url( 'action', 'action=enable_city&amp;city_ID='.$city_ID.'&amp;'.url_crumb('city') ) );
 259      }
 260      $r .= action_icon( T_('Edit this city...'), 'edit',
 261                                          regenerate_url( 'action', 'city_ID='.$city_ID.'&amp;action=edit' ) );
 262      $r .= action_icon( T_('Duplicate this city...'), 'copy',
 263                                          regenerate_url( 'action', 'city_ID='.$city_ID.'&amp;action=new' ) );
 264      $r .= action_icon( T_('Delete this city!'), 'delete',
 265                                          regenerate_url( 'action', 'city_ID='.$city_ID.'&amp;action=delete&amp;'.url_crumb('city') ) );
 266  
 267      return $r;
 268  }
 269  if( $current_User->check_perm( 'options', 'edit', false ) )
 270  {
 271      $Results->cols[] = array(
 272              'th' => T_('Actions'),
 273              'td' => '%city_td_actions( #city_enabled#, #city_ID# )%',
 274              'td_class' => 'shrinkwrap',
 275          );
 276  
 277      $Results->global_icon( T_('Create a new city ...'), 'new',
 278                  regenerate_url( 'action', 'action=new'), T_('New city').' &raquo;', 3, 4  );
 279  
 280      $Results->global_icon( T_('Import cities from CSV file ...'), 'new',
 281                  regenerate_url( 'action', 'action=csv'), T_('Import CSV').' &raquo;', 3, 4  );
 282  }
 283  
 284  $Results->display();
 285  
 286  ?>
 287  <script type="text/javascript">
 288  jQuery( '#c' ).change( function ()
 289  {    // Load option list with regions for seleted country
 290      jQuery.ajax( {
 291      type: 'POST',
 292      url: '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php',
 293      data: 'action=get_regions_option_list&mode=load_subregions&ctry_id=' + jQuery( this ).val(),
 294      success: function( result )
 295          {
 296              result = ajax_debug_clear( result );
 297              var options = result.split( '-##-' );
 298  
 299              jQuery( '#r' ).html( options[0] );
 300              jQuery( '#sr' ).html( options[1] );
 301          }
 302      } );
 303  } );
 304  
 305  jQuery( '#r' ).change( function ()
 306  {    // Change option list with sub-regions
 307      load_subregions( jQuery( this ).val() );
 308  } );
 309  
 310  function load_subregions( region_ID )
 311  {    // Load option list with sub-regions for seleted region
 312      jQuery.ajax( {
 313      type: 'POST',
 314      url: '<?php echo get_samedomain_htsrv_url(); ?>anon_async.php',
 315      data: 'action=get_subregions_option_list&rgn_id=' + region_ID,
 316      success: function( result )
 317          {
 318              jQuery( '#sr' ).html( ajax_debug_clear( result ) );
 319          }
 320      } );
 321  }
 322  </script>

title

Description

title

Description

title

Description

title

title

Body