<?php include 'controller/admissionCode.php' ?>
<?php  

function grade($total_score){
  $grade = "";
  if ($total_score>=80) {
    $grade = "A1";
  }elseif($total_score>=75){
    $grade = "B2";
  }elseif($total_score>=70){
    $grade = "B3";
  }elseif($total_score>=65){
    $grade = "C4";
  }elseif($total_score>=60){
    $grade = "C5";
  }elseif($total_score>=55){
    $grade = "C6";
  }elseif($total_score>=50){
    $grade = "D7";
  }elseif($total_score>=40){
    $grade = "E8";
  }elseif($total_score<=39){
    $grade = "F9";
  }elseif ($total_score=="") {
    $grade = "IC";
  }
  return $grade;
  }

  function remark($total_score){
  $remark = "";
  if ($total_score>=80) {
    $remark = "Exellent";
  }elseif($total_score>=75){
    $remark = "Very Good";
  }elseif($total_score>=70){
    $remark = "Good";
  }elseif($total_score>=65){
    $remark = "Credit";
  }elseif($total_score>=60){
    $remark = "Credit";
  }elseif($total_score>=55){
    $remark = "Credit";
  }elseif($total_score>=50){
    $remark = "Pass";
  }elseif($total_score>=40){
    $remark = "Pass";
  }elseif($total_score<=39){
    $remark = "Fail";
  }
  return $remark;
  }


