Index: /branches/0.4/web/addons/job_monarch/overview.php
===================================================================
--- /branches/0.4/web/addons/job_monarch/overview.php	(revision 731)
+++ /branches/0.4/web/addons/job_monarch/overview.php	(revision 732)
@@ -4,5 +4,5 @@
  * This file is part of Jobmonarch
  *
- * Copyright (C) 2006  Ramon Bastiaans
+ * Copyright (C) 2006-2013  Ramon Bastiaans
  *
  * Jobmonarch is free software; you can redistribute it and/or modify
@@ -34,15 +34,15 @@
 }
 
-$ds        = new DataSource();
-$myxml_data    = $ds->getData();
-
-$data_gatherer    = new DataGatherer( $clustername );
+$ds         = new DataSource();
+$myxml_data = $ds->getData();
+
+$data_gatherer = new DataGatherer( $clustername );
 $data_gatherer->parseXML( $myxml_data );
 
-$heartbeat    = $data_gatherer->getHeartbeat();
-$jobs        = $data_gatherer->getJobs();
-$gnodes        = $data_gatherer->getNodes();
-$cpus        = $data_gatherer->getCpus();
-$use_fqdn    = $data_gatherer->getUsingFQDN();
+$heartbeat = $data_gatherer->getHeartbeat();
+$jobs      = $data_gatherer->getJobs();
+$gnodes    = $data_gatherer->getNodes();
+$cpus      = $data_gatherer->getCpus();
+$use_fqdn  = $data_gatherer->getUsingFQDN();
 
 function setupFilterSettings() 
@@ -65,7 +65,7 @@
 
     unset( $_SESSION["data"] );
-    $_SESSION["data"]    = &$myxml_data;
-
-    $ic            = new ClusterImage( $myxml_data, $clustername );
+    $_SESSION["data"] = &$myxml_data;
+
+    $ic = new ClusterImage( $myxml_data, $clustername );
 
     $ic->setBig();
@@ -101,28 +101,28 @@
 function timeToEpoch( $time ) 
 {
-    $time_fields    = explode( ':', $time );
+    $time_fields = explode( ':', $time );
 
     if( count( $time_fields ) == 3 ) 
     {
-        $hours        = $time_fields[0];
-        $minutes    = $time_fields[1];
-        $seconds    = $time_fields[2];
+        $hours   = $time_fields[0];
+        $minutes = $time_fields[1];
+        $seconds = $time_fields[2];
 
     } 
     else if( count( $time_fields ) == 2 ) 
     {
-        $hours         = 0;
-        $minutes     = $time_fields[0];
-        $seconds     = $time_fields[1];
+        $hours   = 0;
+        $minutes = $time_fields[0];
+        $seconds = $time_fields[1];
 
     } 
     else if( count( $time_fields ) == 1 ) 
     {
-        $hours         = 0;
-        $minutes     = 0;
-        $seconds     = $time_fields[0];
-    }
-
-    $myepoch     = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
+        $hours   = 0;
+        $minutes = 0;
+        $seconds = $time_fields[0];
+    }
+
+    $myepoch = intval( $seconds + (intval( $minutes * 60 )) + (intval( $hours * 3600 )) );
 
     return $myepoch;
@@ -149,15 +149,15 @@
     $min_diff = 50;
 
