<?php
if (!defined("root")) {
	define("root", $_SERVER['DOCUMENT_ROOT']);
}
require(root."/___simple_config.php");
session_start();
$pageName = "index";
$pageTitle = "Dashboard";
$coutSpecs = array('nl'=>"n");
$act_ket = "Main Page of Index";
require(root."/".adminFolder."/_common.php");
require(root."/".adminFolder."/_lib/db.php");
require(root."/".adminFolder."/_lib/main.php");
if (!isset($_SESSION["user"])) {
	header("Location: /".adminFolder."/login/");
	exit;
}
$stgl = cekpost(cleanQuery($_REQUEST["fil_stgl"]), date('d-m-Y', time()));
$etgl = cekpost(cleanQuery($_REQUEST["fil_etgl"]), date('d-m-Y', time()));
$q_stgl = strtotime($stgl);
$q_etgl = strtotime($etgl)+86400;
$q_ytgl = strtotime($stgl)-86400;
#require(root."/".adminFolder."/checklog.php");

require(root."/".adminFolder."/_tpl/tag_html_a.php");

cout('
<style type="text/css">
	
</style>
');
require(root."/".adminFolder."/_tpl/openbody.php");
require(root."/".adminFolder."/_tpl/header.php");
cout('<div class="container">');
	cout('<div id="contentPanel">');
		cout('<div class="bigTitle">'.$pageTitle.'</div>');
		cout('<div class="contentMenu">');
		cout('</div>');
		cout('<div class="contentContainer">');
			cout('<div class="helper">');
				
				cout('<div class="fcols" style="width:90%;">');
					$rsnm=array();
					$qnm="SELECT COUNT(kdmember) AS tmem FROM members
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal_daftar
						AND tanggal_daftar < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						";
					$qnm="SELECT COUNT(kdmember) AS tmem FROM members
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
						AND isdeleted=0 AND isactive=1
						";
					callRS($rsnm, $qnm);
					cout('<div class="col">');
						cout('<div class="title title-member"><div class="icon"></div><div class="text">Today\'s Members</div></div>');
						cout('<div class="data">'.$rsnm[0]["tmem"].'</div>');
					cout('</div>');
					
					$rsnd=array();
					$qnd="SELECT SUM(jumlah) AS tjum FROM deposits
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal
						AND tanggal < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						AND isclear = 1
						";
					$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
						AND isclear = 1
						";
						
					callRS($rsnd, $qnd);
					cout('<div class="col">');
						cout('<div class="title title-deposit"><div class="icon"></div><div class="text">Today\'s Deposits</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnd[0]["tjum"],0).'</div>');
						cout('<div class="data" style="margin:5px 0;">'.number_format($rsnd[0]["tdp"],0).' transaction(s)</div>');
					cout('</div>');
					
					$rsnw=array();
					$qnw="SELECT SUM(jumlah) AS tjum FROM withdraws
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal
						AND tanggal < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						AND isclear = 1
						";
					$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
						AND isclear = 1
						";
					callRS($rsnw, $qnw);
					cout('<div class="col">');
						cout('<div class="title title-withdraw"><div class="icon"></div><div class="text">Today\'s Withdrawals</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnw[0]["tjum"],0).'</div>');
						cout('<div class="data" style="margin:5px 0;">'.number_format($rsnw[0]["twd"],0).' transaction(s)</div>');
					cout('</div>');
					/*
					$rsnt=array();
					$qnt="SELECT SUM(jumlah) AS tjum FROM transfers
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal_transfer
						AND tanggal_transfer < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)";
					$qnt="SELECT SUM(jumlah) AS tjum FROM transfers
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_transfer))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_transfer))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_etgl.")) 
						";
					callRS($rsnt, $qnt);
					cout('<div class="col">');
						cout('<div class="title title-transfer"><div class="icon"></div><div class="text">Today\'s Transfers</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnt[0]["tjum"],0).'</div>');
					cout('</div>');
					*/
				cout('</div>');
				
				cout('<div class="fcols" style="width:90%;margin:10px 0;background:#e2e2e2;padding:10px 0;">');
					$rsnm=array();
					$qnm="SELECT COUNT(kdmember) AS tmem FROM members
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal_daftar
						AND tanggal_daftar < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						";
					$qnm="SELECT COUNT(kdmember) AS tmem FROM members
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_daftar))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND isdeleted=0 AND isactive=1
						";
					callRS($rsnm, $qnm);
					cout('<div class="col">');
						cout('<div class="title title-member"><div class="icon"></div><div class="text">Yesterday\'s Members</div></div>');
						cout('<div class="data">'.$rsnm[0]["tmem"].'</div>');
					cout('</div>');
					
					$rsnd=array();
					$qnd="SELECT SUM(jumlah) AS tjum FROM deposits
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal
						AND tanggal < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						AND isclear = 1
						";
					$qnd="SELECT SUM(jumlah) AS tjum, COUNT(kddeposit) AS tdp FROM deposits
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND isclear = 1
						";
						
					callRS($rsnd, $qnd);
					cout('<div class="col">');
						cout('<div class="title title-deposit"><div class="icon"></div><div class="text">Yesterday\'s Deposits</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnd[0]["tjum"],0).'</div>');
						cout('<div class="data" style="margin:5px 0;">'.number_format($rsnd[0]["tdp"],0).' transaction(s)</div>');
					cout('</div>');
					
					$rsnw=array();
					$qnw="SELECT SUM(jumlah) AS tjum FROM withdraws
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal
						AND tanggal < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)
						AND isclear = 1
						";
					$qnw="SELECT SUM(jumlah) AS tjum, COUNT(kdwithdraw) AS twd FROM withdraws
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						AND isclear = 1
						";
					callRS($rsnw, $qnw);
					cout('<div class="col">');
						cout('<div class="title title-withdraw"><div class="icon"></div><div class="text">Yesterday\'s Withdrawals</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnw[0]["tjum"],0).'</div>');
						cout('<div class="data" style="margin:5px 0;">'.number_format($rsnw[0]["twd"],0).' transaction(s)</div>');
					cout('</div>');
					/*
					$rsnt=array();
					$qnt="SELECT SUM(jumlah) AS tjum FROM transfers
						WHERE UNIX_TIMESTAMP(CURRENT_DATE()) <= tanggal_transfer
						AND tanggal_transfer < DATE_ADD(CURRENT_DATE(), INTERVAL 1 DAY)";
					$qnt="SELECT SUM(jumlah) AS tjum FROM transfers
						WHERE 1=1
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_transfer))>=UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_ytgl.")) 
						AND UNIX_TIMESTAMP(FROM_UNIXTIME(tanggal_transfer))< UNIX_TIMESTAMP(FROM_UNIXTIME(".$q_stgl.")) 
						";
					callRS($rsnt, $qnt);
					cout('<div class="col">');
						cout('<div class="title title-transfer"><div class="icon"></div><div class="text">Yesterday\'s Transfers</div></div>');
						cout('<div class="data">Rp. '.number_format($rsnt[0]["tjum"],0).'</div>');
					cout('</div>');
					*/
				cout('</div>');
				/*
				echo(root."/php-sdk/facebook.php");
				require(root."/php-sdk/facebook.php");
				echo 'a';
				$fbconfig = array(
					'appId' => '660372727335134',
					'secret' => 'c796f9430b182b6c8ab0afead7bc1c75',
					'fileUpload' => false, // optional
					'allowSignedRequest' => false, // optional, but should be set to false for non-canvas apps
				);
				$facebook = new Facebook($fbconfig);
				$user_id = $facebook->getUser();
				echo 'b';
				if($user_id) {
					// We have a user ID, so probably a logged in user.
					// If not, we'll get an exception, which we handle below.
					try {
						$user_profile = $facebook->api('/me','GET');
						echo "Name: " . $user_profile['name'];
					} catch(FacebookApiException $e) {
						// If the user is logged out, you can have a 
						// user ID even though the access token is invalid.
						// In this case, we'll get an exception, so we'll
						// just ask the user to login again here.
						$login_url = $facebook->getLoginUrl(); 
						echo 'Please <a href="' . $login_url . '">login.</a>';
						error_log($e->getType());
						error_log($e->getMessage());
					}
				} else {
					// No user, print a link for the user to login
					$login_url = $facebook->getLoginUrl();
					echo 'Please <a href="' . $login_url . '">login.</a>';
				}
				
				
				#660372727335134
				#c796f9430b182b6c8ab0afead7bc1c75
				*/
			cout('</div>');
		cout('</div>');
	cout('</div>');
cout('</div>');
require(root."/".adminFolder."/_tpl/footer.php");
require(root."/".adminFolder."/_tpl/tag_html_b.php");
?>