<?php include ("kfunctions.php"); ?>
<html>
<head>
<?php kheader(); ?>
<?php 
require_once("connect.php");

?>
<link href="css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">
<script src="js/sorttable.js"></script>
<script src="js/printreport.js"></script>
</head>
<body>


    <div id="wrapper">

        <!-- Navigation -->
        <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
            <!-- Brand and toggle get grouped for better mobile display -->
            <?php ktopbar(); ?>
            <!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
            <?php kleftbar(); ?>
            <!-- /.navbar-collapse -->
        </nav>

        <div id="page-wrapper">

            <div class="container-fluid">

 <!-- Page Heading -->
                

<div class="row">
<form method='post'>
<div class='col-lg-2'>
<select class='form-control' name='schoolclass' required>
<option value="">Class</option>
<?php
include("connect.php");
$result_scrap = $dbh->query("select * from scrap where (item>=21 && item<25) and type='secclas'");
$row_scrap = $result_scrap->fetchObject();
$count_scrap = $result_scrap->rowCount();
if($count_scrap>0){
do{
echo "<option value='".$row_scrap->item."'>".$row_scrap->item2."</option>";
}while($row_scrap = $result_scrap->fetchObject());
}else{
echo "<option value=''>Please contact your IT department. </option>";
}
?>
</select>
</div>
<div class='col-lg-2'>
<select class='form-control' name='stream' required>
<option value=''>Stream</option>
<?php 
include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where type='ostream' ");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
do{
echo "<option value='".$row_scrap->item."'>".$row_scrap->item2."</option>";
}while($row_scrap=$result_scrap->fetchObject());
echo "<option value='allstreams'>All streams</option>";
}else{
    echo "<option value=''>Please contact your IT department. </option>";
}
?>
</select>
</div>
<div class='col-lg-2'>
<select class='form-control' name='setid' required>
<option value=''>Exam Set</option>
  <?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_setname = $dbh->query("select * from examsets where ouruser like '%$role%'");
$row_setname = $result_setname->fetchObject();
$count_setname = $result_setname->rowCount();
if($count_setname>0){
do{
echo "<option value='".$row_setname->setid."'>".$row_setname->setname."</option>";
}while($row_setname = $result_setname->fetchObject());
}else{
echo "<option value=''>There is no data here so far. </option>";
}
?>
</select>
    </div>
<div class='col-lg-1'>
<input type='submit' name="class_filter" class='btn btn-md btn-primary' value='Filter'>
</div>
<div class='col-lg-1'>
<input type="button" value="Print table" style="float:right;" class="btn btn-sm btn-info" onclick="PrintDiv('mydiv')" />
</div>
</form>

<div class='col-lg-12'><br></div>

<div id='mydiv'>
<div class='col-lg-12'>
<div class='panel panel-yellow'><!--Initiative-->
<?php
include ("connect.php");
if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$stream=$_POST["stream"];


$setid=$_POST["setid"];

$result_kingslanding = $dbh->query("select * from kingslanding_o where setid='$setid' and schoolclass='$schoolclass'");
$row_kingslanding = $result_kingslanding->fetchObject();
$count_kingslanding = $result_kingslanding->rowCount();

if($count_kingslanding>0){

$result_examsets = $dbh->query("select * from examsets where setid='$setid'");
$row_examsets = $result_examsets->fetchObject();

$result_scrapsec = $dbh->query("select * from scrap where item='$schoolclass' and (type='secclas' or type='priclas')");
$row_scrapsec = $result_scrapsec->fetchObject();

include("class.php");
$title_out="Term : <u>".$row_kingslanding->term."</u> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Class : <u>".$row_scrapsec->item2." ".$stream."</u> &nbsp;&nbsp;&nbsp; Exam set: <u>".$row_examsets->setname."</u>";
}else{ $title_out=""; }
}else{ $title_out=""; }

echo "
<div class='panel-heading'><h3 class='panel-title'>Individual Assessment for ".$title_out."</h3></div>
<div class='panel-body'>";

