<?php
/************************************************************************/
/* Maximus CMS: Web Portal System                                       */
/* ==============================                                       */
/*                                                                      */
/* Copyright (c) 2002 - 2006                                            */
/* http://www.php-maximus.fr                                            */
/* dev@php-maximus.org                                                  */
/*                                                                      */
/* This program is free software. You can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 2 of the License.       */
/************************************************************************/
/* Based on PHP-NUKE: Web Portal System                                 */
/************************************************************************/
defined('MAXIMUS') or Header("Location: index.php");

   incoh();
    Max_OpenTable();
    $pid    = $GLOBALS['db']->XMFnum($pid);
    $sql = "SELECT * FROM `".TABLE_PAGES."` WHERE `pid`='$pid'";
     if ( !($result = $GLOBALS['db']->sql_query($sql)) )
{ query_die(CORE_ERROR, 'Could not obtain _pages', '', __LINE__, __FILE__, $sql);}
    $mypage = $GLOBALS['db']->sql_fetchrow($result);
    $myactive      = $GLOBALS['db']->XMFnum($mypage['active']);
    $mytitle       = stripslashes(check_html($mypage['title'], "nohtml"));
    $mysubtitle    = stripslashes(check_html($mypage['subtitle'], "nohtml"));
    $mypage_header = stripslashes($mypage['page_header']);
    $mytext        = stripslashes($mypage['text']);
    $mypage_footer = stripslashes($mypage['page_footer']);
    $mysignature   = stripslashes($mypage['signature']);
    $mydate        = stripslashes($mypage['date']);
    $mycounter     = $GLOBALS['db']->XMFnum($mypage['counter']);
    if (($myactive == 0) AND (!defined('ADMIN_ALLOW'))) {
	echo "Sorry... This page doesn't exist.";
    } else {
	$GLOBALS['db']->sql_query("UPDATE `".TABLE_PAGES."` SET `counter`=counter+1 WHERE `pid`='$pid'");
	$date = explode(" ", $mydate);
	echo "<font class='title'>$mytitle</font><br />"
		."<font class=\"content\">$mysubtitle</font><br /><br /><br /><br />";
	$contentpages = explode( "<!--pagebreak-->", $mytext );
	$pageno = count($contentpages);
	if ( $page=="" || $page < 1 )
	    $page = 1;
	if ( $page > $pageno )
	    $page = $pageno;
	$arrayelement = (int)$page;
	$arrayelement --;
	if ($pageno > 1) {
	    echo ""._PAGE.": $page/$pageno<br />";
	}
	if ($page == 1) {
	    echo "<p align=\"justify\">".nl2br($mypage_header)."</p><br />";
	}
	echo "<p align=\"justify\">$contentpages[$arrayelement]</p>";
	if($page >= $pageno) {
	    $next_page = "";
	} else {
	    $next_pagenumber = $page + 1;
	    if ($page != 1) {
		$next_page .= "- ";
	    }
	    $next_page .= "<a href=\"modules.php?name=$module_name&amp;pa=showpage&amp;pid=$pid&amp;page=$next_pagenumber\">"._NEXT." ($next_pagenumber/$pageno)</a> <a href=\"modules.php?name=$module_name&amp;pa=showpage&amp;pid=$pid&amp;page=$next_pagenumber\"><img src=\"images/right.gif\" border=\"0\" alt=\""._NEXT."\" title=\""._NEXT."\" /></a>";
	}
	if ($page == $pageno) {
	    echo "<br /><p align=\"justify\">".nl2br($mypage_footer)."</p><br /><br />";
	}
	if($page <= 1) {
	    $previous_page = "";
	} else {
	    $previous_pagenumber = $page - 1;
	    $previous_page = "<a href=\"modules.php?name=$module_name&amp;pa=showpage&amp;pid=$pid&amp;page=$previous_pagenumber\"><img src=\"images/left.gif\" border=\"0\" alt=\""._PREVIOUS."\" title=\""._PREVIOUS."\" /></a> <a href=\"modules.php?name=$module_name&amp;pa=showpage&amp;pid=$pid&amp;page=$previous_pagenumber\">"._PREVIOUS." ($previous_pagenumber/$pageno)</a>";
	}
	echo "<br /><br /><br /><center>$previous_page $next_page</center><br /><br />";
	if ($page == $pageno) {
	    echo "<p align=\"right\">".nl2br($mysignature)."</p>"
		."<p align=\"right\">"._COPYRIGHT." $sitename "._COPYRIGHT2."</p>"
		."<p align=\"right\"><font class=\"tiny\">"._PUBLISHEDON.": $date[0] ($mycounter "._READS.")</font></p>"
		."<center>"._GOBACK."</center>";
	}
    }
    Max_CloseTable();
    incof();