<?php include ("app_needed/config.php");
require_once("app_classes/module_statistics.inc"); 
$stats_country = new class_statistics();
$stats_impressions = new class_statistics();
if(!$_SESSION[unique])
header("Location: ".APP_WEBSITE."/login.html");


$parameters_impressions[0] = date("Y-m-d",strtotime("-31 days"));
$parameters_impressions[1] = date("Y-m-d");
$parameters_impressions[2] = $logged->get_unique();
$parameters_impressions[3] = 2;
$parameters_country[0] = date("Y-m-d");
$parameters_country[1] = date("Y-m-d");
$parameters_country[2] = $logged->get_unique();
$parameters_country[3] = 2;

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?= language("CHARSET") ?>" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title><?php echo language('PAGE_dashboard_title'); ?> - <?= $config->get_value('platform_title') ?></title>
<link rel="shortcut icon" type="image/png" href="<?= $config->get_value('platform_favicon') ?>"/>
<link href="app_needed/style.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="app_needed/morris.css">
<link rel="stylesheet" href="app_needed/style.tipsy.css" type="text/css" />
<link rel="stylesheet" href="app_needed/jquery.bxslider.css" type="text/css" />
<link rel="stylesheet" href="app_needed/ammap/ammap.css" type="text/css">

<script src="app_needed/ammap/ammap.js" type="text/javascript"></script>
<script src="app_needed/ammap/maps/js/worldLow.js" type="text/javascript"></script>

<script type="text/javascript" src="app_needed/jquery-1.9.0.min.js"></script>
<script src="http://code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.2/raphael-min.js"></script>
<script src="app_needed/morris.min.js"></script>

<script type='text/javascript' src='app_needed/jquery.accordionmenu.js'></script>
<script type='text/javascript' src='app_needed/jquery.checkbox.js'></script>
<script type='text/javascript' src='app_needed/jquery.bxslider.min.js'></script>
<script type='text/javascript' src='app_needed/jquery.tipsy.js'></script>
<script type='text/javascript' src='app_needed/function.ajax.js'></script>
<script type='text/javascript' src='app_needed/simply-toast.min.js'></script>
<script type='text/javascript' src='app_needed/jquery.simplemodal.js'></script>
<script type='text/javascript' src='app_needed/functions.js'></script>

</head>

<body>
<div id="wrapper">
	<?php include("module.header.php"); ?>
