<?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">   
   
</head>

<body>

  <!--==========================
  Header
  ============================-->
   <?php include "includes/header2.php"; ?>
  
  <!-- #header -->

  <!--==========================
    Intro Section
  ============================-->           
    <div class="">
        <h3 class="text-center mb-4" style="margin-top: 90px"><font color="black"> About</font></h3>
        <input type="hidden" name="bref" id="bref" value="<?php echo $bref; ?>">
    </div>
    <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">
               
                            <?php
                                $edit_run = mysqli_query($con, "SELECT * FROM about WHERE a_by = '$_SESSION[uid]'");
                                
                            if ($edit_row = mysqli_fetch_assoc($edit_run))
                              {  

                            ?>

                            <form method="post" enctype="multipart/form-data">
                           
                           <div class="form-row">                             
                                <div class="col-md-12">
                                <font color="black">Title</font>
                                    <input type="text" name="abouttitle" class="form-control mb-3" value="<?php echo $edit_row['a_title'];?>">
                                </div>
                            </div>
                            <br>
                                <font color="black">Description</font>
                            <textarea name="content" id="content" class="form-control ckeditor" ><?php echo $edit_row["about"]; ?></textarea>
                          <h3 class="text-center mb-4" style="margin-top: 40px"><font color="black"> The Jesuit Heritage </font></h3>
                            <div class="form-group row">
                               
                            
                            </div>  
                                  <font color="black">   Description </font>
                            <textarea name="content1" id="content1" class="form-control ckeditor" ><?php echo $edit_row["oabout"]; ?></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>

                            <?php 
                            }
                            else{
                             ?>

                             <form method="post" enctype="multipart/form-data">
                           
                           <div class="form-row">                             
                                <div class="col-md-12">
                                <font color="black">Title</font>
                                    <input type="text" name="abouttitle" class="form-control mb-3">
                                </div>
                            </div>
                            <br>
                                <font color="black">Description</font>
                            <textarea name="content" id="content" class="form-control ckeditor" ></textarea>
                          <h3 class="text-center mb-4" style="margin-top: 40px"><font color="black">Others About</font></h3>
                            <div class="form-group row">
                               
                            
                            </div>  
                                  <font color="black">   Description </font>
                            <textarea name="content1" id="content1" class="form-control ckeditor" ></textarea>
                                                        
                            <button type="submit" class="btn btn-success my-4"  name="a_submit"> <i class="fas fa-cloud-upload-alt"></i> Update </button>
                            <a href="index.php" class="btn btn-warning my-4"> Cancel </a>                                                                                
                        </form>

                            <?php 

                            }
                             ?>
                                
                        
                      
                        
            </div>
        </div>
    </div>
  </div>
<!--============================== -->
        
                


 <!--==========================
    Footer
  ============================-->
    <?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['a_submit'])){
        $abouttitle = $_POST["abouttitle"];
        $uabout = $_POST["content"];
        $othabout = $_POST["content1"];

        $ins_sql = "INSERT INTO about (a_title, about, oabout, a_by) VALUES ('$abouttitle', '$uabout','$othabout', '$_SESSION[uid]')";

   

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

    }




   if(isset($_POST['edit_cat'])){
        $abouttitle = $_POST["abouttitle"];
        $uabout = $_POST["content"];
        $othabout = $_POST["content1"];
       
        
       
        $up_sql = "UPDATE about SET a_title = '$abouttitle' , about = '$uabout' , oabout = '$othabout'  WHERE a_by = '$_SESSION[uid]'";

   

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