<?php

// Global vars
$RequestURI		= '';
$Directory		= '';
$sSortField		= '';
$FileArray		= Array();
$bTaskBar		= false;
$fDirSize		= 0;

$os = strtolower(PHP_OS);

if (strpos($os, 'win') !== false) {
	$os = 'windows';
}

$sapi = PHP_SAPI;

if (strpos($sapi, 'apache') !== false) {
	$sapi = 'apache';
}

// Get te sortkey
preg_match('/sort=([a-z]+)/', $_SERVER['QUERY_STRING'], $GetSort);
$GetSort = (count($GetSort) < 2) ? '' : $GetSort[1];

// Only accept valid sort items, else it will be defaulted to SORT_TYPE
switch ($GetSort) {
	case 'char':
	case 'name':
		$sSortField = SORT_NAME;
		break;
	case 'size':
		$sSortField = SORT_SIZE;
		break;
	case 'modify':
		$sSortField = SORT_MODIFY;
		break;
	case 'access':
		$sSortField = SORT_ACCESS;
		break;
	case 'owner':
		$sSortField = SORT_OWNER;
		break;
	case 'group':
		$sSortField = SORT_GROUP;
		break;
	case 'permission':
		$sSortField = SORT_PERMISSION;
		break;
	case 'description':
	case 'type':
	default:
		$sSortField = SORT_TYPE;
}

header('Content-type: text/html; charset=UTF-8');

// Parse the url to the physical directory
ParseURL($RequestURI, $Directory);

// The title of the page, should be the same as the address displayed by the browser
// Tricky part: Forwarded servers
switch ($sapi) {
	case 'apache':
		$sTitle = ((array_key_exists('HTTP_X_FORWARDED_SERVER', $_SERVER)) ? $_SERVER['HTTP_X_FORWARDED_SERVER'] : $_SERVER['SERVER_NAME']) . rawurldecode($_SERVER['REQUEST_URI']);
		break;
	case 'isapi':
		$sTitle = explode('/', $_SERVER['QUERY_STRING']);

		for ($i = 0; $i < count($sTitle); $i++) {
			if ($sTitle[$i] == $_SERVER['hostname']) {
				$sTitle = array_slice($sTitle, $i + 2);
				break;
			}
		}

		$sTitle = '/' . implode('/', $sTitle);
		$sTitle = ((array_key_exists('HTTP_X_FORWARDED_SERVER', $_SERVER)) ? $_SERVER['HTTP_X_FORWARDED_SERVER'] : $_SERVER['SERVER_NAME']) . rawurldecode($sTitle);
		break;
}

function ParseURL(&$RequestURI, &$Directory) {
	global $XPIndexConf, $ApacheConf;

	if ($XPIndexConf['Hide XPindex Dir'] == true) {
		// Hide the XPindex source

		switch ($GLOBALS['sapi']) {
			case 'apache':
				$bXPindexDir = strpos(rawurldecode($_SERVER['REQUEST_URI']), $XPIndexConf['Web Directory']);
				break;
			case 'isapi':
				$bXPindexDir = strpos(rawurldecode($_SERVER['QUERY_STRING']), $XPIndexConf['Web Directory']);
				break;
		}

		if ($bXPindexDir !== false) {
			// Make the browser understand it's an error
			header('HTTP/1.0 404 Not Found');
			header('Status: 404 Not Found');
			// Do some advertising, the apache 404 page would be nicer
			echo '<a href="' . XPindex_URL . '">XPindex ' . XPindex_Version . '</a> ' . _("by") . '<a href="mailto:' . XPindex_AuthorMail . '">' . XPindex_Author . '</a>.';
	    	exit();
		}
	}

	switch ($GLOBALS['sapi']) {
		case 'apache':
			$RequestURI = $_SERVER['REQUEST_URI'];

			$DocumentRoot = rawurldecode($_SERVER['DOCUMENT_ROOT']);
			$RequestURI = $_SERVER['REQUEST_URI'];
			$RequestURI = rawurldecode(substr($_SERVER['REQUEST_URI'], 0, (strpos($RequestURI, '?')) ? strpos($RequestURI, '?') : strlen($RequestURI)));
			$Directory = $DocumentRoot . $RequestURI;

			$d = @dir($Directory);

			if ($d === false) {
				$RequestedDir	= substr($RequestURI, 2);
				$UserDir		= substr($RequestedDir, 0, strpos($RequestedDir, DIRECTORY_SEPARATOR));
				$RequestedDir	= substr($RequestedDir, strpos($RequestedDir, DIRECTORY_SEPARATOR));

				$Directory = rawurldecode($ApacheConf['User Directories'] . DIRECTORY_SEPARATOR . $UserDir . DIRECTORY_SEPARATOR . $ApacheConf['User HTML Directory'] . $RequestedDir);
			} else {
				$d->close();
			}
			break;
		case 'isapi':
			$RequestURI = explode('/', $_SERVER['QUERY_STRING']);

			for ($i = 0; $i < count($RequestURI); $i++) {
				if ($RequestURI[$i] == $_SERVER['hostname']) {
					$RequestURI = array_slice($RequestURI, $i + 2);
					break;
				}
			}

			$RequestURI = DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $RequestURI);

			$RequestURI = rawurldecode(substr($RequestURI, 0, (strpos($RequestURI, '?')) ? strpos($RequestURI, '?') : strlen($RequestURI)));
			$DocumentRoot = rawurldecode($_SERVER['DOCUMENT_ROOT']);
			$Directory = $DocumentRoot . $RequestURI;
			break;
	}

	// Make sure the directoryname doesn't include a trailing slash
	if (substr($Directory, -1) == '/') {
		$Directory = substr($Directory, 0, strlen($Directory)-1);
 	}
}

