<?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>
</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='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='schoolclass' required>
<option value="">Class</option>
<?php
include("connect.php");
$result_scrap = $dbh->query("select * from scrap where 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='astream' required>
<option value=''>Stream</option>
<option value='arts'>Arts</option>
<option value='sciences'>Sciences</option>
</select>
</div>
<div class='col-lg-1'>
<input type='submit' name="class_filter" class='btn btn-sm btn-primary' value='Filter'>
</div>
</form>
<div class='col-lg-12'><br></div>


<?php
include ("connect.php");
if(isset($_POST["class_filter"])){
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];
$astream=$_POST["astream"];

  include("asub.php");

$result_kingslanding = $dbh->query("select * from rivendell where setid='$setid' and schoolclass='$schoolclass' ");
$row_kingslanding = $result_kingslanding->fetchObject();
$count_kingslanding = $result_kingslanding->rowCount();

if($count_kingslanding>0){
$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 <i>Term</i> : <u><i>".$row_kingslanding->term."</i></u> &nbsp;&nbsp;&nbsp; <i>Stream</i> : <u><i>".$astream."</i></u> &nbsp;&nbsp;&nbsp; <i>Class</i> : <i><u>".$row_scrapsec->item2."</u></i> &nbsp;&nbsp;&nbsp; <i>Exam set</i> : <i><u>".$row_examsets->setname."</u></i>";

}else{$title_out="";}
}else{$title_out="";}

if(isset($_POST["submit"])){
$schoolclass=$_POST["schoolclass"];
$setid=$_POST["setid"];
$astream=$_POST["astream"];
include("connect.php");
//for arts, history1 or div1 or literature
//for sciences, math or physics or chemistry

if ($astream=='arts'){
$streamselector="(sub10_1m!='N' or sub14_1m!='N' or sub13_1m!='N')";
}
elseif($astream=='sciences'){
$streamselector="(sub19_1m!='N' or sub16_1m!='N' or sub17_1m!='N')";
}

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

if($count_kingslanding>0){
do{
$cid=$_POST["cid".$row_kingslanding->autoid.""];
$sub22=$_POST["sub22".$row_kingslanding->autoid.""];
$sub24=$_POST["sub24".$row_kingslanding->autoid.""];
$sub23=$_POST["sub23".$row_kingslanding->autoid.""];
$sub20=$_POST["sub20".$row_kingslanding->autoid.""];
$sub20a=$_POST["sub20a".$row_kingslanding->autoid.""];
$sub11=$_POST["sub11".$row_kingslanding->autoid.""];
$sub11a=$_POST["sub11a".$row_kingslanding->autoid.""];
$sub12=$_POST["sub12".$row_kingslanding->autoid.""];
$sub12a=$_POST["sub12a".$row_kingslanding->autoid.""];
$sub21=$_POST["sub21".$row_kingslanding->autoid.""];
$sub21a=$_POST["sub21a".$row_kingslanding->autoid.""];

if($astream=="arts"){
$sub10=$_POST["sub10".$row_kingslanding->autoid.""];
$sub10a=$_POST["sub10a".$row_kingslanding->autoid.""];
$sub15=$_POST["sub15".$row_kingslanding->autoid.""];
$sub15a=$_POST["sub15a".$row_kingslanding->autoid.""];
$sub13=$_POST["sub13".$row_kingslanding->autoid.""];
$sub13a=$_POST["sub13a".$row_kingslanding->autoid.""];
$sub14=$_POST["sub14".$row_kingslanding->autoid.""];
$sub14a=$_POST["sub14a".$row_kingslanding->autoid.""];
$totalpoints=$_POST["totalpoints".$row_kingslanding->autoid.""];

$update_rivendell=$dbh->query("update rivendell set sub22_points='$sub22', sub24_points='$sub24', sub23_points='$sub23', sub20_letter='$sub20', sub20_points='$sub20a', sub11_letter='$sub11', sub11_points='$sub11a', sub12_letter='$sub12', sub12_points='$sub12a', sub21_letter='$sub21', sub21_points='$sub21a', sub10_letter='$sub10', sub10_points='$sub10a', sub15_letter='$sub15', sub15_points='$sub15a', sub13_letter='$sub13', sub13_points='$sub13a', sub14_letter='$sub14', sub14_points='$sub14a', totalpoints='$totalpoints' where cid='$cid' and schoolclass='$schoolclass' and setid='$setid'");

}elseif($astream=="sciences"){
$sub16=$_POST["sub16".$row_kingslanding->autoid.""];
$sub16a=$_POST["sub16a".$row_kingslanding->autoid.""];
$sub17=$_POST["sub17".$row_kingslanding->autoid.""];
$sub17a=$_POST["sub17a".$row_kingslanding->autoid.""];
$sub18=$_POST["sub18".$row_kingslanding->autoid.""];
$sub18a=$_POST["sub18a".$row_kingslanding->autoid.""];
$sub19=$_POST["sub19".$row_kingslanding->autoid.""];
$sub19a=$_POST["sub19a".$row_kingslanding->autoid.""];
$totalpoints=$_POST["totalpoints".$row_kingslanding->autoid.""];

$update_rivendell=$dbh->query("update rivendell set sub22_points='$sub22', sub24_points='$sub24', sub23_points='$sub23', sub20_letter='$sub20', sub20_points='$sub20a', sub11_letter='$sub11', sub11_points='$sub11a', sub12_letter='$sub12', sub12_points='$sub12a', sub21_letter='$sub21', sub21_points='$sub21a', sub16_letter='$sub16', sub16_points='$sub16a', sub17_letter='$sub17', sub17_points='$sub17a', sub18_letter='$sub18', sub18_points='$sub18a', sub19_letter='$sub19', sub19_points='$sub19a', totalpoints='$totalpoints' where cid='$cid' and schoolclass='$schoolclass' and setid='$setid' ");
}


}while($row_kingslanding = $result_kingslanding->fetchObject()); 
}
}



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

