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

<head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0-beta3/dist/css/bootstrap.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css" />
    <link rel="stylesheet" href="css/main.css">
    <title>Add Server</title>
</head>

<body>


    <?php include_once('includes/header.php'); 
    
    
    include '../config.php';


    if (isset($_POST['insert'])) {

        $name = $_POST['name'];
        $user = $_POST['user'];
        $password = $_POST['password'];
        $flag = $_POST['flag'];

        $config = mysqli_real_escape_string($conn, ($_POST['config']));

        $type = $_POST['type'];


        $update = "INSERT INTO `servers`(`name`, `username`, `password`, `configFile`,  `flagURL`, `type`) 
        VALUES ('$name','$user','$password','$config','$flag','$type')";

        $query = mysqli_query($conn, $update);
        if ($query) {
            echo "<script>window.history.back(); window.location.reload();</script>";
            echo "Sucess";
        } else {
            echo "<script>window.history.back(); window.location.reload();</script>";
            echo "Failed : " . mysqli_error($conn);
        }
    } 
    ?>

    <!-- content -->

    <div class="row mx-5">

        <div class="col bg-light rounded p-3 m-3">

            <div id="alert">

            </div>

            <h4 class="mx-3 mb-3 text-secondary">Add Servers</h4>


            <form method="post" role="form">

                <div class="mb-3">
                    <label for="name" class="form-label">Country Name</label>
                    <input type="text" class="form-control" id="name" name="name" placeholder=".." required>
                </div>


                <div class="mb-3">
                    <label for="user" class="form-label">User Name</label>
                    <input type="text" class="form-control" id="user" name="user" placeholder="..." required>
                </div>

                <div class="mb-3">
                    <label for="password" class="form-label">Password</label>
                    <input type="text" class="form-control" id="password" name="password" placeholder="..." required>
                </div>


                <div class="mb-3">
                    <label for="flag" class="form-label">Flag URL</label>
                    <input type="text" class="form-control" id="flag" name="flag" placeholder="...">
                </div>


                <div class="mb-3">
                    <label for="config" class="form-label">Config File</label>
                    <textarea class="form-control" id="config" name="config"  required></textarea>
                </div>



                <div class="mb-3 mx-5">
                    <label for="type" class="form-label">Server Type</label>
                    <select class="form-select" aria-label="Default select example" id="type" name="type">
                        <option value="0" selected>Free Server</option>
                        <option value="1">Paid Server</option>
                    </select>

                </div>


                <div class="text-center" id="subBtn">
                    <input type="submit" class="btn btn-primary" name="insert"/>
                </div>

        </div>

        <?php include_once('includes/footer.php'); ?>
</body>

</html>
