<?php
include("common/connection.php");
//login_check();
$_REQUEST['d'];
$_REQUEST['pid'];
//$Lead_Req_Id=$_REQUEST['Lid'];
$user_type_sql="select * from user_master where User_Name='".$_SESSION['user']."'";
$user_type_query=mysqli_query($con,$user_type_sql);
$user_type=mysqli_fetch_array($user_type_query);
$cityname=mysqli_fetch_array(mysqli_query($con,"select * from location_master where SLN='".$user_type['Location']."'"));
$cityname['Location_Name'];
/*$lead_basic_sql="select * from lead_master where Lead_ID='".$Lead_Req_Id."'";
$lead_basic_query=mysqli_query($con,$lead_basic_sql);
$lead_details=mysqli_fetch_array($lead_basic_query);*/
?>

<!doctype html>
<html class="no-js" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="x-ua-compatible" content="ie=edge">
    <title>Add Roster Plan| Buurtzorg</title>
    <?php include("headerlink.php"); ?> 
     <link rel="stylesheet" href="css/form/all-type-forms.css">
    <!-- x-editor CSS
		============================================ -->
    <link rel="stylesheet" href="css/editor/select2.css">
    <link rel="stylesheet" href="css/editor/datetimepicker.css">
    <link rel="stylesheet" href="css/editor/bootstrap-editable.css">
    <link rel="stylesheet" href="css/editor/x-editor-style.css">

    
	<style>
	
	.table_head_class{
		background-color:#337ab7;
		height:30px;
		line-height:30px;
		text-align:center;
		color:#FFF;
		font-size:15px;
	}
	
		.table_body_class{
		background-color:#f7f7f6;
		height:auto;
		padding:5px 2%
	}
	
	
	</style>
	
	
	
	
    <script>
	function unlock_form() {
	 
	$('#edit_c_form  input'). prop("disabled", false);
	//$('#not_editable  input'). prop("disabled", true);
	$('#edit_c_form  textarea'). prop("disabled", false);
	$('#edit_c_form  select'). prop("disabled", false);
	$('#update_btn').show();
	$('#edit_btn_1').hide();
	
 
	}
	</script>
    
    <script>
	function call_status(per) {
	 
	// alert(per);
	if(per=='Call Later') {
	$('#call_later').show();
	$('#call_later_time').show();
	
	} 	
	else{
	
	  $('#call_later').hide();
	  $('#call_later_time').hide();
	}
 
	}
	
 
	</script> 
    
    <script>
function isNumberKey(evt) 
{
var charCode = (evt.which) ? evt.which : event.keyCode; 
if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57)) 
{
return false;
} 
else 
{
return true;
} 
} 

function get_time()
{
var from_time=$("#DutyHour").val();
var from_date=$("#date").val();
var work_hour=$("#dutyto").val();
	$.ajax({
		url:'ajax-calculate-time.php',
		type:'POST',
		data:'time1=' + from_time + '&date1=' + from_date + '&work_hour=' + work_hour,
		success:function(f)
		{
		$('#hour1').show();
		$('#hour_d').val(f);
		}
	});
}
</script>

<script>
function select_day()
{
 if($('#check_day').is(":checked"))   
        $("#countday").show();
    else
        $("#countday").hide();
		
}
</script>    
    
  <script>
function validation123()
{

var DutyHour=$('#DutyHour').val();
var dutyto=$('#dutyto').val();
var date5=$('#date').val();
var tna=$('#servicetna').val();
//alert(dutyto);
	$.ajax({
	url:'ajax-tna-alert.php',
	type:'POST',
	data:'DutyHour=' + DutyHour + '&dutyto=' + dutyto + '&date5=' + date5 + '&tna=' + tna,
	success:function(f)
	{
		//alert(f);
		if(f==1)
		{
		 var c=confirm('TNA serve more than 12 hours on last days.Do you want allocate this TNA for today?');
		 if(c == true)
		 {
		 $('#edit_lead').submit();
		 }
		}
		
		else if(f==2)
		{
		 var c=confirm('TNA serve more than 72 hours on last six days.Do you want allocate this TNA for today?');
		 if(c == true)
		 {
		 $('#edit_lead').submit();
		 }
		}
		
		else if(f==3)
		{
		 var c=confirm('TNA serve on last two nights.Do you want allocate this TNA for today?');
		 if(c == true)
		 {
		 $('#edit_lead').submit();
		 }
		}
		else if(f==4)
		{
		 var c=confirm('TNA serve more than 120 hours on last few days.Do you want allocate this TNA for today?');
		 if(c == true)
		 {
		 $('#edit_lead').submit();
		 }
		}
		else
		{
		$('#edit_lead').submit();
		}
	}	
	})
}

