<?php include('parent/callMe.php');?>
<?php include('Sessioncheck.php');?>
<?php 

 $session1;
      if($_REQUEST['session']!=NULL){

       $session1=$_REQUEST['session'];
     }else {
       $session1=$_SESSION['current_session'];
     }

//getting branch details 
$branchID=$_SESSION['branch'];
$date=date('Y-m');
$branch=getBranch($m);

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

$STDid=$_REQUEST['student'];
$qr="SELECT * FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance!='P' and branch_Id='$branchID' and session_id='$session1' order by date DESC limit 10"; 

$Datas=$m->query($qr);

 $m->where("session_id", $_SESSION['current_session']);
 $sessionName = $m->get("edu_session_config");


?>
 <!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />
<title>Student Profile Details</title>
<!-- Favicons-->
<link rel="icon" type="image/png" href="img/favicon.png" sizes="32x32" />

<!-- <script type="text/javascript">
 window.print();
</script> -->
<style> 
.section{width:100%; height:auto;float:left;padding-right:1%;margin-left:1%;}
     
tr th {background-color:lightgray; text-align:center;font-size:14px;padding:3px;border:1px solid lightgray;}
tr td {border-bottom:1px solid lightgray;border-left:1px solid lightgray;padding:3px;}

@media print {
    #Header, #Footer { display: none !important; }
}
@media screen
   {
      p.bodyText {font-family:verdana, arial, sans-serif;}
   }

   @media print
   {
      p.bodyText {font-family:georgia, times, serif;}
   }
   @media screen, print
   {
      p.bodyText {font-size:10pt}
   }
   @media print {
  a[href]:after {
    content: none !important;
  }
}
</style>

<style>
.footer {
  position: fixed;
  left: 0;
  bottom: 0;
  width: 100%;
  
}
</style>
</head>
<body>

<div class="section" >         
<div style="width:100%;font-size:24px;text-align:center;"><?php echo $branch[0]['Branch_Name'];?></div>
<br><div style="font-size: 18px;text-align: center;">Student Profile</div>
<div class="profile_img" style="margin: -73px 100px 0px 0px">
        <div id="crop-avatar">
          <!-- Current avatar -->
           <?php if($student[0]['image']!=NULL){ ?>

      <img src="<?php echo DOMAIN;?>Production/students_pics/<?php echo $student[0]['image'];?>" id="preview" class="img-thumbnail" style="width:100px;height:100px;"   />

   <?php }else { ?>   

       <img src="<?php echo DOMAIN;?>Production/images/upload.png" id="preview" height="100px" class="img-thumbnail" width="100px"  />


   <?php } ?>
                        </div>
                      </div>
   <table width="100%" style="font-size:14px; padding-right: 2%;" cellspacing="0" >  
   
   
      <tr>  
         <td width="10%" style="border:none;"> Roll No:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['candidate_roll_no'];?>  </td>
      
         <td width="10%" style="border:none;"> Name:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['first_name'];?>  </td>

         <td width="10%" style="border:none;"> F.Name:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['last_name'];?>  </td>

      </tr>

       <tr>  
         <td width="10%" style="border:none;"> F.Contact:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['cell_no'];?>  </td>
      
         <td width="10%" style="border:none;"> H.Contact:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['father_cellno'];?>  </td>

         <td width="10%" style="border:none;"> P.Contact:   </td>
         <td width="20%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">  <?php echo $student[0]['cell_no'];?>  </td>

      </tr>

  </table>
<br>

  <table  class="table table-striped table-bordered"style="width:98%; float: left;padding-left: 2%;">
            <tr>
              <th colspan="14" style="text-align: center;background-color: white;border:none;">Detail of Marks Obtained</th>
            </tr>
            <tr>
            
            <th class="thStyle" width="25%"> Test/Term   </th>
            <?php              
              

        $sql = "SELECT * FROM  eduportal_exam_marksheet  WHERE branch_id='$branchID' and session_id='$session1' and student_id='$STDid' group by subject_id ";
       //print_r($sql);
       $teacher_sbj = $m->query($sql); 

              foreach($teacher_sbj as $teacher_sb) {
                      
                $m->where("subject_id", $teacher_sb['subject_id']);
                $subjects = $m->get("eduportal_subject_config");
                ?>
            <th width="6%" class="center"> <?php echo $subjects[0]['subject']; ?> </th>
            <?php } ?>
            <th class="thStyle" width="5%"> Total </th>
            <th class="thStyle" width="15%"> Obtain</th>
            <th class="thStyle" width="5%"> %           </th>
            <th class="thStyle" width="10%"> Grade       </th>
           <!--  <th class="thStyle" width="10%">  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_title asc";
