<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<? global $vis_language;
   $schedule=array(0=>'Never', 1=>'Daily', 2=>'Weekly', 3=>'Monthly',4=>'Yearly');
   $status=array(1 => $vis_language['TXTINPROGRESS'],2 => $vis_language['TXTOVERDUE'],3 => $vis_language['TXTCOMPLETED'],4 => $vis_language['TXTCANCELED'],5 =>$vis_language['TXTNOTSTARTED']);
   ?>
<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['TXTADDTASK']; ?></h4>
        </div>
        <div class="modal-body">
            <div class="row">
			 <form name="vis_ticket_task_create_form" id="vis_ticket_task_create_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']; ?>" >
                     </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']?>" ></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 $vis_language['TXTLOW'];?></option>
                                    <option value="2" ><? echo $vis_language['TXTMEDIUM'];?></option>
                                    <option value="3" ><? echo $vis_language['TXTHIGH'];?></option>
                                 </select>
                              </div>
                           </div>
					<?php if(!isset($operation['auto_task_flag']))
					 { ?> 
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskStartdate"><? echo $vis_language['TXTSTARTDATE'];?></label>
                               <span class="input-group-addon no-padder no-borders start">  <input class="input-sm form-control" id="vis_task_start_date" name="vis_task_start_date" size="16" type="text" placeholder="DD-MM-YYYY" ></span>
                              </div>
                           </div>
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskEnddate"><? echo $vis_language['TXTENDDATE'];?></label>
                               <span class="input-group-addon no-padder no-borders start">  <input class="input-sm form-control" id="vis_task_end_date" name="vis_task_end_date" size="16" type="text" placeholder="DD-MM-YYYY" ></span>
                              </div>
                           </div>
					 <?php }  else { ?>
							<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">  
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Days" type="text" name="vis_overdueday" id="vis_overdueday">
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Hourss" type="text" name="vis_overduehr" id="vis_overduehr">
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Minutes" type="text" name="vis_overduemin" id="vis_overduemin" >
								</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">  
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Days" type="text" name="vis_resolutionday" id="vis_resolutionday" >
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Hours" type="text" name="vis_resolutionhr" id="vis_resolutionhr">
								</div>
								<div class="col-md-4">
								<input class="form-control input-sm" placeholder="Minutes" type="text" name="vis_resolutionmin" id="vis_resolutionmin" >
								</div>
							   </span>
                              </div>
                           </div>
					 <?php } ?>
					   </div>
                     </div>
                     <? if(($newly_added_task_details['parent_id']==0 && $get_sub_task_total==0) || $get_recursive_task_total>0){ ?>
					 <?php if(!isset($operation['auto_task_flag']))
					 { ?> 
                     <div class="row">
                        <div class="col-xs-4">
                           <a href="#taskrepeat" id="vis_task_repeat" class="link" data-toggle="class:show animated fadeInRight"><i class="vh vh-stopwatch"></i> Repeat <? echo $schedule[$newly_added_task_details['task_repeat_schedule']];?></a>
                           <?if($newly_added_task_details['task_repeat_schedule']!=0 && $occurance!=''){?>
                           <p class="text-muted"><?= $occurance;?> occurance(s) left</p>
                           <? } ?>
                        </div>
                     </div>
					 <?php } ?>
                     <div class="hide" id="taskrepeat" >
                        <div class="row">
                           <div class="wrapper">
                              <div class="col-xs-4">
                                 <div class="form-group col-xs-10">
                                    <label for="taskPriority"><? echo $vis_language['TXTSETSCHEDULE'];?></label>
                                    <select class="form-control input-sm selectpicker" id="vis_set_schedule" name="vis_set_schedule">
                                    <?
                                       for($i=0;$i<count($schedule);$i++) {
                                       if($newly_added_task_details['task_repeat_schedule'] == $i) $selected='selected="selected"'; else $selected='';
                                       echo '<option value="'.$i.'" '.$selected.' >'.$schedule[$i].'</option>'; } ?>
                                    </select>
                                 </div>
                              </div>
                              <div class="form-group" id="vis_daily" style="display: none;">
                                 <label class="col-sm-2 text-muted text-right"></label>
                                 <div class="col-sm-10">
                                    <? $repeat_daily=explode(',', $newly_added_task_details['task_repeat_occurence']);?>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"> <label>
                                       <input type="checkbox" <? if($repeat_daily[0]==1) echo 'checked="checked"'; else echo '';?><? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?> value="1" id="vis_daily1" name="vis_daily1"/><i></i> <? echo $vis_language['TXTSUNDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[1]==1) echo 'checked="checked"'; else echo '';?> <? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily2" name="vis_daily2"/><i></i> <? echo $vis_language['TXTMONDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[2]==1) echo 'checked="checked"'; else echo '';?><? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily3" name="vis_daily3"/><i></i> <? echo $vis_language['TXTTUESDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[3]==1) echo 'checked="checked"'; else echo '';?> <? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily4" name="vis_daily4"/><i></i> <? echo $vis_language['TXTWEDNESDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[4]==1) echo 'checked="checked"'; else echo '';?><? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily5" name="vis_daily5"/><i></i> <? echo $vis_language['TXTTHURSDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[5]==1) echo 'checked="checked"'; else echo '';?> <? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily6" name="vis_daily6"/><i></i> <? echo $vis_language['TXTFRIDAY']; ?></label>
                                    </div>
                                    <div class="checkbox i-checks m-r-lg pull-left p-d-sm"><label>
                                       <input type="checkbox" <? if($repeat_daily[6]==1) echo 'checked="checked"'; else echo '';?> <? if($newly_added_task_details['task_repeat_occurence']!=1)  echo 'checked="checked"';?>  value="1" id="vis_daily7" name="vis_daily7"/><i></i> <? echo $vis_language['TXTSATURDAY']; ?></label>
                                    </div>
                                 </div>
                              </div>
                              <div class="form-group" id="vis_weekly" style="display: none;">
                                 <label class="col-sm-2 text-muted text-right"></label>
                                 <div class="col-sm-10">
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==2) echo ' checked="checked"'; ?> checked="checked" value="2" id="vis_weekly1" name="vis_weekly"/><i></i><? echo $vis_language['TXTSUNDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==3) echo ' checked="checked"'; ?> value="3" id="vis_weekly2" name="vis_weekly"/><i></i><? echo $vis_language['TXTMONDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==4) echo ' checked="checked"'; ?> value="4" id="vis_weekly3" name="vis_weekly"/><i></i><? echo $vis_language['TXTTUESDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==5) echo ' checked="checked"'; ?> value="5" id="vis_weekly4" name="vis_weekly"/><i></i><? echo $vis_language['TXTWEDNESDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==6) echo ' checked="checked"'; ?> value="6" id="vis_weekly5" name="vis_weekly"/><i></i><? echo $vis_language['TXTTHURSDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==7) echo ' checked="checked"'; ?> value="7" id="vis_weekly6" name="vis_weekly"/><i></i><? echo $vis_language['TXTFRIDAY']; ?></label>
                                    </div>
                                    <div class="radio i-checks m-r-lg pull-left "><label>
                                       <input type="radio" <? if($newly_added_task_details['task_repeat_occurence']==8) echo ' checked="checked"'; ?> value="8" id="vis_weekly7" name="vis_weekly"/><i></i><? echo $vis_language['TXTSATURDAY']; ?></label>
                                    </div>
                                 </div>
                              </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_problem_id" name="vis_problem_id" value="<? echo $operation['vis_problem_id'];?>" />  
                  <input type="hidden" id="vis_changes_id" name="vis_changes_id" value="<? echo $operation['vis_changes_id'];?>" /> 
                  <input type="hidden" id="vis_release_id" name="vis_release_id" value="<? echo $operation['vis_release_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':'add_task', 'vis_form':'vis_ticket_task_create_form'});"><? echo $vis_language['TXTADD']; ?></a>      
        </div>
    </div>
</div>
<script>$('.start').datetimepicker({
        format: "<?php echo VIS_DATETIMEPICKER_FORMAT;?>"
	});
   function vis_remove_attachment(attach_id){
   $.ajax({
   	url: 'index.php',
   	data: {'vis_module':"ticket", 'vis_operation':"remove_attachment", 'vis_attachment_id':attach_id },
   	type: "POST",
   	success: function(data) {  }
   });
   var attachments=$("#vis_attachment_count").val();
   $("#vis_attachment_count").val(eval(parseInt(attachments)-1));
   var attachmentsCnt=$("#vis_attachment_count").val();
   if((attachmentsCnt==0)) $("#attachedMedia").css('display','none');
   }
   $('#vis_task_repeat').on('click',function(){
   	var cn = document.getElementById("taskrepeat").className;
   	if(cn.search("show")!=-1)
   	$("#vis_set_task_repeat").val('0');
   	else
   	$("#vis_set_task_repeat").val('1');
   });
    $(document).ready(function(){
   	$('#attachedMedia').hide();
   	var val=$("#vis_set_schedule").val();
   	if(val=='1') $('#vis_daily').show(); else $('#vis_daily').hide();
   	if(val=='2') $('#vis_weekly').show(); else $('#vis_weekly').hide();
   });
   $('#vis_set_schedule').on('change',function(){
   	var val=$("#vis_set_schedule").val();
   	if(val=='1') $('#vis_daily').show(); else $('#vis_daily').hide();
   	if(val=='2') $('#vis_weekly').show(); else $('#vis_weekly').hide();
   });
   $(".selectpicker").selectpicker();
</script>
