<?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/content/34/10381234/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."); }

  //get category data if category is selected.
  if(@$_REQUEST['category']){
    $selectedCategoryData = mysql_get('health_articles_categories', intval($_REQUEST['category']));
  }

  // load record from 'master_info'
  list($master_infoRecords, $master_infoMetaData) = getRecords(array(
    'tableName'   => 'master_info',
    'where'       => '', // load first record
    'loadUploads' => false,
    'allowSearch' => false,
    'limit'       => '1',
  ));
  $master_infoRecord = @$master_infoRecords[0]; // get first record
  if (!$master_infoRecord) { dieWith404("Record not found!"); } // show error message if no record found



/* ----- 1/5 - SECTION SPECIFIC INFO ----- */

  // load records from 'health_articles_content'
  list($health_articles_contentRecords, $health_articles_contentMetaData) = getRecords(array(
    'tableName'   => 'health_articles_content',
    'perPage'     => '2',
  ));	
	
  // load records from 'health_articles_categories'
  list($health_articles_categoriesRecords, $health_articles_categoriesMetaData) = getRecords(array(
    'tableName'   => 'health_articles_categories',
    'loadUploads' => false,
    'allowSearch' => false,
  ));


?>
<!DOCTYPE HTML>
<html >
<head>
  <meta charset="UTF-8">

  <meta name="description" content="">
  <meta name="keywords" content="">
  <!-- <meta http-equiv="Content-Type" content="text/html;charset=iso8859-1"> -->



<!--  2/5 - PAGE NAME  -->
  <title>
      <?php echo htmlencode($master_infoRecord['meta_title_prefix']) ?> :: Health Articles
	</title>
  
  <?php include("ext_css.php"); ?>
  
  <?php include("ext_scripts.php"); ?>

  <link rel="shortcut icon" href="favicon.ico">

</head>
<body>
  <?php include("ext_alert_top.php"); ?>
  <div class="site_container">  
		<?php include("ext_header.php"); ?>
    <div class="clear"></div>
  
    <div id="block_nav_primary">
      	<?php include("ext_menu.php"); ?>
    </div><!-- .block_nav_primary -->
  
    <div class="clear"></div>
  
  <div class="container_12">
    <div class="grid_12">
       <div class="breadcrumbs">



<!--  3/5 - BREADCRUMBS  -->

	      <a href="/index.php">Home</a><span>&#8250;</span><span class="current">Health Articles</span>
       </div><!-- .breadcrumbs -->
    </div><!-- .grid_12 -->
  </div><!-- .container_12 -->

  <div class="clear"></div>

  <section id="main">
    <div class="container_12">
       <div id="sidebar" class="grid_3">
       
					<?php include("ext_side_categories_health_articles.php"); ?>
          
					<?php include("ext_side_archives_health_articles.php"); ?>
          
          <?php include("ext_side_tags.php"); ?>

          <?php include("ext_side_newsletter.php"); ?>
          
          <?php include("ext_side_banners.php"); ?>          
          
       </div><!-- .sidebar -->

       <div id="content" class="grid_9">



<!--  4/5 - PAGE TITLE  -->

          <h1 class="page_title">Health Articles<?php if (@$selectedCategoryData['category']): ?> :: <?php echo $selectedCategoryData['category']; ?><?php else: ?><?php endif ?></h1>
          
          
<!--  5/5 - CONTENT  -->

<?php
// TEXT-LIMITING FUNCTION (to display only a portion of each blog post's content)
// For use on all Blog list pages

function cutText($string, $setlength) { 
    $length = $setlength; 
    if($length<strlen($string)){ 
        while (($string{$length} != " ") AND ($length > 0)) { 
            $length--; 
        } 
        if ($length == 0) return substr($string, 0, $setlength); 
        else return substr($string, 0, $length); 
    }else return $string; 
} 
// END TEXT-LIMITING FUNCTION
?>

    <?php foreach ($health_articles_contentRecords as $record): ?>
      <article class="post">
        <h2 class="title_article"><a href="<?php echo $record['_link'] ?>"><?php echo htmlencode($record['title']) ?></a></h2>
        <div class="content_article">
					<?php echo cutText($record['content'], 425); ?>&nbsp;... &nbsp;
        	<a href="<?php echo $record['_link'] ?>" class="read_more">MORE >></a>
        </div>
        <!-- .content_article -->
        <div class="footer_article">
          <div class="number_c">3</div>
          <span><?php echo htmlencode($record['author']) ?>, <time datetime="2012-11-03"><?php echo date("m.j.Y", strtotime($record['date'])) ?></time></span>  |  



<!-- "POSTED IN" CATEGORY MODULE -->
<?php
  // This piece NOT NECESSARY IF PLACED IN HEADER - load records from 'health_articles_content'
  list($health_articles_contentRecords, $health_articles_contentMetaData) = getRecords(array(
    'tableName'   => 'health_articles_content',
    'loadUploads' => false,
    'allowSearch' => false,
  ));
