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

</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='schoolclass' required>

<option value="">Class</option>

<?php

include("connect.php");

$role=$_SESSION["role"];

if($role=="dosp"){$class_out="type='priclas'";}

elseif($role=="doss"){$class_out="type='secclas'";}

else{header("location:../logout.php");}

$result_scrap = $dbh->query("select * from scrap where $class_out and item<=10 ");

$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='schoolyear' required>

<option value=''>Year</option>

  <?php

include("connect.php");

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

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

<option value=''>Term</option>

   <?php

include("connect.php");

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

$row_scrap = $result_scrap->fetchObject();

$count_scrap = $result_scrap->rowCount();

if($count_scrap>0){

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

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

</div>

</form>

<?php

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

$schoolclass=$_POST["schoolclass"];

$schoolyear=$_POST["schoolyear"];

$schoolterm="t".$_POST["schoolterm"];

$schoolt=$_POST["schoolterm"];



include("connect.php");

$result_t=$dbh->query("select * from $schoolterm where schoolyear='$schoolyear' and schoolclass='$schoolclass' and active='1'");

$row_t=$result_t->fetchObject();

$count_t=$result_t->rowCount();



if($count_t){

    do{



if(isset($_POST["checkcid".$row_t->autoid.""])){

$cid=$_POST["cid".$row_t->autoid.""];

$stream=$_POST["stream".$row_t->autoid.""];



$result_c=$dbh->query("select * from citadel_p where schoolyear='$schoolyear' and schoolclass='$schoolclass' and term='$schoolt' and cid='$cid' and stream='$stream'");

$count_c=$result_c->rowCount();



if($count_c<=0){

$update_citadelp=$dbh->query("insert into citadel_p (schoolyear,schoolclass,term,cid,stream) values('$schoolyear','$schoolclass','$schoolt','$cid','$stream')");}



}



}while($row_t=$result_t->fetchObject());

}



echo "

<div class='col-lg-12'><br></div>

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

<div class='alert alert-success'>Success: Childrens have been submitted. Click to <a href='studentlistp.php'>Edit students' subjects</a></div>

</div>";

}

?>

<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'>Active students in the selected term </h3></div>

<div class='panel-body'>



<form method='post'>

<div class='col-lg-11'><i><b>Note : </b>Checked students are ready for subject entry. </i></div> 

<div class='col-lg-1'><input type='submit' class='btn btn-sm btn-primary' name='submit_std' value='Submit'></div>



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

<tr>

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

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

    <th width='15%'>Stream</th>

    <th>Subjects</th>

</tr>

<?php

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



echo "<input type='checkbox' id='checkallz' onclick='checkall()'> &nbsp; <i><b>Select all</b></i>";



$schoolclass=$_POST["schoolclass"];

$schoolyear=$_POST["schoolyear"];

$schoolt=$_POST["schoolterm"];

$schoolterm="t".$_POST["schoolterm"];



echo "

<input type='hidden' name='schoolclass' value='".$schoolclass."'>

<input type='hidden' name='schoolyear' value='".$schoolyear."'>

<input type='hidden' name='schoolterm' value='".$schoolt."'>";

include("connect.php");

$result_t=$dbh->query("select * from $schoolterm where schoolyear='$schoolyear' and schoolclass='$schoolclass' and active='1'");

$row_t=$result_t->fetchObject();

$count_t=$result_t->rowCount();



if($count_t){

$x=1;

    do{

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

$row_children=$result_children->fetchObject();

$count_children=$result_children->rowCount();



echo "

<tr>

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

<td>";



$result_citadel=$dbh->query("select * from citadel_p where cid='$row_t->cid'");

$count_citadel=$result_citadel->rowCount();



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



echo "

<input type='hidden' name='cid".$row_t->autoid."' value='".$row_t->cid."'>

<input type='checkbox' name='checkcid".$row_t->autoid."' id='cidcheck".$row_t->autoid."' value='1' ".$checkstatus."> &nbsp;&nbsp;&nbsp;&nbsp;".$row_t->cid." - ".$row_children->fname." ".$row_children->sname;

echo "

</td>

<td>

<select class='form-control' name='stream".$row_t->autoid."'>";



$result_citadelp=$dbh->query("select * from citadel_p where cid='$row_t->cid'");

$row_citadelp=$result_citadelp->fetchObject();

$count_citadelp=$result_citadelp->rowCount();



if($count_citadelp>0 && $row_citadelp->stream!=""){echo "<option value='".$row_citadelp->stream."'>".$row_citadelp->stream."</option>";}

else{echo "<option value=''>Stream</option>";}



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

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

echo "

</select>

</td>

<td>";



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

$count_child=$result_child->rowCount();



if($count_child>0){echo "subjects missing";}

echo "

</td>

</tr>"; 

}while($row_t=$result_t->fetchObject());

}else{

echo "<tr>

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

</tr>";} 



}else{

echo "<tr>

<td align='center' colspan='4'><b><i>Select the above filter. </i></b></td>

</tr>";

} 

?>

</table>

</form>

</div></div>



</div>



</div>



</form>



                            </div> 



                <!-- /.row -->



               



            </div>

            <!-- /.container-fluid -->



        </div>

        <!-- /#page-wrapper -->



    </div>

    <!-- /#wrapper -->

<script>

function checkall(){

<?php

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

$schoolclass=$_POST["schoolclass"];

$schoolyear=$_POST["schoolyear"];

$schoolterm="t".$_POST["schoolterm"];



$result_t=$dbh->query("select * from $schoolterm where schoolyear='$schoolyear' and schoolclass='$schoolclass' and active='1'");

$row_t=$result_t->fetchObject();

$count_t=$result_t->rowCount();



if($count_t>0){

    do{

?>

if(document.getElementById('checkallz').checked){

document.getElementById('cidcheck<?php echo $row_t->autoid; ?>').checked=true;

}else{

document.getElementById('cidcheck<?php echo $row_t->autoid; ?>').checked=false; 

}



<?php

}while($row_t=$result_t->fetchObject());

}

}

?>

}

</script>

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

