<?php
require_once('staff.php');
require_once('scores.php');
require_once('studentRecord.php');

  session_start();
if (!isset($_SESSION['staffno'])) {
   header( "Location: signIn.php" );
}

else{
	$staffnoo = ($_SESSION['staffno']);
	}
	
// declaring session variables	
	
$month = date("n");
$year = date("Y");

if($month == 9 || $month == 10 || $month == 11 || $month == 12){

$session1 = $year . "/". ($year + 1);
$term1 = "First";
}


else if($month == 1 || $month == 2 || $month == 3 || $month == 4){
$session1 = ($year-1)."/".$year;
$term1 = "Second";
}

else if($month == 5 || $month == 6 || $month == 7){
$session1 = ($year-1)."/".$year;
//$term1 = "Third";
$term1 = "Second";
}	
	
// end of declerations	



$db = new Staff();
$db2 = new Scores();

 $db->findStaffbyUsername($staffnoo);
 
 $level = $db->status;
 $class1 = $db->class1;
 
 
 $db1 = new StudentRecord();

//$statement =  $db1->viewAllStudentsBySessionAndClass($session1,$class1);

$statement2 = $db2->viewAllSubjectByLevel($level);

?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>  Rex Christus College, Abuja</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>


 <SCRIPT LANGUAGE="JavaScript">
<!-- 	
<!-- Begin
function Check(chk)
{
if(document.form1.checkbox.checked==true){
for (i = 0; i < chk.length; i++)
chk[i].checked = true ;
}else{

for (i = 0; i < chk.length; i++)
chk[i].checked = false ;
}
}

// End -->




</script>



<script language="javascript">
//frm is the form element
function checkForm(frm){
var destCount = frm.elements['users[]'].length;

var destSel   = false;
for(i = 0; i < destCount; i++){
if(frm.elements['users[]'][i].checked){
destSel = true;
break;
}
}

if(!destSel){
alert('Please Select atleast one student');
}



return destSel;



}
</script>
</head>
<body>

<div style="background-color:rgb(0,0,128); width:100%; height:50px;"><div style="float:left; color:white; font:bold; font-size:16px; padding:10px;">  
Rex Christus College, Abuja</div><div style="float:right;"><a href="#" class="btn btn-primary btn-lg disabled">Log Out</a></div></div>
<div class="row">

<?php


if($level == "senior")
{
 include('staffmenu2.html');
}

 else {
	 
	 include('staffmenu.html');
	 }


 ?>

</div>

<?php 

if(($level == "Nursery") || ($level == "play")) {
 ?>

 <div class="container">
 <h3 align="center"><?php echo  "Record Scores ".$class1." ".$session1." "."Session"; ?></h3>
 <div class="row">
 <div class="table-responsive">
 <form action="" method="post" name="form2">
 <table width="50%%" border="0" class="table">
  <tr>
    <th scope="col"><div class="form-group">

        <label for="inputPassword" class="control-label col-xs-2">Subject</label>

        <div class="col-xs-10">

            <select class="form-control inputstl" id="area"  name="subject" required="required">
 
 <option value="">Select Subject</option>
 
  <?php
    $rowCount1 = 0;
    while ($row = $statement2->fetch(PDO::FETCH_ASSOC)){
            extract($row);
		$rowCount1++;	
    ?>
 
<option value="<?php echo $row['title'];  ?>"><?php echo $row['title'];  ?></option>
		
        
	<?php 
	}
	?>	
</select>

        </div>

    </div> </th>
    <th scope="col"> <div class="form-group">

        <div class="col-xs-offset-2 col-xs-10">
        
        <input type="submit" value="Submit" name="submit2" class="btn btn-primary"/>


          
           
        </div>

    </div></th>
  </tr>
</table>

 </form>
 </div>
 </div>
 <?php
 if(isset($_POST['submit2'])){
	 
	 $subject = $_POST['subject'];
	 
$statement = $db2->viewAllScoresBySessionAndClassAndSubject($class1,$subject,$session1,$term1);	 
	 
	 
	 
	 ?>
 
<div class="row">
    <div class="table-responsive"> 
    <form  method="post" name="form1" action="addScores.php" onsubmit="return checkForm(this);">
    
    <table class="table" border="1">

    <thead>

        <tr>

            <th>SN<input name="levels" type="hidden" value="<?php echo $level; ?>"><input name="subject6" type="hidden" value="<?php echo $subject; ?>"/></th>
            <th><input type="checkbox" name="checKAll" id="checkbox" onClick="Check(document.form1.checklist)" value="7">
          <label for="checkbox">SELECT ALL</label></th>
            <th>ADMISSION NO</th>

            <th>LAST NAME</th>

            <th>FIRST NAME</th>
            
            <th>FIRST TEST</th>
            <th>SECOND TEST</th>
            
            <th>EXAM</th>
            <th>TOTAL</th>
            
        </tr>

    </thead>

    <tbody>
    <?php
    $rowCount1 = 0;
    while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
            extract($row);
		$rowCount1++;	
    ?>

        <tr   <?php if ( $rowCount1 % 2 == 0 ) { echo ' class="active"'; } else { echo ' class="success" ';} ?>>

            <td><?php echo $rowCount1; ?></td>
            <td><input type="checkbox" name="users[]" value="<?php echo $row['scoresid']; ?>" id="checklist" ></td>
            <td><?php echo $row['admissionno']; ?></td>

            <td><?php echo $row['lname']; ?></td>

             <td><?php echo $row['fname']; ?><input type="hidden" name="class4" value="<?php echo $row['class']; ?>" ></td>
              

           
             <td><?php echo $row['ftest']; ?></td>
              <td><?php echo $row['stest']; ?></td>
               
                 <td><?php echo $row['exam']; ?></td>
                  <td><?php echo $row['total']; ?></td>
           
        </tr>

        <?php 
	}
		?>
       
       <tr  colspan="5"> 
 
 
        
        <input type="submit" value="CLICK TO ENTER SCORES" name="button" class="btn btn-primary"/>


          
           
            </tr>
        
        </tbody>
        </table>
        </div>
        
    </form>
    </div>
    </div>
            

<?php 
 }
 
}











