<?  global $vis_language;
	$problem_filters=array(8=>$vis_language['TXTALL'],9=>$vis_language['TXTOPEN'],10=>$vis_language['TXTCLOSED'],11=>$vis_language['TXTASSIGNED']);

    function get_lists($list, $operation) {
		global $vis_language;
	    $name=$operation.'_name';
        $search = ($operation=='staff' && count($list)>9) ? ' data-live-search="true"' : ((count($list)>10) ? ' data-live-search="true"' : "");
        $return_value .= '<select class="form-control i-1x selectpicker" id="search_'.$operation.'" name="search_'.$operation.'" data-selector-label="Select"'.$search.'>';
        $return_value .='<option value="">'.$vis_language['TXTSELECT'].'</option>';
        if($operation=='staff') $return_value .= '<option value="0">'.$vis_language['TXTUNASSIGNED'].'</option>';
        $txt = $flag_color = $domain_id ='';
		for($i=0;$i<count($list);$i++) {
			if($operation=='flag') { $flag_color = 'style="color:'.$list[$i]['flag_color'].'"'; $txt = $list[$i][$name];
			}else if($operation=='staff'){ $txt = $list[$i]['first_name'].' '.$list[$i]['last_name'];
			}else if($operation==strtolower($vis_language['TXTDEPARTMENT'])){
				if($domain_id=="" || ($domain_id!="" && $domain_id!=$list[$i]['domain_id'])){
					$domain_id = $list[$i]['domain_id'];
					if($i!=0) $return_value .= '</optgroup>';
				}
				$txt = $list[$i]['domain_name'] ." : ". $list[$i][$name];
			}else if($operation=='department'){
				if($domain_id=="" || ($domain_id!="" && $domain_id!=$list[$i]['domain_id'])){
					$domain_id = $list[$i]['domain_id'];
					if($i!=0) $return_value .= '</optgroup>';
				}
				$txt = $list[$i]['domain_name'] ." : ". $list[$i][$name];
			}else if($operation==strtolower($vis_language['TXTIMPACT']) || $operation==strtolower($vis_language['TXTRISK'])){
				$txt = $list[$i]['name'];
			}
			else  $txt = $list[$i][$name];
			$return_value .= '<option value="'.$list[$i][$operation.'_id'].'" '.$flag_color.'>'.$txt.'</option>';
		}

		$return_value .= "</select>";
        return $return_value;
    }

?>
<section class="vbox fadeInRight">
   <section class="scrollable">
      <div class="text-md hidden-nav-xs text-black vis_leftpanel_domain_span"><? echo $vis_language['TXTPROBLEMFILTERS']; ?></div>
       <div id="staff_list">
         <ul class="list-group auto no-radius m-b-none m-t-n-xxs list-group-lg">
            <? for($i=8;$i<=count($problem_filters)+7;$i++){?>
            <li class="list-group-item">
			   <a href="#/problem/filter_problem/<? echo $problem_filters[$i].'/'.$i ;?>"><span id="vis_cnt_<?= $i;?>" ><? echo $quick_view[$i];?></span>
               <span><? echo $problem_filters[$i];?></span>
               </a>
            </li>
            <? }?>
         </ul>
      </div>
	<? if($operation['vis_current_operations']!='problems_details' && $operation['vis_current_operations']!='new_problem'){ ?>
	<div class="text-md hidden-nav-xs text-black vis_leftpanel_domain_span"><? echo $vis_language['TXTFILTERLIST']; ?></div>
    <div class="wrapper bg-white b-t" id="vis_filter_list">
	  <form id="vis_problems_search_form" name="vis_problems_search_form" method="post">
		<!--<input type="hidden" id="vis_filter_id" name="vis_filter_id" value="<? echo $operation['filter_id'];?>"/>-->
            <div class="row">
              <div class="m-t m-b">
				<div class="form-group form-group col-sm-12">
				   <label class="col-sm-4 control-label m-t-xs"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
				    <div class="col-sm-7">
					  <?= get_lists($departments, 'department');?>
			        </div>
				</div>
                <div class="form-group form-group col-sm-12">
				    <label class="col-sm-4 control-label m-t-xs"><? echo $vis_language['TXTIMPACT']; ?></label>
				    <div class="col-sm-7">
						<?= get_lists($impacts, strtolower($vis_language['TXTIMPACT']));?>
				    </div>
				</div>
                <div class="form-group form-group col-sm-12">
				   <label class="col-sm-4 control-label m-t-xs"><? echo $vis_language['TXTPRIORITY']; ?></label>
					<div class="col-sm-7">
						<?= get_lists($priorities, 'priority');?>
					</div>
				</div>
				<div class="form-group form-group col-sm-12">
                    <label class="col-sm-4 control-label m-t-xs"><? echo $vis_language['TXTSTATUS']; ?></label>
                    <div class="col-sm-7">
						<?= get_lists($status, 'status');?>
					</div>
                </div>
              </div>
            </div>
           <div class="row">
                <div class="m-t m-b">
                    <div class="form-group">
                        <div class="col-sm-12">
                          <button type="button" id="btn_apply_filter" class="btn btn-primary pull-right" onClick="javascript:vis_apply_filter();"><?= $vis_language['TXTAPPLYFILTER'];?></button>
                         <button type="button" id="reset-form" class="btn btn-default pull-right m-r-sm"><?= $vis_language['TXTCLEAR'];?></button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
	</div>
	<? } ?>
   </section>
</section>
<script type="text/javascript">
	$(document).ready(function(){
		<? for($i=8;$i<=count($problem_filters)+7;$i++){?>
			$("#vis_cnt_<? echo $i;?>").attr("class","badge bg-gradient pull-right font-normal text-xs");
		<?}?>
	});

	$('#reset-form').on('click', function()
	{
		$("#vis_right_panel_div").visExecution("load_area",{"vis_module":"home", "vis_operation":"load_right_panel","vis_current_module":"problem","vis_current_operations":"view_problems","vis_filter_id":"<? echo $filter_id;?>"});
	});

	function vis_apply_filter(vis_page){
	vis_page = (vis_page!=undefined && typeof(vis_page)!=undefined && vis_page != '') ? vis_page:'';
	var data = {'vis_filter_enable':'1', 'vis_page':vis_page, 'vis_action': $("#vis_filter_list input, #vis_filter_list select").serialize()};

    $.ajax({
		url: 'index.php?vis_module=problem&vis_operation=view_problems',
		data: data,
		type: "POST",
		dataType: "json",
		success: function(data) {
			$(".tkt_right_menu").html(data.paging);
			$("#vis_problems_list").html(data.list);
			$('#url_header').html('<h3 class="m-b-xs text-black"><? echo $vis_language['TXTFILTERRESULT']; ?><span id="total_cnt"> ('+data.total_cnt+')</span></h3><div><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="#/problem/filter_problem/<? echo $vis_language['TXTPROBLEMS'];?>/8" onclick="location.reload();"><? echo $vis_language['TXTPROBLEMS'];?></a></li><li class="active"><? echo $vis_language['TXTFILTERRESULT']; ?></li></ul></div>').show();
			if(data.total_cnt==0){
				$("#vis_no_record_search1").show();
				$("#no_record_yet").hide();
				$("#vis_no_record_search1").html(data.list);
			}else $("#vis_no_record_search1").hide();
            toggle_mass_actions(); // To disable header & footer mass actions on list pages
		},
		error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
	});
}
</script>
