Index: trunk/web/addons/job_monarch/index.php
===================================================================
--- trunk/web/addons/job_monarch/index.php	(revision 611)
+++ trunk/web/addons/job_monarch/index.php	(revision 648)
@@ -23,5 +23,6 @@
  */
 
-ini_set("memory_limit","200M");
+//ini_set("memory_limit","200M");
+ini_set("memory_limit","1G");
 set_time_limit(0);
 
@@ -44,7 +45,23 @@
 chdir( $my_dir );
 
-$httpvars = new HTTPVariables( $HTTP_GET_VARS, $_GET );
-$clustername = $httpvars->getClusterName();
-$view = $httpvars->getHttpVar( "view" );
+$httpvars	= new HTTPVariables( $HTTP_GET_VARS, $_GET );
+$clustername	= $httpvars->getClusterName();
+$view		= $httpvars->getHttpVar( "view" );
+
+global $mySession, $myData, $myXML;
+
+//printf( "c %s\n", $clustername );
+
+$mySession      = new SessionHandler( $clustername );
+$mySession->checkSession();
+
+$session        = &$mySession->getSession();
+$myXML          = $session['data'];
+
+$myData         = new DataGatherer( $clustername );
+$myData->parseXML( $myXML );
+
+$mySession->updatePollInterval( $myData->getPollInterval() );
+$mySession->endSession();
 
 $filter = array();
@@ -94,314 +111,4 @@
 }
 
