<?php
include("db.php");
$mss=0; $smsAry="";
$ch=$_REQUEST["type"];

if($ch=="smsprint"){
?>
<div id="printableDiv">
<?php	
$allStudent=$db->getRows("select * from student where school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."' and class='".$_REQUEST["class"]."' and idno='".$_SESSION["user"]["uid"]."' and status=1 and issue_TC=0 order by name");
$examtype=$db->getRows("select name,id,total from examterm where school_id='".$_SESSION["user"]["school_id"]."' order by lorder");
if(is_array($allStudent) && count($allStudent)>0){
	foreach($allStudent as $aryForm){$mss++;$he++;
	//echo $_REQUEST["term"];
  if($_REQUEST["term"]=="term1" || $_REQUEST["term"]=="term2"){ ?>
	  <!--one page <div style="height:942px">end --> 
	  <!--two page-->
	  <div style="height:962px;margin-bottom:20px;">
	  <div style="height:955px;border:8px solid #D5DA13;">
		<?php
		$_GET['id']=$aryForm["idno"];
		error_reporting(55);
		$_REQUEST["class"]=$db->getVal("select class from student where school_id='".$_SESSION["user"]["school_id"]."' and idno=".$aryForm["idno"]);
		$exam=$db->getVal("select idno from student where school_id='".$_SESSION["user"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["user"]["session"]."' limit 0,1");
		//echo $db->getLastQuery();
		$termWhere="";if($_REQUEST["term"]!="final") $termWhere=" and term='".$_REQUEST["term"]."' ";
		$examtype=$db->getRows("select name,id,total from examterm  where school_id='".$_SESSION["user"]["school_id"]."' $termWhere order by lorder");
		//echo $db->getLastQuery();print_r($examtype);
		if(count($exam)>0){
		?>
		<?php $aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm['idno']."'");$overallTotalGrade=0; ?>
		<form method="post" action="">
		  <input type="hidden" name="class" value="<?php echo $_REQUEST["class"] ?>" />
		  <input type="hidden" name="idno" value="<?php echo $aryForm["idno"] ?>" />
		  <div class="row-fluid">
			<div class="span12">
			  <div class="well" >
			  <div class="headPrint hide" style="border: none;">
			 
			  
			 <div style="margin-left:22px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="110px" style="margin:6px 0px 0px 10px;"></div>
			 <div style="float:left;text-align:center;margin-bottom:18px;"> <h1 style="font-size:32px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
			   <span style="font-size:17px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
			 </div> 
		  </div>
				
				<div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 1px solid #000;"> ACADEMIC PERFORMANCE (<?php echo ucwords($_POST['term']); ?> : <?php echo $_SESSION["user"]["session"];?>)</div>
				<table style="width:100%;font-size:13px;font-weight: bold;color:#1224A5;" cellpadding="5" cellspacing="2">
				  <tr>
					<td width="20%">Name</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["name"] ?></td>
					<td width="20%">Class</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["class"] ?></td>
					<td width="20%">Section</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["section"] ?></td>
				   
				  </tr>
				  <tr>
					<td width="20%"><strong class="st">Father's Name</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["fname"] ?></td>
					<td width="20%"><strong class="st">Admission No.</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["admissionno"] ?></td>
					<td width="21%"><strong class="st">Contact</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["mobile"] ?></td>
					
				  </tr>
				  <tr>
					<td width="21%"><strong class="st">Mother's Name</strong></td><td width="2%">:</td>
					<td width="30%"><?php echo $aryForm["mname"] ?></td>
					<td width="20%"><strong class="st">D.O.B</strong></td><td width="2%">:</td>
					<td width="30%"><?php if($aryForm["dob"]!="")echo date("d-M-Y",strtotime($aryForm["dob"])); ?></td>
					
				  </tr>
				 
				</table>
				<table style="width:100%; font-size:14px;border-top:1px solid #000;border-bottom:1px solid #000;text-align: center;color: #1224A5;
	font-weight: 800;" cellpadding="3" cellspacing="0">
						
						<tr style="background-color: #D5DA13;font-weight: 800;padding: 5px;color: #000;">
							<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="22%">SUBJECTS</td>
							<?php 
							
							if(is_array($examtype) && count($examtype)>0){
								 $finalObtain=0;$finalTotal=0;
								foreach($examtype as $eytpe){ //echo "<pre>";print_r($eytpe);echo "</pre>";?>
								<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="15%">
								<input type="hidden" name="type[]" style="width:80px" class="total" value="<?php echo $eytpe[0] ?>" placeholder="Exam type" /><?php echo $eytpe[0] ?>
	</td>
							<?php }
							}?>
							<?php if($_REQUEST["term"]=="final"){?> 
							<td style="border-right:2px solid #FA0606">FA</td>
							<td style="border-right:2px solid #FA0606">SA</td>
							<td style="border-right:2px solid #FA0606">Grade</td>
							<?php }elseif($_REQUEST["term"]=="term1"){ ?>
							<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="15%">FA1+FA2+SA1</td>
							<?php }elseif($_REQUEST["term"]=="term2"){ ?>
							<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">FA3+FA4+SA2</td>
							<?php } ?>
							<td style="border-bottom: 1px solid #000;" width="18%">Grade Point</td>
						</tr>
						
						<?php $x=0;
						$detail=$db->getRows("select * from subject where school_id='".$_SESSION["user"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["user"]["session"]."' order by id");
						foreach($detail as $d){ $fsAry=array();$final="";
						?><tr>
								<td style="border-right:2px solid #FA0606"><?php echo ucfirst($d["subject"]) ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
								<?php 
								for($i=1; $i<=count($examtype);$i++){ 
								$examResultData=$db->getRow("select * from exammarks where idno='".$aryForm["idno"]."' and type='".$examtype[$i-1][0]."' and subject='".$d["subject"]."'");
								?>
								<td style="border-right:2px solid #FA0606">
								<input readonly="readonly" type="hidden" style="width:40px" name="<?php echo $d["subject"]."_".$examtype[$i-1][0];?>[]" class="<?php echo $examtype[$i-1][0];?>_total_marks total" value="<?php
								echo $total=$db->getVal("select total from examterm where school_id='".$_SESSION["user"]["school_id"]."' and id='".$examtype[$i-1][1]."'"); ?>" placeholder="Total Maks" />
								 <input required type="hidden" style="width:70px" name="<?php echo $examtype[$i-1][0];?>_student[]" class="onlyZero obtain <?php echo $examtype[$i-1][0];?>_obtain_marks" value="<?php echo (int)$examResultData["obtain"]; ?>" placeholder="Obtain Maks" />
								 <?php
								 $fs=$examtype[$i-1][0];
								 $fsAry[$fs."_Obtain"]=$examResultData["obtain"];
								 $fsAry[$fs."_Total"]=$total;
								  echo FindGrade($examResultData["obtain"],$total);//."/".$examResultData["obtain"]."-".$total; ?>
								 </td>
								<?php }$x++; ?>
								<?php if($_REQUEST["term"]=="final"){?> 
								<td style="border-right:2px solid #FA0606"><?php $faObtain=$fsAry["FA1_Obtain"]+$fsAry["FA2_Obtain"]+$fsAry["FA3_Obtain"]+$fsAry["FA4_Obtain"];$faTotal=$fsAry["FA1_Total"]+$fsAry["FA2_Total"]+$fsAry["FA3_Total"]+$fsAry["FA4_Total"];echo FindGrade($faObtain,$faTotal); ?></td>

								<td style="border-right:2px solid #FA0606"><?php $saObtain=$fsAry["SA1_Obtain"]+$fsAry["SA2_Obtain"];$saTotal=$fsAry["SA1_Total"]+$fsAry["SA2_Total"];echo FindGrade($saObtain,$saTotal); ?></td>
								<td style="border-right:2px solid #FA0606">
								<?php 
								$AllObtain = $saObtain + $faObtain;
								$AllTotal = $saTotal + $faTotal;
								echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
								$finalObtain+=$AllObtain;
								$finalTotal+=$AllTotal;
								?>
								</td>
								<?php }elseif($_REQUEST["term"]=="term1"){ ?>
								<td style="border-right:2px solid #FA0606"><?php $fa1Obtain=$fa2Obtain=0;
									$fa1Obtain=($fsAry["FA1_Obtain"]*100)/$fsAry["FA1_Total"];
									$fa2Obtain=($fsAry["FA2_Obtain"]*100)/$fsAry["FA2_Total"];
									$saObtain=($fsAry["SA1_Obtain"]*100)/$fsAry["SA1_Total"];
									$fa1Obtain=(10*$fa1Obtain)/100;
									$fa2Obtain=(10*$fa2Obtain)/100;
									$saObtain=(30*$saObtain)/100;
									
									$faObtain=$fa1Obtain + $fa2Obtain;
									$AllTotal =50;
									$AllObtain = $saObtain + $faObtain;
									echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
									$finalObtain+=$AllObtain;
									$finalTotal+=$AllTotal;
								?></td>
								<?php }elseif($_REQUEST["term"]=="term2"){ ?>
								<td style="border-right:2px solid #FA0606"><?php 
									$fa1Obtain=($fsAry["FA3_Obtain"]*100)/$fsAry["FA3_Total"];
									$fa2Obtain=($fsAry["FA4_Obtain"]*100)/$fsAry["FA4_Total"];
									$saObtain=($fsAry["SA2_Obtain"]*100)/$fsAry["SA2_Total"];
									$fa1Obtain=(10*$fa1Obtain)/100;
									$fa2Obtain=(10*$fa2Obtain)/100;
									$saObtain=(30*$saObtain)/100;
									
									$faObtain=$fa1Obtain + $fa2Obtain;
									$AllTotal =50;
									//$faObtain=$fsAry["FA3_Obtain"]+$fsAry["FA4_Obtain"];
									//$faTotal=$fsAry["FA3_Total"]+$fsAry["FA4_Total"];
									//$saObtain=$fsAry["SA2_Obtain"];
									//$saTotal=$fsAry["SA2_Total"];
									$AllObtain = $saObtain + $faObtain;
									//$AllTotal = $saTotal + $faTotal;
									echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
									$finalObtain+=$AllObtain;
									$finalTotal+=$AllTotal;
								?></td>
								<?php } ?>
								<td><?php $tgrade=$db->getVal("select point from examgrade where grade='".$final."'"); echo (float)$tgrade; $overallTotalGrade+=$tgrade;?></td>
							</tr>
						<?php
						 $stid=$_GET["id"];$subj1=$d["subject"];
						$smsAry.="$stid~$subj1~".$final."<br/>";
						} 
						?>
						</table>
				<div style="width:100%;height:52px;border-bottom: 2px solid #F71111;text-align:center;font-weight:800;color: #1224A5;">        
				 <div style="float:left;width:49%;">
					 <div style="width:100%;background:#D5DA13;padding:5px;border-bottom:1px solid #000;color:#000;">REMARKS BY CLASS TEACHER</div>
					 <span>Keep Up The Good Work</span>
				 </div>
				 <div style="font-size:16px;float:left;width:50%;border-left:2px solid #F71111;text-align:left;">
					<div style="width:100%;background:#D5DA13;border-bottom:1px solid #000;padding:5px;color:#000;">CGPA </div> 
					<span style="padding:5px;font-size:17px">
					<?php $c=$overallTotalGrade/count($detail); echo $cgpa=number_format((float)$c, 2, '.', ''); ?></span>
				    <?php $attr=$db->getRow("select * from allattandence where idno='".$aryForm["idno"]."' and session='".$_SESSION["user"]["session"]."'"); 
				 
				?>
					<div style="margin-top:4px;">
                   <?php if($attr!=NULL){?>
						 <div style="background:#D5DA13;color:#000;width:100%;float:left;padding:4px;border-top:1px solid #000;border-bottom:1px solid #000;">ATTENDANCE</div>
						<span style="padding:5px;">Total Attendance of the student : <?php if($_REQUEST["term"]=="term1")echo $attr['term1_att'];elseif($_REQUEST["term"]=="term2") $attr['term2_att'];?></span><br/>
						<span style="padding:5px">Total working days : <?php if($_REQUEST["term"]=="term1")echo $LinksDetails['term1_all_day'];elseif($_REQUEST["term"]=="term2") $LinksDetails['term2_all_day']?></span>
                    <?php } ?>    
					</div>
                   
					</div>
				</div>
				
				<?php
				$smsAry.="$stid~-------~<br/>";
				$smsAry.="$stid~FINAL CGPA~".$cgpa."<br/>";
				echo $db->getErMsg();
					?>
						 <div>
							   <table style="width:100%; text-align:center;font-size:14px;border-bottom: 2px solid #F71111;height: 90px;font-weight: 800;color: #1224A5;" cellpadding="0" cellspacing="2" >
								<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
								</tr>
								<tr style="vertical-align: bottom;">
								  <td width="25%">Date</td>
								  <td>Class teacher</td>
								  <td>Principal</td>
								  <td>Parents/Guardian</td>
								</tr>
							  </table>
						</div>
						 <div style="margin-left: 5px;">
			<div style="width:65%;float:left;  margin-top: 10px;color:#1224A5;font-size: 13px;font-weight: 800;">
				Subject wise Indicative percentage of marks = 9.5 x GP of the subject <br/><br/>
			   First Term - FA1(10%)+FA2(10%)+SA1(30%) = 50%  <br/><br/>
				Second Term - FA3(10%)+FA4(10%)+SA2(30%) = 50% <br/><br />
				FORMATIVE ASSESSMENT(FA) 1 + 2 + 3 + 4 = 40%   <br/><br />
				SUMMATIVE ASSESSMENT(SA) 1 + 2 = 60%           <br/><br />
				CGPA is calculated excluding 3rd language.
			</div>
			<div style="width:34%;float:left;margin-top:8px;">
			<table border="1" cellpadding="3" cellspacing="0" style="text-align:center;color:#1224A5;font-size: 13px;font-weight: 800;">
				<tr>
					<td colspan="3">GRADING SYSTEM - SCHOLASTIC</td>
				</tr>
				<tr>
					<td>MARK RANGE</td><td>GRADE</td><td>GRADE POINT</td>
				</tr>
				<tr>
					<td>91 - 100</td><td>A1</td><td>10.0</td>
				</tr>
				<tr>
					<td>81 - 90</td><td>A2</td><td>9.0</td>
				</tr>
				<tr>
					<td>71 - 80</td><td>B1</td><td>8.0</td>
				</tr>
				<tr>
					<td>61 - 70</td><td>B2</td><td>7.0</td>
				</tr>
				<tr>
					<td>51 - 60</td><td>C1</td><td>6.0</td>
				</tr>
				<tr>
					<td>41 - 50</td><td>C2</td><td>5.0</td>
				</tr>
				<tr>
					<td>33 - 40</td><td>D</td><td>4.0</td>
				</tr>
				<tr>
					<td>21 - 32</td><td>E1</td><td>3.0</td>
				</tr>
				<tr>
					<td>0 - 20</td><td>E2</td><td>2.0</td>
				</tr>
			</table>
			</div>
		</div>
			  </div>
			</div>
		  </div>
		</form>
		<?php
		}
			?>
	   
	  </div>
	  </div>
	<?php }
	   elseif($_REQUEST["term"]=="final"){ ?>
		  
		  <div style="height:715px;margin-bottom:20px; <?php if($he!=1){?> padding-top: 10px;<?php } ?>">
	  <div style="height:707px;border:8px solid #D5DA13;font-size:14px;"><!--end --> 
		<!--three page <div style="height:2826px">end -->
		<?php
		$_GET['id']=$aryForm["idno"];
		error_reporting(55);
		$_REQUEST["class"]=$db->getVal("select class from student where school_id='".$_SESSION["user"]["school_id"]."' and idno=".$aryForm["idno"]);
		$exam=$db->getVal("select idno from student where school_id='".$_SESSION["user"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["user"]["session"]."' limit 0,1");
		
		$termWhere="";if($_REQUEST["term"]!="final") $termWhere=" and term='".$_POST["term"]."' ";
		$examtype=$db->getRows("select name,id,total from examterm  where school_id='".$_SESSION["user"]["school_id"]."' $termWhere order by lorder");
		//echo $db->getLastQuery();print_r($examtype);
		if(count($exam)>0){
		?>
		<?php $aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["user"]["school_id"]."' and idno='".$aryForm['idno']."'");$overallTotalGrade=0; ?>
		<form method="post" action="">
		  <input type="hidden" name="class" value="<?php echo $_REQUEST["class"] ?>" />
		  <input type="hidden" name="idno" value="<?php echo $aryForm["idno"] ?>" />
		  <div class="row-fluid">
			<div class="span12">
			  <div class="well" >
			  <div class="headPrint hide" style="border: none;">
			 
			  
			 <div style="margin-left:226px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="80px" style="margin:12px 0px 0px 10px;"></div>
			 <div style="float:left;text-align:center;margin-bottom:17px;"> <h1 style="font-size:38px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
			   <span style="font-size:17px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>
			 </div> 
		  </div>
				
				<div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 1px solid #000;"> PERFORMANCE PROFILE [C. C. E.] FINAL (SESSION : <?php echo $_SESSION["user"]["session"];?>)</div>
				<table style="width:50%;font-size:13px;font-weight: bold;color:#1224A5;float:left" cellpadding="5" cellspacing="2">
				  <tr>
					<td width="20%">Name</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["name"] ?></td>
					<td width="20%"><strong class="st">Admission No.</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["admissionno"] ?></td>
				  </tr>
				  <tr>
					<td width="20%">Class</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["class"] ?></td>
					<td width="20%">Section</td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["section"] ?></td>
				   </tr>
				 <tr>
					<td width="20%"><strong class="st">Father's Name</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["fname"] ?></td>
					<td width="20%"><strong class="st">D.O.B</strong></td><td width="2%">:</td>
					<td width="21%"><?php if($aryForm["dob"]!="")echo date("d-M-Y",strtotime($aryForm["dob"])); ?></td>
					
				 </tr>
				 <tr>
					<td width="21%"><strong class="st">Mother's Name</strong></td><td width="2%">:</td>
					<td width="38%"><?php echo $aryForm["mname"] ?></td>
					<td width="21%"><strong class="st">Contact</strong></td><td width="2%">:</td>
					<td width="21%"><?php echo $aryForm["mobile"] ?></td>
				 </tr>
				</table>
                <?php $attr=$db->getRow("select * from allattandence where idno='".$aryForm["idno"]."' and session='".$_SESSION["user"]["session"]."'"); 
				  if($attr!=NULL){
				?>
               	<table border="1" style="float:left;margin:29px 40px 5px 40px;font-weight: bold;color:#1224A5;text-align:center;" cellpadding="3" cellspacing="0">
					<tr>
						<td>Attendance</td><td>TERM-I</td><td>TERM-II</td>
					</tr>
					<tr>
						<td>Total Present Days</td><td><?php echo $attr['term1_att']?></td><td><?php echo $attr['term2_att']?></td>
					</tr>
					<tr>
						<td>Total Working Days</td><td><?php echo $LinksDetails['term1_all_day']?></td><td><?php echo $LinksDetails['term2_all_day']?></td>
					</tr>
				</table>
				<?php } if($aryForm['photo']!=""){ ?> 
					<div style="float:right;margin:5px 30px 0px 0px;  border: 4px solid #6B6868;">
					<img src="media/photo/<?php echo $aryForm["photo"]; ?>" style="height:96px;width:90px" />
				   
					 </div>     
				 <?php } ?> 
				 <div style="font-size: 16px;clear: both;background-color: #D5DA13;font-weight: bold;padding: 5px;color: #000;text-align: center;  border-top: 1px solid #000;border-bottom: 1px solid #FA0606;"> ACADEMIC PERFORMANCE - SCHOLASTIC AREAS</div>  
				<table style="width:100%; font-size:13px;margin:0;border-top:1px solid #FA0606 ;border-bottom:1px solid #000;text-align: center;color: #1224A5;font-weight: 800;" cellpadding="5" cellspacing="0">
						
						<tr  style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							<td rowspan="2" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606;padding:5px;" width="16%">SUBJECTS</td>
							<td colspan="4" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">TERM-I</td>
							<td colspan="4" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">TERM-II</td>
							<td colspan="4" style="border-right:2px solid #FA0606;border-bottom: 2px solid #FA0606; text-align:center">(OVERALL GRADE)</td>
						</tr>
						<tr style="background-color: #FFEA15;font-weight: 800;padding: 0px;color: #000;">
							
							<?php 
							
							if(is_array($examtype) && count($examtype)>0){
								 $finalObtain=0;$finalTotal=0;$f=0;
								foreach($examtype as $eytpe){ $f++; //echo "<pre>";print_r($eytpe);echo "</pre>";
								if($f==4){?>
								<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="7%">TOTAL FA+SA1</td>
								<?php }  ?>
								<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="7%">
								<input type="hidden" name="type[]" style="width:80px" class="total" value="<?php echo $eytpe[0] ?>" placeholder="Exam type" /><?php echo $eytpe[0] ?>
	</td>
							<?php }
							}?>
							<?php if($_REQUEST["term"]=="final"){?>
							 
							
							<td width="3%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">TOTAL FA+SA2</td> 
							<td width="3%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">TOTAL FA</td>
							<td width="3%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">TOTAL SA</td>
							<td width="3%" style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;">OVERALL GRADE</td>
							
							<?php } ?>
							<td width="3%" style="border-bottom: 2px solid #6F6868;">G.P.</td>
						</tr>
						
						<?php $x=0;
						$detail=$db->getRows("select * from subject where school_id='".$_SESSION["user"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["user"]["session"]."' order by id");
						foreach($detail as $d){ $fsAry=array();$final="";
						?><tr>
								<td style="border-right:2px solid #FA0606"><?php echo ucfirst($d["subject"]) ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
								<?php 
								for($i=1; $i<=count($examtype);$i++){ 
								$examResultData=$db->getRow("select * from exammarks where idno='".$aryForm["idno"]."' and type='".$examtype[$i-1][0]."' and subject='".$d["subject"]."'");
								?>
								<td style="border-right:2px solid #FA0606">
								<input readonly="readonly" type="hidden" style="width:40px" name="<?php echo $d["subject"]."_".$examtype[$i-1][0];?>[]" class="<?php echo $examtype[$i-1][0];?>_total_marks total" value="<?php
								echo $total=$db->getVal("select total from examterm where school_id='".$_SESSION["user"]["school_id"]."' and id='".$examtype[$i-1][1]."'"); ?>" placeholder="Total Maks" />
								 <input required type="hidden" style="width:70px" name="<?php echo $examtype[$i-1][0];?>_student[]" class="onlyZero obtain <?php echo $examtype[$i-1][0];?>_obtain_marks" value="<?php echo (int)$examResultData["obtain"]; ?>" placeholder="Obtain Maks" />
								 <?php
								 $fs=$examtype[$i-1][0];
								 $fsAry[$fs."_Obtain"]=$examResultData["obtain"];
								 $fsAry[$fs."_Total"]=$total;
								  echo FindGrade($examResultData["obtain"],$total);//."/".$examResultData["obtain"]."-".$total; ?>
								 </td>
								<?php if($i==3){?>
										 <td style="border-right:2px solid #FA0606"><?php 
											$fa1Obtain=($fsAry["FA1_Obtain"]*100)/$fsAry["FA1_Total"];
											$fa2Obtain=($fsAry["FA2_Obtain"]*100)/$fsAry["FA2_Total"];
											$sa1Obtain=($fsAry["SA1_Obtain"]*100)/$fsAry["SA1_Total"];
											$fa1Obtain=(10*$fa1Obtain)/100;
											$fa2Obtain=(10*$fa2Obtain)/100;
											$sa1Obtain=(30*$sa1Obtain)/100;
											
											$faObtain=$fa1Obtain + $fa2Obtain;
											$AllTotal = 50;
											$AllObtain = $sa1Obtain + $faObtain;
											//$AllTotal = $saTotal + $faTotal;
											echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
											$finalObtain+=$AllObtain;
											$finalTotal+=$AllTotal;
										?></td>
								<?php  } ?>
								<?php }$x++; ?>
								<?php if($_REQUEST["term"]=="final"){?> 
									<!-- overall term1 FA+SA1 -->
							   
									  <!-- overall term2 FA+SA -->
								<td style="border-right:2px solid #FA0606"><?php 
									$fa3Obtain=($fsAry["FA3_Obtain"]*100)/$fsAry["FA3_Total"];
									$fa4Obtain=($fsAry["FA4_Obtain"]*100)/$fsAry["FA4_Total"];
									$sa2Obtain=($fsAry["SA2_Obtain"]*100)/$fsAry["SA2_Total"];
									$fa3Obtain=(10*$fa3Obtain)/100;
									$fa4Obtain=(10*$fa4Obtain)/100;
									$sa2Obtain=(30*$sa2Obtain)/100;
									
									$faObtain=$fa3Obtain + $fa4Obtain;
									$AllTotal =50;
									$AllObtain = $sa2Obtain + $faObtain;
									//$AllTotal = $saTotal + $faTotal;
									echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
									$finalObtain+=$AllObtain;
									$finalTotal+=$AllTotal;
								?></td>
								 <!-- overall final term FA+SA+Overall Grade -->
								<td style="border-right:2px solid #FA0606"><?php 
											$fa1Obtain=($fsAry["FA1_Obtain"]*100)/$fsAry["FA1_Total"];
											$fa2Obtain=($fsAry["FA2_Obtain"]*100)/$fsAry["FA2_Total"];
											$fa3Obtain=($fsAry["FA3_Obtain"]*100)/$fsAry["FA3_Total"];
											$fa4Obtain=($fsAry["FA4_Obtain"]*100)/$fsAry["FA4_Total"];
											$fa1Obtain=(10*$fa1Obtain)/100;
											$fa2Obtain=(10*$fa2Obtain)/100;
											$fa3Obtain=(10*$fa3Obtain)/100;
											$fa4Obtain=(10*$fa4Obtain)/100;
											$faObtain=$fa1Obtain + $fa2Obtain + $fa3Obtain + $fa4Obtain;
											$faTotal=40;
//$faObtain=$fsAry["FA1_Obtain"]+$fsAry["FA2_Obtain"]+$fsAry["FA3_Obtain"]+$fsAry["FA4_Obtain"];$faTotal=$fsAry["FA1_Total"]+$fsAry["FA2_Total"]+$fsAry["FA3_Total"]+$fsAry["FA4_Total"];
								echo FindGrade($faObtain,$faTotal);//."/".$faObtain."-".$faTotal; ?></td>
								<td style="border-right:2px solid #FA0606"><?php
									$sa1Obtain=($fsAry["SA1_Obtain"]*100)/$fsAry["SA1_Total"];
									$sa2Obtain=($fsAry["SA2_Obtain"]*100)/$fsAry["SA2_Total"];
									$sa1Obtain=(30*$sa1Obtain)/100;
									$sa2Obtain=(30*$sa2Obtain)/100;
									$saObtain=$sa1Obtain + $sa2Obtain;
									$saTotal=60;
								 //$saObtain=$fsAry["SA1_Obtain"]+$fsAry["SA2_Obtain"];$saTotal=$fsAry["SA1_Total"]+$fsAry["SA2_Total"];
								 echo FindGrade($saObtain,$saTotal);//."/".$saObtain."-".$saTotal; ?></td>
								<td style="border-right:2px solid #FA0606">
								<?php 
								$AllObtain = $saObtain + $faObtain;
								$AllTotal = $saTotal + $faTotal;
								echo $final=FindGrade($AllObtain,$AllTotal);//."/".$AllObtain."-".$AllTotal;
								$finalObtain+=$AllObtain;
								$finalTotal+=$AllTotal;
								?>
								</td>
								<?php } ?>
								
								<td><?php $tgrade=$db->getVal("select point from examgrade where grade='".$final."'"); echo (float)$tgrade; $overallTotalGrade+=$tgrade;?></td>
							</tr>
						<?php
						 $stid=$_GET["id"];$subj1=$d["subject"];
						$smsAry.="$stid~$subj1~".$final."<br/>";
						} 
						?>
						</table>
				<div style="width:100%;height:48px;border-bottom: 2px solid #F71111;text-align:center;font-weight:800;color: #1224A5;">        
				 <div style="float:left;width:49%;">
					 <div style="width:100%;background:#D5DA13;padding:5px;border-bottom:1px solid #000;color:#000;margin-bottom: 5px;">
							REMARKS BY CLASS TEACHER</div>
					 <span>Keep Up The Good Work</span>
				 </div>
				 <div style="font-size:14px;float:left;width:50%;border-left:2px solid #F71111;text-align:left;">
					<div style="width:100%;background:#D5DA13;border-bottom:1px solid #000;padding:5px;color:#000;">CGPA : 
					<?php $c=$overallTotalGrade/count($detail); echo $cgpa=number_format((float)$c, 2, '.', ''); ?></div> 
					<div style="width:100%;padding: 5px 5px 0px 5px;font-size:14px;background:#FFEA15;">RESULT : Promoted
					</div>
				 
					<!--<div style="margin-top:4px;">
						 <div style="background:#FFEA15;color:#000;width:100%;float:left;padding:4px;border-top:1px solid #000;border-bottom:1px solid #000;">ATTENDANCE</div>
						<span style="padding:5px;">Total Attendance of the student : 70</span><br/>
						<span style="padding:5px">Total working days : 95</span>
					</div>-->
					</div>
				</div>
				
				<?php
				$smsAry.="$stid~-------~<br/>";
				$smsAry.="$stid~CGPA~".$cgpa."<br/>";
				echo $db->getErMsg();
					$type=$db->getRows("select * from criteria where school_id='".$_SESSION["user"]["school_id"]."' group by type order by id");
					if(is_array($type) && count($type)>0){
						?>
			  <!--  <div style="font-size:12px;  clear:both; background-color: #ccc; margin-top:20px; padding: 3px; color: #000;">Part–II :  Co-Scholastic Areas </div>
				<div style="width:48%; display:inline-block; vertical-align:top; margin:0 2% 2% 0">
				  <?php $ijk=0;
							foreach($type as $t){$ijk++;
								if($ijk%4==0)echo '</div><div style="width:48%; display:inline-block;  vertical-align:top;  margin:0 2% 2% 0">';
								?>
								
								<table border="1" style="width:100%;font-size:11px; margin-top:10px; display:inline-table" cellpadding="0" cellspacing="0">
						<tbody id="tbodyskill">
							<tr><th colspan="3"><?php echo $t["type"] ?></th></tr>
						  <?php
										 $lifeskill=$db->getRows("select * from criteria where school_id='".$_SESSION["user"]["school_id"]."' and type='".$t["type"]."'");
										 echo $db->getErMsg(); $i=1;
										 //echo"<pre>";print_r($all_product);echo"</pre>";
										  if(is_array($lifeskill) && count($lifeskill))
										  {
											   ?>
						  <tr>
							<th>Trait</th>
							<th>Descriptive_	Indicators</th>
							<th>Grade</th>
						  </tr>
						  <?php
											  
											foreach($lifeskill as $iSkill)
											{
												$grade=$db->getVal("select grade from examcriteriarecord where idno='".$_GET['id']."' and term='".$_REQUEST["term"]."' and criteria='".$t["type"]."' and subcriteria='".$iSkill["name"]."' and school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."'");
										 ?>
						  <tr>
							<td width="200px"><?php echo $iSkill["name"]; ?></td>
							<td ><?php echo $db->getVal("select detail from grade where grade='".$grade."' and  school_id='".$_SESSION["user"]["school_id"]."' and session='".$_SESSION["user"]["session"]."'  and criteria='".$t["type"]."' ");//echo $db->getLastQuery() ?></td>
							<td width="55px"><?php echo $grade; ?></td>
						  </tr>
						  <?php $i++;
											} 
										}
										 ?>
						</tbody>
					  </table>
					  
				  <?php
							}
							?>
			   </div>-->
				<?php
							echo $db->getErMsg();
						}
						?>
						 <div style="border-bottom:2px solid #F71111;height: 80px;">
								<div style="float:left;font-size:12px;font-weight:800;color: #1224A5;">
									<ul>
										<li>Subject wise Indicative percentage of marks = 9.5 x GP of the subject </li>
										<li>CGPA is calculated excluding 3rd language</li>
										<li>Student must obtain the qualifyig Grade (min grade-D) in all subjects.</li>
										<li>Overall indicative % of marks = 9.5 x CGPA</li>
									</ul>
								</div>
							   <table style="width:60%;margin:0;text-align:center;font-size:13px;border-left:2px solid #F71111;height: 80px;font-weight: 800;color: #1224A5;float:right;" cellpadding="0" cellspacing="2" >
								<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
								</tr>
								<tr style="vertical-align: bottom;">
								  <td width="25%">Student</td>
								  <td>Class teacher</td>
								  <td>Principal</td>
								  <td>Parents/Guardian</td>
								</tr>
							  </table>
						</div>
						<!--<div style="margin-left: 5px;">
			<div style="width:65%;float:left;  margin-top: 10px;color:#1224A5;font-size: 13px;font-weight: 800;">
				Subject wise Indicative percentage of marks = 9.5 x GP of the subject <br/><br/>
			   First Term - FA1(10%)+FA2(10%)+SA1(30%) = 50%  <br/><br/>
				Second Term - FA3(10%)+FA4(10%)+SA2(30%) = 50% <br/><br />
				FORMATIVE ASSESSMENT(FA) 1 + 2 + 3 + 4 = 40%   <br/><br />
				SUMMATIVE ASSESSMENT(SA) 1 + 2 = 60%           <br/><br />
				CGPA is calculated excluding 3rd language.
			</div>
			<div style="width:34%;float:left;margin-top:8px;">
			<table border="1" cellpadding="1" cellspacing="0" style="text-align:center;color:#1224A5;font-size: 13px;font-weight: 800;">
				<tr>
					<td colspan="3">GRADING SYSTEM - SCHOLASTIC</td>
				</tr>
				<tr>
					<td>MARK RANGE</td><td>GRADE</td><td>GRADE POINT</td>
				</tr>
				<tr>
					<td>91 - 100</td><td>A1</td><td>10.0</td>
				</tr>
				<tr>
					<td>81 - 90</td><td>A2</td><td>9.0</td>
				</tr>
				<tr>
					<td>71 - 80</td><td>B1</td><td>8.0</td>
				</tr>
				<tr>
					<td>61 - 70</td><td>B2</td><td>7.0</td>
				</tr>
				<tr>
					<td>51 - 60</td><td>C1</td><td>6.0</td>
				</tr>
				<tr>
					<td>41 - 50</td><td>C2</td><td>5.0</td>
				</tr>
				<tr>
					<td>33 - 40</td><td>D</td><td>4.0</td>
				</tr>
				<tr>
					<td>21 - 32</td><td>E1</td><td>3.0</td>
				</tr>
				<tr>
					<td>0 - 20</td><td>E2</td><td>2.0</td>
				</tr>
			</table>
			</div>
		</div>-->
			  </div>
			</div>
		  </div>
		</form>
		<?php
		}
			?>
	   
	  </div>
	  </div>
	<?php   }
  
	}
}
?><style>th{color:#000;} td{padding-left:20px;;}td, th{line-height: 1;} table{margin:2px;}</style>
</div>

<input type="hidden" name="smsTXT" id="smsTXT" value="<?php echo $smsAry; ?>" />
<input type="hidden" name="examtype" id="examtype" value="<?php echo $_REQUEST["term"]; ?>" />
<script type="text/javascript">

function printDiv(divID) {
	//var styles="<style>button{display:none}</style><link href='"+root+"assets/css/print.css' rel='stylesheet'>";
	var divElements = document.getElementById(divID).innerHTML;
	var newbody="<html><head><title></title><style>.nextBtn{display:none;}</style></head><body>" + divElements + "<hr/></body>";
    var thePopup = window.open( '', "Print", "menubar=0,location=0,height=700,width=700" );
    thePopup.document.write(newbody);
    thePopup.print();
}
</script>
<?php
}
?>
