<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<? global $vis_language; 
	$overdue_day=floor($task_details['startdate']/1440);
	$remaining_minutes=$task_details['startdate']%1440;
	$overdue_hr = floor($remaining_minutes/60);
	$overdue_min = $remaining_minutes%60;

	$resolution_day = floor($task_details['enddate']/1440);
	$remaining_minutes=$task_details['enddate']%1440;
	$resolution_hr = floor($remaining_minutes/60);
	$resolution_min = $remaining_minutes%60;?>
<div class="modal-dialog modal-lg">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">   <?php echo $vis_language['TXTUPDATETASK']; ?></h4>
        </div>
        <div class="modal-body">
            <div class="row">
			 <form name="vis_ticket_task_update_form" id="vis_ticket_task_update_form" class="form-horizontal" method="post">
            <section class="no-borders no-gutter no-radius">
               <div class="panel-body">				
                  <div class="wrapper">
                     <div class="form-group">
                        <label for="taskTitle"><? echo $vis_language['TXTTASKTITLE']; ?></label>
                        <input type="text" class="form-control" id="vis_task_title" name="vis_task_title" placeholder="<? echo $vis_language['TXTENTERTASKTITLE']; ?>" value="<?php echo $task_details['task_title']; ?>" >
                     </div>
                     <div class="form-group">
                        <label for="taskDescription"><? echo $vis_language['TXTDESCRIPTION'];?></label>
                        <textarea class="form-control" rows="2" data-minwords="6" id="vis_task_description" name="vis_task_description" placeholder="<?= $vis_language['TXTADDTASKDESCRIPTION']?>" ><?php echo $task_details['description']; ?></textarea>
                     </div>
                     <div class="row">
                        <div class="wrapper">
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskPriority"><? echo $vis_language['TXTPRIORITY'];?></label>
                                 <select class="form-control input-sm selectpicker" id="vis_task_priority" name="vis_task_priority">
                                    <option value="1" <? echo ($task_details['priority']==1)?' selected="selected"':''; ?> ><? echo $vis_language['TXTLOW'];?></option>
                                    <option value="2" <? echo ($task_details['priority']==2)?' selected="selected"':''; ?>><? echo $vis_language['TXTMEDIUM'];?></option>
                                    <option value="3" <? echo ($task_details['priority']==3)?' selected="selected"':''; ?> ><? echo $vis_language['TXTHIGH'];?></option>
                                 </select>
                              </div>
                           </div>
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskStartdate"><? echo $vis_language['TXTDUETIME'];?></label>
                               <span class="input-group-addon no-padder no-borders start">  
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Days" type="text" name="vis_overdueday" id="vis_overdueday" value="<?php echo $overdue_day;?>">
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Hourss" type="text" name="vis_overduehr" id="vis_overduehr" value="<?php echo $overdue_hr;?>">
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Minutes" type="text" name="vis_overduemin" id="vis_overduemin" value="<?php echo $overdue_min;?>" >
								</div>
							   </span>
                              </div>
                           </div>
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskEnddate"><? echo $vis_language['TXTRESOLUTIONTIME'];?></label>
                                 <span class="input-group-addon no-padder no-borders start">  
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Days" type="text" name="vis_resolutionday" id="vis_resolutionday" value="<?php echo $resolution_day;?>" >
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Hours" type="text" name="vis_resolutionhr" id="vis_resolutionhr" value="<?php echo $resolution_hr;?>" >
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Minutes" type="text" name="vis_resolutionmin" id="vis_resolutionmin" value="<?php echo $resolution_min;?>" >
								</div>
							   </span>
                              </div>
                           </div>
                        </div>
                     </div>
					<div class="row">
                        <div class="wrapper">
                           <div class="form-group">
                              <label for="taskTitle"><? echo $vis_language['TXTASSIGNTO']; ?></label>
                              <input type="text" class="form-control" id="vis_assignto" name="vis_assignto" placeholder="<? echo $vis_language['TXTSEARCHSTAFF'];?>" data-resize="no">
                              <script type="text/javascript">
                                 $(document).ready(function() {
                                 	$("#vis_assignto").tokenInput(
                                 		"index.php?vis_module=staff&vis_operation=staff_listing&vis_task_assign=1&vis_task_owner_id=<?= VIS_STAFF_ID; ?>",
                                 		{
                                 			theme: "facebook",
                                 			searchDelay: 300,
                                 			minChars: 1,
                                 			queryParam: "vis_data",
                                 			preventDuplicates: true,
                                 			propertyToSearch: "full_name",
                                 			tokenValue: "full_name",
                                 			searchingText: "<? echo $vis_language['MSGSEARCHING']."..."; ?>",
                                 			noResultsText: "<? echo $vis_language['TXTNOMATCHFOUND']; ?>",
                                 			resultsFormatter: function(item){
                                 			if(item.type=="heading"){
                                 				return "<b>" + "<div style='cursor:pointer;display: inline-block; padding-left: 10px;'><div class='full_name'>" + item.full_name + "</div></div></b>"
                                 			}
                                 			else{ return "<li>" + "<div style='display: inline-block; padding-left: 10px;margin-left:30px;'><div class='full_name'>" + item.full_name + "</div></div></li>"	} },
                                 			tokenFormatter: function(item) { if(item.id){$('#vis_task_grp_share').val($('#vis_task_grp_share').val()+item.id+',');}return "<li><p>" + item.full_name + "</p></li>" },
                                 			onDelete: function(item){
                                 if(item.id)
                                 {
                                 var staffs = $('#vis_task_grp_share').val();
                                 var old_staffs = $('#vis_old_staff').val();
                                 var Staffs1 = old_staffs.replace(item.id+',', '');
                                 $('#vis_old_staff').val(Staffs1);
                                 var newStaffs = staffs.replace(item.id+',', '');
                                 $('#vis_task_grp_share').val(newStaffs);

                                 }
                                 else
                                 {
                                 var staffs = $('#vis_task_share').val();
                                 var staffIds = $('#vis_staff').val();
                                 var newStaffs = staffs.replace(item.id+',', '');
                                 $('#vis_task_share').val(newStaffs);
                                 $('#vis_staff').val(newStaffs);
                                 }
                                 },
                                 onAdd: function(item)
                                 {
                                 if(item.type == "heading")
                                 {
                                 $("#vis_assignto").tokenInput("remove", {full_name: item.full_name});
                                 }
                                 }
                                 		}
                                 	);
                                 	<? if($assign_task_details!=-1) for($i=0 ; $i<count($assign_task_details); $i++){?>
                                 		$("#vis_assignto").tokenInput("add", {id: "<?= $assign_task_details[$i]['owner_id']; ?>", full_name: "<?= $assign_task_details[$i]['first_name']." ".$assign_task_details[$i]['last_name']; ?>"});<? } ?>
                                 });
                              </script>
                              <input type="hidden" id="vis_task_grp_share" name="vis_task_grp_share"/>
                              <input type="hidden" id="vis_task_share" name="vis_task_share"/>
                              <input type="hidden" id="vis_staff" name="vis_staff" value="<?php echo VIS_STAFF_ID; ?>"/>
                              <input type="hidden" id="vis_old_staff" name="vis_old_staff" value="<?echo $old_staff;?>"/>
                           </div>
                        </div>
                     </div>
                     <!----------------- Newly added div ---------------->
                     <?
					 if($custom_field_var!=''){
						 ?>
						 <div class="row">
							<div class="wrapper">
							   <div class="form-group">
								<? 	echo $custom_field_var;?>
                                <input type="hidden" name="vis_add_org" id="vis_add_org" value="1" />
                                <input type="hidden" id="vis_department" name="vis_department" value="<? echo $departmentid;?>"/>
							   </div>
							</div>
						 </div>
						 <?
					 }
                     ?>
                     <!-------------------------------------------------->
                  <div class="line line-dashed b-b line-lg pull-in"></div>        
                  <input type="hidden" id="vis_ticket_id" name="vis_ticket_id" value="<? echo $operation['vis_ticket_id'];?>" />  
				  <input type="hidden" id="auto_task_flag" name="auto_task_flag" value="<? echo $operation['auto_task_flag'];?>" />
				  <input type="hidden" id="autotask_id" name="autotask_id" value="<? echo $operation['autotask_id'];?>" />
				  <input type="hidden" id="page" name="page" value="<? echo $operation['page'];?>" />				  
                  <input type="hidden" id="vis_task_id" name="vis_task_id" value="<? echo $task_details['task_id'];?>" />  
                  <input type="hidden" id="vis_set_task_repeat" name="vis_set_task_repeat" value="0" />
                  <input type="hidden" id="vis_filter_id" name="vis_filter_id" value="<? echo $operation['filter_id'];?>"/>
               </div>
               </div>
               </div>
            </section>
         </form>
        </div>
        <div class="modal-footer">	
            <a class="btn btn-default" data-dismiss="modal"><? echo $vis_language['TXTCANCEL']; ?></a>	
            <!-- <a class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'home', 'vis_operation':'update_autosub_task', 'vis_form':'vis_ticket_task_update_form'});"><?  //  echo $vis_language['TXTUPDATE']; ?></a>    -->
 <a class="btn btn-primary" id="update_task_btn" onclick="submit_form(this.value)" >  <?  echo $vis_language['TXTUPDATE']; ?></a>  
        </div>
    </div>
