<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');
   $status=array(1 => $vis_language['TXTINPROGRESS'],2 => $vis_language['TXTOVERDUE'],3 => $vis_language['TXTCOMPLETED'],4 => $vis_language['TXTCANCELED']);
   $priority=array(1 => $vis_language['TXTLOW'],2 => $vis_language['TXTMEDIUM'],3 => $vis_language['TXTHIGH']); 
   ?>
<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['TXTUPDATETASK']; ?> </li>
      </ul>
   </div>
</section>
<section class="padder">
   <section class="panel panel-default">
      <header class="panel-heading sub_header"><?echo $vis_language['TXTUPDATETASK']?></header>
      <section class="col-sm-12 bg-white">
         <form name="vis_task_update_form" id="vis_task_update_form" class="form-horizontal" method="post">
            <section class="no-borders no-gutter no-radius">
               <div class="panel-body">
                   <div class="btn-group">
                   <? if($newly_added_task_details['image']=='' || $newly_added_task_details['image']=='default.jpg'){?>
<div class="l-avatar m-r">
<? if($newly_added_task_details['name']!=''){
$namearr=explode(' ',$newly_added_task_details['name']);
$fullname='';
if($newly_added_task_details['first_name']!=''){ 
$lastname=preg_split('//u', $newly_added_task_details['last_name'], -1, PREG_SPLIT_NO_EMPTY); 
$firstname=preg_split('//u', $newly_added_task_details['first_name'], -1, PREG_SPLIT_NO_EMPTY);
$fullname=ucfirst($firstname[0]).ucfirst($lastname[0]);
}else{
	$firstname=preg_split('//u', $namearr[0], -1, PREG_SPLIT_NO_EMPTY);
	$fullname=ucfirst($firstname[0]);
}
	?>
 <div class="md"><? echo $fullname; ?></div>
    <? }else{ ?>
    <img class="md img-circle" src="<?= VIS_PATH_PROFILE.'default.jpg';?>">
    <? }?>

</div>
<? }else{ ?>
<div class="l-avatar m-r">
<img src="<? echo VIS_PATH_PROFILE; echo $newly_added_task_details['image']; ?>" class="md img-circle">
</div>
<? }?>

							<!--<a href="#" class="thumb-md m-r">
								<img src="<? //echo VIS_PATH_PROFILE; echo ($newly_added_task_details['image']=='')?'default.jpg':$newly_added_task_details['image']; ?>"  class="img-circle"/>
							</a>	 --> 
							  </div>
							   <div class="btn-group">
								<div class="m-r-md"><? echo $vis_language['TXTCREATEDBY']; ?> : <a class="text-md link" href="#/home/profile_view/<? echo $vis_language['TXTPROFILE'];?><?= ($newly_added_task_details['staff_id'] != VIS_STAFF_ID) ? '/'.$newly_added_task_details['staff_id'] : '';?>"><? echo $newly_added_task_details['name']; ?></a></div>
								  <label class="m-r-sm"><? echo $vis_language['TXTSTATUS']; ?></label>
								  <?if($newly_added_task_details['enddate_diff']<=0){ if($newly_added_task_details['task_status']!=3 && $newly_added_task_details['task_status']!=4){?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-danger-bg m-t-xs" ><? echo $vis_language['TXTOVERDUE']; ?></label>
									<?} else
									{ if($newly_added_task_details['task_status']==1) {?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-success-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label>
									<?}else if($newly_added_task_details['task_status']==3){?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-info-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label>
									<?}else if($newly_added_task_details['task_status']==4){ ?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-grey-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label><? }} ?>
									<?}else { if($newly_added_task_details['task_status']==1) {?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-success-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label>
									<?}else if($newly_added_task_details['task_status']==3){?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-info-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label>
									<?}else if($newly_added_task_details['task_status']==4){ ?>
									<label id="vis_task_status" class="btn-xs wrapper-xxs vh-grey-bg m-t-xs"><? echo $status[$newly_added_task_details['task_status']]; ?></label><? }} ?>
								</div>
								 <?if($newly_added_task_details['parent_id']>0 && $newly_added_task_details['is_repeat']!=1) { ?>
									<div class="btn-group pull-right m-t-md">
										<label for="taskTitle" class="m-r-xs"><? echo $vis_language['TXTCHILDOF']; ?></label>
										<a class="text-md link" href="javascript:void(0);" onclick="$('#vis_workpanel_div').visExecution('load_module','<?= $parent_task_details['task_title'].'/'.$parent_task_details['task_id']?>',{'vis_module':'home', 'vis_operation':'view_update_tasks', 'vis_form':'vis_task_form'  ,'vis_filter_id':'<? echo $operation['filter_id'];?>','vis_task_id':'<? echo $parent_task_details['task_id'];?>'})"><? echo $parent_task_details['task_title']; ?></a>
									</div><? } ?>
								 <?if($newly_added_task_details['parent_id']==0 && $child_task_details[0]['total']>0) { ?>
								<div class="btn-group pull-right m-t-md">
									<button class="btn btn-default btn-xs btn-rounded" id="close"><? echo ($newly_added_task_details['task_repeat_schedule']==0 || $newly_added_task_details['task_repeat_schedule']==NULL)?$vis_language['TXTSUBTASK']:$vis_language['TXTRECURSIVETASK']; ?> (<? echo $child_task_details[0]['total'];?>)</button>
								</div><? } ?>
								<div id="vis_subtasks" class="wrapper-sm m-b-none m-t" style="display:none;">
									<? $tbl_data='';
										if($child_task_details[1]!=-1){?>
											<table class="table table-hover b-t b-light m-b-none" id="table_ticket_relation">
																<thead class="table_head">
																	<tr>
																		<th></th>
																		<th><? echo $vis_language['TXTTITLE'];?></th>
																		<th><? echo $vis_language['TXTTARGATEDATE'];?></th>	
																		<th><? echo $vis_language['TXTSTATUS'];?></th>	
																		<? if($newly_added_task_details['task_repeat_schedule']==0) {?><th></th>	<? } ?>				
																	</tr>
																</thead>
											
											<?for($i=0;$i<count($child_task_details[1]);$i++){?>
												<tr>
													<td>
              <? if($child_task_details[1][$i]['image']=='' || $child_task_details[1][$i]['image']=='default.jpg'){?>
             <div class="l-avatar m-l">
             <? if($newly_added_task_details['name']!=''){
$namearr=explode(' ',$newly_added_task_details['name']);
$fullname='';
if($newly_added_task_details['first_name']!=''){ 
$lastname=preg_split('//u', $newly_added_task_details['last_name'], -1, PREG_SPLIT_NO_EMPTY); 
$firstname=preg_split('//u', $newly_added_task_details['first_name'], -1, PREG_SPLIT_NO_EMPTY);
$fullname=ucfirst($firstname[0]).ucfirst($lastname[0]);
}else{
	$firstname=preg_split('//u', $namearr[0], -1, PREG_SPLIT_NO_EMPTY);
	$fullname=ucfirst($firstname[0]);
}
														?>
    <div class="xs"><? echo $fullname; ?></div>
    <? }else{ ?>
    <img class="xs img-circle" src="<?= VIS_PATH_PROFILE.'default.jpg';?>">
    <? }?>
             
             </div>
             <? }else{ ?>
             <div class="l-avatar m-l">
             <img src="<? echo VIS_PATH_PROFILE; echo $child_task_details[1][$i]['image']; ?>" class="xs img-circle">
             </div>
             <? }?>
             
            <!-- <div class="avatar thumb-xs m-l"><img src="<? //echo VIS_PATH_PROFILE; echo ($child_task_details[1][$i]['image']=='')?'default.jpg':$child_task_details[1][$i]['image']; ?>"  class="img-circle"/></div>--></td>
													<td width="30%"><a class="text-md link" href="javascript:void(0);" onclick="$('#vis_workpanel_div').visExecution('load_module','<?= $child_task_details[1][$i]['task_title'].'/'.$child_task_details[1][$i]['task_id']?>',{'vis_module':'home', 'vis_operation':'view_update_tasks', 'vis_form':'vis_task_form'  ,'vis_filter_id':'<? echo $operation['filter_id'];?>','vis_task_id':'<? echo $child_task_details[1][$i]['task_id'];?>'})"><? echo $child_task_details[1][$i]['task_title'];?></a></td><td><? echo format_datetime($child_task_details[1][$i]['enddate']);?></td>
													<td><?if($child_task_details[1][$i]['enddate_diff']<=0){ if($child_task_details[1][$i]['task_status']!=3 && $child_task_details[1][$i]['task_status']!=4){?>
														<label id="vis_task_status" class="btn-xs vh-danger-bg" ><? echo $vis_language['TXTOVERDUE']; ?></label>
														<?} else
														{ if($child_task_details[1][$i]['task_status']==1) {?>
														<label id="vis_task_status" class="btn-xs vh-success-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label>
														<?}else if($child_task_details[1][$i]['task_status']==3){?>
														<label id="vis_task_status" class="btn-xs vh-info-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label>
														<?}else if($child_task_details[1][$i]['task_status']==4){ ?>
														<label id="vis_task_status" class="btn-xs vh-grey-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label><? }} ?>
														<?}else { if($child_task_details[1][$i]['task_status']==1) {?>
														<label id="vis_task_status" class="btn-xs vh-success-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label>
														<?}else if($child_task_details[1][$i]['task_status']==3){?>
														<label id="vis_task_status" class="btn-xs vh-info-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label>
														<?}else if($child_task_details[1][$i]['task_status']==4){ ?>
														<label id="vis_task_status" class="btn-xs vh-grey-bg"><? echo $status[$child_task_details[1][$i]['task_status']]; ?></label><? }} ?>
													</td><? if($child_task_details[1][$i]['is_repeat']==0) {?><td><a href="javascript:void(0);" class="link" data-toggle="ajaxModal" data-modal-arguments="vis_module=home&vis_operation=confirm_detach_subtask&vis_static_area=vis_subtask_area&vis_task_id=<? echo $child_task_details[1][$i]['task_id']; ?>&vis_parent_id=<? echo $newly_added_task_details['task_id']; ?>"><? echo $vis_language['TXTDETACH']; ?></a></td><? } ?></tr>
											<?}?></table>
										<?}?>
								</div>
                  <div class="wrapper">
                     <div class="form-group">
                        <label for="taskTitle"><? echo $vis_language['TXTTASKTITLE']; ?></label>
						<div class="m-r-sm"> <? echo $newly_added_task_details['task_title'];?></div>                        
                     </div>
                     <div class="form-group">
                        <label for="taskDescription"><? echo $vis_language['TXTDESCRIPTION'];?></label>
                        <div class="m-r-sm"> <? echo $newly_added_task_details['description'];?></div>
                     </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> 
                                 <div class="m-r-sm"><? echo $priority[$newly_added_task_details['priority']];?></div>
                              </div>
                           </div>
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskStartdate"><? echo $vis_language['TXTSTARTDATE'];?></label>
								 <div class="m-r-sm"><?= date(VIS_DATETIME_FORMAT, ($newly_added_task_details['startdate']+VIS_TIMEZONE)); ?></div>
                              
                              </div>
                           </div>
                           <div class="col-xs-4">
                              <div class="form-group col-xs-10">
                                 <label for="taskEnddate"><? echo $vis_language['TXTENDDATE'];?></label>
								 <div class="m-r-sm"><?= date(VIS_DATETIME_FORMAT, ($newly_added_task_details['enddate']+VIS_TIMEZONE)); ?></div>              
							  </div>
                           </div>
                        </div>
                     </div> 				
                     <div class="row">
                        <div class="wrapper">
                           <div class="form-group">
                              <label for="taskTitle"><? echo $vis_language['TXTASSIGNTO']; ?></label>							        	
								<div class="m-r-sm">
								<? if($assign_task_details!=-1) for($i=0 ; $i<count($assign_task_details); $i++){ 
									$assign_user.=$assign_task_details[$i]['owner_id'].',';?>
									<span class="btn btn-xs alert-success m-r-xs"><? echo $assign_task_details[$i]['first_name']." ".$assign_task_details[$i]['last_name']; ?></span>
								<? } if(substr($assign_user, -1)==',') $assign_user=substr($assign_user, 0, -1); ?></div>                                                    
                              <input type="hidden" id="vis_task_grp_share" name="vis_task_grp_share" value="<?echo $assign_user;?>"/>
                              <input type="hidden" id="vis_task_share" name="vis_task_share"/>
                              <input type="hidden" id="vis_staff" name="vis_staff" value=""/>
                              <input type="hidden" id="vis_old_staff" name="vis_old_staff" value="<?echo $old_staff;?>"/>
                           </div>
                        </div>
                     </div>     
                       <div class="row">
                        <div class="wrapper">
                           <div class="col-xs-4">
							    <input type="hidden" name="vis_task_id" value="<? echo $newly_added_task_details['task_id']; ?>" />
								  <input type="hidden" name="vis_parent_id" value="<? echo $newly_added_task_details['parent_id']; ?>" />
								  <input type="hidden" id="vis_tasktitle" name="vis_tasktitle" value="<?echo $newly_added_task_details['task_title'];?>"/>
								  <input type="hidden" id="vis_task_description" name="vis_task_description" value="<?echo $newly_added_task_details['description'];?>"/>
								  <input type="hidden" id="vis_task_priority" name="vis_task_priority" value="<?echo $newly_added_task_details['priority'];?>"/>
								  <input type="hidden" id="vis_task_start_date" name="vis_task_start_date" value="<?echo date('M-jS, Y G:i', ($newly_added_task_details['startdate']+VIS_TIMEZONE));?>"/>
								  <input type="hidden" id="vis_task_end_date" name="vis_task_end_date" value="<?echo date('M-jS, Y G:i', ($newly_added_task_details['enddate']+VIS_TIMEZONE));?>"/>
                              <div class="form-group col-xs-10">
                                 <label for="taskPriority"><? echo $vis_language['TXTSTATUS'];?></label>
                                 <select id="vis_task_status" name="vis_task_status" class="form-control selectpicker" onchange="$('#vis_workpanel_div').visExecution('load_operations', {'vis_module':'home', 'vis_operation':'update_task_status_by_assign_user', 'vis_form':'vis_task_update_form','vis_filter_id':'<? echo ($operation['filter_id']!='')?$operation['filter_id']:'1';?>','vis_tasktitle':'<?= $newly_added_task_details['task_title'];?>'});">
                                	<option value=""><?= $vis_language['TXTSELECT']; ?></option>
                                    <option value="1" <? echo ($newly_added_task_details['task_status']==4)?' selected="selected"':''; ?>><? echo $vis_language['TXTMARKASCANCEL'];?></option>
                                    <option value="2" <? echo ($newly_added_task_details['task_status']==3)?' selected="selected"':''; ?>><? echo $vis_language['TXTMARKASCOMPLETE'];?></option>
                                 </select>
                              </div>
                           </div>
                           <div class="col-xs-8">
                              <div class="form-group m-t text-right">
								
                              </div>
                           </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>
                     </div>
                  <div class="line line-dashed b-b line-lg pull-in"></div>
                  <!-- comment section start -->
                  <div id="vis_comment_list">
                     <? if($get_task_comment != -1){
                        include(VIS_PATH_TEMPLATE."task_comment_list.php");
                          }?>
                  </div>
                  <!-- comment section end -->
                  <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'];?>"/>
                  <input type="hidden" id="vis_task_staff_id" name="vis_task_staff_id" value="<? echo $newly_added_task_details['staff_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>
