<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/sites/oxfordlabs.co.uk/public_html/','','../','../../','../../../');
  foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
  if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

  // load records
  list($categoryRecords, $categoryMetaData) = getRecords(array(
    'tableName'   => 'categories',
  ));

// get listings records 
 list( $listingsRecords, $listingsMetaData ) = getRecords(array( 
       'tableName'       =>   'listings', 
       'allowSearch'     =>    false, 
      )); 
  
  //talling the number of listings for each category 
  $categoryNumToListingsCount = array(); 
   
  foreach($listingsRecords as $listing){ 
     
    @$categoryNumToListingsCount[ $listing['category'] ] ++;  
  }

?>


<?php include "include_header.php"; ?>
			
<h2>All Categories</h2>

<!-- STEP2: Display Records (Paste this where you want your records to be listed) --> 
    <ul> 
    <?php foreach ($categoryRecords as $record): ?> 
	<?php if(!@$categoryNumToListingsCount [$record['num']]) { continue; } ?>
			<?php echo $record['_listItemStart'] ?>  
      <a href="searchResults.php?categories=<?php echo $record['num'] ?>"><?php echo $record['name'] ?></a> 
      <?php echo $record['_listItemEnd'] ?>  
    <?php endforeach; ?> 
    <?php if (!$categoryRecords): ?> 
      <li>No records were found!</li> 
    <?php endif ?> 
  	</ul> 
  <!-- /STEP2: Display Records -->

<?php include "include_footer.php"; ?>
