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

//include ("seredirect.php");

?>

<html>

<head>

<?php kheader(); ?>

<?php 

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

$result=$dbh->query("select * from scrap");



?>

<link href="../css/bootstrap-datetimepicker.min.css" rel="stylesheet" media="screen">



<script src="../js/sorttable.js"></script>

<script src="../js/printreport.js"></script>

</head>

<body onload="myFunction()">



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

                        <h1 class="page-header">

                           O level - Class performance

                        </h1>

                        

                    </div>

                </div>

                <!-- /.row -->



                <div class="row">

<form method='post'>

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

<select class='form-control' name='category'>

<option value=''>Category</option>

<option value='best'>Best</option>

<option value='worst'>Worst</option>

</select>

</div>

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

<table >

    <tr>

<td width='70%'><input type='text' class='form-control' placeholder='Number' name='number'></td>

<td width='10%'></td>

<td> in</td>

</tr>

</table>

</div>

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

<div class='panel panel-yellow'>

   <div class='panel-body'> 

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

<select class='form-control' name='schoolclass' required>

<option value=''>Class</option>

<?php 

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

$result_scrap=$dbh->prepare("select * from scrap where type='secclas' and item<25 ");

$result_scrap->execute();

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

<select class='form-control' name='stream' required>

<option value=''>Stream</option>

<?php 

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

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

$result_scrap->execute();

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

<select class='form-control' name='examset' required>

<option value=''>Set</option>

<?php 

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

$result_exam=$dbh->prepare("select * from examsets where setid!=''");

$result_exam->execute();

$row_exam=$result_exam->fetchObject();

$count_exam=$result_exam->rowCount();



if($count_exam>0){

do{

echo "<option value='".$row_exam->setid."'>".$row_exam->setname."</option>";

}while($row_exam=$result_exam->fetchObject());

}else{

    echo "<option value=''>So far, there is NO set. </option>";

}

?>

</select>

</div>   

</div>

</div>

</div>

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

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

</div>

</form>

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

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

 <div class='panel panel-yellow'>

      <div class='panel-heading'>

        <h4 class='panel-title'>

          <a data-toggle='collapse' data-parent='#accordion' href='#cord1' aria-expanded='false' class='collapsed'>Aggregate summary - O level</a>

        </h4>

      </div>

      <div id='cord1' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>

        <div class='panel-body'>

<?php

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

$schoolclass=$_POST["schoolclass"];

$stream=$_POST["stream"];

$examset=$_POST["examset"];

$category=$_POST["category"];

$number=$_POST["number"];



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

else{$stream_out="and stream='$stream'";}



$result_exam=$dbh->prepare("select * from examsets where setid='$examset'");

$result_exam->execute();

$row_exam=$result_exam->fetchObject();



include("class.php");

echo "<u>Class : <i>".$daclass."</i></u> <u>Stream : <i>".$stream."</i></u> <u>Exam set : <i>".$row_exam->setname."</i></u>";



?>



<div style="float:right;" class='col-lg-2'>

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

</div>



<?php

echo "

<div id='myDiv1'>

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

<tr>

<th>No</th>

<th>Subject</th>";

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

$result_grade=$dbh->prepare("select * from grades");

$result_grade->execute();

$row_grade=$result_grade->fetchObject();

$count_grade=$result_grade->rowCount();



if($count_grade>0){

    do{

echo "<td>".$row_grade->grade."</td>";

    }while($row_grade=$result_grade->fetchObject());

}

echo "

<td>Total</td>

</tr>";



$result_scrap=$dbh->prepare("select * from scrap where (type='secsub' or type='prisubps')  and item4='1'");

