<?  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'); 
					}
		}
		
    }	
	
?>

 <?   $paging_list='';
        for($i=0;$i<$page_count;$i++) $paging_list.='<option value="'.$i.'" '.(($ticket_info['page']==$i)?'selected="selected"':'').'>'.($i+1).'</option>';  ?>
	  
<div id="alert_div" class="m-t container alert text-center alert-danger" style="display:none">Please select any field</div>
<section  id="vis_filter_list">
   
		<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" for="sm"><?= $vis_language['TXTSUBJECT'];?></label>
				  <div class="col-sm-11">
				  <input class="form-control input-sm" type="text" name="search_subject" id="search_subject"/>
				 </div>
		    </div>
		</div>
    </div>
	   
	 <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($statuslist, 'status', $options);?>
				</div>
			</div>
			<?php if(VIS_HEAD_MENU_ASSIGNEDTO==1){ ?>
			<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(isset($module_setting['vis_show_priority']) && $module_setting['vis_show_priority']==2): ?>
			<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>
			<?endif;?>
            
		
		 <? if(isset($module_setting['vis_show_tickettype']) && $module_setting['vis_show_tickettype']==2): ?>
			 <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>
			<? endif; ?>
			
            <? if(isset($module_setting['vis_show_location']) && $module_setting['vis_show_location']==2): ?>
			<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>
               <? endif;?>
	     <? if(isset($module_setting['vis_show_level']) && $module_setting['vis_show_level']==2): ?>
		<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>
		 <?endif;  ?>
		  
		  <? if(isset($module_setting['vis_show_category']) && $module_setting['vis_show_category']==2): ?>
			<div class="form-group">
				  <label class="col-sm-1 control-label"><?= $vis_language['TXTCATEGORY'];?></label>
				  <div class="col-sm-2">
					 <?= get_lists($category_details, 'category', $options);?>
				  </div>
			 </div>
              <? endif; ?>
             
	
              <? if(isset($module_setting['vis_show_subcategory']) && $module_setting['vis_show_subcategory']==2): ?>
			<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>
			<?endif; ?>

 			
			 <? if(isset($module_setting['vis_show_item']) && $module_setting['vis_show_item']==2): ?>
			<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>
			<?endif; ?>
			 
		     </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="vis_apply_filter();"><?= $vis_language['TXTSEARCH'];?></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 -->
	
		
	 </section>
	

<script>
    $("#filter_lists").html('<a class="link" href="javascript:void(0);" onclick="$(\'#vis_ticket_list\').slideToggle();"><?= $vis_language['TXTFILTERLIST']; ?></a>');
</script>

<script>

/*function vis_apply_filter(vis_page){
	    
	    if($("#search_subject").val()=="" && $("#search_department").val()=="" && $("#search_status").val()=="" && $("#search_priority").val()=="" && $("#search_staff").val()=="" && $("#search_type").val()=="" && $("#search_category").val()=="" && $("#search_subcategory").val()=="" && $("#search_item").val()=="" && $("#search_level").val()=="" && $("#search_location").val()=="")
		{
		   $("#alert_div").show();
		 	return false;
		}
		else{
			 $("#alert_div").hide();
		    }
        var data = {'vis_filter_enable': 1,'vis_page':vis_page, 'search_domain':$("#search_domain").val(),'search_subject':$("#search_subject").val(), 'search_dept':$("#search_department").val(), 'search_status':$("#search_status").val(),'search_priority':$("#search_priority").val(),'search_owner':$("#search_staff").val(),'search_type':$("#search_type").val(),'search_flag':$("#search_flag").val(),'search_category':$("#search_category").val(),'search_subcategory':$("#search_subcategory").val(),'search_item':$("#search_item").val(),'search_level':$("#search_level").val(),'search_location':$("#search_location").val() };
	 
	$.ajax({
		url: 'index.php?vis_module=ticket&vis_operation=view_ticket',
		data: data,
		type: "POST",
		success: function(data) {
			   $("#vis_ticket_list").html(data);
						$('.filtab').removeClass('btn-primary');
						$('.filtab').addClass('btn-default');
						$('#fitertb').removeClass('btn-default');
						$('#fitertb').addClass('btn-primary');
          
		  },
		  error: function(xhr, ajaxOptions, thrownError) {$("#vis_global_msg_div").visInterface("load_global_message", "Error: "+xhr.status+" - "+thrownError);}
	     });
	   
    } */
	
	

</script>
<script type="text/javascript">
$(document).on('click','.selectpicker',function(e){
	var winwdt=$(window).width();
	if(winwdt <810){
var lilen=$(this).next('#lst').children('ul').children().length;
$(this).next('#lst').css('overflow-y','scroll');
		if(lilen <3 && lilen>1)
		{$(this).next('#lst').css('min-height',(40*parseInt(lilen))+'px');
		}else{		$(this).next('#lst').css('min-height','120px');}
	}
	});
</script>

