b2evolution PHP Cross Reference Blogging Systems

Source: /inc/regional/currencies.ctrl.php - 315 lines - 9990 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: currencies.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  31   */
  32  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  33  
  34  // Load Currency class (PHP4):
  35  load_class( 'regional/model/_currency.class.php', 'Currency' );
  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', 'currencies' );
  52  
  53  // Get action parameter from request:
  54  param_action();
  55  
  56  if( param( 'curr_ID', 'integer', '', true) )
  57  {// Load currency from cache:
  58      $CurrencyCache = & get_CurrencyCache();
  59      if( ($edited_Currency = & $CurrencyCache->get_by_ID( $curr_ID, false )) === false )
  60      {    unset( $edited_Currency );
  61          forget_param( 'curr_ID' );
  62          $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Currency') ), 'error' );
  63          $action = 'nil';
  64      }
  65  }
  66  
  67  switch( $action )
  68  {
  69      case 'disable_currency':
  70      case 'enable_currency':
  71          // Check that this action request is not a CSRF hacked request:
  72          $Session->assert_received_crumb( 'currency' );
  73  
  74          // Disable a currency only if it is enabled, and user has edit access.
  75          $current_User->check_perm( 'options', 'edit', true );
  76  
  77          // Make sure the currency information was loaded. If not, just exit with error.
  78          if( empty($edited_Currency) )
  79          {
  80              $Messages->add( sprintf( 'The currency with ID %d could not be instantiated.', $curr_ID ), 'error' );
  81              break;
  82          }
  83  
  84          if ( $action == 'disable_currency' )
  85          {    // Disable this currency by setting flag to false.
  86              $edited_Currency->set( 'enabled', 0 );
  87              $Messages->add( sprintf( T_('Disabled currency (%s, #%d).'), $edited_Currency->name, $edited_Currency->ID ), 'success' );
  88          }
  89          elseif ( $action == 'enable_currency' )
  90          {    // Enable currency by setting flag to true.
  91              $edited_Currency->set( 'enabled', 1 );
  92              $Messages->add( sprintf( T_('Enabled currency (%s, #%d).'), $edited_Currency->name, $edited_Currency->ID ), 'success' );
  93          }
  94  
  95          // Update db with new flag value.
  96          $edited_Currency->dbupdate();
  97  
  98          param( 'results_curr_page', 'integer', '', true );
  99          param( 'results_curr_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 'new':
 107          // Check permission:
 108          $current_User->check_perm( 'options', 'edit', true );
 109  
 110          if( ! isset($edited_Currency) )
 111          {    // We don't have a model to use, start with blank object:
 112              $edited_Currency = new Currency();
 113          }
 114          else
 115          {    // Duplicate object in order no to mess with the cache:
 116              $edited_Currency = duplicate( $edited_Currency ); // PHP4/5 abstraction
 117              $edited_Currency->ID = 0;
 118          }
 119          break;
 120  
 121      case 'edit':
 122          // Check permission:
 123          $current_User->check_perm( 'options', 'edit', true );
 124  
 125          // Make sure we got an curr_ID:
 126          param( 'curr_ID', 'integer', true );
 127           break;
 128  
 129      case 'create': // Record new currency
 130      case 'create_new': // Record currency and create new
 131      case 'create_copy': // Record currency and create similar
 132          // Insert new currency:
 133          $edited_Currency = new Currency();
 134  
 135          // Check that this action request is not a CSRF hacked request:
 136          $Session->assert_received_crumb( 'currency' );
 137  
 138          // Check permission:
 139          $current_User->check_perm( 'options', 'edit', true );
 140  
 141          // Load data from request
 142          if( $edited_Currency->load_from_Request() )
 143          {    // We could load data from form without errors:
 144  
 145              // Insert in DB:
 146              $DB->begin();
 147              $q = $edited_Currency->dbexists();
 148              if($q)
 149              {    // We have a duplicate entry:
 150  
 151                  param_error( 'curr_code',
 152                      sprintf( T_('This currency already exists. Do you want to <a %s>edit the existing currency</a>?'),
 153                          'href="?ctrl=currencies&amp;action=edit&amp;curr_ID='.$q.'"' ) );
 154              }
 155              else
 156              {
 157                  $edited_Currency->dbinsert();
 158                  $Messages->add( T_('New currency created.'), 'success' );
 159              }
 160              $DB->commit();
 161  
 162              if( empty($q) )
 163              {    // What next?
 164  
 165                  switch( $action )
 166                  {
 167                      case 'create_copy':
 168                          // Redirect so that a reload doesn't write to the DB twice:
 169                          header_redirect( '?ctrl=currencies&action=new&curr_ID='.$edited_Currency->ID, 303 ); // Will EXIT
 170                          // We have EXITed already at this point!!
 171                          break;
 172                      case 'create_new':
 173                          // Redirect so that a reload doesn't write to the DB twice:
 174                          header_redirect( '?ctrl=currencies&action=new', 303 ); // Will EXIT
 175                          // We have EXITed already at this point!!
 176                          break;
 177                      case 'create':
 178                          // Redirect so that a reload doesn't write to the DB twice:
 179                          header_redirect( '?ctrl=currencies', 303 ); // Will EXIT
 180                          // We have EXITed already at this point!!
 181                          break;
 182                  }
 183              }
 184          }
 185          break;
 186  
 187      case 'update':
 188          // Edit currency form:
 189  
 190          // Check that this action request is not a CSRF hacked request:
 191          $Session->assert_received_crumb( 'currency' );
 192  
 193          // Check permission:
 194          $current_User->check_perm( 'options', 'edit', true );
 195  
 196          // Make sure we got an curr_ID:
 197          param( 'curr_ID', 'integer', true );
 198  
 199          // load data from request
 200          if( $edited_Currency->load_from_Request() )
 201          {    // We could load data from form without errors:
 202  
 203              // Update in DB:
 204              $DB->begin();
 205              $q = $edited_Currency->dbexists();
 206              if($q)
 207              {     // We have a duplicate entry:
 208                  param_error( 'curr_code',
 209                      sprintf( T_('This currency already exists. Do you want to <a %s>edit the existing currency</a>?'),
 210                          'href="?ctrl=currencies&amp;action=edit&amp;curr_ID='.$q.'"' ) );
 211              }
 212              else
 213              {
 214                  $edited_Currency->dbupdate();
 215                  $Messages->add( T_('Currency updated.'), 'success' );
 216              }
 217              $DB->commit();
 218  
 219              if( empty($q) )
 220              {    // If no error, Redirect so that a reload doesn't write to the DB twice:
 221                  header_redirect( '?ctrl=currencies', 303 ); // Will EXIT
 222                  // We have EXITed already at this point!!
 223              }
 224          }
 225          break;
 226  
 227      case 'delete':
 228          // Delete currency:
 229  
 230          // Check that this action request is not a CSRF hacked request:
 231          $Session->assert_received_crumb( 'currency' );
 232  
 233          // Check permission:
 234          $current_User->check_perm( 'options', 'edit', true );
 235  
 236          // Make sure we got an curr_ID:
 237          param( 'curr_ID', 'integer', true );
 238  
 239          if( param( 'confirm', 'integer', 0 ) )
 240          { // confirmed, Delete from DB:
 241              $msg = sprintf( T_('Currency &laquo;%s&raquo; deleted.'), $edited_Currency->dget('name') );
 242              $edited_Currency->dbdelete( true );
 243              unset( $edited_Currency );
 244              forget_param( 'curr_ID' );
 245              $Messages->add( $msg, 'success' );
 246              // Redirect so that a reload doesn't write to the DB twice:
 247              header_redirect( '?ctrl=currencies', 303 ); // Will EXIT
 248              // We have EXITed already at this point!!
 249          }
 250          else
 251          {    // not confirmed, Check for restrictions:
 252              if( ! $edited_Currency->check_delete( sprintf( T_('Cannot delete currency &laquo;%s&raquo;'), $edited_Currency->dget('name') ), array(), true ) )
 253              {    // There are restrictions:
 254                  $action = 'view';
 255              }
 256          }
 257          break;
 258  
 259  }
 260  
 261  
 262  $AdminUI->breadcrumbpath_init( false );
 263  $AdminUI->breadcrumbpath_add( T_('System'), '?ctrl=system',
 264          T_('Global settings are shared between all blogs; see Blog settings for more granular settings.') );
 265  $AdminUI->breadcrumbpath_add( T_('Regional settings'), '?ctrl=locales' );
 266  $AdminUI->breadcrumbpath_add( T_('Currencies'), '?ctrl=currencies' );
 267  
 268  
 269  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 270  $AdminUI->disp_html_head();
 271  
 272  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 273  $AdminUI->disp_body_top();
 274  
 275  $AdminUI->disp_payload_begin();
 276  
 277  /**
 278   * Display payload:
 279   */
 280  switch( $action )
 281  {
 282      case 'nil':
 283          // Do nothing
 284          break;
 285  
 286  
 287      case 'delete':
 288          // We need to ask for confirmation:
 289          $edited_Currency->confirm_delete(
 290                  sprintf( T_('Delete currency &laquo;%s&raquo;?'), $edited_Currency->dget('name') ),
 291                  'currency', $action, get_memorized( 'action' ) );
 292      case 'new':
 293      case 'create':
 294      case 'create_new':
 295      case 'create_copy':
 296      case 'edit':
 297      case 'update':
 298          $AdminUI->disp_view( 'regional/views/_currency.form.php' );
 299          break;
 300  
 301      default:
 302          // No specific request, list all currencies:
 303          // Cleanup context:
 304          forget_param( 'curr_ID' );
 305          // Display currency list:
 306          $AdminUI->disp_view( 'regional/views/_currency_list.view.php' );
 307          break;
 308  }
 309  
 310  $AdminUI->disp_payload_end();
 311  
 312  // Display body bottom, debug info and close </html>:
 313  $AdminUI->disp_global_footer();
 314  
 315  ?>

title

Description

title

Description

title

Description

title

title

Body