<?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']) && !isset($_SESSION['uname']) )

        header("Location: logout.php");





$u_sql ="SELECT * FROM users WHERE uid= '$_GET[s_ref]'";

$u_res = mysqli_query($con,$u_sql);

$u_row = mysqli_fetch_assoc($u_res);



$h_sql ="SELECT * FROM homework WHERE h_ref= '$_GET[h_ref]'";

$h_res = mysqli_query($con,$h_sql);

$h_row = mysqli_fetch_assoc($h_res);



?>

<!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">

                    <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"> <?php echo $u_row['uname']."'s"; ?> Submitted Homework </h5>

                            <div class="card-body">

                                

                            <div class="row mt-4">

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

                                    <label class="badge badge-warning">Homework Title</label>

                                    <div class="col-md-12" style="margin-bottom: 15px;"><b><?php echo $h_row['h_title'] ?></b></div>

                                </div>

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

                                    <label class="badge badge-warning">Homework</label>

                                </div>



                            <?php 

                                $hi_sql ="SELECT * FROM homework_img WHERE hi_ref= '$_GET[h_ref]' AND sh_id='$_GET[s_ref]' ORDER BY hi_pos ASC";

                                $hi_res = mysqli_query($con,$hi_sql);

                                while ($hi_rows = mysqli_fetch_assoc($hi_res)) {

                                    

                                    if (!empty($hi_rows['hi_editDT'])) {

                                        $dt = 'Edit Date: '.$hi_rows['hi_editDT'];

                                    }else{

                                        $dt = 'Submit Date: '.$hi_rows['hi_submitDT'];

                                    }

                                                    ?>

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

                                    <?php if ($hi_rows['hi_pos']==1){ ?>



                                        <div class="col-md-12" style="position: relative;margin-bottom:7px;">

                                            <?php echo $hi_rows['hi_name'] ?>

                                            <div style="position: absolute;z-index: 999;margin: 0 auto;left: 0;right: 0;top: -7%; text-align: right;width: 90%;">

                                                <font color="black"><b><?php echo $dt; ?></b></font>

                                            </div>

                                        </div>



                                    <?php }else{ ?>



                                        <div class="col-md-12" style="position: relative;margin-bottom:7px;">

                                            <img src="../upload/homework_submit/<?php echo $hi_rows['hi_name'] ?>" width="100%" style="display: block;margin-left: auto;margin-right: auto;margin-bottom:7px;">

                                            <div style="position: absolute;z-index: 999;margin: 0 auto;left: 0;right: 0;top: 3%; text-align: right;width: 90%;">

                                                <font color="black"><b><?php echo $dt; ?></b></font>

                                            </div>

                                        </div>



                                    <?php } ?>

                                </div>



                            <?php

                                }

                            ?>

                            </div>

                            <?php 

                                $hReview_sql ="SELECT sh_review FROM homework_img WHERE hi_ref= '$_GET[h_ref]' AND sh_id='$_GET[s_ref]' AND hi_pos='1'";

                                $hReview_res = mysqli_query($con,$hReview_sql);

                                $hReview_rows = mysqli_fetch_assoc($hReview_res);

                                if (!empty($hReview_rows['sh_review'])) {

                                   ?>

                                    <form method="POST">

                                        <div class="row mt-4">

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

                                                <label class="badge badge-warning">Teacher's Feedback

                                                </label>

                                                <textarea class="form-control" rows="5" name="feedback"><?php echo $hReview_rows['sh_review']; ?> </textarea>

                                            </div>

                                        </div>

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

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

                                            </button>

                                            &nbsp;&nbsp;&nbsp;

                                            <a href="view-student-homework.php?h_ref=<?php echo $_GET['h_ref'] ?>" class="btn btn-warning text-sm-center mt-4"> Back

                                            </a>

                                        </div>

                                    </form>

                                   <?php

                                }else{

                                    ?>

                                    <form method="POST">

                                        <div class="row mt-4">

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

                                                <label class="badge badge-warning">Teacher's Feedback

                                                </label>

                                                <textarea class="form-control" rows="5" name="feedback"> </textarea>

                                            </div>

                                        </div>

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

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

                                            </button>

                                            &nbsp;&nbsp;&nbsp;

                                            <a href="view-student-homework.php?h_ref=<?php echo $_GET['h_ref'] ?>" class="btn btn-warning text-sm-center mt-4"> Back

                                            </a>

                                        </div>

                                    </form>



                                    <?php

                                }

                            ?>





                            </div>

                        </div>

                    </div>

                </div>

            </div>

                <?php



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



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



      $up_sql = "UPDATE homework_img SET sh_review = '$feedback' WHERE hi_ref= '$_GET[h_ref]' AND sh_id='$_GET[s_ref]' AND hi_pos='1'";





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

            ?>

            <script>window.location = "view-submitted-homework.php?h_ref=<?php echo $_GET['h_ref'] ?>&s_ref=<?php echo $_GET['s_ref'] ?>";</script>

            <?php

        }

        else{

            ?>

            <script>

                alert('OOPS !!!!');

                setTimeout(() => {

                    window.location = "view-submitted-homework.php?h_ref=<?php echo $_GET['h_ref'] ?>&s_ref=<?php echo $_GET['s_ref'] ?>";

                }, 1200);

            </script>

            <?php

        }

    } 



?>



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

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

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



    <script src="js/jquery.min.js"></script>

    <script src="js/bootstrap.min.js"></script>

    <script src="js/jquery.easing.min.js"></script>

    <script src="js/sb-admin-2.min.js"></script>

    <script src="js/sweetalert2.min.js"></script>

    <script src="js/jquery.dataTables.min.js"></script>

    <script src="js/dataTables.bootstrap4.min.js"></script>

    <script src="js/datatables.mark.min.js"></script>

    <script src="js/jquery-ui-custom.min.js"></script>

    <script src="js/custom.js"></script>



   

</body>

</html>







