<?php 
include ("kfunctions.php");
adminall("overadmin","secadmin","priadmin");
?>

<html>
<head>
<?php kheader(); ?>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
<script src="js/highcharts.js"></script>
<script src="js/exporting.js"></script>
<script src="js/input.js"></script>

<script>
$(function ($) {
    $('#primarychart').highcharts({
    credits: {
            enabled: false
        },
        title: {
            text: 'Commercial Revenue Chart'
        },
        xAxis: {
            categories: ['NTV','Spark','Digital','Totals']
       /* },
        labels: {
            items: [{
                html: 'Month in summary',
                style: {
                    left: '50px',
                    top: '18px',
                    color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
                }
            }]*/
        },
        series: [{
            type: 'column',
            name: 'Booked',
            data: [ 10,10,10,10],
            color: '#00FF00'
        },{
            type: 'column',
            name: 'Sales Target',
            data: [10,10,10,10],
            color: '#000000'
        } 
/*
         {
            type: 'pie',
            name: 'Total consumption',
            data: [{
                name: 'Jane',
                y: 13,
                color: Highcharts.getOptions().colors[0] // Jane's color
            }, {
                name: 'John',
                y: 23,
                color: Highcharts.getOptions().colors[1] // John's color
            }],
            center: [100, 80],
            size: 100,
            showInLegend: false,
            dataLabels: {
                enabled: false
            }
        }*/]
    });
});


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

      

                <!-- /.row -->
<form method="post">               
<div class="col-lg-12">
  <div class="panel panel-yellow">
                <div class="panel-heading">
                                <h3 class="panel-title">View entered marks for students</h3>
                            </div>
                            <div class="panel-body">
<table class="table table-bordered table-hover table-striped sortable">
<tr>
  <th>No</th>
  <th>Student name</th>
  <th>Examination</th>
   <th>SST Marks</th>
   <th>SST Grade</th>
   <th>Eng Marks</th>
   <th>Eng Grade</th>
   <th>Math Marks</th>
   <th>Math Grade</th>
   <th>Sci Marks</th>
   <th>Sci Grade</th>
</tr>
<?php 
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap=$dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowCount();

if($count_scrap>0){
$fclass="where schoolclass='$row_scrap->item'";
}else{
$fclass="";
}

$result_finalgrades=$dbh->query("select * from finalgrades $fclass");
$row_finalgrades=$result_finalgrades->fetchObject();
$count_finalgrades=$result_finalgrades->rowCount();

if($count_finalgrades>0){
  $x=1;
do{
$result_child=$dbh->query("select * from children where cid='$row_finalgrades->cid'");
$row_child=$result_child->fetchObject();

$result_scrap=$dbh->query("select * from scrap where type='exam' and item='$row_finalgrades->examid'");
$row_scrap=$result_scrap->fetchObject();

echo "
<tr>
<td>".$x++."</td>";
?>
<td onClick="da_chart('<?php echo $row_finalgrades->cid; ?>','<?php echo $row_finalgrades->examid; ?>')" style="cursor:pointer;"><?php echo $row_child->fname." ".$row_child->sname; ?></td>
<?php
echo "
<td>".$row_scrap->item2."</td>
<td>".$row_finalgrades->sstmarks."</td>
<td>".$row_finalgrades->sstgrade."</td>
<td>".$row_finalgrades->engmarks."</td>
<td>".$row_finalgrades->enggrade."</td>
<td>".$row_finalgrades->mathmarks."</td>
<td>".$row_finalgrades->mathgrade."</td>
<td>".$row_finalgrades->scimarks."</td>
<td>".$row_finalgrades->scigrade."</td>
</tr>";
}while($row_finalgrades=$result_finalgrades->fetchObject());
}else{
echo "<tr><td align='center' colspan='9'>There is NO data in the table so far. </td></tr>";
}
?>
</table>


                    </div>
                </div>
              </div>


               
<div class="col-lg-12">
  <div class="panel panel-primary">
                <div class="panel-heading">
                                <h3 class="panel-title">Enter marks here</h3>
                            </div>
                            <div class="panel-body">
                              <form method='post'>

                              <div class='col-lg-2'>
                                <select class="form-control" name="examid" id="exam">
                                <?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrapout=$dbh->query("select * from scrap where item2='exam' and type='$rolenumber'");
