<?php
include("client/loader.php");

$loader = new FileLoader();

$cssTemplate = "\t\t<link rel=\"stylesheet\" type=\"text/css\" href=\"{file}\">\n";
$jsTemplate = "\t\t<script type=\"text/javascript\" src=\"{file}\"></script>\n";

?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	
	<head>
		<meta name="Generator" content="Zarafa WebApp v<?=phpversion("mapi")?>">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Zarafa WebApp</title>
		<link rel="icon" href="client/resources/images/favicon.ico" type="image/x-icon">
		<link rel="shortcut icon" href="client/resources/images/favicon.ico" type="image/x-icon">
		<?php
			$extjsFiles = $loader->getExtjsCSSFiles(DEBUG_LOADER);
			$loader->printFiles($extjsFiles, $cssTemplate);

			$webappFiles = $loader->getZarafaCSSFiles(DEBUG_LOADER);
			$loader->printFiles($webappFiles, $cssTemplate);

			$pluginFiles = $loader->getPluginCSSFiles(DEBUG_LOADER);
			$loader->printFiles($pluginFiles, $cssTemplate);

			$remoteFiles = $loader->getRemoteCSSFiles(DEBUG_LOADER);
			$loader->printFiles($remoteFiles, $cssTemplate);
		?>
	</head>

	<body>
		<div id="loading-mask"></div>
		<div id="loading">
			<img src="client/resources/images/Zarafa_logo_transparent.png" />
			<span id="loading-message" class="loading"><?= _('Loading Zarafa WebApp ...') ?></span>
		</div>

		<!-- ExtJS & Thirdparty extensions-->
		<?php	
			$extjsFiles = $loader->getExtjsJavascriptFiles(DEBUG_LOADER);
			$loader->printFiles($extjsFiles, $jsTemplate);
		?>

		<!-- Zarafa client stuff -->
		<script type="text/javascript" src="index.php?version=<?=phpversion("mapi")?>&load=translations.js&lang=<?=$GLOBALS["language"]->getSelected()?>"></script>

		<?php
			$webappFiles = $loader->getZarafaJavascriptFiles(DEBUG_LOADER, $extjsFiles);
			$loader->printFiles($webappFiles, $jsTemplate);

			$pluginFiles = $loader->getPluginJavascriptFiles(DEBUG_LOADER, array_merge($extjsFiles, $webappFiles));
			$loader->printFiles($pluginFiles, $jsTemplate);

			$remoteFiles = $loader->getRemoteJavascriptFiles(DEBUG_LOADER);
			$loader->printFiles($remoteFiles, $jsTemplate);
		?>
		
		<script type="text/javascript">
			<?= $GLOBALS["settings"]->getJavaScript(); ?>
		</script>
		<script type="text/javascript">
			<?= $GLOBALS["properties"]->getProperties(); ?>
		</script>
		<script type="text/javascript">
			<?= $GLOBALS["language"]->getJavascript(); ?>
		</script>

		<script type="text/javascript">
			user = {
				username		: "<?= addslashes($GLOBALS["mapisession"]->getUserName()) ?>",
				fullname		: "<?= addslashes($GLOBALS["mapisession"]->getFullName()) ?>",
				entryid			: "<?= bin2hex($GLOBALS["mapisession"]->getUserEntryid()) ?>",
				email_address		: "<?= addslashes($GLOBALS["mapisession"]->getEmailAddress()) ?>",
				smtp_address		: "<?= addslashes($GLOBALS["mapisession"]->getSMTPAddress()) ?>",
				search_key		: "<?= bin2hex($GLOBALS["mapisession"]->getSearchKey()) ?>"
			};
		</script>
	</body>
</html>