-    $c1r     = hexDec( colorRed( $first ) );
-    $c1g     = hexDec( colorGreen( $first ) );
-    $c1b     = hexDec( colorBlue( $first ) );
-
-    $c2r     = hexDec( colorRed( $second ) );
-    $c2g     = hexDec( colorGreen( $second ) );
-    $c2b     = hexDec( colorBlue( $second ) );
-
-    $rdiff     = ($c1r >= $c2r) ? $c1r - $c2r : $c2r - $c1r;
-    $gdiff     = ($c1g >= $c2g) ? $c1g - $c2g : $c2g - $c1g;
-    $bdiff     = ($c1b >= $c2b) ? $c1b - $c2b : $c2b - $c1b;
+    $c1r   = hexDec( colorRed( $first ) );
+    $c1g   = hexDec( colorGreen( $first ) );
+    $c1b   = hexDec( colorBlue( $first ) );
+
+    $c2r   = hexDec( colorRed( $second ) );
+    $c2g   = hexDec( colorGreen( $second ) );
+    $c2b   = hexDec( 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 ) 
@@ -175,25 +175,25 @@
 {
     // White (000000) would be invisible
-    $start        = "004E00";
+    $start       = "004E00";
     
-    $start_red    = colorRed( $start );
-    $start_green    = colorGreen( $start );
-    $start_blue    = colorBlue( $start );
+    $start_red   = colorRed( $start );
+    $start_green = colorGreen( $start );
+    $start_blue  = colorBlue( $start );
     
-    $end        = "FFFFFF";
-
-    $end_red    = colorRed( $end );
-    $end_green    = colorGreen( $end );
+    $end         = "FFFFFF";
+
+    $end_red     = colorRed( $end );
+    $end_green   = colorGreen( $end );
     $end_blue    = colorBlue( $end );
 
-    $change_color     = TRUE;
+    $change_color= TRUE;
 
     while( $change_color ) 
     {
-        $change_color    = FALSE;
+        $change_color= FALSE;
 
         $new_red     = rand( hexDec( $start_red ), hexDec( $end_red ) );
-        $new_green     = rand( hexDec( $start_green ), hexDec( $end_green ) );
-        $new_blue     = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
+        $new_green   = rand( hexDec( $start_green ), hexDec( $end_green ) );
+        $new_blue    = rand( hexDec( $start_blue ), hexDec( $end_blue ) );
 
         $new         = decHex( $new_red ) . decHex( $new_green ) . decHex( $new_blue );
@@ -219,59 +219,58 @@
 function drawQueuePie() { }
 
-
 function drawPie() 
 {
     global $jobs, $gnodes, $piefilter, $filter, $metrics;
 
-    $nodes         = $gnodes;
+    $nodes = $gnodes;
 
     if( isset($piefilter) )    
     {
-        $pie_args    = "title=" . rawurlencode("Cluster ".$piefilter." usage");
+        $pie_args = "title=" . rawurlencode("Cluster ".$piefilter." usage");
     } 
     else 
     {
-        $pie_args     = "title=" . rawurlencode("Cluster queue usage");
-    }
-
-    $pie_args     .= "&size=250x150";
-
-    $queues     = array();
-    $nr_jobs     = count( $jobs );
-    $nr_nodes     = count( $nodes );
-
-    $nr_cpus     = cluster_sum("cpu_num", $metrics);
-
-    $empty_cpus     = 0;
-    $used_cpus     = 0;
-
-    $job_weight     = array();
+        $pie_args = "title=" . rawurlencode("Cluster queue usage");
+    }
+
+    $pie_args .= "&size=250x150";
+
+    $queues    = array();
+    $nr_jobs   = count( $jobs );
+    $nr_nodes  = count( $nodes );
+
+    $nr_cpus   = cluster_sum("cpu_num", $metrics);
+
+    $empty_cpus= 0;
+    $used_cpus = 0;
+
+    $job_weight= array();
 
     foreach( $nodes as $node ) 
     {
-        $myjobs        = $node->getJobs();
-        $myhost        = $node->getHostname();
-        $node_cpus    = $metrics[$myhost]["cpu_num"]['VAL'];
-        $job_cpu    = 0;
+        $myjobs    = $node->getJobs();
+        $myhost    = $node->getHostname();
+        $node_cpus = $metrics[$myhost]["cpu_num"]['VAL'];
+        $job_cpu   = 0;
 
         foreach( $myjobs as $myjob ) 
         {
-            $job_cpu    += isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
+            $job_cpu += isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
         }
 
-        $node_freecpu    = $node_cpus - $job_cpu;
-
-        $empty_cpus    += $node_freecpu;
-    }
-
-    $empty_cpus        = ( $empty_cpus >= 0 ) ? $empty_cpus : 0;
-    $used_cpus        = $nr_cpus - $empty_cpus;
-
-    $empty_percentage     = $empty_cpus;
-
-    $qcolors         = array();
-    $color             = randomColor( $qcolors );
-    $qcolors[]         = $color;
-    $pie_args         .= "&free=$empty_percentage,$color";
+        $node_freecpu= $node_cpus - $job_cpu;
+
+        $empty_cpus += $node_freecpu;
+    }
+
+    $empty_cpus = ( $empty_cpus >= 0 ) ? $empty_cpus : 0;
+    $used_cpus  = $nr_cpus - $empty_cpus;
+
+    $empty_percentage= $empty_cpus;
+
+    $qcolors   = array();
+    $color     = randomColor( $qcolors );
+    $qcolors[] = $color;
+    $pie_args .= "&free=$empty_percentage,$color";
 
     if( isset( $piefilter ) )
@@ -282,12 +281,12 @@
     foreach( $nodes as $node )
     {
-        $node_jobs     = $node->getJobs();
-        $nr_node_jobs     = count( $node_jobs );
-        $myhost     = $node->getHostname();
+        $node_jobs    = $node->getJobs();
+        $nr_node_jobs = count( $node_jobs );
+        $myhost       = $node->getHostname();
         $node_cpus    = $metrics[$myhost]["cpu_num"]['VAL'];
 
         foreach( $node_jobs as $myjob )
         {
-            $job_cpu        = isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
+            $job_cpu = isset( $jobs[$myjob]['ppn'] ) ? $jobs[$myjob]['ppn'] : 1;
 
             // Determine the weight of this job
@@ -353,5 +352,5 @@
             {
 
-                $qname        = $jobs[$myjob]['queue'];
+                $qname = $jobs[$myjob]['queue'];
 
                 if( !isset( $queues[$qname] ) )
@@ -378,5 +377,5 @@
     foreach( $graphvals as $name => $totalweight) 
     {
-        $percentage     = $totalweight;
+        $percentage    = $totalweight;
         
         $color         = randomColor( $qcolors );
@@ -408,10 +407,10 @@
         foreach( $jobs as $jobid => $jobattrs ) 
         {
-                $state        = $jobattrs['status'];
-                $owner      = $jobattrs['owner'];
-                $queue         = $jobattrs['queue'];
-                $name         = $jobattrs['name'];
-                $req_cpu     = $jobattrs['requested_time'];
-                $req_memory     = $jobattrs['requested_memory'];
+                $state     = $jobattrs['status'];
+                $owner     = $jobattrs['owner'];
+                $queue     = $jobattrs['queue'];
+                $name      = $jobattrs['name'];
+                $req_cpu   = $jobattrs['requested_time'];
+                $req_memory= $jobattrs['requested_memory'];
 
                 if( $state == 'R' )
@@ -519,41 +518,41 @@
     $tpl->assign("sortby", $sortby );
 
-    $sorted_jobs         = sortJobs( $jobs, $sortby, $sortorder );
-
-    $even             = 1;
-
-    $used_jobs         = 0;
-    $used_cpus         = 0;
+    $sorted_jobs        = sortJobs( $jobs, $sortby, $sortorder );
+
+    $even               = 1;
+
+    $used_jobs          = 0;
+    $used_cpus          = 0;
     $used_nodes         = 0;
 
-    $queued_jobs         = 0;
-    $queued_nodes         = 0;
-    $queued_cpus         = 0;
-
-    $total_nodes         = 0;
+    $queued_jobs        = 0;
+    $queued_nodes       = 0;
+    $queued_cpus        = 0;
+
+    $total_nodes        = 0;
     $total_cpus         = 0;
     $total_jobs         = 0;
 
     $all_used_nodes     = array();
-    $total_used_nodes     = array();
-
-    $running_name_nodes     = array();
-
-    $running_nodes         = 0;
-    $running_jobs         = 0;
-    $running_cpus         = 0;
-
-    $avail_nodes         = count( $gnodes );
+    $total_used_nodes   = array();
+
+    $running_name_nodes = array();
+
+    $running_nodes      = 0;
+    $running_jobs       = 0;
+    $running_cpus       = 0;
+
+    $avail_nodes        = count( $gnodes );
     $avail_cpus         = cluster_sum("cpu_num", $metrics);
 
-    $view_cpus         = 0;
-    $view_jobs         = 0;
+    $view_cpus          = 0;
+    $view_jobs          = 0;
     $view_nodes         = 0;
 
-    $all_nodes         = 0;
-    $all_jobs         = 0;
-    $all_cpus         = 0;
-
-    $view_name_nodes     = array();
+    $all_nodes          = 0;
+    $all_jobs           = 0;
+    $all_cpus           = 0;
+
+    $view_name_nodes    = array();
 
     // Is the "requested memory" column enabled in the config
@@ -578,10 +577,10 @@
     }
 
-    $last_displayed_job     = null;
-
-    $rjqj_host        = null;
-
-    $na_nodes        = 0;
-    $na_cpus        = 0;
+    $last_displayed_job = null;
+
+    $rjqj_host = null;
+
+    $na_nodes  = 0;
+    $na_cpus   = 0;
 
     foreach( $metrics as $bhost => $bmetric )
@@ -591,5 +590,5 @@
             if( ( $mname == 'zplugin_monarch_rj' ) || ($mname == 'zplugin_monarch_qj') )
             {
-                $rjqj_host      = $bhost;
+                $rjqj_host = $bhost;
             }
         }
@@ -600,6 +599,6 @@
         if( $gnode->isDown() || $gnode->isOffline() )
         {
-            $na_nodes    += 1;
-            $na_cpus    += $metrics[$ghost]['cpu_num']['VAL'];
+            $na_nodes += 1;
+            $na_cpus  += $metrics[$ghost]['cpu_num']['VAL'];
         }
     }
@@ -632,6 +631,6 @@
         }
 
-        $ppn         = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
-        $cpus         = $nodes * $ppn;
+        $ppn  = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
+        $cpus = $nodes * $ppn;
 
         if( $report_time == $heartbeat ) 
@@ -694,6 +693,6 @@
                 }
 
-                $queued_cpus     += $cpus;
-                $queued_nodes     += $nodes;
+                $queued_cpus  += $cpus;
+                $queued_nodes += $nodes;
 
                 $queued_jobs++;
@@ -804,14 +803,14 @@
                 }
 