</div>
<script>  
   
     
   $(".selectpicker").selectpicker();
   
   // set loading on button click event
   function submit_form(view_ticket) {    
        var btn = $("#update_task_btn");
        btn.button('loading');        
        var i=0;        
            $.ajax({
            url: 'index.php',
            data: {'vis_module':"home", 'vis_operation':"update_autosub_task", 'vis_task_title':$("#vis_task_title").val(), 'vis_task_description':$("#vis_task_description").val(), 'vis_task_priority':$("#vis_task_priority").val(), 'vis_task_start_date':$("#vis_task_start_date").val(), 'vis_task_end_date':$("#vis_task_end_date").val(),'vis_assignto':$("#vis_assignto").val(), 'vis_task_grp_share':$("#vis_task_grp_share").val(),  'vis_task_share':$("#vis_task_share").val(), 'vis_staff':$("#vis_staff").val(), 'vis_old_staff':$("#vis_old_staff").val(), 'vis_ticket_id':$("#vis_ticket_id").val(), 'auto_task_flag':$("#auto_task_flag").val(),'autotask_id':$("#autotask_id").val(), 'page':$("#page").val(),'autotask_id':$("#autotask_id").val(), 'vis_filter_id':$("#vis_filter_id").val(), 'vis_form':'vis_ticket_task_update_form',  'vis_task_id':$("#vis_task_id").val(),'vis_overdueday':$("#vis_overdueday").val(),'vis_overduehr':$("#vis_overduehr").val(),'vis_overduemin':$("#vis_overduemin").val(),'vis_resolutionday':$("#vis_resolutionday").val(),'vis_resolutionhr':$("#vis_resolutionhr").val(),'vis_resolutionmin':$("#vis_resolutionmin").val()},
            type: "POST",
            success: function(data) {
				        if(data=='error')
						{
							$("#vis_global_msg_div").visInterface("load_global_message", "<?php echo $vis_language['MSGERROPRT'] ?>");
							var btn = $("#update_task_btn"); 
							btn.button('reset');
						}
						else{
							$("#vis_global_msg_div").visInterface("load_global_message","<?php echo $vis_language['MSGSUCCOPRT'] ?>"); 
							$("#autosub_task_list").visExecution("load_area",{"vis_module":"setting", "vis_operation":"refresh_autosubtask_list","vis_autotask_id":$("#autotask_id").val()}); 
							$(".modal").modal("toggle"); 
						}
						
						}
        });    
}  
</script>
