<?php
	require_once('source/session.php');
	require_once('source/error.php');
	require_once('source/dbconfig.php');
	require_once('source/function.php');
	require_once('source/restrict_user.php');
	
	if($_GET['msg'] == "refered"){
		$msg = "<h5 class='alert alert-success'>Refered successfully</h5>";
	}else if($_GET['msg'] == "failed"){
		$msg = "<h5 class='alert alert-warning'>Something went wrong, please try again</h5>";
	}
	
	if($_SESSION['msg'] == "update")
	{
		$msg = "<h5 class='alert alert-success text-center'>Order Update Succesful. Customer will receive email.<a 
		class='btn-sm' href='new_order.php'>Refresh</a></h5>";
	}       
	      
	      		//pin validation
			$STH 				= $DBH->prepare("SELECT count(*) FROM tbl_pin WHERE pin = ? ");
			$result 	   		= $STH->execute(array($_GET['mypin']));
			$count_pin	  	= $STH->fetchColumn();
			if($count_pin > 0){  
			
                    $rows1 = sql($DBH, "SELECT * FROM tbl_pin where pin = ?", 
            	array($_GET['mypin']), "rows");
		foreach($rows1 as $row1)
		{	
			$stu_pin	 	= $row1['pin'];
			$stu_reg_no 		= $row1['reg_no'];
			
			if($stu_reg_no != $_GET['myreg']){
			redirect("main.php?msg=failed");
			exit;
			}
		}
	      }else{
			redirect("main.php?msg=failed");
			exit;
		}
	      
                    $rows1 = sql($DBH, "SELECT * FROM tbl_student_results where csv_no = ?", 
            	array($_GET['val']), "rows");
		foreach($rows1 as $row1)
		{	
			$u_name	 		= $row1['name'];
			$u_registration_no 		= $row1['registration_no'];
			$u_test 			= $row1['test'];
			$u_home_work 			= $row1['home_work'];
			$u_project			= $row1['project'];
			$u_exam			= $row1['exam'];
			
			$total = ($u_test + $u_home_work + $u_project + $u_exam);


			sql($DBH, "UPDATE tbl_student_results set total = ?, teacher_no = ? WHERE registration_no = ? AND year = ? AND term = ? AND class = ?", array($total,$SESS_HASH_USER,$u_registration_no,$u_test));
			
			
                    $rows2 = sql($DBH, "SELECT * FROM tbl_student_results where csv_no = ? ORDER by (total) desc", 
            	array($_GET['val']), "rows");
            	$sno = 0;
		foreach($rows2 as $row2)
		{	
			$sno++;
			$us_name	 		= $row2['name'];
			$us_registration_no 		= $row2['registration_no'];
			$us_test 			= $row2['test'];
			$us_home_work 			= $row2['home_work'];
			$us_project			= $row2['project'];
			$us_exam			= $row2['exam'];
			$us_total			= $row2['total'];
			$us_class			= $row2['class'];
			$us_year			= $row2['year'];
			$us_term			= $row2['term'];
			
			if($us_total <=39){
			$grade = "Poor";
			}
			else if ($us_total >39 && $us_total<= 49)
			{
			$grade = "Fair";
			}
			else if ($us_total >49 && $us_total<= 59)
			{
			$grade = "Credit";
			}
			else if ($us_total >59 && $us_total<= 69)
			{
			$grade = "Good";
			}
			else if ($us_total >69 && $us_total<= 79)
			{
			$grade = "Very Good";
			}
			else if ($us_total >79 && $us_total<= 100)
			{
			$grade = "Excellent";
			}
			
			sql($DBH, "UPDATE tbl_student_results set grade = ?, position = ? WHERE registration_no = ? AND test = ?", array($grade,$sno,$us_registration_no,$us_test));
			}
			}
			
			//Overall
			
		$STH 			= $DBH->prepare("SELECT count(*) FROM tbl_overall WHERE class = ? AND year = ? AND term = ?");
        	$result 	   	= $STH->execute(array($_GET['myclass'],$_GET['examyear'],$_GET['term']));
        	$cnt_overall	  	= $STH->fetchColumn();
        	if($cnt_overall == 0){
        	
			
                    $rows1 = sql($DBH, "SELECT * FROM tbl_overall WHERE class = ? AND year = ? AND term = ?", array($_GET['stclass'],$_GET['examyear'],$_GET['term']), "rows");
		foreach($rows1 as $row1)
		{	
			$st_registration_no	=	$row1['reg_no'];
			$st_class	=	$row1['class'];
			$st_name	=	$row1['name'];
			
		                                 
		$b_in_s = sql($DBH, "SELECT SUM(total) FROM tbl_overall WHERE class = ? AND year = ? AND term = ? AND registration_no = ?", array($_GET['stclass'],$_GET['year'],$_GET['stterm'],$st_registration_no), "rows");			
		foreach($b_in_s as $b_in_row){	
			$b_ins	=	$b_in_row[0];
		}
			
		
		sql($DBH, "insert into  tbl_overall (name , reg_no , class , year , term, overall)values (?,?,?,?,?,?)", array($st_name,$st_registration_no,$_GET['stclass'],$_GET['year'],$_GET['stterm'],$b_ins));	
		
		
                    $rows2 = sql($DBH, "SELECT * FROM tbl_overall WHERE class = ? AND year = ? AND term = ? ORDER by (overall) desc", 
            	array($_GET['stclass'],$_GET['year'],$_GET['stterm']), "rows");
            	$snum = 0;
		foreach($rows2 as $row2)
		{	
			$snum++;
			$ust_name	 		= $row2['name'];
			$ust_reg_no 		= $row2['reg_no'];
			$ust_test 			= $row2['test'];	
		
			$rows1 = sql($DBH, "SELECT * FROM tbl_user where registration_no = ?", array($ust_reg_no), "rows");							
			foreach($rows1 as $row1)
			{	
				$dob   		= $row1['age'];
				
				//date in mm/dd/yyyy format; or it can be in other formats as well
  $birthDate = "$dob";
  //explode the date to get month, day and year
  $birthDate = explode("/", $birthDate);
  //get age from date or birthdate
  $age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md")
    ? ((date("Y") - $birthDate[2]) - 1)
    : (date("Y") - $birthDate[2]));
    }
			sql($DBH, "UPDATE tbl_overall set position = ?, age = ? WHERE class = ? AND year = ? AND term = ? AND reg_no = ?", array($snum,$age,$_GET['stclass'],$_GET['year'],$_GET['stterm'],$ust_reg_no), "rows");
		}
	}	
}else if($cnt_overall > 0){
                    $rows2 = sql($DBH, "SELECT * FROM tbl_overall WHERE class = ? AND year = ? AND term = ? ORDER by (overall) desc", 
            	array($_GET['stclass'],$_GET['year'],$_GET['stterm']), "rows");
            	$snum = 0;
		foreach($rows2 as $row2)
		{	
			$snum++;
			$ust_name	 		= $row2['name'];
			$ust_reg_no 		= $row2['reg_no'];
			$ust_test 			= $row2['test'];	
			
			                                 
		$b_in_s = sql($DBH, "SELECT SUM(total) FROM tbl_student_results WHERE class = ? AND year = ? AND term = ? AND registration_no = ?", array($_GET['stclass'],$_GET['year'],$_GET['stterm'],$ust_reg_no), "rows");			
		foreach($b_in_s as $b_in_row){	
			$b_ins	=	$b_in_row[0];
          $STH 				= $DBH->prepare( "SELECT AVG(total) FROM tbl_student_results WHERE registration_no = ? AND class =? AND term = ? AND year = ?");
			$result 	   		= $STH->execute(array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']));
			$AverageScore	  	= $STH->fetchColumn();   
		}
			
			
	sql($DBH, "UPDATE tbl_overall set overall = ? WHERE class = ? AND year = ? AND term = ? AND reg_no = ?", array($b_ins,$_GET['stclass'],$_GET['year'],$_GET['stterm'],$ust_reg_no), "rows");
			sql($DBH, "UPDATE tbl_overall set position = ? WHERE class = ? AND year = ? AND term = ? AND reg_no = ?", array($snum,$_GET['stclass'],$_GET['year'],$_GET['stterm'],$ust_reg_no), "rows");
	sql($DBH, "UPDATE tbl_overall set AverageScore = ? WHERE class = ? AND year = ? AND term = ? AND reg_no = ?", array($AverageScore,$_GET['stclass'],$_GET['year'],$_GET['stterm'],$ust_reg_no), "rows");
	}
}

?>
<!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, shrink-to-fit=no">
  <meta name="description" content="">
  <meta name="author" content="">
  <title>GILFORD MEMORIAL SCHOOLS: My Term Result!</title>
  <!-- Bootstrap core CSS-->
  <link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
  <!-- Custom fonts for this template-->
  <link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
  <!-- Page level plugin CSS-->
  <link href="vendor/datatables/dataTables.bootstrap4.css" rel="stylesheet">
  <!-- Custom styles for this template-->
  <link href="css/sb-admin.css" rel="stylesheet">
  <link href="css/folder.css" rel="stylesheet">
  <link href="css/user_profile.css" rel="stylesheet">
  
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
  <!-- select-->
  <link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
  
 
<style> 
div.a {
    white-space: nowrap; 
    width: 100px; 
    overflow: hidden;
    text-overflow:ellipsis;
    border: 0px solid #000000;
    padding-left: 25px;
}

div.a:hover {
    overflow: visible;
}
</style>
  
</head>

<body class="fixed-nav sticky-footer bg-dark" id="page-top">
  <!-- Navigation-->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top" id="mainNav">
  
<?php
            	
            	$rows = sql($DBH, "SELECT * FROM tbl_admin where status = ?", 
            	array("Active"), "rows");							
            	foreach($rows as $row)
            	{
            		$admin_name 		= $row['username'];
            	}
		
      if (isset($_SESSION['SESS_HASH_ADMIN'])) {
		$user_true 			 = "<h4 style='color: yellow'><b>GILFORD SCHOOL SCORESHEET</b></h4>";
		
}
		echo "$user_true ";
?>
    <button class="navbar-toggler navbar-toggler-right" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>
    <div class="collapse navbar-collapse" id="navbarResponsive">
      <ul class="navbar-nav navbar-sidenav" id="exampleAccordion">
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="My Dashboard">
          <a class="nav-link" href="main.php">
            <i class="fa fa-fw fa-dashboard" style="color: #3498db"></i>
            <span class="nav-link-text" style="color: white">Dashboard</span>
          </a>
          <a class="nav-link" href="logout.php">
            <i class="fa fa-fw fa-sign-out" style="color: #3498db"></i>
            <span class="nav-link-text" style="color: white">Logout</span>
          </a>
        </li>
      </ul>
      <ul class="navbar-nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" data-toggle="modal" href="logout.php" style="color: white">
            <i class="fa fa-fw fa-sign-out"></i>Logout</a>
        </li>
      </ul>
    </div>
  </nav>
  
  <div class="content-wrapper">
    <div class="container-fluid">
      <?php 
          $STH 				= $DBH->prepare("SELECT count(*) FROM tbl_overall WHERE class =? AND term = ? AND year = ?");
			$result 	   		= $STH->execute(array($_GET['myclass'],$_GET['term'],$_GET['examyear']));
			$count_student	  	= $STH->fetchColumn();   
			
			                      
		$AverageScore = sql($DBH, "SELECT AVG(total) FROM tbl_student_results WHERE registration_no = ? AND class =? AND term = ? AND year = ?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($AverageScore as $b_in_row){	
			$AverageScore	= round($b_in_row[0],2);
		}	

		$b_in_q = sql($DBH, "SELECT AVG(total) FROM tbl_student_results where class =? AND term = ? AND year = ?", array($_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($b_in_q as $b_in_row){	
			$b_in	= round($b_in_row[0],2);
		}	
		                      
		$b_in_qa = sql($DBH, "SELECT AVG(total) FROM tbl_student_results where class =? AND term = ? AND year = ?", array($_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($b_in_qa as $b_in_row){	
			$b_inqa	= $b_in_row[0];
		}
		                         
		$b_in_m = sql($DBH, "SELECT MIN(total) FROM tbl_student_results where class =? AND term = ? AND year = ?", array($_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($b_in_m as $b_in_row){	
			$b_inm	= $b_in_row[0];
		}
		                         
		$b_in_mx = sql($DBH, "SELECT MAX(total) FROM tbl_student_results where class =? AND term = ? AND year = ?", array($_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($b_in_mx as $b_in_row){	
			$b_inmx	= $b_in_row[0];
		}
		
		$b_in_ag = sql($DBH, "SELECT AVG(age) FROM tbl_overall where class =? AND term = ? AND year = ?", array($_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($b_in_ag as $b_in_row){	
			$b_inag	= $b_in_row[0];
			
			$b_age = round(($b_inag),2);
		}
		
                    $rows1 = sql($DBH, "SELECT * FROM tbl_user where registration_no = ?", 
            	array($_GET['myreg']), "rows");
		foreach($rows1 as $row1)
		{	
			$user_name	 		= $row1['fullname'];
			$user_gender	 		= $row1['gender'];
			$user_age	 		= $row1['age'];
			$user_profile_pic	 	= $row1['profile_pic'];
		}
		
            		if($user_profile_pic == "default"){
            		$profile_pic = "<img width='100px' src='../admin/admin/profile/profile.jpg'>";
			}else{						
			$profile_pic = "<img width='100px' src='../admin/admin/profile/$user_profile_pic'>";
			}
		
                    $rows1 = sql($DBH, "SELECT * FROM tbl_overall where class =? AND term = ? AND year = ? AND reg_no =?", array($_GET['myclass'],$_GET['term'],$_GET['examyear'],$_GET['myreg']), "rows");
		foreach($rows1 as $row1)
		{	
			$user_position	 		= $row1['position'];
		}
		
		if($user_position == 1){
		$user_p = "$user_position st";
		} else if($user_position == 2){
		$user_p = "$user_position nd";
		} else if($user_position == 3){
		$user_p = "$user_position rd";
		} else if($user_position == 21){
		$user_p = "$user_position st";
		} else if($user_position == 22){
		$user_p = "$user_position nd";
		} else if($user_position == 3){
		$user_p = "$user_position rd";
		} else if($user_position == 31){
		$user_p = "$user_position st";
		} else if($user_position == 32){
		$user_p = "$user_position nd";
		} else if($user_position == 33){
		$user_p = "$user_position rd";
		} else if($user_position == 41){
		$user_p = "$user_position st";
		} else if($user_position == 42){
		$user_p = "$user_position nd";
		} else if($user_position == 43){
		$user_p = "$user_position rd";
		}else{
		$user_p = "$user_position th";
		}
		
	?>
<img src='image/sch_logo.png' width='778' height="199" style=' margin-left: auto; margin-right: auto; display: block'/><br/><br/>
	<div class='row'>
	  <div class='col-sm-4'> <small><b>Name of Student: </b> <u><?php echo $user_name ; ?></u></small><br>
	    <small><b>Registration No: </b> <u><?php echo $_GET['myreg'] ; ?></u></small><br>
	    <small><b>Sex: </b> <u><?php echo $user_gender ; ?></u></small><br>
	    <small><b>Term: </b> <u><?php echo $_GET['term']; ?></u></small><br>
	    <small><b>Year: </b> <u><?php echo $_GET['examyear']; ?></u></small><br>
	    </div>
	  <div class='col-sm-3'> <small><b>Class: </b> <u><?php echo $_GET['myclass'] ; ?></u></small><br>
		  <small><b>No in Class: </b> <u><?php echo $count_student; ?></u></small><br>
		  <small><b>Position: </b> <u><?php echo $user_p ; ?></u></small><br>
		  <small><b>Average Score: </b> <u><?php echo $AverageScore ; ?></u></small><br>
		  </div>
		<div class='col-sm-3'> <small><b>Class Average: </b> <u><?php echo $b_in ; ?></u></small><br>
		  <small><b>Class Lowest: </b> <u><?php echo $b_inm; ?></u></small><br>
		  <small><b>Clas Highest: </b> <u><?php echo $b_inmx; ?></u></small><br>
		  <small><b>Age: </b> <u><?php echo $user_age ; ?></u></small><br>
		  <small><b>Class Average Age: </b> <u><?php echo $b_age; ?></u></small><br>
		  </div>
		<div class='col-sm-2'>
			<?php echo $profile_pic ; ?>
		</div>
	</div><br/>
	<hr>
	
      <div class="row">
        <div class="col-lg-12">
                            <table width="95%" class='table table-bordered'>
                                <tr style='font-size: 14px'>
                                    <th  class='text-center'>&nbsp;</th>
                                    <th width="6%" colspan='1'  class='text-center'>Class Work<br></th>
                                    <th width="6%" colspan='1'  class='text-center'>Home<br>
                                    work</th>
                                    <th width="5%" colspan='1'  class='text-center'><p>Test</p></th>
                                    <th width="5%" colspan='1'  class='text-center'>Exam</th>
                                    <th width="7%" colspan='1'  class='text-center'>Total</th>
                                    <th width="6%" rowspan="2" valign="baseline"  class='text-center'>Class <br/>
Lowest <br/>
Score</th>
                                    <th width="6%" rowspan="2" valign="bottom"  class='text-center'>Class <br/>
Highest <br/>
Score</th>
                                    <th width="7%" rowspan="2" valign="bottom"  class='text-center'>Class <br/>
Average <br/>
Score</th>
                                    <th width="6%" rowspan="2" valign="bottom"  class='text-center'>Position In Subj.</th>
                                    <th width="6%" rowspan="2" valign="bottom"  class='text-center'>Grade</th>
                                    <th width="33%" rowspan="2" valign="bottom"  class='text-center'>Remarks</th>
                                </tr>
                                <tr style='font-size: 14px'>
                                  <th  class='text-center'>Subject</th>
                                  <th colspan='1'  class='text-center'>20%</th>
                                  <th width="6%" colspan='1'  class='text-center'>20%</th>
                                  <th width="5%" colspan='1'  class='text-center'>20%</th>
                                  <th width="5%" colspan='1'  class='text-center'>40%</th>
                                  <th width="7%" colspan='1'  class='text-center'>100%</th>
                                </tr>
<?php
                                
	$rows = sql($DBH, "SELECT * FROM tbl_student_results where registration_no = ? AND class =? AND term =? AND year =?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($rows as $row)
		{	
                $subject 	 	= $row['subject'];
                $test 		= $row['test'];
                $home_work 		= $row['home_work'];
                $project 		= $row['project'];
                $exam 		= $row['exam'];
                $total 		= $row['total'];
                $position 		= $row['position'];
                $remark 		= $row['grade'];
		if($position == 1){
		$position = "$position st";
		} else if($position == 2){
		$position = "$position nd";
		} else if($position == 3){
		$position = "$position rd";
		} else if($position == 21){
		$position = "$position st";
		} else if($position == 22){
		$position = "$position nd";
		} else if($user_position == 3){
		$position = "$position rd";
		} else if($position == 31){
		$position = "$position st";
		} else if($user_position == 32){
		$position = "$position nd";
		} else if($position == 33){
		$position = "$position rd";
		} else if($position == 41){
		$position = "$position st";
		} else if($position == 42){
		$position = "$position nd";
		} else if($position == 43){
		$position = "$position rd";
		}else{
		$position = "$position th";
		}
                
                                        
		$b_in_mn = sql($DBH, "SELECT MIN(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mn as $b_in_row){	
			$b_inmn	= $b_in_row[0];
		}
		                            
		$b_in_mnx = sql($DBH, "SELECT MAX(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mnx as $b_in_row){	
			$b_inmnx	= $b_in_row[0];
		}
		                               
		$b_in_mav = sql($DBH, "SELECT AVG(total) FROM tbl_student_results where class =? AND term = ? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['term'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mav as $b_in_row){	
			$b_inmav = round($b_in_row[0],2);
		}
		  
			if($total <=39){
			$grade = "F";
			}
			else if ($total >39 && $total<= 49)
			{
			$grade = "E";
			}
			else if ($total >49 && $total<= 59)
			{
			$grade = "D";
			}
			else if ($total >59 && $total<= 69)
			{
			$grade = "C";
			}
			else if ($total >69 && $total<= 79)
			{
			$grade = "B";
			}
			else if ($total >79 && $total<= 100)
			{
			$grade = "A";
			}
			 
                
                echo"
                                <tr>
                                <td colspan='2'>$subject</td>
                                <td>$test</td>
                                <td>$home_work</td>
                                <td>$project</td>
                                <td>$exam</td>
                                <td>$total</td>
                                <td>$b_inmn</td>
                                <td>$b_inmnx</td>
                                <td>$b_inmav</td>
                                <td>$position</td>
                                <td>$grade</td>
                                <td>$remark</td>
                                </tr>";
                               }
?>
            </table>
          </div>
      </div>
	<hr>
	<div class='row'>
	  <table width="95%" class='table table-bordered'>
	    <tr style='font-size: 14px'>
		    <th width="50%"  class='text-center'>LANGUAGE SKILLS</th>
		    <th width="50%"  class='text-center'>WORKING HABIT</th>
		    </tr>
		  <tr style='font-size: 14px'>
		    <th colspan='2'  class='text-center'><table width="98%" border="0" cellpadding="2" cellspacing="2">
		      <tr>
		        <td width="37%">Describes self (name, age, sex)</td>
		        <td width="12%">&nbsp;</td>
		        <td width="4%">&nbsp;</td>
		        <td width="35%">Does homework assignment</td>
		        <td width="12%">&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Names objects in the environment</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Completes work on time</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Repeats simple poems /Nursery rhymes</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Is attentive and follows direction</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Uses simple poems/nursery rhymes</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Respects class and school rules</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Uses simple affirmative &amp; &quot;not&quot; statement</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Works independently</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Uses functional vocabulary related to experience</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Participates in class activities</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Expresses idea and feeling</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Is developing self control</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Describes picture of objects, people and event</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Tries new ideas willingly</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Self confidence rating</td>
		        <td>&nbsp;</td>
		        </tr>
		      </table></th>
		    </tr>
		  <?php
                                
	$rows = sql($DBH, "SELECT * FROM tbl_student_results where registration_no = ? AND class =? AND term =? AND year =?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($rows as $row)
		{	
                $subject 	 	= $row['subject'];
                $test 		= $row['test'];
                $home_work 		= $row['home_work'];
                $project 		= $row['project'];
                $exam 		= $row['exam'];
                $total 		= $row['total'];
                $position 		= $row['position'];
                $remark 		= $row['grade'];
		if($position == 1){
		$position = "$position st";
		} else if($position == 2){
		$position = "$position nd";
		} else if($position == 3){
		$position = "$position rd";
		} else if($position == 21){
		$position = "$position st";
		} else if($position == 22){
		$position = "$position nd";
		} else if($user_position == 3){
		$position = "$position rd";
		} else if($position == 31){
		$position = "$position st";
		} else if($user_position == 32){
		$position = "$position nd";
		} else if($position == 33){
		$position = "$position rd";
		} else if($position == 41){
		$position = "$position st";
		} else if($position == 42){
		$position = "$position nd";
		} else if($position == 43){
		$position = "$position rd";
		}else{
		$position = "$position th";
		}
                
                                        
		$b_in_mn = sql($DBH, "SELECT MIN(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mn as $b_in_row){	
			$b_inmn	= $b_in_row[0];
		}
		                            
		$b_in_mnx = sql($DBH, "SELECT MAX(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mnx as $b_in_row){	
			$b_inmnx	= $b_in_row[0];
		}
		                               
		$b_in_mav = sql($DBH, "SELECT AVG(total) FROM tbl_student_results where class =? AND term = ? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['term'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mav as $b_in_row){	
			$b_inmav = round($b_in_row[0],2);
		}
		  
			if($total <=39){
			$grade = "F";
			}
			else if ($total >39 && $total<= 49)
			{
			$grade = "E";
			}
			else if ($total >49 && $total<= 59)
			{
			$grade = "D";
			}
			else if ($total >59 && $total<= 69)
			{
			$grade = "C";
			}
			else if ($total >69 && $total<= 79)
			{
			$grade = "B";
			}
			else if ($total >79 && $total<= 100)
			{
			$grade = "A";
			}
			 
                
                echo"
                                <tr>
                                <td colspan='2'>$subject</td>
                                <td>$test</td>
                                <td>$home_work</td>
                                <td>$project</td>
                                <td>$exam</td>
                                <td>$total</td>
                                <td>$b_inmn</td>
                                <td>$b_inmnx</td>
                                <td>$b_inmav</td>
                                <td>$position</td>
                                <td>$grade</td>
                                <td>$remark</td>
                                </tr>";
                               }
?>
		  </table>
		<br>
		<table width="95%" class='table table-bordered'>
		  <tr style='font-size: 14px'>
		    <th width="50%"  class='text-center'>COGNITIVE SKILLS</th>
		    <th width="50%"  class='text-center'>SOCIAL DEVELOPMENT</th>
		    </tr>
		  <tr style='font-size: 14px'>
		    <th colspan='2'  class='text-center'><table width="98%" border="0" cellpadding="2" cellspacing="2">
		      <tr>
		        <td width="37%">Identifies colours Red, Blue, Green, etc</td>
		        <td width="12%">&nbsp;</td>
		        <td width="4%">&nbsp;</td>
		        <td width="35%">Appearance</td>
		        <td width="12%">&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Matches Objects by size, colour, shape, etc</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Cleans up work area</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Followes a two/three step directiom</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Interaction with fellow children</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Describes relationship of objects</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Participation in group activities</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>(Comb &amp; Brush, comb &amp; Saucer)</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Respects authority</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td colspan="3">&nbsp;</td>
		        <th colspan="2"  class='text-center'>MOTOR SKILLS</th>
		        </tr>
		      <tr>
		        <td>Ability in Alphabet Work:</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Manipulates toys, beads, blocks etc</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>Ability in Number Work:</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Builds up blocks</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Assembles puzzles</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td colspan="2">Teacher's Comment:</td>
		        <td>&nbsp;</td>
		        <td>Paints and pastes</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td colspan="2">Nest Term Begins: ________________</td>
		        <td>&nbsp;</td>
		        <td>Draws with pencils</td>
		        <td>&nbsp;</td>
		        </tr>
		      <tr>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>&nbsp;</td>
		        <td>Cuts with scissors</td>
		        <td>&nbsp;</td>
		        </tr>
		      </table></th>
		    </tr>
		  <?php
                                
	$rows = sql($DBH, "SELECT * FROM tbl_student_results where registration_no = ? AND class =? AND term =? AND year =?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($rows as $row)
		{	
                $subject 	 	= $row['subject'];
                $test 		= $row['test'];
                $home_work 		= $row['home_work'];
                $project 		= $row['project'];
                $exam 		= $row['exam'];
                $total 		= $row['total'];
                $position 		= $row['position'];
                $remark 		= $row['grade'];
		if($position == 1){
		$position = "$position st";
		} else if($position == 2){
		$position = "$position nd";
		} else if($position == 3){
		$position = "$position rd";
		} else if($position == 21){
		$position = "$position st";
		} else if($position == 22){
		$position = "$position nd";
		} else if($user_position == 3){
		$position = "$position rd";
		} else if($position == 31){
		$position = "$position st";
		} else if($user_position == 32){
		$position = "$position nd";
		} else if($position == 33){
		$position = "$position rd";
		} else if($position == 41){
		$position = "$position st";
		} else if($position == 42){
		$position = "$position nd";
		} else if($position == 43){
		$position = "$position rd";
		}else{
		$position = "$position th";
		}
                
                                        
		$b_in_mn = sql($DBH, "SELECT MIN(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mn as $b_in_row){	
			$b_inmn	= $b_in_row[0];
		}
		                            
		$b_in_mnx = sql($DBH, "SELECT MAX(total) FROM tbl_student_results where class =? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mnx as $b_in_row){	
			$b_inmnx	= $b_in_row[0];
		}
		                               
		$b_in_mav = sql($DBH, "SELECT AVG(total) FROM tbl_student_results where class =? AND term = ? AND year = ? AND subject =?", array($_GET['myclass'],$_GET['term'],$_GET['examyear'],$subject), "rows");							
		foreach($b_in_mav as $b_in_row){	
			$b_inmav = round($b_in_row[0],2);
		}
		  
			if($total <=39){
			$grade = "F";
			}
			else if ($total >39 && $total<= 49)
			{
			$grade = "E";
			}
			else if ($total >49 && $total<= 59)
			{
			$grade = "D";
			}
			else if ($total >59 && $total<= 69)
			{
			$grade = "C";
			}
			else if ($total >69 && $total<= 79)
			{
			$grade = "B";
			}
			else if ($total >79 && $total<= 100)
			{
			$grade = "A";
			}
			 
                
                echo"
                                <tr>
                                <td colspan='2'>$subject</td>
                                <td>$test</td>
                                <td>$home_work</td>
                                <td>$project</td>
                                <td>$exam</td>
                                <td>$total</td>
                                <td>$b_inmn</td>
                                <td>$b_inmnx</td>
                                <td>$b_inmav</td>
                                <td>$position</td>
                                <td>$grade</td>
                                <td>$remark</td>
                                </tr>";
                               }
?>
		  </table>
		<p>&nbsp; </p>
	</div>
	<hr>
	
	<hr>
			<button onclick="myFunction()">Print Result</button><br/><br>

<script>
function myFunction() {
    window.print();
}
</script>
        </div>
           </div>
          </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <footer class="sticky-footer" style="background: ORANGE">
      <div class="container">
        <div class="text-center"><small><strong>Copyright ©2018 GILFORD SCHOOLS, ABA. All Rights Reserved!</strong></small></div>
      </div>
    </footer>
    <!-- Scroll to Top Button-->
    <a class="scroll-to-top rounded" href="#page-top">
      <i class="fa fa-angle-up"></i>
    </a>
    <!-- Logout Modal-->
    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
      <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <h5 class="modal-title" id="exampleModalLabel">Ready to Leave?</h5>
            <button class="close" type="button" data-dismiss="modal" aria-label="Close">
              <span aria-hidden="true">×</span>
            </button>
          </div>
          <div class="modal-body">Select "Logout" below if you are ready to end your current session.</div>
          <div class="modal-footer">
            <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancel</button>
            <a class="btn btn-primary" href="Sign_in.php">Logout</a>
          </div>
        </div>
      </div>
    </div>
    <!-- Bootstrap core JavaScript-->
    <script src="vendor/jquery/jquery.min.js"></script>
    <script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
    <!-- Core plugin JavaScript-->
    <script src="vendor/jquery-easing/jquery.easing.min.js"></script>
    <!-- Page level plugin JavaScript-->
    <script src="vendor/chart.js/Chart.min.js"></script>
    <script src="vendor/datatables/jquery.dataTables.js"></script>
    <script src="vendor/datatables/dataTables.bootstrap4.js"></script>
    <!-- Custom scripts for all pages-->
    <script src="js/sb-admin.min.js"></script>
    <!-- Custom scripts for this page-->
    <script src="js/sb-admin-datatables.min.js"></script>
    <script src="js/sb-admin-charts.min.js"></script>
  </div>
</body>

</html>