//print_r($sql);
     
     $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,sms_status from eduportal_exam_marksheet where branch_id='$b' and session_id='$session1' AND term_id='$trm' AND student_id=".$_GET['student'];
       
       $marks = $m->query($query);

       

       $avg=0+intVal($marks[0]['obt'])/intVal($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 <=".round($avg)." and percantage_end_range >=".round($avg)." and branch_id=".$_SESSION['branch'];
  
        $average =  $m->query($gqr); 
         
          
        
      ?>
          <tr>
          
          <td class="tdStyle" width=""> <?php echo $term['term_title'];?>   </td>
          <?php       
                   
                 
          foreach($teacher_sbj as $teacher_sb) { 

                   // if($ii==$condition){break;}
            $subjectID=$teacher_sb['subject_id'];
            $b=$_SESSION['branch'];
          $subMarks="select * from eduportal_exam_marksheet where branch_id='$b' and session_id='$session1' AND term_id='$trm' AND subject_id='$subjectID' AND student_id=".$_GET['student'];
          $SubjectMarks =  $m->query($subMarks);                           
          //echo print_r(array_reverse($sbs))."="; 
          $SubjectMarks=array_reverse($SubjectMarks);
                    ?>

                  <td width="8%" style="text-align:center;"> <?php  echo $SubjectMarks[0]['obtained_marks']; ?> / <?php  echo $SubjectMarks[0]['total_marks']; ?></td> 
                   <?php   }  ?>

          <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 $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="" style="border-right: 1px solid lightgray;"><?php  if($average[0]['grade_title']!=NULL){echo $average[0]['grade_title'];}else {echo "--";};?></td>
          <!-- <td class="tdStyle" width="" style="border-right: 1px solid lightgray;" > <?php  if($marks[0]['sms_status']==1){ ?> 
          
          <a data-toggle="modal" style="padding: 0px 5px; font-size:14px;" class="btn btn-success">

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

          </a>
          
            <?php }else {echo "NOT";};?>  </td> -->
          <!-- <td class="tdStyle" width=""> 4th </td> -->
          
          </tr>



    <?php }  ?> 
                    </table>

  <table  class="table table-striped table-bordered"style="width:98%;float:left;margin-top: 10px;padding-left: 15px;">
                      <thead>
                        <tr>
                          <th colspan="5">Summarize Attendance History  (<?php echo $sessionName[0]['session_year'];?>)</th>
                        </tr>
                        <tr>
                          
                          <th width="20%">Presents</th>
                          <th width="20%">Absents</th>
                          <th width="20%">Leave </th>
                          <th width="20%">Short Leave</th>
                          <th width="20%">Late</th>
                          
                        </tr>
                      </thead>
                      <tbody>

                        
<?php 
$count=1;
$branchID=$_SESSION['branch'];
$sessionIDs=$_SESSION['current_session'];
$STDid=$_REQUEST['student']; 
$date=date('Y-m');

$qrp="SELECT count(*) as Present FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='P' and branch_Id='$branchID' and session_id='$sessionIDs'";
$Presents=$m->query($qrp);

$qra="SELECT count(*) as Absent FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='A' and branch_Id='$branchID' and session_id='$sessionIDs'";
$Absents=$m->query($qra);

$qrl="SELECT count(*) as Leavestd FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='L' and branch_Id='$branchID' and session_id='$sessionIDs'";
//print_r($qrl);
$Leave=$m->query($qrl);

$qrsl="SELECT count(*) as ShortLeave FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='SL' and branch_Id='$branchID' and session_id='$sessionIDs'";
$ShortLeave=$m->query($qrsl);

$qrla="SELECT count(*) as Late FROM eduportal_attendance_detail WHERE student_id='$STDid' and attendance='LA' and branch_Id='$branchID' and session_id='$sessionIDs'";
$Late=$m->query($qrla);


?>
     <tr>
      <td style="text-align:center;"><?php echo $Presents[0]['Present'];?></td>
      <td style="text-align:center;"><?php echo $Absents[0]['Absent'];?></td>
      <td style="text-align:center;"><?php echo $Leave[0]['Leavestd'];?></td>
      <td style="text-align:center;"><?php echo $ShortLeave[0]['ShortLeave'];?></td>
      <td style="border-right: 1px solid lightgray;text-align:center;"><?php echo $Late[0]['Late'];?></td>

    </tr>

                      

      </tbody>
    </table> 



   

</div>
<br><br><br>
<table width="100%" class="" style="font-size:14px; padding-right: 2%;" cellspacing="0" >  
   
   
      <tr>  
         <td width="10%" style="border:none;"> Remarks:   </td>
         <td width="90%" style="border-bottom: 1px solid lightgray;text-align:center;border-left:none;">    </td>
      
         

      </tr>

     

  </table>
</body>
</html>
