Annotation of loncom/interface/lonsearchcat.pm, revision 1.218

1.98      harris41    1: # The LearningOnline Network with CAPA
1.108     harris41    2: # Search Catalog
                      3: #
1.218   ! matthew     4: # $Id: lonsearchcat.pm,v 1.217 2004/04/27 15:24:09 matthew Exp $
1.108     harris41    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
1.98      harris41   14: #
1.108     harris41   15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
1.1       www        27: #
1.121     matthew    28: ###############################################################################
                     29: ###############################################################################
                     30: 
                     31: =pod 
                     32: 
                     33: =head1 NAME
                     34: 
1.140     matthew    35: lonsearchcat - LONCAPA Search Interface
1.121     matthew    36: 
                     37: =head1 SYNOPSIS
                     38: 
                     39: Search interface to LON-CAPAs digital library
                     40: 
                     41: =head1 DESCRIPTION
                     42: 
                     43: This module enables searching for a distributed browseable catalog.
1.104     harris41   44: 
1.121     matthew    45: This is part of the LearningOnline Network with CAPA project
                     46: described at http://www.lon-capa.org.
                     47: 
                     48: lonsearchcat presents the user with an interface to search the LON-CAPA
                     49: digital library.  lonsearchcat also initiates the execution of a search
                     50: by sending the search parameters to LON-CAPA servers.  The progress of 
1.205     www        51: search (on a server basis) is displayed to the user in a separate window.
1.121     matthew    52: 
                     53: =head1 Internals
                     54: 
                     55: =over 4
                     56: 
                     57: =cut
                     58: 
                     59: ###############################################################################
1.98      harris41   60: ###############################################################################
1.121     matthew    61: 
1.1       www        62: package Apache::lonsearchcat;
                     63: 
                     64: use strict;
1.167     www        65: use Apache::Constants qw(:common :http);
1.6       harris41   66: use Apache::lonnet();
                     67: use Apache::File();
1.7       harris41   68: use CGI qw(:standard);
1.41      harris41   69: use Text::Query;
1.101     harris41   70: use GDBM_File;
1.112     harris41   71: use Apache::loncommon();
1.144     matthew    72: use Apache::lonmysql();
1.200     www        73: use Apache::lonmeta;
                     74: use Apache::lonhtmlcommon;
1.186     www        75: use Apache::lonlocal;
1.204     matthew    76: use LONCAPA::lonmetadata();
1.212     matthew    77: use HTML::Entities();
1.1       www        78: 
1.121     matthew    79: ######################################################################
                     80: ######################################################################
1.196     matthew    81: ##
                     82: ## Global variables
                     83: ##
1.121     matthew    84: ######################################################################
                     85: ######################################################################
1.196     matthew    86: my %groupsearch_db;  # Database hash used to save values for the 
                     87:                      # groupsearch RAT interface.
                     88: my %persistent_db;   # gdbm hash which holds data which is supposed to
                     89:                      # persist across calls to lonsearchcat.pm
1.121     matthew    90: 
1.200     www        91: # The different view modes and associated functions
                     92: 
                     93: my %Views = ("detailed" => \&detailed_citation_view,
                     94: 	     "summary"  => \&summary_view,
                     95: 	     "fielded"  => \&fielded_format_view,
                     96: 	     "xml"      => \&xml_sgml_view,
                     97: 	     "compact"  => \&compact_view);
1.101     harris41   98: 
1.121     matthew    99: ######################################################################
                    100: ######################################################################
1.98      harris41  101: sub handler {
                    102:     my $r = shift;
1.197     www       103: #    &set_defaults();
1.196     matthew   104:     #
                    105:     # set form defaults
1.145     matthew   106:     #
1.196     matthew   107:     my $hidden_fields;# Hold all the hidden fields used to keep track
                    108:                       # of the search system state
                    109:     my $importbutton; # button to take the selected results and go to group 
                    110:                       # sorting
                    111:     my $diropendb;    # The full path to the (temporary) search database file.
                    112:                       # This is set and used in &handler() and is also used in 
                    113:                       # &output_results().
                    114:     my $bodytag;  # LON-CAPA standard body tag, gotten from 
                    115:                   # &Apache::lonnet::bodytag. 
                    116:                   # No title, no table, just a <body> tag.
1.157     www       117: 
                    118:     my $loaderror=&Apache::lonnet::overloaderror($r);
                    119:     if ($loaderror) { return $loaderror; }
                    120: 
1.145     matthew   121:     my $closebutton;  # button that closes the search window 
                    122:                       # This button is different for the RAT compared to
                    123:                       # normal invocation.
                    124:     #
1.186     www       125:     &Apache::loncommon::content_type($r,'text/html');
1.98      harris41  126:     $r->send_http_header;
                    127:     return OK if $r->header_only;
1.156     matthew   128:     ##
                    129:     ## Prevent caching of the search interface window.  Hopefully this means
                    130:     ## we will get the launch=1 passed in a little more.
                    131:     &Apache::loncommon::no_cache($r);
1.145     matthew   132:     ## 
                    133:     ## Pick up form fields passed in the links.
                    134:     ##
                    135:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.146     matthew   136:              ['catalogmode','launch','acts','mode','form','element','pause',
1.158     matthew   137:               'phase','persistent_db_id','table','start','show',
1.191     albertel  138:               'cleargroupsort','titleelement']);
1.146     matthew   139:     ##
                    140:     ## The following is a trick - we wait a few seconds if asked to so
                    141:     ##     the daemon running the search can get ahead of the daemon
                    142:     ##     printing the results.  We only need (theoretically) to do
                    143:     ##     this once, so the pause indicator is deleted
                    144:     ##
                    145:     if (exists($ENV{'form.pause'})) {
1.181     matthew   146:         sleep(1);
1.146     matthew   147:         delete($ENV{'form.pause'});
                    148:     }
1.143     matthew   149:     ##
                    150:     ## Initialize global variables
                    151:     ##
1.121     matthew   152:     my $domain  = $r->dir_config('lonDefDomain');
1.213     matthew   153:     $diropendb= "/home/httpd/perl/tmp/".
                    154:         "$ENV{'user.domain'}_$ENV{'user.name'}_searchcat.db";
1.145     matthew   155:     #
                    156:     # set the name of the persistent database
1.146     matthew   157:     #          $ENV{'form.persistent_db_id'} can only have digits in it.
1.145     matthew   158:     if (! exists($ENV{'form.persistent_db_id'}) ||
1.147     matthew   159:         ($ENV{'form.persistent_db_id'} =~ /\D/) ||
                    160:         ($ENV{'form.launch'} eq '1')) {
1.145     matthew   161:         $ENV{'form.persistent_db_id'} = time;
                    162:     }
1.155     matthew   163:     $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.146     matthew   164:     my $persistent_db_file = "/home/httpd/perl/tmp/".
1.145     matthew   165:         &Apache::lonnet::escape($domain).
                    166:             '_'.&Apache::lonnet::escape($ENV{'user.name'}).
                    167:                 '_'.$ENV{'form.persistent_db_id'}.'_persistent_search.db';
1.146     matthew   168:     ##
1.209     matthew   169:     &Apache::lonhtmlcommon::clear_breadcrumbs();
                    170:     if (exists($ENV{'request.course.id'}) && $ENV{'request.course.id'} ne '') {
                    171:         &Apache::lonhtmlcommon::add_breadcrumb
                    172:              ({href=>'/adm/searchcat?'.
                    173:                    'catalogmode='.$ENV{'form.catalogmode'}.
                    174:                    '&launch='.$ENV{'form.launch'}.
                    175:                    '&mode='.$ENV{'form.mode'},
                    176:               text=>"Course and Catalog Search",
                    177:               bug=>'Searching',});
                    178:     } else {
                    179:         &Apache::lonhtmlcommon::add_breadcrumb
                    180:              ({href=>'/adm/searchcat?'.
                    181:                    'catalogmode='.$ENV{'form.catalogmode'}.
                    182:                    '&launch='.$ENV{'form.launch'}.
                    183:                    '&mode='.$ENV{'form.mode'},
                    184:               text=>"Catalog Search",
                    185:               bug=>'Searching',});
                    186:     }
                    187:     #
1.152     matthew   188:     if (! &get_persistent_form_data($persistent_db_file)) {
1.150     matthew   189:         if ($ENV{'form.phase'} =~ /(run_search|results)/) {
                    190:             &Apache::lonnet::logthis("lonsearchcat:Unable to recover data ".
                    191:                                      "from $persistent_db_file");
                    192:             $r->print(<<END);
                    193: <html>
                    194: <head><title>LON-CAPA Search Error</title></head>
1.155     matthew   195: $bodytag
1.150     matthew   196: We were unable to retrieve data describing your search.  This is a serious
                    197: error and has been logged.  Please alert your LON-CAPA administrator.
                    198: </body>
                    199: </html>
                    200: END
                    201:             return OK;
                    202:         }
1.147     matthew   203:     }
1.124     matthew   204:     ##
1.143     matthew   205:     ## Clear out old values from groupsearch database
1.124     matthew   206:     ##
1.146     matthew   207:     untie %groupsearch_db if (tied(%groupsearch_db));
1.158     matthew   208:     if (($ENV{'form.cleargroupsort'} eq '1') || 
                    209:         (($ENV{'form.launch'} eq '1') && 
                    210:          ($ENV{'form.catalogmode'} eq 'groupsearch'))) {
1.148     matthew   211: 	if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT(),0640)) {
1.101     harris41  212: 	    &start_fresh_session();
1.142     matthew   213: 	    untie %groupsearch_db;
1.158     matthew   214:             delete($ENV{'form.cleargroupsort'});
1.122     matthew   215: 	} else {
1.155     matthew   216:             # This is a stupid error to give to the user.  
                    217:             # It really tells them nothing.
                    218: 	    $r->print('<html><head></head>'.$bodytag.
                    219:                       'Unable to tie hash to db file</body></html>');
1.101     harris41  220: 	    return OK;
                    221: 	}
                    222:     }
1.124     matthew   223:     ##
1.150     matthew   224:     ## Configure hidden fields
1.124     matthew   225:     ##
1.145     matthew   226:     $hidden_fields = '<input type="hidden" name="persistent_db_id" value="'.
1.150     matthew   227:         $ENV{'form.persistent_db_id'}.'" />'."\n";
                    228:     if (exists($ENV{'form.catalogmode'})) {
                    229:         $hidden_fields .= '<input type="hidden" name="catalogmode" value="'.
                    230:                 $ENV{'form.catalogmode'}.'" />'."\n";
                    231:     }
                    232:     if (exists($ENV{'form.form'})) {
                    233:         $hidden_fields .= '<input type="hidden" name="form" value="'.
                    234:                 $ENV{'form.form'}.'" />'."\n";
                    235:     }
                    236:     if (exists($ENV{'form.element'})) {
                    237:         $hidden_fields .= '<input type="hidden" name="element" value="'.
                    238:                 $ENV{'form.element'}.'" />'."\n";
                    239:     }
1.191     albertel  240:     if (exists($ENV{'form.titleelement'})) {
                    241:         $hidden_fields .= '<input type="hidden" name="titleelement" value="'.
                    242:                 $ENV{'form.titleelement'}.'" />'."\n";
                    243:     }
1.150     matthew   244:     if (exists($ENV{'form.mode'})) {
                    245:         $hidden_fields .= '<input type="hidden" name="mode" value="'.
                    246:                 $ENV{'form.mode'}.'" />'."\n";
                    247:     }
                    248:     ##
                    249:     ## Configure dynamic components of interface
1.146     matthew   250:     ##
1.98      harris41  251:     if ($ENV{'form.catalogmode'} eq 'interactive') {
1.150     matthew   252:         $closebutton="<input type='button' name='close' value='CLOSE' ";
                    253:         if ($ENV{'form.phase'} =~ /(results|run_search)/) {
                    254: 	    $closebutton .="onClick='parent.close()'";
                    255:         } else {
                    256:             $closebutton .="onClick='self.close()'";
                    257:         }
                    258:         $closebutton .=">\n";
1.124     matthew   259:     } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.150     matthew   260:         $closebutton="<input type='button' name='close' value='CLOSE' ";
                    261:         if ($ENV{'form.phase'} =~ /(results|run_search)/) {
                    262: 	    $closebutton .="onClick='parent.close()'";
                    263:         } else {
                    264:             $closebutton .="onClick='self.close()'";
                    265:         }
                    266:         $closebutton .= ">";
1.98      harris41  267:         $importbutton=<<END;
                    268: <input type='button' name='import' value='IMPORT'
                    269: onClick='javascript:select_group()'>
                    270: END
1.146     matthew   271:     } else {
                    272:         $closebutton = '';
                    273:         $importbutton = '';
1.98      harris41  274:     }
1.124     matthew   275:     ##
1.146     matthew   276:     ## Sanity checks on form elements
1.124     matthew   277:     ##
1.146     matthew   278:     if (!defined($ENV{'form.viewselect'})) {
1.150     matthew   279:         if (($ENV{'form.catalogmode'} eq 'groupsearch') ||
                    280:             ($ENV{'form.catalogmode'} eq 'interactive')) {
                    281:             $ENV{'form.viewselect'} ="Compact View";
                    282:         } else {
                    283:             $ENV{'form.viewselect'} ="Detailed Citation View";
                    284:         }
1.146     matthew   285:     }
1.149     matthew   286:     $ENV{'form.phase'} = 'disp_basic' if (! exists($ENV{'form.phase'}));
1.151     matthew   287:     $ENV{'form.show'} = 20 if (! exists($ENV{'form.show'}));
1.209     matthew   288:     #
                    289:     $ENV{'form.searchmode'} = 'basic';
                    290:     if ($ENV{'form.phase'} eq 'adv_search' ||
                    291:         $ENV{'form.phase'} eq 'disp_adv') {
                    292:         $ENV{'form.searchmode'} = 'advanced';
                    293:     } elsif ($ENV{'form.phase'} eq 'course_search') {
                    294:         $ENV{'form.searchmode'} = 'course_search';
                    295:     }
                    296:     #
                    297:     if ($ENV{'form.searchmode'} eq 'advanced') {
                    298:         &Apache::lonhtmlcommon::add_breadcrumb
                    299:             ({href=>'/adm/searchcat?phase=disp_adv&'.
                    300:                   'catalogmode='.$ENV{'form.catalogmode'}.
                    301:                   '&launch='.$ENV{'form.launch'}.
                    302:                   '&mode='.$ENV{'form.mode'},
                    303:                   text=>"Advanced Search",
                    304:                   bug=>'Searching',});
                    305:     } elsif ($ENV{'form.searchmode'} eq 'course search') {
                    306:         &Apache::lonhtmlcommon::add_breadcrumb
                    307:             ({href=>'/adm/searchcat?phase=disp_adv&'.
                    308:                   'catalogmode='.$ENV{'form.catalogmode'}.
                    309:                   '&launch='.$ENV{'form.launch'}.
                    310:                   '&mode='.$ENV{'form.mode'},
                    311:                   text=>"Course Search",
                    312:                   bug=>'Searching',});
                    313:     }
1.146     matthew   314:     ##
                    315:     ## Switch on the phase
                    316:     ##
                    317:     if ($ENV{'form.phase'} eq 'disp_basic') {
1.196     matthew   318:         &print_basic_search_form($r,$closebutton,$hidden_fields);
1.146     matthew   319:     } elsif ($ENV{'form.phase'} eq 'disp_adv') {
1.196     matthew   320:         &print_advanced_search_form($r,$closebutton,$hidden_fields);
1.146     matthew   321:     } elsif ($ENV{'form.phase'} eq 'results') {
1.196     matthew   322:         &display_results($r,$importbutton,$closebutton,$diropendb);
1.151     matthew   323:     } elsif ($ENV{'form.phase'} =~ /^(sort|run_search)$/) {
1.146     matthew   324:         my ($query,$customquery,$customshow,$libraries,$pretty_string) =
                    325:             &get_persistent_data($persistent_db_file,
                    326:                  ['query','customquery','customshow',
                    327:                   'libraries','pretty_string']);
1.151     matthew   328:         if ($ENV{'form.phase'} eq 'sort') {
                    329:             &print_sort_form($r,$pretty_string);
                    330:         } elsif ($ENV{'form.phase'} eq 'run_search') {
                    331:             &run_search($r,$query,$customquery,$customshow,
                    332:                         $libraries,$pretty_string);
                    333:         }
1.167     www       334:     } elsif ($ENV{'form.phase'} eq 'course_search') {
                    335:         &course_search($r);
1.146     matthew   336:     } elsif(($ENV{'form.phase'} eq 'basic_search') ||
                    337:             ($ENV{'form.phase'} eq 'adv_search')) {
                    338:         # Set up table
                    339:         if (! defined(&create_results_table())) {
1.198     www       340: 	    my $errorstring=&Apache::lonmysql::get_error();
1.211     matthew   341:             &Apache::lonnet::logthis('lonsearchcat.pm: Unable to create '.
                    342:                                      'needed table.  lonmysql error:'.
                    343:                                      $errorstring);
1.147     matthew   344:             $r->print(<<END);
                    345: <html><head><title>Search Error</title></head>
1.155     matthew   346: $bodytag
1.147     matthew   347: Unable to create table in which to store search results.  
                    348: The search has been aborted.
                    349: </body>
                    350: </html>
                    351: END
                    352:             return OK;
1.146     matthew   353:         }
1.147     matthew   354:         delete($ENV{'form.launch'});
1.146     matthew   355:         if (! &make_form_data_persistent($r,$persistent_db_file)) {
1.147     matthew   356:             $r->print(<<END);
                    357: <html><head><title>Search Error</title></head>
1.155     matthew   358: $bodytag
1.147     matthew   359: Unable to properly store search information.  The search has been aborted.
                    360: </body>
                    361: </html>
                    362: END
                    363:             return OK;
1.146     matthew   364:         }
1.145     matthew   365:         #
1.139     matthew   366:         # We are running a search
1.134     matthew   367:         my ($query,$customquery,$customshow,$libraries) = 
                    368:             (undef,undef,undef,undef);
1.143     matthew   369:         my $pretty_string;
1.146     matthew   370:         if ($ENV{'form.phase'} eq 'basic_search') {
1.180     matthew   371:             ($query,$pretty_string,$libraries) = 
1.196     matthew   372:                 &parse_basic_search($r,$closebutton,$hidden_fields);
1.146     matthew   373:         } else {                      # Advanced search
1.143     matthew   374:             ($query,$customquery,$customshow,$libraries,$pretty_string) 
1.196     matthew   375:                 = &parse_advanced_search($r,$closebutton,$hidden_fields);
1.134     matthew   376:             return OK if (! defined($query));
                    377:         }
1.152     matthew   378:         &make_persistent({ query => $query,
1.146     matthew   379:                            customquery => $customquery,
                    380:                            customshow => $customshow,
                    381:                            libraries => $libraries,
                    382:                            pretty_string => $pretty_string },
                    383:                          $persistent_db_file);
1.145     matthew   384:         ##
1.146     matthew   385:         ## Print out the frames interface
1.145     matthew   386:         ##
1.146     matthew   387:         &print_frames_interface($r);
1.124     matthew   388:     }
                    389:     return OK;
                    390: } 
