<?  global $vis_language;
    function get_lists($list, $operation, $options) {
		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=='location'){
				$txt=$list[$i]['name'];
			}else if($operation=='level' || $operation=='category' || $operation=='subcategory' || $operation=='item'){
				$txt=$list[$i]['title'];
			}else $txt = $list[$i][$name];
			$return_value .= '<option value="'.$list[$i][$operation.'_id'].'" '.$flag_color.'>'.$txt.'</option>';
		}
		$return_value .= "</select>";
        return $return_value;
    }
function vis_show_subcategories($location_assets,$call=NULL) {
         
        for($i=0;$i<count($location_assets);$i++) { ?>
		 <? echo '<option value="'.$location_assets[$i]['location_id'].'">'.ucfirst($location_assets[$i]['name']). '</option>';?>
				 <?php 
				if(isset($location_assets[$i]['subcat']) && $location_assets[$i]['subcat']!=NULL) { 
					 
					  vis_show_subcategories($location_assets[$i]['subcat'],'sub_cat'); 
					}
		}
		
    }	
?>

		<form name="vis_ticket_search_form" id="vis_ticket_search_form" method="POST">
		<label class="control-label"><b><?= $vis_language['TXTFILTERLIST']; ?></b></label>
		<div class="row">
		  <div class="m-t m-b">
			<div class="form-group">
				<label class="col-sm-1 control-label"><? echo $vis_language['TXTDEPARTMENT']; ?></label>
				<div class="col-sm-2">
				  <?= get_lists($departments,'department',$options);?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><? echo $vis_language['TXTSTATUS']; ?></label>
				<div class="col-sm-2">
				  <?= get_lists($status, 'status', $options);?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><?= $vis_language['TXTPRIORITY'];?></label>
				<div class="col-sm-2">
				 <?= get_lists($priorities, 'priority', $options);?>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-1 control-label"><?= $vis_language['TXTTYPE'];?></label>
				<div class="col-sm-2">
				   <?= get_lists($ticket_types, 'type', $options);?>
				</div>
			</div>
		  </div>
		</div>
		<div class="row">
		  <div class="m-t m-b">
			<div class="form-group">
				<label class="col-sm-1 control-label"><?= $vis_language['TXTFLAG'];?></label>
				<div class="col-sm-2">
                     <select name="search_flag" id="search_flag" class="form-control i-1x selectpicker" data-selector-label="Select" <? if(count($flags)>10) echo ' data-live-search="true"';?>>
                        <option value=""><? echo $vis_language['TXTSELECT']; ?></option>
                        <? foreach($flags as $flag){ ?>
                        <option data-content='<span class="vh-stack pull-right"><i class="vh vh-flag-inner vh-stack-lg" style="color:<?= $flag['flag_color'];?>"></i><i class="vh vh-flag-empty vh-stack-lg"></i></span><?= $flag['flag_name'];?>' value="<?= $flag['flag_id']; ?>"></option>
                        <? } ?>
                    </select>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-1 control-label"><?= $vis_language['TXTOWNER'];?></label>
				<div class="col-sm-2">
				  <?= get_lists($owner, 'staff', $options);?>
				</div>
			</div>

		<? if(VIS_ITIL==1){?>
			<div class="form-group">
				  <label class="col-sm-1 control-label"><?= $vis_language['TXTLOCATION'];?></label>
				  <div class="col-sm-2">
				  <select class="form-control input-sm selectpicker" name="search_location" id="search_location">
					 <option value=""><? echo $vis_language['TXTSELECT']; ?></option>
					   <?	vis_show_subcategories($location_details,''); ?>
					
									</select>
					 <? // get_lists($location_details, 'location', $options);?>
				  </div>
			   </div>
               <? }?>
              
               <? if(count($level_details)!=0 && count($level_details)!=-1 && isset($level_details)) { ?>
        <div class="form-group">
              <label class="col-sm-1 control-label"><?= $vis_language['TXTTICKETLEVEL'];?></label>
              <div class="col-sm-2">
                 <?= get_lists($level_details, 'level', $options);?>
              </div>
           </div>
           <? }?>
         
           
		  </div>
		</div><!-- /.row -->
        
        <div class="row">
		  <div class="m-t m-b">
         
			<? if(count($category_details)!=0 && count($category_details)!=-1 && isset($category_details)) { ?>
			<div class="form-group">
				  <label class="col-sm-1 control-label"><?= $vis_language['TXTTICKETCATEGORY'];?></label>
				  <div class="col-sm-2">
					 <?= get_lists($category_details, 'category', $options);?>
				  </div>
			   </div>
              
			
			<div class="form-group">
				<label class="col-sm-1 control-label"><?= $vis_language['TXTTICKETSUBCATEGORY'];?></label>
				<div class="col-sm-2">
				  <?= get_lists($subcategory_details, 'subcategory', $options);?>
				</div>
			</div>

 			
			
			<div class="form-group">
				  <label class="col-sm-1 control-label"><?= $vis_language['TXTTICKETITEM'];?></label>
				  <div class="col-sm-2">
					 <?= get_lists($item_details, 'item', $options);?>
				  </div>
			   </div>
               <? }?>
              
			<div class="form-group">
				  <label class="col-sm-1 control-label"></label>
				  <div class="col-sm-2">
					 <label class="checkbox-inline i-checks">
					 <input type="checkbox" name="search1_internal_ticket" id="search1_internal_ticket"><i></i> <? echo $vis_language['TXTSHOWONLYINTERNALTICKETS']?>
					 </label>
				  </div>
			   </div>

			
		  </div>
		</div><!-- /.row -->
        
        <div class="row">
        <div class="m-t m-b">
        <div class="form-group">
				<div class="col-sm-12 text-right">
				  <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" class="btn btn-default pull-right m-r-sm" onclick="$('#vis_ticket_search_form').trigger('reset');$('.selectpicker').selectpicker('refresh');"><?= $vis_language['TXTCLEAR'];?></button>
				</div>
			</div>
        </div>
        </div><!-- /.row -->
        
		</form>
<script>
    $("#filter_lists").html('<a title="<?= $vis_language['TXTFILTERLIST']; ?>" class="btn btn-default btn-sm dropdown-toggle" href="javascript:void(0);" onclick="$(\'#vis_filter_list\').slideToggle();"><i style="font-size:10px;" class="vh vh-filter"></i></a>');
</script>