function ParseDir($Directory) {
	global $sSortField, $FileArray;

	switch ($GLOBALS['os']) {
		case 'netware':
			$FileMgr = new UCS('UCX:NWFileMgr');
			$Dir = $FileMgr->findentry($Directory);
			$Entries = $Dir->getchildren();
			$Entries->reset();

			while ($Entries->hasmoreelements()) {
				$Entry = $Entries->next();
				$FilePath = $Directory . '/' . $Entry->{'Name'};

				AddFileToArray($FileArray, Array(
					'Name'			=> $Entry->{'Name'},
					'Directory'		=> $Entry->{'Directory'},
					'Size'			=> $Entry->{'Size'},
					'Owner'			=> $Entry->{'Owner'},
					'Permission'	=> $Entry->{'Attributes'},
					'Modify'		=> filemtime($FilePath),
					'Access'		=> fileatime($FilePath)
				));
			}
			break;
		default:
			$Dir = @dir($Directory);

			while ($Entry = $Dir->read()) {
				$FilePath = $Directory . '/' . $Entry;

				AddFileToArray($FileArray, Array(
					'Name'			=> $Entry,
					'Directory'		=> is_dir($FilePath),
					'Size'			=> filesize($FilePath),
					'Owner'			=> GetFileOwner($FilePath),
					'Group'			=> GetFileGroup($FilePath),
					'Permission'	=> fileperms($FilePath),
					'Modify'		=> filemtime($FilePath),
					'Access'		=> fileatime($FilePath)
				));
			}

			$Dir->close();
	}

	aasort($FileArray, 'Type');

	if (count($FileArray) > 0 && ($FileArray[0]['Type'] & (FT_DIRECTORYREFRESH|FT_DIRECTORYUP))) {
		$Dots = array_splice($FileArray, 0, 1);
		PrintFile($Dots[0], NULL, FT_DIRECTORYREFRESH);
	}

	if (count($FileArray) > 0 && ($FileArray[0]['Type'] & (FT_DIRECTORYREFRESH|FT_DIRECTORYUP))) {
		$Dots = array_splice($FileArray, 0, 1);
		PrintFile($Dots[0], NULL, FT_DIRECTORYUP);
	}

	aasort($FileArray, $sSortField);

	$CurrentGroup = Array();
	$CurrentGroup['Sortvalue'] = '';
	$CurrentGroup['Items'] = Array();

	array_walk($FileArray, 'WalkGroups', &$CurrentGroup);

	if (count($CurrentGroup['Items']) > 0) {
		aasort($CurrentGroup['Items'], 'Name');

		array_walk($CurrentGroup['Items'], 'PrintFile', FT_DIRECTORY);
		array_walk($CurrentGroup['Items'], 'PrintFile', FT_FILE);
	}
}

