<? global $vis_language; 
$tp=0;
if(isset($module_setting['vis_category'])){
	$tp++;
	if(isset($module_setting['vis_show_subcategory']) && ($module_setting['vis_show_subcategory']==1 || $module_setting['vis_show_subcategory']==2)){
		$tp++;
		$module_setting['vis_subcategory']='';
		if(isset($module_setting['vis_show_item']) && ($module_setting['vis_show_item']==1 || $module_setting['vis_show_item']==2)){$tp++;$module_setting['vis_item']='';}
	}
}
if(VIS_ITIL==1)$tp++;
?>
<div class="row m-b">
	<div class="form-group m-b-none">
		<div class="col-sm-2">
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
			<div id="department">
                <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="<? if(VIS_DEPARTMENT_ACCESS!=0){ ?>$('#department').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'department', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['department_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>});<? } else{ ?>$('#vis_global_msg_div').visInterface('load_global_message', '<?= $vis_language['MSGACCSSDND']; ?>');<? } ?>"><span class="filter-option pull-left"><?= $departments[0]['domain_name'].' : '.$departments[0]['department_name']; ?>&nbsp;</span><span class="caret"></span></button>
			</div>
		</div>
		<div class="col-sm-2">
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTSTATUS']; ?></label>
			<div id="status">
                <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="<? if(VIS_STATUS_ACCESS!=0){ ?>$('#status').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'status', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['status_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});<? } else{ ?>$('#vis_global_msg_div').visInterface('load_global_message', '<?= $vis_language['MSGACCSSDND']; ?>');<? } ?>"><span class="filter-option pull-left"  style="color:<?= $problems_details['status_color']; ?>" ><?= $problems_details['status_name']; ?>&nbsp;</span><span class="caret"></span></button>
			</div>
		</div>
		<div class="col-sm-2">
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTPRIORITY']; ?></label>
			<div id="priority">
                <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="<? if(VIS_PRIORITY_ACCESS!=0){ ?>$('#priority').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'priority', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['priority_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});<? } else{?>$('#vis_global_msg_div').visInterface('load_global_message', '<?= $vis_language['MSGACCSSDND']; ?>');<? } ?>"><span class="filter-option pull-left" style="color:<?= $problems_details['priority_color']; ?>" ><?= $problems_details['priority_name']; ?>&nbsp;</span><span class="caret"></span></button>
			</div>
		</div>
		<div class="col-sm-2">
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTIMPACT']; ?></label>
			<div id="impact">
                <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="<? if(VIS_TYPE_ACCESS!=0){ ?>$('#impact').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'impact', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['impact_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});<? } else{ ?>$('#vis_global_msg_div').visInterface('load_global_message', '<?= $vis_language['MSGACCSSDND']; ?>');<? } ?>"><span class="filter-option pull-left" style="color:<?= $problems_details['impact_color'];?>" ><?= $problems_details['impact_name']; ?>&nbsp;</span><span class="caret"></span></button>
			</div>
		</div>
		<div class="col-sm-2">
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTDUEBY']; ?></label>
			<div id="duebydate">	
                <span class="filter-option pull-left" id="countdown">&nbsp;</span>
			</div>
		</div>
		<div class="col-sm-2">
            <div id="owner">
                <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white" type="button" onclick="<? if(VIS_STAFF_ACCESS!=0){ ?>$('#owner').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'owner', 'vis_problem_id': <?= $operation['vis_problem_id']?>,  'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});<? } else{?>$('#vis_global_msg_div').visInterface('load_global_message', '<?= $vis_language['MSGACCSSDND']; ?>');<? } ?>"><span class="filter-option pull-left"><?= $vis_language['TXTASSIGNEDTO']; ?>&nbsp;</span><span class="caret"></span></button>
            </div>
                <?  $owner1 = $vis_language['TXTUNASSIGNED'];
                    $owner_cnt = (!empty($owner_details) && $owner_details != -1) ? count($owner_details) : 0;
                        if ($owner_details != -1 ) {
                            foreach ($owner_details as $owner) {
								if ($owner1 == $vis_language['TXTUNASSIGNED']) {
									$owner1 = $owner['first_name'] . ' ' . $owner['last_name'];
								}
							}
                        } ?>
            <div><? if ($owner_cnt > 1) { ?>
                <span class="m-l-sm text-sm"><? echo $vis_language['TXTMULTIPLEOWNERS'];?></span>
                <? } else { ?>
                <span class="m-l-sm text-sm"><? echo $owner1;?></span>
                <? } ?>
            </div>
		</div>
     </div>
</div>

<? if ($owner_cnt > 1) { ?>
<div class="wrapper-sm m-b-none" id="vis_assigned_to_<?= $problems_details['problem_id'];?>">		
	<div class="row">			
		<div class="form-group clear m-b-xs m-t-xs">
			<label class="col-sm-1 control-label"><? echo $vis_language['TXTOWNERS']; ?></label>
			<div class="col-sm-11">
			<?  if($owner_details != -1) {		
				for($i = 0; $i < count($owner_details); $i++) { ?>
				<div class="btn-group pull-left<? if($i > 0) echo ' m-l-sm m-b-xs'?>">
					<span class="btn btn-xs alert-danger"><?= $owner_details[$i]['first_name'] . ' ' . $owner_details[$i]['last_name']?></span>
					<button type="button" class="btn btn-xs alert-danger" data-dismiss="alert" onclick="$('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'staff', 'vis_problem_id': <?= $problems_details['problem_id'];?>, 'vis_update_id': <?= $owner_details[$i]['staff_id']?>, 'vis_sub_action': 0});"><span aria-hidden="true"><i class="vh vh-cross"></i></span><span class="sr-only">Close</span></button>
				</div>
				<? }
				} ?>	
			</div>
		</div>
	</div>
</div>
<? } ?>

<? if($tp!=0){ ?>
<div class="wrapper-sm m-t b m-b-none bg-light m-b">
	<div class="row">
            <? if(isset($module_setting['vis_category'])){ ?>
		<div class="col-sm-3 m-t-xs">
		     <div>
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTTICKETCATEGORY']; ?></label>
			<span id="category">
                           <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white m-t-xxs" type="button" onclick="$('#category').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'category', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['category_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});"><span class="filter-option pull-left"><?= ($problems_details['category_name']!='')?$problems_details['category_name']:$vis_language['TXTSELECT']; ?>&nbsp;</span><span class="caret"></span></button>
			</span>
		    </div>
		</div>
           <? } ?>

           <? if(isset($module_setting['vis_subcategory'])){ ?>
		<div class="col-sm-3 m-t-xs">
		     <div>
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTTICKETSUBCATEGORY']; ?></label>
			<span id="subcategory">
                           <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white m-t-xxs" type="button" onclick="$('#subcategory').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'subcategory', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['subcategory_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_category_id': <?= $problems_details['category_id']; ?>});"><span class="filter-option pull-left"><?= ($problems_details['subcategory_name'])?$problems_details['subcategory_name']:$vis_language['TXTSELECT']; ?>&nbsp;</span><span class="caret"></span></button>
			</span>
		    </div>
		</div>
           <? } ?>

           <? if(isset($module_setting['vis_item'])){ ?>
		<div class="col-sm-3 m-t-xs">
		     <div>
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTTICKETITEM']; ?></label>
			<span id="item">
                           <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white m-t-xxs" type="button" onclick="$('#item').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'item', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['item_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_subcategory_id': <?= $problems_details['subcategory_id']; ?>});"><span class="filter-option pull-left"><?= ($problems_details['item_name'])?$problems_details['item_name']:$vis_language['TXTSELECT']; ?>&nbsp;</span><span class="caret"></span></button>
			</span>
		    </div>
		</div>
           <? } ?>
           <? if(VIS_ITIL==1){ ?>
		<div class="col-sm-3 m-t-xs">
		     <div>
			<label class="control-label m-l-sm font-bold"><? echo $vis_language['TXTLOCATION']; ?></label>
			<span id="location">
                           <button data-toggle="dropdown" class="btn bg-empty btn-sm dropdown-toggle action_btn bg-white m-t-xxs" type="button" onclick="$('#location').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'load_lists', 'vis_action': 'location', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_selected_id': <?= $problems_details['location_id']; ?>, 'vis_domain_id': <?= $problems_details['domain_id']; ?>, 'vis_dept_id': <?= $problems_details['department_id']; ?>});"><span class="filter-option pull-left"><?= ($problems_details['location_name']!='')?$problems_details['location_name']:$vis_language['TXTSELECT']; ?>&nbsp;</span><span class="caret"></span></button>
			</span>
		    </div>
		</div>
           <? } ?>
	</div>
</div>
<? } ?>

