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

<head>
    <?php require_once('head.php');?>
    <title>Hệ Thống | Thêm Gói Hosting Mới</title>
    <?php require_once('nav.php');?>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    
    <style>
        /* CSS UI Premium Core */
        .custom-card {
            border: none !important;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.04) !important;
            border-radius: 16px !important;
            background: #ffffff;
            overflow: hidden;
        }
        .form-group label {
            font-weight: 600 !important;
            color: #475569 !important;
            font-size: 0.85rem;
            text-transform: uppercase;
            letter-spacing: 0.05em;
            margin-bottom: 8px;
        }
        .form-control {
            border: 1px solid #e2e8f0 !important;
            border-radius: 10px !important;
            padding: 12px 16px !important;
            height: auto !important;
            color: #334155 !important;
            font-size: 0.95rem;
            transition: all 0.2s ease-in-out !important;
            background-color: #f8fafc;
        }
        .form-control:focus {
            background-color: #ffffff;
            border-color: #3b82f6 !important;
            box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.1) !important;
        }
        select.form-control {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23475569' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 16px center;
            background-size: 16px;
            padding-right: 40px !important;
        }
        .btn-submit {
            background: #3b82f6 !important;
            border: none !important;
            border-radius: 10px !important;
            padding: 12px 30px !important;
            font-weight: 600 !important;
            box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
            transition: all 0.2s;
        }
        .btn-submit:hover {
            background: #2563eb !important;
            transform: translateY(-1px);
            box-shadow: 0 6px 20px rgba(59, 130, 246, 0.35);
        }
        .btn-back {
            background: #f1f5f9 !important;
            color: #475569 !important;
            border: none !important;
            border-radius: 10px !important;
            padding: 12px 24px !important;
            font-weight: 500 !important;
            transition: all 0.2s;
        }
        .btn-back:hover {
            background: #e2e8f0 !important;
            color: #1e293b !important;
        }
    </style>
</head>

