
<div style="margin:0; position:fixed; left:0; top:30%; height:25px; background:#999">
<a style=" padding:10px 25px;" href="javascript:;" onclick="printDivNoHeader('printableDiv')">Print</a>
</div>
<style> .headPrint{display:none}</style>
<div id="printableDiv">

<?php
$mss=0;
$allStudent=$db->getRows("select * from student where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and class='".$_GET["class"]."'");
if(is_array($allStudent) && count($allStudent)>0){
	foreach($allStudent as $aryForm){$mss++;
		?>
		<div style="height:942px">
        <div class="headPrint"><img src="<?php echo $LinksDetails["logo"] ?>" height="60px"><h1><?php echo ucfirst($LinksDetails["site_name"]) ?></h1></div>
     <div class="row-fluid">
				<div class="span12">
					<div class="top-bar">
						<h3><i class="icon-cog"></i> Exam type detail</h3>
					</div>
                    
					<div class="well">
                        <div class="span3">
                            <ul class="unstyled">
                              <li><strong class="st">id no</strong> : <?php echo $aryForm["idno"] ?></li>
                              <li><strong class="st">DOA</strong> : <?php echo $aryForm["doa"] ?></li>
                            </ul>
                        </div>
                        <div class="span2">
                            <ul class="unstyled">
                              <li><strong class="st">Class</strong> : <?php echo $aryForm["class"] ?></li>
                              <li><strong class="st">Father</strong> : <?php echo $aryForm["fname"] ?></li>
                            </ul>
                        </div>
                        <div class="span2">
                            <ul class="unstyled">
                              <li><strong class="st">Roll no</strong> : <?php echo $aryForm["rollno"] ?></li>
                              <li><strong class="st">Subling</strong> : <?php echo $aryForm["sibling"] ?></li>
                            </ul>
                        </div>
                        <div class="span3">
                            <ul class="unstyled">
                              <li><strong class="st">Name</strong> : <?php echo $aryForm["name"] ?></li>
                              <li><strong class="st">DOB</strong> : <?php echo $aryForm["dob"] ?></li>
                            </ul>
                        </div>
                        <div class="span2">
                            <?php if($aryForm["photo"]!=""){
                                ?><img src="media/photo/<?php echo $aryForm["photo"]; ?>" style="height:70px" /><?php
                            }?>
                        </div>
                        <?php 
						$exam=$db->getVal("select id from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$aryForm["class"]."' and session='".$_SESSION["admin"]["session"]."' limit 0,1");
						$examtype=$db->getRows("select distinct(type) from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$aryForm["class"]."' and session='".$_SESSION["admin"]["session"]."'");
						if(count($exam)>0){
							$_REQUEST["class"]=$aryForm["class"];$_GET["id"]=$aryForm["idno"];$_GET["type"]="view";
						?>
                        <table class="table">
                        <tr>
                            <td style="border-right:2px solid #FA0606"></td>
                            <?php 
                            
                            if(is_array($examtype) && count($examtype)>0){
                                foreach($examtype as $eytpe){ //echo "<pre>";print_r($eytpe);echo "</pre>";?>
                                <td style="border-right:2px solid #FA0606">
                                <input type="hidden" name="type_<?php echo $mss; ?>[]" style="width:80px" class="total_<?php echo $mss; ?>" value="<?php echo $eytpe[0] ?>" placeholder="Exam type" /><?php echo $eytpe[0] ?><br />
                                Total /Obtain
    </td>
                            <?php }
                            }?>
                        </tr>
                        <?php $x=0;
                        $detail=$db->getRows("select * from subject where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."'");
                        foreach($detail as $d){
                        ?><tr>
                                <td style="border-right:2px solid #FA0606"><?php echo ucfirst($d["subject"]) ?><input type="hidden" name="subject_<?php echo $mss; ?>[]" value="<?php echo $d["subject"] ?>" /></td>
                                <?php 
                                for($i=1; $i<=count($examtype);$i++){ 
                                $examResultData=$db->getRow("select * from exammarks where school_id='".$_SESSION["admin"]["school_id"]."' and idno='".$_GET["id"]."' 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];?>_<?php echo $mss; ?>[]" class="<?php echo $examtype[$i-1][0];?>_total_marks_<?php echo $mss; ?> total" value="<?php
                                echo $total=$db->getVal("select total from examtype where school_id='".$_SESSION["admin"]["school_id"]."' and class='".$_REQUEST["class"]."' and session='".$_SESSION["admin"]["session"]."' and subject='".$d["subject"]."' and type='".$examtype[$i-1][0]."'"); ?>" placeholder="Total Maks" /><?php echo $total; ?>/
                                 <?php if($_GET["type"]=="view")echo (int)$examResultData["obtain"];?>
                                 <input required type="<?php if($_GET["type"]=="view") echo "hidden";else echo "text";?>" onkeyup="getTotal('<?php echo $d["subject"]?>','<?php echo $examtype[$i-1][0];?>','<?php echo $mss; ?>')" style="width:70px" name="<?php echo $examtype[$i-1][0];?>_student_<?php echo $mss; ?>[]" class="onlyZero obtain <?php echo $examtype[$i-1][0];?>_obtain_marks_<?php echo $mss; ?>" value="<?php echo (int)$examResultData["obtain"]; ?>" placeholder="Obtain Maks" />
                                 </td>
                                <?php }$x++; ?>
                            </tr>
                        <?php
                        }
                        ?>
                        <tr>
                            <td style="border-right:2px solid #FA0606">Total</td>
                            <?php 
                            for($i=1; $i<=count($examtype);$i++){ ?>
                                <td style="border-right:2px solid #FA0606">
                                <script type="text/javascript">
                                $(document).ready(function(){
                                    getTotal("0","<?php echo $examtype[$i-1][0];?>",'<?php echo $mss; ?>');
                                    onlyNumber("<?php echo $examtype[$i-1][0]; ?>_obtain_marks_<?php echo $mss; ?>")
                                })
                                </script>
                                <input type="hidden" style="width:70px" id="<?php echo $examtype[$i-1][0];?>_alltotal_<?php echo $mss; ?>" name="<?php echo $examtype[$i-1][0];?>_total_<?php echo $mss; ?>[]" class="total_<?php echo $mss; ?>" value="" placeholder="total Maks" /><span id="<?php echo $examtype[$i-1][0];?>_alldivtotal_<?php echo $mss; ?>"></span>/
                                    <input type="hidden" style="width:70px" id="<?php echo $examtype[$i-1][0];?>_allobtain_<?php echo $mss; ?>" name="<?php echo$examtype[$i-1][0];?>_total_<?php echo $mss; ?>[]" class="total_<?php echo $mss; ?>" value="" placeholder="total obtain" />
                                    <span id="<?php echo $examtype[$i-1][0];?>_alldivobtain_<?php echo $mss; ?>"></span>
                                </td>
                                
                            <?php } ?>
                        </tr>
                        <tr>
                            <td style="border-right:2px solid #FA0606">Percentage</td>
                            <?php 
                            for($i=1; $i<=count($examtype);$i++){ ?>
                            <td style="border-right:2px solid #FA0606">
                            <input type="hidden" style="width:70px" id="<?php echo $examtype[$i-1][0];?>_percentage_<?php echo $mss; ?>" name="<?php echo$examtype[$i-1][0];?>_per_<?php echo $mss; ?>[]" class="per_<?php echo $mss; ?>" value="" placeholder="total obtain" />
                            <span id="<?php echo $examtype[$i-1][0];?>_divpercentage_<?php echo $mss; ?>"></span>
                            </td>
                            <?php }?>
                        </tr>
                        </table>
                        <?php
						}?>
                       <table class="table">
                 	<thead>
                    	<tr>
                        	<th>School Fee Description</th>
                            <th>Total Fee</th>
                            <th>Total Paid</th>
                            <th>Total Left</th>
                            <th>Discount</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php 
                     $session=$db->getRows("select session from session where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."'");
                     $my_root=$db->getVal("select is_root from session_idno	where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and idno='".$aryForm["idno"]."'");
					 if($my_root==""){$db->insertAry("session_idno",array("session"=>$_SESSION["admin"]["session"],"school_id"=>$_SESSION["admin"]["school_id"],"added_by"=>$_SESSION["admin"]["uid"],"idno"=>$aryForm["idno"],"is_root"=>$aryForm["idno"]));$my_root=$aryForm["idno"];}
					 //echo $db->getErMsg().$db->getLastQuery(); 
                     if(is_array($session) && count($session)>0){
                         foreach($session as $s){
                            $installs=$db->getRow("select * from installment where school_id='".$_SESSION["admin"]["school_id"]."' and session='".$s["session"]."' and idno=(select idno from session_idno where session='".$s["session"]."' and is_root=".$my_root.")");
                            $classFee=0;$busFee=0;$classFeePay=0;$busFeePay=0;
                            for($i=1;$i<=15;$i++){
                                $classFee=$classFee+$installs["i".$i];
                                $busFee=$busFee+$installs["b".$i];
                                $classFeePay=$classFeePay+$installs["ip".$i];
                                $busFeePay=$busFeePay+$installs["bp".$i];
                            }
							if(($classFee+$busFee)>($classFeePay+$busFeePay) ){
                            ?>
							<tr style="border-top:2px solid #090">
                                <th>Total Class Fee </th>
                                <th><?php echo $installs["total"]; ?></th>
                                <th><?php echo $classFeePay; ?></th>
                                <th><?php echo (int)($installs["total"]-$classFeePay); ?></th>
                                <td><?php echo $installs["discount"]; ?></td>
                           </tr>
                           <tr>
                                <th>Total Bus Fee</th>
                               <th><?php echo $installs["bus"]; ?></th>
                                <th><?php echo $busFeePay; ?></th>
                                <th><?php echo (int)($installs["bus"]-$busFeePay); ?></th>
                                <td><?php echo $installs["busdiscount"]; ?></td>
                           </tr>
							<?php
							}
                         }
                     }
                     ?>
                     </tbody></table>
                    </div>
                </div>
			</div>
     	</div>
		<?php
	}
}
?>
</div>
<script>
function onlyNumber(name){
	$('.'+name).keydown(function(event) {
		if(event.shiftKey)
		{
			event.preventDefault();
		}
   		if (event.keyCode == 46 || event.keyCode == 8 || event.keyCode == 9 || event.keyCode == 190 || event.keyCode == 110 )   {
   		}
   		else {
        if (event.keyCode < 95) {
			if (event.keyCode < 48 || event.keyCode > 57) {
                event.preventDefault();
			}
        }
        else {
              if (event.keyCode < 96 || event.keyCode > 105) {
                  event.preventDefault();
              }
        }
      }
   });
}

function getTotal(subject,type,id){
	var alltotal=0;var allobtain=0;
	$("."+type+"_total_marks_"+id).each(function(){
		alltotal = parseInt(alltotal) + parseInt($(this).val());
	});
	$("."+type+"_obtain_marks_"+id).each(function(){
		allobtain = parseInt(allobtain) + parseInt($(this).val());
	});
	$("#"+type+"_alltotal_"+id).val(parseInt(alltotal));
	$("#"+type+"_alldivtotal_"+id).html(parseInt(alltotal));
	$("#"+type+"_allobtain_"+id).val(parseInt(allobtain));
	$("#"+type+"_alldivobtain_"+id).html(parseInt(allobtain));
	getAverage($("#"+type+"_alltotal_"+id).val(),$("#"+type+"_allobtain_"+id).val(),type,id);
} 

function getAverage(total,obtain,type,id){
	//alert(total+"-"+obtain+"-"+type+"-"+id)
	var average=0;
	average=(100*obtain)/total;
	$("#"+type+"_percentage_"+id).val(average+"%");
	$("#"+type+"_divpercentage_"+id).html(average+"%");
}
</script>
