<script type="text/javascript" src="js/tableExport.js"></script>

<script type="text/javascript" src="js/jquery.base64.js"></script>

<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>

<?php
    $pgMod="personal_detail";
    $pgAct="view";
?>
    <form method="get" action="">
    <input type="hidden" name="src" value="Student" />
    <input type="hidden" name="page_id" value="<?php echo $pgMod; ?>" />
	<div class="row-fluid">
            <div class="span12">
            	<div class="top-bar">
                    <br />

                    <fieldset style="width:48%; float:left"><legend>Student Personal Details</legend></fieldset>

				</div>

				<div class="well no-padding">
				    <label style="padding:10px;">
				    <input  onchange="checkAll()" class="check" type="checkbox" name="check[]" value="" id="checkboxa" />
				    All Classes
				    </label>
				    <div class="controls controls-row">
				        <?php
			            $class = $db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1");
    					if(is_array($class) && count($class)>0){
						$j = 0;
						foreach($class as $cla){ $number=array(); $j++;

							$sections = $db->getRows("select * from section");
						?>
						<input type="hidden" value="<?php echo count($class); ?>" id="allclass" />
						<input type="hidden" value="<?php echo count($sections); ?>" id="allsection" />
                        	<div class="subcat" style="width:32%;float:left;border-right:solid 2px crimson;padding-left:10px;">

                                <label for="cat<?php echo $cla["id"]; ?>">
                                    <input class="checkboxes" type="checkbox"  value="<?php echo $cla['class']; ?>" id="cat<?php echo $j; ?>" data-class="<?php echo $cla["class"]; ?>" />
                                    <span style="width:150px;position:absolute;padding-left:10px;">
                                        <?php echo $cla["class"] ?>
                                    </span>
                                    <span style="position:relative;margin-left:150px;">
                                        <?php $s=0; foreach($sections as $sec){
                                            $allstudent = $db->getVal("select count(idno) from student where class='".$cla["class"]."' and section='".$sec['name']."' and  session='".$_SESSION["admin"]["session"]."' and school_id='".$_SESSION["admin"]["school_id"]."' and status = 1");
                                                if($allstudent > 0){$s++;
                                                    echo " <input class='checkboxes' type='checkbox' value='$sec[name]' id='sec_".$j."_".$s."' /> $sec[name] &nbsp";
                                                    // $s++;
                                                }
                                            }
                                        ?>
                                    </span>
                                </label>

                            </div>
                          <?php }
					}
				        ?>
				    </div>
				    
                	<div class="controls controls-row">
                        <div style="width:100%;margin-top:20px;">&emsp;&emsp;&emsp;&emsp;
                            <span name="detail" class="btn-classic margin" onclick="fetchByClass('student_personal_detail')"> Personal Detail</span>
                            <span name="roll_no_wise" class="btn-classic margin" onclick="fetchByClass('roll_no_wise')"> Roll No. Wise</span>
                            <span name="roll_no_wise" class="btn-classic margin" onclick="fetchByClass('get_password')"> Password</span>
                            <span name="house_wise" class="btn-classic margin" onclick="fetchByClass('house_wise')"> House Wise</span>
                            <span name="detail" class="btn-classic margin" onclick="fetchByClass('cancelstudent')"> Cancel Student</span>
                            <span class="btn-classic margin" onclick="fetchByClass('bplstudent')"> BPL Students</span>
                            <span class="btn-classic margin" onclick="fetchByClass('newstudent')"> New Students</span>

                            <button type="submit" name="class_teacher" class="btn-classic margin"> Class Teacher Report</button>
                            
                            <button type="submit" name="sibling_report" class="btn-classic margin"> Sibling Report</button>

                        </div>



                    </div>
                    
				</div>
			</div>
    </div>
    </form>

    <input type="button" class="btn btn-primary" id="btn_excel" value="Excel" style="float:right;"/>

    <div id="studentList"></div>
    
	<?php
	$where=array();
	$qry="";
	
    if(isset($_GET["class_teacher"])){
            		$aryClass=$db->getRows("select * from class where school_id='".$_SESSION["admin"]["school_id"]."' and status=1 order by id");
    		$section=$db->getRows("select * from section where school_id='".$_SESSION["admin"]["school_id"]."' order by name ");
    		
    		if(is_array($aryClass) && count($aryClass)>0){
    			?>
          <center><h4>LIST OF CLASS TEACHERS STUDENT STRENGTH - <?php echo $_SESSION["admin"]["session"]; ?> </h4></center>
		 <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 " />-->
                   <button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Class Teacher Report')" >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" cellpadding="0" cellspacing="0" border="1" id="tblData" >
    			<thead>
    				<tr>
                    	<th>S. No.</th>
                    	<th>Name of the Teacher</th>
                    	<th>Teacher Contact</th>
    					<th>Class & Sec</th>
    					<th>Student Strength</th>
    					<th>BPL</th>
    					<th>Total</th>
        			</tr>
    			</thead>
    			<tbody>
    		<?php	$i=0;$total_bpl=0;$total=0;
    					foreach($aryClass as $fclass){
                            $allstudent = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");
                            if($allstudent > 0){
        					foreach($section as $sec){
        					$sectotal = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 ");

        					$clsteacher = $db->getRow("select * from assign_teacher where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' ");

        					$teacher = $db->getRow("select * from staff where idno='".$clsteacher["teacher_id"]."' and session='".$_SESSION["admin"]["session"]."' ");
        				    $bpl = $db->getVal("select Count(*) from student where class='".$fclass["class"]."' and section='$sec[name]' and  school_id='".$_SESSION["admin"]["school_id"]."' and session='".$_SESSION["admin"]["session"]."' and status=1 and issue_TC=0 and bpl='1' ");
            				$total+= $sectotal;
            				$total_bpl+=$bpl;
            					if($sectotal > 0){$i++;
            					?>
                                <tr>
                                	<td><?php echo $i ?></td>
                                	<td><?php echo $teacher['name']; ?></td>
                                	<td><?php echo $teacher['mobile']; ?></td>
            						<td><?php echo $fclass["class"]."-".$sec["name"]; ?></td>
                                    <td><?php echo $sectotal ?></td>
                                    <td><?php echo $bpl ?></td>
            						<td><?php echo $sectotal ?></td>
            					</tr>
                                  <?php
            					}
        					}
    					 } } ?>
    			</tbody>
    				<tfoot><td></td><td>Total</td>
    					<td></td>
    					<td></td>
    				    <td><?php echo $total; ?></td>
                        <td><?php echo $total_bpl; ?></td>
                        <td><?php echo $total; ?></td>
    				</tfoot>
    			</table>  Print date : <?php echo date("d-M-Y") ?>
        </div>
        </div>
    
    <?php }
    }

    if(isset($_GET['sibling_report'])){
        ?>
		<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 " />-->
                   <!--<button class="btn btn-primary" onclick="exportTableToExcel('tblData', 'Class Teacher Report')" >Excel</button>-->
                    <button type="button" onclick="printDiv('printDiv2')" class="btn btn-primary">Print</button>
                </div>
            </div>
            <div class="well no-padding divclass" id="printDiv2">
            <input type="hidden" id="filename" value="Subject Gender Report" />
			 <table class="contentdiv" style="width:100%;">
			     <tr>
			         <td><img src="<?php echo $LinksDetails["logo"]; ?>" height="90px" width="110px" style="margin:0px 0px 3px 10px;"></td>
			         <td style="text-align:center;margin-bottom:18px;margin-right:200px !important;"><h1 style="font-size:30px;margin:5px 0px 0px 0px;color: #EC1E1E;"><?php echo ucfirst($LinksDetails["site_name"]) ?></h1>
    			         <label style="font-size:16px;font-weight:800;  color: #186916;"> <?php echo ucfirst(nl2br($LinksDetails["contact_content"])) ?></label>
			         </td>
			     </tr>
			 </table>
    			 <h3 style="border-bottom:solid 2px green;color:green;text-align:center;">SIBLING REPORT - <?php echo $_SESSION["admin"]["session"]; ?></h3>
    		<table class="table" cellpadding="0" cellspacing="0" border="1" id="tblData" >
    			<thead>
    				<tr>
                    	<th>S.No.</th>
                    	<th>Admission No.</th>
                    	<th>Student Name</th>
                    	<th>Class</th>
                    	<th>Sibling Name</th>
                    	<th>Sibling Adm No</th>
                    	<th>Siblingn Class</th>
        			</tr>
    			</thead>

    			<tbody>
        			<?php
        			    $students = $db->getRows("select * from student where sibling!='' and session='".$_SESSION["admin"]["session"]."' ");
        			        foreach($students as $stu){
        			        $siblings = explode(",", $stu['sibling']);
        			        
        			        foreach($siblings as $sib){
        			            if($sib){ $i++;
        			                
        			                $sibling = $db->getRow("select * from student where idno='$sib' ");
        			        ?>
        			        <tr>
        			            <td><?php echo $i; ?></td>
        			            <td><?php echo $stu['admissionno']; ?></td>
        			            <td><?php echo $stu['name']; ?></td>
        			            <td><?php echo $stu['class']; ?></td>
        			            <td><?php echo $sibling['name']; ?></td>
        			            <td><?php echo $sibling['admissionno']; ?></td>
        			            <td><?php echo $sibling['class']; ?></td>
        			        </tr>
			        <?php } } } ?>
    			</tbody>
    		</table>
    		
            <style>
                .contentdiv {
                    display:none;
                }
                @media print {
                    .contentdiv {display:block;}
                    .contentdiv h1 {
                        margin-left:00px !important;
                    }
                    .contentdiv label{
                        margin-left:00px !important;
                    }
                .headPrint {display:none !important;}
                .mydiv {page-break-after: always;}
                
                }

            </style>
    		
    		</div>
    	</div>
    	</div>
		<?php
    }

	echo $db->getErMsg();
	