function AddFileToArray(&$FileArray, $Entry) {
	global $ApacheConf, $Extensions, $IncrementalExtensions, $XPIndexConf;

	if (($Entry['Directory'] == false) && ((array_key_exists($Entry['Name'], $ApacheConf['Readme Files'])) && ($ApacheConf['Readme Files'][$Entry['Name']][1] == false))) {
		return;
	}

	if (!$Entry['Directory']) {
		$Entry['Type'] = FT_FILE;
		$Entry['URL'] = rawurlencode($Entry['Name']);
	} else if ($Entry['Name'] == '.') {
		$Entry['Type'] = FT_DIRECTORYREFRESH;
		$Entry['URL'] = './';
	} else if ($Entry['Name'] == '..') {
		$Entry['Type'] = FT_DIRECTORYUP;
		$Entry['URL'] = '../';
	} else {
		$Entry['Type'] = FT_DIRECTORY;
		$Entry['URL'] = rawurlencode($Entry['Name']) . '/';
	}

	$Entry['Extension'] = split('\.', $Entry['Name']);
	$Entry['Extension'] = strtolower((count($Entry['Extension']) > 1 ? array_pop($Entry['Extension']) : ''));

	if ($Entry['Type'] == FT_DIRECTORYREFRESH) {
		$Entry['Extension'] = '.';
	} else if ($Entry['Type'] == FT_DIRECTORYUP) {
		$Entry['Extension'] = '..';
	} else if ($Entry['Type'] == FT_DIRECTORY) {
		$Entry['Extension'] = '^^DIRECTORY^^';
	} else if (preg_match('/^(\D{1})\d{2}$/', $Entry['Extension'], $matches)) {
		if (array_key_exists($matches[1], $IncrementalExtensions)) {
			$Entry['Extension'] = $IncrementalExtensions[$matches[1]];
		}
	}

	if ($Entry['Type'] & (FT_DIRECTORYREFRESH|FT_DIRECTORYUP)) {
		$Entry['Description'] = '';
	} else if (array_key_exists($Entry['Extension'], $Extensions)) {
		$Entry['Description'] = $Extensions[$Entry['Extension']];
	} else if ($Entry['Extension'] != '') {
		$Entry['Description'] = strtoupper($Entry['Extension']) . _("-") . _("File");
	} else if ($Entry['Type'] == FT_FILE) {
		$Entry['Description'] = ucfirst(_("File"));
	}

	if ($Entry['Type'] == FT_FILE) {
		$GLOBALS['fDirSize'] += $Entry['Size'];
	} else {
	 	$Entry['Size'] = '';
	}

	$Entry['Char'] 		= strtoupper($Entry['Name'][0]);
	$Entry['SizeGroup']	= GetSizeGroup($Entry['Size']/1024, $Entry['Type']);
	$Entry['ModifyGrp']	= GetDateGroup($Entry['Modify']);
	$Entry['AccessGrp']	= GetDateGroup($Entry['Access']);

	if (!(($Entry['Type'] == FT_FILE) && ($Entry['Char'] == '.'))) {
		// Skip files which have a . as first character of the name
		$FileArray[] = $Entry;
	}
}

function GetFileOwner($File) {
	if (!strpos(' windows netware', $GLOBALS['os'])) {
		$File = posix_getpwuid(fileowner($File));

		return $File['name'];
	}
}

function GetFileGroup($File) {
	if (!strpos(' windows netware', $GLOBALS['os'])) {
		$File = posix_getgrgid(filegroup($File));

		return $File['name'];
	}
}

function aasort(&$FileArray, $SortColumn, $SortFlags = 'strcasecmp') {
	if (is_string($SortColumn)) $SortColumn = "'$SortColumn'";

	uasort($FileArray, create_function('$a, $b', 'return ' . $SortFlags . ' ($a[' . $SortColumn . '], $b[' . $SortColumn . ']);'));
}

function GetSizeGroup($Value, $FileType) {
	if ($FileType != FT_FILE) {
		return 9;
	} else if ($Value == 0) {
		return 1;
	} else if ($Value < pow(2, 5)) {
		return 2;
	} else if ($Value < pow(2, 7)) {
		return 3;
	} else if ($Value < pow(2, 10)) {
		return 4;
	} else if ($Value < pow(2, 14)) {
		return 5;
	} else if ($Value < pow(2, 17)) {
		return 6;
	} else {
		return 7;
	}
}

