2024-04-27 09:23:34 +02:00
|
|
|
<?php
|
2024-09-30 08:44:00 +00:00
|
|
|
|
|
|
|
|
/*
|
2024-04-27 09:23:34 +02:00
|
|
|
//crontab job - save currencies
|
|
|
|
|
set_time_limit(9999999999);
|
|
|
|
|
require_once("./../../config.php");
|
|
|
|
|
$sql1=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
|
|
|
|
|
mysql_select_db($sugar_config['dbconfig']['db_name']);
|
|
|
|
|
|
|
|
|
|
//get xml file name from dir.txt
|
|
|
|
|
$today=date('ymd');
|
|
|
|
|
//$today="120127";
|
|
|
|
|
$connect = fopen("http://www.nbp.pl/kursy/xml/dir.txt", "r") or die("Błąd przy łączeniu");
|
|
|
|
|
while (!feof ($connect)) {
|
|
|
|
|
$buffer = fgets($connect, 4096) or die("Błąd przy odczycie
|
|
|
|
|
");
|
|
|
|
|
if ((substr($buffer,0,1)=='a') && (substr($buffer,5,6))==$today)
|
|
|
|
|
{
|
|
|
|
|
$xml_file = $buffer;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
if (substr($buffer,0,1)=='a') $xml_file = $buffer; //get last "a" if file when "today" not exists
|
|
|
|
|
};
|
|
|
|
|
fclose($connect);
|
|
|
|
|
|
|
|
|
|
//download xml
|
|
|
|
|
$connect = fopen("http://www.nbp.pl/kursy/xml/".trim($xml_file).".xml", "r") or die("Błąd przy łączeniu");
|
2024-09-30 08:44:00 +00:00
|
|
|
echo "http://www.nbp.pl/kursy/xml/".trim($xml_file).".xml";
|
2024-04-27 09:23:34 +02:00
|
|
|
$download = fopen("./currencies.xml", "w") or die("Błąd przy łączeniu");
|
|
|
|
|
while (!feof ($connect)) {
|
|
|
|
|
$buffer = fgets($connect, 4096);//or die("Błąd przy odczyciee");
|
|
|
|
|
fwrite($download, $buffer);// or die("Błąd przy zapisie");
|
|
|
|
|
}
|
|
|
|
|
fclose($connect);
|
|
|
|
|
fclose($download);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//load currencies
|
|
|
|
|
$currencies = array();
|
|
|
|
|
$result = mysql_query("select id, iso4217 from currencies where deleted='0'");
|
|
|
|
|
while ($r=mysql_fetch_array($result)) {
|
|
|
|
|
$currencies[$r['iso4217']] = array();
|
|
|
|
|
$currencies[$r['iso4217']]['id']=$r['id'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//read xml
|
|
|
|
|
$doc = new DOMDocument();
|
|
|
|
|
$doc->load( 'currencies.xml' );
|
|
|
|
|
$tmp = $doc->getElementsByTagName("data_publikacji");
|
2024-09-30 08:44:00 +00:00
|
|
|
var_dump($tmp);
|
2024-04-27 09:23:34 +02:00
|
|
|
$cur_date = $tmp->item(0)->nodeValue;
|
|
|
|
|
$tmp = $doc->getElementsByTagName("numer_tabeli");
|
|
|
|
|
$table_name = $tmp->item(0)->nodeValue;
|
|
|
|
|
$poz = $doc->getElementsByTagName("pozycja");
|
|
|
|
|
foreach ($poz as $p) {
|
|
|
|
|
$kod_waluty=$p->getElementsByTagName("kod_waluty");
|
|
|
|
|
$kod = $kod_waluty->item(0)->nodeValue;
|
|
|
|
|
if (isset($currencies[$kod])) {
|
|
|
|
|
$kurs_sredni=$p->getElementsByTagName("kurs_sredni");
|
|
|
|
|
$kurs = $kurs_sredni->item(0)->nodeValue;
|
|
|
|
|
$currencies[$kod]['kurs']=$kurs;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-30 08:44:00 +00:00
|
|
|
//var_dump($currencies);
|
2024-04-27 09:23:34 +02:00
|
|
|
//save values into db
|
|
|
|
|
foreach ($currencies as $key=>$value) {
|
|
|
|
|
mysql_query("INSERT INTO currency_nbp_archive VALUES ('".$cur_date."', '".$value['id']."', '".$key."', ".str_replace(",",".",$value['kurs']).",'".$table_name."')");
|
|
|
|
|
|
|
|
|
|
//update nbp_conversion_rate in Currencies
|
|
|
|
|
mysql_query("UPDATE currencies SET nbp_conversion_rate='".str_replace(",",".",$value['kurs'])."' WHERE id='".$value['id']."'");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//delete xls
|
|
|
|
|
unlink("./currencies.xml");
|
2024-09-30 08:44:00 +00:00
|
|
|
*/
|