<?php
if(!isset($_SERVER['HTTP_REFERER'])){
    // redirect them to your desired location
    header('location:../index.php');
    exit;
}
?>
<?php include_once('head.php'); ?>
<?php include_once('header_admin.php'); ?>
<?php include_once('sidebar.php'); ?>
<?php include_once('alert.php'); ?>

<style>
body { 
	overflow-y:scroll;
}

tbody tr{
	height:100px;	
}

.modal-content1 {
   position: absolute;
   left: 125px; 
}
@media only screen and (max-width: 500px) {

	.modal-content1 {
   		
		position:static;
   
	}
	#divGender1{
		
	 	width:75%;
		
	}
	
}




.form-control-feedback {
  
   pointer-events: auto;
  
}

.set-width-tooltip + .tooltip > .tooltip-inner { 
  
     min-width:180px;
}
.set-color-tooltip + .tooltip > .tooltip-inner { 
  
     min-width:180px;
	 background-color:red;
}
.image-error{
	border:1px solid #f44336;
	
}

.image-success{
	border:1px solid #009900;
	
}

.msk-fade {  
      
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s

}

body.modal-open-noscroll1
{
    overflow:hidden;
	
 
}
/* Add Animation */
@-webkit-keyframes animatetop {
    from {top:-300px; opacity:0} 
    to {top:0; opacity:1}
}

@keyframes animatetop {
    from {top:-300px; opacity:0}
    to {top:0; opacity:1}
}


</style>

<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
	<!-- Content Header (Page header) -->
    <section class="content-header">
    	<h1>
        	Emploi du temps
            <small>Aperçu</small>
        </h1>
        <ol class="breadcrumb">
        	<li><a href="#"><i class="fa fa-dashboard"></i> Accueil</a></li>
            <li><a href="#">Emploi du temps</a></li>
        </ol>
	</section>

	<!-- Main content -->
    <section class="content">
    	<div class="row">
        	<!-- left column -->
            <div class="col-md-6">
            	<!-- general form elements -->
              	<div class="box box-primary">
                	<div class="box-header with-border">
                  		<h3 class="box-title">Ajouter emploi du temps</h3>
                	</div><!-- /.box-header -->
                  	<div class="box-body" >
                  	 	<div class="form-group" id="divGender">
                    		<div class="col-xs-3">
                      			<label for="exampleInputPassword1">Spécialité</label>
                    		</div>
                    		<div class="col-xs-4" id="divGender1">
                    			<select name="grade" class="form-control" id="grade" ><!--MSK-000107-->
                    				<option>Sélectionnez spécialité...</option>
<?php
include_once('../controller/config.php');
$sql="SELECT * FROM grade";
$result=mysqli_query($conn,$sql);
if(mysqli_num_rows($result) > 0){
	while($row=mysqli_fetch_assoc($result)){
?> 
     								<option value="<?php echo $row["id"]; ?>"><?php echo $row['name']; ?></option>
<?php }} ?>
					  			</select>
                     		</div>
							
							<div class="col-xs-3">
                      			<label for="exampleInputPassword1">Groupe</label>
                    		</div>
							<div class="col-xs-2" id="divGender1">
                    			<select name="grade_groupe" class="form-control" id="grade_groupe" ><!--MSK-000107-->		
										   <option value="G1">G1</option>
                                           <option value="G2">G2</option>
                                           <option value="G3">G3</option>
										   <option value="G4">G4</option>
                                           <option value="G5">G5</option>
								</select>									
                     		 </div>

							
							
							
                    	</div>
                  	</div><!-- /.box-body -->
                  	<div class="box-footer">
                    	<button type="button" class="btn btn-primary"  onClick="showTimeTable(this)">Afficher</button><!--MSK-000108-->
                  	</div>
            	</div><!-- /.box -->
        	</div>
    	</div>
	</section><!-- End of form section -->

<!-- table for view all records-->
	<!-- Main content -->
    <section class="content" > <!-- Start of table section -->
    	<div class="row" id="table1"><!--MSK-000112--> 
           
        </div>
    </section> <!-- End of table section --> 
     

