<?php 
include ("kfunctions.php"); 
?>
<html>
<head>
<?php kheader(); ?>
<?php 
require_once("connect.php");

?>

<script src="js/printreport.js"></script>
<script src="js/sorttable.js"></script>
<?php
include("connect.php");
$result_scrapft=$dbh->prepare("select * from scrap where item3='ftype' and type='reportedit'");
$result_scrapft->execute();
$row_scrapft=$result_scrapft->fetchObject();
$count_scrapft=$result_scrapft->rowCount();
?>
<style>
.reptit{
color:#0066cc;
font-family: <?php echo $row_scrapft->item; ?>;
}
.table > tbody > tr > td, .table > tbody > tr > th, .table > tfoot > tr > td, .table > tfoot > tr > th, .table > thead > tr > td, .table > thead > tr > th {
    padding: 2px !important;
    line-height: 1 !important;}
</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-12">
                        <div class="panel panel-default">
               <div class="panel-body">
<div class='col-lg-12'>
Font
</div>
<div class='col-lg-2'>
<?php 

include("connect.php");
$result_scrapts=$dbh->prepare("select * from scrap where item3='tsize' and type='reportedit'");
$result_scrapts->execute();
$row_scrapts=$result_scrapts->fetchObject();
$count_scrapts=$result_scrapts->rowCount();

