<?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/blakem/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 record from 'products'
  list($productsRecords, $productsMetaData) = getRecords(array(
    'tableName'   => 'products',
    'where'       => whereRecordNumberInUrl(0),
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $productsRecord = @$productsRecords[0]; // get first record
  if (!$productsRecord) { dieWith404("Record not found!"); } // show error message if no record found

  // load record from 'contact_person'
  list($contact_personRecords, $contact_personMetaData) = getRecords(array(
    'tableName'   => 'contact_person',
    'where' 	  => "num = '". intval($productsRecord['rep']) ."'" , 
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  
  $contact_personRecord = @$contact_personRecords[0]; // get first record
   
  // load record from 'snippets'
  list($snippetsRecords, $snippetsMetaData) = getRecords(array(
    'tableName'   => 'snippets',
    'where'       => '', // load first record
    'loadUploads' => true,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $snippetsRecord = @$snippetsRecords[0]; // get first record
  if (!$snippetsRecord) { dieWith404("Record not found!"); } // show error message if no record found  

?>
<html>
	<head>
		<title><?php echo $productsRecord['make'] ?> | <?php echo htmlencode($productsRecord['model']) ?></title>
		<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,400italic,600' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" type="text/css" href="css/kubePrint.css" />
		<link rel="stylesheet" type="text/css" href="css/print.css" />
		
	</head>
	<body>
	<div id="header" class="row">
		<div class="half logo"><img src="images/blake_machinery_black.png" alt="blake_machinery_black" width="250" height="81" /></div>
		<div class="half header">
			<h1><?php echo $productsRecord['make'] ?> | <?php echo htmlencode($productsRecord['model']) ?></h1>
			<p><span class="price"><?php echo $productsRecord['total_price_ex_gst'] ?></span><span> + GST</span></p>
		</div>
	</div>
	<div id="images" class="row">
		<?php $imageCount=0 ?>
		<?php foreach ($productsRecord['images'] as $index => $upload): ?>
			<?php $imageCount++ ?>
			<div class="half"><img src="<?php echo $upload['urlPath'] ?>"></div>
			<?php if ($imageCount==2): ?><?php break ?>
			<?php endif ?> 
		<?php endforeach ?>
	</div>
	<div id="main" class="row">
		<div class="third sidePanel">
			<?php foreach ($contact_personRecord['photo'] as $index => $upload): ?>
			<img src="<?php echo $upload['urlPath'] ?>" alt="<?php echo ($contact_personRecord['title']) ?> <?php echo ($contact_personRecord['surname']) ?>" class="headShot">
			<?php endforeach ?>
			
			<p class="leadIn">For inquiries contact:</p>
			<h4><?php echo ($contact_personRecord['title']) ?> <?php echo ($contact_personRecord['surname']) ?></h4>
			<p><?php echo ($contact_personRecord['position']) ?><br />
			m <?php echo ($contact_personRecord['mobile']) ?><br />
			e <?php echo ($contact_personRecord['email']) ?></p>

		</div>
		<div class="detail">
			<table class="striped">
				<tbody>
					<tr><td>Stock Number:</td><td><?php echo htmlencode($productsRecord['stock_number']) ?></td><td>
					<tr><td>Year:</td><td><?php echo htmlencode($productsRecord['year']) ?></td><td>
					<tr><td>Serial No.:</td><td><?php echo htmlencode($productsRecord['serial_no']) ?></td><td>
					<tr><td>Engine No.:</td><td><?php echo htmlencode($productsRecord['engine_no']) ?></td><td>
					<tr><td>Hours:</td><td><?php echo htmlencode($productsRecord['hours']) ?></td><td>
					<tr><td>Engine Type:</td><td><?php echo htmlencode($productsRecord['engine']) ?></td><td>
					<tr><td>Transmission Type:</td><td><?php echo htmlencode($productsRecord['transmission']) ?></td><td>
					<tr><td>Steer Tyre Condition:</td><td><?php echo htmlencode($productsRecord['steer_tyre_condition']) ?></td><td>
					<tr><td>First Drive Tyre Condition:</td><td><?php echo htmlencode($productsRecord['first_drive_tyre_condition']) ?></td><td>
					<tr><td>Second Drive Tyre Condition:</td><td><?php echo htmlencode($productsRecord['second_drive_tyre_condition']) ?></td><td>
					<tr><td>Tyre Size:</td><td><?php echo htmlencode($productsRecord['tyre_size']) ?></td><td>
					<tr><td>Undercarriage Condition:</td><td><?php echo htmlencode($productsRecord['undercarriage']) ?></td><td>
					<tr><td>Cabin:</td><td><?php echo htmlencode($productsRecord['cabin']) ?></td><td>
					<tr><td>Paint:</td><td><?php echo htmlencode($productsRecord['paint']) ?></td><td>
					<tr><td>Machine Features:</td><td><?php echo $productsRecord['machine_features']; ?></td><td>
					<tr><td>Comments:</td><td><?php echo htmlencode($productsRecord['comments']) ?></td><td>
						</tbody>	
			</table>
		</div>
	</div>
	<div id="footer" class="row">
		<p>327 Mons Road, Forest Glen QLD 4556 P. (07) 5445 4433 F. (07) 5450 1460<br />sales@blakemachinery.com.au www.blakemachinery.com.au</p>
	</div>
	</body>
</html>