<script type="text/javascript">
    function gendf() {
        var doc = new jsPDF();
        doc.addHTML(document.getElementById('grade'), function () {
			doc.save('demo timetable.pdf');
            alert("Downloaded!");
        });
    }
</script>
<div align="left" style="margin-top: 6px">
    <button id="saveaspdf" class="btn btn-primary" onclick="gendf()">exporeter PDF</button>
</div>






	 
<script>
function showTimeTable(){
//MSK-000109
	
	var grade = document.getElementById("grade").value;	
	var grade_groupe = document.getElementById("grade_groupe").value;	
	var do1 ="show_Timetable";
	
	var xhttp = new XMLHttpRequest();//MSK-000110-Start Ajax  
  		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
					
				document.getElementById('table1').innerHTML = this.responseText;//MSK-000111
										
    		}
			
  		};
			
    	xhttp.open("GET", "timetable_grade_wise.php?grade="+grade + "&grade_groupe="+grade_groupe + "&do="+do1 , true);												
  		xhttp.send();//MSK-000110-End Ajax
	
};
function showgrade(){
//MSK-000109
	
	var grade = document.getElementById("grade").value;	
	var grade_groupe = document.getElementById("grade_groupe").value;	
	var do1 ="show_grade";
	
	var xhttp = new XMLHttpRequest();//MSK-000110-Start Ajax  
  		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
					
				document.getElementById('table1').innerHTML = this.responseText;//MSK-000111
										
    		}
			
  		};
			
    	xhttp.open("GET", "notes.php?grade="+grade + "&grade_groupe="+grade_groupe + "&do="+do1 , true);												
  		xhttp.send();//MSK-000110-End Ajax
	
};
function showTimeTable1(grade){//MSK-000143-8
	
	var do1 ="show_Timetable";
	var xhttp = new XMLHttpRequest();//MSK-00143-9-Ajax Start  
  		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
					
				document.getElementById('table1').innerHTML = this.responseText;//MSK-000143-10
				window.scrollTo(0,document.body.scrollHeight);
										
    		}
			
  		};
			
    	//xhttp.open("GET", "timetable_grade_wise.php?grade="+grade + "&do="+do1 , true);
		xhttp.open("GET", "timetable_grade_wise.php?grade="+grade + "&grade_groupe="+grade_groupe + "&do="+do1 , true);												
  		xhttp.send();//MSK-00143-9-Ajax End
	
};

</script>

	<!-- //MSK-000118 Modal- modalInsertform-->    
	<div id="divAddtt">

	</div>       
    
<script>





