<?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/toledoh1/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 from 'categories'
list($categoriesRecords, $categoriesMetaData) = getRecords(array(
'tableName' => 'categories',
'loadUploads' => false,
'allowSearch' => false,
));

// load records from 'links'
list($linksRecords, $linksMetaData) = getRecords(array(
'tableName'   => 'links',
'loadUploads' => true,
'allowSearch' => false,
));


$categories = mysql_select ('categories');
//make the array key the 'num' field
$categoriesSorted = array_groupBy($categories,'num');


?><ul class="block-four">
<?php foreach ($linksRecords as $record): ?>
      <li><a href="<?php echo htmlencode($record['url']) ?>" target="_blank"><?php echo htmlencode($record['title']) ?></a></li>
<?php endforeach ?>
</ul>

<ul><?php foreach ($categoriesRecords as $category): ?>
<li>
<?php echo htmlencode($category['title']) ?>
<ul><?php foreach ($linksRecords as $record): ?>
<?php if(in_array($category['num'], $record['category:values'])): ?>
<li>
<a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a>
</li>
<?php endif ?>
<?php endforeach ?>
</ul>
</li>
<?php endforeach ?> 