--- loncom/interface/lonsearchcat.pm 2003/12/28 20:12:59 1.199 +++ loncom/interface/lonsearchcat.pm 2004/01/01 20:13:17 1.200 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Search Catalog # -# $Id: lonsearchcat.pm,v 1.199 2003/12/28 20:12:59 www Exp $ +# $Id: lonsearchcat.pm,v 1.200 2004/01/01 20:13:17 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -70,6 +70,8 @@ use Text::Query; use GDBM_File; use Apache::loncommon(); use Apache::lonmysql(); +use Apache::lonmeta; +use Apache::lonhtmlcommon; use Apache::lonlocal; ###################################################################### @@ -83,16 +85,14 @@ my %groupsearch_db; # Database hash use # groupsearch RAT interface. my %persistent_db; # gdbm hash which holds data which is supposed to # persist across calls to lonsearchcat.pm -## %Views: -## Hash which associates an output view description with the function -## that produces it. -# View Description/Name Function Pointer -my %Views = ("Detailed Citation View" => \&detailed_citation_view, - "Summary View" => \&summary_view, - "Fielded Format" => \&fielded_format_view, - "XML/SGML" => \&xml_sgml_view, - "Compact View" => \&compact_view); +# The different view modes and associated functions + +my %Views = ("detailed" => \&detailed_citation_view, + "summary" => \&summary_view, + "fielded" => \&fielded_format_view, + "xml" => \&xml_sgml_view, + "compact" => \&compact_view); ###################################################################### ###################################################################### @@ -366,9 +366,9 @@ sub course_search { if ($ENV{'form.crsrelated'}) { ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'}); if (@New_Words) { - $pretty_search_string .= " with related words: @New_Words."; + $pretty_search_string .= ' '.&mt("with related words").": @New_Words."; } else { - $pretty_search_string .= " with no related words."; + $pretty_search_string .= ' '.&mt('with no related words')."."; } } my $fulltext=$ENV{'form.crsfulltext'}; @@ -498,15 +498,19 @@ $Statement. - - + +
ENDDOCUMENT - $scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40). + $scrout.=' '.&Apache::lonhtmlcommon::textbox('basicexp', + $ENV{'form.basicexp'},40). ' '; - my $relatedcheckbox = &simplecheckbox('related','related',$ENV{'form.related'}); + my $relatedcheckbox = &Apache::lonhtmlcommon::checkbox('related', + $ENV{'form.related'}); my $domain = $r->dir_config('lonDefDomain'); - my $domaincheckbox = &simplecheckbox('domains',$domain); + my $domaincheckbox = &Apache::lonhtmlcommon::checkbox('domains', + $ENV{'form.domains'}); my $srch=&mt('Search'); my $header=&mt('Advanced Search'); my $userelatedwords=&mt('use related words'); my $onlysearchdomain=&mt('only search domain'); + my $view=&viewoptions(); $scrout.=<  $closebutton END - $scrout.=&selectbox('View','viewselect', - $ENV{'form.viewselect'}, - undef,undef,undef, - sort(keys(%Views))); - $scrout.=&selectbox('Per Page','show', - $ENV{'form.show'}, - undef,undef,undef, - (10,20,50,100)); $scrout.=< @@ -537,6 +534,8 @@ ENDDOCUMENT 'srch' => 'Search', 'header' => 'Course Search', 'note' => 'Enter terms or phrases, then press "Search" below', + 'use' => 'use related words', + 'full' =>'fulltext search (time consuming)' ); $scrout.=(< @@ -552,15 +551,18 @@ $lt{'note'}.
ENDCOURSESEARCH $scrout.=' '. - &simpletextfield('courseexp',$ENV{'form.courseexp'},40); + &Apache::lonhtmlcommon::textbox('courseexp', + $ENV{'form.courseexp'},40); my $crscheckbox = - &simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'}); + &Apache::lonhtmlcommon::checkbox('crsfulltext', + $ENV{'form.crsfulltext'}); my $relcheckbox = - &simplecheckbox('crsrelated',$ENV{'form.crsrelated'}); + &Apache::lonhtmlcommon::checkbox('crsrelated', + $ENV{'form.crsrelated'}); $scrout.=(<
$relcheckbox use related words
$crscheckbox fulltext search (time consuming)
$relcheckbox $lt{'use'}
$crscheckbox $lt{'full'}

 

@@ -589,12 +591,15 @@ Returns a scalar which holds html for th sub print_advanced_search_form{ my ($r,$closebutton,$hidden_fields) = @_; + my %lt=&Apache::lonlocal::texthash('srch' => 'Search', + 'reset' => 'Reset', + 'help' => 'Help'); my $advanced_buttons = <<"END";

- - + + $closebutton - +

END if (!defined($ENV{'form.viewselect'})) { @@ -616,59 +621,46 @@ END $bodytag Enter terms or phrases separated by search operators such as AND, OR, or NOT.
-
+ $advanced_buttons $hidden_fields - - -\n"; - $scrout.=&searchphrasefield_with_related('title', 'title' , - $ENV{'form.title'}); - $scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'}); - $scrout.=&searchphrasefield_with_related('subject', 'subject' , - $ENV{'form.subject'}); - $scrout.=&searchphrasefield_with_related('keywords','keywords', - $ENV{'form.keywords'}); - $scrout.=&searchphrasefield('URL', 'url' ,$ENV{'form.url'}); - $scrout.=&searchphrasefield_with_related('notes', 'notes' , - $ENV{'form.notes'}); - $scrout.=&searchphrasefield_with_related('abstract','abstract', - $ENV{'form.abstract'}); - $scrout.=&searchphrasefield('Standards','standards',$ENV{'form.standards'}); + $scrout.=&viewoptions(); + my %fields=&Apache::lonmeta::fieldnames(); +# set undefined to "any" + $ENV{'form.language'}='any' unless length($ENV{'form.language'}); + $ENV{'form.domains'} = 'any' if (! exists($ENV{'form.domains'})); + $ENV{'form.category'}='any' if (! defined($ENV{'form.category'})); + + + $scrout.='
VIEW: ENDHEADER - $scrout.=&selectbox(undef,'viewselect', - $ENV{'form.viewselect'}, - undef,undef,undef, - sort(keys(%Views))); - $scrout.=' '; - $scrout.=&selectbox(undef,'show', - $ENV{'form.show'}, - undef,undef,undef, - (10,20,50,100)); - $scrout.=' '. - ''.&mt('Per Page').''; - $scrout.="".&mt('Related').'
'.&mt('Words')."
'; + $scrout.="\n"; + foreach ('title','author','keywords','notes','abstract','standards', + 'lowestgradelevel','highestgradelevel','mime') { + $scrout.=''; + } # Hack - an empty table row. $scrout.="\n"; - $scrout.=&searchphrasefield('file
extension','extension', - $ENV{'form.extension'}); - $scrout.="\n"; - $scrout.=&searchphrasefield('publisher
owner','owner', - $ENV{'form.owner'}); +# $scrout.=&searchphrasefield('file
extension','extension', +# $ENV{'form.extension'}); +# $scrout.="\n"; +# $scrout.=&searchphrasefield('publisher
owner','owner', + # $ENV{'form.owner'}); $scrout.="
".&mt('Field').''.&mt('Value').'' + .&mt('Related').'
'.&mt('Words')."
'.&titlefield($fields{$_}).''. + &Apache::lonmeta::prettyinput($_,$ENV{'form.'.$_},$_,'advsearch', + 1,'',$ENV{'form.'.$_.'_related'}). + '
   
   
   
\n"; - $ENV{'form.category'}='any' if (! defined($ENV{'form.category'})); - $scrout.=&selectbox('File Category','category', - $ENV{'form.category'}, - 'any','Any category', - undef, - (&Apache::loncommon::filecategories())); - $ENV{'form.language'}='any' unless length($ENV{'form.language'}); +# $scrout.=&Apache::lonmeta::selectbox('File Category','category', +# $ENV{'form.category'}, +# 'any','Any category', +# undef, +# (&Apache::loncommon::filecategories())); #---------------------------------------------------------------- # Allow restriction to multiple domains. # I make the crazy assumption that there will never be a domain 'any'. # - $ENV{'form.domains'} = 'any' if (! exists($ENV{'form.domains'})); my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} : ($ENV{'form.domains'}) ); my %domain_hash = (); @@ -679,8 +671,7 @@ ENDHEADER # adjust the size of the select box my $size = 4; $size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size); - $scrout.="\n".''. - 'DOMAINS TO BE SEARCHED
'. + $scrout.="\n".&titlefield(&mt('Domain to be searched')). '\n"; - #---------------------------------------------------------------- - $scrout.=&selectbox('Limit by language','language', - $ENV{'form.language'},'any','Any Language', - \&Apache::loncommon::languagedescription, - (&Apache::loncommon::languageids), - ); -# ------------------------------------------------ Compute date selection boxes - $scrout.=< -LIMIT BY CREATION DATE RANGE: - -
-between: -CREATIONDATESTART - $scrout.=&dateboxes('creationdatestart',1,1,1976, - $ENV{'form.creationdatestart_month'}, - $ENV{'form.creationdatestart_day'}, - $ENV{'form.creationdatestart_year'}, - ); - $scrout.="and:\n"; - $scrout.=&dateboxes('creationdateend',12,31,2051, - $ENV{'form.creationdateend_month'}, - $ENV{'form.creationdateend_day'}, - $ENV{'form.creationdateend_year'}, - ); - $scrout.="

"; - $scrout.=< -LIMIT BY LAST REVISION DATE RANGE: - -
between: -LASTREVISIONDATESTART - $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976, - $ENV{'form.lastrevisiondatestart_month'}, - $ENV{'form.lastrevisiondatestart_day'}, - $ENV{'form.lastrevisiondatestart_year'}, - ); - $scrout.=< @@ -772,6 +711,82 @@ ENDDOCUMENT $r->print($scrout); return; } +###################################################################### +###################################################################### + +=pod + +=item &titlefield + +Inputs: title text + +Outputs: titletext with font wrapper + +=cut + +###################################################################### +###################################################################### + +sub titlefield { + my $title=shift; + return ''.$title.''; +} +###################################################################### +###################################################################### + +=pod + +=item viewoptiontext + +Inputs: codename for view option + +Outputs: displayed text + +=cut + +###################################################################### +###################################################################### + +sub viewoptiontext { + my $code=shift; + my %desc=&Apache::lonlocal::texthash('detailed' => "Detailed Citation View", + 'xml' => 'XML/SGML', + 'compact' => 'Compact View', + 'fielded' => 'Fielded Format', + 'summary' => 'Summary View'); + return $desc{$code}; +} +###################################################################### + +=pod + +=item viewoptions + +Inputs: none + +Outputs: text for box with view options + +=cut + +###################################################################### +###################################################################### + +sub viewoptions { + my $scrout="\n\n".'
'.&mt('View Options').''. + &mt('Records per Page').'
'; + unless ($ENV{'form.viewselect'}) { $ENV{'form.viewselect'}='detailed'; } + $scrout.=&Apache::lonmeta::selectbox('viewselect', + $ENV{'form.viewselect'}, + \&viewoptiontext, + sort(keys(%Views))); + $scrout.=''; + $scrout.=&Apache::lonmeta::selectbox('show', + $ENV{'form.show'}, + undef, + (10,20,50,100,1000,10000)); + $scrout.="
\n\n"; + return $scrout; +} ###################################################################### ###################################################################### @@ -934,288 +949,6 @@ sub make_form_data_persistent { } ###################################################################### -# HTML form building functions # -###################################################################### - -=pod - -=item HTML form building functions - -=over 4 - -=cut - -############################################### -############################################### - -=pod - -=item &simpletextfield() - -Inputs: $name,$value,$size - -Returns a text input field with the given name, value, and size. -If size is not specified, a value of 20 is used. - -=cut - -############################################### -############################################### - -sub simpletextfield { - my ($name,$value,$size)=@_; - $size = 20 if (! defined($size)); - return ''; -} - -############################################### -############################################### - -=pod - -=item &simplecheckbox() - -Inputs: $name,$value,$checked - -Returns a simple check box with the given $name. -If $value eq 'on' the box is checked. - -=cut - -############################################### -############################################### - -sub simplecheckbox{ - my ($name,$value,$checked)=@_; - $checked="checked" if ($value eq $checked || $value eq 'on'); - return ''; -} - -############################################### -############################################### - -=pod - -=item &fieldtitle() - -Input: $title - -Returns a scalar with html which will display $title as a search -field heading. - -=cut - -############################################### -############################################### - -sub fieldtitle { - my $title = uc(&mt(shift())); - return ''.$title. - ': '; -} - -############################################### -############################################### - -=pod - -=item &searchphrasefield() - -Inputs: $title,$name,$value - -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. - -=cut - -############################################### -############################################### - -sub searchphrasefield { - my ($title,$name,$value)=@_; - return ''.&fieldtitle($title).''. - &simpletextfield($name,$value,50)." \n"; -} - -############################################### -############################################### - -=pod - -=item &searchphrasefield_with_related() - -Inputs: $title,$name,$value - -Returns html for a title line and an input field for entering search terms -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". - -=cut - -############################################### -############################################### - -sub searchphrasefield_with_related { - my ($title,$name,$value)=@_; - return ''.&fieldtitle($title).''. - &simpletextfield($name,$value,50).' '. - &simplecheckbox($name.'_related',$ENV{'form.'.$name.'_related'}). - " \n"; -} - -############################################### -############################################### - -=pod - -=item &dateboxes() - -Returns html selection form elements for the specification of -the day, month, and year. - -=cut - -############################################### -############################################### - -sub dateboxes { - my ($name,$defaultmonth,$defaultday,$defaultyear, - $currentmonth,$currentday,$currentyear)=@_; - ($defaultmonth,$defaultday,$defaultyear)=('','',''); - # - # Day - my $day=< - -END - for (my $i = 1; $i<=31; $i++) { - $day.="\n"; - } - $day.="\n"; - $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday); - # - # Month - my $month=< - -END - my $i = 1; - foreach (qw/January February March April May June - July August September October November December /){ - $month .="\n"; - $i++; - } - $month.="\n"; - $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth); - # - # Year (obviously) - my $year=< - -END - my $maxyear = 2051; - for (my $i = 1976; $i<=$maxyear; $i++) { - $year.="\n"; - } - $year.="\n"; - $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear); - return "$month$day$year"; -} - -############################################### -############################################### - -=pod - -=item &selectbox() - -Returns a scalar containing an html tag. - -=item $default - -The default value of the form. Can be $anyvalue, or in @idlist. - -=item $anyvalue - -The