<?php
  require_once "cmsAdmin/lib/viewer_functions.php";
  if (!@$GLOBALS['WEBSITE_MEMBERSHIP_PLUGIN']) { die("You must activate the Website Membership plugin before you can access this page."); }
  if (!$CURRENT_USER) { websiteLogin_redirectToLogin(); }

  // load product
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
  ));
  $product = @$productsRecords[0]; // get first record
  if (!$product) { header("HTTP/1.0 404 Not Found");  die("Record not found!"); }

  // display PDF
  $filepath = "cmsAdmin/uploads/" . $product['uploads'];
  if      (!$product['uploads']) { die("No uploads defined for this record!"); }
  else if (!is_file($filepath)) { die("PDF file is missing!"); }

  $data = file_get_contents($filepath);
  if (!$data) { die("Couldn't load data for file!"); }
  header("Content-type: application/octet-stream");
  print $data;
  exit;

?>
