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

<head>
    <?php require_once('head.php');?>
    <title>Hệ Thống | Thêm Máy Chủ 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 Giao diện thiết kế cao cấp mới */
        .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;
        }
        .input-group-text-custom {
            background: #f1f5f9;
            border: 1px solid #e2e8f0;
            border-radius: 10px 0 0 10px;
            color: #64748b;
        }
        .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"]))
{
    // Bảo mật dữ liệu đầu vào chống SQL Injection
    $name_server = mysqli_real_escape_string($ketnoi, $_POST['name_server']);
    $link_login  = mysqli_real_escape_string($ketnoi, $_POST['link_login']);
    $tk_whm      = mysqli_real_escape_string($ketnoi, $_POST['tk_whm']);
    $mk_whm      = mysqli_real_escape_string($ketnoi, $_POST['mk_whm']);
    $ip_whm      = mysqli_real_escape_string($ketnoi, $_POST['ip_whm']);
    $ns1         = mysqli_real_escape_string($ketnoi, $_POST['ns1']);
    $ns2         = mysqli_real_escape_string($ketnoi, $_POST['ns2']);
    $status      = mysqli_real_escape_string($ketnoi, $_POST['status']);

    $create = mysqli_query($ketnoi, "INSERT INTO `list_server_host` SET  
        `name_server` = '$name_server',
        `link_login` = '$link_login',
        `tk_whm` = '$tk_whm',
        `mk_whm` = '$mk_whm',
        `ip_whm` = '$ip_whm',
        `ns1` = '$ns1',
        `ns2` = '$ns2',
        `status` = '$status'");

    if($create)
    {
        echo '<script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function() {
            Swal.fire({
                icon: "success",
                title: "Thành Công",
                text: "Đã thêm máy chủ mới vào hệ thống!",
                confirmButtonColor: "#3b82f6"
            }).then(() => {
                window.location.href = "listserverhost.php";
            });
        });
        </script>';
    }
    else
    {
        echo '<script type="text/javascript">
        document.addEventListener("DOMContentLoaded", function() {
            Swal.fire({
                icon: "error",
                title: "Lỗi Hệ Thống",
                text: "Không thể thêm dữ liệu, vui lòng kiểm tra lại!",
                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;">Cấu Hình Trạm Máy Chủ</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="listserverhost.php" class="text-muted">Server Host</a></li>
                                <li class="breadcrumb-item active text-primary">Add New</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-server mr-2 text-primary"></i>Khai Báo Máy Chủ WHM / CPanel
                                    </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-tag mr-1 text-muted"></i> Name Server</label>
                                                <input type="text" class="form-control" name="name_server" placeholder="Ví dụ: SV-VIP-01" required>
                                            </div>
                                            
                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-network-wired mr-1 text-muted"></i> IP WHM</label>
                                                <input type="text" class="form-control" name="ip_whm" placeholder="Ví dụ: 192.168.1.1" required>
                                            </div>

                                            <div class="col-md-12 form-group mb-4">
                                                <label><i class="fas fa-link mr-1 text-muted"></i> Link Login WHM</label>
                                                <input type="url" class="form-control" name="link_login" placeholder="https://your-domain.com:2087" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-user-shield mr-1 text-muted"></i> Tài Khoản WHM</label>
                                                <input type="text" class="form-control" name="tk_whm" placeholder="Thường là: root" required>
                                            </div>
                                            
                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-key mr-1 text-muted"></i> Mật Khẩu WHM</label>
                                                <input type="password" class="form-control" name="mk_whm" placeholder="Nhập mật khẩu bảo mật" required>
                                            </div>

                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-globe mr-1 text-muted"></i> NameServer 1 (NS1)</label>
                                                <input type="text" class="form-control" name="ns1" placeholder="ns1.yourdomain.com" required>
                                            </div>
                                            
                                            <div class="col-md-6 form-group mb-4">
                                                <label><i class="fas fa-globe mr-1 text-muted"></i> NameServer 2 (NS2)</label>
                                                <input type="text" class="form-control" name="ns2" placeholder="ns2.yourdomain.com" required>
                                            </div>

                                            <div class="col-md-12 form-group mb-4">
                                                <label><i class="fas fa-toggle-on mr-1 text-muted"></i> Trạng Thái Hoạt Động</label>
                                                <select class="form-control" name="status">
                                                    <option value="ON">Kích hoạt (ON)</option>
                                                    <option value="OFF">Tạm tắt (OFF)</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="d-flex align-items-center justify-content-between mt-4 pt-3" style="border-top: 1px solid #f1f5f9;">
                                            <a href="listserverhost.php" class="btn btn-back">
                                                <i class="fas fa-arrow-left mr-2"></i>Quay Lại Danh Sách
                                            </a>
                                            <button type="submit" name="submit" class="btn btn-primary btn-submit">
                                                <i class="fas fa-save mr-2"></i>Lưu Máy Chủ
                                            </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>