<?php
if (isset($_POST["submit"]))
{
    // Phòng chống lỗi bảo mật SQL Injection phổ biến bằng Escaped String
    $name_host   = mysqli_real_escape_string($ketnoi, $_POST['name_host']);
    $title_host  = mysqli_real_escape_string($ketnoi, $_POST['title_host']);
    $server_host = mysqli_real_escape_string($ketnoi, $_POST['server_host']);
    $code        = mysqli_real_escape_string($ketnoi, $_POST['code']);
    $gia_host    = mysqli_real_escape_string($ketnoi, $_POST['gia_host']);
    $dung_luong  = mysqli_real_escape_string($ketnoi, $_POST['dung_luong']);
    $mien_khac   = mysqli_real_escape_string($ketnoi, $_POST['mien_khac']);
    $bi_danh     = mysqli_real_escape_string($ketnoi, $_POST['bi_danh']);

    $create = mysqli_query($ketnoi, "INSERT INTO `list_host` SET  
        `name_host` = '$name_host',
        `title_host` = '$title_host',
        `server_host` = '$server_host',
        `code` = '$code',
        `gia_host` = '$gia_host',
        `dung_luong` = '$dung_luong',
        `mien_khac` = '$mien_khac',
        `bi_danh` = '$bi_danh'");

    if($create)
    {
        echo '<script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function() {
            Swal.fire({
                icon: "success",
                title: "Thành Công",
                text: "Cập nhật gói hosting mới thành công!",
                confirmButtonColor: "#3b82f6"
            }).then(() => {
                window.location.href = "listgoihost.php";
            });
        });
        </script>';
    }
    else
    {
        echo '<script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function() {
            Swal.fire({
                icon: "error",
                title: "Thất Bại",
                text: "Đã xảy ra lỗi hệ thống, vui lòng thử lại sau!",
                confirmButtonColor: "#ef4444"
            });
        });
        </script>'; 
    }
}
?>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <div class="content-wrapper" style="background: #f8fafc;">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-3 align-items-center">
                        <div class="col-sm-6">
                            <h1 class="m-0 font-weight-bold text-dark" style="font-size: 1.5rem;">Quản Lý Gói Hosting</h1>
                        </div><div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right" style="background: transparent; padding: 0;">
                                <li class="breadcrumb-item"><a href="#" class="text-muted">Home</a></li>
                                <li class="breadcrumb-item"><a href="listgoihost.php" class="text-muted">Gói Host</a></li>
                                <li class="breadcrumb-item active text-primary">Tạo mới</li>
                            </ol>
                        </div></div></div></div>
            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card custom-card">
                                <div class="card-header py-3" style="background: #ffffff; border-bottom: 1px solid #f1f5f9;">
                                    <h3 class="card-title font-weight-bold text-secondary mb-0" style="font-size: 1.05rem;">
                                        <i class="fas fa-layer-group mr-2 text-primary"></i> Khởi Tạo Gói Host Mới
                                    </h3>
                                </div>
                                <div class="card-body p-4">
                                    <form role="form" action="" method="post">
                                        <div class="row">
                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-hdd mr-1 text-muted"></i> Name Host (Tên gói)</label>
                                                <input type="text" class="form-control" name="name_host" placeholder="Ví dụ: Hosting Sinh Viên Giá Rẻ" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-box-open mr-1 text-muted"></i> Gói Host (Package Name WHM)</label>
                                                <input type="text" class="form-control" name="code" placeholder="Nhập chính xác mã package trên WHM" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-sliders-h mr-1 text-muted"></i> Phân Loại (Title Host)</label>
                                                <select class="form-control" name="title_host">
                                                    <option value="Start Up">Start Up (Cơ bản)</option>
                                                    <option value="Advanced">Advanced (Mở rộng)</option>
                                                    <option value="Enterprise">Enterprise (Doanh nghiệp)</option>
                                                </select>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-server mr-1 text-muted"></i> Thuộc Máy Chủ (Server Host)</label>
                                                <select class="form-control" name="server_host">
                                                    <?php
                                                    $result = mysqli_query($ketnoi, "SELECT * FROM `list_server_host` ");
                                                    while($row = mysqli_fetch_assoc($result)) {
                                                    ?>
                                                    <option value="<?=$row['id'];?>"><?=$row['name_server'];?></option>
                                                    <?php } ?>
                                                </select>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-tags mr-1 text-muted"></i> Giá Cước Gói (VNĐ)</label>
                                                <input type="number" class="form-control" name="gia_host" placeholder="Ví dụ: 50000" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-microchip mr-1 text-muted"></i> Hạn Mức Dung Lượng</label>
                                                <input type="text" class="form-control" name="dung_luong" placeholder="Ví dụ: 2 GB hoặc Không giới hạn" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-globe-asia mr-1 text-muted"></i> Số Miền Khác (Addon Domain)</label>
                                                <input type="text" class="form-control" name="mien_khac" placeholder="Ví dụ: 1 Tên miền / Không giới hạn" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-link mr-1 text-muted"></i> Bí Danh (Parked Domain)</label>
                                                <input type="text" class="form-control" name="bi_danh" placeholder="Ví dụ: 5 bí danh / Không giới hạn" required>
                                            </div>
                                        </div>

                                        <div class="d-flex align-items-center justify-content-between mt-4 pt-3" style="border-top: 1px solid #f1f5f9;">
                                            <a href="listgoihost.php" class="btn btn-back">
                                                <i class="fas fa-arrow-left mr-2"></i>Quay Về Danh Sách
                                            </a>
                                            <button type="submit" name="submit" class="btn btn-primary btn-submit">
                                                <i class="fas fa-plus mr-2"></i>Thêm Gói Mới
                                            </button>
                                        </div>
                                    </form>
                                </div>
                                </div>
                            </div>
                    </div>
                    </div></section>
            </div>
        <aside class="control-sidebar control-sidebar-dark"></aside>
    </div>
    <?php require_once('foot.php');?>
</body>

</html>