<?php
session_start();
$ex=$_SESSION['eexam'];
$pid=$_SESSION['ppupil'];

include('../include/config.php');

    $date = new DateTime("now", new DateTimeZone('Africa/Nairobi') );
    $timenow=$date->format('Y-m-d H:i:s');
    $timenow2=$date->format('Y-m-d');
    $month=$date->format('M');
    
    $feepaid='00';
    $y=$yr;
    if($y=='' || $y==null)
    {$yr=$date->format('Y');}
    else
    {
     $yr=$y;
    }
    
    if($tr=='' || $tr==null)
    {
        $tr='Term One'; 
    }else
    {
    }
    
    if($pid=='' || $pid==null)
    {
      $pid='0';
    }else
    {
    }
    
    $result = mysqli_query($con,"SELECT * from pupils where count='$pid'");
    while($row = $result->fetch_assoc()) 
    {
    $nam=$row["Names"];
    $admno=$row["AdmNo"];
    $claz=$row["Claz"];
    }
    
    $result = mysqli_query($con,"SELECT * from Exam where id='$ex'");
    while($row = $result->fetch_assoc()) 
    {
    $tit=strtoupper($row["Title"]);
    $pe=$row["Period"];
    $year=$row["Year"];
    }
    
    
    $query = mysqli_query($con,"SELECT Classteachers.Teacher as tea, Staffs.Name as tnam from Classteachers left join Staffs ON Staffs.id=Classteachers.Teacher where Classteachers.Clazzz='$claz'");
    while($row = $query->fetch_assoc()) 
    {
    $teaname=$row["tnam"];
    }
   
     $resultt = mysqli_query($con,"SELECT * from MarksScore where PID='$pid' AND EID='$ex'");
    while($row = $resultt->fetch_assoc()) 
    {
    $La=$row["Lang"];
    $Co=$row["Comp"];
    $Lu=$row["Lugha"];
    $In=$row["Insha"];
    $Ma=$row["Maths"];
    $Sc=$row["Scie"];
    $Ss=$row["SS"];
    $SCr=$row["SSCRE"];
    $Cr=$row["CRE"];
    $To=$row["Total"];
    $Re=$row["Remark"];
    
    $En=$La+$Co;
    $Ki=$Lu+$In;
    }
    
    
    $result = mysqli_query($con,"SELECT * FROM pupils where Claz='$claz' AND  Status='Active'");
    $num_rows1 = mysqli_num_rows($result);
    {
    $allpupils=htmlentities($num_rows1); 
    }
   
    
  
    $sql = "select * from Fees2 where count='$autono' AND pid='$pid'";
    $result = $con->query($sql);
    if ($result->num_rows > 0) 
    {
   
    }else
    {
     $feebala='0';
    }
  
 
 
   require_once 'dompdf/vendor/autoload.php';
 use Dompdf\Dompdf;
$html='
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0" name="viewport">
  <title>Exam Result: '.$nam.'</title>
  <meta content="" name="description">
  <meta content="" name="keywords">
  
  <link href="https://fonts.gstatic.com" rel="preconnect">
  <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Nunito:300,300i,400,400i,600,600i,700,700i|Poppins:300,300i,400,400i,500,500i,600,600i,700,700i" rel="stylesheet">
  <link href="assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!-- Vendor CSS Files -->
 
   <link rel="stylesheet" href="data/css/bootstrap.min.css">
  <link href="assets/vendor/bootstrap-icons/bootstrap-icons.css" rel="stylesheet">
  <link href="assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
  <link href="assets/vendor/quill/quill.snow.css" rel="stylesheet">
  <link rel="shortcut icon" href="../images/logo.ico">
</head>
<body style="border:1px solid #004d1a;border-radius:5px;padding:5px;border-style: double;outline-offset: -5px;">
    <div>
     <center> <h6 style="margin-top:5px;color:#0099cc" class="text-red" >CATHOLIC DIOCESE OF MURANGA </h6> </center>
   <center> <h3 style="margin-top:-20px" class="text-red" >BISHOP KAIRO EDUCATION CENTRE </h3> </center>
   <center> <h4 style="margin-top:-20px" class="text-red" >EXCELLENCE IS IN GODLINESS </h4> </center>
  
<img style="position:absolute;margin-top:-80px;margin-bottom:10px;max-height:90px" src="https://bishopkairoeducationcentre.sc.ke/QB-Beta/data/logo.png" alt="" class="" />
<br />
   <label style="margin-top:-20px" class="text-red" ><strong>Telephone:</strong> 0728 966 221, 0714 647 708 </label>
   <br />
  <label style="margin-top:-20px" class="text-red" ><strong>Email:</strong> cdmbishopkairo@gmail.com </label>
  
  <label style="position:absolute;margin-left:220px" class="text-red" ><strong>P.O. Box:</strong> 747- 10200 Murang'."'".'a </label>
  <hr />