function showModal(Insertform){
//MSK-000114	
	var Id = $(Insertform).data("id"); 

	var xhttp = new XMLHttpRequest();//MSK-000115-Ajax Start  
  		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
									
				document.getElementById('divAddtt').innerHTML = this.responseText;//MSK-000117
				$("#modalInsertform").modal('show');//MSK-000119  
	
				$("#subject").change(function() {//MSK-000120
					
					var subject = document.getElementById("subject").value;
	
					var xhttp1 = new XMLHttpRequest();//MSK-00121-Ajax Start  
  						xhttp1.onreadystatechange = function() {
	
    						if (this.readyState == 4 && this.status == 200) {	
									
								document.getElementById('teacher').innerHTML = this.responseText;//MSK-000123
										
    						}
			
  						};	
						
    					xhttp1.open("GET", "../model/get_teacher_timetable.php?subject="+subject + "&grade="+Id, true);												
  						xhttp1.send();//MSK-00121-Ajax End
	
				});
				
				$("form").submit(function (e) {
				//MSK-000126-form submit
				
					var day = $('#day').val();
					var subject = $('#subject').val();
					var teacher = $('#teacher').val();	
					var classroom = $('#classroom').val();
					//var grade_groupe = $('#grade_groupe').val();
					var start_time = $('#start_time').val();	
					var end_time = $('#end_time').val();	
				
					if(day == 'Select Day'){
						//MSK-00127-day 
						$("#btnSubmit").attr("disabled", true);
						$('#divDay').addClass('has-error has-feedback');
						$('#divDay').append('<span id="spanDay" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The day is required" ></span>');	
					
						$("#day").change(function() {
							//MSK-00128-day  
							$("#btnSubmit").attr("disabled", false);	
							$('#divDay').removeClass('has-error has-feedback');
							$('#spanDay').remove();
						
						});
				
					}else{
					
					}
					
					if(subject == 'Select Subject'){
						//MSK-00127-subject       
						$("#btnSubmit").attr("disabled", true);
						$('#divSubject').addClass('has-error has-feedback');
						$('#divSubject').append('<span id="spanSubject" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The subject is required" ></span>');	
					
						$("#subject").change(function() {
							//MSK-00128-subject
							$("#btnSubmit").attr("disabled", false);	
							$('#divSubject').removeClass('has-error has-feedback');
							$('#spanSubject').remove();
						
						});
				
					}else{
					
					}
					
					if(teacher == 'Select Teacher'){
						//MSK-00127teacher  
						$("#btnSubmit").attr("disabled", true);
						$('#divTeacher').addClass('has-error has-feedback');
						$('#divTeacher').append('<span id="spanTeacher" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The teacher is required" ></span>');	
					
						
						$("#teacher").change(function() {
							//MSK-00128-teacher  
							$("#btnSubmit").attr("disabled", false);	
							$('#divTeacher').removeClass('has-error has-feedback');
							$('#spanTeacher').remove();
						
						});
				
					}else{
					
					}
					
					if(classroom == 'Select Classroom'){
						//MSK-00127-classroom
						$("#btnSubmit").attr("disabled", true);
						$('#divClassroom').addClass('has-error has-feedback');
						$('#divClassroom').append('<span id="spanClassroom" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The classroom is required" ></span>');	
					
						$("#classroom").change(function() {
							//MSK-00128-classroom
							$("#btnSubmit").attr("disabled", false);	
							$('#divClassroom').removeClass('has-error has-feedback');
							$('#spanClassroom').remove();
						
						});
				
					}else{
					
					}
					
					if(start_time == ''){
						//MSK-00127-start time  
						$("#btnSubmit").attr("disabled", true);
						$('#divStartTime').addClass('has-error has-feedback');
						$('#divStartTime').append('<span id="spanStartTime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The start time is required" ></span>');	
					
						$("#start_time").keydown(function() {
							//MSK-00128-start time 
							$("#btnSubmit").attr("disabled", false);	
							$('#divStartTime').removeClass('has-error has-feedback');
							$('#spanStartTime').remove();
						
						});
				
					}else{
					
					}
				
					if(end_time == ''){
						//MSK-00127-end time  
						$("#btnSubmit").attr("disabled", true);
						$('#divEndTime').addClass('has-error has-feedback');
						$('#divEndTime').append('<span id="spanEndTime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The end time is required" ></span>');	
					
						$("#end_time").keydown(function() {
							//MSK-00128-end time       
							$("#btnSubmit").attr("disabled", false);	
							$('#divEndTime').removeClass('has-error has-feedback');
							$('#spanEndTime').remove();
						
						});
				
					}else{
					
					}
				
					if(day == 'Select Day' || subject == 'Select Subject' || teacher == 'Select Teacher' || classroom == 'Select Classroom' || start_time == '' || end_time == '' ){
						//MSK-000126- form validation failed
						$("#btnSubmit").attr("disabled", true);
						e.preventDefault();
						return false;
							
					}else{
						$("#btnSubmit").attr("disabled", false);
						//return true;
					}

				});
						
    		}
			
  		};	
		
    	xhttp.open("GET", "timetable_insert_form.php?grade="+Id , true);
		//xhttp.open("GET", "timetable_insert_form?grade="+Id + "&grade_groupe="+grade_groupe, true);												
  		xhttp.send();//MSK-000115-Ajax End
	
};