1.98      harris41  391: 
1.124     matthew   392: ######################################################################
                    393: ######################################################################
1.196     matthew   394: ##
                    395: ##   Course Search
                    396: ##
                    397: ######################################################################
                    398: ######################################################################
                    399: {   # Scope the course search to avoid global variables
                    400: #
                    401: # Variables For course search
                    402: my %alreadyseen;
                    403: my %hash;
                    404: my $totalfound;
1.124     matthew   405: 
1.167     www       406: sub course_search {
                    407:     my $r=shift;
1.217     matthew   408:     my $bodytag=&Apache::loncommon::bodytag('Course Search');
1.167     www       409:     my $pretty_search_string = '<b>'.$ENV{'form.courseexp'}.'</b>';
                    410:     my $search_string = $ENV{'form.courseexp'};
                    411:     my @New_Words;
                    412:     if ($ENV{'form.crsrelated'}) {
                    413:         ($search_string,@New_Words) = &related_version($ENV{'form.courseexp'});
                    414:         if (@New_Words) {
1.200     www       415:             $pretty_search_string .= ' '.&mt("with related words").": <b>@New_Words</b>.";
1.167     www       416:         } else {
1.200     www       417:             $pretty_search_string .= ' '.&mt('with no related words').".";
1.167     www       418:         }
                    419:     }
                    420:     my $fulltext=$ENV{'form.crsfulltext'};
                    421:     my @allwords=($search_string,@New_Words);
1.169     www       422:     $totalfound=0;
1.167     www       423:     $r->print('<html><head><title>LON-CAPA Course Search</title></head>'.
1.203     www       424: 	      $bodytag.'<hr /><center><font size="+2" face="arial">'.$pretty_search_string.'</font></center><hr />');
1.167     www       425:     $r->rflush();
                    426: # ======================================================= Go through the course
1.196     matthew   427:     undef %alreadyseen;
                    428:     %alreadyseen=();
1.169     www       429:     my $c=$r->connection;
1.196     matthew   430:     if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
                    431:             &GDBM_READER(),0640)) {
                    432:         foreach (keys %hash) {
                    433:             if ($c->aborted()) { last; }
                    434:             if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
                    435:                 &checkonthis($r,$hash{$_},0,$hash{'title_'.$1},$fulltext,
                    436:                              @allwords);
                    437:             }
                    438:         }
                    439:         untie(%hash);
                    440:     }
1.169     www       441:     unless ($totalfound) {
1.187     www       442: 	$r->print('<p>'.&mt('No resources found').'.</p>');
1.169     www       443:     }
1.167     www       444: # =================================================== Done going through course
                    445:     $r->print('</body></html>');
                    446: }
                    447: 
                    448: # =============================== This pulls up a resource and its dependencies
                    449: 
                    450: sub checkonthis {
1.168     www       451:     my ($r,$url,$level,$title,$fulltext,@allwords)=@_;
1.167     www       452:     $alreadyseen{$url}=1;
                    453:     $r->rflush();
                    454:     my $result=&Apache::lonnet::metadata($url,'title').' '.
                    455:                &Apache::lonnet::metadata($url,'subject').' '.
                    456:                &Apache::lonnet::metadata($url,'abstract').' '.
                    457:                &Apache::lonnet::metadata($url,'keywords');
                    458:     if (($url) && ($fulltext)) {
1.168     www       459: 	$result.=&Apache::lonnet::ssi_body($url);
1.167     www       460:     }
                    461:     $result=~s/\s+/ /gs;
                    462:     my $applies=0;
                    463:     foreach (@allwords) {
                    464:         if ($_=~/\w/) {
                    465: 	   if ($result=~/$_/si) {
                    466: 	      $applies++;
                    467:            }
                    468:        }
                    469:     }
                    470: # Does this resource apply?
                    471:     if ($applies) {
                    472:        $r->print('<br />');
                    473:        for (my $i=0;$i<=$level*5;$i++) {
                    474:            $r->print('&nbsp;');
                    475:        }
                    476:        $r->print('<a href="'.$url.'" target="cat">'.
1.169     www       477: 		 ($title?$title:$url).'</a><br />');
                    478:        $totalfound++;
                    479:     } elsif ($fulltext) {
                    480:        $r->print(' .');
1.167     www       481:     }
1.169     www       482:     $r->rflush();
1.167     www       483: # Check also the dependencies of this one
                    484:     my $dependencies=
                    485:                 &Apache::lonnet::metadata($url,'dependencies');
                    486:     foreach (split(/\,/,$dependencies)) {
                    487:        if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1.168     www       488:           &checkonthis($r,$_,$level+1,'',$fulltext,@allwords);
1.167     www       489:        }
                    490:     }
                    491: }
                    492: 
1.196     matthew   493: sub untiehash {
                    494:     if (tied(%hash)) {
                    495:         untie(%hash);
                    496:     }
                    497: }
                    498: 
                    499: } # End of course search scoping
                    500: 
1.207     matthew   501: sub search_html_header {
                    502:     my $Str = <<ENDHEADER;
                    503: <html>
                    504: <head>
                    505: <title>The LearningOnline Network with CAPA</title>
                    506: </head>
                    507: ENDHEADER
                    508:     return $Str;
                    509: }
                    510: 
1.167     www       511: ######################################################################
                    512: ######################################################################
                    513: 
1.124     matthew   514: =pod 
                    515: 
1.146     matthew   516: =item &print_basic_search_form() 
1.124     matthew   517: 
1.204     matthew   518: Prints the form for the basic search.  Sorry the name is so cryptic.
1.124     matthew   519: 
                    520: =cut
                    521: 
                    522: ######################################################################
                    523: ######################################################################
1.204     matthew   524: sub print_basic_search_form {
1.196     matthew   525:     my ($r,$closebutton,$hidden_fields) = @_;
1.203     www       526:     my $bodytag=&Apache::loncommon::bodytag('Search').
1.217     matthew   527:         &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching','Searching',
1.209     matthew   528:                                             undef,undef,! $ENV{'form.launch'});
1.207     matthew   529:     my $scrout = &search_html_header().$bodytag;
                    530:     if (&Apache::lonnet::allowed('bre',$ENV{'request.role.domain'})) {
1.213     matthew   531:         # Define interface components
                    532:         my $userelatedwords=
                    533:             &mt('[_1] use related words',
                    534:                 &Apache::lonhtmlcommon::checkbox
                    535:                 ('related',$ENV{'form.related'}));
                    536:         my $onlysearchdomain=
                    537:             &mt('[_1] only search domain [_2]',
                    538:                 &Apache::lonhtmlcommon::checkbox
                    539:                 ('domains',$ENV{'form.domains'}),
                    540:                 $r->dir_config('lonDefDomain'));
                    541:         my $adv_search_link = 
                    542:             '<a href="/adm/searchcat?'.
                    543:             'phase=disp_adv&'.
                    544:             'catalogmode='.$ENV{'form.catalogmode'}.
                    545:             '&launch='.$ENV{'form.launch'}.
                    546:             '&mode='.$ENV{'form.mode'}.
                    547:             '">'.&mt('Advanced Search').'</a>';
                    548:         #
                    549:         $scrout.='<form name="loncapa_search" method="post" '.
                    550:             'action="/adm/searchcat">'.
                    551:             '<input type="hidden" name="phase" value="basic_search" />'.
                    552:             $hidden_fields;
                    553:         #
                    554:         $scrout .= '<center>'.$/;
                    555:         if ($ENV{'request.course.id'}) {
                    556:             $scrout .= '<h1>'.&mt('LON-CAPA Catalog Search').'</h1>';
                    557:         } else {
                    558:             # No need to tell them they are searching
                    559:             $scrout.= ('<br />'x2);
                    560:         }
                    561:         $scrout.='<table>'.
                    562:             '<tr><td align="center" valign="top">'.
1.208     matthew   563:             &Apache::lonhtmlcommon::textbox('basicexp',
1.213     matthew   564:                                             $ENV{'form.basicexp'},50).'<br />'.
                    565:             '<font size="-1">'.&searchhelp().'</font>'.'</td>'.
                    566:             '<td><font size="-1">'.
                    567:             '<nobr>'.('&nbsp;'x3).$adv_search_link.'</nobr>'.'<br />'.
                    568:             '<nobr>'.('&nbsp;'x1).$userelatedwords.'</nobr>'.'<br />'.
                    569:             '<nobr>'.('&nbsp;'x1).$onlysearchdomain.'</nobr>'.'<br />'.
                    570:             '</font></td>'.
                    571:             '</tr>'.$/;
                    572:         #
                    573: #        $scrout .= '<tr><td align="center">'.
                    574: #            '<font size="-1">'.
                    575: #            $userelatedwords.('&nbsp;'x3).
                    576: #            $onlysearchdomain.('&nbsp;'x2).$adv_search_link.
                    577: #            '</font>'.
                    578: #            '</td></tr>'.$/;
                    579:         $scrout .= '<tr><td align="center" colspan="2">'.
                    580:             '<font size="-1">'.
                    581:             '<input type="submit" name="basicsubmit" '.
                    582:             'value="'.&mt('Search').'" />'.
                    583:             ('&nbsp;'x2).$closebutton.('&nbsp;'x2).&viewoptions().
                    584:             '</font>'.
                    585:             '</td></tr>'.$/;
                    586:         $scrout .= '</table>'.$/.'</center>'.'</form>';
1.180     matthew   587:     }
                    588:     if ($ENV{'request.course.id'}) {
1.213     matthew   589: 	my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
1.187     www       590:                                            'header' => 'Course Search',
                    591: 	 'note' => 'Enter terms or phrases, then press "Search" below',
1.200     www       592: 	 'use' => 'use related words',
                    593: 	 'full' =>'fulltext search (time consuming)'
1.187     www       594: 					   );
1.180     matthew   595:         $scrout.=(<<ENDCOURSESEARCH);
1.213     matthew   596: <form name="loncapa_search" method="post" action="/adm/searchcat">
                    597: <center>
1.180     matthew   598: <hr />
1.187     www       599: <h1>$lt{'header'}</h1>    
1.167     www       600: <input type="hidden" name="phase" value="course_search" />
                    601: $hidden_fields
                    602: <p>
1.187     www       603: $lt{'note'}.
1.167     www       604: </p>
                    605: <p>
                    606: <table>
                    607: <tr><td>
                    608: ENDCOURSESEARCH
1.180     matthew   609:         $scrout.='&nbsp;'.
1.200     www       610:             &Apache::lonhtmlcommon::textbox('courseexp',
                    611:                                   $ENV{'form.courseexp'},40);
1.180     matthew   612:         my $crscheckbox = 
1.200     www       613:             &Apache::lonhtmlcommon::checkbox('crsfulltext',
                    614:                                    $ENV{'form.crsfulltext'});
1.180     matthew   615:         my $relcheckbox = 
1.200     www       616:             &Apache::lonhtmlcommon::checkbox('crsrelated',
                    617: 				   $ENV{'form.crsrelated'});
1.180     matthew   618:         $scrout.=(<<ENDENDCOURSE);
1.167     www       619: </td></tr>
1.200     www       620: <tr><td>$relcheckbox $lt{'use'}</td><td></td></tr>
                    621: <tr><td>$crscheckbox $lt{'full'}</td><td></td></tr>
1.167     www       622: </table><p>
1.187     www       623: &nbsp;<input type="submit" name="coursesubmit" value='$lt{'srch'}' />
1.167     www       624: </p>
1.213     matthew   625: </center>
                    626: </form>
1.167     www       627: ENDENDCOURSE
1.180     matthew   628:     }
1.167     www       629:     $scrout.=(<<ENDDOCUMENT);
1.124     matthew   630: </body>
                    631: </html>
                    632: ENDDOCUMENT
1.146     matthew   633:     $r->print($scrout);
                    634:     return;
1.124     matthew   635: }
                    636: ######################################################################
                    637: ######################################################################
                    638: 
                    639: =pod 
                    640: 
                    641: =item &advanced_search_form() 
                    642: 
1.204     matthew   643: Prints the advanced search form.
1.124     matthew   644: 
                    645: =cut
                    646: 
                    647: ######################################################################
                    648: ######################################################################
