<?php 
session_start();

require("config/conn.php");
require("functions.php");
include("includes/header.php");
include("includes/topbar.php");
include("includes/sidebar.php");

session_regenerate_id(true);

if (!isset($_SESSION['AdminLoginId'])) {
    header("Location: index.php");
} 

?>



<main>
    <div class="container-fluid px-4">

        <h1 class="mt-4 dash-heading">App Info</h1>
        <ol class="breadcrumb mb-4">
            <li class="breadcrumb-item active">App Info</li>
        </ol>



        <div class="row my-4">
            <div class="col-12 add-category-box my-4">
                <h1 class="category-heading">App Info</h1>
                <div class="categort-add-container">
                    <form  action="code.php" method="POST" style="width: 100%;">
                        <div class="d-flex align-items-start flex-wrap">
                        <div class="mb-3 mx-2" style="width: 40%;">
                            <label for="privacy_policy" class="form-label">Privacy Policy</label>
                            <textarea class="form-control" id="privacy_policy" name="privacy_policy" rows="20" style="width: 100%;"> <?= getAppInfo('appinfo', 'Privacy Policy'); ?></textarea>
                        </div>
                        <div class="mb-3 mx-2" style="width: 40%;">
                            <label for="about_us" class="form-label">About Us</label>
                            <textarea class="form-control" id="about_us" name="about_us" rows="20" style="width: 100%;"> <?= getAppInfo('appinfo', 'About Us'); ?></textarea>
                        </div>
</div>
                        <button type="submit"  name="save_appinfo" class="add-category-btn  mb-3 mx-2">Save</button>
                    </form>
                </div>

            </div>
           
            
          




    </div>




</main>









<?php 

include("includes/script.php");

?>


<script>
    <?php

    if (isset($_SESSION['status'])) {
    ?>
            swal("<?= $_SESSION['message']; ?>", {
                icon: "<?= $_SESSION['icon'] ?>",

            }
            );
    <?php
  unset($_SESSION['status']);
        unset($_SESSION['message']);
        unset($_SESSION['icon']);
    }

?>


</script>
<script>

        let enableSwitch = $('.enableSwitch').val();
        if (enableSwitch == 1) {
            $("#form").css('display', 'block');
            $('#text').html('');
        } else{
            $("#form").css('display', 'none');
            $('#text').html('AD are Disabled');
        }
   
   


    $('.enableSwitch').on('click', function () {

        $.ajax({
            type: "POST",
            url: "code.php",
            data: {
                'check_onOff': true
            },
            success: function (response) {
                
                let id = $(this).attr('id');
                $.each(response, function (key, value) { 
                     var check =  value['value'];
                    //  console.log(check);
                

       
        if (check == '1') {
            // console.log('disabled');

            $.ajax({
                type: "POST",
                url: "code.php",
                data: {
                    'disable_ad': true
                },
                success: function (response) {
                    $("#form").css('display', 'none');
                    $('#text').html('AD are Disabled');
                    // $("form").hide();
                    swal({
                        title: "AD Disabled",
                        text: "AD Disabled Successfully",
                        icon: "success",
                    });

                   
                }
            });

        } else{
            $.ajax({
                type: "POST",
                url: "code.php",
                data: {
                    'enable_ad': true,
                },
                success: function (response) {
                    // $("form").show();
                    $("#form").css('display', 'block');


                    $('#text').html('');
                    swal({
                        title: "AD Enabled",
                        text: "AD Enabled Successfully",
                        icon: "success",
                    });
                    

                }
            });
        }

    });
            }
        });


     
    });
</script>



<?php

include("includes/footer.php");


?>