<?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 */
  require_once "C:/wamp/www/cmsbuilder_1_33_build1/cmsAdmin/lib/viewer_functions.php";

  list($issuesRecords, $issuesMetaData) = getRecords(array(
    'tableName'   => 'issues',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $issuesRecord = @$issuesRecords[0]; // get first record

  // get year and month from selected Issue
  $year  = date('Y', strtotime( $issuesRecord['date'] ) );
  $month = date('n', strtotime( $issuesRecord['date'] ) );
  
  // search for articles matching that year and month
  list($articlesRecords, $articlesMetaData) = getRecords(array(
    'tableName'   => 'articles',
    'where'       => "YEAR(date)={$year} AND MONTH(date)=${month}",
  ));

  // show error message if no matching record is found
  if (!$issuesRecord) {
    print "Record not found!";
    exit;
  }

?>
<!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>

  <!-- Issue Details -->
    <h1>Issues - Detail Page Viewer</h1>
      Record Number: <?php echo $issuesRecord['num'] ?><br/>
      Title: <?php echo $issuesRecord['title'] ?><br/>
      Content: <?php echo $issuesRecord['content'] ?><br/>
      Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($issuesRecord['date'])) ?><br/>
      <!-- For date formatting codes see: http://www.php.net/date -->
      _link : <a href="<?php echo $issuesRecord['_link'] ?>"><?php echo $issuesRecord['_link'] ?></a><br/>

      <hr/>
    <?php if (!$issuesRecord): ?>
      No record found!<br/><br/>
    <?php endif ?>
  <!-- /Issue Details -->

  <!-- Matching Articles -->
    <h1>Articles in this issue</h1>
    <?php foreach ($articlesRecords as $record): ?>
      Record Number: <?php echo $record['num'] ?><br/>
      Title: <?php echo $record['title'] ?><br/>
      Content: <?php echo $record['content'] ?><br/>
      Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($record['date'])) ?><br/>
      <!-- For date formatting codes see: http://www.php.net/date -->
      _link : <a href="<?php echo $record['_link'] ?>"><?php echo $record['_link'] ?></a><br/>

      <hr/>
    <?php endforeach; ?>

    <?php if (!$articlesRecords): ?>
      No records were found!<br/><br/>
    <?php endif ?>
  <!-- /Matching Articles -->

  <a href="<?php echo $issuesMetaData['_listPage']; ?>">&lt;&lt; Back to issue list page</a> - 
  <a href="mailto:?subject=<?php echo thisPageUrl() ?>">Email this Page</a>
</body>
</html>
