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

matthew lon-capa-cvs@mail.lon-capa.org
Mon, 16 Jun 2003 20:54:39 -0000


matthew		Mon Jun 16 16:54:39 2003 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Default to only searching current domain on basic search.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.179 loncom/interface/lonsearchcat.pm:1.180
--- loncom/interface/lonsearchcat.pm:1.179	Mon Jun 16 15:42:02 2003
+++ loncom/interface/lonsearchcat.pm	Mon Jun 16 16:54:39 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.179 2003/06/16 19:42:02 www Exp $
+# $Id: lonsearchcat.pm,v 1.180 2003/06/16 20:54:39 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -382,7 +382,8 @@
             (undef,undef,undef,undef);
         my $pretty_string;
         if ($ENV{'form.phase'} eq 'basic_search') {
-            ($query,$pretty_string) = &parse_basic_search($r,$closebutton);
+            ($query,$pretty_string,$libraries) = 
+                &parse_basic_search($r,$closebutton);
         } else {                      # Advanced search
             ($query,$customquery,$customshow,$libraries,$pretty_string) 
                 = &parse_advanced_search($r,$closebutton);
@@ -554,12 +555,15 @@
 ENDDOCUMENT
     $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).
         ' ';
-    my $checkbox = &simplecheckbox('related',$ENV{'form.related'});
+    my $relatedcheckbox = &simplecheckbox('related',$ENV{'form.related'});
+    my $domain = $r->dir_config('lonDefDomain');
+    my $domaincheckbox = &simplecheckbox('domains',$domain,'checked');
     $scrout.=<<END;
 </td><td><a
 href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}"
 >Advanced Search</a></td></tr>
-<tr><td>$checkbox use related words</td><td></td></tr>
+<tr><td>$relatedcheckbox use related words</td>
+    <td>$domaincheckbox only search domain <b>$domain</b></td></tr>
 </table>
 </p>
 <p>
@@ -579,10 +583,10 @@
 </p>
 </form>
 ENDDOCUMENT
-    if ($ENV{'request.course.id'}) { $scrout.='<hr />'; }
-}
-if ($ENV{'request.course.id'}) {
-    $scrout.=(<<ENDCOURSESEARCH);
+    }
+    if ($ENV{'request.course.id'}) {
+        $scrout.=(<<ENDCOURSESEARCH);
+<hr />
 <h1>Course Search</h1>    
 <form method="post" action="/adm/searchcat">
 <input type="hidden" name="phase" value="course_search" />
@@ -594,10 +598,13 @@
 <table>
 <tr><td>
 ENDCOURSESEARCH
-    $scrout.='&nbsp;'.&simpletextfield('courseexp',$ENV{'form.courseexp'},40);
-    my $crscheckbox = &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});
-    my $relcheckbox = &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});
-$scrout.=(<<ENDENDCOURSE);
+        $scrout.='&nbsp;'.
+            &simpletextfield('courseexp',$ENV{'form.courseexp'},40);
+        my $crscheckbox = 
+            &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'});
+        my $relcheckbox = 
+            &simplecheckbox('crsrelated',$ENV{'form.crsrelated'});
+        $scrout.=(<<ENDENDCOURSE);
 </td></tr>
 <tr><td>$relcheckbox use related words</td><td></td></tr>
 <tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr>
@@ -605,7 +612,7 @@
 &nbsp;<input type="submit" name="coursesubmit" value='SEARCH' />
 </p>
 ENDENDCOURSE
-}
+    }
     $scrout.=(<<ENDDOCUMENT);
 </body>
 </html>
@@ -1017,11 +1024,11 @@
 ###############################################
 ###############################################
 
-sub simplecheckbox {
-    my ($name,$value)=@_;
-    my $checked='';
-    $checked="checked" if $value eq 'on';
-    return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
+sub simplecheckbox{
+    my ($name,$value,$checked)=@_;
+    $checked="checked" if ($value eq 'on');
+    return '<input type="checkbox" name="'.$name.'" value="'.$value.'" '.
+        $checked.' />';
 }
 
 ###############################################
@@ -1415,11 +1422,33 @@
     ## ---------------------------------------------------------------
     ## Deal with restrictions to given domains
     ## 
+    my ($libraries_to_query,$pretty_domains_string) = 
+        &parse_domain_restrictions();
+    $pretty_search_string .= $pretty_domains_string."<br />\n";
+    #
+    if (@queries) {
+	$query=join(" AND ",@queries);
+	$query="select * from metadata where $query";
+    } elsif ($customquery) {
+        $query = '';
+    }
+    return ($query,$customquery,$customshow,$libraries_to_query,
+            $pretty_search_string);
+}
+
+sub parse_domain_restrictions {
     my $libraries_to_query = undef;
     # $ENV{'form.domains'} can be either a scalar or an array reference.
     # We need an array.
-    my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} 
-                           :  ($ENV{'form.domains'}) );
+    if (! exists($ENV{'form.domains'})) {
+        return (undef,'');
+    }
+    my @allowed_domains;
+    if (ref($ENV{'form.domains'})) {
+        @allowed_domains =  @{$ENV{'form.domains'}};
+    } else {
+        @allowed_domains = ($ENV{'form.domains'});
+    }
     my %domain_hash = ();
     my $pretty_domains_string;
     foreach (@allowed_domains) {
@@ -1442,16 +1471,7 @@
             }
         }
     }
-    $pretty_search_string .= $pretty_domains_string."<br />\n";
-    #
-    if (@queries) {
-	$query=join(" AND ",@queries);
-	$query="select * from metadata where $query";
-    } elsif ($customquery) {
-        $query = '';
-    }
-    return ($query,$customquery,$customshow,$libraries_to_query,
-            $pretty_search_string);
+    return ($libraries_to_query,$pretty_domains_string);
 }
 
 ######################################################################
@@ -1479,7 +1499,8 @@
 	$ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
 	$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
     }
-
+    my ($libraries_to_query,$pretty_domains_string) = 
+        &parse_domain_restrictions();
     # Check to see if enough is filled in
     unless (&filled($ENV{'form.basicexp'})) {
 	&output_blank_field_error($r,$closebutton,'phase=disp_basic');
@@ -1503,8 +1524,12 @@
                         'keywords'));
     $concatarg='title' if $ENV{'form.titleonly'};
     $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string);
+    if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
+        $pretty_search_string .= ' '.$pretty_domains_string;
+    }
     $pretty_search_string .= "<br />\n";
-    return 'SELECT * FROM metadata WHERE '.$query,$pretty_search_string;
+    return ('SELECT * FROM metadata WHERE '.$query,$pretty_search_string,
+            $libraries_to_query);
 }