<?php 
// ----------------------------------------------------------------------------------------------------
//			Mod Classement des Sites 
//
//      par Saint-pere  <saintpere5 AT hotmail POINT com> http://www.yep-yop.com
//
//     premiere distribution le Dimanche 26 Février 2006
//
// ----------------------------------------------------------------------------------------------------


define('IN_PHPBB', true); 

$phpbb_root_path = './'; 

include($phpbb_root_path . 'extension.inc'); 
include($phpbb_root_path . 'common.'.$phpEx); 

	function conv_date($date)
		{
			$d = substr($date,8,2); // jour
			$m = substr($date,5,2); // mois
			return $d."/".$m;
		}
		


$site = eregi_replace('[^0-9]','',$HTTP_GET_VARS['site']);
// On teste le modele de graphique que l'on désire
if (isset($HTTP_GET_VARS['modele']))
{
	$modele  = eregi_replace('[^0-9]','',$HTTP_GET_VARS['modele']);
	switch($modele) 
	{
		// Activité des clics ces dernières semaines
		case '1':
		
			// recupération des données
			$sql = "SELECT date,votes, clics FROM ". CLASS_SEM ." WHERE id_site=".$site." ORDER BY date DESC limit 5";
			if( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not query recent classification information', '', __LINE__, __FILE__, $sql);
			}
			$votes = array();
			$clics = array();
			$dates = array();
			while ($row = $db->sql_fetchrow($result))
			{
				$votes[] = $row['votes'];
				$clics[] = $row['clics'];
				$dates[] = conv_date($row['date']);
			}
		
			// On inverse l'ordre pour avoir une évolution dans le temps ..
			$votes = array_reverse($votes);
			$clics = array_reverse($clics);
			$dates = array_reverse($dates);
		
		
			require_once "Artichow/BarPlot.class.php";

			$graph = new Graph(400, 200);
			$graph->setAntiAliasing(TRUE);
   
			$blue = new Color(0,92, 139);
			$red = new Color(243, 157, 7);

 
			$group = new PlotGroup;
			$group->setPadding(40, 40);
			$group->setBackgroundGradient(
					new LinearGradient(
					new Color(230, 230, 230),
					new Color(255, 255, 255),
					0
					)
			);
  
   
			$plot = new BarPlot($votes, 1, 2);
			$plot->setBarGradient(
					new LinearGradient(
					new Color(150, 150, 210, 0),
					new Color(230, 230, 255, 30),
					0
					)
			); 
			$plot->barBorder->setColor(new Color(0, 0, 150, 20));
	

			$plot->setYAxis(PLOT_LEFT);
   
			$group->add($plot);
			$group->axis->left->setColor($blue);
			$group->axis->left->title->set($lang['prog_votes']);

   
			$plot = new BarPlot($clics, 2, 2);
			$plot->setBarGradient(
					new LinearGradient(
					new Color(243, 157, 7, 0),
					new Color(230, 230, 255, 30),
					0
					)
			); 
			$plot->barBorder->setColor(new Color(243, 157, 7, 20));

			$plot->setYAxis(PLOT_RIGHT);
			
			$plot->xAxis->label->setFont(new TuffyBold(7));

			$graph->shadow->setSize(4);
			$graph->shadow->setPosition(SHADOW_TOP);
			$graph->shadow->smooth(TRUE);
			$graph->shadow->setColor(new Color(160, 160, 160)); 
			$group->add($plot);
			$group->axis->right->setColor($red);
			$group->axis->right->title->set($lang['prog_clics']);
			// On ajoute les jours à l'axe des abscisses
			$group->axis->bottom->setLabelText($dates);
      
			$graph->add($group);
			$graph->draw();
			break;
			
			
		// Progression dans le classement
		case '2':
					// recupération des données
			$sql = "SELECT place, date FROM ". CLASS_SEM ." WHERE id_site=".$site." ORDER BY date LIMIT 10";
			if( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not query recent classification information', '', __LINE__, __FILE__, $sql);
			}
			$place = array();
			$date = array();
			$min = 9999;
			$max = 0;
			while ($row = $db->sql_fetchrow($result))
			{
				if ($row['place'] < $min)  $min = $row['place'];
				if ($row['place'] > $max)  $max = $row['place'];
				$place[] = $row['place'];
				$date[] = conv_date($row['date']);
			}
			if ($min <= 10 ) $min  = 0 ; else $min = $min - 5;
			if ($max <= 10 ) $max  = 10 ;  else $max = $max + 5;
			
			// On inverse l'ordre pour avoir une évolution dans le temps ..
			$place = array_reverse($place);
			$date = array_reverse($date);
			
			require_once "Artichow/LinePlot.class.php";

			$graph = new Graph(400, 200);
			$graph->setAntiAliasing(TRUE);

			$plot = new LinePlot($place);
			$plot->setXAxisZero(FALSE);
			$plot->setYMin($max);
			$plot->setYMax($min);
			$plot->grid->setNoBackground();

			$plot->title->set($lang['pos_clas']);
			$plot->title->setFont(new Tuffy(10));
			$plot->title->setBackgroundColor(new Color(255, 255, 255, 25));
			$plot->title->border->show();
			$plot->title->setPadding(2, 2, 2, 2);
			$plot->title->move(30, 20);

			$plot->setSpace(4, 4, 10, 0);
			$plot->setPadding(25, 15, 10, 18);

			$plot->setBackgroundGradient(
				new LinearGradient(
				new Color(150, 150, 210),
				new Color(255, 255, 255),
				0
			));

			$plot->setColor(new Color(150, 150, 210, 20));

			$plot->setBackgroundColor(
				new Color(240, 240, 240)
			);

			$plot->label->set($place);
			$plot->label->setPadding(2, 2, 2, 2);
			$plot->label->setBackgroundColor(
				new Color(227, 223, 241, 15)
			);
			$plot->label->setFont(new Tuffy(7));
			$plot->xAxis->setLabelText($date);

			$graph->add($plot);
			$graph->draw();
			break;
		
	}
}



   
?>