<?php
$region_arr = array();
$zone_arr = array();
	/*echo $f_con;
	echo "<br><br>";
	echo "User type=>".$user_type;
	echo "<br><br>";
	echo "dealer_code=>".$dealer_code;
	echo "<br><br>";
	echo $_SESSION['zone'];*/
	//echo $_SESSION['dealer_code_Wice'];
?>
<li class="app-sidebar__heading" style="color:#003e80 !important">Filters</li>
    <input type="hidden" value="" id="cond">
    <div class="btn-actions-pane-right">
        <div role="group" class="btn-group-sm btn-group text-center">
            <button class="btn-transition btn btn-outline-success btn-sm" onclick="applyF(1)" style="margin-left:50px">&nbsp;&nbsp;Apply&nbsp;&nbsp;</button>
            <button class="btn-transition btn btn-outline-danger btn-sm" onclick="resetFilters()" style="margin-left:5px">&nbsp;&nbsp;Reset&nbsp;&nbsp;</button>
        </div>
    </div>
    
    <fieldset style="width:244px;padding:5px;border:1px solid blue !important" id="timeField">
        <legend style="font-size: 12px"><b style="font-size: 14px">Time Period</b></legend>
        <select id="time" class="form-control" multiple="multiple" style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important">
            <?php 
			$k=1;
                foreach($time as $key => $value){
					if(sizeof($time)==$k){
                    echo '<option value="'.$value.'" data-name="'.$key.'" selected>'.$key.'</option>';
					}
					else{
					echo '<option value="'.$value.'" data-name="'.$key.'">'.$key.'</option>';	
					}
					$k++;
                }
            ?>
        </select>
    </fieldset>
    
    
    <fieldset style="width:244px;border:1px solid blue !important" id="zoneField">
        <legend style="font-size: 12px"><b style="font-size: 14px">Zone</b></legend>
		<?php if($user_type==1){	?>
			<select id="zone" class="form-control" data-type="<?php echo $user_type; ?>" multiple="multiple" style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important">	
			
		<?php		
		} 
		else{ ?>
			<select id="zone" class="form-control" data-type="<?php echo $user_type; ?>"  style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important">	
			
			<?php 
		}
			$query=mysqli_query($conn,"SELECT DISTINCT `Zone` FROM Q1 WHERE $f_con `Zone`!='' and  `status` = '3' ORDER BY `Zone` ASC "); 
                if(mysqli_num_rows($query) >0){
                    while($row = mysqli_fetch_array($query)){
						if($user_type>=999){
						echo '<option value="'.$_SESSION['zone'].'" selected >'.$_SESSION['zone'].'</option>';	
						}
						else if($user_type==1){
						echo '<option value="'.$row['Zone'].'">'.$row['Zone'].'</option>';	
						}
						else{
						echo '<option value="'.$row['Zone'].'" selected>'.$row['Zone'].'</option>';	
						}
						
                    }
                }
            ?>
        </select>
    </fieldset>

    <fieldset style="width:244px;border:1px solid blue !important;display:none" id="regionField">
        <legend style="font-size: 12px"><b style="font-size: 14px">Region</b></legend>
		<?php 
		if(($user_type>=7 and $user_type<=24) or $user_type==999)
		{				
		?>
        <select id="region" class="form-control"  style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important">

			<?php
		}
		else{			
			?> 
		<select id="region" class="form-control" multiple="multiple" style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important"> 
		 <?php
		}	
			
			if($user_type==999){
				
				echo "<option value='".$_SESSION['Region']."' selected>".$_SESSION['Region']."</option>";
			}
			?>
			
			
			
        </select>
    </fieldset>

    <fieldset style="width:244px;border:1px solid blue !important;display:none" id="maindealerField">
        <legend style="font-size: 12px"><b style="font-size: 14px">Main Dealer</b></legend>
        <select id="maindealer" class="form-control" style="font-size:0.8rem !important" onchange="maindealerLogicF();">
				<?php
				if($user_type==999){
				echo "<option value='".$_SESSION['main_Dealer_name']."' selected>".$_SESSION['main_Dealer_name']."</option>";
				}
				else{
				?>

		  <option value="0">-SELECT MAIN DEALER-</option>
		  <?php
				}
		  ?>
        </select>
    </fieldset>

    <fieldset style="width:244px;border:1px solid blue !important;display:none" id="dealerField">
        <legend style="font-size: 12px"><b style="font-size: 14px">Dealer</b></legend>
        
		<select id="dealer" class="form-control"  style="font-size:0.8rem !important">
			<?php
				if($user_type==999){
					if($_SESSION['dealer_code_Wice']!='0'){
						echo '<option value="'.$_SESSION['dealer_code_Wice'].'" selected>'.$_SESSION['dealer_code_Wice'].'</option>';
					}
					else{
						echo ' <option value=0>-SELECT DEALER-</option>';
					}
				}
			else{	
		?>
		   <option value=0>-SELECT DEALER-</option>
		   <?php
			}
		   ?>
        </select>
    </fieldset>
    
    <fieldset style="width:244px;border:1px solid blue !important;display:none" id="stateField">
        <legend style="font-size: 12px"><b style="font-size: 14px">State</b></legend>
        <select id="state" class="form-control" multiple="multiple" style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important" onchange="stateLogicF();">
            
        </select>
    </fieldset>
    <fieldset style="width:244px;border:1px solid blue !important;display:none" id="cityField">
        <legend style="font-size: 12px"><b style="font-size: 14px">City</b></legend>
        <select id="city" class="form-control" multiple="multiple" style="height:35px;margin-top:-10px;font-size:0.8rem !important;border: 1px solid grey !important">
            
        </select>
    </fieldset>
    
                                
                               
                                
                                