<?php include ("kfunctions.php"); 
role("dosp");
?>
<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;
font-size: 14px;
}
</style>
</head>
<body onload="average_out()">


    <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-4">
                        <div class="panel panel-default">
                            <div class="panel-body">
                                <b><i>Sets</i></b>
                                <div style='height:120px;overflow-y: scroll;'>
                <form method='post'>
<?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_examset=$dbh->query("select * from examsets where ouruser='$rolenumber' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
    $x=1;

echo "
<table style='cursor:pointer;' class='table table-bordered table-hover table-striped sortable' >
<tr>
<th>Set name</th>
<th>Year</th>
<th>Term</th>
</tr>";
do{
$result_kingslanding=$dbh->query("select * from kingslanding_p where setid='$row_examset->setid'");
$count_kingslanding=$result_kingslanding->rowCount();
if($count_kingslanding>0){

echo "<tr title='".$row_examset->setclasses."'><td>"; ?>

<input type='checkbox' onClick="xpush<?php echo $row_examset->autoid; ?>(this.value,'<?php echo $x++; ?>')" id="checkz<?php echo $row_examset->autoid; ?>" name='examset<?php echo $row_examset->autoid; ?>' value='<?php echo $row_examset->setid; ?>'> <?php echo $row_examset->setname."</td>"; ?>

<td>20<?php echo $row_examset->year ;?></td> <td><?php echo $row_examset->term; ?></td></tr>
<script>
function xpush<?php echo $row_examset->autoid; ?>(value_out,number_out){

if(document.getElementById("checkz<?php echo $row_examset->autoid; ?>").checked){
document.getElementById("text"+number_out).value=value_out;
}else{
document.getElementById("text"+number_out).value="";
}
}
</script>

<?php 
}
}while($row_examset=$result_examset->fetchObject());
echo "</table>";
}else{
    echo "There is no set so far";
}
?>
                            </div>
                            </div>
                            </div>
                            </div>
<?php
for($x=1;$x<=20;$x++){
echo "<input type='hidden' name='examz".$x."' id='text".$x."'>";
}
?>

                    <div class="col-lg-8">
                        <div class="panel panel-default">
                            <div class="panel-body">

<div class='col-lg-4'>
<select class='form-control' name='schoolclass'>
<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-4'>
<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 where schoolclass<=10 and cid<50000");
$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-2'>
<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"])){

include("showset.php");
$schoolclass=$_POST["schoolclass"];
$stdname=$_POST["stdname"];
if($stdname!=""){
$fstdname=substr($stdname,0,5);
$std_in="cid='$fstdname'";
}else{
$std_in="schoolclass='$schoolclass'";
}

$result_kingslandingcid=$dbh->query("select distinct(cid) from kingslanding_p where $std_in order by cid asc");
$row_kingslandingcid=$result_kingslandingcid->fetchObject();
$count_kingslandingcid=$result_kingslandingcid->rowCount();

