<div style="overflow-x:auto;">


        <table width="100%"  class="responsive">



          <tr>
            
            <th class="thStyle" width="20%"> Test/Term     </th>
            <th class="thStyle" width="15%"> Class/Section </th>
            <th class="thStyle" width="10%"> Total Marks </th>
            <th class="thStyle" width="8%"> Obt Marks   </th>
            <th class="thStyle" width="8%"> %           </th>
            <th class="thStyle" width="8%"> Grade       </th>
            <th class="thStyle" width="8%"> SMS  </th>
            <!-- <th class="thStyle" width="10%"> Class Position </th> -->
              
          </tr>

     <?php 

      $sql = "select * from  eduportal_exam_terms where branch_id=".$_SESSION['branch']." and session_id='$session1' order by term_id asc";
      $terms = $m->query($sql);
      $count=1;
      foreach($terms as $term)
      { 

       $b=$_SESSION['branch'];
       $trm=$term['term_id'];
       
       $query="select SUM(obtained_marks)as obt,SUM(total_marks) as tm from eduportal_exam_marksheet where session_id='$session1' and branch_id='$b' AND term_id='$trm' AND student_id=".$WorkAssignListVal[0]['student_id'];
      // echo $query;
       $marks = $m->query($query);
       //print_r($marks);
       

       $avg=0+$marks[0]['obt']/$marks[0]['tm']*100;
      
        if($marks[0]['tm']==NULL){
         continue;
        }
  


      $gqr="SELECT grade_id,grade_title FROM eduportal_exam_school_grades WHERE percantage_start_range <=".$avg." and percantage_end_range >=".$avg." and branch_id=".$_SESSION['branch'];


        $average =  $m->query($gqr); 
         
        
      ?>
          <tr>

           <td class="tdStyle" width="">
           <a data-toggle="modal" data-toggle="modal" data-target="#TermTest<?php echo $term['term_id'];?>" style="padding: 0px 5px; font-size:14px;" href ="#">

          <?php echo $term['term_title'];?>

          </a>
          </td>
          
          <td class="tdStyle" width=""> <?php echo $class[0]['Class_Name']."-".$section[0]['section_name'];?>    </td>
          <td class="tdStyle" width=""> <?php  if($marks[0]['tm']!=NULL){echo $marks[0]['tm'];}else {echo "--";};?> </td>
          <td class="tdStyle" width=""> <?php  if($marks[0]['obt']!=NULL){echo ceil($marks[0]['obt']);}else {echo "--";};?>   </td>
          <td class="tdStyle" width=""> <?php  if($avg!="NULL"){echo number_format($avg,1);}else {echo "--";};?>%            </td>
          <td class="tdStyle" width=""><?php  if($average[0]['grade_title']!=NULL){echo $average[0]['grade_title'];}else {echo "--";};?></td>
          <td class="tdStyle" width=""> <?php  if($marks[0]['sms_status']==1){ ?> 
          
          <a data-toggle="modal" data-target="#Result<?php echo $term['term_id'];?>" style="padding: 0px 5px; font-size:14px;" class="btn btn-success">

          Resend <i class="fa fa-check" aria-hidden="true"></i>

          </a>
          
            <?php }else {?> 

          
          <a data-toggle="modal" data-toggle="modal" data-target="#Result<?php echo $term['term_id'];?>" style="padding: 0px 5px; font-size:14px;" class="btn btn-warning">

          Send

          </a>

            <?php }?> 
        





      <!-- Modal -->
      <div id="Result<?php echo $term['term_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content popup_style">
            <div class="modal-header">
              <button type="button" class="close pull-right" data-dismiss="modal">Close</button>
              <h4 class="modal-title"> RESULT OF (<?php echo $WorkAssignListVal[0]['first_name']." - ".$WorkAssignListVal[0]['last_name']; ?>)  </h4>
            </div>

            <div class="modal-body">

<form class="form-style-7" action="<?php echo DOMAIN.AgentDirectory;?>parent/InsertMe.php" method="get"  enctype="multipart/form-data">

          <input type="hidden" name="action" value="ResendResult">
          
          <input type="hidden" name="student_name" value="<?php echo $WorkAssignListVal[0]['first_name'];?>" />
          <input type="hidden" name="term_id"  value="<?php echo $term['term_id']; ?>" />
          <input type="hidden" name="session"  value="<?php echo $WorkAssignListVal[0]['session_id']; ?>" />
          <input type="hidden" name="class_id"  value="<?php echo $WorkAssignListVal[0]['class_id']; ?>" />
          <input type="hidden" name="section"  value="<?php echo $WorkAssignListVal[0]['section_id']; ?>" />
          <input type="hidden" name="limit"  value="<?php echo $brid[0]['sms_limit']; ?>" />          
          <input type="hidden" name="student"  value="<?php echo $_GET['student']; ?>" />          

          <br>

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

          
                      <div class="form-group" >
                        
                        <label>  Test/Paper: </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $term['term_title']; ?>"  class="form-control field" name="term_title" readonly/>
                      </div>
          </div>

        
                <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Total Marks </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $marks[0]['tm'];?>"  class="form-control field" name="tmarks" readonly/>
                      </div>
                </div>

                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Obtained Marks </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo ceil($marks[0]['obt']); ?>"  class="form-control field" name="obt" readonly/>
                      </div>
                  </div>


                 <div class="col-md-4" >
                      <div class="form-group" >
                        
                        <label>  Percantage % </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo number_format($avg,1);?>%"  class="form-control field" readonly/>
                      </div>
                  </div>




                 <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Grade </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $average[0]['grade_title']; ?>"  class="form-control field" name="grade" readonly/>
                          </div>
                    </div>

                     <div class="col-md-4" >
                          <div class="form-group" >
                            
                            <label>  Cell No </label>
                              <input style="height:40px;padding-left:1%;"  type="text"  required  class="form-control field" name="cell_no" value="<?php echo $WorkAssignListVal[0]['cell_no']; ?>" />
                          </div>
                      </div>



            <div class="modal-footer">

              <button type="submit" class="btn btn-primary" name="submit" >Send Result </button>
              <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>


            </div>



                 </form>

          </div>

          </div>

        </div>
      </div>

      <!-- ending -->







                                  <!-- Student Result popup start -->


      <div id="TermTest<?php echo $term['term_id'];?>" class="modal fade" role="dialog">
        <div class="modal-dialog">

          <!-- Modal content-->
          <div class="modal-content popup_style">
            <div class="modal-header">
              <button type="button" class="btn btn-default pull-right" data-dismiss="modal">Close</button>
              <h4 class="modal-title"><?php echo $WorkAssignListVal[0]['first_name']." - ".$WorkAssignListVal[0]['last_name']; ?>  </h4>
            </div>

            <div class="modal-body">

            
          <div class="col-md-12" >
                      <div class="form-group" >
                        
                        <label>  Test/Paper </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $term['term_title']; ?>"  class="form-control field" name="term_title" readonly/>
                      </div>
          </div>




<table width="100%" style="font-size:18px;" cellspacing="0" >  
   
        <tr>  
         
            <th width="8%"  class="tdalign" style="border-top-left-radius:15px;">SR </th>
            <th width="35%"  class="tdalign"> SUBJECTS </th>
            <th width="10%"  class="tdalign"> TOTAL </th>
            <th width="10%"  class="tdalign"> OBTAINED </th>
      
                        
         </tr>
<?php 

              // printing all the relevant subjects of each class
                         
                 $m->where("branch_id", $_SESSION['branch']);
                 $m->where("session_id", $WorkAssignListVal[0]['session_id']);
                 $m->where("class_id", $WorkAssignListVal[0]['class_id']);
                 $m->where("section_id", $WorkAssignListVal[0]['section_id']);


                 $teacher_sbj = $m->get("eduportal_class_subjects");

                $count=1;
                
                $totalm=0;
                $totalobt=0;
                $pertg =0;
  
              foreach($teacher_sbj as $teacher_sb) {


                $m->where("subject_id", $teacher_sb['subject_id']);
                $subjects = $m->get("eduportal_subject_config"); 

                $m->where("session_id", $WorkAssignListVal[0]['session_id']);
                $m->where("term_id", $term['term_id']);
                $m->where("subject_id", $teacher_sb['subject_id']);
                $m->where("student_id", $_REQUEST['student']); 
                $marks = $m->get("eduportal_exam_marksheet"); 

                 $totalm+=$marks[0]['total_marks']+0;
                $totalobt+=$marks[0]['obtained_marks']+0;

                $pertg = $total_obt*100/$total_marks;
  
        
                ?>

   
         <tr>  
         
            <td style="padding:0%;text-align:center;"  class="tdalign"> <?php echo $count; $count++; ?> </td>
            <td style="padding:0%;"> <?php echo $subjects[0]['subject']; ?> </td>
            <td style="padding:0%;text-align:center;" class="tdalign"> <?php echo $marks[0]['total_marks']; ?> </td>
            <td style="padding:0%;text-align:center;" class="tdalign"> <?php echo $marks[0]['obtained_marks'] ?> </td>
      
            
         </tr>



   <?php }  $percentage=ceil($totalobt)/$totalm*100; ?>

      
   </table>







        <br>
                <div class="col-md-3" >
                      <div class="form-group" >
                        
                        <label>  Total </label>
                          <input style="height:40px;padding-left:1%;" type="text" value="<?php echo $totalm;?>"  class="form-control field" name="tmarks" readonly/>
                      </div>
                </div>

                 <div class="col-md-3" >
                      <div class="form-group" >
                        
                        <label>  Obtained </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo ceil($totalobt); ?>"  class="form-control field" name="obt" readonly/>
                      </div>
                  </div>


                 <div class="col-md-3" >
                      <div class="form-group" >
                        
                        <label>  Percantage % </label>
                          <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo  number_format($percentage,1);?>%"  class="form-control field" readonly/>
                      </div>
                  </div>




                 <div class="col-md-3" >
                          <div class="form-group" >
                            
                            <label>  Grade </label>
                            
                              <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $average[0]['grade_title']; ?>"  class="form-control field" name="grade" readonly/>
                          </div>
                    </div>

                  


            <div class="modal-footer">

            


            </div>




          </div>

          </div>

        </div>
      </div>

      <!-- Student result popup ending -->



        </td>
          
          
          </tr>



    <?php }  ?>                       




    </table>


</div>