Index: trunk/web/addons/job_monarch/libtoga.php
===================================================================
--- trunk/web/addons/job_monarch/libtoga.php	(revision 518)
+++ trunk/web/addons/job_monarch/libtoga.php	(revision 519)
@@ -25,26 +25,28 @@
 
 
-class HTTPVariables {
-
+class HTTPVariables
+{
 	var $clustername, $metricname;
 	var $restvars, $httpvars;
 
-	function HTTPVariables( $httpvars, $getvars ) {
-
-		$this->restvars = array();
-
-		$this->clustername = $httpvars["c"] ? $httpvars["c"] : $getvars["c"];
-		$this->metricname = $httpvars["m"] ? $httpvars["m"] : $getvars["m"];
-
-		foreach( $httpvars as $httpvar => $httpval ) {
-			
-			if( $httpval ) {
+	function HTTPVariables( $httpvars, $getvars )
+	{
+		$this->restvars		= array();
+
+		$this->clustername	= $httpvars["c"] ? $httpvars["c"] : $getvars["c"];
+		$this->metricname	= $httpvars["m"] ? $httpvars["m"] : $getvars["m"];
+
+		foreach( $httpvars as $httpvar => $httpval )
+		{
+			if( $httpval )
+			{
 				$this->restvars[$httpvar] = $httpval;
 			}
 		}
 
-		foreach( $getvars as $getvar => $getval ) {
-
-			if( $getval ) {
+		foreach( $getvars as $getvar => $getval )
+		{
+			if( $getval )
+			{
 				$this->restvars[$getvar] = $getval;
 			}
@@ -52,17 +54,24 @@
 	}
 
-	function getClusterName() {
+	function getClusterName()
+	{
 		return $this->clustername;
 	}
 
-	function getMetricName() {
+	function getMetricName()
+	{
 		return $this->metricname;
 	}
 
-	function getHttpVar( $var ) {
+	function getHttpVar( $var )
+	{
 		if( isset( $this->restvars[$var] ) )
+		{
 			return $this->restvars[$var];
+		}
 		else
+		{
 			return null;
+		}
 	}
 }
@@ -70,5 +79,5 @@
 $CLUSTER_CONFS	= array();
 
-// Toga's conf
+// Monarch's conf
 //
 include_once "./conf.php";
@@ -79,9 +88,6 @@
 global $JOB_ARCHIVE_DIR;
 global $JOB_ARCHIVE_DBASE;
-//global $SORTBY_HOSTNAME;
-//global $SORT_ORDER;
 global $skan_str;
 global $x_first, $y_first;
-//global $SORT_XLABEL, $SORT_YLABEL;
 global $CLUSTER_CONFS;
 
@@ -95,5 +101,5 @@
 include_once "./ganglia.php";
 include_once "./get_context.php";
-//unset( $start );
+
 $context = 'cluster';
 include_once "./get_ganglia.php";
@@ -110,6 +116,4 @@
 global $context, $clustername, $reports;
 
-//$clustername = $httpvars->getClusterName();
-
 global $default_metric;
 
@@ -121,5 +125,6 @@
 global $DATETIME_FORMAT;
 
-function makeDate( $time ) {
+function makeDate( $time )
+{
 	global $DATETIME_FORMAT;
 	return strftime( $DATETIME_FORMAT, $time );
@@ -127,10 +132,10 @@
 
 
-class TarchDbase {
-
+class TarchDbase
+{
 	var $ip, $dbase, $conn;
 
-	function TarchDbase( $ip = null, $dbase = null ) {
-
+	function TarchDbase( $ip = null, $dbase = null )
+	{
 		global $CLUSTER_CONFS, $clustername;
 		global $JOB_ARCHIVE_DBASE;
@@ -153,6 +158,6 @@
 	}
 
-	function connect() {
-
+	function connect()
+	{
 		if( $this->ip == null )
 			$this->conn = pg_connect( "dbname=".$this->dbase );
@@ -161,38 +166,59 @@
 	}
 
-	function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null ) {
-
+	function searchDbase( $id = null, $queue = null, $user = null, $name = null, $start_from_time = null, $start_to_time = null, $end_from_time = null, $end_to_time = null )
+	{
 		global $SEARCH_RESULT_LIMIT;
 
-		if( $id ) {
+		if( $id )
+		{
 			$select_query = "SELECT job_id FROM jobs WHERE job_id = '$id' AND job_status = 'F'";
 			$this->resultcount = 1;
-		} else {
+		}
+		else
+		{
 			$query_args = array();
 			
 			if( $queue )
+			{
 				$query_args[] = "job_queue ='$queue'";
+			}
 			if( $user )
+			{
 				$query_args[] = "job_owner ='$user'";
+			}
 			if( $name )
+			{
 				$query_args[] = "job_name = '$name'";
+			}
 			if( $start_from_time )
+			{
 				$query_args[] = "job_start_timestamp >= $start_from_time";
+			}
 			if( $start_to_time )
+			{
 				$query_args[] = "job_start_timestamp <= $start_to_time";
+			}
 			if( $end_from_time )
+			{
 				$query_args[] = "job_stop_timestamp >= $end_from_time";
+			}
 			if( $end_to_time )
+			{
 				$query_args[] = "job_stop_timestamp <= $end_to_time";
+			}
 
 			$query = "FROM jobs WHERE job_status = 'F' AND ";
 			$extra_query_args = '';
 
-			foreach( $query_args as $myquery ) {
-
+			foreach( $query_args as $myquery )
+			{
 				if( $extra_query_args == '' )
+				{
 					$extra_query_args = $myquery;
+				}
 				else
+				{
 					$extra_query_args .= " AND ".$myquery;
+				}
 			}
 			$query .= $extra_query_args;
@@ -214,11 +240,13 @@
 
 		foreach( $ids as $crow)
+		{
 			$ret[] = $crow[job_id];
+		}
 
 		return $ret;
 	}
 
-	function getNodesForJob( $jobid ) {
-
+	function getNodesForJob( $jobid )
+	{
 		$result = $this->queryDbase( "SELECT node_id FROM job_nodes WHERE job_id = '$jobid'" );
 
@@ -226,12 +254,13 @@
 
 		foreach( $result as $result_row ) 
-
+		{
 			$nodes[] = $this->getNodeArray( $result_row[node_id] );
+		}
 
 		return $nodes;
 	}
 
-	function getJobsForNode( $nodeid ) {
-
+	function getJobsForNode( $nodeid )
+	{
 		$result = $this->queryDbase( "SELECT job_id FROM job_nodes WHERE node_id = '$nodeid'" );
 
@@ -239,11 +268,12 @@
 
 		foreach( $result as $result_row )
-
+		{
 			$jobs[] = $this->getJobArray( $result_row[job_id] );
-
+		}
 		return $jobs;
 	}
 
-	function getJobArray( $id ) {
+	function getJobArray( $id )
+	{
 		$result = $this->queryDbase( "SELECT * FROM jobs WHERE job_id = '$id'" );
 
@@ -251,6 +281,6 @@
 	}
 
-	function getNodeArray( $id ) {
-
+	function getNodeArray( $id )
+	{
 		$result = $this->queryDbase( "SELECT * FROM nodes WHERE node_id = '$id'" );
 
@@ -258,10 +288,10 @@
 	}
 
-	function makeArray( $result_row ) {
-
+	function makeArray( $result_row )
+	{
 		$myar = array();
 
-		foreach( $result_row as $mykey => $myval ) {
-
+		foreach( $result_row as $mykey => $myval )
+		{
 			$map_key = explode( '_', $mykey );
 
@@ -278,16 +308,19 @@
 	}
 
-	function queryDbase( $query ) {
-
+	function queryDbase( $query )
+	{
 		$result_rows = array();
 	
 		if( !$this->conn )
+		{
 			$this->connect();
-
-		//printf( "query = [%s]\n", $query );
+		}
+
 		$result = pg_query( $this->conn, $query );
 
 		while ($row = pg_fetch_assoc($result))
+		{
 			$result_rows[] = $row;
+		}
 
 		return $result_rows;
@@ -295,25 +328,26 @@
 }
 
-class TarchRrdGraph {
+class TarchRrdGraph
+{
 	var $rrdbin, $rrdvalues, $clustername, $hostname, $tempdir, $tarchdir, $metrics;
 
-	function TarchRrdGraph( $clustername, $hostname ) {
-
+	function TarchRrdGraph( $clustername, $hostname )
+	{
 		global $RRDTOOL;
 		global $JOB_ARCHIVE_DIR;
 
-		$this->rrdbin = $RRDTOOL;
-		$this->rrdvalues = array();
-		$this->tarchdir = $JOB_ARCHIVE_DIR;
-		$this->clustername = $clustername;
-		$this->hostname = $hostname;
-	}
-
-	function doCmd( $command ) {
-
-		printf( "command = %s\n", $command );
+		$this->rrdbin		= $RRDTOOL;
+		$this->rrdvalues	= array();
+		$this->tarchdir		= $JOB_ARCHIVE_DIR;
+		$this->clustername	= $clustername;
+		$this->hostname		= $hostname;
+	}
+
+	function doCmd( $command )
+	{
 		$pipe = popen( $command . ' 2>&1', 'r' );
 
-		if (!$pipe) {
+		if (!$pipe)
+		{
 			print "pipe failed.";
 			return "";
@@ -321,21 +355,27 @@
 
 		$output = '';
+
 		while(!feof($pipe))
+		{
 			$output .= fread($pipe, 1024);
+		}
 
 		pclose($pipe);
 
 		$output = explode( "\n", $output );
-		//print_r( $output );
+
 		return $output;
 	}
 
-	function dirList( $dir ) {
-
+	function dirList( $dir )
+	{
 		$dirlist = array();
 
-		if ($handle = opendir( $dir )) {
-			while (false !== ($file = readdir($handle))) {
-				if ($file != "." && $file != "..") {
+		if ($handle = opendir( $dir ))
+		{
+			while (false !== ($file = readdir($handle)))
+			{
+				if ($file != "." && $file != "..")
+				{
 					$dirlist[] = $file;
 				}
@@ -347,56 +387,45 @@
 	}
 
-	function getTimePeriods( $start, $end ) {
-
-		//printf("start = %s end = %s\n", $start, $end );
+	function getTimePeriods( $start, $end )
+	{
 		$times = array();
 		$dirlist = $this->dirList( $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname );
 
-		//print_r( $dirlist );
-
 		$first = 0;
 		$last = 9999999999999;
 
-		foreach( $dirlist as $dir ) {
-
+		foreach( $dirlist as $dir )
+		{
 			if( $dir > $first and $dir <= $start )
+			{
 				$first = $dir;
+			}
 			if( $dir < $last and $dir >= $end )
+			{
 				$last = $dir;
-		}
-
-		//printf( "first = %s last = %s\n", $first, $last );
-
-		foreach( $dirlist as $dir ) {
-
-			//printf( "dir %s ", $dir );
-
-			if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) ) {
-			
+			}
+		}
+
+		foreach( $dirlist as $dir )
+		{
+			if( $dir >= $first and $dir <= $last and !array_key_exists( $dir, $times ) )
+			{
 				$times[] = $dir;
-				//printf("newtime %s ", $dir );
-
-			}
-		}
-
-		//print_r( $times );
+			}
+		}
 
 		sort( $times );
 
-		//print_r( $times );
-
 		return $times;
 	}
 
-	function getRrdDirs( $start, $stop ) {
-
-		//printf( "tarchdir = %s\n", $this->tarchdir );
+	function getRrdDirs( $start, $stop )
+	{
 		$timess = $this->getTimePeriods( $start, $stop );
-		//print_r( $timess );
 
 		$rrd_files = array();
 
-		foreach( $timess as $time ) {
-
+		foreach( $timess as $time )
+		{
 			$rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname. '/'.$time;
 		}
@@ -405,12 +434,12 @@
 	}
 
-	function getRrdFiles( $metric, $start, $stop ) {
-
+	function getRrdFiles( $metric, $start, $stop )
+	{
 		$times = $this->getTimePeriods( $start, $stop );
 
 		$rrd_files = array();
 
-		foreach( $times as $time ) {
-
+		foreach( $times as $time )
+		{
 			$rrd_files[] = $this->tarchdir . '/' . $this->clustername . '/' . $this->hostname . '/' .$time. '/' . $metric. '.rrd';
 		}
@@ -418,27 +447,12 @@
 		return $rrd_files;
 	}
-
-	function graph( $descr ) {
-//	monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl# rrdtool graph /var/www/ganglia/test1.png --start 1118683231 --end 1118750431 --width 300 --height 400 DEF:'1'='./1118647515/load_one.rrd':'sum':AVERAGE DEF:'2'='./1118690723/load_one.rrd':'sum':AVERAGE DEF:'3'='./1118733925/load_one.rrd':'sum':AVERAGE AREA:1#555555:"load_one" AREA:2#555555 AREA:3#555555
-//	380x461
-//	monitor2:/data/toga/rrds/LISA Cluster/gb-r15n11.irc.sara.nl#
-		//$command = $this->rrdbin . " graph - --start $start --end $end ".
-			"--width $width --height $height $upper_limit $lower_limit ".
-			"--title '$title' $vertical_label $extras $background ". $series;
-
-		//$graph = $this->doCmd( $command );
-
-		//return $graph;
-		return 0;
-	}
 }
 
-class DataSource {
-
+class DataSource
+{
 	var $data, $ip, $port;
 
-	//function DataSource( $ip = '127.0.0.1', $port = 8649 ) {
-	function DataSource() {
-
+	function DataSource()
+	{
 		global $DATA_SOURCE;
 
@@ -453,6 +467,6 @@
 	}
 
-	function getData() {
-
+	function getData()
+	{
 		$errstr;
 		$errno = 0;
@@ -461,5 +475,6 @@
 		$fp = fsockopen( $this->ip, $this->port, $errno, $errstr, $timeout );
 
-		if( !$fp ) {
+		if( !$fp )
+		{
 			echo 'Unable to connect to '.$this->ip.':'.$this->port; // printf( 'Unable to connect to [%s:%.0f]', $this->ip, $this->port );
 			return;
@@ -468,6 +483,6 @@
 		stream_set_timeout( $fp, 30 );
 
-		while ( !feof( $fp ) ) {
-			
+		while ( !feof( $fp ) )
+		{
 			$data .= fread( $fp, 16384 );
 		}
@@ -479,78 +494,77 @@
 }
 
-class DataGatherer {
-
+class DataGatherer
+{
 	var $xmlhandler, $data, $httpvars;
 
-	function DataGatherer( $cluster ) {
-
-		//global $DATA_SOURCE;
-	
-		//printf("dg cluster = %s\n", $cluster );
-		//$ds_fields = explode( ':', $DATA_SOURCE );
-		//$ds_ip = $ds_fields[0];
-		//$ds_port = $ds_fields[1];
-
-		//$this->source = new DataSource( $ds_ip, $ds_port );
-
+	function DataGatherer( $cluster )
+	{
 		$this->cluster	= $cluster;
 		$this->httpvars = $httpvars;
 	}
 
-	function parseXML( $data ) {
-
-		//$src = &$this->source;
-		//$this->data = $src->getData();
-
+	function parseXML( $data )
+	{
 		$this->parser 		= xml_parser_create();
 		$this->xmlhandler 	= new TorqueXMLHandler( $this->cluster );
 
 		xml_set_element_handler( $this->parser, array( &$this->xmlhandler, 'startElement' ), array( &$this->xmlhandler, 'stopElement' ) );
-		//if ( !xml_parse( $this->parser, $this->data ) )
+
 		if ( !xml_parse( $this->parser, $data ) )
+		{
 			$error = sprintf( 'XML error: %s at %d', xml_error_string( xml_get_error_code( $this->parser ) ), xml_get_current_line_number( $this->parser ) );
-	}
-
-	function printInfo() {
+		}
+	}
+
+	function printInfo()
+	{
 		$handler = $this->xmlhandler;
 		$handler->printInfo();
 	}
 
-	function getUsingFQDN() {
+	function getUsingFQDN()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getUsingFQDN();
 	}
 
-	function getNodes() {
+	function getNodes()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getNodes();
 	}
 
-	function getNode( $node ) {
+	function getNode( $node )
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getNode( $node );
 	}
 
-	function getCpus() {
+	function getCpus()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getCpus();
 	}
 
-	function getJobs() {
+	function getJobs()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getJobs();
 	}
 
-	function getJob( $job ) {
+	function getJob( $job )
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getJob( $job );
 	}
 
-	function getHeartbeat() {
+	function getHeartbeat()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->getHeartbeat();
 	}
 
-	function isJobmonRunning() {
+	function isJobmonRunning()
+	{
 		$handler = $this->xmlhandler;
 		return $handler->isJobmonRunning();
@@ -558,9 +572,10 @@
 }
 
-class TorqueXMLHandler {
-
+class TorqueXMLHandler
+{
 	var $clusters, $heartbeat, $nodes, $jobs, $clustername, $proc_cluster;
 
-	function TorqueXMLHandler( $clustername ) {
+	function TorqueXMLHandler( $clustername )
+	{
 		$jobs			= array();
 		$clusters 		= array();
@@ -573,34 +588,36 @@
 	}
 
-	function getUsingFQDN() {
-
+	function getUsingFQDN()
+	{
 		return $this->fqdn;
-	
-	
-	}
-
-	function getCpus() {
-
+	}
+
+	function getCpus()
+	{
 		$cpus = 0;
 
-		if( isset( $this->jobs ) && count( $this->jobs ) > 0 ) {
-
-			foreach( $this->jobs as $jobid=>$jobattrs ) {
-
-				$nodes = count( $jobattrs[nodes] );
-				$ppn = (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
-				$mycpus = $nodes * $ppn;
-
-				$cpus = $cpus + $mycpus;
-			}
-		}
-	}
-
-	function isJobmonRunning() {
-
+		if( isset( $this->jobs ) && count( $this->jobs ) > 0 )
+		{
+			foreach( $this->jobs as $jobid=>$jobattrs )
+			{
+				$nodes	= count( $jobattrs[nodes] );
+				$ppn	= (int) $jobattrs[ppn] ? $jobattrs[ppn] : 1;
+				$mycpus	= $nodes * $ppn;
+
+				$cpus	= $cpus + $mycpus;
+			}
+		}
+	}
+
+	function isJobmonRunning()
+	{
 		if (isset( $this->heartbeat['time'] ))
+		{
 			return 1;
+		}
 		else
+		{
 			return 0;
+		}
 	}
 
@@ -614,5 +631,6 @@
 
 		//$tdomain = explode( '.', $thostname );
-		// TODO: domain van hostname afhalen: parameter weghalen
+		//
+		// TODO?: extract domain from hostname or something?
 
 		if( $tdomain )
@@ -624,5 +642,4 @@
 			foreach( $nodes as $hostname => $nimage )
 			{
-	
 				if( substr( $hostname, $domain_len ) != $tdomain )
 				{
@@ -651,44 +668,37 @@
 	}
 
-	function startElement( $parser, $name, $attrs ) {
-
+	function startElement( $parser, $name, $attrs )
+	{
 		$jobs = $this->jobs;
 		$nodes = $this->nodes;
 
-		if ( $attrs[TN] ) {
-
+		if ( $attrs[TN] )
+		{
 			// Ignore dead metrics. Detect and mask failures.
 			if ( $attrs[TN] > $attrs[TMAX] * 4 )
+			{
 				return;
+			}
 		}
 
 		$jobid = null;
 
-		//printf( '%s=%s', $attrs[NAME], $attrs[VAL] );
-
-		//printf( "clustername = %s proc_cluster = %s\n", $this->clustername, $this->proc_cluster );
-
-		if( $name == 'CLUSTER' ) {
-
+		if( $name == 'CLUSTER' )
+		{
 			$this->proc_cluster = $attrs[NAME];
-			//printf( "Found cluster %s\n", $attrs[NAME] );
-			//print_r( $attrs );
-
-			//if( !isset( $clusters[$clustername] ) )
-			//	$clusters[$clustername] = array();
-
-		} else if( $name == 'HOST' and $this->proc_cluster == $this->clustername) {
-
+		}
+		else if( $name == 'HOST' and $this->proc_cluster == $this->clustername)
+		{
 			$hostname = $attrs[NAME];
 
-
 			$location = $attrs[LOCATION];
-			//printf( "Found node %s\n", $hostname );
 
 			if( !isset( $nodes[$hostname] ) )
+			{
 				$nodes[$hostname] = new NodeImage( $this->proc_cluster, $hostname );
-
-		} else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername ) {
-
+			}
+		}
+		else if( $name == 'METRIC' and strstr( $attrs[NAME], 'MONARCH' ) and $this->proc_cluster == $this->clustername )
+		{
 			if( strstr( $attrs[NAME], 'MONARCH-HEARTBEAT' ) )
 			{
@@ -730,7 +740,7 @@
 					}
 				}
-
-			} else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) ) {
-
+			}
+			else if( strstr( $attrs[NAME], 'MONARCH-OFFLINE' ) )
+			{
 				$fields		= explode( ' ', $attrs[VAL] );
 
@@ -766,15 +776,18 @@
 					}
 				}
-
-			} else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) ) {
-
+			}
+			else if( strstr( $attrs[NAME], 'MONARCH-JOB' ) )
+			{
 				sscanf( $attrs[NAME], 'MONARCH-JOB-%d-%d', $jobid, $monincr );
 
 				if( !isset( $jobs[$jobid] ) )
+				{
 					$jobs[$jobid] = array();
+				}
 
 				$fields = explode( ' ', $attrs[VAL] );
 
-				foreach( $fields as $f ) {
+				foreach( $fields as $f )
+				{
 					$togavalues = explode( '=', $f );
 
@@ -782,35 +795,37 @@
 					$togavalue = $togavalues[1];
 
-					if( $toganame == 'nodes' ) {
-
-						if( $jobs[$jobid][status] == 'R' ) {
-						
+					if( $toganame == 'nodes' )
+					{
+						if( $jobs[$jobid][status] == 'R' )
+						{
 							if( !isset( $jobs[$jobid][$toganame] ) )
+							{
 								$jobs[$jobid][$toganame] = array();
+							}
 
 							$mynodes = explode( ';', $togavalue );
 
-							//print_r($mynodes);
-
-							foreach( $mynodes as $node ) {
-
-								if( !in_array( $node, $jobs[$jobid][$toganame] ) ) {
+							foreach( $mynodes as $node )
+							{
+								if( !in_array( $node, $jobs[$jobid][$toganame] ) )
+								{
 									$jobs[$jobid][$toganame][] = $node;
 								}
 							}
 
-						} else if( $jobs[$jobid][status] == 'Q' ) {
-
+						}
+						else if( $jobs[$jobid][status] == 'Q' )
+						{
 							$jobs[$jobid][$toganame] = $togavalue;
 						}
-						
-					} else {
-
+					}
+					else
+					{
 						$jobs[$jobid][$toganame] = $togavalue;
 					}
 				}
 
-				if( isset( $jobs[$jobid][nodes] ) ) {
-			
+				if( isset( $jobs[$jobid][nodes] ) )
+				{
 					$nr_nodes = count( $jobs[$jobid][nodes] );
 		
@@ -860,14 +875,23 @@
 
 							if( !isset( $nodes[$host] ) )
+							{
 								$my_node = new NodeImage( $this->proc_cluster, $host );
+							}
 							else
+							{
 								$my_node = $nodes[$host];
+							}
 
 							if( !$my_node->hasJob( $jobid ) )
-
+							{
 								if( isset( $jobs[$jobid][ppn] ) )
+								{
 									$my_node->addJob( $jobid, ((int) $jobs[$jobid][ppn]) );
+								}
 								else
+								{
 									$my_node->addJob( $jobid, 1 );
+								}
+							}
 
 							$nodes[$host] = $my_node;
@@ -877,12 +901,10 @@
 			}
 		}
-		$this->jobs = $jobs;
-		//print_r( $nodes );
-		$this->nodes = $nodes;
-		//print_r( $this->nodes );
-	}
-
-	function stopElement( $parser, $name ) {
-
+		$this->jobs	= $jobs;
+		$this->nodes	= $nodes;
+	}
+
+	function stopElement( $parser, $name )
+	{
 		$nodes	= $this->nodes;
 
@@ -893,5 +915,4 @@
 				foreach( $this->down_nodes as $reported => $dnodes )
 				{
-
 					if( $reported == $this->heartbeat['time'] )
 					{
@@ -946,18 +967,18 @@
 	}
 
-	function printInfo() {
-
+	function printInfo()
+	{
 		$jobs = &$this->jobs;
 
 		printf( "---jobs---\n" );
 
-		foreach( $jobs as $jobid => $job ) {
-
+		foreach( $jobs as $jobid => $job )
+		{
 			printf( "job %s\n", $jobid );
 
-			if( isset( $job[nodes] ) ) {
-
-				foreach( $job[nodes] as $node ) {
-
+			if( isset( $job[nodes] ) )
+			{
+				foreach( $job[nodes] as $node )
+				{
 					$mynode = $this->nodes[$node];
 					$hostname = $mynode->getHostname();
@@ -965,5 +986,4 @@
 
 					printf( "\t- node %s\tlocation %s\n", $hostname, $location );
-					//$this->nodes[$hostname]->setLocation( "hier draait job ".$jobid );
 				}
 			}
@@ -974,6 +994,6 @@
 		$nodes = &$this->nodes;
 
-		foreach( $nodes as $node ) {
-
+		foreach( $nodes as $node )
+		{
 			$hostname = $node->getHostname();
 			$location = $node->getLocation();
@@ -983,117 +1003,131 @@
 	}
 
-	function getNodes() {
-		//print_r( $this->nodes );
+	function getNodes()
+	{
 		return $this->nodes;
 	}
 
-	function getNode( $node ) {
-
+	function getNode( $node )
+	{
 		$nodes = &$this->nodes;
+
 		if( isset( $nodes[$node] ) )
+		{
 			return $nodes[$node];
+		}
 		else
+		{
 			return NULL;
-	}
-
-	function getJobs() {
+		}
+	}
+
+	function getJobs()
+	{
 		return $this->jobs;
 	}
 
-	function getJob( $job ) {
-
+	function getJob( $job )
+	{
 		$jobs = &$this->jobs;
+
 		if( isset( $jobs[$job] ) )
+		{
 			return $jobs[$job];
+		}
 		else
+		{
 			return NULL;
-	}
-
-	function getHeartbeat() {
+		}
+	}
+
+	function getHeartbeat()
+	{
 		return $this->heartbeat['time'];
 	}
 }
 
-class NodeImage {
-
+class NodeImage
+{
 	var $image, $x, $y, $hostname, $jobs, $tasks, $showinfo;
 
-	function NodeImage( $cluster, $hostname ) {
-
+	function NodeImage( $cluster, $hostname )
+	{
 		global $SMALL_CLUSTERIMAGE_NODEWIDTH;
 
-		$this->jobs = array();
-		//$this->image = $image;
-		//$this->x = $x;
-		//$this->y = $y;
-		$this->tasks = 0;
-		$this->hostname = $hostname;
-		$this->cpus = $this->determineCpus();
-		$this->clustername = $cluster;
-		$this->showinfo = 1;
-		$this->size = $SMALL_CLUSTERIMAGE_NODEWIDTH;
-		$this->down = 0;
-		$this->offline = 0;
-	}
-
-	function addJob( $jobid, $cpus ) {
-		$jobs = &$this->jobs;
-
-		$jobs[] = $jobid;
-		$this->jobs = $jobs;
+		$this->jobs		= array();
+		$this->tasks		= 0;
+		$this->hostname		= $hostname;
+		$this->cpus		= $this->determineCpus();
+		$this->clustername	= $cluster;
+		$this->showinfo		= 1;
+		$this->size		= $SMALL_CLUSTERIMAGE_NODEWIDTH;
+		$this->down		= 0;
+		$this->offline		= 0;
+	}
+
+	function addJob( $jobid, $cpus )
+	{
+		$jobs		= &$this->jobs;
+		$jobs[]		= $jobid;
+		$this->jobs	= $jobs;
 
 		$this->addTask( $cpus );
 	}
 
-	function hasJob( $jobid ) {
-
+	function hasJob( $jobid )
+	{
 		$jobfound = 0;
 
 		if( count( $this->jobs ) > 0 )
+		{
 			foreach( $this->jobs as $job )
-
+			{
 				if( $job == $jobid )
+				{
 					$jobfound = 1;
+				}
+			}
+		}
 
 		return $jobfound;
 	}
 
-	function addTask( $cpus ) {
-
+	function addTask( $cpus )
+	{
 		$this->tasks = $this->tasks + $cpus;
 	}
 
-	function setDown( $down ) {
-
+	function setDown( $down )
+	{
 		$this->down = $down;
 	}
 
-	function isDown() {
-
+	function isDown()
+	{
 		return $this->down;
 	}
-	function setOffline( $offline ) {
-
+	function setOffline( $offline )
+	{
 		$this->offline = $offline;
 	}
 
-	function isOffline() {
-
+	function isOffline()
+	{
 		return $this->offline;
 	}
 
-	function setImage( $image ) {
-
+	function setImage( $image )
+	{
 		$this->image = $image;
 	}
 
-	function setCoords( $x, $y ) {
-
+	function setCoords( $x, $y )
+	{
 		$this->x = $x;
 		$this->y = $y;
 	}
 
-	function getImagemapArea() {
-
+	function getImagemapArea()
+	{
 		$area_topleft		= $this->x . "," . $this->y;
 		$area_bottomright	= ($this->x + $this->size) . "," . ($this->y + $this->size);
@@ -1123,6 +1157,6 @@
 	}
 
-	function colorHex( $color ) {
-	
+	function colorHex( $color )
+	{
 		$my_color = imageColorAllocate( $this->image, hexdec( substr( $color, 0, 2 )), hexdec( substr( $color, 2, 2 )), hexdec( substr( $color, 4, 2 )) );
 
@@ -1130,26 +1164,31 @@
 	}
 
-	function setLoad( $load ) {
+	function setLoad( $load )
+	{
 		$this->load = $load;
 	}
 
-	function setHostname( $hostname ) {
+	function setHostname( $hostname )
+	{
 		$this->hostname = $hostname;
 	}
 
-	function getHostname() {
+	function getHostname()
+	{
 		return $this->hostname;
 	}
 
-	function getJobs() {
+	function getJobs()
+	{
 		return $this->jobs;
 	}
 
-	function setShowinfo( $showinfo ) {
+	function setShowinfo( $showinfo )
+	{
 		$this->showinfo = $showinfo;
 	}
 
-	function drawSmall() {
-
+	function drawSmall()
+	{
 		global $SMALL_CLUSTERIMAGE_NODEWIDTH;
 
@@ -1159,6 +1198,6 @@
 	}
 
-	function drawBig() {
-
+	function drawBig()
+	{
 		global $BIG_CLUSTERIMAGE_NODEWIDTH;
 
@@ -1168,6 +1207,6 @@
 	}
 
-	function draw() {
-
+	function draw()
+	{
 		global $JOB_NODE_MARKING, $NODE_DOWN_MARKING, $NODE_OFFLINE_MARKING;
 
@@ -1177,14 +1216,14 @@
 		imageFilledRectangle( $this->image, $this->x, $this->y, $this->x+($size), $this->y+($size), $black_color );
 
-		if( $this->showinfo) {
-		
+		if( $this->showinfo)
+		{
 			$this->load = $this->determineLoad();
 
-			if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) ) {
+			if( !isset( $this->image ) or !isset( $this->x ) or !isset( $this->y ) )
+			{
 				printf( "aborting\n" );
 				printf( "x %d y %d load %f\n", $this->x, $this->y, $load );
 				return;
 			}
-
 
 			// Convert Ganglias Hexadecimal load color to a Decimal one
@@ -1205,31 +1244,33 @@
 				imageString( $this->image, 1, $this->x+(($size/2)-1), $this->y+(($size/2)-4), $JOB_NODE_MARKING, $black_color );
 			}
-
-		} else {
-
+		}
+		else
+		{
 			// White
 			$usecolor = imageColorAllocate( $this->image, 255, 255, 255 );
 			imageFilledRectangle( $this->image, $this->x+1, $this->y+1, $this->x+($size-1), $this->y+($size-1), $usecolor );
 		}
-
-
-	}
-
-	function determineCpus() {
-
+	}
+
+	function determineCpus()
+	{
 		global $metrics;
 
 		$cpus = $metrics[$this->hostname][cpu_num][VAL];
-		if (!$cpus) $cpus=1;
+
+		if (!$cpus)
+		{
+			$cpus=1;
+		}
 
 		return $cpus;
 	}
 
-	function determineLoad() {
-
+	function determineLoad()
+	{
 		global $metrics;
 
-		$load_one = $metrics[$this->hostname][load_one][VAL];
-		$load = ((float) $load_one)/$this->cpus;
+		$load_one	= $metrics[$this->hostname][load_one][VAL];
+		$load		= ((float) $load_one)/$this->cpus;
 
 		return $load;
@@ -1237,13 +1278,11 @@
 }
 
-class ClusterImage {
-
+class ClusterImage
+{
 	var $dataget, $image, $clustername;
 	var $filtername, $filters;
 
-	//function ClusterImage( $clustername ) {
-	function ClusterImage( $data, $clustername ) {
-
-		//$this->dataget		= $dataget;
+	function ClusterImage( $data, $clustername )
+	{
 		$this->dataget		= new DataGatherer( $clustername );
 		$this->data		= $data;
@@ -1256,62 +1295,67 @@
 	}
 
-	function getWidth() {
+	function getWidth()
+	{
 		return $this->width;
 	}
-	function getHeight() {
+	function getHeight()
+	{
 		return $this->height;
 	}
-
-	function setSmall() {
+	function setSmall()
+	{
 		$this->size	= 's';
 	}
-
-	function setBig() {
+	function setBig()
+	{
 		$this->size	= 'b';
 	}
-
-	function setNoimage() {
+	function setNoimage()
+	{
 		$this->output	= 0;
 	}
-
-	function isSmall() {
+	function isSmall()
+	{
 		return ($this->size == 's');
 	}
-
-	function isBig() {
+	function isBig()
+	{
 		return ($this->size == 'b');
 	}
-
-	function setFilter( $filtername, $filtervalue ) {
-
+	function setFilter( $filtername, $filtervalue )
+	{
 		$this->filters[$filtername] = $filtervalue;
 	}
 
-	function filterNodes( $jobs, $nodes ) {
-
+	function filterNodes( $jobs, $nodes )
+	{
 		$filtered_nodes = array();
 
-		foreach( $nodes as $node ) {
-
+		foreach( $nodes as $node )
+		{
 			$hostname = $node->getHostname();
 
 			$addhost = 1;
 
-			if( count( $this->filters ) > 0 ) {
-
+			if( count( $this->filters ) > 0 )
+			{
 				$mynjobs = $node->getJobs();
 
-				if( count( $mynjobs ) > 0 ) {
-
-					foreach( $mynjobs as $myjob ) {
-
-						foreach( $this->filters as $filtername => $filtervalue ) {
-
-							if( $filtername!=null && $filtername!='' ) {
-
-								if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) ) {
+				if( count( $mynjobs ) > 0 )
+				{
+					foreach( $mynjobs as $myjob )
+					{
+						foreach( $this->filters as $filtername => $filtervalue )
+						{
+							if( $filtername!=null && $filtername!='' )
+							{
+								if( $filtername == 'jobid' && !$node->hasJob( $filtervalue) )
+								{
 									$addhost = 0;
-								} else if( $filtername != 'jobid' ) {
-									if( $jobs[$myjob][$filtername] != $filtervalue ) {
+								}
+								else if( $filtername != 'jobid' )
+								{
+									if( $jobs[$myjob][$filtername] != $filtervalue )
+									{
 										$addhost = 0;
 									}
@@ -1320,10 +1364,15 @@
 						}
 					}
-				} else
+				}
+				else
+				{
 					$addhost = 0;
+				}
 			}
 
 			if( $addhost )
+			{
 				$filtered_nodes[] = $hostname;
+			}
 		}
 
@@ -1331,6 +1380,6 @@
 	}
 
-	function draw() {
-
+	function draw()
+	{
 		global $SMALL_CLUSTERIMAGE_MAXWIDTH, $SMALL_CLUSTERIMAGE_NODEWIDTH;
 		global $BIG_CLUSTERIMAGE_MAXWIDTH, $BIG_CLUSTERIMAGE_NODEWIDTH;
@@ -1348,42 +1397,44 @@
 		}
 
-		//global $SORTBY_HOSTNAME, $SORT_ORDER;
-		//global $SORT_XLABEL, $SORT_YLABEL;
-	
-		//printf( "SORTBY_HOSTNAME %s SORT_YLABEL %s\n", $SORTBY_HOSTNAME, $SORT_YLABEL );
-
 		$mydatag = $this->dataget;
 		$mydatag->parseXML( $this->data );
 
-		if( $this->isSmall() ) {
-			$max_width = $SMALL_CLUSTERIMAGE_MAXWIDTH;
-			$node_width = $SMALL_CLUSTERIMAGE_NODEWIDTH;
-		} else if( $this->isBig() ) {
-			$max_width = $BIG_CLUSTERIMAGE_MAXWIDTH;
-			$node_width = $BIG_CLUSTERIMAGE_NODEWIDTH;
-		}
-
-		$nodes = $mydatag->getNodes();
-		$nodes_hosts = array_keys( $nodes );
-
-		$nodes_nr = count( $nodes );
-
-		$nodes_size = $nodes_nr*$node_width;
-		$node_rows = 0;
-
-		if( $nodes_size > $max_width ) {
+		if( $this->isSmall() )
+		{
+			$max_width	= $SMALL_CLUSTERIMAGE_MAXWIDTH;
+			$node_width	= $SMALL_CLUSTERIMAGE_NODEWIDTH;
+		}
+		else if( $this->isBig() )
+		{
+			$max_width	= $BIG_CLUSTERIMAGE_MAXWIDTH;
+			$node_width	= $BIG_CLUSTERIMAGE_NODEWIDTH;
+		}
+
+		$nodes		= $mydatag->getNodes();
+		$nodes_hosts	= array_keys( $nodes );
+
+		$nodes_nr	= count( $nodes );
+
+		$nodes_size	= $nodes_nr*$node_width;
+		$node_rows	= 0;
+
+		if( $nodes_size > $max_width )
+		{
 			$nodes_per_row = ( (int) ($max_width/$node_width) );
-		} else {
+		}
+		else
+		{
 			$nodes_per_row = $nodes_size;
 			$node_rows = 1;
 		}
 
-		if( $nodes_per_row < $nodes_nr ) {
+		if( $nodes_per_row < $nodes_nr )
+		{
 			$node_rows = ( (int) ($nodes_nr/$nodes_per_row) );
 			$node_rest = fmod( $nodes_nr, $nodes_per_row );
-			//printf( "nodesnr %d noderest %f\n", $nodes_nr, $node_rest );
-			if( $node_rest > 0 ) {
+
+			if( $node_rest > 0 )
+			{
 				$node_rows++;
-				//printf( "noderows %d\n", $node_rows );
 			}
 		}
@@ -1399,20 +1450,6 @@
 		$this->height	= ($y_offset + (($node_rows*$node_width)+1) );
 
-		//$image = imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) );
-		//$colorwhite = imageColorAllocate( $image, 255, 255, 255 );
-		//imageFill( $image, 0, 0, $colorwhite );
-
-		//if( $this->isSmall() ) {
-
-		//	$colorblue	= imageColorAllocate( $image, 0, 0, 255 );
-
-		//	imageString( $image, $font, 2, 2, "Monarch Joblist - cluster: ".$this->clustername, $colorblue );
-		//}
-
 		$jobs = $mydatag->getJobs();
-		//printf("filtername = %s\n", $filtername );
 		$filtered_nodes = $this->filterNodes( $jobs, $nodes );
-
-		//print_r($filtered_nodes);
 
 		if( $SORTBY_HOSTNAME != "" )
@@ -1622,11 +1659,4 @@
 
 			}
-			//$x_offset	= ($fontwidth * 3) + (5 * $fontspaceing);
-
-			//printf( "xmin %s xmax %s\n", $x_min, $x_max );
-			//printf( "ymin %s ymax %s\n", $y_min, $y_max );
-
-			// werkt
-			//print_r( $nodes );
 
 			$image_width	= $x_offset + ($node_width * ($x_max-$x_min+2));
@@ -1635,12 +1665,9 @@
 			{
 				$image_width	= $max_width;
-			} else if( $this->isBig() ) 
+			}
+			else if( $this->isBig() ) 
 			{
 				$image_width	= ($image_width < $max_width) ? $image_width : $max_width;
 			}
-			//else if( $this->isSmall() )
-			//{
-			//	$image_width	= $this->width;
-			//}
 			$image_height	= $y_offset + ($node_width * ($y_max-$y_min+2));
 
@@ -1653,6 +1680,6 @@
 			imageFill( $image, 0, 0, $colorwhite );
 
-			if( $this->isSmall() ) {
-
+			if( $this->isSmall() )
+			{
 				// Draw a fancy little header text to explain what it is
 				//
@@ -1779,10 +1806,12 @@
 						$nodes[$cur_node]->setImage( $image );
 
-						//print_r( $nodes[$cur_node] );
-
 						if( $this->isSmall() )
+						{
 							$nodes[$cur_node]->drawSmall();
+						}
 						else if( $this->isBig() )
+						{
 							$nodes[$cur_node]->drawBig();
+						}
 
 						$cur_node++;
@@ -1794,7 +1823,10 @@
 		else
 		{
-			if( $this->isSmall() ) {
+			if( $this->isSmall() )
+			{
 				$image		= imageCreateTrueColor( $max_width, ($y_offset + (($node_rows*$node_width)+1) ) );
-			} else if( $this->isBig() ) {
+			}
+			else if( $this->isBig() )
+			{
 				$image_width	= ($node_width * $nodes_nr) + 2;
 				$image_width	= ($image_width < $max_width) ? $image_width : $max_width;
@@ -1805,6 +1837,6 @@
 			imageFill( $image, 0, 0, $colorwhite );
 
-			if( $this->isSmall() ) {
-
+			if( $this->isSmall() )
+			{
 				$colorblue	= imageColorAllocate( $image, 0, 0, 255 );
 
@@ -1812,8 +1844,8 @@
 			}
 
-			for( $n = 0; $n < $node_rows; $n++ ) {
-			
-				for( $m = 0; $m < $nodes_per_row; $m++ ) {
-			
+			for( $n = 0; $n < $node_rows; $n++ )
+			{
+				for( $m = 0; $m < $nodes_per_row; $m++ )
+				{
 					$x = ($m * $node_width);
 					$y = $y_offset + ($n * $node_width);
@@ -1822,6 +1854,6 @@
 					$host = $nodes_hosts[$cur_node];
 
-					if( isset( $nodes[$host] ) ) {
-
+					if( isset( $nodes[$host] ) )
+					{
 						$nodes[$host]->setCoords( $x, $y );
 						$nodes[$host]->setImage( $image );
@@ -1833,7 +1865,11 @@
 
 						if( $this->isSmall() )
+						{
 							$nodes[$host]->drawSmall();
+						}
 						else if( $this->isBig() )
+						{
 							$nodes[$host]->drawBig();
+						}
 					}
 				}
@@ -1843,5 +1879,6 @@
 		$this->nodes	= &$nodes;
 
-		if ($this->output) {
+		if ($this->output)
+		{
 			header( 'Content-type: image/png' );
 			imagePNG( $image );
@@ -1850,10 +1887,10 @@
 	}
 
-	function getImagemapArea() {
-
+	function getImagemapArea()
+	{
 		$clusterimage_map	= "";
 
-		foreach( $this->nodes as $hostname => $node ) {
-
+		foreach( $this->nodes as $hostname => $node )
+		{
 			$node_map		= $node->getImagemapArea();
 			$clusterimage_map	.= $node_map;
@@ -1864,7 +1901,8 @@
 }
 
-class EmptyImage {
-
-	function draw() {
+class EmptyImage
+{
+	function draw()
+	{
 		$image		= imageCreateTrueColor( 1, 1 );
 		$colorwhite	= imageColorAllocate( $image, 255, 255, 255 );
@@ -1877,11 +1915,11 @@
 }
 
-class HostImage {
-
+class HostImage
+{
 	var $data_gather, $cluster, $host, $node, $image;
 	var $headerstrlen;
 
-	function HostImage( $data_gather, $cluster, $host ) {
-
+	function HostImage( $data_gather, $cluster, $host )
+	{
 		$this->data_gather 	= $data_gather;
 		$this->cluster		= $cluster;
@@ -1901,11 +1939,11 @@
 	}
 
-	function drawJobs() {
-
+	function drawJobs()
+	{
 		$dg                     = &$this->data_gather;
 		$colorblack		= imageColorAllocate( $this->image, 0, 0, 0 );
 
-		for( $n = 0; $n < count( $this->njobs ); $n++ ) {
-
+		for( $n = 0; $n < count( $this->njobs ); $n++ )
+		{
 			$jobid			= $this->njobs[$n];
 			$jobinfo		= $dg->getJob( $jobid );
@@ -1914,18 +1952,25 @@
 			imageString( $this->image, $this->font, $xoffset, $this->y_offset, strval( $jobid ), $colorblack );
 
-			foreach( $this->headerstrlen as $headername => $headerlen ) {
-
-				if( $headername == 'nodes' ) {
+			foreach( $this->headerstrlen as $headername => $headerlen )
+			{
+				if( $headername == 'nodes' )
+				{
 					$attrval	= strval( count( $jobinfo[nodes] ) );
-				} else if( $headername == 'cpus' ) {
-
+				}
+				else if( $headername == 'cpus' )
+				{
 					if( !isset( $jobinfo[ppn] ) )
+					{
 						$jobinfo[ppn] = 1;
+					}
 
 					$attrval	= strval( count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] ) );
-
-				} else if( $headername == 'runningtime' ) {
+				}
+				else if( $headername == 'runningtime' )
+				{
 					$attrval	= makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
-				} else {
+				}
+				else
+				{
 					$attrval	= strval( $jobinfo[$headername] );
 				}
@@ -1934,5 +1979,4 @@
 		
 				$xoffset	= $xoffset + ($this->fontwidth * ( $headerlen + 1 ) );
-
 			}
 			
@@ -1941,90 +1985,113 @@
 	}
 
-	function drawHeader() {
-
+	function drawHeader()
+	{
 		$dg                     = &$this->data_gather;
 
-		for( $n = 0; $n < count( $this->njobs ); $n++ ) {
-
+		for( $n = 0; $n < count( $this->njobs ); $n++ )
+		{
 			$jobid			= $this->njobs[$n];
 			$jobinfo		= $dg->getJob( $jobid );
 
 			if( !isset( $this->headerstrlen[id] ) )
+			{
 				$this->headerstrlen[id]	= strlen( strval( $jobid ) );
-			else
-				if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] )
-					$this->headerstrlen[id]	= strlen( strval( $jobid ) );
+			}
+			else if( strlen( strval( $jobid ) ) > $this->headerstrlen[id] )
+			{
+				$this->headerstrlen[id]	= strlen( strval( $jobid ) );
+			}
 
 			if( !isset( $this->headerstrlen[owner] ) )
+			{
 				$this->headerstrlen[owner]	= strlen( strval( $jobinfo[owner] ) );
-			else
-				if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] )
-					$this->headerstrlen[owner]	= strlen( strval( $jobinfo[owner] ) );
+			}
+			else if( strlen( strval( $jobinfo[owner] ) ) > $this->headerstrlen[owner] )
+			{
+				$this->headerstrlen[owner]	= strlen( strval( $jobinfo[owner] ) );
+			}
 
 			if( !isset( $this->headerstrlen[queue] ) )
+			{
 				$this->headerstrlen[queue]	= strlen( strval( $jobinfo[queue] ) );
-			else
-				if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] )
-					$this->headerstrlen[queue]	= strlen( strval( $jobinfo[queue] ) );
+			}
+			else if( strlen( strval( $jobinfo[queue] ) ) > $this->headerstrlen[queue] )
+			{
+				$this->headerstrlen[queue]	= strlen( strval( $jobinfo[queue] ) );
+			}
 
 			if( !isset( $jobinfo[ppn] ) )
+			{
 				$jobinfo[ppn] = 1;
+			}
 
 			$cpus			= count( $jobinfo[nodes] ) * intval( $jobinfo[ppn] );
 
 			if( !isset( $this->headerstrlen[cpus] ) )
+			{
 				$this->headerstrlen[cpus]	= strlen( strval( $cpus ) );
-			else
-				if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] )
-					$this->headerstrlen[cpus]	= strlen( strval( $cpus ) );
+			}
+			else if( strlen( strval( $cpus ) ) > $this->headerstrlen[cpus] )
+			{
+				$this->headerstrlen[cpus]	= strlen( strval( $cpus ) );
+			}
 
 			$nodes			= count( $jobinfo[nodes] );
 
 			if( !isset( $this->headerstrlen[nodes] ) )
+			{
 				$this->headerstrlen[nodes]	= strlen( strval( $nodes ) );
-			else
-				if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] )
-					$this->headerstrlen[nodes]	= strlen( strval( $nodes ) );
+			}
+			else if( strlen( strval( $nodes) ) > $this->headerstrlen[nodes] )
+			{
+				$this->headerstrlen[nodes]	= strlen( strval( $nodes ) );
+			}
 
 			$runningtime		= makeTime( intval( $jobinfo[reported] ) - intval( $jobinfo[start_timestamp] ) );
 
 			if( !isset( $this->headerstrlen[runningtime] ) )
+			{
 				$this->headerstrlen[runningtime]	= strlen( strval( $runningtime) );
-			else
-				if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] )
-					$this->headerstrlen[runningtime]	= strlen( strval( $runningtime) );
+			}
+			else if( strlen( strval( $runningtime) ) > $this->headerstrlen[runningtime] )
+			{
+				$this->headerstrlen[runningtime]	= strlen( strval( $runningtime) );
+			}
 
 			if( !isset( $this->headerstrlen[name] ) )
+			{
 				$this->headerstrlen[name]	= strlen( strval( $jobinfo[name] ) );
-			else
-				if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] )
-					$this->headerstrlen[name]	= strlen( strval( $jobinfo[name] ) );
-
+			}
+			else if( strlen( strval( $jobinfo[name] ) ) > $this->headerstrlen[name] )
+			{
+				$this->headerstrlen[name]	= strlen( strval( $jobinfo[name] ) );
+			}
 		}
 
 		$xoffset	= 5;
 
-		foreach( $this->headerstrlen as $headername => $headerlen ) {
-
+		foreach( $this->headerstrlen as $headername => $headerlen )
+		{
 			$colorgreen	= imageColorAllocate( $this->image, 0, 200, 0 );
 
 			if( $headerlen < strlen( $headername ) )
+			{
 				$this->headerstrlen[$headername]	= strlen( $headername );
+			}
 
 			imageString( $this->image, $this->font, $xoffset, $this->y_offset, ucfirst( $headername ), $colorgreen );
 
 			$xoffset	= $xoffset + ($this->fontwidth * ( $this->headerstrlen[$headername] + 1 ) );
-
 		}
 		$this->newLineOffset();
 	}
 
-	function newLineOffset() {
-
+	function newLineOffset()
+	{
 		$this->y_offset		= $this->y_offset + $this->fontheight + $this->fontspaceing;
 	}
 
-	function draw() {
-
+	function draw()
+	{
 		$xlen		= 450;
 		$ylen		= ( count( $this->njobs ) * ( $this->fontheight + $this->fontspaceing ) ) + (3 * $this->fontheight);
@@ -2088,5 +2155,4 @@
 	global $x_present, $y_present;
 
-	//printf("ppoep = %s\n", $skan_str);
 	$a_node		= $a;
 	$b_node		= $b;
@@ -2228,19 +2294,22 @@
 	}
 }
-function makeTime( $time ) {
-
+function makeTime( $time )
+{
         $days = intval( $time / 86400 );
         $time = ($days>0) ? $time % ($days * 86400) : $time;
 
-        //printf( "time = %s, days = %s\n", $time, $days );
-
         $date_str = '';
         $day_str = '';
 
-        if( $days > 0 ) {
+        if( $days > 0 )
+	{
                 if( $days > 1 )
+		{
                         $day_str .= $days . ' days';
+		}
                 else
+		{
                         $day_str .= $days . ' day';
+		}
         }
 
@@ -2248,6 +2317,6 @@
         $time = $hours ? $time % ($hours * 3600) : $time;
 
-        //printf( "time = %s, days = %s, hours = %s\n", $time, $days, $hours );
-        if( $hours > 0 ) {
+        if( $hours > 0 )
+	{
                 $date_str .= $hours . ':';
                 $date_unit = 'hours'; 
@@ -2257,14 +2326,21 @@
         $seconds = $minutes ? $time % ($minutes * 60) : $time;
 
-        if( $minutes > 0 ) {
-
+        if( $minutes > 0 )
+	{
                 if( $minutes >= 10 )
+		{
                         $date_str .= $minutes . ':';
+		}
                 else
+		{
                         $date_str .= '0' . $minutes . ':';
+		}
 
                 $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
-        } else {
-                if($hours > 0 ) {
+        }
+	else
+	{
+                if($hours > 0 )
+		{
                         $date_str .= '00:';
                         $date_unit = (!isset($date_unit)) ? 'minutes' : $date_unit;
@@ -2272,26 +2348,33 @@
         }
 
-
         $date_unit = (!isset($date_unit)) ? 'seconds' : $date_unit;
 
-        if( $seconds > 0 ) {
-
+        if( $seconds > 0 )
+	{
                 if( $seconds >= 10 )
+		{
                         $date_str .= $seconds . ' ' . $date_unit;
+		}
                 else
+		{
                         $date_str .= '0' . $seconds . ' ' . $date_unit;
-
-        } else if ( $hours > 0 or $minutes > 0 )
-
+		}
+        }
+	else if ( $hours > 0 or $minutes > 0 )
+	{
                 $date_str .= '00 ' . $date_unit;
-
-        if( $days > 0) {
-
+	}
+
+        if( $days > 0)
+	{
                 if( $hours > 0 or $minutes > 0 or $seconds > 0 )
+		{
                         $date_str = $day_str . ' - ' . $date_str;
+		}
                 else
+		{
                         $date_str = $day_str;
+		}
         }
-
         return $date_str;
 }
