<?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';
 
    $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); 
    }
   
  //CBC
$RM='';
$RE='';
$RK='';
$RI='';  
$RC='';
$RMP='';
$REP='';
$RKP='';
$RIP='';  
$RCP='';

$ex=$_SESSION['eexam'];
$pid=$_SESSION['ppupil'];

$query=mysqli_query($con,"select CBC1.*,pupils.Names as nm from CBC1 left join pupils ON pupils.count=CBC1.PID where CBC1.EID='$ex' AND CBC1.PID='$pid'");
$cnt=1;
$pos=1;
$lastscore='';
while($row=mysqli_fetch_array($query))
{
$ma=$row["Math"]; 
$eng=$row["Eng"]; 
$kis=$row["Kis"]; 
$in=$row["ILA"]; 
$cre=$row["CRE"]; 
$cra=$row["CrA"]; 
$ea=$row["EA"];
$trubb=$row["TRub"];
$tmks=$row["TMks"];

$ma2=$row["Ruma"]; 
$eng2=$row["Ruen"]; 
$kis2=$row["Ruks"]; 
$cre2=$row["CRE1"]; 
$cra2=$row["CA1"]; 
$ea2=$row["EA1"];

$ma1=$row["MP"];
$eng1=$row["EP"];
$kis1=$row["KP"];
$cre1=$row["CREP"];
$cra1=$row["CAP"];
$ea1=$row["EAP"];

$ca=$row["TMks"];
$trub=$row["TRub"];
$ttp=$row["TTP"];
}

$que=mysqli_query($con,"select * from examsetting where Grad='$claz' AND examid='$ex'");
while($row=mysqli_fetch_array($que))
{
$maa=addslashes($row['MA']);
$enn=addslashes($row['EN']);
$kss=addslashes($row['KS']);
$crE=addslashes($row['CRE']);
$caa=addslashes($row['CA']);
$eaa=addslashes($row['EA']);
}

  $m2= (int)$maa;
  $en2=(int)$enn;
  $ks2=(int)$kss;
  $cre22=(int)$crE;
  $ca2=(int)$caa;
  $ea22=(int)$eaa;
  
 $tot2= $m2+$en2+$ks2+$cre22+$ca2+$ea22;
 
  $query=mysqli_query($con,"select * FROM companydata");
   while($row=mysqli_fetch_array($query))
   {
   $com_name=$row["School"];
   $tag=$row["Tag"];
   $em=$row["Email"];
   }
  
 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" >. </h6> </center>
     <center> <h3 style="margin-top:-20px" class="text-red" >'.$com_name.' </h3> </center>
     <center> <h4 style="margin-top:-20px" class="text-red" >'.$tag.'</h4> </center>
  