1.146     matthew   649: sub print_advanced_search_form{
1.196     matthew   650:     my ($r,$closebutton,$hidden_fields) = @_;
1.217     matthew   651:     my $bodytag=&Apache::loncommon::bodytag('Advanced Catalog Search').
                    652:         &Apache::lonhtmlcommon::breadcrumbs(undef,'Searching',
                    653:                                             'Searching',
                    654:                                             undef,undef,
                    655:                                             ! $ENV{'form.launch'});
                    656: 
1.200     www       657:     my %lt=&Apache::lonlocal::texthash('srch' => 'Search',
                    658: 				       'reset' => 'Reset',
                    659: 				       'help' => 'Help');
1.217     matthew   660:     my $advanced_buttons=<<"END";
1.200     www       661: <input type="submit" name="advancedsubmit" value='$lt{"srch"}' />
                    662: <input type="reset" name="reset" value='$lt{"reset"}' />
1.129     matthew   663: $closebutton
                    664: END
1.207     matthew   665:     my $scrout=&search_html_header();
                    666:     $scrout .= <<"ENDHEADER";
1.154     www       667: $bodytag
1.200     www       668: <form method="post" action="/adm/searchcat" name="advsearch">
1.217     matthew   669: <p>
1.129     matthew   670: $advanced_buttons
1.124     matthew   671: ENDHEADER
1.208     matthew   672:     $scrout.=('&nbsp;'x2).&viewoptions().'</p>'.$hidden_fields. 
                    673:         '<input type="hidden" name="phase" value="adv_search" />';
1.200     www       674:     my %fields=&Apache::lonmeta::fieldnames();
1.208     matthew   675:     #
1.217     matthew   676:     $scrout .= '<h3>'.&mt('Standard Metadata').'</h3>';
                    677:     $scrout .= "<table>\n";
                    678:     $scrout .= '<tr><td>&nbsp;</td><td colspan="2"><font size="-1">'.
                    679:         ('&nbsp;'x2).&searchhelp()."</font></td></tr>\n";
1.208     matthew   680:     my %related_word_search = 
1.217     matthew   681:         ('title'    => 1,
                    682:          'author'   => 0,
                    683:          'owner'    => 0,
                    684:          'authorspace'  => 0,
                    685:          'modifyinguser'=> 0,
                    686:          'keywords' => 1,
                    687:          'notes'    => 1,
                    688:          'abstract' => 1,
                    689:          'standards'=> 1,
                    690:          'mime'     => 1,
1.208     matthew   691:          );
1.209     matthew   692:     #
1.208     matthew   693:     foreach my $field ('title','author','owner','authorspace','modifyinguser',
                    694: 	     'keywords','notes','abstract','standards','mime') {
                    695: 	$scrout.='<tr><td align="right">'.&titlefield($fields{$field}).'</td><td>'.
                    696: 	    &Apache::lonmeta::prettyinput($field,
                    697:                                           $ENV{'form.'.$field},
                    698:                                           $field,
                    699:                                           'advsearch',
                    700: 					  $related_word_search{$field},
                    701:                                           '</td><td align="left">',
                    702:                                           $ENV{'form.'.$field.'_related'},
                    703:                                           50);
                    704:         if ($related_word_search{$field}) {
                    705:             $scrout .= 'related words';
                    706:         } else {
                    707:             $scrout .= '</td><td>&nbsp;';
                    708:         }
                    709:         $scrout .= '</td></tr>'.$/;
                    710:     }
                    711:     foreach my $field ('lowestgradelevel','highestgradelevel') {
                    712: 	$scrout.='<tr>'.
                    713:             '<td align="right">'.&titlefield($fields{$field}).'</td>'.
                    714:             '<td colspan="2">'.
                    715: 	    &Apache::lonmeta::prettyinput($field,
                    716:                                           $ENV{'form.'.$field},
                    717:                                           $field,
                    718:                                           'advsearch',
                    719: 					  0).
                    720:                                           '</td></tr>'.$/;
1.200     www       721:     }
1.208     matthew   722:     $scrout.='<tr><td align="right">'.
                    723: 	&titlefield(&mt('MIME Type Category')).'</td><td colspan="2">'. 
1.202     www       724: 	    &Apache::loncommon::filecategoryselect('category',
                    725: 						   $ENV{'form.category'}).
1.208     matthew   726: 	    '</td></tr>'.$/;
                    727:     $scrout.='<tr><td align="right" valign="top">'.
                    728: 	&titlefield(&mt('Domains')).'</td><td colspan="2">'. 
1.202     www       729: 	    &Apache::loncommon::domain_select('domains',
                    730: 						   $ENV{'form.domains'},1).
1.208     matthew   731: 	    '</td></tr>'.$/;
1.217     matthew   732:     #
                    733:     # Misc metadata
                    734:     $scrout.='<tr><td align="right" valign="top">'.
                    735: 	&titlefield(&mt('Copyright/Distribution')).'</td><td colspan="2">'.
                    736:         &Apache::lonmeta::selectbox('copyright',
                    737:                                     '',,
                    738:                                     \&Apache::loncommon::copyrightdescription,
                    739:                                     ( undef,
                    740:                                       &Apache::loncommon::copyrightids)
                    741:                                     ).'</td></tr>'.$/;
                    742:     $scrout.='<tr><td align="right" valign="top">'.
                    743: 	&titlefield(&mt('Language')).'</td><td colspan="2">'.
                    744:         &Apache::lonmeta::selectbox('language',
                    745:                                     'notset',,
                    746:                                     \&Apache::loncommon::languagedescription,
                    747:                                     ('any',&Apache::loncommon::languageids)
                    748:                                     ).'</td></tr>';
                    749:     $scrout .= "</table>\n";    
                    750:     #
                    751:     # Dynamic metadata
                    752:     $scrout .= '<h3>'.&mt('Problem Statistics').'</h3>';
                    753:     $scrout .= "<table>\n";
                    754:     $scrout .= '<tr><td>&nbsp;</td><td align="center">'.&mt('Minimum').'</td>'.
                    755:         '<td align="center">'.&mt('Maximum').'</td></tr>'."\n";
                    756:     foreach my $statistic 
                    757:         ({ name=>'stdno',
                    758:            description=>'Number of Students',},
                    759:          { name => 'avetries',
                    760:            description=>'Average tries to answer correctly',},
                    761:          { name => 'difficulty',
                    762:            description=>'Degree of difficulty',},
                    763:          { name => 'disc',
                    764:            description=>'Degree of discrimination'}) {
                    765:         $scrout .= '<tr><td align="right">'.
                    766:             &titlefield(&mt($statistic->{'description'})).
                    767:             '</td><td align="center">'.
                    768:             '<input type="text" name="'.$statistic->{'name'}.'_min" '.
                    769:             'value="" size="6" />'.
                    770:             '</td><td align="center">'.
                    771:             '<input type="text" name="'.$statistic->{'name'}.'_max" '.
                    772:             'value="" size="6" />'.
                    773:             '</td></tr>'.$/;
                    774:     }
                    775:     $scrout .= "</table>\n";
                    776:     $scrout .= '<h3>'.&mt('Evaluation Data').'</h3>';
                    777:     $scrout .= "<table>\n";
                    778:     $scrout .= '<tr><td>&nbsp;</td><td align="center">'.&mt('Minimum').'</td>'.
                    779:         '<td align="center">'.&mt('Maximum').'</td></tr>'."\n";
                    780:     foreach my $evaluation
                    781:         ( { name => 'clear',
                    782:             description => 'Material presented in clear way'},
                    783:           { name =>'depth',
                    784:             description => 'Material covered with sufficient depth'},
                    785:           { name => 'helpful',
                    786:             description => 'Material is helpful'},
                    787:           { name => 'correct',
                    788:             description => 'Material appears to be correct'},
                    789:           { name => 'technical',
                    790:             description => 'Resource is technically correct'}){
                    791:         $scrout .= '<tr><td align="right">'.
                    792:             &titlefield(&mt($evaluation->{'description'})).
                    793:             '</td><td align="center">'.
                    794:             '<input type="text" name="'.$evaluation->{'name'}.'_min" '.
                    795:             'value="" size="6" />'.
                    796:             '</td><td align="center">'.
                    797:             '<input type="text" name="'.$evaluation->{'name'}.'_max" '.
                    798:             'value="" size="6" />'.
                    799:             '</td></tr>'.$/;
                    800:     }
                    801:     $scrout .= "</table>\n";
1.216     matthew   802:     #
                    803:     # Creation/Modification date limits
1.217     matthew   804:     $scrout .= '<h3>'.&mt('Creation and Modification dates').'</h3>';
1.216     matthew   805:     $scrout .= "\n<table>\n";
                    806:     my $cafter = 
                    807:         &Apache::lonhtmlcommon::date_setter('advsearch',         # formname
                    808:                                             'creationdate1', # fieldname
                    809:                                             0,           # current value
                    810:                                             '',          # special 
                    811:                                             1,           # includeempty
                    812:                                             '',          # state
                    813:                                             1,           # no_hh_mm_ss
                    814:                                             );
                    815:     my $cbefore = 
                    816:         &Apache::lonhtmlcommon::date_setter('advsearch',         # formname
                    817:                                             'creationdate2', # fieldname
                    818:                                             0,           # current value
                    819:                                             '',          # special 
                    820:                                             1,           # includeempty
                    821:                                             '',          # state
                    822:                                             1,           # no_hh_mm_ss
                    823:                                             );
                    824:     $scrout .= &mt('<tr><td align="right">Created between</td>'.
                    825:                    '<td>[_1]</td></tr>'.
                    826:                    '<tr><td align="right">and </td>'.
                    827:                    '<td>[_2]</td></tr>',$cafter,$cbefore);
                    828:     my $lafter = 
                    829:         &Apache::lonhtmlcommon::date_setter('advsearch',
                    830:                                             'revisiondate1', 
                    831:                                             0,           # current value
                    832:                                             '',          # special 
                    833:                                             1,           # includeempty
                    834:                                             '',          # state
                    835:                                             1,           # no_hh_mm_ss
                    836:                                             );
                    837:     my $lbefore = 
                    838:         &Apache::lonhtmlcommon::date_setter('advsearch',
                    839:                                             'revisiondate2',
                    840:                                             0,           # current value
                    841:                                             '',          # special 
                    842:                                             1,           # includeempty
                    843:                                             '',          # state
                    844:                                             1,           # no_hh_mm_ss
                    845:                                             );
                    846:     $scrout .= &mt('<tr><td align="right">Last modified between </td>'.
                    847:                    '<td>[_1]</td></tr>'.
                    848:                    '<tr><td align="right">and</td>'.
                    849:                    '<td>[_2]</td></tr>',$lafter,$lbefore);
1.202     www       850:     $scrout.="</table>\n";
1.124     matthew   851:     $scrout.=<<ENDDOCUMENT;
1.129     matthew   852: $advanced_buttons
1.8       harris41  853: </form>
                    854: </body>
                    855: </html>
                    856: ENDDOCUMENT
1.146     matthew   857:     $r->print($scrout);
                    858:     return;
1.124     matthew   859: }
1.204     matthew   860: 
1.200     www       861: ######################################################################
                    862: ######################################################################
                    863: 
                    864: =pod 
                    865: 
1.204     matthew   866: =item &titlefield()
1.200     www       867: 
                    868: Inputs: title text
                    869: 
                    870: Outputs: titletext with font wrapper
                    871: 
                    872: =cut
                    873: 
                    874: ######################################################################
                    875: ######################################################################
                    876: sub titlefield {
                    877:     my $title=shift;
1.208     matthew   878:     return $title;
1.200     www       879: }
1.204     matthew   880: 
1.200     www       881: ######################################################################
                    882: ######################################################################
                    883: 
                    884: =pod 
                    885: 
1.204     matthew   886: =item viewoptiontext()
1.200     www       887: 
                    888: Inputs: codename for view option
                    889: 
                    890: Outputs: displayed text
                    891: 
                    892: =cut
                    893: 
                    894: ######################################################################
                    895: ######################################################################
                    896: sub viewoptiontext {
                    897:     my $code=shift;
1.204     matthew   898:     my %desc=&Apache::lonlocal::texthash
                    899:         ('detailed' => "Detailed Citation View",
                    900:          'xml' => 'XML/SGML',
                    901:          'compact' => 'Compact View',
                    902:          'fielded' => 'Fielded Format',
                    903:          'summary' => 'Summary View');
1.200     www       904:     return $desc{$code};
                    905: }
1.204     matthew   906: 
                    907: ######################################################################
1.200     www       908: ######################################################################
                    909: 
                    910: =pod 
                    911: 
1.204     matthew   912: =item viewoptions()
1.200     www       913: 
                    914: Inputs: none
                    915: 
                    916: Outputs: text for box with view options
                    917: 
                    918: =cut
                    919: 
                    920: ######################################################################
                    921: ######################################################################
                    922: sub viewoptions {
1.208     matthew   923:     my $scrout="\n".'<nobr>';
                    924:     if (! defined($ENV{'form.viewselect'})) { 
                    925:         $ENV{'form.viewselect'}='detailed'; 
                    926:     }
1.200     www       927:     $scrout.=&Apache::lonmeta::selectbox('viewselect',
                    928: 			$ENV{'form.viewselect'},
                    929: 			\&viewoptiontext,
                    930: 			sort(keys(%Views)));
1.208     matthew   931:     $scrout.= '&nbsp;&nbsp;';
1.214     matthew   932:     my $countselect = &Apache::lonmeta::selectbox('show',
                    933:                                                   $ENV{'form.show'},
                    934:                                                   undef,
                    935:                                                   (10,20,50,100,1000,10000));
                    936:     $scrout .= ('&nbsp;'x2).&mt('[_1] Records per Page',$countselect).
                    937:         '</nobr>'.$/;
1.200     www       938:     return $scrout;
1.201     www       939: }
                    940: 
                    941: ######################################################################
1.204     matthew   942: ######################################################################
1.201     www       943: 
                    944: =pod 
                    945: 
1.204     matthew   946: =item searchhelp()
1.201     www       947: 
                    948: Inputs: none
                    949: 
                    950: Outputs: return little blurb on how to enter searches
                    951: 
                    952: =cut
                    953: 
                    954: ######################################################################
                    955: ######################################################################
                    956: sub searchhelp {
                    957:     return &mt('Enter terms or phrases separated by AND, OR, or NOT');
1.200     www       958: }
1.8       harris41  959: 
1.121     matthew   960: ######################################################################
                    961: ######################################################################
                    962: 
                    963: =pod 
                    964: 
1.204     matthew   965: =item &get_persistent_form_data()
1.145     matthew   966: 
1.146     matthew   967: Inputs: filename of database
                    968: 
                    969: Outputs: returns undef on database errors.
                    970: 
                    971: This function is the reverse of &make_persistent() for form data.
1.145     matthew   972: Retrieve persistent data from %persistent_db.  Retrieved items will have their
1.146     matthew   973: values unescaped.  If a form value already exists in $ENV, it will not be
                    974: overwritten.  Form values that are array references may have values appended
                    975: to them.
1.145     matthew   976: 
                    977: =cut
                    978: 
                    979: ######################################################################
                    980: ######################################################################
1.146     matthew   981: sub get_persistent_form_data {
                    982:     my $filename = shift;
1.147     matthew   983:     return 0 if (! -e $filename);
1.146     matthew   984:     return undef if (! tie(%persistent_db,'GDBM_File',$filename,
1.148     matthew   985:                            &GDBM_READER(),0640));
1.146     matthew   986:     #
                    987:     # These make sure we do not get array references printed out as 'values'.
1.161     matthew   988:     my %arrays_allowed = ('form.domains'=>1);
1.146     matthew   989:     #
                    990:     # Loop through the keys, looking for 'form.'
                    991:     foreach my $name (keys(%persistent_db)) {
                    992:         next if ($name !~ /^form./);
1.182     matthew   993:         # Kludgification begins!
                    994:         if ($name eq 'form.domains' && 
                    995:             $ENV{'form.searchmode'} eq 'basic' &&
                    996:             $ENV{'form.phase'} ne 'disp_basic') {
                    997:             next;
                    998:         }
                    999:         # End kludge (hopefully)
1.152     matthew  1000:         next if (exists($ENV{$name}));
1.146     matthew  1001:         my @values = map { 
                   1002:             &Apache::lonnet::unescape($_);
                   1003:         } split(',',$persistent_db{$name});
                   1004:         next if (@values <1);
1.152     matthew  1005:         if ($arrays_allowed{$name}) {
                   1006:             $ENV{$name} = [@values];
1.146     matthew  1007:         } else {
1.152     matthew  1008:             $ENV{$name} = $values[0] if ($values[0]);
1.146     matthew  1009:         }
                   1010:     }
                   1011:     untie (%persistent_db);
                   1012:     return 1;
                   1013: }
1.181     matthew  1014: 
1.146     matthew  1015: ######################################################################
                   1016: ######################################################################
                   1017: 
                   1018: =pod 
                   1019: 
1.204     matthew  1020: =item &get_persistent_data()
1.146     matthew  1021: 
                   1022: Inputs: filename of database, ref to array of values to recover.
                   1023: 
                   1024: Outputs: array of values.  Returns undef on error.
                   1025: 
                   1026: This function is the reverse of &make_persistent();
                   1027: Retrieve persistent data from %persistent_db.  Retrieved items will have their
                   1028: values unescaped.  If the item contains commas (before unescaping), the
                   1029: returned value will be an array pointer. 
                   1030: 
                   1031: =cut
                   1032: 
                   1033: ######################################################################
                   1034: ######################################################################
                   1035: sub get_persistent_data {
                   1036:     my $filename = shift;
                   1037:     my @Vars = @{shift()};
                   1038:     my @Values;   # Return array
                   1039:     return undef if (! -e $filename);
                   1040:     return undef if (! tie(%persistent_db,'GDBM_File',$filename,
1.148     matthew  1041:                            &GDBM_READER(),0640));
1.146     matthew  1042:     foreach my $name (@Vars) {
                   1043:         if (! exists($persistent_db{$name})) {
                   1044:             push @Values, undef;
                   1045:             next;
                   1046:         }
                   1047:         my @values = map { 
                   1048:             &Apache::lonnet::unescape($_);
                   1049:         } split(',',$persistent_db{$name});
1.152     matthew  1050:         if (@values <= 1) {
1.146     matthew  1051:             push @Values,$values[0];
1.145     matthew  1052:         } else {
1.146     matthew  1053:             push @Values,\@values;
1.145     matthew  1054:         }
                   1055:     }
1.146     matthew  1056:     untie (%persistent_db);
                   1057:     return @Values;
1.145     matthew  1058: }
                   1059: 
                   1060: ######################################################################
                   1061: ######################################################################
                   1062: 
                   1063: =pod 
                   1064: 
1.121     matthew  1065: =item &make_persistent() 
                   1066: 
1.146     matthew  1067: Inputs: Hash of values to save, filename of persistent database.
                   1068: 
                   1069: Store variables away to the %persistent_db.
1.145     matthew  1070: Values will be escaped.  Values that are array pointers will have their
1.205     www      1071: elements escaped and concatenated in a comma separated string.  
1.122     matthew  1072: 
1.121     matthew  1073: =cut
                   1074: 
                   1075: ######################################################################
                   1076: ######################################################################
1.98      harris41 1077: sub make_persistent {
1.133     matthew  1078:     my %save = %{shift()};
1.146     matthew  1079:     my $filename = shift;
                   1080:     return undef if (! tie(%persistent_db,'GDBM_File',
1.148     matthew  1081:                            $filename,&GDBM_WRCREAT(),0640));
1.146     matthew  1082:     foreach my $name (keys(%save)) {
1.145     matthew  1083:         my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
                   1084:         # We handle array references, but not recursively.
                   1085:         my $store = join(',', map { &Apache::lonnet::escape($_); } @values );
                   1086:         $persistent_db{$name} = $store;
1.109     harris41 1087:     }
1.146     matthew  1088:     untie(%persistent_db);
                   1089:     return 1;
                   1090: }
                   1091: 
                   1092: ######################################################################
                   1093: ######################################################################
                   1094: 
                   1095: =pod 
                   1096: 
                   1097: =item &make_form_data_persistent() 
                   1098: 
                   1099: Inputs: filename of persistent database.
                   1100: 
                   1101: Store most form variables away to the %persistent_db.
                   1102: Values will be escaped.  Values that are array pointers will have their
1.205     www      1103: elements escaped and concatenated in a comma separated string.  
1.146     matthew  1104: 
                   1105: =cut
                   1106: 
                   1107: ######################################################################
                   1108: ######################################################################
                   1109: sub make_form_data_persistent {
                   1110:     my $r = shift;
                   1111:     my $filename = shift;
                   1112:     my %save;
                   1113:     foreach (keys(%ENV)) {
1.150     matthew  1114:         next if (!/^form/ || /submit/);
1.146     matthew  1115:         $save{$_} = $ENV{$_};
                   1116:     }
1.152     matthew  1117:     return &make_persistent(\%save,$filename);
1.98      harris41 1118: }
                   1119: 
1.122     matthew  1120: ######################################################################
                   1121: ######################################################################
                   1122: 
                   1123: =pod 
                   1124: 
1.134     matthew  1125: =item &parse_advanced_search()
                   1126: 
                   1127: Parse advanced search form and return the following:
                   1128: 
                   1129: =over 4
                   1130: 
                   1131: =item $query Scalar containing an SQL query.
1.126     matthew  1132: 
1.134     matthew  1133: =item $customquery Scalar containing a custom query.
                   1134: 
                   1135: =item $customshow Scalar containing commands to show custom metadata.
                   1136: 
                   1137: =item $libraries_to_query Reference to array of domains to search.
                   1138: 
                   1139: =back
1.122     matthew  1140: 
                   1141: =cut
                   1142: 
                   1143: ######################################################################
                   1144: ######################################################################