function GetDateGroup($Value) {
	$Date = getdate($Value);

	$Today = getdate();

	if ($Date[0] > $Today[0]) {
		// Future
		if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['mday'] == $Today['mday'])) {
			return '01';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['mday'] == $Today['mday'] + 1)) {
			return '13';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['mday'] == $Today['mday'] + 2)) {
			return '14';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['yday'] <= ($Today['yday'] + (7 - $Today['wday'])))) {
			return '15';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon'])) {
			return '16';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon'] + 1)) {
			return '17';
		} else if ($Date['year'] == $Today['year']) {
			return '18';
		} else if ($Date['year'] == $Today['year'] + 1) {
			return '19';
		} else if ($Date['year'] == $Today['year'] + 2) {
			return '20';
		} else {
			return '21';
		}
	} else {
		// Past
		if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['mday'] == $Today['mday'])) {
			return '01';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['mday'] == $Today['mday'] - 1)) {
			return '02';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['yday'] >= ($Today['yday'] - $Today['wday']))) {
			return '03';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['yday'] >= ($Today['yday'] - $Today['wday'] - 7))) {
			return '04';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon']) && ($Date['yday'] >= ($Today['yday'] - $Today['wday'] - 14))) {
			return '05';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon'])) {
			return '06';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon'] - 1)) {
			return '07';
		} else if (($Date['year'] == $Today['year']) && ($Date['mon'] == $Today['mon'] - 2)) {
			return '08';
		} else if ($Date['year'] == $Today['year']) {
			return '09';
		} else if ($Date['year'] == ($Today['year'] - 1)) {
			return '10';
		} else if ($Date['year'] == ($Today['year'] - 2)) {
			return '11';
		} else {
			return '12';
		}
	}
}

function DisplayFilePermissions($Mode) {
	switch ($GLOBALS['os']) {
		case 'netware':
			$Perm = '';
			if ($Mode & 0x20000000)
				$Perm .= 'Cc';		// Can't compress
			if ($Mode & 0x08000000)
				$Perm .= 'Dc';		// Don't compress
			if ($Mode & 0x02000000)
				$Perm .= 'Ic';		// Immediate compress
			if ($Mode & 0x00800000)
				$Perm .= 'Dm';		// Don't migrate
			if ($Mode & 0x00400000)
				$Perm .= 'M';		// Migrated
			if ($Mode & 0x00080000)
				$Perm .= 'Ci';		// Copy inhibit
			if ($Mode & 0x00040000)
				$Perm .= 'Di';		// Delete inhibit
			if ($Mode & 0x00020000)
				$Perm .= 'R';		// Rename inhibit
			if ($Mode & 0x00010000)
				$Perm .= 'P';		// Purge immediate
			if ($Mode & 0x2000)
				$Perm .= 'I';		// Indexed
			if ($Mode & 0x1000)
				$Perm .= 'T';		// Transactional
			if ($Mode & 0x0080)
				$Perm .= 'Sh';		// Shareable
			if ($Mode & 0x0020)
				$Perm .= 'A';		// Archive needed
//			if ($Mode & 0x0010)
//				$Perm .= 'D';		// Directory
			if ($Mode & 0x0008)
				$Perm .= 'X';		// Execute only
			if ($Mode & 0x0004)
				$Perm .= 'Sy';		// System
			if ($Mode & 0x0002)
				$Perm .= 'H';		// Hidden
			if ($Mode & 0x0001)
				$Perm .= 'Ro';		// Read-only
			return $Perm;
		case 'windows':
			if ($Mode == 16895) {
				return '';		// Directory
			} else if ($Mode == 33060) {
				return 'R';		// Read only
			} else if ($Mode == 33206) {
				return '';		// Regular
			}
			break;
		default:
			// Determine Type
			if ($Mode & 0x1000) {
				$Type = 'p';	// FIFO pipe
			} else if ($Mode & 0x2000) {
				$Type = 'c';	// Character special
			} else if ($Mode & 0x4000) {
				$Type = 'd';	// Directory
			} else if ($Mode & 0x6000) {
				$Type = 'b';	// Block special
			} else if ($Mode & 0x8000) {
				$Type = '-';	// Regular
			} else if ($Mode & 0xA000) {
				$Type = 'l';	// Symbolic Link
			} else if ($Mode & 0xC000) {
				$Type = 's';	// Socket
			} else {
				$Type = 'u';	// UNKNOWN
			}

			// Determine permissions
			$Owner['read']    = ($Mode & 00400) ? 'r' : '-';
			$Owner['write']   = ($Mode & 00200) ? 'w' : '-';
			$Owner['execute'] = ($Mode & 00100) ? 'x' : '-';
			$Group['read']    = ($Mode & 00040) ? 'r' : '-';
			$Group['write']   = ($Mode & 00020) ? 'w' : '-';
			$Group['execute'] = ($Mode & 00010) ? 'x' : '-';
			$World['read']    = ($Mode & 00004) ? 'r' : '-';
			$World['write']   = ($Mode & 00002) ? 'w' : '-';
			$World['execute'] = ($Mode & 00001) ? 'x' : '-';

			// Adjust for SUID, SGID and sticky bit
			if ($Mode & 0x800) $Owner['execute'] = ($Owner['execute'] == 'x') ? 's' : 'S';
			if ($Mode & 0x400) $Group['execute'] = ($Group['execute'] == 'x') ? 's' : 'S';
			if ($Mode & 0x200) $World['execute'] = ($World['execute'] == 'x') ? 't' : 'T';

			return
				$Type
				. $Owner['read'] . $Owner['write'] . $Owner['execute']
				. $Group['read'] . $Group['write'] . $Group['execute']
				. $World['read'] . $World['write'] . $World['execute'];
	}
}

