periodos.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?
  2. ini_set('display_errors', 1);
  3. ini_set('display_startup_errors', 1);
  4. error_reporting(E_ALL);
  5. $ruta = "../../";
  6. require_once "$ruta/include/bd_pdo.php";
  7. header('Content-Type: application/json');
  8. // json data from service\periodos.v1.php (input)
  9. $data = json_decode(file_get_contents('php://input'), true);
  10. // check if the input is empty
  11. if (is_response_empty($data)) {
  12. echo json_encode([
  13. 'status' => 'error',
  14. 'message' => 'No se recibieron datos',
  15. ]);
  16. exit;
  17. }
  18. /*
  19. {
  20. "IdNivel": 1,
  21. "IdPeriodo": 635,
  22. "NombreNivel": "LICENCIATURA",
  23. "NombrePeriodo": "241",
  24. "in_db": false
  25. inicio,
  26. fin
  27. }
  28. */
  29. // insert into database
  30. setlocale(LC_TIME, 'es_MX.UTF-8');
  31. $formatter = new IntlDateFormatter('es_MX', IntlDateFormatter::FULL, IntlDateFormatter::FULL, 'America/Mexico_City', IntlDateFormatter::GREGORIAN, 'MMMM');
  32. $inicio = strtotime($data['inicio']);
  33. $fin = strtotime($data['fin']);
  34. try {
  35. $result = $db->insert('periodo', [
  36. 'id_periodo_sgu' => $data['IdPeriodo'],
  37. 'periodo_nombre' => "{$data['NombreNivel']}: {$formatter->format($inicio)} - {$formatter->format($fin)} " . date('Y', $inicio),
  38. 'nivel_id' => $data['IdNivel'],
  39. 'periodo_fecha_inicio' => $data['inicio'],
  40. 'periodo_fecha_fin' => $data['fin'],
  41. 'estado_id' => 4,
  42. 'periodo_clave' => $data['NombrePeriodo']
  43. ], ['id_periodo_sgu']);
  44. } catch (PDOException $th) {
  45. echo json_encode([
  46. 'success' => false,
  47. 'message' => $th->getMessage()
  48. ]);
  49. exit;
  50. }
  51. echo json_encode($result ? [
  52. 'success' => true,
  53. 'message' => 'Periodo agregado correctamente'
  54. ] : [
  55. 'success' => false,
  56. 'message' => 'Error al agregar el periodo'
  57. ]);