241 lines
6.2 KiB
PHP
241 lines
6.2 KiB
PHP
<?php
|
|
require_once "connect.php";
|
|
require_once "armasql.php";
|
|
|
|
class UsuariosModel {
|
|
static public function mdlLOVUsuarios() {
|
|
$sql = "select
|
|
u.id,
|
|
u.nombre
|
|
from tem_usuarios u
|
|
order by u.nombre";
|
|
$stmt = Conexion::conectar()->prepare($sql);
|
|
$stmt->execute();
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
static public function mdlListarUsuarios() {
|
|
$sql = "select
|
|
u.id,
|
|
u.nombre,
|
|
u.usuario,
|
|
u.dni,
|
|
u.email,
|
|
u.id_rol,
|
|
(select r.nombre
|
|
from tem_roles r
|
|
where r.id = u.id_rol) as rol,
|
|
case
|
|
when id_habilitado = 1 then 'Si'
|
|
when id_habilitado = 0 then 'No'
|
|
else 'Error'
|
|
end as activo
|
|
from tem_usuarios u
|
|
order by u.nombre";
|
|
$stmt = Conexion::conectar()->prepare($sql);
|
|
$stmt->execute();
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
}
|
|
static public function mdlDatosUsuario($id) {
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare("select id, nombre, usuario, dni, email, id_rol, id_habilitado from tem_usuarios where id = :id");
|
|
$stmt->bindParam(":id", $id, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
|
|
return $stmt->fetchAll();
|
|
} catch (PDOException $e) {
|
|
return $e;
|
|
} finally {
|
|
$stmt = null;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static public function mdlDatosCurso($id) {
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare("
|
|
select id,
|
|
nombre,
|
|
departamento,
|
|
fecha_bp,
|
|
lugar_bp,
|
|
alojamiento_bp,
|
|
alojamiento_inicio_bp,
|
|
alojamiento_fin_bp,
|
|
|
|
fecha_b1_1,
|
|
lugar_b1_1,
|
|
fecha_b1_2,
|
|
lugar_b1_2,
|
|
alojamiento_b1,
|
|
alojamiento_inicio_b1,
|
|
alojamiento_fin_b1,
|
|
|
|
fecha_b2_1,
|
|
lugar_b2_1,
|
|
fecha_b2_2,
|
|
lugar_b2_2,
|
|
alojamiento_b2,
|
|
alojamiento_inicio_b2,
|
|
alojamiento_fin_b2,
|
|
|
|
fecha_b3_1,
|
|
lugar_b3_1,
|
|
fecha_b3_2,
|
|
lugar_b3_2,
|
|
alojamiento_b3,
|
|
alojamiento_inicio_b3,
|
|
alojamiento_fin_b3,
|
|
|
|
comida
|
|
from aca_usuarios
|
|
where id = :id");
|
|
$stmt->bindParam(":id", $id, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
return $e;
|
|
} finally {
|
|
$stmt = null;
|
|
}
|
|
}
|
|
|
|
static public function mdlGuardarCurso($todos_los_campos) {
|
|
$todos_los_campos = normalizarAlojamiento($todos_los_campos);
|
|
|
|
$sql = construirSentenciaUpdate('aca_usuarios', $todos_los_campos);
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare($sql['sql']);
|
|
$stmt->execute($sql['parametros']);
|
|
if ($stmt->rowCount() > 0) {
|
|
$resultado = "OK";
|
|
} else {
|
|
$resultado = "No se realizaron cambios en el usuario";
|
|
}
|
|
$stmt = null;
|
|
return array(
|
|
'respuesta' => $resultado
|
|
);
|
|
} catch (\PDOException $e) {
|
|
return array(
|
|
'respuesta' => "Error en la base de datos: " . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
static public function mdlListarDatosCurso() {
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare("
|
|
SELECT
|
|
id,
|
|
nombre,
|
|
usuario,
|
|
dni,
|
|
email,
|
|
departamento,
|
|
fecha_bp,
|
|
lugar_bp,
|
|
asistencia_bp,
|
|
alojamiento_bp,
|
|
|
|
fecha_b1_1,
|
|
lugar_b1_1,
|
|
asistencia_b1_1,
|
|
fecha_b1_2,
|
|
lugar_b1_2,
|
|
asistencia_b1_2,
|
|
alojamiento_b1,
|
|
|
|
fecha_b2_1,
|
|
lugar_b2_1,
|
|
asistencia_b2_1,
|
|
fecha_b2_2,
|
|
lugar_b2_2,
|
|
asistencia_b2_2,
|
|
alojamiento_b2,
|
|
|
|
fecha_b3_1,
|
|
lugar_b3_1,
|
|
asistencia_b3_1,
|
|
fecha_b3_2,
|
|
lugar_b3_2,
|
|
asistencia_b3_2,
|
|
alojamiento_b3,
|
|
|
|
comida
|
|
FROM aca_participantes");
|
|
$stmt->execute();
|
|
|
|
return $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
return $e;
|
|
} finally {
|
|
$stmt = null;
|
|
}
|
|
}
|
|
|
|
static public function mdlNuevoUsuario($todos_los_campos) {
|
|
$todos_los_campos['id_rol'] = 2;
|
|
$todos_los_campos['id_habilitado'] = 1;
|
|
$todos_los_campos['participante'] = 1;
|
|
$sql = construirSentenciaInsert('aca_usuarios', $todos_los_campos);
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare($sql['sql']);
|
|
$stmt->execute($sql['parametros']);
|
|
if ($stmt->rowCount() > 0) {
|
|
$resultado = "OK";
|
|
} else {
|
|
$resultado = "No se dió de alta el participante";
|
|
}
|
|
$stmt = null;
|
|
return array(
|
|
'respuesta' => $resultado,
|
|
'mensaje' => 'Error desconocido'
|
|
);
|
|
} catch (\PDOException $e) {
|
|
return array(
|
|
'respuesta' => "Error",
|
|
'mensaje' => "Error en la base de datos: " . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
|
|
static public function mdlBorrarUsuario($id) {
|
|
$resultado = "OK";
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare("delete from aca_usuarios where id = :id");
|
|
$stmt->bindParam(":id", $id, PDO::PARAM_STR);
|
|
$stmt->execute();
|
|
} catch (PDOException $e) {
|
|
$resultado = "Error: " . $e;
|
|
} finally {
|
|
$stmt = null;
|
|
return array(
|
|
'respuesta' => $resultado
|
|
);
|
|
}
|
|
}
|
|
|
|
static public function mdlEditarUsuario($todos_los_campos) {
|
|
$sql = construirSentenciaUpdate('aca_usuarios', $todos_los_campos);
|
|
try {
|
|
$stmt = Conexion::conectar()->prepare($sql['sql']);
|
|
$stmt->execute($sql['parametros']);
|
|
if ($stmt->rowCount() > 0) {
|
|
$resultado = "OK";
|
|
} else {
|
|
$resultado = "No se realizo el cambio en el participante";
|
|
}
|
|
$stmt = null;
|
|
return array(
|
|
'respuesta' => $resultado
|
|
);
|
|
} catch (\PDOException $e) {
|
|
return array(
|
|
'respuesta' => "Error en la base de datos: " . $e->getMessage()
|
|
);
|
|
}
|
|
}
|
|
}
|