</script>  
<script>
/*function time_alert()
{
var DutyHour=$('#DutyHour').val();
//alert(DutyHour);
	$.ajax({
	
	url:'ajax-time-view-tna.php',
	type:'POST',
	data:'DutyHour=' + DutyHour,
	//success:function(f)
	{
	alert(f);
	}
	})
}*/
</script>      
</head>
   <?php
$patient_master=mysqli_fetch_array(mysqli_query($con,"select Patient_Id,Lead_ID,Control_Location from patient_master where Patient_Id='".$_REQUEST['pid']."'"));   
$allocation_master=mysqli_fetch_array(mysqli_query($con,"select Care_Type from allocation_master where Lead_ID='".$patient_master['Lead_ID']."'"));   
  if(isset($_REQUEST['servicetna']))
  {
	  if(date('H:i:s',strtotime($_REQUEST['DutyHour']))>='19:00:00')
	  {
	  $night=1;
	  }
	  else
	  {
	  $night=0;
	  }
	    	
	  $numofday=$_REQUEST['countday'];
	  $select_date=date('Y-m-d H-i-s',strtotime($_REQUEST['d']." ".$_REQUEST['DutyHour']));
	  $end_date=date('Y-m-d',strtotime($_REQUEST['hour_d']));
	  $check_roster=mysqli_fetch_array(mysqli_query($con,"select * from roster_master where TNA_Name='".$_REQUEST['servicetna']."' and  Duty_Hour_Start_Time='".$select_date."' and Active='0' and Offday='0'"));
		if($check_roster['TNA_Name']!=$_REQUEST['servicetna'])
		{
	   $Roster="insert into  roster_master(Duty_Hour_Start_Time,Number_Of_Working_Hour,TNA_Name,Patient_Id,Treatment_Service_Date,To_Time_Date,To_Time,night_shift,Service_Type,Control_Location)values('".$select_date."','".$_REQUEST['dutyto']."','".$_REQUEST['servicetna']."','".$_REQUEST['patient2']."','".$_REQUEST['date']."','".$end_date."','".date('H:i:s',strtotime($_REQUEST['hour_d']))."','".$night."','".$allocation_master['Care_Type']."','".$patient_master['Control_Location']."')";
	  $Roster_query=mysqli_query($con,$Roster);
		
	  
	  for($i=1; $i<=$numofday; $i++)
	  {
	  $service_date=date('Y-m-d',strtotime($_REQUEST['date'].' +'.$i.'day'));
	  $end_service_date=date('Y-m-d',strtotime($end_date.' +'.$i.'day'));
			
	  $sql="insert into  roster_master(Duty_Hour_Start_Time,Number_Of_Working_Hour,TNA_Name,Patient_Id,Treatment_Service_Date,To_Time_Date,To_Time,Service_Type,Control_Location)values('".$select_date."','".$_REQUEST['dutyto']."','".$_REQUEST['servicetna']."','".$_REQUEST['patient2']."','".$service_date."','".$end_service_date."','".date('H:i:s',strtotime($_REQUEST['hour_d']))."','".$allocation_master['Care_Type']."','".$patient_master['Control_Location']."')";
	  $update_lead_query=mysqli_query($con,$sql);
	  }
	  if($night==1)
	  {
	  ?>
	  <script>
	  alert ('Please select start time before 7:30pm');
	  /*Please select start time before 7:30pm*/
	  </script>
	  <?php
  $msg=1;
	}	
		}						  
									else
									{
										?>
										<script>
										alert ("Roster already created");
										</script>
										<?php
									}
  }							 
	 ?>                                         
                                              
                                
