Documentation
Project Links
Upload the following file to your catalog/admin directory:
<?php
/*
$Id: currency_updater.php,v 1.01 2007/01/23 14:39:00 hpdl Exp $
osCommerce, Open Source E-Commerce Solutions
http://www.oscommerce.com
Copyright (c) 2007 IT-commerce
Released under the GNU General Public License
!!---------------------------------------------------------------------------------------------------------------------------------------------------------------!!
I make no warranties, expressed or implied, regarding the data that this inputs into your database. I AM NOT LIABLE FOR ANY
FINANCIAL LOSSES OR DAMAGE YOU OR YOUR SITE MIGHT SUSTAIN BY USING THIS SCRIPT.
********************IF THAT RISK IS UNACCEPTABLE, DELETE THIS SCRIPT IMMEDIATELY***********************
!!---------------------------------------------------------------------------------------------------------------------------------------------------------------!!
*/
///////CONFIGURABLE VARIABLES///////////
//Enable/Disable Reporting
//0=none, 1=screen,
$output_report = 1;
$report='';
///////////////END//////////////////////
//Whatever you set for $output_report above will be overridden if you set output_report in the URL
//Defaults to 1
//insomniac2 added the reporting code, I just modified it a little
if (isset($_GET['output_report'])) {
switch ($_GET['output_report']) {
case '0':
$output_report = (int)$_GET['output_report'];
break;
default:
$output_report = 1;
break;
}
}
// ------ start code from application_top -----------
// Set the level of error reporting
error_reporting(E_ALL & ~E_NOTICE);
// Check if register_globals is enabled.
// Since this is a temporary measure this message is hardcoded. The requirement will be removed before 2.2 is finalized.
// if (function_exists('ini_get')) {
// ini_get('register_globals') or exit('Server Requirement Error: register_globals is disabled in your PHP configuration. This can be enabled in your php.ini configuration file or in the .htaccess file in your catalog directory.');
// }
// Set the local configuration parameters - mainly for developers
if (file_exists('includes/local/configure.php')) include('includes/local/configure.php');
// Include application configuration parameters
require('includes/configure.php');
// set php_self in the local scope
$PHP_SELF = (isset($_SERVER['PHP_SELF']) ? $_SERVER['PHP_SELF'] : $_SERVER['SCRIPT_NAME']);
// include the list of project database tables
require(DIR_WS_INCLUDES . 'database_tables.php');
// Define how do we update currency exchange rates
// Possible values are 'oanda' 'xe' or ''
define('CURRENCY_SERVER_PRIMARY', 'xe');
define('CURRENCY_SERVER_BACKUP', 'oanda');
// include the database functions
require(DIR_WS_FUNCTIONS . 'database.php');
// make a connection to the database... now
tep_db_connect() or die('Unable to connect to database server!');
// --------8<-----------------8<-------------------8<-------------
// set application wide parameters
$configuration_query = tep_db_query('select configuration_key as cfgKey, configuration_value as cfgValue from ' . TABLE_CONFIGURATION);
while ($configuration = tep_db_fetch_array($configuration_query)) {
define($configuration['cfgKey'], $configuration['cfgValue']);
}
// define our general functions used application-wide
require(DIR_WS_FUNCTIONS . 'general.php');
require(DIR_WS_FUNCTIONS . 'html_output.php');
// some code to solve compatibility issues
require(DIR_WS_FUNCTIONS . 'compatibility.php');
// define our localization functions
require(DIR_WS_FUNCTIONS . 'localization.php');
// check if a default currency is set
if (!defined('DEFAULT_CURRENCY')) {
$messageStack->add(ERROR_NO_DEFAULT_CURRENCY_DEFINED, 'error');
}
// ------- end code from application_top -----------------
require(DIR_WS_CLASSES . 'currencies.php');
$currencies = new currencies();
// --
$server_used = CURRENCY_SERVER_PRIMARY;
$currency_query = tep_db_query("select currencies_id, code, title from " . TABLE_CURRENCIES);
while ($currency = tep_db_fetch_array($currency_query)) {
$quote_function = 'quote_' . CURRENCY_SERVER_PRIMARY . '_currency';
$rate = $quote_function($currency['code']);
if (empty($rate) && (tep_not_null(CURRENCY_SERVER_BACKUP))) {
$report = $report.'Warning: '.'Server: '.CURRENCY_SERVER_PRIMARY.' - '. $currency['title'].', '. $currency['code']. ' failed currency update'."\n" ;
$quote_function = 'quote_' . CURRENCY_SERVER_BACKUP . '_currency';
$rate = $quote_function($currency['code']);
$server_used = CURRENCY_SERVER_BACKUP;
}
if (tep_not_null($rate)) {
tep_db_query("update " . TABLE_CURRENCIES . " set value = '" . $rate . "', last_updated = now() where currencies_id = '" . (int)$currency['currencies_id'] . "'");
//$report = $report.$currency['title'].' '. $currency['code'].' '. $server_used. ' success'."\n";
$report = $report.'Server: '.$server_used.' - '.$currency['title'].', '. $currency['code'].' currency update successfully'."\n";
} else {
//$report = $report.$currency['title'].' '. $currency['code'].' '. $server_used. ' error'."\n";
$report = $report.'Server: '. $server_used.' - '.$currency['title'].', '. $currency['code'].' error during currency update'."\n";
}
}
// ---
//If there's anything to report and the user has outputting enabled, display the info
if ($report && $output_report > 0) {
$report = 'Currencies Updated on ' . date("D M j G:i:s Y") . "\n\n" . $report;
if ($output_report != 2) {
echo str_replace("\n", '<br>', $report);
}
}
?>
Go to cPanel and enter the following command in Cron Jobs, changing the values to suit.
php /home/xxxxx/public_html/catalog/admin/currency_updater.php >/home/xxxxx/tmp/currency_log.txt 2>&1
If you use many currencies then I suggest running the cron at least twice per day. Otherwise, once per day may be sufficient.
— Ridexbuilder 2010/04/05 05:28