<?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/smesacoz/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."); }

 $tables = array('news_finance','news_technology'); 
   $records=array(); 
   $maxRecords = 5; 
    
   foreach($tables as $table){ 
      
     list($tableRecords,$tableMetaData)=getRecords(array( 
            'tableName'      =>   mysql_escape($table), 
            'allowSearch'    =>  false, 
            'limit'          =>  $maxRecords, 
            'orderBy'        => "createdDate desc", 
          )); 
      
      foreach($tableRecords as $tableRecord){ 
        $records[]=$tableRecord; 
      } 
   } 
    
$records=sort_array($records,'createdDate','desc'); 
  
  ?>
<!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>Untitled Document</title>
</head>

<body>
<?php $count=0; ?> 
 
<?php foreach($records as $record): ?> 
 <?php  if($count==$maxRecords){ 
     break; 
   } 
   else{ 
     $count++; 
   }?> 
    <!-- STEP2: Display Records (Paste this where you want your records to be listed) -->
     <!-- STEP 2a: Display Uploads for field '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 -->
       <div class="img"><?php foreach ($record['image'] as $upload): ?>
          <?php if ($upload['hasThumbnail']): ?>
            <img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>

          <?php elseif ($upload['isImage']): ?>
            <img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

          <?php else: ?>
            <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

          <?php endif ?>
        <?php endforeach ?></div>
      <!-- STEP2a: /Display Uploads -->
	  
	  <a class="news" href="<?php echo $record['_link'] ?>"><?php echo $record['title'] ?></a>
      <div class="spacer"></div>
     <?php echo $record['intro'] ?>
     <div class="spacer"></div>
    
<?php endforeach ?>

  <?php if (!$records): ?>
      No records were found!<br/><br/>
    <?php endif ?>
  <!-- /STEP2: Display Records -->

<div class="spacer"></div>

</body>
</html>
<?php 
function sort_array ($array, $index, $order='asc', $natsort=FALSE, $case_sensitive=FALSE) { 
  if(is_array($array) && count($array)>0) { 
    foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; 
    if(!$natsort) ($order=='asc')? asort($temp) : arsort($temp); 
    else { 
      ($case_sensitive)? natsort($temp) : natcasesort($temp); 
      if($order!='asc') $temp=array_reverse($temp,TRUE); 
    } 
    foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; 
    return $sorted; 
  } 
  return $array; 
} 
 
?>