//for arts, history1 or div1 or literature
//for sciences, math or physics or chemistry

if ($astream=='arts'){
$streamselector="(sub10_1m!='N' or sub14_1m!='N' or sub13_1m!='N')";
}
elseif($astream=='sciences'){
$streamselector="(sub19_1m!='N' or sub16_1m!='N' or sub17_1m!='N')";
}

echo "
<form method='post'>
<input type='submit' style='float:right;margin-right:15px;' class='btn btn-sm btn-warning' name='submit' value='Submit'><br>
<input type='hidden' name='schoolclass' value='".$schoolclass."'>
<input type='hidden' name='setid' value='".$setid."'>
<input type='hidden' name='astream' value='".$astream."'>


<div class='col-lg-12'>     
<div class='panel panel-primary'>
<div class='panel-heading'><h3 class='panel-title'>Position ".$title_out."</h3></div>
<div class='panel-body'>
<table class='table table-striped sortable' border='1' style='font-size:12px !important;'>
<thead>
<tr>
<th rowspan='2'>Name</th>
<th rowspan='2'>GP</th>
<th rowspan='2'>S/ICT</th>
<th rowspan='2'>S/Math</th>
<th >Econ</th>
<th >Ent</th>
<th >Geography</th>
<th >Fine Art</th>";

