<?php
/*
$Id: currencies.php,v 1.3 2003/06/20 16:23:08 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2003 osCommerce
Released under the GNU General Public License
*/
////
// Class to handle currencies
// TABLES: currencies
class currencies {
var $currencies;
// class constructor
function currencies() {
$this->currencies = array();
$this->currencies_cv = array();
$currencies_query = tep_db_query("select currencies_id, code, title, symbol_left, symbol_right, decimal_point, thousands_point, decimal_places, value from " . TABLE_CURRENCIES);
while ($currencies = tep_db_fetch_array($currencies_query)) {
$this->currencies[$currencies['code']] = array('title' => $currencies['title'],
'symbol_left' => $currencies['symbol_left'],
'symbol_right' => $currencies['symbol_right'],
'decimal_point' => $currencies['decimal_point'],
'thousands_point' => $currencies['thousands_point'],
'decimal_places' => $currencies['decimal_places'],
'currencies_id' => $currencies['currencies_id'],
'value' => $currencies['value']);
$this->currencies_cv[$currencies['currencies_id']] = array('code' => $currencies['code'],
'value' => $currencies['value']);
}
}
// class methods
function format($number, $calculate_currency_value = true, $currency_type = DEFAULT_CURRENCY, $currency_value = '') {
if ($calculate_currency_value) {
$rate = ($currency_value) ? $currency_value : $this->currencies[$currency_type]['value'];
$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number * $rate, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
} else {
$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];
}
return $format_string;
}
function get_value($code) {
return $this->currencies[$code]['value'];
}
function get_value_from_id($currencies_id) { // added by snowbird
return $this->currencies_cv[$currencies_id]['value'];
}
function get_code($currencies_id) { // added by snowbird
return $this->currencies_cv[$currencies_id]['code'];
}
function display_price($products_price, $currencies_id, $products_tax = 0, $quantity = 1, $currency_type = DEFAULT_CURRENCY) {
return $this->format(tep_round(tep_add_tax($products_price, $products_tax), $this->currencies[$currency_type]['decimal_places']) * $quantity, true, $currency_type, $this->get_value_from_id($currencies_id));
}
}
?>