Quick Search:

View

Revision:

Diff

Diff from 484 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 484 2006-04-17 23:32:41Z 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
69       if ( (DISPLAY_PRICE_WITH_TAX == 'true') && ($tax_class_id > 0) ) {
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
76     function exists($code) {
77       if (isset($this->currencies[$code])) {
78         return true;
79       }
80
81       return false;
82     }
83
84     function decimalPlaces($code) {
85       if ($this->exists($code)) {
86         return $this->currencies[$code]['decimal_places'];
87       }
88
89       return false;
90     }
91
92     function value($code) {
93       if ($this->exists($code)) {
94         return $this->currencies[$code]['value'];
95       }
96
97       return false;
98     }
hpdl
386
99
100     function getCode($id = '') {
101       if (is_numeric($id)) {
102         foreach ($this->currencies as $key => $value) {
hpdl
399
103           if ($value['id'] == $id) {
hpdl
386
104             return $key;
105           }
106         }
107       } else {
108         return $_SESSION['currency'];
109       }
110     }
hpdl
387
111
112     function getID($code = '') {
113       if (empty($code)) {
114         $code = $_SESSION['currency'];
115       }
116
117       return $this->currencies[$code]['id'];
118     }
hpdl
1
119   }
120 ?>