<?php 
require_once("includes/initialize.php");
// $alldept = ONLINEPAY:: showdept();
// $dprepare ="";
session_start();

echo "huuuh:".$Hod = $_SESSION["$HoD"];
// print_r($Hod);

$allsession = ONLINEPAY:: showsession();

$semesters = ONLINEPAY:: showsemester();
//$session = $allsession->session;
// echo $hod;
// $allpayment =ONLINEPAY::showpayment_online("acceptance_tranzact");
$count=0;
?>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
    <script src="https://cdn.datatables.net/1.10.12/js/jquery.dataTables.min.js"></script>  
    <script src="https://cdn.datatables.net/1.10.12/js/dataTables.bootstrap.min.js"></script> 
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/css/bootstrap-datepicker.css" />
    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.4/js/bootstrap-datepicker.js"></script>
</head>
    <body>       
		<div class="container" style="margin-right:0; clear:right; right:0px; width:auto" >
			<h2 align="center">Welcome :: <?php //echo $Hod;?> Head of Department</h2><br/>
			    <form method="post">
			        <div class="form-group input-group" align="center">
			            <table class="table table-bordered table-hover" align="center">
                        	<tr>
                            	<td>
                					<select name="department" id="department" class="form-control action" style="width:200px" required>
                						<option value="">Department</option>
                							<?php if (is_array($Hod))
                							{
                							    foreach($Hod as $dept)
                							{ ?>
                							<option value="<?php echo $dept;?>"><?php 
                							echo strtoupper($dept);?></option> <?php }}
                							else 
                							{?>
                							    <option value="<?php echo $Hod;?>"><?php 
                							echo strtoupper($Hod);?></option>
                							<?}
                							?>
                					</select>
            					</td>
        					    <td>
                					<select name="level" id="level" class="form-control action" style="width:120px" required>
                						<option value="">Level</option>
                						<option value="ND I">ND I</option>
                	                    <option value="ND II">ND II</option>
                	                    <option value="HND I">HND I</option>
                	                    <option value="HND II">HND II</option>		
                					</select></td>
                					<td>
                					<select name="prog" id="prog" class="form-control action" style="width:120px" required>
                						<option value="">Programme</option>
                						<option value="PU">ND Full-Time</option>
                	                    <option value="DP">DPT (ND/HND)</option>
                	                    <option value="FT">HND Full-Time</option>		
                					</select></td>
        					    <td>
                					<select name="session" id="session" class="form-control action" style="width:120px">
                						<option value="">Session</option>
                						<?php foreach($allsession as $session){?>
                						<option value="<?php echo $session->session;?>"><?php 
                						echo $session->session?></option><?php }?>
                					</select></td>
            					<td>
                                    <select name="semester" id="semester" class="form-control action" style="width:120px" required>
                                        <option value="">Semester</option>
                                        <?php foreach($semesters as $sem){?>
                                        <option value="<?php echo $sem->semester;?>"><?php 
                                        echo $sem->semester?></option><?php }?>
                                    </select></td>
                                    
                                    	<td>
                                    <select name="coursecode" id="coursecode" class="form-control action" style="width:120px">
                                        <option value="">Course title|code</option>
                                        
                                    </select></td>
                					<td>
                					    <div class="col-md-4">
                                            <input type="submit" name="search" id ="search" value="Search" class="btn btn-info" />
                                        </div>
                					</td>
                					<td>
        					            <input type="submit" name="Print_pdf" id ="Print_pdf" class="btn btn-danger" value="Print PDF" />
                					</td>
        					</tr> 
                        </table>
					</div>
			    </form>
                <div class="table-responsive">  
                    <div id="showboard" style="width:800; height = 70; overflow:auto; ">
                        <table id="mytable" class="table table-bordered table-hover" style = "height:20">  
                   
                        </table>
                    </div>
                     <!--</form>  -->
                 </div>
    </body>
    
