<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;} 
.dynamic{display:none}
table td {
padding: 6px !important;
}
legend{line-height: 16px;font-weight:100;}

.outer .MigrateLeftFee{
  background-color: #DADADA !important;
  border: 5px solid #181616 !important;
  min-height: 440px;
  min-width:700px;
}
.st {
	width: 55px;
	font-size:10px;
	display: inline-block;
	color: #021EF0;
}
.size{
	font-size:12px;
}
.recepit {
	width: 717px !important;
	height: 344px !important;
}
.total{
	color: darkgreen;
    font-weight: 800;
}
</style>
<script type="text/javascript" src="https://unpkg.com/xlsx@0.15.1/dist/xlsx.full.min.js"></script>
<input type="hidden" name="tog" id="togglevalueforzeoshow" value="0" />
<script>


function checkAll(){
	if($('#checkboxa').prop('checked')) {
		$('.checkboxes').prop('checked', true);
		 
    } else {
		
        $('.checkboxes').prop('checked', false);
    }
	
	//var chk=$('input[name=cat]:checked').length;
	
	//alert(chk);
	
}
function  sendAll(){
	checked = $('input[name=sid]:checked');
        if( checked.length > 0 ) {
            var checkValues = checked.map(function(){
               return $(this).val();
            }).get();
			//alert(checkValues);
			//confirm();
			var chk=checkValues.toString();
			$.post( "?page_id=sms&type=student", { type: "POST" ,chk: chk} , function( data ) {
	  
				window.location.href = './?page_id=sms&type=student&chk='+chk+'';
		});
          /*$.ajax({
                type: "POST",
				 url: "http://127.0.0.1/sms/?page_id=sms&type=student",
                data: { ids: checkValues },
                success:function(data){
						window.location.href = '?page_id=sms&type=student';
					 },
            });*/
        }else{
             alert("You need to pick at least one checkbox!");
        }
	//var date=$("#date").val();
	//$.post( "ajax.php", { type: "DATE_SEARCH" ,date: date } , function( data ) {
	//  	$("#date_content").html(data);
	//	getTotal();
	//});
}

function SMSComplete(valueid,act){
	$(this).hide();
	var Fee=$("#"+valueid).html();
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: act ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
	  	//$("#ins").html(data);getTotal();
		alert(data);
		$(this).show();
	});
}
function SMS(type){
	if(confirm('Do you want to send sms now..!')){
	//var ids=document.getElementsByName('mobile[]');
	
	var ids=document.getElementsByName('idno[]');
	var detail=document.getElementsByName('details[]');
	var arr = [];
	for(var i=0;i<ids.length;i++){
		arr.push(ids[i].value+"-"+detail[i].value);
	}
	var Fee=arr.join(",");
	var fdate='<?php if($_GET["fdate"]!="")echo $_GET["fdate"];else echo "0" ?>';
	var fmonth='<?php if($_GET["fmonth"]!="")echo $_GET["fmonth"];else echo "0" ?>';
	var fyear='<?php if($_GET["fyear"]!="")echo $_GET["fyear"];else echo "0" ?>';
	var tdate='<?php if($_GET["tdate"]!="")echo $_GET["tdate"];else echo "0" ?>';
	var tmonth='<?php if($_GET["tmonth"]!="")echo $_GET["tmonth"];else echo "0" ?>';
	var tyear='<?php if($_GET["tyear"]!="")echo $_GET["tyear"];else echo "0" ?>';
	var cls='<?php if($_GET["class"]!="")echo $_GET["class"];else echo "0" ?>';
	$.post( "ajax.php", { type: type ,fee: Fee, fdate:fdate, fmonth:fmonth, fyear:fyear, tdate:tdate, tmonth:tmonth, tyear:tyear,class: cls  } , function( data ) {
		alert(data);
	});
}}
function sendSMDTO(){
	//alert("sms sending process under constration...");
}

