<?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>";
	}       
	          
	      
                    $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_homework 			= $row1['homework'];
			$u_test 			= $row1['test'];
			$u_exam			= $row1['exam'];
			
			$total = ($u_homework + $u_test + $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_homework 			= $row2['homework'];
			$us_test 			= $row2['test'];
			$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 = "F";
			}
			else if ($us_total >39 && $us_total<= 59)
			{
			$grade = "P";
			}
			else if ($us_total >59 && $us_total<= 79)
			{
			$grade = "C";
			}
			else if ($us_total >79 && $us_total<= 100)
			{
			$grade = "D";
			}
			
			
			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>MOTHERCARE INT'L SCHOOL: 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;
}
.style1 {color: #FFFFFF}
.Psychomotor {
	color: #F00;
}
.Psychomotor {
	color: #F00;
}
Assessment Title {
	color: #F00;
}
Assessment Title {
	color: #F00;
}
#page-top .content-wrapper .container-fluid .row .col-lg-12 div b center {
	color: #F00;
}
</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: #e6b3e6'><b>MOTHERCARE INT'L SCHOOL: ADMIN Dashboard</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="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>        </li>
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Charts">
          <a class="nav-link" href="#">
            <i class="fa fa-fw fa-clock-o" style="color: #3498db"></i>
            <span class="nav-link-text" style="color: white">Results</span>          </a>        </li>
        <li class="nav-item" data-toggle="tooltip" data-placement="right" title="Tables">
          <a class="nav-link" href="logout.php">
            <i class="fa fa-fw fa-money" 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></span>
        </li>
      </ul>
    </div>
  </nav>
  
  <div class="content-wrapper">
    <div class="container-fluid">
      <div align="center" vertical-align= "top" margin-top= "0px"><img src="mothercarelogo1.png" alt="MOTHERCARE INT'L SCHOOL" width="1080" height="122"><br>
        <?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);
		}
		if($AverageScore <=39){
			$htcomments = "Failure, work extremely hard next time" AND $cgrade = "F" AND $cgradeR = "FAIL";
			}
			else if ($AverageScore >39 && $AverageScore<= 59)
			{
			$htcomments = "Pass. Put more effort next term" AND $cgrade = "P" AND $cgradeR = "PASS";
			}
			else if ($AverageScore >59 && $AverageScore<= 79)
			{
			$htcomments = "Very Good Result, put more effort" AND $cgrade = "C" AND $cgradeR = "CREDIT";
			}
			else if ($AverageScore >79 && $AverageScore<= 100)
			{
			$htcomments = "Excellent Result, Keep it up" AND $cgrade = "D" AND $cgradeR = "DISTINCTION";
			}

		$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/profile/profile.jpg'>";
			}else{						
			$profile_pic = "<img width='100px' src='../admin/profile_pic/$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'];
			$overall	 		= $row1['overall'];
		}
		
		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 == 23){
		$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 if($user_position == 51){
		$user_p = "$user_position st";
		} else if($user_position == 52){
		$user_p = "$user_position nd";
		} else if($user_position == 53){
		$user_p = "$user_position rd";
		}else{
		$user_p = "$user_position th";
		}
		
	?>
        <?php
$rows = sql($DBH, "SELECT * FROM skills_and_remarksPri where registration_no = ? AND class =? AND term =? AND year =?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($rows as $row)
		{	
                $Attendance  		= $row['Attendance'];
                $Present  		= $row['Present'];
                $Absent  		= $row['Absent '];
                $NextTermBegins   		= $row['NextTermBegins'];               
                $DateOfReport  		= $row['DateOfReport'];
                $ClassTeachersComments  		= $row['ClassTeachersComments'];
                $Punctuality   		= $row['Punctuality'];                
                $Regularity   		= $row['Regularity'];                
                $Reliability   		= $row['Reliability'];
                $Neatness   		= $row['Neatness'];
                $Politeness   		= $row['Politeness'];                
                $Honesty   		= $row['Honesty'];                
                $Initiative   		= $row['Initiative'];
                $Perseverance   		= $row['Perseverance'];                
                $Attentiveness   		= $row['Attentiveness'];                
                $SelfControl   		= $row['SelfControl'];                
                $Obedience  		= $row['Obedience'];                
                $SenseOfResponsibility   		= $row['SenseOfResponsibility'];
                $HandWriting   		= $row['HandWriting'];
                $PublicSpeaking   		= $row['PublicSpeaking'];
                $HandlingTools   		= $row['HandlingTools'];
                $Drawing   		= $row['Drawing'];
                $Games   		= $row['Games'];
                $Painting   		= $row['Painting'];
                $Sports   		= $row['Sports'];
                $Music   		= $row['Music'];

                               }
?>
      </div>
      	  <Center> <div class='col-sm-12' style='font-size: 20px; color: Purple'>Student's Name: <b><?php echo $user_name ; ?></b> 
      	  </div></Center>

      <div class='row'>
	  <div class='col-sm-4'> 
	    <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>Session: </b> <u><?php echo $_GET['examyear']; ?></u></small><br>
	    <small><b>Age : </b>
	    <Big>
	    <?php
			
			$rows1 = sql($DBH, "SELECT * FROM tbl_user where hash = ?", array($SESS_HASH_USER), "rows");							
			foreach($rows1 as $row1)
			{	
				$dob   		= $row1['age'];
				$userst_registration_no   		= $row1['registration_no'];
				
				//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]));
    }
    
              
		$rows = sql($DBH, "SELECT MIN(id) AS id, class FROM tbl_student_results  WHERE registration_no = ? GROUP BY class", 
            	array($userst_registration_no), "rows");
		foreach($rows as $row)
		{	
			$userst_class	 		= $row['class'];
		}
		
		$rows = sql($DBH, "SELECT MAX(id) AS id, subclass FROM tbl_student_results  WHERE registration_no = ? GROUP BY subclass", 
            	array($userst_registration_no), "rows");
		foreach($rows as $row)
		{	
			$userst_subclass	 		= $row['class'];
		}
		
			 echo $age; ?>
	    </Big>Yr(s)	    </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><medium><?php echo $user_p ; ?></medium></u></small><br><br>
		  <small><b>Total Score: </b> <u><medium><?php echo $overall ; ?></medium></u></small><br>
		  <small><b> Average Score: </b> <u><?php echo $AverageScore ; ?></u></small><br>
		  <!--<small><b>Class Average Score: </b> <u><?php echo $b_in ; ?></u></small><br> -->
		  <Small><b>Term Ending: </b> <u><?php echo $DateOfReport; ?></u></Small><br>
		   <br>
		  <!--<small><b>Position: </b></small> <u><?php echo $user_p ; ?></u> ::--> 
		  <!--<small><b>Grade: </b></small> <u><?php echo $cgrade ; ?></u><br> -->
	  </div><br />
		<div class='col-sm-3'><small><b>Total Sch. Days: </b><small><big><big><u><?php echo $SchOpen; ?></u></big></big></small></small><br>
		  <small><b>Times Present: </b> <u><?php echo $Present; ?></u></small><br>
		  <!--<small><b>Times Punctual: </b> <u><?php echo $Punctual; ?></u></small><br> -->
		  <small><b>Times Absent: </b> <u><?php echo $Absent; ?></u></small><br>
		  <br>
		  <small><b>Next Term Begins : </b> <?php echo $TermBegins; ?></small><br>
		  <br>
	  </div>
		<div class='col-sm-2'>
			<?php echo $profile_pic ; ?><br/>
	</div>
      </div>
      <div class="row">
      <div class="col-sm-9">
            <b><u><Center><?php echo $_GET['term']; ?> SCHOOL REPORT For <?php echo $_GET['examyear']; ?></Center></u></b>
    </div>
      <div class="row">
      <div class="col-sm-9">
                            <div><b><u><Center>STUDENT'S CONTINUOUS ASSESSMENT REPORT</Center></u></b></div><table width="98%" border="1" class='table table-bordered'>
                                <tr style='font-size: 12px'>
                                    <th width="40%" class='text-center' colspan='2' valign="baseline" rowspan='3'>Subject</th>
                                    <th width="3%" colspan='1'  class='text-center'>Home Work</th>
                                    <th width="3%" colspan='1'  class='text-center'>Test</th>
                                    <th width="3%" colspan='1'  class='text-center'>Exam<br>
                                      Score</th>
                                    <th width="3%" colspan='1'  class='text-center'>Term<br>
                                    Total</th>
                                    <th  class='text-left' colspan='5'>Summary of Term's Work</th>
                                </tr>
                                <tr style='font-size: 12px'>
    								
    								<th bgcolor="#C1C1C1"  class='text-center'>30</th>	
    								<th bgcolor="#C1C1C1"  class='text-center'>20</th>	
    								<th bgcolor="#C1C1C1"  class='text-center'>50</th>	
    								<th bgcolor="#C1C1C1"  class='text-center'>100</th>	
   								  <th width="3%" rowspan='2' valign="baseline"  class='text-center'>Class <br/> 
   								  Avg.</th>
   								  <th width="10%" rowspan='2' valign="baseline"  class='text-left'>Grade</th>	
    								<th width="51%" rowspan='2' valign="baseline"  class='text-left'>Remarks</th>	
                                </tr>
                                <tr style='font-size: 10px'>

<?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'];
                $homework 		= $row['homework'];
                $test 		= $row['test'];
                $exam 		= $row['exam'];
                $total 		= $row['total'];
                $position 		= $row['position'];
                $remark 		= $row['grade'];
                $hremark 		= $row['hgrade'];
		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 == 23){
		$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 if($position == 51){
		$position = "$position st";
		} else if($position == 52){
		$position = "$position nd";
		} else if($user_position == 53){
		$position = "$position rd";
		} else{
		$position = "$position ";
		}
                
                                        
		$b_in_mn = sql($DBH, "SELECT MIN(total) FROM tbl_student_results where class =? AND year = ? AND term =? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$_GET['term'],$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 term =? AND subject =?", array($_GET['myclass'],$_GET['examyear'],$_GET['term'],$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){
			$gradee = "F" AND $remarkk = "Fail";
			}
			else if ($total >39 && $total<= 59)
			{
			$gradee = "P" AND $remarkk = "Pass";
			}
			else if ($total >59 && $total<= 79)
			{
			$gradee = "C"  AND $remarkk = "Credit";
			}
			else if ($total >79 && $total<= 100)
			{
			$gradee = "D"  AND $remarkk = "Distinction";
			}
			
		
			 
                
                echo"
                                <tr>
                                <td colspan='2'>$subject</td>
                                <td>$homework</td>
                                <td>$test</td>
                                <td>$exam</td>
                                <td>$total</td>
                                <td>$b_inmav</td>
                                <td>$gradee</td>
                                <td>$remarkk</td>
                                </tr>";
                               }
                               
?>
	          <?php
$rows = sql($DBH, "SELECT * FROM skills_and_remarksPri where registration_no = ? AND class =? AND term =? AND year =?", array($_GET['myreg'],$_GET['myclass'],$_GET['term'],$_GET['examyear']), "rows");							
		foreach($rows as $row)
		{	
                $Attendance  		= $row['Attendance'];
                $Present  		= $row['Present'];
                $Absent  		= $row['Absent '];
                $NextTermBegins   		= $row['NextTermBegins'];               
                $DateOfReport  		= $row['DateOfReport'];
                $ClassTeachersComments  		= $row['ClassTeachersComments'];
                $Punctuality   		= $row['Punctuality'];                
                $Regularity   		= $row['Regularity'];                
                $Reliability   		= $row['Reliability'];
                $Neatness   		= $row['Neatness'];
                $Politeness   		= $row['Politeness'];                
                $Honesty   		= $row['Honesty'];                
                $Initiative   		= $row['Initiative'];
                $Perseverance   		= $row['Perseverance'];                
                $Attentiveness   		= $row['Attentiveness'];                
                $SelfControl   		= $row['SelfControl'];                
                $Obedience  		= $row['Obedience'];                
                $SenseOfResponsibility   		= $row['SenseOfResponsibility'];
                $HandWriting   		= $row['HandWriting'];
                $PublicSpeaking   		= $row['PublicSpeaking'];
                $HandlingTools   		= $row['HandlingTools'];
                $Drawing   		= $row['Drawing'];
                $Games   		= $row['Games'];
                $Painting   		= $row['Painting'];
                $Sports   		= $row['Sports'];
                $Music   		= $row['Music'];
                               }
?>
</tr></tr>
</table>
<div class="col-sm-12">
    <div class="row">
        <div class="col-sm-3"><b>Grand Total:</b> <u><?php echo $overall ; ?></u></div>
        <div class="col-sm-3"><b>% Average:</b> <u><?php echo $AverageScore ; ?></u></div>
        <div class="col-sm-3"><b>Remarks:</b> <u><?php echo $cgradeR ; ?></u></div>
        <div class="col-sm-3"><b>Grade:</b> <u><?php echo $cgrade ; ?></u></div>
    </div>
</div>
<hr size="10">
       <tr>
                      <Center><strong><u>Grade Details:</u></strong>   <small><td height="120" bgcolor="#CCCCFF"><strong>79-100</strong> = Distinction. <strong>59-78</strong> = Credit. <strong>39-58</strong> = Pass.  <strong style='color: Red'>0-38 = Fail</strong><P></P></small></Center>
        </tr>
        </div>
    <div class="col-sm-3">
	          <table width="98%" height="5%" border="1" cellspacing="5">
	            <STRONG>AFFECTIVE DOMAIN REPORT</STRONG><tr style='font-size: 16px'>
            <tr style='font-size: 10px'>
	            <tr style='font-size: 12px'>
	              <td width="65%"><small><strong><span class="text-center">Punctuality</span></strong></small></td>
	              <td width="8%"><small><?php echo $Punctuality; ?></small></td>
                </tr>
	            <tr style='font-size: 12px'>
	              <td><small><strong><span class="text-center">Regularity</span></strong></small></td>
	              <td><?php echo $Regularity; ?></td>
                </tr>
	            <tr style='font-size: 12px'>
	              <td><small><strong>Reliability</strong></small></td>
	              <td><?php echo $Reliability; ?></td>
                </tr>
	            <tr style='font-size: 12px'>
	              <td><small><strong><span class="text-center">Neatness</span></strong></small></td>
	              <td><?php echo $Neatness; ?></td>
                </tr>
	            <tr style='font-size: 12px'>
	              <td><small><strong><span class="text-center">Politeness</span></strong></small></td>
	              <td><?php echo $Politeness; ?></td>
                </tr>
	            <tr style='font-size: 12px'>
	              <td><small><strong><span>Honesty</span></strong></small></td>
	              <td><?php echo $Honesty; ?></td>
                </tr>
                <tr style='font-size: 12px'>
	              <td><small><strong><span>Initiative</span></strong></small></td>
	              <td><?php echo $Initiative; ?></td>
                </tr>
                <tr style='font-size: 12px'>
	              <td><small><strong><span>Perseverance</span></strong></small></td>
	              <td><?php echo $Perseverance; ?></td>
                </tr>
                <tr style='font-size: 12px'>
	              <td><small><strong><span>Attentiveness</span></strong></small></td>
	              <td><?php echo $Attentiveness; ?></td>
                </tr>
                <tr style='font-size: 12px'>
	              <td><small><strong><span>SelfControl</span></strong></small></td>
	              <td><?php echo $SelfControl; ?></td>
                </tr>
                <tr style='font-size: 12px'>
	              <td><small><strong><span>Obedience</span></strong></small></td>
	              <td><?php echo $Obedience; ?></td>
                </tr><tr style='font-size: 12px'>
	              <td><small><strong><span>'Sense Of Responsibility'</span></strong></small></td>
	              <td><?php echo $SenseOfResponsibility; ?></td>
                </tr><tr style='font-size: 12px'>
	              <td><small><strong><span>Hand Writing</span></strong></small></td>
	              <td><?php echo $HandWriting; ?></td>
                </tr><tr style='font-size: 12px'>
	              <td><small><strong><span>Public Speaking</span></strong></small></td>
	              <td><?php echo $PublicSpeaking; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Handling Tools</span></strong></small></td>
	              <td><?php echo $HandlingTools; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Drawing</span></strong></small></td>
	              <td><?php echo $Drawing; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Games</span></strong></small></td>
	              <td><?php echo $Games; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Painting</span></strong></small></td>
	              <td><?php echo $Painting; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Sports</span></strong></small></td>
	              <td><?php echo $Sports; ?></td>
                </tr><tr style='font-size: 12px'>
                    <td><small><strong><span>Music</span></strong></small></td>
	              <td><?php echo $Music; ?></td>
                </tr>
                </table><br />
	           <tr>
                      <strong><u>Key:</u><br /></strong> <td height="176" bgcolor="#CCCCFF"><strong>1</strong> = Exellent.<br />  <strong>2</strong> = Very Good.<br />     <strong>3</strong> = Good.<br />  <strong>4</strong> = Fair.<br />   <strong>5</strong> = Poor.<br /><P></P>
        </tr>

    </div>
<br />
<br />

	    <br /><P>
	  <div class='col-sm-10'><small><b>Form Teacher's Comment :</b></small><medium><u><?php echo $ClassTeachersComments; ?></u></medium>
	    <br>
	    <small><b>Principal's Comment : </b></small><medium><u><?php echo $htcomments; ?></u></medium><br></P>
	  </div>
	</div>
      <center><button onclick="myFunction()">|||| PRINT THIS RESULT ||||</button></div></center>
<script>
function myFunction() {
    window.print();
}
</script>
    </div>
</div>
          </div>
    <!-- /.container-fluid-->
    <!-- /.content-wrapper-->
    <footer class="sticky-footer" style="background: #ac39ac">
      <div class="container">
        <div class="text-center"> <small><strong><span class="style1">Copyright © 2021-2022 MOTHERCARE INT'L SCHOOL: All Rights Reserved!</span></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>