1.134     matthew  1145: sub parse_advanced_search {
1.196     matthew  1146:     my ($r,$closebutton,$hidden_fields)=@_;
1.216     matthew  1147:     my @BasicFields = ('title','author','subject','keywords','url','version',
1.217     matthew  1148:                        'notes','abstract','extension','owner',
1.216     matthew  1149: #                       'custommetadata','customshow',
                   1150:                        'modifyinguser','standards','mime');
1.217     matthew  1151:     my @StatsFields = ('stdno','avetries','difficulty','disc');
                   1152:     my @EvalFields = ('clear','depth','helpful','correct','technical');
1.32      harris41 1153:     my $fillflag=0;
1.143     matthew  1154:     my $pretty_search_string = "<br />\n";
1.64      harris41 1155:     # Clean up fields for safety
1.216     matthew  1156:     for my $field (@BasicFields,
                   1157:                    'creationdatestart_month','creationdatestart_day',
1.64      harris41 1158: 		   'creationdatestart_year','creationdateend_month',
                   1159: 		   'creationdateend_day','creationdateend_year',
                   1160: 		   'lastrevisiondatestart_month','lastrevisiondatestart_day',
                   1161: 		   'lastrevisiondatestart_year','lastrevisiondateend_month',
1.216     matthew  1162: 		   'lastrevisiondateend_day','lastrevisiondateend_year') {
                   1163: 	$ENV{'form.'.$field}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64      harris41 1164:     }
1.117     matthew  1165:     foreach ('mode','form','element') {
                   1166: 	# is this required?  Hmmm.
1.216     matthew  1167: 	next if (! exists($ENV{'form.'.$_}));
                   1168: 	$ENV{'form.'.$_}=&Apache::lonnet::unescape($ENV{'form.'.$_});
                   1169: 	$ENV{'form.'.$_}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.117     matthew  1170:     }
1.131     matthew  1171:     # Preprocess the category form element.
1.161     matthew  1172:     $ENV{'form.category'} = 'any' if (! defined($ENV{'form.category'}) ||
                   1173:                                       ref($ENV{'form.category'}));
                   1174:     #
1.90      harris41 1175:     # Check to see if enough information was filled in
1.216     matthew  1176:     for my $field (@BasicFields) {
                   1177: 	if (&filled($ENV{'form.'.$field})) {
1.32      harris41 1178: 	    $fillflag++;
                   1179: 	}
                   1180:     }
1.216     matthew  1181:     for my $field ('lowestgradelevel','highestgradelevel') {
                   1182:         if ( $ENV{'form.'.$field} =~ /^\d+$/ &&
                   1183:              $ENV{'form.'.$field} > 0) {
                   1184:             $fillflag++;
                   1185:         }
                   1186:     }
1.212     matthew  1187:     if (! $fillflag) {
1.204     matthew  1188: 	&output_blank_field_error($r,$closebutton,
                   1189:                                   'phase=disp_adv',$hidden_fields);
1.134     matthew  1190: 	return ;
1.32      harris41 1191:     }
1.90      harris41 1192:     # Turn the form input into a SQL-based query
1.39      harris41 1193:     my $query='';
1.45      harris41 1194:     my @queries;
1.143     matthew  1195:     my $font = '<font color="#800000" face="helvetica">';
1.90      harris41 1196:     # Evaluate logical expression AND/OR/NOT phrase fields.
1.216     matthew  1197:     foreach my $field (@BasicFields) {
1.44      harris41 1198: 	if ($ENV{'form.'.$field}) {
1.142     matthew  1199:             my $searchphrase = $ENV{'form.'.$field};
1.143     matthew  1200:             $pretty_search_string .= $font."$field</font> contains <b>".
                   1201:                 $searchphrase."</b>";
1.142     matthew  1202:             if ($ENV{'form.'.$field.'_related'}) {
1.143     matthew  1203:                 my @New_Words;
                   1204:                 ($searchphrase,@New_Words) = &related_version($searchphrase);
                   1205:                 if (@New_Words) {
                   1206:                     $pretty_search_string .= " with related words: ".
                   1207:                         "<b>@New_Words</b>.";
                   1208:                 } else {
                   1209:                     $pretty_search_string .= " with no related words.";
                   1210:                 }
1.142     matthew  1211:             }
1.143     matthew  1212:             $pretty_search_string .= "<br />\n";
1.142     matthew  1213: 	    push @queries,&build_SQL_query($field,$searchphrase);
1.131     matthew  1214:         }
1.44      harris41 1215:     }
1.161     matthew  1216:     #
                   1217:     # Make the 'mime' from 'form.category' and 'form.extension'
                   1218:     #
                   1219:     my $searchphrase;
                   1220:     if (exists($ENV{'form.category'})    && 
                   1221:         $ENV{'form.category'} !~ /^\s*$/ &&
                   1222:         $ENV{'form.category'} ne 'any')     {
                   1223:         my @extensions = &Apache::loncommon::filecategorytypes
                   1224:                                                    ($ENV{'form.category'});
                   1225:         if (scalar(@extensions) > 0) {
                   1226:             $searchphrase = join(' OR ',@extensions);
                   1227:         }
                   1228:     }
                   1229:     if (defined($searchphrase)) {
                   1230:         push @queries,&build_SQL_query('mime',$searchphrase);
                   1231:         $pretty_search_string .=$font.'mime</font> contains <b>'.
                   1232:             $searchphrase.'</b><br />';
1.135     matthew  1233:     }
1.204     matthew  1234:     #
1.90      harris41 1235:     # Evaluate option lists
1.216     matthew  1236:     if ($ENV{'form.lowestgradelevel'}        &&
                   1237:         $ENV{'form.lowestgradelevel'} ne '0' &&
                   1238:         $ENV{'form.lowestgradelevel'} =~ /^\d+$/) {
                   1239: 	push(@queries,
                   1240:              '(lowestgradelevel>='.$ENV{'form.lowestgradelevel'}.')');
                   1241:         $pretty_search_string.="lowestgradelevel>=".
                   1242:             $ENV{'form.lowestgradelevel'}."<br />\n";
                   1243:     }
                   1244:     if ($ENV{'form.highestgradelevel'}        &&
                   1245:         $ENV{'form.highestgradelevel'} ne '0' &&
                   1246:         $ENV{'form.highestgradelevel'} =~ /^\d+$/) {
                   1247: 	push(@queries,
                   1248:              '(highestgradelevel<='.$ENV{'form.highestgradelevel'}.')');
                   1249:         $pretty_search_string.="highestgradelevel<=".
                   1250:             $ENV{'form.highestgradelevel'}."<br />\n";
                   1251:     }
1.58      harris41 1252:     if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90      harris41 1253: 	push @queries,"(language like \"$ENV{'form.language'}\")";
1.143     matthew  1254:         $pretty_search_string.=$font."language</font>= ".
                   1255:             &Apache::loncommon::languagedescription($ENV{'form.language'}).
                   1256:                 "<br />\n";
1.58      harris41 1257:     }
                   1258:     if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90      harris41 1259: 	push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.143     matthew  1260:         $pretty_search_string.=$font."copyright</font> = ".
                   1261:             &Apache::loncommon::copyrightdescription($ENV{'form.copyright'}).
                   1262:                 "<br \>\n";
1.58      harris41 1263:     }
1.143     matthew  1264:     #
1.217     matthew  1265:     # Statistics
                   1266:     foreach my $field (@StatsFields,@EvalFields) {
                   1267:         my ($min,$max);
                   1268:         if (exists($ENV{'form.'.$field.'_min'}) && 
                   1269:             $ENV{'form.'.$field.'_min'} ne '') {
                   1270:             $min = $ENV{'form.'.$field.'_min'};
                   1271:         }
                   1272:         if (exists($ENV{'form.'.$field.'_max'}) &&
                   1273:             $ENV{'form.'.$field.'_max'} ne '') {
                   1274:             $max = $ENV{'form.'.$field.'_max'};
                   1275:         }
                   1276:         next if (! defined($max) && ! defined($min));
                   1277:         if (defined($min) && defined($max)) {
                   1278:             ($min,$max) = sort {$a <=>$b} ($min,$max);
                   1279:         }
                   1280:         if (defined($min) && $min =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
                   1281:             push(@queries,'('.$field.'>'.$min.')');
                   1282:             $pretty_search_string.=$font.$field.'</font>&gt;'.$min.'<br />';
                   1283:         }
                   1284:         if (defined($max) && $max =~ /^(\d+\.\d+|\d+|\.\d+)$/) {
                   1285:             push(@queries,'('.$field.'<'.$max.')');
                   1286:             $pretty_search_string.=$font.$field.'</font>&lt;'.$max.'<br />';
                   1287:         }
                   1288:     }
                   1289:     #
1.90      harris41 1290:     # Evaluate date windows
1.216     matthew  1291:     my $cafter =
                   1292:         &Apache::lonhtmlcommon::get_date_from_form('creationdate1');
                   1293:     my $cbefore = 
                   1294:         &Apache::lonhtmlcommon::get_date_from_form('creationdate2');
                   1295:     if ($cafter > $cbefore) {
                   1296:         my $tmp = $cafter;
                   1297:         $cafter = $cbefore;
                   1298:         $cbefore = $tmp;
                   1299:     }
                   1300:     my $mafter = 
                   1301:         &Apache::lonhtmlcommon::get_date_from_form('revisiondate1');
                   1302:     my $mbefore =
                   1303:         &Apache::lonhtmlcommon::get_date_from_form('revisiondate2');
                   1304:     if ($mafter > $mbefore) {
                   1305:         my $tmp = $mafter;
                   1306:         $mafter = $mbefore;
                   1307:         $mbefore = $tmp;
                   1308:     }
                   1309:     my ($datequery,$error,$prettydate)=&build_date_queries($cafter,$cbefore,
                   1310:                                                            $mafter,$mbefore);
                   1311:     if (defined($error)) {
                   1312:         &output_date_error($r,$error,$closebutton,$hidden_fields);
                   1313:     } elsif (defined($datequery)) {
1.143     matthew  1314:         # Here is where you would set up pretty_search_string to output
                   1315:         # date query information.
1.216     matthew  1316:         $pretty_search_string .= '<br />'.$prettydate.'<br />';
1.60      harris41 1317: 	push @queries,$datequery;
                   1318:     }
1.204     matthew  1319:     #
1.90      harris41 1320:     # Process form information for custom metadata querying
1.134     matthew  1321:     my $customquery=undef;
1.204     matthew  1322:     ##
                   1323:     ## The custom metadata search was removed q long time ago mostly 
                   1324:     ## because I was unable to figureout exactly how it worked and could
                   1325:     ## not imagine people actually using it.  MH
                   1326:     ##
                   1327:     # if ($ENV{'form.custommetadata'}) {
                   1328:     #    $pretty_search_string .=$font."Custom Metadata Search</font>: <b>".
                   1329:     #    $ENV{'form.custommetadata'}."</b><br />\n";
                   1330:     #    $customquery=&build_custommetadata_query('custommetadata',
                   1331:     #                                             $ENV{'form.custommetadata'});
                   1332:     # }
1.134     matthew  1333:     my $customshow=undef;
1.204     matthew  1334:     # if ($ENV{'form.customshow'}) {
                   1335:     # $pretty_search_string .=$font."Custom Metadata Display</font>: <b>".
                   1336:     #                         $ENV{'form.customshow'}."</b><br />\n";
                   1337:     #    $customshow=$ENV{'form.customshow'};
                   1338:     #    $customshow=~s/[^\w\s]//g;
                   1339:     #    my @fields=split(/\s+/,$customshow);
                   1340:     #    $customshow=join(" ",@fields);
                   1341:     # }
                   1342:     ##
1.132     matthew  1343:     ## Deal with restrictions to given domains
                   1344:     ## 
1.180     matthew  1345:     my ($libraries_to_query,$pretty_domains_string) = 
                   1346:         &parse_domain_restrictions();
                   1347:     $pretty_search_string .= $pretty_domains_string."<br />\n";
                   1348:     #
                   1349:     if (@queries) {
1.216     matthew  1350: 	$query="select * from metadata where ".join(" AND ",@queries);
1.180     matthew  1351:     } elsif ($customquery) {
                   1352:         $query = '';
                   1353:     }
1.217     matthew  1354: #    &Apache::lonnet::logthis('query = '.$/.$query);
1.180     matthew  1355:     return ($query,$customquery,$customshow,$libraries_to_query,
                   1356:             $pretty_search_string);
                   1357: }
                   1358: 
                   1359: sub parse_domain_restrictions {
1.132     matthew  1360:     my $libraries_to_query = undef;
                   1361:     # $ENV{'form.domains'} can be either a scalar or an array reference.
                   1362:     # We need an array.
1.180     matthew  1363:     if (! exists($ENV{'form.domains'})) {
                   1364:         return (undef,'');
                   1365:     }
                   1366:     my @allowed_domains;
                   1367:     if (ref($ENV{'form.domains'})) {
                   1368:         @allowed_domains =  @{$ENV{'form.domains'}};
                   1369:     } else {
                   1370:         @allowed_domains = ($ENV{'form.domains'});
                   1371:     }
1.204     matthew  1372:     #
1.132     matthew  1373:     my %domain_hash = ();
1.143     matthew  1374:     my $pretty_domains_string;
1.132     matthew  1375:     foreach (@allowed_domains) {
                   1376:         $domain_hash{$_}++;
                   1377:     }
1.143     matthew  1378:     if ($domain_hash{'any'}) {
1.152     matthew  1379:         $pretty_domains_string = "In all LON-CAPA domains.";
1.143     matthew  1380:     } else {
                   1381:         if (@allowed_domains > 1) {
1.152     matthew  1382:             $pretty_domains_string = "In LON-CAPA domains:";
1.143     matthew  1383:         } else {
1.152     matthew  1384:             $pretty_domains_string = "In LON-CAPA domain ";
1.143     matthew  1385:         }
                   1386:         foreach (sort @allowed_domains) {
1.152     matthew  1387:             $pretty_domains_string .= "<b>".$_."</b> ";
1.132     matthew  1388:         }
1.143     matthew  1389:         foreach (keys(%Apache::lonnet::libserv)) {
                   1390:             if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
                   1391:                 push @$libraries_to_query,$_;
                   1392:             }
1.132     matthew  1393:         }
                   1394:     }
1.180     matthew  1395:     return ($libraries_to_query,$pretty_domains_string);
1.18      harris41 1396: }
                   1397: 
1.122     matthew  1398: ######################################################################
                   1399: ######################################################################
                   1400: 
                   1401: =pod 
                   1402: 
1.134     matthew  1403: =item &parse_basic_search() 
1.122     matthew  1404: 
1.134     matthew  1405: Parse the basic search form and return a scalar containing an sql query.
1.126     matthew  1406: 
1.122     matthew  1407: =cut
                   1408: 
                   1409: ######################################################################
                   1410: ######################################################################
1.134     matthew  1411: sub parse_basic_search {
1.145     matthew  1412:     my ($r,$closebutton)=@_;
1.204     matthew  1413:     #
1.64      harris41 1414:     # Clean up fields for safety
                   1415:     for my $field ('basicexp') {
                   1416: 	$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
                   1417:     }
1.117     matthew  1418:     foreach ('mode','form','element') {
                   1419: 	# is this required?  Hmmm.
                   1420: 	next unless (exists($ENV{"form.$_"}));
                   1421: 	$ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
                   1422: 	$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
                   1423:     }
1.180     matthew  1424:     my ($libraries_to_query,$pretty_domains_string) = 
                   1425:         &parse_domain_restrictions();
1.204     matthew  1426:     #
                   1427:     # Check to see if enough of a query is filled in
1.26      harris41 1428:     unless (&filled($ENV{'form.basicexp'})) {
1.151     matthew  1429: 	&output_blank_field_error($r,$closebutton,'phase=disp_basic');
1.24      harris41 1430: 	return OK;
                   1431:     }
1.143     matthew  1432:     my $pretty_search_string = '<b>'.$ENV{'form.basicexp'}.'</b>';
1.142     matthew  1433:     my $search_string = $ENV{'form.basicexp'};
1.141     matthew  1434:     if ($ENV{'form.related'}) {
1.143     matthew  1435:         my @New_Words;
                   1436:         ($search_string,@New_Words) = &related_version($ENV{'form.basicexp'});
                   1437:         if (@New_Words) {
                   1438:             $pretty_search_string .= " with related words: <b>@New_Words</b>.";
                   1439:         } else {
                   1440:             $pretty_search_string .= " with no related words.";
                   1441:         }
1.141     matthew  1442:     }
1.204     matthew  1443:     #
1.90      harris41 1444:     # Build SQL query string based on form page
1.39      harris41 1445:     my $query='';
1.178     matthew  1446:     my $concatarg=join(',',
1.124     matthew  1447: 		       ('title', 'author', 'subject', 'notes', 'abstract',
                   1448:                         'keywords'));
1.95      harris41 1449:     $concatarg='title' if $ENV{'form.titleonly'};
1.178     matthew  1450:     $query=&build_SQL_query('concat_ws(" ",'.$concatarg.')',$search_string);
1.180     matthew  1451:     if (defined($pretty_domains_string) && $pretty_domains_string ne '') {
                   1452:         $pretty_search_string .= ' '.$pretty_domains_string;
                   1453:     }
1.143     matthew  1454:     $pretty_search_string .= "<br />\n";
1.183     matthew  1455:     my $final_query = 'SELECT * FROM metadata WHERE '.$query;
1.204     matthew  1456:     # &Apache::lonnet::logthis($final_query);
1.183     matthew  1457:     return ($final_query,$pretty_search_string,
1.180     matthew  1458:             $libraries_to_query);
1.22      harris41 1459: }
                   1460: 
1.122     matthew  1461: ######################################################################
                   1462: ######################################################################
                   1463: 
                   1464: =pod 
                   1465: 
