Quick Search:

View

Revision:

Diff

Diff from 538 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 538 2006-04-27 16:53:59Z 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
hpdl
484
52     function formatRaw($number, $currency_code = '', $currency_value = '') {
53       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
54         $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY);
55       }
56
57       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
58         $currency_value = $this->currencies[$currency_code]['value'];
59       }
60
61       return number_format(tep_round($number * $currency_value, $this->currencies[$currency_code]['decimal_places']), $this->currencies[$currency_code]['decimal_places'], '.', '');
62     }
63
hpdl
1
64     function displayPrice($price, $tax_class_id, $quantity = 1) {
65       global $osC_Tax;
66
67       $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
68
hpdl
500
69       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_class_id > 0) ) {
hpdl
1
70         $price += tep_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
71       }
72
73       return $this->format($price * $quantity);
74     }
75
hpdl
538
76     function displayPriceWithTaxRate($price, $tax_rate, $quantity = 1, $currency_code = '', $currency_value = '') {
77       global $osC_Tax;
78
79       $price = tep_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
80
81       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_rate > 0) ) {
82         $price += tep_round($price * ($tax_rate / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
83       }
84
85       return $this->format($price * $quantity, $currency_code, $currency_value);
86     }
87
hpdl
1
88     function exists($code) {
89       if (isset($this->currencies[$code])) {
90         return true;
91       }
92
93       return false;
94     }
95
96     function decimalPlaces($code) {
97       if ($this->exists($code)) {
98         return $this->currencies[$code]['decimal_places'];
99       }
100
101       return false;
102     }
103
104     function value($code) {
105       if ($this->exists($code)) {
106         return $this->currencies[$code]['value'];
107       }
108
109       return false;
110     }
hpdl
386
111
112     function getCode($id = '') {
113       if (is_numeric($id)) {
114         foreach ($this->currencies as $key => $value) {
hpdl
399
115           if ($value['id'] == $id) {
hpdl
386
116             return $key;
117           }
118         }
119       } else {
120         return $_SESSION['currency'];
121       }
122     }
hpdl
387
123
124     function getID($code = '') {
125       if (empty($code)) {
126         $code = $_SESSION['currency'];
127       }
128
129       return $this->currencies[$code]['id'];
130     }
hpdl
1
131   }
132 ?>