<div class="btn-group">
	<button class="btn btn-default btn-xs btn-rounded" onclick="$('#vis_show_attach_all_<? echo $problems_details['problem_id']; ?>').visExecution('load_operations',{'vis_module':'problem', 'vis_operation':'get_details', 'vis_action':'attach_ticket', 'vis_problem_id':'<? echo $problems_details['problem_id']; ?>'});"><? echo $vis_language['TXTTICKET']. '('.$total_ticket.')'; ?></button>
</div>
<div class="btn-group">    
    <button class="btn btn-default btn-xs btn-rounded" onclick="$('#vis_show_attach_all_<? echo $problems_details['problem_id']; ?>').visExecution('load_operations',{'vis_module':'problem', 'vis_operation':'get_details', 'vis_action':'attach_ci', 'vis_problem_id':'<? echo $problems_details['problem_id']; ?>'});"><? echo $vis_language['TXTCI']. '('.$total_ci.')'; ?></button>
</div>
<div class="btn-group">
	<button class="btn btn-default btn-xs btn-rounded" onclick="$('#vis_show_attach_all_<? echo $problems_details['problem_id']; ?>').visExecution('load_operations',{'vis_module':'problem', 'vis_operation':'get_details', 'vis_action':'attach_changes', 'vis_problem_id':'<? echo $problems_details['problem_id']; ?>'});"><? echo $vis_language['TXTCHANGES']. '('.$total_change.')'; ?></button>