1.204     matthew  1466: =item &related_version()
1.142     matthew  1467: 
                   1468: Modifies an input string to include related words.  Words in the string
                   1469: are replaced with parenthesized lists of 'OR'd words.  For example
                   1470: "torque" is replaced with "(torque OR word1 OR word2 OR ...)".  
                   1471: 
                   1472: Note: Using this twice on a string is probably silly.
                   1473: 
                   1474: =cut
                   1475: 
                   1476: ######################################################################
                   1477: ######################################################################
                   1478: sub related_version {
                   1479:     my $search_string = shift;
                   1480:     my $result = $search_string;
1.143     matthew  1481:     my %New_Words = ();
1.142     matthew  1482:     while ($search_string =~ /(\w+)/cg) {
                   1483:         my $word = $1;
                   1484:         next if (lc($word) =~ /\b(or|and|not)\b/);
                   1485:         my @Words = &Apache::loncommon::get_related_words($word);
1.143     matthew  1486:         @Words = ($#Words>4? @Words[0..4] : @Words);
                   1487:         foreach (@Words) { $New_Words{$_}++;}
                   1488:         my $replacement = join " OR ", ($word,@Words);
1.142     matthew  1489:         $result =~ s/(\b)$word(\b)/$1($replacement)$2/g;
                   1490:     }
1.143     matthew  1491:     return $result,sort(keys(%New_Words));
1.142     matthew  1492: }
                   1493: 
                   1494: ######################################################################
                   1495: ######################################################################
                   1496: 
                   1497: =pod 
                   1498: 
1.122     matthew  1499: =item &build_SQL_query() 
                   1500: 
1.126     matthew  1501: Builds a SQL query string from a logical expression with AND/OR keywords
                   1502: using Text::Query and &recursive_SQL_query_builder()
                   1503: 
1.122     matthew  1504: =cut
                   1505: 
                   1506: ######################################################################
                   1507: ######################################################################
1.98      harris41 1508: sub build_SQL_query {
                   1509:     my ($field_name,$logic_statement)=@_;
                   1510:     my $q=new Text::Query('abc',
                   1511: 			  -parse => 'Text::Query::ParseAdvanced',
                   1512: 			  -build => 'Text::Query::Build');
                   1513:     $q->prepare($logic_statement);
                   1514:     my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
                   1515:     my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
                   1516:     return $sql_query;
                   1517: }
                   1518: 
1.122     matthew  1519: ######################################################################
                   1520: ######################################################################
                   1521: 
                   1522: =pod 
                   1523: 
                   1524: =item &build_custommetadata_query() 
                   1525: 
1.126     matthew  1526: Constructs a custom metadata query using a rather heinous regular
                   1527: expression.
                   1528: 
1.122     matthew  1529: =cut
                   1530: 
                   1531: ######################################################################
                   1532: ######################################################################
1.98      harris41 1533: sub build_custommetadata_query {
                   1534:     my ($field_name,$logic_statement)=@_;
                   1535:     my $q=new Text::Query('abc',
                   1536: 			  -parse => 'Text::Query::ParseAdvanced',
                   1537: 			  -build => 'Text::Query::BuildAdvancedString');
                   1538:     $q->prepare($logic_statement);
                   1539:     my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
                   1540:     # quick fix to change literal into xml tag-matching
                   1541:     # will eventually have to write a separate builder module
1.122     matthew  1542:     # wordone=wordtwo becomes\<wordone\>[^\<] *wordtwo[^\<]*\<\/wordone\>
                   1543:     $matchexp =~ s/(\w+)\\=([\w\\\+]+)?# wordone=wordtwo is changed to 
                   1544:                  /\\<$1\\>?#           \<wordone\>
                   1545:                    \[\^\\<\]?#        [^\<]         
                   1546:                    \*$2\[\^\\<\]?#           *wordtwo[^\<]
                   1547:                    \*\\<\\\/$1\\>?#                        *\<\/wordone\>
                   1548:                    /g;
1.98      harris41 1549:     return $matchexp;
                   1550: }
                   1551: 
1.122     matthew  1552: ######################################################################
                   1553: ######################################################################
                   1554: 
                   1555: =pod 
                   1556: 
                   1557: =item &recursive_SQL_query_build() 
                   1558: 
1.126     matthew  1559: Recursively constructs an SQL query.  Takes as input $dkey and $pattern.
                   1560: 
1.122     matthew  1561: =cut
                   1562: 
                   1563: ######################################################################
                   1564: ######################################################################
1.98      harris41 1565: sub recursive_SQL_query_build {
                   1566:     my ($dkey,$pattern)=@_;
                   1567:     my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
                   1568:     return $pattern unless @matches;
                   1569:     foreach my $match (@matches) {
1.173     matthew  1570:         $match=~/\[ (\w+)\s(.*) \]/;
                   1571:         my ($key,$value)=($1,$2);
                   1572:         my $replacement='';
                   1573:         if ($key eq 'literal') {
1.178     matthew  1574:             $replacement="($dkey LIKE \"\%$value\%\")";
                   1575:         } elsif (lc($key) eq 'not') {
                   1576:             $value=~s/LIKE/NOT LIKE/;
1.173     matthew  1577: #          $replacement="($dkey not like $value)";
                   1578:             $replacement="$value";
                   1579:         } elsif ($key eq 'and') {
                   1580:             $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                   1581:             $replacement="($1 AND $2)";
                   1582: 	} elsif ($key eq 'or') {
                   1583:             $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                   1584:             $replacement="($1 OR $2)";
1.98      harris41 1585: 	}
                   1586: 	substr($pattern,
1.173     matthew  1587:                index($pattern,$match),
                   1588:                length($match),
                   1589:                $replacement);
1.98      harris41 1590:     }
                   1591:     &recursive_SQL_query_build($dkey,$pattern);
                   1592: }
1.22      harris41 1593: 
1.122     matthew  1594: ######################################################################
                   1595: ######################################################################
                   1596: 
                   1597: =pod 
                   1598: 
                   1599: =item &build_date_queries() 
                   1600: 
1.126     matthew  1601: Builds a SQL logic query to check time/date entries.
                   1602: Also reports errors (check for /^Incorrect/).
                   1603: 
1.122     matthew  1604: =cut
                   1605: 
                   1606: ######################################################################
                   1607: ######################################################################
1.98      harris41 1608: sub build_date_queries {
1.216     matthew  1609:     my ($cafter,$cbefore,$mafter,$mbefore) = @_;
                   1610:     my ($result,$error,$pretty_string);
                   1611:     #
                   1612:     # Verify the input
                   1613:     if (! defined($cafter) && ! defined($cbefore) &&
                   1614:         ! defined($mafter) && ! defined($mbefore)) {
                   1615:         # This is an okay situation, so return undef for the error
                   1616:         return (undef,undef,undef);
                   1617:     }
                   1618:     if ((defined($cafter)  && ! defined($cbefore)) ||
                   1619:         (defined($cbefore) && ! defined($cafter))) {
                   1620:         # This is bad, so let them know
                   1621:         $error = &mt('Incorrect entry for the creation date.  '.
                   1622:                     'You must specify both the beginning and ending dates.');
                   1623:     }
                   1624:     if (! defined($error) && 
                   1625:         ((defined($mafter)  && ! defined($mbefore)) ||
                   1626:         (defined($mbefore) && ! defined($mafter)))) {
                   1627:         # This is also bad, so let them know
                   1628:         $error = &mt('Incorrect entry for the last revision date.  '.
                   1629:                      'You must specify both the beginning and ending dates.');
1.98      harris41 1630:     }
1.216     matthew  1631:     if (! defined($error)) {
                   1632:         #
                   1633:         # Build the queries
                   1634:         my @queries;
                   1635:         if (defined($cbefore) && defined($cafter)) {
                   1636:             my (undef,undef,undef,$caday,$camon,$cayear) = localtime($cafter);
                   1637:             my (undef,undef,undef,$cbday,$cbmon,$cbyear) = localtime($cbefore);
                   1638:             # Correct for year being relative to 1900
                   1639:             $cayear+=1900; $cbyear+=1900;
                   1640:             my $cquery=
                   1641:                 '(creationdate BETWEEN '.
                   1642:                 "'".$cayear.'-'.$camon.'-'.$caday."'".
                   1643:                 ' AND '.
                   1644:                 "'".$cbyear.'-'.$cbmon.'-'.$cbday." 23:59:59')";
                   1645:             $pretty_string .= '<br />' if (defined($pretty_string));
                   1646:             $pretty_string .= 
                   1647:                 &mt('created between [_1] and [_2]',
                   1648:                     &Apache::lonlocal::locallocaltime($cafter),
                   1649:                     &Apache::lonlocal::locallocaltime($cbefore+24*60*60-1));
                   1650:             push(@queries,$cquery);
                   1651:             $pretty_string =~ s/ 00:00:00//g;
                   1652:         }
                   1653:         if (defined($mbefore) && defined($mafter)) {
                   1654:             my (undef,undef,undef,$maday,$mamon,$mayear) = localtime($mafter);
                   1655:             my (undef,undef,undef,$mbday,$mbmon,$mbyear) = localtime($mbefore);
                   1656:             # Correct for year being relative to 1900
                   1657:             $mayear+=1900; $mbyear+=1900;
                   1658:             my $mquery=
                   1659:                 '(lastrevisiondate BETWEEN '.
                   1660:                 "'".$mayear.'-'.$mamon.'-'.$maday."'".
                   1661:                 ' AND '.
                   1662:                 "'".$mbyear.'-'.$mbmon.'-'.$mbday." 23:59:59')";
                   1663:             push(@queries,$mquery);
                   1664:             $pretty_string .= '<br />' if (defined($pretty_string));
                   1665:             $pretty_string .= 
                   1666:                 &mt('last revised between [_1] and [_2]',
                   1667:                     &Apache::lonlocal::locallocaltime($mafter),
                   1668:                     &Apache::lonlocal::locallocaltime($mbefore+24*60*60-1));
                   1669:             $pretty_string =~ s/ 00:00:00//g;
                   1670:         }
                   1671:         if (@queries) {
                   1672:             $result .= join(" AND ",@queries);
                   1673:         }
1.98      harris41 1674:     }
1.216     matthew  1675:     return ($result,$error,$pretty_string);
1.18      harris41 1676: }
1.6       harris41 1677: 
1.122     matthew  1678: ######################################################################
                   1679: ######################################################################
                   1680: 
1.144     matthew  1681: =pod
                   1682: 
                   1683: =item &copyright_check()
                   1684: 
1.204     matthew  1685: Inputs: $Metadata, a hash pointer of metadata for a resource.
                   1686: 
                   1687: Returns: 1 if the resource is available to the user making the query, 
                   1688:          0 otherwise.
                   1689: 
1.144     matthew  1690: =cut
                   1691: 
                   1692: ######################################################################
                   1693: ######################################################################
                   1694: sub copyright_check {
                   1695:     my $Metadata = shift;
                   1696:     # Check copyright tags and skip results the user cannot use
                   1697:     my (undef,undef,$resdom,$resname) = split('/',
                   1698:                                               $Metadata->{'url'});
                   1699:     # Check for priv
                   1700:     if (($Metadata->{'copyright'} eq 'priv') && 
                   1701:         (($ENV{'user.name'} ne $resname) &&
                   1702:          ($ENV{'user.domain'} ne $resdom))) {
                   1703:         return 0;
                   1704:     }
                   1705:     # Check for domain
                   1706:     if (($Metadata->{'copyright'} eq 'domain') &&
                   1707:         ($ENV{'user.domain'} ne $resdom)) {
                   1708:         return 0;
                   1709:     }
                   1710:     return 1;
                   1711: }
                   1712: 
1.151     matthew  1713: ######################################################################
                   1714: ######################################################################
                   1715: 
                   1716: =pod
                   1717: 
1.204     matthew  1718: =item &ensure_db_and_table()
1.151     matthew  1719: 
                   1720: Ensure we can get lonmysql to connect to the database and the table we
                   1721: need exists.
                   1722: 
                   1723: Inputs: $r, table id
                   1724: 
                   1725: Returns: undef on error, 1 if the table exists.
                   1726: 
                   1727: =cut
                   1728: 
                   1729: ######################################################################
                   1730: ######################################################################
                   1731: sub ensure_db_and_table {
                   1732:     my ($r,$table) = @_;
                   1733:     ##
                   1734:     ## Sanity check the table id.
                   1735:     ##
                   1736:     if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
                   1737:         $r->print("Unable to retrieve search results.  ".
                   1738:                   "Unable to determine the table results were stored in.  ".
                   1739:                   "</body></html>");
                   1740:         return undef;
                   1741:     }
                   1742:     ##
                   1743:     ## Make sure we can connect and the table exists.
                   1744:     ##
                   1745:     my $connection_result = &Apache::lonmysql::connect_to_db();
                   1746:     if (!defined($connection_result)) {
                   1747:         $r->print("Unable to connect to the MySQL database where your results".
                   1748:                   " are stored. </body></html>");
                   1749:         &Apache::lonnet::logthis("lonsearchcat: unable to get lonmysql to".
                   1750:                                  " connect to database.");
                   1751:         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
                   1752:         return undef;
                   1753:     }
                   1754:     my $table_check = &Apache::lonmysql::check_table($table);
                   1755:     if (! defined($table_check)) {
                   1756:         $r->print("A MySQL error has occurred.</form></body></html>");
                   1757:         &Apache::lonnet::logthis("lonmysql was unable to determine the status".
                   1758:                                  " of table ".$table);
                   1759:         return undef;
                   1760:     } elsif (! $table_check) {
                   1761:         $r->print("The table of results could not be found.");
                   1762:         &Apache::lonnet::logthis("The user requested a table, ".$table.
                   1763:                                  ", that could not be found.");
                   1764:         return undef;
                   1765:     }
                   1766:     return 1;
                   1767: }
                   1768: 
                   1769: ######################################################################
                   1770: ######################################################################
                   1771: 
                   1772: =pod
                   1773: 
1.204     matthew  1774: =item &print_sort_form()
                   1775: 
                   1776: The sort feature is not implemented at this time.  This form just prints 
                   1777: a link to change the search query.
1.151     matthew  1778: 
                   1779: =cut
                   1780: 
                   1781: ######################################################################
                   1782: ######################################################################
                   1783: sub print_sort_form {
                   1784:     my ($r,$pretty_query_string) = @_;
1.196     matthew  1785:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.151     matthew  1786:     ##
1.187     www      1787:     my %SortableFields=&Apache::lonlocal::texthash( 
                   1788:          id        => 'Default',
1.151     matthew  1789:          title     => 'Title',
                   1790:          author    => 'Author',
                   1791:          subject   => 'Subject',
                   1792:          url       => 'URL',
                   1793:          version   => 'Version Number',
                   1794:          mime      => 'Mime type',
                   1795:          lang      => 'Language',
                   1796:          owner     => 'Owner/Publisher',
                   1797:          copyright => 'Copyright',
                   1798:          hostname  => 'Host',
                   1799:          creationdate     => 'Creation Date',
1.187     www      1800:          lastrevisiondate => 'Revision Date'
1.151     matthew  1801:      );
                   1802:     ##
                   1803:     my $table = $ENV{'form.table'};
                   1804:     return if (! &ensure_db_and_table($r,$table));
                   1805:     ##
                   1806:     ## Get the number of results 
                   1807:     ##
                   1808:     my $total_results = &Apache::lonmysql::number_of_rows($table);
                   1809:     if (! defined($total_results)) {
                   1810:         $r->print("A MySQL error has occurred.</form></body></html>");
                   1811:         &Apache::lonnet::logthis("lonmysql was unable to determine the number".
                   1812:                                  " of rows in table ".$table);
                   1813:         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
                   1814:         return;
                   1815:     }
                   1816:     my $result;
                   1817:     $result.=<<END;
                   1818: <html>
                   1819: <head>
                   1820: <script>
                   1821:     function change_sort() {
                   1822:         var newloc = "/adm/searchcat?phase=results";
                   1823:         newloc += "&persistent_db_id=$ENV{'form.persistent_db_id'}";
                   1824:         newloc += "&sortby=";
                   1825:         newloc += document.forms.statusform.elements.sortby.value;
                   1826:         parent.resultsframe.location= newloc;
                   1827:     }
                   1828: </script>
                   1829: <title>Results</title>
                   1830: </head>
1.155     matthew  1831: $bodytag
1.151     matthew  1832: <form name="statusform" action="" method="post">
1.153     matthew  1833: <input type="hidden" name="Queue" value="" />
1.151     matthew  1834: END
                   1835: 
                   1836: #<h2>Sort Results</h2>
                   1837: #Sort by: <select size="1" name="sortby" onchange="javascript:change_sort();">
                   1838: #    $ENV{'form.sortby'} = 'id' if (! defined($ENV{'form.sortby'}));
                   1839: #    foreach (keys(%SortableFields)) {
                   1840: #        $result.="<option name=\"$_\"";
                   1841: #        if ($_ eq $ENV{'form.sortby'}) {
                   1842: #            $result.=" selected ";
                   1843: #        }
                   1844: #        $result.=" >$SortableFields{$_}</option>\n";
                   1845: #    }
                   1846: #    $result.="</select>\n";
                   1847:     my $revise = &revise_button();
                   1848:     $result.=<<END;
                   1849: <p>
                   1850: There are $total_results matches to your query. $revise
                   1851: </p><p>
                   1852: Search:$pretty_query_string
                   1853: </p>
                   1854: </form>
                   1855: </body>
                   1856: </html>
                   1857: END
                   1858:     $r->print($result);
                   1859:     return;
                   1860: }
                   1861: 
1.144     matthew  1862: #####################################################################
                   1863: #####################################################################
                   1864: 
                   1865: =pod
                   1866: 
                   1867: =item MySQL Table Description
                   1868: 
                   1869: MySQL table creation requires a precise description of the data to be
                   1870: stored.  The use of the correct types to hold data is vital to efficient
                   1871: storage and quick retrieval of records.  The columns must be described in
                   1872: the following format:
                   1873: 
                   1874: =cut
                   1875: 
1.170     matthew  1876: #####################################################################
                   1877: #####################################################################
1.204     matthew  1878: #
                   1879: # These should probably be scoped but I don't have time right now...
                   1880: #
                   1881: my @Datatypes;
                   1882: my @Fullindicies;
1.147     matthew  1883:     
1.144     matthew  1884: ######################################################################
                   1885: ######################################################################
                   1886: 
                   1887: =pod
                   1888: 
1.146     matthew  1889: =item &create_results_table()
                   1890: 
                   1891: Creates the table of search results by calling lonmysql.  Stores the
                   1892: table id in $ENV{'form.table'}
                   1893: 
                   1894: Inputs: none.
                   1895: 
                   1896: Returns: the identifier of the table on success, undef on error.
                   1897: 
                   1898: =cut
                   1899: 
                   1900: ######################################################################
                   1901: ######################################################################
1.204     matthew  1902: sub set_up_table_structure {
                   1903:     my ($datatypes,$fullindicies) = 
                   1904:         &LONCAPA::lonmetadata::describe_metadata_storage();
1.212     matthew  1905:     # Copy the table description before modifying it...
                   1906:     @Datatypes = @{$datatypes};
                   1907:     unshift(@Datatypes,{name => 'id',  
1.204     matthew  1908:         type => 'MEDIUMINT',
                   1909:         restrictions => 'UNSIGNED NOT NULL',
                   1910:         primary_key  => 'yes',
                   1911:         auto_inc     => 'yes' });
                   1912:     @Fullindicies = @{$fullindicies};
                   1913:     return;
                   1914: }
                   1915: 
1.146     matthew  1916: sub create_results_table {
1.204     matthew  1917:     &set_up_table_structure();
1.146     matthew  1918:     my $table = &Apache::lonmysql::create_table
1.170     matthew  1919:         ( { columns => \@Datatypes,
1.172     matthew  1920:             FULLTEXT => [{'columns' => \@Fullindicies},],
1.146     matthew  1921:         } );
                   1922:     if (defined($table)) {
                   1923:         $ENV{'form.table'} = $table;
                   1924:         return $table;
                   1925:     } 
                   1926:     return undef; # Error...
                   1927: }
