$original_currency), 300, true); } catch (NotFoundException $e) { throw new CurrencyConversionException("The specified origin currency is not a valid currency code."); } $sUsdRate = $amount * $sOriginRate->sFromRate; if($target_currency === "USD") { return $sUsdRate; } else { try { $sTargetRate = ExchangeRate::CreateFromQuery("SELECT * FROM exchange_rates WHERE `Code` = :Code", array(":Code" => $target_currency), 300, true); } catch (NotFoundException $e) { throw new CurrencyConversionException("The specified target currency is not a valid currency code."); } $sResult = $sUsdRate * $sTargetRate->sToRate; return $sResult; } } public static function Format($currency, $amount, $precision = 2) { try { $sExchangeRate = ExchangeRate::CreateFromQuery("SELECT * FROM exchange_rates WHERE `Code` = :Code", array(":Code" => $currency), 30, true); } catch (NotFoundException $e) { throw new CurrencyFormattingException("The specified currency is not a valid currency code."); } if($sExchangeRate->sSymbol == "") { return "{$sExchangeRate->sCurrencyCode} " . number_format($amount, $precision); } else { return "{$sExchangeRate->sSymbol}" . number_format($amount, $precision); } } public static function UpdateRates() { global $cphp_config; $json = json_decode(file_get_contents("http://openexchangerates.org/api/latest.json?app_id={$cphp_config->openexchangerates->app_id}"), true); $rates = $json["rates"]; foreach($rates as $currency => $rate) { ExchangeRate::Update($currency, $rate); } } }