solicitudes

<?php
session_start();
$_SESSION['username'] = "sss";

// Conexión a la base de datos
$host = 'localhost';
$db   = 'bdaudiencias';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];

try {
    $pdo = new PDO($dsn, $user, $pass, $options);
} catch (\PDOException $e) {
    throw new \PDOException($e->getMessage(), (int)$e->getCode());
}

// Funciones principales
function crearSolicitud($pdo, $datos) {
    $stmt = $pdo->prepare("INSERT INTO solicitudes
        (prefolio, promovente, carpeta, tipo_solicitud, observaciones, dirigido, medio, registro)
        VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
   
    return $stmt->execute([
        $datos['prefolio'],
        $datos['promovente'],
        $datos['carpeta'],
        $datos['tipo_solicitud'],
        $datos['observaciones'],
        $datos['dirigido'],
        $datos['medio'],
        $datos['registro']
    ]);
}

function obtenerSolicitudes($pdo) {
    $stmt = $pdo->query("SELECT * FROM solicitudes ORDER BY fecha_registro DESC");
    return $stmt->fetchAll();
}

// Procesar formulario
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['form_submitted'])) {
    $datos = [
        'promovente' => $_POST['promovente'],
        'carpeta' => $_POST['carpeta'],
        'tipo_solicitud' => $_POST['tipo_solicitud'],
        'observaciones' => $_POST['observaciones'],
        'dirigido' => $_POST['dirigido'],
        'medio' => $_POST['medio'],
        'registro' => $_POST['registro']
    ];
   
    $prefolio = 'PRE-' . date('Ymd') . '-' . str_pad(rand(1, 999), 3, '0', STR_PAD_LEFT);
    $datos['prefolio'] = $prefolio;
   
    if (crearSolicitud($pdo, $datos)) {
        header("Location: ".$_SERVER['PHP_SELF']."?success=1&prefolio=".$prefolio);
        exit();
    } else {
        $error = "Error al crear la solicitud";
    }
}

// Mostrar mensaje de éxito después de redirección
if (isset($_GET['success']) && $_GET['success'] == 1 && isset($_GET['prefolio'])) {
    $mensaje = "Solicitud creada exitosamente! Prefolio: " . htmlspecialchars($_GET['prefolio']);
}

$solicitudes = obtenerSolicitudes($pdo);