1.148     matthew  1928: 
1.146     matthew  1929: ######################################################################
                   1930: ######################################################################
                   1931: 
                   1932: =pod
                   1933: 
1.150     matthew  1934: =item Search Status update functions
1.144     matthew  1935: 
1.150     matthew  1936: Each of the following functions changes the values of one of the
                   1937: input fields used to display the search status to the user.  The names
                   1938: should be explanatory.
1.144     matthew  1939: 
1.150     matthew  1940: Inputs: Apache request handler ($r), text to display.
1.148     matthew  1941: 
1.150     matthew  1942: Returns: Nothing.
1.148     matthew  1943: 
                   1944: =over 4
                   1945: 
                   1946: =item &update_count_status()
                   1947: 
1.150     matthew  1948: =item &update_status()
1.148     matthew  1949: 
1.150     matthew  1950: =item &update_seconds()
1.148     matthew  1951: 
                   1952: =back
                   1953: 
                   1954: =cut
                   1955: 
                   1956: ######################################################################
                   1957: ######################################################################
                   1958: sub update_count_status {
                   1959:     my ($r,$text) = @_;
                   1960:     $text =~ s/\'/\\\'/g;
                   1961:     $r->print
                   1962:         ("<script>document.statusform.count.value = ' $text'</script>\n");
                   1963:     $r->rflush();
                   1964: }
                   1965: 
1.150     matthew  1966: sub update_status {
1.148     matthew  1967:     my ($r,$text) = @_;
                   1968:     $text =~ s/\'/\\\'/g;
                   1969:     $r->print
1.150     matthew  1970:         ("<script>document.statusform.status.value = ' $text'</script>\n");
1.148     matthew  1971:     $r->rflush();
                   1972: }
                   1973: 
1.214     matthew  1974: {
                   1975:     my $max_time  = 40;  # seconds for the search to complete
                   1976:     my $start_time = 0;
                   1977:     my $last_time = 0;
                   1978: 
                   1979: sub reset_timing {
                   1980:     $start_time = 0;
                   1981:     $last_time = 0;
                   1982: }
                   1983: 
                   1984: sub time_left {
                   1985:     if ($start_time == 0) {
                   1986:         $start_time = time;
                   1987:     }
                   1988:     my $time_left = $max_time - (time - $start_time);
                   1989:     $time_left = 0 if ($time_left < 0);
                   1990:     return $time_left;
                   1991: }
                   1992: 
1.150     matthew  1993: sub update_seconds {
1.214     matthew  1994:     my ($r) = @_;
                   1995:     my $time = &time_left();
                   1996:     if (($last_time-$time) > 0) {
                   1997:         $r->print("<script>".
                   1998:                   "document.statusform.seconds.value = '$time'".
                   1999:                   "</script>\n");
                   2000:         $r->rflush();
                   2001:     }
                   2002:     $last_time = $time;
                   2003: }
                   2004: 
1.148     matthew  2005: }
                   2006: 
                   2007: ######################################################################
                   2008: ######################################################################
                   2009: 
                   2010: =pod
                   2011: 
1.204     matthew  2012: =item &revise_button()
1.151     matthew  2013: 
                   2014: Inputs: None
                   2015: 
                   2016: Returns: html string for a 'revise search' button.
                   2017: 
                   2018: =cut
                   2019: 
                   2020: ######################################################################
                   2021: ######################################################################
                   2022: sub revise_button {
                   2023:     my $revise_phase = 'disp_basic';
                   2024:     $revise_phase = 'disp_adv' if ($ENV{'form.searchmode'} eq 'advanced');
                   2025:     my $newloc = '/adm/searchcat'.
                   2026:         '?persistent_db_id='.$ENV{'form.persistent_db_id'}.
1.158     matthew  2027:             '&cleargroupsort=1'.
1.151     matthew  2028:             '&phase='.$revise_phase;
                   2029:     my $result = qq{<input type="button" value="Revise search" name="revise"} .
                   2030:         qq{ onClick="parent.location='$newloc';" /> };
                   2031:     return $result;
                   2032: }
                   2033: 
                   2034: ######################################################################
                   2035: ######################################################################
                   2036: 
                   2037: =pod
                   2038: 
1.204     matthew  2039: =item &run_search()
                   2040: 
                   2041: Executes a search query by sending it the the other servers and putting the
                   2042: results into MySQL.
1.144     matthew  2043: 
                   2044: =cut
                   2045: 
                   2046: ######################################################################
                   2047: ######################################################################
                   2048: sub run_search {
1.146     matthew  2049:     my ($r,$query,$customquery,$customshow,$serverlist,$pretty_string) = @_;
1.196     matthew  2050:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.150     matthew  2051:     my $connection = $r->connection;
1.144     matthew  2052:     #
1.146     matthew  2053:     # Print run_search header
                   2054:     #
1.151     matthew  2055:     $r->print(<<END);
                   2056: <html>
                   2057: <head><title>Search Status</title></head>
1.155     matthew  2058: $bodytag
1.151     matthew  2059: <form name="statusform" action="" method="post">
                   2060: <input type="hidden" name="Queue" value="" />
                   2061: END
                   2062:     # Check to see if $pretty_string has more than one carriage return.
                   2063:     # Assume \n s are following <br /> s and truncate the value.
                   2064:     # (there is probably a better way)...
1.152     matthew  2065:     my @Lines = split /<br \/>/,$pretty_string;
                   2066:     if (@Lines > 2) {
                   2067:         $pretty_string = join '<br \>',(@Lines[0..2],'....<br />');
1.151     matthew  2068:     }
1.214     matthew  2069:     $r->print(&mt("Search: [_1]",$pretty_string));
1.146     matthew  2070:     $r->rflush();
                   2071:     #
1.145     matthew  2072:     # Determine the servers we need to contact.
1.144     matthew  2073:     my @Servers_to_contact;
                   2074:     if (defined($serverlist)) {
1.152     matthew  2075:         if (ref($serverlist) eq 'ARRAY') {
                   2076:             @Servers_to_contact = @$serverlist;
                   2077:         } else {
                   2078:             @Servers_to_contact = ($serverlist);
                   2079:         }
1.144     matthew  2080:     } else {
                   2081:         @Servers_to_contact = sort(keys(%Apache::lonnet::libserv));
                   2082:     }
                   2083:     my %Server_status;
1.214     matthew  2084:     #
                   2085:     # Check on the mysql table we will use to store results.
1.146     matthew  2086:     my $table =$ENV{'form.table'};
1.150     matthew  2087:     if (! defined($table) || $table eq '' || $table =~ /\D/ ) {
1.147     matthew  2088:         $r->print("Unable to determine table id to store search results in.".
1.148     matthew  2089:                   "The search has been aborted.</body></html>");
1.147     matthew  2090:         return;
                   2091:     }
                   2092:     my $table_status = &Apache::lonmysql::check_table($table);
                   2093:     if (! defined($table_status)) {
                   2094:         $r->print("Unable to determine status of table.</body></html>");
                   2095:         &Apache::lonnet::logthis("Bogus table id of $table for ".
                   2096:                                  "$ENV{'user.name'} @ $ENV{'user.domain'}");
                   2097:         &Apache::lonnet::logthis("lonmysql error = ".
1.144     matthew  2098:                                  &Apache::lonmysql::get_error());
1.147     matthew  2099:         return;
                   2100:     }
                   2101:     if (! $table_status) {
1.204     matthew  2102:         &Apache::lonnet::logthis("lonmysql error = ".
                   2103:                                  &Apache::lonmysql::get_error());
                   2104:         &Apache::lonnet::logthis("lonmysql debug = ".
                   2105:                                  &Apache::lonmysql::get_debug());
                   2106:         &Apache::lonnet::logthis('table status = "'.$table_status.'"');
1.147     matthew  2107:         $r->print("The table id,$table, we tried to use is invalid.".
1.148     matthew  2108:                   "The search has been aborted.</body></html>");
1.144     matthew  2109:         return;
                   2110:     }
1.145     matthew  2111:     ##
1.146     matthew  2112:     ## Prepare for the big loop.
1.144     matthew  2113:     my $hitcountsum;
                   2114:     my $server; 
                   2115:     my $status;
1.151     matthew  2116:     my $revise = &revise_button();
1.148     matthew  2117:     $r->print(<<END);
                   2118: <table>
1.151     matthew  2119: <tr><th>Status</th><th>Total Matches</th><th>Time Remaining</th><th></th></tr>
1.148     matthew  2120: <tr>
1.150     matthew  2121: <td><input type="text" name="status"  value="" size="30" /></td>
                   2122: <td><input type="text" name="count"   value="" size="10" /></td>
                   2123: <td><input type="text" name="seconds" value="" size="8" /></td>
1.151     matthew  2124: <td>$revise</td>
1.148     matthew  2125: </tr>
                   2126: </table>
                   2127: </form>
                   2128: END
                   2129:     $r->rflush();
1.214     matthew  2130:     &reset_timing();
                   2131:     &update_seconds($r);
                   2132:     &update_status($r,&mt('contacting [_1]',$Servers_to_contact[0]));
                   2133:     while (&time_left() &&
1.144     matthew  2134:            ((@Servers_to_contact) || keys(%Server_status))) {
1.214     matthew  2135:         &update_seconds($r);
                   2136:         #
                   2137:         # Send out a search request
1.144     matthew  2138:         if (@Servers_to_contact) {
                   2139:             # Contact one server
                   2140:             my $server = shift(@Servers_to_contact);
1.214     matthew  2141:             &update_status($r,&mt('contacting [_1]',$server));
1.144     matthew  2142:             my $reply=&Apache::lonnet::metadata_query($query,$customquery,
                   2143:                                                       $customshow,[$server]);
                   2144:             ($server) = keys(%$reply);
                   2145:             $Server_status{$server} = $reply->{$server};
                   2146:         } else {
1.150     matthew  2147:             # wait a sec. to give time for files to be written
                   2148:             # This sleep statement is here instead of outside the else 
                   2149:             # block because we do not want to pause if we have servers
                   2150:             # left to contact.  
1.183     matthew  2151:             if (scalar (keys(%Server_status))) {
                   2152:                 &update_status($r,
1.214     matthew  2153:                        &mt('waiting on [_1]',join(' ',keys(%Server_status))));
1.183     matthew  2154:             }
1.150     matthew  2155:             sleep(1)1.144     matthew  2156:         }
1.159     matthew  2157:         #
                   2158:         # Loop through the servers we have contacted but do not
                   2159:         # have results from yet, looking for results.
1.144     matthew  2160:         while (my ($server,$status) = each(%Server_status)) {
1.150     matthew  2161:             last if ($connection->aborted());
1.214     matthew  2162:             &update_seconds($r);
1.144     matthew  2163:             if ($status eq 'con_lost') {
                   2164:                 delete ($Server_status{$server});
                   2165:                 next;
                   2166:             }
                   2167:             $status=~/^([\.\w]+)$/; 
                   2168:        	    my $datafile=$r->dir_config('lonDaemons').'/tmp/'.$1;
                   2169:             if (-e $datafile && ! -e "$datafile.end") {
1.214     matthew  2170:                 &update_status($r,&mt('Receiving results from [_1]',$server));
1.144     matthew  2171:                 next;
                   2172:             }
1.150     matthew  2173:             last if ($connection->aborted());
1.144     matthew  2174:             if (-e "$datafile.end") {
1.214     matthew  2175:                 &update_status($r,&mt('Reading results from [_1]',$server));
1.144     matthew  2176:                 if (-z "$datafile") {
                   2177:                     delete($Server_status{$server});
                   2178:                     next;
                   2179:                 }
                   2180:                 my $fh;
                   2181:                 if (!($fh=Apache::File->new($datafile))) { 
1.146     matthew  2182:                     $r->print("Unable to open search results file for ".
1.145     matthew  2183:                                   "server $server.  Omitting from search");
1.150     matthew  2184:                     delete($Server_status{$server}); 
                   2185:                    next;
1.144     matthew  2186:                 }
                   2187:                 # Read in the whole file.
                   2188:                 while (my $result = <$fh>) {
1.150     matthew  2189:                     last if ($connection->aborted());
1.214     matthew  2190:                     #
                   2191:                     # Records are stored one per line
1.144     matthew  2192:                     chomp($result);
1.214     matthew  2193:                     next if (! $result);
                   2194:                     #
1.144     matthew  2195:                     # Parse the result.
                   2196:                     my %Fields = &parse_raw_result($result,$server);
                   2197:                     $Fields{'hostname'} = $server;
1.214     matthew  2198:                     #
                   2199:                     # Skip based on copyright
1.144     matthew  2200:                     next if (! &copyright_check(\%Fields));
1.214     matthew  2201:                     #
1.144     matthew  2202:                     # Store the result in the mysql database
                   2203:                     my $result = &Apache::lonmysql::store_row($table,\%Fields);
                   2204:                     if (! defined($result)) {
1.146     matthew  2205:                         $r->print(&Apache::lonmysql::get_error());
1.144     matthew  2206:                     }
1.214     matthew  2207:                     #
1.144     matthew  2208:                     $hitcountsum ++;
1.214     matthew  2209:                     &update_seconds($r);
1.150     matthew  2210:                     if ($hitcountsum % 50 == 0) {
                   2211:                         &update_count_status($r,$hitcountsum);
                   2212:                     }
1.214     matthew  2213:                 }
1.144     matthew  2214:                 $fh->close();
                   2215:                 # $server is only deleted if the results file has been 
                   2216:                 # found and (successfully) opened.  This may be a bad idea.
                   2217:                 delete($Server_status{$server});
                   2218:             }
1.150     matthew  2219:             last if ($connection->aborted());
1.148     matthew  2220:             &update_count_status($r,$hitcountsum);
1.144     matthew  2221:         }
1.150     matthew  2222:         last if ($connection->aborted());
1.214     matthew  2223:         &update_seconds($r);
1.144     matthew  2224:     }
1.214     matthew  2225:     &update_status($r,&mt('Search Complete [_1]',$server));
                   2226:     &update_seconds($r);
1.204     matthew  2227:     #
1.214     matthew  2228:     &Apache::lonmysql::disconnect_from_db(); # This is unneccessary
1.204     matthew  2229:     #
1.144     matthew  2230:     # We have run out of time or run out of servers to talk to and
1.214     matthew  2231:     # results to get, so let the client know the top frame needs to be
                   2232:     # loaded from /adm/searchcat
1.146     matthew  2233:     $r->print("</body></html>");
1.153     matthew  2234:     if ($ENV{'form.catalogmode'} ne 'groupsearch') {
                   2235:         $r->print("<script>".
                   2236:                       "window.location='/adm/searchcat?".
                   2237:                       "phase=sort&".
                   2238:                       "persistent_db_id=$ENV{'form.persistent_db_id'}';".
                   2239:                   "</script>");
                   2240:     }
1.144     matthew  2241:     return;
                   2242: }
                   2243: 
                   2244: ######################################################################
                   2245: ######################################################################
1.204     matthew  2246: 
1.144     matthew  2247: =pod
                   2248: 
1.204     matthew  2249: =item &prev_next_buttons()
                   2250: 
                   2251: Returns html for the previous and next buttons on the search results page.
1.144     matthew  2252: 
                   2253: =cut
                   2254: 
                   2255: ######################################################################
                   2256: ######################################################################
1.146     matthew  2257: sub prev_next_buttons {
1.145     matthew  2258:     my ($current_min,$show,$total,$parms) = @_;
                   2259:     return '' if ($show eq 'all'); # No links if you get them all at once.
1.214     matthew  2260:     #
                   2261:     # Create links
1.145     matthew  2262:     my $prev_min = $current_min - $show;
1.151     matthew  2263:     $prev_min = 1 if $prev_min < 1;
1.214     matthew  2264:     my $prevlink = 
                   2265:         qq{<a href="/adm/searchcat?$parms&start=$prev_min&show=$show">};
                   2266:     #
1.145     matthew  2267:     my $next_min = $current_min + $show;
1.146     matthew  2268:     $next_min = $current_min if ($next_min > $total);
1.214     matthew  2269:     my $nextlink =
                   2270:         qq{<a href="/adm/searchcat?$parms&start=$next_min&show=$show">};
                   2271:     my $reloadlink = 
                   2272:         qq{<a href="/adm/searchcat?$parms&start=$current_min&$show=$show">};
                   2273:     #
                   2274:     # Determine which parameters to pass
                   2275:     my $String = '[_1]prev[_2] &nbsp; [_3]reload[_4] &nbsp; [_5]next[_6]';
                   2276:     if ($prev_min == $current_min) {
                   2277:         $String =~ s:\[_[12]\]::g;
                   2278:     }
                   2279:     if ($next_min == $current_min) {
                   2280:         $String =~ s:\[_[56]\]::g;
                   2281:     }
                   2282:     my $links = &mt($String,
                   2283:                     $prevlink,  '</a>',
                   2284:                     $reloadlink,'</a>',
                   2285:                     $nextlink,  '</a>');
1.145     matthew  2286:     return $links;
1.144     matthew  2287: }
1.204     matthew  2288: 
1.144     matthew  2289: ######################################################################
                   2290: ######################################################################
                   2291: 
                   2292: =pod
                   2293: 
1.204     matthew  2294: =item &display_results()
                   2295: 
                   2296: Prints the results out for selection and perusal.
