version 1.245, 2005/04/07 07:34:52
|
version 1.255, 2006/03/06 18:23:10
|
Line 77 use LONCAPA::lonmetadata();
|
Line 77 use LONCAPA::lonmetadata();
|
use HTML::Entities(); |
use HTML::Entities(); |
use Parse::RecDescent; |
use Parse::RecDescent; |
use Apache::lonnavmaps; |
use Apache::lonnavmaps; |
|
use Apache::lonindexer(); |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 93 my %persistent_db; # gdbm hash which h
|
Line 94 my %persistent_db; # gdbm hash which h
|
# The different view modes and associated functions |
# The different view modes and associated functions |
|
|
my %Views = ("detailed" => \&detailed_citation_view, |
my %Views = ("detailed" => \&detailed_citation_view, |
|
"detailedpreview" => \&detailed_citation_preview, |
"summary" => \&summary_view, |
"summary" => \&summary_view, |
|
"summarypreview" => \&summary_preview, |
"fielded" => \&fielded_format_view, |
"fielded" => \&fielded_format_view, |
"xml" => \&xml_sgml_view, |
"xml" => \&xml_sgml_view, |
"compact" => \&compact_view); |
"compact" => \&compact_view); |
Line 283 END
|
Line 286 END
|
## Sanity checks on form elements |
## Sanity checks on form elements |
## |
## |
if (!defined($env{'form.viewselect'})) { |
if (!defined($env{'form.viewselect'})) { |
if (($env{'form.catalogmode'} eq 'groupsearch') || |
$env{'form.viewselect'} ="summary"; |
($env{'form.catalogmode'} eq 'interactive')) { |
|
$env{'form.viewselect'} ="Compact View"; |
|
} else { |
|
$env{'form.viewselect'} ="Detailed Citation View"; |
|
} |
|
} |
} |
$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'})); |
Line 708 sub print_basic_search_form {
|
Line 706 sub print_basic_search_form {
|
), |
), |
$r->dir_config('lonDefDomain') |
$r->dir_config('lonDefDomain') |
).'</label>'; |
).'</label>'; |
|
my $inclext= '<label>'. |
|
&mt('[_1] include external resources', |
|
&Apache::lonhtmlcommon::checkbox |
|
('inclext',$env{'form.inclext'})).'</label>'; |
my $adv_search_link = |
my $adv_search_link = |
'<a href="/adm/searchcat?'. |
'<a href="/adm/searchcat?'. |
'phase=disp_adv&'. |
'phase=disp_adv&'. |
Line 740 sub print_basic_search_form {
|
Line 742 sub print_basic_search_form {
|
'<nobr>'.(' 'x3).$adv_search_link.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x3).$adv_search_link.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x1).$userelatedwords.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x1).$userelatedwords.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x1).$onlysearchdomain.'</nobr>'.'<br />'. |
'<nobr>'.(' 'x1).$onlysearchdomain.'</nobr>'.'<br />'. |
'</font></td>'. |
'<nobr>'.(' 'x1).$inclext.'</nobr>'.'<br />'. |
|
'</font></td>'. |
'</tr>'.$/; |
'</tr>'.$/; |
# |
# |
$scrout .= '<tr><td align="center" colspan="2">'. |
$scrout .= '<tr><td align="center" colspan="2">'. |
Line 860 ENDHEADER
|
Line 863 ENDHEADER
|
'abstract' => 1, |
'abstract' => 1, |
'standards'=> 1, |
'standards'=> 1, |
'mime' => 1, |
'mime' => 1, |
|
'subject' => 1, |
); |
); |
# |
# |
foreach my $field ('title','author','owner','authorspace','modifyinguser', |
foreach my $field ('title','author','subject','owner','authorspace', |
'keywords','notes','abstract','standards','mime') { |
'modifyinguser','keywords','notes','abstract', |
|
'standards','mime') { |
$scrout.='<tr><td align="right">'.&titlefield($fields{$field}).'</td><td>'. |
$scrout.='<tr><td align="right">'.&titlefield($fields{$field}).'</td><td>'. |
&Apache::lonmeta::prettyinput($field, |
&Apache::lonmeta::prettyinput($field, |
$env{'form.'.$field}, |
$env{'form.'.$field}, |
Line 900 ENDHEADER
|
Line 905 ENDHEADER
|
&titlefield(&mt('Domains')).'</td><td colspan="2">'. |
&titlefield(&mt('Domains')).'</td><td colspan="2">'. |
&Apache::loncommon::domain_select('domains', |
&Apache::loncommon::domain_select('domains', |
$env{'form.domains'},1). |
$env{'form.domains'},1). |
'</td></tr>'.$/; |
'<br /><label>'. |
|
&mt('[_1] include external resources', |
|
&Apache::lonhtmlcommon::checkbox |
|
('inclext',$env{'form.inclext'})).'</label></td></tr>'.$/; |
# |
# |
# Misc metadata |
# Misc metadata |
$scrout.='<tr><td align="right" valign="top">'. |
$scrout.='<tr><td align="right" valign="top">'. |
Line 1075 sub viewoptiontext {
|
Line 1083 sub viewoptiontext {
|
'xml' => 'XML/SGML', |
'xml' => 'XML/SGML', |
'compact' => 'Compact View', |
'compact' => 'Compact View', |
'fielded' => 'Fielded Format', |
'fielded' => 'Fielded Format', |
'summary' => 'Summary View'); |
'summary' => 'Summary View', |
|
'summarypreview' => 'Summary Preview', |
|
'detailedpreview' => 'Detailed Citation Preview'); |
return $desc{$code}; |
return $desc{$code}; |
} |
} |
|
|
Line 1535 sub parse_advanced_search {
|
Line 1545 sub parse_advanced_search {
|
## |
## |
## Deal with restrictions to given domains |
## Deal with restrictions to given domains |
## |
## |
my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = |
my ($libraries_to_query,$pretty_domains_string) = &parse_domain_restrictions(); |
&parse_domain_restrictions(); |
if ($pretty_domains_string) { |
push(@queries,$domain_sql_restriction); |
$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).')'; |
Line 1561 sub parse_domain_restrictions {
|
Line 1571 sub parse_domain_restrictions {
|
# |
# |
my %domain_hash = (); |
my %domain_hash = (); |
my $pretty_domains_string; |
my $pretty_domains_string; |
my $domain_sql_restriction; |
|
foreach (@allowed_domains) { |
foreach (@allowed_domains) { |
$domain_hash{$_}++; |
$domain_hash{$_}++; |
} |
} |
if ($domain_hash{'any'}) { |
if ($domain_hash{'any'}) { |
$pretty_domains_string = "In all LON-CAPA domains."; |
$pretty_domains_string = "In all LON-CAPA domains."; |
$domain_sql_restriction = undef; |
|
} else { |
} else { |
if (@allowed_domains > 1) { |
if (@allowed_domains > 1) { |
$pretty_domains_string = "In LON-CAPA domains:"; |
$pretty_domains_string = "In LON-CAPA domains:"; |
} else { |
} else { |
$pretty_domains_string = "In LON-CAPA domain "; |
$pretty_domains_string = "In LON-CAPA domain "; |
} |
} |
$domain_sql_restriction = |
|
'(domain="'.join('" OR domain="',@allowed_domains).'")'; |
|
foreach (sort @allowed_domains) { |
foreach (sort @allowed_domains) { |
$pretty_domains_string .= "<b>".$_."</b> "; |
$pretty_domains_string .= "<b>".$_."</b> "; |
} |
} |
Line 1586 sub parse_domain_restrictions {
|
Line 1592 sub parse_domain_restrictions {
|
} |
} |
} |
} |
return ($libraries_to_query, |
return ($libraries_to_query, |
$pretty_domains_string, |
$pretty_domains_string); |
$domain_sql_restriction); |
|
} |
} |
|
|
###################################################################### |
###################################################################### |
Line 1616 sub parse_basic_search {
|
Line 1621 sub parse_basic_search {
|
$env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"}); |
$env{"form.$_"}=&Apache::lonnet::unescape($env{"form.$_"}); |
$env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; |
$env{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g; |
} |
} |
my ($libraries_to_query,$pretty_domains_string,$domain_sql_restriction) = |
my ($libraries_to_query,$pretty_domains_string) = &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 |
my $search_string = $env{'form.basicexp'}; |
my $search_string = $env{'form.basicexp'}; |
Line 1640 sub parse_basic_search {
|
Line 1644 sub parse_basic_search {
|
return; |
return; |
} |
} |
push(@Queries,$SQLQuery); |
push(@Queries,$SQLQuery); |
if (defined($domain_sql_restriction) && $domain_sql_restriction ne '') { |
|
push(@Queries,$domain_sql_restriction); |
|
} |
|
#foreach my $q (@Queries) { |
#foreach my $q (@Queries) { |
# &Apache::lonnet::logthis(' '.$q); |
# &Apache::lonnet::logthis(' '.$q); |
#} |
#} |
Line 2286 sub update_status {
|
Line 2287 sub update_status {
|
} |
} |
|
|
{ |
{ |
my $max_time = 40; # seconds for the search to complete |
my $max_time = 300; # seconds for the search to complete |
my $start_time = 0; |
my $start_time = 0; |
my $last_time = 0; |
my $last_time = 0; |
|
|
Line 2520 END
|
Line 2521 END
|
my %Fields = &parse_raw_result($result,$server); |
my %Fields = &parse_raw_result($result,$server); |
$Fields{'hostname'} = $server; |
$Fields{'hostname'} = $server; |
# |
# |
|
# Skip if external and we did not want that |
|
next if ((! $env{'form.inclext'}) && ($Fields{'url'}=~/^\/ext\//)); |
# Skip based on copyright |
# Skip based on copyright |
next if (! ©right_check(\%Fields)); |
next if (! ©right_check(\%Fields)); |
|
|
# |
# |
# Store the result in the mysql database |
# Store the result in the mysql database |
my $result = &Apache::lonmysql::store_row($table,\%Fields); |
my $result = &Apache::lonmysql::store_row($table,\%Fields); |
Line 2723 sub display_results {
|
Line 2727 sub display_results {
|
} |
} |
my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields; |
my %sort_fields = map {$_->{'key'},$_->{'desc'}} @fields; |
$sort_fields{'select_form_order'} = \@field_order; |
$sort_fields{'select_form_order'} = \@field_order; |
$env{'form.sortorder'} = 'asc' if (! exists($env{'form.sortorder'})); |
$env{'form.sortorder'} = 'desc' if (! exists($env{'form.sortorder'})); |
|
$env{'form.sortfield'} = 'count' if (! exists($env{'form.sortfield'})); |
|
if (! exists($env{'form.sortorder'})) { |
|
if ($env{'form.sortfield'}=~/^(count|stdno|disc|clear|technical|correct|helpful)$/) { |
|
$env{'form.sortorder'}='desc'; |
|
} else { |
|
$env{'form.sortorder'}='asc'; |
|
} |
|
} |
my $sortform = &mt('Sort by [_1] [_2]', |
my $sortform = &mt('Sort by [_1] [_2]', |
&Apache::loncommon::select_form($env{'form.sortfield'}, |
&Apache::loncommon::select_form($env{'form.sortfield'}, |
'sortfield', |
'sortfield', |
Line 2774 sub display_results {
|
Line 2786 sub display_results {
|
exists($sort_fields{$env{'form.sortfield'}})) { |
exists($sort_fields{$env{'form.sortfield'}})) { |
$sort_command = $env{'form.sortfield'}.' IS NOT NULL '. |
$sort_command = $env{'form.sortfield'}.' IS NOT NULL '. |
'ORDER BY '.$env{'form.sortfield'}.' '.$order. |
'ORDER BY '.$env{'form.sortfield'}.' '.$order. |
' LIMIT '.($min-1).','.($max-$min); |
' LIMIT '.($min-1).','.($max-$min+1); |
} |
} |
my @Results = &Apache::lonmysql::get_rows($table,$sort_command); |
my @Results = &Apache::lonmysql::get_rows($table,$sort_command); |
## |
## |
Line 3220 extra custom metadata to show.
|
Line 3232 extra custom metadata to show.
|
sub detailed_citation_view { |
sub detailed_citation_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
my $result; |
my $result; |
|
my $jumpurl=$values{'url'}; |
|
$jumpurl=~s/^\/ext\//http\:\/\//; |
$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="'.$jumpurl.'" '. |
'target="search_preview">'.$values{'title'}."</a></b>\n"; |
'target="search_preview">'.$values{'title'}."</a></b>\n"; |
$result .= "<p>\n"; |
$result .= "<p>\n"; |
$result .= '<b>'.$values{'author'}.'</b>,'. |
$result .= '<b>'.$values{'author'}.'</b>,'. |
Line 3291 sub detailed_citation_view {
|
Line 3305 sub detailed_citation_view {
|
foreach my $item (split(',',$values{$field->{'name'}})){ |
foreach my $item (split(',',$values{$field->{'name'}})){ |
$result .= '<li>'. |
$result .= '<li>'. |
'<a target="search_preview" '. |
'<a target="search_preview" '. |
'href="/res/'.$item.'">'.$item.'</a></li>'; |
'href="'.$jumpurl.'">'.$item.'</a></li>'; |
} |
} |
$result .= '</ul>'; |
$result .= '</ul>'; |
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ |
} elsif (exists($field->{'format'}) && $field->{'format'} ne ''){ |
Line 3302 sub detailed_citation_view {
|
Line 3316 sub detailed_citation_view {
|
if ($field->{'special'} eq 'url link') { |
if ($field->{'special'} eq 'url link') { |
$result.= |
$result.= |
&mt($field->{'translate'}, |
&mt($field->{'translate'}, |
'<a href="'.$values{'url'}.'" '. |
'<a href="'.$jumpurl.'" '. |
'target="search_preview">'. |
'target="search_preview">'. |
$values{$field->{'name'}}. |
$values{$field->{'name'}}. |
'</a>'); |
'</a>'); |
Line 3324 sub detailed_citation_view {
|
Line 3338 sub detailed_citation_view {
|
return $result; |
return $result; |
} |
} |
|
|
|
sub detailed_citation_preview { |
|
my ($prefix,%values)=@_; |
|
return '<table><tr><td>'. |
|
&detailed_citation_view($prefix,%values). |
|
'</td><td>'. |
|
&Apache::lonindexer::showpreview($values{'url'}). |
|
'</td></tr></table><hr />'; |
|
} |
|
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 3350 sub summary_view {
|
Line 3374 sub summary_view {
|
if (! defined($tmp)) { $tmp = 'undefined'; } |
if (! defined($tmp)) { $tmp = 'undefined'; } |
$result .= ' '.$tmp.' '; |
$result .= ' '.$tmp.' '; |
} |
} |
|
my $jumpurl=$values{'url'}; |
|
$jumpurl=~s/^\/ext\//http\:\/\//; |
|
|
$result.=<<END; |
$result.=<<END; |
<a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
<a href="$jumpurl" |
target='search_preview'>$values{'title'}</a><br /> |
target='search_preview'>$values{'title'}</a><br /> |
$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}<br /> |
$values{'author'}, $values{'owner'} -- $values{'lastrevisiondate'}<br /> |
$values{'copyrighttag'}<br /> |
$values{'copyrighttag'}<br /> |
Line 3362 END
|
Line 3389 END
|
return $result; |
return $result; |
} |
} |
|
|
|
sub summary_preview { |
|
my ($prefix,%values)=@_; |
|
return '<table><tr><td>'. |
|
&summary_view($prefix,%values). |
|
'</td><td>'. |
|
&Apache::lonindexer::showpreview($values{'url'}). |
|
'</td></tr></table><hr />'; |
|
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 3375 END
|
Line 3411 END
|
###################################################################### |
###################################################################### |
sub compact_view { |
sub compact_view { |
my ($prefix,%values) = @_; |
my ($prefix,%values) = @_; |
|
my $jumpurl=$values{'url'}; |
|
$jumpurl=~s/^\/ext\//http\:\/\//; |
|
|
my $result = |
my $result = |
$prefix.'<img src="'.&Apache::loncommon::icon($values{'url'}).'">'; |
$prefix.'<img src="'.&Apache::loncommon::icon($values{'url'}).'">'; |
if (exists($env{'form.sortfield'}) && |
if (exists($env{'form.sortfield'}) && |
Line 3383 sub compact_view {
|
Line 3422 sub compact_view {
|
if (! defined($tmp)) { $tmp = 'undefined'; } |
if (! defined($tmp)) { $tmp = 'undefined'; } |
$result .= ' '.$tmp.' '; |
$result .= ' '.$tmp.' '; |
} |
} |
$result.=' <a href="'.$values{'url'}.'" target="search_preview">'. |
$result.=' <a href="'.$jumpurl.'" target="search_preview">'. |
$values{'title'}.'</a>'.(' 'x2). |
$values{'title'}.'</a>'.(' 'x2). |
'<b>'.$values{'author'}.'</b><br />'; |
'<b>'.$values{'author'}.'</b> ('.$values{'domain'}.')<br />'; |
return $result; |
return $result; |
} |
} |
|
|
Line 3405 sub fielded_format_view {
|
Line 3444 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 %Translated = &Apache::lonmeta::fieldnames(); |
|
my $jumpurl=$values{'url'}; |
|
$jumpurl=~s/^\/ext\//http\:\/\//; |
|
|
my $result=<<END; |
my $result=<<END; |
$prefix <img src="$icon" /> |
$prefix <img src="$icon" /> |
<dl> |
<dl> |
<dt>URL:</dt> |
<dt>URL:</dt> |
<dd><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" |
<dd><a href="$jumpurl" |
target='search_preview'>$values{'url'}</a></dd> |
target='search_preview'>$values{'url'}</a></dd> |
END |
END |
foreach my $field ('title','author','domain','subject','keywords','notes', |
foreach my $field ('title','author','domain','subject','keywords','notes', |
Line 3710 sub cleanup {
|
Line 3752 sub cleanup {
|
} |
} |
&untiehash(); |
&untiehash(); |
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
|
return OK; |
} |
} |
|
|
__END__ |
__END__ |