<?php
session_start();
if(isset($_SESSION['teacher']))
{
    $teacher_id=$_SESSION['teacher']['id'];
  if(isset($_GET['class_id']) && isset($_GET['session_id']))
  {
     
    $class_id=htmlentities($_GET['class_id']);
    include '../manage/function.php';
    $session_id=htmlentities($_GET['session_id']);

    include '../classes/students_class.php';
    include '../classes/classroom_class.php';
    include '../classes/class_subjects_class.php';
    include '../classes/subjects_class.php';
    include '../classes/assessment_class.php';
    include '../classes/session_class.php';
    include '../classes/result_class.php';

    $student=new Student("../manage/connection.php");
    $classroom=new ClassRoom("../manage/connection.php");
    $classSubject=new ClassSubject("../manage/connection.php");
    $subject=new Subject("../manage/connection.php");
    $assessment=new Assessment("../manage/connection.php");
    $class_session=new Session("../manage/connection.php");
    $result=new Result("../manage/connection.php");
    
    if($classroom->getClassRoom($class_id)['teacher_id']==$teacher_id)
    {
    ?>
<!DOCTYPE html>
<html lang="en">

<head>
    <title>Malika International Academy Teacher</title>
    <!-- HTML5 Shim and Respond.js IE9 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
      <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
      <![endif]-->
    <!-- Meta -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="description" content="CodedThemes">
    <meta name="keywords"
        content=" Admin , Responsive, Landing, Bootstrap, App, Template, Mobile, iOS, Android, apple, creative app">
    <meta name="author" content="CodedThemes">
    <!-- Favicon icon -->
    <link rel="icon" href="assets/images/favicon.ico" type="image/x-icon">
    <!-- Google font-->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,600" rel="stylesheet">
    <!-- Required Fremwork -->
    <link rel="stylesheet" type="text/css" href="assets/css/bootstrap/css/bootstrap.min.css">
    <!-- themify-icons line icon -->
    <link rel="stylesheet" type="text/css" href="assets/icon/themify-icons/themify-icons.css">
    <!-- ico font -->
    <link rel="stylesheet" type="text/css" href="assets/icon/icofont/css/icofont.css">
    <!-- Style.css -->
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link rel="stylesheet" type="text/css" href="assets/css/jquery.mCustomScrollbar.css">
    <link rel="stylesheet" href="assets/vendors/simple-datatables/style.css">
</head>

<body>
    <!-- Pre-loader start -->
    <div class="theme-loader">
        <div class="ball-scale">
            <div class='contain'>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">

                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
                <div class="ring">
                    <div class="frame"></div>
                </div>
            </div>
        </div>
    </div>
    <!-- Pre-loader end -->
    <div id="pcoded" class="pcoded">
        <div class="pcoded-overlay-box"></div>
        <div class="pcoded-container navbar-wrapper">

            <?php
                include 'topnav.php';
            ?>
            <div class="pcoded-main-container">
                <div class="pcoded-wrapper">
                    <?php
                        include 'sidenav.php';
                    ?>
                    <div class="pcoded-content">
                        <div class="pcoded-inner-content">
                            <div class="main-body">
                                <div class="page-wrapper">
                                    <div>
                                        <h4>
                                            <b
                                                style="color: black;"><?php echo strtoupper($classroom->getClassRoom($class_id)['section']).' '.$classroom->getClassRoom($class_id)['class_no'].$classroom->getClassRoom($class_id)['class_group'];?></b>
                                            - <span>
                                                <?php
                                                    echo $class_session->getSession($session_id)['year'].' ';
                                                    
                                                    if($class_session->getSession($session_id)['term']==1)
                                                    {
                                                    
                                                    echo $class_session->getSession($session_id)['term'].'st term ';
                                                    }
                                                    elseif($class_session->getSession($session_id)['term']==2)
                                                    {
                                                    
                                                    echo $class_session->getSession($session_id)['term'].'nd term ';
                                                    }
                                                    else 
                                                    {
                                                    
                                                    echo $class_session->getSession($session_id)['term'].'rd term ';
                                                    }
                                                    ?>
                                                - Student's <span> Results</span>
                                        </h4>
                                    </div>
                                    <?php
                                        if(isset($_GET['message']))
                                        {
                                            echo '<div align="center" id="status"><h4>'.$_GET['message'].'</h4></div>';
                                        }
                                        ?>
                                    <div id="status" align="center"></div>
                                    <!-- people -->
                                    <section class="people">
                                        <section class="w3l-team-block">
                                            <!-- //people cards style 1 -->
                                            <div class="card card_border mb-5">
                                                <div class="cards__heading">
                                                    <div class="container-fluid">
                                                        <div class="row">
                                                            <!-- <div class="col-sm-10">
                                                                <h3> </h3>
                                                            </div> -->
                                                        </div>
                                                    </div>
                                                </div>
                                                <div class="card-body">
                                                    <table class='table table-striped' id="table1">
                                                        <thead>
                                                            <tr>
                                                                <th>S/N</th>
                                                                <th>Student's Name</th>
                                                                <th>Reg No.</th>
                                                                <th>CA 1</th>
                                                                <th>CA 2</th>
                                                                <th>Exam</th>
                                                                <th>Total</th>
                                                                <th>Position</th>
                                                                <th>Grade</th>
                                                                <th>Action</th>
                                                            </tr>
                                                        </thead>
                                                        <tbody>
                                                            <?php
                                                                $n=1;
                                                                foreach($result->getAllResult($class_id, $session_id) as $resultInfo)
                                                                {
                                                                    echo '<tr>
                                                                    <td>'.$n.'</td>
                                                                    <td>'.$student->getStudent($resultInfo['student_id'])['firstname'].' '.$student->getStudent($resultInfo['student_id'])['lastname'].'</td> 
                                                                    <td>'.$student->getStudent($resultInfo['student_id'])['reg_no'].'</td> 
                                                                    <td>'.$resultInfo['ca_1'].'</td>
                                                                    <td>'.$resultInfo['ca_2'].'</td>
                                                                    <td>'.$resultInfo['exam'].'</td>
                                                                    <td>'.$resultInfo['total'].'</td>
                                                                    <td>'.posInfo($resultInfo['position']).'</td>
                                                                    <td>'.$resultInfo['grade'].'</td>
                                                                    <td><a href="view_result.php?result_id='.$resultInfo['id'].'" class="btn btn-primary">View</a></td>
                                                                </tr>';
                                                                $n++;
                                                                }

                                                                ?>

                                                        </tbody>
                                                    </table>

                                                    <div align="center">
                                                        <button type="button" class="btn btn-secondary" data-toggle="modal"
                                                            data-target="#studRemark">Add Rating
                                                        </button>
                                                    </div><br/>
                                                    <div class="row">
                                                        <div align="center" class="col-md-3 col-6"><button
                                                                name="generate" class="btn btn-primary">Generate
                                                                Result</button></div>
                                                        <?php
                                                        if(count($result->getAllResult($class_id, $session_id))!=0)
                                                        {
                                                            ?>
                                                        <div align="center" class="col-md-3 col-64"><a
                                                                href="promote_students.php?class_id=<?php echo $class_id;?>&session_id=<?php echo $session_id;?>"
                                                                class="btn btn-success">Promote Students</a></div>
                                                        <div align="center" class="col-md-2 col-6"><a
                                                                href="print_class_report.php?class_id=<?php echo $class_id;?>&session_id=<?php echo $session_id;?>"
                                                                class="btn btn-primary">Print Report</a></div>
                                                        <div align="center" class="col-md-3 col-6"><a
                                                                href="print_all_result.php?class_id=<?php echo $class_id;?>&session_id=<?php echo $session_id;?>"
                                                                class="btn btn-success">Print All Result</a></div>
                                                        <?php 
                      }?>
                                                    </div>
                                                </div>
                                            </div>
                                            <!--Rating Modal  -->

                                            <!-- <button type="button" class="btn btn-primary" data-toggle="modal"
                                            data-target="#studRemark">Add Rating
                                        </button> -->
                                        <div class="modal fade" id="studRemark" tabindex="-1" role="dialog"
                                            aria-labelledby="studRemarkTitle" aria-hidden="true">
                                            <div class="modal-dialog modal-dialog-centered" role="document">
                                                <div class="modal-content">
                                                    <div class="modal-header">
                                                        <h5 class="modal-title" id="exampleModalLongTitle">Add
                                                            Rating</h5>
                                                        <button type="button" class="close" data-dismiss="modal"
                                                            aria-label="Close">
                                                            <span aria-hidden="true">&times;</span>
                                                        </button>
                                                    </div>
                                                    <div id="rate_status" align="center"></div>
                                                    <form method="post" name="add_rate">
                                                        <div class="modal-body">
                                                            <div id="rate_success" align="center"></div>
                                                            <div class='row'>
                                                                <div class="col-sm-4 col-6">
                                                                    <span>Punctuality</span>
                                                                    <input type="number" class="form-control"
                                                                        name="puntuality" 
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Attendance</span>
                                                                    <input type="number" class="form-control"
                                                                        name="attendance"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Reliability</span>
                                                                    <input type="number" class="form-control"
                                                                        name="reliability"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Neatness</span>
                                                                    <input type="number" class="form-control"
                                                                        name="neatness"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Politeness</span>
                                                                    <input type="number" class="form-control"
                                                                        name="politeness"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Honesty</span>
                                                                    <input type="number" class="form-control"
                                                                        name="honesty"
                                                                        required />
                                                                </div>
                                                                <div class="col-sm-4 col-6">
                                                                    <span>Staff Relationship</span>
                                                                    <input type="number" class="form-control"
                                                                        name="staff_relationship"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Peers Relationship</span>
                                                                    <input type="number" class="form-control"
                                                                        name="peers_relationship"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Self Control</span>
                                                                    <input type="number" class="form-control"
                                                                        name="self_control"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Spirit Of Coopp</span>
                                                                    <input type="number" class="form-control"
                                                                        name="spirit_corpration"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Willigness to learn</span>
                                                                    <input type="number" class="form-control"
                                                                        name="learn_willingness"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Initiative</span>
                                                                    <input type="number" class="form-control"
                                                                        name="initiative"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Perseverence</span>
                                                                    <input type="number" class="form-control"
                                                                        name="perseverence"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Physchomotor</span>
                                                                    <input type="number" class="form-control"
                                                                        name="physchomotor"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Handrwiting</span>
                                                                    <input type="number" class="form-control"
                                                                        name="handwriting"
                                                                        required />
                                                                </div>
                                                                <div class="col-sm-4 col-6">
                                                                    <span>Games</span>
                                                                    <input type="number" class="form-control"
                                                                        name="games"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Sports</span>
                                                                    <input type="number" class="form-control"
                                                                        name="sports"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Drawing/Painting</span>
                                                                    <input type="number" class="form-control"
                                                                        name="drawing_paint"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-2 col-0"></div>
                                                                <div class="col-sm-4 col-6">
                                                                    <span>Craft</span>
                                                                    <input type="number" class="form-control"
                                                                        name="craft"
                                                                        required />
                                                                </div>

                                                                <div class="col-sm-4 col-6">
                                                                    <span>Musical SKills</span>
                                                                    <input type="number" class="form-control"
                                                                        name="musicals"
                                                                        required />
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <input type="radio" name="session_id"
                                                            value="<?php echo $session_id;?>" style="display: none;"
                                                            checked />
                                                        <input type="radio" name="class_id"
                                                            value="<?php echo $class_id;?>" style="display: none;"
                                                            checked />
                                                        <div class="modal-footer">
                                                            <button type="button" class="btn btn-danger"
                                                                data-dismiss="modal">Close</button>
                                                            <button type="submit" name="submit"
                                                                class="btn btn-success">Save
                                                                changes</button>
                                                        </div>
                                                    </form>
                                                </div>
                                            </div>
                                        </div>
                                        </section>

                                        <div id="styleSelector">

                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
        </div>

        <!-- Warning Section Ends -->
        <!-- Required Jquery -->
        <script type="text/javascript" src="assets/js/jquery/jquery.min.js"></script>
        <script type="text/javascript" src="assets/js/jquery-ui/jquery-ui.min.js"></script>
        <script type="text/javascript" src="assets/js/popper.js/popper.min.js"></script>
        <script type="text/javascript" src="assets/js/bootstrap/js/bootstrap.min.js"></script>
        <!-- jquery slimscroll js -->
        <script type="text/javascript" src="assets/js/jquery-slimscroll/jquery.slimscroll.js"></script>
        <!-- modernizr js -->
        <script type="text/javascript" src="assets/js/modernizr/modernizr.js"></script>
        <!-- am chart -->
        <script src="assets/pages/widget/amchart/amcharts.min.js"></script>
        <script src="assets/pages/widget/amchart/serial.min.js"></script>
        <!-- Todo js -->
        <script type="text/javascript " src="assets/pages/todo/todo.js "></script>
        <!-- Custom js -->
        <script type="text/javascript" src="assets/pages/dashboard/custom-dashboard.js"></script>
        <script type="text/javascript" src="assets/js/script.js"></script>
        <script type="text/javascript " src="assets/js/SmoothScroll.js"></script>
        <script src="assets/js/pcoded.min.js"></script>
        <script src="assets/js/demo-12.js"></script>
        <script src="assets/js/jquery.mCustomScrollbar.concat.min.js"></script>

        <script src="assets/js/jquery.nicescroll.js"></script>
        <script src="assets/js/scripts.js"></script>
        <script src="assets/vendors/perfect-scrollbar/perfect-scrollbar.min.js"></script>
        <script src="assets/vendors/simple-datatables/simple-datatables.js"></script>
        <script src="assets/js/vendors.js"></script>
        <script>
        var $window = $(window);
        var nav = $('.fixed-button');
        $window.scroll(function() {
            if ($window.scrollTop() >= 200) {
                nav.addClass('active');
            } else {
                nav.removeClass('active');
            }
        });
        </script>

        <script>
        $(document).on('click', 'button[name=generate]', function(e) {

            e.preventDefault();

            studentResult();
            subjectResult();
        });

        function studentResult() {
            $.post('../control/students_results.php', {
                    session_id: '<?php echo $session_id; ?>',
                    class_id: '<?php echo $class_id; ?>'
                },
                function(data, status) {
                    if (data == 'Result Generated') {
                        window.location =
                            "?class_id=<?php echo $class_id; ?>&session_id=<?php echo $session_id; ?>&message=Result Generated";
                    } else {
                        $("#status").html('<h4>' + data + '</h4>')
                    }
                });
        }

        function subjectResult() {
            $.post('../control/subject_result.php', {
                    session_id: '<?php echo $session_id; ?>',
                    class_id: '<?php echo $class_id; ?>'
                },
                function(data, status) {
                    // alert(data);
                    // if(data=='Result Generated')
                    // {
                    //   window.location="?class_id=1&session_id=1&message=Result Generated";
                    // }
                    // else
                    // {
                    //   $("#status").html('<h4>'+data+'</h4>')
                    // }
                });
        }

        // // Rateing
        $(document).on('submit', 'form[name=add_rate]', function(e) {
            e.preventDefault();
            //    alert("WORKIN");
            var formData = new FormData(this);

            $('#rate_status').html('<h4 class="card-title">Adding</h4>');
            // alert(pres);
            $.ajax({
                url: "../control/add_general_rating.php", // Url to which the request is send
                type: "POST", // Type of request to be send, called as method
                data: formData, // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                contentType: false, // The content type used when sending data to the server.
                cache: false, // To unable request pages to be cached
                processData: false, // To send DOMDocument or non processed data file it is set to false
                success: function(data) // A function to be called if request succeeds
                {
                    $('#rate_status').html('<h4 class="card-title">' + data + '</h4>');
                    // alert(data);

                }
            });
        });
        </script>
</body>

</html>
<?php
    }
    else
    {
      header('location:assessments.php');
    }
  }
  else
  {
    header("location:classes.php");
  }
}
else
{
    header("location:../index.php");
}
?>