1.144     matthew  2297: 
                   2298: =cut
                   2299: 
                   2300: ######################################################################
                   2301: ######################################################################
                   2302: sub display_results {
1.196     matthew  2303:     my ($r,$importbutton,$closebutton,$diropendb) = @_;
1.150     matthew  2304:     my $connection = $r->connection;
                   2305:     $r->print(&search_results_header($importbutton,$closebutton));
1.144     matthew  2306:     ##
                   2307:     ## Set viewing function
                   2308:     ##
                   2309:     my $viewfunction = $Views{$ENV{'form.viewselect'}};
                   2310:     if (!defined($viewfunction)) {
                   2311:         $r->print("Internal Error - Bad view selected.\n");
                   2312:         $r->rflush();
                   2313:         return;
                   2314:     }
                   2315:     ##
1.158     matthew  2316:     ## $checkbox_num is a count of the number of checkboxes output on the 
                   2317:     ## page this is used only during catalogmode=groupsearch.
                   2318:     my $checkbox_num = 0;
                   2319:     ##
1.144     matthew  2320:     ## Get the catalog controls setup
                   2321:     ##
1.146     matthew  2322:     my $action = "/adm/searchcat?phase=results";
                   2323:     ##
1.204     matthew  2324:     ## Deal with groupsearch by opening the groupsearch db file.
1.146     matthew  2325:     if ($ENV{'form.catalogmode'} eq 'groupsearch') {
                   2326:         if (! tie(%groupsearch_db,'GDBM_File',$diropendb,
1.148     matthew  2327:                   &GDBM_WRCREAT(),0640)) {
1.150     matthew  2328:             $r->print('Unable to store import results.</form></body></html>');
1.146     matthew  2329:             $r->rflush();
                   2330:             return;
                   2331:         } 
1.144     matthew  2332:     }
1.145     matthew  2333:     ##
                   2334:     ## Prepare the table for querying
1.144     matthew  2335:     my $table = $ENV{'form.table'};
1.151     matthew  2336:     return if (! &ensure_db_and_table($r,$table));
1.145     matthew  2337:     ##
                   2338:     ## Get the number of results 
                   2339:     my $total_results = &Apache::lonmysql::number_of_rows($table);
                   2340:     if (! defined($total_results)) {
1.150     matthew  2341:         $r->print("A MySQL error has occurred.</form></body></html>");
1.145     matthew  2342:         &Apache::lonnet::logthis("lonmysql was unable to determine the number".
                   2343:                                  " of rows in table ".$table);
                   2344:         &Apache::lonnet::logthis(&Apache::lonmysql::get_error());
                   2345:         return;
                   2346:     }
                   2347:     ##
                   2348:     ## Determine how many results we need to get
1.151     matthew  2349:     $ENV{'form.start'} = 1      if (! exists($ENV{'form.start'}));
                   2350:     $ENV{'form.show'}  = 'all'  if (! exists($ENV{'form.show'}));
1.146     matthew  2351:     my $min = $ENV{'form.start'};
1.145     matthew  2352:     my $max;
                   2353:     if ($ENV{'form.show'} eq 'all') {
                   2354:         $max = $total_results ;
                   2355:     } else {
1.151     matthew  2356:         $max = $min + $ENV{'form.show'} - 1;
1.146     matthew  2357:         $max = $total_results if ($max > $total_results);
1.145     matthew  2358:     }
                   2359:     ##
                   2360:     ## Output links (if necessary) for 'prev' and 'next' pages.
1.146     matthew  2361:     $r->print
1.148     matthew  2362:         ('<center>'.
1.146     matthew  2363:          &prev_next_buttons($min,$ENV{'form.show'},$total_results,
                   2364:                             "table=".$ENV{'form.table'}.
                   2365:                             "&phase=results".
                   2366:                             "&persistent_db_id=".$ENV{'form.persistent_db_id'})
1.148     matthew  2367:          ."</center>\n"
1.146     matthew  2368:          );
1.150     matthew  2369:     if ($total_results == 0) {
1.214     matthew  2370:         $r->print('<meta HTTP-EQUIV="Refresh" CONTENT="2">'.
1.187     www      2371:                   '<h3>'.&mt('There are currently no results').'.</h3>'.
1.150     matthew  2372:                   "</form></body></html>");
                   2373:         return;
                   2374:     } else {
                   2375:         $r->print
                   2376:             ("<center>Results $min to $max out of $total_results</center>\n");
                   2377:     }
1.145     matthew  2378:     ##
                   2379:     ## Get results from MySQL table
                   2380:     my @Results = &Apache::lonmysql::get_rows($table,
1.151     matthew  2381:                                               'id>='.$min.' AND id<='.$max);
1.145     matthew  2382:     ##
                   2383:     ## Loop through the results and output them.
1.144     matthew  2384:     foreach my $row (@Results) {
1.150     matthew  2385:         if ($connection->aborted()) {
1.162     www      2386:             &cleanup();
1.150     matthew  2387:             return;
                   2388:         }
1.144     matthew  2389:         my %Fields = %{&parse_row(@$row)};
1.145     matthew  2390:         my $output="<p>\n";
1.210     matthew  2391:         if (! defined($Fields{'title'}) || $Fields{'title'} eq '') {
                   2392:             $Fields{'title'} = 'Untitled';
                   2393:         }
1.158     matthew  2394:         my $prefix=&catalogmode_output($Fields{'title'},$Fields{'url'},
                   2395:                                        $Fields{'id'},$checkbox_num++);
1.144     matthew  2396:         # Render the result into html
1.150     matthew  2397:         $output.= &$viewfunction($prefix,%Fields);
1.145     matthew  2398:         # Print them out as they come in.
1.144     matthew  2399:         $r->print($output);
                   2400:         $r->rflush();
                   2401:     }
                   2402:     if (@Results < 1) {
1.187     www      2403:         $r->print(&mt("There were no results matching your query"));
1.147     matthew  2404:     } else {
                   2405:         $r->print
1.148     matthew  2406:             ('<center>'.
1.147     matthew  2407:              &prev_next_buttons($min,$ENV{'form.show'},$total_results,
                   2408:                                 "table=".$ENV{'form.table'}.
                   2409:                                 "&phase=results".
                   2410:                                 "&persistent_db_id=".
                   2411:                                 $ENV{'form.persistent_db_id'})
1.148     matthew  2412:              ."</center>\n"
1.147     matthew  2413:              );
1.144     matthew  2414:     }
1.150     matthew  2415:     $r->print("</form></body></html>");
1.144     matthew  2416:     $r->rflush();
1.150     matthew  2417:     untie %groupsearch_db if (tied(%groupsearch_db));
1.144     matthew  2418:     return;
                   2419: }
                   2420: 
                   2421: ######################################################################
                   2422: ######################################################################
                   2423: 
                   2424: =pod
                   2425: 
1.158     matthew  2426: =item &catalogmode_output($title,$url,$fnum,$checkbox_num)
1.145     matthew  2427: 
                   2428: Returns html needed for the various catalog modes.  Gets inputs from
1.158     matthew  2429: $ENV{'form.catalogmode'}.  Stores data in %groupsearch_db.
1.145     matthew  2430: 
                   2431: =cut
                   2432: 
                   2433: ######################################################################
                   2434: ######################################################################
                   2435: sub catalogmode_output {
                   2436:     my $output = '';
1.158     matthew  2437:     my ($title,$url,$fnum,$checkbox_num) = @_;
1.145     matthew  2438:     if ($ENV{'form.catalogmode'} eq 'interactive') {
1.150     matthew  2439:         $title=~ s/\'/\\\'/g;
1.145     matthew  2440:         if ($ENV{'form.catalogmode'} eq 'interactive') {
                   2441:             $output.=<<END 
                   2442: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
                   2443: onClick="javascript:select_data('$title','$url')">
                   2444: </font>
                   2445: END
                   2446:         }
1.150     matthew  2447:     } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.145     matthew  2448:         $groupsearch_db{"pre_${fnum}_link"}=$url;
                   2449:         $groupsearch_db{"pre_${fnum}_title"}=$title;
                   2450:         $output.=<<END;
                   2451: <font size='-1'>
                   2452: <input type="checkbox" name="returnvalues" value="SELECT"
1.158     matthew  2453: onClick="javascript:queue($checkbox_num,$fnum)" />
1.145     matthew  2454: </font>
                   2455: END
                   2456:     }
                   2457:     return $output;
                   2458: }
                   2459: ######################################################################
                   2460: ######################################################################
                   2461: 
                   2462: =pod
                   2463: 
1.204     matthew  2464: =item &parse_row()
1.144     matthew  2465: 
                   2466: Parse a row returned from the database.
                   2467: 
                   2468: =cut
                   2469: 
                   2470: ######################################################################
                   2471: ######################################################################
                   2472: sub parse_row {
                   2473:     my @Row = @_;
                   2474:     my %Fields;
1.204     matthew  2475:     if (! scalar(@Datatypes)) {
                   2476:         &set_up_table_structure();
                   2477:     }
1.144     matthew  2478:     for (my $i=0;$i<=$#Row;$i++) {
1.170     matthew  2479:         $Fields{$Datatypes[$i]->{'name'}}=&Apache::lonnet::unescape($Row[$i]);
1.144     matthew  2480:     }
                   2481:     $Fields{'language'} = 
1.198     www      2482:         &Apache::loncommon::languagedescription($Fields{'language'});
1.144     matthew  2483:     $Fields{'copyrighttag'} =
                   2484:         &Apache::loncommon::copyrightdescription($Fields{'copyright'});
                   2485:     $Fields{'mimetag'} =
                   2486:         &Apache::loncommon::filedescription($Fields{'mime'});
                   2487:     return \%Fields;
                   2488: }
1.126     matthew  2489: 
                   2490: ###########################################################
                   2491: ###########################################################
                   2492: 
                   2493: =pod
                   2494: 
                   2495: =item &parse_raw_result()
                   2496: 
                   2497: Takes a line from the file of results and parse it.  Returns a hash 
1.198     www      2498: with keys according to column labels
1.126     matthew  2499: 
                   2500: In addition, the following tags are set by calling the appropriate 
1.198     www      2501: lonnet function: 'language', 'copyrighttag', 'mimetag'.
1.126     matthew  2502: 
                   2503: The 'title' field is set to "Untitled" if the title field is blank.
                   2504: 
                   2505: 'abstract' and 'keywords' are truncated to 200 characters.
                   2506: 
                   2507: =cut
                   2508: 
                   2509: ###########################################################
                   2510: ###########################################################
                   2511: sub parse_raw_result {
                   2512:     my ($result,$hostname) = @_;
1.204     matthew  2513:     # conclude from self to others regarding fields
1.206     matthew  2514:     my %Fields=&LONCAPA::lonmetadata::metadata_col_to_hash
                   2515:         (map {
                   2516:             &Apache::lonnet::unescape($_);
                   2517:         } (split(/\,/,$result)) );
1.126     matthew  2518:     return %Fields;
                   2519: }
                   2520: 
                   2521: ###########################################################
                   2522: ###########################################################
                   2523: 
                   2524: =pod
                   2525: 
                   2526: =item &handle_custom_fields()
                   2527: 
                   2528: =cut
                   2529: 
                   2530: ###########################################################
                   2531: ###########################################################
                   2532: sub handle_custom_fields {
                   2533:     my @results = @{shift()};
                   2534:     my $customshow='';
                   2535:     my $extrashow='';
                   2536:     my @customfields;
                   2537:     if ($ENV{'form.customshow'}) {
                   2538:         $customshow=$ENV{'form.customshow'};
                   2539:         $customshow=~s/[^\w\s]//g;
                   2540:         my @fields=map {
                   2541:             "<font color=\"#008000\">$_:</font><!-- $_ -->";
                   2542:         } split(/\s+/,$customshow);
                   2543:         @customfields=split(/\s+/,$customshow);
                   2544:         if ($customshow) {
                   2545:             $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
                   2546:         }
                   2547:     }
                   2548:     my $customdata='';
                   2549:     my %customhash;
                   2550:     foreach my $result (@results) {
                   2551:         if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
                   2552:             my $tmp=$result;
                   2553:             $tmp=~s/^custom\=//;
                   2554:             my ($k,$v)=map {&Apache::lonnet::unescape($_);
                   2555:                         } split(/\,/,$tmp);
                   2556:             $customhash{$k}=$v;
                   2557:         }
                   2558:     }
                   2559:     return ($extrashow,\@customfields,\%customhash);
1.41      harris41 2560: }
                   2561: 
1.122     matthew  2562: ######################################################################
                   2563: ######################################################################
                   2564: 
1.125     matthew  2565: =pod
                   2566: 
1.204     matthew  2567: =item &search_results_header()
1.125     matthew  2568: 
1.130     matthew  2569: Output the proper html headers and javascript code to deal with different 
                   2570: calling modes.
                   2571: 
                   2572: Takes most inputs directly from %ENV, except $mode.  
                   2573: 
                   2574: =over 4
                   2575: 
                   2576: =item $mode is either (at this writing) 'Basic' or 'Advanced'
                   2577: 
                   2578: =back
1.126     matthew  2579: 
1.130     matthew  2580: The following environment variables are checked:
1.126     matthew  2581: 
                   2582: =over 4
                   2583: 
                   2584: =item 'form.catalogmode' 
                   2585: 
                   2586: Checked for 'interactive' and 'groupsearch'.
                   2587: 
                   2588: =item 'form.mode'
                   2589: 
                   2590: Checked for existance & 'edit' mode.
                   2591: 
                   2592: =item 'form.form'
                   2593: 
1.191     albertel 2594: Contains the name of the form that has the input fields to set
                   2595: 
1.126     matthew  2596: =item 'form.element'
                   2597: 
1.191     albertel 2598: the name of the input field to put the URL into
                   2599: 
                   2600: =item 'form.titleelement'
                   2601: 
                   2602: the name of the input field to put the title into
                   2603: 
1.126     matthew  2604: =back
                   2605: 
1.125     matthew  2606: =cut
                   2607: 
                   2608: ######################################################################
                   2609: ######################################################################
                   2610: sub search_results_header {
1.150     matthew  2611:     my ($importbutton,$closebutton) = @_;
1.196     matthew  2612:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.125     matthew  2613:     my $result = '';
                   2614:     # output beginning of search page
                   2615:     # conditional output of script functions dependent on the mode in
                   2616:     # which the search was invoked
                   2617:     if ($ENV{'form.catalogmode'} eq 'interactive'){
                   2618: 	if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
                   2619:             $result.=<<SCRIPT;
                   2620: <script type="text/javascript">
                   2621:     function select_data(title,url) {
                   2622: 	changeTitle(title);
                   2623: 	changeURL(url);
1.150     matthew  2624: 	parent.close();
1.125     matthew  2625:     }
                   2626:     function changeTitle(val) {
1.153     matthew  2627: 	if (parent.opener.inf.document.forms.resinfo.elements.t) {
                   2628: 	    parent.opener.inf.document.forms.resinfo.elements.t.value=val;
1.125     matthew  2629: 	}
                   2630:     }
                   2631:     function changeURL(val) {
1.153     matthew  2632: 	if (parent.opener.inf.document.forms.resinfo.elements.u) {
                   2633: 	    parent.opener.inf.document.forms.resinfo.elements.u.value=val;
1.125     matthew  2634: 	}
                   2635:     }
                   2636: </script>
                   2637: SCRIPT
                   2638:         } elsif ($ENV{'form.mode'} eq 'edit') {
                   2639:             my $form = $ENV{'form.form'};
                   2640:             my $element = $ENV{'form.element'};
1.191     albertel 2641:             my $titleelement = $ENV{'form.titleelement'};
                   2642: 	    my $changetitle;
                   2643: 	    if (!$titleelement) {
                   2644: 		$changetitle='function changeTitle(val) {}';
                   2645: 	    } else {
                   2646: 		    $changetitle=<<END;
                   2647: function changeTitle(val) {
                   2648:     if (parent.targetwin.document) {
                   2649:         parent.targetwin.document.forms["$form"].elements["$titleelement"].value=val;
                   2650:     } else {
                   2651: 	var url = 'forms[\"$form\"].elements[\"$titleelement\"].value';
                   2652:         alert("Unable to transfer data to "+url);
                   2653:     }
                   2654: }
                   2655: END
                   2656:             }
                   2657: 
1.125     matthew  2658:             $result.=<<SCRIPT;
                   2659: <script type="text/javascript">
                   2660: function select_data(title,url) {
                   2661:     changeURL(url);
1.191     albertel 2662:     changeTitle(title);
1.150     matthew  2663:     parent.close();
1.125     matthew  2664: }
1.191     albertel 2665: $changetitle
1.125     matthew  2666: function changeURL(val) {
1.150     matthew  2667:     if (parent.targetwin.document) {
                   2668:         parent.targetwin.document.forms["$form"].elements["$element"].value=val;
1.125     matthew  2669:     } else {
                   2670: 	var url = 'forms[\"$form\"].elements[\"$element\"].value';
                   2671:         alert("Unable to transfer data to "+url);
                   2672:     }
                   2673: }
                   2674: </script>
                   2675: SCRIPT
                   2676:         }
                   2677:     }
                   2678:     $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
                   2679: <script type="text/javascript">
1.158     matthew  2680:     function queue(checkbox_num,val) {
1.185     matthew  2681:         if (document.forms.results.returnvalues.length != "undefined" &&
                   2682:             typeof(document.forms.results.returnvalues.length) == "number") {
                   2683:             if (document.forms.results.returnvalues[checkbox_num].checked) {
                   2684:                 parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
                   2685:             } else {
                   2686:                 parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
                   2687:             }
1.150     matthew  2688:         } else {
1.185     matthew  2689:             if (document.forms.results.returnvalues.checked) {
                   2690:                 parent.statusframe.document.forms.statusform.elements.Queue.value +='1a'+val+'b';
                   2691:             } else {
                   2692:                 parent.statusframe.document.forms.statusform.elements.Queue.value +='0a'+val+'b';
                   2693:             }
1.150     matthew  2694:         }
1.125     matthew  2695:     }
                   2696:     function select_group() {
1.150     matthew  2697: 	parent.window.location=
1.125     matthew  2698:     "/adm/groupsort?mode=$ENV{'form.mode'}&catalogmode=groupsearch&acts="+
1.150     matthew  2699: 	    parent.statusframe.document.forms.statusform.elements.Queue.value;
1.125     matthew  2700:     }
                   2701: </script>
                   2702: SCRIPT
1.130     matthew  2703:     $result.=<<END;
                   2704: </head>
1.155     matthew  2705: $bodytag
1.150     matthew  2706: <form name="results" method="post" action="" >
                   2707: <input type="hidden" name="Queue" value="" />
                   2708: $importbutton
1.130     matthew  2709: END
1.125     matthew  2710:     return $result;
                   2711: }
                   2712: 
                   2713: ######################################################################
                   2714: ######################################################################
1.146     matthew  2715: sub search_status_header {
1.196     matthew  2716:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.146     matthew  2717:     return <<ENDSTATUS;
                   2718: <html><head><title>Search Status</title></head>
1.155     matthew  2719: $bodytag
1.146     matthew  2720: <h3>Search Status</h3>
                   2721: Sending search request to LON-CAPA servers.<br />
                   2722: ENDSTATUS
                   2723: }
                   2724: 
