<?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 = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('/home/sites/mydomain.co.uk/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
  list($listingsRecords, $listingsMetaData) = getRecords(array(
    'tableName'   => 'listings',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $listingsRecord = @$listingsRecords[0]; // get first record

  // show error message if no matching record is found
  if (!$listingsRecord) { dieWith404("Record not found!"); }

?>
<!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>Website Favorites Plug-in DEMO</title>
<!-- favorites -->
  <script type="text/javascript" src="/cmsAdmin/plugins/websiteFavorites/websiteFavorites.js"></script>
  <script type="text/javascript" src="/cmsAdmin/3rdParty/jquery/jquery-1.3.2.min.js"></script>
  <script type="text/javascript">jQuery.noConflict();</script>
  <?php $GLOBALS['WSF_SCRIPTS_LOADED'] = true; ?>
  <!-- /favorites -->
  <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 Page 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 Records (Paste this where you want your records to be listed) -->
    <h1>For Sale Ads - Detail Page Viewer</h1>
      ID: <?php echo $listingsRecord['num'] ?><br/>
      Status: <?php echo $listingsRecord['status'] ?><br/>
      Top Deal: <?php echo $listingsRecord['top_deal'] ?><br/>
      Sold: <?php echo $listingsRecord['sold'] ?><br/>
      Category: <?php echo $listingsRecord['category'] ?><br/>
      Product: <?php echo $listingsRecord['product'] ?><br/>
      Manufacturer: <?php echo $listingsRecord['manufacturer'] ?><br/>
      Model: <?php echo $listingsRecord['model'] ?><br/>
      Currency: <?php echo $listingsRecord['currency'] ?><br/>
      List Price: <?php echo $listingsRecord['list_price'] ?><br/>
      Sale Price: <?php echo $listingsRecord['sale_price'] ?><br/>
      Age: <?php echo $listingsRecord['age'] ?><br/>
      Condition: <?php echo $listingsRecord['condition'] ?><br/>
      Warranty: <?php echo $listingsRecord['warranty'] ?><br/>
      Description: <?php echo $listingsRecord['description'] ?><br/>
      Ad Cost (&pound;): <?php echo $listingsRecord['ad_cost'] ?><br/>
      Expiry: <?php echo date("D, M jS, Y g:i:s a", strtotime($listingsRecord['paid_until'])) ?><br/>
      <!-- For date formatting codes see: http://www.php.net/date -->
      _link : <a href="<?php echo $listingsRecord['_link'] ?>"><?php echo $listingsRecord['_link'] ?></a><br/>


      <!-- STEP 2a: Display Uploads for field 'uploads' (Paste this anywhere inside STEP2 to display uploads) -->
        <!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
        <?php foreach ($listingsRecord['uploads'] as $upload): ?>
          <?php if ($upload['hasThumbnail']): ?>
            <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

          <?php elseif ($upload['isImage']): ?>
            <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

          <?php else: ?>
            <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

          <?php endif ?>
        <?php endforeach ?>
      <!-- STEP2a: /Display Uploads -->


      <hr/>
    <?php if (!$listingsRecord): ?>
      No record found!<br/><br/>
    <?php endif ?>
  <!-- /STEP2: Display Records -->

  <a href="<?php echo $listingsMetaData['_listPage']; ?>">&lt;&lt; Back to list page</a> - 
  <a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>

<!-- Website Favorites -->
<?php
    $tableOrTag = 'listings';       // Update with your section's table name
    $recordNum  = $record['num'];  // Update this with current record number
  ?>

  <div class="<?php wsf_cssClassFor($tableOrTag, $recordNum, 'add'); ?>"
       style="<?php wsf_displayStyleFor($tableOrTag, $recordNum, 'add'); ?>">
    <a href="#" onclick="<?php wsf_onClickFor($tableOrTag, $recordNum, 'add'); ?>">Add Favorite</a>
  </div>

  <div class="<?php wsf_cssClassFor($tableOrTag, $recordNum, 'remove'); ?>"
       style="<?php wsf_displayStyleFor($tableOrTag, $recordNum, 'remove'); ?>">
    <a href="#" onclick="<?php wsf_onClickFor($tableOrTag, $recordNum, 'remove'); ?>">Remove Favorite</a>
  </div>
</body>
</html>
