2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
2020-09-07 15:04:06 +02:00
|
|
|
/*
|
|
|
|
* OpenSTAManager: il software gestionale open source per l'assistenza tecnica e la fatturazione
|
2021-01-20 15:08:51 +01:00
|
|
|
* Copyright (C) DevCode s.r.l.
|
2020-09-07 15:04:06 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2020-07-28 16:37:44 +02:00
|
|
|
use API\Response;
|
|
|
|
|
2017-08-28 18:15:52 +02:00
|
|
|
function serverError()
|
|
|
|
{
|
2017-08-29 12:42:42 +02:00
|
|
|
$error = error_get_last();
|
|
|
|
if ($error['type'] == E_ERROR) {
|
|
|
|
ob_end_clean();
|
2019-07-19 15:23:00 +02:00
|
|
|
echo Response::error('serverError');
|
2017-08-28 18:24:45 +02:00
|
|
|
}
|
2017-08-28 18:15:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Gestione degli errori
|
|
|
|
set_error_handler('serverError');
|
2017-08-28 18:24:45 +02:00
|
|
|
register_shutdown_function('serverError');
|
|
|
|
|
|
|
|
include_once __DIR__.'/../core.php';
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Permesso di accesso all'API da ogni dispositivo
|
|
|
|
header('Access-Control-Allow-Origin: *');
|
2018-08-01 15:15:14 +02:00
|
|
|
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
try {
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::manage();
|
2017-08-04 16:28:16 +02:00
|
|
|
} catch (Exception $e) {
|
2018-07-27 12:17:17 +02:00
|
|
|
// Log dell'errore
|
|
|
|
$logger = logger();
|
2024-01-15 15:30:45 +01:00
|
|
|
$logger->addRecord(Monolog\Logger::ERROR, $e);
|
2018-07-27 12:17:17 +02:00
|
|
|
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::error('serverError');
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 15:15:14 +02:00
|
|
|
// Richiesta OPTIONS (controllo da parte del dispositivo)
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
|
2019-07-19 15:23:00 +02:00
|
|
|
$response = Response::error('ok');
|
2018-08-01 15:15:14 +02:00
|
|
|
}
|
|
|
|
|
2024-05-23 11:36:25 +02:00
|
|
|
json_decode((string) $response);
|
2018-06-29 15:57:12 +02:00
|
|
|
|
|
|
|
// Impostazioni di Content-Type e Charset Header
|
|
|
|
if (json_last_error() == JSON_ERROR_NONE) {
|
|
|
|
header('Content-Type: application/json; charset=UTF-8');
|
|
|
|
} else {
|
|
|
|
header('Content-Type: text/plain; charset=UTF-8');
|
|
|
|
}
|
|
|
|
|
2018-01-12 16:23:26 +01:00
|
|
|
// Stampa dei risultati
|
2018-08-09 15:33:01 +02:00
|
|
|
echo $response;
|
2022-11-23 16:45:46 +01:00
|
|
|
|
2023-08-04 14:54:28 +02:00
|
|
|
Auth::logout();
|