--- loncom/interface/lonsearchcat.pm 2001/03/21 02:34:35 1.55
+++ loncom/interface/lonsearchcat.pm 2001/03/21 12:51:15 1.62
@@ -107,7 +107,7 @@ END
{
my $fh=Apache::File->new($r->dir_config('lonTabDir').'/language.tab');
map {
- $_=~/(\w+)\s+([\w\s\-]+)/;
+ $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
$language{$1}=$2;
} <$fh>;
}
@@ -117,7 +117,7 @@ END
{
my $fh=Apache::File->new($r->dir_config('lonIncludes').'/copyright.tab');
map {
- $_=~/(\w+)\s+([\w\s\-]+)/;
+ $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
$cprtag{$1}=$2;
} <$fh>;
}
@@ -127,7 +127,7 @@ END
{
my $fh=Apache::File->new($r->dir_config('lonTabDir').'/filetypes.tab');
map {
- $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/;
+ $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
$mimetag{$1}=".$1 $3";
} <$fh>;
}
@@ -494,13 +494,45 @@ sub advancedsearch {
my @queries;
# Go through logical expression AND/OR/NOT phrase fields.
- foreach my $field ('title','author','subject','notes','abstract') {
+
+ foreach my $field ('title','author','subject','notes','abstract','url',
+ 'keywords','version','owner') {
if ($ENV{'form.'.$field}) {
push @queries,&build_SQL_query($field,$ENV{'form.'.$field});
}
}
+ if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
+ push @queries,"(language like \"\%$ENV{'form.language'}\%\")";
+ }
+ if ($ENV{'form.mime'} and $ENV{'form.mime'} ne 'any') {
+ push @queries,"(mime like \"\%$ENV{'form.mime'}\%\")";
+ }
+ if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
+ push @queries,"(copyright like \"\%$ENV{'form.copyright'}\%\")";
+ }
+ my $datequery=&build_date_queries(
+ $ENV{'form.creationdatestart_month'},
+ $ENV{'form.creationdatestart_day'},
+ $ENV{'form.creationdatestart_year'},
+ $ENV{'form.creationdateend_month'},
+ $ENV{'form.creationdateend_day'},
+ $ENV{'form.creationdateend_year'},
+ $ENV{'form.lastrevisiondatestart_month'},
+ $ENV{'form.lastrevisiondatestart_day'},
+ $ENV{'form.lastrevisiondatestart_year'},
+ $ENV{'form.lastrevisiondateend_month'},
+ $ENV{'form.lastrevisiondateend_day'},
+ $ENV{'form.lastrevisiondateend_year'},
+ );
+ if ($datequery=~/^Incorrect/) {
+ &output_date_error($r,$datequery);
+ return OK;
+ }
+ elsif ($datequery) {
+ push @queries,$datequery;
+ }
if (@queries) {
- $query=join(" and ",@queries);
+ $query=join(" AND ",@queries);
$query="select * from metadata where $query";
my $reply=&Apache::lonnet::metadata_query($query);
&output_results('Advanced',$r,$envhash,$query,$reply);
@@ -625,7 +657,7 @@ sub output_results {
$shortabstract=substr($abstract,0,200) if length($abstract)>200;
$fields[7]=$shortabstract;
$compiledresult.=<
END
$compiledresult.=<
Subject: $subject
-Title: $title
-Author(s): $author
+$owner, last revised $lastrevisiondate
+$title
+$author
+
Keyword(s): $keywords
Notes: $notes
-Abstract: $shortabstract
MIME Type: $mimetag{$mime}
Language: $language{$lang}
-Creation Date: $creationdate
-Last Revision Date: $lastrevisiondate
-Publisher/Owner: $owner
-Copyright/Distribution: $copyright
-Repository Location: $hostname
+Copyright/Distribution: $cprtag{$copyright}
+$shortabstract
-Title: $title
-Author(s): $author
-Subject: $subject
-Keyword(s): $keywords
-Notes: $notes
-Abstract: $shortabstract
-MIME Type: $mimetag{$mime}
-Language: $language{$lang}
-Creation Date: $creationdate
-Last Revision Date: $lastrevisiondate
-Publisher/Owner: $owner
-Copyright/Distribution: $copyright
-Repository Location: $hostname
+$author
+$title
+$owner -- $lastrevisiondate
+$cprtag{$copyright}
+<LonCapaResource> +<url>$url</url> +<title>$title</title> +<author>$author</author> +<subject>$subject</subject> +<keywords>$keywords</keywords> +<notes>$notes</notes> +<mimeInfo> +<mime>$mime</mime> +<mimetag>$mimetag{$mime}</mimetag> +</mimeInfo> +<languageInfo> +<language>$lang</language> +<languagetag>$language{$lang}</languagetag> +</languageInfo> +<creationdate>$creationdate</creationdate> +<lastrevisiondate>$lastrevisiondate</lastrevisiondate> +<owner>$owner</owner> +<copyrightInfo> +<copyright>$copyright</copyright> +<copyrighttag>$cprtag{$copyright}</copyrighttag> +</copyrightInfo> +<repositoryLocation>$hostname</repositoryLocation> +<shortabstract>$shortabstract</shortabstract> +</LonCapaResource> +END return $result; } +sub build_date_queries { + my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2, + $lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_; + my @queries; + if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) { + unless ($cmonth1 and $cday1 and $cyear1 and + $cmonth2 and $cday2 and $cyear2) { + return "Incorrect entry for the creation date. You must specify ". + "a starting month, day, and year and an ending month, ". + "day, and year."; + } + my $cnumeric1="$cyear1$cmonth1$cday1"; + $cnumeric1+=0; + my $cnumeric2="$cyear2$cmonth2$cday2"; + $cnumeric2+=0; + if ($cnumeric1>$cnumeric2) { + return "Incorrect entry for the creation date. The starting ". + "date must occur before the ending date."; + } + my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '". + "$cyear2-$cmonth2-$cday2 23:59:59')"; + push @queries,$cquery; + } + if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) { + unless ($lmonth1 and $lday1 and $lyear1 and + $lmonth2 and $lday2 and $lyear2) { + return "Incorrect entry for the last revision date. You must ". + "specify a starting month, day, and year and an ending ". + "month, day, and year."; + } + my $lnumeric1="$lyear1$lmonth1$lday1"; + $lnumeric1+=0; + my $lnumeric2="$lyear2$lmonth2$lday2"; + $lnumeric2+=0; + if ($lnumeric1>$lnumeric2) { + return "Incorrect entry for the last revision date. The ". + "starting date must occur before the ending date."; + } + my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '". + "$lyear2-$lmonth2-$lday2 23:59:59')"; + push @queries,$lquery; + } + if (@queries) { + return join(" AND ",@queries); + } + return ''; +} + +sub output_date_error { + my ($r,$message)=@_; + # make query information persistent to allow for subsequent revision + my $persistent=''; + map { + if (/^form\./ && !/submit/) { + my $name=$_; + my $key=$name; + $name=~s/^form\.//; + $persistent.=<