<img style="position:absolute;margin-top:-80px;margin-bottom:10px;max-height:90px" src="https://sch.cwmk.co.ke/images/schicon.jpg" alt="" class="" />
<br />
   <label style="margin-top:-20px" class="text-red" ><strong>Telephone:</strong> 0700 221 331 </label>
   <br />
  <label style="margin-top:-20px" class="text-red" ><strong>Email:</strong>'.$em.'</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:15px">
       <thead>
        <tr style="background-color:#000;color:#FFF">
         <th>SUBJECT </th> <th>PERFORMANCE <br  /> </th> <th>RUBRICS</th> <th>POINTS</th>
        </tr>
       </thead>
        <tbody>
         <tr style="border:1px solid black">
            <td  style="border:1px solid black">MATH </td>
            <td  style="border:1px solid black"><strong>'.$ma.'<span style="color:green"> out of </span>'.$maa.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$ma2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$ma1.'</strong></td>
         </tr> 
        <tr style="border:1px solid black">
            <td  style="border:1px solid black"> ENGLISH </td>
            <td  style="border:1px solid black"> <strong>'.$eng.'<span style="color:green"> out of </span>'.$enn.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$eng2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$eng1.'</strong></td>
        </tr>

         <tr>
            <td  style="border:1px solid black"> KISWAHILI </td>
            <td  style="border:1px solid black"> <strong>'.$kis.'<span style="color:green"> out of </span>'.$kss.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$kis2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$kis1.'</strong></td>
         </tr>
          <tr>
            <td  style="border:1px solid black"> CRE</td>
            <td  style="border:1px solid black"> <strong>'.$cre.'<span style="color:green"> out of </span>'.$crE.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$cre2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$cre1.'</strong></td>
         </tr>
         
          <tr>
            <td  style="border:1px solid black"> CREATIVE ARTS</td>
            <td  style="border:1px solid black"> <strong>'.$cra.'<span style="color:green"> out of </span>'.$caa.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$cra2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$cra1.'</strong></td>
         </tr>
         
          <tr>
            <td  style="border:1px solid black"> ENVIRONMENTAL ACTIVITIES</td>
            <td  style="border:1px solid black"> <strong>'.$ea.'<span style="color:green"> out of </span>'.$eaa.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$ea2.'</strong></td>
            <td  style="border:1px solid black"><strong>'.$ea1.'</strong></td>
         </tr>
         <tr>
         <td colspan="4">
            <hr />
        </td>
        </tr>
         <tr>
            <td  style="border:1px solid black" colspan=""> OVERALL PERFORMANCE </td>
            <td  style="border:1px solid black"><strong style="color:green"> '.$tmks.'/'.$tot2.'</strong></td>
            <td  style="border:1px solid black"><strong style="color:green"> '.$trubb.' </strong></td>
            <td  style="border:1px solid black"><strong style="color:green">'.$ttp.'</strong></td>
         </tr>
        <tr>
         <td colspan="4"><hr /></td>
        </tr>
        </tbody>
         <hr />
     </table>
</div>

<p>Class Teacher Remarks :</p> 
<p>.............................................................................................................................................................................</p>
<p>.............................................................................................................................................................................</p>
<br />
<p>SIGN .......................................................................                </p>

<h5><u>ASSESSMENT RUBRIC</u></h5>

<table style="font-size:11px;border:1px solid #000">

<tr>
 <th>Level </th>
 <th>Raw Marks</th>
 <th>Points </th>
</tr>

<tr>
 <td colspan="1"> EE 1 </td>
 <td><strong> 90 - 99 </strong></td>
 <td><strong> 4.0 </strong></td>
</tr>

<tr>
 <td style="border-bottom:1px solid #000" colspan="1"> EE 2 </td>
 <td style="border-bottom:1px solid #000"><strong> 80 - 89 </strong></td>
 <td style="border-bottom:1px solid #000"><strong>3.5 </strong></td>
</tr>

<tr>
  <td> ME 1  </td>
 <td><strong> 65 - 79 </strong></td>
 <td><strong>3.0 </strong></td>
</tr>

<tr>
 <td style="border-bottom:1px solid #000"> ME 2 </td>
 <td style="border-bottom:1px solid #000"><strong> 50 - 64 </strong></td>
 <td style="border-bottom:1px solid #000"><strong>2.5</strong></td>
</tr>


<tr>
 <td> AE 1 </td>
 <td><strong> 40 - 49 </strong></td>
 <td><strong>2.0</strong></td>
</tr>

<tr>
 <td style="border-bottom:1px solid #000"> AE 2 </td>
 <td style="border-bottom:1px solid #000"><strong> 30 - 39 </strong></td>
 <td style="border-bottom:1px solid #000"><strong>1.5</strong></td>
</tr>

<tr>
 <td> BE 1 </td>
 <td><strong> 20 - 29 </strong></td>
 <td><strong>1.0</strong></td>
</tr>

<tr>
 <td> BE 2 </td>
 <td><strong> 0 - 20 </strong></td>
 <td><strong>0.5</strong></td>
</tr>

</table>

      </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]);