<body>

    
    <?php //include("left-menu.php"); ?>
    
    
    
    <!-- End Left menu area -->
    <!-- Start Welcome area -->
    <div class="all-content-wrapper">
        
        
       <?php //include("header-menu.php"); ?> 
        
       
                                        	
        <!-- Static Table Start -->
        <div class="static-table-area">
        
       
        
        
        
            <div class="container-fluid">
                <div class="row">
                <?php 
				$name="select * from patient_master where Patient_Id='".$_REQUEST['pid']."'";
				$name_query=mysqli_query($con,$name);
				$name_fetch=mysqli_fetch_array($name_query);
                ?>    
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" >
                        <div class="sparkline9-list analysis-progrebar-ctn" style="background-color:#FFFFFF">
                            <div class="sparkline9-hd">
                                <div class="main-sparkline9-hd">
                                    <h1 style="margin-bottom:15px">Roster Plan for <?php echo $name_fetch['Patient_Name']; ?> on <?php echo date('d-M-y',strtotime($_REQUEST['d'])); ?></h1>
                                   
                                    
                                    
                                       <div class="row" style="padding:0; background-color:#FFFFFF; ">

                                  <form method="post" action="" id="edit_lead"  >
                                      <!--<input id="hidden_call_box" name="call_status" value="" style="width:100%" type="hidden">-->
                                         <input type="hidden" id="from_date" value="<?php echo $_REQUEST['d']; ?>"/>   
                                        <div class="col-sm-12" id="call_later_div" style="padding:25px 0px;">
                                   
                                        <div class="form-group col-xs-3"><label>From Duty Time Start</label>
                                            <select id="DutyHour" name="DutyHour" class="form-control" style="width:100%;" onChange="time_alert()" required>
                                            
                                            <option value="">Select Duty Hour From</option>
                                            <?php
											$SqlAssLoc="select * from  roster_time_master";
											$RsAssLoc=mysqli_query($con,$SqlAssLoc);
											if(mysqli_num_rows($RsAssLoc)>0)
											{
											while($RowLoc=mysqli_fetch_array($RsAssLoc))
												{
											?>
                                            <option value="<?php echo $RowLoc['Start']; ?>"><?php echo date('h.i a',strtotime($RowLoc['Start'])); ?></option>
                                            <?php
												}
											}
											?>
                                           
                                            
                                            
                                            </select>
                                                   </div>
												   
												   
											<div class="form-group col-xs-3">
                                            <label>Number Of Working Hours</label>
                                            <select id="dutyto" name="dutyto" class="form-control" style=" width:100%;" onChange="get_time()" required>
                                            
                                            <option value="">Select Duty Hour</option>
                                            <?php
											$SqlAssLoc="select * from  roster_hours";
											$RsAssLoc=mysqli_query($con,$SqlAssLoc);
											if(mysqli_num_rows($RsAssLoc)>0)
											{
											while($RowLoc=mysqli_fetch_array($RsAssLoc))
												{
											?>
                                            <option value="<?php echo $RowLoc['Hours']; ?>"><?php echo $RowLoc['Hours']; ?></option>
                                            <?php
												}
											}
											?>
                                           
                                            
                                            
                                            </select>
                                                   </div>	
                                                 <div class="form-group col-xs-3" id="hour1" style="display:none;"><label>Work End Time</label> 
                                     <input type="text"class="form-control"  id="hour_d" name="hour_d"  readonly>
												   </div>
                                                   
                                        <div class="form-group col-xs-3"><label>TNA Name</label>
                                            <!--<input name="service" type="text" class="form-control" id="service" placeholder="Service Name" autocomplete="off" value="<?php echo $lead_details['Course_Name']; ?>" >-->
                                          
											
											<select name="servicetna" class="form-control" id="servicetna"  required>
                                            
                                               <option value="">Select TNA</option>
                                             <?php
											   if($user_type['Location']!='0')
											   {
											   $Sql_tna="select * from employee_master where Status='Active' and Office_Location_City='".$cityname['Location_Name']."' and (Designation='TNA' or Designation='Junior Nurse' or Designation='Senior Nursing Attendant' or Designation='Physiotherapist') order by First_Name";
											   }
											   else
											   {
												 $Sql_tna="select * from employee_master where Status='Active' and (Designation='TNA' or Designation='Junior Nurse' or Designation='Senior Nursing Attendant' or Designation='Physiotherapist') order by First_Name";  
											   }
                                               $Sql_tna_query= mysqli_query($con,$Sql_tna);
											   if(mysqli_num_rows($Sql_tna_query)>0)
											   {
                                               while($Rowtna=mysqli_fetch_array($Sql_tna_query))
											   		{
											
													$check_tna=mysqli_fetch_array(mysqli_query($con,"Select sum(Number_Of_Working_Hour) as wh from roster_master where TNA_Name='".$Rowtna['SLN']."' and Treatment_Service_Date='".date('Y-m-d',strtotime("-1 days", strtotime($_REQUEST['d'])))."'"));
													
													
											 ?>
                                              <option <?php if($check_tna['wh']>12 ){ ?> style="color:#FF0000;" <?php } ?> value="<?php echo $Rowtna['SLN']; ?>"><?php echo $Rowtna['First_Name']." ".$Rowtna['Last_Name']; ?></option>
                                                <?php

													}
												}
												$outsource_master=mysqli_query($con,"select * from outsource_master where Active='Yes'");
							while($outemployee=mysqli_fetch_array($outsource_master))
							{
								?>
								<option <?php if($check_tna['wh']>12 ){ ?> style="color:#FF0000;" <?php }else{?>style="color:blue;"<?php } ?> value="<?php echo $outemployee['Temp_Emp_Id']; ?>"><?php echo $outemployee['Oursource_Emp']; ?></option>
								<?php
							}
												?>
                                             </select>
										
											
                                                   </div>
									<div class="col-xs-12" style="padding:0px;">
                                      <div class="form-group col-xs-3" style="padding-top:15px;"> 
                                       <label><input type="checkbox" name="check_day" id="check_day" onClick="select_day()"/> Do you want to repeat this schedule next some days</label>
                                      </div>
                                      
                                       <div class="form-group col-xs-3"> 
                                      <!-- <label>Select Days </label>-->
                                       <select name="countday" class="form-control" id="countday" style="display:none;">
                                            
                                               <option value="">Select Days</option>
                                             <?php
											   
											   $Sql_tna1="select * from roster_hours";
                                               $Sql_tna_query1= mysqli_query($con,$Sql_tna1);
                                               while($Rowtna1=mysqli_fetch_array($Sql_tna_query1))
											   		{
											 ?>
                                              <option value="<?php echo $Rowtna1['Hours']; ?>"><?php echo $Rowtna1['Hours']; ?></option>
                                                <?php
												}
												?>
                                             </select>
                                      </div>
                                    </div>    
                                        <?php
                                        
										?>
                                         
												   
                                           <!-- <input name="patient" type="text" class="form-control" id="patient" placeholder="Patient Name" autocomplete="off" value="<?php echo $name_fetch['Patient_Name']; ?>" readonly>-->
											<input name="patient2" type="hidden" class="form-control" id="patient2" placeholder="Patient Name" autocomplete="off" value="<?php echo $name_fetch['Patient_Id']; ?>" readonly>
                                            <input name="date" type="hidden" class="form-control" id="date" placeholder="Patient Name" autocomplete="off" value="<?php echo $_REQUEST['d'];; ?>" readonly>

																			
											
											
											 
                                          </div>
								
                                             </select></td>
								  
								   <input type="button" class="btn btn-custon-rounded-three btn-primary" name="update_status" value="ADD" style="margin-left:20px;" onClick="validation123()">
								   
								   
								   </td>
								   			   
								   	</tr>
								   
								   
								   
								   </table>
								   
                                        </form>
								
                                       
                                       
                                        
                                          
                                         
                                       <?php
									   if($msg==1){
									   ?>
                                      <script>
									  alert('Plan Added Successfully');
									  window.location.href='view-patient-roster-plan.php?d=<?php echo $_REQUEST['d']; ?>&pid=<?php echo $_REQUEST['pid']; ?>';
									  </script>
									  <?php 
									  }
                                       ?>
                                         
                                           
                                </div>
                            </div>
                             
                         </div>
                         
                    </div> 
                     
                    	
                                         
                        </div>
                    </div>
                </div>
                
                
            </div>
        </div>
        <!-- Static Table End -->
        <!-- <div class="footer-copyright-area">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="footer-copy-right">
                           <p>Copyright © 2019. All rights reserved. </p>
                           
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

     <!-- jquery
		============================================ -->
     
       <script src="js/vendor/jquery-1.12.4.min.js"></script>
    <!-- bootstrap JS
		============================================ -->
    <script src="js/bootstrap.min.js"></script>
    <!-- wow JS
		============================================ -->
    <script src="js/wow.min.js"></script>
    <!-- price-slider JS
		============================================ -->
    <script src="js/jquery-price-slider.js"></script>
    <!-- meanmenu JS
		============================================ -->
    <script src="js/jquery.meanmenu.js"></script>
    <!-- owl.carousel JS
		============================================ -->
    <script src="js/owl.carousel.min.js"></script>
    <!-- sticky JS
		============================================ -->
    <script src="js/jquery.sticky.js"></script>
    <!-- scrollUp JS
		============================================ -->
    <script src="js/jquery.scrollUp.min.js"></script>
    
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>

     
    
     <!--  editable JS
		============================================ -->
    <script src="js/editable/jquery.mockjax.js"></script>
    <script src="js/editable/mock-active.js"></script>
    <script src="js/editable/select2.js"></script>
    <script src="js/editable/moment.min.js"></script>
    <script src="js/editable/bootstrap-datetimepicker.js"></script>
    <script src="js/editable/bootstrap-editable.js"></script>
    <script src="js/editable/xediable-active.js"></script>
 <!-- datepicker JS
		============================================ -->
    <script src="js/datepicker/jquery-ui.min.js"></script>
    <script src="js/datepicker/datepicker-active.js"></script>
    
    <!-- mCustomScrollbar JS
		============================================ -->
    <script src="js/scrollbar/jquery.mCustomScrollbar.concat.min.js"></script>
    <script src="js/scrollbar/mCustomScrollbar-active.js"></script>
    <!-- metisMenu JS
		============================================ -->
    <script src="js/metisMenu/metisMenu.min.js"></script>
    <script src="js/metisMenu/metisMenu-active.js"></script>
    <!-- peity JS
		============================================ -->
    <script src="js/peity/jquery.peity.min.js"></script>
    <script src="js/peity/peity-active.js"></script>
    <!-- sparkline JS
		============================================ -->
    <script src="js/sparkline/jquery.sparkline.min.js"></script>
    <script src="js/sparkline/sparkline-active.js"></script>
    <!-- tab JS
		============================================ -->
    <script src="js/tab.js"></script>
    <!-- plugins JS
		============================================ -->
    <script src="js/plugins.js"></script>
    <!-- main JS
		============================================ -->
    <script src="js/main.js"></script>
    <!-- tawk chat JS
		============================================ -->
    <script src="js/tawk-chat.js"></script>
   <!-- form validate JS
		============================================ -->
    <script src="js/form-validation/jquery.form.min.js"></script>
    <script src="js/form-validation/jquery.validate.min.js"></script>
    <script src="js/form-validation/form-active.js"></script>
    
    <script>