function DisplayFileSize($Value) {
	if ($Value === '') {
		return '';
	} else if ($Value < pow(2, 10)) {
		return number_format($Value, 0, ',', '.') . ' B';
	} else if ($Value < pow(2, 20)) {
		return number_format($Value/pow(2, 10), 0, ',', '.') . ' kB';
	} else if ($Value < pow(2, 30)) {
		return number_format($Value/pow(2, 20), 0, ',', '.') . ' MB';
	} else {
		$return = number_format($Value/pow(2, 30), 0, ',', '.') . ' GB';
	}
}

function DisplayTotalFileSize($Value) {
	if ($Value === '') {
		return '';
	} else if ($Value < pow(2, 10)) {
		$return = number_format($Value, 0, ',', '.') . ' bytes';
	} else if ($Value < pow(2, 10) * 100) {
		$return = number_format($Value/pow(2, 10), 2, ',', '.') . ' kB';
	} else if ($Value < pow(2, 20)) {
		$return = number_format($Value/pow(2, 10), 0, ',', '.') . ' kB';
	} else if ($Value < pow(2, 20) * 100) {
		$return = number_format($Value/pow(2, 20), 1, ',', '.') . ' MB';
	} else if ($Value < pow(2, 30)) {
		$return = number_format($Value/pow(2, 20), 0, ',', '.') . ' MB';
	} else {
		$return = number_format($Value/pow(2, 30), 2, ',', '.') . ' GB';
	}

	return preg_replace('/,00/', '', $return);
}

function WalkGroups($File, $Counter, $CurrentGroup) {
	global $sSortField;

	if ($CurrentGroup['Sortvalue'] != $File[$sSortField]) {
		if (count($CurrentGroup['Items']) > 0) {
			aasort($CurrentGroup['Items'], 'Name');

			array_walk($CurrentGroup['Items'], 'PrintFile', FT_DIRECTORY);
			array_walk($CurrentGroup['Items'], 'PrintFile', FT_FILE);
		}

		$CurrentGroup['Items'] = Array();

		$CurrentGroup['Sortvalue'] = $File[$sSortField];
		PrintGroup($CurrentGroup['Sortvalue']);
	}

	$CurrentGroup['Items'][$File['Name']] = $File;
}

function PrintGroup($GroupName) {
	global $sSortField, $SizeGroups, $DateGroups;

	switch($sSortField) {
		case SORT_SIZE:
			$GroupName = $SizeGroups[$GroupName];
			break;
		case SORT_MODIFY:
		case SORT_ACCESS:
			$GroupName = $DateGroups[$GroupName];
			break;
		case SORT_PERMISSION:
			$GroupName = DisplayFilePermissions($GroupName);
			break;
	}

?>								<tr>
									<td colspan="8"></td>
								</tr>
								<tr>
									<td colspan="8" class="group"><?php echo $GroupName?></td>
								</tr>
<?php
}

function PrintFile($File, $Counter, $FileType) {
	if ($File['Type'] == $FileType) {
		global $XPIndexConf, $Icons;

		$FileIcon = '';

		if (array_key_exists($File['Extension'], $Icons)) {
			$FileIcon = $XPIndexConf['Web Directory'] . '/icons/' . $Icons[$File['Extension']];
		} else {
			$FileIcon = $XPIndexConf['Web Directory'] . '/icons/' . $Icons['^^BLANKICON^^'];
		}
?>								<tr>
									<td class="left"><a href="./<?php echo $File['URL']?>" title="<?php echo $File['Name']?>"><img src="<?php echo $FileIcon?>" class="icon" alt="" />&nbsp;<?php echo $File['Name']?></a></td>
									<td class="right"><?php echo DisplayFileSize($File['Size'])?></td>
									<td class="left"><?php echo $File['Description']?></td>
									<td class="left"><?php echo date('d-m-Y H:m', $File['Modify'])?></td>
<?php	if ($GLOBALS['os'] != 'windows') { ?>
									<td class="left"><?php echo $File['Owner']?></td>
<?php   }
		if (!strpos(' windows netware', $GLOBALS['os'])) { ?>
									<td class="left"><?php echo $File['Group']?></td>
 <?php	} ?>
									<td class="left"><?php echo DisplayFilePermissions($File['Permission'])?></td>
									<td></td>
								</tr>
<?php
	}
}