<div style="">
 NAME: <strong> <u>'.$nam.' </u></strong> <br /> CLASS:   <strong><u>'.$claz.'</u></strong> <br /> ADM NO:  <strong><u>'.$admno.'</u>  <br /> CLASS TEACHER:  <strong><u>'.$teaname.'</u></strong> 
 
       <center><h3><u>REPORT FORM </u></h3></center>
        <u><h4 style="position:absolute;margin-top:-5px"><strong style="color:#00661a;">'.$tit.'</strong> <strong style="margin-left:50px">Year:  <span>'.$year.'</span></strong></h4></u>
    <table style="border:1px solid black;position:relative;margin-top:20px">
       <thead>
        <tr style="background-color:#000;color:#FFF">
         <th>SUBJECT </th><th>MARKS <br /> PREVIOUS</th> <th>MARKS <br  /> '.$pe.' </th> <th>OUT OF</th>
        </tr>
       </thead>
        <tbody>
         <tr style="border:1px solid black">
            <td  style="border:1px solid black">LANGUAGE </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"><strong>'.$La.'</strong></td>
            <td  style="border:1px solid black"><strong>50</strong></td>
         </tr> 
        <tr style="border:1px solid black">
            <td  style="border:1px solid black"> COMPOSITION </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$Co.' </strong></td>
            <td  style="border:1px solid black"><strong>50</strong></td>
        </tr>
        <tr>
            <td  style="border:1px solid black"> ENGLISH </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$En.' </strong> </td>
            <td  style="border:1px solid black"><strong>100</strong></td>
         </tr>
         <tr>
            <td  style="border:1px solid black"> LUGHA </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$Lu.'  </strong></td>
            <td  style="border:1px solid black"><strong>50</strong></td>
         </tr>
         <tr>
            <td  style="border:1px solid black"> INSHA </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$In.'  </strong></td>
            <td  style="border:1px solid black"><strong>50</strong></td>
         </tr>
         <tr>
            <td  style="border:1px solid black"> KISWAHILI </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$Ki.'  </strong></td>
            <td  style="border:1px solid black"><strong>100</strong></td>
         </tr>
          <tr>
            <td  style="border:1px solid black"> MATHS</td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$Ma.'  </strong></td>
            <td  style="border:1px solid black"><strong>100</strong></td>
         </tr>
          <tr>
            <td  style="border:1px solid black"> SCIENCE </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"> <strong>'.$Sc.'  </strong></td>
            <td  style="border:1px solid black"><strong>100</strong></td>
         </tr>
         <tr>
            <td  style="border:1px solid black"> SOCIAL STUDIES </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"><strong> '.$Ss.' </strong></td>
            <td  style="border:1px solid black"><strong>60</strong></td>
         </tr>
         
         <tr>
            <td  style="border:1px solid black"> CRE </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"><strong> '.$Cr.' </strong></td>
            <td  style="border:1px solid black"><strong>30</strong></td>
         </tr>
         
         <tr>
            <td  style="border:1px solid black"> SS/CRE </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"><strong> '.$SCr.' </strong></td>
            <td  style="border:1px solid black"><strong>100</strong></td>
         </tr>
         <tr>
            <td colspan="4"> <hr /> </td>
         </tr>
         <tr>
            <td  style="border:1px solid black"> TOTAL MARKS </td>
            <td  style="border:1px solid black"><strong></strong></td>
            <td  style="border:1px solid black"><strong style="color:green"> '.$To.' </strong></td>
            <td  style="border:1px solid black"><strong>500</strong></td>
         </tr>
        <tr>
         <td colspan="4"><hr /></td>
        </tr>
         <tr style="background-color:gray;color:#FFF">
            <td> POSITION IN CLASS </td>
            <td colspan="3"><strong> /'.$allpupils.'</strong></td>
         </tr>
        </tbody>
         <hr />
        <tfoot>
     
        <tr>
        <td colspan="4">
            <hr />
        </td>
        </tr>
       
        </tfoot>
     </table>
</div>

<p>Class Teacher Remarks : <u><strong>'.$Re.' </strong></u>         </p>
<br /> <br />
<p>SIGN .......................................................................                </p>
            
      </div>
      </section>
     </div>

  <script src="assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
  <script src="assets/vendor/quill/quill.min.js"></script>
  <script src="assets/vendor/simple-datatables/simple-datatables.js"></script>
  <script src="assets/vendor/tinymce/tinymce.min.js"></script>
  <script src="assets/vendor/php-email-form/validate.js"></script>
  <!-- Template Main JS File -->
  <script src="assets/js/main.js"></script>
  <script src="assets/js/jQuery-2.1.4.min.js"></script>
</body>
</html>'; 
$name=$nam.'.php';
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$options = $dompdf->getOptions(); 
$options->set(array('isRemoteEnabled' => true));
$dompdf->setOptions($options);
$dompdf->setPaper('A4', 'portrait');
$dompdf->render();
$dompdf->stream($name,['Attachment' => 0]);