if($astream=="arts"){
echo "
<th >History</th>
<th >Luganda</th>
<th >Literature</th>
<th >Divinity</th>";
}elseif($astream=="sciences"){
echo "
<th >Physics</th>
<th >Chemistry</th>
<th >Biology</th>
<th >Math</th>";}

echo "
<th>Total points</th>
</tr>
</thead>
<tbody>";

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

if($count_kingslanding>0){
do{

if($row_kingslanding->sub22_m>=50){$gp="O"; $ngp=1;}else{$gp="F"; $ngp=0;}
if($row_kingslanding->sub24_m>=50){$ict="O"; $nict=1;}else{$ict="F"; $nict=0;}
if($row_kingslanding->sub23_m>=50){$smath="O"; $nsm=1;}else{$smath="F"; $nsm=0;}

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

echo "
<input type='hidden' name='cid".$row_kingslanding->autoid."' value='".$row_kingslanding->cid."'>
<tr>";
//echo "<td>".$row_kingslanding->cid." - ".$row_child->fname." ".$row_child->sname."</td>"; 
echo "<td>".ucwords(strtolower($row_child->fname))." ".ucwords(strtolower($row_child->sname))." - ".$row_kingslanding->cid."</td>

<td>".$gp."
<input type='hidden' name='sub22".$row_kingslanding->autoid."' value='".$gp."'></td>

<td>".$ict."
<input type='hidden' name='sub24".$row_kingslanding->autoid."' value='".$ict."'></td>

<td>".$smath."
<input type='hidden' name='sub23".$row_kingslanding->autoid."' value='".$smath."'></td>

<td>"; sub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g); echo "
<input type='hidden' name='sub20".$row_kingslanding->autoid."' value='"; vsub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g); 
echo "'>

<input type='hidden' name='sub20a".$row_kingslanding->autoid."' value='"; 
if($row_kingslanding->sub20_1g=="x"){$f20_1=0;}else{$f20_1=$row_kingslanding->sub20_1g;}
if($row_kingslanding->sub20_2g=="x"){$f20_2=0;}else{$f20_2=$row_kingslanding->sub20_2g;}

echo $f20_1+$f20_2; echo "'>
</td>

<td>"; sub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g); echo "
<input type='hidden' name='sub11".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g);
 echo "'>

<input type='hidden' name='sub11a".$row_kingslanding->autoid."' value='"; 
if($row_kingslanding->sub11_1g=="x"){$f11_1=0;}else{$f11_1=$row_kingslanding->sub11_1g;}
if($row_kingslanding->sub11_2g=="x"){$f11_2=0;}else{$f11_2=$row_kingslanding->sub11_2g;}
if($row_kingslanding->sub11_3g=="x"){$f11_3=0;}else{$f11_3=$row_kingslanding->sub11_3g;}

echo $f11_1+$f11_2+$f11_3; echo "'>
</td>

<td>"; sub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g); echo "
<input type='hidden' name='sub12".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g);
echo "'>
<input type='hidden' name='sub12a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub12_1g=="x"){$f12_1=0;}else{$f12_1=$row_kingslanding->sub12_1g;}
if($row_kingslanding->sub12_2g=="x"){$f12_2=0;}else{$f12_2=$row_kingslanding->sub12_2g;}
if($row_kingslanding->sub12_3g=="x"){$f12_3=0;}else{$f12_3=$row_kingslanding->sub12_3g;}

echo $f12_1+$f12_2+$f12_3; echo "'>

</td>

<td>"; sub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g); echo "
<input type='hidden' name='sub21".$row_kingslanding->autoid."' value='"; vsub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g); 
echo "'>
<input type='hidden' name='sub21a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub21_1g=="x"){$f21_1=0;}else{$f21_1=$row_kingslanding->sub21_1g;}
if($row_kingslanding->sub21_2g=="x"){$f21_2=0;}else{$f21_2=$row_kingslanding->sub21_2g;}
if($row_kingslanding->sub21_3g=="x"){$f21_3=0;}else{$f21_3=$row_kingslanding->sub21_3g;}
if($row_kingslanding->sub21_4g=="x"){$f21_4=0;}else{$f21_4=$row_kingslanding->sub21_4g;}

echo $f21_1+$f21_2+$f21_3+$f21_4; echo "'></td>";

if($astream=="arts"){
echo "
<td>"; sub4($row_kingslanding->sub10_1g,$row_kingslanding->sub10_2g,$row_kingslanding->sub10_3g,$row_kingslanding->sub10_4g); echo "
<input type='hidden' name='sub10".$row_kingslanding->autoid."' value='"; vsub4($row_kingslanding->sub10_1g,$row_kingslanding->sub10_2g,$row_kingslanding->sub10_3g,$row_kingslanding->sub10_4g); 
echo "'>
<input type='hidden' name='sub10a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub10_1g=="x"){$f10_1=0;}else{$f10_1=$row_kingslanding->sub10_1g;}
if($row_kingslanding->sub10_2g=="x"){$f10_2=0;}else{$f10_2=$row_kingslanding->sub10_2g;}
if($row_kingslanding->sub10_3g=="x"){$f10_3=0;}else{$f10_3=$row_kingslanding->sub10_3g;}
if($row_kingslanding->sub10_4g=="x"){$f10_4=0;}else{$f10_4=$row_kingslanding->sub10_4g;}
echo $f10_1+$f10_2+$f10_3+$f10_4; echo "'></td>

<td>"; sub3($row_kingslanding->sub15_1g,$row_kingslanding->sub15_2g,$row_kingslanding->sub15_3g); echo "
<input type='hidden' name='sub15".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub15_1g,$row_kingslanding->sub15_2g,$row_kingslanding->sub15_3g); 

echo "'>

<input type='hidden' name='sub15a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub15_1g=="x"){$f15_1=0;}else{$f15_1=$row_kingslanding->sub15_1g;}
if($row_kingslanding->sub15_2g=="x"){$f15_2=0;}else{$f15_2=$row_kingslanding->sub15_2g;}
if($row_kingslanding->sub15_3g=="x"){$f15_3=0;}else{$f15_3=$row_kingslanding->sub15_3g;}
echo $f15_1+
$row_kingslanding->sub15_2g+$f15_3; echo "'>
</td>

<td>"; sub3($row_kingslanding->sub13_1g,$row_kingslanding->sub13_2g,$row_kingslanding->sub13_3g); echo "
<input type='hidden' name='sub13".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub13_1g,$row_kingslanding->sub13_2g,$row_kingslanding->sub13_3g); 

echo "'>
<input type='hidden' name='sub13a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub13_1g=="x"){$f13_1=0;}else{$f13_1=$row_kingslanding->sub13_1g;}
if($row_kingslanding->sub13_2g=="x"){$f13_2=0;}else{$f13_2=$row_kingslanding->sub13_2g;}
if($row_kingslanding->sub13_3g=="x"){$f13_3=0;}else{$f13_3=$row_kingslanding->sub13_3g;}
echo $f13_1+$f13_2+$f13_3; echo "'></td>


<td>"; sub4($row_kingslanding->sub14_1g,$row_kingslanding->sub14_2g,$row_kingslanding->sub14_3g,$row_kingslanding->sub14_4g); echo "
<input type='hidden' name='sub14".$row_kingslanding->autoid."' value='"; vsub4($row_kingslanding->sub14_1g,$row_kingslanding->sub14_2g,$row_kingslanding->sub14_3g,$row_kingslanding->sub14_4g); 

echo "'>
<input type='hidden' name='sub14a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub14_1g=="x"){$f14_1=0;}else{$f14_1=$row_kingslanding->sub14_1g;}
if($row_kingslanding->sub14_2g=="x"){$f14_2=0;}else{$f14_2=$row_kingslanding->sub14_2g;}
if($row_kingslanding->sub14_3g=="x"){$f14_3=0;}else{$f14_3=$row_kingslanding->sub14_3g;}
if($row_kingslanding->sub14_4g=="x"){$f14_4=0;}else{$f14_4=$row_kingslanding->sub14_3g;}

echo $f14_1+$f14_2+$f14_3+$f14_4; echo "'></td>
<td>"; 

echo nsub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g) + nsub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g) + nsub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g) + nsub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g) + nsub4($row_kingslanding->sub10_1g,$row_kingslanding->sub10_2g,$row_kingslanding->sub10_3g,$row_kingslanding->sub10_4g) + nsub3($row_kingslanding->sub15_1g,$row_kingslanding->sub15_2g,$row_kingslanding->sub15_3g) + nsub3($row_kingslanding->sub13_1g,$row_kingslanding->sub13_2g,$row_kingslanding->sub13_3g) + nsub4($row_kingslanding->sub14_1g,$row_kingslanding->sub14_2g,$row_kingslanding->sub14_3g,$row_kingslanding->sub14_4g) + $ngp + $nict + $nsm;