?>

	<script type="text/javascript">
	$(document).ready(function(e) {
		var oTable = $('.table').dataTable( {
			"bPaginate": false,
			"bLengthChange": false,
			"bFilter": true,
			"bSort": true,
			"bInfo": true,
			"bAutoWidth": false
		});
	});
	function activeNowMe(id){
		$.ajax({
			url: "<?php echo URL_ROOT ?>Promote/ajax.php?type=activeMe&id="+id
		}).done(function(data) {
			$("#row"+id).hide("slow");
		});
	}
	function getStudentPopup(){
		var url="";
		$(".checkboxes").each(function(){
			if($(this).prop('checked')==true){
				var idno=$(this).val();
				var name=$(".name"+idno).html()
				var left=$(".left"+idno).html()
				url+="&"+name+"`"+idno+"="+left;
			}
		})
		if(url!=""){
			getPopup("<?php echo URL_ROOT ?>Promote/?page_id=MigrateLeftFee&class=<?php echo $_GET["class"] ?>"+url,"1","MigrateLeftFee");
			$(".close").click(function() {
				$(this).parent().remove();
			});
			$(".outer").click(function() {
				$(this).remove();
			});

		}else{
			alert("select atleast one student to mgrate");
		}
	}
	</script>
    <style>
        tfoot{display: table-footer-group !important;}
    	.MigrateLeftFee{width:650px !important}
    </style> 

    <script>
    
        $("#btn_excel").click(function(e) {
            var filename = $("#filename").val();

        let file = new Blob([$('.divclass').html()], {type:"application/vnd.ms-excel"});
        let url = URL.createObjectURL(file);
        let a = $("<a />", {
        href: url,
        download: filename+".xls"}).appendTo("body").get(0).click();
        e.preventDefault();
        });
    
        function exportTableToExcel(tableID, filename = '',e){
            
            var tableType = document.getElementById('tblData').getAttribute("data-tblname");
        
            var downloadLink;
            var dataType = 'application/vnd.ms-excel';
            // var tableSelect = document.getElementById(tableID); 
            
            var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
        
            // Specify file name
            filename = filename?filename+'.xls':'excel_data.xls';
            
            // Create download link element
            downloadLink = document.createElement("a");
            
            document.body.appendChild(downloadLink);
            
            if(navigator.msSaveOrOpenBlob){
                var blob = new Blob(['\ufeff', tableHTML], {
                    type: dataType
                });
                navigator.msSaveOrOpenBlob( blob, filename);
            }else{
                // Create a link to the file
                downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
            
                // Setting the file name
                downloadLink.download = filename;
                
                //triggering the function
                downloadLink.click();
            }
            e.preventDefault();
        }

