version 1.141, 2002/07/12 14:36:16
|
version 1.142, 2002/07/12 21:02:27
|
Line 109 button that closes the search window
|
Line 109 button that closes the search window
|
|
|
button to take the select results and go to group sorting |
button to take the select results and go to group sorting |
|
|
=item %hash |
=item %groupsearch_db |
|
|
The ubiquitous database hash |
Database hash used to save values for the groupsearch RAT interface. |
|
|
=item $diropendb |
=item $diropendb |
|
|
Line 137 my $closebutton; # button that closes t
|
Line 137 my $closebutton; # button that closes t
|
my $importbutton; # button to take the selected results and go to group sorting |
my $importbutton; # button to take the selected results and go to group sorting |
|
|
# -- miscellaneous variables |
# -- miscellaneous variables |
my %hash; # database hash |
my %groupsearch_db; # database hash |
my $diropendb = ""; # db file |
my $diropendb = ""; # db file |
|
|
# View Description Function Pointer |
# View Description Function Pointer |
Line 173 string that holds portions of the screen
|
Line 173 string that holds portions of the screen
|
###################################################################### |
###################################################################### |
sub handler { |
sub handler { |
my $r = shift; |
my $r = shift; |
untie %hash; |
untie %groupsearch_db; |
|
|
$r->content_type('text/html'); |
$r->content_type('text/html'); |
$r->send_http_header; |
$r->send_http_header; |
Line 190 sub handler {
|
Line 190 sub handler {
|
## Clear out old values from database |
## Clear out old values from database |
## |
## |
if ($ENV{'form.launch'} eq '1') { |
if ($ENV{'form.launch'} eq '1') { |
if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
&start_fresh_session(); |
&start_fresh_session(); |
untie %hash; |
untie %groupsearch_db; |
} else { |
} else { |
$r->print('<html><head></head><body>Unable to tie hash to db '. |
$r->print('<html><head></head><body>Unable to tie hash to db '. |
'file</body></html>'); |
'file</body></html>'); |
Line 246 END
|
Line 246 END
|
= &parse_advanced_search($r); |
= &parse_advanced_search($r); |
return OK if (! defined($query)); |
return OK if (! defined($query)); |
} |
} |
|
# Output some information to the user. |
|
$r->print(&search_results_header($searchtype)); |
|
$r->print("Sending search request to LON-CAPA servers.<br />\n"); |
|
$r->rflush(); |
# Send query statements over the network to be processed by |
# Send query statements over the network to be processed by |
# either the SQL database or a recursive scheme of 'grep'-like |
# either the SQL database or a recursive scheme of 'grep'-like |
# actions (for custom metadata). |
# actions (for custom metadata). |
$r->rflush(); |
|
my $reply=&Apache::lonnet::metadata_query($query,$customquery, |
my $reply=&Apache::lonnet::metadata_query($query,$customquery, |
$customshow,$libraries); |
$customshow,$libraries); |
|
$r->rflush(); |
&output_results($searchtype,$r,$reply,$hidden); |
&output_results($searchtype,$r,$reply,$hidden); |
} else { |
} else { |
# |
# |
Line 397 ENDHEADER
|
Line 401 ENDHEADER
|
$ENV{'form.viewselect'}, |
$ENV{'form.viewselect'}, |
undef,undef,undef, |
undef,undef,undef, |
sort(keys(%Views))); |
sort(keys(%Views))); |
$scrout.="</td></tr>\n"; |
$scrout.="</td><td>Related<br />Words</td></tr>\n"; |
$scrout.=&searchphrasefield('title', 'title' ,$ENV{'form.title'}); |
$scrout.=&searchphrasefield_with_related('title', 'title' , |
|
$ENV{'form.title'}); |
$scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'}); |
$scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'}); |
$scrout.=&searchphrasefield('subject', 'subject' ,$ENV{'form.subject'}); |
$scrout.=&searchphrasefield_with_related('subject', 'subject' , |
$scrout.=&searchphrasefield('keywords','keywords',$ENV{'form.keywords'}); |
$ENV{'form.subject'}); |
|
$scrout.=&searchphrasefield_with_related('keywords','keywords', |
|
$ENV{'form.keywords'}); |
$scrout.=&searchphrasefield('URL', 'url' ,$ENV{'form.url'}); |
$scrout.=&searchphrasefield('URL', 'url' ,$ENV{'form.url'}); |
$scrout.=&searchphrasefield('notes', 'notes' ,$ENV{'form.notes'}); |
$scrout.=&searchphrasefield_with_related('notes', 'notes' , |
$scrout.=&searchphrasefield('abstract','abstract',$ENV{'form.abstract'}); |
$ENV{'form.notes'}); |
|
$scrout.=&searchphrasefield_with_related('abstract','abstract', |
|
$ENV{'form.abstract'}); |
# Hack - an empty table row. |
# Hack - an empty table row. |
$scrout.="<tr><td> </td><td> </td></tr>\n"; |
$scrout.="<tr><td> </td><td> </td><td> </td></tr>\n"; |
$scrout.=&searchphrasefield('file<br />extension','mime', |
$scrout.=&searchphrasefield('file<br />extension','mime', |
$ENV{'form.mime'}); |
$ENV{'form.mime'}); |
$scrout.="<tr><td> </td><td> </td></tr>\n"; |
$scrout.="<tr><td> </td><td> </td><td> </td></tr>\n"; |
$scrout.=&searchphrasefield('publisher<br />owner','owner', |
$scrout.=&searchphrasefield('publisher<br />owner','owner', |
$ENV{'form.owner'}); |
$ENV{'form.owner'}); |
$scrout.="</table>\n"; |
$scrout.="</table>\n"; |
Line 568 END
|
Line 577 END
|
return $persistent; |
return $persistent; |
} |
} |
|
|
|
|
###################################################################### |
###################################################################### |
|
# HTML form building functions # |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
Line 578 END
|
Line 587 END
|
|
|
=over 4 |
=over 4 |
|
|
|
=cut |
|
|
|
############################################### |
|
############################################### |
|
|
|
=pod |
|
|
=item &simpletextfield() |
=item &simpletextfield() |
|
|
Inputs: $name,$value,$size |
Inputs: $name,$value,$size |
Line 585 Inputs: $name,$value,$size
|
Line 601 Inputs: $name,$value,$size
|
Returns a text input field with the given name, value, and size. |
Returns a text input field with the given name, value, and size. |
If size is not specified, a value of 20 is used. |
If size is not specified, a value of 20 is used. |
|
|
|
=cut |
|
|
|
############################################### |
|
############################################### |
|
|
|
sub simpletextfield { |
|
my ($name,$value,$size)=@_; |
|
$size = 20 if (! defined($size)); |
|
return '<input type="text" name="'.$name. |
|
'" size="'.$size.'" value="'.$value.'" />'; |
|
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=pod |
|
|
=item &simplecheckbox() |
=item &simplecheckbox() |
|
|
Inputs: $name,$value |
Inputs: $name,$value |
Line 592 Inputs: $name,$value
|
Line 625 Inputs: $name,$value
|
Returns a simple check box with the given $name. |
Returns a simple check box with the given $name. |
If $value eq 'on' the box is checked. |
If $value eq 'on' the box is checked. |
|
|
=item &searchphrasefield() |
=cut |
|
|
Inputs: $title,$name,$value |
############################################### |
|
############################################### |
|
|
Returns html for a title line and an input field for entering search terms. |
sub simplecheckbox { |
the instructions "Enter terms or phrases separated by search operators such |
my ($name,$value)=@_; |
as AND, OR, or NOT." are given following the title. The entry field (which |
my $checked=''; |
is where the $name and $value are used) is an 80 column simpletextfield. |
$checked="checked" if $value eq 'on'; |
|
return '<input type="checkbox" name="'.$name.'" '. $checked . ' />'; |
|
} |
|
|
=item &dateboxes() |
############################################### |
|
############################################### |
|
|
Returns html selection form elements for the specification of |
=pod |
the day, month, and year. |
|
|
|
=item &selectbox() |
=item &fieldtitle() |
|
|
Returns a scalar containing an html <select> form. |
Input: $title |
|
|
Inputs: |
Returns a scalar with html which will display $title as a search |
|
field heading. |
|
|
=over 4 |
=cut |
|
|
=item $title |
############################################### |
|
############################################### |
|
|
Printed above the select box, in uppercase. If undefined, only a select |
sub fieldtitle { |
box will be returned, with no additional html. |
my $title = uc(shift()); |
|
return '<font color="#800000" face="helvetica"><b>'.$title. |
|
': </b></font>'; |
|
} |
|
|
=item $name |
############################################### |
|
############################################### |
|
|
The name element of the <select> tag. |
=pod |
|
|
=item $default |
=item &searchphrasefield() |
|
|
The default value of the form. Can be $anyvalue, or in @idlist. |
Inputs: $title,$name,$value |
|
|
=item $anyvalue |
Returns html for a title line and an input field for entering search terms. |
|
The entry field (which is where the $name and $value are used) is a 50 column |
|
simpletextfield. The html returned is for a row in a three column table. |
|
|
The <option value="..."> used to indicate a default of |
=cut |
none of the values. Can be undef. |
|
|
|
=item $anytag |
############################################### |
|
############################################### |
|
|
|
sub searchphrasefield { |
|
my ($title,$name,$value)=@_; |
|
return '<tr><td>'.&fieldtitle($title).'</td><td>'. |
|
&simpletextfield($name,$value,50)."</td><td> </td></tr>\n"; |
|
} |
|
|
The text associate with $anyvalue above. |
############################################### |
|
############################################### |
|
|
=item $functionref |
=pod |
|
|
Each element in @idlist will be passed as a parameter |
=item &searchphrasefield_with_related() |
to the function referenced here. The return value of the function should |
|
be a scalar description of the items. If this value is undefined the |
|
description of each item in @idlist will be the item name. |
|
|
|
=item @idlist |
Inputs: $title,$name,$value |
|
|
The items to be selected from. One of these or $anyvalue will be the |
Returns html for a title line and an input field for entering search terms |
value returned by the form element, $ENV{form.$name}. |
and a check box for 'related words'. The entry field (which is where the |
|
$name and $value are used) is a 50 column simpletextfield. The name of |
|
the related words checkbox is "$name_related". |
|
|
=back |
=cut |
|
|
=back |
############################################### |
|
############################################### |
|
|
|
sub searchphrasefield_with_related { |
|
my ($title,$name,$value)=@_; |
|
return '<tr><td>'.&fieldtitle($title).'</td><td>'. |
|
&simpletextfield($name,$value,50).'</td><td align="center"> '. |
|
&simplecheckbox($name.'_related',$ENV{'form.'.$name.'_related'}). |
|
" </td></tr>\n"; |
|
} |
|
|
=cut |
############################################### |
|
############################################### |
|
|
###################################################################### |
=pod |
###################################################################### |
|
|
|
sub simpletextfield { |
=item &dateboxes() |
my ($name,$value,$size)=@_; |
|
$size = 20 if (! defined($size)); |
|
return '<input type="text" name="'.$name. |
|
'" size="'.$size.'" value="'.$value.'" />'; |
|
} |
|
|
|
sub simplecheckbox { |
Returns html selection form elements for the specification of |
my ($name,$value)=@_; |
the day, month, and year. |
my $checked=''; |
|
$checked="checked" if $value eq 'on'; |
|
return '<input type="checkbox" name="'.$name.'" '. $checked . ' />'; |
|
} |
|
|
|
sub searchphrasefield { |
=cut |
my ($title,$name,$value)=@_; |
|
my $uctitle=uc($title); |
############################################### |
return '<tr><td><font color="#800000" face="helvetica">'. |
############################################### |
'<b>'.$uctitle.': </b></font></td><td>'. |
|
&simpletextfield($name,$value,50)."</td></tr>\n"; |
|
} |
|
|
|
sub dateboxes { |
sub dateboxes { |
my ($name,$defaultmonth,$defaultday,$defaultyear, |
my ($name,$defaultmonth,$defaultday,$defaultyear, |
Line 723 END
|
Line 770 END
|
return "$month$day$year"; |
return "$month$day$year"; |
} |
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=pod |
|
|
|
=item &selectbox() |
|
|
|
Returns a scalar containing an html <select> form. |
|
|
|
Inputs: |
|
|
|
=over 4 |
|
|
|
=item $title |
|
|
|
Printed above the select box, in uppercase. If undefined, only a select |
|
box will be returned, with no additional html. |
|
|
|
=item $name |
|
|
|
The name element of the <select> tag. |
|
|
|
=item $default |
|
|
|
The default value of the form. Can be $anyvalue, or in @idlist. |
|
|
|
=item $anyvalue |
|
|
|
The <option value="..."> used to indicate a default of |
|
none of the values. Can be undef. |
|
|
|
=item $anytag |
|
|
|
The text associate with $anyvalue above. |
|
|
|
=item $functionref |
|
|
|
Each element in @idlist will be passed as a parameter |
|
to the function referenced here. The return value of the function should |
|
be a scalar description of the items. If this value is undefined the |
|
description of each item in @idlist will be the item name. |
|
|
|
=item @idlist |
|
|
|
The items to be selected from. One of these or $anyvalue will be the |
|
value returned by the form element, $ENV{form.$name}. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
############################################### |
|
|
sub selectbox { |
sub selectbox { |
my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_; |
my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_; |
if (! defined($functionref)) { $functionref = sub { $_[0]}; } |
if (! defined($functionref)) { $functionref = sub { $_[0]}; } |
Line 748 sub selectbox {
|
Line 848 sub selectbox {
|
} |
} |
|
|
###################################################################### |
###################################################################### |
|
# End of HTML form building functions # |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=back |
|
|
|
=cut |
|
|
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
Line 818 sub parse_advanced_search {
|
Line 929 sub parse_advanced_search {
|
foreach my $field ('title','author','subject','notes','abstract','url', |
foreach my $field ('title','author','subject','notes','abstract','url', |
'keywords','version','owner','mime') { |
'keywords','version','owner','mime') { |
if ($ENV{'form.'.$field}) { |
if ($ENV{'form.'.$field}) { |
push @queries,&build_SQL_query($field,$ENV{'form.'.$field}); |
my $searchphrase = $ENV{'form.'.$field}; |
|
if ($ENV{'form.'.$field.'_related'}) { |
|
$searchphrase = &related_version($searchphrase); |
|
$ENV{'form.'.$field} = $searchphrase; |
|
$ENV{'form.'.$field.'_related'} = undef; |
|
} |
|
push @queries,&build_SQL_query($field,$searchphrase); |
} |
} |
} |
} |
# I dislike the hack below. |
# I dislike the hack below. |
Line 930 sub parse_basic_search {
|
Line 1047 sub parse_basic_search {
|
&output_blank_field_error($r); |
&output_blank_field_error($r); |
return OK; |
return OK; |
} |
} |
|
my $search_string = $ENV{'form.basicexp'}; |
if ($ENV{'form.related'}) { |
if ($ENV{'form.related'}) { |
my $tmp = $ENV{'form.basicexp'}; |
$search_string = &related_version($ENV{'form.basicexp'}); |
while ($ENV{'form.basicexp'} =~ /(\w+)/cg) { |
|
my $word = $1; |
|
my @Words = &Apache::loncommon::get_related_words($word); |
|
my $replacement = join " OR ", ($word, |
|
($#Words>4? @Words[0..4] : @Words) |
|
); |
|
$tmp =~ s/\b$word\b/ $replacement /g; |
|
} |
|
$ENV{'form.basicexp'} = $tmp; |
|
} |
} |
# Build SQL query string based on form page |
# Build SQL query string based on form page |
my $query=''; |
my $query=''; |
Line 948 sub parse_basic_search {
|
Line 1057 sub parse_basic_search {
|
('title', 'author', 'subject', 'notes', 'abstract', |
('title', 'author', 'subject', 'notes', 'abstract', |
'keywords')); |
'keywords')); |
$concatarg='title' if $ENV{'form.titleonly'}; |
$concatarg='title' if $ENV{'form.titleonly'}; |
|
$query=&build_SQL_query('concat('.$concatarg.')',$search_string); |
$query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'}); |
|
return 'select * from metadata where '.$query; |
return 'select * from metadata where '.$query; |
} |
} |
|
|
Line 959 sub parse_basic_search {
|
Line 1067 sub parse_basic_search {
|
|
|
=pod |
=pod |
|
|
|
=item &related_version |
|
|
|
Modifies an input string to include related words. Words in the string |
|
are replaced with parenthesized lists of 'OR'd words. For example |
|
"torque" is replaced with "(torque OR word1 OR word2 OR ...)". |
|
|
|
Note: Using this twice on a string is probably silly. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub related_version { |
|
my $search_string = shift; |
|
my $result = $search_string; |
|
while ($search_string =~ /(\w+)/cg) { |
|
my $word = $1; |
|
next if (lc($word) =~ /\b(or|and|not)\b/); |
|
my @Words = &Apache::loncommon::get_related_words($word); |
|
my $replacement = join " OR ", ($word, |
|
($#Words>4? @Words[0..4] : @Words) |
|
); |
|
$result =~ s/(\b)$word(\b)/$1($replacement)$2/g; |
|
} |
|
return $result; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
=item &build_SQL_query() |
=item &build_SQL_query() |
|
|
Builds a SQL query string from a logical expression with AND/OR keywords |
Builds a SQL query string from a logical expression with AND/OR keywords |
Line 1161 sub output_results {
|
Line 1301 sub output_results {
|
my $persistent=&make_persistent(\%ENV); |
my $persistent=&make_persistent(\%ENV); |
# |
# |
# Begin producing output |
# Begin producing output |
$r->print(&search_results_header($mode)); |
|
$r->rflush(); |
$r->rflush(); |
# |
# |
# begin showing the cataloged results |
# begin showing the cataloged results |
Line 1264 CATALOGCONTROLS
|
Line 1403 CATALOGCONTROLS
|
&handle_custom_fields(\@results); |
&handle_custom_fields(\@results); |
my @customfields = @$customfields; |
my @customfields = @$customfields; |
my %customhash = %$customhash; |
my %customhash = %$customhash; |
untie %hash if (keys %hash); |
untie %groupsearch_db if (tied %groupsearch_db); |
# |
# |
if (! tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
if (! tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) { |
$r->print('<html><head></head><body>Unable to tie hash to db '. |
$r->print('<html><head></head><body>Unable to tie hash to db '. |
'file</body></html>'); |
'file</body></html>'); |
} else { |
} else { |
Line 1314 END
|
Line 1453 END
|
} |
} |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
$fnum+=0; |
$fnum+=0; |
$hash{"pre_${fnum}_link"}=$Fields{'url'}; |
$groupsearch_db{"pre_${fnum}_link"}=$Fields{'url'}; |
$hash{"pre_${fnum}_title"}=$Fields{'title'}; |
$groupsearch_db{"pre_${fnum}_title"}=$Fields{'title'}; |
$compiledresult.=<<END; |
$compiledresult.=<<END; |
<font size='-1'> |
<font size='-1'> |
<input type="checkbox" name="returnvalues" value="SELECT" |
<input type="checkbox" name="returnvalues" value="SELECT" |
Line 1333 END
|
Line 1472 END
|
$compiledresult.="<hr align='left' width='200' noshade />"; |
$compiledresult.="<hr align='left' width='200' noshade />"; |
} |
} |
} |
} |
untie %hash; |
untie %groupsearch_db; |
} |
} |
if ($compiledresult) { |
if ($compiledresult) { |
$resultflag=1; |
$resultflag=1; |
Line 1982 RESULTS
|
Line 2121 RESULTS
|
|
|
=item &start_fresh_session() |
=item &start_fresh_session() |
|
|
Cleans the global %hash by removing all fields which begin with |
Cleans the global %groupsearch_db by removing all fields which begin with |
'pre_' or 'store'. |
'pre_' or 'store'. |
|
|
=cut |
=cut |
Line 1990 Cleans the global %hash by removing all
|
Line 2129 Cleans the global %hash by removing all
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub start_fresh_session { |
sub start_fresh_session { |
delete $hash{'mode_catalog'}; |
delete $groupsearch_db{'mode_catalog'}; |
foreach (keys %hash) { |
foreach (keys %groupsearch_db) { |
if ($_ =~ /^pre_/) { |
if ($_ =~ /^pre_/) { |
delete $hash{$_}; |
delete $groupsearch_db{$_}; |
} |
} |
if ($_ =~ /^store/) { |
if ($_ =~ /^store/) { |
delete $hash{$_}; |
delete $groupsearch_db{$_}; |
} |
} |
} |
} |
} |
} |