define ('BASE10', "0123456789");
define ('BASE16', "0123456789ABCDEF");
define ('BASE32', "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
define ('BASE62', "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
$digestKey = $inifile['Global']['DigestKey'];
if (empty ($digestKey)) $digestKey = 'uquief5moh8yeebeuTaivahKoT3ceeseiQuood1iequ4ahshohchijeid1oe4Gis';
// Processa totes les plantilles
$estacions = explode (';', $inifile['Global']['Stations']);
foreach ($estacions as $station_id) {
clearstatcache ();
$password = $inifile[$station_id]['Password'];
$datafile = $inifile[$station_id]['Path'];
if (file_exists ($datafile) && filemtime ($datafile) > time () - 3600) {
$plantilla = file_get_contents ($datafile);
$plantilla = str_replace ("\n", "", $plantilla);
$plantilla = str_replace ("\r", "", $plantilla);
$items = explode ("*", $plantilla);
$tpl = array ();
foreach ($items as $valor) {
//list ($var, $val) = explode ('=',$valor);
//Se sustituye la linea anterior por la siguiente, que cambia las comas decimales por puntos decimales
list ($var, $val) = explode ('=',str_replace(',', '.', str_replace('.', '', $valor)));
$tpl[$var] = trim ($val);
// Genera OTP
$OTP = md5 (md5 ($password) . ($tpl['TMP'] * 10) . $digestKey);
$OTP = substr ($OTP, rand (1, strlen ($OTP) - 10), 10);
if (!is_numeric (substr ($tpl['AZI'], 0, 1))) $tpl['AZI'] = rsentit ($tpl['AZI']);
// Confecciona el Query
$T = BaseConvert (round ($tpl['TMP'] * 10), BASE10, BASE62) . ';' .