b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/regions.ctrl.php - 352 lines - 11553 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: regions.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 Region class (PHP4):

  35  load_class( 'regional/model/_region.class.php', 'Region' );
  36  
  37  /**

  38   * @var User

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

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

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

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

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

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

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

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

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

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

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

 104          break;
 105  
 106      case 'enable_region_pref':
 107      case 'disable_region_pref':
 108  
 109          // Check that this action request is not a CSRF hacked request:

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

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

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

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

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

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

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

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

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

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

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

 171          $edited_Region = new Region();
 172  
 173          // Check that this action request is not a CSRF hacked request:

 174          $Session->assert_received_crumb( 'region' );
 175  
 176          // Check permission:

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

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

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

 207                          header_redirect( '?ctrl=regions&action=new&rgn_ID='.$edited_Region->ID, 303 ); // Will EXIT

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

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

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

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

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

 217                          header_redirect( '?ctrl=regions', 303 ); // Will EXIT

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

 219                          break;
 220                  }
 221              }
 222          }
 223          break;
 224  
 225      case 'update':
 226          // Edit region form:

 227  
 228          // Check that this action request is not a CSRF hacked request:

 229          $Session->assert_received_crumb( 'region' );
 230  
 231          // Check permission:

 232          $current_User->check_perm( 'options', 'edit', true );
 233  
 234          // Make sure we got an rgn_ID:

 235          param( 'rgn_ID', 'integer', true );
 236  
 237          // load data from request

 238          if( $edited_Region->load_from_Request() )
 239          {    // We could load data from form without errors:
 240  
 241              // Update in DB:

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

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

 261              }
 262          }
 263          break;
 264  
 265      case 'delete':
 266          // Delete region:

 267  
 268          // Check that this action request is not a CSRF hacked request:

 269          $Session->assert_received_crumb( 'region' );
 270  
 271          // Check permission:

 272          $current_User->check_perm( 'options', 'edit', true );
 273  
 274          // Make sure we got an rgn_ID:

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

 285              header_redirect( '?ctrl=regions', 303 ); // Will EXIT

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

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

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

 311  $AdminUI->disp_body_top();
 312  
 313  $AdminUI->disp_payload_begin();
 314  
 315  /**

 316   * Display payload:

 317   */
 318  switch( $action )
 319  {
 320      case 'nil':
 321          // Do nothing

 322          break;
 323  
 324      case 'delete':
 325          // We need to ask for confirmation:

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

 340          // Cleanup context:

 341          forget_param( 'rgn_ID' );
 342          // Display regions list:

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

 350  $AdminUI->disp_global_footer();
 351  
 352  ?>

title

Description

title

Description

title

Description

title

title

Body