function showModal1(time){
//MSK-000130 

	var myArray = $(time).closest('a').data("id").split(',');
	var myArray1 = $(time).closest('tr').attr('id').split('_');
	
	var xhttp = new XMLHttpRequest();
		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
									
				document.getElementById('divAddtt').innerHTML = this.responseText;
				$("#modalInsertform").modal('show');
	
				document.getElementById("start_time").value=myArray1[0];
				document.getElementById("end_time").value=myArray1[1];
				document.getElementById("day").value=myArray[0];
					
					$("#subject").change(function() {
							
						var subject = document.getElementById("subject").value;
						
						var xhttp1 = new XMLHttpRequest();
  							xhttp1.onreadystatechange = function() {
	
    							if (this.readyState == 4 && this.status == 200) {	
									
									document.getElementById('teacher').innerHTML = this.responseText;
										
    							}
			
  							};	
							
    						xhttp1.open("GET", "../model/get_teacher_timetable.php?subject="+subject + "&grade="+myArray[1] , true);												
  							xhttp1.send();
	
					});
					
					$("form").submit(function (e) {
						
						var day = $('#day').val();
						var subject = $('#subject').val();
						var teacher = $('#teacher').val();	
						var classroom = $('#classroom').val();
						var start_time = $('#start_time').val();	
						var end_time = $('#end_time').val();	
					
						if(day == 'Select Day'){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divDay').addClass('has-error has-feedback');
							$('#divDay').append('<span id="spanDay" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The day is required" ></span>');	
						
							
							$("#day").change(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divDay').removeClass('has-error has-feedback');
								$('#spanDay').remove();
							
							});
					
						}else{
						
						}
						
						if(subject == 'Select Subject'){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divSubject').addClass('has-error has-feedback');
							$('#divSubject').append('<span id="spanSubject" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The subject is required" ></span>');	
						
							$("#subject").change(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divSubject').removeClass('has-error has-feedback');
								$('#spanSubject').remove();
							
							});
					
						}else{
						
						}
						
						if(teacher == 'Select Teacher'){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divTeacher').addClass('has-error has-feedback');
							$('#divTeacher').append('<span id="spanTeacher" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The teacher is required" ></span>');	
						
							
							$("#teacher").change(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divTeacher').removeClass('has-error has-feedback');
								$('#spanTeacher').remove();
							
							});
					
						}else{
						
						}
						
						if(classroom == 'Select Classroom'){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divClassroom').addClass('has-error has-feedback');
							$('#divClassroom').append('<span id="spanClassroom" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The classroom is required" ></span>');	
							
							$("#classroom").change(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divClassroom').removeClass('has-error has-feedback');
								$('#spanClassroom').remove();
							
							});
					
						}else{
						
						}
						
						if(start_time == ''){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divStartTime').addClass('has-error has-feedback');
							$('#divStartTime').append('<span id="spanStartTime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The start time is required" ></span>');	
						
							$("#start_time").keydown(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divStartTime').removeClass('has-error has-feedback');
								$('#spanStartTime').remove();
							
							});
					
						}else{
						
						}
					
						if(end_time == ''){
						
							$("#btnSubmit").attr("disabled", true);
							$('#divEndTime').addClass('has-error has-feedback');
							$('#divEndTime').append('<span id="spanEndTime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip"    title="The end time is required" ></span>');	
						
							$("#end_time").keydown(function() {
							
								$("#btnSubmit").attr("disabled", false);	
								$('#divEndTime').removeClass('has-error has-feedback');
								$('#spanEndTime').remove();
							
							});
					
						}else{
						
						}
					
						if(day == 'Select Day' || subject == 'Select Subject' || teacher == 'Select Teacher' || classroom == 'Select Classroom' || start_time == '' || end_time == '' ){
						
							$("#btnSubmit").attr("disabled", true);
							e.preventDefault();
							return false;
								
						}else{
							$("#btnSubmit").attr("disabled", false);
							//return true;
						}

					});//end of the form submit function
					
									
    			}
			
		};
			
		xhttp.open("GET", "timetable_insert_form.php?grade="+myArray[1] , true);												
  		xhttp.send();
	
};


