Quick Search:

View

Revision:

Diff

Diff from 368 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/currencies.php

Annotated File View

hpdl
1
1 <?php
2 /*
mattice
151
3   $Id: currencies.php 368 2005-12-22 16:27:23Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2004 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Currencies {
14     var $currencies;
15
16 // class constructor
17     function osC_Currencies() {
18       global $osC_Database;
19
20       $this->currencies = array();
21
22       $Qcurrencies = $osC_Database->query('select code, title, symbol_left, symbol_right, decimal_places, value from :table_currencies');
23       $Qcurrencies->bindRaw(':table_currencies', TABLE_CURRENCIES);
24       $Qcurrencies->execute();
25
26       while ($Qcurrencies->next()) {
27         $this->currencies[$Qcurrencies->value('code')] = array('title' => $Qcurrencies->value('title'),
28                                                                'symbol_left' => $Qcurrencies->value('symbol_left'),
29                                                                'symbol_right' => $Qcurrencies->value('symbol_right'),
30                                                                'decimal_places' => $Qcurrencies->valueInt('decimal_places'),
31                                                                'value' => $Qcurrencies->valueDecimal('value'));
32       }
33     }
34
35 // class methods
36     function format($number, $currency_code = '', $currency_value = '') {
37       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
hpdl
368
38         $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY);
hpdl
1
39       }
40
41       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
42         $currency_value = $this->currencies[$currency_code]['value'];
43       }
44
45       return $this->currencies[$currency_code]['symbol_left'] . number_format(tep_round($number * $currency_value, $this->currencies[$currency_code]['decimal_places']), $this->currencies[$currency_code]['decimal_places'], NUMERIC_DECIMAL_SEPARATOR, NUMERIC_THOUSANDS_SEPARATOR) . $this->currencies[$currency_code]['symbol_right'];
46     }
47
48     function displayPrice($price, $tax_class_id, $quantity = 1) {
49       global $osC_Tax;
50
51       $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
52
53       if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax_class_id > 0) ) {
54         $price += tep_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
55       }
56
57       return $this->format($price * $quantity);
58     }
59
60     function exists($code) {
61       if (isset($this->currencies[$code])) {
62         return true;
63       }
64
65       return false;
66     }
67
68     function decimalPlaces($code) {
69       if ($this->exists($code)) {
70         return $this->currencies[$code]['decimal_places'];
71       }
72
73       return false;
74     }
75
76     function value($code) {
77       if ($this->exists($code)) {
78         return $this->currencies[$code]['value'];
79       }
80
81       return false;
82     }
83   }
84 ?>