All
This commit is contained in:
77
action/puesto.php
Normal file
77
action/puesto.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
require_once "{$_SERVER['DOCUMENT_ROOT']}/class/c_login.php";
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!Login::is_logged()) {
|
||||
header('HTTP/1.1 401 Unauthorized');
|
||||
echo json_encode(['error' => 'No se ha iniciado sesión']);
|
||||
exit();
|
||||
}
|
||||
$user = Login::get_user();
|
||||
|
||||
try {
|
||||
switch ($_SERVER['REQUEST_METHOD']) {
|
||||
case 'GET':
|
||||
// Fetch all puestos
|
||||
$facultad_id = $user->facultad['facultad_id'] ?? -1;
|
||||
$puestos = $db->orderBy('puesto_id', 'desc')
|
||||
->where('facultad_id', $facultad_id)
|
||||
->get('puesto');
|
||||
echo json_encode($puestos);
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$raw_input = file_get_contents('php://input');
|
||||
$input_data = json_decode($raw_input, true);
|
||||
|
||||
if (!$input_data || !isset($input_data['puesto_nombre'])) {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
echo json_encode(['error' => 'Datos inválidos']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$puesto_id = $db->insert('puestos', ['puesto_nombre' => $input_data['puesto_nombre']]);
|
||||
echo json_encode(['msg' => 'Puesto creado exitosamente', 'puesto_id' => $puesto_id]);
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
$raw_input = file_get_contents('php://input');
|
||||
$input_data = json_decode($raw_input, true);
|
||||
|
||||
if (!$input_data || !isset($input_data['puesto_id'], $input_data['puesto_nombre'])) {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
echo json_encode(['error' => 'Datos inválidos']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$db->where('puesto_id', $input_data['puesto_id'])->update('puestos', ['puesto_nombre' => $input_data['puesto_nombre']]);
|
||||
echo json_encode(['msg' => 'Puesto actualizado exitosamente']);
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$raw_input = file_get_contents('php://input');
|
||||
$input_data = json_decode($raw_input, true);
|
||||
|
||||
if (!$input_data || !isset($input_data['puesto_id'])) {
|
||||
header('HTTP/1.1 400 Bad Request');
|
||||
echo json_encode(['error' => 'Datos inválidos']);
|
||||
exit();
|
||||
}
|
||||
|
||||
$db->where('puesto_id', $input_data['puesto_id'])->delete('puestos');
|
||||
echo json_encode(['msg' => 'Puesto eliminado exitosamente']);
|
||||
break;
|
||||
|
||||
default:
|
||||
header('HTTP/1.1 405 Method Not Allowed');
|
||||
echo json_encode(['error' => 'Método no permitido']);
|
||||
break;
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
echo json_encode([
|
||||
'error' => $e->getMessage(),
|
||||
'query' => $db->getLastQuery(),
|
||||
'exception' => $e->getTraceAsString()
|
||||
]);
|
||||
}
|
||||
@@ -23,9 +23,15 @@ $user = unserialize($_SESSION['user']);
|
||||
|
||||
|
||||
try{
|
||||
$rs = $db->querySingle('SELECT * from fs_reposicion(:id, NULL, NULL, NULL, NULL, NULL, NULL, NULL)',
|
||||
[':id' => $id]
|
||||
);
|
||||
if($user->rol["rol_id"] == 9){//es coordinador
|
||||
$rs = $db->querySingle('SELECT * from fs_reposicion(:id, NULL, :fac, NULL, NULL, NULL, NULL, NULL, NULL)',
|
||||
[':id' => $id, ":fac"=>$user->facultad["facultad_id"] ]
|
||||
);
|
||||
}else{//supervisor
|
||||
$rs = $db->querySingle('SELECT * from fs_reposicion(:id, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL)',
|
||||
[':id' => $id]
|
||||
);
|
||||
}
|
||||
|
||||
}catch(Exception $e){
|
||||
$return["error"] = "Ocurrió un error al leer los datos de la reposición.";
|
||||
|
||||
Reference in New Issue
Block a user