<?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/matusikc/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($property_picksRecords, $property_picksMetaData) = getRecords(array(
    'tableName'   => 'property_picks',
  ));
 
 
  $query  = "SELECT * FROM `{$TABLE_PREFIX}property_picks`"; 
  $properties = mysql_query_fetch_all_assoc($query); 
   
  $valueField = "num"; 
  $labelField = "title"; 


  // process form
  if (@$_REQUEST['submitForm']) {

    // error checking
    $errorsAndAlerts = "";
    if (!@$_REQUEST['fullname'])                { $errorsAndAlerts .= "You must enter your full name!<br/>\n"; }
    if (!@$_REQUEST['email'])                   { $errorsAndAlerts .= "You must enter your email!<br/>\n"; }
    else if(!isValidEmail(@$_REQUEST['email'])) { $errorsAndAlerts .= "Please enter a valid email (example: user@example.com)<br/>\n"; }

    // send email user
    if (!$errorsAndAlerts) {
      $from     = $_REQUEST['email'];
      $fullname = $_REQUEST['fullname'];
      $to       = "tim@toledoh.com.au";
      $subject  = "Application form submitted from {$_SERVER['HTTP_HOST']}";
      $message  = <<<__TEXT__
You've received an email from the email form here:
http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}

Full name: {$_REQUEST['fullname']}
Message:   {$_REQUEST['message']}

The user who sent this message had the IP address {$_SERVER['REMOTE_ADDR']}.
__TEXT__;
      // Note: The above line must be flush left or you'll get an error
      // This is a PHP heredoc.  See: http://ca2.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc

      // send email
      $headers    = "Content-Type: text/plain; charset=UTF-8\n";
      $headers   .= "From: $fullname <$from>\n";
      $mailResult = @mail($to, $subject, $message, $headers);
      if (!$mailResult) { die("Mail Error: $php_errormsg"); }

      //
      $errorsAndAlerts = "Thanks!  We've sent your email.";
      $_REQUEST = array(); // clear form values
    }

  }

?>
<!doctype html>
<html>
<head>
<title>Think Matusik - Property Picks</title>
<meta charset="utf-8" />

<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<link href="assets/css/propertyPicks.css" rel="stylesheet" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Terminal+Dosis' rel='stylesheet' type='text/css' />
</head>
<body>
<div id="pagewidth" >
	<div id="wrapper" class="clearfix">
		<div id="twocols"> 
			<div id="maincol">
			<?php foreach ($property_picksRecords as $record): ?>
            
            <div class="propertySection">
                <?php foreach ($record['image'] as $upload): ?>
                    <img  class="hero" src="<?php echo $upload['urlPath'] ?>" width="300" >
                <?php endforeach ?>
              <h1><?php echo $record['title'] ?></h1>
              <?php echo $record['summary'] ?>
              <ul>
              <li><a href="<?php echo $record['url'] ?>" target="_blank" >Visit Website</a></li>
              <li><a href="mailto:<?php echo $record['email'] ?>" >Email</a></li>
              </ul>
              <div class="clearfix"></div>
                  <!--KPI's -->
                  <table width="100%" cellpadding="10" class="kpis"><tr valign="top">
                      <td><span class="kpi">KPI 1</span><br><span class="kpiValue"><?php echo $record['kpi_1'] ?></span></td>
                      <td><span class="kpi">KPI 2</span><br><span class="kpiValue"><?php echo $record['kpi_2'] ?></span></td>
                      <td><span class="kpi">KPI 3</span><br><span class="kpiValue"><?php echo $record['kpi_3'] ?></span></td>
                      <td><span class="kpi">KPI 4</span><br><span class="kpiValue"><?php echo $record['kpi_4'] ?></span></td>
                      <td><span class="kpi">KPI 5</span><br><span class="kpiValue"><?php echo $record['kpi_5'] ?></span></td>
                      <td><span class="kpi">KPI 6</span><br><span class="kpiValue"><?php echo $record['kpi_6'] ?></span></td>
                      <td><span class="kpi">KPI 7</span><br><span class="kpiValue"><?php echo $record['kpi_7'] ?></span></td>
                      <td><span class="kpi">KPI 8</span><br><span class="kpiValue"><?php echo $record['kpi_8'] ?></span></td>
                      <td><span class="kpi">KPI 9</span><br><span class="kpiValue"><?php echo $record['kpi_9'] ?></span></td>
                      <td><span class="kpi">KPI 10</span><br><span class="kpiValue"><?php echo $record['kpi_10'] ?></span></td>
                  </tr></table>
        
            </div>
			<?php endforeach ?>            
            </div>
			<div id="rightcol">
                <div class="rightPanel">
                    <h2>MONEY BACK</h2>
                    <p>This is a message saying that if they book through us, (or Acuity) they get...</p>
<form method="POST" action="">
<input type="hidden" name="submitForm" value="1" />

<?php if (@$errorsAndAlerts): ?>
  <div class="sideAlert""><br/>
    <?php echo $errorsAndAlerts; ?>
  </div>
<?php endif ?>
  <?php foreach ($properties as $property): ?>
    <input type="checkbox" id="<?php echo $property[$labelField];?>">
    <label for="<?php echo $property[$labelField];?>"><?php echo $property[$labelField];?></label><br />
  <?php endforeach ?> 

<input type="hidden" name="fullname" value="TEST" /></p>
<input type="hidden" name="email" value="tim@forrest.id.au" /></p>
<p>Comments<br />
<textarea name="message" ><?php echo htmlspecialchars(@$_REQUEST['message']); ?></textarea></p>

<p><input type="submit" name="submit" value="Send" class="buttom"></p>


</form>

                    </div>
                <div class="rightPanel">
                    <h2>ADVERTISMENT</h2>
                    <p>This is a paid ad...</p>
                </div>
                <div class="rightPanel">
                    <h2>ADVERTISMENT</h2>
                    <p>This is a paid ad...</p>
                </div>
            </div>
	  </div> 
  </div>
</div>
</body>
</html>