<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
  $libraryPath = 'cms/lib/viewer_functions.php';
  $dirsToCheck = array('/home/turnerhopk/turnerhopkins.co.nz/','','../','../../','../../../');
  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($pagesRecords, $pagesMetaData) = getRecords(array(
    'tableName'   => 'pages',
    'where'       => whereRecordNumberInUrl(1),
    'limit'       => '1',
	'useSeoUrls'	=> true,
	// 'debugSql' =>'true',
  ));
  $pagesRecord = @$pagesRecords[0]; // get first record

  // load records
  list($settingsRecords, $settingsMetaData) = getRecords(array(
    'tableName'   => 'settings',
    'limit'       => '1',
  ));
  $settingsRecord = @$settingsRecords[0]; // get first record
  
  // show error message if no matching record is found
  if (!$pagesRecord) {
    header("HTTP/1.0 404 Not Found");
    print "Record not found!";
    exit;
  }

?>

<!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=utf-8" />
<title><?php if ($pagesRecord['title']): ?><?php echo htmlspecialchars($pagesRecord['title']) ?><?php elseif ($pagesRecord['heading']): ?><?php echo htmlspecialchars($pagesRecord['heading']) ?><?php endif ?> - <?php echo htmlspecialchars($settingsRecord['title']) ?></title>
<?php if ($pagesRecord['meta_desc']): ?><meta name="description" content="<?php echo htmlspecialchars($pagesRecord['meta_desc']) ?>" /><?php endif ?>

<link rel="canonical" href="<?php echo $settingsRecord['website_address'] ?><?php echo strtolower($pagesRecord['url']); ?>-<?php echo $pagesRecord['num'] ?>/" />
<link href="/library/css/style-v2.css" rel="stylesheet" type="text/css" />
<? include("library/inc/head.php"); ?>
</head>

<body>
<a name="top" id="top"></a>
<div class="wrapper">
<? include("library/inc/header.php"); ?>

<div class="innerwrapper clearfix">

<div class="main">
    <div class="content">
		<?php  
        // load records for breadcrumb 
           list($pagesRecords, $pagesMetaData) = getCategories(array(    
           'tableName'   => 'pages',  
           'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()   
		   'debugSql' =>'true',
        ));  
        ?>  
		<?php 
		  $selectedCategory=$pagesRecord['num'];
          $categoriesRecordsByNum = array_combine(array_pluck($pagesRecords, "num"), $pagesRecords); 
           
          $lineage = explode("\t", trim(preg_replace("/:/", "\t", $selectedCategory['lineage']))); 
           
          $parents = array(); 
          foreach ($lineage as $parentCatNum) { 
            $parents[] = $categoriesRecordsByNum[$parentCatNum]; 
          } 
        ?> 
         
        <div class="breadcrumb"><a href="/">Home</a> 
        <?php foreach($parents as $parent): ?> 
          <span>&rsaquo;</span> 
          <?php if ($parent === $selectedCategory): ?> 
            <?php echo $parent['name'] ?> 
          <?php else: ?> 
            <a href="/<?php echo $parent['url'] ?>-<?php echo $parent['num'] ?>/"><?php echo $parent['name'] ?></a> 
          <?php endif ?> 
        <?php endforeach ?>
        </div>   

        <?php if ($pagesRecord['heading']): ?><h1><?php echo htmlspecialchars ($pagesRecord['heading']) ?></h1><?php endif ?>
        
        <?php echo $pagesRecord['content'] ?>

        

			<?php  
            // load records for subcat navigation
               list($pagesRecords, $pagesMetaData) = getCategories(array(    
               'tableName'   => 'pages',  
               'selectedCategoryNum' => '', // defaults to getNumberFromEndOfUrl()   
			   // 'debugSql' =>'true',
            ));  
			?>  
			  
			<?php $selectedCat=$pagesRecord['num']; ?>
            <h2>Explore more in <?php echo htmlspecialchars ($pagesRecord['heading']) ?>:</h2>
			<ul>
			<?php foreach ($pagesRecords as $record): ?>   
			  
						<?php if ($record['depth'] == 0) { continue; } ?>   
							  
						 <?php if($record['active']==1 && $record['hide']==0 && $record['parentNum']==$selectedCat): ?>  
									<li><a href="/<?php echo ($record['url']);?>-<?php echo ($record['num']);?>/"><?php echo htmlspecialchars($record['name']);?></a></li>   
						<?php endif ?>  
			  
			 <?php endforeach; ?>
             </ul>
        
<? include("library/inc/form.php"); ?>

        <p class="top"><a href="#top">Top of Page</a></p>
    </div><!--end content-->
</div><!--end main-->

