<?php
    session_start();
    include "../../db.php";
    date_default_timezone_set('Asia/Kolkata');
      $currentTime = date('jS  F Y');

    if ( !isset($_SESSION['uid']) && !isset($_SESSION['uref']) && !isset($_SESSION['utype']) )
        header("Location: logout.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
 <?php include "includes/meta.php"; ?>             
    <?php include "includes/css.php"; ?>
    <link href="css/all.min.css" rel="stylesheet" type="text/css">
    <link href="css/alltable.css" rel="stylesheet"> 
 

<!-- style -->
    <style>
        .custom-file-label::after {
            height: 8.25rem;
            padding-top: 50px;
        }
        .custom-file-label-edit::after{
            height: 2.25rem;
            padding-top: 5px;
        }
        #uploadimageModal .modal-dialog{
            max-width: 100% !important;
        }
    </style>
</head>
<body>
    <?php include "includes/header2.php"; ?>

     <div class="container">
            <div class="row mx-0 just ify-content-center">
                <div class="col-8 col-sm-12 col-md-8">
                        <div class="card-body">
                            <h1 class="h3 mb-2 text-gray-800 text-center" style="margin-top: 90px">Map link</h1>
                            <hr>
               
                            <?php
                                $edit_run = mysqli_query($con, "SELECT * FROM users WHERE uid = '$_SESSION[uid]'");
                                $edit_row = mysqli_fetch_assoc($edit_run); 
                            ?>
                       
                           <form method="post" enctype="multipart/form-data">
                         
                                       <font color="black">Map Link</font>
                                        <textarea name="content" id="content" class="form-control ckeditor" required><?php echo $edit_row['umap']; ?></textarea>
                              
                                      
                                        <button type="submit" class="btn btn-success my-4"  name="edit_cat"> <i class="fas fa-cloud-upload-alt"></i> Update </button>
                                        <a href="index.php" class="btn btn-warning my-4"> Cancel </a>       


                            </form>
                        
                      </div>
                  </div>
                  <div class="col-4 col-sm-12 col-md-4">
                        <div class="card-body">
                            <h1 class="h3 mb-2 text-gray-800 text-center" style="margin-top: 90px">Map View</h1>
                            <hr>
               
                            <iframe src="<?php echo $edit_row['umap'];?>" width="100%" height="400" frameborder="0" style="border:0;" allowfullscreen></iframe>
                        
                      </div>
                  </div>
                        
            </div>
        </div>
        <?php include "includes/ft.php"; ?>
        <?php include "includes/js.php"; ?>


</body>
</html>



<script>
     CKEDITOR.replace( 'content', {
        height: 300,
        filebrowserUploadUrl: "upload.php"
    });
   
</script>

   



<?php


   if(isset($_POST['edit_cat'])){
    
        $map = $_POST["content"];
       
       
        
       
        $up_sql = "UPDATE users SET umap = '$map' WHERE uid = '$_SESSION[uid]'";

   

        if(mysqli_query($con, $up_sql)){
            ?>
            <script>window.location = 'contact_page.php';</script>
            <?php
        }
        else{
            ?>
            <script>
                alert('OOPS !!!!');
                setTimeout(() => {
                    window.location = 'contact_page.php';
                }, 500);
            </script>
            <?php
        }
    }
?>