$row_scrapout=$result_scrapout->fetchObject();
$count_scrapout=$result_scrapout->rowCount();

if($count_scrapout>0){
$result_scrapex=$dbh->query("select * from scrap where item='$row_scrapout->item' and type='exam'");
$row_scrapex=$result_scrapex->fetchObject();

echo "<option value='".$row_scrapout->item."'>".$row_scrapex->item2."</option>";
}else{
  echo "<option value=''>Examination</option>";
}

$result_scrap=$dbh->query("select * from scrap where type='exam'");
$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'>

                                <form method='post'>
                                <select class="form-control" name="priclass" id="priclass">

<?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrapout=$dbh->query("select * from scrap where item2='priclass' and type='$rolenumber'");
$row_scrapout=$result_scrapout->fetchObject();
$count_scrapout=$result_scrapout->rowCount();

if($count_scrapout>0){
$result_scrappri=$dbh->query("select * from scrap where item='$row_scrapout->item' and type='clas'");
$row_scrappri=$result_scrappri->fetchObject();

echo "<option value='".$row_scrapout->item."'>".$row_scrappri->item2."</option>";
}else{
  echo "<option value=''>Class</option>";
}


$result_scrap=$dbh->query("select * from scrap where type='clas'");
$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-1">
<input type="submit" name="selected" class="btn btn-sm btn-primary" value="Submit">
                              </div>
                               </form>
                              <?php 
                              
                                if(isset($_POST["selected"])){
                                  $exam=$_POST["examid"];
                                  $priclass=$_POST["priclass"];
                                  $rolenumber=$_SESSION["rolenumber"];
                                  include("connect.php");

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

if($count_scrap>0){
  $update_scrap=$dbh->query("update scrap set item='$exam' where item2='exam' and type='$rolenumber'");
  $update_scrap=$dbh->query("update scrap set item='$priclass' where item2='priclass' and type='$rolenumber'");
}else{
  $insert_scrap=$dbh->query("insert into scrap (item,item2,type) values('$exam','exam','$rolenumber')");
  $insert_scrap=$dbh->query("insert into scrap (item,item2,type) values('$priclass','priclass','$rolenumber')");
}

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


$rolenumber=$_SESSION["rolenumber"];
$result_scrap = $dbh->query("select * from scrap where item2='priclass' and type='$rolenumber'");
$row_scrap = $result_scrap->fetchObject();
$count_scrap = $result_scrap->rowCount();

if($count_scrap>0){
$result_grades = $dbh->query("select * from grades where priclass='$row_scrap->item'");
$count_grades = $result_grades->rowCount();

if($count_grades>0){
  echo "<div class='col-lg-7 alert alert-success'>Success: Grades for this class have been already set. </div>";
}else{
  echo "<div class='col-lg-7 alert alert-danger'>Sorry: Grades for this class have not been set. Please contact the class teacher. </div>";
}
}
?>
<div class="col-lg-12"><br>
<?php
if(isset($_POST["submit_marks"])){
$studname=$_POST["studname"];

$result_scrappri = $dbh->query("select * from scrap where item2='priclass' and type='$rolenumber'");
$row_scrappri = $result_scrappri->fetchObject();

$result_scrapex = $dbh->query("select * from scrap where item2='exam' and type='$rolenumber'");
$row_scrapex = $result_scrapex->fetchObject();

$examid=$row_scrapex->item;
$priclass=$row_scrappri->item;

$sstmarks=$_POST["sstmarks"];
$sstgrade=$_POST["sstgrade"];
$mathmarks=$_POST["mathmarks"];
$mathgrade=$_POST["mathgrade"];
$engmarks=$_POST["engmarks"];
$enggrade=$_POST["enggrade"];
$scimarks=$_POST["scimarks"];
$scigrade=$_POST["scigrade"];

$cid=substr($studname,0,6);
include("connect.php");
$insert_finalgrades=$dbh->query("insert into finalgrades (cid,schoolclass,examid,sstmarks,sstgrade,mathmarks,mathgrade,engmarks,enggrade,scimarks,scigrade) values('$cid','$priclass','$examid','$sstmarks','$sstgrade','$mathmarks','$mathgrade','$engmarks','$enggrade','$scimarks','$scigrade')");

echo "<div style='text-align:center;' class='alert alert-success'>Success: Marks for ".$studname." have been submitted. </div>";
header("location:child_performance.php");
}
?>
</div>

                    <form method='post'>
                              <table class="table table-bordered table-hover table-striped">
                                <tr>
                                  <td style="font-size:15px;">Student names</td>
                                  <td style="font-size:15px;">SST Marks</td>
                                  <td style="font-size:15px;">SST Grade</td>
                                  <td style="font-size:15px;">ENG Marks</td>
                                  <td style="font-size:15px;">ENG Grade</td>
                                  <td style="font-size:15px;">MATH Marks</td>
                                  <td style="font-size:15px;">MATH Grade</td>
                                  <td style="font-size:15px;">SCI Marks</td>
                                  <td style="font-size:15px;">SCI Grade</td>

                                </tr>
                                <tr>
                              <td width='20%'>
                              <input type='text' list='studname' name='studname' class='form-control' placeholder='Student name'>
                              <datalist id='studname'>
                                <?php
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap = $dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap = $result_scrap->fetchObject();
$count_scrap = $result_scrap->rowCount();

if($count_scrap>0){
  $fcid="where schoolclass='$row_scrap->item'";
}else{
  $fcid="where cid<'50000'";
}

$result_child = $dbh->query("select * from children $fcid");
$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());
}else{
  echo "gwe";
}
                                ?>
                              </datalist>
                              </td>
                                <td>
                              <input type='text' class='form-control' name='sstmarks' onKeyup="sst_grade(this.value)">
                              </td>
                            <td>
                              <input type='text' class='form-control' name='sstgrade' id='sstgrade' readonly>
                              </td>
                              <td>
                              <input type='text' class='form-control' name='engmarks' onKeyup="eng_grade(this.value)">
                              </td>
                              <td>
                              <input type='text' class='form-control' name='enggrade' id='enggrade' readonly>
                              </td>
                              <td>
                              <input type='text' class='form-control' name='mathmarks' onKeyup="math_grade(this.value)">
                              </td>
                              <td>
                              <input type='text' class='form-control' name='mathgrade' id='mathgrade' readonly>
                              </td>
                              <td>
                              <input type='text' class='form-control' name='scimarks' onKeyup="sci_grade(this.value)">
                              </td>
                              <td>
                              <input type='text' class='form-control' name='scigrade' id='scigrade' readonly>
                              </td>
                              </tr>
                            </table>
