<?php include ("kfunctions.php");
//role("overadmin");
?>
<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>
</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">
                    <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">

<div class='panel panel-primary'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>Position query</h3></div>
<div class='panel-body'>

<form method='post'>
<div class='col-lg-3'>
<select class='form-control' name='setname'>
<option value=''>Exam set</option>
<?php
include("connect.php");
$result_exam=$dbh->query("select * from examsets");
$row_exam=$result_exam->fetchObject();
$count_exam=$result_exam->rowCount();

if($count_exam>0){
do{
echo "<option value='".$row_exam->setid."'>".$row_exam->setname."</option>";
}while($row_exam=$result_exam->fetchObject());
}else{
    echo "<option value=''>Please contact your IT department. </option>";
}
?>
</select>
</div>

<div class='col-lg-3'>
<select class='form-control' name='schoolclass'>
<option value=''>Class</option>
<?php
include("connect.php");
$result_scrap=$dbh->query("select * from scrap where type='secclas' or type='priclas'");
$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>

<input type='submit' name='filter' class='btn btn-sm btn-primary' value='Filter'>
</form>
<?php

if(isset($_POST["submit_f"])){
$schoolclass=$_POST["schoolclass"];
$setname=$_POST["setname"];
$result_kingslanding=$dbh->query("select * from kingslanding where schoolclass='$schoolclass' and setid='$setname'");
$row_kingslanding=$result_kingslanding->fetchObject();
$count_kingslanding=$result_kingslanding->rowCount();
if($count_kingslanding>0){
    do{

$finaltotal=$_POST["finaltotal".$row_kingslanding->autoid.""];
$cid=$_POST["finalcid".$row_kingslanding->autoid.""];
$update_kingslanding=$dbh->query("update kingslanding set totalmarks='$finaltotal' where cid='$cid'");
    }while($row_kingslanding=$result_kingslanding->fetchObject());
}
}

if(isset($_POST["filter"])){
$schoolclass=$_POST["schoolclass"];
$setname=$_POST["setname"];

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



echo "
<table class='table table-bordered table-hover table-striped sortable'>
<tr>
<th>No</th>
<th>Names</th>
<th>Total marks</th>
<tr>";
if($count_kingslanding>0){
    $x=1;
    echo "<form method='post'>
<input type='submit' style='float:right;' class='btn btn-sm btn-warning' name='submit_f' value='Submit'>
<input type='hidden' name='schoolclass' value='".$schoolclass."'>
<input type='hidden' name='setname' value='".$setname."'>"; 

    do{
$total = $row_kingslanding->sub44marks + $row_kingslanding->sub45marks + $row_kingslanding->sub46marks + $row_kingslanding->sub47marks + $row_kingslanding->sub48marks + $row_kingslanding->sub49marks + $row_kingslanding->sub50marks + $row_kingslanding->sub51marks + $row_kingslanding->sub52marks + $row_kingslanding->sub53marks + $row_kingslanding->sub54marks + $row_kingslanding->sub55marks + $row_kingslanding->sub56marks + $row_kingslanding->sub57marks + $row_kingslanding->sub58marks + $row_kingslanding->sub59marks + $row_kingslanding->sub60marks + $row_kingslanding->sub61marks + $row_kingslanding->sub62marks + $row_kingslanding->sub63marks + $row_kingslanding->sub64marks + $row_kingslanding->sub65marks + $row_kingslanding->sub66marks + $row_kingslanding->sub67marks + $row_kingslanding->sub68marks + $row_kingslanding->sub69marks + $row_kingslanding->sub70marks + $row_kingslanding->sub71marks + $row_kingslanding->sub72marks + $row_kingslanding->sub73marks + $row_kingslanding->sub74marks + $row_kingslanding->sub75marks + $row_kingslanding->sub76marks + $row_kingslanding->sub77marks + $row_kingslanding->sub78marks + $row_kingslanding->sub79marks + $row_kingslanding->sub80marks + $row_kingslanding->sub81marks + $row_kingslanding->sub82marks + $row_kingslanding->sub83marks + $row_kingslanding->sub84marks + $row_kingslanding->sub85marks + $row_kingslanding->sub86marks + $row_kingslanding->sub87marks + $row_kingslanding->sub88marks + $row_kingslanding->sub89marks + $row_kingslanding->sub90marks;

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

echo "
<tr>
<td>".$x++."</td>
<td>".$row_child->fname." ".$row_child->sname."</td>
<td>
".$total."
<input type='hidden' name='finaltotal".$row_kingslanding->autoid."' value='".$total."'>
<input type='hidden' name='finalcid".$row_kingslanding->autoid."' value='".$row_kingslanding->cid."'>
</td>

</tr>";


}while($row_kingslanding=$result_kingslanding->fetchObject()); 
echo "</form>";
}else{
echo "
<tr>
<td>There is NO data in this table so far. </td>
</tr>";
} 
echo "</table>";
}
?>
</div></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>
