--- loncom/interface/lonsearchcat.pm 2001/03/22 14:13:53 1.72
+++ loncom/interface/lonsearchcat.pm 2001/08/26 21:49:49 1.99
@@ -1,14 +1,40 @@
-# The LearningOnline Network
+# The LearningOnline Network with CAPA
+#
# Search Catalog
#
+# YEAR=2001
# 03/08/2001 Scott Harrison
# Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001
-# Scott Harrison: 03/20/2001
+# Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
+# Scott Harrison: 04/02/2001, 08/15/2001, 08/24/2001, 08/25/2001
+
+###############################################################################
+## ##
+## ORGANIZATION OF THIS PERL MODULE ##
+## ##
+## 1. Description of functions ##
+## 2. Modules used by this module ##
+## 3. Choices for different output views (detailed, summary, xml, etc) ##
+## 4. BEGIN block (to be run once after compilation) ##
+## 5. Handling routine called via Apache and mod_perl ##
+## 6. Other subroutines ##
+## ##
+###############################################################################
+
+# ---------------------------------------------------- Description of functions
#
-# Functions
#
+# === WEB HANDLER FUNCTIONS
+# BEGIN() : run once after compilation to initialize values
# handler(server reference) : interacts with the Apache server layer
# (for /adm/searchcat URLs)
+# get_unprocessed_cgi() : reads in critical name/value pairs that may have not
+# been processed and passed into %ENV by the web server
+# make_persistent() : makes a set of hidden HTML fields to make
+# SQL search interface information to be persistent
+#
+#
+# === WEB INTERFACE COMPONENT FUNCTIONS
# simpletextfield(name,value) : returns HTML formatted string for simple text
# field
# simplecheckbox(name,value) : returns HTML formatted string for simple
@@ -20,25 +46,64 @@
# for a calendar date
# selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
# a selection box field
+#
+#
+# === SEARCH FUNCTIONS
# advancedsearch(server reference, environment reference) : perform a complex
# multi-field logical query
-# filled(field) : determines whether a given field has been filled
# basicsearch(server reference, environment reference) : perform a simple
# single-field logical query
-# output_blank_field_error(server reference) : outputs a message saying that
-# more fields need to be filled in
-# output_results(output mode,
-# server reference,
-# environment reference,
-# reply list reference) : outputs results from search
# build_SQL_query(field name, logic) : builds a SQL query string from a
# logical expression with AND/OR keywords
+# build_custommetadata_query(field_name, logic_statement) : builds a perl
+# regular expression from a logical expression with AND/OR
+# keywords
# recursive_SQL_query_build(field name, reverse notation expression) :
# builds a SQL query string from a reverse notation expression
# logical expression with AND/OR keywords
+# build_date_queries(cmonth1, cday1, cyear1, cmonth2, cday2, cyear2,
+# lmonth1, lday1, lyear1, lmonth2, lday2, lyear2) :
+# Builds a SQL logic query to check time/date entries.
+#
+#
+# === OUTPUTTING RESULTS FUNCTION
+# output_results(output mode,
+# server reference,
+# environment reference,
+# reply list reference) : outputs results from search
+#
+#
+# === DIFFERENT WAYS TO VIEW METADATA RECORDS
+# detailed_citation_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
+# see metadata viewing notes below
+# summary_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
+# see metadata viewing notes below
+# fielded_format_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
+# see metadata viewing notes below
+# xml_sgml_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
+# see metadata viewing notes below
+# ___________________________________________________________________________
+# | * Metadata viewing notes |
+# | Output is a HTML-ified string. |
+# | Input arguments are title, author, subject, url, keywords, version, notes,|
+# | short abstract, mime, language, creation date, last revision date, owner, |
+# | copyright, hostname, httphost, and extra custom metadata to show. |
+# ---------------------------------------------------------------------------
+#
+#
+# === TEST CONDITIONAL FUNCTIONS
+# filled(field) : determines whether a given field has been filled
+#
+#
+# === ERROR FUNCTIONS
+# output_blank_field_error(server reference) : outputs a message saying that
+# more fields need to be filled in
+# output_date_error(server reference, error message) : outputs
+# an error message specific to bad date format.
package Apache::lonsearchcat;
+# ------------------------------------------------- modules used by this module
use strict;
use Apache::Constants qw(:common);
use Apache::lonnet();
@@ -46,12 +111,30 @@ use Apache::File();
use CGI qw(:standard);
use Text::Query;
-my %language;
-my $scrout;
-my %metadatafields;
-my %cprtag;
-my %mimetag;
-my $closebutton;
+# ---------------------------------------- variables used throughout the module
+
+# -- information holders
+my %language; # holds contents of language.tab
+my %cprtag; # holds contents of copyright.tab
+my %mimetag; # holds contents of filetypes.tab
+my %hostdomains; # matches host name to host domain
+my %hostips; # matches host name to host ip
+my %hitcount; # stores number of hits per host
+
+# -- dynamically rendered interface components
+my $closebutton; # button that closes the search window
+my $importbutton; # button to take the selected results and go to group sorting
+
+# -- miscellaneous variables
+my $scrout; # string that holds portions of the screen output
+my $fnum; # search result counter
+my $yourself; # allows for quickly limiting to oneself
+
+# ------------------------------------------ choices for different output views
+# Detailed Citation View ---> sub detailed_citation_view
+# Summary View ---> sub summary_view
+# Fielded Format ---> sub fielded_format_view
+# XML/SGML ---> sub xml_sgml_view
my $basicviewselect=<
LIMIT BY CREATION DATE RANGE:
-
LIMIT BY LAST REVISION DATE RANGE:
-
@@ -288,6 +402,36 @@ ENDDOCUMENT
return OK;
}
+# ----------- grab unprocessed CGI variables that may have been appended to URL
+sub get_unprocessed_cgi {
+ map {
+ my ($name, $value) = split(/=/,$_);
+ $value =~ tr/+/ /;
+ $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
+ if ($name eq 'catalogmode') {
+ $ENV{'form.'.$name}=$value;
+ }
+ } (split(/&/,$ENV{'QUERY_STRING'}));
+}
+
+# ------------------------------------------------------------- make persistent
+sub make_persistent {
+ my $persistent='';
+
+ map {
+ if (/^form\./ && !/submit/) {
+ my $name=$_;
+ my $key=$name;
+ $ENV{$key}=~s/\'//g; # do not mess with html field syntax
+ $name=~s/^form\.//;
+ $persistent.=< $uctitle:".
- " $instruction $uctitle:".
- "
+
between:
CREATIONDATESTART
$scrout.=&dateboxes('creationdatestart',1,1,1976,
@@ -201,7 +305,7 @@ CREATIONDATEEND
between:
+
between:
LASTREVISIONDATESTART
$scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
$ENV{'form.lastrevisiondatestart_month'},
@@ -220,7 +324,6 @@ LASTREVISIONDATEEND
$scrout.=&searchphrasefield('Limit by publisher/owner','owner',
$ENV{'form.owner'});
-# $metadatafields{'owner'});
$ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
$scrout.=&selectbox('Limit by copyright/distribution','copyright',
@@ -229,16 +332,27 @@ LASTREVISIONDATEEND
# ------------------------------------------- Compute customized metadata field
$scrout.=<
+For resource-specific metadata, enter in an expression in the form of
+key=value separated by operators such as AND or OR.
Example: grandmother=75 OR grandfather=85
-
+
CUSTOMMETADATA
$scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
$scrout.=' initial users of this system do not need to worry about this option';
+ $scrout.=<
+CUSTOMSHOW
+$scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
+$scrout.=' initial users of this system do not need to worry about this option';
+
# ---------------------------------------------------------------- Print screen
$r->print(<Search Catalog
+
$closebutton
$basicviewselect
+
Advanced Search
$scrout
".
+ " $instruction
".
'';
}
@@ -463,7 +607,7 @@ sub selectbox {
my ($title,$name,$value,%options)=@_;
my $uctitle=uc($title);
my $selout="\n
".'Search Results
');
+ $r->rflush();
+ my $servernum=(keys %rhash)+0;
+
+ # define server grid (shows status of multiple machines)
+ my $hcinit;
+ my $grid="'
'+";
+ $grid.="\n";
+ my $sn=1;
+ for my $sk (sort keys %rhash) {
+ # ''+
+ $grid.="'+\"'\"+')\">'+";
+ $grid.="\n";
+ $grid.="''+\n";
+ $grid.="'
'+\n" unless $sn%10;
+ $sn++;
}
-}
-
-# ------------------------------------------------------------- build_SQL_query
-sub build_SQL_query {
- my ($field_name,$logic_statement)=@_;
- my $q=new Text::Query('abc',
- -parse => 'Text::Query::ParseAdvanced',
- -build => 'Text::Query::Build');
- $q->prepare($logic_statement);
- my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
- my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
- return $sql_query;
-}
+ $r->print(<
\n";
+ }
}
- substr($pattern,
- index($pattern,$match),
- length($match),
- $replacement
- );
+ my $customdata='';
+ my %customhash;
+ foreach my $result (@results) {
+ if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
+ my $tmp=$result;
+ $tmp=~s/^custom\=//;
+ my ($k,$v)=map {&Apache::lonnet::unescape($_);
+ } split(/\,/,$tmp);
+ $customhash{$k}=$v;
+ }
+ }
+ foreach my $result (@results) {
+ next if $result=~/^custom\=/;
+ chomp $result;
+ next unless $result;
+ my @fields=map
+ {&Apache::lonnet::unescape($_)}
+ (split(/\,/,$result));
+ my ($title,$author,$subject,$url,$keywords,$version,
+ $notes,$abstract,$mime,$lang,
+ $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
+ my $shortabstract=$abstract;
+ $shortabstract=substr($abstract,0,200) if length($abstract)>200;
+ $fields[7]=$shortabstract;
+ my $extrashow2=$extrashow;
+ if ($extrashow) {
+ foreach my $field (@customfields) {
+ my $value='';
+ if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
+ $value=$1;
+ }
+ $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
+ }
+ }
+
+ $compiledresult.=<
+END
+ $compiledresult.=<
+END
+ my $httphost=$ENV{'HTTP_HOST'};
+
+ my $viewselect;
+ if ($mode eq 'Basic') {
+ $viewselect=$ENV{'form.basicviewselect'};
+ }
+ elsif ($mode eq 'Advanced') {
+ $viewselect=$ENV{'form.advancedviewselect'};
+ }
+
+ if ($viewselect eq 'Detailed Citation View') {
+ $compiledresult.=&detailed_citation_view(@fields,
+ $hostname,$httphost,
+ $extrashow2);
+ }
+ elsif ($viewselect eq 'Summary View') {
+ $compiledresult.=&summary_view(@fields,$hostname,$httphost,
+ $extrashow2);
+ }
+ elsif ($viewselect eq 'Fielded Format') {
+ $compiledresult.=&fielded_format_view(@fields,$hostname,
+ $httphost,$extrashow2);
+ }
+ elsif ($viewselect eq 'XML/SGML') {
+ $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
+ $extrashow2);
+ }
+
+ }
+
+ if ($compiledresult) {
+ $resultflag=1;
+ }
+
+ $r->print(<$title
$author
-Subject: $subject
-Keyword(s): $keywords
-Notes: $notes
-MIME Type: $mimetag{$mime}
-Language: $language{$lang}
-Copyright/Distribution: $cprtag{$copyright}
+Subject: $subject
+Keyword(s): $keywords
+Notes: $notes
+MIME Type: $mimetag{$mime}
+Language: $language{$lang}
+Copyright/Distribution: $cprtag{$copyright}
+
$shortabstract
END @@ -856,12 +1299,13 @@ sub summary_view { my ($title,$author,$subject,$url,$keywords,$version, $notes,$shortabstract,$mime,$lang, $creationdate,$lastrevisiondate,$owner,$copyright, - $hostname,$httphost)=@_; + $hostname,$httphost,$extrashow)=@_; my $result=<+Incorrect search query due to blank entry fields. +You need to fill in the relevant +fields on the search page in order for a query to be +processed. +
+ + +RESULTS +} + +# ----------------------------------------------------------- Output date error sub output_date_error { my ($r,$message)=@_; # make query information persistent to allow for subsequent revision @@ -993,14 +1437,14 @@ BEGINNING $r->print(<
$message
@@ -1010,21 +1454,6 @@ $message
RESULTS
}
-sub make_persistent {
- my $persistent='';
-
- map {
- if (/^form\./ && !/submit/) {
- my $name=$_;
- my $key=$name;
- $ENV{$key}=~s/\'//g; # do not mess with html field syntax
- $name=~s/^form\.//;
- $persistent.=<