<!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>Admob ADS</title>
</head>

<body>

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

    $q = "SELECT * FROM `admob` WHERE `id` = 1";
    $fire = mysqli_query($conn, $q);

    $data = mysqli_fetch_assoc($fire);

    $app_id = $data['app_id'];
    $banner = $data['banner'];
    $interstitial = $data['interstitial'];
    $native = $data['native'];
    $active = $data['active'];





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

        $uappid =  $_POST['appid'];
        $ubanner = $_POST['banner'];
        $uinterstitial = $_POST['interstitial'];
        $unative = $_POST['native'];
        $uactive = $_POST['active'];

        $query = "UPDATE `admob` SET `app_id`='$uappid',`banner`='$ubanner',`interstitial`='$uinterstitial',`native`='$unative',`active`='$uactive' WHERE `id`=1";
        $update = mysqli_query($conn, $query);

        if ($update) {
            echo "<script>window.history.back(); window.location.reload();</script>";
        } else {
            echo "<script>window.history.back(); window.location.reload();</script>";
        }
    }

    ?>

    <!-- content -->
    <div class="row m-3">

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

            <div id="alert">

            </div>

            <form action="" method="post" class="mt-3">


                <div class="mb-3">
                    <label for="appid" class="form-label">App ID</label>
                    <input type="text" class="form-control" id="appid" name="appid" value="<?php echo $app_id ?>">
                </div>


                <div class="mb-3">
                    <label for="banner" class="form-label">Banner</label>
                    <input type="text" class="form-control" id="banner" name="banner" value="<?php echo $banner ?>">
                </div>

                <div class="mb-3">
                    <label for="interstitial" class="form-label">Interstitial</label>
                    <input type="text" class="form-control" id="interstitial" name="interstitial" value="<?php echo $interstitial ?>">
                </div>



                <div class="mb-3">
                    <label for="native" class="form-label">Native</label>
                    <input type="text" class="form-control" id="native" name="native" value="<?php echo $native ?>">
                </div>


                <div class="mb-3">
                    <label for="active" class="form-label">Active</label>
                    <select class="form-select" aria-label="Default select example" id="active" name="active">

                        <?php
                        if ($active == "1") {
                        ?>

                            <option value="0">Off</option>
                            <option value="1" selected>On</option>

                        <?php
                        } else {
                        ?>
                            <option value="0" selected>Off</option>
                            <option value="1">On</option>

                        <?php

                        }

                        ?>


                    </select>

                </div>


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

            </form>

        </div>
    </div>



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

</html>