<?php $localCodebaseVersion = getVersionCurrentLocalCodebase(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!--
    ___   __                  _ __
   /   | / /_____ ___  ____ _(_) /
  / /| |/ __/ __ `__ \/ __ `/ / / 
 / ___ / /_/ / / / / / /_/ / / /  
/_/  |_\__/_/ /_/ /_/\__,_/_/_/

(C) Atmail Pty Ltd http://atmail.com/
-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <?php $this->pluginCall("startHeadTag"); ?>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
	<title><?php if($this->Username == 'admin') echo $this->translate('Atmail WebAdmin'); elseif( $this->global['demo'] != 1 ) echo $this->translate('Atmail SubAdmin') . ' - ' . $this->Username; else echo $this->translate('Atmail') . ' - ' . $this->Username; ?></title>
	
	<!-- Fav icon -->
	<link rel="shortcut icon" href="<?php echo $this->siteBaseUrl ?>images/favicon-admin.ico?<?php echo $localCodebaseVersion ?>" type="image/x-icon" />	
	
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/ui.css?<?php echo $localCodebaseVersion ?>" type="text/css" media="screen" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/calendar.css?<?php echo $localCodebaseVersion ?>" type="text/css" media="screen" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/webmail.css?<?php echo $localCodebaseVersion ?>" type="text/css" media="screen" />
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl ?>css/admin.css?<?php echo $localCodebaseVersion ?>" type="text/css" media="screen"/>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/themes/fresh/ui.css?<?php echo $localCodebaseVersion ?>" type="text/css" media="screen" />
		
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/leaflet.css" />
	<!--[if lte IE 8]>
	<link rel="stylesheet" href="<?php echo $this->siteBaseUrl; ?>css/leaflet.ie.css" />
	<![endif]-->


	<!-- jsTranslation -->
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->moduleBaseUrl ?>/index/jstranslate/<?php echo $localCodebaseVersion ?>"></script>

	<!--[if IE]>
	<script language="javascript" type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/excanvas.js?<?php echo $localCodebaseVersion ?>"></script>
  	<![endif]-->

  	<!--[if lte IE 6]>
    <script type="text/javascript" src="<?php echo $this->siteBaseUrl; ?>js/dd_png.js"></script>
    <script type="text/javascript" src="<?php echo $this->siteBaseUrl; ?>js/pngfix_selectors.js"></script>
  	<![endif]-->

	<!-- jQuery -->
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/jquery-1.3.2.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/ui/jquery-ui-1.7.2.custom.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.json-1.3.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.jcacher-1.0.0.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.php.pack.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.flash.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.ajaxupload.3.9.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.highlight-3.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.scrollTo-min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.flot.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.flot.resize.js"></script>
<?php /*<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.flot.pie.js"></script> */ ?>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.alphanumeric.pack.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.countdown.pack.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.bgiframe.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/iphone-style-checkboxes.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.numberformatter-1.1.2.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.slider.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.spritely.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/crossfilter.min.js"></script>
	<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/d3.v3.js"></script>
<?php /*<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery-jvectormap-1.2.2.min.js"></script>*/ ?>
<?php /*<script type="text/javascript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery-jvectormap-world-mill-en.js"></script>*/ ?>
	<script src="<?php echo $this->siteBaseUrl ?>js/leaflet.js"></script>	
	
	<!-- Webadmin specific files -->
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/mail/mail.js?<?php echo $localCodebaseVersion ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/admin/users.js?<?php echo $localCodebaseVersion ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/atmail/admin/graphs.js?<?php echo $localCodebaseVersion ?>"></script>
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/jQuery/plugins/jquery.stronglastword.js?<?php echo $localCodebaseVersion ?>"></script>
	
    <!-- php compatible js functions (htmlentities etc) -->
	<script type="text/javascript" language="JavaScript" src="<?php echo $this->siteBaseUrl ?>js/php.js"></script>
	
	<script type="text/javascript">

		// Global JS name for script access
		var siteBaseUrl = "<?php echo $this->siteBaseUrl ?>";
		var moduleBaseUrl = "<?php echo $this->moduleBaseUrl ?>";
		
		var timeout = 500;
		var closetimer = 0;
		var ddmenuitem = 0;
		var firstclick = 0;
		
<?php $debugEnabled = isset(Zend_Registry::get('config')->global['debug'])? (Zend_Registry::get('config')->global['debug']?true:false):false; ?>
		var debugEnabled = <?php echo $debugEnabled?'true':'false' ?>;
		
		// Drop down menu functions
		function jsddm_open()
		{
			if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');
			if( $(this).children('a').hasClass('disabled') )
				return;
			ddmenuitem = $(this).find('ul').eq(0).css('visibility', 'visible');
			var left = Math.round($(this).offset().left - 8) + 'px';
			// Must manually set !important, to get the more button to display on the right position for different UI languages
			ddmenuitem.css("cssText", "visibility:visible; position: absolute; left: " + left + " !important;");

			firstclick = 1;

		}

		function jsddm_close()
		{

			if(ddmenuitem) ddmenuitem.css('visibility', 'hidden');

		}

		function jsddm_timer()
		{
		}   

		function jsddm_canceltimer()
		{
		}
		document.onclick = function () 
		{ 

			if( firstclick != 1 ) 
			{ 

				jsddm_close(); 

			} 
			firstclick = 0;

		};
		
	</script>
	
	<!-- Highlight Search Bar -->
	<script type="text/javascript">
	$(document).ready(function(){
		$("#searchQuery").focus(function() {
			$(this).parent().removeClass("searchFormDiv").addClass("searchFormFocus")
		});
		$("#searchQuery").blur(function() {
			$(this).parent().removeClass("searchFormFocus").addClass("searchFormDiv")
		});
	});
	</script>

<?php $this->pluginCall("endHeadTag"); ?>
</head>

<body class='<?php echo $this->userData['Language'] ?> <?php echo $this->userData['cssColorTheme'] ?>'>
<?php $this->pluginCall("startBodyTag"); ?>

<div id="header">
  <h3 class="branding"><a href="<?php echo $this->company_url ?>" target="_blank"><?php echo $this->global['brandname'] ?></a></h3>
  
  <div id='navTab'>
	  <ul id="nav">
		<?php
			$tabs = new StdClass;
			$tabs->number = 0;

            $this->pluginCall("beginTabs", $tabs);
        ?>
        
		<?php $tabs->dashboard = $tabs->number++; ?>
		<li id="nav_dsh"><a href="<?php echo $this->moduleBaseUrl ?>/dashboard" title="Dashboard"><span><?php echo $this->translate('Dashboard') ?></span></a></li>

		<?php if(@file_exists("/usr/local/atmail/mailserver/bin/atmail-services-restart") && $this->adminUser['UMasterAdmin'] == '1') :?>
		<?php $tabs->appliance = $tabs->number++; ?>
		<li id="nav_app"><a href="<?php echo $this->moduleBaseUrl ?>/appliance" title="Appliance"><span><?php echo $this->translate('Appliance') ?></span></a></li>
		<?php endif ?>
		
		<?php $tabs->users = $tabs->number++; ?>
		<li id="nav_mgr"><a href="<?php echo $this->moduleBaseUrl ?>/users" title="Users"><span><?php echo $this->translate('User Manager') ?></span></a></li>
		
		<?php if($this->adminUser['UMasterAdmin'] == '1' || $this->adminUser['UAlias'] == '1') :?>
		<?php $tabs->services = $tabs->number++; ?>
		<li id="nav_srv"><a href="<?php echo $this->moduleBaseUrl ?>/services" title="Services"><span><?php echo $this->translate('Services') ?></span></a></li>
		<?php endif ?>

		<?php if($this->adminUser['UMasterAdmin'] == '1') :?>
			<?php $tabs->settings = $tabs->number++; ?>
		    <li id="nav_set"><a href="<?php echo $this->moduleBaseUrl ?>/settings" title="AdminSettings"><span><?php echo $this->translate('Settings') ?></span></a></li>
		<?php endif ?>

		<?php $tabs->security = $tabs->number++; ?>
		<li id="nav_sec"><a href="<?php echo $this->moduleBaseUrl ?>/security" title="Security"><span><?php echo $this->translate('Security') ?></span></a></li>

		<?php if($this->adminUser['UMasterAdmin'] == '1') :?>		
			<?php $tabs->plugins = $tabs->number++; ?>
			<li id="nav_plu"><a href="<?php echo $this->moduleBaseUrl ?>/plugins" title="Plugins"><span>Plugins</span></a></li>
			<?php $tabs->license = $tabs->number++; ?>
			<li id="nav_lic"><a href="<?php echo $this->moduleBaseUrl ?>/license" title="License"><span><?php echo $this->translate('License') ?></span></a></li>
		<?php endif ?>
		<?php if( $this->archiveVaultAPIEnabled && $this->adminUser['UArchiveVault'] == '1') :?>
		<?php $tabs->archivevault = $tabs->number++; ?>
	    <li id="nav_avt"><a href="<?php echo $this->archiveVaultURL ?>" title="ArchiveVault" target="_blank" url="<?php echo $this->archiveVaultURL ?>"><span><?php echo $this->translate('ArchiveVault') ?></span></a></li>
		<?php endif ?>

        <?php $this->pluginCall("endTabs", $tabs); ?>
	  </ul>
  </div>
<?php if(true || $this->adminUser['UMasterAdmin'] == '1' || $this->adminUser['USearch'] == '1') : //TODO: should USearch != 1 hide this? ?>
	<div id="search_anything" style="position:absolute; right:139px;">
		<form action="" method="get" id='searchForm'>
			<div class="searchFormDiv">
				<input type="text" name="searchQuery" value="<?php echo $this->translate('Search Anything...') ?>" id="searchQuery" onfocus='this.value=""' />
			</div>
		</form>
	</div>
	<div id="help">
		<a href="<?php echo $this->moduleBaseUrl ?>/index/help?helpFile=Dashboard" target="_blank">&nbsp;</a>
	</div>
	<div id="sign_out"><a href="<?php echo $this->moduleBaseUrl ?>/index/logout"><span><?php echo $this->translate('Sign Out') ?></span></a></div>
<?php endif; ?>  

<div class="account-dropdown" style="display:none;">
	<div class="contact-photo">
		<img/>
	</div>
	<ul id="jsddm">
		<li id="account-options"><a class="moredrop" href="#"><span><strong><?php print $this->translate('More')?><span class="arrow">▼</span></strong></span></a>
			<ul class="menu_drop_more">
				<li class="color-palette">
					<a class="blue" themeColor="blue"></a>
					<a class="green" themeColor="green"></a>
					<a class="purple" themeColor="purple"></a>
					<a class="red" themeColor="red"></a>
					<a class="orange" themeColor="orange"></a>
				</li>
				<li id="user-help"><a href="<?php echo $this->moduleBaseUrl ?>/index/help?helpFile=Dashboard" target="_blank">Help</a></li>
				<li class="bottom"><a href="<?php echo $this->moduleBaseUrl ?>/index/logout"><?php print $this->translate('Sign Out')?></a></li>
			</ul>
		</li>
	</ul>

</div>

</div>

<div id="Dashboard">
</div>

<script type="text/javascript">

        $( function() {

			$('#navTab').tabs({
				
			 	select: function(event, ui) {
			        if( ui.tab.title == 'ArchiveVault' )
					{
						$("#ArchiveVaultLogin").submit();
						//window.open( $(ui.tab).attr('url') + 'index.php/archive/auth/processlogin/username/<?php echo $this->adminUser['Username'] ?>/password/<?php echo $this->adminUser['Password'] ?>');
						return false;
						
					}
			    }
				<?php if($this->dbUpdate || $this->notRegistered) : ?>
				, selected: <?php echo isset($tabs->license) ? $tabs->license : 0; ?>
				<?php endif ?>
			})
	   })

$.simpleFlashAdmin = function(message, type)
	{
		if( type == undefined )
			type = 'notice';
			
		visiblePanelContext = $('.ui-tabs-selected a', 'div#navTab').attr('href');

		if( $('#Flash', visiblePanelContext).length == 0 )
		{
			//no #Flash exists so append one
			if( $('#primary_content_inner', visiblePanelContext).length == 0 )
			{
				// nothing found, alert
				alert(message);
			}
			else
			{
				$('#primary_content_inner', visiblePanelContext).prepend('<div id="Flash"></div>');
			}
		}
		var flashNotice = $('#Flash', visiblePanelContext);

		if( type.toLowerCase() == 'notice' ) 
		{
			flashNotice.removeClass('flash_notice_error');
			flashNotice.addClass('flash_notice');
		}
		else if (type.toLowerCase() == 'important')
		{
			flashNotice.hide();
			flashNotice = $('#licence-error SPAN',  visiblePanelContext);
		}
		else
		{
			flashNotice.removeClass('flash_notice');
			flashNotice.addClass('flash_notice_error');
		}
			
		flashNotice.parent().scrollTo(0);
		flashNotice.parent().parent().scrollTo(0);
		flashNotice.html(message);
		flashNotice.show();
		
		if(flashTimeout != undefined || flashTimeout != null)
			clearTimeout(flashTimeout);
		var flashTimeout = null		
		flashTimeout = setTimeout(function() { flashNotice.fadeOut() },5000);
		flashNotice.unbind('click');
		flashNotice.bind('click', function() { $(this).fadeOut(); clearTimeout(flashTimeout) });
	}

$( function()
{

	// Bind the search query
	$('#searchForm').bind('submit', function() 
	{
		
		$.php('<?php echo $this->moduleBaseUrl ?>/users/list/domain/<?php echo $this->domain ?>/searchQuery/' + $("#searchQuery").val());			
		return false
		
	});
	
	$('.menu_drop_more', '#account-options').bind('mouseleave', function() { setTimeout(jsddm_close, 500); });
	
	// open account options dd
	$('.account-dropdown #jsddm > li').bind('mousedown', jsddm_open);
	$('.account-dropdown .contact-photo img').bind('click', function() {
		$('.account-dropdown #jsddm > li').trigger('mousedown');
	});
	
	// Color picker change
	$(".color-palette a", "#account-options").bind('click', function(e) {
		var color = $(this).attr('themeColor');

		$("body").removeClass('blue green purple red orange').addClass(color);
		themeColorsCurrentUpdate()
		$(".statGraph:visible, .statGraphSmall:visible").each( function()
		{

			var existingData = $(this).data("plot").getData()
			existingData[0].color = themeColorsCurrent.lineColor
			existingData[0].lines.fillColor = themeColorsCurrent.fillColor
			$(this).data("plot").setData(existingData);
			$(this).data("plot").draw();

		})
		toggleColorTheme(color);
	})

	function toggleColorTheme(color)
	{

		var url = "<?php echo $this->moduleBaseUrl; ?>/index/adminsettingssave";
		var postData = {
			"fields[cssColorTheme]" : color,
			save : 1
		}
		$.getJSON(url, postData);

	}
	
	// Add the loading div
	function showLoadingIconInVisibleContext() 
	{
	
		visiblePanelContext = $('.ui-tabs-selected a', 'div#navTab').attr('href');
		$('#primary_header', visiblePanelContext).addClass('loading')
		$('#back_button').each( function() { $(this).fadeTo(100, 0.5) } );
		
	}   
	
	function hideAllLoadingIcons() {
		
		//CONSIDER: revising to allow selectively removing loading icons, i.e. when multiple segments are loading we dont want to remove all loading icons when first completes
	    //alert( 'done'); 
		$('.loading').each( function() { $(this).removeClass('loading') } );
        $('#back_button').each( function() { $(this).fadeTo(100, 1) } );

	}
	
	php.beforeSend = function () { 

		showLoadingIconInVisibleContext()		
	}

	php.complete = function () { 
		
		hideAllLoadingIcons()
		
	}  
	
	$("body").bind("ajaxSend", function(){
	    
		showLoadingIconInVisibleContext()
	
	}).bind("ajaxComplete", function(){
	
		hideAllLoadingIcons()
		
	});
	
	function displaySessionTimeout()
	{
		
		window.location.replace("<?php echo $this->siteBaseUrl ?>index.php/default/index/sessiontimeout/admin/1");
	
	}
	
	// lets add a custom error handler
	// but save current one
	current_php_succcess_handler = php.success;
	php.success = function (response, textStatus)
	{
		// might be customized/invalid/corrupt json resp
		response['q'] = (typeof(response['q']) != 'undefined') ? response['q'] : new Array();
		response['a'] = (typeof(response['a']) != 'undefined') ? response['a'] : new Array();
		return current_php_succcess_handler(response, textStatus);
	}
	
	previous_php_error_handler = php.error;
	php.error = function(xmlEr, typeEr, except) 
	{
		// check for session timeout
		if( xmlEr.responseText.indexOf("__ATMAIL_SESSION_TIMEOUT") != -1 )
		{
			displaySessionTimeout();
			return;
		}
		
		// check for session timeout
		if( xmlEr.responseText.indexOf("Error validating access rights.") != -1
		|| xmlEr.responseText.indexOf("displaySessionTimeout") != -1 
		|| xmlEr.responseText.indexOf("MasterAdmin rights required.") != -1 )
		{
			displaySessionTimeout();
			return;
		}
		
		
		if( xmlEr.readyState == 4 && xmlEr.status == '200' && xmlEr.statusText == 'OK' && (xmlEr.responseText == undefined || xmlEr.responseText.length == 0)  )
			{
			
			if( xmlEr.responseText == undefined || xmlEr.responseText.length == 0 )
			{
				return;
			}
		}
		
		if( xmlEr.readyState == 4 && xmlEr.status == '0' && (xmlEr.responseText == undefined || xmlEr.responseText.length == 0) )
		{
			return;
		}


		if( debugEnabled )
		{
			// use the default handler
			previous_php_error_handler(xmlEr, typeEr, except);
		}
	}
	
	php.errors.defaultCallBack = function (msg, params) 
	{
		// check for session timeout
			if( msg.indexOf("__ATMAIL_SESSION_TIMEOUT") != -1 
			|| msg.indexOf("Error validating access rights.") != -1
			|| msg.indexOf("displaySessionTimeout") != -1 
			|| msg.indexOf("MasterAdmin rights required.") != -1)
			{
				displaySessionTimeout();
				return;
			}
		$.simpleFlash(msg, 'error');
	}

	php.messages.defaultCallBack = function (msg, params) 
	{
		$.simpleFlash(msg, 'notice');
	}
		
})  

// global var needed to re-find the progressbar updater
var progressBarUpdaterSetTimeout = null

</script>
<div id="flash"></div>
<div id="dialog"></div>
<?php if( $this->archiveVaultAPIEnabled && $this->adminUser['UArchiveVault'] == '1') :?>
	<form method="post" action="<?php echo $this->archiveVaultURL ?>index.php/archive/auth/processlogin/" id="ArchiveVaultLogin" target="_blank">
	
	<input type='hidden' name='username' value='<?php echo $this->adminUser['Username'] ?>'/>
	<input type='hidden' name='password' value='<?php echo $this->adminUser['Password'] ?>'/>
	
	</form>
<?php endif ?>
<?php $this->pluginCall("endBodyTag"); ?>
</body>
</html>
