<div id="primary_header">
  <h1><?php print $this->translate('Total Logins')?></h1>

	<div id="back_button" style="filter: none;">
		<a href="#" id='day'>
			<span class="stronglastword"><?php echo $this->translate('Day') ?></span>
		</a>
		
		<a href="#" id='week'>
			<span class="stronglastword"><?php echo $this->translate('Week') ?></span>
		</a>

		<a href="#" id='month'>
			<span class="stronglastword"><?php echo $this->translate('Month') ?></span>
		</a>
		
		<a href="#" id='year'>
			<span class="stronglastword"><?php echo $this->translate('Year') ?></span>
		</a>
	</div>

</div>

<div id="primary_content">
  <div id="primary_content_inner">
<?php if($this->allLicensesExpired): ?>
<div id="licence-error"><img class="regerror" src="<?php echo $this->siteBaseUrl; ?>images/icons/error.png"/><span><?php echo $this->translate('Your Atmail license is either not registered or invalid. Use the license tab above to enter your details') ?></span></div>
<?php endif; ?>
	
<div id="licence-error" class='versionDiv' style='display: none;'>
<img class="regerror" src="<?php echo $this->siteBaseUrl ?>images/icons/error.png"/>
<span></span>
</div>


<div class='statContainer'>
	
<div class='graphSummary'>
	<div>
		<div id="summaryGraphBig" class='statGraph'></div>
	</div>

	<div class='graphMetric'>
		<span class='graphName'>Logins</span>
		<span class='graphMetric high'>+33% 44,400</span>
	</div>

	<div class='graphMetric'>
		<span class='graphName'>New Users</span>
		<span class='graphMetric high'>+2% 30</span>
	</div>

	<div class='graphMetric'>
		<span class='graphName'>SMTP In</span>
		<span class='graphMetric low'>-12% 7,093</span>
	</div>

	<div class='graphMetric'>
		<span class='graphName'>SMTP Out</span>
		<span class='graphMetric high'>+8% 28,029</span>
	</div>

	<div class='graphMetric'>
		<span class='graphName'>SMTP Out</span>
		<span class='graphMetric low'>-18% 8,992</span>
	</div>
	
</div>

<div class='pieContainer'>
	
	<div class='pie1'></div>
	
	<div class='pie2'></div>
	
</div>

</div>

  </div>
</div>

<script type="text/javascript" language="JavaScript">
	$( function() {

        $('#summaryGraph .statGraph,.statGraphSmall').html("<div id='loading' style='top: 50%; position: relative;left: 50%;'><h1 class='loading-text'><img class='loadingimg' src='<?php echo $this->siteBaseUrl; ?>images/25.gif' width='28' height='28'/><span class='loading'><?php echo $this->translate('Loading...')?></span></h1></div>");

        // Build the pie charts
		var data = [];
		var series = Math.floor(Math.random()*10)+1;
		for( var i = 0; i<series; i++)
		{
			data[i] = { label: "Series"+(i+1), data: Math.floor(Math.random()*100)+1 }
		}
		
		<?php if($this->allLicensesExpired): ?>
		var len = $('#navTab').tabs('length') - 1;	
		$('#navTab').tabs('select', len);
		<?php endif ?>
	
	    var data = [];
	    var placeholder = $("#loginGraph #loginGraphGraph");

	    //$.plot(placeholder, data, options);

	    // fetch one series, adding to what we got
	    var alreadyFetched = {};

        generateLargeGraph($("#loginGraph"), '<?php echo $this->moduleBaseUrl ?>/graph/json/view/', '<?php echo $this->view; ?>', 'Log_Login');
        generateSmallGraph($('#loginGraph'), "<?php echo $this->moduleBaseUrl ?>/graph/json/view/", "<?php echo $this->view; ?>", "Log_Login");

        $(".statGraph", '#loginGraph').bind("plotclick", function (event, pos, item) {
            if (item) {
                alert(item.datapoint);
                $('.statGraph').timePeriodLogs('<?php echo $this->moduleBaseUrl ?>', '', 'Log_Login', '<?php echo $this->view ?>', item.datapoint);

            }
        });

			$('#loginGraph #back_button A').each(function(n) {
				var record = this;
	
				$(this).bind('click', function() {
					$("#loginGraph").load('<?php echo $this->moduleBaseUrl ?>/dashboard/login/view/' + $(record).attr('id'));		
				});
				
			});

			$('.statTotal').viewLogs('<?php echo $this->moduleBaseUrl ?>', 'Log_Login', '<?php echo $this->view ?>');

$('.stronglastword').each( function() { $(this).stronglastword() });

// Update the activeState
$("#loginGraph #back_button #<?php echo $this->view ?> SPAN").addClass('activeState');
$("#loginGraph #back_button #<?php echo $this->view ?>").addClass('activeState');

// Attach the load element for downloading the CSV file
$("SPAN.downloadLog").each(function() {

	$(this).attr('title', "<?php $this->translate('Download CSV for logs') ?>");

	$(this).bind('click', function() {
		var id = $(this).parent().find('.statGraphSmall').attr('logtype');
		var url = '<?php echo $this->moduleBaseUrl ?>/dashboard/logexport/log/Log_Login/type/' + id + '/view/<?php echo $this->view ?>/';
		
		// Redirect the browser to the new URL, however will prompt to download the CSV
		location.href=url;
	});
	
});


// Only on first load
<?php if($this->view == 'day' && $this->userData['UMasterAdmin'] == '1') :?>
setTimeout(function() { $.php("<?php echo $this->moduleBaseUrl ?>/dashboard/version") }, 300);
<?php endif ?>

var optionsSmall = {
                    lines: { show: true },
                        grid: { color: "#999" },
                        yaxis: {tickDecimals: 1, min: 0, autoscaleMargin: 0.1, ticks: []},
                        xaxis : { mode : "time", localTimezone: true },
                        label: ""
                };

// DEFAULT
$.plot($(".pie1"), data,
{
        series: {
            pie: {
                show: true,
                radius: 1,
                label: {
                    show: true,
                    radius: 2/3,
                    formatter: function(label, series){
                        return '<div style="font-size:8pt;text-align:center;padding:2px;color:white;">'+label+'<br/>'+Math.round(series.percent)+'%</div>';
                    },
                    threshold: 0.1
                }
            }
        },
        legend: {
            show: false
        }
});

});

</script>