<?php
$wp_include = "../wp-load.php";$i = 0;
while (!file_exists($wp_include) && $i++ < 10) {$wp_include = "../$wp_include";} require($wp_include);
if ( !is_user_logged_in()) 
	wp_die(__("You are not allowed to be here","cloudfw"));


require (TMP_ADMIN_PATH.'/classes/gapi.class.php');
require (TMP_ADMIN_PATH.'/inc/fn.admin.ga.php');



global $_opt, $ga_page;
$_opt = getCO(NULL, array(PFIX."_ga_id", PFIX."_ga_pass", PFIX."_ga_profile"));

echo '<pre>';
 print_r($opt);
echo '</pre>';

if (defined("GA_ID")&&defined("GA_PASS")):
		 
		 $ga_id = GA_ID;
		 $ga_pass = GA_PASS;
		 
		else:
		
		 $ga_id = $_opt[PFIX."_ga_id"];
		 $ga_pass = $_opt[PFIX."_ga_pass"];
		
		endif;
		

if (empty($ga_id) || empty($ga_pass) ){
		
	
	echo ' 
	<div class="module">
	
	<div class="error-div box-div" style="margin:-10px 20px 10px; width:auto;"><a href="'.$ga_page.'">'.__('Please configure your Google Analytics information to view analytics datas here.','cloudfw').'</a> '.__('or you can disable it from the system settings page.','cloudfw').'</div>
	
	</div>';
	update_option(PFIX."_ga_profile", NULL);
	exit;
}



if (empty($_opt[PFIX."_ga_profile"])){
		
	
	echo ' 
	<div class="module">
	
	<div class="error-div box-div" style="margin:-10px 20px 10px; width:auto;">'.__('Accout ID cannot found.','cloudfw').'<a href="'.$ga_page.'">'.__('Please check your Google Analytics account informations','cloudfw').'</a></div>
	
	</div>';
	
	exit;
}


if (empty($_opt[PFIX."_ga_profile"])){
		
	
	echo ' 
	<div class="module">
	
	<div class="error-div box-div" style="margin:-10px 20px 10px; width:auto;">'.__('Account ID cannot found.','cloudfw').'<a href="'.$ga_page.'">'.__('Please check your Google Analytics account informations','cloudfw').'</a></div>
	
	</div>';
	
	exit;
}

if (isset($_GET["x"])) { echo '	
	<div class="tabs">   
		<ul>
			<li class="firsttab"><a href="#today">'.__('Today','cloudfw').'</a></li>
			<li><a href="'.TMP_ADMIN.'/ajax/ga.php?case=lastweek" title="lastweek">'.__('Last Week','cloudfw').'</a></li>
			<li><a href="'.TMP_ADMIN.'/ajax/ga.php?case=lastmonth" title="lastmonth">'.__('Last Month','cloudfw').'</a></li>
			<li class="lasttab"><a href="'.TMP_ADMIN.'/ajax/ga.php?case=thisyear" title="thisyear">'.__('Last Year','cloudfw').'</a></li>
		</ul>
        <div class="clear"></div>
                    
  	';
	

	echo '
	<div id="today">
		'.cloud_cache(ga_today,'ga_cache_today_'.$_opt[PFIX."_ga_profile"].'.cache').'
	</div>
	</div>';
		
	;} // End of isset x
	
	if ($_GET["case"] == "lastweek" ) echo cloud_cache(ga_lastweek,'ga_cache_lastweek_'.$_opt[PFIX."_ga_profile"].'.cache');
	if ($_GET["case"] == "lastmonth" ) echo cloud_cache(ga_lastmonth,'ga_cache_lastmonth_'.$_opt[PFIX."_ga_profile"].'.cache');
	if ($_GET["case"] == "thisyear" ) echo cloud_cache(ga_thisyear,'ga_cache_thisyear_'.$_opt[PFIX."_ga_profile"].'.cache');
	
function ga_today()		{	return cloudfw_ga('today','hourly',date('Y-m-d'),date('Y-m-d'));};
function ga_lastweek()	{	return cloudfw_ga('lastweek','daily',date('Y-m-d', strtotime('-1 week')), date('Y-m-d'));};
function ga_lastmonth()	{	return cloudfw_ga('lastmonth','daily',date('Y-m-d', strtotime('-1 month')), date('Y-m-d'));};
function ga_thisyear()	{	return cloudfw_ga('lastyear','monthly',date('Y-m-d', strtotime('-1 year')), date('Y-m-d'));};

?>