<script src="<?= VIS_PATH_SCRIPT; ?>file-input/bootstrap-filestyle.min.js"></script>
<style>#customfi [class*="col"]{ padding:0 15px 0 15px;}</style>
<? 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']);
   ?>
<section id="breadcrumb" class="row m-b m-l-none m-r-none">
   <div class="col-sm-6">
      <h3 class="m-b-xs text-black"><? echo $vis_language['TXTTASKS']; ?> </h3>
      <ul class="breadcrumb bg-empty no-border m-b-xxs no-padder">
         <li><a class="link" href="#/home/quick_view/<? echo $vis_language['TXTHOME']; ?>"><?echo $vis_language['TXTHOME'];?></a></li>
         <li><a  class="link" href="#/home/view_tasks/<? echo $vis_language['TXTTASKS']; ?>/1" ><? echo $vis_language['TXTTASKS'] ?></a> </li>
         <li class="active"><? echo $vis_language['TXTADDTASK']; ?> </li>
      </ul>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><? echo $vis_language['TXTADDTASK']; ?></header>
      <section class="col-sm-12 bg-white">
         <form name="vis_task_create_form" id="vis_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>
                           <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="<?php echo strtoupper(VIS_DATETIME_FORMAT);?>" ></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="<?php echo strtoupper(VIS_DATETIME_FORMAT);?>" ></span>
                              </div>
                           </div>
                        </div>
                     </div>
                     <? if(($newly_added_task_details['parent_id']==0 && $get_sub_task_total==0) || $get_recursive_task_total>0){ ?>
                     <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><? */ ?>
						   <a href="#taskrepeat" id="vis_task_repeat" class="link" data-toggle="class:show"><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>
                     <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" id="customfi">
								<div class="form-group">
									<? 	echo $custom_field_var;?>
                                    <input type="hidden" name="vis_add_tsk" id="vis_add_tsk" value="1" />
                                    <input type="hidden" id="vis_department" name="vis_department" value="<? echo $departmentid;?>"/>
							   	</div>
							</div>
						</div>
                     	<? 
					 } 
					 ?>
                     <!-------------------------------------------------->
                     <div class="row">
                     	<div class="wrapper">
                           <div class="col-xs-12">
                           		<div class="form-group">
                                	<label for="taskTitle"><? echo $vis_language['TXTASSIGNTEAM']; ?></label>
                                    <div class="dept_access_list m-b">
                                      <?
									  if($get_groups!=-1)
									  {
										  for($i=0;$i<count($get_groups);$i++)
										  {
											?>
											<label class="checkbox-inline i-checks">
											<input type="checkbox" id="vis_groupnames_<? echo ($i+1);?>" name="vis_groupname[]" value="<? echo $get_groups[$i]['group_id'];?>"/>
											<i></i><? echo $get_groups[$i]['group_name']; ?></label>
											<br/>
											<?
										  }
									  }
                                      ?>
                                    </div>
                                </div>
                           </div>
                        </div>
                     </div>
                     
                     <div class="row">
                        <div class="wrapper">                        
                           <div class="col-xs-12">
                              <div class="form-group m-t text-right">								 
                               <button type="button" id= "add_new_task_button" class="btn btn-primary" onclick="$('#vis_workpanel_div').visExecution('submit_form',{'vis_module':'home', 'vis_operation':'add_task', 'vis_form':'vis_task_create_form'}); $(this).attr('disabled','disabled');"><? echo $vis_language['TXTADD'];?></button>
                              </div>
                           </div>
                        </div>
                     </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>          
                  <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>
      </section>
   </section>
</section>
<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();
   
   $('#close').click(function (e) {
        e.preventDefault();
        $('#vis_subtasks').slideToggle();
    });
    function task_delete(task_id,filter_id)
    {
		$('#del').attr('data-toggle','ajaxModal');
		$('#del').attr('data-modal-arguments','vis_module=home&vis_operation=get_delete_task&vis_task_id='+task_id+'&vis_filter_id='+filter_id+'&vis_static_area=vis_task_delete_area');
	}

</script>