function checkAll(){
	if($('#checkboxa').prop('checked')) {
		$('.checkboxes').prop('checked', true);
		 
    } else {
		
        $('.checkboxes').prop('checked', false);
    }
}


function fetchByClass(ftype){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: ftype, classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });

}



/*
function personalDetail(){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "student_personal_detail", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });


}

function cancelstudent(){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "cancelstudent", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });


}

function getpassword(){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "get_password", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });

}

function housewise(){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "house_wise", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });

}

function bplstudent(){

    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "bplstudent", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });

}

function newstudent(){
    
    var classes = [];

    var totalclass = $("#allclass").val();
    var totalsection = $("#allsection").val();

    for(var i=1; i<=totalclass; i++) 
    {
        if (document.getElementById("cat"+i)) {
            if (document.getElementById("cat"+i).checked) {
                var cls = document.getElementById("cat"+i).getAttribute("data-class");
                var  sectest = [];
                for(var j=1; j<=totalsection; j++){
                    
                    if (document.getElementById("sec_"+i+"_"+j)) {
                        if (document.getElementById("sec_"+i+"_"+j).checked) {
                            var sec = document.getElementById("sec_"+i+"_"+j).value;
                            sectest.push(sec);
                        }
                    }
                }
                
                classes.push({class:cls, section:sectest});
            }
        }
    }

    $.post("ajax.php", { type: "newstudent", classAry: classes}, function( data ) {
        $('#studentList').html(data);
    });

}
*/

</script>
    
    <!--<input type="button" id="btnExport" value="Export" />-->
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.22/pdfmake.min.js"></script>
    <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
    <script type="text/javascript">
        $("body").on("click", "#btnExport", function () {
            html2canvas($('#tblData')[0], {
                onrendered: function (canvas) {
                    var data = canvas.toDataURL(); 
                    var docDefinition = {
                        content: [{
                            image: data,
                            width: 500
                        }]
                    };
                    pdfMake.createPdf(docDefinition).open("cutomer-details.pdf");
                }
            });
        });
    </script>
