now() - INTERVAL 7 DAY and stats_pools.partner_id=".$user['id']." and stats_pools.banner_id=banners.id and banners.id=".$banner_id." and stats_pools.pool_id='".$pool_id."' group by banners.id, stats_pools.statsdate"); $names['views']='Views'; $names['hits']='Clicks'; $names['ratio']='Ratio %'; while($stats_date_banner=mysql_fetch_array($stats_date_banners)){ $bannername=$stats_date_banner['name']; if(!isset($dates) && substr($stats_date_banner['statsdate'],8)!=date("d",mktime(0,0,0,date("m"),date("d")-7,date("Y")))){ // we seem to have started half-way the month, please fill in the first couple of days first. $begindate=date("d",mktime(0,0,0,date("m"),date("d")-6,date("Y"))); $enddate=substr($stats_date_banner['statsdate'],8); for($i=$begindate;$i!=$enddate;$i++){ $ydata['views'][]=NULL; $ydata['hits'][]=NULL; $ydata['ratio'][]=NULL; if($i>$enddate){ $month=1; } else { $month=NULL; } $dates[]=date("Y-m-d",mktime(0,0,0,date("m")-$month,$i,date("Y"))); if($i>$enddate && $i==date("t",mktime(0,0,0,date("m"),date("d")-7,date("Y")))) { $i=0; } } $skip=TRUE; } else { $skip=FALSE; } if(($lastdate!=substr($stats_date_banner['statsdate'],8)-1) && (substr($stats_date_banner['statsdate'],8)!=1) && $skip!=TRUE){ $adddays=substr($stats_date_banner['statsdate'],8)-$lastdate; for($i=1;$i<$adddays;$i++){ $ydata['views'][]=NULL; $ydata['hits'][]=NULL; $ydata['ratio'][]=NULL; $dates[]=date("Y-m-d",mktime(0,0,0,date("m")-$month,$lastdate+$i,date("Y"))); } } $lastdate=substr($stats_date_banner['statsdate'],8); $ydata['views'][]=$stats_date_banner['views']; $ydata['hits'][]=$stats_date_banner['hits']; $ydata['ratio'][]=$stats_date_banner['ratio']; $dates[]=$stats_date_banner['statsdate']; } if(($lastdate!=date('d')) && (date('d')!=1)){ $adddays=(date('d')-$lastdate)+1; // add 1 to display current date for($i=1;$i<$adddays;$i++){ $ydata['views'][]=NULL; $ydata['hits'][]=NULL; $ydata['ratio'][]=NULL; $dates[]=date("Y-m-d",mktime(0,0,0,date("m")-$month,$lastdate+$i,date("Y"))); } } // Create the graph and specify the scale for both Y-axis $graph = new Graph(500,200,"auto"); $graph->SetScale("textlin"); $graph->SetY2Scale("lin"); $graph->SetColor("#FFFFFF"); $graph->SetFrame(true,'#B8106A',1); $graph->SetMarginColor('#FFFFFF'); // Adjust the margin $graph->img->SetMargin(40,170,20,90); // Create the plots and Add the plots to the graph foreach($ydata as $key => $value){ $ydata[$key]['obj']=new LinePlot($ydata[$key]); } $graph->Add($ydata['views']['obj']); $graph->Add($ydata['hits']['obj']); $graph->AddY2($ydata['ratio']['obj']); $graph->title->Set("Statistieken voor: ".$bannername."."); $graph->title->Pos(0.05,0.1,"left","top"); $graph->title->SetColor('#B8106A'); $graph->title->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->title->Set("Datum"); $graph->xaxis->SetFont(FF_FONT1,FS_BOLD); $graph->xaxis->SetColor('#000000'); $graph->xaxis->title->SetColor('#B8106A'); $graph->xaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->yaxis->title->Set("Views/Clicks"); $graph->yaxis->SetColor('#000000'); $graph->yaxis->title->SetColor('white'); $graph->yaxis->title->SetFont(FF_FONT1,FS_BOLD); $graph->y2axis->title->Set("Ratio %"); $graph->y2axis->SetColor('#000000'); $graph->y2axis->title->SetColor('#B8106A'); $graph->y2axis->title->SetFont(FF_FONT1,FS_BOLD); // Set the legends for the plots foreach($ydata as $key => $value){ $ydata[$key]['obj']->SetLegend($names[$key]); $ydata[$key]['obj']->SetWeight(2); } // add color to the lines $ydata['hits']['obj']->SetColor("blue"); $ydata['views']['obj']->SetColor("orange"); $ydata['ratio']['obj']->SetColor("red"); $ydata['hits']['obj']->mark->SetType(MARK_FILLEDCIRCLE); $ydata['hits']['obj']->mark->SetFillColor("blue"); $ydata['views']['obj']->mark->SetType(MARK_FILLEDCIRCLE); $ydata['views']['obj']->mark->SetFillColor("orange"); $ydata['ratio']['obj']->mark->SetType(MARK_FILLEDCIRCLE); $ydata['ratio']['obj']->mark->SetFillColor("red"); // make sure dates are diplayed $graph->xaxis->SetTickLabels($dates); $graph->xaxis->SetLabelAngle(90); // Adjust the legend position $graph->legend->Pos(0.05,0.1,"right","top"); $graph->legend->SetShadow(FALSE); // Display the graph $graph->Stroke(); } else { include ("../../jpgraph/jpgraph.php"); include ("../../jpgraph/jpgraph_canvas.php"); // Create the graph. $graph = new CanvasGraph(380,25,"auto"); $t1 = new Text("U dient ingelogd te zijn om deze afbeelding te bekijken."); $t1->Pos(0.05,0.1); $t1->SetOrientation("h"); $t1->SetFont(FF_FONT1,FS_NORMAL); $t1->SetBox("white","black",'gray'); $t1->SetColor("black"); $graph->AddText($t1); $graph->Stroke(); } ?>