<!DOCTYPE html>
<html lang="vi">

<head>
    <?php require_once('head.php');?>
    <title>Thêm Server Cron | Admin Dashboard</title>
    <?php require_once('nav.php');?>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <style>
        .card { border-radius: 20px; border: none; box-shadow: 0 5px 20px rgba(0,0,0,0.05); }
        .form-control { border-radius: 12px; padding: 12px; border: 1px solid #e2e8f0; }
        .btn-primary { border-radius: 12px; padding: 10px 25px; font-weight: 600; }
    </style>
</head>

<?php
if (isset($_POST["submit"])) {
    // Sử dụng Prepared Statements để bảo mật
    $stmt = $ketnoi->prepare("INSERT INTO `list_server_cron` (`name_cron`, `min_time`, `money`, `status`) VALUES (?, ?, ?, ?)");
    $stmt->bind_param("ssis", $_POST['name_cron'], $_POST['min_time'], $_POST['money'], $_POST['status']);

    if ($stmt->execute()) {
        echo '<script>
            Swal.fire("Thành công", "Đã thêm server mới!", "success").then(() => {
                location.href = "server-cron.php";
            });
        </script>';
    } else {
        echo '<script>Swal.fire("Lỗi", "Có lỗi xảy ra, vui lòng thử lại!", "error");</script>';
    }
    $stmt->close();
}
?>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <div class="content-wrapper p-4">
            <section class="content">
                <div class="row justify-content-center">
                    <div class="col-md-8">
                        <div class="card p-4">
                            <div class="card-header bg-transparent border-0">
                                <h3 class="card-title font-weight-bold"><i class="fas fa-plus-circle mr-2"></i>Thêm Server Cron</h3>
                            </div>
                            <div class="card-body">
                                <form method="post">
                                    <div class="form-group">
                                        <label>TÊN SERVER</label>
                                        <input type="text" class="form-control" name="name_cron" placeholder="VD: Server 1" required>
                                    </div>
                                    <div class="form-row">
                                        <div class="form-group col-md-6">
                                            <label>SỐ GIÂY TỐI THIỂU</label>
                                            <input type="number" class="form-control" name="min_time" placeholder="VD: 30" required>
                                        </div>
                                        <div class="form-group col-md-6">
                                            <label>GIÁ (VNĐ)</label>
                                            <input type="number" class="form-control" name="money" placeholder="VD: 10000" required>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label>TRẠNG THÁI</label>
                                        <select class="form-control" name="status">
                                            <option value="ON">Hiển Thị (ON)</option>
                                            <option value="OFF">Ẩn (OFF)</option>
                                        </select>
                                    </div>
                                    <button type="submit" name="submit" class="btn btn-primary w-100 mt-3">Lưu Server</button>
                                </form>
                            </div>
                            <div class="card-footer bg-transparent border-0 text-center">
                                <a href="server-cron.php" class="text-muted"><i class="fas fa-arrow-left mr-1"></i> Quay lại danh sách</a>
                            </div>
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </div>
    <?php require_once('foot.php');?>
</body>
</html>