-                $ppn             = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
-                $cpus             = $nodes * $ppn;
+                $ppn       = isset( $jobs[$jobid]['ppn'] ) ? $jobs[$jobid]['ppn'] : 1;
+                $cpus      = $nodes * $ppn;
 
                 $tpl->assign( "nodes", $nodes );
                 $tpl->assign( "cpus", $cpus );
 
-                $start_time         = (int) $jobs[$jobid]['start_timestamp'];
-                $job_start         = $start_time;
-
-                $view_cpus         += $cpus;
+                $start_time= (int) $jobs[$jobid]['start_timestamp'];
+                $job_start = $start_time;
+
+                $view_cpus += $cpus;
 
                 $view_jobs++;
@@ -834,11 +833,11 @@
                             if( $use_fqdn == 1)
                             {
-                                $mynode    = $shortnode.".".$jobs[$jobid]['domain'];
+                                $mynode     = $shortnode.".".$jobs[$jobid]['domain'];
                             }
-                            $myhost_href     = "./?c=".$clustername."&h=".$mynode;
-                            $mynodehosts[]     = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
+                            $myhost_href    = "./?c=".$clustername."&h=".$mynode;
+                            $mynodehosts[]  = "<A HREF=\"".$myhost_href."\">".$shortnode."</A>";
                         }
 