echo "
<input type='hidden' name='totalpoints".$row_kingslanding->autoid."' value='"; 
echo nsub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g) + nsub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g) + nsub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g) + nsub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g) + nsub4($row_kingslanding->sub10_1g,$row_kingslanding->sub10_2g,$row_kingslanding->sub10_3g,$row_kingslanding->sub10_4g) + nsub3($row_kingslanding->sub15_1g,$row_kingslanding->sub15_2g,$row_kingslanding->sub15_3g) + nsub3($row_kingslanding->sub13_1g,$row_kingslanding->sub13_2g,$row_kingslanding->sub13_3g) + nsub4($row_kingslanding->sub14_1g,$row_kingslanding->sub14_2g,$row_kingslanding->sub14_3g,$row_kingslanding->sub14_4g) + $ngp + $nict + $nsm;
echo "'>

</td>";
}elseif($astream=="sciences"){
    echo "
<td>"; sub3($row_kingslanding->sub16_1g,$row_kingslanding->sub16_2g,$row_kingslanding->sub16_3g); 
echo "
<input type='hidden' name='sub16".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub16_1g,$row_kingslanding->sub16_2g,$row_kingslanding->sub16_3g); 

echo "'>
<input type='hidden' name='sub16a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub16_1g=="x"){$f16_1=0;}else{$f16_1=$row_kingslanding->sub16_1g;}
if($row_kingslanding->sub16_2g=="x"){$f16_2=0;}else{$f16_2=$row_kingslanding->sub16_2g;}
if($row_kingslanding->sub16_3g=="x"){$f16_3=0;}else{$f16_3=$row_kingslanding->sub16_3g;}
echo $f16_1+$f16_2+$f16_3; echo "'></td>

<td>"; sub3($row_kingslanding->sub17_1g,$row_kingslanding->sub17_2g,$row_kingslanding->sub17_3g); echo "
<input type='hidden' name='sub17".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub17_1g,$row_kingslanding->sub17_2g,$row_kingslanding->sub17_3g); 

echo "'>
<input type='hidden' name='sub17a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub17_1g=="x"){$f17_1=0;}else{$f17_1=$row_kingslanding->sub17_1g;}
if($row_kingslanding->sub17_2g=="x"){$f17_2=0;}else{$f17_2=$row_kingslanding->sub17_2g;}
if($row_kingslanding->sub17_3g=="x"){$f17_3=0;}else{$f17_3=$row_kingslanding->sub17_3g;}
echo $f17_1+$f17_2+$f17_3; echo "'></td>

<td>"; sub3($row_kingslanding->sub18_1g,$row_kingslanding->sub18_2g,$row_kingslanding->sub18_3g); echo "
<input type='hidden' name='sub18".$row_kingslanding->autoid."' value='"; vsub3($row_kingslanding->sub18_1g,$row_kingslanding->sub18_2g,$row_kingslanding->sub18_3g); 
echo "'>
<input type='hidden' name='sub18a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub18_1g=="x"){$f18_1=0;}else{$f18_1=$row_kingslanding->sub18_1g;}
if($row_kingslanding->sub18_2g=="x"){$f18_2=0;}else{$f18_2=$row_kingslanding->sub18_2g;}
if($row_kingslanding->sub18_3g=="x"){$f18_3=0;}else{$f18_3=$row_kingslanding->sub18_3g;}
echo $f18_1+$f18_2+$f18_3; echo "'></td>



<td>"; sub2($row_kingslanding->sub19_1g,$row_kingslanding->sub19_2g); echo "
<input type='hidden' name='sub19".$row_kingslanding->autoid."' value='"; vsub2($row_kingslanding->sub19_1g,$row_kingslanding->sub19_2g); 
echo "'>
<input type='hidden' name='sub19a".$row_kingslanding->autoid."' value='"; 

if($row_kingslanding->sub19_1g=="x"){$f19_1=0;}else{$f19_1=$row_kingslanding->sub19_1g;}
if($row_kingslanding->sub19_2g=="x"){$f19_2=0;}else{$f19_2=$row_kingslanding->sub19_2g;}
echo $f19_1+$f19_2; echo "'></td>
<td>";
echo nsub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g) + nsub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g) + nsub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g) + nsub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g) + nsub3($row_kingslanding->sub16_1g,$row_kingslanding->sub16_2g,$row_kingslanding->sub16_3g) + nsub3($row_kingslanding->sub17_1g,$row_kingslanding->sub17_2g,$row_kingslanding->sub17_3g) + nsub3($row_kingslanding->sub18_1g,$row_kingslanding->sub18_2g,$row_kingslanding->sub18_3g) + nsub2($row_kingslanding->sub19_1g,$row_kingslanding->sub19_2g) + $ngp + $nict + $nsm;


