<?php include ("../core/kfunctions.php");

//role("dos,hmp");

?>

<html>

<head>

<?php kheader(); ?>

<?php 

require_once("../core/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="schoolyear" required>

<option value="<?php echo date("y"); ?>"><?php echo date("Y"); ?></option>

<?php

$result_scrap=$dbh->query("select * from scrap where  type='ya'");

$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="schoolterm" required>

<?php

$cm=date("m");

if($cm>='1' and $cm<='4'){$oterm="Term 1"; $iterm="1";}

elseif($cm>='5' and $cm<='8'){$oterm="Term 2"; $iterm="2";}

elseif($cm>='9' and $cm<='12'){$oterm="Term 3"; $iterm="3";}

echo "

<option value='".$iterm."'>".$oterm."</option>";



$result_scrap=$dbh->query("select * from scrap where  type='ts'");

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap){

    do{

echo "<option value='".$row_scrap->item."'>Term ".$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="schoolclass">

<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-4'>

<input type='text' class='form-control' list='std' name='stdname' placeholder='Student name'>

<datalist id='std'>

<?php

include("../core/connect.php");

$result_child=$dbh->query("select cid,fname,sname from children");

$row_child=$result_child->fetchObject();

$count_child=$result_child->rowCount();



if($count_child>0){

    do{

echo "<option value='".$row_child->cid." - ".$row_child->fname." ".$row_child->sname."'>";

    }while($row_child=$result_child->fetchObject());

}

?>

</datalist>

</div>

<div class='col-lg-2'>

<input type='submit' name='filter_std' class='btn btn-sm btn-primary' value='Filter'>

<input type="button" value="Print table" style="float:right;" class="btn btn-sm btn-info" onclick="PrintDiv('myDiv')" />

</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 class='col-lg-12'><br></div>

<div class="col-lg-12">

<div class='panel panel-primary'><!--Initiative-->

<div class='panel-heading'><h3 class='panel-title'>O-level Student list </h3></div>

<div class='panel-body'>

<div id='myDiv'>

<table class='table table-bordered table-hover table-striped sortable'>

<tr>

    <th width='2%'>No</th>

    <th width='30%'>Student name</th>

    <th width='30%'>Student count</th>

 </tr>

<?php

if(isset($_POST["filter_std"])){

$stdname=$_POST["stdname"];

$schoolclass=$_POST["schoolclass"];    

$schoolterm=$_POST["schoolterm"];

$schoolyear=$_POST["schoolyear"];



if($stdname!=""){

$fstdname=substr($stdname,0,5);

$std_in="and cid='$fstdname'";

}else{

$std_in="and schoolclass='$schoolclass'";

}



include("../core/connect.php");

$result_citadel=$dbh->query("select * from citadel_o where schoolyear='$schoolyear' and term='$schoolterm' $std_in and active='1'");

$row_citadel=$result_citadel->fetchObject();

$count_citadel=$result_citadel->rowCount();



if($count_citadel>0){

$x=1;

    do{

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

$row_child=$result_child->fetchObject();

$count_child=$result_child->rowCount();



$result_citadelc=$dbh->query("select * from citadel_o where cid='$row_citadel->cid'");

$count_citadelc=$result_citadelc->rowCount();



echo "

<tr>

<td>".$x++."</td>

<td title='Click to edit student subjects'><a href='subjectlist_o.php?cid=".$row_citadel->cid."'>".$row_child->cid." - ".$row_child->fname." ".$row_child->sname."</a></td>

<td>".$count_citadelc."</td>

</tr>";

}while($row_citadel=$result_citadel->fetchObject());

}else{

echo "<tr>

<td align='center' colspan='3'><b><i>There is NO match. </i></b></td>

</tr>"; }   

}else{

echo "

<tr>    

<td colspan='3' align='center'><b><i>Select the filters above</i></b></td>

</tr>"; }

?>

</table>

</div>

</div></div>



</div>



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

