<?php $employeeid=$this->session->userdata('employeeId');?>
<div class="page-content" style="<?php if($employeeid =='1234'){ echo'display:block'; } else {echo'display:none';} ?>">   
<div class="row">
    <div class="col-sm-12 col-md-6">
        <div class="table-header" style="height:30px;">
                            <h3 style="text-align:center;">Employee Task List
                                
                            </h3>
                        </div>
                        <iframe src="https://ccare.hasanhomesltd.com/alltasks/index.php" style="width:100%; height: 650px; overflow:hidden; border:none;"></iframe><br>
                    <!--<div class="float-right"><a href="javascript:void(0);" class="btn btn-primary" data-toggle="modal" data-target="#addEmpModal"><span class="fa fa-plus"></span> Add New</a></div>-->
<?php $useridprint=$this->session->userdata('employeeId'); ?>
        <?php $dt = new DateTime();
                $tz = new DateTimeZone('Asia/Dhaka'); 
                $dt->setTimezone($tz);
                $timenow= $dt->format('Y-m-d');
                ?>

<!--                 <div style="overflow:scroll; height: 410px;">       -->
<!--                <table class="table table-striped" id="employeeListing" >-->
<!--                    <thead>-->
<!--                        <tr>-->
<!--                            <th>Id</th>-->
<!--    						<th>Details</th>-->
<!--    						<th>Created</th>-->
<!--                            <th>Actions</th>-->
<!--                        </tr>-->
<!--                    </thead>-->
<!--                    <tbody id="listRecords">                    -->
<!--                    </tbody>-->
<!--                </table>-->
<!--                </div>-->
<!--            <br>-->
<!--<form id="saveEmpForm" method="post">-->
	<!--<div class="modal fade" id="addEmpModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">-->
	<!--  <div class="modal-dialog modal-lg" role="document">-->
	<!--	<div class="modal-content">-->
	<!--	  <div class="modal-header">-->
	<!--		<h5 class="modal-title" id="exampleModalLabel">Add New Task</h5>-->
	<!--		<button type="button" class="close" data-dismiss="modal" aria-label="Close">-->
	<!--		  <span aria-hidden="true">&times;</span>-->
	<!--		</button>-->
	<!--	  </div>-->
	<!--	  <div class="modal-body">-->
<!--				<div class="form-group row">-->
<!--					<label class="col-md-2 col-form-label">Details</label>-->
<!--					<div class="col-md-10">-->
<!--					    <input type="hidden" name="employee_id" id="employee_id" value="<?php echo $useridprint; ?>" class="form-control">-->
<!--					  <textarea name="details" id="details" class="form-control" rows="2" required></textarea>-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="form-group row">-->
<!--					<label class="col-md-2 col-form-label">Date</label>-->
<!--					<div class="col-md-10">-->
<!--					  <input type="hidden" name="priority" id="priority" value="first" />-->
<!--					  <input type="date" name="created_at" id="created_at" value="<?php echo $timenow; ?>" class="form-control" required>-->
<!--					</div>-->
<!--				</div>-->
		  <!--</div>-->
		  <!--<div class="modal-footer">-->
			<!--<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>-->
<!--			<div class="form-group row"><div class="col-md-2"></div><div class="col-md-4">-->
<!--			<button type="submit" class="btn btn-primary btn-sm">Add Task</button>-->
<!--			</div>-->
<!--			</div>-->
	<!--	  </div>-->
	<!--	</div>-->
	<!--  </div>-->
	<!--</div>-->
<!--</form>-->
            </div>
        
        