echo "
<input type='hidden' name='totalpoints".$row_kingslanding->autoid."' value='"; 
echo nsub2($row_kingslanding->sub20_1g,$row_kingslanding->sub20_2g) + nsub3($row_kingslanding->sub11_1g,$row_kingslanding->sub11_2g,$row_kingslanding->sub11_3g) + nsub3($row_kingslanding->sub12_1g,$row_kingslanding->sub12_2g,$row_kingslanding->sub12_3g) + nsub4($row_kingslanding->sub21_1g,$row_kingslanding->sub21_2g,$row_kingslanding->sub21_3g,$row_kingslanding->sub21_4g) + nsub3($row_kingslanding->sub16_1g,$row_kingslanding->sub16_2g,$row_kingslanding->sub16_3g) + nsub3($row_kingslanding->sub17_1g,$row_kingslanding->sub17_2g,$row_kingslanding->sub17_3g) + nsub3($row_kingslanding->sub18_1g,$row_kingslanding->sub18_2g,$row_kingslanding->sub18_3g) + nsub2($row_kingslanding->sub19_1g,$row_kingslanding->sub19_2g) + $ngp + $nict + $nsm;
echo "'></td>";
}

echo "

</tr>";
}while($row_kingslanding = $result_kingslanding->fetchObject());
}else{
    echo "
<tr>
<td colspan='30' align='center'><i><b>There is NO data in the table so far.</b></i> </td>
</tr>";
}

echo "
</tbody>
</table>
</div></div>
</div>
</form>
</div>";
}else{
    echo "<div style='float:right;' class='alert alert-success'>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>
