<?

error_reporting(E_ALL);

// xgettext -n -i -L PHP -d XPindex index.php
// xgettext -n -i -L PHP -d XPindex -j include/*.php
// msgfmt XPindex.po -o XPindex.mo

// Languages
$Languages = array(
	'en' 	=> 'en_US',
	'en-au'	=> 'en_US',
	'en-ie'	=> 'en_US',
	'en-nz'	=> 'en_US',
	'en-gb'	=> 'en_US',
	'en-us'	=> 'en_US',
	'en-za'	=> 'en_US',
	'nl'	=> 'nl_NL',
	'nl-be'	=> 'nl_NL'
);

$sLanguage = '';

if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
	$aLanguages = explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']);

	foreach($aLanguages as $sLanguage) {
		$sLanguage = trim(preg_replace('/^(.+);.+$/', '$1', $sLanguage));

		if (isset($Languages[$sLanguage])) {
			$sLanguage = $Languages[$sLanguage];
			putenv("LANG=" . $sLanguage);
			setlocale(LC_ALL, $sLanguage);

			if (extension_loaded('gettext')) {
 				bindtextdomain('XPindex', './locale/');
 				textdomain('XPindex');
 			} else {
				include('./include/gettext.inc.php');
 			}

			break;
		}
	}
}

require('./include/const.inc.php');
require('./include/conf.inc.php');
require('./include/index.inc.php');

echo '<?xml version="1.0" encoding="UTF-8"?>';
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo substr($sLanguage, 0, 2) ?>">
	<head>
		<title>http://<?php echo $sTitle; ?></title>
		<meta name="author" content="<?php echo XPindex_Author; ?>" />
		<meta name="date" content="<?php echo XPindex_Date; ?>" />
		<meta name="description" content="XPindex <?php echo XPindex_Version; ?> by <?php echo XPindex_Author; ?>" />
		<meta name="url" content="<?php echo XPindex_URL; ?>" />
		<link rel="icon" type="image/png" href="<?php echo $XPIndexConf['Web Directory']; ?>/icons/map.png" />
<?php StyleSheets(); ?>
	</head>
	<body>
		<div style="position: absolute; top: 0px; left: 0px;height: 100%">
			<table cellspacing="0" cellpadding="0" class="main">
				<tr>
<?php DrawTaskBar($Directory); ?>
					<td style="width: 100%; vertical-align: top; padding: 0px; height: 100%">
						<table cellspacing="0" cellpadding="0" class="header">
							<thead>
								<tr>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=name" class="head"><?php echo _("Name"); ?></a></th>
									<th class="header-right"><a href="<?php echo $RequestURI?>?sort=size" class="head"><?php echo _("Size"); ?></a></th>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=type" class="head"><?php echo _("Type"); ?></a></th>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=modify" class="head"><?php echo _("Changed"); ?></a></th>
<?php	if ($GLOBALS['os'] != 'windows') { ?>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=owner" class="head"><?php echo _("Owner"); ?></a></th>
<?php	}
		if (!strpos(' windows netware', $GLOBALS['os'])) { ?>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=group" class="head"><?php echo _("Group"); ?></a></th>
<?php	} ?>
									<th class="header-left"><a href="<?php echo $RequestURI?>?sort=permission" class="head"><?php echo _("Attributes"); ?></a></th>
									<th class="fill"></th>
								</tr>
							</thead>
							<tbody>
<?php ParseDir($Directory); ?>
								<tr>
									<td colspan="8"></td>
								</tr>
							</tbody>
						</table>
					</td>
				</tr>
<?php DrawStatusBar(); ?>
			</table>
		</div>
	</body>
</html>