$(document).ready(function() {
   $("body").tooltip({ 
   	selector: '[data-toggle=tooltip]' 
	 });
});
 
</script> 
  
               
                                               <script>
 
$('button.call_btn_1').click(function() {
    //var text = $(this).text();
	var text = $(this).data('value_santanu');
	//alert(text)
	$('#hidden_call_box').val(text);
	$('#response').val(text);
    // do something with the text
});
												</script> 
                                                
                                                
                                                
                                                
       <!-- bootstrap-clockpicker -->
      <link rel="stylesheet" type="text/css" href="css/bootstrap-clockpicker.min.css">
    <script type="text/javascript" src="js/bootstrap-clockpicker.min.js"></script>


 <script type="text/javascript">
$('.clockpicker').clockpicker()
	.find('input').change(function(){
		console.log(this.value);
	});
var input = $('#single-input').clockpicker({
	placement: 'bottom',
	align: 'left',
	autoclose: true,
	'default': 'now'
});

$('.clockpicker-with-callbacks').clockpicker({
		donetext: 'Done',
		init: function() { 
			console.log("colorpicker initiated");

		},
		beforeShow: function() {
			console.log("before show");
		},
		afterShow: function() {
			console.log("after show");
		},
		beforeHide: function() {
			console.log("before hide");
		},
		afterHide: function() {
			console.log("after hide");
		},
		beforeHourSelect: function() {
			console.log("before hour selected");
		},
		afterHourSelect: function() {
			console.log("after hour selected");
		},
		beforeDone: function() {
			console.log("before done");
		},
		afterDone: function() {
			console.log("after done");
		}
	})
	.find('input').change(function(){
		console.log(this.value);
	});

// Manually toggle to the minutes view
$('#check-minutes').click(function(e){
	// Have to stop propagation here
	e.stopPropagation();
	input.clockpicker('show')
			.clockpicker('toggleView', 'minutes');
});
if (/mobile/i.test(navigator.userAgent)) {
	$('input').prop('readOnly', true);
}
</script>                                          
                                                
                                                
 <script type="text/javascript">
$("#edit_lead").validate({
          
      showErrors: function(errorMap, errorList) {
          // Clean up any tooltips for valid elements
          $.each(this.validElements(), function (index, element) {
              var $element = $(element);
              $element.data("title", "") // Clear the title - there is no error associated anymore
                  .removeClass("error")
                  .tooltip("destroy");
          });
          // Create new tooltips for invalid elements
          $.each(errorList, function (index, error) {
              var $element = $(error.element);

              $element.tooltip("destroy") // Destroy any pre-existing tooltip so we can repopulate with new tooltip content
                  .data("title", error.message)
                  .addClass("error")
                  .tooltip(); // Create a new tooltip based on the error messsage we just set in the title
          });
      },

     
	  
});
</script>                                               
                                                
    
</body>

</html>