// Opciones para el combobox "Dirigido a"
$opcionesDirigido = [
    'LIC. ERICK SERRANO AGUIRRE',
    'LIC. PATRICIA LOZANO HERNANDEZ',
    'ADMINISTRACIÓN'
];
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Oficialía de Partes - Registro de Solicitudes</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css">
    <style>
        .badge-primary { background-color: #0d6efd; color: #fff; }
        .badge-en_proceso { background-color: #ffc107; color: #000; }
        .badge-contestado { background-color: #198754; color: #fff; }
        .badge-rechazada { background-color: #dc3545; color: #fff; }
        .badge-caducada { background-color: #6c757d; color: #fff; }
        .badge-fisico { background-color: #0d6efd; color: #fff; }
        .badge-email { background-color: #6f42c1; color: #fff; }
    </style>
</head>
<body>
    <div class="container mt-5">
        <h1 class="mb-4">Oficialía de Partes <small class="text-muted">Registro de Solicitudes</small></h1>
       
        <?php if (isset($mensaje)): ?>
            <div class="alert alert-success"><?= $mensaje ?></div>
        <?php endif; ?>
       
        <?php if (isset($error)): ?>
            <div class="alert alert-danger"><?= $error ?></div>
        <?php endif; ?>
       
        <button type="button" class="btn btn-primary mb-4" data-bs-toggle="modal" data-bs-target="#registroModal">
            <i class="bi bi-plus-circle"></i> Registrar Nueva Solicitud
        </button>
       
        <div class="table-responsive">
            <table class="table table-striped table-hover">
                <thead class="table-dark">
                    <tr>
                        <th>Prefolio</th>
                        <th>Folio</th>
                        <th>Fecha Registro</th>
                        <th>Promovente</th>
                        <th>Dirigido a</th>
                        <th>Carpeta</th>
                        <th>Tipo</th>
                        <th>Medio</th>
                        <th>Estado</th>
                        <th>Acciones</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach ($solicitudes as $solicitud): ?>
                        <tr>
                            <td><?= htmlspecialchars($solicitud['prefolio']) ?></td>
                            <td><?= htmlspecialchars($solicitud['folio'] ?? 'Pendiente') ?></td>
                            <td><?= date('d/m/Y H:i', strtotime($solicitud['fecha_registro'])) ?></td>
                            <td><?= htmlspecialchars($solicitud['promovente']) ?></td>
                            <td><?= htmlspecialchars($solicitud['dirigido']) ?></td>
                            <td><?= htmlspecialchars($solicitud['carpeta']) ?></td>
                            <!-- CORRECCIÓN: Mostrar directamente el valor de la base de datos -->
                            <td><?= htmlspecialchars($solicitud['tipo_solicitud']) ?></td>
                            <td>
                                <?php
                                    $medios = [
                                        'FISICO' => '<span class="badge badge-fisico">Presencial</span>',
                                        'EMAIL' => '<span class="badge badge-email">Correo</span>'
                                    ];
                                    echo $medios[$solicitud['medio']] ?? htmlspecialchars($solicitud['medio']);
                                ?>
                            </td>
                            <td>
                                <?php
                                    $estados = [
                                        'OFICIALIA' => '<span class="badge badge-primary">Oficialía</span>',
                                        'EN_PROCESO' => '<span class="badge badge-en_proceso">En Proceso</span>',
                                        'CONTESTADO' => '<span class="badge badge-contestado">Contestado</span>',
                                        'RECHAZADA' => '<span class="badge badge-rechazada">Rechazada</span>',
                                        'CADUCADA' => '<span class="badge badge-caducada">Caducada</span>'
                                    ];
                                    echo $estados[$solicitud['estado']] ?? htmlspecialchars($solicitud['estado']);
                                ?>
                            </td>
                            <td>
                                <a href="solicitud_destalle.php?prefolio=<?= urlencode($solicitud['prefolio']) ?>" class="btn btn-sm btn-info" title="Ver detalles">
                                    <i class="bi bi-eye"></i>
                                </a>
                            </td>
                        </tr>
                    <?php endforeach; ?>
                </tbody>
            </table>
        </div>
       
        <!-- Modal para registro -->
        <div class="modal fade" id="registroModal" tabindex="-1" aria-labelledby="registroModalLabel" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="registroModalLabel">Registrar Nueva Solicitud</h5>
                        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                    </div>
                    <form method="POST">
                        <div class="modal-body">
                            <div class="mb-3">
                                <label class="form-label">Promovente</label>
                                <input type="text" name="promovente" class="form-control" required>
                            </div>
                           
                            <div class="mb-3">
                                <label class="form-label">Dirigido a</label>
                                <select name="dirigido" class="form-select" required>
                                    <?php foreach ($opcionesDirigido as $opcion): ?>
                                        <option value="<?= htmlspecialchars($opcion) ?>"><?= htmlspecialchars($opcion) ?></option>
                                    <?php endforeach; ?>
                                </select>
                            </div>

                            <div class="mb-3">
                                <label class="form-label">Carpeta</label>
                                <input type="text" name="carpeta" class="form-control" required>
                            </div>
                           
                            <!-- Input de texto para tipo_solicitud -->
                            <div class="mb-3">
                                <label class="form-label">Tipo de Solicitud</label>
                                <input type="text" name="tipo_solicitud" class="form-control" required>
                            </div>
                           
                            <div class="mb-3">
                                <label class="form-label">Medio de recepción</label>
                                <select name="medio" class="form-select" required>
                                    <option value="FISICO">Presentación física en juzgado</option>
                                    <option value="EMAIL">Correo electrónico</option>
                                </select>
                            </div>
                           
                            <div class="mb-3">
                                <label class="form-label">Observaciones</label>
                                <textarea name="observaciones" class="form-control" rows="3" required></textarea>
                            </div>
                           
                            <input type="hidden" name="registro" value="<?= isset($_SESSION['username']) ? $_SESSION['username'] : 'Sistema' ?>">
                            <input type="hidden" name="form_submitted" value="1">
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancelar</button>
                            <button type="submit" class="btn btn-primary">Registrar Solicitud</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>

Comentarios

Entradas populares de este blog

Guardar solicituc