<?php

    session_start();

    include "../db.php";

    date_default_timezone_set('Asia/Kolkata');

    $currentTime = date('M j, Y g:i a');



    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"; ?>     

  



</head>

<body id="page-top" class="mt-55">



    <div style="margin-top: 130px;"></div>



      <?php include "includes/header2.php"; ?>

<div class="container">



                                 <?php

                                    if ( isset($_GET["edit_id"]) ) {

                                        $edit_run = mysqli_query($con, "SELECT * FROM class WHERE sid = '$_GET[edit_id]'");

                                        $edit_row = mysqli_fetch_assoc($edit_run);

                                        ?>



                    <div class="row justify-content-center">

                    <div class="col-md-8">

                        <div class="card shadow mt-3">

                        <h5 class="card-header text-dark  text-center font-weight-bold"> Add class</h5>

                            <div class="card-body">

                                <form method="POST">

                                    <div class="row mt-4">

                                        <div class="col-md-12">

                                            <label class="badge badge-warning text-dark">Class</label>

                                            <input type="text" class=" form-control" id="sclass" placeholder="Enter class" name="sclass" value="<?php echo $edit_row['sclass'];?>">

                                        </div>

                                    </div>

                                    <div class=" row justify-content-center">

                                        <button type="submit" class="btn btn-success text-sm-center mt-4" name="upload">

                                            <i class="fa fa-upload"></i> Upload

                                        </button>

                                    </div>

                                </form>

                            </div>

                        </div>

                    </div>

                </div>

            </div>

<div style="margin-top: 260px;"></div>



            <?php include "includes/ft.php"; ?>

            <?php include "includes/js.php"; ?>





    

</body>

</html>







<?php



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

        $sclass = mysqli_real_escape_string($con, strip_tags($_POST['sclass']));

            $up_sql = "UPDATE class SET sclass = '$sclass' WHERE sid = '$_GET[edit_id]'";

    

            if(mysqli_query($con, $up_sql)){

                ?>

                <script>window.location = 'view-class.php';</script>

                <?php

            }

            else{

                ?>

                <script>

                    alert('OOPS !!!!');

                    setTimeout(() => {

                        window.location = 'edit-class.php?edit_id=<?php echo $_GET["edit_id"]; ?>';

                    }, 1200);

                </script>

                <?php

            }

        } 

    }



?>