<style>
.top-bar-minimize { display: none; }
thead, tfoot { display: table-header-group; }
.top-bar+.well, .accordion .accordion-heading+.accordion-body { display: inline-block !important; width: 100% !important; overflow: inherit !important; }
</style>
<script type="text/javascript">
function getType(id){
	$.post( "ajax.php", { type: "exmtype" ,class: id } , function( data ) {
	  	$("#extype").html(data);
	});
}
function smsDivNoHeader(){
	var id=$("#smsTXT").val();
	var examtype=$("#examtype").val();
	$.post( "ajax.php", { type: "sendsmsexamcbse" ,AllData: id, examtype: examtype } , function( data ) {
	  	alert(data);
	});
}
function findStudent(t){
	var cls=$("#class").val();
	var section=$("#section").val();
	$.post( "ExamCBSE/ajax.php", { type: "findStudent" ,cls: cls, section: section } , function( data ) {
	  	$("#findStudent").html(data);
	});
}
</script>
<style>
.headPrint { display: none }
table{font-size:10px;}
</style>
<form method="post" action="">
  <div class="row-fluid">
    <div class="span12">
      <div class="top-bar">
        <h3><i class="icon-cog"></i>Search Student Record</h3>
        <div>
          <?php 
						if($_POST){
							?>
          <button type="button" name="fee" onClick="printDivNoHeader('printableDiv')" class="btn btn-primary"> Print</button>
          <button type="button" name="fee" onClick="smsDivNoHeader()" class="btn btn-primary"> SMS</button>
          <?php
						}
						?>
          <button type="submit" name="fee" class="btn btn-primary"> View Record</button>
          <button type="submit" name="grade" class="btn btn-primary"> View Grade</button>
        </div>
      </div>
      <div class="well no-padding">
        <div class="controls controls-row">
        
           			    <div class="control-group span3">
                    
                           
                            <div class="controls span3">
                                <select onchange="findStudent()" name="class" id="class">
                                    <option value="">Class</option>
                                    <?php 
                                        $class=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["class"]==$aryForm["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                                                <?php echo $cla["class"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                       </div>
                       	<div class="control-group span3">
                            
                            <div class="controls span3">
                               <select name="section" onchange="findStudent()" id="section">
                                    <option value="">Section</option>
                                    <?php 
                                        $class=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."'");
                                        foreach($class as $cla){
                                            ?>
                                            <option <?php if($cla["name"]==$aryForm["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                                                <?php echo $cla["name"] ?>
                                            </option>
                                            <?php
                                
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>  
                        <div class="control-group span3">   
                               <select name="term">
                                <option value="">Exam type</option>
                                <option value="term1">Term1</option>
                                <option value="term2">Term2</option>
                                <option value="final">Final</option>
                              </select>
                           </div>
                        <div class="control-group span3">
                            <div class="controls span3" id="findStudent">
                              <select  name="idno" id="idno">
                               <option value="">All Student</option>
                              </select>
                            </div>
         			   </div>   
        </div>
        <br>
      </div>
      <!-- / Forms: Content --> 
      
    </div>
  </div>
</form>
<div id="printableDiv">
  <?php
    if($_POST){
$mss=0; $smsAry="";$where="";$stsearch="";

if(isset($_POST["section"]) && $_POST["section"]!="")
			$where=" AND section='".$_POST["section"]."' ";
if(isset($_POST["idno"]) && $_POST["idno"]!="")
	$stsearch=" and idno='".$_POST["idno"]."' ";
	
 if(isset($_POST['fee'])){
		$allStudent=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_POST["class"]."' $where $stsearch and status=1 and issue_TC=0 order by name");
	//echo $db->getLastQuery();
	$examtype=$db->getRows("select name,id,total from examterm_junior where school_id='".$_SESSION["admin"]["school_id"]."' order by lorder");
	if(is_array($allStudent) && count($allStudent)>0){ $he=0;
		foreach($allStudent as $aryForm){$mss++;$he++;
				
	  if($_POST["term"]=="term1" || $_POST["term"]=="term2"){ ?>
	  <!--one page <div style="height:942px">end --> 
	  <!--two page-->
	  <div style="height:1025px;margin-bottom:20px;">
	  <div style="height:940px;border:8px solid #D5DA13;">
		<?php
		$_GET['id']=$aryForm["idno"];
		error_reporting(55);
		$_REQUEST["class"]=$db->getVal("select class from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno=".$aryForm["idno"]);
		$exam=$db->getVal("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' limit 0,1");
		
		$termWhere="";
		if($_POST["term"]=="term1") $termWhere=" and term='".$_POST["term"]."' and name='1st Semester' ";
		elseif($_POST["term"]=="term2") $termWhere=" and term='".$_POST["term"]."' and name='2nd Semester' ";
		$examtype=$db->getRow("select name,id,total from examterm_junior  where school_id='".$_SESSION["admin"]["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["admin"]["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:70px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="80px" 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 if($_POST['term']=="term1") echo "1st Semester";elseif($_POST['term']=="term2") echo "2nd Semester"; ?> : <?php echo $_SESSION["admin"]["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>
				  
				 
				</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="40%"  rowspan="2">SUBJECTS</td>
							<?php 
							  if($_POST["term"]=="term1"){ ?>
							<td style="border-bottom: 1px solid #000;padding:5px;" width="60%" colspan="3">1st Semester</td>
							<?php }elseif($_POST["term"]=="term2"){ ?>
							<td style="border-bottom: 1px solid #000;padding:5px;" width="60%" colspan="3">2nd Semester</td>
							<?php } ?>
							
						</tr>
                        <tr>
                        	<!--<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;">&nbsp;</td>-->
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="20%">Max Marks</td>
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="20%">Marks</td>
                            <td style="border-bottom: 1px solid #000;padding:5px;" width="20%">Grade</td>
                            <!--<td style="border-bottom: 1px solid #000;padding:5px;">&nbsp;</td>-->
                        </tr>
						
						<?php $x=0;$total_get=$grand_total=0;
						$detail=$db->getRows("select * from sub_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."'");
						foreach($detail as $d){ $fsAry=array();$final="";
							$detail1=$db->getRows("select * from subjects_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and subject='".$d["subject"]."'");
						?><tr style="">
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php echo ucfirst($d["subject"]) ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
								<?php $swhere="";
								
								$examResultData=$db->getVal("select sum(obtain) from exammarks_junior where idno='".$aryForm["idno"]."' and type='".$examtype[0]."' and subject='".$d["subject"]."'");
								//echo $db->getLastQuery();
								?>
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php	echo $total=$d["total"]; $grand_total+=$total;?>
								</td>
								<?php $x++; ?>
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php echo $examResultData; $total_get+=$examResultData;?></td>
								<td style="border-bottom:1px solid #ccc"><?php  echo FindGrade_junior(round($examResultData),$total);?></td>
							</tr>
                        <?php if(is_array($detail1) && count($detail1)>0){
									foreach($detail1 as $d1){
										if($d1["sub_div"]!=""){?>
                        		<tr style="">
								<td style="border-right:2px solid #FA0606;text-align:right;border-bottom:1px solid #ccc;color: #090;"><?php echo ucfirst($d1["sub_div"]) ?><input type="hidden" name="subject[]" value="<?php echo $d1["sub_div"] ?>" /></td>
								<?php $swhere="";
								if($d1["sub_div"]!="") $swhere=" and sub_div='".$d1["sub_div"]."'";
									$examResultData=$db->getVal("select obtain from exammarks_junior where idno='".$aryForm["idno"]."' and type='".$examtype[0]."' and subject='".$d1["subject"]."' $swhere");
								?>
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php	echo $total=$d1["sub_div_total"]; ?>
								<input readonly="readonly" type="hidden" style="width:40px" name="<?php echo $d1["sub_div"]."_".$examtype[0];?>[]" class="<?php echo $examtype[0];?>_total_marks total" value="<?php echo $total=$d1["sub_div_total"]; ?>" placeholder="Total Maks" />
								 <input required type="hidden" style="width:70px" name="<?php echo $examtype[0];?>_student[]" class="onlyZero obtain <?php echo $examtype[0];?>_obtain_marks" value="<?php echo $examResultData; ?>" placeholder="Obtain Maks" />
								 </td>
                             <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $examResultData; ?></td>
								<?php $x++; ?>
								
								<td style="border-bottom:1px solid #ccc;"><?php  echo FindGrade_junior(round($examResultData),$total);?></td>
							</tr>
                            <?php } }}?> 
                           
						<?php
						 $stid=$_GET["id"];$subj1=$d["subject"];
						$smsAry.="$stid~$subj1~".$final."<br/>";
						} 
						?>
                        <?php
						$detail_ext=$db->getRows("select * from sub_junior_extra where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."'");
						if(is_array($detail_ext) && count($detail_ext)>0){
							foreach($detail_ext as $dext){?>
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $dext["subject"] ?></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;""></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;""></td>
                                <?php $grade=$db->getVal("select grade from extra_subgrade_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and idno='".$aryForm["idno"]."' and type='".$examtype[0]."' and subject='".$dext["subject"]."' and session='".$_SESSION["admin"]["session"]."'"); ?>
                                <td style="border-bottom:1px solid #ccc;"><?php echo $grade; ?></td>
                            </tr>
                            <?php }} ?>
                        	<tr>
                            	<td style="border-right:2px solid #FA0606;border-top:1px solid red;border-bottom:1px solid #ccc;">Total</td>
                                <td  style="border-top:2px solid red;border-bottom:1px solid #ccc;" colspan="3"><?php echo $grand_total."/".$total_get; ?></td>
                            </tr>
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;">Percentage</td><?php $per=($total_get*100)/$grand_total;$per=sprintf ("%.2f", $per);?>
                                <td colspan="3" style="border-bottom:1px solid #ccc;"><?php echo $per."%"; ?></td>
                            </tr>
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;">Grade</td><?php $per=($total_get*100)/$grand_total;$per=sprintf ("%.2f", $per);?>
                                <td colspan="3" style="border-bottom:1px solid #ccc;"><?php echo FindGrade_junior((int)$per,100);?></td>
                            </tr>
						</table>
				<div style="width:100%;height:80px;border-bottom: 2px solid #F71111;text-align:center;font-weight:800;color: #1224A5;">        
				 <div style="text-align:center;width:100%;">
					 <div style="width:100%;background:#D5DA13;padding:5px;border-bottom:1px solid #000;color:#000;">REMARKS </div>
					 <span></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["admin"]["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($_POST["term"]=="term1")echo $attr['term1_att'];elseif($_POST["term"]=="term2") $attr['term2_att'];?></span><br/>
						<span style="padding:5px">Total working days : <?php if($_POST["term"]=="term1")echo $LinksDetails['term1_all_day'];elseif($_POST["term"]=="term2") $LinksDetails['term2_all_day']?></span>
                    <?php } ?>    
					</div>
                   
					</div>-->
				</div>
				
				<?php
				$smsAry.="$stid~-------~<br/>";
				$smsAry.="$stid~CGPA~".$cgpa."<br/>";
				echo $db->getErMsg();
					
						?>
						 <div>
							   <table style="width:100%; text-align:center;font-size:14px;border-bottom: 2px solid #F71111;height: 100px;font-weight: 800;color: #1224A5;" cellpadding="0" cellspacing="2" >
								<tr><td>&nbsp;</td><td>&nbsp;</td>
                                <!--<td><img src="</tr>/?php echo URL_ROOT ?>assets/css/principal_sign.jpg" height="50px" width="100px" style="margin-top:13px;" /></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>
			</div>
		  </div>
		</form>
		<?php
		}
			?>
	   
	  </div>
	  </div>
	<?php }
	   elseif($_POST["term"]=="final"){ ?>
	  <!--one page <div style="height:942px">end --> 
	  <!--two page-->
	  <div style="height:1032px;margin-bottom:20px;">
	  <div style="height:1000px;border:8px solid #D5DA13;">
		<?php
		$_GET['id']=$aryForm["idno"];
		error_reporting(55);
		$_REQUEST["class"]=$db->getVal("select class from student where school_id='".$_SESSION["admin"]["school_id"]."' and idno=".$aryForm["idno"]);
		$exam=$db->getVal("select idno from student where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' limit 0,1");
		
		//$termWhere="and name='1st Semester' or name='2nd Semester'";
		$examtype=$db->getRows("select name,id,total from examterm_junior where school_id='".$_SESSION["admin"]["school_id"]."' order by lorder");
		//echo $db->getLastQuery();print_r($examtype);
		if(count($exam)>0){
		?>
		<?php $aryForm=$db->getRow("SELECT * FROM student WHERE school_id='".$_SESSION["admin"]["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:50px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="80px" width="80px" style="margin:6px 0px 0px 10px;"></div>
			 <div style="float:left;text-align:center;margin-bottom:18px;"> <h1 style="font-size:28px;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 $_SESSION["admin"]["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%"></tr>/?php echo $aryForm["section"] ?></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="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>
				  
				 
				</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="25%"  rowspan="2">SUBJECTS</td>
							
							<td style="border-bottom: 1px solid #000;padding:5px;border-right:2px solid #FA0606;" width="25%" colspan="3">SUMMATIVE ASSESSMENT-1</td>
						
							<td style="border-bottom: 1px solid #000;padding:5px;border-right:2px solid #FA0606;" width="25%" colspan="3">SUMMATIVE ASSESSMENT-2</td>
							
							<td style="border-bottom: 1px solid #000;padding:5px;" width="25%" colspan="3">TOTAL</td>
						</tr>
                        <tr>
                        	<!--<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;">&nbsp;</td>-->
                            <!--<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="9%">Max Marks</td>
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="8%">Marks</td>-->
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="8%" colspan="3">Grade</td>
                           <!-- <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="9%">Max Marks</td>
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="8%">Marks</td>-->
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="8%" colspan="3">Grade</td>
                            <!--<td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="9%">Total</td>
                            <td style="border-right:2px solid #FA0606;border-bottom: 1px solid #000;padding:5px;" width="8%">Average</td>-->
                            <td style="border-bottom: 1px solid #000;padding:5px;" width="8%" colspan="3">Grade</td>
                            <!--<td style="border-bottom: 1px solid #000;padding:5px;">&nbsp;</td>-->
                        </tr>
						
				<?php if(is_array($examtype) && count($examtype)>0){
                    $total_get_1st=$grand_total_1st=$total_get_2nd=$grand_total_2nd=0;$total_get_final=$grand_total_final=0;
                         $x=0;
									 
						$detail=$db->getRows("select * from sub_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."'");
						foreach($detail as $d){ $fsAry=array();$final="";
							$detail1=$db->getRows("select * from subjects_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and subject='".$d["subject"]."'");
						?>
                       <tr style="">
                        		
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc" ><?php echo ucfirst($d["subject"]) ?><input type="hidden" name="subject[]" value="<?php echo $d["subject"] ?>" /></td>
								<?php  $swhere="";$final_tot=0;$final_tot_max=0;$avg=0;$i=0;
							foreach($examtype as $etype){$i++;
								$examResultData=$db->getVal("select sum(obtain) from exammarks_junior where idno='".$aryForm["idno"]."' and type='".$etype[0]."' and subject='".$d["subject"]."'"); //echo $db->getLastQuery();print_r($etype);exit;
								?>
					<!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php //echo $total=$d["total"]; 
					$total=$d["total"];
					if($i==1)$grand_total_1st+=$total;
						elseif($i==2)$grand_total_2nd+=$total; $final_tot_max+=$total; ?>
								</td>-->
								<!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc" ><?php //echo $examResultData; 
								if($i==1)$total_get_1st+=$examResultData; elseif($i==2)$total_get_2nd+=$examResultData;   $final_tot+=$examResultData;?></td>-->
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc" colspan="3"><?php 
if($d["subject"]=='DRAWING')
								echo FindGrade_junior(round($examResultData),$total);?></td>
                     <?php } ?>
                                <!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php //echo $final_tot; ?></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php //echo $avg=($final_tot/2); 
								$avg=($final_tot/2);
								$total_get_final+=$avg;?></td>-->
                                <td style="border-bottom:1px solid #ccc" colspan="3"><?php 
								if($d["subject"]=='DRAWING')
								echo FindGrade_junior(round($final_tot),$final_tot_max);?></td>
							</tr>
                        <?php if(is_array($detail1) && count($detail1)>0){
									foreach($detail1 as $d1){
										if($d1["sub_div"]!=""){?>
                        		<tr style="">
								<td style="border-right:2px solid #FA0606;text-align:right;border-bottom:1px solid #ccc;color: #090;"><?php echo ucfirst($d1["sub_div"]) ?><input type="hidden" name="subject[]" value="<?php echo $d1["sub_div"] ?>" /></td>
								<?php  $swhere="";
								if($d1["sub_div"]!="") $swhere=" and sub_div='".$d1["sub_div"]."'";
								$final_tot_sub=0;$final_tot_max_sub=0;$avg1=0;
							foreach($examtype as $etype){
									$examResultData=$db->getVal("select obtain from exammarks_junior where idno='".$aryForm["idno"]."' and type='".$etype[0]."' and subject='".$d1["subject"]."' $swhere");
								?>
								<!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php	//echo $total=$d1["sub_div_total"];
								$total=$d1["sub_div_total"];
								$final_tot_max_sub+=$total;?>
								 </td>-->
                           <!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $examResultData; 
						   $final_tot_sub+=$examResultData; ?></td>-->								
								<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;" colspan="3"><?php echo FindGrade_junior(round($examResultData),$total);?></td>
                               <?php $i++; }?> 
                                <!--<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php echo $final_tot_sub; ?></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc"><?php echo $avg1=$final_tot/2; ?></td>-->
                                <td style="border-bottom:1px solid #ccc" colspan="3"><?php echo FindGrade_junior(round($final_tot_sub),$final_tot_max_sub);?></td>
							</tr>
                            <?php } }}?> 
                           
						<?php
						 $stid=$_GET["id"];$subj1=$d["subject"];
						$smsAry.="$stid~$subj1~".$final."<br/>";
						 } }
						?>
                        <?php
						$detail_ext=$db->getRows("select * from sub_junior_extra where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."'");
						if(is_array($detail_ext) && count($detail_ext)>0){
							foreach($detail_ext as $dext){?>
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $dext["subject"] ?></td>
                                <?php foreach($examtype as $etype){  ?>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"></td>
                                <?php $grade=$db->getVal("select grade from extra_subgrade_junior where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and idno='".$aryForm["idno"]."' and type='".$etype[0]."' and subject='".$dext["subject"]."' and session='".$_SESSION["admin"]["session"]."'"); ?>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $grade; ?></td>
                                <?php } ?>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"></td>
                                <td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"></td>
                                <td style="border-bottom:1px solid #ccc;"></td>
                                
                            </tr>
                            <?php }} ?>
                           <!--	<tr>
                            	<td style="border-right:2px solid #FA0606;border-top:1px solid red;border-bottom:1px solid #ccc;">Total</td>
                                <td style="border-right:2px solid #FA0606;border-top:2px solid red;border-bottom:1px solid #ccc;" colspan="3"><?php echo $grand_total_1st."/".$total_get_1st; ?></td>
                                <td style="border-right:2px solid #FA0606;border-top:2px solid red;border-bottom:1px solid #ccc;" colspan="3"><?php echo $grand_total_2nd."/".$total_get_2nd; ?></td>
                                <td style="border-top:2px solid red;border-bottom:1px solid #ccc;" colspan="3"><?php echo $grand_total_2nd."/".$total_get_final; ?></td>
                            </tr>
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;">Percentage</td>
								<?php $per=($total_get_1st*100)/$grand_total_1st;
									  $per=sprintf ("%.2f", $per);?>
                                <td colspan="3" style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $per."%"; ?></td>
                                <?php $per=($total_get_2nd*100)/$grand_total_2nd;
									  $per=sprintf ("%.2f", $per);?>
                                <td colspan="3" style="border-right:2px solid #FA0606;border-bottom:1px solid #ccc;"><?php echo $per."%"; ?></td>
                                <?php $per=($total_get_final*100)/$grand_total_2nd;
									  $per=sprintf ("%.2f", $per);?>
                                <td colspan="3" style="border-bottom:1px solid #ccc;"><?php echo $per."%"; ?></td>
                            </tr>-->
                            <tr>
                            	<td style="border-right:2px solid #FA0606;border-top:px solid red;border-bottom:1px solid #ccc;">Overall Grade</td>
								    <td colspan="3" style="border-right:2px solid #FA0606;border-top:2px solid red;border-bottom:1px solid #ccc;"><?php echo FindGrade_junior((int)$total_get_1st,$grand_total_1st);?></td>
                                    <td colspan="3"style="border-right:2px solid #FA0606;border-top:2px solid red;border-bottom:1px solid #ccc;""><?php echo FindGrade_junior((int)$total_get_2nd,$grand_total_2nd);?></td>
                                    <td colspan="3" style="border-top:2px solid red;border-bottom:1px solid #ccc;"><?php echo FindGrade_junior((int)$total_get_final,$grand_total_2nd);?></td>
                            </tr>
						</table>
				<div style="width:100%;height:110px;text-align:center;border-bottom: 2px solid #F71111;font-weight:800;color: #1224A5;margin-bottom:25px;">        
				 
					 <div style="width:100%;background:#D5DA13;padding:5px;border-bottom:1px solid #000;color:#000;">REMARKS</div>
					 <span></span>
				
				 	<?php $attr=$db->getRow("select * from allattandence where idno='".$aryForm["idno"]."' and session='".$_SESSION["admin"]["session"]."'"); 	 ?>				
					<!--<div style="margin-top:2px;">
                   <?php ///if($attr!=NULL){?>
						 <div style="background:#D5DA13;color:#000;w						 <div style="background:#D5DA13;color:#000;width:100%;float:left;padding:4px;border-top:1px solid #000;border-bottom:1px solid #000;">ATTENDANCE</div>
of the student : <?php if($_POST["term"]=="term1")echo $attr['term1_att'];elseif($_POST["term"]=="term2") $attr['term2_att'];?></span><br/>
						<span style="padding:5px">Total working days : <?php if($_POST["term"]=="term1")echo $LinksDetails['term1_all_day'];elseif($_POST["term"]=="term2") $LinksDetails['term2_all_day']?></span>
                    <?php ///} ?>    
                    
					</div>-->
                    		                 	
				</div>
                <?php if($attr!=NULL){?>
				<table border="1" style="width:40%;font-size:12px;height:80px;font-weight: 800;color: #1224A5;margin:0 auto" cellpadding="0" cellspacing="0" >
								<tr><td colspan="2" style="text-align:center;background-color: #D5DA13;color:#000">ATTENDANCE</td>
								</tr>
								<tr>
								  <td>Total Attendance of the student :</td>
								  <td><?php echo $attr['term1_att']+$attr['term2_att'];?></td>
								 </tr>
                                 <tr>
								  <td>Total working days :</td>
								  <td><?php echo $LinksDetails['term1_all_day']+$LinksDetails['term2_all_day'];?></td>
								 </tr>
							  </table>
				<?php }
				$smsAry.="$stid~-------~<br/>";
				$smsAry.="$stid~CGPA~".$cgpa."<br/>";
				echo $db->getErMsg();
					
						?>
						 <div>
							   <table style="width:100%; text-align:center;font-size:14px;height: 210px;font-weight: 800;color: #1224A5;" cellpadding="0" cellspacing="2" >
								<tr><td>&nbsp;</td><td>&nbsp;</td>
                               <!-- <td><img src="</tr>/?php echo URL_ROOT ?>assets/css/principal_sign.jpg" height="50px" width="100px" style="margin-top:13px;" /></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(isset($_POST['grade'])){
	$allStudent=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_POST["class"]."' $where $stsearch and status=1 and issue_TC=0 order by name");
//echo $db->getLastQuery();
///$examtype=$db->getRows("select name,id,total from examterm where school_id='".$_SESSION["admin"]["school_id"]."' order by lorder");
if(is_array($allStudent) && count($allStudent)>0){ $he=0;
	foreach($allStudent as $aryForm){$mss++;$he++;	
		$_GET['id']=$aryForm['idno'];
		$type=$db->getRows("select * from junior_criteria where school_id='".$_SESSION["admin"]["school_id"]."' group by type order by id");
				if(is_array($type) && count($type)>0){
					?>
                    <div style="height:1025px;margin-bottom:20px;<?php if($he!=1){?> padding-top:10px;<?php } ?>">
	 				 <div style="height:998px;border:8px solid #D5DA13;">
           
                   <div style="height:20px;width:100%;background:#FDFD0A;color: #0743D2;font-weight: 800;BORDER-TOP:2PX SOLID RED;BORDER-BOTTOM:2PX SOLID RED;font-size:12px;">
                      <ul style="padding-right:5px;width:100%;margin-top:2px;">
                      <li style="float:left;width:30%"> Name : <?php echo $aryForm["name"];?></li>
                      <li style="float:left;width:20%">Class : <?php echo $_POST['class'];if(isset($_POST["section"]) && $_POST["section"]!="") echo "-".$_POST['section']; ?></li>                   <li style="float:left;width:30%">Father's Name : <?php echo $aryForm["fname"];?></li>
                 
                      </ul>
                    </div>
                      <div style="height:18px;width:100%;text-align:center;background:#FDFD0A;color: #0743D2;font-weight: 800;font-size:12px;BORDER-BOTTOM:2PX SOLID RED;"> ALL ROUND PERFORMANCE </div>
                        <div style="width:99.5%;display:inline-block;vertical-align:top;margin:0 5px 0 0">
              <?php $ijk=0;
						foreach($type as $t){$ijk++;
							?>                            
                            <table border="1" style="width:100%;margin-top:10px;font-size:11px;font-weight:800;text-align:center;display:inline-table" cellpadding="7" cellspacing="0">
                   <thead style="font-size:14px;">
                    	<?php
                                     $lifeskill=$db->getRows("select * from junior_criteria where school_id='".$_SESSION["admin"]["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 style="background:#D5DA13;">
                        <th><?php echo $t["type"]; ?></th>
                        <th>1st Semester</th>
                        <th>2nd Semester</th>
                      </tr>
                      </thead>
                    <tbody id="tbodyskill">
                      <?php
										  $i=0;
                                        foreach($lifeskill as $iSkill)
                                        {
											$grade_1st=$db->getVal("select grade from junior_examcriteriarecord where idno='".$_GET['id']."' and term='1st Semester' and criteria='".$t["type"]."' and subcriteria='".$iSkill["name"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
											$grade_2nd=$db->getVal("select grade from junior_examcriteriarecord where idno='".$_GET['id']."' and term='2nd Semester' and criteria='".$t["type"]."' and subcriteria='".$iSkill["name"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
											//echo $db->getLastQuery();
                                     ?>
                      <tr>
                        <td style="color:blue;" width="25%"><?php echo $iSkill["name"]; ?></td>
                        <td style="color:blue;" width="5%"><?php echo ucwords($grade_1st); ?></td>
                        <td style="color:blue;" width="5%"><?php echo ucwords($grade_2nd); ?></td>
                      </tr>
                      <?php $i++;
                                        } 
                                    }
                                     ?>
                    </tbody>
                  </table>
                  
              <?php
						}
						?>
           			</div>
                    <!--<div style="margin-left: 5px;">
					    <div style="width:50%;margin-top:6px;">
                           <table border="1" cellpadding="2" cellspacing="0" style="text-align:center;color:#1224A5;font-size:10px;width:59%;font-weight:800;float:left;">
                                   <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>
                   
                    <table border="1" cellpadding="6" cellspacing="0" style="text-align:center;width:39%;color:#1224A5;font-size:10px;font-weight:800;line-height:29px;float:left">
                                    <tr>
                                        <td colspan="3">CO - SCHOLASTIC</td>
                                    </tr>
                                    <tr>
                                        <td>GRADE</td><td>GRADE POINTS</td>
                                    </tr>
                                    <tr>
                                        <td>A</td><td>4.1 - 5.0</td>
                                    </tr>
                                    <tr>
                                        <td>B</td><td>3.1 - 4.0</td>
                                    </tr>
                                    <tr>
                                        <td>C</td><td>2.1 - 3.0</td>
                                    </tr>
                                    <tr>
                                        <td>D</td><td>1.1 - 2.0</td>
                                    </tr>
                                    <tr>
                                        <td>E</td><td>0 - 1.0</td>
                                    </tr>
                    </table>
                    </div>
                        <div style="width:48%;float:right;margin:6px;color:#1224A5;font-size:10px;font-weight: 800;">
                            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%
                        </div>
					</div>-->
                    <div style="height:40px;width:100%;font-weight: 800;font-size:12px;margin-top:10px;">
                    		<div style="height:15px;width:100%;text-align:center;background:#FDFD0A;color: #0743D2;font-size:11x;">          	Remarks   </div>
                            <div style="border:2px solid #ccc;margin:0 auto;height:20px;color:#0743D2;width:200px;margin-top:10px;text-align:center"> Keep up the good work.</div>
                    </div>
                    <table style="width:100%;margin-top:10px;font-size:10px;color:#0743D2;font-weight:800;text-align:center;display:inline-table" cellpadding="5" cellspacing="5">
                    	<!--<tr><td>&nbsp;</td><td><img src="</table>?php echo URL_ROOT ?>assets/css/principal_sign.jpg" height="50px" width="100px" style="margin-top:13px;" /></td><td>&nbsp;</td>-->
                    	</tr>
                        <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>
                    	</tr>
                        <tr><td>Class Teacher's Signature</td><td>Principal's Signature</td><td>Parent's Signature</td></tr>
                    </table>
		</div> 
        </div>
            <?php
						echo $db->getErMsg();
				}
	  }
	}
}
?> 
<style>th{color:#000;}td, th{line-height: 1;} table{margin:2px;}</style>

<input type="hidden" name="smsTXT" id="smsTXT" value="<?php echo $smsAry; ?>" />
<input type="hidden" name="examtype" id="examtype" value="<?php echo $_POST["term"]; ?>" />
<?php
}
?>
</div>
<div id="canvas"></div>
<script src="http://html2canvas.hertzen.com/build/html2canvas.js"></script>
<script>

</script>
