  |
1 | 1 | | <?php |
| |
2 | 2 | | /* |
  |
3 | | - | $Id: currencies.php 199 2005-09-22 15:56:13Z hpdl $ |
| |
| 3 | + | $Id: currencies.php 386 2006-01-12 11:36:39Z hpdl $ |
|
4 | 4 | | |
| |
5 | 5 | | osCommerce, Open Source E-Commerce Solutions |
| |
6 | 6 | | http://www.oscommerce.com |
| |
7 | 7 | | |
  |
8 | | - | Copyright (c) 2004 osCommerce |
| |
| 8 | + | Copyright (c) 2006 osCommerce |
|
9 | 9 | | |
| |
10 | 10 | | Released under the GNU General Public License |
| |
11 | 11 | | */ |
| |
12 | 12 | | |
| |
13 | 13 | | class osC_Currencies { |
  |
14 | | - | var $currencies; |
| |
| 14 | + | var $currencies = array(); |
|
15 | 15 | | |
| |
16 | 16 | | // class constructor |
| |
17 | 17 | | function osC_Currencies() { |
| |
18 | 18 | | global $osC_Database; |
| |
19 | 19 | | |
  |
20 | | - | $this->currencies = array(); |
| |
21 | | - | |
| |
22 | | - | $Qcurrencies = $osC_Database->query('select code, title, symbol_left, symbol_right, decimal_places, value from :table_currencies'); |
| |
23 | | - | $Qcurrencies->bindRaw(':table_currencies', TABLE_CURRENCIES); |
| |
| 20 | + | $Qcurrencies = $osC_Database->query('select * from :table_currencies'); |
| |
| 21 | + | $Qcurrencies->bindTable(':table_currencies', TABLE_CURRENCIES); |
| |
| 22 | + | $Qcurrencies->setCache('currencies'); |
|
24 | 23 | | $Qcurrencies->execute(); |
| |
25 | 24 | | |
| |
26 | 25 | | while ($Qcurrencies->next()) { |
  |
27 | | - | $this->currencies[$Qcurrencies->value('code')] = array('title' => $Qcurrencies->value('title'), |
| |
| 26 | + | $this->currencies[$Qcurrencies->value('code')] = array('id' => $Qcurrencies->valueInt('currencies_id'), |
| |
| 27 | + | 'title' => $Qcurrencies->value('title'), |
|
28 | 28 | | 'symbol_left' => $Qcurrencies->value('symbol_left'), |
| |
29 | 29 | | 'symbol_right' => $Qcurrencies->value('symbol_right'), |
| |
30 | 30 | | 'decimal_places' => $Qcurrencies->valueInt('decimal_places'), |
| |
31 | 31 | | 'value' => $Qcurrencies->valueDecimal('value')); |
| |
32 | 32 | | } |
  |
| 33 | + | |
| |
| 34 | + | $Qcurrencies->freeResult(); |
|
33 | 35 | | } |
| |
34 | 36 | | |
| |
35 | 37 | | // class methods |
| |
36 | 38 | | function format($number, $currency_code = '', $currency_value = '') { |
  |
| 39 | + | global $osC_Language; |
| |
| 40 | + | |
|
37 | 41 | | if (empty($currency_code) || ($this->exists($currency_code) == false)) { |
| |
38 | 42 | | $currency_code = (isset($_SESSION['currency']) ? $_SESSION['currency'] : DEFAULT_CURRENCY); |
| |
39 | 43 | | } |
| |
|
|
 |
… |
|
42 | 46 | | $currency_value = $this->currencies[$currency_code]['value']; |
| |
43 | 47 | | } |
| |
44 | 48 | | |
  |
45 | | - | 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'], NUMERIC_DECIMAL_SEPARATOR, NUMERIC_THOUSANDS_SEPARATOR) . $this->currencies[$currency_code]['symbol_right']; |
| |
| 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']; |
|
46 | 50 | | } |
| |
47 | 51 | | |
| |
48 | 52 | | function displayPrice($price, $tax_class_id, $quantity = 1) { |
| |
|
|
 |
… |
|
80 | 84 | | |
| |
81 | 85 | | return false; |
| |
82 | 86 | | } |
  |
| 87 | + | |
| |
| 88 | + | function getCode($id = '') { |
| |
| 89 | + | if (is_numeric($id)) { |
| |
| 90 | + | foreach ($this->currencies as $key => $value) { |
| |
| 91 | + | if ($value['currencies_id'] == $id) { |
| |
| 92 | + | return $key; |
| |
| 93 | + | } |
| |
| 94 | + | } |
| |
| 95 | + | } else { |
| |
| 96 | + | return $_SESSION['currency']; |
| |
| 97 | + | } |
| |
| 98 | + | } |
  |
83 | 99 | | } |
| |
84 | 100 | | ?> |