<?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-12 col-sm-12 col-md-12">
                        <div class="card-body">
                            <h1 class="h3 mb-2 text-gray-800 text-center" style="margin-top: 90px">Mission Vission</h1>
                            <hr>
               
                            <?php
                                $edit_run = mysqli_query($con, "SELECT * FROM vission WHERE v_by = '$_SESSION[uid]'");
                                if ($edit_row = mysqli_fetch_assoc($edit_run)) {
                                    
                                
                            ?>
                        <form method="post" enctype="multipart/form-data">
                           
					
								<font color="black" class="h4">Write A Description For Mission</font>
                            <textarea name="content" id="content" class="form-control ckeditor" ><?php echo $edit_row["mission"]; ?></textarea>
                            <br><br>
                            <font color="black" class="h4">Write A Description For Vission</font>
                            <textarea name="content1" id="content1" class="form-control ckeditor" ><?php echo $edit_row["vission"]; ?></textarea>

                            							
                            <button type="submit" class="btn btn-success my-4"  name="edit_cat"> <i class="fas fa-cloud-upload-alt"></i> Update </button>																			
                        </form>
                        <?php 
                            }
                        else {
                            
                         ?> 

                           <form method="post" enctype="multipart/form-data">
                           
                    
                                <font color="black" class="h4">Write A Description For Mission</font>
                            <textarea name="content" id="content" class="form-control ckeditor" ></textarea>
                            <br><br>
                            <font color="black" class="h4">Write A Description For Vission</font>
                            <textarea name="content1" id="content1" class="form-control ckeditor" ></textarea>

                                                        
                            <button type="submit" class="btn btn-success my-4"  name="vission_submit"> <i class="fas fa-cloud-upload-alt"></i> Update </button>                                                                           
                        </form>

                        <?php 
                        } ?>
                        
                      </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>


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



<?php
   if(isset($_POST['vission_submit'])){

        $mission = $_POST["content"];
        $vission = $_POST["content1"];
       
        
        $ins_sql = "INSERT INTO vission (mission, vission, v_by) VALUES ('$mission', '$vission','$_SESSION[uid]')";
   

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


   if(isset($_POST['edit_cat'])){
    
        $mission = $_POST["content"];
        $vission = $_POST["content1"];
       
       
        
       
        $up_sql = "UPDATE vission SET mission = '$mission', vission = '$vission'   WHERE v_by = '$_SESSION[uid]'";

   

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