<?php
/* 
* Theme: PREMIUMPRESS CORE FRAMEWORK FILE
* Url: www.premiumpress.com
* Author: Mark Fail
*
* THIS FILE WILL BE UPDATED WITH EVERY UPDATE
* IF YOU WANT TO MODIFY THIS FILE, CREATE A CHILD THEME
*
* http://codex.wordpress.org/Child_Themes
*/
if (!defined('THEME_VERSION')) {	header('HTTP/1.0 403 Forbidden'); exit; }

global $CORE, $CORE_UI, $userdata, $filter_data; 

$taxonomy = $filter_data['tax'];

$cats = $GLOBALS['ncats'];
 

?>
 
<div class="tax_wrapper <?php echo $filter_data['wrap_css']; ?> <?php  if($filter_data['nav'] == 1){ ?>max_height_desc<?php echo $taxonomy; ?><?php } ?>">

<?php

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

$count = 1; 
foreach($cats as $cat){  
		
			//if($count > 200){ continue; }
			
			// DEFAULT GENDER FOR DATING THEME
			if( in_array(THEME_KEY, array("da")) && $taxonomy == "dagender" && !isset($_GET['tax-dagender']) ){ 
			
				 $_GET['tax-'.$taxonomy] = get_user_meta($userdata->ID,'da-seek2',true);
				 
			}
			
		 ?>

<div class="tax-div tax-val-<?php echo $cat->term_id; ?> <?php echo $filter_data['css']; ?>">
 
<label class="custom-control custom-checkbox  f-<?php echo $taxonomy."-".$cat->term_id; ?>">
	
    <input 
    type="checkbox" <?php if(isset($GLOBALS['flag-taxonomy-id']) && $GLOBALS['flag-taxonomy-id'] == $cat->term_id ){  ?>disabled<?php } ?> 
    value="<?php echo $cat->term_id; ?>" 
    name="catid[]" 
    class="custom-control-input customfilter f-<?php echo $taxonomy; ?>" 
    data-type="checkbox" 
    onclick="_hidesubcatsListing(<?php echo $cat->term_id; ?>);" 
   
    data-key="taxonomy" 
    data-value="<?php if($taxonomy == "listing" && isset($GLOBALS['flag-taxonomy-id']) && is_numeric($GLOBALS['flag-taxonomy-id'])){ echo "subcatid"; }else{ echo $taxonomy; } ?>-<?php echo $cat->term_id; ?>"
        <?php if(isset($_GET['tax-'.$taxonomy]) && $_GET['tax-'.$taxonomy] == $cat->term_id){ echo "checked=checked"; } ?>
    >

    <div class="custom-control-label" data-countkey="<?php echo $taxonomy; ?>-<?php echo $cat->term_id; ?>">
      
     
    
      <div class="d-flex justify-content-between">
      
          <div class="filtertxt">
            
        

          <?php echo $CORE->GEO("translation_tax_value", array($cat->term_id, $cat->name));  ?>
        
     
        
        </div>

    <div class="end-section d-flex justify-content-between">
          
          <div class="<?php if($filter_data['count'] != 1){ ?>addcount<?php } ?>" data-countkey="<?php echo $taxonomy; ?>-<?php echo $cat->term_id; ?>"><?php if($filter_data['count'] == 1 && $cat->count > 0){ ?><span class="badge badge-primary text-light"><?php echo $cat->count; ?></span> <?php } ?></div>
         

          <?php  if(in_array($taxonomy,array("listing")) && !isset($GLOBALS['search_settings']['show_3columns'])){ ?>
          <div>
            
          <a href="<?php echo str_replace("listing",get_option('premiumpress_customcategorypermalink'),get_term_link( $cat->term_id, $taxonomy)); ?>" class="ml-2 text-dark">
          <div ppt-icon-size="16"><?php echo $CORE_UI->icons_svg['add-circle']; ?></div>
          </a>

          </div>
          <?php }   ?> 

    </div>

      </div>   
      
      
     
    </div>

</label>

</div>



<?php
if($taxonomy == "listing"){

$subcats = get_terms( 'listing', 
  array( 
    'hide_empty'  => 1, 
    'parent'      => $cat->term_id, 
    "number"      => 20, 
    'orderby'     => 'count',
    'order'       => 'desc' 
  ),
);

if(!empty($subcats)){  ?>
	<div class="tax_wrapperxxxxxxxx subcats-<?php echo $cat->term_id; ?>" style="display:none;">
	<?php foreach($subcats as $subcat){  ?>


		<div class="tax-div tax-val-<?php echo $subcat->term_id; ?>">

<label class="custom-control custom-radio f-<?php echo $taxonomy."-".$subcat->term_id; ?> parent-cat-<?php echo $cat->term_id; ?>" onclick="_hideallotherchecks(<?php echo $cat->term_id; ?>, <?php echo $subcat->term_id; ?>)" >	
    <input 
    type="radio" <?php if(isset($GLOBALS['flag-taxonomy-id']) && $GLOBALS['flag-taxonomy-id'] == $subcat->term_id ){  ?>disabled<?php } ?> 
    value="<?php echo $subcat->term_id; ?>" 
    name="catid[]" 
    class="custom-control-input customfilter" 
    data-type="checkbox" 
    
    data-key="taxonomy" 
    data-value="subcatid-<?php echo $subcat->term_id; ?>"
        <?php if(isset($_GET['tax-'.$taxonomy]) && $_GET['tax-'.$taxonomy] == $subcat->term_id){ echo "checked=checked"; } ?>
    >

    <div class="custom-control-label" data-countkey="<?php echo $taxonomy; ?>-<?php echo $subcat->term_id; ?>"> 
      <div class="d-flex justify-content-between">      
          <div class="filtertxt"> <?php echo $CORE->GEO("translation_tax_value", array($subcat->term_id, $subcat->name));  ?> </div>
          
          <div class="addcount" data-countkey="<?php echo $taxonomy; ?>-<?php echo $subcat->term_id; ?>"><?php if($subcat->count > 0){ ?><span class="badge badge-primary text-light"><?php echo $subcat->count; ?></span> <?php } ?></div>
          
      </div>
    </div>
</label>

</div>

	<?php } ?>
	</div>
	<?php } } // end if is listing subcats ?>


<?php $count++; } ?>
 