</div>
<div class="btn-group">
	<button class="btn btn-default btn-xs btn-rounded" onclick="$('#vis_show_attach_all_<? echo $problems_details['problem_id']; ?>').visExecution('load_operations',{'vis_module':'problem', 'vis_operation':'get_details', 'vis_action':'attach_task', 'vis_problem_id':'<? echo $problems_details['problem_id']; ?>'});"><? echo $vis_language['TXTTASKS']. '('.$total_task.')'; ?></button>
</div>
<div id="vis_show_attach_all_<? echo $problems_details['problem_id']; ?>"></div>

<script>
	var permanent_solution = <? echo $problems_details['permanent_id']; ?>;
	var workaround_solution = <? echo $problems_details['workaround_id']; ?>;
	var end = new Date('<?= date("m/d/Y h:i A", $problems_details['due_by']); ?>');
	var _second = 1000;
	var _minute = _second * 60;
	var _hour = _minute * 60;
	var _day = _hour * 24;
	var now = new Date();var countd='';
	var distance = end - now;
	
	if (distance < 0) {
		if(permanent_solution!='0' || workaround_solution!='0'){
			var result='<span class="label vh-green-bg m-l-xs"><i class="vh vh-clock"></i> <? echo $vis_language['TXTUNDUE']; ?></span>';
		}else{
			var result='<span class="label vh-red-bg m-l-xs"><i class="vh vh-clock"></i> <? echo $vis_language['TXTOVERDUE']; ?></span>';
		}
		$('#countdown').html(result);
	}else{
		var days = Math.floor(distance / _day);
		var hours = Math.floor((distance % _day) / _hour);
		var minutes = Math.floor((distance % _hour) / _minute);
		var seconds = Math.floor((distance % _minute) / _second);
		
		if(days > 0){countd += days + 'D : ';}
		 
		 countd += hours + 'H : ';
		 countd += minutes + 'M';
		 if(days==0){countd += ' : '+seconds + 'S';}
		 countd = countd.replace("undefined", ""); 
		
		if(permanent_solution!='0' || workaround_solution!='0'){
			var result='<span class="label vh-green-bg m-l-xs"> <i class="vh vh-clock"></i> <? echo $vis_language['TXTUNDUE']; ?></span>';
		}else{
			var result='<span class="label vh-green-bg m-l-xs"><i class="vh vh-clock"></i> '+countd+'</span>';
		}
		
		$('#countdown').html(result);
	}
</script>
<script>  
    $(".selectpicker").selectpicker();
 
    // Add scrolling to section below bredcrumbs & bredcrumb sticks fixed at top
    $("#vis_workpanel_div").removeClass("scrollable");
    $("#ticket_details_view").css({"overflow-x":"hidden", "min-height":($( window ).height()-132-10)+"px", "max-height":($( window ).height()-132-10)+"px", "overflow-y":"auto"});
    $(window).resize(function() {	//resize just happened, pixels changed 
        $("#ticket_details_view").css({"overflow-x":"hidden", "min-height":($( window ).height()-132-10)+"px", "max-height":($( window ).height()-132-10)+"px", "overflow-y":"auto"});
    });
    function update_owner(staff_id, update_owner) { // update owner properties i.e. assign new/remove 
        $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'staff', 'vis_problem_id': <?= $operation['vis_problem_id']?>, 'vis_update_id': staff_id, 'vis_sub_action': update_owner});
    }
    function toggle_assigned_owner() { // show/hide assigned to (owner)
        $("#vis_assigned_to_<?= $problems_details['problem_id'];?>").toggle();
        if($("#vis_assigned_to_<?= $problems_details['problem_id'];?>").is(":visible")) {
            $("#vis_assigned_to_<?= $problems_details['problem_id'];?>").next().removeClass('m-t');
        } else {
            $("#vis_assigned_to_<?= $problems_details['problem_id'];?>").next().addClass('m-t');
        }
    }
    function update_properties(updateid,serialid){
        if(serialid==1) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'department', 'vis_problem_id': <?= $problems_details['problem_id']; ?>, 'vis_update_id': updateid});
        else if(serialid==2) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'status', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==3) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'priority', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==4) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'impact', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==15) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'category', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==16) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'subcategory', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==17) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'item', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
        else if(serialid==18) $('#vis_global_msg_div').visExecution('load_operations', {'vis_module': 'problem', 'vis_operation': 'update_properties', 'vis_action': 'location', 'vis_problem_id': <?= $problems_details['problem_id']; ?>,  'vis_update_id': updateid});
    }
</script>