<input type="submit" style="float:right;" class="btn btn-sm btn-primary" value="Submit" name="submit_marks"> 

</form>
                          </div>

              
                    </div>
                   <div style='background-color:#000000'>
<div id='primarychart' style='min-width: 310px; height: 450px; margin: 0 auto; width:100%;'></div>

</div>
                </div>                
            </div>

<!----row---->

                     


                             
                                </div>
                                
                            </div>
                        </div>
                    </div>
                  </div>
                <!-- /.row -->
</form>






                  </div>
                <!-- /.row -->

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

        </div>
        <!-- /#page-wrapper -->
<?php useractivity("on page","2"); ?>
    </div>
    <!-- /#wrapper -->

<script>
var chart_anim=function(){
$("#display_chart").animate({
  top: "-1250px"
  },400);

 $("#display_chart").animate({
  top: "1090px"
  },400);
}
</script>
  
    <script>
function math_grade(submarks){
var exam = document.getElementById("exam").value;
var priclass = document.getElementById("priclass").value;

if(exam=="" && priclass==""){
alert("Select Examination and Class, First then Submit");
document.getElementById("exam").style.borderColor="red";
document.getElementById("priclass").style.borderColor="red";
}else{
document.getElementById("exam").style.borderColor="green";
document.getElementById("priclass").style.borderColor="green";
}

<?php 
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap=$dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowcount();

if($count_scrap>0){
$daclass="where priclass='$row_scrap->item'";
}else{
  $daclass="";
}

$result_grades=$dbh->query("select mathfrom,mathto,grade from grades $daclass");
$row_grades=$result_grades->fetchObject();

do{
?>
if( parseInt(submarks) >= <?php echo $row_grades->mathfrom; ?>  && parseInt(submarks) <= <?php echo $row_grades->mathto; ?>){
document.getElementById("mathgrade").value="<?php echo $row_grades->grade; ?>";
}
<?php
}while($row_grades=$result_grades->fetchObject());
?>
}