?>
        <?php  $linkArray = array_combine($record['category:values'], $record['category:labels']);  ?>
        <span>Posted in 
      		<?php foreach($linkArray as $num => $title): ?>
        		<a href="health_articles_list.php?category=<?php echo $num;?>"><?php echo $title; ?></a>,
      		<?php endforeach; ?>
    		</span>
        </div>
      </article>
    <?php endforeach ?>
<!-- /end "POSTED IN" CATEGORY MODULE -->



<!--  BEGIN PAGINATION  -->
<?php
  list($health_articles_contentRecords, $health_articles_contentMetaData) = getRecords(array(
    'tableName'   => 'health_articles_content',
    'perPage'     => '2',
  ));	
  $blog_contentRecord = @$blog_contentRecords[0]; // get first record
?>

		 <?php if ($health_articles_contentMetaData['totalPages'] > 1): ?>
		   <div class="pagination">
		     <ul>
			    <li class="prev">
          	<?php if ($health_articles_contentMetaData['prevPage']): ?>
              <a href="<?php echo $health_articles_contentMetaData['prevPageLink'] ?>">&#8592;</a>
						<?php else: ?>
            <?php endif ?>
          </li>
					<?php foreach(range('1',$health_articles_contentMetaData['totalPages']) as $pageNumber): ?>
            <li <?php if($pageNumber == $health_articles_contentMetaData['page']): ?>class="curent"<?php endif; ?>>
              <a href="/health_articles_list.php?page=<?php echo $pageNumber; ?>"><?php echo $pageNumber; ?></a>
            </li>
          <?php endforeach; ?>
			    <li class="next">
          	<?php if ($health_articles_contentMetaData['nextPage']): ?>
          		<a href="<?php echo $health_articles_contentMetaData['nextPageLink'] ?>">&#8594;</a>
            <?php else: ?>
            <?php endif ?>
          </li>
		     </ul>
	     </div><!-- .pagination -->
     <?php endif ?> 
<!--  END PAGINATION  -->



<br>
<br>


		<div class="pagination">
		     <ul>
			    <li class="prev"><span>&#8592;</span></li>
			    <li><a href="#">1</a></li>
			    <li><span>...</span></li>
			    <li class="curent"><a href="#">8</a></li>
			    <li><a href="#">9</a></li>
			    <li><a href="#">10</a></li>
			    <li><a href="#">11</a></li>
			    <li><a href="#">12</a></li>
			    <li><span>...</span></li>
			    <li><a href="#">100</a></li>
			    <li class="next"><a href="#">&#8594;</a></li>
		     </ul>
	  </div><!-- .pagination -->
    
    
    <br>
<br>


<!--  BEGIN PAGINATION  -->
<?php
  list($health_articles_contentRecords, $health_articles_contentMetaData) = getRecords(array(
    'tableName'   => 'health_articles_content',
    'perPage'     => '2',
  )); 
  $blog_contentRecord = @$blog_contentRecords[0]; // get first record
?>
<?php $counter = 0;  // set page counter to zero ?>
<?php $maxPageNumbers = 3;  // maximum number of page numbers to display ?>

 <?php if ($health_articles_contentMetaData['totalPages'] > 1): ?>
   <div class="pagination">
     <ul>
    <li class="prev">
           <?php if ($health_articles_contentMetaData['prevPage']): ?>
              <a href="<?php echo $health_articles_contentMetaData['prevPageLink'] ?>">&#8592;</a>
<?php else: ?>
            <?php endif ?>
          </li>
<?php foreach(range('1',$health_articles_contentMetaData['totalPages']) as $pageNumber): ?>
            <li <?php if($pageNumber == $health_articles_contentMetaData['page']): ?>class="curent"<?php endif; ?>>
              <a href="/health_articles_list.php?page=<?php echo $pageNumber; ?>"><?php echo $pageNumber; ?></a>
            </li>
           <?php if (++$counter == $maxPageNumbers) {break;} ?>
          <?php endforeach; ?>
						<?php if ($counter > 1): ?>
              <li><span>...</span></li>
              <li <?php if($health_articles_contentMetaData['totalPages'] == $health_articles_contentMetaData['page']): ?>class="curent"<?php endif; ?>><a href="/health_articles_list.php?page=<?php echo $health_articles_contentMetaData['totalPages']; ?>"><?php echo $health_articles_contentMetaData['totalPages']; ?></a></li><?php endif ?>
    					<li class="next">
							  <?php if ($health_articles_contentMetaData['nextPage']): ?>
                  <a href="<?php echo $health_articles_contentMetaData['nextPageLink'] ?>">&#8594;</a>
                <?php else: ?>
                <?php endif ?>
              </li>
     </ul>
     </div><!-- .pagination -->
     <?php endif ?> 
<!--  END PAGINATION  -->





      </div><!-- #content -->

      <div class="clear"></div>

    </div><!-- .container_12 -->
  </section><!-- #main -->

  <div class="clear"></div>

    <?php include("ext_footer.php"); ?>

</html>
