[Reconnoiter-devel] [reconnoiter commit] r749 - trunk/ui/web/htdocs

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Wed Jun 10 18:06:27 EDT 2009


Author: umar
Date: 2009-06-10 18:06:27 -0400 (Wed, 10 Jun 2009)
New Revision: 749

Modified:
   trunk/ui/web/htdocs/template_browse_json.php
   trunk/ui/web/htdocs/template_graph.php
Log:
confirm that the user wants to update graphs before doing so when using templates, refs #112

Modified: trunk/ui/web/htdocs/template_browse_json.php
===================================================================
--- trunk/ui/web/htdocs/template_browse_json.php	2009-06-10 17:39:06 UTC (rev 748)
+++ trunk/ui/web/htdocs/template_browse_json.php	2009-06-10 22:06:27 UTC (rev 749)
@@ -184,13 +184,37 @@
 }
 
 if(have_req_txtvals && have_req_sidvals){
-	var dataString = 'templateid='+templateid+'&textvars='+textvars.join(',')+'&sidvars='+sidvars.join(',')+textvals+sidvals;
+	var dataString = 'templateid='+templateid+'&textvars='+textvars.join(',')+'&sidvars='+sidvars.join(',')+textvals+sidvals;		
 	$.ajax({
 		type: "POST",
 	url: "template_graph.php",
-	data: dataString,
-	success: function() { }
-	});
+	data: dataString+"&update=0",
+	success: function(d) { 
+	  graphs = eval('(' + d + ')');
+	   if(graphs.length>0) {	  
+             gtitles = "";
+	     for(i=0; i<graphs.length; i++){
+	       gtitles+="\\n"+graphs[i].title
+             }
+	     confirm("Found existing graphs made from this template:<p><textarea rows='10' disabled style='border:none;'>"+gtitles+"</textarea><p> continue and update these?",
+	       function () {
+	      	  $.ajax({
+		         type: "POST",
+	                 url: "template_graph.php",
+ 	                 data: dataString+"&update=1",
+ 	                 success: function() { }
+  	          });
+              });
+          }
+          else {
+                  $.ajax({
+		         type: "POST",
+	                 url: "template_graph.php",
+ 	                 data: dataString+"&update=1",
+ 	                 success: function() { }
+  	          });
+         }
+       }});
 	template_e.find(".CreateGraph").html('Graph Saved').fadeIn('slow');
 	template_e.find(".CreateGraph").html('Graph Saved').fadeOut('slow');
 }

Modified: trunk/ui/web/htdocs/template_graph.php
===================================================================
--- trunk/ui/web/htdocs/template_graph.php	2009-06-10 17:39:06 UTC (rev 748)
+++ trunk/ui/web/htdocs/template_graph.php	2009-06-10 22:06:27 UTC (rev 749)
@@ -3,6 +3,7 @@
 require_once 'Reconnoiter_GraphTemplate.php';
 
 $templateid = $_POST['templateid'];
+$update = $_POST['update'];
 
 $sid_vars = explode(",", $_POST['sidvars']);
 $text_vars = explode(",", $_POST['textvars']);
@@ -21,6 +22,8 @@
   $var_vals[] = explode(",", $_POST[$sv]);
 }
 
+$graphs_to_update = array();
+
 //this number is used so we dont end up trying to create multiple graphs with the same title		
 $graph_num = 1;
 
@@ -28,8 +31,10 @@
 //then, it will create graphs for each of these combinations, updating a graph if one already exists with the same genesis
 //a graph's genesis is composed of its templateid, its text vars and their values, and its sid vars and their values, and
 //should be unique among saved_graphs   
-function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num)
+function createGraphsFromCombos($combo, $var_vals, $i, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num, $update)
     {
+        global $graphs_to_update;
+
 	$genesis = $genesis_base;
         if ($i >= count($var_vals)){	    
 	    $vals_combo = explode(",", $combo);
@@ -48,25 +53,32 @@
 
 	    $grow = $db->getGraphByGenesis($genesis);
 	    if($grow['graphid']) {
-               $graph_json['id'] = $grow['graphid'];
-	       $graph_id = $db->saveGraph($graph_json);
+	       if($update) {
+	         $graph_json['id'] = $grow['graphid'];
+	         $graph_id = $db->saveGraph($graph_json);
+               }
+	       $graphs_to_update[] = array( 'graphid' => $grow['graphid'],
+	        		     	    	          'title' => $grow['title'],);
 	       return;
 	    }
-	    $graph_id = $db->saveGraph($graph_json);
-	    $graph_json['id'] = $graph_id;
-	    $graph_id = $db->saveGraph($graph_json);
+	    if($update) {
+	      $graph_id = $db->saveGraph($graph_json);
+	      $graph_json['id'] = $graph_id;
+	      $graph_id = $db->saveGraph($graph_json);
+            }
 	    return;
 	}
         else
         {
             foreach ($var_vals[$i] as $vval){
 	        $graph_num++;
-	        createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num);
+	        createGraphsFromCombos(($combo) ? "$combo,$vval" : $vval, $var_vals, $i + 1, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num, $update);
            }
         }
     }
 
-createGraphsFromCombos('', $var_vals, 0, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num);
+createGraphsFromCombos('', $var_vals, 0, $sid_vars, $genesis_base, $rparams, $templateid, $graph_num, $update);
 
+print json_encode($graphs_to_update);
 ?>
 



More information about the Reconnoiter-devel mailing list