if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];

$result_scrap1=$dbh->query("select * from scrap where item2='title1' and type='reports'");
$row_scrap1=$result_scrap1->fetchObject();
echo "

<center><p><strong>".$row_scrap1->item." <p>INDIVIDUAL ASSESSMENT ".$title_out."</p></strong></center>

<table class='table table-striped sortable' border='2' style='font-size:12px !important;'>
<thead>
<tr>
<th width='1%'>No</th>
<th>Name</th>
<th>Eng</th>
<th>Mat</th>
<th>Phy</th>
<th>Che</th>
<th>Bio</th>
<th>Geo</th>
<th>His</th>
<th>CRE</th>
<th>Comm</th>
<th>ICT</th>
<th>Lug</th>
<th>Lit</th>
<th>Swa</th>
<th>Ent</th>
<th>Art</th>
<th>Agr</th>
<th><b>AGGR</b></th>
<th><b>DIV</b></th>
</tr>
</thead>
<tbody>";

$result_kingslanding = $dbh->query("select * from kingslanding_o where setid='$setid' and schoolclass='$schoolclass' and active='1' order by cid asc");
$row_kingslanding = $result_kingslanding->fetchObject();
$count_kingslanding = $result_kingslanding->rowCount();

if($count_kingslanding>0){
$r=1;
do{


if($stream=="allstreams"){$stream_out=""; $streamchecker='1';}

else{$stream_out="and stream='$stream'";
$result_citadel = $dbh->query("select * from citadel_o where cid='$row_kingslanding->cid' $stream_out");
$row_citadel = $result_citadel->fetchObject();
$count_citadel = $result_citadel->rowCount();
$streamchecker=$count_citadel;}

$result_child = $dbh->query("select * from children where cid='$row_kingslanding->cid'");
$row_child = $result_child->fetchObject();

if ($streamchecker>0){
echo "
<tr>
<td>".$r++."</td>
<td>".$row_kingslanding->cid." - ".ucwords(strtolower($row_child->fname))." ".ucwords(strtolower($row_child->sname))."</td>";

?>


<?php
echo "<font size='10px'>
<td>".$row_kingslanding->sub46grade."</td>
<td>".$row_kingslanding->sub47grade."</td>
<td>".$row_kingslanding->sub48grade."</td>
<td>".$row_kingslanding->sub50grade."</td>
<td>".$row_kingslanding->sub52grade."</td>
<td>".$row_kingslanding->sub53grade."</td>
<td>".$row_kingslanding->sub54grade."</td>
<td>".$row_kingslanding->sub55grade."</td>
<td>".$row_kingslanding->sub58grade."</td>
<td>".$row_kingslanding->sub59grade."</td>
<td>".$row_kingslanding->sub61grade."</td>
<td>".$row_kingslanding->sub63grade."</td>
<td>".$row_kingslanding->sub66grade."</td>
<td>".$row_kingslanding->sub62grade."</td>
<td>".$row_kingslanding->sub49grade."</td>
<td>".$row_kingslanding->sub71grade."</td>
<td>".$row_kingslanding->totalaggr."</td>
<td>".$row_kingslanding->division."</td>
</tr>";

}
?>
<?php
}while($row_kingslanding = $result_kingslanding->fetchObject());
}else{
    echo "
<tr>
<td colspan='6' align='center'>There is NO data in the table so far. </td>
</tr>";
}

echo "
</tbody>
</table>
</font>
";
}else{
    echo "Select from the options above and select filter";
}
?>
</div></div>
</div>
</div>
                </div>
                <!-- /.row -->

               

            </div>
            <!-- /.container-fluid -->
<?php useractivity("on page", "56"); ?>
        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

    <!-- jQuery -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.1/jquery.js"></script>

    <!-- Bootstrap Core JavaScript -->
    <script src="js/bootstrap.min.js"></script>
    <script type="text/javascript" src="js/jquery-1.8.3.min.js" charset="UTF-8"></script>
</body>

</html>
