Stable 2-ago-2023
This commit is contained in:
27
service/auto.php
Normal file
27
service/auto.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?
|
||||
$ruta = "../";
|
||||
require_once "$ruta/include/bd_pdo.php";
|
||||
header('Content-Type: application/json');
|
||||
|
||||
// json data from service\periodos.v1.php (input)
|
||||
|
||||
$urls = array(
|
||||
'periodos.v1',
|
||||
'periodos.v2',
|
||||
'horarios',
|
||||
);
|
||||
|
||||
$urls = array_map(fn($item) => "../$item.php", $urls);
|
||||
|
||||
ob_start();
|
||||
include_once 'periodos.v1.php';
|
||||
$periodos_v1 = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
ob_start();
|
||||
include_once 'periodos.v2.php';
|
||||
$periodos_v2 = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
// echo $periodos_v1;
|
||||
echo $periodos_v2;
|
||||
76
service/backend/carreras.php
Normal file
76
service/backend/carreras.php
Normal file
@@ -0,0 +1,76 @@
|
||||
<?
|
||||
$ruta = "../../";
|
||||
require_once "$ruta/include/bd_pdo.php";
|
||||
header('Content-Type: application/json');
|
||||
global $db;
|
||||
// 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',
|
||||
'data' => $data
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// check if data is array
|
||||
if (!is_array($data)) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'La información recibida no es válida',
|
||||
'data' => $data
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* [{
|
||||
* carrera_nombre
|
||||
* carrera_clave
|
||||
* id_nivel
|
||||
* },]
|
||||
*/
|
||||
// check for this schema
|
||||
array_walk($data, function ($item) {
|
||||
if (!isset($item['ClaveCarrera']) || !isset($item['NombreCarrera']) || !isset($item['IdNivel'])) {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'Los datos recibidos no son validos',
|
||||
'data' => $item
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
array_walk($data, function ($item) use ($db) {
|
||||
|
||||
if ($db->where('carrera_nombre', "%{$item['NombreCarrera']}", 'ILIKE')->has('carrera'))
|
||||
$db
|
||||
->where('carrera_nombre', "%{$item['NombreCarrera']}", 'ILIKE')
|
||||
->update('carrera', [
|
||||
'carrera_nombre' => $item['NombreCarrera'],
|
||||
'id_referencia' => $item['ClaveCarrera'],
|
||||
]);
|
||||
else {
|
||||
try {
|
||||
$db->insert('carrera', [
|
||||
'carrera_nombre' => $item['NombreCarrera'],
|
||||
'id_referencia' => $item['ClaveCarrera'],
|
||||
'nivel_id' => $item['IdNivel'],
|
||||
]);
|
||||
} catch (PDOException $th) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => $th->getMessage(),
|
||||
'last_query' => $db->getLastQuery(),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
});
|
||||
60
service/backend/periodos.php
Normal file
60
service/backend/periodos.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?
|
||||
$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_reference' => $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_reference']);
|
||||
} 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'
|
||||
]);
|
||||
155
service/client.html
Normal file
155
service/client.html
Normal file
@@ -0,0 +1,155 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Cliente REST</title>
|
||||
<script type="module" src="../js/client.js" defer></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"
|
||||
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
|
||||
<link rel="stylesheet" href="../css/indivisa.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header class="container-fluid bg-dark text-white text-center">
|
||||
Página de Cliente REST
|
||||
</header>
|
||||
<main class="container" @vue:mounted="mounted">
|
||||
<div v-for="error in store.errors" class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<strong>Error!</strong> {{error}}
|
||||
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h1>Periodos activos</h1>
|
||||
</div>
|
||||
</div>
|
||||
<ul class="list-group">
|
||||
|
||||
<li href="#" class="list-group-item" v-for="(periodo, index) in store.periodosV1" :key="periodo.IdPeriodo">
|
||||
<!-- v1
|
||||
IdNivel: number;
|
||||
IdPeriodo: number;
|
||||
NombreNivel: string;
|
||||
NombrePeriodo: string;
|
||||
-->
|
||||
<div class="row">
|
||||
<span class="badge bg-secondary">{{index}}</span>
|
||||
<h2 class="text-center">
|
||||
Información
|
||||
</h2>
|
||||
<div class="col-md-3">
|
||||
<strong>ID Nivel:</strong> {{periodo.IdNivel}}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>ID Periodo:</strong> {{periodo.IdPeriodo}}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>Nombre Nivel:</strong> {{periodo.NombreNivel}}
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<strong>Nombre Periodo:</strong> {{periodo.NombrePeriodo}}
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
FechaFin: string;
|
||||
FechaInicio: string;
|
||||
IdPeriodo: number;
|
||||
-- info(IdPeriodo) --
|
||||
-->
|
||||
<div class="row mt-2" v-if="complete(periodo.IdPeriodo)">
|
||||
<h2 class="text-center">
|
||||
Fechas
|
||||
</h2>
|
||||
<div class="col-md-2">
|
||||
<strong>Fecha Inicio:</strong> {{info(periodo.IdPeriodo).FechaInicio}}
|
||||
</div>
|
||||
<div class="col-md-2">
|
||||
<strong>Fecha Fin:</strong> {{info(periodo.IdPeriodo).FechaFin}}
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="!periodo.in_db" class="row mt-2">
|
||||
<!--
|
||||
PeriodoV2
|
||||
ClaveCarrera: string;
|
||||
NombreCarrera: string;
|
||||
PeriodoV1
|
||||
IdNivel: number;
|
||||
-->
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-primary float-end" @click="store.addPeriodo(periodo)"
|
||||
:disabled="!complete(periodo.IdPeriodo)">
|
||||
Agregar
|
||||
<i class="ing ing-mas"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-else class="row mt-2">
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-success float-end disabled">
|
||||
Agregado
|
||||
<i class="ing-aceptar"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mt-2">
|
||||
<div class="col-md-12">
|
||||
<button class="btn btn-secondary float-end" @click="store.addCarreras(periodo.IdPeriodo)">
|
||||
Sincronizar Carreras
|
||||
<i class="ing ing-link"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="accordion mt-2">
|
||||
<div class="accordion-item">
|
||||
<h2 class="accordion-header">
|
||||
<button class="accordion-button collapsed" data-bs-toggle="collapse"
|
||||
:data-bs-target="`#collapse-${periodo.IdPeriodo}`">
|
||||
Horarios del periodo
|
||||
</button>
|
||||
</h2>
|
||||
<div :id="`collapse-${periodo.IdPeriodo}`" class="accordion-collapse collapse">
|
||||
<div class="accordion-body">
|
||||
<ul class="list-group">
|
||||
<li class="list-group-item"
|
||||
v-for="periodo in store.periodosV2.filter(periodov2 => periodov2.IdPeriodo === periodo.IdPeriodo)">
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<strong>Clave Carrera:</strong> {{periodo.ClaveCarrera}}
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<strong>Nombre Carrera:</strong> {{periodo.NombreCarrera}}
|
||||
</div>
|
||||
|
||||
<div class="col-md-3">
|
||||
<span class="badge float-end mx-1"
|
||||
:class="periodo.linked ?'bg-success':'bg-secondary'">
|
||||
<i class="ing-link"></i>
|
||||
</span>
|
||||
<span class="badge float-end mx-1"
|
||||
:class="periodo.in_db ?'bg-success':'bg-secondary'">
|
||||
<i class="ing-aceptar"></i>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</main>
|
||||
<footer>
|
||||
|
||||
</footer>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"
|
||||
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz"
|
||||
crossorigin="anonymous"></script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
81
service/horarios.php
Normal file
81
service/horarios.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?
|
||||
/*
|
||||
• idPeriodo: identificador del periodo a consultar (obligatorio, número entero)
|
||||
• claveFacultad: clave de la facultad a consultar (opcional, cadena)
|
||||
• claveCarrera: clave de la carrera a consultar (opcional, cadena)
|
||||
• claveProfesor: clave del empleado a consultar (opcional, cadena)
|
||||
• fecha: fecha de la clase (opcional, cadena en formato yyyy-MM-dd)
|
||||
*/
|
||||
$required_params = [
|
||||
'idPeriodo'
|
||||
];
|
||||
|
||||
$optional_params = [
|
||||
'claveFacultad',
|
||||
'claveCarrera',
|
||||
'claveProfesor',
|
||||
'fecha'
|
||||
];
|
||||
|
||||
// Check if all required params are present in $_GET
|
||||
$params = array_map('strtolower', $_GET); // Convert keys to lowercase for case-insensitive comparison
|
||||
|
||||
// Check for missing required parameters
|
||||
$missing_params = array_diff($required_params, array_keys($params));
|
||||
if (!empty($missing_params)) {
|
||||
$missing_params_str = implode(', ', $missing_params);
|
||||
die("Missing required parameter(s): $missing_params_str");
|
||||
}
|
||||
|
||||
// Filter and retain only the required and optional parameters
|
||||
$params = array_filter($params, function ($key) use ($required_params, $optional_params) {
|
||||
return in_array($key, $required_params) || in_array($key, $optional_params);
|
||||
}, ARRAY_FILTER_USE_KEY);
|
||||
|
||||
$curl = curl_init();
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/seleccionar",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_ENCODING => "",
|
||||
CURLOPT_MAXREDIRS => 10,
|
||||
CURLOPT_TIMEOUT => 0,
|
||||
CURLOPT_CUSTOMREQUEST => "POST",
|
||||
CURLOPT_POSTFIELDS => json_encode($params),
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"token: e12e2dde0e95a32e274328fd274e07d53f127630c211d838efffacd3cafc4f14edf3f3de6a649eb23f98edf6a1863a008f60e78a316d4dec996b79aeea161a0c",
|
||||
"username: SGU_APSA_AUD_ASIST",
|
||||
"Content-Type: application/json"
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err)
|
||||
die("cURL Error #:$err");
|
||||
|
||||
|
||||
$selectedData = json_decode($response, true);
|
||||
|
||||
$rawInput = file_get_contents('php://input');
|
||||
|
||||
$input = json_decode($rawInput, true);
|
||||
// check for {collect: []} in raw input
|
||||
if (isset($input['collect']) && is_array($input['collect'])) {
|
||||
$collect = $input['collect'];
|
||||
$selectedData = array_map(function ($item) use ($collect) {
|
||||
return array_intersect_key($item, array_flip($collect));
|
||||
}, $selectedData);
|
||||
// unique and distinct
|
||||
$selectedData = array_unique($selectedData, SORT_REGULAR);
|
||||
}
|
||||
else {
|
||||
// return invalid request error
|
||||
die($rawInput);
|
||||
}
|
||||
|
||||
// Output the selected data directly
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($selectedData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
35
service/periodos.v1.php
Normal file
35
service/periodos.v1.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?
|
||||
$ruta = "../";
|
||||
require_once '../include/bd_pdo.php';
|
||||
$curl = curl_init();
|
||||
global $db;
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/catalogos/periodos/v1/seleccionar",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => "",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"token: f65f921264e4ab135472adb5a946212dd4b995d929294afec31eef192b8de8d6a076648906f70012c9803e5918d0fc99499d7d1fb7c998cc06c7a10eef61f66a",
|
||||
"username: SGU_APSA_AUD_ASIST"
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err)
|
||||
die("cURL Error #:$err");
|
||||
|
||||
$data = json_decode($response, true);
|
||||
|
||||
$in_db = array_map(function ($item) use ($db) {
|
||||
$item['in_db'] = $db->where('id_reference', $item['IdPeriodo'])->has('periodo');
|
||||
return $item;
|
||||
}, $data);
|
||||
|
||||
$selectedData = array_unique($in_db, SORT_REGULAR);
|
||||
|
||||
// Output the selected data directly
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($selectedData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
37
service/periodos.v2.php
Normal file
37
service/periodos.v2.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?
|
||||
$ruta = "../";
|
||||
require_once '../include/bd_pdo.php';
|
||||
global $db;
|
||||
|
||||
$curl = curl_init();
|
||||
|
||||
curl_setopt_array($curl, [
|
||||
CURLOPT_URL => "https://portal.ulsa.edu.mx/servicios/AuditoriaAsistencialRest/AuditoriaAsistencialService.svc/auditoriaAsistencial/catalogos/periodos/v2/seleccionar",
|
||||
CURLOPT_RETURNTRANSFER => true,
|
||||
CURLOPT_POSTFIELDS => "",
|
||||
CURLOPT_HTTPHEADER => [
|
||||
"token: f65f921264e4ab135472adb5a946212dd4b995d929294afec31eef192b8de8d6a076648906f70012c9803e5918d0fc99499d7d1fb7c998cc06c7a10eef61f66a",
|
||||
"username: SGU_APSA_AUD_ASIST"
|
||||
],
|
||||
]);
|
||||
|
||||
$response = curl_exec($curl);
|
||||
$err = curl_error($curl);
|
||||
|
||||
curl_close($curl);
|
||||
|
||||
if ($err)
|
||||
die("cURL Error #:$err");
|
||||
|
||||
|
||||
$json = json_decode($response, true);
|
||||
|
||||
$selectedData = array_map(function ($item) use ($db) {
|
||||
$item['in_db'] = $db->where('carrera_nombre', $item['NombreCarrera'], 'ILIKE')->has('carrera');
|
||||
$item['linked'] = $db->where('id_referencia', $item['ClaveCarrera'], 'ILIKE')->has('carrera');
|
||||
return $item;
|
||||
}, $json);
|
||||
|
||||
// Output the selected data directly
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($selectedData, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
|
||||
Reference in New Issue
Block a user