1.150     matthew  2725: sub results_link {
                   2726:     my $basic_link   = "/adm/searchcat?"."&table=".$ENV{'form.table'}.
                   2727:         "&persistent_db_id=".$ENV{'form.persistent_db_id'};
                   2728:     my $results_link = $basic_link."&phase=results".
1.151     matthew  2729:         "&pause=1"."&start=1";
1.150     matthew  2730:     return $results_link;
                   2731: }
                   2732: 
1.146     matthew  2733: ######################################################################
                   2734: ######################################################################
                   2735: sub print_frames_interface {
                   2736:     my $r = shift;
                   2737:     my $basic_link = "/adm/searchcat?"."&table=".$ENV{'form.table'}.
                   2738:         "&persistent_db_id=".$ENV{'form.persistent_db_id'};
                   2739:     my $run_search_link = $basic_link."&phase=run_search";
1.150     matthew  2740:     my $results_link = &results_link();
1.146     matthew  2741:     my $result = <<"ENDFRAMES";
                   2742: <html>
                   2743: <head>
1.150     matthew  2744: <script>
                   2745: var targetwin = opener;
1.158     matthew  2746: var queue = '';
1.150     matthew  2747: </script>
1.146     matthew  2748: <title>LON-CAPA Digital Library Search Results</title>
                   2749: </head>
1.176     www      2750: <frameset rows="150,*">
1.146     matthew  2751:     <frame name="statusframe"  src="$run_search_link">
                   2752:     <frame name="resultsframe" src="$results_link">
                   2753: </frameset>
                   2754: </html>
                   2755: ENDFRAMES
                   2756: 
                   2757:     $r->print($result);
                   2758:     return;
                   2759: }
                   2760: 
                   2761: ######################################################################
                   2762: ######################################################################
1.125     matthew  2763: 
1.122     matthew  2764: =pod 
                   2765: 
                   2766: =item Metadata Viewing Functions
                   2767: 
                   2768: Output is a HTML-ified string.
1.204     matthew  2769: 
1.122     matthew  2770: Input arguments are title, author, subject, url, keywords, version,
                   2771: notes, short abstract, mime, language, creation date,
1.126     matthew  2772: last revision date, owner, copyright, hostname, and
1.122     matthew  2773: extra custom metadata to show.
                   2774: 
                   2775: =over 4
                   2776: 
                   2777: =item &detailed_citation_view() 
                   2778: 
                   2779: =cut
                   2780: 
                   2781: ######################################################################
                   2782: ######################################################################
1.50      harris41 2783: sub detailed_citation_view {
1.150     matthew  2784:     my ($prefix,%values) = @_;
1.218   ! matthew  2785:     my $icon=
        !          2786:     my $result;
        !          2787:     $result .= '<b>'.$prefix.
        !          2788:         '<img src="'.&Apache::loncommon::icon($values{'url'}).' " />'.
        !          2789:         '<a href="http://'.$ENV{'HTTP_HOST'}.$values{'url'}.'" '.
        !          2790:         'target="search_preview">'.$values{'title'}."</a></b>\n";
        !          2791:     $result .= "<p>\n";
        !          2792:     $result .= '<b>'.$values{'author'}.'</b>,'.
        !          2793:         ' <i>'.$values{'owner'}.'</i><br />';
        !          2794:     foreach my $field 
        !          2795:         (
        !          2796:          { name=>'subject',
        !          2797:            translate => '<b>Subject:</b>&nbsp;[_1]',},
        !          2798:          { name=>'keywords',
        !          2799:            translate => '<b>Keywords:</b>&nbsp;[_1]',},
        !          2800:          { name=>'notes',
        !          2801:            translate => '<b>Notes:</b>&nbsp;[_1]',},
        !          2802:          { name=>'mimetag',
        !          2803:            translate => '<b>MIME Type:</b>&nbsp;[_1]',},
        !          2804:          { name=>'standards',
        !          2805:            translate => '<b>Standards:</b>[_1]',},
        !          2806:          { name=>'copyrighttag',
        !          2807:            translate => '<b>Copyright/Distribution:</b>&nbsp;[_1]',},
        !          2808:          { name=>'stdno',
        !          2809:            translate => '<b>Number of Students:</b>&nbsp;[_1]',},
        !          2810:          { name=>'avetries',
        !          2811:            translate => '<b>Average Tries:</b>&nbsp;[_1]',},
        !          2812:          { name=>'disc',
        !          2813:            translate => '<b>Degree of Discrimination:</b>&nbsp;[_1]',},
        !          2814:          { name=>'difficulty',
        !          2815:            translate => '<b>Degree of Difficulty:</b>&nbsp;[_1]',},
        !          2816:          { name=>'clear',
        !          2817:            translate => '<b>Clear:</b>&nbsp;[_1]',},
        !          2818:          { name=>'depth',
        !          2819:            translate => '<b>Depth:</b>&nbsp;[_1]',},
        !          2820:          { name=>'helpful',
        !          2821:            translate => '<b>Helpful:</b>&nbsp;[_1]',},
        !          2822:          { name=>'correct',
        !          2823:            translate => '<b>Correcy:</b>&nbsp;[_1]',},
        !          2824:          { name=>'technical',
        !          2825:            translate => '<b>Technical:</b>&nbsp;[_1]',},
        !          2826:          ) {
        !          2827:         $result.= &mt($field->{'translate'},$values{$field->{'name'}}).
        !          2828:             "<br />\n";
        !          2829:     }
        !          2830:     $result .= "</p>".$values{'extrashow'}.
        !          2831:         '<p>'.$values{'shortabstract'}.'</p>';
        !          2832:     $result .= '<hr align="left" width="200" noshade />'."\n";
1.50      harris41 2833:     return $result;
                   2834: }
                   2835: 
1.122     matthew  2836: ######################################################################
                   2837: ######################################################################
                   2838: 
                   2839: =pod 
                   2840: 
                   2841: =item &summary_view() 
                   2842: 
                   2843: =cut
                   2844: ######################################################################
                   2845: ######################################################################
1.50      harris41 2846: sub summary_view {
1.150     matthew  2847:     my ($prefix,%values) = @_;
1.192     albertel 2848:     my $icon=&Apache::loncommon::icon($values{'url'});
1.50      harris41 2849:     my $result=<<END;
1.192     albertel 2850: $prefix<img src="$icon" /><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
1.126     matthew  2851:    target='search_preview'>$values{'author'}</a><br />
                   2852: $values{'title'}<br />
                   2853: $values{'owner'} -- $values{'lastrevisiondate'}<br />
                   2854: $values{'copyrighttag'}<br />
                   2855: $values{'extrashow'}
1.50      harris41 2856: </p>
1.150     matthew  2857: <hr align='left' width='200' noshade />
1.50      harris41 2858: END
                   2859:     return $result;
                   2860: }
                   2861: 
1.122     matthew  2862: ######################################################################
                   2863: ######################################################################
                   2864: 
                   2865: =pod 
                   2866: 
1.150     matthew  2867: =item &compact_view() 
                   2868: 
                   2869: =cut
                   2870: 
                   2871: ######################################################################
                   2872: ######################################################################
                   2873: sub compact_view {
                   2874:     my ($prefix,%values) = @_;
1.192     albertel 2875:     my $icon=&Apache::loncommon::icon($values{'url'});
1.150     matthew  2876:     my $result=<<END;
1.192     albertel 2877: $prefix <img src="$icon" /> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}"  target='search_preview'>
1.150     matthew  2878: $values{'title'}</a>
                   2879: <b>$values{'author'}</b><br />
                   2880: END
                   2881:     return $result;
                   2882: }
                   2883: 
                   2884: 
                   2885: ######################################################################
                   2886: ######################################################################
                   2887: 
                   2888: =pod 
                   2889: 
1.122     matthew  2890: =item &fielded_format_view() 
                   2891: 
                   2892: =cut
                   2893: 
                   2894: ######################################################################
                   2895: ######################################################################
1.50      harris41 2896: sub fielded_format_view {
1.150     matthew  2897:     my ($prefix,%values) = @_;
1.192     albertel 2898:     my $icon=&Apache::loncommon::icon($values{'url'});
1.50      harris41 2899:     my $result=<<END;
1.192     albertel 2900: $prefix <img src="$icon" />
1.126     matthew  2901: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
                   2902:               target='search_preview'>$values{'url'}</a>
1.56      harris41 2903: <br />
1.126     matthew  2904: <b>Title:</b> $values{'title'}<br />
                   2905: <b>Author(s):</b> $values{'author'}<br />
                   2906: <b>Subject:</b> $values{'subject'}<br />
                   2907: <b>Keyword(s):</b> $values{'keywords'}<br />
                   2908: <b>Notes:</b> $values{'notes'}<br />
                   2909: <b>MIME Type:</b> $values{'mimetag'}<br />
                   2910: <b>Language:</b> $values{'language'}<br />
                   2911: <b>Creation Date:</b> $values{'creationdate'}<br />
                   2912: <b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
                   2913: <b>Publisher/Owner:</b> $values{'owner'}<br />
                   2914: <b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
                   2915: <b>Repository Location:</b> $values{'hostname'}<br />
                   2916: <b>Abstract:</b> $values{'shortabstract'}<br />
                   2917: $values{'extrashow'}
1.50      harris41 2918: </p>
1.150     matthew  2919: <hr align='left' width='200' noshade />
1.50      harris41 2920: END
                   2921:     return $result;
                   2922: }
                   2923: 
1.122     matthew  2924: ######################################################################
                   2925: ######################################################################
                   2926: 
                   2927: =pod 
                   2928: 
                   2929: =item &xml_sgml_view() 
                   2930: 
                   2931: =back 
                   2932: 
                   2933: =cut
                   2934: 
                   2935: ######################################################################
                   2936: ######################################################################
1.50      harris41 2937: sub xml_sgml_view {
1.150     matthew  2938:     my ($prefix,%values) = @_;
1.212     matthew  2939:     my $xml = <<END;
                   2940: <LonCapaResource>
                   2941: <url>$values{'url'}</url>
                   2942: <title>$values{'title'}</title>
                   2943: <author>$values{'author'}</author>
                   2944: <subject>$values{'subject'}</subject>
                   2945: <keywords>$values{'keywords'}</keywords>
                   2946: <notes>$values{'notes'}</notes>
                   2947: <mimeInfo>
                   2948: <mime>$values{'mime'}</mime>
                   2949: <mimetag>$values{'mimetag'}</mimetag>
                   2950: </mimeInfo>
                   2951: <languageInfo>
                   2952: <language>$values{'language'}</language>
                   2953: <languagetag>$values{'languagetag'}</languagetag>
                   2954: </languageInfo>
                   2955: <creationdate>$values{'creationdate'}</creationdate>
                   2956: <lastrevisiondate>$values{'lastrevisiondate'}</lastrevisiondate>
                   2957: <owner>$values{'owner'}</owner>
                   2958: <copyrightInfo>
                   2959: <copyright>$values{'copyright'}</copyright>
                   2960: <copyrighttag>$values{'copyrighttag'}</copyrighttag>
                   2961: </copyrightInfo>
                   2962: <repositoryLocation>$values{'hostname'}</repositoryLocation>
                   2963: <shortabstract>$values{'shortabstract'}</shortabstract>
                   2964: </LonCapaResource>
                   2965: END
                   2966:     $xml = &HTML::Entities::encode($xml,'<>&');
1.50      harris41 2967:     my $result=<<END;
1.150     matthew  2968: $prefix
1.56      harris41 2969: <pre>
1.212     matthew  2970: $xml
1.56      harris41 2971: </pre>
1.126     matthew  2972: $values{'extrashow'}
1.150     matthew  2973: <hr align='left' width='200' noshade />
1.50      harris41 2974: END
                   2975:     return $result;
1.60      harris41 2976: }
                   2977: 
1.122     matthew  2978: ######################################################################
                   2979: ######################################################################
                   2980: 
                   2981: =pod 
                   2982: 
                   2983: =item &filled() see if field is filled.
                   2984: 
                   2985: =cut
                   2986: 
                   2987: ######################################################################
                   2988: ######################################################################
1.98      harris41 2989: sub filled {
                   2990:     my ($field)=@_;
                   2991:     if ($field=~/\S/ && $field ne 'any') {
1.204     matthew  2992:         return 1;
                   2993:     } else {
                   2994:         return 0;
1.61      harris41 2995:     }
1.60      harris41 2996: }
                   2997: 
1.122     matthew  2998: ######################################################################
                   2999: ######################################################################
                   3000: 
                   3001: =pod 
                   3002: 
                   3003: =item &output_blank_field_error()
                   3004: 
1.151     matthew  3005: Output a complete page that indicates the user has not filled in enough
                   3006: information to do a search.
                   3007: 
                   3008: Inputs: $r (Apache request handle), $closebutton, $parms.
                   3009: 
                   3010: Returns: nothing
                   3011: 
                   3012: $parms is extra information to include in the 'Revise search request' link.
                   3013: 
1.122     matthew  3014: =cut
                   3015: 
                   3016: ######################################################################
                   3017: ######################################################################
1.98      harris41 3018: sub output_blank_field_error {
1.196     matthew  3019:     my ($r,$closebutton,$parms,$hidden_fields)=@_;
                   3020:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.98      harris41 3021:     # make query information persistent to allow for subsequent revision
                   3022:     $r->print(<<BEGINNING);
                   3023: <html>
                   3024: <head>
                   3025: <title>The LearningOnline Network with CAPA</title>
                   3026: BEGINNING
                   3027:     $r->print(<<RESULTS);
                   3028: </head>
1.155     matthew  3029: $bodytag
1.98      harris41 3030: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
                   3031: <h1>Search Catalog</h1>
                   3032: <form method="post" action="/adm/searchcat">
1.145     matthew  3033: $hidden_fields
1.151     matthew  3034: <a href="/adm/searchcat?$parms&persistent_db_id=$ENV{'form.persistent_db_id'}"
1.146     matthew  3035: >Revise search request</a>&nbsp;
1.98      harris41 3036: $closebutton
                   3037: <hr />
1.151     matthew  3038: <h3>Unactionable search query.</h3>
1.98      harris41 3039: <p>
1.151     matthew  3040: You did not fill in enough information for the search to be started.
                   3041: You need to fill in relevant fields on the search page in order 
                   3042: for a query to be processed.
1.98      harris41 3043: </p>
                   3044: </body>
                   3045: </html>
                   3046: RESULTS
                   3047: }
                   3048: 
1.122     matthew  3049: ######################################################################
                   3050: ######################################################################
                   3051: 
                   3052: =pod 
                   3053: 
                   3054: =item &output_date_error()
                   3055: 
                   3056: Output a full html page with an error message.
                   3057: 
1.145     matthew  3058: Inputs: 
                   3059: 
                   3060:     $r, the request pointer.
                   3061:     $message, the error message for the user.
                   3062:     $closebutton, the specialized close button needed for groupsearch.
                   3063: 
1.122     matthew  3064: =cut
                   3065: 
                   3066: ######################################################################
                   3067: ######################################################################
1.60      harris41 3068: sub output_date_error {
1.196     matthew  3069:     my ($r,$message,$closebutton,$hidden_fields)=@_;
1.60      harris41 3070:     # make query information persistent to allow for subsequent revision
1.196     matthew  3071:     my $bodytag=&Apache::loncommon::bodytag(undef,undef,undef,1);
1.122     matthew  3072:     $r->print(<<RESULTS);
1.60      harris41 3073: <html>
                   3074: <head>
                   3075: <title>The LearningOnline Network with CAPA</title>
                   3076: </head>
1.155     matthew  3077: $bodytag
1.98      harris41 3078: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60      harris41 3079: <h1>Search Catalog</h1>
                   3080: <form method="post" action="/adm/searchcat">
1.145     matthew  3081: $hidden_fields
1.60      harris41 3082: <input type='button' value='Revise search request'
1.98      harris41 3083: onClick='this.form.submit();' />
1.60      harris41 3084: $closebutton
1.98      harris41 3085: <hr />
1.151     matthew  3086: <h3>Error</h3>
1.60      harris41 3087: <p>
                   3088: $message
                   3089: </p>
                   3090: </body>
                   3091: </html>
                   3092: RESULTS
1.101     harris41 3093: }
                   3094: 
1.122     matthew  3095: ######################################################################
                   3096: ######################################################################
                   3097: 
                   3098: =pod 
                   3099: 
                   3100: =item &start_fresh_session()
                   3101: 
1.142     matthew  3102: Cleans the global %groupsearch_db by removing all fields which begin with
1.122     matthew  3103: 'pre_' or 'store'.
                   3104: 
                   3105: =cut
                   3106: 
                   3107: ######################################################################
                   3108: ######################################################################
1.101     harris41 3109: sub start_fresh_session {
1.142     matthew  3110:     delete $groupsearch_db{'mode_catalog'};
                   3111:     foreach (keys %groupsearch_db) {
1.101     harris41 3112:         if ($_ =~ /^pre_/) {
1.142     matthew  3113:             delete $groupsearch_db{$_};
1.101     harris41 3114:         }
                   3115:         if ($_ =~ /^store/) {
1.142     matthew  3116: 	    delete $groupsearch_db{$_};
1.101     harris41 3117: 	}
1.109     harris41 3118:     }
1.3       harris41 3119: }
1.1       www      3120: 
                   3121: 1;
1.162     www      3122: 
                   3123: sub cleanup {
1.163     www      3124:     if (tied(%groupsearch_db)) {
                   3125:         unless (untie(%groupsearch_db)) {
                   3126: 	  &Apache::lonnet::logthis('Failed cleanup searchcat: groupsearch_db');
                   3127:         }
                   3128:     }
1.167     www      3129:     &untiehash();
1.162     www      3130:     &Apache::lonmysql::disconnect_from_db();
                   3131: }
1.98      harris41 3132: 
1.1       www      3133: __END__
1.105     harris41 3134: 
1.121     matthew  3135: =pod
1.105     harris41 3136: 
1.121     matthew  3137: =back 
1.105     harris41 3138: 
                   3139: =cut

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>