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

<head>
    <?php require_once('head.php');?>
    <title>AdminLTE 3 | Thêm Mẫu Web</title>
    <?php require_once('nav.php');?>
</head>

<?php
if (isset($_POST["submit"])) {
    // Sử dụng Prepared Statement để chống SQL Injection cực kỳ an toàn
    $stmt = $ketnoi->prepare("INSERT INTO `list_mau_web` (`title`, `mo_ta`, `img`, `list_img`, `gia`, `gia_han`, `ns1`, `ns2`, `ip`, `status`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
    
    $stmt->bind_param(
        "ssssssssss", 
        $_POST['title'], 
        $_POST['mo_ta'], 
        $_POST['img'], 
        $_POST['list_img'], 
        $_POST['gia'], 
        $_POST['gia_han'], 
        $_POST['ns1'], 
        $_POST['ns2'], 
        $_POST['ip'], 
        $_POST['status']
    );

    if ($stmt->execute()) {
        echo '<script type="text/javascript">
            alert("Thêm mẫu website thành công!");
            window.location.href = "dsmauweb.php";
        </script>';
    } else {
        echo '<script type="text/javascript">
            alert("Có lỗi xảy ra trong quá trình lưu dữ liệu!");
            window.history.back();
        </script>'; 
    }
    $stmt->close();
}
?>

<body class="hold-transition sidebar-mini layout-fixed">
    <div class="wrapper">
        <div class="content-wrapper">
            <div class="content-header">
                <div class="container-fluid">
                    <div class="row mb-2">
                        <div class="col-sm-6">
                            <h1 class="m-0"><i class="fas fa-plus-circle text-primary mr-2"></i>Thêm Mẫu Web Mới</h1>
                        </div>
                        <div class="col-sm-6">
                            <ol class="breadcrumb float-sm-right">
                                <li class="breadcrumb-item"><a href="#">Home</a></li>
                                <li class="breadcrumb-item"><a href="dsmauweb.php">Mẫu Web</a></li>
                                <li class="breadcrumb-item active">Thêm Mẫu Web</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
            <section class="content">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-12">
                            <div class="card card-primary card-outline">
                                <div class="card-header">
                                    <h3 class="card-title"><i class="fas fa-edit mr-1"></i> Nhập thông tin cấu hình Website</h3>
                                </div>
                                <form role="form" action="" method="post">
                                    <div class="card-body">
                                        <div class="row">
                                            <div class="col-md-6">
                                                <div class="form-group">
                                                    <label class="font-weight-bold">Tên mẫu Website (TITLE) <span class="text-danger">*</span></label>
                                                    <div class="input-group">
                                                        <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-heading"></i></span></div>
                                                        <input type="text" class="form-control" name="title" placeholder="Ví dụ: Mã nguồn bán hàng chuẩn SEO" required>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="font-weight-bold">Ảnh đại diện (LINK IMG) <span class="text-danger">*</span></label>
                                                    <div class="input-group">
                                                        <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-image"></i></span></div>
                                                        <input type="url" class="form-control" name="img" placeholder="https://domain.com/anh-demo.png" required>
                                                    </div>
                                                </div>

                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <label class="font-weight-bold">Giá khởi tạo (VNĐ) <span class="text-danger">*</span></label>
                                                            <div class="input-group">
                                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-money-bill-wave text-success"></i></span></div>
                                                                <input type="number" class="form-control" name="gia" placeholder="500000" required>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <label class="font-weight-bold">Giá gia hạn / tháng (VNĐ) <span class="text-danger">*</span></label>
                                                            <div class="input-group">
                                                                <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-sync text-info"></i></span></div>
                                                                <input type="number" class="form-control" name="gia_han" placeholder="50000" required>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="font-weight-bold">Trạng thái hoạt động</label>
                                                    <div class="input-group">
                                                        <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-toggle-on"></i></span></div>
                                                        <select class="form-control" name="status">
                                                            <option value="ON">ON - Cho phép hiển thị & mua</option>
                                                            <option value="OFF">OFF - Tạm ẩn bảo trì</option>
                                                        </select>
                                                    </div>
                                                </div>
                                            </div>

                                            <div class="col-md-6">
                                                <div class="row">
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <label class="font-weight-bold">Nameserver 1 (NS1)</label>
                                                            <input type="text" class="form-control" name="ns1" placeholder="ns1.cloud.com">
                                                        </div>
                                                    </div>
                                                    <div class="col-md-6">
                                                        <div class="form-group">
                                                            <label class="font-weight-bold">Nameserver 2 (NS2)</label>
                                                            <input type="text" class="form-control" name="ns2" placeholder="ns2.cloud.com">
                                                        </div>
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="font-weight-bold">Địa chỉ IP Máy Chủ (IP Server)</label>
                                                    <div class="input-group">
                                                        <div class="input-group-prepend"><span class="input-group-text"><i class="fas fa-network-wired"></i></span></div>
                                                        <input type="text" class="form-control" name="ip" placeholder="123.45.67.89">
                                                    </div>
                                                </div>

                                                <div class="form-group">
                                                    <label class="font-weight-bold">Danh sách ảnh mô tả (LIST IMG)</label>
                                                    <textarea class="form-control" name="list_img" placeholder="Nhập link ảnh mô tả chi tiết (Mỗi dòng nhập 1 link ảnh)" rows="4"></textarea>
                                                </div>
                                            </div>
                                        </div>

                                        <hr class="my-4">
                                        <div class="form-group">
                                            <label class="font-weight-bold"><i class="fas fa-file-alt mr-1"></i> Mô tả chi tiết tính năng mẫu Web</label>
                                            <textarea class="form-control" name="mo_ta" rows="5" placeholder="Nhập các thông tin nổi bật của mã nguồn..."></textarea>
                                        </div>
                                    </div>
                                    <div class="card-footer bg-light d-flex justify-content-between">
                                        <a href="dsmauweb.php" class="btn btn-default"><i class="fas fa-arrow-left mr-1"></i> Quay lại danh sách</a>
                                        <button type="submit" name="submit" class="btn btn-primary ml-auto px-4"><i class="fas fa-save mr-1"></i> Lưu dữ liệu</button>
                                    </div>
                                </form>
                            </div>
                            </div>
                    </div>
                </div></section>
            </div>
        <aside class="control-sidebar control-sidebar-dark">
            </aside>
        </div>
    <?php require_once('foot.php');?>
</body>

</html>