Istanbul Bilgi University Department of Computer Science
Previous Home > About This Site > Navigate.php Next
Home
   About This Site
      Previous Scripts
      Scripts Version 2.2.4
      Apache2.conf
      Messages.php
      Navigate.php
      Pagelayout.php
      Pagelayout.tpl0
      Style.css
   Academic Policies
   Academic Staff
   Courses
   Curiosity Corner
   High School Computer Clubs Project
   Lab Rules
   Links
   Member Help
   News
   Other Stuff
   Standards Project
   Turing Days
   Usage Statistics
   Yarışma

<?php
include("messages.php");
####################################################### 
# 		NAVIGATION CODE 				
#		HtmlFile class							
#		Navigate class					
#									
#		"Proof of Concept"				
#		Version 1.0
#		Version 1.1 turkish characters removed from file names
#		spoofed in display names from file: -c- => display: ç and so on
#		Minor update html tidied up 26 October 2001 CS					
#		Version 2.0 switch to inheritable templates, add inheritable settings	
#		headers and footers allowed to be symbolic links CS 2002/11/08
#		Version 2.1 template format changed to allow placeholder text
#		our tags are now proper html comment tags.
#		Version 2.2 eregi now used to make sure we accept both upper and lower case tags!
#		Version 2.2.1 bugs in header and footer corrected (use foreach to avoid error when
#		there are missing headers or footers in the numerical sequence) 2002-12-10 
#		Version 2.2.2 ignore files and directories that begin with .
#		fix a couple of minor bugs in dealing with missing directories
#		Version 2.2.3 use ksort to make sure headers and footers are dipslayed in numerical order	
#		Version 2.2.4 bug fix of typo where endofpath had no $ on it 
#		in a couple of places in the directory function	
#     Version 2.2.5 2004-11-15 Seker Bayrami
#     (a) list pdf files in menus with links to open in new window
#     (b) format .txt files with pre tags
#     (c) do not list directories that contain (recursively) no listable files
#     Version 2.2.6
#     (a) correct checks for html and txt files to really only accept files that END
#        in .txt and .htm(l), by using eregi. 
#     (b) A number of absurd pieces of historical code removed or corrected.
#
#     Version 2.2.7
#     Fix case sensitivity bug for the extensions of files to be converted into links
#
#     Version next: To be done...in the next version
#     (a) ?? eliminate or proportionalise tables in bodies??
#     (b) pop out menus
#     (c) cacheing ( probably needed if we do (b) )
#									
#		GPL Licence	Version 2 or later					
#		Author Chris Stephenson sep 2001/sep 2002/nov 2002/nov 2004		
####################################################### 
class HtmlFile
	{
	var $filepath;
	var $title;
	var $bodycontents;
	var $filecontents;
	var $header;

#######################################################
#	Constructor for HtmlFile class			
#	Obtains filecontents prepares class data for 		
#	the generation of output
#	just recovers the part of the file between the body tags			
#######################################################

	function HtmlFile($filepath)
		{
		if (is_file($filepath))
			{
			$fp=fopen($filepath,"rb");
			$this->filecontents=fread($fp,filesize($filepath));
			fclose($fp);
			}
		#now parse the header and look for body tags
		if (eregi("<body([^>]*)>(.*)</body[[:space:]]*>",$this->filecontents,$analysis))
			{
			$this->bodycontents = $analysis[2];
			}
		else
			{
			$this->bodycontents = $this->filecontents;
			}
		}
	}