if($count_kingslandingcid>0){
    $x=1;
echo "<div id='myDiv'>";
do{
$result_kingslanding=$dbh->query("select * from kingslanding_p where cid='$row_kingslandingcid->cid'");
$row_kingslanding=$result_kingslanding->fetchObject();
$count_kingslanding=$result_kingslanding->rowCount();

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

$schoolclass=$row_kingslanding->schoolclass;
include("class.php");

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

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

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

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

echo "
<div>
<table class='table'>
<tr>
<td width='20%' align='center'>

<img src='img/lapsbadge.jpg' style='height:130px;width:180px;'>
</td>
<td align='center' with='60%'>
<b style='font-size:30px;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 class='reptit'><b>Pupil's Name</b> : ".$row_children->fname." ".$row_children->sname."</td>
<td class='reptit'><b>GENDER</b> : ".$row_children->gender."</td>

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

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

<table border='1' class='table'>";

$result_examset=$dbh->query("select * from examsets where autoid='' $exam1 $exam2 $exam3 $exam4 $exam5 $exam6 $exam7 $exam8 $exam9 $exam10 $exam11 $exam12 $exam13 $exam14 $exam15 $exam16 $exam17 $exam18 $exam19 $exam20");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();
    
echo "
<tr>
<th rowspan='2' class='reptit'>SUBJECT</th>";
if($count_examset>0){
do{
echo " 
<td class='reptit' colspan='2' align='center'><b>".$row_examset->setname."</b></td>";
}while($row_examset=$result_examset->fetchObject());
}

echo "
<th rowspan='2' class='reptit' width='35%'>SUBJECT TEACHER'S DESCRIPTIVE REPORT</th>
<th rowspan='2' class='reptit' width='3%'>TEACHER'S INITIALS</th>
</tr>
<tr>";

$result_examset=$dbh->query("select * from examsets where autoid='' $exam1 $exam2 $exam3 $exam4 $exam5 $exam6 $exam7 $exam8 $exam9 $exam10 $exam11 $exam12 $exam13 $exam14 $exam15 $exam16 $exam17 $exam18 $exam19 $exam20");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
do{
echo " 
<th class='reptit'>Marks(%)</th>
<th class='reptit'>AGG</th>";
}while($row_examset=$result_examset->fetchObject());
}

echo "</tr>";


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


if($count_scrap>0){
    $z=1;
do{
    $fsub=$row_scrap->item."marks";
    $gsub=$row_scrap->item."grade";
    $tr=$row_scrap->item."x";
    $comz=$row_scrap->item."c";

$result_kings=$dbh->query("select * from kingslanding_p where ($fsub>=0 and $fsub!='N') and cid='$row_kingslanding->cid' order by autoid desc");
$row_kings=$result_kings->fetchObject();
$count_kings=$result_kings->rowCount();

if($count_kings>0){
echo "
<tr>
<th class='reptit'>".$row_scrap->item2."</th>";

$result_examset=$dbh->query("select * from examsets where autoid='' $exam1 $exam2 $exam3 $exam4 $exam5 $exam6 $exam7 $exam8 $exam9 $exam10 $exam11 $exam12 $exam13 $exam14 $exam15 $exam16 $exam17 $exam18 $exam19 $exam20");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
    do{
$result_kingsexam=$dbh->query("select * from kingslanding_p where ($fsub>=0 and $fsub!='N') and setid='$row_examset->setid' and cid='$row_kingslanding->cid'");
$row_kingsexam=$result_kingsexam->fetchObject();
$count_kingsexam=$result_kingsexam->rowCount();

if($count_kingsexam>0){echo "
<td class='reptit'>".$row_kingsexam->$fsub."</td>
<td class='reptit'>".$row_kingsexam->$gsub."</td>";}
else{echo "
<td class='reptit'></td>
<td class='reptit'></td>";}

}while($row_examset=$result_examset->fetchObject());
}

if($row_kings->$comz!=""){echo "<td class='reptit'>".$row_kings->$comz."</td>";}else{echo "<td></td>";}
echo " 
<td class='reptit' align='center'>".$row_kings->$tr."</td>
</tr>";
}
}while($row_scrap=$result_scrap->fetchObject());

$result_examset=$dbh->query("select * from examsets where autoid='' $exam1 $exam2 $exam3 $exam4 $exam5 $exam6 $exam7 $exam8 $exam9 $exam10 $exam11 $exam12 $exam13 $exam14 $exam15 $exam16 $exam17 $exam18 $exam19 $exam20");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
echo "
<tr>
<th class='reptit'>Sub Total</th>";
$r=1;
do{
$result_kingsexam=$dbh->query("select * from kingslanding_p where setid='$row_examset->setid' and cid='$row_kingslanding->cid'");
$row_kingsexam=$result_kingsexam->fetchObject();
$count_kingsexam=$result_kingsexam->rowCount();

include("totalaggr.php");

echo "
<th class='reptit'>".$total."</th>
<th class='reptit'>".$aggrz."</th>";

}while($row_examset=$result_examset->fetchObject());
echo "
<th rowspan='2' colspan='2' class='reptit'>
Fees balance : 
<input type='hidden' id='count_out' value='".$count_examset."'>
</th>
</tr>";}

$result_examset=$dbh->query("select * from examsets where autoid='' $exam1 $exam2 $exam3 $exam4 $exam5 $exam6 $exam7 $exam8 $exam9 $exam10 $exam11 $exam12 $exam13 $exam14 $exam15 $exam16 $exam17 $exam18 $exam19 $exam20");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
echo "
<tr>
<th class='reptit'>Division</th>";
$r=1;
do{
$result_kingsexam=$dbh->query("select * from kingslanding_p where setid='$row_examset->setid' and cid='$row_kingslanding->cid'");
$row_kingsexam=$result_kingsexam->fetchObject();
$count_kingsexam=$result_kingsexam->rowCount();

include("totalaggr.php");

echo "<td colspan='2' align='center' class='reptit'>"; 

$result_grades=$dbh->query("select divfrom,divto,aggr from grades where divfrom!='' and divto!=''");
$row_grades=$result_grades->fetchObject();
$count_grades=$result_grades->rowCount();

if($count_grades>0){
do{
if($aggrz>=$row_grades->divfrom && $aggrz<=$row_grades->divto){echo $row_grades->aggr;}
}while($row_grades=$result_grades->fetchObject());
}
echo "</td >";

}while($row_examset=$result_examset->fetchObject());
echo "</tr>";}

echo "</tr>
</table>
<table class='table' border='1'>
<tr>
<td width='30%'><b class='reptit'>Next term begins on </b> : </td>
<td width='18%'></td>
<td width='30%'><b class='reptit'>Additional Comment(s) </b></td>
<td></td>
</tr>

<tr>
<td colspan='2' width='40%'><b class='reptit'>Class Manager's Remarks : </b></td>
<td rowspan='2' colspan='6'></td>
</tr>
<tr>
<td colspan='4'><b class='reptit'>Signed by :............................</b></td>
</tr>
<tr>
<td colspan='2'><b class='reptit'>Headteacher's Summary Report : </b></td>
<td rowspan='2' colspan='6'></td>
</tr>
<tr>
<td colspan='4'><b class='reptit'>Signed by :............................</b></td>
</tr>";
}else{
echo "
<tr>
<td colspan='10'>There is NO exam set has been submitted yet. </td>
<td></td>
</tr>";
}

echo "
</table>
<table border='1' class='table'>
<tr>";
$result_grades=$dbh->query("select pfrom, pto from grades");
$row_grades=$result_grades->fetchObject();
$count_grades=$result_grades->rowCount();

if($count_grades>0){
do{
echo "<td align='center' class='reptit'>".$row_grades->pfrom." - ".$row_grades->pto."</td>";
}while($row_grades=$result_grades->fetchObject());
}

echo "
</tr>
<tr>";
$result_grades=$dbh->query("select grade from grades");
$row_grades=$result_grades->fetchObject();
$count_grades=$result_grades->rowCount();

if($count_grades>0){
do{
echo "<td align='center' class='reptit'>".$row_grades->grade."</td>";
}while($row_grades=$result_grades->fetchObject());
}

echo "
</tr>
</table>
</div>";

}while($row_kingslandingcid=$result_kingslandingcid->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>
