62 lines
1.7 KiB
PHP
62 lines
1.7 KiB
PHP
<?
|
|
ini_set('display_errors', 1);
|
|
ini_set('display_startup_errors', 1);
|
|
error_reporting(E_ALL);
|
|
$ruta = "../../";
|
|
require_once "$ruta/include/bd_pdo.php";
|
|
header('Content-Type: application/json');
|
|
|
|
// json data from service\periodos.v1.php (input)
|
|
$data = json_decode(file_get_contents('php://input'), true);
|
|
// check if the input is empty
|
|
|
|
if (is_response_empty($data)) {
|
|
echo json_encode([
|
|
'status' => 'error',
|
|
'message' => 'No se recibieron datos',
|
|
]);
|
|
exit;
|
|
}
|
|
|
|
/*
|
|
{
|
|
"IdNivel": 1,
|
|
"IdPeriodo": 635,
|
|
"NombreNivel": "LICENCIATURA",
|
|
"NombrePeriodo": "241",
|
|
"in_db": false
|
|
inicio,
|
|
fin
|
|
}
|
|
*/
|
|
|
|
// insert into database
|
|
setlocale(LC_TIME, 'es_MX.UTF-8');
|
|
$formatter = new IntlDateFormatter('es_MX', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Mexico_City', IntlDateFormatter::GREGORIAN, 'MMMM');
|
|
$inicio = strtotime($data['inicio']);
|
|
$fin = strtotime($data['fin']);
|
|
try {
|
|
|
|
$result = $db->insert('periodo', [
|
|
'id_periodo_sgu' => $data['IdPeriodo'],
|
|
'periodo_nombre' => "{$data['NombreNivel']}: {$formatter->format($inicio)} - {$formatter->format($fin)} " . date('Y', $inicio),
|
|
'nivel_id' => $data['IdNivel'],
|
|
'periodo_fecha_inicio' => $data['inicio'],
|
|
'periodo_fecha_fin' => $data['fin'],
|
|
'estado_id' => 4,
|
|
'periodo_clave' => $data['NombrePeriodo']
|
|
], ['id_periodo_sgu']);
|
|
} catch (PDOException $th) {
|
|
echo json_encode([
|
|
'success' => false,
|
|
'message' => $th->getMessage()
|
|
]);
|
|
exit;
|
|
}
|
|
echo json_encode($result ? [
|
|
'success' => true,
|
|
'message' => 'Periodo agregado correctamente'
|
|
] : [
|
|
'success' => false,
|
|
'message' => 'Error al agregar el periodo'
|
|
]); |