2016-09-29 18:08:23 +02:00

60 lines
1.6 KiB
PHP

<?php
require_once(dirname(__FILE__).'../../../config/config.inc.php');
require_once(dirname(__FILE__).'../../../init.php');
header('Content-Type: application/json');
if(Tools::getValue('action') != 'getReport') {
http_response_code(418);
die('I\'m a teapot');
}
switch (Tools::getValue('type')) {
case 'ART':
die(getReport('ART'));
break;
case 'CDC':
die(getReport('CDC'));
break;
case 'CRP':
die(getReport('CRP'));
break;
default:
http_response_code(418);
die(json_encode('I\'m a teapot'));
break;
}
function getReport($type) {
//global $cookie;
$id_sale = (int)Tools::getValue('id_sale', false);
if (!$id_sale) {
http_response_code(500);
return json_encode(array(
'error'=> 'true',
'message'=> Tools::displayError('Vente non trouvée')
));
}
$report = Db::getInstance()->getRow('
SELECT `report_data`, `report_date`, `id_sale`
FROM `'._DB_PREFIX_.'philea_syncreport`
WHERE `id_sale` = '.$id_sale.'
AND `filename` LIKE "'.$type.'%"
');
if(empty($report['report_data'])){
$report['report_data'] = Tools::displayError('Pas encore de rapport '.$type.' disponible');
}
if(isset($report) && $report != false) {
return json_encode(array(
'error' => 'false',
'report' => $report
));
} else {
return json_encode(array(
'error'=> 'true',
'message' => Tools::displayError('Pas encore de rapport '.$type.' disponible')
));
}
}