[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/kernel/shop/ -> editcurrency.php (source)

   1  <?php
   2  //
   3  // Created on: <08-Nov-2005 13:06:15 dl>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  /*! \file editcurrency.php
  28  */
  29  
  30  include_once ( 'kernel/shop/classes/ezcurrencydata.php' );
  31  include_once ( 'lib/ezutils/classes/ezini.php' );
  32  include_once ( 'kernel/shop/classes/ezshopfunctions.php' );
  33  include_once ( 'kernel/classes/ezcontentcachemanager.php' );
  34  
  35  $module =& $Params['Module'];
  36  
  37  $ini =& eZINI::instance( 'site.ini' );
  38  
  39  $error = false;
  40  $originalCurrencyCode =& $Params['Currency'];
  41  $currencyParams = array( 'code' => false,
  42                           'symbol' => false,
  43                           'locale' => $ini->variable( 'RegionalSettings', 'Locale' ),
  44                           'custom_rate_value' => '0.0000',
  45                           'rate_factor' => '1.0000' );
  46  
  47  if ( $module->isCurrentAction( 'Cancel' ) )
  48  {
  49      return $module->redirectTo( $module->functionURI( 'currencylist' ) );
  50  }
  51  else if ( $module->isCurrentAction( 'Create' ) )
  52  {
  53      if ( $module->hasActionParameter( 'CurrencyData' ) )
  54          $currencyParams = $module->actionParameter( 'CurrencyData' );
  55  
  56      if ( $errCode = eZCurrencyData::canCreate( $currencyParams['code'] ) )
  57      {
  58          $error = eZCurrencyData::errorMessage( $errCode );
  59      }
  60      else
  61      {
  62          eZShopFunctions::createCurrency( $currencyParams );
  63          eZContentCacheManager::clearAllContentCache();
  64  
  65          return $module->redirectTo( $module->functionURI( 'currencylist' ) );
  66      }
  67  }
  68  else if ( $module->isCurrentAction( 'StoreChanges' ) )
  69  {
  70      $originalCurrencyCode = $module->hasActionParameter( 'OriginalCurrencyCode' ) ? $module->actionParameter( 'OriginalCurrencyCode' ) : '';
  71      if ( $module->hasActionParameter( 'CurrencyData' ) )
  72          $currencyParams = $module->actionParameter( 'CurrencyData' );
  73  
  74      $errCode = eZShopFunctions::changeCurrency( $originalCurrencyCode, $currencyParams['code'] );
  75      if ( $errCode === EZ_CURRENCYDATA_ERROR_OK )
  76      {
  77          $currency = eZCurrencyData::fetch( $currencyParams['code'] );
  78          if ( is_object( $currency ) )
  79          {
  80              $currency->setAttribute( 'symbol', $currencyParams['symbol'] );
  81              $currency->setAttribute( 'locale', $currencyParams['locale'] );
  82              $currency->setAttribute( 'custom_rate_value', $currencyParams['custom_rate_value'] );
  83              $currency->setAttribute( 'rate_factor', $currencyParams['rate_factor'] );
  84  
  85              $db =& eZDB::instance();
  86              $db->begin();
  87              $currency->sync();
  88              $db->commit();
  89  
  90              eZContentCacheManager::clearAllContentCache();
  91  
  92              return $module->redirectTo( $module->functionURI( 'currencylist' ) );
  93          }
  94          else
  95          {
  96              $error = eZCurrencyData::errorMessage( $currency );
  97          }
  98      }
  99      else
 100      {
 101          $error = eZCurrencyData::errorMessage( $errCode );
 102      }
 103  }
 104  
 105  $canEdit = true;
 106  $pathText = '';
 107  if ( strlen( $originalCurrencyCode ) > 0 )
 108  {
 109      // going to edit existing currency
 110      $pathText = ezi18n( 'kernel/shop', 'Edit currency' );
 111  
 112      if ( $currencyParams['code'] === false )
 113      {
 114          // first time in 'edit' mode? => initialize template variables
 115          // with existing data.
 116          include_once ( 'kernel/shop/classes/ezcurrencydata.php' );
 117  
 118          $currency = eZCurrencyData::fetch( $originalCurrencyCode );
 119          if ( is_object( $currency ) )
 120          {
 121              $currencyParams['code'] = $currency->attribute( 'code' );
 122              $currencyParams['symbol'] = $currency->attribute( 'symbol' );
 123              $currencyParams['locale'] = $currency->attribute( 'locale' );
 124              $currencyParams['custom_rate_value'] = $currency->attribute( 'custom_rate_value' );
 125              $currencyParams['rate_factor'] = $currency->attribute( 'rate_factor' );
 126          }
 127          else
 128          {
 129              $error = "'$originalCurrencyCode' currency  doesn't exist.";
 130              $canEdit = false;
 131          }
 132      }
 133  }
 134  else
 135  {
 136      // going to create new currency
 137      $pathText = ezi18n( 'kernel/shop', 'Create new currency' );
 138  }
 139  
 140  include_once ( 'kernel/common/template.php' );
 141  $tpl =& templateInit();
 142  
 143  $tpl->setVariable( 'error', $error );
 144  $tpl->setVariable( 'can_edit', $canEdit );
 145  $tpl->setVariable( 'original_currency_code', $originalCurrencyCode );
 146  $tpl->setVariable( 'currency_data', $currencyParams );
 147  
 148  $Result = array();
 149  $Result['content'] =& $tpl->fetch( "design:shop/editcurrency.tpl" );
 150  $Result['path'] = array( array( 'text' => $pathText,
 151                                  'url' => false ) );
 152  
 153  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7