</script>
  
<!--run Insert alert using PHP & JS/jQuery  -->          
<?php
if(isset($_GET["do"])&&($_GET["do"]=="alert_from_insert")){
//MSK-000143-6-PHP-JS-INSERT
  
	$msg=$_GET['msg'];
	$grade=$_GET['grade'];
	
	if($msg==1){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-7-msg=1 
		
		echo"
			<script>
			
			var myModal = $('#duplicate_Record2');
			myModal.modal('show');
			
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
						
			</script>
		";
	
	}

	if($msg==2){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-7-msg=2 
		
		echo"
			<script>
			
			var myModal = $('#insert_Success');
			myModal.modal('show');

			clearTimeout(myModal.data('hideInterval'));
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
			
			</script>
		";
	
	}

	if($msg==3){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-7-msg=3 
		
		echo"
			<script>
			
			var myModal = $('#connection_Problem');
			myModal.modal('show');
			
			clearTimeout(myModal.data('hideInterval'));
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
			
			</script>
		";
	
	}
	
	
}
?><!--./Insert alert -->    


    <div id="divUpdatett"><!--MSK-000138-->
    
    </div>

<script>
function showModal2(Updateform){
//MSK-000132
	
	var myArray = $(Updateform).data("id").split(',');
	
	var Id = myArray[0];
	var grade = myArray[1];
	
	var xhttp = new XMLHttpRequest();//MSK-00133-Ajax Start  
		xhttp.onreadystatechange = function() {
			
    		if (this.readyState == 4 && this.status == 200) {	
									
				var myArray1 = eval( xhttp.responseText );
				
				var xhttp2 = new XMLHttpRequest();//MSK-00135-Ajax Start  
  					xhttp2.onreadystatechange = function() {
	
						if (this.readyState == 4 && this.status == 200) {	
										
							document.getElementById('divUpdatett').innerHTML = this.responseText;//MSK-000137
							$("#modalUpdateform").modal('show');//MSK-000139
							
							//MSK-000140
							document.getElementById("id1").value=myArray1[0];
							document.getElementById("day1").value=myArray1[1];
							document.getElementById("subject1").value=myArray1[2];
							document.getElementById("teacher1").value=myArray1[3];
							document.getElementById("classroom1").value=myArray1[4];
							document.getElementById("start_time1").value=myArray1[5];
							document.getElementById("end_time1").value=myArray1[6];
							
							$("#subject1").change(function() {//MSK-000141
							
								var subject = document.getElementById("subject1").value;
								
								var xhttp1 = new XMLHttpRequest();//MSK-00142-Ajax Start  
  									xhttp1.onreadystatechange = function() {
	
    								if (this.readyState == 4 && this.status == 200) {	
									
										document.getElementById('teacher1').innerHTML = this.responseText;//MSK-000144
										
    								}
			
  								};	
							
    							xhttp1.open("GET", "../model/get_teacher_timetable.php?subject="+subject + "&grade="+grade, true);												
  								xhttp1.send();//MSK-00142-Ajax End
	
							});
							
							$("form").submit(function (e) {//MSK-000147-form submit
							
								var day = $('#day1').val();
								var subject = $('#subject1').val();
								var teacher = $('#teacher1').val();	
								var classroom = $('#classroom1').val();
								var start_time = $('#start_time1').val();	
								var end_time = $('#end_time1').val();	
											
								if(teacher == 'Select Teacher'){
									//MSK-00148-teacher  
									$("#btnSubmit1").attr("disabled", true);
									$('#divUpdateTeacher').addClass('has-error has-feedback');
									$('#divUpdateTeacher').append('<span id="spanUpdateTeacher" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The teacher is required" ></span>');	
								
									
									$("#teacher1").change(function() {
										//MSK-00149-teacher  
										$("#btnSubmit1").attr("disabled", false);	
										$('#divUpdateTeacher').removeClass('has-error has-feedback');
										$('#spanUpdateTeacher').remove();
									
									});
							
								}else{
								
								}
								
								if(start_time == ''){
									//MSK-00148-start time  
									$("#btnSubmit1").attr("disabled", true);
									$('#divUpdateSTime').addClass('has-error has-feedback');
									$('#divUpdateSTime').append('<span id="spanUpdateSTime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The start time is required" ></span>');	
								
									$("#start_time1").keydown(function() {
										//MSK-00149-start time 
										$("#btnSubmit1").attr("disabled", false);	
										$('#divUpdateSTime').removeClass('has-error has-feedback');
										$('#spanUpdateSTime').remove();
									
									});
							
								}else{
								
								}
					
								if(end_time == ''){
									//MSK-00148-end time  
									$("#btnSubmit1").attr("disabled", true);
									$('#divUpdateETime').addClass('has-error has-feedback');
									$('#divUpdateETime').append('<span id="spanUpdateETime" class="glyphicon glyphicon-remove form-control-feedback set-width-tooltip" data-toggle="tooltip" title="The end time is required" ></span>');	
								
									$("#end_time1").keydown(function() {
										//MSK-00149-end time       
										$("#btnSubmit1").attr("disabled", false);	
										$('#divUpdateETime').removeClass('has-error has-feedback');
										$('#spanUpdateETime').remove();
									
									});
							
								}else{
								
								}
					
								if(teacher == 'Select Teacher' ||  start_time == '' || end_time == '' ){
									//MSK-000147-form validation failed
									$("#btnSubmit1").attr("disabled", true);
									e.preventDefault();
									return false;
										
								}else{
									$("#btnSubmit1").attr("disabled", false);
									//return true;
								}
								
							});
							
						}
			
  					};	
							
    				xhttp2.open("GET", "timetable_update_form.php?subject="+myArray1[2] + "&grade="+grade, true);												
  					xhttp2.send();//MSK-00135-Ajax End						
    			}
			
		};
			
		xhttp.open("GET", "../model/get_timetable.php?id="+Id , true);												
  		xhttp.send();//MSK-00133-Ajax End
	
};

