[LON-CAPA-cvs] cvs: loncom / lonsql /interface lonsearchcat.pm

www lon-capa-cvs@mail.lon-capa.org
Wed, 08 Feb 2006 21:17:58 -0000


www		Wed Feb  8 16:17:58 2006 EDT

  Modified files:              
    /loncom	lonsql 
    /loncom/interface	lonsearchcat.pm 
  Log:
  Bug #4531: limit search to queried domain on multidomain machines
  
  
Index: loncom/lonsql
diff -u loncom/lonsql:1.73 loncom/lonsql:1.74
--- loncom/lonsql:1.73	Wed Feb  8 12:11:46 2006
+++ loncom/lonsql	Wed Feb  8 16:17:53 2006
@@ -3,7 +3,7 @@
 # The LearningOnline Network
 # lonsql - LON TCP-MySQL-Server Daemon for handling database requests.
 #
-# $Id: lonsql,v 1.73 2006/02/08 17:11:46 www Exp $
+# $Id: lonsql,v 1.74 2006/02/08 21:17:53 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -466,7 +466,7 @@
                 }
             } else {
                 # Do an sql query
-                $result = &do_sql_query($query,$arg1,$arg2);
+                $result = &do_sql_query($query,$arg1,$arg2,$searchdomain);
             }
             # result does not need to be escaped because it has already been
             # escaped.
@@ -517,8 +517,18 @@
 }
 
 sub do_sql_query {
-    my ($query,$custom,$customshow) = @_;
-#    &logthis('doing query '.$query);
+    my ($query,$custom,$customshow,$searchdomain) = @_;
+
+#
+# limit to searchdomain if given and table is metadata
+#
+    if (($searchdomain) && ($query=~/FROM metadata/)) {
+	$query.=' HAVING (domain="'.$searchdomain.'")';
+    }
+#    &logthis('doing query ('.$searchdomain.')'.$query);
+
+
+
     $custom     = &unescape($custom);
     $customshow = &unescape($customshow);
     #
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.253 loncom/interface/lonsearchcat.pm:1.254
--- loncom/interface/lonsearchcat.pm:1.253	Wed Feb  8 11:25:39 2006
+++ loncom/interface/lonsearchcat.pm	Wed Feb  8 16:17:58 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.253 2006/02/08 16:25:39 www Exp $
+# $Id: lonsearchcat.pm,v 1.254 2006/02/08 21:17:58 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1540,9 +1540,8 @@
     ##
     ## Deal with restrictions to given domains
     ## 
-    my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = 
-        &parse_domain_restrictions();
-    if ((defined($domain_sql_restriction)) && ($domain_sql_restriction ne '')) {
+    my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
+    if ($pretty_domains_string) {
        $pretty_search_string .= $pretty_domains_string."<br />\n";
     }
     #
@@ -1567,21 +1566,17 @@
     #
     my %domain_hash = ();
     my $pretty_domains_string;
-    my $domain_sql_restriction;
     foreach (@allowed_domains) {
         $domain_hash{$_}++;
     }
     if ($domain_hash{'any'}) {
         $pretty_domains_string = "In all LON-CAPA domains.";
-        $domain_sql_restriction = undef;
     } else {
         if (@allowed_domains > 1) {
             $pretty_domains_string = "In LON-CAPA domains:";
         } else {
             $pretty_domains_string = "In LON-CAPA domain ";
         }
-        $domain_sql_restriction = 
-            '(domain="'.join('" OR domain="',@allowed_domains).'")';
         foreach (sort @allowed_domains) {
             $pretty_domains_string .= "<b>".$_."</b> ";
         }
@@ -1592,8 +1587,7 @@
         }
     }
     return ($libraries_to_query,
-            $pretty_domains_string,
-            $domain_sql_restriction);
+            $pretty_domains_string);
 }
 
 ######################################################################
@@ -1622,8 +1616,7 @@
 	$env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"});
 	$env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
     }
-    my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = 
-        &parse_domain_restrictions();
+    my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions();
     #
     # Check to see if enough of a query is filled in
     my $search_string = $env{'form.basicexp'};