</div>
<script>
function _hideallotherchecks(pcid, h){


  // UNCHECK ALL OTHER TICKED LISTING CATEGORIES
  jQuery('.f-<?php echo $taxonomy; ?>:not([data-value="listing-'+pcid+'"])').each(function(){
    jQuery(this).prop('checked',false); 
  });

  // ADD BACK THE CUSTOM CSS FOR THIS ONE
  jQuery('[data-value="subcatid-'+h+'"]').addClass('customfilter');

  // MAKE SURE IS CHECKED
  jQuery('[data-value="subcatid-'+h+'"]').prop('checked',true);

  // UPDATE
  _filter_update();

}
function _hidesubcatsListing(pcid){
	 
	if(jQuery('[data-value="listing-'+pcid+'"]').length > 0){

    // CLEAN OLD SELECTIONS
		jQuery(".parent-cat-"+pcid+"").each(function(){
     
			var h = jQuery(this).find("input").val();	
     	
			if(jQuery('[data-value="subcatid-'+h+'"]').length > 0){ 

        // UNCHECK SUB CAT BOX
        jQuery('[data-value="subcatid-'+h+'"]').prop('checked',false);

        // REMOVE CUSTOM CSS
        jQuery('[data-value="subcatid-'+h+'"]').removeClass('customfilter');

			} 
		
		});
		
	}

  // SHOW SUB CATS
  if(jQuery("[data-value='listing-"+pcid+"']").prop("checked") == true){
    jQuery('.subcats-'+pcid).show(100);
  }else{
    jQuery('.subcats-'+pcid).hide(100);
  } 

  // UPDATE RESULTS
  _filter_update();

}
 
</script>