class Navigate
	{
	var $urlbase;		# the start for our URLs
	var $filebase;		# the start for our files in the file structure (relative to htdocs)
	var $documentroot;	# the absolute root for documents (typically htdocs)
	var $filepathabsolute;	# an absolute file path to the currently adressed file
	var $path;			# an array representing the path to the current page
	var $pathsarray;		# an array of arrays for the directories at every level on $path 
	var $nextlink;		# url of the "next" page - the next actual file or directory if no more files at this level
	var $previouslink;	# url of the "previous" page - the previous actual file or directory if no previous files at this level
	var $headers;		# an array of headers to be included
	var $footers;		# an array of footers to be included
	var $templates;		# an array of templates to be included (only template zero is actually used)
	var $settings;		# an array of settings files to be included
	var $filecontents;	# contents of the file as (possibly rather long) string
					# introduced to allow us to manipulate the file (remove header tags etc)
	var $htmlfileobject;	# object representing the file for this page
	var $title;			# title string	


#######################################################
#	print_link:print a single link			
#	takes 							
#	$link: a link for the href, 					
#	$linkname: a name for the entry			
#									
#######################################################

	/*function print_link($link,$linkname)
		{
		echo "<a href=\"" . $link . "\" >" . $linkname . "</a>"; 
		}*/
		
		
#######################################################
# These 2 functions below are modified by Naz 12.09.2002
# *****2.2.5 need pdf link to open in a new window...
#######################################################

	function print_menu_link($link,$linkname)
		{
		echo "<a href=\"" . $link . "\" class='menuTitle'>" . $linkname . "</a>"; 
		}
	
	function print_link($link,$linkname)
		{
      if (eregi("^(.*).pdf)$",$link))
		    echo "<a href=\"" . $link . "\" target=\"_blank\" class='bodyTitle' >" . $linkname . "</a>"; 
      else
		    echo "<a href=\"" . $link . "\" class='bodyTitle' >" . $linkname . "</a>"; 
		}
	
#######################################################
#	printtitle:print page title			
#									
#######################################################

	function printtitle($sitename)
		{
		print($sitename.Navigate::make_link_name($this->title)); 
		}
	

#######################################################
#	print_menu_entry:print a single side bar entry	
#	takes 							
#	$link: a link for the href, 					
#	$linkname: a name for the entry			
#	$depth: depth of indentation				
#######################################################

	function print_menu_entry($link,$linkname,$depth)
		{
		echo "<br>";
		for ($i=0;$i<$depth+1;$i++) 
			printf("&nbsp;&nbsp;&nbsp;");
		Navigate::print_menu_link($link,$linkname); 
		}

#######################################################
#	Make the file path for a link URL			
#######################################################
	function make_link($file,$urlsofar)
		{
		return $urlsofar."/".$file;
		}

#######################################################
#	Make the name for a link URL				
#######################################################

	function make_link_name($file)
		{
		$file=eregi_replace(".html","",$file);
		$file=eregi_replace(".htm","",$file);
		$file=eregi_replace(".txt","",$file); #added .txt files to the rewrite rule, too.
		$file=eregi_replace(".pdf"," (pdf)",$file); #added .pdf files to the rewrite rule, too.
		$file=str_replace("_"," ",$file);
		$file=ucwords($file);
		$file=str_replace("-g-","\360",$file);
		$file=str_replace("-i-","\375",$file);
		$file=str_replace("-o-","\366",$file);
		$file=str_replace("-s-","\376",$file);
		$file=str_replace("-u-","\374",$file);
		$file=str_replace("-c-","\347",$file); 
		$file=str_replace("-G-","\320",$file);
		$file=str_replace("-I-","\335",$file);
		$file=str_replace("-O-","\326",$file);
		$file=str_replace("-S-","\336",$file);
		$file=str_replace("-U-","\334",$file);
		$file=str_replace("-C-","\267",$file);
		return $file;
		}

#######################################################
#	Print out part of a sidebar				
#									
#	Takes:-							
#	path - the current path					
#	pathsarray - an array of dircetory listings	
#			for each directory on the path	
#	urlsofar - a start for the URL			
#	level - the level to be printed 			
#	- zero prints out the entire menu			
#									
#	function calls lower levels recursively		
#######################################################

	function print_menu($urlsofar,$level)
		{
		if ($level < count($this->pathsarray))
			{
			for ($i=0;$i< count($this->pathsarray[$level]);$i++)
				{
				$pathentry = $this->pathsarray[$level][$i];
				Navigate::print_menu_entry(Navigate::make_link($pathentry,$urlsofar),Navigate::make_link_name($pathentry),$level);
				if ($level < (count($this->pathsarray)-1))
					{
					if (!strcmp($pathentry,$this->path[$level])) 
						{
						Navigate::print_menu($urlsofar."/".$pathentry,$level+1);
						}
					}
				}
			}		
		} 
#######################################################
#	Top level call to recursive print_menu function	
#######################################################
	
	function sidebar($roottitle)
		{
		# Print out the Link to the Homepage 
		Navigate::print_menu_link($this->urlbase,$roottitle);
		# Print out the side bar recursively
		Navigate::print_menu($this->urlbase.$this->filebase,0);
		}


#######################################################
#	page header function -added by NAZ 12.09.2002
#   displays header file(s)					
#######################################################
	function pageHeader()
	{
    		foreach ($this->headers as $headerFile)
    		{
			if (is_file($headerFile) || is_link($headerFile)) //symbolic links added 2002/11/08 CS
			{
				$htmlfile = new HtmlFile ($headerFile);
				print($htmlfile->bodycontents);
			}
		}

	}
#######################################################
#	make a previous or next link				
#									
#######################################################

	function make_relative_link($reldepth,$positioninlevel)
		{
		$url=$this->urlbase.$this->filebase;
		for ($i=0;$i<$reldepth;$i++)
			$url .= "/".$this->path[$i];
		if ($positioninlevel >= 0)
			$url .= "/".$this->pathsarray[$reldepth][$positioninlevel];
		return $url;
		}

#######################################################
#	Find next and previous					
#									
#	calculate the links for next and previous page	
#	and store the links in $next and $previous	
#									
#	This code is obscure and has a bug when		
#	the first entry in the home directory is a file	
#	rather than a directory, the previous link is	
#	not correctly computed.					
#	Only try to fix this if you are very sure		
#	of yourself!						
#	debug code left in place to help you!		
#######################################################
	function find_next_and_previous()
		{
		$depth=count($this->path);
		#printf("<br>depth=%d",$depth);
		if ($depth <= 1)
		{
			$this->nextlink = "___";
			$this->previouslink = "___";
			return;
		}
		if ((!strcmp($this->path[$depth-1],"index.html")) && ($depth>1))
			{
			$depth = $depth-1;	
			}
		$level=$depth-1;
		#printf("<br>level=%d",$level);
		$positioninlevel=Navigate::my_array_search($this->pathsarray[$level],$this->path[$level]);
		$previousoffset=1;
		while (($level >= 0) && ($positioninlevel-$previousoffset < 0))
			{
		#	printf("<br>Level = %d, Position in Level = %d, Path entry = %s",$level,$positioninlevel,$this->path[$level]);
			$level=$level-1;
			$previousoffset=0;
			if ($level >= 0)
				$positioninlevel=Navigate::my_array_search($this->pathsarray[$level],$this->path[$level]);
			}
		#echo "<br>previous level = ";printf("%d", $level);echo " position = "; printf("%d", $positioninlevel);
		if ($level >= 0)
			$this->previouslink = Navigate::make_relative_link($level,$positioninlevel-$previousoffset);
		else if (($level == -1) && ($positioninlevel == -1) && (count($this->path) > 1))
			$this->previouslink = Navigate::make_relative_link($level,$positioninlevel-$previousoffset);
		else
			$this->previouslink = "___";
		$level=$depth-1;
		$positioninlevel=Navigate::my_array_search($this->pathsarray[$level],$this->path[$level]);
		while (($level >= 0) && ($positioninlevel == (count($this->pathsarray[$level])-1)))
			{
			$level=$level-1;
			if ($level >= 0)
				$positioninlevel=Navigate::my_array_search($this->pathsarray[$level],$this->path[$level]);
			}
		if ($level >= 0)
			$this->nextlink = Navigate::make_relative_link($level,$positioninlevel+1);
		else
			$this->nextlink = "___";
		}
	
#######################################################
#	Breadcrumb function					
#######################################################
	
	function breadcrumb($separator,$roottitle)
		{
		# Print out the Link to the Homepage 
		Navigate::print_link($this->urlbase,$roottitle);
		# Loop through the array printing out the link to the respective directory or file 
		$url=$this->urlbase.$this->filebase;
 		for($i=0; $i<count($this->path) ; $i++) 
			{ 
 			#Append the next directory or file down to the URL 
 			$url = $url . "/" . $this->path[$i];
 			# Format the link text 
 			$linktext = Navigate::make_link_name($this->path[$i]);
 			# Print Out the URL With The Formatted Link Text
			if ((strcmp($this->path[$i],"index.html")) &&
				(strcmp($this->path[$i],"index.htm")))
				{
				echo $separator;
	 			Navigate::print_link($url,$linktext); 
				}
 			} 
		}
#######################################################
#	directory function	
#	make a directory where the index.html is missing				
#######################################################
	
	function directory()
		{
		global $messages;
		$endofpath=count($this->path)-2;
		if ($endofpath>=0)
			echo Navigate::make_link_name($this->path[$endofpath]);
		else
			echo "Home";
		if (count($this->pathsarray[$endofpath+1]) == 0)
			{
			echo $messages["empty"];
			return;
			}
		$dirurl=$this->urlbase.$this->filebase;
		for ($j=0 ; $j < (count($this->path)-1) ; $j++)
			$dirurl .= "/".$this->path[$j];
 		for($i=0; $i<count($this->pathsarray[$endofpath+1]) ; $i++) 
			{ 
 			if ((strcmp($this->pathsarray[$endofpath+1][$i],"index.html")) &&
					(strcmp($this->pathsarray[$endofpath+1][$i],"index.htm")) )
				{
 			$linktext = Navigate::make_link_name($this->pathsarray[$endofpath+1][$i]);
				$url = $dirurl."/".$this->pathsarray[$endofpath+1][$i];
 			# Make the link
				echo "<br>";
	 			Navigate::print_link($url,$linktext); 
				}
 		}
		echo "<br>"; 
		}

#######################################################
#	people directory function	
#	make a people directory (the index.html is missing)				
#######################################################
	
	function people_directory()
		{
		if ($dir = opendir($documentroot.$currentfilepath)) 
			{
			while (false !==($file = readdir($dir))) 
				{
				if (($file != "index.html")&&($file != "..")&&($file != "."))
				{
					$fullfilepath="$documentroot"."$currentfilepath"."/"."$file";
					#we only display .htm* files, .txt, pdf files and directories**2.2.6
					if 	
						( 
                     ( 
                        (eregi("^(.*).pdf$",$file)
                           ||eregi("^(.*).txt$",$file)
                           ||eregi("^(.*).htm$",$file)
                           ||eregi("^(.*).html$",$file)
                        )
                        &&    
                        (!is_link($fullfilepath))
                     )
							|| 
						   (is_dir ($fullfilepath))
                  ) 
					{
						$this->pathsarray[$level][$levelpoint++] = $file;
					};
					if (eregi("^(.*).hdr([0-9])$",$file,$analysis) )
					{
						sscanf($analysis[2],"%d",&$headerno); 
						$this->headers[$headerno]=$fullfilepath;
						}
					if (eregi("^(.*).ftr([0-9])$",$file,$analysis) )
						{
						sscanf($analysis[2],"%d",&$footerno); 
						$this->footers[$footerno]=$fullfilepath;
						}
					};
				};
			closedir($dir);
			$validlevel=$level;
			}
		if (count($this->pathsarray[$endofpath+1]) == 0)
			{
			echo $messages["empty"];
			return;
			}
		$dirurl=$this->urlbase.$this->filebase;
		for ($j=0 ; $j < (count($this->path)-1) ; $j++)
			$dirurl .= "/".$this->path[$j];
 		for($i=0; $i<count($this->pathsarray[$endofpath+1]) ; $i++) 
			{ 
 			if ((strcmp($this->pathsarray[endofpath+1][$i],"index.html")) &&
					(strcmp($this->pathsarray[endofpath+1][$i],"index.htm")) )
				{
 			$linktext = Navigate::make_link_name($this->pathsarray[$endofpath+1][$i]);
				$url = $dirurl."/".$this->pathsarray[$endofpath+1][$i];
 			# Make the link
				echo "<br>";
	 			Navigate::print_link($url,$linktext); 
				}
 		}
		echo "<br>"; 
		}

#######################################################
#	nextlink function						
#	generate link to next page				
#									
#									
#									 
#######################################################
	
	function nextlink($nextlinklabel)
		{
		if (strcmp($this->nextlink,"___"))
			Navigate::print_link($this->nextlink,$nextlinklabel);
		else
			echo("&nbsp;");
		}

#######################################################
#	previouslink function					
#	generate link to previous page			
#									
#									
#									 
#######################################################
	
	function previouslink($previouslinklabel)
		{
		if (strcmp($this->previouslink,"___"))
			Navigate::print_link($this->previouslink,$previouslinklabel);
		else
			echo("&nbsp;");
		}

#######################################################
#	page body function					
#	generate page body					
#	page body (or directory if index.html missing	
#######################################################
	
	function body()
		{
		global $messages;
		if (is_file($this->filepathabsolute))
			{
			if (eregi("^(.*).txt$",$this->filepathabsolute))
				{
				$this->filecontents = $this->htmlfileobject->filecontents;
				$this->filecontents = htmlentities($this->filecontents);
				$this->filecontents = "<pre>".$this->filecontents."</pre>";#tt replaced by per with 2.2.5
				}
			else
				$this->filecontents = $this->htmlfileobject->bodycontents;
			print($this->filecontents);
			}
		else
			{
			if ((strpos($this->filepathabsolute,"index.htm")=== false)&&(!is_dir($this->filepathabsolute)))
				#are we requesting a directory or file that does not exist?
				{
				if (is_file($this->documentroot.$this->filebase."/missing.html"))
					readfile($this->documentroot.$this->filebase."/missing.html");
				else
					echo("<br>".$messages["notexist"]."<br>");
				}
			else #we are requesting an index for a directory that exists but has no index.htm* so create an 
				#artificial index
				{
				Navigate::directory();
				}
			};
 
		}
		


#######################################################
#	page footer function -added by NAZ 12.09.2002
#   displays footer file(s)																			
#######################################################
   function pageFooter()
   {
   	foreach ($this->footers as $footerFile)
			{
			if (is_file($footerFile) || is_link($footerFile)) // symbolic links allowed 2002/11/08 CS
				{
				$htmlfile = new HtmlFile ($footerFile);
				print($htmlfile->bodycontents);
				}
			}
   }


#######################################################
#	page update function -added by NAZ 12.09.2002															
#######################################################
   function pageUpdateTime()
   {
   	if (is_file($this->filepathabsolute))
			{
			print( date(": Y-m-d H:i:s",filemtime($this->filepathabsolute)));
			}
   }


#######################################################
#	my_array_search						
#	search an array of strings for a string		
# 	need this because we don't have PHP 4.0.5		
#									
#######################################################
	function my_array_search($array,$str)	
		{
		for ($i=0;$i<count($array);$i++)
			{
			if (!strcmp($array[$i],$str))
				return $i; 
			}
		return -1;
		}
#######################################################
#	my_find_file_position					
#	if file is index.html					
#	position is automatically -1				
#									
#######################################################
	function my_find_file_position($array,$str)	
		{
		return -1;
		}

#######################################################
#	dir_has_contents					
#	true only if a directory has appropriate contents					
#	added for ***2.2.5  cs
#									
#######################################################
	function dir_has_contents($fpath)	
		{
      # check for htm* txt pdf files
      # check directories recursively
		/*return true; #2.2.5 dummy to be filled in*/
		
      if ($dir = opendir($fpath)) 
			{
			while (false !==($file = readdir($dir))) 
				{
				if ($file[0] != '.')
					{
               $fullfilepath=$fpath."/".$file;
					if (
                     ( 
                        (eregi("^(.*).pdf$",$file)
                           ||eregi("^(.*).txt$",$file)
                           ||eregi("^(.*).htm$",$file) 
                           ||eregi("^(.*).html$",$file)
                        )
                        &&    
                        (!is_link($fullfilepath))
                     )
							|| 
						   (is_dir($fullfilepath) && Navigate::dir_has_contents($fullfilepath))
                  )
                  return true;
               }
            }
         } 
      return false;  
		}


#######################################################
#	callTemplateFunction				
#	 					
#	check no of parameters and call the function
# 	escaped paramter strings are expanded by using create_function 
#	to make a lambda function which we then execute!
#	
#									
#######################################################
	function callTemplateFunction($funcName,$params)	
		{
		for ($i=0;$i<count($params);$i++)
			{
			if (strstr($params[$i],"\\"))
				{
				$func=create_function("","return \"" . $params[$i] . "\";");
				$params[$i]=$func();
				}
			}
		if ((strcmp(trim($funcName), "body")==0) && ((count($params) == 0)||(!isset($params))))
			Navigate::body();
		elseif ((strcmp(trim($funcName),"printtitle")==0) && (count($params) == 1))
			Navigate::printtitle($params[0]);
		elseif ((strcmp(trim($funcName),"breadcrumb")==0) && (count($params) == 2))
			Navigate::breadcrumb($params[0],$params[1]);
		elseif ((strcmp(trim($funcName),"nextlink")==0) && (count($params) == 1))
			Navigate::nextlink($params[0]);
		elseif ((strcmp(trim($funcName),"previouslink")==0) && (count($params) == 1))
			Navigate::previouslink($params[0]);
		elseif ((strcmp(trim($funcName),"sidebar")==0) && (count($params) == 1))
			Navigate::sidebar($params[0]);
		elseif ((strcmp(trim($funcName),"pageHeader")==0) && (count($params) == 0))
			Navigate::pageHeader();
		elseif ((strcmp(trim($funcName),"pageFooter")==0) && (count($params) == 0))
			Navigate::pageFooter();

		elseif ((strcmp(trim($funcName),"pageUpdateTime")==0) && (count($params) == 0))
			Navigate::pageUpdateTime();
		
		else
			{
			print("\n<br>Unknown template function or wrong parameter ".$funcName);
			print(count($params));
			return false;
			}
		return true;
		}

#######################################################
#	processTemplatePiece				
#	process the a piece of template 					
#	if this is text it is simply ouput
#	if not a function is called
#									
#######################################################
	function processTemplatePiece($piece)	
		{
		$funcParams=array();
		if (eregi("^!cs!([^;]*);",$piece,$analysis) )
			{
			if (eregi("(.*)\(([^,]*)(,[^,]*)*\)",$analysis[1],$funcAndParams))
				{
				for ($j=2;$j<count($funcAndParams);$j++)
					{
					if ($funcAndParams[$j] !=null)
						{
						if(eregi(",?\"(.*)\"",$funcAndParams[$j],$params[$j-2]))
							{
							$funcParams[$j-2]=$params[$j-2][1];
							}
						else
							{	
							printf ("\n<br>Invalid template function parameter %s",$funcAndParams[$j]);
							return false;
							}
						}
					}
				return Navigate::callTemplateFunction($funcAndParams[1],$funcParams);
				}
			else
				{
				printf("\n<br>Invalid function call in template  > %s", $analysis[1]);
				return false;
				}
			}
		else if (eregi("^&>(.*)",$piece,$analysis))
			print($analysis[1]);#this was a filler end tag print the following text
		else
			print($piece);
		
		return true;
		}
#######################################################
#	processTemplate				
#	process the default template at this point in the tree					
#	this is actually where the page is output
#									
#######################################################
	function processTemplate()	
		{
		#read the template file in
		if (is_file($this->templates[0]))
			{
			$fp=fopen($this->templates[0],"rb");
			$templateString=fread($fp,filesize($this->templates[0]));
			fclose($fp);
			}
		else
			{
			echo "No Template found";
         echo "File path =  $this->templates[0]";
			return false;
			}
		$templatePieces = explode ("<!%%",$templateString);
		#now loop through the pieces just outputting the text
		#and processing the function calls.
		$pieceCount=count($templatePieces);
		for ($i=0;$i<$pieceCount;$i++)
			if (!Navigate::processTemplatePiece($templatePieces[$i]))
				{
				printf("\n<br>Template Error, Processing > %s",$templatePieces[$i]);
				return false; 
				}
		return true;
		}


	

#######################################################
#	Constructor for Navigate class			
#	Obtains path and prepares class data for 		
#	the generation of navigation menus			
#######################################################

	function Navigate($httphost,$querystring,$documentroot,$filebaseset)
		{
		#Base URL 
		$this->urlbase = "http://".$httphost;
		$this->documentroot=$documentroot;
		#base directory for our rewritten pages
		$this->filebase = $filebaseset;
		# Link Text for the link to the base URL
		$roottitle = "Home"; 
		#Split the path into an array using a forward slash 
		$this->path = explode ("/", $querystring);
		$this->title = implode(" ",$this->path); 
		$depth = count ($this->path);
		$currentfilepath=$this->filebase;
		$this->filepathabsolute=$documentroot.$this->filebase."/".$querystring;
		$this->pathsarray=array();
		$this->headers=array();
		$this->footers=array();
		$this->templates=array();
		$this->settings=array();
		$validlevel = 0;
		# construct the two d array for the cascading menu
		for($level=0; $level<$depth ; $level++) 
			{ 
		 # make the array here	
			$this->pathsarray[$level]=array();
			$levelpoint=0;
			if ($dir = opendir($documentroot.$currentfilepath)) 
				{
				while (false !==($file = readdir($dir))) 
					{
					if (($file != "index.html")&&($file != "index.htm")&&($file[0] != '.'))
						{
						$fullfilepath="$documentroot"."$currentfilepath"."/"."$file";
						#we only display .htm* files, .txt files and directories
                  #from 2.2.5 .pdf files added and empty directories excluded
						/*if 	(
							(($filedisplay != $file) && (!is_link($fullfilepath)))
								|| 
							((is_dir ($fullfilepath)) 
                        && (Navigate::dir_has_contents ($fullfilepath)) #***2.2.5
								)
							)*/
                  if (
                     ( 
                        (eregi("^(.*).pdf$",$file)
                           ||eregi("^(.*).txt$",$file)
                           ||eregi("^(.*).htm$",$file) 
                           ||eregi("^(.*).html$",$file)
                        )
                        &&    
                        (!is_link($fullfilepath))
                     )
							|| 
						   (is_dir($fullfilepath) && Navigate::dir_has_contents($fullfilepath))
                  )
							{
							$this->pathsarray[$level][$levelpoint++] = $file;
							};
						if (ereg("^(.*).hdr([0-9])$",$file,$analysis))
							{
							sscanf($analysis[2],"%d",&$headerno); 
							$this->headers[$headerno]=$fullfilepath;
							}
						if (ereg("^(.*).ftr([0-9])$",$file,$analysis) )
							{
							sscanf($analysis[2],"%d",&$footerno); 
							$this->footers[$footerno]=$fullfilepath;
							}
						if (ereg("^(.*).tpl([0-9])$",$file,$analysis) )
							{
							sscanf($analysis[2],"%d",&$templateno); 
							$this->templates[$templateno]=$fullfilepath;
							}
						if (ereg("^(.*).set([0-9])$",$file,$analysis) )
							{
							sscanf($analysis[2],"%d",&$settingno); 
							$this->settings[$settingno]=$fullfilepath;
							}
						};
					};
				closedir($dir);
				$validlevel=$level;
				}
			else if (is_file($documentroot.$currentfilepath))
				$validlevel=$level;
	 	sort($this->pathsarray[$level]);
			#Append the next directory or file down to the file path 
	 		$currentfilepath = $currentfilepath . "/" . $this->path[$level]; 
			}
		$this->htmlfileobject = new HtmlFile($this->filepathabsolute);
		ksort($this->footers);
		ksort($this->headers);
		ksort($this->templates);
		ksort($this->settings);
		Navigate::find_next_and_previous();
		}
	}
?>