$result_scrap->execute();

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap>0){

$x=1;

do{

echo "<tr>

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

<td>".$row_scrap->item2."</td>";

$result_grade=$dbh->prepare("select * from grades");

$result_grade->execute();

$row_grade=$result_grade->fetchObject();

$count_grade=$result_grade->rowCount();





if($count_grade>0){

    do{

$gsub=$row_scrap->item."grade";

$gin=$row_grade->aggr;

$result_kings=$dbh->prepare("select * from kingslanding_o where $gsub='$gin' and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1'");

$result_kings->execute();

$row_kings=$result_kings->fetchObject();

$count_kings=$result_kings->rowCount();



echo "<td>".$count_kings."</td>";

    }while($row_grade=$result_grade->fetchObject());

}



$gsub=$row_scrap->item."grade";

$result_kingst=$dbh->prepare("select * from kingslanding_o where ($gsub='1' or $gsub='2' or $gsub='3' or $gsub='4' or $gsub='5' or $gsub='6' or $gsub='7' or $gsub='8' or $gsub='9') and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1'");

$result_kingst->execute();

$row_kingst=$result_kingst->fetchObject();

$count_kingst=$result_kingst->rowCount();



echo "

<td>".$count_kingst."</td>

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

}else{

    echo "<tr>

    <td colspan='10' align='center'>Please contact your IT department.</td>

    </tr>";}

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

}



 ?>



</div>

</div>

</div>

</div>

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

<div class='panel panel-info'>

      <div class='panel-heading'>

        <h4 class='panel-title'>

          <a data-toggle='collapse' data-parent='#accordion' href='#cord4' aria-expanded='false' class='collapsed'>Division summary</a>

        </h4>

      </div>

      <div id='cord4' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>

        <div class='panel-body'>

<?php

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

$schoolclass=$_POST["schoolclass"];

$stream=$_POST["stream"];

$examset=$_POST["examset"];



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

else{$stream_out="and stream='$stream'";}



$result_exam=$dbh->prepare("select * from examsets where setid='$examset'");

$result_exam->execute();

$row_exam=$result_exam->fetchObject();



include("class.php");

echo "<u>Class : <i>".$daclass."</i></u> <u>Stream : <i>".$stream."</i></u> <u>Exam set : <i>".$row_exam->setname."</i></u>";



?>

<div style="float:right;" class='col-lg-2'>

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

</div>

<div id='myDiv4'>

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

<tr>

<th>No</th>

<th>Division</th>

<th>Number of students</th>

</tr>

 <?php



$result_grade=$dbh->prepare("select divtotake from grades where divtotake!=''");

$result_grade->execute();

$row_grade=$result_grade->fetchObject();

$count_grade=$result_grade->rowCount();



if($count_grade>0){

    $x=1;

    do{

$result_kings=$dbh->prepare("select * from kingslanding_o where division='$row_grade->divtotake' and schoolclass='$schoolclass' and setid='$examset' $stream_out");

$result_kings->execute();

$row_kings=$result_kings->fetchObject();

$count_kings=$result_kings->rowCount();



echo "<tr>

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

<td>Div ".$row_grade->divtotake."</td>

<td>".$count_kings."</td>

</tr>";

 }while($row_grade=$result_grade->fetchObject());

}else{

    echo "<tr>

    <td colspan='3' align='center'>There is NO data in this table</td>

    </tr>";}



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

}else{

    echo "Select the field above";

}

?>

</div>

</div>

</div>

</div>

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

                        <div class='panel panel-primary'>

      <div class='panel-heading'>

        <h4 class='panel-title'>

          <a data-toggle='collapse' data-parent='#accordion' href='#cord2' aria-expanded='false' class='collapsed'>Average</a>

        </h4>

      </div>

      <div id='cord2' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>

        <div class='panel-body'>

<?php

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

?>



<div style="float:right;" class='col-lg-2'>

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

</div>



<?php



echo "        

<div id='myDiv2'>

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

<tr>

    <th>Subject</th>

    <th>Best 10</th>

    <th>Last 10</th>

    <th>General</th>

</tr>";



$result_scrap=$dbh->prepare("select * from scrap where (type='secsub' or type='prisubps') and item4='1' ");

$result_scrap->execute();

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();



if($count_scrap>0){

do{

echo "<tr>

<td>".$row_scrap->item2."</td>

<td id='bst".$row_scrap->autoid."'></td>

<td id='wst".$row_scrap->autoid."'></td>

<td id='gen".$row_scrap->autoid."'></td>

<td>";

$fsub=$row_scrap->item."marks";

$result_kingbst=$dbh->query("select sum($fsub) from kingslanding_o where ($fsub!='N' and $fsub>20) and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1' order by $fsub desc limit 0,10");

$row_kingbst=$result_kingbst->fetch();

$count_kingbst=$result_kingbst->rowCount();





echo $row_kingbst[0];



echo "

</td>

</tr>";

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

}else{

    echo "<tr>

<td align='center' colspan='4'>Please contact your IT department. </td>

    </tr>";

}



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

}else{

    echo "Select the field above";

}



?>

</div>

            </div>

        </div>

</div>

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

                        <div class='panel panel-green'>

      <div class='panel-heading'>

        <h4 class='panel-title'>

          <a data-toggle='collapse' data-parent='#accordion' href='#cord3' aria-expanded='false' class='collapsed'>Best & Worst</a>

        </h4>

      </div>

      <div id='cord3' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>

        <div class='panel-body'>

<?php

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

$schoolclass=$_POST["schoolclass"];

$stream=$_POST["stream"];

$examset=$_POST["examset"];

$category=$_POST["category"];

$number=$_POST["number"];



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

else{$stream_out="and stream='$stream'";}



if($category=="best"){$fcat="desc";}

elseif($category=="worst"){$fcat="asc";}



?>



<div style="float:right;" class='col-lg-2'>

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

</div>



<?php

echo "        

<div id='myDiv3'>

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

<tr>

    <th>No</th>

    <th>Names</th>

    <th>CID</th>

    <th>Total</th>

    <th>Average</th>

    <th>Aggregates</th>

    

</tr>";



$result_kings=$dbh->prepare("select * from kingslanding_o where schoolclass='$schoolclass' and setid='$examset' $stream_out order by cast(totalmarks AS unsigned) $fcat limit 0,$number");

$result_kings->execute();

$row_kings=$result_kings->fetchObject();

$count_kings=$result_kings->rowCount();



if($count_kings>0){

$x=1;

do{

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

$result_child->execute();

$row_child=$result_child->fetchObject();



$total = $row_kings->sub46marks + $row_kings->sub47marks + $row_kings->sub48marks + $row_kings->sub49marks + $row_kings->sub50marks + $row_kings->sub51marks + $row_kings->sub52marks + $row_kings->sub53marks+ $row_kings->sub54marks + $row_kings->sub55marks + $row_kings->sub56marks + $row_kings->sub57marks + $row_kings->sub58marks + $row_kings->sub59marks + $row_kings->sub60marks + $row_kings->sub61marks + $row_kings->sub62marks + $row_kings->sub63marks + $row_kings->sub64marks + $row_kings->sub66marks + $row_kings->sub67marks + $row_kings->sub68marks + $row_kings->sub71marks + $row_kings->sub72marks + $row_kings->sub75marks + $row_kings->sub76marks + $row_kings->sub77marks + $row_kings->sub78marks + $row_kings->sub79marks + $row_kings->sub80marks + $row_kings->sub81marks + $row_kings->sub82marks + $row_kings->sub83marks + $row_kings->sub84marks + $row_kings->sub85marks;



$marks = array($row_kings->sub46marks,$row_kings->sub47marks,$row_kings->sub48marks,$row_kings->sub49marks,$row_kings->sub50marks,$row_kings->sub51marks,$row_kings->sub52marks,$row_kings->sub53marks,$row_kings->sub54marks,$row_kings->sub55marks,$row_kings->sub56marks,$row_kings->sub57marks,$row_kings->sub58marks,$row_kings->sub59marks,$row_kings->sub60marks,$row_kings->sub61marks,$row_kings->sub62marks,$row_kings->sub63marks,$row_kings->sub64marks,$row_kings->sub66marks,$row_kings->sub67marks,$row_kings->sub68marks,$row_kings->sub71marks,$row_kings->sub72marks,$row_kings->sub75marks,$row_kings->sub76marks,$row_kings->sub77marks,$row_kings->sub78marks,$row_kings->sub79marks,$row_kings->sub80marks,$row_kings->sub81marks,$row_kings->sub82marks,$row_kings->sub83marks,$row_kings->sub84marks,$row_kings->sub85marks);

$counter=array_count_values($marks);

$countall=count($marks);

$countn=$counter['N'];



$does=$countall-$countn;

$faveragemark=$total/$does;

$averagemark=number_format($faveragemark,0);



echo "<tr>

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

<td>".$row_child->fname." ".$row_child->sname."</td>

<td>".$row_kings->cid."</td>

<td>".$row_kings->totalmarks."</td>

<td>".$averagemark."</td>

<td>".$row_kings->totalaggr."</td>

</tr>";

}while($row_kings=$result_kings->fetchObject());

}else{

echo "<tr>

<td colspan='3' align='center'>There is no data in this table. </td>

</tr>";

}



echo "</table>";

}else{

    echo "Select the field above";

}



