Quick Search:

View

Revision:

Diff

Diff from 1 to:

Annotations

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

Annotated File View

hpdl
1
1 <?php
2 /*
3   $Id: currencies.php,v 1.21 2004/07/22 16:01:55 hpdl Exp $
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       global $osC_Session;
38
39       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
40         $currency_code = ($osC_Session->exists('currency') ? $osC_Session->value('currency') : DEFAULT_CURRENCY);
41       }
42
43       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
44         $currency_value = $this->currencies[$currency_code]['value'];
45       }
46
47       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'];
48     }
49
50     function displayPrice($price, $tax_class_id, $quantity = 1) {
51       global $osC_Tax;
52
53       $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
54
55       if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax_class_id > 0) ) {
56         $price += tep_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
57       }
58
59       return $this->format($price * $quantity);
60     }
61
62     function exists($code) {
63       if (isset($this->currencies[$code])) {
64         return true;
65       }
66
67       return false;
68     }
69
70     function decimalPlaces($code) {
71       if ($this->exists($code)) {
72         return $this->currencies[$code]['decimal_places'];
73       }
74
75       return false;
76     }
77
78     function value($code) {
79       if ($this->exists($code)) {
80         return $this->currencies[$code]['value'];
81       }
82
83       return false;
84     }
85   }
86 ?>