Index: trunk/web/addons/toga/image.php
===================================================================
--- trunk/web/addons/toga/image.php	(revision 113)
+++ trunk/web/addons/toga/image.php	(revision 114)
@@ -8,5 +8,5 @@
 function drawSmallClusterImage() {
 
-	$ic = new ClusterImage( $clustername );
+	$ic = new ClusterImage( $clustername, null );
 	$ic->draw();
 }
@@ -14,5 +14,6 @@
 function drawBigClusterImage() {
 
-	// iets
+	$ic = new ClusterImage( $clustername, null );
+	$ic->draw();
 }
 
Index: trunk/web/addons/toga/libtoga.php
===================================================================
--- trunk/web/addons/toga/libtoga.php	(revision 113)
+++ trunk/web/addons/toga/libtoga.php	(revision 114)
@@ -145,4 +145,8 @@
 	}
 
+	function getHeartbeat() {
+		$handler = $this->xmlhandler;
+		return $handler->getHeartbeat();
+	}
 }
 
@@ -193,5 +197,5 @@
 			if( strstr( $attrs[NAME], 'TOGA-HEARTBEAT' ) ) {
 
-				$heartbeat['time'] = $attrs[VAL];
+				$this->heartbeat['time'] = $attrs[VAL];
 				//printf( "heartbeat %s\n", $heartbeat['time'] );
 
@@ -256,4 +260,5 @@
 			}
 		}
+		$this->jobs = $jobs;
 	}
 
@@ -304,4 +309,8 @@
 	function getJobs() {
 		return $this->jobs;
+	}
+
+	function getHeartbeat() {
+		return $this->heartbeat['time'];
 	}
 }
@@ -375,4 +384,8 @@
 	}
 
