--- loncom/interface/lonsearchcat.pm 2002/11/03 19:03:29 1.160 +++ loncom/interface/lonsearchcat.pm 2002/11/22 18:36:07 1.161 @@ -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 @@ ENDHEADER $ENV{'form.abstract'}); # Hack - an empty table row. $scrout.="   \n"; - $scrout.=&searchphrasefield('file
extension','mime', - $ENV{'form.mime'}); + $scrout.=&searchphrasefield('file
extension','extension', + $ENV{'form.extension'}); $scrout.="   \n"; $scrout.=&searchphrasefield('publisher
owner','owner', $ENV{'form.owner'}); $scrout.="\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 @@ sub get_persistent_form_data { &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 @@ sub parse_advanced_search { '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 @@ sub parse_advanced_search { $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 @@ sub parse_advanced_search { my $font = ''; # 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 contains ". @@ -1190,10 +1187,30 @@ sub parse_advanced_search { 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 contains '. + $searchphrase.'
'; } + ##### # Evaluate option lists if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') { push @queries,"(language like \"$ENV{'form.language'}\")";