

<?php 

$m->where("student_id", $_REQUEST['student']);
$m->where("branch_id", $_SESSION['branch']);
$WorkAssignListVal = $m->get("edu_student_details");

?>

<table width="100%"  class="responsive" style="overflow-x:auto; background-color: white;">


          <tr>
            
            <th class="thStyle" width="40%"> Test/Term </th>
            <th class="thStyle" width="8%"> Total </th>
            <th class="thStyle" width="8%"> Obtained </th>
            <th class="thStyle" width="8%"> % </th>
            <th class="thStyle" width="8%"> Grade</th>
            <th class="thStyle" width="8%">Edit</th>
            <th class="thStyle" width="15%"> SMS/Print  </th>
                          
          </tr>

<?php 

         $session1;

      if($_REQUEST['session']!=NULL){
        $session1=$_REQUEST['session'];
      }else { $session1=$_SESSION['current_session']; }


       $sql = "select * from  eduportal_exam_terms where branch_id='".$_SESSION['branch']."' and session_id='$session1' order by term_id asc";

     // echo $sql;

      $terms = $m->query($sql);
      $count=1;
      foreach($terms as $term)
      { 

       $b=$_SESSION['branch'];
       $trm=$term['term_id'];
       $stdID=$WorkAssignListVal[0]['student_id'];
       $clsID=$WorkAssignListVal[0]['class_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='$stdID'";

      
    // echo $query;

      $marks = $m->query($query);
      //  print_r($marks);
       

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

      // getting grades 
        
      if($marks[0]['obt']!=NULL){

           $grade = getGrade($avg,$m); 
      }
      


        
      ?>
 <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  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($grade!=NULL){echo $grade;}else {echo "--";};?></td>

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

          Eidt

          </a>
          </td>


          <?php
          $total_sms_monthly_used=getCurrentMonthFeeSms($m)+getCurrentMonthResultSms($m)+getCurrentMonthOtherSms($m)+getCurrentMonthAttendanceSms($m)+0;
      $sms_credit=$brid[0]['monthly_credit']-$total_sms_monthly_used; ?>

          <td class="tdStyle" width=""> <?php  if($marks[0]['sms_status']==1){ ?> 
          
          <a data-toggle="modal" data-target="#Result<?php echo $term['term_id'];?>" <?php if($sms_credit <= 0) { echo "disabled";}?> 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'];?>" <?php if($sms_credit <= 0) { echo "disabled";}?> style="padding: 0px 5px; font-size:14px;" class="btn btn-warning">

          Send Sms

          </a>

            <?php }?> 

          <a href="print_oldstudent_reportcard.php?<?php echo session_id().session_id().session_id().session_id().session_id(); ?>&student_id=<?php echo $_REQUEST['student'];?>&session=<?php echo $session1;?>&class_id=<?php echo $WorkAssignListings[0]['class_id'];?>&section=<?php echo $WorkAssignListings[0]['section_id'];?>&term_id=<?php echo $term['term_id'];?>" style="padding: 4px 6px; font-size:14px;" class="btn btn-success fa fa-print">

          Print 

          </a>
 <!-- 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 $grade; ?>"  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" <?php if($sms_credit <= 0) { echo "disabled";}?> 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" style="height:600px;">
            <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>
            <th width="10%"  class="tdalign"> Grade </th>
      
                        
         </tr>
<?php 

              // printing all the relevant subjects of each class
                 
                  if($_REQUEST['session']!=NULL){
                  $session1=$_REQUEST['session'];
                  }else { $session1=$_SESSION['current_session']; }

        
                $m->where("session_id", $session1);
                $m->where("term_id", $term['term_id']);
                $m->where("student_id", $_REQUEST['student']);
                $teacher_sbj = $m->get("eduportal_exam_marksheet"); 

                $count=1;
                
                $totalm=0;
                $totalobt=0;
                $pertg =0;
                $status;

              foreach($teacher_sbj as $Termmarks) {


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

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

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

                $percentage = ($Termmarks['obtained_marks']/$Termmarks['total_marks'])*100;

                // getting grade

                if($Termmarks['obtained_marks']!=NULL){

                     $grade = getGrade($percentage,$m); 
                }
      

                ?>

   
         <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 $Termmarks['total_marks']; ?> </td>
            <td style="padding:0%;text-align:center;" class="tdalign"> <?php echo $Termmarks['obtained_marks'] ?> </td>
            <td style="padding:0%;text-align:center;" class="tdalign"><?php  echo $grade; ?></td> 
            
         </tr>



   <?php $grade=""; }  $percentage=$totalobt/$totalm*100; 


                // getting grade

                if($Termmarks['obtained_marks']!=NULL){

                     $grade = getGrade($percentage,$m); 
                }
        

   ?>
      
   </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>
                                                          
                     <?php 

                         if ($status == 1) {

                        }else {?>

                  <input style="height:40px;padding-left:1%;" type="text"  value="<?php echo $grade; ?>"  class="form-control field" name="grade" readonly/>
                   <?php  }

                  $status="";?>           
                           </div>
                </div>

                  




          </div>

          </div>

        </div>
      </div>

      <!-- Student result popup ending -->



<!-- Employee Edit Salary Popup start -->


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

          <!-- Modal content-->
          <div class="modal-content">
            <div class="modal-header" style="border-bottom:none;">
              <button type="button" class="close" data-dismiss="modal">&times;</button>
              <h4 class="modal-title">Edit Result (<?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>

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

  <input type="hidden" name="action" value="ProfileTermTestEdit"> 
  <input type="hidden" name="student_id" value="<?php echo $_REQUEST['student']; ?>">
  <input type="hidden" name="class_id" value="<?php echo $clsID; ?>">
  <input type="hidden" name="section_id" value="<?php echo $WorkAssignListVal[0]['section_id']; ?>">
  <input type="hidden" name="term_id" value="<?php echo $term['term_id']; ?>">
  <input type="hidden" name="session_id"  value="<?php echo $WorkAssignListVal[0]['session_id']; ?>" />
         
         <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
                 
                  if($_REQUEST['session']!=NULL){
                  $session1=$_REQUEST['session'];
                  }else { $session1=$_SESSION['current_session']; }

        
                $m->where("session_id", $session1);
                $m->where("term_id", $term['term_id']);
                $m->where("student_id", $_REQUEST['student']);
                $teacher_sbj = $m->get("eduportal_exam_marksheet"); 

                $count=1;
                
                $totalm=0;
                $totalobt=0;
                $pertg =0;
                $status;

              foreach($teacher_sbj as $Termmarks) {


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

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

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

                $percentage = ($Termmarks['obtained_marks']/$Termmarks['total_marks'])*100;

                // getting grade

                if($Termmarks['obtained_marks']!=NULL){

                     $grade = getGrade($percentage,$m); 
                }
      

                ?>

   
         <tr>  

            <input type="hidden" name="subject_id[]"  value="<?php echo $subjects[0]['subject_id']; ?>" />

            <input type="hidden" name="totalMarks[]"  value="<?php echo $Termmarks['total_marks']; ?>" />
         
            <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 $Termmarks['total_marks']; ?> </td>
            <td style="padding:0%;text-align:center;" class="tdalign"> <input type="text" name="obtainMarks[]" id="obtainMarks<?php echo $subjects[0]['subject_id'];?>" onkeyup="net_totals(<?php echo $subjects[0]['subject_id'];?>)" value="<?php echo $Termmarks['obtained_marks'] ?>" style="width: 90px;">  </td>  


                      
            
         </tr>



   <?php $grade=""; }  $percentage=$totalobt/$totalm*100; 


                // getting grade

                if($Termmarks['obtained_marks']!=NULL){

                     $grade = getGrade($percentage,$m); 
                }
        

   ?>
      
   </table>


   <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" id="totalamt<?php echo $subjects[0]['subject_id'];?>"  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="modal-footer">

            <button type="submit" style="margin: 30px;" class="btn btn-primary" name="submit" >Submit </button>
              


            </div>

<script>

       

      function net_totals(id) {
        
       // alert(id);

        var obt_marks=document.getElementById("obtainMarks"+id).value;

        var total_amount= (Number(obt_marks));

//alert(total_amount);
        document.getElementById("totalamt"+id).value=total_amount;
                
      }




</script> 


                 </form>

          </div>

          </div>

        </div>
      </div>

      <!-- Employee Edit Salary popup ending -->






        </td>
          
          
          </tr>



    <?php }  ?>                       



            </table>