-function makeHeader( $page_call, $title, $longtitle )
-{
-	global $tpl, $grid, $context, $initgrid;
-	global $jobrange, $jobstart;
-	global $page, $gridwalk, $clustername;
-	global $parentgrid, $physical, $hostname;
-	global $self, $filter, $cluster_url, $get_metric_string;
-	global $metrics, $reports, $m, $default_metric;
-	global $default_refresh, $filterorder, $view;
-	global $JOB_ARCHIVE, $period_start, $period_stop, $h, $id;
-	global $job_start, $job_stop, $range, $r, $metricname;
-	
-	if( isset($default_metric) and !isset($m) )
-		$metricname = $default_metric;
-	else
-		if( isset( $m ) )
-			$metricname = $m;
-		else
-			$metricname = "load_one";
-
-	$header = "header";
-
-	# Maintain our path through the grid tree.
-	$me = $self . "@" . $grid[$self]['AUTHORITY'];
-
-	$gridstack = array();
-	$gridstack[] = $me;
-
-	if ($gridwalk=="fwd")
-	{
-		# push our info on gridstack, format is "name@url>name2@url".
-		if (end($gridstack) != $me)
-		{
-			$gridstack[] = $me;
-		}
-	}
-	else if ($gridwalk=="back") 
-	{
-		# pop a single grid off stack.
-		if (end($gridstack) != $me) 
-		{
-			array_pop($gridstack);
-		}
-	}
-
-	$gridstack_str = join(">", $gridstack);
-	$gridstack_url = rawurlencode($gridstack_str);
-
-	if ($initgrid or $gridwalk) 
-	{
-		# Use cookie so we dont have to pass gridstack around within this site.
-		# Cookie values are automatically urlencoded. Expires in a day.
-		setcookie("gs", $gridstack_str, time() + 86400);
-	}
-
-	# Invariant: back pointer is second-to-last element of gridstack. Grid stack never
-	# has duplicate entries.
-	list($parentgrid, $parentlink) = explode("@", $gridstack[count($gridstack)-2]);
-
-	# Setup a redirect to a remote server if you choose a grid from pulldown menu. Tell
-	# destination server that we're walking foward in the grid tree.
-	if (strstr($clustername, "http://")) 
-	{
-		$tpl->assign("refresh", "0");
-		$tpl->assign("redirect", ";URL=$clustername?gw=fwd&gs=$gridstack_url");
-		echo "<h2>Redirecting, please wait...</h2>";
-		$tpl->printToScreen();
-		exit;
-	}
-	$tpl->gotoBlock( "_ROOT" );
-
-	if( $view != "search" )
-		$tpl->assign( "refresh", $default_refresh );
-
-	$tpl->assign( "date", date("r") );
-	//printf("lg %s\n", $longtitle );
-	//printf("title %s\n", $title );
-	$tpl->assign( "longpage_title", $longtitle );
-	$tpl->assign( "page_title", $title );
-
-	# The page to go to when "Get Fresh Data" is pressed.
-	$tpl->assign("page","./");
-
-	# Templated Logo image
-	$tpl->assign("images","./templates/$template_name/images");
-
-	#
-	# Used when making graphs via graph.php. Included in most URLs
-	#
-	$sort_url=rawurlencode($sort);
-	$get_metric_string = "m=$metric&r=$range&s=$sort_url&hc=$hostcols";
-
-	if ($jobrange and $jobstart)
-		$get_metric_string .= "&jr=$jobrange&js=$jobstart";
-
-	# Set the Alternate view link.
-	$cluster_url=rawurlencode($clustername);
-	$node_url=rawurlencode($hostname);
-
-	# Make some information available to templates.
-	$tpl->assign("cluster_url", $cluster_url);
-	# Build the node_menu
-	$node_menu = "";
-
-	if ($parentgrid) 
-	{
-		$node_menu .= "<B>$parentgrid $meta_designator</B> ";
-		$node_menu .= "<B>&gt;</B>\n";
-	}
-
-	# Show grid.
-	$mygrid =  ($self == "unspecified") ? "" : $self;
-	$node_menu .= "<B><A HREF=\"../..\">$mygrid $meta_designator</A></B> ";
-	$node_menu .= "<B>&gt;</B>\n";
-
-	if ($physical)
-	{
-		$node_menu .= hiddenvar("p", $physical);
-	}
-
-	if ( $clustername ) 
-	{
-		$url = rawurlencode($clustername);
-		$node_menu .= "<B><A HREF=\"../../?c=".rawurlencode($clustername)."\">$clustername</A></B> ";
-		$node_menu .= "<B>&gt;</B>\n";
-		$node_menu .= hiddenvar("c", $clustername);
-	}
-
-	if (!count($metrics)) 
-	{
-		echo "<h4>Cannot find any metrics for selected cluster \"$clustername\", exiting.</h4>\n";
-		echo "Check ganglia XML tree (telnet $ganglia_ip $ganglia_port)\n";
-		exit;
-	}
-	reset($metrics);
-	$firsthost = key($metrics);
-
-	$mmfh	= array();
-
-	$mmfh	= $metrics[$firsthost];
-
-	$context_metrics	= array();
-
-	//foreach ($mmfh as $mm => $mfoo)
-	foreach( $mmfh as $mm => $bla )
-	{
-		$context_metrics[] = $mm;
-	}
-
-	foreach ($reports as $mr => $mfoo)
-		$context_metrics[] = $mr;
-
-	$node_menu .= "<B><A HREF=\"./?c=".rawurlencode($clustername)."\">Joblist</A></B> ";
-
-	if( isset( $hostname ) && ( $view != 'host' ) ) 
-	{
-		$node_menu .= "<B>&gt;</B>\n";
-		$href = "<A HREF=\"./?c=".rawurlencode($clustername)."&h=".$hostname."\">";
-		$node_menu .= "<B>$href";
-		$node_menu .= "host: $hostname</A></B> ";
-	}
-
-	if( count( $filter ) > 0 && $view != "search" ) 
-	{
-		$my_ct = 1;
-		$filter_nr = count( $filter );
-
-		foreach( $filter as $filtername=>$filterval ) 
-		{
-			$node_menu .= "<B>&gt;</B>\n";
-
-			$href = "<A HREF=\"./?c=".rawurlencode($clustername);
-			$temp_ct = 0;
-			$n_filter = $filter;
-			$my_filterorder = "";
-			$my_filters = array_keys( $filter );
-
-			foreach( $n_filter as $n_filtername=>$n_filterval ) 
-			{
-				if( $temp_ct < $my_ct ) 
-				{
-					$href .= "&". $n_filtername . "=" . $n_filterval;
-
-					if( $my_filterorder == "" )
-						$my_filterorder = $my_filters[$temp_ct];
-					else
-						$my_filterorder .= "," . $my_filters[$temp_ct];
-				}
-
-				$temp_ct++;
-			}
-			$href .= "&filterorder=$my_filterorder\">";
-
-			if( $my_ct < $filter_nr )
-				$node_menu .= "<B>$href$filtername: $filterval</A></B> ";
-			else
-				$node_menu .= "<B>$filtername: $filterval</B> ";
-
-			$my_ct++;
-		}
-	}
-
-	$tpl->gotoBlock( "_ROOT" );
-	$tpl->assignGlobal("view", $view);
-
-	if( array_key_exists( "id", $filter ) or isset($hostname) ) 
-	{
-		$range = "job";
-
-		if( $page_call != "host_view" )
-		{
-			if (is_array($context_metrics) ) 
-			{
-				$metric_menu = "<B>Metric</B>&nbsp;&nbsp;"
-					."<SELECT NAME=\"m\" OnChange=\"toga_form.submit();\">\n";
-
-				sort($context_metrics);
-				foreach( $context_metrics as $k ) 
-				{
-					$url = rawurlencode($k);
-					$metric_menu .= "<OPTION VALUE=\"$url\" ";
-					if ($k == $metricname )
-						$metric_menu .= "SELECTED";
-					$metric_menu .= ">$k\n";
-				}
-				$metric_menu .= "</SELECT>\n";
-			}
-
-		}
-
-		$tpl->assign("metric_menu", $metric_menu );
-
-		if( $view == "search" or $view == "host" ) 
-		{
-			$tpl->newBlock("timeperiod");
-			if( is_numeric( $period_start ) ) 
-			{
-				$period_start = epochToDatetime( $period_start );
-			}
-			if( is_numeric( $period_stop ) ) 
-			{
-				$period_stop = epochToDatetime( $period_stop );
-			}
-			$tpl->assign("period_start", $period_start );
-			$tpl->assign("period_stop", $period_stop );
-			$tpl->assign("hostname", $hostname );
-
-			if( $view == "host" ) 
-			{
-				$tpl->newBlock("hostview");
-				$tpl->assign("job_start", $job_start );
-				$tpl->assign("job_stop", $job_stop );
-			}
-		} 
-
-	}
-
-	if( $view != "search" )
-	{
-		$context_ranges[]="hour";
-		$context_ranges[]="day";
-		$context_ranges[]="week";
-		$context_ranges[]="month";
-		$context_ranges[]="year";
-		$context_ranges[]="job";
-
-		$range_menu = "<B>Last</B>&nbsp;&nbsp;" ."<SELECT NAME=\"r\" OnChange=\"toga_form.submit();\">\n";
-		foreach ($context_ranges as $v) 
-		{
-			$url=rawurlencode($v);
-			$range_menu .= "<OPTION VALUE=\"$url\" ";
-			if ($v == $range)
-				$range_menu .= "SELECTED";
-			$range_menu .= ">$v\n";
-		}
-		$range_menu .= "</SELECT>\n";
-
-		$tpl->assign("range_menu", $range_menu);
-
-	}
-
-	if( $view == "search" or $view == "host" ) 
-	{
-		$node_menu .= "<B>&gt;</B>\n";
-		$node_menu .= "<B>Jobarchive</B> ";
-		$form_name = "archive_search_form";
-		$tpl->assignGlobal("form_name", $form_name );
-	}
-	else
-	{
-		$form_name = "toga_form";
-		$tpl->assignGlobal("form_name", $form_name );
-	}
-
-	if( $JOB_ARCHIVE && $page_call == 'overview' ) 
-	{
-		$tpl->newBlock( "search" );
-		$tpl->assignGlobal( "cluster_url", rawurlencode($clustername) );
-		$tpl->assignGlobal( "cluster", $clustername );
-	}
-	$tpl->gotoBlock( "_ROOT" );
-	$tpl->assignGlobal( "cluster", $clustername );
-	$tpl->assign("node_menu", $node_menu);
-
-	# Make sure that no data is cached..
-	header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");    # Date in the past
-	header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); # always modified
-	header ("Cache-Control: no-cache, must-revalidate");  # HTTP/1.1
-	header ("Pragma: no-cache");                          # HTTP/1.0
-}
 
 function makeFooter() 
