<?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 = 'cms/lib/viewer_functions.php';
  $dirsToCheck = array('/home/directory/cmsb.testdev.com/','','../','../../','../../../');
  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 record from 'accounts'
  list($accountsRecords, $accountsMetaData) = getRecords(array(
    'tableName'   => 'accounts',
    //'where'       => '', // load first record
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $accountsRecord = @$accountsRecords[0]; // get first record
  if (!$accountsRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load records from 'user_pages'
  list($user_pagesRecords, $user_pagesMetaData) = getRecords(array(
    'tableName'   => 'user_pages',
    'loadUploads' => true,
    'allowSearch' => false,
  ));

?>

<!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; }
    .instructions { border: 3px solid #000; background-color: #EEE; padding: 10px; text-align: left; margin: 25px}
  </style>
 </head>
<body>

  <!-- INSTRUCTIONS -->
    <div class="instructions">
      <b>Sample Detail Viewer - Instructions:</b>
      <ol>
        <?php /*><li style="color: red; font-weight: bold">Rename this file to have a .php extension!</li><x */ ?>
        <li><b>Remove any fields you don't want displayed.</b></li>
        <li>Rearrange remaining fields to suit your needs.</li>
        <li>Copy and paste code into previously designed page (or add design to this page).</li>
      </ol>
    </div>
  <!-- /INSTRUCTIONS -->

  <!-- STEP2: Display Record (Paste this where you want your record to appear) -->
    <h1>User Accounts - Detail Page Viewer</h1>
      <h2>Full Name: <?php echo htmlencode($accountsRecord['fullname']) ?></h2><br/>
  <!-- /STEP2: Display Record -->
    <hr/>
    
    <h1>User Pages - List Page Viewer</h1>
    <?php foreach ($user_pagesRecords as $record): ?>
    <?php if ($accountsRecord['num'] == $record['accountsNum']): ?>
      <h2>Title: <?php echo htmlencode($record['title']) ?></h2><br/>
      <b>View: <a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></b><br/>
      <hr/>
    <?php endif ?>
    <?php endforeach ?>

    <?php if (!$user_pagesRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>

  <a href="<?php echo $accountsMetaData['_listPage'] ?>">&lt;&lt; Back to list page</a>
  <a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>

<?php echo poweredByHTML(); ?>
</body>
</html>
