<?php
	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');
    $exa=$_POST['exa'];
    $grd=$_POST['grd'];

    $sql = "SELECT * FROM pupils where Claz='$grd' AND Status='Active'";
	$result = $con->query($sql);
	if ($result->num_rows > 0) 
	{
	$sql2 = "SELECT * FROM CBC1 where Grad='$grd' AND EID='$exa'";
	$result = $con->query($sql2);
	if ($result->num_rows > 0) 
	{
	 ?>
	 <table class="table table-bordered" id="tablecbc" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr>
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>CRE</th>
             <th>Creative Arts</th>
             <th>Environmental Activities</th>
             <th colspan="2" class="bg-secondary">Overall Performance</th>
         </tr>
     </thead>
     <tbody id="" style="font-size:11px;font-family:Arial">
	 <?php
	$sql = "SELECT CBC1.*, pupils.Names as nm, pupils.AdmNo as adm from CBC1 left join pupils ON CBC1.PID=pupils.count where CBC1.EID='$exa' AND Grad='$grd'";
	$result = $con->query($sql);
	    $cnt=1;
		while($row = $result->fetch_assoc()) 
		{
    ?>	
		<tr>
			<td><?php echo $cnt; ?></td>
			<td><?php  echo $row['nm'].' ('.$row['adm'].')'; ?></td>
			<td><input type="text" class="sc scematt" value="<?php echo $row['Math']; ?>" onkeypress="return /[0-9]/i.test(event.key)" /> |
		    	<select id="gr" style="font-size:12px"  class="ruma" required >
		    	<option selected value="<?php echo $row['Ruma']; ?>"><?php echo $row['Ruma']; ?></option>
                <option value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
			</td>
			<td><input type="text" class="sc scengg" value="<?php echo $row['Eng']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /> | 	
			   <select id="gr" style="font-size:12px"  class="ruen" required >
			     <option selected value="<?php echo $row['Ruen']; ?>"><?php echo $row['Ruen']; ?></option>
                <option  value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select></td>
			<td><input type="text" class="sc sckiss" value="<?php echo $row['Kis']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /> | 
		  	<select id="" style="font-size:12px"  class="ruks" required >
                <option  selected value="<?php echo $row['Ruks']; ?>"><?php echo $row['Ruks']; ?></option>
                <option value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select></td>
		
		  	<td><input type="text" class="sc cree"  value="<?php echo $row['CRE']; ?>"  onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="cre" required >
			    <option selected value="<?php echo $row['CRE1']; ?>"><?php echo $row['CRE1']; ?></option>
                <option  value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
            
            
            <td><input type="text" class="sc CRAA" value="<?php echo $row['CrA']; ?>" onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="CRA" required >
			    <option selected value="<?php echo $row['CA1']; ?>"><?php echo $row['CA1']; ?></option>
                <option value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
            
            <td><input type="text" class="sc EVAA"  value="<?php echo $row['EA']; ?>" onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="EVA" required >
			     <option selected value="<?php echo $row['EA1']; ?>"><?php echo $row['EA1']; ?></option>
                <option  value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
            
            <td class="bg-secondary"><input type="text" class="sc tmks"  value="<?php echo $row['TRub']; ?>" onkeypress="return /[0-9]/i.test(event.key)" />
           </td>
           <td class="bg-secondary">
           <select id="" style="font-size:12px"  class="trbu" required >
            <option selected value="<?php echo $row['TRub2']; ?>"><?php echo $row['TRub2']; ?></option>
            <option value="">---</option>
            <option value="EE">EE</option>
            <option value="ME">ME</option>
            <option value="AE">AE</option>
            <option value="BE">BE</option>
           </select>
           
           <input type="hidden" class="exadataid"  value="<?php echo $row['mid']; ?>" />
           </td> 
			<!--td><input type="hidden" class="pupilidholder"  value="<?php echo $row['PID']; ?>" />
			    
			     <i class="fa fa-save btn text-info cbcsave" title="click to save marks"></i>
			 </td-->
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
	<tr>
	    <td colspan="10">
       
	    </td>
	</tr>
	</tbody>
 </table>
 
 <?php
	}else
	{
	  ?>
 <table class="table" id="tablecbc" style="font-size:12px;font-family:Tahoma">
     <thead>
         <tr>
             <th>#</th>
             <th>Pupil's Details</th>
             <th>Maths</th>
             <th>Eng</th>
             <th>Kisw</th>
             <th>CRE</th>
             <th>Creative Arts</th>
             <th>Environmental Activities</th>
             <th colspan="2" class="bg-secondary">Overall Performance</th>
             <!--th>Action</th-->
         </tr>
     </thead>
     <tbody id="" style="font-size:11px;font-family:Arial">
	  <?php
	     $sql = "SELECT * FROM pupils where Claz='$grd' AND Status='Active'";
	$result = $con->query($sql);
	    $cnt=1;
		while($row = $result->fetch_assoc()) 
		{
    ?>	
		<tr>
			<td><?php echo $cnt; ?></td>
			<td><?php  echo $row['Names'].' ('.$row['AdmNo'].')'; ?></td>
			<td><input type="text" class="sc scematt" onkeypress="return /[0-9]/i.test(event.key)" /> |
			   <select id="gr" style="font-size:12px"  class="ruma" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select></td>
			<td><input type="text" class="sc scengg"  onkeypress="return /[0-9]/i.test(event.key)" />| 
			  <select id="gr" style="font-size:12px"  class="ruen" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select></td>
			<td><input type="text" class="sc sckiss"  onkeypress="return /[0-9]/i.test(event.key)" />| 
			  <select id="gr" style="font-size:12px"  class="ruks" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select></td>
               
			<td><input type="text" class="sc cree"  onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="cre" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
            
            
            <td><input type="text" class="sc CRAA"  onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="CRA" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
            
            <td><input type="text" class="sc EVAA"  onkeypress="return /[0-9]/i.test(event.key)" /> |
			<select id="gr" style="font-size:12px"  class="EVA" required >
                <option  selected value="">Rub---</option>
                <option value="EE">EE</option>
                <option value="ME">ME</option>
                <option value="AE">AE</option>
                <option value="BE">BE</option>
               </select>
            </td>
			
			    
		   <td class="bg-secondary"><input type="text" class="sc tmks"  onkeypress="return /[0-9]/i.test(event.key)" />
           </td>
           <td class="bg-secondary">
           <select id="" style="font-size:12px"  class="trbu" required >
            <option selected value=""></option>
            <option value="">---</option>
            <option value="EE">EE</option>
            <option value="ME">ME</option>
            <option value="AE">AE</option>
            <option value="BE">BE</option>
           </select>
           
           <input type="hidden" class="pupilidholder"  value="<?php echo $row['count']; ?>" />
           </td> 
           <!--td>
			    
			    <i class="fa fa-save btn text-info cbcsave" title="click to save marks">
			        
			    </i>
			</td-->
		</tr>
    <?php
    $cnt=$cnt+1;
	}
	?>
   <tr>
	    <td colspan="10">
        <button class="btn btn-info btn-sm pull-right" id="savealll"><i class="fa fa-save"></i> Submit</button>
	    </td>
	</tr>
	 </tbody>
 </table>
	<?php
	}

	}
	else {
		echo "0 results";
	}
		
	mysqli_close($con);

?>