<?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/colourp1/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($categoriesRecords, $categoriesMetaData) = getRecords(array( 
    'tableName'   => 'categories', 
  )); 
  
  $categoriesRecord = @$categoriesRecords[0]; // get first record 
   
  $title = ""; 
  foreach ($categoriesRecords as $category) { 
    if($category['num'] == @$_REQUEST['main_category']) { 
      $title = $category['title']; 
    } 
  } 
  // show error message if no matching record is found
  if (!$categoriesRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;
  }

  list($product_subcategoriesRecords, $product_subcategoriesMetaData) = getRecords(array(
    'tableName'   => 'product_subcategories',
	'orderBy'     => 'title',
  ));

  list($product_detailsRecords, $product_detailsMetaData) = getRecords(array(
    'tableName'   => 'product_details',
  ));

?>
<!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>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<TITLE><?php echo $title; ?></TITLE>
<LINK HREF="styles.css" REL="stylesheet" TYPE="text/css">
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript"><!--

var image = new Array();

image[0] = 'images/background-01.jpg' ;
image[1] = 'images/background-02.jpg' ;
image[2] = 'images/background-03.jpg' ;
image[3] = 'images/background-04.jpg' ;
image[4] = 'images/background-05.jpg' ;

var index = Math.floor(Math.random() * image.length);
document.write('<style type="text/css"> td.titleLower { background-image: url('+ image[index] +') } </style>');
//-->
</SCRIPT>
</HEAD>

<BODY>
<TABLE WIDTH="1000" BORDER="0" ALIGN="CENTER" CELLPADDING="0" CELLSPACING="0">
  <TR>
    <TD COLSPAN="7" CLASS="tdWhite"><?php require_once('_include-masthead.php'); ?></TD>
  </TR>
  <TR>
    <TD CLASS="titleLower" COLSPAN="7" ALIGN="LEFT" VALIGN="TOP"><TABLE WIDTH="1000" HEIGHT="170" BORDER="0" CELLPADDING="0" CELLSPACING="0">
      <TR>
        <TD CLASS="tdLowerHeadlineCell"><H1><?php echo $title; ?></H1></TD>
      </TR>
    </TABLE></TD>
  </TR>
  <TR>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="20" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="176" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="20" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="499" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="20" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="245" HEIGHT="17"></TD>
    <TD CLASS="tdWhite"><IMG SRC="images/single-pixel.gif" WIDTH="20" HEIGHT="20"></TD>
  </TR>
  <TR>
    <TD CLASS="tdWhite">&nbsp;</TD>
    <TD CLASS="tdWhite"><?php require_once('_include-plants-nav.php'); ?></TD>
    <TD CLASS="tdWhite">&nbsp;</TD>
    <TD CLASS="tdWhite">  <p><a href="plants.php">&laquo; Back</a></p><hr />
          <?php foreach ($product_subcategoriesRecords as $record): ?>
		  <table width="499" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td>      <!-- STEP 2a: Display Uploads for field 'main_image' (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 ($record['main_image'] as $upload): ?>
          <?php if ($upload['hasThumbnail']): ?>
            <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />

          <?php elseif ($upload['isImage']): ?>
          <?php else: ?>
          <?php endif ?>
        <?php endforeach ?>
      <!-- STEP2a: /Display Uploads --></td>
          <td>&nbsp;</td>
          <td>      <h2><a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a></h2>
<!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
    <ul><?php foreach ($product_detailsRecords as $record): ?>
     <li>
       <a href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
             <?php endforeach ?>
         
              <?php if (!$product_detailsRecords): ?>
       </li>
    <?php endif ?></ul>
  <!-- /STEP2: Display Records --></td>
        </tr>
        <tr>
          <td><img src="images/single-pixel.gif" width="140" height="10" /></td>
          <td><img src="images/single-pixel.gif" width="10" height="10" /></td>
          <td><img src="images/single-pixel.gif" width="349" height="10" /></td>
        </tr>
      </table>    <?php endforeach ?>

    <?php if (!$product_subcategoriesRecords): ?>
      <p>No records were found!</p>
    <?php endif ?>

</TD><TD CLASS="tdWhite">&nbsp;</TD>
    <TD COLSPAN="2" CLASS="tdWhite"><?php require_once('_include-right-column.php'); ?></TD>
  </TR>
  <TR>
    <TD CLASS="tdWhite">&nbsp;</TD>
    <TD COLSPAN="5" CLASS="tdWhiteRuleTop"><?php require_once('_include-footer.php'); ?></TD>
    <TD CLASS="tdWhite">&nbsp;</TD>
  </TR>
</TABLE>
</BODY>
</HTML>
