Location: PHPKode > projects > TrafficCenter > trafficcenter/spon_stat.php
<?php
ini_set("register_globals", 1);
include("funktions.php");
openmysql();
$config=loadconfig();

###Check Password
session_start();
if($ac == 'logout') session_destroy();

if(!$_GET) {
	$_GET=$HTTP_GET_VARS;
}

if($pass) {
	$result=mysql_query("select PASSWORD('$pass')");
	list($vpass)=mysql_fetch_row($result);
}

if($_GET[id]) $id=$_GET[id];

if($id and $vpass) {
	$result=mysql_query("select * from all_sponsoren where sid=$id and PASSWORD(pass)='$vpass'");
	if(!mysql_error()) {
		if(mysql_num_rows($result)) {
			$sid=$id;
			$user=mysql_fetch_row($result);
			session_register("id");
			session_register("vpass");
			$ok=1;
		} else {
			$ok=0;
		}
	}
}

if($ok) {
	$hoch=250;
	$breit=320;
	$breit_m=420;

	### Intialisieren
	$tabelle=$was."sponstat";
	if($was == 'f_' or $was == 'b_' or $was == 't_') {
		$felder=array('views', 'klicks');
		$query="sum(views), sum(klicks)*10";
		$legende[]="Views";
		$legende[]="Klicks x10";
	} elseif($was == 'p_') {
		$felder=array('popups');
		$query="sum(popups)";
		$legende[]="PopUps";
	} else {
		$felder=array('views');
		$query="sum(views)";
		$legende[]="Besucher";
	}
	$result=mysql_query("SELECT sum($felder[0]) as max FROM $tabelle where kid=$kid and datum>date_sub(curdate(), interval 31 day) group by datum order by max desc limit 1");
	list($max)=mysql_fetch_row($result);
	#Header( "Content-type: image/png"); 
	$im = imagecreate ($breit_m,$hoch); 
	$white = ImageColorAllocate($im, 0xFF, 0xFF, 0xFF);
	$grey = ImageColorAllocate($im, 0xE0, 0xE0, 0xE0); 
	$grey2 = ImageColorAllocate($im, 0xA0, 0xA0, 0xA0); 
	$grey3 = ImageColorAllocate($im, 0xD0, 0xD0, 0xD0); 
	$green = ImageColorAllocate($im, 0x00, 0xFF, 0x00); 
	$black = ImageColorAllocate($im, 0x00, 0x00, 0x00); 
	$black = ImageColorAllocate($im,0x00,0x00,0x00);
	$cl[0] = ImageColorAllocate($im,0xFF,0x00,0x00); 
	$cl[3] = ImageColorAllocate($im,0xFF,0x33,0xFF);
	$cl[2] = ImageColorAllocate($im,0xEA,0x99,0x00);
	$cl[1] = ImageColorAllocate($im,0x00,0xFF,0x00);
	$cl[4] = ImageColorAllocate($im,0x00,0xCC,0xFF);
	$cl[5] = ImageColorAllocate($im,0x99,0x33,0xCC);

	ImageFilledRectangle($im,0,0,$breit_m,$hoch,$white);
	ImageFilledRectangle($im,35,10,$breit-10,$hoch-30,$grey);
	ImageRectangle($im, 0, 0, $breit_m-1, $hoch-1, $black);


	## X-Achsen anschreiben
	if($max > 1000) {
		$max=floor(($max+1000)/1000)*1000;
		$mitte=$max/2;
	} elseif($max > 100) {
		$max=floor(($max+100)/100)*100;
		$mitte=$max/2;
	} else {
		$max=floor(($max+10)/10)*10;
		$mitte=$max/2;
	}

	## Y-Achse anschreiben
	$result=mysql_query("select date_format(curdate(), '%d. %b'), date_format(date_sub(curdate(), interval 30 day), '%d. %b')");
	list($st, $end)=mysql_fetch_row($result);
	ImageString ($im,2,$breit-50,$hoch-27,$st,$black);
	ImageString ($im,2,13,$hoch-27,$end,$black);

	$temp=floor(($hoch-40)/2)+10;
	$abstand=($breit-15-35)/30;
	for($i=0;$i<=29;$i++) {
		ImageLine($im, (35+$i*$abstand), $hoch-29, (35+$i*$abstand), $hoch-31, $black);
		ImageLine($im, (35+$i*$abstand), $hoch-31, (35+$i*$abstand), 10, $grey3);
	}

	ImageLine($im, 35, $temp, $breit-10, $temp, $grey2);
	ImageLine($im, 35, 15, $breit-10, 15, $grey2);
	ImageLine($im, 35, 10, 35, $hoch-30, $black);
	ImageLine($im, 35, $hoch-30, $breit-10, $hoch-30, $black);
	ImageString ($im,2,5,11,$max,$black);
	ImageString ($im,2,5,$temp-4,$mitte,$black);



	
	#Kurve zeichnen
	$fakt=($hoch-15-30)/$max;
	$xold=35;
	$result=mysql_query("SELECT $query FROM $tabelle WHERE kid=$kid and datum=date_sub(curdate(), interval 30 day) group by datum ");
	$zeile=mysql_fetch_row($result);
	$yold_a=$hoch-30-$fakt*$zeile[0];
	if($felder[1]) $yold_b=$hoch-30-$fakt*$zeile[1];

	$tx=0;
	for($datum=29;$datum>=0;$datum--) {
		$tx++;
		$x=($tx)*$abstand+35;
		$result=mysql_query("SELECT $query FROM $tabelle WHERE kid=$kid and datum=date_sub(curdate(), interval $datum day) group by datum ");
		$zeile=mysql_fetch_row($result);
		if(!$zeile[0]) $zeile[0]=0;
		$y0=$hoch-30-$fakt*$zeile[0];
		ImageLine($im, $xold, $yold_a, $x, $y0, $cl[0]);
		$yold_a=$y0;
		if($felder[1]) {
			if(!$zeile[1]) $zeile[1]=0;
			$y1=$hoch-30-$fakt*$zeile[1];
			ImageLine($im, $xold, $yold_b, $x, $y1, $cl[1]);
			$yold_b=$y1;
		}
		$xold=$x;
	}
	

	##Legende
	ImageString ($im,3,$breit_m-92,27,"Legende",$black);
	ImageRectangle($im, $breit_m-95, 25, $breit_m-15, 230, $black);

	$a=0;
	while(list($abfall,$temp)=each($legende)) {
		ImageLine($im, $breit_m-89, 48+($a*11), $breit_m-85, 48+($a*11), $cl[$a]);
		ImageLine($im, $breit_m-89, 47+($a*11), $breit_m-85, 47+($a*11), $cl[$a]);
		ImageLine($im, $breit_m-89, 46+($a*11), $breit_m-85, 46+($a*11), $cl[$a]);
		ImageString ($im,2,$breit_m-80,40+($a*11),$temp,$black);
		$a++;
	}
	
	ImagePNG($im); 
	ImageDestroy($im); 


}
?>
Return current item: TrafficCenter