--- loncom/interface/lonsearchcat.pm 2005/04/01 19:57:23 1.242 +++ loncom/interface/lonsearchcat.pm 2005/04/07 06:56:23 1.243 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.242 2005/04/01 19:57:23 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.243 2005/04/07 06:56:23 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -63,7 +63,7 @@ package Apache::lonsearchcat; use strict; use Apache::Constants qw(:common :http); -use Apache::lonnet(); +use Apache::lonnet; use Apache::File(); use CGI qw(:standard); use Text::Query; @@ -144,54 +144,54 @@ sub handler { ## printing the results. We only need (theoretically) to do ## this once, so the pause indicator is deleted ## - if (exists($ENV{'form.pause'})) { + if (exists($env{'form.pause'})) { sleep(1); - delete($ENV{'form.pause'}); + delete($env{'form.pause'}); } ## ## Initialize global variables ## my $domain = $r->dir_config('lonDefDomain'); $diropendb= "/home/httpd/perl/tmp/". - "$ENV{'user.domain'}_$ENV{'user.name'}_searchcat.db"; + "$env{'user.domain'}_$env{'user.name'}_searchcat.db"; # # set the name of the persistent database - # $ENV{'form.persistent_db_id'} can only have digits in it. - if (! exists($ENV{'form.persistent_db_id'}) || - ($ENV{'form.persistent_db_id'} =~ /\D/) || - ($ENV{'form.launch'} eq '1')) { - $ENV{'form.persistent_db_id'} = time; + # $env{'form.persistent_db_id'} can only have digits in it. + if (! exists($env{'form.persistent_db_id'}) || + ($env{'form.persistent_db_id'} =~ /\D/) || + ($env{'form.launch'} eq '1')) { + $env{'form.persistent_db_id'} = time; } $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); my $persistent_db_file = "/home/httpd/perl/tmp/". &Apache::lonnet::escape($domain). - '_'.&Apache::lonnet::escape($ENV{'user.name'}). - '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db'; + '_'.&Apache::lonnet::escape($env{'user.name'}). + '_'.$env{'form.persistent_db_id'}.'_persistent_search.db'; ## &Apache::lonhtmlcommon::clear_breadcrumbs(); - if (exists($ENV{'request.course.id'}) && $ENV{'request.course.id'} ne '') { + if (exists($env{'request.course.id'}) && $env{'request.course.id'} ne '') { &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. - 'catalogmode='.$ENV{'form.catalogmode'}. - '&launch='.$ENV{'form.launch'}. - '&mode='.$ENV{'form.mode'}, + 'catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"Course and Catalog Search", target=>'_top', bug=>'Searching',}); } else { &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?'. - 'catalogmode='.$ENV{'form.catalogmode'}. - '&launch='.$ENV{'form.launch'}. - '&mode='.$ENV{'form.mode'}, + 'catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"Catalog Search", target=>'_top', bug=>'Searching',}); } # - if ($ENV{'form.phase'} !~ m/(basic|adv|course)_search/) { + if ($env{'form.phase'} !~ m/(basic|adv|course)_search/) { if (! &get_persistent_form_data($persistent_db_file)) { - if ($ENV{'form.phase'} =~ /(run_search|results)/) { + if ($env{'form.phase'} =~ /(run_search|results)/) { &Apache::lonnet::logthis('lonsearchcat:'. 'Unable to recover data from '. $persistent_db_file); @@ -216,13 +216,13 @@ END ## Clear out old values from groupsearch database ## untie %groupsearch_db if (tied(%groupsearch_db)); - if (($ENV{'form.cleargroupsort'} eq '1') || - (($ENV{'form.launch'} eq '1') && - ($ENV{'form.catalogmode'} eq 'groupsearch'))) { + if (($env{'form.cleargroupsort'} eq '1') || + (($env{'form.launch'} eq '1') && + ($env{'form.catalogmode'} eq 'groupsearch'))) { if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) { &start_fresh_session(); untie %groupsearch_db; - delete($ENV{'form.cleargroupsort'}); + delete($env{'form.cleargroupsort'}); } else { # This is a stupid error to give to the user. # It really tells them nothing. @@ -236,36 +236,36 @@ END ## Configure hidden fields ## $hidden_fields = ''."\n"; - if (exists($ENV{'form.catalogmode'})) { + $env{'form.persistent_db_id'}.'" />'."\n"; + if (exists($env{'form.catalogmode'})) { $hidden_fields .= &hidden_field('catalogmode'); } - if (exists($ENV{'form.form'})) { + if (exists($env{'form.form'})) { $hidden_fields .= &hidden_field('form'); } - if (exists($ENV{'form.element'})) { + if (exists($env{'form.element'})) { $hidden_fields .= &hidden_field('element'); } - if (exists($ENV{'form.titleelement'})) { + if (exists($env{'form.titleelement'})) { $hidden_fields .= &hidden_field('titleelement'); } - if (exists($ENV{'form.mode'})) { + if (exists($env{'form.mode'})) { $hidden_fields .= &hidden_field('mode'); } ## ## Configure dynamic components of interface ## - if ($ENV{'form.catalogmode'} eq 'interactive') { + if ($env{'form.catalogmode'} eq 'interactive') { $closebutton="'/adm/searchcat?phase=disp_adv&'. - 'catalogmode='.$ENV{'form.catalogmode'}. - '&launch='.$ENV{'form.launch'}. - '&mode='.$ENV{'form.mode'}, + 'catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"Advanced Search", bug=>'Searching',}); - } elsif ($ENV{'form.searchmode'} eq 'course search') { + } elsif ($env{'form.searchmode'} eq 'course search') { &Apache::lonhtmlcommon::add_breadcrumb ({href=>'/adm/searchcat?phase=disp_adv&'. - 'catalogmode='.$ENV{'form.catalogmode'}. - '&launch='.$ENV{'form.launch'}. - '&mode='.$ENV{'form.mode'}, + 'catalogmode='.$env{'form.catalogmode'}. + '&launch='.$env{'form.launch'}. + '&mode='.$env{'form.mode'}, text=>"Course Search", bug=>'Searching',}); } ## ## Switch on the phase ## - if ($ENV{'form.phase'} eq 'disp_basic') { + if ($env{'form.phase'} eq 'disp_basic') { &print_basic_search_form($r,$closebutton,$hidden_fields); - } elsif ($ENV{'form.phase'} eq 'disp_adv') { + } elsif ($env{'form.phase'} eq 'disp_adv') { &print_advanced_search_form($r,$closebutton,$hidden_fields); - } elsif ($ENV{'form.phase'} eq 'results') { + } elsif ($env{'form.phase'} eq 'results') { &display_results($r,$importbutton,$closebutton,$diropendb); - } elsif ($ENV{'form.phase'} =~ /^(sort|run_search)$/) { + } elsif ($env{'form.phase'} =~ /^(sort|run_search)$/) { my ($query,$customquery,$customshow,$libraries,$pretty_string) = &get_persistent_data($persistent_db_file, ['query','customquery','customshow', 'libraries','pretty_string']); - if ($ENV{'form.phase'} eq 'sort') { + if ($env{'form.phase'} eq 'sort') { &print_sort_form($r,$pretty_string); - } elsif ($ENV{'form.phase'} eq 'run_search') { + } elsif ($env{'form.phase'} eq 'run_search') { &run_search($r,$query,$customquery,$customshow, $libraries,$pretty_string); } - } elsif ($ENV{'form.phase'} eq 'course_search') { + } elsif ($env{'form.phase'} eq 'course_search') { &course_search($r); - } elsif(($ENV{'form.phase'} eq 'basic_search') || - ($ENV{'form.phase'} eq 'adv_search')) { + } elsif(($env{'form.phase'} eq 'basic_search') || + ($env{'form.phase'} eq 'adv_search')) { # # We are running a search, try to parse it my ($query,$customquery,$customshow,$libraries) = (undef,undef,undef,undef); my $pretty_string; - if ($ENV{'form.phase'} eq 'basic_search') { + if ($env{'form.phase'} eq 'basic_search') { ($query,$pretty_string,$libraries) = &parse_basic_search($r,$closebutton,$hidden_fields); return OK if (! defined($query)); - &make_persistent({ basicexp => $ENV{'form.basicexp'}}, + &make_persistent({ basicexp => $env{'form.basicexp'}}, $persistent_db_file); } else { # Advanced search ($query,$customquery,$customshow,$libraries,$pretty_string) @@ -384,7 +384,7 @@ The search has been aborted. END return OK; } - delete($ENV{'form.launch'}); + delete($env{'form.launch'}); if (! &make_form_data_persistent($r,$persistent_db_file)) { my $html=&Apache::lonxml::xmlbegin(); $r->print(<'.$/; } @@ -470,20 +470,20 @@ sub make_symb { sub course_search { my $r=shift; my $bodytag=&Apache::loncommon::bodytag('Course Search'); - my $pretty_search_string = ''.$ENV{'form.courseexp'}.''; - my $search_string = $ENV{'form.courseexp'}; + my $pretty_search_string = ''.$env{'form.courseexp'}.''; + my $search_string = $env{'form.courseexp'}; my @New_Words; undef(%alreadyseen); - if ($ENV{'form.crsrelated'}) { - ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'}); + if ($env{'form.crsrelated'}) { + ($search_string,@New_Words) = &related_version($env{'form.courseexp'}); if (@New_Words) { $pretty_search_string .= ' '.&mt("with related words").": @New_Words."; } else { $pretty_search_string .= ' '.&mt('with no related words')."."; } } - my $fulltext=$ENV{'form.crsfulltext'}; - my $discuss=$ENV{'form.crsdiscuss'}; + my $fulltext=$env{'form.crsfulltext'}; + my $discuss=$env{'form.crsdiscuss'}; my @allwords=($search_string,@New_Words); $totalfound=0; my $html=&Apache::lonxml::xmlbegin(); @@ -492,12 +492,12 @@ sub course_search { $r->rflush(); # ======================================================= Go through the course my $c=$r->connection; - if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db", + if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db", &GDBM_READER(),0640)) { foreach (sort(keys(%hash))) { if ($c->aborted()) { last; } if (($_=~/^src\_(.+)$/)) { - if ($hash{'randomout_'.$1} & !$ENV{'request.role.adv'}) { + if ($hash{'randomout_'.$1} & !$env{'request.role.adv'}) { next; } my $symb=&make_symb($1); @@ -518,8 +518,8 @@ sub course_search { my $navmap = Apache::lonnavmaps::navmap->new(); my @allres=$navmap->retrieveResources(); my %discussiontime = &Apache::lonnet::dump('discussiontimes', - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); foreach my $resource (@allres) { my $result = ''; my $applies = 0; @@ -532,9 +532,9 @@ sub course_search { } } if (defined($discussiontime{$ressymb})) { - my %contrib = &Apache::lonnet::restore($ressymb,$ENV{'request.course.id'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, - $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my %contrib = &Apache::lonnet::restore($ressymb,$env{'request.course.id'}, + $env{'course.'.$env{'request.course.id'}.'.domain'}, + $env{'course.'.$env{'request.course.id'}.'.num'}); if ($contrib{'version'}) { for (my $id=1;$id<=$contrib{'version'};$id++) { unless (($contrib{'hidden'}=~/\.$id\./) || ($contrib{'deleted'}=~/\.$id\./)) { @@ -598,7 +598,7 @@ sub checkonthis { $r->rflush(); my $result=$title.' '; - if ($ENV{'request.role.adv'} || !$hash{'encrypted_'.$id}) { + if ($env{'request.role.adv'} || !$hash{'encrypted_'.$id}) { $result.=&Apache::lonnet::metadata($url,'title').' '. &Apache::lonnet::metadata($url,'subject').' '. &Apache::lonnet::metadata($url,'abstract').' '. @@ -619,7 +619,7 @@ sub checkonthis { $r->print(' '); } my $href=$url; - if ($hash{'encrypted_'.$id} && !$ENV{'request.role.adv'}) { + if ($hash{'encrypted_'.$id} && !$env{'request.role.adv'}) { $href=&Apache::lonenc::encrypted($href) .'?symb='.&Apache::lonenc::encrypted($symb); } else { @@ -688,22 +688,22 @@ Prints the form for the basic search. S ###################################################################### sub print_basic_search_form { my ($r,$closebutton,$hidden_fields) = @_; - my $result = ($ENV{'form.catalogmode'} ne 'groupsearch'); + my $result = ($env{'form.catalogmode'} ne 'groupsearch'); my $bodytag=&Apache::loncommon::bodytag('Search'). &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Search_Basic', undef,undef, - $ENV{'form.catalogmode'} ne 'groupsearch'); + $env{'form.catalogmode'} ne 'groupsearch'); my $scrout = &search_html_header().$bodytag; - if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { + if (&Apache::lonnet::allowed('bre',$env{'request.role.domain'})) { # Define interface components my $userelatedwords= ''; + ('related',$env{'form.related'},'related')).''; my $onlysearchdomain='