<?php

include('../conf.php');

$MySQL=mysqli_query($connect,'SELECT count(*) FROM cards');
$all=mysqli_fetch_row($MySQL);

$startOfDay = strtotime('today 00:00:00');
$endOfDay = strtotime('today 23:59:59');

$MySQL=mysqli_query($connect,'SELECT count(*) FROM cards WHERE addtime BETWEEN '.$startOfDay.' AND '.$endOfDay);
$day=mysqli_fetch_row($MySQL);

$startOfWeek = strtotime('monday this week 00:00:00');
$endOfWeek = strtotime('sunday this week 23:59:59');

$MySQL=mysqli_query($connect,'SELECT count(*) FROM cards WHERE addtime BETWEEN '.$startOfWeek.' AND '.$endOfWeek);
$week=mysqli_fetch_row($MySQL);

$startOfMonth = strtotime('first day of this month 00:00:00');
$endOfMonth = strtotime('last day of this month 23:59:59');

$MySQL=mysqli_query($connect,'SELECT count(*) FROM cards WHERE addtime BETWEEN '.$startOfMonth.' AND '.$endOfMonth);
$month=mysqli_fetch_row($MySQL);

function Percent($num,$sum){
	if($num==$sum){ return 100; }
	if($num==0){ return 0; }
	@$result=(100*$num)/$sum;
	return round($result,2);
}

?>
<style type="text/css"> small{ display: block; margin-top: 1em; }.block { width: 20px; padding: 3px; padding-right: 15px; float: left; }</style>

						<div class="col-lg-4">
							<div id="form" class="bs-component">
								<ul class="list-group">
								<li class="list-group-item">
									<span class="badge"><?=$all[0];?></span>
									<?=$GLOBALS['lang']['oth2'];?> <!-- total -->
								</li>
								<li class="list-group-item">
									<span class="badge"><?=$day[0];?></span>
									<?=$GLOBALS['lang']['oth3'];?> <!-- day -->
								</li>
								<li class="list-group-item">
									<span class="badge"><?=$week[0];?></span>
									<?=$GLOBALS['lang']['oth4'];?> <!-- week -->
								</li>
								<li class="list-group-item">
									<span class="badge"><?=$month[0];?></span>
									<?=$GLOBALS['lang']['oth5'];?> <!-- month -->
								</li>
							</ul>
							</div>
						</div>

						<div class="col-lg-4">
							<div id="info" class="bs-component">
								<div class="panel panel-default">
								<div class="panel-body">
									<table>
										<tr>
											<th>
			                                <canvas id="PayStat" width="190" height="190"></canvas>
			                                </th>
			                                <th style="display: table-cell; vertical-align: bottom; padding: 3px;">

			                                	<p>
			                                    <div class="block" style="background: #DCDCDC;">
			                                    <center>&nbsp;</center>
			                                    </div>&nbsp;&nbsp; - &nbsp;<?=$GLOBALS['lang']['tri9'];?><br />
			                                    </p>

			                                    <p>
												<div class="block" style="background: #D18177; float:left;">
			                                    <center>&nbsp;</center>
			                                    </div>&nbsp;&nbsp; - &nbsp;<?=$GLOBALS['lang']['tri7'];?>
			                                    </p><p>
			                                    <div class="block" style="background: #811BD6;">
			                                    <center>&nbsp;</center>
			                                    </div>&nbsp;&nbsp; - &nbsp;<?=$GLOBALS['lang']['tri8'];?><br />
			                                    </p>

			                                </th>
										</tr>
										<p></p>
									</table>
								</div>
							</div>
							</div>
						</div>

<script language="JavaScript">
  var pieData = [
   {
      value: <?=Percent($week[0],$all[0]);?>,
      label: "<?=$GLOBALS['lang']['tri8'];?>",
      color: "#811BD6"
   },
   {
      value: <?=Percent($day[0],$all[0]);?>,
      label: "<?=$GLOBALS['lang']['tri7'];?>",
      color: "#D18177"
   },
   {
      value: <?=Percent($month[0],$all[0]);;?>,
      label: "<?=$GLOBALS['lang']['tri9'];?>",
      color: "#DCDCDC"
   }
];

var context = document.getElementById("PayStat").getContext("2d");
var PayStat = new Chart(context).Pie(pieData);
</script><?php mysqli_close($connect); ?>