if ($all_class_students) {
  
foreach ($all_class_students as $student) {
  $class_name  = $admission->get_all_class_students($student['class']);
  // $subject = $admission->get_subject($student['subject_id']);
  // $subject_name = $subject[0]['subject_name'];

 


  $class_name = $class_name[0]['class_name'];
	?>
	<style type="text/css">
		<?php include '../inc/media_bootstrap.php' ?>
		<?php include '../inc/print_css.php' ?>
		@media print{
		<?php include '../inc/media_bootstrap.php' ?>
		<?php include '../inc/print_css.php' ?>
		body{
			margin: 0px !important;

		}
    footer{
      page-break-after: always;

    }
		.ibox-content{
      /*height: 90% !important;*/
      /*margin-bottom: 5px !important;*/
      /*margin-top: 5px !important;*/
			outline-style: solid !important;
		    outline-color: red !important;
		    border: 3px solid yellow !important;
		    /*padding-top: 10px !important;*/
		    padding-bottom: 0px !important;
        /*background-size: 50px !important;*/
        background: url('../img/fw_.png') !important;
        /*background-attachment: fixed !important;*/
        background-size: 500px 500px !important;
        background-position: bottom  !important;
        background-repeat: no-repeat !important;

		}
    
		/*.table,.m-t,.m-t th,.m-t td,.table-bordered th,.table-bordered td{
     background-color: red !important: 
		}*/
    .table-bordered > thead > tr > th,
.table-bordered > tbody > tr > td {
  background-color: transparent !important;
  border-bottom-width: 1px;
  border: 1px solid #000 !important;

}

.main> thead > tr >th{
  font-size: 9px !important;
}
.main> tbody > tr >td{
  font-size: 13px !important;
}
/*.table-bodered{
  border-color: 2px solid #000 !important;
}*/
		th{
			font-size: 11px !important;
			background-color:transparent !important;
			padding-top: 1px !important;
			padding-bottom: 0px !important;
		}
		td{
			background-color:transparent !important;
			font-size: 16px !important;
			padding-top: 1px !important;
			padding-bottom: 1px !important;
      border-color: 1px solid #000 !important;
		}

}

	</style>
<body class="white-bg">
                <div class="wrapper wrapper-content p-xl">
                    <div class="ibox-content p-xl">
                    	<div class="green">
                    	<div class="row">
                    		<div class="col-sm-4"></div>
                    		<div class="col-sm-6">
                    			<div class="col-sm-2"></div>
                    		<h2 style="font-family: Times New Romans !important;font-weight: bolder !important;margin-left:0px !important;">OSEI TUTU SENIOR HIGH SCHOOL</h2>
                    		</div>
                    	</div>
                            <div class="row">
                                <div class="col-sm-3">
                                	<h5>
                                        Student Name:     <span><?php echo $student['student_name'] ?></span>
                                    </h5>
                                    <h5>
                                        Class Level:      <span>Form <?php echo $class_name; ?></span>
                                    </h5>
                                    <br>
                                    <h5>
                                        Next Term Begins:      <span></span>
                                    </h5>
                                </div>
                                <div class="col-sm-2"><br>
                                	<img style="width: 60% !important" src="../img/OT-Crest.fw_.png">
                                </div>
                                <div class="col-sm-4">
                                	
                                	<h3 style="font-family: Times New Romans !important;font-weight: bolder !important;font-size: 18px !important;margin-left:85px !important;">P.M.B</h3>
                                	<h3 style="font-family: Times New Romans !important;font-weight: bolder !important;font-size: 19px !important">AKROPONG ASHANTI</h3>
                                	<h3 style="font-family: Times New Romans !important;font-weight: bold !important;font-size: 19px !important">TEL: +233 547472237</h3>
                                	<h3 style="font-family: Times New Romans !important;font-weight: bolder !important;font-size: 19px !important">SESSION: <?php $a_year = $admission->get_a_year_name($a_year_id); echo $a_year[0]['a_year'] ?> SEM <?php echo $semester_id ?></h3>
                                </div>
                                <div class="col-sm-3">
                                	<h5>
                                        Student Overall Percentage:     
                                        <span>
                                          <?php 
                                          $over_all_position = $admission->overall_position($student['form_id'],$semester_id,$a_year_id);
                                          if ($over_all_position) {
                                            $i=0;
                                            foreach ($over_all_position as $over_all_position) {
                                              $i++;
                                            if ($over_all_position['student_id']==$student['student_id']) {
                                             echo round(($over_all_position['total_score']/900)*100);
                                            }
                                          }
                                          }
                                           ?>
                                        </span>
                                    </h5>
                                    <h5>
                                       Student Overall Grade:     
                                        <span>
                                          <?php 
                                          $over_all_position = $admission->overall_position($student['form_id'],$semester_id,$a_year_id);
                                          if ($over_all_position) {
                                            $i=0;
                                            foreach ($over_all_position as $over_all_position) {
                                              $i++;
                                            if ($over_all_position['student_id']==$student['student_id']) {
                                             echo grade(round(($over_all_position['total_score']/900)*100));
                                            }
                                          }
                                          }
                                           ?>
                                        </span>
                                    </h5>
                                    <h5>
                                        Overall Position:      
                                        <span>
                                          <?php 
                                          $over_all_position = $admission->overall_position($student['form_id'],$semester_id,$a_year_id);
                                          if ($over_all_position) {
                                            $i=0;
                                            foreach ($over_all_position as $over_all_position) {
                                              $i++;
                                            if ($over_all_position['student_id']==$student['student_id']) {
                                              $no_on_roll = $admission->form_noOf_stds($student['form_id']);
                                             echo $i.'/'.$no_on_roll;
                                            }
                                          }
                                          }
                                           ?>
                                        </span>
                                    </h5>
                                    <h5>
                                        Position Class:      
                                        <span>
                                          <?php
                                              $i++;
                                              $roll = $admission->class_noOf_stds($student['class']);
                                             echo $i.'/'.$roll;
                                            $i=0;
                                            foreach ($position_in_class as $position_in_class) {
                                            if ($position_in_class['student_id']==$student['student_id']) {
                                            }
                                           ?>
                                          <?php $position_in_class = $admission->postion_in_class($student['class'],$semester_id,$a_year_id);
                                          if ($position_in_class) {
                                          }
                                          }
                                          ?>
                                        </span>
                                    </h5>
                                    <h5>
                                        House:      <span></span>
                                    </h5>
                                </div>
                            </div>

                            <div class="table-responsive m-t">
                                <table class="table table-bordered invoice-table main" style="background-color:transparent !important">
                                    <thead>
                                    <tr>
                                      <th style="width: 200px !important;padding-left: 50px !important;padding-top: 15px !important">SUBJECT</th>
                                      <th>CLASS SCORE</th>
                                      <th>EXAM SCORE</th>
                                      <th>TOAL SCORE</th> 
                                      <th>GRADE</th>
                                      <th>CLASS AVERAGE</th>
                                      <th>SUBJECT CLASS POSITION</th>
                                      <th>OVERALL SUBJECT POSITION</th>
                                      <?php 
                                      $colspan = 11;
                                      $sem_id = 0;
                                      if ($globals) {
                                        foreach($globals as $global){
                                          $is_term = $setup->get_semester($global['semester_id']);
                                          if ($is_term[0]['sem_name']=="Second Semester") {
                                            $colspan = 11+1;
                                         $sem_id = 1;
                                         ?>
                                         <th>1st Sem Total</th>
                                         <?php
                                          }
                                        }
                                      }

                                       ?>
                                      
                                      <th>ANNUAL AVERAGE</th>
                                      <th style="width: 20px !important">REMARKS</th>
                                      <th style="width: 150px !important;text-align:left !important">TEACHER NAME</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                      <?php 
                                      // if ($student['student_id']) {
                                      //   $student_student_core = $admission->student_student_core($student['student_id'],$student['class_id'],$student['semester_id'],$student['a_year_id']);
                                      //   $student_student_elective = $admission->student_student_elective($student['student_id'],$student['class_id'],$student['track_id'],$student['semester_id'],$student['a_year_id']);
                                      //   if ($student_student_core) {
                                          ?>
          <!--  <tr>
                                      <td colspan="<?php //echo $colspan ?>" style="background-color: #ccc !important;"><b style="float: left;">CORE</b></td>
                                      
                                    </tr> -->
                                            <?php
                                  //           foreach($student_student_core as $rpt){
                                  // $subject_position = $admission->subject_position($rpt['subject_id'],$student['class_id'],$student['track_id'],$student['semester_id'],$student['a_year_id']);
                                  // $over_all_subject_position = $admission->over_all_subject_position($rpt['subject_id'],$student['form_id'],$student['track_id'],$student['semester_id'],$student['a_year_id']);

                                  // $last_sem_subject_position = $admission->subject_position($rpt['subject_id'],$student['class_id'],$student['track_id'],$sem_id,$student['a_year_id']);
                                              
                                             ?>
                                            <!--   <tr>
                                      <td><?php //echo $rpt['subject_name']; ?></td>
                                      <td><?php //echo $rpt['class_score']; ?></td>
                                      <td><?php //echo $rpt['exam_score']; ?></td>
                                      <td><?php //echo $rpt['total_score']; ?></td>
                                      <td><?php //echo grade($rpt['total_score']); ?></td>
                                      <td>  -->
                                        <?php 
                                        // if ($subject_position) {
                                        //   $i=0;
                                        //   $subject_total = "";
                                        //   foreach($subject_position as $position){
                                        //     $i++;
                                        //     $subject_total += $position['total_score'];
                                           
                                        //   }
                                          
                                        //   echo round($subject_total/$i);
                                        // }
                                         ?>

                                      <!-- </td>
                                      <td> --> <?php 
                                        // if ($subject_position) {
                                        //   $i=0;
                                        //   foreach($subject_position as $position){
                                        //     $i++;
                                        //    if ($rpt['student_id']==$position['student_id']) {
                                        //       echo $i; echo position($i);
                                        //    }
                                        //   }
                                        // }
                                         ?><!-- </td>
                                      <td> -->
                                         <?php 
                                        // if ($over_all_subject_position) {
                                        //   $i=0;
                                        //   foreach($over_all_subject_position as $position){
                                        //     $i++;
                                        //    if ($rpt['student_id']==$position['student_id']) {
                                        //       echo $i; echo position($i);
                                        //    }
                                        //   }
                                        // }
                                         ?>
                                    <!--   </td> -->
                                      <?php 
                                      // if ($globals) {
                                      //   foreach($globals as $global){
                                      //     $is_term = $setup->get_semester($global['semester_id']);
                                      //     if ($is_term[0]['sem_name']=="Second Semester") {
                                         ?>
                                         <!-- <td> -->
                                            <?php 

                                        //     if ($last_sem_subject_position) {
                                        //     $j=0;
                                        //    foreach($last_sem_subject_position as $position){
                                        //     $j++;
                                        //    if ($rpt['student_id']==$position['student_id']) {
                                        //      echo $position['total_score'];
                                        //    }
                                           
                                        //   }
                                        // }
                                            ?>
                                         <!-- </td> -->
                                         <?php
                                      //     }
                                      //   }
                                      // }

                                       ?>
                                       <?php 
                                      // if ($globals) {
                                      //   foreach($globals as $global){
                                      //     $is_term = $setup->get_semester($global['semester_id']);
                                      //     if ($is_term[0]['sem_name']=="Third Semester") {
                                         ?>
                                        <!--  <td>

                                         </td> -->
                                         <?php
                                      //     }
                                      //   }
                                      // }

                                       ?>
                                      <!-- <td> --> <?php 
                                      // $i=0;
                                      // $j=0;
                                      //   if ($subject_position) {
                                      //     $i=0;
                                      //     $subject_total = "";
                                      //     $last_sem_subject_total = "";
                                      //     foreach($subject_position as $position){
                                      //       $i++;
                                      //       $subject_total += $position['total_score'];
                                           
                                      //     }
                                      //     if ($last_sem_subject_position) {
                                      //       $j=0;
                                      //      foreach($last_sem_subject_position as $position){
                                      //       $j++;
                                      //       $last_sem_subject_total += $position['total_score'];
                                           
                                      //     }
                                      //     }
                                      //     $avg1 = 0;
                                      //     $avg2 = 2;
                                      //     if ($subject_total!=0) {
                                      //      $avg1 = $subject_total/$i;
                                      //     }else{
                                      //        $avg1 = $subject_total;
                                      //     }
                                      //     if ($last_sem_subject_total!=0) {
                                      //       $avg2 = $last_sem_subject_total/$j;
                                      //     }else{
                                      //       $avg2 = $last_sem_subject_total;
                                      //     }
                                      //     $sum = $avg1+$avg2;
                                      //     if ($avg1!=0&&$avg2!=0) {
                                      //       echo round(($sum)/2);
                                      //     }elseif($avg1!=0&&$avg2==0){
                                      //       echo round(($sum));
                                      //     }else{
                                      //       echo round($avg1);
                                      //     }
                                      //   }
                                         ?><!-- </td>
                                      <td style="font-size: 9px !important;"> --><?php //echo remark($rpt['total_score']); ?><!-- </td>
                                      <td style="font-size: 8px !important;text-align: left !important;padding-left: 3px !important">Ms PATIENCE ABONGO TENI</td>
                                    </tr> -->
                                             <?php
                                          //   }
                                          // }
                                          // if ($student_student_elective) {
                                            ?>
                                            <!-- <tr>
                                      <td colspan="<?php //echo $colspan ?>" style="background-color: #ccc !important;"><b style="float: left;">ELECTIVE</b></td>
                                      
                                    </tr> -->
                                            <?php
                                  //           foreach($student_student_elective as $rpt){
                                  // $subject_position = $admission->subject_position($rpt['subject_id'],$student['class_id'],$student['track_id'],$student['semester_id'],$student['a_year_id']);
                                  // $over_all_subject_position = $admission->over_all_subject_position($rpt['subject_id'],$student['form_id'],$student['track_id'],$student['semester_id'],$student['a_year_id']);

                                  //  $last_sem_subject_position = $admission->subject_position($rpt['subject_id'],$student['class_id'],$student['track_id'],$sem_id,$student['a_year_id']);
                                              
                                             ?>
                                             <!--  <tr>
                                      <td><?php //echo $rpt['subject_name']; ?></td>
                                      <td><?php //echo $rpt['class_score']; ?></td>
                                      <td><?php //echo $rpt['exam_score']; ?></td>
                                      <td><?php //echo $rpt['total_score']; ?></td>
                                      <td><?php //echo grade($rpt['total_score']); ?></td>
                                      <td>  -->
                                        <?php 
                                        // if ($subject_position) {
                                        //   $i=0;
                                        //   $subject_total = "";
                                        //   foreach($subject_position as $position){
                                        //     $i++;
                                        //     $subject_total += $position['total_score'];
                                           
                                        //   }
                                        //  echo round($subject_total/$i);
                                        // }
                                         ?>

                                      <!-- </td>
                                      <td> --> <?php 
                                        // if ($subject_position) {
                                        //   $i=0;
                                        //   foreach($subject_position as $position){
                                        //     $i++;
                                        //    if ($rpt['student_id']==$position['student_id']) {
                                        //       echo $i; echo position($i);
                                        //    }
                                        //   }
                                        // }
                                         ?><!-- </td>
                                      <td> -->
                                         <?php 
                                        // if ($over_all_subject_position) {
                                        //   $i=0;
                                        //   foreach($over_all_subject_position as $position){
                                        //     $i++;
                                        //    if ($rpt['student_id']==$position['student_id']) {
                                        //       echo $i; echo position($i);
                                        //    }
                                        //   }
                                        // }
                                         ?>
<!--                                       </td> -->
                                      <?php 
                                      // if ($globals) {
                                      //   foreach($globals as $global){
                                      //     $is_term = $setup->get_semester($global['semester_id']);
                                      //     if ($is_term[0]['sem_name']=="Second Semester") {
                                         ?>
                                         <!-- <td>
                                          
                                         </td> -->
                                         <?php
                                      //     }
                                      //   }
                                      // }

                                       ?>
                                       <?php 
                                      // if ($globals) {
                                      //   foreach($globals as $global){
                                      //     $is_term = $setup->get_semester($global['semester_id']);
                                      //     if ($is_term[0]['sem_name']=="Third Semester") {
                                         ?>
                                        <!--  <td>
                                           

                                         </td> -->
                                         <?php
                                      //     }
                                      //   }
                                      // }

                                       ?>
                                      <!-- <td> -->
                                         <?php 
                                      // $i=0;
                                      // $j=0;
                                      //   if ($subject_position) {
                                      //     $i=0;
                                      //     $subject_total = "";
                                      //     $last_sem_subject_total = "";
                                      //     foreach($subject_position as $position){
                                      //       $i++;
                                      //       $subject_total += $position['total_score'];
                                           
                                      //     }
                                      //     if ($last_sem_subject_position) {
                                      //       $j=0;
                                      //      foreach($last_sem_subject_position as $position){
                                      //       $j++;
                                      //       $last_sem_subject_total += $position['total_score'];
                                           
                                      //     }
                                      //     }
                                      //     $avg1 = 0;
                                      //     $avg2 = 2;
                                      //     if ($subject_total!=0) {
                                      //      $avg1 = $subject_total/$i;
                                      //     }else{
                                      //        $avg1 = $subject_total;
                                      //     }
                                      //     if ($last_sem_subject_total!=0) {
                                      //       $avg2 = $last_sem_subject_total/$j;
                                      //     }else{
                                      //       $avg2 = $last_sem_subject_total;
                                      //     }
                                      //     $sum = $avg1+$avg2;
                                      //     if ($avg1!=0&&$avg2!=0) {
                                      //       echo round(($sum)/2);
                                      //     }elseif($avg1!=0&&$avg2==0){
                                      //       echo round(($sum));
                                      //     }else{
                                      //       echo round($avg1);
                                      //     }
                                      //   }
                                         ?>
                                    <!--   </td>
                                      <td style="font-size: 9px !important;"><?php //echo remark($rpt['total_score']); ?></td>
                                      <td style="font-size: 8px !important;text-align: left !important;padding-left: 3px !important">Ms PATIENCE ABONGO TENI</td>
                                    </tr> -->
                                             <?php
                                          //   }
                                          // }
                                         
                                  

                                          // }
                                             ?>
                                              <tr>
                                                 <td colspan="<?php echo $colspan ?>" style="background-color: #ccc !important;"><b style="float: left;">CORE</b></td>
                                      
                                                  </tr> 

                                             <?php
                                             if ($subjects) {
                                              foreach ($subjects as $key) {
                                                if ($key['core_elective_name']=="Core") {
                                                     $student_report_core = $admission->student_report_core($student['student_id'],$student['class'],$key['subject_id'],$semester_id,$a_year_id);
                                  $subject_position = $admission->subject_position($key['subject_id'],$student['class'],$semester_id,$a_year_id);
                                  $over_all_subject_position = $admission->over_all_subject_position($key['subject_id'],$student['form_id'],$semester_id,$a_year_id);

                                   $last_sem_subject_position = $admission->subject_position($key['subject_id'],$student['class'],$semester_id,$a_year_id);
                                                 ?>
                                                 <tr>
                                                 <td  style="background-color: #fff !important;"><b style="float: left;"><?php echo $key['subject_name'] ?></b></td>
                                                 <td><?php echo $student_report_core[0]['class_score']; ?></td>
                                      <td><?php echo $student_report_core[0]['exam_score']; ?></td>
                                      <td><?php echo $student_report_core[0]['total_score']; ?></td>
                                      <td><?php echo grade($student_report_core[0]['total_score']); ?></td>
                                      <td>  
                                        <?php 
                                        if ($subject_position) {
                                          $i=0;
                                          $subject_total = "";
                                          foreach($subject_position as $position){
                                            $i++;
                                            $subject_total += $position['total_score'];
                                           
                                          }
                                         echo round($subject_total/$i);
                                        }
                                         ?>

                                      </td>
                                      <td> <?php 
                                        if ($subject_position) {
                                          $i=0;
                                          foreach($subject_position as $position){
                                            $i++;
                                           if ($student['student_id']==$position['student_id']) {
                                              echo $i; echo position($i);
                                           }
                                          }
                                        }
                                         ?></td>
                                      <td>
                                         <?php 
                                        if ($over_all_subject_position) {
                                          $i=0;
                                          foreach($over_all_subject_position as $position){
                                            $i++;
                                           if ($student['student_id']==$position['student_id']) {
                                              echo $i; echo position($i);
                                           }
                                          }
                                        }
                                         ?>
                                      </td>
                                      <?php 
                                      if ($globals) {
                                        foreach($globals as $global){
                                          $is_term = $setup->get_semester($global['semester_id']);
                                          if ($is_term[0]['sem_name']=="Second Semester") {
                                         ?>
                                         <td>
                                          
                                         </td>
                                         <?php
                                          }
                                        }
                                      }

                                       ?>
                                       <?php 
                                      if ($globals) {
                                        foreach($globals as $global){
                                          $is_term = $setup->get_semester($global['semester_id']);
                                          if ($is_term[0]['sem_name']=="Third Semester") {
                                         ?>
                                         <td>
                                           

                                         </td>
                                         <?php
                                          }
                                        }
                                      }

                                       ?>
                                      <td>
                                         <?php 
                                      $i=0;
                                      $j=0;
                                        if ($subject_position) {
                                          $i=0;
                                          $subject_total = "";
                                          $last_sem_subject_total = "";
                                          foreach($subject_position as $position){
                                            $i++;
                                            $subject_total += $position['total_score'];
                                           
                                          }
                                          if ($last_sem_subject_position) {
                                            $j=0;
                                           foreach($last_sem_subject_position as $position){
                                            $j++;
                                            $last_sem_subject_total += $position['total_score'];
                                           
                                          }
                                          }
                                          $avg1 = 0;
                                          $avg2 = 2;
                                          if ($subject_total!=0) {
                                           $avg1 = $subject_total/$i;
                                          }else{
                                             $avg1 = $subject_total;
                                          }
                                          if ($last_sem_subject_total!=0) {
                                            $avg2 = $last_sem_subject_total/$j;
                                          }else{
                                            $avg2 = $last_sem_subject_total;
                                          }
                                          $sum = $avg1+$avg2;
                                          if ($avg1!=0&&$avg2!=0) {
                                            echo round(($sum)/2);
                                          }elseif($avg1!=0&&$avg2==0){
                                            echo round(($sum));
                                          }else{
                                            echo round($avg1);
                                          }
                                        }
                                         ?>
                                      </td>
                                      <td style="font-size: 9px !important;"><?php echo remark($student_report_core[0]['total_score']); ?></td>
                                      <td style="font-size: 8px !important;text-align: left !important;padding-left: 3px !important"><?php 
                                      $title = "";
                                      if ($key['sex']=="Male") {
                                        $title = "Mr ";
                                        echo $title.$key['last_name'].' '.$key['first_name'];
                                      }elseif($key['sex']=="Female"){
                                        $title = "Ms ";
                                        echo $title.$key['last_name'].' '.$key['first_name'];
                                      }
                                       ?></td>
                                    </tr>
                                             <?php
                                            }
                                          }
                                         
                                  

                                          }
                                             ?>
                                      
                                                 
                                                
                                           <tr>
                                                 <td colspan="<?php echo $colspan ?>" style="background-color: #ccc !important;"><b style="float: left;">ELECTIVE</b></td>
                                      
                                                  </tr> 

                                             <?php
                                             if ($subjects) {
                                              foreach ($subjects as $key) {
                                                if ($key['core_elective_name']=="Elective") {
                                                   $student_report_elective = $admission->student_report_elective($student['student_id'],$student['class'],$key['subject_id'],$semester_id,$a_year_id);
                                  $subject_position = $admission->subject_position($key['subject_id'],$student['class'],$semester_id,$a_year_id);
                                  $over_all_subject_position = $admission->over_all_subject_position($key['subject_id'],$student['form_id'],$semester_id,$a_year_id);

                                   $last_sem_subject_position = $admission->subject_position($key['subject_id'],$student['class'],$semester_id,$a_year_id);
                                                 ?>
                                                 <tr>
                                                 <td  style="background-color: #fff !important;"><b style="float: left;"><?php echo $key['subject_name'] ?></b></td>
                                                  <td><?php echo $student_report_elective[0]['class_score']; ?></td>
                                      <td><?php echo $student_report_elective[0]['exam_score']; ?></td>
                                      <td><?php echo $student_report_elective[0]['total_score']; ?></td>
                                      <td><?php echo grade($student_report_elective[0]['total_score']); ?></td>
                                      <td>  
                                        <?php 
                                        if ($subject_position) {
                                          $i=0;
                                          $subject_total = "";
                                          foreach($subject_position as $position){
                                            $i++;
                                            $subject_total += $position['total_score'];
                                           
                                          }
                                         echo round($subject_total/$i);
                                        }
                                         ?>

                                      </td>
                                      <td> <?php 
                                        if ($subject_position) {
                                          $i=0;
                                          foreach($subject_position as $position){
                                            $i++;
                                           if ($student['student_id']==$position['student_id']) {
                                              echo $i; echo position($i);
                                           }
                                          }
                                        }
                                         ?></td>
                                      <td>
                                         <?php 
                                        if ($over_all_subject_position) {
                                          $i=0;
                                          foreach($over_all_subject_position as $position){
                                            $i++;
                                           if ($student['student_id']==$position['student_id']) {
                                              echo $i; echo position($i);
                                           }
                                          }
                                        }
                                         ?>
                                      </td>
                                      <?php 
                                      if ($globals) {
                                        foreach($globals as $global){
                                          $is_term = $setup->get_semester($global['semester_id']);
                                          if ($is_term[0]['sem_name']=="Second Semester") {
                                         ?>
                                         <td>
                                          
                                         </td>
                                         <?php
                                          }
                                        }
                                      }

                                       ?>
                                       <?php 
                                      if ($globals) {
                                        foreach($globals as $global){
                                          $is_term = $setup->get_semester($global['semester_id']);
                                          if ($is_term[0]['sem_name']=="Third Semester") {
                                         ?>
                                         <td>
                                           

                                         </td>
                                         <?php
                                          }
                                        }
                                      }

                                       ?>
                                      <td>
                                         <?php 
                                      $i=0;
                                      $j=0;
                                        if ($subject_position) {
                                          $i=0;
                                          $subject_total = "";
                                          $last_sem_subject_total = "";
                                          foreach($subject_position as $position){
                                            $i++;
                                            $subject_total += $position['total_score'];
                                           
                                          }
                                          if ($last_sem_subject_position) {
                                            $j=0;
                                           foreach($last_sem_subject_position as $position){
                                            $j++;
                                            $last_sem_subject_total += $position['total_score'];
                                           
                                          }
                                          }
                                          $avg1 = 0;
                                          $avg2 = 2;
                                          if ($subject_total!=0) {
                                           $avg1 = $subject_total/$i;
                                          }else{
                                             $avg1 = $subject_total;
                                          }
                                          if ($last_sem_subject_total!=0) {
                                            $avg2 = $last_sem_subject_total/$j;
                                          }else{
                                            $avg2 = $last_sem_subject_total;
                                          }
                                          $sum = $avg1+$avg2;
                                          if ($avg1!=0&&$avg2!=0) {
                                            echo round(($sum)/2);
                                          }elseif($avg1!=0&&$avg2==0){
                                            echo round(($sum));
                                          }else{
                                            echo round($avg1);
                                          }
                                        }
                                         ?>
                                      </td>
                                      <td style="font-size: 9px !important;"><?php echo remark($student_report_elective[0]['total_score']); ?></td>
                                      <td style="font-size: 8px !important;text-align: left !important;padding-left: 3px !important"><?php 
                                      $title = "";
                                      if ($key['sex']=="Male") {
                                        $title = "Mr ";
                                        echo $title.$key['last_name'].' '.$key['first_name'];
                                      }elseif($key['sex']=="Female"){
                                        $title = "Ms ";
                                        echo $title.$key['last_name'].' '.$key['first_name'];
                                      }
                                       ?></td>
                                    </tr>
                                           
                                                   
                                                 <?php
                                                }
                                              }
                                             }
                                          ?>

                                  

                                    </tbody>
                                </table>
                            </div><!-- /table-responsive -->

                       <div class="row">
                       	<div class="col-sm-6">
                          <span style="font-size: 15px !important;font-weight: bold !important;">Form mistress' student: Ms Patience AbbongoTeni</span>
                          <table class="table-responsive" style="margin-left: 50px !important">
                            <tr>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Conduct:</td>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Obidient</td>
                            </tr>
                            <tr>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Interest:</td>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Reading</td>
                            </tr>
                            <tr>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Attitude:</td>
                              <td style="font-size: 14px !important;text-align: right !important;width: 100px;">Sociable</td>
                            </tr>
                          </table>
                          <span style="font-size: 15px !important;font-weight: bold !important;">House master' student: Mr Patience AbbongoTeni</span>
                          <span style="margin-left: 90px !important;">Well behaved</span>
                          <p></p>
                         <span style="font-size: 15px !important;font-weight: bold !important;padding-right: 80px">Head master' student: Mr Patience AbbongoTeni</span>
                          <span style="margin-left: 90px !important;">Well behaved</span>

                        </div>
                       	<div class="col-sm-3"></div>
                       	<div class="col-sm-3">
                       		<table class="table table-bordered">
                       			<thead>
                       				<th>Grading Code</th>
                       				<th>Grade</th>
                       				<th>Remarks</th>
                       			</thead>
                       			<tbody>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">80-100</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">A1</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Excellent</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">75-59</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">B2</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Very Good</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">70-74</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">B3</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Good</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">65-69</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">C4</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Credit</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">60-64</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">C5</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Credit</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">55-59</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">C6</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Credit</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">50-54</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">D7</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Pass</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">40-49</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">E8</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Pass</td>
                       				</tr>
                       				<tr>
                       					<td style="text-align: center !important;font-size: 10px !important;">0-39</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">F9</td>
                       					<td style="text-align: center !important;font-size: 10px !important;">Fail</td>
                       				</tr>
                       			</tbody>
                       		</table>
                       	</div>
                       </div>

                        </div>
                    </div>

    </div>
    <footer></footer>
<script type="text/javascript">
	window.print();
</script>

</body>


<?php
}
}
 ?>