<?php include ("module.menu.php"); ?>
<div class="content">
	  <div class="info">
		<h1><?php echo language('PAGE_dashboard_title');  ?></h1>
		</div>
        <div class="dashboard">
         <div class="left_half height_400 white">
                  <?php $statistics_imp =  $stats_impressions->__call('get_impressions',$parameters_impressions); ?>
          <?php if(!$statistics_imp) echo "<div style='text-align:center; padding:100px 0 100px 0;'><h1>".language('MESSAGE_no_stats')."</h1></div>";else {  ?>
       	  <div id="graph" style="  width: 100%; max-width:100%; height: 380px;"></div>
			<?php } ?>
        
         <script>

				var day_data = [
		<?php 		
		if($statistics_imp)
		foreach ($statistics_imp as $day => $value)
		{
			$split = explode("|",$value);
			$to_echo_imp .= '{"period": "'.$day.'", "Impressions": '.$split[0].',"clicks": '.$split[2].'},';
		}
			echo substr($to_echo_imp,0,-1);
		?>
  		
];
Morris.Line({
  element: 'graph',
  data: day_data,
  xkey: 'period',
  ykeys: ['Impressions','clicks'],
  labels: ['Impressions','clicks'],
  xLabelAngle: 60
});
	
				</script>

         </div>
         <div class="right_half height_400">
         	<div class="left_half margin_bottom_2 gray height_200">
            <?php $money = class_statistics::get_today_money($logged->get_unique(),$logged->get_user_type()); ?>
                <div class="inside">
				<h1><?= language('ACTIVE') ?> <br /><strong><?= language('CAMPAIGNS') ?></strong></h1>
                <span class="big_text"><?= class_statistics::get_active_campains() ?></span>
                
                </div>
           </div>
            <div class="right_half margin_bottom_2 blue height_200">
                <div class="inside">
                <?php $click = class_statistics::get_today_clicks($logged->get_unique(),$logged->get_user_type()); ?>
                <ul class="content_slider">
                <li>
                <h1><?= language('TODAY') ?> <br /><strong><?= language('CLICKS') ?></strong></h1>
                <span class="big_text"><?= $click[0] ?></span>
                <p><span class="huge_text"><?= $click[1] ?> % <?php if(strpos($click[1],"-") === false) echo "&uarr;"; else echo "&darr;"; ?></span></p>
                </li>
                <li>
                <h1><?= language('THIS_MONTH') ?> <br /><strong><?= language('CLICKS') ?></strong></h1>
                <span class="big_text"><?= $click[2] ?></span>
                </li>
                </ul>
                
                </div>

            </div>
            <div class="clear"></div>
            <div class="left_half green height_200">
             <?php $imp = class_statistics::get_today_impressions($logged->get_unique(),$logged->get_user_type()); ?>
                <div class="inside">
                <ul class="content_slider">
                <li>
                <h1><?= language('TODAY') ?> <br /><strong><?= language('IMPRESSIONS') ?></strong></h1>
                <span class="big_text"><?= $imp[0] ?> </span>
                <p><span class="huge_text"><?= $imp[1] ?> % <?php if(strpos($imp[1],"-") === false) echo "&uarr;"; else echo "&darr;"; ?> </span></p>
                </li>
                <li>
                <h1><?= language('THIS_MONTH') ?><br /><strong><?= language('IMPRESSIONS') ?></strong></h1>
                <span class="big_text"><?= $imp[2] ?> </span>
                </li>
                </ul>
                
                </div>

            </div>
            <div class="right_half height_200 black">
            <div class="inside">
            <h1><?= language('ACTIVE') ?> <br /><strong><?= language('TAGS') ?></strong></h1>
                <span class="big_text"><?= class_statistics::get_active_tags() ?></span>
            </div>
            </div>
         </div> 
         
         <div class="clear"></div>
         <div class="margin_bottom_2"></div>
         <div class="height_300  white none">
        
         <div class="left_30 height_300 black ">
         <div class="inside">
         <h1><?= language('GEOLOGICAL_TODAY') ?></h1>
         <?= language('IMPRESSIONS') ?>
         </div>
         <div class="inside ">
         <h1><?= language('TOP_COUNTRIES') ?></h1>
         <hr />
         <?php $top_countries = class_statistics::get_top_impression_countries($logged->get_unique(),$logged->get_user_type());
		 $nr = count($top_countries);
		 if($top_countries)
		 foreach ($top_countries as $country => $key)
		 {
		  ?>
         <span class="big_text"><?= $country ?></span><br />
         <span><?= $key ?> <?= language('IMPRESSIONS') ?></span>
         <?php
		 if($i != $nr) echo "<hr />"; 
		 $i++;
		 }
		 ?>
         </div>
         </div>
         <div class="right_70">
         <?php $statistics_country =  $stats_country->__call('get_countries',$parameters_country); ?>
         <?php if(!$statistics_country) echo "<div class='inside'><div style='text-align:center; padding:100px 0 100px 0;'><h1>".language('MESSAGE_no_stats')."</h1></div></div>";else {  ?>
        <div class="inside"  id="map" style="height:280px;"></div>
        <?php } ?>
 
         </div>
         <div class="clear"></div>
         </div> 
         <div class="margin_bottom_2"></div>
         <div class="clear"></div>
        </div>
	</div>
</div>
<div id='confirm'>
<div class="left">
	<div class='title'><span><?= language('CONFIRM') ?></span></div>
	<div class='message'></div>
</div>
<div class="right">
	<div class='buttons'>
				<span class='no simplemodal-close'><?= language('NO') ?></span><span class='yes'><?= language('YES') ?></span>
               
	</div>
</div>
<div class="clear"></div>
	</div>
		<!-- preload the images -->
	<div style='display:none'>
		<img src='img/confirm/header.gif' alt='' />
		<img src='img/confirm/button.gif' alt='' />
	</div>
<script>
<?php 		
		if($statistics_country)
		foreach ($statistics_country as $country => $value)
		{
			$split = explode("|",$value);
			$to_echo_country .= '{"code":"'.$country.'" , "name":"'.$country.'", "value":'.$split[0].', "color":"#eea638"},';
		}
		
?>
var mapData = [<?= substr($to_echo_country,0,-1)?>];
			 
</script>
<script type='text/javascript' src='app_needed/function.map.js'></script>
<script>
$(document).ready(function(){
$('.content_slider ').bxSlider({
  mode: 'vertical',
  infiniteLoop: true,
  auto:true,
  pause: 6000,
  pager: false,
  adaptiveHeight:true,
  responsive:true,
  controls:false,
  touchEnabled:true
});
});
</script>
</body>
</html>
<?php mysql_close($conn); ?>