<?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>Kinder Basic School - <?php echo strtoupper($classroom->getClassRoom($class_id)['section']).' '.$classroom->getClassRoom($class_id)['class_no'].' - ';
    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 ';
    } 
    echo ' - '.$class_session->getSession($session_id)['year'].'';
     
    ?>
   - Student's Result
  </title>

    <style>
    #posInfo td {
        padding: 5px;
    }

    #printResult {
        border-spacing: 0px;
        border: 1px solid black;
    }

    #printResult td,
    th {
        padding: 5px;
    }

    #kinderHead td {
        padding: 10px;
    }

    #azizaTitle {
        font-size: 35px;
        font-weight: bold;
        color: blue;
    }
    </style>


</head>

<body class="sidebar-menu-collapsed">
    <!-- main content start -->
    <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">
                    <table border="0" id="kinderHead" align="center">
                        <tr>
                            <td><img src="../images/aziza_logo.jpg" height="80px" width="80px" /></td>
                            <td align="center">
                                    <div id="azizaTitle">MALIKA INTERNATIONAL ACADEMY</div>
                                <b>NURSERY, PRIMARY, TAHFEEZ & SECONDARY</b>
                                <div><?php echo strtoupper($classroom->getClassRoom($class_id)['section']); ?> SECTION </div>
                            </td>
                        </tr>
                    </table>
                    <br>
                    <div class="container-fluid">
                        <div class="row">
                            <div align="center">
                                <h3><b
                                        style="color: black;"><?php echo strtoupper($classroom->getClassRoom($class_id)['section']).' '.$classroom->getClassRoom($class_id)['class_no'];?></b>
                                    - <span>
                                        <?php
                           
                            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 ';
                            } 
                            echo ' '.$class_session->getSession($session_id)['year'].'';
                            
                            ?> - Student's <span> Results</span> </h3>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="card-body">
                    <table id="printResult" width="100%" border="1">
                        <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>
                            </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 align="center">'.posInfo($resultInfo['position']).'</td>
                                <td align="center">'.posInfo($resultInfo['grade']).'</td>
                                </tr>';
                            $n++;
                            }

                            ?>

                        </tbody>
                    </table>

                </div>
                <!-- //teams1 -->

                <script>
    // When the user scrolls down 20px from the top of the document, show the button
    window.onscroll = function() {
        scrollFunction()
    };

    function scrollFunction() {
        if (document.body.scrollTop > 20 || document.documentElement.scrollTop > 20) {
            document.getElementById("movetop").style.display = "block";
        } else {
            document.getElementById("movetop").style.display = "none";
        }
    }

    // When the user clicks on the button, scroll to the top of the document
    function topFunction() {
        document.body.scrollTop = 0;
        document.documentElement.scrollTop = 0;
    }
    </script>
    <!-- /move top -->


    <script src="assets/js/jquery-3.3.1.min.js"></script>
    <script src="assets/js/jquery-1.10.2.min.js"></script>
 

    <!-- close script -->
       
    <script>
    $(window).load(function() {
      window.print();
      setTimeout(function()
      {
        window.location="results.php?class_id=<?php echo $class_id;?>&session_id=<?php echo $session_id;?>";
      },1000);
    });
    </script>
    <!--// loading-gif Js -->
    
    <script src="assets/js/bootstrap.min.js"></script>



</body>

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