<?php
/**
 * @package		Ad Platform
 * @author		Uta Marian - Alexandru ( -uMarian- )
 * @license		http://codecanyon.net/licenses
 * @link		http://www.uta-marian.com
 * @version		Version 1.0
 */
require_once(dirname(__FILE__).'/../config.php');
require_once(DIR_SYSTEM.'/admin/session.admin.php');

//*** VARS ***//
$stats					=	array();
$YESTERDAY_COUNTER		=	0;
$TODAY_COUNTER			=	0;



//*** DATES ***//
$today				=	strtotime( "now" );
$BEGIN_TODAY		=	strtotime("midnight", $today);
$END_TODAY			=	strtotime("tomorrow", $BEGIN_TODAY) - 1;

$yesterday			=	strtotime( "-1 day" );
$BEGIN_YESTERDAY	=	strtotime("midnight", $yesterday);
$END_YESTERDAY		=	strtotime("tomorrow", $BEGIN_YESTERDAY) - 1;



//*** USERS ACCOUNTS STATISTICS ***//
$users = $db->Query("SELECT `user_id`,`user_date` FROM users");

foreach ( $users as $usr ) {
	if ( $usr['user_date'] > $BEGIN_TODAY && $usr['user_date'] < $END_TODAY ) {
		$TODAY_COUNTER++;
	}
	if ( $usr['user_date'] > $BEGIN_YESTERDAY && $usr['user_date'] < $END_YESTERDAY ) {
		$YESTERDAY_COUNTER++;
	}
}

//*** END USERS ACCOUNTS STATISTICS ***//



//*** ADVERTISERS STATISTICS ***//
$ADVERTISER_CAMPAIGNS	=	0;
$ADVERTISER_IMPRESSIONS	=	0;
$ADVERTISER_CLICKS		=	0;
$ADVERTISER_SPENT		=	0;


$campaigns = $db->Query("SELECT `acs_impressions`, `acs_clicks`, `acs_money_spent` FROM advertisers_campaigns_statistics");

foreach ( $campaigns as $campaign ) {
	$ADVERTISER_CAMPAIGNS++;
	$ADVERTISER_IMPRESSIONS	=	$ADVERTISER_IMPRESSIONS + $campaign['acs_impressions'];
	$ADVERTISER_CLICKS		=	$ADVERTISER_CLICKS + $campaign['acs_clicks'];
	$ADVERTISER_SPENT		=	$ADVERTISER_SPENT + $campaign['acs_money_spent'];
}
//*** ADVERTISERS STATISTICS ***//




//*** PUBLISHERS STATISTICS ***//
$PUBLISHERS_CHANNELS	=	0;
$PUBLISHERS_IMPRESSIONS	=	0;
$PUBLISHERS_CLICKS		=	0;
$PUBLISHERS_MAKED		=	0;


$channels = $db->Query("SELECT `pcs_impressions`, `pcs_clicks`, `pcs_money` FROM publisher_channels_statistics");

foreach ( $channels as $channel ) {
	$PUBLISHERS_CHANNELS++;
	$PUBLISHERS_IMPRESSIONS	=	$PUBLISHERS_IMPRESSIONS + $channel['pcs_impressions'];
	$PUBLISHERS_CLICKS		=	$PUBLISHERS_CLICKS + $channel['pcs_clicks'];
	$PUBLISHERS_MAKED		=	$PUBLISHERS_MAKED + $channel['pcs_money'];
}
//*** PUBLISHERS STATISTICS ***//







$stats['users']				=	count($users);
$stats['today']				=	$TODAY_COUNTER;
$stats['yesterday']			=	$YESTERDAY_COUNTER;

$stats['adv_campaigns']		=	$ADVERTISER_CAMPAIGNS;
$stats['adv_impressions']	=	$ADVERTISER_IMPRESSIONS;
$stats['adv_clicks']		=	$ADVERTISER_CLICKS;
$stats['adv_spent']			=	$ADVERTISER_SPENT;

$stats['pub_channels']		=	$PUBLISHERS_CHANNELS;
$stats['pub_impressions']	=	$PUBLISHERS_IMPRESSIONS;
$stats['pub_clicks']		=	$PUBLISHERS_CLICKS;
$stats['pub_maked']			=	$PUBLISHERS_MAKED;




$view->stats	=	$stats;

//**DEFINE CUSTOM CSS/JS FILLES**//
$view->customCode = '<link href="'.HTTP_SERVER_WEBSITE.'templates/'.ADMIN_TEMPLATE.'/assets/css/dashboard.css" rel="stylesheet">';

/* set page title */
$view->title = $LANG["WBS_ADMIN_DASHBOARD_SEO"];
$view->description = $LANG["WBS_ADMIN_DASHBOARD_SEO"];
$view->keywords = $LANG["WBS_ADMIN_DASHBOARD_SEO"];

$view->header = $view->render(DIR_TEMPLATE.ADMIN_TEMPLATE.'/header.php');
$view->footer = $view->render(DIR_TEMPLATE.ADMIN_TEMPLATE.'/footer.php');

echo $view->render(DIR_TEMPLATE.ADMIN_TEMPLATE.'/index.php');
?>