2017-01-11 15:53:24 +01:00

88 lines
2.7 KiB
PHP
Executable File

<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/../../../../config/config.inc.php';
## GET relais.txt FILE
$fname = 'relais.txt';
$filename = dirname(__FILE__) . '/' . $fname;
$file = fopen($filename, 'w+');
$remote_file = $fname;
$ftp = ftp_connect(Configuration::get('MONDIALRELAYWS_FTP_HOST'));
ftp_login($ftp, Configuration::get('MONDIALRELAYWS_FTP_LOGIN'), Configuration::get('MONDIALRELAYWS_FTP_PASSWORD'));
ftp_chdir($ftp, 'depuismrelay');
if (!ftp_fget($ftp, $file, $remote_file, FTP_BINARY))
die('An error occures while downloading remote file : ' . $fname);
$file = fopen($filename, 'r');
$content = fgets($file);
if (!$content)
die('File is empty : ' . $fname);
## Update DB
Db::getInstance()->ExecuteS('
TRUNCATE TABLE `'._DB_PREFIX_.'mondialrelay_relais`
');
while($line = fgets($file)) {
if(substr($line, 1, 1) == '1') {
$datouv = explode('.', substr($line, 62, 10));
if(count($datouv) > 1) {
$datouv = $datouv[2].'-'.$datouv[1].'-'.$datouv[0];
} else {
$datouv = '0000-00-00';
}
$datfer = explode('.', substr($line, 72, 10));
if(count($datfer) > 1) {
$datfer = $datfer[2].'-'.$datfer[1].'-'.$datfer[0];
} else {
$datfer = '0000-00-00';
}
Db::getInstance()->ExecuteS('
INSERT INTO `'._DB_PREFIX_.'mondialrelay_relais`
VALUES (
"'.pSQl(substr($line, 4, 5)).'",
"'.pSQl(substr($line, 9, 1)).'",
"'.pSQl(substr($line, 10, 31)).'",
"'.pSQl(substr($line, 41, 5)).'",
"'.pSQl(substr($line, 46, 5)).'",
"'.pSQl(substr($line, 51, 5)).'",
"'.pSQl(substr($line, 56, 5)).'",
"'.pSQl(substr($line, 61, 1)).'",
"'.pSQl($datouv).'",
"'.pSQl($datfer).'",
"'.pSQl(substr($line, 202, 30)).'",
"'.pSQl(substr($line, 232, 31)).'",
"'.pSQl(substr($line, 325, 4)).'",
"'.pSQl(substr($line, 336, 31)).'",
"'.pSQl(substr($line, 367, 31)).'",
"'.pSQl(substr($line, 398, 31)).'",
"'.pSQl(substr($line, 429, 31)).'",
"'.pSQl(substr($line, 460, 5)).'",
"'.pSQl(substr($line, 465, 26)).'",
"'.pSQl(substr($line, 491, 5)).'",
"'.pSQl(substr($line, 613, 1)).'",
"'.pSQl(substr($line, 614, 1)).'",
"'.pSQl(substr($line, 615, 1)).'",
"'.pSQl(substr($line, 616, 1)).'",
"'.pSQl(substr($line, 617, 1)).'",
"'.pSQl(substr($line, 618, 1)).'",
"'.pSQl(substr($line, 619, 1)).'",
"'.pSQl(substr($line, 620, 2)).'",
"'.pSQl(substr($line, 622, 5)).'",
"'.pSQl(substr($line, 627, 20)).'",
"'.pSQl(substr($line, 652, 1)).'",
"'.pSQl(substr($line, 653, 6)).'",
"'.pSQl(substr($line, 659, 3)).'",
"'.pSQl(substr($line, 662, 6)).'"
)
');
}
}