</script>

<!--run Update alert using PHP & JS/jQuery  -->          
<?php
//MSK-000143-U-18-PHP-JS-UPDATE
if(isset($_GET["do"])&&($_GET["do"]=="alert_from_update")){
  
	$msg=$_GET['msg'];
	$grade=$_GET['grade'];
	
	if($msg==1){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-U-18-msg=1 
		
		echo"
			<script>
			
			var myModal = $('#update_Success');
			myModal.modal('show');
			
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
						
			</script>
		";
	
	}

	if($msg==2){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-U-18-msg=2 
		
		echo"
			<script>
			
			var myModal = $('#connection_Problem');
			myModal.modal('show');

			clearTimeout(myModal.data('hideInterval'));
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
			
			</script>
		";
	
	}

	if($msg==3){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-U-18-msg=3 
		
		echo"
			<script>
			
			var myModal = $('#update_error1');
			myModal.modal('show');
			
			clearTimeout(myModal.data('hideInterval'));
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
			
			</script>
		";
	
	}
	
	if($msg==4){
		
		echo '<script>','showTimeTable1('.$grade.');','</script>';//MSK-000143-U-18-msg=4     
		
		echo"
			<script>
			
			var myModal = $('#duplicate_Record2');
			myModal.modal('show');
			
			clearTimeout(myModal.data('hideInterval'));
    		myModal.data('hideInterval', setTimeout(function(){
    			myModal.modal('hide');
    		}, 3000));
			
			</script>
		";
	
	}
	
}
?><!--./Insert alert -->    
                       
