Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/PortalSources/Pages.php
<?php
/*
*****************************************************************

 Pages.php
 
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version:                  LSP 2.0 "Enigma 2"
Software by:                         Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by:       Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at:    http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it 
under the terms of the provided license as published by Lunabyte Systems.

This program is distributed in the hope that it is and will be useful,                  
but WITHOUT ANY WARRANTIES; without even any implied warranty of           
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                        

See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/

if (!defined('ENIGMA'))
	die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');

function Pages($pg = null)
{
	global $db_prefix, $page, $context, $txt, $scripturl;

	loadPLanguage('Pages');
	// find our page...
	switch (true)
	{
		case ($pg != NULL) :
			$page = $pg;
		break;
		case !empty($_REQUEST['pg']) :
			$page = $_REQUEST['pg'];
		break;
		case !empty($page) :
			$page = $page;
		break;
		case !empty($_REQUEST['page']) :
			$page = $_REQUEST['page'];
		break;

		// Spawn error...
		default :
			fatal_lang_error ('page_not_specified');
		break;
	}

	$get_page = db_query("
		SELECT *
		FROM {$db_prefix}pages
		WHERE stitle = '$page'
		LIMIT 1", __FILE__, __LINE__);

	if (mysql_num_rows($get_page) == 0)
		fatal_lang_error ('page_not_found');

	$pagec = mysql_fetch_assoc($get_page);
	mysql_free_result($get_page);
	
	// If we're inside a folder structure, build the tree
	$myfolder = $pagec['folder'];
	while($myfolder > 0) {		
		$get_folder = db_query("
			SELECT *
			FROM {$db_prefix}page_folders
			WHERE id = '$myfolder'
			LIMIT 1",__FILE__,__LINE__);
		$row = mysql_fetch_assoc($get_folder);
		mysql_free_result($get_folder);
		$myfolders[] = array($myfolder,$row['name']);
		$myfolder = $row['isSub'];		
	}

	if (!GroupPermissions($pagec['memberGroup']))
		fatal_lang_error ('page_restricted');

	$context['block_override'] = $pagec['block_override'];
	$context['phpe'] = $pagec['phpe'];

	loadPTemplate('Pages');
	$context['sub_template'] = 'display_page';

	if (!isset($context['page_title']))
		$context['page_title'] = $pagec['title'];

	$context['linktree'][] = array(
			'url'	=> $scripturl . '?op=PageListing',
			'name'	=> $txt['pages_01'],
	);
	// If we're inside a folder structure, show it in the linktree
	if ($pagec['folder'] > 0) {
		krsort($myfolders);
		while (list($key,$val) = each($myfolders)) {
			$context['linktree'][] = array(
				'url'	=> $scripturl . '?op=PageListing;folder=' . $val[0],
				'name'	=> $val[1],
			);
		}
	}
	$context['linktree'][] = array(
			'url'	=> $scripturl . '?page=' . $page,
			'name'	=> $pagec['title'],
	);

	if (!$pagec['yabbce'] || $context['phpe'])
		$context['page_content'] = un_htmlspecialchars($pagec['contents']);
	else
		$context['page_content'] = doUBBC(un_htmlspecialchars($pagec['contents']));

	obExit();
}

function ListPages()
{
	global $context, $txt, $db_prefix, $color, $folder, $imagesdir, $scripturl;

	loadPLanguage('Pages');
	loadPTemplate('Pages');

	if (!isset($context['page_title']))
		$context['page_title'] = $txt['pages_01'];

	$context['linktree'][] = array(
		'url'	=> $scripturl . '?op=PageListing',
		'name'	=> $txt['pages_01'],
	);

	$context['useicons'] = 0;
	$folder = (!isset($_REQUEST['folder']) || $_REQUEST['folder'] == '') ? '0' : is_numeric($_REQUEST['folder']) ? $_REQUEST['folder'] : 0;
	$context['crumb'] = $folder;
	$myfolder = $folder;
	
	// If we're inside a folder structure, build the tree
	while($myfolder > 0) {	
		$get_folder = db_query("
			SELECT *
			FROM {$db_prefix}page_folders
			WHERE id = '$myfolder'
			LIMIT 1",__FILE__,__LINE__);
		$row = mysql_fetch_assoc($get_folder);
		mysql_free_result($get_folder);
		$myfolders[] = array($myfolder,$row['name']);
		$myfolder = $row['isSub'];		
	}
	// Update linktree accordingly
	if ($folder > 0) {
		krsort($myfolders);
		while (list($key,$val) = each($myfolders)) {
			$context['linktree'][] = array(
				'url'	=> $scripturl . '?op=PageListing;folder=' . $val[0],
				'name'	=> $val[1],
			);
		}
	}
	
	$folders = db_query("
			SELECT *
			FROM {$db_prefix}page_folders
			WHERE (isSub='$folder') ORDER BY name", __FILE__, __LINE__);

	if (mysql_num_rows($folders) != 0)
	{
		while ($curr_folder = mysql_fetch_assoc($folders))
		{
			$pagecount = db_query("
				SELECT COUNT(*) AS num
				FROM {$db_prefix}pages AS p,
					{$db_prefix}page_folders AS pf
				WHERE (p.folder='$curr_folder[id]' || pf.isSub='$curr_folder[id]')", __FILE__, __LINE__);

			$isempty = mysql_result ($pagecount, 0, 'num');
			mysql_free_result($pagecount);

			$context['curr_folder'][] = array(
					'id'    => $curr_folder['id'],
					'name'  => $curr_folder['name'],
					'empty' => $isempty[0]
			);
		}
	}
	else
	{
		$context['curr_folder'] = 0;
	}
	mysql_free_result($folders);

	// Get pages
	$pages = db_query("
			SELECT title, stitle, memberGroup, folder
			FROM {$db_prefix}pages
			WHERE (folder='$folder') AND list='1' ORDER BY title", __FILE__, __LINE__);

	// did we get any pages for this folder?
	if (mysql_num_rows($pages) > 0)
	{
		$context['curr_page'] = array();
		// Get the name of the folder
		if ($context['crumb'] != 0)
		{
			$getname = db_query("
					SELECT name
					FROM {$db_prefix}page_folders
					WHERE (id='$context[crumb]') LIMIT 1", __FILE__, __LINE__);
			$name = mysql_fetch_row ($getname);
			mysql_free_result($getname);
		}
		$context['foldername'] = ($context['crumb'] != 0) ? $name[0] : $txt['pages_02'];
		
		// build pages array
		while ( $curr_page =  mysql_fetch_assoc ($pages) )
		{
			if (!GroupPermissions($curr_page['memberGroup']))
				continue;

			$context['curr_page'][] = array(
				'stitle' => $curr_page['stitle'],
				'title'  => $curr_page['title']
				);
		}
	}
	else
	{
		$context['curr_page'] = 0;
	}
	mysql_free_result($pages);

	$context['sub_template'] = 'list';
	obExit();
}

?>
Return current item: Enigma