From d154bc25ece5330618ef5e8e96c954ab0cd0e7a4 Mon Sep 17 00:00:00 2001
From: "Leigh B. Stoller" <stoller@flux.utah.edu>
Date: Wed, 17 Oct 2007 23:13:23 +0000
Subject: [PATCH] Some additional support saving,using,deleting saved template
 searches.

---
 www/template_defs.php | 52 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/www/template_defs.php b/www/template_defs.php
index 5133bc81af..03270405fd 100644
--- a/www/template_defs.php
+++ b/www/template_defs.php
@@ -991,6 +991,58 @@ class Template
 
 	return 0;
     }
+
+    function SavedSearches($user) {
+	$guid    = $this->guid();
+	$vers    = $this->vers();
+	$uid_idx = $user->uid_idx();
+	
+	$query_result =
+	    DBQueryFatal("select name from experiment_template_searches ".
+			 "where parent_guid='$guid' and ".
+			 "      parent_vers='$vers' and uid_idx='$uid_idx'");
+
+	if (!mysql_num_rows($query_result))
+	    return null;
+
+	$result = array();
+
+	while ($row = mysql_fetch_array($query_result)) {
+	    $name = $row['name'];
+	    $result[$name] = $name;
+	}
+	return $result;
+    }
+    function SavedSearch($name, $user) {
+	$guid    = $this->guid();
+	$vers    = $this->vers();
+	$uid_idx = $user->uid_idx();
+	
+	$query_result =
+	    DBQueryFatal("select expr from experiment_template_searches ".
+			 "where parent_guid='$guid' and ".
+			 "      parent_vers='$vers' and ".
+			 "      uid_idx='$uid_idx'  and ".
+			 "      name='$name'");
+
+	if (!mysql_num_rows($query_result))
+	    return array();
+
+	$row = mysql_fetch_array($query_result);
+	return unserialize($row['expr']);
+    }
+    function DeleteSearch($name, $user) {
+	$guid    = $this->guid();
+	$vers    = $this->vers();
+	$uid_idx = $user->uid_idx();
+	
+	$query_result =
+	    DBQueryFatal("delete from experiment_template_searches ".
+			 "where parent_guid='$guid' and ".
+			 "      parent_vers='$vers' and ".
+			 "      uid_idx='$uid_idx'  and ".
+			 "      name='$name'");
+    }
 }
 
 #
-- 
GitLab