@@ -456,4 +163,11 @@
 	$hostname = $h;
 }
+$ic                     = new ClusterImage( $myData, $clustername );
+$ic->setBig();
+$ic->setNoimage();
+$ic->draw();
+
+//printf("%s\n", $ic->getImagemapArea() );
+
 
 switch( $view ) 
@@ -461,20 +175,20 @@
 	case "overview":
 
-		includeOverview();
+		//includeOverview();
 		break;
 
 	case "search":
 
-		includeSearchPage();
+		//includeSearchPage();
 		break;
 
 	case "host":
 
-		includeHostPage();
+		//includeHostPage();
 		break;
 
 	default:
 
-		includeOverview();
+		//includeOverview();
 		break;
 }
@@ -488,27 +202,38 @@
 $tpl->assign("cluster", $clustername );
 
+session_start();
+$tpl->assign( "session_name", session_name() );
+$tpl->assign( "session_id", session_id() );
+
+$rjqj_str .= "./graph.php?z=small&c=$clustername&g=job_report&r=$range&st=$cluster[LOCALTIME]";
+
+$tpl->assign( "rjqj_graph", $rjqj_str );
+$tpl->assign( "uue_clustername", rawurlencode($clustername) );
+
+$tpl->assign( "node_area_map", $ic->getImagemapArea() );
+
 switch( $view ) 
 {
 	case "overview":
 
-		include "./overview.php";
-		makeOverview();
+		//include "./overview.php";
+		//makeOverview();
 		break;
 
 	case "search":
 
-		include "./search.php";
-		makeSearchPage();
+		//include "./search.php";
+		//makeSearchPage();
 		break;
 
 	case "host":
 
-		include "./host_view.php";
-		makeHostView();
+		//include "./host_view.php";
+		//makeHostView();
 		break;
 
 	default:
 
-		makeOverview();
+		//makeOverview();
 		break;
 }
