From ee205e1389c7ae5225ee6af7ed6a854614b406eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Torkelsson?= <torkel@torkel.se>
Date: Fri, 14 Feb 2014 15:01:26 +0100
Subject: [PATCH] Add an option to keep the ordering of graphs in the order
 they were added. Default to the old sorted behaviour.

---
 functions.php | 11 +++++++++--
 graph.php     |  9 ++++++++-
 2 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/functions.php b/functions.php
index dd54b0d0..704669f5 100644
--- a/functions.php
+++ b/functions.php
@@ -747,6 +747,10 @@ function get_view_graph_elements($view) {
           } else {
             $graph_args_array[] = "z=" . $default_size;
           }
+
+          if ( isset($item['sortit']) ) {
+            $graph_args_array[] = "sortit=" . $item['sortit'];
+          }
 	  
 	  // If graph type is not specified default to line graph
 	  if (isset($item['graph_type']) && 
@@ -1111,7 +1115,8 @@ function build_aggregate_graph_config ($graph_type,
                                        $hreg,
                                        $mreg,
                                        $glegend,
-                                       $exclude_host_from_legend_label) {
+                                       $exclude_host_from_legend_label,
+                                       $sortit = true) {
 
   global $conf, $index_array, $hosts, $grid, $clusters, $debug, $metrics;
   
@@ -1157,7 +1162,9 @@ function build_aggregate_graph_config ($graph_type,
         }
       }
     }
-    ksort($metric_matches);
+    if($sortit) {
+      ksort($metric_matches);
+    }
   }
   if( isset($metric_matches)){
     $metric_matches_unique = array_unique($metric_matches);
diff --git a/graph.php b/graph.php
index 45186123..f6e026da 100644
--- a/graph.php
+++ b/graph.php
@@ -293,13 +293,20 @@ function build_aggregate_graph_config_from_url($conf_graph_colors) {
     $exclude_host_from_legend_label = 
       (array_key_exists('lgnd_xh', $_GET) && 
        $_GET['lgnd_xh'] == "true") ? TRUE : FALSE;
+
+    $sortit = true;
+    if($_GET['sortit'] == "false") {
+      $sortit = false;
+    }
+
     $graph_config = 
       build_aggregate_graph_config($graph_type, 
 				   $line_width, 
 				   $_GET['hreg'], 
 				   $_GET['mreg'],
 				   $graph_legend,
-				   $exclude_host_from_legend_label);
+				   $exclude_host_from_legend_label,
+                                   $sortit);
   }
 
   // Set up