if(isset($_POST["tsize"])){
$tsize=$_POST["tsize"];

if($count_scrapts>0){
$update_user=$dbh->prepare("update scrap set item='$tsize' where item3='tsize' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$tsize','tsize','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}

echo "
<form method='post'>
Title size
<select class='form-control' name='tsize' onchange='this.form.submit()'>";

if($count_scrapts>0){echo "<option value='".$row_scrapts->item."'>".$row_scrapts->item."</option>";}
else{echo "<option value=''>Title</option>";}

for($x=9;$x<=100;$x++){
echo "<option value='".$x."'>".$x."</option>";
}

echo "
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapus=$dbh->prepare("select * from scrap where item3='usize' and type='reportedit'");
$result_scrapus->execute();
$row_scrapus=$result_scrapus->fetchObject();
$count_scrapus=$result_scrapus->rowCount();

if(isset($_POST["usize"])){
$usize=$_POST["usize"];

if($count_scrapus>0){
$update_user=$dbh->prepare("update scrap set item='$usize' where item3='usize' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$usize','usize','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}
echo "
Upper table
<form method='post'>
<select class='form-control' name='usize' onchange='this.form.submit()'>";
if($count_scrapus>0){echo "<option value='".$row_scrapus->item."'>".$row_scrapus->item."</option>";}
else{echo "<option value=''>Upper table</option>";}

for($x=9;$x<=100;$x++){
echo "<option value='".$x."'>".$x."</option>";
}

echo "
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapls=$dbh->prepare("select * from scrap where item3='lsize' and type='reportedit'");
$result_scrapls->execute();
$row_scrapls=$result_scrapls->fetchObject();
$count_scrapls=$result_scrapls->rowCount();

if(isset($_POST["lsize"])){
$lsize=$_POST["lsize"];

if($count_scrapls>0){
$update_user=$dbh->prepare("update scrap set item='$lsize' where item3='lsize' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$lsize','lsize','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}

echo "
Lower table
<form method='post'>
<select class='form-control' name='lsize' onchange='this.form.submit()'>";
if($count_scrapls>0){echo "<option value='".$row_scrapls->item."'>".$row_scrapls->item."</option>";}
else{echo "<option value=''>Lower table</option>";}

for($x=9;$x<=100;$x++){
echo "<option value='".$x."'>".$x."</option>";
}

echo "
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapcs=$dbh->prepare("select * from scrap where item3='csize' and type='reportedit'");
$result_scrapcs->execute();
$row_scrapcs=$result_scrapcs->fetchObject();
$count_scrapcs=$result_scrapcs->rowCount();

if(isset($_POST["csize"])){
$csize=$_POST["csize"];

if($count_scrapcs>0){
$update_user=$dbh->prepare("update scrap set item='$csize' where item3='csize' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$csize','csize','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}

echo "
Comment table
<form method='post'>
<select class='form-control' name='csize' onchange='this.form.submit()'>";
if($count_scrapcs>0){echo "<option value='".$row_scrapcs->item."'>".$row_scrapcs->item."</option>";}
else{echo "<option value=''>Comment table</option>";}

for($x=9;$x<=100;$x++){
echo "<option value='".$x."'>".$x."</option>";
}

echo "
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapgs=$dbh->prepare("select * from scrap where item3='gsize' and type='reportedit'");
$result_scrapgs->execute();
$row_scrapgs=$result_scrapgs->fetchObject();
$count_scrapgs=$result_scrapgs->rowCount();

if(isset($_POST["gsize"])){
$gsize=$_POST["gsize"];

if($count_scrapgs>0){
$update_user=$dbh->prepare("update scrap set item='$gsize' where item3='gsize' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$gsize','gsize','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}

echo "
Grade size
<form method='post'>
<select class='form-control' name='gsize' onchange='this.form.submit()'>";
if($count_scrapgs>0){echo "<option value='".$row_scrapgs->item."'>".$row_scrapgs->item."</option>";}
else{echo "<option value=''>Grade table</option>";}

for($x=9;$x<=100;$x++){
echo "<option value='".$x."'>".$x."</option>";
}

echo "
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapft=$dbh->prepare("select * from scrap where item3='ftype' and type='reportedit'");
$result_scrapft->execute();
$row_scrapft=$result_scrapft->fetchObject();
$count_scrapft=$result_scrapft->rowCount();

if(isset($_POST["ftype"])){
$ftype=$_POST["ftype"];

if($count_scrapft>0){
$update_user=$dbh->prepare("update scrap set item='$ftype' where item3='ftype' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$ftype','ftype','reportedit')");
$insert_user->execute();
}
header("location:reportedit.php");
}

echo "
Font type
<form method='post'>
<select class='form-control' name='ftype' onchange='this.form.submit()'>";
if($count_scrapft>0){echo "<option value='".$row_scrapft->item."'>".$row_scrapft->item."</option>";}
else{echo "<option value=''>Font type</option>";}
echo "
<option value='Times new Romans'>Times new Romans</option>
<option value='Brush Script MT'>Brush Script MT</option>
<option value='Cambria'>Cambria</option>
</select>
</form>
</div>
<div class='col-lg-2'>";

$result_scrapwm=$dbh->prepare("select * from scrap where item3='wmark' and type='reportedit'");
$result_scrapwm->execute();
$row_scrapwm=$result_scrapwm->fetchObject();
$count_scrapwm=$result_scrapwm->rowCount();

if(isset($_POST["wmark"])){
$wmark=$_POST["wmark"];

if($count_scrapwm>0){
$update_user=$dbh->prepare("update scrap set item='$wmark' where item3='wmark' and type='reportedit'");
$update_user->execute();
}else{
$insert_user=$dbh->prepare("insert into scrap (item,item3,type) values('$wmark','wmark','reportedit')");
$insert_user->execute();

}
header("location:reportedit.php");
}

echo "
Watermark
<form method='post'>
<select class='form-control' name='wmark' onchange='this.form.submit()'>";
if($count_scrapwm>0){
if($row_scrapwm->item==1){$wmout="Show watermark";}
elseif($row_scrapwm->item==0){$wmout="Don't Show watermark";}

echo "<option value='".$row_scrapwm->item."'>".$wmout."</option>";}
else{echo "<option value='0'>Water mark</option>";}

echo "
<option value='1'>Show </option>
<option value='0'>Don't Show </option>
</select>
</form>
</div>
<div class='col-lg-2'>
Comment level
<form method='post'>
<select class='form-control' name='comments' onchange='this.form.submit()'>
<option value=''>Level comment</option>
<option value='pcacomment'>O level Class teacher</option>
<option value='phacomment'>O level Head teacher</option>
<option value='cacomment'>A level Class teacher</option>
<option value='hacomment'>A level Head teacher</option>
</select>
</form>
</div>
<div class='col-lg-2'>
Report level display
<form method='post'>
<select class='form-control' name='reportlevel' onchange='this.form.submit()'>
<option value=''>Report level</option>
<option value='olevel'>O level</option>
<option value='alevel'>A level</option>
</select>
</form>
</div>";

if(isset($_POST["setdefault"])){
$insert_userts=$dbh->prepare("insert into scrap (item,item3,type) values('20','tsize','reportedit')");
$insert_userts->execute();
$insert_userus=$dbh->prepare("insert into scrap (item,item3,type) values('16','usize','reportedit')");
$insert_userus->execute();
$insert_userls=$dbh->prepare("insert into scrap (item,item3,type) values('16','lsize','reportedit')");
$insert_userls->execute();
$insert_usercs=$dbh->prepare("insert into scrap (item,item3,type) values('16','csize','reportedit')");
$insert_usercs->execute();
$insert_usergs=$dbh->prepare("insert into scrap (item,item3,type) values('16','gsize','reportedit')");
$insert_usergs->execute();
$insert_userft=$dbh->prepare("insert into scrap (item,item3,type) values('16','ftype','reportedit')");
$insert_userft->execute();
$insert_userwm=$dbh->prepare("insert into scrap (item,item3,type) values('1','wmark','reportedit')");
$insert_userwm->execute();

header("location:reportedit.php");
}

$result_scraprept=$dbh->prepare("select * from scrap where type='reportedit'");
$result_scraprept->execute();
$row_scraprept=$result_scraprept->fetchObject();
$count_scraprept=$result_scraprept->rowCount();

if($count_scraprept==0){
echo "
<form method='post'>
<div style='float:right;' class='col-lg-2'>
Set default<br>
<input type='submit' name='setdefault' class='btn btn-sm btn-primary' value='Set'>
</div>
</form>";}

?>
</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='#cord4' aria-expanded='false' class='collapsed'>Comment edit</a>
        </h4>
      </div>
      <div id='cord4' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>
        <div class='panel-body'>
<?php
if(isset($_POST["submit_comment"])){
$comments=$_POST["comments"];

include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where type='$comments'");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
    do{
$comment=$_POST["comment".$row_scrap->autoid.""];
$update_scrap=$dbh->prepare("update scrap set item3='$comment' where type='$comments' and item='$row_scrap->item' and item2='$row_scrap->item2'");
$update_scrap->execute();

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


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

echo "
<table class='table'>
<tr>
    <td align='center'>From</td>
    <td align='center'>To</td>
    <td align='center'>Comment</td>
    <td align='center'>Owner</td>
</tr>";

$comments=$_POST["comments"];

include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where type='$comments'");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();


if($count_scrap>0){
    $x=1;
echo "<form method='post'>
<input type='hidden' name='comments' value='".$comments."'>
<input type='submit' class='btn btn-sm btn-primary' style='float:right' name='submit_comment' value='Submit'>";
do{
echo "<tr>
<td align='center'>".$row_scrap->item."</td>
<td align='center'>".$row_scrap->item2."</td>
<td><input type='text' class='form-control' name='comment".$row_scrap->autoid."' value='".$row_scrap->item3."'></td>
<td align='center'>"; 
if($row_scrap->type=="cacomment"){echo "(A level) Class teacher";}
elseif($row_scrap->type=="hacomment"){echo "(A level) Head teacher";}
elseif($row_scrap->type=="pcacomment"){echo "(O level) Class teacher";}
elseif($row_scrap->type=="phacomment"){echo "(O level) Head teacher";}

echo "</td>
</tr>";
}while($row_scrap=$result_scrap->fetchObject());
echo "</form>";
}else{
    echo "<tr>
    <td align='center' colspan='4'>There is NO data in this table. </td>
    </tr>";
}
echo "</table>";
}else{
echo "Select  the 'Comment level' Field";
}
?>

</div>
</div>
</div>
</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='#cord9' aria-expanded='false' class='collapsed'>Report display</a>
        </h4>
      </div>
      <div id='cord9' class='panel-collapse collapse' aria-expanded='false' style='height: 0px;'>
        <div class='panel-body'>
<?php
if(isset($_POST["submit_reportlevel"])){
$reportlevel=$_POST["reportlevel"];
if($reportlevel=="olevel"){$selectors="type='secclas' and (item>=21 and item<25)";}
elseif($reportlevel=="alevel"){$selectors="type='secclas' and item>=25";}

include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where $selectors");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
do{
$clas=$_POST["clas"];

if($reportlevel=="olevel"){
if(isset($_POST["total"])){$total=$_POST["total"];}else{$total=0;}
if(isset($_POST["averagemark"])){$averagemark=$_POST["averagemark"];}else{$averagemark=0;}
if(isset($_POST["positionclass"])){$positionclass=$_POST["positionclass"];}else{$positionclass=0;}
if(isset($_POST["positionstream"])){$positionstream=$_POST["positionstream"];}else{$positionstream=0;}

//total
$result_scrapt=$dbh->prepare("select * from scrap where item='total' and item3='$clas' and type='reportdown'");
$result_scrapt->execute();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt==0 and $clas!=0){
$insert_scrapt=$dbh->prepare("insert into scrap (item,item2,item3,item4,type) values('total','$total','$clas','','reportdown')");
$insert_scrapt->execute();  

}else{
$update_scrapt=$dbh->prepare("update scrap set item2='$total' where item='total' and item3='$clas' and type='reportdown'");
$update_scrapt->execute();
}
//total

//averagemark
$result_scrapt=$dbh->prepare("select * from scrap where item='averagemark' and item3='$clas' and type='reportdown'");
$result_scrapt->execute();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt==0 and $clas!=0){
$insert_scrapt=$dbh->prepare("insert into scrap (item,item2,item3,item4,type) values('averagemark','$averagemark','$clas','','reportdown')");
$insert_scrapt->execute();  

}else{
$update_scrapt=$dbh->prepare("update scrap set item2='$averagemark' where item='averagemark' and item3='$clas' and type='reportdown'");
$update_scrapt->execute();
}
//averagemark

//positionclass
$result_scrapt=$dbh->prepare("select * from scrap where item='positionclass' and item3='$clas' and type='reportdown'");
$result_scrapt->execute();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt==0 and $clas!=0){
$insert_scrapt=$dbh->prepare("insert into scrap (item,item2,item3,item4,type) values('positionclass','$positionclass','$clas','','reportdown')");
$insert_scrapt->execute();  

}else{
$update_scrapt=$dbh->prepare("update scrap set item2='$positionclass' where item='positionclass' and item3='$clas' and type='reportdown'");
$update_scrapt->execute();
}
//positionclass

//positionstream
$result_scrapt=$dbh->prepare("select * from scrap where item='positionstream' and item3='$clas' and type='reportdown'");
$result_scrapt->execute();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt==0 and $clas!=0){
$insert_scrapt=$dbh->prepare("insert into scrap (item,item2,item3,item4,type) values('positionstream','$positionstream','$clas','','reportdown')");
$insert_scrapt->execute();  

}else{
$update_scrapt=$dbh->prepare("update scrap set item2='$positionstream' where item='positionstream' and item3='$clas' and type='reportdown'");
$update_scrapt->execute();
}
//positionstream
}else{
if(isset($_POST["totalpts"])){$totalpts=$_POST["totalpts"];}else{$totalpts=0;}

//totalpts
$result_scrapt=$dbh->prepare("select * from scrap where item='totalpts' and item3='$clas' and type='reportdown'");
$result_scrapt->execute();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt==0 and $clas!=0){
$insert_scrapt=$dbh->prepare("insert into scrap (item,item2,item3,item4,type) values('totalpts','$totalpts','$clas','','reportdown')");
$insert_scrapt->execute();  

}else{
$update_scrapt=$dbh->prepare("update scrap set item2='$totalpts' where item='totalpts' and item3='$clas' and type='reportdown'");
$update_scrapt->execute();
}
//totalpts
}

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

}

}

if(isset($_POST["reportlevel"])){
$reportlevel=$_POST["reportlevel"];
if($reportlevel=="olevel"){$selectors="type='secclas' and (item>=21 and item<25)";}
elseif($reportlevel=="alevel"){$selectors="type='secclas' and item>=25";}

include("connect.php");
$result_scrap=$dbh->prepare("select * from scrap where $selectors");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();


echo "<form method='post'>
<input type='hidden' name='reportlevel' value='".$reportlevel."'>";
if($count_scrap>0){
do{
echo "<div class='col-lg-3'>
<div class='panel panel-yellow'>
<div class='panel-body'>"; ?>
<input type="radio" name="clas" onclick="fetchdata('<?php echo $row_scrap->item; ?>')" value='<?php echo $row_scrap->item; ?>'> &nbsp;&nbsp;&nbsp;&nbsp;<?php echo $row_scrap->item2; ?>
<?php
echo "
</div></div>
</div>";
}while($row_scrap=$result_scrap->fetchObject());
}else{echo "Please contact your IT department.";}

if($reportlevel=="olevel"){
 echo "<div class='col-lg-3'>
<div class='col-lg-12'><br></div>
<div class='panel panel-primary'>
<div class='panel-body'>
<input type='checkbox' name='total' id='total' value='1'> &nbsp;&nbsp;&nbsp;&nbsp;Total
</div></div>
</div>
<div class='col-lg-3'>
<div class='panel panel-primary'>
<div class='panel-body'>
<input type='checkbox' name='averagemark' id='averagemark' value='1'> &nbsp;&nbsp;&nbsp;&nbsp;Average Mark
</div></div>
</div>
<div class='col-lg-3'>
<div class='panel panel-primary'>
<div class='panel-body'>
<input type='checkbox' name='positionclass' id='positionclass' value='1'> &nbsp;&nbsp;&nbsp;&nbsp;Position in class
</div></div>
</div>
<div class='col-lg-3'>
<div class='panel panel-primary'>
<div class='panel-body'>
<input type='checkbox' name='positionstream' id='positionstream' value='1'> &nbsp;&nbsp;&nbsp;&nbsp;Position in stream</div></div>
</div>";
}elseif($reportlevel=="alevel"){
echo "
<div class='col-lg-12'><br></div>
<div class='col-lg-3'>
<div class='panel panel-primary'>
<div class='panel-body'>
<input type='checkbox' name='totalpts' id='totalpts' value='1'> &nbsp;&nbsp;&nbsp;&nbsp;Total points
</div></div>
</div>";
}
echo "<input type='submit' class='btn btn-sm btn-primary' name='submit_reportlevel' value='Submit'>
</form>";
?>

<script>
function fetchdata(clas){
<?php
$result_scrap=$dbh->prepare("select * from scrap where type='secclas'");
$result_scrap->execute();
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();
if($count_scrap>0){
    do{
?>
if(clas == <?php echo $row_scrap->item; ?>){
<?php
if($reportlevel=="olevel"){
//total
$result_scrapt=$dbh->prepare("select * from scrap where item='total' and item3='$row_scrap->item' and type='reportdown'");
$result_scrapt->execute();
$row_scrapt=$result_scrapt->fetchObject();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt>0 and $row_scrapt->item2==1){
?>
document.getElementById("total").checked=true;
<?php }else{ ?>
document.getElementById("total").checked=false;
<?php } 
//total 

//averagemark
$result_scrapt=$dbh->prepare("select * from scrap where item='averagemark' and item3='$row_scrap->item' and type='reportdown'");
$result_scrapt->execute();
$row_scrapt=$result_scrapt->fetchObject();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt>0 and $row_scrapt->item2==1){
?>
document.getElementById("averagemark").checked=true;
<?php }else{ ?>
document.getElementById("averagemark").checked=false;
<?php } 
//averagemark

//positionclass
$result_scrapt=$dbh->prepare("select * from scrap where item='positionclass' and item3='$row_scrap->item' and type='reportdown'");
$result_scrapt->execute();
$row_scrapt=$result_scrapt->fetchObject();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt>0 and $row_scrapt->item2==1){
?>
document.getElementById("positionclass").checked=true;
<?php }else{ ?>
document.getElementById("positionclass").checked=false;
<?php } 
//positionclass

//positionstream
$result_scrapt=$dbh->prepare("select * from scrap where item='positionstream' and item3='$row_scrap->item' and type='reportdown'");
$result_scrapt->execute();
$row_scrapt=$result_scrapt->fetchObject();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt>0 and $row_scrapt->item2==1){
?>
document.getElementById("positionstream").checked=true;
<?php }else{ ?>
document.getElementById("positionstream").checked=false;
<?php } 
//positionstream
}elseif($reportlevel=="alevel"){
//totalpts
$result_scrapt=$dbh->prepare("select * from scrap where item='totalpts' and item3='$row_scrap->item' and type='reportdown'");
$result_scrapt->execute();
$row_scrapt=$result_scrapt->fetchObject();
$count_scrapt=$result_scrapt->rowCount();

if($count_scrapt>0 and $row_scrapt->item2==1){
?>
document.getElementById("totalpts").checked=true;
<?php }else{ ?>
document.getElementById("totalpts").checked=false;
<?php } 
//totalpts 
} ?>
}

<?php 
}while($row_scrap=$result_scrap->fetchObject());
}
?>
}
</script>
<?php
}else{
    echo "Select the 'Report level display' Field";
}
?>
</div>
</div>
</div>
</div>
 <div class="col-lg-12">
                        <div class="panel panel-default">
                            <div class="panel-body">
<?php

$result_kingslandingcid=$dbh->query("select distinct(cid) from rivendell where schoolclass='26' and active='1' order by cid asc");
$row_kingslandingcid=$result_kingslandingcid->fetchObject();
$count_kingslandingcid=$result_kingslandingcid->rowCount();


$result_scrapwm=$dbh->prepare("select * from scrap where item3='wmark' and type='reportedit'");
$result_scrapwm->execute();
$row_scrapwm=$result_scrapwm->fetchObject();
$count_scrapwm=$result_scrapwm->rowCount();


if($count_scrapwm>0 and $row_scrapwm->item==1){$bgimg="background-image:url(img/codehsbkg.png);background-size: 100%;";}
else{$bgimg="";}

echo "<page size='A4'>
<div style='".$bgimg."'>";

$result_kingslanding=$dbh->query("select * from rivendell where cid='$row_kingslandingcid->cid' and active='1'");
$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='reports'");
$row_scrap1=$result_scrap1->fetchObject();

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

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

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

$result_scrapts=$dbh->prepare("select * from scrap where item3='tsize' and type='reportedit'");
$result_scrapts->execute();
$row_scrapts=$result_scrapts->fetchObject();
$count_scrapts=$result_scrapts->rowCount();

$smaller=$row_scrapts->item/1.3;
echo "
<div style='height:297mm; width:210mm;  margin-left:auto; margin-right: auto; margin-top: 30px; margin-bottom: auto;'>
<table class='table'>
<tr>
<td width='20%' align='center' width='10%'>
<img src='img/chsbadgefinal.png' style='height:150px;width:200px;'>
</td>
<td align='center'>
<b style='font-size:".$row_scrapts->item."px;font-family:Times New Roman;color:#0066cc;'>".$row_scrap1->item."</b><br>
<b style='font-size:".$row_scrapts->item."px;font-family:Times New Roman;color:#0066cc; text-align:right'>".$row_scrap2->item."</b>
<br>
<div style='font-size:".$smaller."px;font-family:Times New Roman;color:#0066cc;'><b>".$row_scrap3->item."</div><br>
<div style='font-size:".$smaller."px;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>
echo "
</td>

</tr>
<tr>
<td colspan='3'>
<hr style='border-width:5px;border-color:black;'>
</td>
</tr>";

$result_scrapus=$dbh->prepare("select * from scrap where item3='usize' and type='reportedit'");
$result_scrapus->execute();
$row_scrapus=$result_scrapus->fetchObject();
$count_scrapus=$result_scrapus->rowCount();

echo "
</table>
<table class='table' border='1' style='font-size:".$row_scrapus->item."px;'>
<tr>
<td class='reptit'><b>Name</b>: ".$row_children->fname." ".$row_children->sname."</td>

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

<td class='reptit'><b>CLASS</b>: ".$daclass."</td>
<td class='reptit'><b>Stream</b>: ".$row_kingslanding->stream."</td>

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

$result_scrapls=$dbh->prepare("select * from scrap where item3='lsize' and type='reportedit'");
$result_scrapls->execute();
$row_scrapls=$result_scrapls->fetchObject();
$count_scrapls=$result_scrapls->rowCount();

echo "
<table border='2' class='table' style='font-size:".$row_scrapls->item."px;'>";

$result_examset=$dbh->query("select * from examsets where setid='set180421043942' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();
    
echo "
<tr>
<td class='reptit' width='10%' rowspan='2' align='center'><b>Paper code</b></td>
<td class='reptit' width='20%' rowspan='2' align='center'><b>SUBJECT</b></td>
<td class='reptit' width='5%' rowspan='2' align='center'><b>PAPER</b></td>";

if($count_examset>0){
do{
echo " 
<td class='reptit' align='center' colspan='3' width='30%'><b>".$row_examset->setname."</b></td>";
}while($row_examset=$result_examset->fetchObject());
}

echo "
<td class='reptit' rowspan='2' align='center'><b>COMMENTS</b></td>
<td class='reptit' rowspan='2' align='center'><b>INITIALS</b></td>
</tr>
<tr>";


$result_examset=$dbh->query("select * from examsets where setid='set180421043942' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
do{
echo " 
<td class='reptit' align='center'><b>Marks (%)</b></td>
<td class='reptit' align='center'><b>AGG.</b></td>
<td class='reptit' align='center'><b>Grade</b></td>";
}while($row_examset=$result_examset->fetchObject());
}

echo "
</tr>";


$result_scrapdis=$dbh->query("select distinct(item3) from scrap where type='secsuba'");
$row_scrapdis=$result_scrapdis->fetchObject();
$count_scrapdis=$result_scrapdis->rowCount();

if($count_scrapdis>0){
$z=1;
do{
$result_scrap=$dbh->query("select * from scrap where item3='$row_scrapdis->item3'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

    $fsub=$row_scrap->item."m";
    $gsub=$row_scrap->item."g";
    $tr=$row_scrap->item."x";
    $fitem=substr($row_scrap->item,0,6);


//rivendell = true
if($fitem=="sub10_"){$fsum="((sub10_1m>='0' && sub10_1m!='N') || (sub10_2m>='0' && sub10_2m!='N') || (sub10_3m>='0' && sub10_3m!='N') || (sub10_4m>='0') && sub10_4m!='N')";}
else{$fsum="($fsub>=0 and $fsub!='N')";}

$result_kings=$dbh->query("select * from rivendell where $fsum and cid='$row_kingslanding->cid' and active='1' order by autoid desc");
$row_kings=$result_kings->fetchObject();
$count_kings=$result_kings->rowCount();

if($count_kings>0){
echo "
<tr>
<td class='reptit' width='10%' align='center' rowspan='".$count_scrap."'><b>".$row_scrap->item3."</b></td>
<td class='reptit' rowspan='".$count_scrap."'><b>".$row_scrap->item2."</b></td>
<td class='reptit' align='center'>1</td>";

//selected sets = true
$result_examset=$dbh->query("select * from examsets where setid='set180421043942' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){
    do{
if($fitem=="sub10_"){$fsum="(sub10_1m>='0' || sub10_2m>='0' || sub10_3m>='0' || sub10_4m>='0')";}
else{$fsum="($fsub>=0 and $fsub!='N')";}

$result_kingsexam=$dbh->query("select * from rivendell where $fsum and setid='$row_examset->setid' and cid='$row_kingslanding->cid' and active='1'");
$row_kingsexam=$result_kingsexam->fetchObject();
$count_kingsexam=$result_kingsexam->rowCount();


if($count_kingsexam>0){
$fletter=$fitem."letter";
$fpoints=$fitem."points";
if($fitem=="sub22_" || $fitem=="sub23_"  || $fitem=="sub24_"){$fmarks=$fitem."m";$fgrade= $fitem."g"; $ffletter=$row_kingsexam->$fpoints;}
else{$fmarks= $fitem."1m";$fgrade= $fitem."1g"; $ffletter=$row_kingsexam->$fletter;}
if($row_kingsexam->$fmarks=="N"){$ffmark="";}else{$ffmark=$row_kingsexam->$fmarks;}

echo "<td class='reptit' align='center'>".$ffmark."</td>
<td class='reptit' align='center'>".$row_kingsexam->$fgrade."</td>
<td class='reptit' align='center' rowspan='".$count_scrap."'>".$ffletter."</td>";}

else{echo "<td class='reptit'></td><td class='reptit'></td><td class='reptit'></td>";}
}while($row_examset=$result_examset->fetchObject());
}
//selected sets = false

//Comments and initials
if($count_kingsexam>0){

$result_scrapl=$dbh->query("select * from scrap where item='$ffletter' and type='aletter'");
$row_scrapl=$result_scrapl->fetchObject();
$count_scrapl=$result_scrapl->rowCount();

if($count_scrapl>0){$commenttoshow=$row_scrapl->item3;}else{$commenttoshow='';}


}else {$commenttoshow='';}

echo " 
<td class='reptit' rowspan='".$count_scrap."' align='center'>".$commenttoshow."</td>
<td class='reptit' align='center' rowspan='".$count_scrap."' align='center'>".$row_kingslanding->$tr."</td>
</tr>";
//Comments and initials

//for loop
$other=$count_scrap-1;
for($x=1;$x<=$other;$x++){
$y=$x+1;
//selected Sets
$result_examset=$dbh->query("select * from examsets where setid='set180421043942' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

if($count_examset>0){

if($fitem=="sub10_" and $y=="4"){$fy="6";}else{$fy=$y;}
    echo "
<tr>
<td class='reptit' align='center'>".$fy."</td>";
    do{
        if($fitem=="sub10_"){$fsum="(sub10_1m>='0' || sub10_2m>='0' || sub10_3m>='0' || sub10_4m>='0')";}
else{$fsum="($fsub>=0 and $fsub!='N')";}

$result_kingsexam=$dbh->query("select * from rivendell where $fsum and setid='$row_examset->setid' and cid='$row_kingslanding->cid' and active='1'");
$row_kingsexam=$result_kingsexam->fetchObject();
$count_kingsexam=$result_kingsexam->rowCount();

if($count_kingsexam>0){
$fmarks= $fitem.$y."m";
$fgrade= $fitem.$y."g";

//N = true
if($row_kingsexam->$fmarks=="N"){ 
echo "
<td class='reptit' align='center'></td>
<td class='reptit' align='center'></td>";
}else{
echo "
<td class='reptit' align='center'>".$row_kingsexam->$fmarks."</td>
<td class='reptit' align='center'>".$row_kingsexam->$fgrade."</td>";
}
//N = false

}else{
echo "<td class='reptit'></td><td class='reptit'></td><td class='reptit'></td>";}

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

}
//for loop
}

//rivendell = true

}while($row_scrapdis=$result_scrapdis->fetchObject());

echo "
<tr>
<td colspan='3' class='reptit' align='center'><b>Total Points: </b></td>";

//selected Sets
$result_examset=$dbh->query("select * from examsets where setid='set180421043942' order by autoid desc");
$row_examset=$result_examset->fetchObject();
$count_examset=$result_examset->rowCount();

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

echo "
<td class='reptit'></td>
<td class='reptit'></td>
<td class='reptit' align='center'><b>";
$totalpoints=$row_kingsexam->totalpoints;
if($row_kingsexam->totalpoints==""){$totalpoints="0"; echo "0";}{$totalpoints=$row_kingsexam->totalpoints; echo $totalpoints;}
echo "</b></td>";
}while($row_examset=$result_examset->fetchObject());
}
echo "</tr>";

}else{
echo "
<tr>
<td colspan='10'>NO exam set has been submitted yet. </td>
<td></td>
</tr>";
}

$result_scrapcs=$dbh->prepare("select * from scrap where item3='csize' and type='reportedit'");
$result_scrapcs->execute();
$row_scrapcs=$result_scrapcs->fetchObject();
$count_scrapcs=$result_scrapcs->rowCount();

echo "
<table class='table' border='1' style='font-size:".$row_scrapcs->item."px;' class='reptit'>

<tr>
<td width='40%' class='reptit' colspan='2'><b>Class teacher's comment : </b><br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span align='center'>Class teacher comment</span></td>

</tr>
<tr>
</td>
</tr>

<tr>
<td width='40%' class='reptit' colspan='2'><b>Head teacher's comment : </b><br>&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Head teacher comment</td>
</tr>
<tr>
</table>";

$result_scrapgs=$dbh->prepare("select * from scrap where item3='gsize' and type='reportedit'");
$result_scrapgs->execute();
$row_scrapgs=$result_scrapgs->fetchObject();
$count_scrapgs=$result_scrapgs->rowCount();

echo "
<table border='2' class='table'  width='100%' style='font-size:".$row_scrapgs->item."px'>
<tr>";
$result_grades=$dbh->query("select sfrom, sto from grades order by autoid desc");
$row_grades=$result_grades->fetchObject();
$count_grades=$result_grades->rowCount();

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

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

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

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

$result_scrapls=$dbh->prepare("select * from scrap where item3='lsize' and type='reportedit'");
$result_scrapls->execute();
$row_scrapls=$result_scrapls->fetchObject();
$count_scrapls=$result_scrapls->rowCount();

echo "
</div>
<div style='text-align:center;margin-top:-150px;font-size:".$row_scrapls->item."px;' class='reptit'><b><br>&nbsp;<br>&nbsp;<u>This Report Card is not valid without the official School Stamp</u></b></div>
</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>
