b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/subregions.ctrl.php - 355 lines - 12092 bytes - 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: subregions.ctrl.php 88 2011-10-26 18:45:27Z yura $

  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  // Load Subregion class (PHP4):

  35  load_class( 'regional/model/_subregion.class.php', 'Subregion' );
  36  load_funcs( 'regional/model/_regional.funcs.php' );
  37  
  38  /**

  39   * @var User

  40   */
  41  global $current_User;
  42  
  43  // Check minimum permission:

  44  $current_User->check_perm( 'options', 'view', true );
  45  
  46  // Memorize this as the last "tab" used in the Global Settings:

  47  $UserSettings->set( 'pref_glob_settings_tab', $ctrl );
  48  $UserSettings->set( 'pref_glob_regional_tab', $ctrl );
  49  $UserSettings->dbupdate();
  50  
  51  // Set options path:

  52  $AdminUI->set_path( 'options', 'regional', 'subregions' );
  53  
  54  // Get action parameter from request:

  55  param_action();
  56  
  57  if( param( 'subrg_ID', 'integer', '', true) )
  58  {    // Load subregion from cache:
  59      $SubregionCache = & get_SubregionCache();
  60      if( ($edited_Subregion = & $SubregionCache->get_by_ID( $subrg_ID, false )) === false )
  61      {    unset( $edited_Subregion );
  62          forget_param( 'subrg_ID' );
  63          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Region') ), 'error' );
  64          $action = 'nil';
  65      }
  66  }
  67  
  68  switch( $action )
  69  {
  70      case 'disable_subregion':
  71      case 'enable_subregion':
  72          // Check that this action request is not a CSRF hacked request:

  73          $Session->assert_received_crumb( 'subregion' );
  74  
  75          // Disable a subregion only if it is enabled, and user has edit access.

  76          $current_User->check_perm( 'options', 'edit', true );
  77  
  78          // Make sure the subregion information was loaded. If not, just exit with error.

  79          if( empty($edited_Subregion) )
  80          {
  81              $Messages->add( sprintf( 'The sub-region with ID %d could not be instantiated.', $subrg_ID ), 'error' );
  82              break;
  83          }
  84  
  85          if ( $action == 'disable_subregion' )
  86          {    // Disable this subregion by setting flag to false.
  87              $edited_Subregion->set( 'enabled', 0 );
  88              $Messages->add( sprintf( T_('Disabled sub-region (%s, #%d).'), $edited_Subregion->name, $edited_Subregion->ID ), 'success' );
  89          }
  90          elseif ( $action == 'enable_subregion' )
  91          {    // Enable subregion by setting flag to true.
  92              $edited_Subregion->set( 'enabled', 1 );
  93              $Messages->add( sprintf( T_('Enabled sub-region (%s, #%d).'), $edited_Subregion->name, $edited_Subregion->ID ), 'success' );
  94          }
  95  
  96          // Update db with new flag value.

  97          $edited_Subregion->dbupdate();
  98  
  99          param( 'results_subrg_page', 'integer', '', true );
 100          param( 'results_subrg_order', 'string', '', true );
 101  
 102          // Redirect so that a reload doesn't write to the DB twice:

 103          header_redirect( regenerate_url( '', '', '', '&' ), 303 ); // Will EXIT

 104          // We have EXITed already at this point!!

 105          break;
 106  
 107      case 'enable_subregion_pref':
 108      case 'disable_subregion_pref':
 109  
 110          // Check that this action request is not a CSRF hacked request:

 111          $Session->assert_received_crumb( 'subregion' );
 112  
 113          // Disable a subregion only if it is enabled, and user has edit access.

 114          $current_User->check_perm( 'options', 'edit', true );
 115  
 116          // Make sure the subregion information was loaded. If not, just exit with error.

 117          if( empty($edited_Subregion) )
 118          {
 119              $Messages->add( sprintf( 'The sub-region with ID %d could not be instantiated.', $subrg_ID ), 'error' );
 120              break;
 121          }
 122  
 123          if ( $action == 'disable_subregion_pref' )
 124          {    // Disable this subregion by setting flag to false.
 125              $edited_Subregion->set( 'preferred', 0 );
 126              $Messages->add( sprintf( T_('Removed from preferred sub-regions (%s, #%d).'), $edited_Subregion->name, $edited_Subregion->ID ), 'success' );
 127          }
 128          elseif ( $action == 'enable_subregion_pref' )
 129          {    // Enable subregion by setting flag to true.
 130              $edited_Subregion->set( 'preferred', 1 );
 131              $Messages->add( sprintf( T_('Added to preferred sub-regions (%s, #%d).'), $edited_Subregion->name, $edited_Subregion->ID ), 'success' );
 132          }
 133  
 134          // Update db with new flag value.

 135          $edited_Subregion->dbupdate();
 136  
 137          param( 'results_subrg_page', 'integer', '', true );
 138          param( 'results_subrg_order', 'string', '', true );
 139  
 140          // Redirect so that a reload doesn't write to the DB twice:

 141          header_redirect( regenerate_url( '', '', '', '&' ), 303 ); // Will EXIT

 142          // We have EXITed already at this point!!

 143          break;
 144  
 145      case 'new':
 146          // Check permission:

 147          $current_User->check_perm( 'options', 'edit', true );
 148  
 149          if( ! isset($edited_Subregion) )
 150          {    // We don't have a model to use, start with blank object:
 151              $edited_Subregion = new Subregion();
 152          }
 153          else
 154          {    // Duplicate object in order no to mess with the cache:
 155              $edited_Subregion = duplicate( $edited_Subregion ); // PHP4/5 abstraction

 156              $edited_Subregion->ID = 0;
 157          }
 158          break;
 159  
 160      case 'edit':
 161          // Check permission:

 162          $current_User->check_perm( 'options', 'edit', true );
 163  
 164          // Make sure we got an subrg_ID:

 165          param( 'subrg_ID', 'integer', true );
 166           break;
 167  
 168      case 'create': // Record new subregion
 169      case 'create_new': // Record subregion and create new
 170      case 'create_copy': // Record subregion and create similar
 171          // Insert new subregion:

 172          $edited_Subregion = new Subregion();
 173  
 174          // Check that this action request is not a CSRF hacked request:

 175          $Session->assert_received_crumb( 'subregion' );
 176  
 177          // Check permission:

 178          $current_User->check_perm( 'options', 'edit', true );
 179  
 180          // Load data from request

 181          if( $edited_Subregion->load_from_Request() )
 182          {    // We could load data from form without errors:
 183  
 184              // Insert in DB:

 185              $DB->begin();
 186              $q = $edited_Subregion->dbexists();
 187              if($q)
 188              {    // We have a duplicate entry:
 189  
 190                  param_error( 'subrg_code',
 191                      sprintf( T_('This sub-region already exists. Do you want to <a %s>edit the existing sub-region</a>?'),
 192                          'href="?ctrl=subregions&amp;action=edit&amp;subrg_ID='.$q.'"' ) );
 193              }
 194              else
 195              {
 196                  unset( $edited_Subregion->dbchanges['subrg_ctry_ID'] );
 197                  $edited_Subregion->dbinsert();
 198                  $Messages->add( T_('New region created.'), 'success' );
 199              }
 200              $DB->commit();
 201  
 202              if( empty($q) )
 203              {    // What next?
 204  
 205                  switch( $action )
 206                  {
 207                      case 'create_copy':
 208                          // Redirect so that a reload doesn't write to the DB twice:

 209                          header_redirect( '?ctrl=subregions&action=new&subrg_ID='.$edited_Subregion->ID, 303 ); // Will EXIT

 210                          // We have EXITed already at this point!!

 211                          break;
 212                      case 'create_new':
 213                          // Redirect so that a reload doesn't write to the DB twice:

 214                          header_redirect( '?ctrl=subregions&action=new', 303 ); // Will EXIT

 215                          // We have EXITed already at this point!!

 216                          break;
 217                      case 'create':
 218                          // Redirect so that a reload doesn't write to the DB twice:

 219                          header_redirect( '?ctrl=subregions', 303 ); // Will EXIT

 220                          // We have EXITed already at this point!!

 221                          break;
 222                  }
 223              }
 224          }
 225          break;
 226  
 227      case 'update':
 228          // Edit subregion form:

 229  
 230          // Check that this action request is not a CSRF hacked request:

 231          $Session->assert_received_crumb( 'subregion' );
 232  
 233          // Check permission:

 234          $current_User->check_perm( 'options', 'edit', true );
 235  
 236          // Make sure we got an subrg_ID:

 237          param( 'subrg_ID', 'integer', true );
 238  
 239          // load data from request

 240          if( $edited_Subregion->load_from_Request() )
 241          {    // We could load data from form without errors:
 242  
 243              // Update in DB:

 244              $DB->begin();
 245              $q = $edited_Subregion->dbexists();
 246              if($q)
 247              {    // We have a duplicate entry:
 248                  param_error( 'subrg_code',
 249                      sprintf( T_('This sub-region already exists. Do you want to <a %s>edit the existing sub-region</a>?'),
 250                          'href="?ctrl=subregions&amp;action=edit&amp;subrg_ID='.$q.'"' ) );
 251              }
 252              else
 253              {
 254                  unset( $edited_Subregion->dbchanges['subrg_ctry_ID'] );
 255                  $edited_Subregion->dbupdate();
 256                  $Messages->add( T_('Region updated.'), 'success' );
 257              }
 258              $DB->commit();
 259  
 260              if( empty($q) )
 261              {    // If no error, Redirect so that a reload doesn't write to the DB twice:
 262                  header_redirect( '?ctrl=subregions', 303 ); // Will EXIT

 263                  // We have EXITed already at this point!!

 264              }
 265          }
 266          break;
 267  
 268      case 'delete':
 269          // Delete subregion:

 270  
 271          // Check that this action request is not a CSRF hacked request:

 272          $Session->assert_received_crumb( 'subregion' );
 273  
 274          // Check permission:

 275          $current_User->check_perm( 'options', 'edit', true );
 276  
 277          // Make sure we got an subrg_ID:

 278          param( 'subrg_ID', 'integer', true );
 279  
 280          if( param( 'confirm', 'integer', 0 ) )
 281          { // confirmed, Delete from DB:
 282              $msg = sprintf( T_('Region &laquo;%s&raquo; deleted.'), $edited_Subregion->dget('name') );
 283              $edited_Subregion->dbdelete( true );
 284              unset( $edited_Subregion );
 285              forget_param( 'subrg_ID' );
 286              $Messages->add( $msg, 'success' );
 287              // Redirect so that a reload doesn't write to the DB twice:

 288              header_redirect( '?ctrl=subregions', 303 ); // Will EXIT

 289              // We have EXITed already at this point!!

 290          }
 291          else
 292          {    // not confirmed, Check for restrictions:
 293              if( ! $edited_Subregion->check_delete( sprintf( T_('Cannot delete sub-region &laquo;%s&raquo;'), $edited_Subregion->dget('name') ) ) )
 294              {    // There are restrictions:
 295                  $action = 'view';
 296              }
 297          }
 298          break;
 299  
 300  }
 301  
 302  
 303  $AdminUI->breadcrumbpath_init( false );
 304  $AdminUI->breadcrumbpath_add( T_('System'), '?ctrl=system',
 305          T_('Global settings are shared between all blogs; see Blog settings for more granular settings.') );
 306  $AdminUI->breadcrumbpath_add( T_('Regional settings'), '?ctrl=locales' );
 307  $AdminUI->breadcrumbpath_add( T_('Sub-regions'), '?ctrl=subregions' );
 308  
 309  
 310  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)

 311  $AdminUI->disp_html_head();
 312  
 313  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)

 314  $AdminUI->disp_body_top();
 315  
 316  $AdminUI->disp_payload_begin();
 317  
 318  /**

 319   * Display payload:

 320   */
 321  switch( $action )
 322  {
 323      case 'nil':
 324          // Do nothing

 325          break;
 326  
 327      case 'delete':
 328          // We need to ask for confirmation:

 329          $edited_Subregion->confirm_delete(
 330                  sprintf( T_('Delete sub-region &laquo;%s&raquo;?'), $edited_Subregion->dget('name') ),
 331                  'subregion', $action, get_memorized( 'action' ) );
 332      case 'new':
 333      case 'create':
 334      case 'create_new':
 335      case 'create_copy':
 336      case 'edit':
 337      case 'update':
 338          $AdminUI->disp_view( 'regional/views/_subregion.form.php' );
 339          break;
 340  
 341      default:
 342          // No specific request, list all subregions:

 343          // Cleanup context:

 344          forget_param( 'subrg_ID' );
 345          // Display subregions list:

 346          $AdminUI->disp_view( 'regional/views/_subregion_list.view.php' );
 347          break;
 348  }
 349  
 350  $AdminUI->disp_payload_end();
 351  
 352  // Display body bottom, debug info and close </html>:

 353  $AdminUI->disp_global_footer();
 354  
 355  ?>

title

Description

title

Description

title

Description

title

title

Body