[ Index ]
 

Code source de Zen Cart E-Commerce Shopping Cart 1.3.7.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/includes/classes/ -> currencies.php (source)

   1  <?php
   2  /**

   3   * currencies Class.

   4   *

   5   * @package classes

   6   * @copyright Copyright 2003-2006 Zen Cart Development Team

   7   * @copyright Portions Copyright 2003 osCommerce

   8   * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0

   9   * @version $Id: currencies.php 3041 2006-02-15 21:56:45Z wilt $

  10   */
  11  if (!defined('IS_ADMIN_FLAG')) {
  12    die('Illegal Access');
  13  }
  14  /**

  15   * currencies Class.

  16   * Class to handle currencies

  17   *

  18   * @package classes

  19   */
  20  class currencies extends base {
  21    var $currencies;
  22  
  23    // class constructor

  24    function currencies() {
  25      global $db;
  26      $this->currencies = array();
  27      $currencies_query = "select code, title, symbol_left, symbol_right, decimal_point,
  28                                    thousands_point, decimal_places, value
  29                            from " . TABLE_CURRENCIES;
  30  
  31      $currencies = $db->Execute($currencies_query);
  32  
  33      while (!$currencies->EOF) {
  34        $this->currencies[$currencies->fields['code']] = array('title' => $currencies->fields['title'],
  35        'symbol_left' => $currencies->fields['symbol_left'],
  36        'symbol_right' => $currencies->fields['symbol_right'],
  37        'decimal_point' => $currencies->fields['decimal_point'],
  38        'thousands_point' => $currencies->fields['thousands_point'],
  39        'decimal_places' => $currencies->fields['decimal_places'],
  40        'value' => $currencies->fields['value']);
  41  
  42        $currencies->MoveNext();
  43      }
  44    }
  45  
  46    // class methods

  47    function format($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
  48  
  49      if (empty($currency_type)) $currency_type = $_SESSION['currency'];
  50  
  51      if ($calculate_currency_value == true) {
  52        $rate = (zen_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
  53        $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
  54      } else {
  55        $format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(zen_round($number, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
  56      }
  57  
  58      if ((DOWN_FOR_MAINTENANCE=='true' and DOWN_FOR_MAINTENANCE_PRICES_OFF=='true') and (!strstr(EXCLUDE_ADMIN_IP_FOR_MAINTENANCE, $_SERVER['REMOTE_ADDR']))) {
  59        $format_string= '';
  60      }
  61  
  62      return $format_string;
  63    }
  64  
  65    function value($number, $calculate_currency_value = true, $currency_type = '', $currency_value = '') {
  66  
  67      if (empty($currency_type)) $currency_type = $_SESSION['currency'];
  68  
  69      if ($calculate_currency_value == true) {
  70        if ($currency_type == DEFAULT_CURRENCY) {
  71          $rate = (zen_not_null($currency_value)) ? $currency_value : 1/$this->currencies[$_SESSION['currency']]['value'];
  72        } else {
  73          $rate = (zen_not_null($currency_value)) ? $currency_value : $this->currencies[$currency_type]['value'];
  74        }
  75        $currency_value = zen_round($number * $rate, $this->currencies[$currency_type]['decimal_places']);
  76      } else {
  77        $currency_value = zen_round($number, $this->currencies[$currency_type]['decimal_places']);
  78      }
  79  
  80      return $currency_value;
  81    }
  82  
  83    function is_set($code) {
  84      if (isset($this->currencies[$code]) && zen_not_null($this->currencies[$code])) {
  85        return true;
  86      } else {
  87        return false;
  88      }
  89    }
  90  
  91    function get_value($code) {
  92      return $this->currencies[$code]['value'];
  93    }
  94  
  95    function get_decimal_places($code) {
  96      return $this->currencies[$code]['decimal_places'];
  97    }
  98  
  99    function display_price($products_price, $products_tax, $quantity = 1) {
 100      return $this->format(zen_add_tax($products_price, $products_tax) * $quantity);
 101    }
 102  }
 103  ?>


Généré le : Mon Nov 26 16:45:43 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics