<?php 

include("mycode/newsconf.php");
require_once("mycode/funcnews.php");
$viewnews = (isset ($_GET['view']))? intval($_GET['view']) : "-1";

if(file_exists("$newsdbfilename")){
	$news=file("$newsdbfilename");
	$countallnews = count($news);
	if ($viewnews=="-1") {
	if(!isset($_REQUEST["newspage"])) {$_REQUEST["newspage"]=1;
	} else {$_REQUEST["newspage"] = (int)$_REQUEST["newspage"];}
	$j = ($countallnews-1)-(($_REQUEST["newspage"]-1)*$newsperpage);
	$i = $j-$newsperpage;
		for($j;(($i<$j)&&($j>=0));$j--)  {
		$new=unserialize($news[$j]);
		if ($new=="") {continue;}
		@$newsmarkers=array(
		@$head = $new['head'],
		@$startnews = $new['mess'],
		@$adminemail = $new['admmail'],
		@$adminname = $new['aname'],
		@$date = $new['pubdate'],
		@$time = $new['pubtime']
		);
		$p = $j+1;
		print "<h2>$head</h2>$startnews<br><b>$date</b> | $adminname | <a href=\"news-$p.html\">Читать далее</a><br><br>" ;
		}
	print "<b>Страницы:</b>&nbsp;";
	$all = ceil($countallnews/$newsperpage); 
	for($i=1;$i<=$all;$i++) {
		if($_REQUEST["newspage"]==$i) {
		print "&laquo;<b>$i</b>&raquo; ";
		}
		else {
		print "<a href=\"news-page-$i.html\">$i</a> ";
		}
	}
	print "<br><div align=\"right\">Всего&nbsp;новостей&nbsp;:&nbsp;<b>$countallnews</b></div>";
	} else {
		$new=unserialize($news[$viewnews-1]);
		if ($new=="") {continue;}
		@$newsmarkers=array(
		@$head = $new['head'],
		@$startnews = $new['mess'],
		@$adminemail = $new['admmail'],
		@$adminname = $new['aname'],
		@$date = $new['pubdate'],
		@$time = $new['pubtime'],
		@$fullnews = $new['extra']
		);
		print "<h2>$head</h2>$startnews<br><br>$fullnews<br><br><b>$date</b> | $adminname<br><br>$back" ;
		}
} else {print("<center><font color=\"red\" size=\"2\">Записей нет!</font></center>");}
 
?>