function eng_grade(submarks){
var exam = document.getElementById("exam").value;
var priclass = document.getElementById("priclass").value;

if(exam=="" && priclass==""){
alert("Select Examination and Class, First then Submit");
document.getElementById("exam").style.borderColor="red";
document.getElementById("priclass").style.borderColor="red";
}else{
document.getElementById("exam").style.borderColor="green";
document.getElementById("priclass").style.borderColor="green";
}
<?php 
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap=$dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowcount();

if($count_scrap>0){
$daclass="where priclass='$row_scrap->item'";
}else{
  $daclass="";
}

$result_grades=$dbh->query("select engfrom,engto,grade from grades $daclass");
$row_grades=$result_grades->fetchObject();

do{
?>
if( parseInt(submarks) >= <?php echo $row_grades->engfrom; ?>  && parseInt(submarks) <= <?php echo $row_grades->engto; ?>){
document.getElementById("enggrade").value="<?php echo $row_grades->grade; ?>";
}
<?php
}while($row_grades=$result_grades->fetchObject());
?>
}

function sci_grade(submarks){
var exam = document.getElementById("exam").value;
var priclass = document.getElementById("priclass").value;

if(exam=="" && priclass==""){
alert("Select Examination and Class, First then Submit");
document.getElementById("exam").style.borderColor="red";
document.getElementById("priclass").style.borderColor="red";
}else{
document.getElementById("exam").style.borderColor="green";
document.getElementById("priclass").style.borderColor="green";
}
<?php 
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap=$dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowcount();

if($count_scrap>0){
$daclass="where priclass='$row_scrap->item'";
}else{
  $daclass="";
}
$result_grades=$dbh->query("select scifrom,scito,grade from grades $daclass");
$row_grades=$result_grades->fetchObject();

do{
?>
if( parseInt(submarks) >= <?php echo $row_grades->scifrom; ?>  && parseInt(submarks) <= <?php echo $row_grades->scito; ?>){
document.getElementById("scigrade").value="<?php echo $row_grades->grade; ?>";
}
<?php
}while($row_grades=$result_grades->fetchObject());
?>
}

function sst_grade(submarks){
var exam = document.getElementById("exam").value;
var priclass = document.getElementById("priclass").value;

if(exam=="" && priclass==""){
alert("Select Examination and Class, First then Submit");
document.getElementById("exam").style.borderColor="red";
document.getElementById("priclass").style.borderColor="red";
}else{
document.getElementById("exam").style.borderColor="green";
document.getElementById("priclass").style.borderColor="green";
}
<?php 
include("connect.php");
$rolenumber=$_SESSION["rolenumber"];
$result_scrap=$dbh->query("select * from scrap where type='$rolenumber' and item2='priclass'");
$row_scrap=$result_scrap->fetchObject();
$count_scrap=$result_scrap->rowcount();

if($count_scrap>0){
$daclass="where priclass='$row_scrap->item'";
}else{
  $daclass="";
}

$result_grades=$dbh->query("select sstfrom,sstto,grade from grades $daclass");
$row_grades=$result_grades->fetchObject();

do{
?>
if( parseInt(submarks) >= <?php echo $row_grades->sstfrom; ?>  && parseInt(submarks) <= <?php echo $row_grades->sstto; ?>){
document.getElementById("sstgrade").value="<?php echo $row_grades->grade; ?>";
}
<?php
}while($row_grades=$result_grades->fetchObject());
?>
}
    </script>



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

    <!-- Morris Charts JavaScript -->

</body>

</html>