<?php
include('header.php');
	echo '<div class="page_title"><h3>DashBoard</h3></div>';

if (!empty($general_setting['envato_username']) AND !empty($general_setting['envato_items_number']) AND !empty($general_setting['envato_api_key'])) {
	echo '<div class="divider_td">Envato\'s Sales & Earnings</div>';
	require 'inc/Envato_marketplaces.php';
	$Envato = new Envato_marketplaces();
	$Envato->cache_dir = '../cache';
	$Envato->set_api_key($general_setting['envato_api_key']);
	$monthly_earnings = $Envato->earnings_by_month($general_setting['envato_username']);
	$sales = objectToArray($monthly_earnings);
echo '<table id="envato" class="visual">
				<thead>
					<tr>
						<th></th>';
						$i=0;
						foreach (array_slice($sales, -6, 6, true) AS $sale) {
						$n = explode(' ',$sale['month']);
						echo '<th scope="col">'.$n[1].'</th>';
						}
						
					
					echo '</tr>
				</thead>
					<tbody>
					<tr>
						<th scope="row">Sales</th>';
						foreach (array_slice($sales, -6, 6, true) AS $sale) { 
						echo '<td>'.$sale['sales'].'</td>';
						}
					echo '</tr>
					<tr>
						<th scope="row">Earnings</th>';
						foreach (array_slice($sales, -6, 6, true) AS $sale) {
						echo '<td>'.$sale['earnings'].'</td>'; 
						}
					echo '</tr>
				</tbody>
			</table>';
}		
echo '<script type="text/javascript" src="http://www.google.com/jsapi"></script>';
include('footer.php');
?>