<?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/print.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='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-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>=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='astream' required>
<option value=''>Stream</option>
<option value='arts'>Arts</option>
<option value='sciences'>Sciences</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>


<?php
include ("connect.php");
if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$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_scrap = $dbh->query("select * from scrap where item='$subjectid'");
//$row_scrap = $result_scrap->fetchObject();

$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");

}
}



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


//for sciences, math or physics or chemistry else its arts

if ($astream=='sciences'){
$streamselector="(sub19_1m!='N' or sub19_2m!='N' or sub16_1m!='N' or sub17_1m!='N')";
}
else{
$streamselector="(sub19_1m='N' and sub19_2m='N' and sub16_1m='N' and sub17_1m='N')";
}

//$result_scrap = $dbh->query("select * from scrap where item='$subjectid'");
//$row_scrap = $result_scrap->fetchObject();


echo "

<div id='myDiv'>

<table class='table table-striped sortable' border='1' style='font-size:12px !important;'>
<thead>
<tr>
<th rowspan='2'>Name</th>
<th rowspan='2'>TPs</th>
<th rowspan='2'>GP</th>
<th rowspan='2'>S/ICT</th>
<th rowspan='2'>S/Math</th>
<th colspan='2'>Econ</th>
<th colspan='3'>Ent</th>
<th colspan='3'>Geography</th>
<th colspan='5'>Fine Art</th>";

if($astream=="arts"){
echo "
<th colspan='4'>History</th>
<th colspan='3'>Luganda</th>
<th colspan='3'>Literature</th>
<th colspan='4'>Divinity</th>";
}elseif($astream=="sciences"){
echo "
<th colspan='3'>Physics</th>
<th colspan='3'>Chemistry</th>
<th colspan='3'>Biology</th>
<th colspan='3'>Math</th>";}

echo "
</tr>
<tr>
<th>1</th><th>2</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th><th>4</th><th>5</th>";

if($astream=="arts"){
echo "
<th>1</th><th>2</th><th>3</th><th>6</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th><th>4</th>";
}elseif($astream=="sciences"){
echo "
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th><th>3</th>
<th>1</th><th>2</th>";}

echo "
</tr>
</thead>
<tbody>";

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

if($count_kingslanding>0){
do{

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

echo "
<tr>";
//echo "<td>".$row_kingslanding->cid." - ".$row_child->fname." ".$row_child->sname."</td>"; 
echo "<td>".ucwords(strtolower($row_child->fname))." ".ucwords(strtolower($row_child->sname))." - ".$row_kingslanding->cid."</td>
<td>".$row_kingslanding->totalpoints."</td>
<td>".$row_kingslanding->sub22_m."</td>
<td>".$row_kingslanding->sub24_m."</td>
<td>".$row_kingslanding->sub23_m."</td>
<td>".$row_kingslanding->sub20_1m."</td>
<td>".$row_kingslanding->sub20_2m."</td>
<td>".$row_kingslanding->sub11_1m."</td>
<td>".$row_kingslanding->sub11_2m."</td>
<td>".$row_kingslanding->sub11_3m."</td>
<td>".$row_kingslanding->sub12_1m."</td>
<td>".$row_kingslanding->sub12_2m."</td>
<td>".$row_kingslanding->sub12_3m."</td>
<td>".$row_kingslanding->sub21_1m."</td>
<td>".$row_kingslanding->sub21_2m."</td>
<td>".$row_kingslanding->sub21_3m."</td>
<td>".$row_kingslanding->sub21_4m."</td>
<td>".$row_kingslanding->sub21_5m."</td>";

if($astream=="arts"){
echo "
<td>".$row_kingslanding->sub10_1m."</td>
<td>".$row_kingslanding->sub10_2m."</td>
<td>".$row_kingslanding->sub10_3m."</td>
<td>".$row_kingslanding->sub10_4m."</td>
<td>".$row_kingslanding->sub15_1m."</td>
<td>".$row_kingslanding->sub15_2m."</td>
<td>".$row_kingslanding->sub15_3m."</td>
<td>".$row_kingslanding->sub13_1m."</td>
<td>".$row_kingslanding->sub13_2m."</td>
<td>".$row_kingslanding->sub13_3m."</td>
<td>".$row_kingslanding->sub14_1m."</td>
<td>".$row_kingslanding->sub14_2m."</td>
<td>".$row_kingslanding->sub14_3m."</td>
<td>".$row_kingslanding->sub14_4m."</td>";
}elseif($astream=="sciences"){
    echo "
<td>".$row_kingslanding->sub16_1m."</td>
<td>".$row_kingslanding->sub16_2m."</td>
<td>".$row_kingslanding->sub16_3m."</td>
<td>".$row_kingslanding->sub17_1m."</td>
<td>".$row_kingslanding->sub17_2m."</td>
<td>".$row_kingslanding->sub17_3m."</td>
<td>".$row_kingslanding->sub18_1m."</td>
<td>".$row_kingslanding->sub18_2m."</td>
<td>".$row_kingslanding->sub18_3m."</td>
<td>".$row_kingslanding->sub19_1m."</td>
<td>".$row_kingslanding->sub19_2m."</td>";}

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

echo "
</tbody>
</table>
</div>";
}else{
    echo "<div class='col-lg-12'><div style='float:right;' class='alert alert-success'>Select from the options above and select filter. Click to <b>'Hide / Show Menu'</b> </div></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>
