revisión gestiones
This commit is contained in:
parent
57b8a5e43c
commit
3a608a73b1
|
@ -1,126 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$profesorId = $_SESSION['profesor']['id'] ?? null;
|
||||
|
||||
try {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$alumnoId = $_GET['alumno_id'] ?? null;
|
||||
|
||||
if ($alumnoId) {
|
||||
// Obtener cursos de un alumno específico (con tipo)
|
||||
$query = "SELECT c.id, c.nombre, c.tipo FROM cursos c
|
||||
JOIN alumnos_cursos ac ON c.id = ac.curso_id
|
||||
WHERE ac.alumno_id = ? AND c.profesor_id = ?";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute([$alumnoId, $profesorId]);
|
||||
} else {
|
||||
// Obtener todos los vínculos alumnos-cursos con estado y tipo
|
||||
$query = "
|
||||
SELECT
|
||||
ac.id,
|
||||
ac.alumno_id,
|
||||
ac.curso_id,
|
||||
c.nombre AS curso_nombre,
|
||||
c.tipo,
|
||||
c.estado
|
||||
FROM alumnos_cursos ac
|
||||
JOIN cursos c ON ac.curso_id = c.id
|
||||
WHERE c.profesor_id = ?
|
||||
";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute([$profesorId]);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $stmt->fetchAll(PDO::FETCH_ASSOC)
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$cursoId = $data['curso_id'] ?? null;
|
||||
$alumnos = $data['alumnos'] ?? [];
|
||||
|
||||
if (empty($cursoId) || empty($alumnos)) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Datos incompletos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar que el curso pertenece al profesor
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE id = ? AND profesor_id = ?");
|
||||
$stmt->execute([$cursoId, $profesorId]);
|
||||
|
||||
if (!$stmt->fetch()) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
foreach ($alumnos as $alumnoId) {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO alumnos_cursos (alumno_id, curso_id, estado)
|
||||
VALUES (?, ?, 'cursando')
|
||||
ON DUPLICATE KEY UPDATE estado = 'cursando'
|
||||
");
|
||||
$stmt->execute([$alumnoId, $cursoId]);
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Alumnos asignados correctamente'
|
||||
]);
|
||||
break;
|
||||
|
||||
|
||||
|
||||
case 'DELETE':
|
||||
$alumnoId = $_GET['alumno_id'] ?? null;
|
||||
$cursoId = $_GET['curso_id'] ?? null;
|
||||
|
||||
if (!$alumnoId || !$cursoId) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'IDs requeridos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar que el curso pertenece al profesor
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE id = ? AND profesor_id = ?");
|
||||
$stmt->execute([$cursoId, $profesorId]);
|
||||
|
||||
if (!$stmt->fetch()) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Eliminar asignación
|
||||
$stmt = $pdo->prepare("DELETE FROM alumnos_cursos WHERE alumno_id = ? AND curso_id = ?");
|
||||
$stmt->execute([$alumnoId, $cursoId]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Alumno desvinculado del curso correctamente'
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'error' => 'Método no permitido']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'Error en la base de datos: ' . $e->getMessage()]);
|
||||
}
|
||||
?>
|
206
api/alumnos.php
206
api/alumnos.php
|
@ -1,206 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
try {
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
// Obtener todos los alumnos
|
||||
$query = "SELECT * FROM alumnos ORDER BY nombre ASC";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
$alumnos = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $alumnos,
|
||||
'count' => count($alumnos)
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($data['nombre']) || empty($data['email'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Nombre y email son requeridos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar email duplicado
|
||||
$stmt = $pdo->prepare("SELECT id FROM alumnos WHERE email = ?");
|
||||
$stmt->execute([$data['email']]);
|
||||
if ($stmt->fetch()) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'El correo ya está registrado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar teléfono duplicado
|
||||
if (!empty($data['telefono'])) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM alumnos WHERE telefono = ?");
|
||||
$stmt->execute([$data['telefono']]);
|
||||
if ($stmt->fetch()) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'El teléfono ya está registrado']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
try {
|
||||
// Insertar alumno
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO alumnos (nombre, email, telefono)
|
||||
VALUES (?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['nombre'],
|
||||
$data['email'],
|
||||
$data['telefono'] ?? null
|
||||
]);
|
||||
|
||||
$alumnoId = $pdo->lastInsertId();
|
||||
|
||||
// Si viene curso_id, asignar también a curso
|
||||
if (!empty($data['curso_id'])) {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO alumnos_cursos (alumno_id, curso_id, estado)
|
||||
VALUES (?, ?, 'cursando')
|
||||
");
|
||||
$stmt->execute([$alumnoId, $data['curso_id']]);
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => $alumnoId,
|
||||
'message' => 'Alumno creado y asignado exitosamente'
|
||||
]);
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'Error al registrar: ' . $e->getMessage()]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
case 'PUT':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($data['id']) || empty($data['nombre']) || empty($data['email'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Datos incompletos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar email duplicado (excluyendo el mismo alumno)
|
||||
$stmt = $pdo->prepare("SELECT id FROM alumnos WHERE email = ? AND id != ?");
|
||||
$stmt->execute([$data['email'], $data['id']]);
|
||||
if ($stmt->fetch()) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'El correo ya está registrado por otro alumno']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar teléfono duplicado (excluyendo el mismo alumno)
|
||||
if (!empty($data['telefono'])) {
|
||||
$stmt = $pdo->prepare("SELECT id FROM alumnos WHERE telefono = ? AND id != ?");
|
||||
$stmt->execute([$data['telefono'], $data['id']]);
|
||||
if ($stmt->fetch()) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'El teléfono ya está registrado por otro alumno']);
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE alumnos SET
|
||||
nombre = ?,
|
||||
email = ?,
|
||||
telefono = ?
|
||||
WHERE id = ?
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['nombre'],
|
||||
$data['email'],
|
||||
$data['telefono'] ?? null,
|
||||
$data['id']
|
||||
]);
|
||||
|
||||
// Si curso_id viene en la actualización, actualizar también el curso
|
||||
if (!empty($data['curso_id'])) {
|
||||
// Verifica si ya tiene una relación previa
|
||||
$check = $pdo->prepare("SELECT id FROM alumnos_cursos WHERE alumno_id = ?");
|
||||
$check->execute([$data['id']]);
|
||||
|
||||
if ($check->fetch()) {
|
||||
// Si ya tiene relación, actualizamos el curso asignado
|
||||
$updateCurso = $pdo->prepare("
|
||||
UPDATE alumnos_cursos SET curso_id = ?, estado = 'cursando'
|
||||
WHERE alumno_id = ?
|
||||
");
|
||||
$updateCurso->execute([$data['curso_id'], $data['id']]);
|
||||
} else {
|
||||
// Si no tiene relación previa, la insertamos
|
||||
$insertCurso = $pdo->prepare("
|
||||
INSERT INTO alumnos_cursos (alumno_id, curso_id, estado)
|
||||
VALUES (?, ?, 'cursando')
|
||||
");
|
||||
$insertCurso->execute([$data['id'], $data['curso_id']]);
|
||||
}
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Alumno actualizado exitosamente'
|
||||
]);
|
||||
break;
|
||||
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'ID de alumno no proporcionado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar si el alumno está asignado a algún curso primero
|
||||
$stmt = $pdo->prepare("SELECT COUNT(*) FROM alumnos_cursos WHERE alumno_id = ?");
|
||||
$stmt->execute([$id]);
|
||||
$tieneCursos = $stmt->fetchColumn();
|
||||
|
||||
if ($tieneCursos > 0) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'No se puede eliminar, el alumno está asignado a cursos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM alumnos WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => 'Alumno eliminado exitosamente'
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'error' => 'Método no permitido']);
|
||||
}
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'Error en la base de datos: ' . $e->getMessage()]);
|
||||
}
|
||||
?>
|
171
api/cursos.php
171
api/cursos.php
|
@ -1,171 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$profesorId = $_SESSION['profesor']['id'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
try {
|
||||
$tipo = $_GET['tipo'] ?? null;
|
||||
if ($tipo) {
|
||||
$query = "SELECT * FROM cursos WHERE profesor_id = ? AND tipo = ?";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute([$profesorId, $tipo]);
|
||||
} else {
|
||||
$query = "SELECT * FROM cursos WHERE profesor_id = ?";
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute([$profesorId]);
|
||||
}
|
||||
echo json_encode(['success' => true, 'data' => $stmt->fetchAll()]);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error al cargar cursos']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($data['nombre']) || empty($data['tipo'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Nombre y tipo son requeridos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Validar que no exista otro curso con el mismo nombre y tipo para ese profesor
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE nombre = ? AND tipo = ? AND profesor_id = ?");
|
||||
$stmt->execute([$data['nombre'], $data['tipo'], $profesorId]);
|
||||
if ($stmt->fetch()) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => "Ya existe un curso llamado '{$data['nombre']}' de tipo '{$data['tipo']}'."
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO cursos (nombre, descripcion, tipo, competencias, docente, horas_trabajadas, estado, profesor_id)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['nombre'],
|
||||
$data['descripcion'] ?? null,
|
||||
$data['tipo'],
|
||||
$data['competencias'] ?? null,
|
||||
$data['docente'] ?? null,
|
||||
$data['horas_trabajadas'] ?? null,
|
||||
$data['estado'],
|
||||
$profesorId
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 'PUT':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (empty($data['id']) || empty($data['nombre']) || empty($data['tipo'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'Datos incompletos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Verificar que el curso pertenece al profesor
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE id = ? AND profesor_id = ?");
|
||||
$stmt->execute([$data['id'], $profesorId]);
|
||||
|
||||
if (!$stmt->fetch()) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validar que no haya otro curso con el mismo nombre y tipo (excluyendo el actual)
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE nombre = ? AND tipo = ? AND profesor_id = ? AND id != ?");
|
||||
$stmt->execute([$data['nombre'], $data['tipo'], $profesorId, $data['id']]);
|
||||
if ($stmt->fetch()) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'error' => "Ya existe otro curso llamado '{$data['nombre']}' de tipo '{$data['tipo']}'."
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE cursos SET
|
||||
nombre = ?,
|
||||
descripcion = ?,
|
||||
tipo = ?,
|
||||
competencias = ?,
|
||||
docente = ?,
|
||||
horas_trabajadas = ?,
|
||||
estado = ?
|
||||
WHERE id = ?
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['nombre'],
|
||||
$data['descripcion'] ?? null,
|
||||
$data['tipo'],
|
||||
$data['competencias'] ?? null,
|
||||
$data['docente'] ?? null,
|
||||
$data['horas_trabajadas'] ?? null,
|
||||
$data['estado'],
|
||||
$data['id']
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error al actualizar curso']);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'DELETE':
|
||||
$id = $_GET['id'] ?? null;
|
||||
if (!$id) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['error' => 'ID de curso no proporcionado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Verificar que el curso pertenece al profesor
|
||||
$stmt = $pdo->prepare("SELECT id FROM cursos WHERE id = ? AND profesor_id = ?");
|
||||
$stmt->execute([$id, $profesorId]);
|
||||
|
||||
if (!$stmt->fetch()) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("DELETE FROM cursos WHERE id = ?");
|
||||
$stmt->execute([$id]);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
} catch (PDOException $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['error' => 'Error al eliminar curso']);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Método no permitido']);
|
||||
}
|
||||
?>
|
|
@ -1,54 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$profesorId = $_GET['profesor_id'] ?? null;
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
d.codigo_unico,
|
||||
d.fecha_emision,
|
||||
a.nombre AS alumno_nombre,
|
||||
a.email AS alumno_email,
|
||||
c.nombre AS curso_nombre,
|
||||
c.tipo AS curso_tipo
|
||||
FROM diplomas d
|
||||
JOIN alumnos_cursos ac ON d.alumno_curso_id = ac.id
|
||||
JOIN alumnos a ON ac.alumno_id = a.id
|
||||
JOIN cursos c ON ac.curso_id = c.id
|
||||
";
|
||||
|
||||
$params = [];
|
||||
if ($profesorId) {
|
||||
$query .= " WHERE c.profesor_id = ?";
|
||||
$params[] = $profesorId;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY d.fecha_emision DESC";
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute($params);
|
||||
|
||||
$diplomas = [];
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$row['fecha_formateada'] = date("d/m/Y", strtotime($row['fecha_emision']));
|
||||
$diplomas[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $diplomas,
|
||||
'count' => count($diplomas)
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
|
@ -1,91 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
$profesorId = $_GET['profesor_id'] ?? null;
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
d.codigo_unico,
|
||||
d.fecha_emision,
|
||||
a.nombre AS alumno_nombre,
|
||||
a.email AS alumno_email,
|
||||
c.nombre AS curso_nombre,
|
||||
c.tipo AS curso_tipo
|
||||
FROM diplomas d
|
||||
JOIN alumnos_cursos ac ON d.alumno_curso_id = ac.id
|
||||
JOIN alumnos a ON ac.alumno_id = a.id
|
||||
JOIN cursos c ON ac.curso_id = c.id
|
||||
";
|
||||
|
||||
$params = [];
|
||||
if ($profesorId) {
|
||||
$query .= " WHERE c.profesor_id = ?";
|
||||
$params[] = $profesorId;
|
||||
}
|
||||
|
||||
$query .= " ORDER BY d.fecha_emision DESC";
|
||||
|
||||
$stmt = $pdo->prepare($query);
|
||||
$stmt->execute($params);
|
||||
|
||||
$diplomas = [];
|
||||
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
|
||||
$row['fecha_formateada'] = date("d/m/Y", strtotime($row['fecha_emision']));
|
||||
$diplomas[] = $row;
|
||||
}
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $diplomas,
|
||||
'count' => count($diplomas)
|
||||
]);
|
||||
|
||||
} catch (Exception $e) {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
if (!isset($input['alumno_curso_id']) || empty($input['alumno_curso_id'])) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'alumno_curso_id requerido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Generar código único
|
||||
function generarCodigoUnico($length = 10) {
|
||||
return substr(str_shuffle("ABCDEFGHJKLMNPQRSTUVWXYZ23456789"), 0, $length);
|
||||
}
|
||||
|
||||
$alumnoCursoId = $input['alumno_curso_id'];
|
||||
$codigoUnico = generarCodigoUnico();
|
||||
|
||||
// Verificar que no exista diploma duplicado para el mismo alumno_curso_id
|
||||
$stmt = $pdo->prepare("SELECT id FROM diplomas WHERE alumno_curso_id = ?");
|
||||
$stmt->execute([$alumnoCursoId]);
|
||||
if ($stmt->fetch()) {
|
||||
http_response_code(409);
|
||||
echo json_encode(['success' => false, 'error' => 'Este alumno ya tiene un diploma registrado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Insertar diploma
|
||||
$stmt = $pdo->prepare("INSERT INTO diplomas (alumno_curso_id, codigo_unico) VALUES (?, ?)");
|
||||
if ($stmt->execute([$alumnoCursoId, $codigoUnico])) {
|
||||
echo json_encode(['success' => true, 'codigo_unico' => $codigoUnico]);
|
||||
} else {
|
||||
http_response_code(500);
|
||||
echo json_encode(['success' => false, 'error' => 'No se pudo guardar el diploma']);
|
||||
}
|
||||
exit;
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
$profesorId = $_SESSION['profesor']['id'] ?? null;
|
||||
|
||||
switch ($method) {
|
||||
case 'POST':
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$alumnoCursoId = $input['alumno_curso_id'] ?? null;
|
||||
|
||||
if (!$alumnoCursoId) {
|
||||
http_response_code(400);
|
||||
echo json_encode(['success' => false, 'error' => 'Falta ID de alumno_curso']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Validar que el alumno_curso pertenece al profesor
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT ac.id
|
||||
FROM alumnos_cursos ac
|
||||
JOIN cursos c ON ac.curso_id = c.id
|
||||
WHERE ac.id = ? AND c.profesor_id = ?
|
||||
");
|
||||
$stmt->execute([$alumnoCursoId, $profesorId]);
|
||||
|
||||
if (!$stmt->fetch()) {
|
||||
http_response_code(403);
|
||||
echo json_encode(['success' => false, 'error' => 'No autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Verificar si ya existe un diploma para este alumno_curso
|
||||
$stmt = $pdo->prepare("SELECT codigo_unico FROM diplomas WHERE alumno_curso_id = ?");
|
||||
$stmt->execute([$alumnoCursoId]);
|
||||
$existing = $stmt->fetchColumn();
|
||||
|
||||
if ($existing) {
|
||||
http_response_code(409);
|
||||
echo json_encode(['success' => false, 'error' => 'Este alumno ya tiene un diploma', 'codigo_unico' => $existing]);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Generar código único y fecha
|
||||
$codigo = strtoupper(substr(uniqid(), -6));
|
||||
$fecha = date('Y-m-d');
|
||||
|
||||
// Insertar nuevo diploma
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO diplomas (alumno_curso_id, codigo_unico, fecha_emision)
|
||||
VALUES (?, ?, ?)
|
||||
");
|
||||
$stmt->execute([$alumnoCursoId, $codigo, $fecha]);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'codigo_unico' => $codigo
|
||||
]);
|
||||
break;
|
||||
|
||||
case 'GET':
|
||||
if (!$profesorId) {
|
||||
echo json_encode(['success' => false, 'error' => 'Profesor no identificado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT d.codigo_unico, d.fecha_emision,
|
||||
a.nombre AS alumno_nombre, a.email AS alumno_email,
|
||||
c.nombre AS curso_nombre, c.tipo AS curso_tipo
|
||||
FROM diplomas d
|
||||
JOIN alumnos_cursos ac ON d.alumno_curso_id = ac.id
|
||||
JOIN alumnos a ON ac.alumno_id = a.id
|
||||
JOIN cursos c ON ac.curso_id = c.id
|
||||
WHERE c.profesor_id = ?
|
||||
ORDER BY d.fecha_emision DESC
|
||||
");
|
||||
$stmt->execute([$profesorId]);
|
||||
|
||||
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'data' => $result
|
||||
]);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'error' => 'Método no permitido']);
|
||||
}
|
|
@ -1,109 +0,0 @@
|
|||
<?php
|
||||
require '../includes/config.php';
|
||||
header('Content-Type: application/json');
|
||||
|
||||
if (!is_logged_in()) {
|
||||
http_response_code(401);
|
||||
echo json_encode(['success' => false, 'error' => 'No autenticado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$input = json_decode(file_get_contents('php://input'), true);
|
||||
$alumnos = $input['alumnos'] ?? [];
|
||||
|
||||
if (empty($alumnos)) {
|
||||
echo json_encode(['success' => false, 'error' => 'No se recibieron alumnos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
function limpiar($s) {
|
||||
return trim($s, "\"' ");
|
||||
}
|
||||
|
||||
$errores = [];
|
||||
$importados = 0;
|
||||
|
||||
foreach ($alumnos as $index => $alumno) {
|
||||
$fila = $index + 2;
|
||||
|
||||
$nombre = limpiar($alumno['nombre'] ?? '');
|
||||
$email = limpiar($alumno['email'] ?? '');
|
||||
$telefono = limpiar($alumno['telefono'] ?? '');
|
||||
$tipoCurso = strtolower(limpiar($alumno['tipoCurso'] ?? ''));
|
||||
$nombreCurso = limpiar($alumno['nombreCurso'] ?? '');
|
||||
|
||||
if (!$nombre || !$email || !$telefono || !$tipoCurso || !$nombreCurso) {
|
||||
$errores[] = "Fila $fila: faltan datos obligatorios.";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Verificar curso+tipo
|
||||
$stmtCurso = $pdo->prepare("
|
||||
SELECT id
|
||||
FROM cursos
|
||||
WHERE nombre = ? AND tipo = ?
|
||||
");
|
||||
$stmtCurso->execute([$nombreCurso, $tipoCurso]);
|
||||
$curso = $stmtCurso->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$curso) {
|
||||
$errores[] = "Fila $fila: el curso '$nombreCurso' con tipo '$tipoCurso' no existe.";
|
||||
continue;
|
||||
}
|
||||
|
||||
// Verificar duplicados por separado
|
||||
$emailDuplicado = false;
|
||||
$telefonoDuplicado = false;
|
||||
|
||||
$stmtEmail = $pdo->prepare("SELECT id FROM alumnos WHERE email = ?");
|
||||
$stmtEmail->execute([$email]);
|
||||
if ($stmtEmail->fetch()) {
|
||||
$emailDuplicado = true;
|
||||
}
|
||||
|
||||
$stmtTel = $pdo->prepare("SELECT id FROM alumnos WHERE telefono = ?");
|
||||
$stmtTel->execute([$telefono]);
|
||||
if ($stmtTel->fetch()) {
|
||||
$telefonoDuplicado = true;
|
||||
}
|
||||
|
||||
if ($emailDuplicado || $telefonoDuplicado) {
|
||||
if ($emailDuplicado && $telefonoDuplicado) {
|
||||
$errores[] = "Fila $fila: el email '$email' y el teléfono '$telefono' ya están registrados.";
|
||||
} elseif ($emailDuplicado) {
|
||||
$errores[] = "Fila $fila: el email '$email' ya está registrado.";
|
||||
} elseif ($telefonoDuplicado) {
|
||||
$errores[] = "Fila $fila: el teléfono '$telefono' ya está registrado.";
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$stmtAlumno = $pdo->prepare("INSERT INTO alumnos (nombre, email, telefono) VALUES (?, ?, ?)");
|
||||
$stmtAlumno->execute([$nombre, $email, $telefono]);
|
||||
$alumnoId = $pdo->lastInsertId();
|
||||
|
||||
$stmtAsignar = $pdo->prepare("INSERT INTO alumnos_cursos (alumno_id, curso_id, estado) VALUES (?, ?, 'cursando')");
|
||||
$stmtAsignar->execute([$alumnoId, $curso['id']]);
|
||||
|
||||
$pdo->commit();
|
||||
$importados++;
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
$errores[] = "Fila $fila: error al guardar en base de datos.";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($errores)) {
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'conflicts' => $errores
|
||||
]);
|
||||
} else {
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'message' => "$importados alumnos importados exitosamente."
|
||||
]);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 1);
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
http_response_code(405);
|
||||
echo json_encode(['success' => false, 'message' => 'Método no permitido']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$email = trim($_POST['email'] ?? '');
|
||||
$password = $_POST['password'] ?? '';
|
||||
|
||||
if (empty($email) || empty($password)) {
|
||||
echo json_encode(['success' => false, 'message' => 'Email y contraseña son requeridos']);
|
||||
exit;
|
||||
}
|
||||
|
||||
try {
|
||||
// Buscar profesor en la base de datos
|
||||
$stmt = $pdo->prepare("SELECT * FROM usuarios WHERE email = ? AND aprobado = 1");
|
||||
$stmt->execute([$email]);
|
||||
$profesor = $stmt->fetch();
|
||||
|
||||
if (!$profesor) {
|
||||
echo json_encode(['success' => false, 'message' => 'Profesor no encontrado o no aprobado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
if (!password_verify($password, $profesor['password'])) {
|
||||
echo json_encode(['success' => false, 'message' => 'Contraseña incorrecta']);
|
||||
exit;
|
||||
}
|
||||
|
||||
// Configurar sesión de profesor
|
||||
$_SESSION['profesor'] = [
|
||||
'id' => $profesor['id'],
|
||||
'nombre' => $profesor['nombre'],
|
||||
'email' => $profesor['email']
|
||||
];
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'redirect' => 'dashboard.php',
|
||||
'profesor_id' => $profesor['id']
|
||||
]);
|
||||
|
||||
|
||||
} catch (PDOException $e) {
|
||||
error_log('Error en login.php: ' . $e->getMessage());
|
||||
echo json_encode([
|
||||
'success' => false,
|
||||
'message' => 'Error en el servidor. Por favor, intente más tarde.'
|
||||
]);
|
||||
}
|
||||
?>
|
|
@ -1,6 +0,0 @@
|
|||
<?php
|
||||
session_start();
|
||||
session_destroy();
|
||||
header('Location: ../index.php');
|
||||
exit;
|
||||
?>
|
|
@ -1,42 +0,0 @@
|
|||
<?php
|
||||
header('Content-Type: application/json');
|
||||
require '../includes/config.php';
|
||||
|
||||
if (!is_logged_in() || $_SESSION['user']['rol'] !== 'admin') {
|
||||
http_response_code(403);
|
||||
echo json_encode(['error' => 'Acceso no autorizado']);
|
||||
exit;
|
||||
}
|
||||
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
|
||||
switch ($method) {
|
||||
case 'GET':
|
||||
$stmt = $pdo->query("SELECT id, username, nombre, email, rol FROM usuarios");
|
||||
echo json_encode($stmt->fetchAll());
|
||||
break;
|
||||
|
||||
case 'POST':
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$hashedPassword = password_hash($data['password'], PASSWORD_DEFAULT);
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO usuarios (username, password, nombre, email, rol)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$data['username'],
|
||||
$hashedPassword,
|
||||
$data['nombre'],
|
||||
$data['email'],
|
||||
$data['rol'] ?? 'user'
|
||||
]);
|
||||
|
||||
echo json_encode(['success' => true, 'id' => $pdo->lastInsertId()]);
|
||||
break;
|
||||
|
||||
default:
|
||||
http_response_code(405);
|
||||
echo json_encode(['error' => 'Método no permitido']);
|
||||
}
|
||||
?>
|
|
@ -612,12 +612,9 @@ header h1 {
|
|||
}
|
||||
|
||||
.description-cell:hover {
|
||||
white-space: normal;
|
||||
overflow: visible;
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
background: white;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
|
||||
background: inherit;
|
||||
box-shadow: none;
|
||||
cursor: default;
|
||||
}
|
||||
|
||||
/* Estilos para mensaje de no datos */
|
||||
|
@ -1048,3 +1045,16 @@ svg:hover + .tooltip-csv,
|
|||
visibility: visible;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.table-container td,
|
||||
.table-container th {
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.table-container td:nth-child(1),
|
||||
.table-container td:nth-child(2) {
|
||||
max-width: 280px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
|
|
@ -142,8 +142,6 @@ async function renderCursosGenerablesPorTipo(tipo) {
|
|||
const vinculos = await fetch("api/alumnos-cursos.php").then((r) => r.json());
|
||||
|
||||
const cursosConAlumnos = cursosFiltrados.map((curso) => {
|
||||
console.log("Curso:", curso);
|
||||
console.log("Vínculos:", vinculos.data.filter((ac) => ac.curso_id == curso.id));
|
||||
const alumnosDelCurso = vinculos.data
|
||||
.filter((ac) => ac.curso_id == curso.id)
|
||||
.map((ac) => {
|
||||
|
@ -159,27 +157,44 @@ async function renderCursosGenerablesPorTipo(tipo) {
|
|||
.map((curso) => {
|
||||
const alumnosHtml = curso.alumnos.length
|
||||
? curso.alumnos
|
||||
.map(
|
||||
(al) => `
|
||||
<tr>
|
||||
<td>${al.nombre}</td>
|
||||
<td>${al.email}</td>
|
||||
<td>
|
||||
<button class="btn btn-sm" onclick="generateDiploma(${al.alumno_curso_id})">Generar Diploma</button>
|
||||
<button class="btn btn-sm btn-outline" disabled>Enviar Diploma</button>
|
||||
</td>
|
||||
</tr>`
|
||||
)
|
||||
.map((al) => {
|
||||
const safeNombre = al.nombre.replace(/'/g, "\\'").replace(/"/g, """);
|
||||
const safeEmail = al.email.replace(/'/g, "\\'").replace(/"/g, """);
|
||||
|
||||
return `
|
||||
<tr>
|
||||
<td class="description-cell">
|
||||
<span class="truncated-text" id="nombre-${al.id}">${al.nombre}</span>
|
||||
<span class="read-more-container" id="nombre-readmore-${al.id}"></span>
|
||||
</td>
|
||||
<td class="description-cell">
|
||||
<span class="truncated-text" id="email-${al.id}">${al.email}</span>
|
||||
<span class="read-more-container" id="email-readmore-${al.id}"></span>
|
||||
</td>
|
||||
<td>
|
||||
<div class="action-buttons" style="display: flex; gap: 0.5rem; flex-wrap: wrap;">
|
||||
<button class="btn btn-sm" onclick="generateDiploma(${al.alumno_curso_id})">Generar Diploma</button>
|
||||
<button class="btn btn-sm btn-outline" disabled>Enviar</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>`;
|
||||
})
|
||||
.join("")
|
||||
: `<tr><td colspan="3" class="text-muted">No hay alumnos inscritos</td></tr>`;
|
||||
|
||||
return `
|
||||
<div class="card">
|
||||
<h3>${curso.nombre} <span class="badge ${getCourseTypeClass(curso.tipo)}">${formatCourseType(curso.tipo)}</span></h3>
|
||||
<div class="card" style="padding: 1.5rem 2rem; border-radius: 8px; margin-bottom: 1.5rem; box-shadow: 0 2px 6px rgba(0,0,0,0.05);">
|
||||
<h3 style="margin-bottom: 1rem;">${curso.nombre}
|
||||
<span class="badge ${getCourseTypeClass(curso.tipo)}">${formatCourseType(curso.tipo)}</span>
|
||||
</h3>
|
||||
<div class="table-container">
|
||||
<table class="table">
|
||||
<table class="table" style="width: 100%;">
|
||||
<thead>
|
||||
<tr><th>Alumno</th><th>Email</th><th>Acciones</th></tr>
|
||||
<tr>
|
||||
<th style="width: 35%;">Alumno</th>
|
||||
<th style="width: 35%;">Email</th>
|
||||
<th style="width: 30%;">Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>${alumnosHtml}</tbody>
|
||||
</table>
|
||||
|
@ -187,6 +202,29 @@ async function renderCursosGenerablesPorTipo(tipo) {
|
|||
</div>`;
|
||||
})
|
||||
.join("");
|
||||
|
||||
// Agregar "Leer más" si es necesario
|
||||
setTimeout(() => {
|
||||
cursosConAlumnos.forEach(curso => {
|
||||
curso.alumnos.forEach(al => {
|
||||
["nombre", "email"].forEach(campo => {
|
||||
const span = document.getElementById(`${campo}-${al.id}`);
|
||||
const leerMas = document.getElementById(`${campo}-readmore-${al.id}`);
|
||||
|
||||
if (span && leerMas && span.scrollWidth > span.clientWidth) {
|
||||
const safeContent = (al[campo] || "")
|
||||
.replace(/'/g, "\\'")
|
||||
.replace(/"/g, """)
|
||||
.replace(/\n/g, "\\n");
|
||||
|
||||
const titulo = campo === "nombre" ? "Nombre completo" : "Correo electrónico completo";
|
||||
leerMas.innerHTML = `
|
||||
<a href="#" class="read-more" onclick="showFullDescriptionWithTitle('${titulo}', '${safeContent}'); return false;">Leer más</a>`;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
}, 0);
|
||||
} catch (err) {
|
||||
container.innerHTML = `<div class="card error-card"><p>${err.message}</p></div>`;
|
||||
}
|
||||
|
@ -248,6 +286,10 @@ window.showFullDescription = function (descripcion) {
|
|||
showModal("Descripción del Curso", `<div class="modal-description">${descripcion}</div>`);
|
||||
};
|
||||
|
||||
window.showFullDescriptionWithTitle = function (titulo, contenido) {
|
||||
showModal(titulo, `<div class="modal-description">${contenido}</div>`);
|
||||
};
|
||||
|
||||
window.closeModal = function () {
|
||||
const modal = document.getElementById("modal-overlay");
|
||||
if (modal) {
|
||||
|
@ -1639,7 +1681,7 @@ function loadDiplomasSection(container) {
|
|||
|
||||
|
||||
// Inicializar contenido emitido
|
||||
fetch(`api/diploma.php?profesor_id=${getProfesorId()}`)
|
||||
fetch(`api/diplomas.php?profesor_id=${getProfesorId()}`)
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
const emitidosContainer = document.querySelector("#diploma-tab-emitidos .card");
|
||||
|
|
139
certificado.php
139
certificado.php
|
@ -10,16 +10,6 @@ function t($txt) {
|
|||
return iconv('UTF-8', 'windows-1252//TRANSLIT', $txt);
|
||||
}
|
||||
|
||||
function traducirMes($mesEn) {
|
||||
$meses = [
|
||||
'January' => 'enero', 'February' => 'febrero', 'March' => 'marzo',
|
||||
'April' => 'abril', 'May' => 'mayo', 'June' => 'junio',
|
||||
'July' => 'julio', 'August' => 'agosto', 'September' => 'septiembre',
|
||||
'October' => 'octubre', 'November' => 'noviembre', 'December' => 'diciembre'
|
||||
];
|
||||
return $meses[$mesEn] ?? $mesEn;
|
||||
}
|
||||
|
||||
$codigo = $_GET['codigo'] ?? null;
|
||||
if (!$codigo) {
|
||||
ob_end_clean();
|
||||
|
@ -32,6 +22,7 @@ $stmt = $pdo->prepare("
|
|||
c.nombre AS curso_nombre,
|
||||
c.tipo,
|
||||
c.horas_trabajadas,
|
||||
c.competencias,
|
||||
d.fecha_emision
|
||||
FROM diplomas d
|
||||
JOIN alumnos_cursos ac ON d.alumno_curso_id = ac.id
|
||||
|
@ -51,9 +42,10 @@ $alumno = $diploma['alumno_nombre'];
|
|||
$curso = $diploma['curso_nombre'];
|
||||
$tipo = $diploma['tipo'];
|
||||
$horas = $diploma['horas_trabajadas'];
|
||||
$competencias = $diploma['competencias'] ?? '';
|
||||
$fecha = new DateTime($diploma['fecha_emision']);
|
||||
$dia = $fecha->format('j');
|
||||
$mes = traducirMes($fecha->format('F'));
|
||||
$dia = str_pad($fecha->format('d'), 2, '0', STR_PAD_LEFT);
|
||||
$mes = $fecha->format('m');
|
||||
$anio = $fecha->format('Y');
|
||||
|
||||
$pdf = new Fpdi();
|
||||
|
@ -64,53 +56,106 @@ $pdf->useTemplate($template);
|
|||
|
||||
$pdf->SetTextColor(33, 37, 41);
|
||||
|
||||
// --- Encabezado
|
||||
$pdf->SetFont('Helvetica', '', 16);
|
||||
$pdf->SetXY(0, 82);
|
||||
$pdf->Cell(210, 10, t("Otorga la presente"), 0, 1, 'C');
|
||||
// === TRATAMIENTO ===
|
||||
if ($tipo === 'tratamiento') {
|
||||
$pdf->SetFont('Helvetica', '', 16);
|
||||
$pdf->SetXY(0, 80);
|
||||
$pdf->Cell(210, 10, t("Otorga el presente reconocimiento"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 18);
|
||||
$pdf->SetXY(0, 95);
|
||||
$pdf->Cell(210, 10, t("CONSTANCIA"), 0, 1, 'C');
|
||||
$pdf->SetFont('Helvetica', '', 14);
|
||||
$pdf->SetXY(0, 92);
|
||||
$pdf->Cell(210, 10, t("a:"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'I', 14);
|
||||
$pdf->SetXY(0, 106);
|
||||
$pdf->Cell(210, 10, t("a:"), 0, 1, 'C');
|
||||
$pdf->SetFont('Helvetica', 'I', 22);
|
||||
$pdf->SetXY(0, 102);
|
||||
$pdf->Cell(210, 10, t($alumno), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 22);
|
||||
$pdf->SetXY(0, 120);
|
||||
$pdf->Cell(210, 10, t($alumno), 0, 1, 'C');
|
||||
|
||||
// --- Cuerpo
|
||||
$pdf->SetFont('Helvetica', '', 13);
|
||||
$pdf->SetXY(20, 135);
|
||||
$tipoTexto = match($tipo) {
|
||||
'inyeccion' => 'la Inyección Educativa',
|
||||
'pildora' => 'la Píldora Educativa',
|
||||
'tratamiento' => 'el Tratamiento Educativo',
|
||||
default => 'la formación'
|
||||
};
|
||||
$pdf->MultiCell(170, 8, t("Por su participación en {$tipoTexto}"), 0, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 14);
|
||||
$pdf->MultiCell(170, 8, t("“{$curso}”,"), 0, 'C');
|
||||
|
||||
if ($horas) {
|
||||
$y = 120;
|
||||
$pdf->SetFont('Helvetica', '', 12);
|
||||
$pdf->MultiCell(170, 8, t("con duración de {$horas} horas, modalidad remota."), 0, 'C');
|
||||
$textoBase = "Por haber acreditado en el curso “{$curso}”";
|
||||
if ($horas) $textoBase .= " ({$horas} horas de trabajo)";
|
||||
$pdf->SetXY(20, $y);
|
||||
$pdf->MultiCell(170, 7, t($textoBase . ",\nla evaluación de las competencias:"), 0, 'L');
|
||||
|
||||
$y = $pdf->GetY() + 2;
|
||||
$pdf->SetFont('Helvetica', '', 11);
|
||||
$lineas = explode("\n", $competencias);
|
||||
foreach ($lineas as $linea) {
|
||||
$pdf->SetXY(25, $y);
|
||||
$pdf->MultiCell(160, 6, t("• " . trim($linea)), 0, 'L');
|
||||
$y = $pdf->GetY();
|
||||
}
|
||||
|
||||
// === INYECCIÓN ===
|
||||
} elseif ($tipo === 'inyeccion') {
|
||||
$pdf->SetFont('Helvetica', '', 16);
|
||||
$pdf->SetXY(0, 82);
|
||||
$pdf->Cell(210, 10, t("Otorga la presente"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 18);
|
||||
$pdf->SetXY(0, 95);
|
||||
$pdf->Cell(210, 10, t("CONSTANCIA"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'I', 14);
|
||||
$pdf->SetXY(0, 106);
|
||||
$pdf->Cell(210, 10, t("a:"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 22);
|
||||
$pdf->SetXY(0, 116);
|
||||
$pdf->Cell(210, 10, t($alumno), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 13);
|
||||
$pdf->SetXY(20, 135);
|
||||
$pdf->MultiCell(170, 8, t("Por su participación en la Inyección Educativa"), 0, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 14);
|
||||
$pdf->MultiCell(170, 8, t("“{$curso}”,"), 0, 'C');
|
||||
|
||||
if ($horas) {
|
||||
$pdf->SetFont('Helvetica', '', 12);
|
||||
$pdf->MultiCell(170, 8, t("con duración de {$horas} horas."), 0, 'C');
|
||||
}
|
||||
|
||||
// === PÍLDORA ===
|
||||
} elseif ($tipo === 'pildora') {
|
||||
$pdf->SetFont('Helvetica', '', 16);
|
||||
$pdf->SetXY(0, 82);
|
||||
$pdf->Cell(210, 10, t("Otorga la presente"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 18);
|
||||
$pdf->SetXY(0, 95);
|
||||
$pdf->Cell(210, 10, t("CONSTANCIA"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'I', 14);
|
||||
$pdf->SetXY(0, 106);
|
||||
$pdf->Cell(210, 10, t("a:"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 22);
|
||||
$pdf->SetXY(0, 116);
|
||||
$pdf->Cell(210, 10, t($alumno), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 13);
|
||||
$pdf->SetXY(20, 135);
|
||||
$pdf->MultiCell(170, 8, t("Por su asistencia a la píldora educativa"), 0, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', 'B', 14);
|
||||
$pdf->MultiCell(170, 8, t("“{$curso}”"), 0, 'C');
|
||||
|
||||
if ($horas) {
|
||||
$pdf->SetFont('Helvetica', '', 12);
|
||||
$pdf->MultiCell(170, 8, t("con duración de {$horas} horas."), 0, 'C');
|
||||
}
|
||||
}
|
||||
|
||||
// --- Firma
|
||||
// Firma y pie para todos
|
||||
$pdf->SetFont('Helvetica', 'B', 12);
|
||||
$pdf->SetXY(0, 240);
|
||||
$pdf->SetXY(0, 245);
|
||||
$pdf->Cell(210, 10, t("Dr. Juan Manuel Gutiérrez Méndez"), 0, 1, 'C');
|
||||
|
||||
$pdf->SetFont('Helvetica', '', 11);
|
||||
$pdf->Cell(210, 6, t("Director de Proyectos"), 0, 1, 'C');
|
||||
|
||||
// --- Fecha
|
||||
$pdf->SetFont('Helvetica', 'I', 10);
|
||||
$pdf->SetXY(0, 270);
|
||||
$pdf->SetXY(0, 268);
|
||||
$pdf->Cell(210, 6, t("Se expide en la ciudad de Xalapa, Ver., a los {$dia} días de {$mes} de {$anio}"), 0, 1, 'C');
|
||||
|
||||
ob_end_clean();
|
||||
|
|
Loading…
Reference in New Issue