<?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");

	$tid = $GLOBALS['db']->XMFnum($tid);
	incoh();
	Max_OpenTable();
	$ency = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT * FROM `".TABLE_ENCYCLOPEDIA_TEXT."` WHERE `tid`='$tid'"));
	$etid = $GLOBALS['db']->XMFnum($ency['tid']);
	$eeid = $GLOBALS['db']->XMFnum($ency['eid']);
	$etitle = stripslashes(check_html($ency['title'], "nohtml"));
	$etext = stripslashes($ency['text']);
	$ecounter = $GLOBALS['db']->XMFnum($ency['counter']);
	$row = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `active` FROM `".TABLE_ENCYCLOPEDIA."` WHERE `eid`='$eeid'"));
	$active = $GLOBALS['db']->XMFnum($row['active']);
	if (($active == 1) OR ($active == 0 AND defined('ADMIN_ALLOW'))) {
		$GLOBALS['db']->sql_query("UPDATE `".TABLE_ENCYCLOPEDIA_TEXT."` SET `counter`=counter+1 WHERE tid='$tid'");
		$row2 = $GLOBALS['db']->sql_fetchrow($GLOBALS['db']->sql_query("SELECT `title` FROM `".TABLE_ENCYCLOPEDIA."` WHERE `eid`='$eeid'"));
		$enc_title = stripslashes($row2['title']);
		echo "<font class='title'>$etitle</font>";
		br('3');
		$contentpages = explode( "<!--pagebreak-->", $etext );
		$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 (isset($query)) {
			$query = htmlentities($query);
			$contentpages[$arrayelement] = eregi_replace($query,"<b>$query</b>",$contentpages[$arrayelement]);
			$fromsearch = "&query=$query";
		} else {
			$fromsearch = "";
		}
		echo "<p align=\"justify\">".nl2br($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;op=content&amp;tid=$tid&amp;page=$next_pagenumber$fromsearch\">"._NEXT." ($next_pagenumber/$pageno)</a> <a href=\"modules.php?name=$module_name&amp;op=content&amp;tid=$tid&amp;page=$next_pagenumber\"><img src=\"images/right.gif\" border=\"0\" alt=\""._NEXT."\" title=\""._NEXT."\"></a>";
		}
		if($page <= 1) {
			$previous_page = "";
		} else {
			$previous_pagenumber = $page - 1;
			$previous_page = "<a href=\"modules.php?name=$module_name&amp;op=content&amp;tid=$tid&amp;page=$previous_pagenumber$fromsearch\"><img src=\"images/left.gif\" border=\"0\" alt=\""._PREVIOUS."\" title=\""._PREVIOUS."\"></a> <a href=\"modules.php?name=$module_name&amp;op=content&amp;tid=$tid&amp;page=$previous_pagenumber$fromsearch\">"._PREVIOUS." ($previous_pagenumber/$pageno)</a>";
		}
		br('3');
		echo "<center>$previous_page $next_page";
		br('2');
		echo ""._GOBACK."</center><br />";
		if (defined('ADMIN_ALLOW')) {
			echo "<p align=\"right\">[ <a href=\"".$admin_file.".php?op=encyclopedia_text_edit&amp;tid=$etid\">"._EDIT."</a> ]</p>";
		}
		echo "<p align=\"right\"><a href=\"modules.php?name=$module_name&amp;op=list_content&amp;eid=$eeid\">$enc_title</a></p>";
		if ($page == $pageno) {
			echo "<p align=\"right\">"._COPYRIGHT." &copy; "._BY." $sitename - ($ecounter "._READS.")</font></p>";
		}
	} else {
		echo "Sorry, This page isn't active...";
	}
	Max_CloseTable();
	incof();