<script>
$(document).ready(function(){
     
$('#search').on("click", function(e){
    e.preventDefault(e);
    	if($(this).val() != '')
	{
        var department = $('#department').val();
        var level = $('#level').val();
        var prog = $('#prog').val();
        var session = $('#session').val();
        var semester = $('#semester').val();
        var coursecode = $('#coursecode').val();
        
        if(department == '')
		{
			alert("Please Select Department");
		}
		else if(level == '')
		{
			alert("Please Select Level");
		}
		else if(prog == '')
		{
			alert("Please Select Programme Type");
		}
		else if(coursecode == '')
		{
			alert("Please Select Course Title");
		}
		else if(semester == '')
		{
			alert("Please Select Semester");
		}else{
		    alert (coursecode);
                $.ajax({
                	url:"attendance_sheet.php",
                	method:"POST",
                	data:{department:department,level:level,session:session,semester:semester,prog:prog,coursecode:coursecode},
                	success:function(data)
                	{
                	    if(data)
                	    {
                	       // dataTable.draw();
                	        $("#mytable").html(data);
                	    }
                	    else
                	    {
                	        alert('Error!!!')
                	    }
                	}
                });
	}
            // }
	
	}else{alert ("Please Select all Options");}
 });
 
 $('#Print_pdf').on("click", function(e){
    e.preventDefault(e);
    
        {
		    window.open("attend_sheetPDF.php");
        }
 });
 
 

$('#semester').on("change",function(e){
    e.preventDefault(e);
    // alert ("Welcome");
	if($(this).val() != '')
	{
	    var department = $('#department').val();
		var level = $('#level').val();
        var prog = $('#prog').val();
		var session = $('#session').val();
		var semester = $('#semester').val();
	   // var action = $(this).attr("id");
        var query = $(this).val();
        var result = 'coursecode';
        // if (action == 'semester')
        // {
        //     result = 'coursecode';
        // }
        // else
        // {
        //     result = '';
        // }
        $.ajax({
            url:'get_courses.php',
            method:"POST",
            data:{query:query,department:department,level:level,session:session,semester:semester,prog:prog},
            success:function(data)
            {
                $('#'+result).html(data);
                                        
            }
        });
	}
}); 
     

$('#level').on("change",function(e){
        e.preventDefault(e);
		if($(this).val() != '')
		{
			var department = $('#department').val();
			var level = $('#level').val();
            var prog = $('#prog').val();
			var session = $('#session').val();
			var semester = $('#semester').val();
			var query = $(this).val();
            var result = 'coursecode';
			{
				$.ajax({
					method:"POST",
					url:"get_courses.php",
					data:{department:department,level:level,session:session,semester:semester,prog:prog},
					success:function(data)
					{
						$('#'+result).html(data);
					}
				})
			}
		}
	}); 
	
	
	$('#department').on("change",function(e){
        e.preventDefault(e);
		if($(this).val() != '')
		{
			var department = $('#department').val();
			var level = $('#level').val();
            var prog = $('#prog').val();
			var session = $('#session').val();
			var semester = $('#semester').val();
			var query = $(this).val();
            var result = 'coursecode';
			{
				$.ajax({
					method:"POST",
					url:"get_courses.php",
					data:{department:department,level:level,session:session,semester:semester,prog:prog},
					success:function(data)
					{
						$('#'+result).html(data);
					}
				})
			}
		}
	});   

//  });      
 
 
 
 
 
 
// //  $(document).ready(function(e){  
//     //   alert ("Welcome");
//     $('#department').on("change",function(e){
       
//         alert ("Welcome");
//      //    e.preventDefault(e);
//  	//	if($(this).val() != '') //AND $('#department').val()!='' AND $('#level').val()!='' AND $('#department').val()!='' )
//  		{
//  		    alert $(this);
//  		     	var department = $('#department').val();
// 			var level = $('#level').val();
// 			var session = $('#session').val();		
 			
//  				$.ajax({
//  					method:"POST",
//  					url:"fetchcoursecode.php",
//  					data:{department:department,level:level,session:session},
//  					success:function(data)
//  					{
// // 						$("#fo_table").html(data);
//  					}
//  				})
 			
//  		}else {
//  		    alert("Incomplete search query string..Check again");
//  		}
//  	});  

 });
 
 
 </script>  
 <!--</html>-->