<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php 

  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/content/d/w/e/dwelling/html/clients/cvrs/','','../','../../','../../../');
  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 'faq_questions'
  list($faq_questionsRecords, $faq_questionsMetaData) = getRecords(array(
    'tableName'   => 'faq_questions',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

  // load records from 'faq_topics'
  list($faq_topicsRecords, $faq_topicsMetaData) = getRecords(array(
    'tableName'   => 'faq_topics',
    'loadUploads' => true,
    'allowSearch' => false,
  ));
?>
<!DOCTYPE HTML>
<html class="no-js">
<head>
	<title>FAQ Test</title>
</head>
<body class="single-post header-style2">



      Select a topic:<br>
    <?php foreach ($faq_topicsRecords as $record): ?>
      <a href="#<?php echo htmlencode($record['num']) ?>" target="_self"><?php echo htmlencode($record['title']) ?></a><br/>
      <?php if ($record['description']): ?><?php echo htmlencode($record['description']) ?><br/><?php endif ?>
    <?php endforeach ?>

<br>
<hr>
<br>



<?php $faqsTopicsToRecords= array_groupBy($faq_questions, 'topics:label', true); ?>

<?php foreach ($faqsTopicsToRecords as $topic => $records): ?>
  <h1><?php echo htmlencode($topic) ?></h1>

  <?php foreach ($records => $record): ?>
    <p>
      <?php echo $record['question'] ?><br>
      <?php echo $record['answer'] ?><br><br>
    </p>
  <?php endforeach ?>

<?php endforeach ?>

    

</body>
</html>