<?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">
                    <form method='post'>
<div class='col-lg-2'>
<input type='text' list="cid" name="cid" class='form-control' placeholder="Student ID">

</div>

<div class='col-lg-2'>
<select class="form-control" name="schoolclass" required>
<option value="">All classes</option>
<?php
$role=$_SESSION["role"];
if($role=="doss"){$type_out="type='secclas'";}
elseif($role=="dosp"){$type_out="type='priclas'";}

$result_scrap=$dbh->query("select * from scrap where $type_out and item<25 ");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap){
    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='class_stream' required>
<option value=''>All Streams</option>
<?php
include("connect.php");
$result_scrap=$dbh->query("select * from scrap where type='ostream'");
$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=''>So far, there is NO data here. </option>";
}
?>
</select>
</div>



<div class='col-lg-2'>
<input type='submit' name='changeclass' class='btn btn-sm btn-primary' value='Change Class'>

</div>
<?php
$result_scrap=$dbh->query("select * from scrap where type='secclas'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
do{
    echo "
<input type='hidden' name='cla".$row_scrap->item."' id='cla".$row_scrap->item."'>";
}while($row_scrap=$result_scrap->fetchObject());
}
?>



</div>
<?php

if(isset($_POST["changeclass"])){
$cid=$_POST["cid"];
$schoolclass=$_POST["schoolclass"];
$class_stream=$_POST["class_stream"];


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

if($count_kingslanding>0){
$update_class=$dbh->query("update kingslanding_o set schoolclass='$schoolclass', stream='$class_stream' where cid='$cid' ");
//kkk   and setid='$setid' this would be a good idea to set

$update_citadel=$dbh->query("update citadel_o set schoolclass='$schoolclass', stream='$class_stream' where cid='$cid'");
echo "Success! Class Changed";
}

else

{

    echo "Student does not exist";
}


}

?>

</div>

</form>

                            </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>
