Quick Search:

View

Revision:

Diff

Diff from 399 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 /*
hpdl
153
3   $Id: currencies.php 399 2006-01-25 06:08:03Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
386
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Currencies {
hpdl
386
14     var $currencies = array();
hpdl
1
15
16 // class constructor
17     function osC_Currencies() {
18       global $osC_Database;
19
hpdl
386
20       $Qcurrencies = $osC_Database->query('select * from :table_currencies');
21       $Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES);
22       $Qcurrencies->setCache('currencies');
hpdl
1
23       $Qcurrencies->execute();
24
25       while ($Qcurrencies->next()) {
hpdl
386
26         $this->currencies[$Qcurrencies->value('code')] = array('id' => $Qcurrencies->valueInt('currencies_id'),
27                                                                'title' => $Qcurrencies->value('title'),
hpdl
1
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       }
hpdl
386
33
34       $Qcurrencies->freeResult();
hpdl
1
35     }
36
37 // class methods
38     function format($number, $currency_code = '', $currency_value = '') {
hpdl
386
39       global $osC_Language;
40
hpdl
1
41       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
hpdl
199
42         $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY);
hpdl
1
43       }
44
45       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
46         $currency_value = $this->currencies[$currency_code]['value'];
47       }
48
hpdl
386
49       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'], $osC_Language->getNumericDecimalSeparator(), $osC_Language->getNumericThousandsSeparator()) . $this->currencies[$currency_code]['symbol_right'];
hpdl
1
50     }
51
52     function displayPrice($price, $tax_class_id, $quantity = 1) {
53       global $osC_Tax;
54
55       $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
56
57       if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax_class_id > 0) ) {
58         $price += tep_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
59       }
60
61       return $this->format($price * $quantity);
62     }
63
64     function exists($code) {
65       if (isset($this->currencies[$code])) {
66         return true;
67       }
68
69       return false;
70     }
71
72     function decimalPlaces($code) {
73       if ($this->exists($code)) {
74         return $this->currencies[$code]['decimal_places'];
75       }
76
77       return false;
78     }
79
80     function value($code) {
81       if ($this->exists($code)) {
82         return $this->currencies[$code]['value'];
83       }
84
85       return false;
86     }
hpdl
386
87
88     function getCode($id = '') {
89       if (is_numeric($id)) {
90         foreach ($this->currencies as $key => $value) {
hpdl
399
91           if ($value['id'] == $id) {
hpdl
386
92             return $key;
93           }
94         }
95       } else {
96         return $_SESSION['currency'];
97       }
98     }
hpdl
387
99
100     function getID($code = '') {
101       if (empty($code)) {
102         $code = $_SESSION['currency'];
103       }
104
105       return $this->currencies[$code]['id'];
106     }
hpdl
1
107   }
108 ?>