+	function getJobs() {
+		return $this->jobs;
+	}
+
 	function draw() {
 
@@ -440,6 +453,11 @@
 	var $dataget, $image, $clustername;
 
-	function ClusterImage( $clustername ) {
-		$this->dataget = new DataGatherer();
+	function ClusterImage( $clustername, $data_gather ) {
+
+		if( !isset( $data_gather ) )
+			$this->dataget = new DataGatherer();
+		else
+			$this->dataget = $data_gather;
+
 		$this->clustername = $clustername;
 	}
Index: trunk/web/addons/toga/overview.php
===================================================================
--- trunk/web/addons/toga/overview.php	(revision 113)
+++ trunk/web/addons/toga/overview.php	(revision 114)
@@ -1,2 +1,215 @@
 <?php
+
+$my_dir = getcwd();
+
+include_once "./libtoga.php";
+
+global $GANGLIA_PATH;
+chdir( $GANGLIA_PATH );
+include_once "./class.TemplatePower.inc.php";
+chdir( $my_dir );
+
+$httpvars = new HTTPVariables( $HTTP_GET_VARS );
+$clustername = $httpvars->getClusterName();
+
+$data_gatherer = new DataGatherer();
+
+$tpl = new TemplatePower("templates/overview.tpl");
+$tpl->prepare();
+
+$tpl->assign( "clusterimage", "./image.php?c=".$clustername."&view=big-clusterimage" );
+
+$data_gatherer->parseXML();
+$heartbeat = $data_gatherer->getHeartbeat();
+$jobs = $data_gatherer->getJobs();
+$nodes = $data_gatherer->getNodes();
+
+$tpl->assign("heartbeat", makeDate( $heartbeat ) );
+
+$pie = drawPie();
+$tpl->assign("pie", $pie );
+
+function makeTime( $time ) {
+
+	$days = intval( $time / 86400 );
+	if( $days > 0 ) {
+		$time = $time % ($days * 86400);
+		if( $days > 1 )
+			$date_str .= $days . 'days - ';
+		else
+			$date_str .= $days . 'day - ';
+	}
+	$hours = intval( $time / 3600 );
+	if( $hours > 0 ) {
+		$time = $time % ($hours * 3600);
+		$date_str .= $hours . ':';
+		$date_unit = ' hours';
+	}
+	$minutes = intval( $time / 60 );
+	if( $minutes > 0 ) {
+		$seconds = $time % ($minutes * 60);
+		$date_str .= $minutes . ':';
+		$date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
+	}
+	$date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
+	$date_str .= $seconds . ' ' . $date_unit;
+
+	return $date_str;
+}
+
+function makeDate( $time ) {
+	return strftime( "%a %d %b %Y %H:%M:%S", $time );
+}
+
+function colorRed( $color ) {
+	return substr( $color, 0, 2 );
+}
+function colorGreen( $color ) {
+	return substr( $color, 2, 2 );
+}
+function colorBlue( $color ) {
+	return substr( $color, 4, 2 );
+}
+
+function colorDiffer( $first, $second ) {
+
+	// Make sure these two colors differ atleast 50 R/G/B
+	$min_diff = 50;
+
+	$c1r = decHex( colorRed( $first ) );
+	$c1g = decHex( colorGreen( $first ) );
+	$c1b = decHex( colorBlue( $first ) );
+
+	$c2r = decHex( colorRed( $second ) );
+	$c2g = decHex( colorGreen( $second ) );
+	$c2b = decHex( colorBlue( $second ) );
+
+	$rdiff = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
+	$gdiff = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
+	$bdiff = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
+
+	if( $rdiff >= $min_diff or $gdiff >= $min_diff or $bdiff >= $min_diff )
+		return TRUE;
+	else
+		return FALSE;
+}
+
+function randomColor( $known_colors ) {
+
+	$start = hexdec( "004E00" );
+	$end = hexdec( "FFFFFF" );
+
+	if( count( $known_colors ) == 0 )
+		return dechex(rand( $start, $end ));
+
+	$color_changed = TRUE;
+
+	while( $color_changed ) {
+
+		$color_changed = FALSE;
+
+		foreach( $known_colors as $old ) {
+
+			if( !isset( $new ) )
+				$new = rand( $start, $end );
+
+			if( !colorDiffer( dechex( $new ), $old ) )
+
+				while( !colorDiffer( $new, $old ) ) {
+
+					$new = rand( $start, $end );
+					$color_changed = TRUE;
+				}
+		}
+	}
+
+	// Whoa! Actually found a good color ;)
+	return dechex( $new );
+}
+
+function drawPie() {
+
+	global $jobs, $nodes;
+
+	$pie_args = "title=" . rawurlencode("Cluster Jobload");
+	$pie_args .= "&size=250x150";
+
+	$queues = array();
+	$nr_jobs = count( $jobs );
+	$nr_nodes = count( $nodes );
+
+	$emptynodes = 0;
+
+	foreach( $nodes as $node ) {
+
+		$myjobs = $node->getJobs();
+
+		if( count( $myjobs ) == 0 )
+			$emptynodes++;
+		else
+			$nodes_jobs = $nodes_jobs + count( $myjobs );
+	}
+
+	$empty_percentage = ($emptynodes / $nr_nodes) * 100;
+	$job_percentage = 100 - $empty_percentage; 
+
+	$color = randomColor( $qcolors );
+	$qcolors[] = $color;
+	$pie_args .= "&free=$empty_percentage,$color";
+
+	foreach( $jobs as $jobid => $jobattrs ) {
+
+		$qname = $jobattrs[queue];
+
+		if( !array_search( $qname, $queues ) ) {
+
+			if( !isset( $queues[$qname] ) )
+				$queues[$qname] = array();
+
+			$queues[$qname][] = $jobid;
+		}
+	}
+
+	$qcolors = array();
+	foreach( $queues as $queue => $myjobs ) {
+
+		$qjobs = count ( $myjobs );
+		$percentage = ( $qjobs / $nr_jobs ) * $job_percentage;
+		$color = randomColor( $qcolors );
+		$qcolors[] = $color;
+		$pie_args .= "&$queue=$percentage,$color";
+	}
+	$pie = "../../pie.php?$pie_args";
+
+	return $pie;
+}
+
+foreach( $jobs as $jobid => $jobattrs ) {
+
+	$report_time = $jobattrs[reported];
+
+	if( $report_time == $heartbeat ) {
+
+		$tpl->newBlock("node");
+		$tpl->assign("id", $jobid );
+		$tpl->assign("state", $jobattrs[status] );
+		$tpl->assign("user", $jobattrs[owner] );
+		$tpl->assign("queue", $jobattrs[queue] );
+		$tpl->assign("name", $jobattrs[name] );
+		$nodes = count( $jobattrs[nodes] );
+		$ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
+		$cpus = $nodes * $ppn;
+		$tpl->assign("cpus", $cpus );
+		$tpl->assign("req_cpu", $jobattrs[requested_time] );
+		$tpl->assign("req_memory", $jobattrs[requested_memory] );
+		$tpl->assign("nodes", $nodes );
+		$start_time = (int) $jobattrs[start_timestamp];
+		$runningtime = makeTime( $report_time - $start_time );
+		$tpl->assign("started", makeDate( $start_time ) );
+		$tpl->assign("runningtime", $runningtime );
+	}
+}
+
+$tpl->printToScreen();
+
 ?>