<div class="rightcol">
    <div class="featureimage">
    
    
    <?php // Right Column Image Display
    $imageNum = $pagesRecord['right_image']; 
	$imageDisable = 0;
    if (!$imageNum) { $imageNum = 0; } // set default num
	if ($imageNum == 0) { $imageDisable = 1; } // used to disable image display if no num
    list($sidebar_imagesRecords, $sidebar_imagesMetaData) = getRecords(array(
        'tableName'   => 'sidebar_images',
        'where'		  => "num ='$imageNum'",  
        'limit'       => '1',
    ));
    $sidebar_imagesRecord = @$sidebar_imagesRecords[0]; // get first record
    ?>
    
    <?php if ($imageDisable == 0): ?>
		<?php foreach ($sidebar_imagesRecord['image'] as $upload): ?>
            <?php if ($upload['isImage']): ?>
            <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $sidebar_imagesRecord['title'] ?>" />
            <?php endif ?>
        <?php endforeach ?>
	<?php endif ?>
    
    </div>

	<?php // Right Column Staff Display
      $staffNum = $pagesRecord['staff']; 
	  $staffDisable = 0;
      if (!$staffNum) { $staffNum = 0; } // set default num
      if ($staffNum == 0) { $staffDisable = 1; } // used to disable staff display if no num
      list($staffRecords, $staffMetaData) = getRecords(array(
        'tableName'   => 'staff',
        'allowSearch' => '0',
    	'where' => "title LIKE '$staffNum'",
		'debugSql' =>'true',
      ));
    ?>
    
    <?php if ($staffDisable == 0): ?>
        <div class="box">
        <h2>Meet our <?php echo $pagesRecord['name'] ?> Specialist(s)</h2>
        <?php foreach ($staffRecords as $record): ?>
            <p class="partner clearfix"><b><a href="<?php echo $record['page_link'] ?>">
            <?php foreach ($record['image'] as $upload): ?>
            	<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $record['title'] ?>" />
			<?php endforeach ?>
            <?php echo $record['title'] ?></a></b><br />
            <?php echo $record['description'] ?></p>
        <?php endforeach ?>
        </div>
    <?php endif ?>
    
    <!--<div class="box">
    <h2>Meet our Family Law Specialist(s)</h2>
    <p class="partner clearfix"><b><a href=""><img src="/library/images/sample-profile.jpg" width="100" height="100" />Michael Robinson</a></b><br />
    Michael Robinson has been in practice since 1990.  He joined Turner Hopkins in 1996 and has been a partner since 2000.</p>
    <p class="partner clearfix"><b><a href=""><img src="/library/images/sample-profile.jpg" width="100" height="100" />Michael Robinson</a></b><br />
    Michael Robinson has been in practice since 1990.  He joined Turner Hopkins in 1996 and has been a partner since 2000.</p>
    </div>-->


	<?php // Related News Display
      $newsNum = $pagesRecord['law_category']; 
	  $newsDisable = 0;
      if (!$newsNum) { $newsNum = 0; } // set default num
      if ($newsNum == 0) { $newsDisable = 1; } // used to disable staff display if no num
      list($news_storiesRecords, $news_storiesMetaData) = getRecords(array(
        'tableName'   => 'news_stories',
        'allowSearch' => '0',
		'where'		  => "law_categories ='$newsNum'", 
		'debugSql'	  =>'true',
      ));
    ?>
    
    <?php if ($newsDisable == 0): ?>
        <div class="box news">
            <h2>Recent <?php echo $pagesRecord['name'] ?> News &amp; Advice</h2>
            <ul>
            <?php foreach ($news_storiesRecords as $record): ?>
                <li><a href="/news/<?php echo $record['url'] ?>-<?php echo $record['num'] ?>/"><?php echo $record['title'] ?></a></li>
            <?php endforeach ?>
            </ul>
        <p><a href="/news/">Read more...</a></p>
        </div>
    <?php endif ?>   
 
    <div class="box promo">
		<?php // Right Column Promo Display
            $promoNum = $pagesRecord['promo']; 
            $promoDisable = 0;
            if (!$promoNum) { $promoNum = 0; } // set default num
            if ($promoNum == 0) { $promoDisable = 1; } // used to disable promo display if no num
            list($promo_bannersRecords, $promo_bannersMetaData) = getRecords(array(
                'tableName'   => 'promo_banners',
                'where'		  => "num ='$promoNum'",  
                'limit'       => '1',
            ));
  			$promo_bannersRecord = @$promo_bannersRecords[0]; // get first record
        ?>
     
        <?php if ($promoDisable == 0): ?>
            <a target="_blank" href="<?php if ($promo_bannersRecord['internal_link']): ?><?php echo $promo_bannersRecord['internal_link'] ?><?php elseif ($promo_bannersRecord['external_link']): ?><?php echo $promo_bannersRecord['external_link'] ?><?php else: ?><?php foreach ($promo_bannersRecord['download_file'] as $upload): ?><?php echo $upload['urlPath'] ?><?php endforeach ?><?php endif ?>" title="<?php echo $promo_bannersRecord['title'] ?>"><?php foreach ($promo_bannersRecord['image'] as $upload): ?><img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="<?php echo $promo_bannersRecord['title'] ?>" /><?php endforeach ?></a>
        <?php endif ?>
    </div>
    
</div><!--end rightcol-->

<div class="leftcol">
    <div class="navbar">
<? include("library/inc/navbar.php"); ?>
    </div>
    <div class="search">
<? include("library/inc/search.php"); ?>
    </div>
</div><!--end leftcol-->

</div><!--end innerwrapper-->

<? include("library/inc/footer.php"); ?>

</div><!--end wrapper-->
</body>
</html>
