<?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');
   
      /*  $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"];
       }

   $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 CBC2.*,pupils.Names as nm from CBC2 left join pupils ON pupils.count=CBC2.PID where CBC2.EID='$ex' AND CBC2.PID='$pid'");
   $cnt=1;
   $pos=1;
   $lastscore='';
   while($row=mysqli_fetch_array($query))
   {
   $ma=$row["Math"]; 
   $eng=$row["Eng"]; 
   $kis=$row["Kis"]; 
   $in=$row["ST"]; 
   $cre=$row["CRE"]; 
   $cra=$row["CA"]; 
   $ss=$row["SS"];
   $an=$row["AN"];
   
   $uma=$row["MA1"]; 
   $ueng=$row["EN1"]; 
   $ukis=$row["KS1"]; 
   $uin=$row["ST1"]; 
   $ucre=$row["CR1"]; 
   $ucra=$row["CA1"]; 
   $uss=$row["SS1"];
   $uan=$row["AN1"];
   
   $mp=$row["MP"]; 
   $ep=$row["EP"]; 
   $kp=$row["KP"]; 
   $stp=$row["STP"]; 
   $crep=$row["CREP"]; 
   $cap=$row["CAP"]; 
   $ssp=$row["SSP"];
   $anp=$row["ANP"];
   
   $grade=$row["Grad"];
   $trubb=$row["TRub"];
   $tmks=$row["TMks"];
   $ttp=$row["TTP"];
   }
   
   $resultt = mysqli_query($con,"SELECT * from examsetting where Grad='$grade' AND examid='$ex'");
   while($row = $resultt->fetch_assoc()) 
   {
   $sma=$row["MA"];
   $seng=$row["EN"]; 
   $skis=$row["KS"]; 
   $sin=$row["ST"]; 
   $scre=$row["CRE"]; 
   $scra=$row["CA"]; 
   $sss=$row["SS"];
   $san=$row["AN"];
   $tt=$row["TT"];
   }
   
   $sma = (int)$sma;
   $skis= (int)$skis;
   $sin= (int)$sin;
   $seng= (int)$seng;
   $scre= (int)$scre;
   $scra= (int)$scra;
   $sss= (int)$sss;
   $san= (int)$san;
   
   $tto=$sma+$seng+$san+$sss+$scra+$scre+$sin+$skis;
    //require_once 'dompdf/vendor/autoload.php';
   // use Dompdf\Dompdf;
   
      $query=mysqli_query($con,"select * FROM companydata");
      while($row=mysqli_fetch_array($query))
      {
      $schname=$row["School"];
      $tag=$row["Tag"];
      $em=$row["Email"];
      }
   ?>
<!DOCTYPE html>
<html lang="en">
   <head>
      <meta charset="utf-8">
      <meta content="width=device-width, initial-scale=1.0" name="viewport">
      <title><?php echo '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">
      <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 #002b80;border-radius:5px;padding:5px;border-style: double;outline-offset: -5px;">
      <div>
         <center>
            <h6 style="margin-top:0px;color:#FFF" class="text-red" >.</h6>
         </center>
         <center>
            <h2 style="margin-top:-20px;color:#001a4d"><?php echo $schname; ?> </h2>
         </center>
         <center>
            <h4 style="margin-top:-20px" class="text-red" > <?php echo $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> 0701 672 870 </label>
         <br />
         <label style="margin-top:-20px" class="text-red" ><strong>Email:</strong> <?php echo $em; ?> </label>
         <label style="position:absolute;margin-left:220px" class="text-red" ><strong>P.O. Box:</strong> 50-10101 Karatina </label>
         <hr />
         <div style="">
            NAME: <strong> <u><?php echo $nam; ?></u></strong> <br /> CLASS:   <strong><u><?php echo $claz; ?></u></strong> <br /> ADM NO:  <strong><u><?php echo $admno; ?></u>  <br /> CLASS TEACHER:  <strong>____________________________________</strong> 
            <center>
               <h4><u>REPORT FORM </u></h4>
            </center>
            <u>
               <h4 style="position:absolute;margin-top:-5px"><strong style="color:red;"><?php echo $tit; ?>  </strong> <strong style="margin-left:50px">Year:  <span><?php echo $year; ?> </span></strong></h4>
            </u>
            <table style="border:1px solid gray;position:relative;margin-top:20px;font-size:12px">
               <thead>
                  <tr style="background-color:#000;color:#FFF">
                     <th>#</th>
                     <th>SUBJECT </th>
                     <th>PERFORMANCE</th>
                     <th>RUBRIC</th>
                     <th>POINTS</th>
                  </tr>
               </thead>
               <tbody>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">1</td>
                     <td  style="border:1px solid gray">MATH </td>
                     <td  style="border:1px solid gray"><strong><?php echo $ma.'<span style="color:green"> out of </span>'.$sma; ?>  </strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $uma; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $mp; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">2</td>
                     <td  style="border:1px solid gray"> ENGLISH </td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $eng.'<span style="color:green"> out of </span>'.$seng; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $ueng; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $ep; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">3</td>
                     <td  style="border:1px solid gray"> KISWAHILI</td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $kis.'<span style="color:green"> out of </span>'.$skis; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $ukis; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $kp; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">4</td>
                     <td  style="border:1px solid gray"> CRE </td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $cre.'<span style="color:green"> out of </span>'.$scre; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $ucre; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $crep; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">5</td>
                     <td  style="border:1px solid gray"> SOCIAL STUDIES</td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $ss.'<span style="color:green"> out of </span>'.$sss; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $uss; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $ssp; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">6</td>
                     <td  style="border:1px solid gray"> SCIENCE & TECHNOLOGY  </td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $in.'<span style="color:green"> out of </span>'.$sin; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $uin; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $stp;  ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">7</td>
                     <td  style="border:1px solid gray"> CREATIVE ARTS</td>
                     <td  style="border:1px solid gray"> <strong> <?php echo $cra.'<span style="color:green"> out of </span>'.$scra; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $ucra; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php  echo $cap; ?></strong></td>
                  </tr>
                  <tr style="border:1px solid gray">
                     <td  style="border:1px solid gray">8</td>
                     <td  style="border:1px solid gray"> AGRICULTURE & NUTRITION </td>
                     <td  style="border:1px solid gray"> <strong>  <?php echo $an.'<span style="color:green"> out of </span>'.$san; ?></strong></td>
                     <td  style="border:1px solid gray"><strong> <?php echo $uan ; ?></strong></td>
                     <td  style="border:1px solid gray"><strong><?php echo $anp; ?></strong></td>
                  </tr>
                  <tr>
                     <td colspan="5">
                        <hr />
                     </td>
                  </tr>
                  <tr>
                     <td  style="border:1px solid gray" colspan="2"> OVERALL PERFORMANCE </td>
                     <td  style="border:1px solid gray"><strong style="color:green"> <?php echo $tmks.' / '.$tto; ?></strong></td>
                     <td  style="border:1px solid gray"><strong style="color:green"><?php echo $trubb; ?></strong></td>
                     <td  style="border:1px solid gray"><strong style="color:green"><?php echo $ttp; ?></strong></td>
                  </tr>
                  <tr>
                     <td colspan="5">
                        <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;">
            <thead>
               <tr>
                  <th>Level </th>
                  <th>Raw Marks</th>
                  <th>Points </th>
               </tr>
            </thead>
            <tbody>
               <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>
            </tbody>
         </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>
';