<?php include ("kfunctions.php");
//role("dos,hmp");
?>
<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">
<div class="col-lg-2">
<form method='get'>
<select class='form-control' name='xc' onchange='this.form.submit()'>
<option value=''>Class</option>
<?php
include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where item<25 and type='secclas'");
$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());
}else{
    echo "<option value=''>Please contact your IT department.</option>";}

?>
</select>
</form>
</div>
<div class='col-lg-12'><br></div>
<?php 
echo "
<div class='col-lg-12'>
<div class='panel panel-primary'><!--Initiative-->
<div class='panel-heading'><h3 class='panel-title'>O-level classes</h3></div>
<div class='panel-body'>";
if(isset($_POST["submit_classes"])){
include("connect.php");  

$schoolclass=$_GET["xc"];
$schoolyear="18";
$term="2";
$result_scrap=$dbh->prepare("select * from scrap where type='secsub' or type='prisubps'");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
   do{
if(isset($_POST["sub".$row_scrap->item])){$value_out="0";}else{$value_out="N";}

$rolenumber=$_SESSION["rolenumber"];
$sub_out=$row_scrap->item."marks";
$update_citadel=$dbh->prepare("update citadel_o set $sub_out='$value_out', lastedittedby='$rolenumber' where $sub_out='N' and schoolclass='$schoolclass'");
$update_citadel->execute();

$update_kings=$dbh->prepare("update kingslanding_o set $sub_out='$value_out' where $sub_out='N' and schoolclass='$schoolclass'");
$update_kings->execute();
   }while($row_scrap=$result_scrap->fetchObject());
}    
}

if(isset($_GET["xc"])){
include("connect.php");  

$schoolclass=$_GET["xc"];
$result_scrap=$dbh->prepare("select * from scrap where type='secsub' or type='prisubps'");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();                               

if($count_scrap>0){
echo "<form method='post'>";

do{
$fsub=$row_scrap->item."marks";

$result_citadel=$dbh->query("select * from citadel_o where $fsub!='N' and schoolclass='$schoolclass'");
$count_citadel=$result_citadel->rowCount();

if($count_citadel>0){$checker="checked";}else{$checker="";}

echo "<div class='col-lg-2'><input type='checkbox' name='sub".$row_scrap->item."' value='".$row_scrap->item."' ".$checker."> ".$row_scrap->item2."</div>";
}while($row_scrap=$result_scrap->fetchObject());
echo "
<div class='col-lg-12'>
<input type='submit' style='float:right;' name='submit_classes' class='btn btn-sm btn-primary' value='Submit'>
</div>
</form";
}else{
  echo "Please contact your IT department.";
}

}else{
    echo "Select the class";
}
echo "
</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>
