--- loncom/interface/lonsearchcat.pm 2005/02/02 22:02:41 1.237 +++ loncom/interface/lonsearchcat.pm 2005/04/01 19:57:23 1.242 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.237 2005/02/02 22:02:41 albertel Exp $ +# $Id: lonsearchcat.pm,v 1.242 2005/04/01 19:57:23 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -195,9 +195,11 @@ sub handler { &Apache::lonnet::logthis('lonsearchcat:'. 'Unable to recover data from '. $persistent_db_file); - $r->print(< -LON-CAPA Search Error + my $html=&Apache::lonxml::xmlbegin(); + $r->print(< +LON-CAPA Search Error $bodytag We were unable to retrieve data describing your search. This is a serious error and has been logged. Please alert your LON-CAPA administrator. @@ -224,7 +226,8 @@ END } else { # This is a stupid error to give to the user. # It really tells them nothing. - $r->print(''.$bodytag. + my $html=&Apache::lonxml::xmlbegin(); + $r->print($html.''.$bodytag. 'Unable to tie hash to db file'); return OK; } @@ -368,8 +371,11 @@ END &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '. 'needed table. lonmysql error:'. $errorstring); + my $html=&Apache::lonxml::xmlbegin(); $r->print(<Search Error +$html + +Search Error $bodytag Unable to create table in which to store search results. The search has been aborted. @@ -380,8 +386,11 @@ END } delete($ENV{'form.launch'}); if (! &make_form_data_persistent($r,$persistent_db_file)) { - $r->print(<Search Error + my $html=&Apache::lonxml::xmlbegin(); + $r->print(< +Search Error $bodytag Unable to properly store search information. The search has been aborted. @@ -477,7 +486,8 @@ sub course_search { my $discuss=$ENV{'form.crsdiscuss'}; my @allwords=($search_string,@New_Words); $totalfound=0; - $r->print('LON-CAPA Course Search'. + my $html=&Apache::lonxml::xmlbegin(); + $r->print($html.'LON-CAPA Course Search'. $bodytag.'
'.$pretty_search_string.'

'.&mt('Course content').':
'); $r->rflush(); # ======================================================= Go through the course @@ -653,8 +663,9 @@ sub untiehash { } # End of course search scoping sub search_html_header { + my $html=&Apache::lonxml::xmlbegin(); my $Str = < +$html The LearningOnline Network with CAPA @@ -1524,8 +1535,9 @@ sub parse_advanced_search { ## ## Deal with restrictions to given domains ## - my ($libraries_to_query,$pretty_domains_string) = + my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = &parse_domain_restrictions(); + push(@queries,$domain_sql_restriction); $pretty_search_string .= $pretty_domains_string."
\n"; # if (@queries) { @@ -1533,7 +1545,7 @@ sub parse_advanced_search { } elsif ($customquery) { $query = ''; } - # &Apache::lonnet::logthis('query = '.$/.$query); + #&Apache::lonnet::logthis('advanced query = '.$/.$query); return ($query,$customquery,$customshow,$libraries_to_query, $pretty_search_string); } @@ -1543,7 +1555,7 @@ sub parse_domain_restrictions { # $ENV{'form.domains'} can be either a scalar or an array reference. # We need an array. if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') { - return (undef,''); + return (undef,'',undef); } my @allowed_domains; if (ref($ENV{'form.domains'})) { @@ -1554,17 +1566,21 @@ sub parse_domain_restrictions { # my %domain_hash = (); my $pretty_domains_string; + my $domain_sql_restriction; foreach (@allowed_domains) { $domain_hash{$_}++; } if ($domain_hash{'any'}) { $pretty_domains_string = "In all LON-CAPA domains."; + $domain_sql_restriction = undef; } else { if (@allowed_domains > 1) { $pretty_domains_string = "In LON-CAPA domains:"; } else { $pretty_domains_string = "In LON-CAPA domain "; } + $domain_sql_restriction = + '(domain="'.join('" OR domain="',@allowed_domains).'")'; foreach (sort @allowed_domains) { $pretty_domains_string .= "".$_." "; } @@ -1574,7 +1590,9 @@ sub parse_domain_restrictions { } } } - return ($libraries_to_query,$pretty_domains_string); + return ($libraries_to_query, + $pretty_domains_string, + $domain_sql_restriction); } ###################################################################### @@ -1603,7 +1621,7 @@ sub parse_basic_search { $ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"}); $ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; } - my ($libraries_to_query,$pretty_domains_string) = + my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = &parse_domain_restrictions(); # # Check to see if enough of a query is filled in @@ -1627,6 +1645,9 @@ sub parse_basic_search { return; } push(@Queries,$SQLQuery); + if (defined($domain_sql_restriction) && $domain_sql_restriction ne '') { + push(@Queries,$domain_sql_restriction); + } #foreach my $q (@Queries) { # &Apache::lonnet::logthis(' '.$q); #} @@ -1637,7 +1658,7 @@ sub parse_basic_search { } $pretty_search_string .= "
\n"; $pretty_search_string =~ s:^
and ::; - # &Apache::lonnet::logthis($final_query); + #&Apache::lonnet::logthis('simple search final query = '.$/.$final_query); return ($final_query,$pretty_search_string, $libraries_to_query); } @@ -2111,8 +2132,9 @@ sub print_sort_form { return; } my $result; + my $html=&Apache::lonxml::xmlbegin(); $result.=< +$html