?>

         </div>   

        </div>

        </div>

    </div>

</div>







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

<script>

<?php

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

$schoolclass=$_POST["schoolclass"];

$stream=$_POST["stream"];

$examset=$_POST["examset"];



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

else{$stream_out="and stream='$stream'";}



?>

function myFunction() {

<?php

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

//scrap general lp

$result_scrap=$dbh->prepare("select * from scrap where (type='secsub' or type='prisubps') and item4='1' ");

$result_scrap->execute();

$row_scrap=$result_scrap->fetchObject();

$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){

do{

//Best 10

$fsub=$row_scrap->item."marks";

$result_kingbst=$dbh->prepare("select * from kingslanding_o where ($fsub!='N' and $fsub>20) and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1' order by $fsub desc limit 0,10");

$result_kingbst->execute();

$row_kingbst=$result_kingbst->fetchObject();

$count_kingbst=$result_kingbst->rowCount();



?>

var bst_sum=0 <?php if($count_kingbst>0){do{if($row_kingbst->$fsub==""){$fbst=0;}else{$fbst=$row_kingbst->$fsub;} echo "+".$fbst;}while($row_kingbst=$result_kingbst->fetchObject());}else{echo "+ 0";} ?>



document.getElementById("bst<?php echo $row_scrap->autoid; ?>").innerHTML = parseInt(bst_sum)/10;



<?php

//Last 10

$fsub=$row_scrap->item."marks";

$result_kingwst=$dbh->prepare("select * from kingslanding_o where ($fsub!='N' and $fsub<90) and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1' order by $fsub asc limit 0,10");

$result_kingwst->execute();

$row_kingwst=$result_kingwst->fetchObject();

$count_kingwst=$result_kingwst->rowCount();

?>

var wst_sum=0 <?php if($count_kingwst>0){do{ if($row_kingwst->$fsub==""){$fwst=0;}else{$fwst=$row_kingwst->$fsub;} echo "+".$fwst;}while($row_kingwst=$result_kingwst->fetchObject());}else{echo "+ 0";} ?>



document.getElementById("wst<?php echo $row_scrap->autoid; ?>").innerHTML = parseInt(wst_sum)/10;





<?php

//General average

$fsub=$row_scrap->item."marks";

$result_kinggen=$dbh->prepare("select * from kingslanding_o where $fsub!='N' and schoolclass='$schoolclass' $stream_out and setid='$examset' and active='1'");

$result_kinggen->execute();

$row_kinggen=$result_kinggen->fetchObject();

$count_kinggen=$result_kinggen->rowCount();

?>

var gen_sum=0 <?php if($count_kinggen>0){do{if($row_kinggen->$fsub==""){$fgen=0;}else{$fgen=$row_kinggen->$fsub;} echo "+".$fgen;}while($row_kinggen=$result_kinggen->fetchObject());}else{echo "+ 0";} ?>



document.getElementById("gen<?php echo $row_scrap->autoid; ?>").innerHTML = parseInt(gen_sum)/parseInt(<?php echo $count_kinggen; ?>);



<?php

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

}

?>

}

<?php

}

?>

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

</body>



</html>