function filterPayleft(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
	}
	else
	if(!isNaN(val)){
		var allTot="";
		$(".MyTotalLeft").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}else{
		alert("Please enter only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}

function filterPay(Tval){
	var val=$(Tval).val();
	if(val.trim()==""){
		$(".MyTotalFee").parent().show('slow');
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide('slow');
	}
	else
	if(!isNaN(val)){
		$(".dynamic").show('slow');
		var allTot="";
		$(".MyTotalpaid").each(function(index, element) {
			var myVal=parseInt($(this).html());
			if(myVal>val)
			{
				$(this).parent().hide('slow');
				$(this).parent().removeClass('none');
			}
			else
			{
				$(this).parent().show('slow');
				$(this).parent().addClass('none');
			}
        });
		//alert(allTot);
	}
	else{
		alert("Please user only number");
		$(Tval).val('');
		$(".MyTotalFee").parent().show();
		$(".MyTotalFee").parent().addClass('none');
		$(".dynamic").hide();
	}
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0,MyTotalLeftDynamic=0;
	$(".none").each(function(index, element) {
		var totalleft=val-parseInt($(this).children('.MyTotalpaid').html());
		$(this).children('.MyTotalLeftDynamic').html(totalleft);
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeftDynamic+=parseInt($(this).children('.MyTotalLeftDynamic').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeftDynamic").html(MyTotalLeftDynamic);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
$(document).ready(function(e) {
	$("#btnduesend").click(function () {
		var ch=$("#togglevalueforzeoshow").val();
		if(ch==0){
			$("#togglevalueforzeoshow").val('1');
	   		filterLeftZero(0)
		}else{
			$("#togglevalueforzeoshow").val('0');
			filterLeftZero(1)
		}
	 });
});
function filterLeftZero(ids){
	var allTot="";
	$(".MyTotalLeft").each(function(index, element) {
		var myVal=parseInt($(this).html());
		if(myVal==0 && ids==0)
		{
			$(this).parent().hide('slow');
			$(this).parent().removeClass('none');
		}
		else
		{
			$(this).parent().show('slow');
			$(this).parent().addClass('none');
		}
	});
	//alert(allTot);
	
	var MyTotalFee=0,MyTotalpaid=0,MyTotalLeft=0,MyDiscount=0;
	$(".none").each(function(index, element) {
		MyTotalFee+=parseInt($(this).children('.MyTotalFee').html());
		MyTotalpaid+=parseInt($(this).children('.MyTotalpaid').html());
		MyTotalLeft+=parseInt($(this).children('.MyTotalLeft').html());
		MyDiscount+=parseInt($(this).children('.MyDiscount').html());
	});
	$("#MyTotalFee").html(MyTotalFee);
	$("#MyTotalpaid").html(MyTotalpaid);
	$("#MyTotalLeft").html(MyTotalLeft);
	$("#MyDiscount").html(MyDiscount);
}
</script>
<?php
//echo "<pre>";print_r($_SERVER);exit;
if($_POST){
	//echo "<pre>";
	if(is_array($_POST["student"]) && count($_POST["student"])>0){
		$i=0;
		foreach($_POST["student"] as $stu){
			$detail=json_decode(base64_decode($_POST["detail"][$i]),true);
			$db->delete("exammarks","where school_id='".$_SESSION["admin"]["school_id"]."' and idno=".$detail["idno"]." and type='".$detail["term"]."' and subject='".$detail["subject"]."' and session='".$_SESSION["admin"]["session"]."'");
			$newExam=array("obtain"     =>  $stu, 
							"idno"      =>  $detail["idno"],
							"subject"   =>  $detail["subject"],
							"type"      =>  $detail["term"],
							"total"     =>  $detail["total"],
							"school_id" =>  $_SESSION["admin"]["school_id"],
							"added_by"  =>  $_SESSION["admin"]["uid"],
							"session"   =>  $_SESSION["admin"]["session"]
			); 
			$db->insertAry("exammarks",$newExam); 
			$i++;
		} 
	}
	//print_r($_POST);echo "</pre><hr/>";
	redirect();
}
?>

<?php
$pgMod="term_wise_report";
$pgAct="view";
if(isset($_GET['action']) && trim($_GET['action'])!='')
		$pgAct=strtolower($_GET['action']);

if(isset($_SESSION['msg']) && $_SESSION['msg']!="")
{
	?>
	<div class="alert alert-success">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-thumbs-up-alt"></i> <b>Notice</b><?php echo $_SESSION['msg'] ?></i>
	</div>
	<?php
	unset($_SESSION["msg"]);
}
if(is_array($alert_err) && count($alert_err)>0)
{
	?>
	<div class="alert alert-error">
	  <a class="close" data-dismiss="alert">×</a>
	  <i class="icon icon-warning-sign"></i> <b>Notice</b> <?php echo $alert_err[0] ?></i>
	</div>
	<?php
}
	?>
    <form method="get" action="">
    <input type="hidden" name="src" value="ExamCBSE" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
					<h3><i class="icon-cog"></i>Search Student Record</h3>
                    <div>
                        <button type="submit" name="percentage" class="btn btn-primary">Percentage List</button>
      <!--                  <button type="submit" name="marks" class="btn btn-primary">Cross List</button>-->
						<!--<button type="submit" name="fee" class="btn btn-primary"> Add Marks</button>-->
      <!--                  <button type="submit" name="create_file" class="btn btn-primary"> Create Excel file</button>-->
                        
					</div>
				</div>
				<div class="well no-padding">
                	<div class="controls controls-row">
                        
                        <div class="control-group span4">
                            <label class="control-label" for="class">Class</label>
                            <div class="controls">  
                                <select 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"]==$_GET["class"])echo 'selected';?> value="<?php echo $cla["class"] ?>">
                                                <?php echo $cla["class"] ?>
                                            </option>
                                            <?php
                                        }
                                    ?>
                                </select>
                            </div>
                        </div>
                        <div class="control-group span4">
                            <label class="control-label" for="class">Section</label>
                            <div class="controls">
                               <select name="section" 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"]==$_GET["section"])echo 'selected';?> value="<?php echo $cla["name"] ?>">
                            <?php echo $cla["name"] ?>
                        </option>
                        <?php
            
                    }
                ?>
            </select>
                            </div>
                        </div>
                        <div class="control-group span4 hide">
                            <label class="control-label" for="medium">Medium</label>
                            <div class="controls">
                                <select name="medium" id="medium">
                                    <option <?php if("hindi"==$aryForm["sibling"])echo 'selected';?> value="hindi">Hindi</option>
                                    <option <?php if("english"==$aryForm["sibling"])echo 'selected';?> value="english">English</option>
                                </select>
                            </div>
                        </div>
                        <div class="control-group span4">
                            <label class="control-label" for="term">Term</label>
                            <div class="controls">
                                <select name="term" id="term">
                                    <option value=""> -- Select Term -- </option>
                                     <option value="Term1">Term1</option>
                                    <option value="Term2">Term2</option>
                                    <option value="Final">Final</option>
                                </select>
                                <?php
									//echo $db->getLastQuery();
								?>
                            </div>
                        </div>
                    </div>
                    <br>
				</div>
				<!-- / Forms: Content -->
			</div>
    </div>
    </form>
	<?php
	$where=array();
	$qry="";

	if(isset($_GET["percentage"])){
		?>
		<?php
		$whereC=array();
		if(isset($_GET["class"]) && $_GET["class"]!="")
			$whereC[]=" class='".$_GET["class"]."' ";
		
		/*if(isset($_GET["medium"]) && $_GET["medium"]!="")
			$whereC[]=" medium='".$_GET["medium"]."' ";
		*/	
		$whereM="";$whereM1="";
		if(is_array($whereC) && count($whereC)>0)
			$whereM1=" where ".implode(" and ",$whereC);
		
		if(isset($_GET["section"]) && $_GET["section"]!="")
			$whereC[]=" section='".$_GET["section"]."' ";
		if(is_array($whereC) && count($whereC)>0)
			$whereM=" where ".implode(" and ",$whereC);
		
		$allstudent=$db->getRows("select * from student $whereM and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and issue_TC=0 and status=1 order by name ");

        $checksection = $db->getVal("select count(section) from subject where class='$_GET[class]' and section!='' and session='".$_SESSION["admin"]["session"]."' ");
        $wheresection = '';
        if($checksection > 0){
            $wheresection = " and section='$_GET[section]' ";
        }

// 		$allsubject=$db->getRows("select * from subject $whereM1 and school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' order by id");

        $allsubject=$db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_GET["class"]."' $wheresection  and session='".$_SESSION["admin"]["session"]."' order by id");

		$subcount=count($allsubject);
		
		$chkclassoptional = $db->getVal("select id from optional_class where class='$_GET[class]' and section='$_GET[section]' ");
		
		if(is_array($allstudent) && count($allstudent)>0){
			?>
   <!--         <div id="printableDiv">-->

			<!--<div class="headPrint hide" style="border: none;">-->
			 
			  
			<!-- <div style="margin-left:55px"> <img src="<?php echo $LinksDetails["logo"] ?>" height="90px" width="110px" style="margin:0px 0px 3px 10px;"></div>-->
			<!-- <div style="float:left;text-align:center;margin-bottom:18px;"> <h1 style="font-size:30px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>-->
			<!--   <span style="font-size:16px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></span>-->
			<!-- </div> -->
		 <!-- </div>-->
		  	<!--<div style="font-size: 18px;clear: both;font-weight: bold;padding: 5px;color: #000;text-align: center;border-right: 1px solid #000;  border-left: 1px solid #000;border-top: 1px solid #000;border-bottom: 1px solid #000;"> CROSS LIST OF CLASS:&nbsp;&nbsp;<?php echo $_GET['class']; ?>-<?php echo $_GET['section']; ?>&nbsp;&nbsp;Exam:&nbsp;&nbsp;<?php echo $_GET['term']; ?></div>-->

		 <div class="row-fluid">
        <div class="span12">
            <div class="top-bar">
                <h3><i class="icon-cog"></i> Detail</h3>
                <div style="float:right; margin-top:5px">
				<!--<input  class="btn btn-primary" type="button"  onclick="$('.table').tableExport({type:'excel',escape:'false'});" id="btnExport" value=" Export To Excel " />-->

                    <!--Commented due to non working on 20-10-22-->
                    <!--<button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Fee Summary')" >Excel</button>-->

                    <!--<button class="btn btn-primary" onclick="ExportToExcel('xlsx')" >Excel</button>-->
                    <button class="btn btn-danger" onclick="ExportToExcel('xlsx')">Export Excel</button>

                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding" id="printDiv2">
            	<!--<table class="table" border="1"  id="tbl_exporttable_to_xls">-->
        	    <table class="table" cellspacing="0" cellpadding="0" border="1" id="tbl_exporttable_to_xls">
            	    
    				<thead>
				<tr>
                <td>SNo.</td>
                <td>Adm No.</td>
                <td>Student</td>
                <td>Father Name</td>
    			<td>Roll No.</td>
                    <?php $maxtotal = 0;
                    if($_GET["term"] == "Term1" || $_GET["term"]=="Term2"){
        			    if(is_array($allsubject) && count($allsubject)>0){
        				foreach($allsubject as $sub){
        				
					        $terms = $db->getRows("select * from term_permission where term='$_GET[term]' and class='$_GET[class]' ");
						      //  print_r($terms);
						      $examtotal = 0;
						        foreach($terms as $term){
						            $marks = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]' ");
                                    $examtotal+=$marks;
                                    $maxtotal+=$marks;
						        }
        				    
        					?><td><?php echo $sub["subject"]; //."<br>(".$examtotal.")"; ?></td><?php 
        				} 
        			}
        			}

                    if($_GET["term"]=="Final"){
        			    if(is_array($allsubject) && count($allsubject)>0){
            				foreach($allsubject as $sub){
            				
    					        $terms1 = $db->getRows("select * from term_permission where term='Term1' and class='$_GET[class]' ");
    						      $examtotal = 0;
    						        foreach($terms1 as $term){
    						            $marks = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]' ");
                                        $examtotal+=$marks;
                                        $maxtotal+=$marks;
    						        }

    					        $terms2 = $db->getRows("select * from term_permission where term='Term2' and class='$_GET[class]' ");
    						      //$examtotal = 0;
    						        foreach($terms2 as $term){
    						            $marks = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]' ");
                                        $examtotal+=$marks;
                                        $maxtotal+=$marks;
    						        }
            				    
            					?><td><?php echo $sub["subject"]."<br>(".$examtotal.")"; ?></td><?php
            				}
            			}
                    }
        			?>
    			<td>Total <?php //echo $maxtotal; ?></td>
	    		<td> Percentage</td>
	    		<td> Rank</td>
            </tr>
            </thead>
            <tbody>
			<?php $i=0;
			foreach($allstudent as $stu){$i++;
				?>
				<tr> 
                	<td><?php echo $i; ?></td>
            		<td><?php echo $stu["admissionno"] ?></td>	
                	<td><?php echo $stu["name"] ?></td>
            		<td><?php echo $stu["fname"] ?></td>
					<td><?php echo $stu["fincome"] ?></td>
                    <?php
                        if($_GET["term"] == "Term1" || $_GET["term"]=="Term2"){
					        if(is_array($allsubject) && count($allsubject)>0){
						    foreach($allsubject as $sub){ $subtotal = 0;
						        
					        $chksubjectoptional = 0;
    						if($chkclassoptional > 0){
    						    $chksubjectoptional = $db->getVal("select id from optional_subject where idno='$stu[idno]' and subject='$sub[subject]' and session='".$_SESSION["admin"]["session"]."' ");
    						}

    						if($chksubjectoptional == 0){

    					        $terms = $db->getRows("select * from term_permission where term='$_GET[term]' and class='$_GET[class]' and session='".$_SESSION["admin"]["session"]."' ");
	    					    $examobtain = 0;
						        foreach($terms as $term){
						            $termpercent = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]'  and session='".$_SESSION["admin"]["session"]."' ");

                                    $examResultData = $db->getRow("select * from exammarks where idno='".$stu["idno"]."' and type='".$term["exam"]."' and subject='".$sub["subject"]."'");
                                    $obtain = number_format($examResultData["obtain"]*$termpercent/$examResultData["total"],1)+0;
                                    $examobtain+=round($obtain);
                                    $allobtainmarks+=round($obtain);
		        			        $alltotalmarks+=$termpercent;
		        			        $subtotal+=$termpercent;
						        }
						        
						    } else {
						        $examobtain = 0;
						    }
						        ?>
					<td>
                        <?php
                            echo $examobtain." / ".$subtotal;
						?>
                    </td>
					<?php
						    }
					    }
                        }
                        
                        if($_GET["term"]=="Final"){
                            if(is_array($allsubject) && count($allsubject)>0){
						        foreach($allsubject as $sub){

					        $terms1 = $db->getRows("select * from term_permission where term='Term1' and class='$_GET[class]' ");
						      $examobtain = 0;
						        foreach($terms1 as $term){
						            $termpercent = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]' ");

                                    $examResultData = $db->getRow("select * from exammarks where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$stu["idno"]."' and type='".$term["exam"]."' and subject='".$sub["subject"]."'");
                                    $obtain = number_format($examResultData["obtain"]*$termpercent/$examResultData["total"],1)+0;
                                    $examobtain+=round($obtain);
                                    $allobtainmarks+=round($obtain);
						        }

					        $terms2 = $db->getRows("select * from term_permission where term='Term2' and class='$_GET[class]' ");
						        foreach($terms2 as $term){
						            $termpercent = $db->getVal("select term_percent from examterm where name='$term[exam]' and class='$_GET[class]' $wheresection and subject='$sub[subject]' ");

                                    $examResultData = $db->getRow("select * from exammarks where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$stu["idno"]."' and type='".$term["exam"]."' and subject='".$sub["subject"]."'");
                                    $obtain = number_format($examResultData["obtain"]*$termpercent/$examResultData["total"],1)+0;
                                    $examobtain+=round($obtain);
                                    $allobtainmarks+=round($obtain);
						        }
            					?>
            					<td>
                                    <?php 
                                        echo $examobtain;
            				// 			echo $examResultData["obtain"];
            							$examResultData["total"];
            				// 			$allobtainmarks+=$examResultData["obtain"];
            							$alltotalmarks =$maxtotal;
            						?>
                                </td>
            					<?php
            						    }
        					    }
                        }
					?>
				     <td><?php echo $allobtainmarks." / ".$alltotalmarks;  ?></td>
					 <td> <?PHP
					 echo $percentage = (number_format($allobtainmarks*100/ $alltotalmarks,2)+0);
 			            // $percentage = number_format(($finalObtain*100/ $finalTotal),2);
        				$percentArray[$stu[idno]]= $percentage;

					 
					 ?>  </td>
                    <td><span id="rank_<?php echo $stu['idno']; ?>"></span></td>
                </tr>
				<?php
			$allobtainmarks=0;$alltotalmarks=0;	
			    arsort($percentArray);
			    /*
		        $rank = 1;    
                foreach($percentArray as $key => $value){
                    ?>
                    <script>
                        $("#rank_"+<?php echo $key; ?>).html(<?php echo $rank; ?>);
                    </script>
                    <?
                    $rank++;
                }
                */
			    
			}
			?>
			</tbody>
			</table>
			</div>
			<?php
		}
		
	    $unique = array_unique($percentArray);

	    $temp = []; $j = 1;
	    foreach($unique as $un){
	        $temp["$un"] = $j;
	        $j++;
	    }

        foreach($percentArray as $key => $val){
            foreach($temp as $key1 => $val1){
                if($val==$key1){
                    ?>
                    <script>
                        $("#rank_"+<?php echo $key; ?>).html(<?php echo $val1; ?>);
                    </script>
                    <?
                }
            }
            
        }

		
		?></div></div></div></div></form><?php
	}

?>

<script>
    function ExportToExcel(type, fn, dl) {
        var elt = document.getElementById('tbl_exporttable_to_xls');
        var wb = XLSX.utils.table_to_book(elt, { sheet: "sheet1" });
        return dl ?
            XLSX.write(wb, { bookType: type, bookSST: true, type: 'base64' }) :
            XLSX.writeFile(wb, fn || ('Term Wise Report.' + (type || 'xlsx')));
    }
</script>

<script type="text/javascript">

function validateme(a){
    
	var v=parseInt(a.value);
	var t=$('#total').val();
	var c=(a.value);
// 	alert(c);
//	var r=$(this).val();

if(c=='AB' || c=='NA'){
    
}
else if(v>t){
	alert("Please enter correct marks");
	a.value='';
}
else {
    alert("Please enter only AB or NA");
    a.value='';
}

// if(c!='AB' && isNaN(v))
// {
// alert("Please enter only AB");
// a.value='';	
// }
// else if(v>t){
// 		alert("Please enter correct marks");
// 		a.value='';
// 	}
	//else if(c!='A'){
		
		//a.value='';
	//}
	
		
	//alert(r);
}


</script>



