<?php echo "<?xml version='1.0'?>\n"; ?>
<!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>
<title></title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
</head>
<body>


<!-- STEP1: Load Record List (Paste this above other steps) -->
    <?php
      require_once "../lib/viewer_functions.php";
      $options = array();                  // NOTE: see online documentation for more details on these options
      $options['tableName']  = 'demo';  // (REQUIRED) MySQL tablename to list record from. Example: 'article';
      $options['titleField'] = 'title';    // (optional) MySQL fieldname used in viewer url for search engines. Example: 'title' would display: viewer.php/article_title_here-123
      $options['viewerUrl']  = 'demoPage/'; // (optional) URL of viewer page. Example: '/articles/view.php';
      $options['perPage']    = '1';         // (optional) The number of records to display per page. Example: '5'; Defaults to 10.
      $options['orderBy']    = 'menu_order, title';         // (optional) Fieldnames to sort by. Example: 'field1, field2 DESC, field3';
      $options['pageNum']    = '';         // (optional) Page number of results to display. Example: '1'; Defaults to ?page=# value, or 1 if undefined
      $options['where']      = '';         // (ADVANCED) Additional MySQL WHERE conditions. Example: 'fieldname = "value"'
      $options['useSeoUrls'] = '';         // (ADVANCED) Set this to '1' for search engine friendly urls: view.php/123 instead of view.php?123 (not supported on all web servers)
      list($listRows, $listDetails) = getListRows($options);
 
	  // get requested page name
	  error_reporting(0);
	  $requestedPage = str_replace("/", "", @$_SERVER["PATH_INFO"]);
	  if (!$requestedPage) { $requestedPage = "home"; }

	  // get requested page record
	  $pageRecord = null;
	  foreach ($listRows as $menuRecord) {
	  if ($requestedPage == $menuRecord['filename']) {
		$pageRecord = $menuRecord;
		}
	}

	  // remove all tags and reutnr first NNN words of content 
	  function getTextSummary($value, $maxWords = 25) {   
	  $textOnly = preg_replace("/<(.*?)>/s", " ", 
	  $value); // strip tags   
	  $words    = preg_split("/\s+/", $textOnly);   
	  $words    = array_splice($words, 0, $maxWords);   
	  $summary = join(" ", $words);   
	  return $summary; 
	}

	?>
<!-- /STEP1: Load Record List -->

  
<!-- show menu --> 
<ul>
	<?php 
	  require_once "../lib/viewer_functions.php";
	  $options = array(); 
	  $options['tableName']  = 'demo'; 
	  $options['titleField'] = 'title'; 
	  $options['viewerUrl']  = 'demoPage/'; 
	  $options['perPage']    = '9999'; 
	  $options['orderBy']    = 'title'; 
	  $options['pageNum']    = ''; 
	  $options['where']      = '1'; 
	  
	  list($searchRows, $searchDetails) = getListRows($options); 
	  foreach ($searchRows as $menuRecord): 
	  $menuLink = "{$options['viewerUrl']}{$menuRecord['filename']}/"; 
	  $isSelected = $requestedPage == $menuRecord['filename']; 
	?>

	<?php if ($isSelected): ?>
	<li><a href="<?php echo $menuLink; ?>"><?php echo $menuRecord['title'] ?></a></b></li>
	<?php else: ?>
	<li><a href="<?php echo $menuLink; ?>"><?php echo $menuRecord['title'] ?></a></li>
	<?php endif ?>
	<?php endforeach ?>
</ul>
<!-- /show menu -->


<form method="get" action="<?php echo $_SERVER['PHP_SELF'] ?>">
Keyword : <input type="text" name="content_keyword" value="" size="15">
<input type="submit" name="" value="Search">
</form>



<!-- STEP2: Display Record List (Paste this where you want your records to be listed) -->
    <?php foreach ($listRows as $record): ?>	
    <b><?php echo $record['title'] ?></b><br/>
    <?php
		$record['content'];
		print getTextSummary($record['content'], 40);
		print (" ...<br />");
	?>
    link : <a href="<?php echo $options['viewerUrl'] ?><?php echo $record['filename'] ?>/"><?php echo $record['filename'] ?></a><br/>
    <?php endforeach ?>

    <?php if ($listDetails['noRecordsFound']): ?>
      No records were found!<br/>
    <?php endif ?>

    <?php if ($listDetails['invalidPageNum']): ?>
      Results page '<?php echo $listDetails['page']?>' not found, <a href="<?php echo $listDetails['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/>
    <?php endif ?><br/>
<!-- /STEP2: Display Record List -->




<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
    <?php if ($listDetails['prevPage']): ?>
      <a href="<?php echo $listDetails['prevPageLink'] ?>">&lt;&lt; prev</a>
    <?php else: ?>
      &lt;&lt; prev
    <?php endif ?>

    - page <?php echo $listDetails['page'] ?> of <?php echo $listDetails['totalPages'] ?> -

    <?php if ($listDetails['nextPage']): ?>
      <a href="<?php echo $listDetails['nextPageLink'] ?>">next &gt;&gt;</a>
    <?php else: ?>
      next &gt;&gt;
    <?php endif ?>
<!-- /STEP3: Display Page Links -->


</body>
</html>
