bebeboutik/modules/stats_logistic/ajax.php
2018-02-06 15:41:39 +01:00

56 lines
1.6 KiB
PHP

<?php
require_once dirname(__FILE__).'../../../config/config.inc.php';
require_once dirname(__FILE__).'../../../init.php';
$action = Tools::getValue('action');
switch ($action) {
case 'check':
$filename = Tools::getValue('file');
$path = dirname(__FILE__) . '/export';
$file = $path . '/' . $filename;
if (file_exists($file)) {
echo '<a href="./ajax-tab.php?tab=AdminStatsLogistic&ajax=1&token='.
Tools::getValue('token').'&dl=1&file='.$filename.'" target="_blank">Télécharger le fichier '.$filename.'</a>';
} else {
echo "";
}
break;
case 'export':
$start = Tools::getValue('date_export_begin');
$end = Tools::getValue('date_export_end');
$path = dirname(__FILE__) . '/export';
$filename = 'export-remb-'.$start.'-'.$end.'.csv';
$file = $path . '/' . $filename;
if (file_exists($file)) {
unlink($file);
}
if (empty($start) || empty($end)) {
$url = '';
} else {
$url = Tools::getShopDomain(true) . '/modules/stats_logistic/ajax.php?action=check&token='.Tools::getValue('token');
}
$cmd = dirname(__FILE__).'/bin/export.php --start '.$start.' --end '.$end;
exec("php ".$cmd." > /dev/null &");
// Always return checkin url
echo json_encode(array(
'url' => $url,
'file' => 'export-remb-'.$start.'-'.$end.'.csv',
));
break;
case 'dl':
default:
exit;
}
exit;