version 1.218, 2004/04/27 15:45:04
|
version 1.228, 2004/06/03 19:23:08
|
Line 75 use Apache::lonhtmlcommon;
|
Line 75 use Apache::lonhtmlcommon;
|
use Apache::lonlocal; |
use Apache::lonlocal; |
use LONCAPA::lonmetadata(); |
use LONCAPA::lonmetadata(); |
use HTML::Entities(); |
use HTML::Entities(); |
|
use Parse::RecDescent; |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 117 sub handler {
|
Line 118 sub handler {
|
|
|
my $loaderror=&Apache::lonnet::overloaderror($r); |
my $loaderror=&Apache::lonnet::overloaderror($r); |
if ($loaderror) { return $loaderror; } |
if ($loaderror) { return $loaderror; } |
|
# |
my $closebutton; # button that closes the search window |
my $closebutton; # button that closes the search window |
# This button is different for the RAT compared to |
# This button is different for the RAT compared to |
# normal invocation. |
# normal invocation. |
Line 174 sub handler {
|
Line 175 sub handler {
|
'&launch='.$ENV{'form.launch'}. |
'&launch='.$ENV{'form.launch'}. |
'&mode='.$ENV{'form.mode'}, |
'&mode='.$ENV{'form.mode'}, |
text=>"Course and Catalog Search", |
text=>"Course and Catalog Search", |
|
target=>'_top', |
bug=>'Searching',}); |
bug=>'Searching',}); |
} else { |
} else { |
&Apache::lonhtmlcommon::add_breadcrumb |
&Apache::lonhtmlcommon::add_breadcrumb |
Line 182 sub handler {
|
Line 184 sub handler {
|
'&launch='.$ENV{'form.launch'}. |
'&launch='.$ENV{'form.launch'}. |
'&mode='.$ENV{'form.mode'}, |
'&mode='.$ENV{'form.mode'}, |
text=>"Catalog Search", |
text=>"Catalog Search", |
|
target=>'_top', |
bug=>'Searching',}); |
bug=>'Searching',}); |
} |
} |
# |
# |
if (! &get_persistent_form_data($persistent_db_file)) { |
if ($ENV{'form.phase'} !~ m/(basic|adv|course)_search/) { |
if ($ENV{'form.phase'} =~ /(run_search|results)/) { |
if (! &get_persistent_form_data($persistent_db_file)) { |
&Apache::lonnet::logthis("lonsearchcat:Unable to recover data ". |
if ($ENV{'form.phase'} =~ /(run_search|results)/) { |
"from $persistent_db_file"); |
&Apache::lonnet::logthis('lonsearchcat:'. |
$r->print(<<END); |
'Unable to recover data from '. |
|
$persistent_db_file); |
|
$r->print(<<END); |
<html> |
<html> |
<head><title>LON-CAPA Search Error</title></head> |
<head><title>LON-CAPA Search Error</title></head> |
$bodytag |
$bodytag |
Line 198 error and has been logged. Please alert
|
Line 203 error and has been logged. Please alert
|
</body> |
</body> |
</html> |
</html> |
END |
END |
return OK; |
return OK; |
|
} |
} |
} |
|
} else { |
|
&clean_up_environment(); |
} |
} |
## |
## |
## Clear out old values from groupsearch database |
## Clear out old values from groupsearch database |
Line 226 END
|
Line 234 END
|
$hidden_fields = '<input type="hidden" name="persistent_db_id" value="'. |
$hidden_fields = '<input type="hidden" name="persistent_db_id" value="'. |
$ENV{'form.persistent_db_id'}.'" />'."\n"; |
$ENV{'form.persistent_db_id'}.'" />'."\n"; |
if (exists($ENV{'form.catalogmode'})) { |
if (exists($ENV{'form.catalogmode'})) { |
$hidden_fields .= '<input type="hidden" name="catalogmode" value="'. |
$hidden_fields .= &hidden_field('catalogmode'); |
$ENV{'form.catalogmode'}.'" />'."\n"; |
|
} |
} |
if (exists($ENV{'form.form'})) { |
if (exists($ENV{'form.form'})) { |
$hidden_fields .= '<input type="hidden" name="form" value="'. |
$hidden_fields .= &hidden_field('form'); |
$ENV{'form.form'}.'" />'."\n"; |
|
} |
} |
if (exists($ENV{'form.element'})) { |
if (exists($ENV{'form.element'})) { |
$hidden_fields .= '<input type="hidden" name="element" value="'. |
$hidden_fields .= &hidden_field('element'); |
$ENV{'form.element'}.'" />'."\n"; |
|
} |
} |
if (exists($ENV{'form.titleelement'})) { |
if (exists($ENV{'form.titleelement'})) { |
$hidden_fields .= '<input type="hidden" name="titleelement" value="'. |
$hidden_fields .= &hidden_field('titleelement'); |
$ENV{'form.titleelement'}.'" />'."\n"; |
|
} |
} |
if (exists($ENV{'form.mode'})) { |
if (exists($ENV{'form.mode'})) { |
$hidden_fields .= '<input type="hidden" name="mode" value="'. |
$hidden_fields .= &hidden_field('mode'); |
$ENV{'form.mode'}.'" />'."\n"; |
|
} |
} |
## |
## |
## Configure dynamic components of interface |
## Configure dynamic components of interface |
Line 286 END
|
Line 289 END
|
$ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'})); |
$ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'})); |
$ENV{'form.show'} = 20 if (! exists($ENV{'form.show'})); |
$ENV{'form.show'} = 20 if (! exists($ENV{'form.show'})); |
# |
# |
$ENV{'form.searchmode'} = 'basic'; |
$ENV{'form.searchmode'} = 'basic' if (! exists($ENV{'form.searchmode'})); |
if ($ENV{'form.phase'} eq 'adv_search' || |
if ($ENV{'form.phase'} eq 'adv_search' || |
$ENV{'form.phase'} eq 'disp_adv') { |
$ENV{'form.phase'} eq 'disp_adv') { |
$ENV{'form.searchmode'} = 'advanced'; |
$ENV{'form.searchmode'} = 'advanced'; |
Line 335 END
|
Line 338 END
|
&course_search($r); |
&course_search($r); |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
} elsif(($ENV{'form.phase'} eq 'basic_search') || |
($ENV{'form.phase'} eq 'adv_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') { |
|
($query,$pretty_string,$libraries) = |
|
&parse_basic_search($r,$closebutton,$hidden_fields); |
|
return OK if (! defined($query)); |
|
&make_persistent({ basicexp => $ENV{'form.basicexp'}}, |
|
$persistent_db_file); |
|
} else { # Advanced search |
|
($query,$customquery,$customshow,$libraries,$pretty_string) |
|
= &parse_advanced_search($r,$closebutton,$hidden_fields); |
|
return OK if (! defined($query)); |
|
} |
|
&make_persistent({ query => $query, |
|
customquery => $customquery, |
|
customshow => $customshow, |
|
libraries => $libraries, |
|
pretty_string => $pretty_string }, |
|
$persistent_db_file); |
|
# |
# Set up table |
# Set up table |
if (! defined(&create_results_table())) { |
if (! defined(&create_results_table())) { |
my $errorstring=&Apache::lonmysql::get_error(); |
my $errorstring=&Apache::lonmysql::get_error(); |
Line 362 Unable to properly store search informat
|
Line 388 Unable to properly store search informat
|
END |
END |
return OK; |
return OK; |
} |
} |
# |
|
# We are running a search |
|
my ($query,$customquery,$customshow,$libraries) = |
|
(undef,undef,undef,undef); |
|
my $pretty_string; |
|
if ($ENV{'form.phase'} eq 'basic_search') { |
|
($query,$pretty_string,$libraries) = |
|
&parse_basic_search($r,$closebutton,$hidden_fields); |
|
} else { # Advanced search |
|
($query,$customquery,$customshow,$libraries,$pretty_string) |
|
= &parse_advanced_search($r,$closebutton,$hidden_fields); |
|
return OK if (! defined($query)); |
|
} |
|
&make_persistent({ query => $query, |
|
customquery => $customquery, |
|
customshow => $customshow, |
|
libraries => $libraries, |
|
pretty_string => $pretty_string }, |
|
$persistent_db_file); |
|
## |
## |
## Print out the frames interface |
## Print out the frames interface |
## |
## |
&print_frames_interface($r); |
if (defined($query)) { |
|
&print_frames_interface($r); |
|
} |
} |
} |
return OK; |
return OK; |
} |
} |
|
|
|
# |
|
# The mechanism used to store values away and retrieve them does not |
|
# handle the case of missing environment variables being significant. |
|
# |
|
# This routine sets non existant checkbox form elements to ''. |
|
# |
|
sub clean_up_environment { |
|
if ($ENV{'form.phase'} eq 'basic_search') { |
|
if (! exists($ENV{'form.related'})) { |
|
$ENV{'form.related'} = ''; |
|
} |
|
if (! exists($ENV{'form.domains'})) { |
|
$ENV{'form.domains'} = ''; |
|
} |
|
} elsif ($ENV{'form.phase'} eq 'adv_search') { |
|
foreach my $field ('title','keywords','notes', |
|
'abstract','standards','mime') { |
|
if (! exists($ENV{'form.'.$field.'_related'})) { |
|
$ENV{'form.'.$field.'_related'} = ''; |
|
} |
|
} |
|
} elsif ($ENV{'form.phase'} eq 'course_search') { |
|
if (! exists($ENV{'form.crsrelated'})) { |
|
$ENV{'form.crsrelated'} = ''; |
|
} |
|
} |
|
} |
|
|
|
sub hidden_field { |
|
my ($name,$value) = @_; |
|
if (! defined($value)) { |
|
$value = $ENV{'form.'.$name}; |
|
} |
|
return '<input type="hidden" name="'.$name.'" value="'.$value.'" />'.$/; |
|
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
## |
## |
Line 523 Prints the form for the basic search. S
|
Line 568 Prints the form for the basic search. S
|
###################################################################### |
###################################################################### |
sub print_basic_search_form { |
sub print_basic_search_form { |
my ($r,$closebutton,$hidden_fields) = @_; |
my ($r,$closebutton,$hidden_fields) = @_; |
|
my $result = ($ENV{'form.catalogmode'} ne 'groupsearch'); |
my $bodytag=&Apache::loncommon::bodytag('Search'). |
my $bodytag=&Apache::loncommon::bodytag('Search'). |
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching', |
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching', |
undef,undef,! $ENV{'form.launch'}); |
undef,undef, |
|
$ENV{'form.catalogmode'} ne 'groupsearch'); |
my $scrout = &search_html_header().$bodytag; |
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 |
# Define interface components |
my $userelatedwords= |
my $userelatedwords= |
&mt('[_1] use related words', |
&mt('[_1] use related words', |
&Apache::lonhtmlcommon::checkbox |
&Apache::lonhtmlcommon::checkbox |
('related',$ENV{'form.related'})); |
('related',$ENV{'form.related'},'related')); |
my $onlysearchdomain= |
my $onlysearchdomain= |
&mt('[_1] only search domain [_2]', |
&mt('[_1] only search domain [_2]', |
&Apache::lonhtmlcommon::checkbox |
&Apache::lonhtmlcommon::checkbox('domains', |
('domains',$ENV{'form.domains'}), |
$ENV{'form.domains'}, |
$r->dir_config('lonDefDomain')); |
$r->dir_config('lonDefDomain') |
|
), |
|
$r->dir_config('lonDefDomain') |
|
); |
my $adv_search_link = |
my $adv_search_link = |
'<a href="/adm/searchcat?'. |
'<a href="/adm/searchcat?'. |
'phase=disp_adv&'. |
'phase=disp_adv&'. |
Line 560 sub print_basic_search_form {
|
Line 610 sub print_basic_search_form {
|
} |
} |
$scrout.='<table>'. |
$scrout.='<table>'. |
'<tr><td align="center" valign="top">'. |
'<tr><td align="center" valign="top">'. |
&Apache::lonhtmlcommon::textbox('basicexp', |
&Apache::lonhtmlcommon::textbox |
$ENV{'form.basicexp'},50).'<br />'. |
('basicexp', |
|
&HTML::Entities::encode($ENV{'form.basicexp'},'<>&"'),50 |
|
). |
|
'<br />'. |
'<font size="-1">'.&searchhelp().'</font>'.'</td>'. |
'<font size="-1">'.&searchhelp().'</font>'.'</td>'. |
'<td><font size="-1">'. |
'<td><font size="-1">'. |
'<nobr>'.(' 'x3).$adv_search_link.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x3).$adv_search_link.'</nobr>'.'<br />'. |
Line 570 sub print_basic_search_form {
|
Line 623 sub print_basic_search_form {
|
'</font></td>'. |
'</font></td>'. |
'</tr>'.$/; |
'</tr>'.$/; |
# |
# |
# $scrout .= '<tr><td align="center">'. |
|
# '<font size="-1">'. |
|
# $userelatedwords.(' 'x3). |
|
# $onlysearchdomain.(' 'x2).$adv_search_link. |
|
# '</font>'. |
|
# '</td></tr>'.$/; |
|
$scrout .= '<tr><td align="center" colspan="2">'. |
$scrout .= '<tr><td align="center" colspan="2">'. |
'<font size="-1">'. |
'<font size="-1">'. |
'<input type="submit" name="basicsubmit" '. |
'<input type="submit" name="basicsubmit" '. |
'value="'.&mt('Search').'" />'. |
'value="'.&mt('Search').'" />'. |
(' 'x2).$closebutton.(' 'x2).&viewoptions(). |
(' 'x2).$closebutton.(' 'x2). |
|
&viewoptions(). |
'</font>'. |
'</font>'. |
'</td></tr>'.$/; |
'</td></tr>'.$/; |
$scrout .= '</table>'.$/.'</center>'.'</form>'; |
$scrout .= '</table>'.$/.'</center>'.'</form>'; |
Line 649 Prints the advanced search form.
|
Line 697 Prints the advanced search form.
|
sub print_advanced_search_form{ |
sub print_advanced_search_form{ |
my ($r,$closebutton,$hidden_fields) = @_; |
my ($r,$closebutton,$hidden_fields) = @_; |
my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). |
my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'). |
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching', |
&Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching', |
'Searching', |
undef,undef, |
undef,undef, |
$ENV{'form.catalogmode'} ne 'groupsearch'); |
! $ENV{'form.launch'}); |
|
|
|
my %lt=&Apache::lonlocal::texthash('srch' => 'Search', |
my %lt=&Apache::lonlocal::texthash('srch' => 'Search', |
'reset' => 'Reset', |
'reset' => 'Reset', |
'help' => 'Help'); |
'help' => 'Help'); |
Line 754 ENDHEADER
|
Line 800 ENDHEADER
|
$scrout .= '<tr><td> </td><td align="center">'.&mt('Minimum').'</td>'. |
$scrout .= '<tr><td> </td><td align="center">'.&mt('Minimum').'</td>'. |
'<td align="center">'.&mt('Maximum').'</td></tr>'."\n"; |
'<td align="center">'.&mt('Maximum').'</td></tr>'."\n"; |
foreach my $statistic |
foreach my $statistic |
({ name=>'stdno', |
({ name=>'count', |
description=>'Number of Students',}, |
description=>'Network-wide number of accesses (hits)',}, |
|
{ name=>'stdno', |
|
description=> |
|
'Total number of students who have worked on this problem',}, |
{ name => 'avetries', |
{ name => 'avetries', |
description=>'Average tries to answer correctly',}, |
description=>'Average number of tries till solved',}, |
{ name => 'difficulty', |
{ name => 'difficulty', |
description=>'Degree of difficulty',}, |
description=>'Degree of difficulty',}, |
{ name => 'disc', |
{ name => 'disc', |
Line 920 Outputs: text for box with view options
|
Line 969 Outputs: text for box with view options
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub viewoptions { |
sub viewoptions { |
my $scrout="\n".'<nobr>'; |
my $scrout; |
if (! defined($ENV{'form.viewselect'})) { |
if (! defined($ENV{'form.viewselect'})) { |
$ENV{'form.viewselect'}='detailed'; |
$ENV{'form.viewselect'}='detailed'; |
} |
} |
Line 954 Outputs: return little blurb on how to e
|
Line 1003 Outputs: return little blurb on how to e
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub searchhelp { |
sub searchhelp { |
return &mt('Enter terms or phrases separated by AND, OR, or NOT'); |
return &mt('Enter words and quoted phrases'); |
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 1145 Parse advanced search form and return th
|
Line 1194 Parse advanced search form and return th
|
sub parse_advanced_search { |
sub parse_advanced_search { |
my ($r,$closebutton,$hidden_fields)=@_; |
my ($r,$closebutton,$hidden_fields)=@_; |
my @BasicFields = ('title','author','subject','keywords','url','version', |
my @BasicFields = ('title','author','subject','keywords','url','version', |
'notes','abstract','extension','owner', |
'notes','abstract','extension','owner','authorspace', |
# 'custommetadata','customshow', |
# 'custommetadata','customshow', |
'modifyinguser','standards','mime'); |
'modifyinguser','standards','mime'); |
my @StatsFields = ('stdno','avetries','difficulty','disc'); |
my @StatsFields = &statfields(); |
my @EvalFields = ('clear','depth','helpful','correct','technical'); |
my @EvalFields = &evalfields(); |
my $fillflag=0; |
my $fillflag=0; |
my $pretty_search_string = "<br />\n"; |
my $pretty_search_string = "<br />\n"; |
# Clean up fields for safety |
# Clean up fields for safety |
Line 1173 sub parse_advanced_search {
|
Line 1222 sub parse_advanced_search {
|
ref($ENV{'form.category'})); |
ref($ENV{'form.category'})); |
# |
# |
# Check to see if enough information was filled in |
# Check to see if enough information was filled in |
for my $field (@BasicFields) { |
foreach my $field (@BasicFields) { |
if (&filled($ENV{'form.'.$field})) { |
if (&filled($ENV{'form.'.$field})) { |
$fillflag++; |
$fillflag++; |
} |
} |
} |
} |
|
foreach my $field (@StatsFields,@EvalFields) { |
|
if (&filled($ENV{'form.'.$field.'_max'})) { |
|
$fillflag++; |
|
} |
|
if (&filled($ENV{'form.'.$field.'_min'})) { |
|
$fillflag++; |
|
} |
|
} |
|
|
for my $field ('lowestgradelevel','highestgradelevel') { |
for my $field ('lowestgradelevel','highestgradelevel') { |
if ( $ENV{'form.'.$field} =~ /^\d+$/ && |
if ( $ENV{'form.'.$field} =~ /^\d+$/ && |
$ENV{'form.'.$field} > 0) { |
$ENV{'form.'.$field} > 0) { |
Line 1195 sub parse_advanced_search {
|
Line 1253 sub parse_advanced_search {
|
my $font = '<font color="#800000" face="helvetica">'; |
my $font = '<font color="#800000" face="helvetica">'; |
# Evaluate logical expression AND/OR/NOT phrase fields. |
# Evaluate logical expression AND/OR/NOT phrase fields. |
foreach my $field (@BasicFields) { |
foreach my $field (@BasicFields) { |
if ($ENV{'form.'.$field}) { |
next if (!defined($ENV{'form.'.$field}) || $ENV{'form.'.$field} eq ''); |
my $searchphrase = $ENV{'form.'.$field}; |
my ($error,$SQLQuery) = |
$pretty_search_string .= $font."$field</font> contains <b>". |
&process_phrase_input($ENV{'form.'.$field}, |
$searchphrase."</b>"; |
$ENV{'form.'.$field.'_related'},$field); |
|
if (defined($error)) { |
|
&output_unparsed_phrase_error($r,$closebutton,'phase=disp_adv', |
|
$hidden_fields,$field); |
|
return; |
|
} else { |
|
$pretty_search_string .= |
|
$font.$field.'</font>: '.$ENV{'form.'.$field}; |
if ($ENV{'form.'.$field.'_related'}) { |
if ($ENV{'form.'.$field.'_related'}) { |
my @New_Words; |
my @Words = |
($searchphrase,@New_Words) = &related_version($searchphrase); |
&Apache::loncommon::get_related_words |
if (@New_Words) { |
($ENV{'form.'.$field}); |
$pretty_search_string .= " with related words: ". |
if (@Words) { |
"<b>@New_Words</b>."; |
$pretty_search_string.= ' with related words: '. |
|
join(', ',@Words[0..4]); |
} else { |
} else { |
$pretty_search_string .= " with no related words."; |
$pretty_search_string.= ' with related words.'; |
} |
} |
} |
} |
$pretty_search_string .= "<br />\n"; |
$pretty_search_string .= '<br />'; |
push @queries,&build_SQL_query($field,$searchphrase); |
push (@queries,$SQLQuery); |
} |
} |
} |
} |
# |
# |
Line 1227 sub parse_advanced_search {
|
Line 1293 sub parse_advanced_search {
|
} |
} |
} |
} |
if (defined($searchphrase)) { |
if (defined($searchphrase)) { |
push @queries,&build_SQL_query('mime',$searchphrase); |
my ($error,$SQLsearch) = &process_phrase_input($searchphrase,0,'mime'); |
|
push @queries,$SQLsearch; |
$pretty_search_string .=$font.'mime</font> contains <b>'. |
$pretty_search_string .=$font.'mime</font> contains <b>'. |
$searchphrase.'</b><br />'; |
$searchphrase.'</b><br />'; |
} |
} |
Line 1347 sub parse_advanced_search {
|
Line 1414 sub parse_advanced_search {
|
$pretty_search_string .= $pretty_domains_string."<br />\n"; |
$pretty_search_string .= $pretty_domains_string."<br />\n"; |
# |
# |
if (@queries) { |
if (@queries) { |
$query="select * from metadata where ".join(" AND ",@queries); |
$query="SELECT * FROM metadata WHERE (".join(") AND (",@queries).')'; |
} elsif ($customquery) { |
} elsif ($customquery) { |
$query = ''; |
$query = ''; |
} |
} |
# &Apache::lonnet::logthis('query = '.$/.$query); |
# &Apache::lonnet::logthis('query = '.$/.$query); |
return ($query,$customquery,$customshow,$libraries_to_query, |
return ($query,$customquery,$customshow,$libraries_to_query, |
$pretty_search_string); |
$pretty_search_string); |
} |
} |
Line 1360 sub parse_domain_restrictions {
|
Line 1427 sub parse_domain_restrictions {
|
my $libraries_to_query = undef; |
my $libraries_to_query = undef; |
# $ENV{'form.domains'} can be either a scalar or an array reference. |
# $ENV{'form.domains'} can be either a scalar or an array reference. |
# We need an array. |
# We need an array. |
if (! exists($ENV{'form.domains'})) { |
if (! exists($ENV{'form.domains'}) || $ENV{'form.domains'} eq '') { |
return (undef,''); |
return (undef,''); |
} |
} |
my @allowed_domains; |
my @allowed_domains; |
Line 1413 sub parse_basic_search {
|
Line 1480 sub parse_basic_search {
|
# |
# |
# Clean up fields for safety |
# Clean up fields for safety |
for my $field ('basicexp') { |
for my $field ('basicexp') { |
$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g; |
$ENV{"form.$field"}=~s/[^\w\s\'\"\!\(\)\-]//g; |
} |
} |
foreach ('mode','form','element') { |
foreach ('mode','form','element') { |
# is this required? Hmmm. |
# is this required? Hmmm. |
Line 1425 sub parse_basic_search {
|
Line 1492 sub parse_basic_search {
|
&parse_domain_restrictions(); |
&parse_domain_restrictions(); |
# |
# |
# Check to see if enough of a query is filled in |
# Check to see if enough of a query is filled in |
unless (&filled($ENV{'form.basicexp'})) { |
my $search_string = $ENV{'form.basicexp'}; |
|
if (! &filled($search_string)) { |
&output_blank_field_error($r,$closebutton,'phase=disp_basic'); |
&output_blank_field_error($r,$closebutton,'phase=disp_basic'); |
return OK; |
return OK; |
} |
} |
my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>'; |
my $pretty_search_string=$search_string; |
my $search_string = $ENV{'form.basicexp'}; |
my @Queries; |
if ($ENV{'form.related'}) { |
my $searchfield = 'concat_ws(" ",'.join(',', |
my @New_Words; |
('title','author','subject', |
($search_string,@New_Words) = &related_version($ENV{'form.basicexp'}); |
'notes','abstract','keywords') |
if (@New_Words) { |
).')'; |
$pretty_search_string .= " with related words: <b>@New_Words</b>."; |
my ($error,$SQLQuery) = &process_phrase_input($search_string, |
} else { |
$ENV{'form.related'}, |
$pretty_search_string .= " with no related words."; |
$searchfield); |
} |
if ($error) { |
|
&output_unparsed_phrase_error($r,$closebutton,'phase=disp_basic', |
|
'','basicexp'); |
|
return; |
} |
} |
|
push(@Queries,$SQLQuery); |
|
#foreach my $q (@Queries) { |
|
# &Apache::lonnet::logthis(' '.$q); |
|
#} |
|
my $final_query = 'SELECT * FROM metadata WHERE '.join(" AND ",@Queries); |
# |
# |
# Build SQL query string based on form page |
|
my $query=''; |
|
my $concatarg=join(',', |
|
('title', 'author', 'subject', 'notes', 'abstract', |
|
'keywords')); |
|
$concatarg='title' if $ENV{'form.titleonly'}; |
|
$query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string); |
|
if (defined($pretty_domains_string) && $pretty_domains_string ne '') { |
if (defined($pretty_domains_string) && $pretty_domains_string ne '') { |
$pretty_search_string .= ' '.$pretty_domains_string; |
$pretty_search_string .= ' '.$pretty_domains_string; |
} |
} |
$pretty_search_string .= "<br />\n"; |
$pretty_search_string .= "<br />\n"; |
my $final_query = 'SELECT * FROM metadata WHERE '.$query; |
$pretty_search_string =~ s:^<br /> and ::; |
# &Apache::lonnet::logthis($final_query); |
# &Apache::lonnet::logthis($final_query); |
return ($final_query,$pretty_search_string, |
return ($final_query,$pretty_search_string, |
$libraries_to_query); |
$libraries_to_query); |
} |
} |
|
|
|
|
|
############################################################### |
|
############################################################### |
|
|
|
my @Phrases; |
|
|
|
sub concat { |
|
my ($item) = @_; |
|
my $results = ''; |
|
foreach (@$item) { |
|
if (ref($_) eq 'ARRAY') { |
|
$results .= join(' ',@$_); |
|
} |
|
} |
|
return $results; |
|
} |
|
|
|
sub process_phrase_input { |
|
my ($phrase,$related,$field)=@_; |
|
#&Apache::lonnet::logthis('phrase = :'.$phrase.':'); |
|
my $grammar = <<'ENDGRAMMAR'; |
|
searchphrase: |
|
expression /^\Z/ { |
|
# &Apache::lonsearchcat::print_item(\@item,0); |
|
[@item]; |
|
} |
|
expression: |
|
phrase(s) { |
|
[@item]; |
|
} |
|
phrase: |
|
orword { |
|
[@item]; |
|
} |
|
| andword { |
|
[@item]; |
|
} |
|
| minusword { |
|
unshift(@::Phrases,$item[1]->[0]); |
|
unshift(@::Phrases,$item[1]->[1]); |
|
[@item]; |
|
} |
|
| word { |
|
unshift(@::Phrases,$item[1]); |
|
[@item]; |
|
} |
|
# |
|
orword: |
|
word 'OR' phrase { |
|
unshift(@::Phrases,'OR'); |
|
unshift(@::Phrases,$item[1]); |
|
[@item]; |
|
} |
|
| word 'or' phrase { |
|
unshift(@::Phrases,'OR'); |
|
unshift(@::Phrases,$item[1]); |
|
[@item]; |
|
} |
|
| minusword 'OR' phrase { |
|
unshift(@::Phrases,'OR'); |
|
unshift(@::Phrases,$item[1]->[0]); |
|
unshift(@::Phrases,$item[1]->[1]); |
|
[@item]; |
|
} |
|
| minusword 'or' phrase { |
|
unshift(@::Phrases,'OR'); |
|
unshift(@::Phrases,$item[1]->[0]); |
|
unshift(@::Phrases,$item[1]->[1]); |
|
[@item]; |
|
} |
|
andword: |
|
word phrase { |
|
unshift(@::Phrases,'AND'); |
|
unshift(@::Phrases,$item[1]); |
|
[@item]; |
|
} |
|
| minusword phrase { |
|
unshift(@::Phrases,'AND'); |
|
unshift(@::Phrases,$item[1]->[0]); |
|
unshift(@::Phrases,$item[1]->[1]); |
|
[@item]; |
|
} |
|
# |
|
minusword: |
|
'-' word { |
|
[$item[2],'NOT']; |
|
} |
|
word: |
|
"'" term(s) "'" { |
|
&Apache::lonsearchcat::concat(\@item); |
|
} |
|
| '"' term(s) '"' { |
|
&Apache::lonsearchcat::concat(\@item); |
|
} |
|
| term { |
|
$item[1]; |
|
} |
|
term: |
|
/[\w\Q:!@#$%^&*()+_=|{}<>,.;\\\/?\E]+/ { |
|
$item[1]; |
|
} |
|
ENDGRAMMAR |
|
# |
|
# The end result of parsing the phrase with the grammar is an array |
|
# @::Phrases. |
|
# $phrase = "gene splicing" or cat -> "gene splicing","OR","cat" |
|
# $phrase = "genetic engineering" -dna -> |
|
# "genetic engineering","AND","NOT","dna" |
|
# $phrase = cat or dog -poodle -> "cat","OR","dog","AND","NOT","poodle" |
|
undef(@::Phrases); |
|
my $p = new Parse::RecDescent($grammar); |
|
if (! defined($p->searchphrase($phrase))) { |
|
&Apache::lonnet::logthis('lonsearchcat:unable to process:'.$phrase); |
|
return 'Unable to process phrase '.$phrase; |
|
} |
|
# |
|
# Go through the phrases and make sense of them. |
|
# Apply modifiers NOT OR and AND to the phrases. |
|
my @NewPhrases; |
|
while(@::Phrases) { |
|
my $phrase = shift(@::Phrases); |
|
# &Apache::lonnet::logthis('phrase = '.$phrase); |
|
my $phrasedata; |
|
if ($phrase =~ /^(NOT|OR|AND)$/) { |
|
if ($phrase eq 'OR') { |
|
$phrasedata->{'or'}++; |
|
if (! @::Phrases) { $phrasedata = undef; last; } |
|
$phrase = shift(@::Phrases); |
|
} elsif ($phrase eq 'AND') { |
|
$phrasedata->{'and'}++; |
|
if (! @::Phrases) { $phrasedata = undef; last; } |
|
$phrase = shift(@::Phrases); |
|
} |
|
if ($phrase eq 'NOT') { |
|
$phrasedata->{'negate'}++; |
|
if (! @::Phrases) { $phrasedata = undef; last; } |
|
$phrase = shift(@::Phrases); |
|
} |
|
} |
|
$phrasedata->{'phrase'} = $phrase; |
|
if ($related) { |
|
my @NewWords; |
|
(undef,@NewWords) = &related_version($phrasedata->{'phrase'}); |
|
$phrasedata->{'related_words'} = \@NewWords; |
|
} |
|
push(@NewPhrases,$phrasedata); |
|
} |
|
# |
|
# Actually build the sql query from the phrases |
|
my $SQLQuery; |
|
foreach my $phrase (@NewPhrases) { |
|
my $query; |
|
if ($phrase->{'negate'}) { |
|
$query .= $field.' NOT LIKE "%'.$phrase->{'phrase'}.'%"'; |
|
} else { |
|
$query .= $field.' LIKE "%'.$phrase->{'phrase'}.'%"'; |
|
} |
|
foreach my $related (@{$phrase->{'related_words'}}) { |
|
if ($phrase->{'negate'}) { |
|
$query .= ' AND '.$field.' NOT LIKE "%'.$related.'%"'; |
|
} else { |
|
$query .= ' OR '.$field.' LIKE "%'.$related.'%"'; |
|
} |
|
} |
|
if ($SQLQuery) { |
|
if ($phrase->{'or'}) { |
|
$SQLQuery .= ' OR ('.$query.')'; |
|
} else { |
|
$SQLQuery .= ' AND ('.$query.')'; |
|
} |
|
} else { |
|
$SQLQuery = '('.$query.')'; |
|
} |
|
} |
|
# |
|
# &Apache::lonnet::logthis("SQLQuery = $SQLQuery"); |
|
# |
|
return undef,$SQLQuery; |
|
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 1476 Note: Using this twice on a string is pr
|
Line 1725 Note: Using this twice on a string is pr
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
sub related_version { |
sub related_version { |
my $search_string = shift; |
my ($word) = @_; |
my $result = $search_string; |
return (undef) if (lc($word) =~ /\b(or|and|not)\b/); |
my %New_Words = (); |
my @Words = &Apache::loncommon::get_related_words($word); |
while ($search_string =~ /(\w+)/cg) { |
# Only use 4 related words |
my $word = $1; |
@Words = ($#Words>4? @Words[0..4] : @Words); |
next if (lc($word) =~ /\b(or|and|not)\b/); |
my $result = join " OR ", ($word,@Words); |
my @Words = &Apache::loncommon::get_related_words($word); |
return $result,sort(@Words); |
@Words = ($#Words>4? @Words[0..4] : @Words); |
|
foreach (@Words) { $New_Words{$_}++;} |
|
my $replacement = join " OR ", ($word,@Words); |
|
$result =~ s/(\b)$word(\b)/$1($replacement)$2/g; |
|
} |
|
return $result,sort(keys(%New_Words)); |
|
} |
} |
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &build_SQL_query() |
|
|
|
Builds a SQL query string from a logical expression with AND/OR keywords |
|
using Text::Query and &recursive_SQL_query_builder() |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub build_SQL_query { |
|
my ($field_name,$logic_statement)=@_; |
|
my $q=new Text::Query('abc', |
|
-parse => 'Text::Query::ParseAdvanced', |
|
-build => 'Text::Query::Build'); |
|
$q->prepare($logic_statement); |
|
my $matchexp=${$q}{'matchexp'}; chomp $matchexp; |
|
my $sql_query=&recursive_SQL_query_build($field_name,$matchexp); |
|
return $sql_query; |
|
} |
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 1549 sub build_custommetadata_query {
|
Line 1768 sub build_custommetadata_query {
|
return $matchexp; |
return $matchexp; |
} |
} |
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &recursive_SQL_query_build() |
|
|
|
Recursively constructs an SQL query. Takes as input $dkey and $pattern. |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub recursive_SQL_query_build { |
|
my ($dkey,$pattern)=@_; |
|
my @matches=($pattern=~/(\[[^\]|\[]*\])/g); |
|
return $pattern unless @matches; |
|
foreach my $match (@matches) { |
|
$match=~/\[ (\w+)\s(.*) \]/; |
|
my ($key,$value)=($1,$2); |
|
my $replacement=''; |
|
if ($key eq 'literal') { |
|
$replacement="($dkey LIKE \"\%$value\%\")"; |
|
} elsif (lc($key) eq 'not') { |
|
$value=~s/LIKE/NOT LIKE/; |
|
# $replacement="($dkey not like $value)"; |
|
$replacement="$value"; |
|
} elsif ($key eq 'and') { |
|
$value=~/(.*[\"|\)]) ([|\(|\^].*)/; |
|
$replacement="($1 AND $2)"; |
|
} elsif ($key eq 'or') { |
|
$value=~/(.*[\"|\)]) ([|\(|\^].*)/; |
|
$replacement="($1 OR $2)"; |
|
} |
|
substr($pattern, |
|
index($pattern,$match), |
|
length($match), |
|
$replacement); |
|
} |
|
&recursive_SQL_query_build($dkey,$pattern); |
|
} |
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 1782 a link to change the search query.
|
Line 1960 a link to change the search query.
|
###################################################################### |
###################################################################### |
sub print_sort_form { |
sub print_sort_form { |
my ($r,$pretty_query_string) = @_; |
my ($r,$pretty_query_string) = @_; |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1). |
|
&Apache::lonhtmlcommon::breadcrumbs |
|
(undef,'Searching','Searching',undef,undef, |
|
$ENV{'form.catalogmode'} ne 'groupsearch'); |
|
|
## |
## |
my %SortableFields=&Apache::lonlocal::texthash( |
my %SortableFields=&Apache::lonlocal::texthash( |
id => 'Default', |
id => 'Default', |
Line 2048 results into MySQL.
|
Line 2230 results into MySQL.
|
sub run_search { |
sub run_search { |
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; |
my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_; |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
|
$bodytag.=&Apache::lonhtmlcommon::breadcrumbs |
|
(undef,'Searching','Searching',undef,undef, |
|
$ENV{'form.catalogmode'} ne 'groupsearch'); |
my $connection = $r->connection; |
my $connection = $r->connection; |
# |
# |
# Print run_search header |
# Print run_search header |
Line 2157 END
|
Line 2342 END
|
# |
# |
# Loop through the servers we have contacted but do not |
# Loop through the servers we have contacted but do not |
# have results from yet, looking for results. |
# have results from yet, looking for results. |
while (my ($server,$status) = each(%Server_status)) { |
foreach my $server (keys(%Server_status)) { |
last if ($connection->aborted()); |
last if ($connection->aborted()); |
&update_seconds($r); |
&update_seconds($r); |
|
my $status = $Server_status{$server}; |
if ($status eq 'con_lost') { |
if ($status eq 'con_lost') { |
delete ($Server_status{$server}); |
delete ($Server_status{$server}); |
next; |
next; |
Line 2231 END
|
Line 2417 END
|
# results to get, so let the client know the top frame needs to be |
# results to get, so let the client know the top frame needs to be |
# loaded from /adm/searchcat |
# loaded from /adm/searchcat |
$r->print("</body></html>"); |
$r->print("</body></html>"); |
if ($ENV{'form.catalogmode'} ne 'groupsearch') { |
# if ($ENV{'form.catalogmode'} ne 'groupsearch') { |
$r->print("<script>". |
$r->print("<script>". |
"window.location='/adm/searchcat?". |
"window.location='/adm/searchcat?". |
"phase=sort&". |
"phase=sort&". |
"persistent_db_id=$ENV{'form.persistent_db_id'}';". |
"persistent_db_id=$ENV{'form.persistent_db_id'}';". |
"</script>"); |
"</script>"); |
} |
# } |
return; |
return; |
} |
} |
|
|
Line 2258 sub prev_next_buttons {
|
Line 2444 sub prev_next_buttons {
|
my ($current_min,$show,$total,$parms) = @_; |
my ($current_min,$show,$total,$parms) = @_; |
return '' if ($show eq 'all'); # No links if you get them all at once. |
return '' if ($show eq 'all'); # No links if you get them all at once. |
# |
# |
# Create links |
# Create buttons |
my $prev_min = $current_min - $show; |
my $buttons = '<input type="submit" name="prev" value="'.&mt('Prev').'" '; |
$prev_min = 1 if $prev_min < 1; |
$buttons .= '/>'; |
my $prevlink = |
$buttons .= ' 'x3; |
qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">}; |
$buttons .= '<input type="submit" name="reload" '. |
# |
'value="'.&mt('Reload').'" />'; |
my $next_min = $current_min + $show; |
$buttons .= ' 'x3; |
$next_min = $current_min if ($next_min > $total); |
$buttons .= '<input type="submit" name="next" value="'.&mt('Next').'" '; |
my $nextlink = |
$buttons .= '/>'; |
qq{<a href="/adm/searchcat?$parms&start=$next_min&show=$show">}; |
return $buttons; |
my $reloadlink = |
|
qq{<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">}; |
|
# |
|
# Determine which parameters to pass |
|
my $String = '[_1]prev[_2] [_3]reload[_4] [_5]next[_6]'; |
|
if ($prev_min == $current_min) { |
|
$String =~ s:\[_[12]\]::g; |
|
} |
|
if ($next_min == $current_min) { |
|
$String =~ s:\[_[56]\]::g; |
|
} |
|
my $links = &mt($String, |
|
$prevlink, '</a>', |
|
$reloadlink,'</a>', |
|
$nextlink, '</a>'); |
|
return $links; |
|
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 2346 sub display_results {
|
Line 2516 sub display_results {
|
} |
} |
## |
## |
## Determine how many results we need to get |
## Determine how many results we need to get |
$ENV{'form.start'} = 1 if (! exists($ENV{'form.start'})); |
$ENV{'form.start'} = 1 if (! exists($ENV{'form.start'})); |
$ENV{'form.show'} = 'all' if (! exists($ENV{'form.show'})); |
$ENV{'form.show'} = 20 if (! exists($ENV{'form.show'})); |
|
if (exists($ENV{'form.prev'})) { |
|
$ENV{'form.start'} -= $ENV{'form.show'}; |
|
} elsif (exists($ENV{'form.next'})) { |
|
$ENV{'form.start'} += $ENV{'form.show'}; |
|
} |
|
$ENV{'form.start'} = 1 if ($ENV{'form.start'}<1); |
|
$ENV{'form.start'} = $total_results if ($ENV{'form.start'}>$total_results); |
my $min = $ENV{'form.start'}; |
my $min = $ENV{'form.start'}; |
my $max; |
my $max; |
if ($ENV{'form.show'} eq 'all') { |
if ($ENV{'form.show'} eq 'all') { |
Line 2357 sub display_results {
|
Line 2534 sub display_results {
|
$max = $total_results if ($max > $total_results); |
$max = $total_results if ($max > $total_results); |
} |
} |
## |
## |
|
## Output form elements |
|
$r->print(&hidden_field('table'). |
|
&hidden_field('phase'). |
|
&hidden_field('persistent_db_id'). |
|
&hidden_field('start') |
|
); |
|
## |
## Output links (if necessary) for 'prev' and 'next' pages. |
## Output links (if necessary) for 'prev' and 'next' pages. |
$r->print |
$r->print |
('<center>'. |
('<table width="100%"><tr><td width="50%" align="right">'. |
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
&prev_next_buttons($min,$ENV{'form.show'},$total_results). |
"table=".$ENV{'form.table'}. |
'</td><td align="right">'. |
"&phase=results". |
&viewoptions().'</td></tr></table>' |
"&persistent_db_id=".$ENV{'form.persistent_db_id'}) |
|
."</center>\n" |
|
); |
); |
if ($total_results == 0) { |
if ($total_results == 0) { |
$r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'. |
$r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'. |
Line 2703 SCRIPT
|
Line 2885 SCRIPT
|
$result.=<<END; |
$result.=<<END; |
</head> |
</head> |
$bodytag |
$bodytag |
<form name="results" method="post" action="" > |
<form name="results" method="post" action="/adm/searchcat" > |
<input type="hidden" name="Queue" value="" /> |
<input type="hidden" name="Queue" value="" /> |
$importbutton |
$importbutton |
END |
END |
Line 2761 ENDFRAMES
|
Line 2943 ENDFRAMES
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
|
sub has_stat_data { |
|
my ($values) = @_; |
|
if ( (defined($values->{'count'}) && $values->{'count'} ne '') || |
|
(defined($values->{'stdno'}) && $values->{'stdno'} ne '') || |
|
(defined($values->{'disc'}) && $values->{'disc'} ne '') || |
|
(defined($values->{'avetries'}) && $values->{'avetries'} ne '') || |
|
(defined($values->{'difficulty'}) && $values->{'difficulty'} ne '')) { |
|
return 1; |
|
} |
|
return 0; |
|
} |
|
|
|
sub statfields { |
|
return ('count','stdno','disc','avetries','difficulty'); |
|
} |
|
|
|
sub has_eval_data { |
|
my ($values) = @_; |
|
if ( (defined($values->{'clear'}) && $values->{'clear'} ne '') || |
|
(defined($values->{'technical'}) && $values->{'technical'} ne '') || |
|
(defined($values->{'correct'}) && $values->{'correct'} ne '') || |
|
(defined($values->{'helpful'}) && $values->{'helpful'} ne '') || |
|
(defined($values->{'depth'}) && $values->{'depth'} ne '')) { |
|
return 1; |
|
} |
|
return 0; |
|
} |
|
|
|
sub evalfields { |
|
return ('clear','technical','correct','helpful','depth'); |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
=pod |
=pod |
|
|
=item Metadata Viewing Functions |
=item Metadata Viewing Functions |
Line 2782 extra custom metadata to show.
|
Line 2999 extra custom metadata to show.
|
###################################################################### |
###################################################################### |
sub detailed_citation_view { |
sub detailed_citation_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $icon= |
|
my $result; |
my $result; |
$result .= '<b>'.$prefix. |
$result .= '<b>'.$prefix. |
'<img src="'.&Apache::loncommon::icon($values{'url'}).' " />'. |
'<img src="'.&Apache::loncommon::icon($values{'url'}).' " />'.' '. |
'<a href="http://'.$ENV{'HTTP_HOST'}.$values{'url'}.'" '. |
'<a href="http://'.$ENV{'HTTP_HOST'}.$values{'url'}.'" '. |
'target="search_preview">'.$values{'title'}."</a></b>\n"; |
'target="search_preview">'.$values{'title'}."</a></b>\n"; |
$result .= "<p>\n"; |
$result .= "<p>\n"; |
Line 2793 sub detailed_citation_view {
|
Line 3009 sub detailed_citation_view {
|
' <i>'.$values{'owner'}.'</i><br />'; |
' <i>'.$values{'owner'}.'</i><br />'; |
foreach my $field |
foreach my $field |
( |
( |
|
{ name=>'url', |
|
translate => '<b>URL:</b> [_1]', |
|
special => 'url link',}, |
{ name=>'subject', |
{ name=>'subject', |
translate => '<b>Subject:</b> [_1]',}, |
translate => '<b>Subject:</b> [_1]',}, |
{ name=>'keywords', |
{ name=>'keywords', |
Line 2805 sub detailed_citation_view {
|
Line 3024 sub detailed_citation_view {
|
translate => '<b>Standards:</b>[_1]',}, |
translate => '<b>Standards:</b>[_1]',}, |
{ name=>'copyrighttag', |
{ name=>'copyrighttag', |
translate => '<b>Copyright/Distribution:</b> [_1]',}, |
translate => '<b>Copyright/Distribution:</b> [_1]',}, |
|
{ name=>'count', |
|
format => "%d", |
|
translate => '<b>Access Count:</b> [_1]',}, |
{ name=>'stdno', |
{ name=>'stdno', |
|
format => "%d", |
translate => '<b>Number of Students:</b> [_1]',}, |
translate => '<b>Number of Students:</b> [_1]',}, |
{ name=>'avetries', |
{ name=>'avetries', |
|
format => "%.2f", |
translate => '<b>Average Tries:</b> [_1]',}, |
translate => '<b>Average Tries:</b> [_1]',}, |
{ name=>'disc', |
{ name=>'disc', |
|
format => "%.2f", |
translate => '<b>Degree of Discrimination:</b> [_1]',}, |
translate => '<b>Degree of Discrimination:</b> [_1]',}, |
{ name=>'difficulty', |
{ name=>'difficulty', |
|
format => "%.2f", |
translate => '<b>Degree of Difficulty:</b> [_1]',}, |
translate => '<b>Degree of Difficulty:</b> [_1]',}, |
{ name=>'clear', |
{ name=>'clear', |
|
format => "%.2f", |
translate => '<b>Clear:</b> [_1]',}, |
translate => '<b>Clear:</b> [_1]',}, |
{ name=>'depth', |
{ name=>'depth', |
|
format => "%.2f", |
translate => '<b>Depth:</b> [_1]',}, |
translate => '<b>Depth:</b> [_1]',}, |
{ name=>'helpful', |
{ name=>'helpful', |
|
format => "%.2f", |
translate => '<b>Helpful:</b> [_1]',}, |
translate => '<b>Helpful:</b> [_1]',}, |
{ name=>'correct', |
{ name=>'correct', |
translate => '<b>Correcy:</b> [_1]',}, |
format => "%.2f", |
|
translate => '<b>Correct:</b> [_1]',}, |
{ name=>'technical', |
{ name=>'technical', |
|
format => "%.2f", |
translate => '<b>Technical:</b> [_1]',}, |
translate => '<b>Technical:</b> [_1]',}, |
|
{ name=>'comefrom_list', |
|
type => 'list', |
|
translate => 'Resources that lead up to this resource in maps',}, |
|
{ name=>'goto_list', |
|
type => 'list', |
|
translate => 'Resources that follow this resource in maps',}, |
|
{ name=>'sequsage_list', |
|
type => 'list', |
|
translate => 'Resources using or importing resource',}, |
) { |
) { |
$result.= &mt($field->{'translate'},$values{$field->{'name'}}). |
next if (! exists($values{$field->{'name'}}) || |
"<br />\n"; |
$values{$field->{'name'}} eq ''); |
|
if (exists($field->{'type'}) && $field->{'type'} eq 'list') { |
|
$result .= '<b>'.&mt($field->{'translate'}).'</b><ul>'; |
|
foreach my $item (split(',',$values{$field->{'name'}})){ |
|
$result .= '<li>'. |
|
'<a target="search_preview" '. |
|
'href="/res/'.$item.'">'.$item.'</a></li>'; |
|
} |
|
$result .= '</ul>'; |
|
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ |
|
$result.= &mt($field->{'translate'}, |
|
sprintf($field->{'format'}, |
|
$values{$field->{'name'}})).'<br />'."\n"; |
|
} else { |
|
if ($field->{'special'} eq 'url link') { |
|
$result.= |
|
&mt($field->{'translate'}, |
|
'<a href="'.$values{'url'}.'" '. |
|
'target="search_preview">'. |
|
$values{$field->{'name'}}. |
|
'</a>'); |
|
} else { |
|
$result.= &mt($field->{'translate'}, |
|
$values{$field->{'name'}}); |
|
} |
|
$result .= "<br />\n"; |
|
} |
|
} |
|
$result .= "</p>"; |
|
if (exists($values{'extrashow'}) && $values{'extrashow'} ne '') { |
|
$result .= '<p>'.$values{'extrashow'}.'</p>'; |
|
} |
|
if (exists($values{'shortabstract'}) && $values{'shortabstract'} ne '') { |
|
$result .= '<p>'.$values{'shortabstract'}.'</p>'; |
} |
} |
$result .= "</p>".$values{'extrashow'}. |
|
'<p>'.$values{'shortabstract'}.'</p>'; |
|
$result .= '<hr align="left" width="200" noshade />'."\n"; |
$result .= '<hr align="left" width="200" noshade />'."\n"; |
return $result; |
return $result; |
} |
} |
Line 2847 sub summary_view {
|
Line 3118 sub summary_view {
|
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $icon=&Apache::loncommon::icon($values{'url'}); |
my $icon=&Apache::loncommon::icon($values{'url'}); |
my $result=<<END; |
my $result=<<END; |
$prefix<img src="$icon" /><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
$prefix<img src="$icon" /> |
|
<a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
target='search_preview'>$values{'author'}</a><br /> |
target='search_preview'>$values{'author'}</a><br /> |
$values{'title'}<br /> |
$values{'title'}<br /> |
$values{'owner'} -- $values{'lastrevisiondate'}<br /> |
$values{'owner'} -- $values{'lastrevisiondate'}<br /> |
Line 2872 END
|
Line 3144 END
|
###################################################################### |
###################################################################### |
sub compact_view { |
sub compact_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $icon=&Apache::loncommon::icon($values{'url'}); |
my $result = |
my $result=<<END; |
$prefix.'<img src="'.&Apache::loncommon::icon($values{'url'}). |
$prefix <img src="$icon" /> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" target='search_preview'> |
'"> <a href="'.$values{'url'}.'" target="search_preview">'. |
$values{'title'}</a> |
$values{'title'}.'</a>'.(' 'x2). |
<b>$values{'author'}</b><br /> |
'<b>'.$values{'author'}.'</b><br />'; |
END |
|
return $result; |
return $result; |
} |
} |
|
|
Line 2896 END
|
Line 3167 END
|
sub fielded_format_view { |
sub fielded_format_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $icon=&Apache::loncommon::icon($values{'url'}); |
my $icon=&Apache::loncommon::icon($values{'url'}); |
|
my %Translated = &Apache::lonmeta::fieldnames(); |
my $result=<<END; |
my $result=<<END; |
$prefix <img src="$icon" /> |
$prefix <img src="$icon" /> |
<b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
<dl> |
target='search_preview'>$values{'url'}</a> |
<dt>URL:</dt> |
<br /> |
<dd><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
<b>Title:</b> $values{'title'}<br /> |
target='search_preview'>$values{'url'}</a></dd> |
<b>Author(s):</b> $values{'author'}<br /> |
|
<b>Subject:</b> $values{'subject'}<br /> |
|
<b>Keyword(s):</b> $values{'keywords'}<br /> |
|
<b>Notes:</b> $values{'notes'}<br /> |
|
<b>MIME Type:</b> $values{'mimetag'}<br /> |
|
<b>Language:</b> $values{'language'}<br /> |
|
<b>Creation Date:</b> $values{'creationdate'}<br /> |
|
<b>Last Revision Date:</b> $values{'lastrevisiondate'}<br /> |
|
<b>Publisher/Owner:</b> $values{'owner'}<br /> |
|
<b>Copyright/Distribution:</b> $values{'copyrighttag'}<br /> |
|
<b>Repository Location:</b> $values{'hostname'}<br /> |
|
<b>Abstract:</b> $values{'shortabstract'}<br /> |
|
$values{'extrashow'} |
|
</p> |
|
<hr align='left' width='200' noshade /> |
|
END |
END |
|
foreach my $field ('title','author','subject','keywords','notes', |
|
'mimetag','language','creationdate','lastrevisiondate', |
|
'owner','copyrighttag','hostname','abstract') { |
|
$result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n". |
|
(' 'x8).'<dd>'.$values{$field}.'</dd>'."\n"; |
|
} |
|
if (&has_stat_data(\%values)) { |
|
foreach my $field (&statfields()) { |
|
$result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n". |
|
(' 'x8).'<dd>'.$values{$field}.'</dd>'."\n"; |
|
} |
|
} |
|
if (&has_eval_data(\%values)) { |
|
foreach my $field (&evalfields()) { |
|
$result .= (' 'x4).'<dt>'.$Translated{$field}.'</dt>'."\n". |
|
(' 'x8).'<dd>'.$values{$field}.'</dd>'."\n"; |
|
} |
|
} |
|
$result .= "</dl>\n"; |
|
$result .= $values{'extrashow'}; |
|
$result .= '<hr align="left" width="200" noshade />'."\n"; |
return $result; |
return $result; |
} |
} |
|
|
Line 2936 END
|
Line 3214 END
|
###################################################################### |
###################################################################### |
sub xml_sgml_view { |
sub xml_sgml_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $xml = <<END; |
my $xml = '<LonCapaResource>'."\n"; |
<LonCapaResource> |
# The usual suspects |
<url>$values{'url'}</url> |
foreach my $field ('url','title','author','subject','keywords','notes') { |
<title>$values{'title'}</title> |
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
<author>$values{'author'}</author> |
} |
<subject>$values{'subject'}</subject> |
# |
<keywords>$values{'keywords'}</keywords> |
$xml .= "<mimeInfo>\n"; |
<notes>$values{'notes'}</notes> |
foreach my $field ('mime','mimetag') { |
<mimeInfo> |
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
<mime>$values{'mime'}</mime> |
} |
<mimetag>$values{'mimetag'}</mimetag> |
$xml .= "</mimeInfo>\n"; |
</mimeInfo> |
# |
<languageInfo> |
$xml .= "<languageInfo>\n"; |
<language>$values{'language'}</language> |
foreach my $field ('language','languagetag') { |
<languagetag>$values{'languagetag'}</languagetag> |
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
</languageInfo> |
} |
<creationdate>$values{'creationdate'}</creationdate> |
$xml .= "</languageInfo>\n"; |
<lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate> |
# |
<owner>$values{'owner'}</owner> |
foreach my $field ('creationdate','lastrevisiondate','owner') { |
<copyrightInfo> |
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
<copyright>$values{'copyright'}</copyright> |
} |
<copyrighttag>$values{'copyrighttag'}</copyrighttag> |
# |
</copyrightInfo> |
$xml .= "<copyrightInfo>\n"; |
<repositoryLocation>$values{'hostname'}</repositoryLocation> |
foreach my $field ('copyright','copyrighttag') { |
<shortabstract>$values{'shortabstract'}</shortabstract> |
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
</LonCapaResource> |
} |
END |
$xml .= "</copyrightInfo>\n"; |
|
$xml .= qq{<repositoryLocation>$values{'hostname'}</repositoryLocation>}. |
|
"\n"; |
|
$xml .= qq{<shortabstract>$values{'shortabstract'}</shortabstract>}."\n"; |
|
# |
|
if (&has_stat_data(\%values)){ |
|
$xml .= "<problemstatistics>\n"; |
|
foreach my $field (&statfields()) { |
|
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
|
} |
|
$xml .= "</problemstatistics>\n"; |
|
} |
|
# |
|
if (&has_eval_data(\%values)) { |
|
$xml .= "<evaluation>\n"; |
|
foreach my $field (&evalfields) { |
|
$xml .= qq{<$field>$values{$field}</$field>}."\n"; |
|
} |
|
$xml .= "</evaluation>\n"; |
|
} |
|
# |
|
$xml .= "</LonCapaResource>\n"; |
$xml = &HTML::Entities::encode($xml,'<>&'); |
$xml = &HTML::Entities::encode($xml,'<>&'); |
my $result=<<END; |
my $result=<<END; |
$prefix |
$prefix |
Line 3000 sub filled {
|
Line 3299 sub filled {
|
|
|
=pod |
=pod |
|
|
|
=item &output_unparsed_phrase_error() |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub output_unparsed_phrase_error { |
|
my ($r,$closebutton,$parms,$hidden_fields,$field)=@_; |
|
my $errorstring; |
|
if ($field eq 'basicexp') { |
|
$errorstring = &mt('Unable to understand the search phrase <i>[_1]</i>. Please modify your search.',$ENV{'form.basicexp'}); |
|
} else { |
|
$errorstring = &mt('Unable to understand the search phrase <b>[_1]</b>:<i>[_2]</i>.',$field,$ENV{'form.'.$field}); |
|
} |
|
my $bodytag = &Apache::loncommon::bodytag('Search'); |
|
my $heading = &mt('Unparsed Field'); |
|
my $revise = &mt('Revise search request'); |
|
# make query information persistent to allow for subsequent revision |
|
$r->print(<<ENDPAGE); |
|
<html> |
|
<head> |
|
<title>The LearningOnline Network with CAPA</title> |
|
</head> |
|
$bodytag |
|
<form method="post" action="/adm/searchcat"> |
|
$hidden_fields |
|
$closebutton |
|
<hr /> |
|
<h2>$heading</h2> |
|
<p> |
|
$errorstring |
|
</p> |
|
<p> |
|
<a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}">$revise</a> |
|
</p> |
|
</body> |
|
</html> |
|
ENDPAGE |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
=item &output_blank_field_error() |
=item &output_blank_field_error() |
|
|
Output a complete page that indicates the user has not filled in enough |
Output a complete page that indicates the user has not filled in enough |
Line 3017 $parms is extra information to include i
|
Line 3361 $parms is extra information to include i
|
###################################################################### |
###################################################################### |
sub output_blank_field_error { |
sub output_blank_field_error { |
my ($r,$closebutton,$parms,$hidden_fields)=@_; |
my ($r,$closebutton,$parms,$hidden_fields)=@_; |
my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1); |
my $bodytag=&Apache::loncommon::bodytag('Search'); |
# make query information persistent to allow for subsequent revision |
my $errormsg = &mt('You did not fill in enough information for the search to be started. You need to fill in relevant fields on the search page in order for a query to be processed.'); |
$r->print(<<BEGINNING); |
my $revise = &mt('Revise Search Request'); |
|
my $heading = &mt('Unactionable Search Queary'); |
|
$r->print(<<ENDPAGE); |
<html> |
<html> |
<head> |
<head> |
<title>The LearningOnline Network with CAPA</title> |
<title>The LearningOnline Network with CAPA</title> |
BEGINNING |
|
$r->print(<<RESULTS); |
|
</head> |
</head> |
$bodytag |
$bodytag |
<img align='right' src='/adm/lonIcons/lonlogos.gif' /> |
|
<h1>Search Catalog</h1> |
|
<form method="post" action="/adm/searchcat"> |
<form method="post" action="/adm/searchcat"> |
$hidden_fields |
$hidden_fields |
<a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}" |
|
>Revise search request</a> |
|
$closebutton |
$closebutton |
<hr /> |
<hr /> |
<h3>Unactionable search query.</h3> |
<h2>$heading</h2> |
<p> |
<p> |
You did not fill in enough information for the search to be started. |
$errormsg |
You need to fill in relevant fields on the search page in order |
</p> |
for a query to be processed. |
<p> |
|
<a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}">$revise</a> |
</p> |
</p> |
</body> |
</body> |
</html> |
</html> |
RESULTS |
ENDPAGE |
|
return; |
} |
} |
|
|
###################################################################### |
###################################################################### |