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

matthew lon-capa-cvs@mail.lon-capa.org
Fri, 22 Nov 2002 18:36:07 -0000


matthew		Fri Nov 22 13:36:07 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm 
  Log:
  Fix handling of mime type searches.  Replaced form.mime with form.extension.
  The mime type search is now built up from the form.extension and form.category
  fields.  This makes it possible to do both 'file extension' and 'category'
  searches.  This addresses bug 843.
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.160 loncom/interface/lonsearchcat.pm:1.161
--- loncom/interface/lonsearchcat.pm:1.160	Sun Nov  3 14:03:29 2002
+++ loncom/interface/lonsearchcat.pm	Fri Nov 22 13:36:07 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.160 2002/11/03 19:03:29 www Exp $
+# $Id: lonsearchcat.pm,v 1.161 2002/11/22 18:36:07 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -544,13 +544,13 @@
                                              $ENV{'form.abstract'});
     # Hack - an empty table row.
     $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
-    $scrout.=&searchphrasefield('file<br />extension','mime',
-                        $ENV{'form.mime'});
+    $scrout.=&searchphrasefield('file<br />extension','extension',
+                        $ENV{'form.extension'});
     $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
     $scrout.=&searchphrasefield('publisher<br />owner','owner',
 				$ENV{'form.owner'});
     $scrout.="</table>\n";
-    $ENV{'form.category'}='any' unless length($ENV{'form.category'});
+    $ENV{'form.category'}='any' if (! defined($ENV{'form.category'}));
     $scrout.=&selectbox('File Category','category',
 			$ENV{'form.category'},
 			'any','Any category',
@@ -694,7 +694,7 @@
                            &GDBM_READER(),0640));
     #
     # These make sure we do not get array references printed out as 'values'.
-    my %arrays_allowed = ('form.category'=>1,'form.domains'=>1);
+    my %arrays_allowed = ('form.domains'=>1);
     #
     # Loop through the keys, looking for 'form.'
     foreach my $name (keys(%persistent_db)) {
@@ -1136,7 +1136,7 @@
 		   'lastrevisiondatestart_month','lastrevisiondatestart_day',
 		   'lastrevisiondatestart_year','lastrevisiondateend_month',
 		   'lastrevisiondateend_day','lastrevisiondateend_year',
-		   'notes','abstract','mime','language','owner',
+		   'notes','abstract','extension','language','owner',
 		   'custommetadata','customshow','category') {
 	$ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
     }
@@ -1147,16 +1147,13 @@
 	$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
     }
     # Preprocess the category form element.
-    $ENV{'form.category'} = 'any' if (ref($ENV{'form.category'}));
-    if ($ENV{'form.category'} ne 'any') {
-        my @extensions = &Apache::loncommon::filecategorytypes
-            ($ENV{'form.category'});
-        $ENV{'form.mime'} = join ' OR ',@extensions;
-    }
+    $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) ||
+                                      ref($ENV{'form.category'}));
+    #
     # Check to see if enough information was filled in
     for my $field ('title','author','subject','keywords','url','version',
-		   'notes','abstract','mime','language','owner',
-		   'custommetadata') {
+		   'notes','abstract','category','extension','language',
+                   'owner','custommetadata') {
 	if (&filled($ENV{"form.$field"})) {
 	    $fillflag++;
 	}
@@ -1171,7 +1168,7 @@
     my $font = '<font color="#800000" face="helvetica">';
     # Evaluate logical expression AND/OR/NOT phrase fields.
     foreach my $field ('title','author','subject','notes','abstract','url',
-		       'keywords','version','owner','mime') {
+		       'keywords','version','owner') {
 	if ($ENV{'form.'.$field}) {
             my $searchphrase = $ENV{'form.'.$field};
             $pretty_search_string .= $font."$field</font> contains <b>".
@@ -1190,10 +1187,30 @@
 	    push @queries,&build_SQL_query($field,$searchphrase);
         }
     }
-    # I dislike the hack below.
-    if ($ENV{'form.category'}) {
-        $ENV{'form.mime'}='';
+    #
+    # Make the 'mime' from 'form.category' and 'form.extension'
+    #
+    my $searchphrase;
+    if (exists($ENV{'form.category'})    && 
+        $ENV{'form.category'} !~ /^\s*$/ &&
+        $ENV{'form.category'} ne 'any')     {
+        my @extensions = &Apache::loncommon::filecategorytypes
+                                                   ($ENV{'form.category'});
+        if (scalar(@extensions) > 0) {
+            $searchphrase = join(' OR ',@extensions);
+        }
+    }
+    if (exists($ENV{'form.extension'}) && $ENV{'form.extension'} !~ /^\s*$/) {
+        $searchphrase .= ' OR ' if (defined($searchphrase));
+        my @extensions = split(/,/,$ENV{'form.extension'});
+        $searchphrase .= join(' OR ',@extensions);
+    }
+    if (defined($searchphrase)) {
+        push @queries,&build_SQL_query('mime',$searchphrase);
+        $pretty_search_string .=$font.'mime</font> contains <b>'.
+            $searchphrase.'</b><br />';
     }
+    #####
     # Evaluate option lists
     if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
 	push @queries,"(language like \"$ENV{'form.language'}\")";