<?php
	$home="1";
	include('header.php'); 
?>

<script type="text/javascript" src="<?=$website?>/js/jquery.sparkline.min.js"></script>
<script src="<?=$website?>/js/libraries/RGraph.common.core.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.common.dynamic.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.common.tooltips.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.common.effects.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.common.key.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.pie.js" ></script>
<script src="<?=$website?>/js/libraries/RGraph.line.js" ></script>
<!--[if lt IE 9]><script src="<?=$website?>/js/excanvas/excanvas.js"></script><![endif]-->
<script type="text/javascript">
$(document).ready(function(){
	$('.inlinebar').sparkline('html', {
		type: 'line',
		width: '930px',
		height: '400px',
		enableTagOptions: true
	} );
	<?php
	$getlastdate=@mysql_result(mysql_query("SELECT `register` FROM `members` WHERE `role`='0' ORDER BY `register` ASC LIMIT 1"),0,0);
	$sir=array();
	$sirtips=array();
	$numar=array();
	$datenow=date('d-m-Y',$getlastdate);
	$sir[]="'".$datenow."'";
	$numarquery=@mysql_num_rows(mysql_query("SELECT `id` FROM `members` WHERE `registerfix`='$datenow'"));
	$numar[]=$numarquery;
	$sirtips[]="'$numarquery new members'";
		for ($i = 1; $i <= 5; $i++) {
			$nextdate=date('d-m-Y', strtotime('+'.$i.' day',$getlastdate));
			$sir[]="'".$nextdate."'";
			$numarquery=@mysql_num_rows(mysql_query("SELECT `id` FROM `members` WHERE `registerfix`='$nextdate'"));
			$numar[]=$numarquery;
			$sirtips[]="'$numarquery new members'";
		}
	$sir=implode(",",$sir);
	$sirtips=implode(",",$sirtips);
	$numar=implode(",",$numar);
	

	?>
		var line2 = new RGraph.Line('cvs', [<?=$numar?>]);
            line2.Set('chart.filled', true);
            line2.Set('chart.fillstyle', ['transparent']);
            line2.Set('chart.colors', ['red']);
            line2.Set('chart.linewidth', 2);
            line2.Set('chart.hmargin', 5);
            line2.Set('chart.tickmarks', 'circle');
            line2.Set('chart.labels', [<?=$sir?>]);
            line2.Set('chart.tooltips', [<?=$sirtips?>]);
           // line2.Draw();
		   RGraph.Effects.Fade.In(line2);
	
	
		var pie = new RGraph.Pie('piechart1', [14,54]);
		pie.Set('chart.colors', ['#E18D87','#599FD9']);
		pie.Set('chart.shadow', true);
		pie.Set('chart.shadow.offsetx', 5);
		pie.Set('chart.shadow.offsety', 5);
		pie.Set('chart.shadow.blur', 15);
		pie.Set('chart.shadow.color', '#bbb');
		pie.Set('chart.labels.sticks', true);
		pie.Set('chart.labels.sticks.length', 15);
		pie.Set('chart.tooltips', ['400$','300$']);
		pie.Set('chart.labels', ['Skrill(moneybookers)','Paypal']);
		pie.Set('chart.radius', 100);
		pie.Set('chart.strokestyle', 'rgba(0,0,0,0.1)');
		//pie.Draw();
		RGraph.Effects.Pie.RoundRobin(pie);


		var pie2 = new RGraph.Pie('piechart2', [200,0,252,6,205]);
		pie2.Set('chart.colors', ['#ABD874','#E18D87','#599FD9','#D5BBE5','#599FD9']);
		pie2.Set('chart.shadow', true);
		pie2.Set('chart.shadow.offsetx', 5);
		pie2.Set('chart.shadow.offsety', 5);
		pie2.Set('chart.shadow.blur', 15);
		pie2.Set('chart.shadow.color', '#bbb');
		pie2.Set('chart.labels.sticks', true);
		pie2.Set('chart.labels.sticks.length', 15);
		pie2.Set('chart.tooltips', ['205615615','0','Peter','Jack','205615615']);
		pie2.Set('chart.labels', ['The most sold','The fewest sales','Average sales per day','Jack','Number of files']);
		pie2.Set('chart.radius', 100);
		pie2.Set('chart.strokestyle', 'rgba(0,0,0,0.1)');
		//pie.Draw();
		RGraph.Effects.Pie.Implode(pie2);
	
});
</script>
 
<div class="grid_full page_wrap">

<!--	<span class="inlinebar">1,3,4,5,3,5</span>-->
	<Br/><br/>
	<h2>Members</h2>
	<canvas id="cvs" width="930" height="200">[No canvas support]</canvas>

	<Br/><br/>
	<div class="span6">
		<h2>Last 5 users</h2>
		<table class="table table-bordered table-hover table-condensed">
			<thead>
				<tr>
					<td width="10">#</td>
					<td>Username</td>
					<td>Files</td>
					<td>Sales</td>
					<td>Total amount sales</td>
				</tr>
			</thead>
			<tbody>
			<?php
				$qrmembers=@mysql_query("SELECT * FROM `members` WHERE `role`='0' ORDER BY id DESC LIMIT 5");
				
				while($rowmembers=@mysql_fetch_array($qrmembers)){
				$getfiles=@mysql_num_rows(mysql_query("SELECT `id` FROM `products` WHERE `idu`='$rowmembers[id]'"));
				$getsales=@mysql_num_rows(mysql_query("SELECT `id` FROM `sales` WHERE `idu`='$rowmembers[id]'"));
				$getsum=@mysql_fetch_array(mysql_query("SELECT SUM(price) FROM `sales` WHERE `idu`='$rowmembers[id]'"));
					if(!$getsum['SUM(price)']){
					$getsum['SUM(price)']=0;
					}
				echo "<tr>
					<td>$rowmembers[id]</td>
					<td>$rowmembers[username]</td>
					<td>$getfiles</td>
					<td>$getsales</td>
					<td>".$getsum['SUM(price)']."$</td>
				</tr>";
				}
			?>
			</tbody>
		</table>
	</div>
	<!--
	<div class="span5">
		<canvas id="piechart1" width="380" height="270">[No canvas support]</canvas>
	</div>
	
	-->
	<div class="clearfix"><hr /></div>
	<!--
	<div class="span6">
		<canvas id="piechart2" width="460" height="270">[No canvas support]</canvas>
	</div>
	-->
	<div class="span6">
		<!-- Statistica pentru fisiere( cate vanzari o avut, cea mai mica si cea mai mare vanzare, cate vanzari pe zi sunt ) -->
		<table class="table table-bordered table-hover">
			<tr class="info">
				<td>Number of files</td>
				<td colspan="2"><?php
				$getfilesnum=@mysql_num_rows(mysql_query("SELECT `id` FROM `products`"));
				echo $getfilesnum;
				?></td>
			</tr>
			<tr class="info">
				<td>Number of sales</td>
				<td colspan="2"><?php
				$getsalesnum=@mysql_num_rows(mysql_query("SELECT `id` FROM `sales`"));
				echo $getsalesnum;
				?></td>
			</tr>
			<tr class="info">
				<td>Number of users</td>
				<td colspan="2"><?php
				$getusernum=@mysql_num_rows(mysql_query("SELECT `id` FROM `members`"));
				echo $getusernum;
				?></td>
			</tr>

		</table>
	</div>

	
	<div class="clearfix"><hr /></div>

</div>

<?php include('footer.php'); ?>