version 1.198, 2003/12/27 23:04:28
|
version 1.207, 2004/04/19 13:51:36
|
Line 48 described at http://www.lon-capa.org.
|
Line 48 described at http://www.lon-capa.org.
|
lonsearchcat presents the user with an interface to search the LON-CAPA |
lonsearchcat presents the user with an interface to search the LON-CAPA |
digital library. lonsearchcat also initiates the execution of a search |
digital library. lonsearchcat also initiates the execution of a search |
by sending the search parameters to LON-CAPA servers. The progress of |
by sending the search parameters to LON-CAPA servers. The progress of |
search (on a server basis) is displayed to the user in a seperate window. |
search (on a server basis) is displayed to the user in a separate window. |
|
|
=head1 Internals |
=head1 Internals |
|
|
Line 70 use Text::Query;
|
Line 70 use Text::Query;
|
use GDBM_File; |
use GDBM_File; |
use Apache::loncommon(); |
use Apache::loncommon(); |
use Apache::lonmysql(); |
use Apache::lonmysql(); |
|
use Apache::lonmeta; |
|
use Apache::lonhtmlcommon; |
use Apache::lonlocal; |
use Apache::lonlocal; |
|
use LONCAPA::lonmetadata(); |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 83 my %groupsearch_db; # Database hash use
|
Line 86 my %groupsearch_db; # Database hash use
|
# groupsearch RAT interface. |
# groupsearch RAT interface. |
my %persistent_db; # gdbm hash which holds data which is supposed to |
my %persistent_db; # gdbm hash which holds data which is supposed to |
# persist across calls to lonsearchcat.pm |
# 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); |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 359 my $totalfound;
|
Line 360 my $totalfound;
|
|
|
sub course_search { |
sub course_search { |
my $r=shift; |
my $r=shift; |
my $bodytag=&Apache::loncommon::bodytag('Course Search'); |
my $bodytag=&Apache::loncommon::bodytag('Course Search'). |
|
&Apache::loncommon::help_open_bug('Searching'); |
my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>'; |
my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>'; |
my $search_string = $ENV{'form.courseexp'}; |
my $search_string = $ENV{'form.courseexp'}; |
my @New_Words; |
my @New_Words; |
if ($ENV{'form.crsrelated'}) { |
if ($ENV{'form.crsrelated'}) { |
($search_string,@New_Words) = &related_version($ENV{'form.courseexp'}); |
($search_string,@New_Words) = &related_version($ENV{'form.courseexp'}); |
if (@New_Words) { |
if (@New_Words) { |
$pretty_search_string .= " with related words: <b>@New_Words</b>."; |
$pretty_search_string .= ' '.&mt("with related words").": <b>@New_Words</b>."; |
} else { |
} else { |
$pretty_search_string .= " with no related words."; |
$pretty_search_string .= ' '.&mt('with no related words')."."; |
} |
} |
} |
} |
my $fulltext=$ENV{'form.crsfulltext'}; |
my $fulltext=$ENV{'form.crsfulltext'}; |
my @allwords=($search_string,@New_Words); |
my @allwords=($search_string,@New_Words); |
$totalfound=0; |
$totalfound=0; |
$r->print('<html><head><title>LON-CAPA Course Search</title></head>'. |
$r->print('<html><head><title>LON-CAPA Course Search</title></head>'. |
$bodytag.$pretty_search_string); |
$bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr />'); |
$r->rflush(); |
$r->rflush(); |
# ======================================================= Go through the course |
# ======================================================= Go through the course |
undef %alreadyseen; |
undef %alreadyseen; |
Line 452 sub untiehash {
|
Line 454 sub untiehash {
|
|
|
} # End of course search scoping |
} # End of course search scoping |
|
|
|
sub search_html_header { |
|
my $Str = <<ENDHEADER; |
|
<html> |
|
<head> |
|
<title>The LearningOnline Network with CAPA</title> |
|
<script type="text/javascript"> |
|
function openhelp(val) { |
|
openhelpwin=open('/adm/help/searchcat.html','helpscreen', |
|
'scrollbars=1,width=600,height=300'); |
|
openhelpwin.focus(); |
|
} |
|
</script> |
|
</head> |
|
ENDHEADER |
|
return $Str; |
|
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
Line 459 sub untiehash {
|
Line 478 sub untiehash {
|
|
|
=item &print_basic_search_form() |
=item &print_basic_search_form() |
|
|
Returns a scalar which holds html for the basic search form. |
Prints the form for the basic search. Sorry the name is so cryptic. |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
sub print_basic_search_form { |
sub print_basic_search_form{ |
|
my ($r,$closebutton,$hidden_fields) = @_; |
my ($r,$closebutton,$hidden_fields) = @_; |
my $bodytag=&Apache::loncommon::bodytag('Search'); |
my $bodytag=&Apache::loncommon::bodytag('Search'). |
my $scrout=<<"ENDDOCUMENT"; |
&Apache::loncommon::help_open_topic('Finding_Resources'). |
<html> |
&Apache::loncommon::help_open_bug('Searching'); |
<head> |
my $scrout = &search_html_header().$bodytag; |
<title>The LearningOnline Network with CAPA</title> |
if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { |
<script type="text/javascript"> |
my $CatalogSearch=&mt('Catalog Search'); |
function openhelp(val) { |
my $Statement=&searchhelp(); |
openhelpwin=open('/adm/help/searchcat.html','helpscreen', |
$scrout.=(<<ENDDOCUMENT); |
'scrollbars=1,width=600,height=300'); |
|
openhelpwin.focus(); |
|
} |
|
</script> |
|
</head> |
|
$bodytag |
|
ENDDOCUMENT |
|
if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) { |
|
my $CatalogSearch=&mt('Catalog Search'); |
|
my $Statement=&mt('Enter terms or phrases separated by AND, OR, or NOT then press SEARCH below'); |
|
$scrout.=(<<ENDDOCUMENT); |
|
<h1>$CatalogSearch</h1> |
<h1>$CatalogSearch</h1> |
<form name="loncapa_search" method="post" action="/adm/searchcat"> |
<form name="loncapa_search" method="post" action="/adm/searchcat"> |
<input type="hidden" name="phase" value="basic_search" /> |
<input type="hidden" name="phase" value="basic_search" /> |
Line 498 $Statement.
|
Line 505 $Statement.
|
<table> |
<table> |
<tr><td> |
<tr><td> |
ENDDOCUMENT |
ENDDOCUMENT |
$scrout.=' '.&simpletextfield('basicexp',$ENV{'form.basicexp'},40). |
$scrout.=' '. |
' '; |
&Apache::lonhtmlcommon::textbox('basicexp', |
my $relatedcheckbox = &simplecheckbox('related','related',$ENV{'form.related'}); |
$ENV{'form.basicexp'},40). |
my $domain = $r->dir_config('lonDefDomain'); |
' '; |
my $domaincheckbox = &simplecheckbox('domains',$domain); |
my $relatedcheckbox = |
my $srch=&mt('Search'); |
&Apache::lonhtmlcommon::checkbox('related', |
my $header=&mt('Advanced Search'); |
$ENV{'form.related'}); |
my $userelatedwords=&mt('use related words'); |
my $domain = $r->dir_config('lonDefDomain'); |
my $onlysearchdomain=&mt('only search domain'); |
my $domaincheckbox = |
$scrout.=<<END; |
&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.=<<END; |
</td><td><a |
</td><td><a |
href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}&mode=$ENV{'form.mode'}" |
href="/adm/searchcat?phase=disp_adv&catalogmode=$ENV{'form.catalogmode'}&launch=$ENV{'form.launch'}&mode=$ENV{'form.mode'}" |
>$header</a></td></tr> |
>$header</a></td></tr> |
Line 515 href="/adm/searchcat?phase=disp_adv&cata
|
Line 529 href="/adm/searchcat?phase=disp_adv&cata
|
<td>$domaincheckbox $onlysearchdomain <b>$domain</b></td></tr> |
<td>$domaincheckbox $onlysearchdomain <b>$domain</b></td></tr> |
</table> |
</table> |
</p> |
</p> |
|
$view |
<p> |
<p> |
<input type="submit" name="basicsubmit" value='$srch' /> |
<input type="submit" name="basicsubmit" value='$srch' /> |
$closebutton |
$closebutton |
END |
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.=<<ENDDOCUMENT; |
$scrout.=<<ENDDOCUMENT; |
</p> |
</p> |
</form> |
</form> |
Line 537 ENDDOCUMENT
|
Line 544 ENDDOCUMENT
|
'srch' => 'Search', |
'srch' => 'Search', |
'header' => 'Course Search', |
'header' => 'Course Search', |
'note' => 'Enter terms or phrases, then press "Search" below', |
'note' => 'Enter terms or phrases, then press "Search" below', |
|
'use' => 'use related words', |
|
'full' =>'fulltext search (time consuming)' |
); |
); |
$scrout.=(<<ENDCOURSESEARCH); |
$scrout.=(<<ENDCOURSESEARCH); |
<hr /> |
<hr /> |
Line 552 $lt{'note'}.
|
Line 561 $lt{'note'}.
|
<tr><td> |
<tr><td> |
ENDCOURSESEARCH |
ENDCOURSESEARCH |
$scrout.=' '. |
$scrout.=' '. |
&simpletextfield('courseexp',$ENV{'form.courseexp'},40); |
&Apache::lonhtmlcommon::textbox('courseexp', |
|
$ENV{'form.courseexp'},40); |
my $crscheckbox = |
my $crscheckbox = |
&simplecheckbox('crsfulltext',$ENV{'form.crsfulltext'}); |
&Apache::lonhtmlcommon::checkbox('crsfulltext', |
|
$ENV{'form.crsfulltext'}); |
my $relcheckbox = |
my $relcheckbox = |
&simplecheckbox('crsrelated',$ENV{'form.crsrelated'}); |
&Apache::lonhtmlcommon::checkbox('crsrelated', |
|
$ENV{'form.crsrelated'}); |
$scrout.=(<<ENDENDCOURSE); |
$scrout.=(<<ENDENDCOURSE); |
</td></tr> |
</td></tr> |
<tr><td>$relcheckbox use related words</td><td></td></tr> |
<tr><td>$relcheckbox $lt{'use'}</td><td></td></tr> |
<tr><td>$crscheckbox fulltext search (time consuming)</td><td></td></tr> |
<tr><td>$crscheckbox $lt{'full'}</td><td></td></tr> |
</table><p> |
</table><p> |
<input type="submit" name="coursesubmit" value='$lt{'srch'}' /> |
<input type="submit" name="coursesubmit" value='$lt{'srch'}' /> |
</p> |
</p> |
Line 580 ENDDOCUMENT
|
Line 592 ENDDOCUMENT
|
|
|
=item &advanced_search_form() |
=item &advanced_search_form() |
|
|
Returns a scalar which holds html for the advanced search form. |
Prints the advanced search form. |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
sub print_advanced_search_form{ |
sub print_advanced_search_form{ |
my ($r,$closebutton,$hidden_fields) = @_; |
my ($r,$closebutton,$hidden_fields) = @_; |
|
my %lt=&Apache::lonlocal::texthash('srch' => 'Search', |
|
'reset' => 'Reset', |
|
'help' => 'Help'); |
my $advanced_buttons = <<"END"; |
my $advanced_buttons = <<"END"; |
<p> |
<p> |
<input type="submit" name="advancedsubmit" value='SEARCH' /> |
<input type="submit" name="advancedsubmit" value='$lt{"srch"}' /> |
<input type="reset" name="reset" value='RESET' /> |
<input type="reset" name="reset" value='$lt{"reset"}' /> |
$closebutton |
$closebutton |
<input type="button" value="HELP" onClick="openhelp()" /> |
<input type="button" value="$lt{'help'}" onClick="openhelp()" /> |
</p> |
</p> |
END |
END |
if (!defined($ENV{'form.viewselect'})) { |
|
$ENV{'form.viewselect'} ="Detailed Citation View"; |
|
} |
|
my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'); |
my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search'); |
my $scrout=<<"ENDHEADER"; |
my $searchhelp=&searchhelp(); |
<html> |
my $scrout=&search_html_header(); |
<head> |
$scrout .= <<"ENDHEADER"; |
<title>The LearningOnline Network with CAPA</title> |
|
<script type="text/javascript"> |
|
function openhelp(val) { |
|
openhelpwin=open('/adm/help/searchcat.html','helpscreen', |
|
'scrollbars=1,width=600,height=300'); |
|
openhelpwin.focus(); |
|
} |
|
</script> |
|
</head> |
|
$bodytag |
$bodytag |
Enter terms or phrases separated by search operators |
$searchhelp |
such as AND, OR, or NOT.<br /> |
<form method="post" action="/adm/searchcat" name="advsearch"> |
<form method="post" action="/adm/searchcat"> |
|
$advanced_buttons |
$advanced_buttons |
$hidden_fields |
$hidden_fields |
<input type="hidden" name="phase" value="adv_search" /> |
<input type="hidden" name="phase" value="adv_search" /> |
<table> |
|
<tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td> |
|
<td> |
|
ENDHEADER |
ENDHEADER |
$scrout.=&selectbox(undef,'viewselect', |
$scrout.=&viewoptions(); |
$ENV{'form.viewselect'}, |
my %fields=&Apache::lonmeta::fieldnames(); |
undef,undef,undef, |
|
sort(keys(%Views))); |
$scrout.='<table>'; |
$scrout.=' '; |
$scrout.="<tr><th>".&mt('Field').'</th><th>'.&mt('Value').'</th><th>' |
$scrout.=&selectbox(undef,'show', |
.&mt('Related').'<br />'.&mt('Words')."</td></tr>\n"; |
$ENV{'form.show'}, |
foreach ('title','author','owner','authorspace','modifyinguser', |
undef,undef,undef, |
'keywords','notes','abstract','standards', |
(10,20,50,100)); |
'lowestgradelevel','highestgradelevel','mime') { |
$scrout.=' '. |
$scrout.='<tr><td>'.&titlefield($fields{$_}).'</td><td>'. |
'<font color="#800000" face="helvetica">'.&mt('Per Page').'</font>'; |
&Apache::lonmeta::prettyinput($_,$ENV{'form.'.$_},$_,'advsearch', |
$scrout.="</td><td>".&mt('Related').'<br />'.&mt('Words')."</td></tr>\n"; |
1,'</td><td>',$ENV{'form.'.$_.'_related'}). |
$scrout.=&searchphrasefield_with_related('title', 'title' , |
'</td></tr>'; |
$ENV{'form.title'}); |
} |
$scrout.=&searchphrasefield('author', 'author' ,$ENV{'form.author'}); |
$scrout.='<tr><td>'. |
$scrout.=&searchphrasefield_with_related('subject', 'subject' , |
&titlefield(&mt('MIME Type Category')).'</td><td>'. |
$ENV{'form.subject'}); |
&Apache::loncommon::filecategoryselect('category', |
$scrout.=&searchphrasefield_with_related('keywords','keywords', |
$ENV{'form.category'}). |
$ENV{'form.keywords'}); |
'</td><td> </td></td></tr>'; |
$scrout.=&searchphrasefield('URL', 'url' ,$ENV{'form.url'}); |
$scrout.='<tr><td>'. |
$scrout.=&searchphrasefield_with_related('notes', 'notes' , |
&titlefield(&mt('Limit Search to Domains')).'</td><td>'. |
$ENV{'form.notes'}); |
&Apache::loncommon::domain_select('domains', |
$scrout.=&searchphrasefield_with_related('abstract','abstract', |
$ENV{'form.domains'},1). |
$ENV{'form.abstract'}); |
'</td><td> </td></td></tr>'; |
$scrout.=&searchphrasefield('Standards','standards',$ENV{'form.standards'}); |
my %dates=&Apache::lonlocal::texthash |
# Hack - an empty table row. |
('creationdatestart' => 'Creation Date After', |
$scrout.="<tr><td> </td><td> </td><td> </td></tr>\n"; |
'creationdateend' => 'Creation Date Before', |
$scrout.=&searchphrasefield('file<br />extension','extension', |
'lastrevisiondatestart' => 'Last Revision Date After', |
$ENV{'form.extension'}); |
'lastrevisiondateend' => 'Last Revision Date Before'); |
$scrout.="<tr><td> </td><td> </td><td> </td></tr>\n"; |
foreach (sort keys %dates) { |
$scrout.=&searchphrasefield('publisher<br />owner','owner', |
$scrout.='<tr>'. |
$ENV{'form.owner'}); |
'<td>'.&titlefield($dates{$_}).'</td><td>'. |
$scrout.="</table>\n"; |
&Apache::lonhtmlcommon::date_setter('advsearch',$_,0,'',1). |
$ENV{'form.category'}='any' if (! defined($ENV{'form.category'})); |
'</td><td> </td></td>'. |
$scrout.=&selectbox('File Category','category', |
'</tr>'; |
$ENV{'form.category'}, |
|
'any','Any category', |
|
undef, |
|
(&Apache::loncommon::filecategories())); |
|
$ENV{'form.language'}='any' unless length($ENV{'form.language'}); |
|
#---------------------------------------------------------------- |
|
# 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 = (); |
|
foreach (@allowed_domains) { |
|
$domain_hash{$_}++; |
|
} |
} |
my @domains =&Apache::loncommon::get_domains(); |
|
# adjust the size of the select box |
$scrout.="</table>\n"; |
my $size = 4; |
|
$size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size); |
|
$scrout.="\n".'<font color="#800000" face="helvetica"><b>'. |
|
'DOMAINS TO BE SEARCHED</b></font><br />'. |
|
'<select name="domains" size="'.$size.'" multiple>'."\n". |
|
'<option name="any" value="any" '. |
|
($domain_hash{'any'}? 'selected ' :''). |
|
'>all domains</option>'."\n"; |
|
foreach my $dom (sort @domains) { |
|
$scrout.="<option name=\"$dom\" ". |
|
($domain_hash{$dom} ? 'selected ' :'').">$dom</option>\n"; |
|
} |
|
$scrout.="</select>\n"; |
|
#---------------------------------------------------------------- |
|
$scrout.=&selectbox('Limit by language','language', |
|
$ENV{'form.language'},'any','Any Language', |
|
\&Apache::loncommon::languagedescription, |
|
(&Apache::loncommon::languageids), |
|
); |
|
# ------------------------------------------------ Compute date selection boxes |
|
$scrout.=<<CREATIONDATESTART; |
|
<p> |
|
<font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b> |
|
</font> |
|
<br /> |
|
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.="</p>"; |
|
$scrout.=<<LASTREVISIONDATESTART; |
|
<p> |
|
<font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE: |
|
</b></font> |
|
<br />between: |
|
LASTREVISIONDATESTART |
|
$scrout.=&dateboxes('lastrevisiondatestart',1,1,1976, |
|
$ENV{'form.lastrevisiondatestart_month'}, |
|
$ENV{'form.lastrevisiondatestart_day'}, |
|
$ENV{'form.lastrevisiondatestart_year'}, |
|
); |
|
$scrout.=<<LASTREVISIONDATEEND; |
|
and: |
|
LASTREVISIONDATEEND |
|
$scrout.=&dateboxes('lastrevisiondateend',12,31,2051, |
|
$ENV{'form.lastrevisiondateend_month'}, |
|
$ENV{'form.lastrevisiondateend_day'}, |
|
$ENV{'form.lastrevisiondateend_year'}, |
|
); |
|
$scrout.='</p>'; |
|
$ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'}); |
|
$scrout.=&selectbox('Limit by copyright/distribution','copyright', |
|
$ENV{'form.copyright'}, |
|
'any','Any copyright/distribution', |
|
\&Apache::loncommon::copyrightdescription, |
|
(&Apache::loncommon::copyrightids), |
|
); |
|
# ------------------------------------------- Compute customized metadata field |
|
# $scrout.=<<CUSTOMMETADATA; |
|
#<p> |
|
#<font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b> |
|
#</font> |
|
#For resource-specific metadata, enter in an expression in the form of |
|
#<i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br /> |
|
#<b>Example:</b> grandmother=75 OR grandfather=85 |
|
#<br /> |
|
#CUSTOMMETADATA |
|
# $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'}); |
|
# $scrout.=<<CUSTOMSHOW; |
|
#<p> |
|
#<font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b> |
|
#</font> |
|
#Enter in a space-separated list of special metadata fields to show |
|
#in a fielded listing for each record result. |
|
#<br /> |
|
#CUSTOMSHOW |
|
# $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'}); |
|
$scrout.=<<ENDDOCUMENT; |
$scrout.=<<ENDDOCUMENT; |
$advanced_buttons |
$advanced_buttons |
</form> |
</form> |
Line 778 ENDDOCUMENT
|
Line 675 ENDDOCUMENT
|
|
|
=pod |
=pod |
|
|
=item &get_persistent_form_data |
=item &titlefield() |
|
|
|
Inputs: title text |
|
|
|
Outputs: titletext with font wrapper |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub titlefield { |
|
my $title=shift; |
|
return '<font face="arial" color="#800000">'.$title.'</font>'; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=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".'<table>'. |
|
'<tr><th>'.&mt('View Options').'</th><th>'. |
|
&mt('Records per Page').'</th></tr><tr><td>'; |
|
unless ($ENV{'form.viewselect'}) { $ENV{'form.viewselect'}='detailed'; } |
|
$scrout.=&Apache::lonmeta::selectbox('viewselect', |
|
$ENV{'form.viewselect'}, |
|
\&viewoptiontext, |
|
sort(keys(%Views))); |
|
$scrout.='</td><td>'; |
|
$scrout.=&Apache::lonmeta::selectbox('show', |
|
$ENV{'form.show'}, |
|
undef, |
|
(10,20,50,100,1000,10000)); |
|
$scrout.="</td></tr></table>\n\n"; |
|
return $scrout; |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item searchhelp() |
|
|
|
Inputs: none |
|
|
|
Outputs: return little blurb on how to enter searches |
|
|
|
=cut |
|
|
|
###################################################################### |
|
###################################################################### |
|
sub searchhelp { |
|
return &mt('Enter terms or phrases separated by AND, OR, or NOT'); |
|
} |
|
|
|
###################################################################### |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=item &get_persistent_form_data() |
|
|
Inputs: filename of database |
Inputs: filename of database |
|
|
Line 833 sub get_persistent_form_data {
|
Line 828 sub get_persistent_form_data {
|
|
|
=pod |
=pod |
|
|
=item &get_persistent_data |
=item &get_persistent_data() |
|
|
Inputs: filename of database, ref to array of values to recover. |
Inputs: filename of database, ref to array of values to recover. |
|
|
Line 884 Inputs: Hash of values to save, filename
|
Line 879 Inputs: Hash of values to save, filename
|
|
|
Store variables away to the %persistent_db. |
Store variables away to the %persistent_db. |
Values will be escaped. Values that are array pointers will have their |
Values will be escaped. Values that are array pointers will have their |
elements escaped and concatenated in a comma seperated string. |
elements escaped and concatenated in a comma separated string. |
|
|
=cut |
=cut |
|
|
Line 916 Inputs: filename of persistent database.
|
Line 911 Inputs: filename of persistent database.
|
|
|
Store most form variables away to the %persistent_db. |
Store most form variables away to the %persistent_db. |
Values will be escaped. Values that are array pointers will have their |
Values will be escaped. Values that are array pointers will have their |
elements escaped and concatenated in a comma seperated string. |
elements escaped and concatenated in a comma separated string. |
|
|
=cut |
=cut |
|
|
Line 934 sub make_form_data_persistent {
|
Line 929 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 '<input type="text" name="'.$name. |
|
'" size="'.$size.'" value="'.$value.'" />'; |
|
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=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 '<input type="checkbox" name="'.$name.'" value="'.$value.'" '. |
|
$checked.' />'; |
|
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=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 '<font color="#800000" face="helvetica"><b>'.$title. |
|
': </b></font>'; |
|
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=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 '<tr><td>'.&fieldtitle($title).'</td><td>'. |
|
&simpletextfield($name,$value,50)."</td><td> </td></tr>\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 '<tr><td>'.&fieldtitle($title).'</td><td>'. |
|
&simpletextfield($name,$value,50).'</td><td align="center"> '. |
|
&simplecheckbox($name.'_related',$ENV{'form.'.$name.'_related'}). |
|
" </td></tr>\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; |
|
<select name="${name}_day"> |
|
<option value='$defaultday'> </option> |
|
END |
|
for (my $i = 1; $i<=31; $i++) { |
|
$day.="<option value=\"$i\">$i</option>\n"; |
|
} |
|
$day.="</select>\n"; |
|
$day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday); |
|
# |
|
# Month |
|
my $month=<<END; |
|
<select name="${name}_month"> |
|
<option value='$defaultmonth'> </option> |
|
END |
|
my $i = 1; |
|
foreach (qw/January February March April May June |
|
July August September October November December /){ |
|
$month .="<option value=\"$i\">".&mt($_)."</option>\n"; |
|
$i++; |
|
} |
|
$month.="</select>\n"; |
|
$month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth); |
|
# |
|
# Year (obviously) |
|
my $year=<<END; |
|
<select name="${name}_year"> |
|
<option value='$defaultyear'> </option> |
|
END |
|
my $maxyear = 2051; |
|
for (my $i = 1976; $i<=$maxyear; $i++) { |
|
$year.="<option value=\"$i\">$i</option>\n"; |
|
} |
|
$year.="</select>\n"; |
|
$year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear); |
|
return "$month$day$year"; |
|
} |
|
|
|
############################################### |
|
############################################### |
|
|
|
=pod |
|
|
|
=item &selectbox() |
|
|
|
Returns a scalar containing an html <select> form. |
|
|
|
Inputs: |
|
|
|
=over 4 |
|
|
|
=item $title |
|
|
|
Printed above the select box, in uppercase. If undefined, only a select |
|
box will be returned, with no additional html. |
|
|
|
=item $name |
|
|
|
The name element of the <select> tag. |
|
|
|
=item $default |
|
|
|
The default value of the form. Can be $anyvalue, or in @idlist. |
|
|
|
=item $anyvalue |
|
|
|
The <option value="..."> used to indicate a default of |
|
none of the values. Can be undef. |
|
|
|
=item $anytag |
|
|
|
The text associate with $anyvalue above. |
|
|
|
=item $functionref |
|
|
|
Each element in @idlist will be passed as a parameter |
|
to the function referenced here. The return value of the function should |
|
be a scalar description of the items. If this value is undefined the |
|
description of each item in @idlist will be the item name. |
|
|
|
=item @idlist |
|
|
|
The items to be selected from. One of these or $anyvalue will be the |
|
value returned by the form element, $ENV{form.$name}. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
############################################### |
|
|
|
sub selectbox { |
|
my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_; |
|
if (! defined($functionref)) { $functionref = sub { $_[0]}; } |
|
my $selout=''; |
|
$title=&mt($title); |
|
if (defined($title)) { |
|
my $uctitle=uc($title); |
|
$selout="\n".'<p><font color="#800000" face="helvetica">'. |
|
'<b>'.$uctitle.': </b></font>'; |
|
} |
|
$selout .= '<select name="'.$name.'">'; |
|
unshift @idlist,$anyvalue if (defined($anyvalue)); |
|
foreach (@idlist) { |
|
$selout.='<option value="'.$_.'"'; |
|
if ($_ eq $default and !/^any$/) { |
|
$selout.=' selected >'.&mt(&{$functionref}($_)).'</option>'; |
|
} |
|
elsif ($_ eq $default and /^$anyvalue$/) { |
|
$selout.=' selected >'.&mt($anytag).'</option>'; |
|
} |
|
else {$selout.='>'.&mt(&{$functionref}($_)).'</option>';} |
|
} |
|
return $selout.'</select>'.(defined($title)?'</p>':' '); |
|
} |
|
|
|
###################################################################### |
|
# End of HTML form building functions # |
|
###################################################################### |
|
|
|
=pod |
|
|
|
=back |
|
|
|
=cut |
|
|
|
|
|
###################################################################### |
|
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
Line 1275 sub parse_advanced_search {
|
Line 988 sub parse_advanced_search {
|
} |
} |
} |
} |
unless ($fillflag) { |
unless ($fillflag) { |
&output_blank_field_error($r,$closebutton,'phase=disp_adv',$hidden_fields); |
&output_blank_field_error($r,$closebutton, |
|
'phase=disp_adv',$hidden_fields); |
return ; |
return ; |
} |
} |
# Turn the form input into a SQL-based query |
# Turn the form input into a SQL-based query |
Line 1284 sub parse_advanced_search {
|
Line 998 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 ('title','author','subject','notes','abstract','url', |
foreach my $field ('title','author','subject','notes','abstract','url', |
'keywords','version','owner') { |
'keywords','version','owner','standards') { |
if ($ENV{'form.'.$field}) { |
if ($ENV{'form.'.$field}) { |
my $searchphrase = $ENV{'form.'.$field}; |
my $searchphrase = $ENV{'form.'.$field}; |
$pretty_search_string .= $font."$field</font> contains <b>". |
$pretty_search_string .= $font."$field</font> contains <b>". |
Line 1326 sub parse_advanced_search {
|
Line 1040 sub parse_advanced_search {
|
$pretty_search_string .=$font.'mime</font> contains <b>'. |
$pretty_search_string .=$font.'mime</font> contains <b>'. |
$searchphrase.'</b><br />'; |
$searchphrase.'</b><br />'; |
} |
} |
##### |
# |
# Evaluate option lists |
# Evaluate option lists |
if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') { |
if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') { |
push @queries,"(language like \"$ENV{'form.language'}\")"; |
push @queries,"(language like \"$ENV{'form.language'}\")"; |
Line 1365 sub parse_advanced_search {
|
Line 1079 sub parse_advanced_search {
|
# date query information. |
# date query information. |
push @queries,$datequery; |
push @queries,$datequery; |
} |
} |
|
# |
# Process form information for custom metadata querying |
# Process form information for custom metadata querying |
my $customquery=undef; |
my $customquery=undef; |
# if ($ENV{'form.custommetadata'}) { |
## |
# $pretty_search_string .=$font."Custom Metadata Search</font>: <b>". |
## The custom metadata search was removed q long time ago mostly |
# $ENV{'form.custommetadata'}."</b><br />\n"; |
## because I was unable to figureout exactly how it worked and could |
# $customquery=&build_custommetadata_query('custommetadata', |
## not imagine people actually using it. MH |
# $ENV{'form.custommetadata'}); |
## |
# } |
# if ($ENV{'form.custommetadata'}) { |
|
# $pretty_search_string .=$font."Custom Metadata Search</font>: <b>". |
|
# $ENV{'form.custommetadata'}."</b><br />\n"; |
|
# $customquery=&build_custommetadata_query('custommetadata', |
|
# $ENV{'form.custommetadata'}); |
|
# } |
my $customshow=undef; |
my $customshow=undef; |
# if ($ENV{'form.customshow'}) { |
# if ($ENV{'form.customshow'}) { |
# $pretty_search_string .=$font."Custom Metadata Display</font>: <b>". |
# $pretty_search_string .=$font."Custom Metadata Display</font>: <b>". |
# $ENV{'form.customshow'}."</b><br />\n"; |
# $ENV{'form.customshow'}."</b><br />\n"; |
# $customshow=$ENV{'form.customshow'}; |
# $customshow=$ENV{'form.customshow'}; |
# $customshow=~s/[^\w\s]//g; |
# $customshow=~s/[^\w\s]//g; |
# my @fields=split(/\s+/,$customshow); |
# my @fields=split(/\s+/,$customshow); |
# $customshow=join(" ",@fields); |
# $customshow=join(" ",@fields); |
# } |
# } |
## --------------------------------------------------------------- |
## |
## Deal with restrictions to given domains |
## Deal with restrictions to given domains |
## |
## |
my ($libraries_to_query,$pretty_domains_string) = |
my ($libraries_to_query,$pretty_domains_string) = |
Line 1412 sub parse_domain_restrictions {
|
Line 1132 sub parse_domain_restrictions {
|
} else { |
} else { |
@allowed_domains = ($ENV{'form.domains'}); |
@allowed_domains = ($ENV{'form.domains'}); |
} |
} |
|
# |
my %domain_hash = (); |
my %domain_hash = (); |
my $pretty_domains_string; |
my $pretty_domains_string; |
foreach (@allowed_domains) { |
foreach (@allowed_domains) { |
Line 1452 Parse the basic search form and return a
|
Line 1173 Parse the basic search form and return a
|
###################################################################### |
###################################################################### |
sub parse_basic_search { |
sub parse_basic_search { |
my ($r,$closebutton)=@_; |
my ($r,$closebutton)=@_; |
|
# |
# 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; |
Line 1464 sub parse_basic_search {
|
Line 1186 sub parse_basic_search {
|
} |
} |
my ($libraries_to_query,$pretty_domains_string) = |
my ($libraries_to_query,$pretty_domains_string) = |
&parse_domain_restrictions(); |
&parse_domain_restrictions(); |
# Check to see if enough is filled in |
# |
|
# Check to see if enough of a query is filled in |
unless (&filled($ENV{'form.basicexp'})) { |
unless (&filled($ENV{'form.basicexp'})) { |
&output_blank_field_error($r,$closebutton,'phase=disp_basic'); |
&output_blank_field_error($r,$closebutton,'phase=disp_basic'); |
return OK; |
return OK; |
Line 1480 sub parse_basic_search {
|
Line 1203 sub parse_basic_search {
|
$pretty_search_string .= " with no related words."; |
$pretty_search_string .= " with no related words."; |
} |
} |
} |
} |
|
# |
# Build SQL query string based on form page |
# Build SQL query string based on form page |
my $query=''; |
my $query=''; |
my $concatarg=join(',', |
my $concatarg=join(',', |
Line 1492 sub parse_basic_search {
|
Line 1216 sub parse_basic_search {
|
} |
} |
$pretty_search_string .= "<br />\n"; |
$pretty_search_string .= "<br />\n"; |
my $final_query = 'SELECT * FROM metadata WHERE '.$query; |
my $final_query = 'SELECT * FROM metadata WHERE '.$query; |
# &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); |
} |
} |
|
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
|
|
=item &related_version |
=item &related_version() |
|
|
Modifies an input string to include related words. Words in the string |
Modifies an input string to include related words. Words in the string |
are replaced with parenthesized lists of 'OR'd words. For example |
are replaced with parenthesized lists of 'OR'd words. For example |
Line 1700 sub build_date_queries {
|
Line 1423 sub build_date_queries {
|
|
|
=item ©right_check() |
=item ©right_check() |
|
|
|
Inputs: $Metadata, a hash pointer of metadata for a resource. |
|
|
|
Returns: 1 if the resource is available to the user making the query, |
|
0 otherwise. |
|
|
=cut |
=cut |
|
|
###################################################################### |
###################################################################### |
Line 1723 sub copyright_check {
|
Line 1451 sub copyright_check {
|
return 1; |
return 1; |
} |
} |
|
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
|
|
=item &ensure_db_and_table |
=item &ensure_db_and_table() |
|
|
Ensure we can get lonmysql to connect to the database and the table we |
Ensure we can get lonmysql to connect to the database and the table we |
need exists. |
need exists. |
Line 1785 sub ensure_db_and_table {
|
Line 1512 sub ensure_db_and_table {
|
|
|
=pod |
=pod |
|
|
=item &print_sort_form |
=item &print_sort_form() |
|
|
|
The sort feature is not implemented at this time. This form just prints |
|
a link to change the search query. |
|
|
=cut |
=cut |
|
|
Line 1886 the following format:
|
Line 1616 the following format:
|
|
|
##################################################################### |
##################################################################### |
##################################################################### |
##################################################################### |
|
# |
my @Datatypes = |
# These should probably be scoped but I don't have time right now... |
( { name => 'id', |
# |
type => 'MEDIUMINT', |
my @Datatypes; |
restrictions => 'UNSIGNED NOT NULL', |
my @Fullindicies; |
primary_key => 'yes', |
|
auto_inc => 'yes' }, |
|
{ name => 'title', type=>'TEXT'}, |
|
{ name => 'author', type=>'TEXT'}, |
|
{ name => 'subject', type=>'TEXT'}, |
|
{ name => 'url', type=>'TEXT', restrictions => 'NOT NULL' }, |
|
{ name => 'keywords', type=>'TEXT'}, |
|
{ name => 'version', type=>'TEXT'}, |
|
{ name => 'notes', type=>'TEXT'}, |
|
{ name => 'abstract', type=>'TEXT'}, |
|
{ name => 'mime', type=>'TEXT'}, |
|
{ name => 'language', type=>'TEXT'}, |
|
{ name => 'owner', type=>'TEXT'}, |
|
{ name => 'copyright', type=>'TEXT'}, |
|
{ name => 'dependencies', type=>'TEXT'}, |
|
{ name => 'modifyinguser', type=>'TEXT'}, |
|
{ name => 'authorspace', type=>'TEXT'}, |
|
{ name => 'lowestgradelevel', type=>'INT'}, |
|
{ name => 'highestgradelevel', type=>'INT'}, |
|
{ name => 'standards', type=>'TEXT'}, |
|
{ name => 'count', type=>'INT'}, |
|
{ name => 'course', type=>'INT'}, |
|
{ name => 'course_list', type=>'TEXT'}, |
|
{ name => 'goto', type=>'INT'}, |
|
{ name => 'goto_list', type=>'TEXT'}, |
|
{ name => 'comefrom', type=>'INT'}, |
|
{ name => 'comefrom_list', type=>'TEXT'}, |
|
{ name => 'sequsage', type=>'INT'}, |
|
{ name => 'sequsage_list', type=>'TEXT'}, |
|
{ name => 'stdno', type=>'INT'}, |
|
{ name => 'stdno_list', type=>'TEXT'}, |
|
{ name => 'avetries', type=>'FLOAT'}, |
|
{ name => 'avetries_list', type=>'TEXT'}, |
|
{ name => 'difficulty', type=>'FLOAT'}, |
|
{ name => 'difficulty_list', type=>'TEXT'}, |
|
{ name => 'clear', type=>'FLOAT'}, |
|
{ name => 'technical', type=>'FLOAT'}, |
|
{ name => 'correct', type=>'FLOAT'}, |
|
{ name => 'helpful', type=>'FLOAT'}, |
|
{ name => 'depth', type=>'FLOAT'}, |
|
{ name => 'hostname', type=> 'TEXT'}, |
|
#-------------------------------------------------- |
|
{ name => 'creationdate', type=>'DATETIME'}, |
|
{ name => 'lastrevisiondate', type=>'DATETIME'}, |
|
#-------------------------------------------------- |
|
); |
|
|
|
my @Fullindicies = |
|
qw/title/; |
|
# qw/title author subject abstract mime language owner copyright/; |
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
Line 1960 Returns: the identifier of the table on
|
Line 1640 Returns: the identifier of the table on
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
sub set_up_table_structure { |
|
my ($datatypes,$fullindicies) = |
|
&LONCAPA::lonmetadata::describe_metadata_storage(); |
|
unshift(@$datatypes,{name => 'id', |
|
type => 'MEDIUMINT', |
|
restrictions => 'UNSIGNED NOT NULL', |
|
primary_key => 'yes', |
|
auto_inc => 'yes' }); |
|
@Datatypes = @{$datatypes}; |
|
@Fullindicies = @{$fullindicies}; |
|
return; |
|
} |
|
|
sub create_results_table { |
sub create_results_table { |
|
&set_up_table_structure(); |
my $table = &Apache::lonmysql::create_table |
my $table = &Apache::lonmysql::create_table |
( { columns => \@Datatypes, |
( { columns => \@Datatypes, |
FULLTEXT => [{'columns' => \@Fullindicies},], |
FULLTEXT => [{'columns' => \@Fullindicies},], |
Line 2030 sub update_seconds {
|
Line 1724 sub update_seconds {
|
|
|
=pod |
=pod |
|
|
=item &revise_button |
=item &revise_button() |
|
|
Inputs: None |
Inputs: None |
|
|
Line 2057 sub revise_button {
|
Line 1751 sub revise_button {
|
|
|
=pod |
=pod |
|
|
=item &run_search |
=item &run_search() |
|
|
|
Executes a search query by sending it the the other servers and putting the |
|
results into MySQL. |
|
|
=cut |
=cut |
|
|
Line 2093 END
|
Line 1790 END
|
$r->rflush(); |
$r->rflush(); |
# |
# |
# Determine the servers we need to contact. |
# Determine the servers we need to contact. |
# |
|
my @Servers_to_contact; |
my @Servers_to_contact; |
if (defined($serverlist)) { |
if (defined($serverlist)) { |
if (ref($serverlist) eq 'ARRAY') { |
if (ref($serverlist) eq 'ARRAY') { |
Line 2121 END
|
Line 1817 END
|
return; |
return; |
} |
} |
if (! $table_status) { |
if (! $table_status) { |
|
&Apache::lonnet::logthis("lonmysql error = ". |
|
&Apache::lonmysql::get_error()); |
|
&Apache::lonnet::logthis("lonmysql debug = ". |
|
&Apache::lonmysql::get_debug()); |
|
&Apache::lonnet::logthis('table status = "'.$table_status.'"'); |
$r->print("The table id,$table, we tried to use is invalid.". |
$r->print("The table id,$table, we tried to use is invalid.". |
"The search has been aborted.</body></html>"); |
"The search has been aborted.</body></html>"); |
return; |
return; |
} |
} |
## |
## |
## Prepare for the big loop. |
## Prepare for the big loop. |
## |
|
my $hitcountsum; |
my $hitcountsum; |
my $server; |
my $server; |
my $status; |
my $status; |
Line 2172 END
|
Line 1872 END
|
sleep(1); |
sleep(1); |
} |
} |
# |
# |
# |
|
# 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)) { |
while (my ($server,$status) = each(%Server_status)) { |
Line 2246 END
|
Line 1945 END
|
} |
} |
&update_status($r,&mt('Search Complete').$server); |
&update_status($r,&mt('Search Complete').$server); |
&update_seconds($r,0); |
&update_seconds($r,0); |
|
# |
&Apache::lonmysql::disconnect_from_db(); |
&Apache::lonmysql::disconnect_from_db(); |
|
# |
# We have run out of time or run out of servers to talk to and |
# We have run out of time or run out of servers to talk to and |
# results to get. |
# results to get. |
$r->print("</body></html>"); |
$r->print("</body></html>"); |
Line 2262 END
|
Line 1963 END
|
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
|
|
=item &prev_next_buttons |
=item &prev_next_buttons() |
|
|
|
Returns html for the previous and next buttons on the search results page. |
|
|
=cut |
=cut |
|
|
Line 2279 sub prev_next_buttons {
|
Line 1983 sub prev_next_buttons {
|
my $prev_min = $current_min - $show; |
my $prev_min = $current_min - $show; |
$prev_min = 1 if $prev_min < 1; |
$prev_min = 1 if $prev_min < 1; |
if ($prev_min < $current_min) { |
if ($prev_min < $current_min) { |
$links .= qq{ |
$links .= |
<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">prev</a> |
qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">}. |
}; |
&mt('prev').'</a>'; |
} else { |
} else { |
$links .= 'prev'; |
$links .= &mt('prev'); |
} |
} |
## |
## |
## Pages.... Someday. |
## Pages.... Someday. |
## |
## |
$links .= qq{ |
$links .= |
<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">reload</a> |
qq{ |
}; |
<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">}. |
|
&mt('reload').'</a>'; |
## |
## |
## Next |
## Next |
my $next_min = $current_min + $show; |
my $next_min = $current_min + $show; |
$next_min = $current_min if ($next_min > $total); |
$next_min = $current_min if ($next_min > $total); |
if ($next_min != $current_min) { |
if ($next_min != $current_min) { |
$links .= qq{ |
$links .= |
<a href="/adm/searchcat?$parms&start=$next_min&show=$show">next</a> |
qq{ |
}; |
<a href="/adm/searchcat?$parms&start=$next_min&show=$show">}. |
|
&mt('next').'</a>'; |
} else { |
} else { |
$links .= ' next'; |
$links .= ' '.&mt('next'); |
} |
} |
return $links; |
return $links; |
} |
} |
|
|
###################################################################### |
###################################################################### |
###################################################################### |
###################################################################### |
|
|
=pod |
=pod |
|
|
=item &display_results |
=item &display_results() |
|
|
|
Prints the results out for selection and perusal. |
|
|
=cut |
=cut |
|
|
Line 2337 sub display_results {
|
Line 2046 sub display_results {
|
## |
## |
my $action = "/adm/searchcat?phase=results"; |
my $action = "/adm/searchcat?phase=results"; |
## |
## |
## Deal with groupsearch |
## Deal with groupsearch by opening the groupsearch db file. |
## |
|
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
if ($ENV{'form.catalogmode'} eq 'groupsearch') { |
if (! tie(%groupsearch_db,'GDBM_File',$diropendb, |
if (! tie(%groupsearch_db,'GDBM_File',$diropendb, |
&GDBM_WRCREAT(),0640)) { |
&GDBM_WRCREAT(),0640)) { |
Line 2349 sub display_results {
|
Line 2057 sub display_results {
|
} |
} |
## |
## |
## Prepare the table for querying |
## Prepare the table for querying |
## |
|
my $table = $ENV{'form.table'}; |
my $table = $ENV{'form.table'}; |
return if (! &ensure_db_and_table($r,$table)); |
return if (! &ensure_db_and_table($r,$table)); |
## |
## |
## Get the number of results |
## Get the number of results |
## |
|
my $total_results = &Apache::lonmysql::number_of_rows($table); |
my $total_results = &Apache::lonmysql::number_of_rows($table); |
if (! defined($total_results)) { |
if (! defined($total_results)) { |
$r->print("A MySQL error has occurred.</form></body></html>"); |
$r->print("A MySQL error has occurred.</form></body></html>"); |
Line 2365 sub display_results {
|
Line 2071 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'} = 'all' if (! exists($ENV{'form.show'})); |
my $min = $ENV{'form.start'}; |
my $min = $ENV{'form.start'}; |
Line 2378 sub display_results {
|
Line 2083 sub display_results {
|
} |
} |
## |
## |
## Output links (if necessary) for 'prev' and 'next' pages. |
## Output links (if necessary) for 'prev' and 'next' pages. |
## |
|
$r->print |
$r->print |
('<center>'. |
('<center>'. |
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
&prev_next_buttons($min,$ENV{'form.show'},$total_results, |
Line 2398 sub display_results {
|
Line 2102 sub display_results {
|
} |
} |
## |
## |
## Get results from MySQL table |
## Get results from MySQL table |
## |
|
my @Results = &Apache::lonmysql::get_rows($table, |
my @Results = &Apache::lonmysql::get_rows($table, |
'id>='.$min.' AND id<='.$max); |
'id>='.$min.' AND id<='.$max); |
## |
## |
## Loop through the results and output them. |
## Loop through the results and output them. |
## |
|
foreach my $row (@Results) { |
foreach my $row (@Results) { |
if ($connection->aborted()) { |
if ($connection->aborted()) { |
&cleanup(); |
&cleanup(); |
Line 2481 END
|
Line 2183 END
|
|
|
=pod |
=pod |
|
|
=item &parse_row |
=item &parse_row() |
|
|
Parse a row returned from the database. |
Parse a row returned from the database. |
|
|
Line 2492 Parse a row returned from the database.
|
Line 2194 Parse a row returned from the database.
|
sub parse_row { |
sub parse_row { |
my @Row = @_; |
my @Row = @_; |
my %Fields; |
my %Fields; |
|
if (! scalar(@Datatypes)) { |
|
&set_up_table_structure(); |
|
} |
for (my $i=0;$i<=$#Row;$i++) { |
for (my $i=0;$i<=$#Row;$i++) { |
$Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]); |
$Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]); |
} |
} |
Line 2527 The 'title' field is set to "Untitled" i
|
Line 2232 The 'title' field is set to "Untitled" i
|
########################################################### |
########################################################### |
sub parse_raw_result { |
sub parse_raw_result { |
my ($result,$hostname) = @_; |
my ($result,$hostname) = @_; |
# Check for a comma - if it is there then we do not need to unescape the |
# conclude from self to others regarding fields |
# string. There seems to be some kind of problem with some items in |
my %Fields=&LONCAPA::lonmetadata::metadata_col_to_hash |
# the database - the entire string gets sent out unescaped...? |
(map { |
unless ($result =~ /,/) { |
&Apache::lonnet::unescape($_); |
$result = &Apache::lonnet::unescape($result); |
} (split(/\,/,$result)) ); |
} |
|
my @fields=map { |
|
&Apache::lonnet::unescape($_); |
|
} (split(/\,/,$result)); |
|
# conclude from self to others regarding fields |
|
my @columns=&Apache::lonmysql::col_order('metadata'); |
|
my %Fields=(); |
|
for (my $i=0; $i<=$#columns; $i++) { |
|
$Fields{$columns[$i]}=$fields[$i]; |
|
} |
|
# prettier display |
|
$Fields{'language'} = |
|
&Apache::loncommon::languagedescription($Fields{'language'}); |
|
$Fields{'copyrighttag'} = |
|
&Apache::loncommon::copyrightdescription($Fields{'copyright'}); |
|
$Fields{'mimetag'} = |
|
&Apache::loncommon::filedescription($Fields{'mime'}); |
|
if ($Fields{'author'}=~/^(\s*|error)$/) { |
|
$Fields{'author'}="Unknown Author"; |
|
} |
|
# Put spaces in the keyword list, if needed. |
|
$Fields{'keywords'}=~ s/,([A-z])/, $1/g; |
|
if ($Fields{'title'}=~ /^\s*$/ ) { |
|
$Fields{'title'}='Untitled'; |
|
} |
|
unless ($ENV{'user.adv'}) { |
|
# do not show descriptive information to non-advanced users |
|
$Fields{'keywords'} = '- not displayed -'; |
|
$Fields{'notes'} = '- not displayed -'; |
|
$Fields{'abstract'} = '- not displayed -'; |
|
$Fields{'subject'} = '- not displayed -'; |
|
} |
|
if (length($Fields{'abstract'})>200) { |
|
$Fields{'abstract'} = |
|
substr($Fields{'abstract'},0,200).'...'; |
|
} |
|
if (length($Fields{'keywords'})>200) { |
|
$Fields{'keywords'} = |
|
substr($Fields{'keywords'},0,200).'...'; |
|
} |
|
return %Fields; |
return %Fields; |
} |
} |
|
|
Line 2621 sub handle_custom_fields {
|
Line 2286 sub handle_custom_fields {
|
|
|
=pod |
=pod |
|
|
=item &search_results_header |
=item &search_results_header() |
|
|
Output the proper html headers and javascript code to deal with different |
Output the proper html headers and javascript code to deal with different |
calling modes. |
calling modes. |
Line 2823 ENDFRAMES
|
Line 2488 ENDFRAMES
|
=item Metadata Viewing Functions |
=item Metadata Viewing Functions |
|
|
Output is a HTML-ified string. |
Output is a HTML-ified string. |
|
|
Input arguments are title, author, subject, url, keywords, version, |
Input arguments are title, author, subject, url, keywords, version, |
notes, short abstract, mime, language, creation date, |
notes, short abstract, mime, language, creation date, |
last revision date, owner, copyright, hostname, and |
last revision date, owner, copyright, hostname, and |
Line 3013 END
|
Line 2679 END
|
sub filled { |
sub filled { |
my ($field)=@_; |
my ($field)=@_; |
if ($field=~/\S/ && $field ne 'any') { |
if ($field=~/\S/ && $field ne 'any') { |
return 1; |
return 1; |
} |
} else { |
else { |
return 0; |
return 0; |
|
} |
} |
} |
} |
|
|