--- loncom/interface/lonsearchcat.pm 2002/07/05 18:56:52 1.136 +++ loncom/interface/lonsearchcat.pm 2002/07/12 14:36:16 1.141 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.136 2002/07/05 18:56:52 matthew Exp $ +# $Id: lonsearchcat.pm,v 1.141 2002/07/12 14:36:16 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -40,7 +40,7 @@ =head1 NAME -lonsearchcat +lonsearchcat - LONCAPA Search Interface =head1 SYNOPSIS @@ -118,6 +118,13 @@ The ubiquitous database hash The full path to the (temporary) search database file. This is set and used in &handler() and is also used in &output_results(). +=item %Views + +Hash which associates an output view description with the function +that produces it. Adding a new view type should be as easy as +adding a line to the definition of this hash and making sure the function +takes the proper parameters. + =back =cut @@ -133,6 +140,12 @@ my $importbutton; # button to take the s my %hash; # database hash my $diropendb = ""; # db file +# View Description Function Pointer +my %Views = ("Detailed Citation View" => \&detailed_citation_view, + "Summary View" => \&summary_view, + "Fielded Format" => \&fielded_format_view, + "XML/SGML" => \&xml_sgml_view ); + ###################################################################### ###################################################################### @@ -223,6 +236,7 @@ END $searchtype = 'Basic' if ($ENV{'form.basicsubmit'} eq 'SEARCH'); $searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH'); if ($searchtype) { + # We are running a search my ($query,$customquery,$customshow,$libraries) = (undef,undef,undef,undef); if ($searchtype eq 'Basic') { @@ -239,12 +253,21 @@ END my $reply=&Apache::lonnet::metadata_query($query,$customquery, $customshow,$libraries); &output_results($searchtype,$r,$reply,$hidden); - } elsif ($ENV{'form.reqinterface'} eq 'advanced') { + } else { + # + # We need to get information to search on + # + # Set the default view if it is not already set. + if (!defined($ENV{'form.viewselect'})) { + $ENV{'form.viewselect'} ="Detailed Citation View"; + } # Output the advanced interface - $r->print(&advanced_search_form($closebutton,$hidden)); - } else { - # Output normal search interface - $r->print(&basic_search_form($closebutton,$hidden)); + if ($ENV{'form.reqinterface'} eq 'advanced') { + $r->print(&advanced_search_form($closebutton,$hidden)); + } else { + # Output normal search interface + $r->print(&basic_search_form($closebutton,$hidden)); + } } return OK; } @@ -295,20 +318,21 @@ ENDDOCUMENT ' '; # $scrout.=&simplecheckbox('allversions',$ENV{'form.allversions'}); # $scrout.='Search historic archives'; - $scrout.=<Advanced Search + my $checkbox = &simplecheckbox('related',$ENV{'form.related'}); + $scrout.=<Advanced Search +$checkbox use related words +

   $closebutton - - - +END + $scrout.=&selectbox(undef,'viewselect', + $ENV{'form.viewselect'}, + undef,undef,undef, + sort(keys(%Views))); + $scrout.=<

@@ -341,6 +365,9 @@ $closebutton

END + if (!defined($ENV{'form.viewselect'})) { + $ENV{'form.viewselect'} ="Detailed Citation View"; + } my $scrout=<<"ENDHEADER"; @@ -365,16 +392,12 @@ $hidden ENDHEADER + $scrout.=&selectbox(undef,'viewselect', + $ENV{'form.viewselect'}, + undef,undef,undef, + sort(keys(%Views))); + $scrout.="\n"; $scrout.=&searchphrasefield('title', 'title' ,$ENV{'form.title'}); $scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'}); $scrout.=&searchphrasefield('subject', 'subject' ,$ENV{'form.subject'}); @@ -593,7 +616,8 @@ Inputs: =item $title -Printed above the select box, in uppercase. +Printed above the select box, in uppercase. If undefined, only a select +box will be returned, with no additional html. =item $name @@ -601,12 +625,12 @@ The name element of the '; - foreach ($anyvalue,@idlist) { + my $selout=''; + if (defined($title)) { + my $uctitle=uc($title); + $selout="\n".'

'. + ''.$uctitle.': '; + } + $selout .= '

'; + return $selout.''.(defined($title)?'

':' '); } ###################################################################### @@ -901,7 +930,18 @@ sub parse_basic_search { &output_blank_field_error($r); return OK; } - + if ($ENV{'form.related'}) { + my $tmp = $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 my $query=''; my $concatarg=join('," ",', @@ -1110,16 +1150,7 @@ sub output_results { ## ## Set viewing function ## - my $viewfunction = undef; - if ($ENV{'form.viewselect'} eq 'Detailed Citation View') { - $viewfunction = \&detailed_citation_view; - } elsif ($ENV{'form.viewselect'} eq 'Summary View') { - $viewfunction = \&summary_view; - } elsif ($ENV{'form.viewselect'} eq 'Fielded Format') { - $viewfunction = \&fielded_format_view; - } elsif ($ENV{'form.viewselect'} eq 'XML/SGML') { - $viewfunction = \&xml_sgml_view; - } + my $viewfunction = $Views{$ENV{'form.viewselect'}}; if (!defined($viewfunction)) { $r->print("Internal Error - Bad view selected.\n"); $r->rflush(); @@ -1247,6 +1278,21 @@ CATALOGCONTROLS chomp $result; next unless $result; %Fields = &parse_raw_result($result,$rkey); + # + # Check copyright tags and skip results the user cannot use + my (undef,undef,$resdom,$resname) = split('/',$Fields{'url'}); + # Check for priv + if (($Fields{'copyright'} eq 'priv') && + (($ENV{'user.name'} ne $resname) && + ($ENV{'user.domain'} ne $resdom))) { + next; + } + # Check for domain + if (($Fields{'copyright'} eq 'domain') && + ($ENV{'user.domain'} ne $resdom)) { + next; + } + # $Fields{'extrashow'}=$extrashow; if ($extrashow) { foreach my $field (@customfields) {
VIEW: - - - -