function CheckForReadme($Readme, $File, $aReadme) {
	if (is_file($GLOBALS['Directory'] . '/' . $File)) {
		$aReadme[] = Array("$File", $Readme);
	}
}

function PrintReadme($Readme, $Priority) {
	global $Directory, $ApacheConf, $XPIndexConf, $Captions;

	$fReadme = @fopen($Directory . '/' . $Readme[0], r);
?>						<table cellspacing="0" cellpadding="0" class="task">
							<tr>
								<th class="task"><?php echo $Readme[1][2]?></th>
							</tr>
							<tr>
								<td class="task">
<?php
	if ($Readme[1][0] == RF_TEXT) {
?>									<div class="task-text"><?php echo preg_replace('/[\s]+/', '<br />', preg_replace('/[ ]/', '&nbsp;', fread($fReadme, filesize($Directory . '/' . $Readme[0]))))?></div>
<?php
	} else {
?>									<div class="task-html"><?php echo fread($fReadme, filesize($Directory . '/' . $Readme[0]))?></div>
<?php
	}
?>								</td>
							</tr>
						</table>
<?php
}

function DrawTaskBar(&$Directory) {
	global $XPIndexConf, $ApacheConf, $bTaskBar;

	array_walk($ApacheConf['Readme Files'], 'CheckForReadme', &$aReadme);

	if (($XPIndexConf['TaskBar'] == 'always') || (($XPIndexConf['TaskBar'] == 'readme') && (count($aReadme) > 0))) {
		$bTaskBar = true;
?>
					<td class="taskbar">
<?php
	}

	if (count($aReadme) > 0) {
		array_walk($aReadme, 'PrintReadme');
	}

	if (($XPIndexConf['TaskBar'] == 'always') || (($XPIndexConf['TaskBar'] == 'readme') && (count($aReadme) > 0))) {
?>
						<div style="width: 240px"></div>
					</td>
<?php
	}
}

function DrawStatusBar() {
	global $XPIndexConf, $FileArray, $fDirSize;
?>			<tr>
				<td class="statusbar" colspan="2">
					<table cellspacing="0" cellpadding="0" class="status">
						<tr>
							<td class="status" style="width: 70%"><?php echo count($FileArray) . ' ' . _("Objects")?></td>
							<td class="status" style="width: 7%"><?php echo DisplayTotalFileSize($fDirSize)?></td>
							<td style="width: 23%; text-align: right"><a href="<?php echo XPindex_URL ?>" class="head">XPindex <?php echo XPindex_Version ?></a> <?php echo _("by") ?> <a href="mailto:<?php echo XPindex_AuthorMail ?>" class="head"><?php echo XPindex_Author ?></a></td>
						</tr>
					</table>
				</td>
			</tr>
<?php
}

function StyleSheets() {
	global $Themes, $XPIndexConf;

	$ThemeOutput = Array();
	$ThemeOutput[0] = ''; // Reserved for the default theme

	$bDefault = false;

	while (list($Name, $Theme) = each($Themes)) {
		if ($Theme['Enabled'] == true) {
			if (($Theme['Default'] == true) && ($bDefault == false)) {
				$bDefault = true;

				$ThemeOutput[0] = "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $XPIndexConf['Web Directory'] . "/themes/$Theme[Name]/$Theme[Name].css\" title=\"$Name\" />\n";
			} else {
				$ThemeOutput[] = "\t\t<link rel=\"alternate stylesheet\" type=\"text/css\" href=\"" . $XPIndexConf['Web Directory'] . "/themes/$Theme[Name]/$Theme[Name].css\" title=\"$Name\" />\n";
			}
		}
	}

	if ($bDefault == false) {
		// No default selected
		$ThemeOutput[0] = "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"" . $XPIndexConf['Web Directory'] . "/basic.css\" title=\"Basic Page Style\" />\n";
	}

	while (list($Key, $Theme) = each($ThemeOutput)) {
		echo $Theme;
	}
}



?>