<?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 = 'cmsb/lib/viewer_functions.php';
  $dirsToCheck = array('/home/homevaluere/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 'resource_links_docs'
  list($resource_links_docsRecords, $resource_links_docsMetaData) = getRecords(array(
    'tableName'   => 'resource_links_docs',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
  
  $records = array_groupBy($resource_links_docsRecords, 'category');

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title></title>
  <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
  <style type="text/css">
    body          { font-family: arial; }
  </style>
 </head>
<body>


   <? foreach($records as $categoryLabel => $recordsByCategory): // HTML for the category label?>
    <h4><p><?php echo ($categoryLabel['lables']) ?></p></h4>
   <? foreach($recordsByCategory as $record): ?>
    <ul>
	<li><?php echo ($record['title']) // HTML for each record ?></li>
    </ul>
   <? endforeach ?>
   <hr/>
   <? endforeach ?>



    <h1>Regular Viewer Code</h1>
    <?php foreach ($resource_links_docsRecords as $record): ?>
    
      Record Number: <?php echo htmlencode($record['num']) ?><br/>
      Title: <?php echo htmlencode($record['title']) ?><br/>
      Category (values): <?php echo join(', ', $record['category:values']); ?><br/>
      Category (labels): <?php echo join(', ', $record['category:labels']); ?><br/>
      Link: <?php echo htmlencode($record['link']) ?><br/>

      <hr/>
    <?php endforeach ?>

    <?php if (!$resource_links_docsRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>

</body>
</html>
