Quote Originally Posted by Design75 View Post
Can you past the contents of your currency_update.php? I suspect you are missing some characters at the start of the file
Code:
<?php
/*
 * Automatic Currency Update v5.0
 * Originally by Richard Fink (masterblaster)  based on Zen Cart manual currency update
 * updated by Kuroi to include Zen Cart's currency uplift ratio
 * further updated by Kuroi to use European Central Bank reference rates  (adapted from ECB-supplied code)
 * updated by Zen4All (design75) use Zen Cart standard coding
 *
 * Rework for PHP 5.3 compatibility (ereg and mysql_db_query functions deprecated in PHP 5.3.0)
 * switched to using SimpleXML and mysqli instead.
 * JeRo www.jero.co.nz 18/06/2010
 *
 * license: GNU Public License V2.0
 *
 */

require_once('includes/application_top.php');
/*
 *  Get default currency.
 */
$defaulCurrency = $db->Execute("SELECT configuration_value
                                FROM " . TABLE_CONFIGURATION . "
                                WHERE configuration_key = 'DEFAULT_CURRENCY' LIMIT 1 ");

/* 
 * Get currency conversion ratio.
 */
$currencyUpliftRatio = $db->Execute("SELECT configuration_value
                                     FROM " . TABLE_CONFIGURATION . "
                                     WHERE configuration_key = 'CURRENCY_UPLIFT_RATIO' LIMIT 1 ");

/*
 * Create new SimpleXML element from the Euro zone file
 * If your PHP configuration does not have allow_url_fopen, you may need to
 * write a script to pick it up using wget:
 * wget -O eurofxref-daily.xml www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml
 * and then uncomment/comment these next two lines:
 * $xml = new SimpleXMLElement(file_get_contents("eurofxref-daily.xml"));
 */
$xml = new SimpleXMLElement(file_get_contents("http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"));

/*
 * extract your preferred currency's exchange rate.
 */
$nzd = $xml->xpath("//*[@currency='" . $defaulCurrency->fields['configuration_value'] . "']");
$base = (float)$nzd[0]['rate'];

# If our default currency is the Euro, it won't be in the XML,
# so set the base exchange rate to 1
if ($defaulCurrency->fields['configuration_value'] == 'EUR') {
  $base = (float)1;
}

/*
 * Get array of currency data from the XML file.
 */
$currencies = $xml->xpath("//*[@currency]");

/*
 *  Iterate over array, pulling out currency code and rate.
 * Convert into your preferred currency.
 * Pump it into the database.
 */
foreach ($currencies as $curr) {
  $cc = $curr[0]['currency'];
  $rr = (float)$curr[0]['rate'] * $currencyUpliftRatio->fields['configuration_value'];
  $new = $rr / $base;
/*
 * But don't uplift your default currency!
 */
  if ($cc != $defaulCurrency->fields['configuration_value']) {
    $sql_data_array = array('value' => $new,
                            'last_updated' => 'now()',
                            'code' => $cc);
    zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "code = '" . $cc . "'");
  }
}

/*
 * Feed is based on the Euro, which is not included in the feed,
 * therefore we need to update it manually,
 * unless of course our preferred currency is the Euro
 */
$cc = 'EUR';
$rr = 1 / $base * CURRENCY_UPLIFT_RATIO;
if ($defaulCurrency->fields['configuration_value'] != $cc) {
  $sql_data_array = array('value' => $rr,
                          'last_updated' => 'now()',
                          'code' => $cc);
  zen_db_perform(TABLE_CURRENCIES, $sql_data_array, 'update', "code = '" . $cc . "'");
}