<!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
     <section class="content-header bg-ligth">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h5><strong><a>EXAMINATION RESULT</a></strong></h5>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">Home</a></li>
              <li class="breadcrumb-item"><a href="#">Academic Records </a></li> 
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section> 
   <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <div class="row"> 
          <!-- /.col -->
          <div class="col-md-12"> 
              <div class="card card-primary card-outline">
              <div class="card-header p-2"> 
                   <?php  
                    $id= $_GET['id'];
                    $ex_id= $_GET['id_4']; 
                    $name = mysqli_query($conn,"SELECT student_srms.student_profile,marks_srms.exam_id,marks_srms.student_roll_no,marks_srms.class_id,student_srms.student_name,marks_srms.exam_id FROM `marks_srms`,`student_srms` WHERE marks_srms.student_roll_no=student_srms.student_roll_no AND marks_srms.student_roll_no = '$id' AND marks_srms.exam_id = '$ex_id'");
                    $nam = mysqli_fetch_array($name); 
                    $class_id=$nam['class_id']; 
                    $exam_id=$nam['exam_id'];
                    $student_roll_no=$nam['student_roll_no'];
                    ?>
                   
                  
                <div class="float-right mb-2">
                <a href="views/view_ol_result_pdf.php?id=<?php echo $id ?>&id_4=<?php echo $ex_id ?>" class="btn btn-success btn-xs float-right ml-2" >
                    <i class="fa fa-print"></i> PRINT RESULT
                </a>  
                </div>
              </div>
              <!-- /.card-header --> 
              <div class="card-body"> 
              <div class="tab-content"> 
                <div class="active tab-pane" id="level_5">
                    <div class="container-fluid">
                    <div class="row">
                    <div class="col-sm-12"> 
                    <div class="card"> 
                    <div class="card-body">
                      
                      <div class="row">
                        <div class="col-sm-3 ">
                          <img src="../<?php echo $nam['student_profile']; ?>" class="img-thumbnail" width="200" height="200" /> <br><br>
                           <h3 class="card-title"><b>ID NO:</b> <?php echo $student_roll_no; ?></h3>
                        </div>
                        <div class="col-sm-3 text-center">
                          <?php   
                               // Fetch marks for the student
                            $marks_query = "SELECT * FROM marks_srms WHERE exam_id='$exam_id' and class_id='$class_id' AND  student_roll_no = '$student_roll_no' ORDER BY marks DESC LIMIT 7";
                            $marks_result = $conn->query($marks_query);

                            $total_marks = 0;
                            $total_grade_points = 0;

                            while ($mark = $marks_result->fetch_assoc()) {
                                $total_marks += $mark['marks'];
                                $total_grade_points += $mark['point']; 
                              } 

                           $avr = round($total_marks/7, 1);
                            // Determine division based on grade points
                            if ($total_grade_points <= 17) {
                                $division = "I";
                            } elseif ($total_grade_points <= 21) {
                                $division = "II";
                            } elseif ($total_grade_points <= 25) {
                                $division = "III";
                            } elseif ($total_grade_points <= 33) {
                                $division = "IV";
                            } else {
                                $division = "Fail";
                            } 
                            ?> 
                            <br><br><br>
                        <h4><b>TOTAL MARKS</b></h4>
                        <p style="color: orange;"><b><?php echo  $total_marks; ?></b></p>
                        </div>
                        <div class="col-sm-3 text-center">
                          <br><br><br>
                          <h4><b>TOTAL GRADE POINT</b></h4>
                          <b><p style="color: orange;"><?php echo $total_grade_points; ?></p></b>
                        </div>
                        <div class="col-sm-3 text-center">
                          <br><br><br>
                          <h4><b>DIVISION</b></h4>
                          <b><p style="color: orange;"><?php echo $division; ?></p></b>
                        </div>
                        
                      </div>
                    </div> 
                    </div> 
                    <div class="card"> 
                     <div class="card-header">
                      <h3 class="card-title"><b>NAME OF STUDENT</b> : <?php echo $nam['student_name']; ?></h3> 
                      </div> 
                      <!-- /.card-header -->
                          <div class="card-body p-2">
                          <div class="table-responsive"> 
                            <table class="table table-bordered">
                              <thead>
                                <tr>
                                   <th style="width: 10px">#</th>
                                    <th>SUBJECT NAME</th>
                                    <th>MARKS</th> 
                                    <th>GRADE</th>
                                    <th>POINT</th> 
                                    <th>REMARK</th> 
                                </tr>
                              </thead>
                              <tbody>
                                 <?php   
                                  $i = 1; 
                                  $selecte5_1 = mysqli_query($conn,"SELECT general_subject.sub_id,general_subject.subject_name,marks_srms.marks,marks_srms.grade,marks_srms.student_roll_no,marks_srms.class_id,marks_srms.pass_marks,marks_srms.subject_id,marks_srms.point,marks_srms.exam_id FROM general_subject,marks_srms WHERE general_subject.sub_id=marks_srms.subject_id AND marks_srms.class_id='$class_id' AND marks_srms.student_roll_no = '$id'AND marks_srms.exam_id = '$ex_id'");
                                   while($row = mysqli_fetch_array($selecte5_1)){  
                                    $pass_mark=$row['pass_marks']; 
                                  ?> 
                                <tr>
                                  <td><?php echo $i++ ?></td>
                                  <td><?php echo $row['subject_name']; ?></td> 
                                  <td class="text-center" style="color: green;"><?php echo $row['marks']; ?></td> 
                                  <td class="text-center"><?php echo $row['grade']; ?></td> 
                                  <td class="text-center"><?php echo $row['point']; ?></td> 
                                  <td class="text-center"><?php echo $row['pass_marks']; ?></td> 
                                </tr> 
                                <?php } ?>
                                
                              </tbody>  
                            </table> 
                        </div>
                      </div> <!-- end card body-->
                       <div class="modal-footer">  
                           <a href="admin.php?page=fgtutrs345gj789km231ExamUIYTR7ttdeewz34&Id_2=<?php echo $exam_id; ?>" class="btn btn-secondary">BACK</a> 
                         </div>
                    </div> 
                      </div> <!-- end card --> 
                      </div>
                      <!-- /.card -->
                    </div>
                  </div> 

                </div>
              </div>
                <!-- /.tab-content -->
             </div> 

            <!-- /.card -->
          </div>
          <!-- /.col -->
        </div>
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
 <script src="../stp_con/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../stp_con/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- DataTables  & Plugins -->
<script src="../stp_con/datatables/jquery.dataTables.min.js"></script>
<script src="../stp_con/datatables-bs4/js/dataTables.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-responsive/js/dataTables.responsive.min.js"></script>
<script src="../stp_con/datatables-responsive/js/responsive.bootstrap4.min.js"></script>
<script src="../stp_con/datatables-buttons/js/dataTables.buttons.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.bootstrap4.min.js"></script>
<script src="../stp_con/jszip/jszip.min.js"></script> 
<script src="../stp_con/pdfmake/pdfmake.min.js"></script>
<script src="../stp_con/pdfmake/vfs_fonts.js"></script> 
<script src="../stp_con/datatables-buttons/js/buttons.html5.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.print.min.js"></script>
<script src="../stp_con/datatables-buttons/js/buttons.colVis.min.js"></script>
 
<script src="../assets/js/adminlte.min.js"></script>