<!--<form id="saveEmpForm" method="post">-->
<!--	<div class="modal fade" id="addEmpModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">-->
<!--	  <div class="modal-dialog modal-lg" role="document">-->
<!--		<div class="modal-content">-->
<!--		  <div class="modal-header">-->
<!--			<h5 class="modal-title" id="exampleModalLabel">Add New Task</h5>-->
<!--			<button type="button" class="close" data-dismiss="modal" aria-label="Close">-->
<!--			  <span aria-hidden="true">&times;</span>-->
<!--			</button>-->
<!--		  </div>-->
<!--		  <div class="modal-body">-->
<!--				<div class="form-group row">-->
<!--					<label class="col-md-2 col-form-label">Details</label>-->
<!--					<div class="col-md-10">-->
<!--					    <input type="hidden" name="employee_id" id="employee_id" value="<?php echo $useridprint; ?>" class="form-control">-->
<!--					  <textarea name="details" id="details" class="form-control" rows="3" required></textarea>-->
<!--					</div>-->
<!--				</div>-->
<!--				<div class="form-group row">-->
<!--					<label class="col-md-2 col-form-label">Date</label>-->
<!--					<div class="col-md-10">-->
<!--					  <input type="hidden" name="priority" id="priority" value="first" />-->
<!--					  <input type="date" name="created_at" id="created_at" value="<?php echo $timenow; ?>" class="form-control" required>-->
<!--					</div>-->
<!--				</div>-->
<!--		  </div>-->
<!--		  <div class="modal-footer">-->
<!--			<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>-->
<!--			<button type="submit" class="btn btn-primary">Save</button>-->
<!--		  </div>-->
<!--		</div>-->
<!--	  </div>-->
<!--	</div>-->
<!--</form>-->
<form id="editEmpForm" method="post">
	<div class="modal fade" id="editEmpModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
	  <div class="modal-dialog modal-lg" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<h5 class="modal-title" id="editModalLabel">Edit Task</h5>
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
		  </div>
		  <div class="modal-body">
				<div class="form-group row">
					<label class="col-md-2 col-form-label">Details</label>
					<div class="col-md-10">
					    <textarea name="Details" id="Details" class="form-control" rows="3" required></textarea>
					</div>
				</div>
				<div class="form-group row">
					<label class="col-md-2 col-form-label">Date</label>
					<div class="col-md-10">
					  <input type="date" name="CreatedAt" id="CreatedAt" class="form-control"  required>
					</div>
				</div>
		  </div>
		  <div class="modal-footer">
			 <input type="hidden" name="TaskId" id="TaskId" class="form-control">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
			<button type="submit" class="btn btn-primary">Update</button>
		  </div>
		</div>
	  </div>
	</div>
</form>
<form id="doneTaskForm" method="post">
	<div class="modal fade" id="DoneTaskModal" tabindex="-1" role="dialog" aria-labelledby="doneModalLebel" aria-hidden="true">
	  <div class="modal-dialog" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<h5 class="modal-title" id="doneModalLebel">Done task</h5>
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
		  </div>
		  <div class="modal-body">
		      <strong>Are you sure want to mark as done?</strong>
		  </div>
		  <div class="modal-footer">
			<input type="hidden" name="doneTaskId" id="doneTaskId" class="form-control">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
			<button type="submit" class="btn btn-primary">Yes</button>
		  </div>
		</div>
	  </div>
	</div>
</form>

<form id="deleteEmpForm" method="post">
	<div class="modal fade" id="deleteEmpModal" tabindex="-1" role="dialog" aria-labelledby="deleteModalLabel" aria-hidden="true">
	  <div class="modal-dialog" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<h5 class="modal-title" id="deleteModalLabel">Delete task</h5>
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
		  </div>
		  <div class="modal-body">
			   <strong>Are you sure to delete this record?</strong>
		  </div>
		  <div class="modal-footer">
			<input type="hidden" name="deleteEmpId" id="deleteEmpId" class="form-control">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
			<button type="submit" class="btn btn-primary">Yes</button>
		  </div>
		</div>
	  </div>
	</div>
</form>

<form id="deleteDoneForm" method="post">
	<div class="modal fade" id="deleteDoneModal" tabindex="-1" role="dialog" aria-labelledby="deleteDoneLabel" aria-hidden="true">
	  <div class="modal-dialog" role="document">
		<div class="modal-content">
		  <div class="modal-header">
			<h5 class="modal-title" id="deleteDoneLabel">Delete task</h5>
			<button type="button" class="close" data-dismiss="modal" aria-label="Close">
			  <span aria-hidden="true">&times;</span>
			</button>
		  </div>
		  <div class="modal-body">
			   <strong>Are you sure to delete this record?</strong>
		  </div>
		  <div class="modal-footer">
			<input type="hidden" name="deleteEmpId" id="deleteEmpId" class="form-control">
			<button type="button" class="btn btn-secondary" data-dismiss="modal">No</button>
			<button type="submit" class="btn btn-primary">Yes</button>
		  </div>
		</div>
	  </div>
	</div>
</form>
    <div class="col-sm-12 col-md-6">
        <div class="table-header" style="height:30px;">
                            <h3 style="text-align:center;">Done Task List
                                
                            </h3>
                        </div>
                        <iframe src="https://ccare.hasanhomesltd.com/alltasks/donetask.php" style="width:100%; height: 800px; overflow:hidden; border:none"></iframe><br>
      <!--  <div style="overflow:scroll; height: 610px;"> -->
      <!--      <table class="table table-striped" id="DoneTaskstable">-->
      <!--          <thead>-->
      <!--              <tr>-->
      <!--                  <th>Id</th>-->
						<!--<th>Details</th>-->
						<!--<th>Done</th>-->
      <!--                  <th >Actions</th>-->
      <!--              </tr>-->
      <!--          </thead>-->
      <!--          <tbody id="listDone">                    -->
      <!--          </tbody>-->
      <!--      </table>-->
      <!--  </div>-->
            </div>
            
            
</div>
    </div>
    
    <script>  