else if( ($level == "junior") || ($level == "senior")  ){
?>	
	 <div class="container">
 <h3 align="center"><?php echo  "Record Scores ".$class1." ".$session1." "."Session"; ?></h3>
 <div class="row">
 <div class="table-responsive">
 <form action="" method="post" name="form2">
 <table width="50%%" border="0" class="table">
  <tr>
    <th scope="col"><div class="form-group">

        <label for="inputPassword" class="control-label col-xs-2">Subject</label>

        <div class="col-xs-10">

            <select class="form-control inputstl" id="area"  name="subject" required="required">
 
 <option value="">Select Subject</option>
 
  <?php
    $rowCount1 = 0;
    while ($row = $statement2->fetch(PDO::FETCH_ASSOC)){
            extract($row);
		$rowCount1++;	
    ?>
 
<option value="<?php echo $row['title'];  ?>"><?php echo $row['title'];  ?></option>
		
        
	<?php 
	}
	?>	
</select>

        </div>

    </div> </th>
    <th scope="col"> <div class="form-group">

        <div class="col-xs-offset-2 col-xs-10">
        
        <input type="submit" value="Submit" name="submit2" class="btn btn-primary"/>


          
           
        </div>

    </div></th>
  </tr>
</table>

 </form>
 </div>
 </div>
 <?php
 if(isset($_POST['submit2'])){
	 
	 $subject = $_POST['subject'];
	 
$statement = $db2->viewAllScoresBySessionAndClassAndSubjectAnnual($class1,$subject,$session1);	 
	 
	 
	 
	 ?>
 
<div class="row">
    <div class="table-responsive"> 
    <form  method="post" name="form1" action="addScoresAnnual.php" onsubmit="return checkForm(this);">
    
    <table class="table" border="1">

    <thead>

        <tr>

            <th>SN<input name="levels" type="hidden" value="<?php echo $level; ?>"><input name="subject6" type="hidden" value="<?php echo $subject; ?>"/></th>
            <th><input type="checkbox" name="checKAll" id="checkbox" onClick="Check(document.form1.checklist)" value="7">
          <label for="checkbox">SELECT ALL</label></th>
            <th>ADMISSION NO</th>

            <th>LAST NAME</th>

            <th>FIRST NAME</th>
            
         
            <th>FIRST TERM</th>
            <th>SECOND TERM</th>
            <th>THIRD TERM</th>
            <th>TOTAL</th>
            
        </tr>

    </thead>

    <tbody>
    <?php
    $rowCount1 = 0;
    while ($row = $statement->fetch(PDO::FETCH_ASSOC)){
            extract($row);
		$rowCount1++;	
    ?>

        <tr   <?php if ( $rowCount1 % 2 == 0 ) { echo ' class="active"'; } else { echo ' class="success" ';} ?>>

            <td><?php echo $rowCount1; ?></td>
            <td><input type="checkbox" name="users[]" value="<?php echo $row['scoresid']; ?>" id="checklist" ></td>
            <td><?php echo $row['admissionno']; ?></td>

            <td><?php echo $row['lname']; ?></td>

             <td><?php echo $row['fname']; ?><input type="hidden" name="class4" value="<?php echo $row['class']; ?>" ></td>
              

           
            
              <td><?php echo $row['totalfirst']; ?></td>
              <td><?php echo $row['totalsecond']; ?></td>
               <td><?php echo $row['totalthird']; ?></td>
               
                  <td><?php echo $total; ?></td>
           
        </tr>

        <?php 
	}
		?>
       
       <tr  colspan="5"> 
 
 
        
        <input type="submit" value="CLICK TO ENTER SCORES" name="button" class="btn btn-primary"/>


          
           
            </tr>
        
        </tbody>
        </table>
        </div>
        
    </form>
    </div>
    </div>
            

<?php 
 }
}

?>






</div>
    

  




<!--- // div that closes row  --->


</body>
</html>