<?php
// Подключение к БД
include 'config.php';
$dbhost = DB_HOSTNAME;
$dbuser = DB_USERNAME;
$dbpass = DB_PASSWORD;
$dbname = DB_DATABASE;
$sqlchar='utf8';
$db = new PDO ( 'mysql:host=' . $dbhost . ';dbname=' . $dbname, $dbuser, $dbpass);
$db->query ( 'SET character_set_connection = '.$sqlchar );
$db->query ( 'SET character_set_client = '.$sqlchar );
$db->query ( 'SET character_set_results = '.$sqlchar );
$default=$db->query("SELECT value FROM " . DB_PREFIX . "currency WHERE code='USD'")->fetch(PDO::FETCH_ASSOC);
if($default['value']== 1.00000000){
$xml = simplexml_load_file('http://themoneyconverter.com/rss-feed/USD/rss.xml');
$price=1; // один доллар;
// Гривны
preg_match('/<description>1 United States Dollar = ([0-9.]+) Ukraine Hryvnia<\/description>/', $data, $matches);
$codUAH = "UAH";
$conUAH= $matches[1];
// Рубли
preg_match('/<description>1 United States Dollar = ([0-9.]+) Russian Rouble<\/description>/', $data, $matches);
$codRUB = "RUB";
$conRUB= $matches[1];
date_default_timezone_set('Europe/Kiev');
$date=date('Y-m-d H:i:s');
$stmt = $db->query("SELECT code FROM " . DB_PREFIX . "currency");
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
//echo $row['code'] ;
switch ($row['code']){
case 'USD':
$db->exec("UPDATE " . DB_PREFIX . "currency SET value = '1.00000000', date_modified = '" . $date . "' WHERE code = 'USD'");
break;
case $codUAH:
if($valUAH==true){
$db->exec("UPDATE " . DB_PREFIX . "currency SET value = '" . number_format($conUAH, 8, '.', '') . "', date_modified = '" . $date . "' WHERE code = '" . $codUAH . "'");
}else{
echo "Валюта UAH не обновлена (нет курса)<br>";
}
break;
case $codRUB:
if($valUSD==true){
$db->exec("UPDATE " . DB_PREFIX . "currency SET value = '" . number_format($conRUB, 8, '.', '') . "', date_modified = '" . $date . "' WHERE code = '" . $codRUB . "'");
}else{
echo "Валюта RUB не обновлена (нет курса)<br>";
}
break;
}
}
$defaultd=$db->query("SELECT date_modified FROM " . DB_PREFIX . "currency WHERE code='USD'")->fetch(PDO::FETCH_ASSOC);
echo 'Курс обновился в ('.$defaultd['date_modified'].')';
}
else
{
echo 'Курс не обновился! Установите Доллар по умолчанию';
}
?>