Quick Search:

View

Revision:

Diff

Diff from 758 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 758 2006-08-23 12:30:07Z hpdl $
hpdl
1
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
hpdl
410
8   Copyright (c) 2006 osCommerce
hpdl
1
9
10   Released under the GNU General Public License
11 */
12
13   class osC_Currencies {
hpdl
410
14     var $currencies = array();
hpdl
1
15
16 // class constructor
17     function osC_Currencies() {
18       global $osC_Database;
19
hpdl
410
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
410
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
410
33
34       $Qcurrencies->freeResult();
hpdl
1
35     }
36
37 // class methods
38     function format($number, $currency_code = '', $currency_value = '') {
hpdl
410
39       global $osC_Language;
40
hpdl
1
41       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
hpdl
368
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
757
49       return $this->currencies[$currency_code]['symbol_left'] . number_format(osc_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
554
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
hpdl
757
61       return number_format(osc_round($number * $currency_value, $this->currencies[$currency_code]['decimal_places']), $this->currencies[$currency_code]['decimal_places'], '.', '');
hpdl
554
62     }
63
hpdl
758
64     function addTaxRateToPrice($price, $tax_rate, $quantity = 1) {
hpdl
1
65       global $osC_Tax;
66
hpdl
757
67       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
1
68
hpdl
757
69       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_rate > 0) ) {
70         $price += osc_round($price * ($tax_rate / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
71       }
72
hpdl
758
73       return osc_round($price * $quantity, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
757
74     }
75
76     function displayPrice($price, $tax_class_id, $quantity = 1, $currency_code = null, $currency_value = null) {
77       global $osC_Tax;
78
79       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
80
hpdl
554
81       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_class_id > 0) ) {
hpdl
757
82         $price += osc_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
1
83       }
84
hpdl
757
85       return $this->format($price * $quantity, $currency_code, $currency_value);
hpdl
1
86     }
87
hpdl
554
88     function displayPriceWithTaxRate($price, $tax_rate, $quantity = 1, $currency_code = '', $currency_value = '') {
89       global $osC_Tax;
90
hpdl
757
91       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
554
92
93       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_rate > 0) ) {
hpdl
757
94         $price += osc_round($price * ($tax_rate / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
554
95       }
96
97       return $this->format($price * $quantity, $currency_code, $currency_value);
98     }
99
hpdl
1
100     function exists($code) {
101       if (isset($this->currencies[$code])) {
102         return true;
103       }
104
105       return false;
106     }
107
108     function decimalPlaces($code) {
109       if ($this->exists($code)) {
110         return $this->currencies[$code]['decimal_places'];
111       }
112
113       return false;
114     }
115
116     function value($code) {
117       if ($this->exists($code)) {
118         return $this->currencies[$code]['value'];
119       }
120
121       return false;
122     }
hpdl
410
123
124     function getCode($id = '') {
125       if (is_numeric($id)) {
126         foreach ($this->currencies as $key => $value) {
127           if ($value['id'] == $id) {
128             return $key;
129           }
130         }
131       } else {
132         return $_SESSION['currency'];
133       }
134     }
135
136     function getID($code = '') {
137       if (empty($code)) {
138         $code = $_SESSION['currency'];
139       }
140
141       return $this->currencies[$code]['id'];
142     }
hpdl
1
143   }
144 ?>