<?php include ("kfunctions.php"); ?>
<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>
<script src="js/input.js"></script>
<style>
.reptit{
color:#0066cc;
}
</style>
</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">
<form method='post'>
<div class='col-lg-2'>
<select class='form-control' name='examset' onchange='exam(this.value)'>
<option value=''>Exam set</option>
<?php
include("connect.php");
$result_examset=$dbh->query("select * from examsets where setname!=''");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
do{
echo "<option value='".$row_examset->setid."'>".$row_examset->setname."</option>";
}while($row_examset=$result_examset->fetchObject());
}else{
    echo "<option value=''>So far, there is NO data here. </option>";
}
?>
</select>
</div>
<div class='col-lg-2' id='class_out'>
<select class='form-control' name='schoolclass' onchange='std(this.value)'>
<option value=''>Class</option>
<?php
include("connect.php");
$result_scrap=$dbh->query("select * from scrap where 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=''>So far, there is NO data here. </option>";
}
?>
</select>
</div>
<div class='col-lg-3' id='std_out'>
<input type='text' list="stdname" name="stdname" class='form-control' placeholder="Student Name or ID">
<datalist id='stdname'>
<?php
include("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' class='btn btn-sm btn-primary' value='Filter' name='filter'>
    </div>

<div class='col-lg-3'>
<input type="button" value="Print report(s)" style="float:right;" class="btn btn-sm btn-info" onclick="PrintDiv('myDiv')" />
    </div>
</form>

                            </div>
                            </div> </div>

 <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
<?php
if(isset($_POST["filter"])){
$examset=$_POST["examset"];
$schoolclass=$_POST["schoolclass"];

$stdname=$_POST["stdname"];
if($stdname!=""){
$fstdname=substr($stdname,0,5);
$std_in="and cid='$fstdname'";
}else{
$std_in="";
}


$result_citadel=$dbh->query("select * from citadel where schoolclass='$schoolclass' $std_in");
$row_citadel=$result_citadel->fetchObject();
$count_citadel=$result_citadel->rowCount();

if($count_citadel>0){
    $x=1;
echo "<div id='myDiv'>";
do{

$result_children=$dbh->query("select * from children where cid='$row_citadel->cid'");
$row_children=$result_children->fetchObject();
//$schoolclass=$row_children->schoolclass;

$result_kings=$dbh->query("select * from kingslanding where cid='$row_citadel->cid'");
$row_kings=$result_kings->fetchObject();
$schoolclass=$row_kings->schoolclass;

include("class.php");

$result_scrap1=$dbh->query("select * from scrap where item2='title1' and type='report'");
$row_scrap1=$result_scrap1->fetchObject();

$result_scrap2=$dbh->query("select * from scrap where item2='title2' and type='report'");
$row_scrap2=$result_scrap2->fetchObject();

$result_scrap3=$dbh->query("select * from scrap where item2='title3' and type='report'");
$row_scrap3=$result_scrap3->fetchObject();

$result_scrap4=$dbh->query("select * from scrap where item2='title4' and type='report'");
$row_scrap4=$result_scrap4->fetchObject();

echo "
<div style='height:800px;'>
<table class='table'>
<tr>
<td width='25%' align='center'>
<img src='img/lapsbadge.jpg' style='height:130px;width:180px;'>
</td>
<td align='center' with='60%'>
<b style='font-size:25px;font-family:Times New Roman;color:#0066cc;'>".$row_scrap1->item."</b><br>
<b style='font-size:20px;font-family:Times New Roman;color:#0066cc;'>".$row_scrap2->item."</b><br>
<div style='font-size:15px;font-family:Times New Roman;color:#0066cc;'><b>".$row_scrap3->item."</div><br>
<div style='font-size:17px;font-family:Times New Roman;color:#0066cc;'><b>".$row_scrap4->item."</div><br>
</td>
<td width='20%' align='center'>
<div style='height:150px;width:150px;border:2px dotted black;padding-top:70px;'>Photo here</div>
</td>

</tr>
</table>

<table class='table' border='1'>
<tr>
<td><b class='reptit'>Pupil's Name</b> : ".$row_children->fname." ".$row_children->sname."</td>
<td><b class='reptit'>GENDER</b> : ".$row_children->gender."</td>

<td><b class='reptit'>CLASS</b> : ".$daclass."</td>
<td><b class='reptit'>House</b> : ...............................</td>
</tr>
<tr>
<td><b class='reptit'>COMPUTER NO.</b> : ".$row_citadel->cid."</td>

<td><b class='reptit'>DATE</b> : ".DATE('d-M-Y')."</td>
<td><b class='reptit'>TERM</b> : ".$row_citadel->term."</td>
<td><b class='reptit'>YEAR</b> : 20".$row_citadel->schoolyear."</td>
</tr>
</table>

<table class='table table-bordered table-hover table-striped'>";

$result_examset=$dbh->query("select * from examsets where setid='$examset'");
$row_examset=$result_examset->fetchObject();

echo "
<tr>
<th class='reptit' width='20px'>Subject</th>
<th class='reptit' width='20px'>".$row_examset->setname."</th>
<th class='reptit' width='20px'>Grade</th>
<th class='reptit'>Subject Teacher's comment</th>
</tr>";

//removed from up there <th class='reptit'>Initials</th>

$result_scrap=$dbh->query("select * from scrap where type='secsub' or type='prisubp' or type='prisubps'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();


if($count_scrap>0){
do{
    $fsub=$row_scrap->item."marks";
    $gsub=$row_scrap->item."grade";
    $tr=$row_scrap->item."x";
$result_citadelsub=$dbh->query("select $fsub,cid from citadel where $fsub='0' and cid='$row_citadel->cid'");
$row_citadelsub=$result_citadelsub->fetchObject();
$count_citadelsub=$result_citadelsub->rowCount();

if($count_citadelsub>0){
$result_kingslanding=$dbh->query("select $fsub,$gsub,$tr,cid from kingslanding where setid='$examset' and cid='$row_citadel->cid'");
$row_kingslanding=$result_kingslanding->fetchObject();
echo "
<tr style='height:50px;'>
<th class='reptit'>".$row_scrap->item2."</th>
<td>".$row_kingslanding->$fsub."</td>
<td>".$row_kingslanding->$gsub."</td>";



$result_schcomment=$dbh->query("select * from schcomments");
$row_schcomment=$result_schcomment->fetchObject();
$count_schcomment=$result_schcomment->rowCount();

if($count_schcomment>0){
  do{

if($row_kingslanding->$fsub >= $row_schcomment->comfrom  && $row_kingslanding->$fsub <= $row_schcomment->comto){echo "<td></td>";}

  }while($row_schcomment=$result_schcomment->fetchObject());
}

echo "
</tr>";
}

// removed from bracket above <td>".$row_kingslanding->$tr."</td>


}while($row_scrap=$result_scrap->fetchObject());

echo "
<tr>
<td><b>Total Mark(s)</b></td>
<td></td>
<td></td>
<td></td>
</tr>";
//"<tr><td><b>Position </b></td><td>".$x++."</td><td><b>Average mark</b></td><td></td></tr>"
echo"
<tr>
<td colspan='5'><b class='reptit'>Class teacher's comment on conduct and academics</b> :</td>
</tr>
<tr>
<td colspan='5'><b class='reptit'>Other comment(s)</b> :</td>
</tr>
<tr>
<td colspan='5'><b class='reptit'>Headteacher's comment(s)</b> :</td>
</tr>";
}else{
echo "
<tr>
<td colspan='7'>There is NO exam set submitted yet. </td>
<td></td>
</tr>";
}



echo "
</table>
</div>
";
}while($row_citadel=$result_citadel->fetchObject());
echo "</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>