-                        $nodes_hostnames     = implode( " ", $mynodehosts );
+                        $nodes_hostnames    = implode( " ", $mynodehosts );
 
                         $tpl->assign( "nodes_hostnames", $nodes_hostnames );
@@ -866,5 +865,5 @@
                 if( $start_time ) 
                 {
-                    $runningtime         = makeTime( $report_time - $start_time );
+                    $runningtime        = makeTime( $report_time - $start_time );
                     $job_runningtime    = $heartbeat - $start_time;
 
@@ -877,19 +876,19 @@
 
     $all_used_nodes     = array_unique( $all_used_nodes );
-    $view_name_nodes     = array_unique( $view_name_nodes );
-    $running_name_nodes     = array_unique( $running_name_nodes );
+    $view_name_nodes    = array_unique( $view_name_nodes );
+    $running_name_nodes = array_unique( $running_name_nodes );
 
     $used_nodes         = count( $all_used_nodes );
-    $view_nodes         += count( $view_name_nodes );
-    $running_nodes         += count( $running_name_nodes );
-
-    $total_nodes         = $queued_nodes + $running_nodes;
+    $view_nodes        += count( $view_name_nodes );
+    $running_nodes     += count( $running_name_nodes );
+
+    $total_nodes        = $queued_nodes + $running_nodes;
     $total_cpus         = $queued_cpus + $running_cpus;
     $total_jobs         = $queued_jobs + $running_jobs;
 
     $free_nodes         = $avail_nodes - $running_nodes - $na_nodes;
-    $free_nodes        = ( $free_nodes >= 0 ) ? $free_nodes : 0;
-    $free_cpus         = $avail_cpus - $running_cpus - $na_cpus;
-    $free_cpus        = ( $free_cpus >= 0 ) ? $free_cpus : 0;
+    $free_nodes         = ( $free_nodes >= 0 ) ? $free_nodes : 0;
+    $free_cpus          = $avail_cpus - $running_cpus - $na_cpus;
+    $free_cpus          = ( $free_cpus >= 0 ) ? $free_cpus : 0;
 
     $tpl->assignGlobal( "avail_nodes", $avail_nodes );
