<?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/printreport.js"></script>

<style>
th,td{
color:#0066cc;
border: 2px solid black;
border-collapse: collapse;
}


</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">
<form method='post'>
<div class='col-lg-2'>
<select class='form-control' name='schoolclass' required>
<option value="">Class</option>
<?php
include("connect.php");
$result_scrap = $dbh->query("select * from scrap where (item>=21 && item<25) and type='secclas'");
$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='setid' required>
<option value=''>Exam Set</option>
  <?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_setname = $dbh->query("select * from examsets where ouruser like '%$role%'");
$row_setname = $result_setname->fetchObject();
$count_setname = $result_setname->rowCount();
if($count_setname>0){
do{
echo "<option value='".$row_setname->setid."'>".$row_setname->setname."</option>";
}while($row_setname = $result_setname->fetchObject());
}else{
echo "<option value=''>There is no data here so far. </option>";
}
?>
</select>
    </div>
    <div class='col-lg-2'>
<select class='form-control' name='stream' required>
<option value=''>Stream</option>
  <?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$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());
echo "<option value='allstreams'>All streams</option>";
}else{
echo "<option value=''>Please contact your IT department. </option>";
}
?>

</select>
    </div>
<div class='col-lg-1'>
<input type='submit' name="class_filter" class='btn btn-sm btn-primary' value='Filter'>
</div>
<div class='col-lg-1'>
<input type="button" value="Print table" style="float:right;" class="btn btn-sm btn-info" onclick="PrintDiv('myDiv')" />
</div>
</form>
<div class='col-lg-12'><br></div>
<?php
if(isset($_POST["submit_marks"])){
include("connect.php");
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];

$result_kingslandingin = $dbh->query("select * from kingslanding_o where setid='$setid' and schoolclass='$schoolclass' order by cid asc");
$row_kingslandingin = $result_kingslandingin->fetchObject();
$count_kingslandingin = $result_kingslandingin->rowCount();

if($count_kingslandingin>0){
do{
$cid=$_POST["cid".$row_kingslandingin->autoid.""];
$autoid=$_POST["autoid".$row_kingslandingin->autoid.""];
$marks=$_POST["marks".$row_kingslandingin->autoid.""];
$grade=$_POST["grade".$row_kingslandingin->autoid.""];

$fin_subj=$subjectid."marks";
$fin_grad=$subjectid."grade";
$tr=$subjectid."x";

$rolenumber=$_SESSION["rolenumber"];
$result_users = $dbh->query("select * from users where rolenumber='$rolenumber'");
$row_users = $result_users->fetchObject();
$fn=substr($row_users->firstname,0,1);
$ln=substr($row_users->lastname,0,1);
$initials=$fn.$ln;


$update_kingslanding=$dbh->query("update kingslanding_o set $fin_subj='$marks', $fin_grad='$grade', $tr='$initials' where cid='$cid' and setid='$setid' and schoolclass='$schoolclass'");

}while($row_kingslandingin = $result_kingslandingin->fetchObject());
}

$result_scrap = $dbh->query("select * from scrap where item='$subjectid'");
$row_scrap = $result_scrap->fetchObject();

$result_scrapsec = $dbh->query("select * from scrap where item='$schoolclass' and (type='secclas' or type='priclas')");
$row_scrapsec = $result_scrapsec->fetchObject();

$result_examsets = $dbh->query("select * from examsets where setid='$setid'");
$row_examsets = $result_examsets->fetchObject();

echo "<div class='col-lg-12'><div class='alert alert-success'>Success: Marks for Class : <u><i>".$row_scrapsec->item2."</i></u> &nbsp;&nbsp;&nbsp; <i>Subject</i> : <i><u>".$row_scrap->item2."</u></i> &nbsp;&nbsp;&nbsp; <i>Exam set</i> : <i><u>".$row_examsets->setname."</u></i> have been successfully submitted. </div></div>";
}
?>
<div class='col-lg-12'>     
<div class='panel panel-yellow'><!--Initiative-->
<?php
include ("connect.php");
if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];
$stream=$_POST["stream"];

if($stream=="allstreams"){$stream_out="";}
else{$stream_out="and stream='$stream'";}

$result_kingslanding = $dbh->query("select * from kingslanding_o where setid='$setid' and schoolclass='$schoolclass' $stream_out");

$row_kingslanding = $result_kingslanding->fetchObject();
$count_kingslanding = $result_kingslanding->rowCount();

if($count_kingslanding>0){
//$result_scrap = $dbh->query("select * from scrap where item='$subjectid'");
//$row_scrap = $result_scrap->fetchObject();

$result_examsets = $dbh->query("select * from examsets where setid='$setid'");
$row_examsets = $result_examsets->fetchObject();

$result_scrapsec = $dbh->query("select * from scrap where item='$schoolclass' and (type='secclas' or type='priclas')");
$row_scrapsec = $result_scrapsec->fetchObject();

include("class.php");
$title_out="for Term : <u>".$row_kingslanding->term."</u> &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Class : <u>".$row_scrapsec->item2."</u> &nbsp;&nbsp;&nbsp; Exam set: <u>".$row_examsets->setname."</u>&nbsp;&nbsp;&nbsp; Stream: <u>".$stream."</u>";
}else{ $title_out=""; }
}else{ $title_out=""; }

echo "
<div class='panel-heading'><h3 class='panel-title'>Marks List ".$title_out."</h3></div>
<div class='panel-body'>";

if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];
$stream=$_POST["stream"];

if($stream=="allstreams"){$stream_out="";}
else{$stream_out="and stream='$stream'";}

//$result_scrap = $dbh->query("select * from scrap where item='$subjectid'");
//$row_scrap = $result_scrap->fetchObject();


echo "

<div id='myDiv'>
<center><p><strong>CODE HIGH SCHOOL <p>EXAM MARKS SHEET</p>".$row_scrapsec->item2." ".$stream."</strong></center>

<table class='table table-striped sortable' border='2' style='font-size:12px !important; ;border-style:solid;'>
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Stream</th>
<th>Eng</th>
<th>Mat</th>
<th>Phy</th>
<th>Che</th>
<th>Bio</th>
<th>Geo</th>
<th>His</th>
<th>CRE</th>
<th>Comm</th>
<th>ICT</th>
<th>Lug</th>
<th>Lit</th>
<th>Swa</th>
<th>Ent</th>
<th>Art</th>
<th>Agr</th>
</tr>
</thead>
<tbody>";

$result_kingslanding = $dbh->query("select * from kingslanding_o where setid='$setid' and schoolclass='$schoolclass' $stream_out and active='1' order by cid asc");
$row_kingslanding = $result_kingslanding->fetchObject();
$count_kingslanding = $result_kingslanding->rowCount();

if($count_kingslanding>0){
$y=1;
do{

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

echo "
<tr style='border-style:solid;'>
<td>".$y++."</td>";
//echo "<td>".$row_kingslanding->cid." - ".$row_child->fname." ".$row_child->sname."</td>"; 
echo "<td>".$row_kingslanding->cid." - ".ucwords(strtolower($row_child->fname))." ".ucwords(strtolower($row_child->sname))."</td>
<td>".$row_kingslanding->stream."</td>
<font size='10px'>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>";
?>
<?php
}while($row_kingslanding = $result_kingslanding->fetchObject());
}else{
    echo "
<tr>
<td colspan='6' align='center'>There is NO data in the table so far. </td>
</tr>";
}

echo "
</tbody>
</table>
</font>
";
}else{
    echo "Select from the options above and select filter";
}
?>
</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>