$(document).ready(function(){  
 
function listEmployee(){
		$.ajax({
			type  : 'ajax',
			url   : 'https://ccare.hasanhomesltd.com/admin/home/show',
			async : false,
			dataType : 'json',
			success : function(data){
				var html = '';
				var i;
				for(i=0; i<data.length; i++){
					html += '<tr id="'+data[i].id+'">'+
							'<td>'+data[i].id+'</td>'+
							'<td>'+data[i].details+'</td>'+
							'<td>'+data[i].created_at+'</td>'+
							'<td>'+
								'<a href="javascript:void(0);" class="badge badge-info btn-sm editRecord" data-id="'+data[i].id+'" data-details="'+data[i].details+'" data-created_at="'+data[i].created_at+'"><i class="fa fa-edit"></i></a>'+' '+
								'<a href="javascript:void(0);" class="badge badge-success btn-sm doneRecord" data-id="'+data[i].id+'"><i class="fa fa-check"></i></a>'+' '+
								'<a href="javascript:void(0);" class="badge badge-danger btn-sm deleteRecord" data-id="'+data[i].id+'"><i class="fa fa-trash"></i></a>'+
							'</td>'+
							'</tr>';
				}
				$('#listRecords').html(html);					
			}

		});
	}
	
	
	
	function doneTask(){
		$.ajax({
			type  : 'ajax',
			url   : 'https://ccare.hasanhomesltd.com/admin/home/donelist',
			async : false,
			dataType : 'json',
			success : function(data){
				var html = '';
				var i;
				for(i=0; i<data.length; i++){
					html += '<tr id="'+data[i].id+'">'+
							'<td>'+data[i].id+'</td>'+
							'<td>'+data[i].details+'</td>'+
							'<td>'+data[i].started_at+'</td>'+
							'<td>'+
								
								'<a href="javascript:void(0);" class="badge badge-danger btn-sm deleteDoneRecord" data-id="'+data[i].id+'"><i class="fa fa-trash"></i></a>'+
							'</td>'+
							'</tr>';
				}
				$('#listDone').html(html);					
			}

		});
	}
	
	
	
	
	load_data();
    
	function load_data()
	{
		$.ajax({
			url:"https://ccare.hasanhomesltd.com/admin/home/show",
			method:"POST",
			success:function(data)
			{
				$('#user_data').html(data);
			}
		});
	}
	
	$("#user_dialog").dialog({
		autoOpen:false,
		width:400
	});
	
	$('#add').click(function(){
		$('#user_dialog').attr('title', 'Add Data');
		$('#action').val('insert');
		$('#form_action').val('Insert');
		$('#user_form')[0].reset();
		$('#form_action').attr('disabled', false);
		$("#user_dialog").dialog('open');
	});
	
	$('#user_form').on('submit', function(event){
		event.preventDefault();
		var error_details = '';
		var error_priority = '';
		if($('#details').val() == '')
		{
			error_details = 'First Name is required';
			$('#error_details').text(error_details);
			$('#details').css('border-color', '#cc0000');
		}
		else
		{
			error_details = '';
			$('#error_details').text(error_details);
			$('#details').css('border-color', '');
		}
		if($('#priority').val() == '')
		{
			error_priority = 'Last Name is required';
			$('#error_priority').text(error_priority);
			$('#priority').css('border-color', '#cc0000');
		}
		else
		{
			error_priority = '';
			$('#error_priority').text(error_priority);
			$('#priority').css('border-color', '');
		}
		
		if(error_details != '' || error_priority != '')
		{
			return false;
		}
		else
		{
			$('#form_action').attr('disabled', 'disabled');
			var form_data = $(this).serialize();
			$.ajax({
				url:"action.php",
				method:"POST",
				data:form_data,
				success:function(data)
				{
					//$('#user_dialog').dialog('close');
					//$('#action_alert').html(data);
					//$('#action_alert').dialog('open');
                    $('#user_form')[0].reset();

					load_data();
					$('#form_action').attr('disabled', false);
				}
			});
		}
		
	});

	$('#action_alert').dialog({
		autoOpen:false
	});
		$(document).on('click', '.edit', function(){
		var id = $(this).attr('id');
		var action = 'fetch_single';
		$.ajax({
			url:"action.php",
			method:"POST",
			data:{id:id, action:action},
			dataType:"json",
			success:function(data)
			{
				$('#employee_id').val(data.employee_id);
				$('#employee').val(data.employee);
				$('#details').val(data.details);
				$('#priority').val(data.priority);
				$('#created_at').val(data.created_at);
				$('#user_dialog').attr('title', 'Edit Data');
				$('#action').val('update');
				$('#hidden_id').val(id);
				$('#form_action').val('Update');
				$('#user_dialog').dialog('open');
			}
		});
	});
	
	$('#action_alert').dialog({
		autoOpen:false
	});
		$(document).on('click', '.after_submit', function(){
		var id = $(this).attr('id');
		var action = 'fetch_single';
		$.ajax({
			url:"action.php",
			method:"POST",
			data:{id:id, action:action},
			dataType:"json",
			success:function(data)
			{
				$('#user_dialog').attr('title', 'Add Data');
        		$('#action').val('insert');
        		$('#form_action').val('Insert');
        		$('#user_form')[0].reset();
        		$('#form_action').attr('disabled', false);
        		$("#user_dialog").dialog('open');
			}
		});
	});
	
// 	$('#form_action').click(function(){
// 		//$('#user_dialog').attr('title', 'Add Data');
// 		$('#action').val('insert');
// 		$('#form_action').val('Insert');
// 		$('#user_form')[0].reset();
// 		$('#form_action').attr('disabled', false);
// 		//$("#user_dialog").dialog('open');
// 	});
	
	function form_reset() {
                $('#action').val('insert');
		        $('#form_action').val('Insert');
		        $('#user_form')[0].reset();
		        $('#form_action').attr('disabled', false);
            }
	
	$('#action_alert').dialog({
		autoOpen:false
	});
		$(document).on('click', '.edit', function(){
		var id = $(this).attr('id');
		var action = 'fetch_single';
		$.ajax({
			url:"action.php",
			method:"POST",
			data:{id:id, action:action},
			dataType:"json",
			success:function(data)
			{
				$('#employee_id').val(data.employee_id);
				$('#employee').val(data.employee);
				$('#details').val(data.details);
				$('#priority').val(data.priority);
				$('#user_dialog').attr('title', 'Edit Data');
				$('#action').val('update');
				$('#hidden_id').val(id);
				$('#form_action').val('Update');
				$('#user_dialog').dialog('open');
			}
		});
	});
	

	$('#start_confirmation').dialog({
		autoOpen:false,
		modal: true,
		buttons:{
			Ok : function(){
				var id = $(this).data('id');
				var action = 'started';
				$.ajax({
					url:"action.php",
					method:"POST",
					data:{id:id, action:action},
					success:function(data)
					{
						$('#start_confirmation').dialog('close');
						$('#action_alert').html(data);
						$('#action_alert').dialog('open');
						load_data();
					}
				});
			},
			Cancel : function(){
				$(this).dialog('close');
			}
		}	
	});
	$(document).on('click', '.start', function(){
		var id = $(this).attr("id");
		$('#start_confirmation').data('id', id).dialog('open');
	});

	$('#stop_confirmation').dialog({
		autoOpen:false,
		modal: true,
		buttons:{
			Ok : function(){
				var id = $(this).data('id');
				var action = 'stopped';
				$.ajax({
					url:"action.php",
					method:"POST",
					data:{id:id, action:action},
					success:function(data)
					{
						//$('#stop_confirmation').dialog('close');
						//$('#action_alert').html(data);
						//$('#action_alert').dialog('open');
						    $('#stop_confirmation').dialog('close');
						load_data();
					}
				});
			},
			Cancel : function(){
				$(this).dialog('close');
			}
		}	
	});
	$(document).on('click', '.stop', function(){
		var id = $(this).attr("id");
		$('#stop_confirmation').data('id', id).dialog('open');
	});
	
	$('#delete_confirmation').dialog({
		autoOpen:false,
		modal: true,
		buttons:{
			Ok : function(){
				var id = $(this).data('id');
				var action = 'delete';
				$.ajax({
					url:"action.php",
					method:"POST",
					data:{id:id, action:action},
					success:function(data)
					{
						//$('#delete_confirmation').dialog('close');
						//$('#action_alert').html(data);
						//$('#action_alert').dialog('open');
						$('#delete_confirmation').dialog('close');
						load_data();
					}
				});
			},
			Cancel : function(){
				$(this).dialog('close');
			}
		}	
	});
	
	$(document).on('click', '.delete', function(){
		var id = $(this).attr("id");
		$('#delete_confirmation').data('id', id).dialog('open');
	});
	
});  
</script>
<script type="text/javascript" src="https://ccare.hasanhomesltd.com/assets/ajaxcrud/js/jquery-3.2.1.js"></script>
<script type="text/javascript" src="https://ccare.hasanhomesltd.com/assets/ajaxcrud/js/bootstrap.js"></script>
<script type="text/javascript" src="https://ccare.hasanhomesltd.com/assets/ajaxcrud/js/jquery.dataTables.js"></script>
<script type="text/javascript" src="https://ccare.hasanhomesltd.com/assets/ajaxcrud/js/dataTables.bootstrap4.js"></script>
<script type="text/javascript" src="https://ccare.hasanhomesltd.com/assets/ajaxcrud/task_crud.js"></script>
