Quick Search:

View

Revision:

Diff

Diff from 1497 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 1497 2007-03-29 13:40:05Z 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
hpdl
1497
10   This program is free software; you can redistribute it and/or modify
11   it under the terms of the GNU General Public License v2 (1991)
12   as published by the Free Software Foundation.
hpdl
1
13 */
14
15   class osC_Currencies {
hpdl
386
16     var $currencies = array();
hpdl
1
17
18 // class constructor
19     function osC_Currencies() {
20       global $osC_Database;
21
hpdl
386
22       $Qcurrencies = $osC_Database->query('select * from :table_currencies');
23       $Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES);
24       $Qcurrencies->setCache('currencies');
hpdl
1
25       $Qcurrencies->execute();
26
27       while ($Qcurrencies->next()) {
hpdl
386
28         $this->currencies[$Qcurrencies->value('code')] = array('id' => $Qcurrencies->valueInt('currencies_id'),
29                                                                'title' => $Qcurrencies->value('title'),
hpdl
1
30                                                                'symbol_left' => $Qcurrencies->value('symbol_left'),
31                                                                'symbol_right' => $Qcurrencies->value('symbol_right'),
32                                                                'decimal_places' => $Qcurrencies->valueInt('decimal_places'),
33                                                                'value' => $Qcurrencies->valueDecimal('value'));
34       }
hpdl
386
35
36       $Qcurrencies->freeResult();
hpdl
1
37     }
38
39 // class methods
40     function format($number, $currency_code = '', $currency_value = '') {
hpdl
386
41       global $osC_Language;
42
hpdl
1
43       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
hpdl
199
44         $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY);
hpdl
1
45       }
46
47       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
48         $currency_value = $this->currencies[$currency_code]['value'];
49       }
50
hpdl
733
51       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
52     }
53
hpdl
484
54     function formatRaw($number, $currency_code = '', $currency_value = '') {
55       if (empty($currency_code) || ($this->exists($currency_code) == false)) {
56         $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY);
57       }
58
59       if (empty($currency_value) || (is_numeric($currency_value) == false)) {
60         $currency_value = $this->currencies[$currency_code]['value'];
61       }
62
hpdl
733
63       return number_format(osc_round($number * $currency_value, $this->currencies[$currency_code]['decimal_places']), $this->currencies[$currency_code]['decimal_places'], '.', '');
hpdl
484
64     }
65
hpdl
748
66     function addTaxRateToPrice($price, $tax_rate, $quantity = 1) {
hpdl
1
67       global $osC_Tax;
68
hpdl
733
69       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
1
70
hpdl
733
71       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_rate > 0) ) {
72         $price += osc_round($price * ($tax_rate / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
73       }
74
hpdl
748
75       return osc_round($price * $quantity, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
733
76     }
77
78     function displayPrice($price, $tax_class_id, $quantity = 1, $currency_code = null, $currency_value = null) {
79       global $osC_Tax;
80
81       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
82
hpdl
500
83       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_class_id > 0) ) {
hpdl
733
84         $price += osc_round($price * ($osC_Tax->getTaxRate($tax_class_id) / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
1
85       }
86
hpdl
733
87       return $this->format($price * $quantity, $currency_code, $currency_value);
hpdl
1
88     }
89
hpdl
538
90     function displayPriceWithTaxRate($price, $tax_rate, $quantity = 1, $currency_code = '', $currency_value = '') {
91       global $osC_Tax;
92
hpdl
733
93       $price = osc_round($price, $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
538
94
95       if ( (DISPLAY_PRICE_WITH_TAX == '1') && ($tax_rate > 0) ) {
hpdl
733
96         $price += osc_round($price * ($tax_rate / 100), $this->currencies[DEFAULT_CURRENCY]['decimal_places']);
hpdl
538
97       }
98
99       return $this->format($price * $quantity, $currency_code, $currency_value);
100     }
101
hpdl
1
102     function exists($code) {
103       if (isset($this->currencies[$code])) {
104         return true;
105       }
106
107       return false;
108     }
109
110     function decimalPlaces($code) {
111       if ($this->exists($code)) {
112         return $this->currencies[$code]['decimal_places'];
113       }
114
115       return false;
116     }
117
118     function value($code) {
119       if ($this->exists($code)) {
120         return $this->currencies[$code]['value'];
121       }
122
123       return false;
124     }
hpdl
386
125
hpdl
1213
126     function getData() {
127       return $this->currencies;
128     }
129
hpdl
386
130     function getCode($id = '') {
131       if (is_numeric($id)) {
132         foreach ($this->currencies as $key => $value) {
hpdl
399
133           if ($value['id'] == $id) {
hpdl
386
134             return $key;
135           }
136         }
137       } else {
138         return $_SESSION['currency'];
139       }
140     }
hpdl
387
141
142     function getID($code = '') {
143       if (empty($code)) {
144         $code = $_SESSION['currency'];
145       }
146
147       return $this->currencies[$code]['id'];
148     }
hpdl
1
149   }
150 ?>