<?php

include_once('global.php');

function ShowNews()
{
  global $Database;
  $ItemPerPage = 5;
  if(array_key_exists('Page', $_GET)) $Page = $Database->real_escape_string($_GET['Page']); else $Page = 0;
  $Database->select_db('wow');
  $DbResult = $Database->query('SELECT COUNT(*) FROM news');
  $Total = $DbResult->fetch_array();
  $Total = $Total[0];
  
  $Result = '<strong>Aktuality:</strong>';
  $Result .= '<div style="NewsTable">';
  $DbResult = $Database->query('SELECT news.*, user.User as username FROM news JOIN user ON user.ID=news.user WHERE 1 ORDER BY time DESC LIMIT '.($Page * $ItemPerPage).','.$ItemPerPage);
  while($Row = $DbResult->fetch_array())
  { 
    $Result .= '<div class="NewsItem">';
    if($Row['long_text'] != '') $Row['title'] = '<a href="?new_id='.$Row['id'].'">'.$Row['title'].'</a>';
    $Result .= '<div class="NewsItemTitle"><strong>'.$Row['title'].'</strong> ('.HumanDate($Row['time']).')</div>';  
    $Result .= $Row['short_text'].' ('.$Row['username'].')</div>';
  }
  $Result .= '</div>';
  $Result .= PagesList('?Page=', $Page, $Total, $ItemPerPage);
  return($Result);
}

?>