<!-- //MSK-000153 Modal-Delete Confirm Popup -->
	<div class="modal msk-fade " id="deleteConfirm" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  		<div class="modal-dialog">
    		<div class="modal-content">
				<div class="modal-header bg-primary">
        			<button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
        			<h4 class="modal-title" id="frm_title">Supprimer</h4>
      			</div>

				<div class="modal-body bgColorWhite">
        			<strong style="color:red;">Es-tu sûr?</strong>  Voulez-vous supprimer cet enregistrement.
        		</div>
      			<div class="modal-footer">
					<a href="#" style='margin-left:10px;' id="btnYes" class="deletebtn btn btn-danger col-sm-2 pull-right">Oui</a><!-- MSK-000154 -->
        			<button type="button" class="btn btn-primary col-sm-2 pull-right" data-dismiss="modal" id="frm_cancel">Non</button>
      			</div>
    		</div>
  		</div>
	</div>
  


  
<script>

$('body').on('click', '.confirm-delete', function (e){//MSK-000151
	e.preventDefault();
    var id = $(this).data('id');
	$('#deleteConfirm').data('id1', id).modal('show');//MSK-000152
});

$('#btnYes').click(function() {//MSK-000155
	
	var myArray3 = $('#deleteConfirm').data('id1').split(',');
     		
    var id = myArray3[0];
	var grade1 = myArray3[1];
	var grade_groupe1 = myArray3[9];
	var do1 = "delete_record";	
	var table_name1= "timetable";//give data table name
		
	var info = $('#example1').DataTable().page.info();
	var currentPage= (info.page + 1);
	
	var xhttp = new XMLHttpRequest();//MSK-000156-Ajax Start  
		xhttp.onreadystatechange = function() {
			
    	if (this.readyState == 4 && this.status == 200) {
			//MSK-000157	
			var myArray = eval(xhttp.responseText);
					
				if(myArray[0]==1){//MSK-000158
				
					$("#deleteConfirm").modal('hide');	        		
					var do2 ="show_Timetable";
				    
					var xhttp1 = new XMLHttpRequest();//MSK-000159-Start Ajax  
						xhttp1.onreadystatechange = function() {		
				
							if (this.readyState == 4 && this.status == 200) {
										
								document.getElementById('table1').innerHTML = this.responseText;//MSK-000160
								Delete_alert(myArray[0]);//MSK-000161
								window.scrollTo(0,document.body.scrollHeight);
							
							}
								
						};
						
						xhttp1.open("GET", "timetable_grade_wise.php?grade=" + grade1 + "&grade_groupe1=" + grade_groupe1 + "&do="+do2 , true);												
  						xhttp1.send();//MSK-000159-End Ajax
				
				}
		
				if(myArray[0]==2){//MSK-000163
			
					$("#deleteConfirm").modal('hide');
					Delete_alert(myArray[0]);//MSK-000164
				
				}

    		}
			
  		};
			
		xhttp.open("GET", "../model/delete_record.php?id=" + id + "&do="+do1 + "&table_name="+table_name1 + "&page="+currentPage , true);												
  		xhttp.send();//MSK-000156-Ajax End
	 			   		
});





function Delete_alert(msg){//MSK-000162
	
	if(msg==1){
		
    	var myModal = $('#delete_Success');
		myModal.modal('show');
		
		clearTimeout(myModal.data('hideInterval'));
    	myModal.data('hideInterval', setTimeout(function(){
    		myModal.modal('hide');
			
    	}, 3000));
			
	}
	
	if(msg==2){
		
    	var myModal = $('#connection_Problem');
		myModal.modal('show');
		
    	clearTimeout(myModal.data('hideInterval'));
    	myModal.data('hideInterval', setTimeout(function(){
    		myModal.modal('hide');
    	}, 3000));
				
	}

};	

	
</script>  



<!--redirect your own url when clicking browser back button -->
<script>
(function(window, location) {
history.replaceState(null, document.title, location.pathname+"#!/history");
history.pushState(null, document.title, location.pathname);

window.addEventListener("popstate", function() {
  if(location.hash === "#!/history") {
    history.replaceState(null, document.title, location.pathname);
    setTimeout(function(){
      location.replace("../index.php");//path to when click back button
    },0);
  }
}, false);
}(window, location));
</script>

  	 	
</div><!-- /.content-wrapper -->  
               

               
<?php include_once('footer.php');?>