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

1.98      harris41    1: # The LearningOnline Network with CAPA
1.108     harris41    2: # Search Catalog
                      3: #
1.142   ! matthew     4: # $Id: lonsearchcat.pm,v 1.141 2002/07/12 14:36:16 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.97      harris41   28: # YEAR=2001
1.104     harris41   29: # 3/8, 3/12, 3/13, 3/14, 3/15, 3/19 Scott Harrison
                     30: # 3/20, 3/21, 3/22, 3/26, 3/27, 4/2, 8/15, 8/24, 8/25 Scott Harrison
1.113     harris41   31: # 10/12,10/14,10/15,10/16,11/28,11/29,12/10,12/12,12/16 Scott Harrison
1.115     harris41   32: # YEAR=2002
                     33: # 1/17 Scott Harrison
1.121     matthew    34: # 6/17 Matthew Hall
1.104     harris41   35: #
1.121     matthew    36: ###############################################################################
                     37: ###############################################################################
                     38: 
                     39: =pod 
                     40: 
                     41: =head1 NAME
                     42: 
1.140     matthew    43: lonsearchcat - LONCAPA Search Interface
1.121     matthew    44: 
                     45: =head1 SYNOPSIS
                     46: 
                     47: Search interface to LON-CAPAs digital library
                     48: 
                     49: =head1 DESCRIPTION
                     50: 
                     51: This module enables searching for a distributed browseable catalog.
1.104     harris41   52: 
1.121     matthew    53: This is part of the LearningOnline Network with CAPA project
                     54: described at http://www.lon-capa.org.
                     55: 
                     56: lonsearchcat presents the user with an interface to search the LON-CAPA
                     57: digital library.  lonsearchcat also initiates the execution of a search
                     58: by sending the search parameters to LON-CAPA servers.  The progress of 
                     59: search (on a server basis) is displayed to the user in a seperate window.
                     60: 
                     61: =head1 Internals
                     62: 
                     63: =over 4
                     64: 
                     65: =cut
                     66: 
                     67: ###############################################################################
1.98      harris41   68: ###############################################################################
1.121     matthew    69: 
1.128     harris41   70: ###############################################################################
1.98      harris41   71: ##                                                                           ##
                     72: ## ORGANIZATION OF THIS PERL MODULE                                          ##
                     73: ##                                                                           ##
1.105     harris41   74: ## 1. Modules used by this module                                            ##
1.128     harris41   75: ## 2. Variables used throughout the module                                   ##
                     76: ## 3. handler subroutine called via Apache and mod_perl                      ##
                     77: ## 4. Other subroutines                                                      ##
1.98      harris41   78: ##                                                                           ##
                     79: ###############################################################################
                     80: 
1.1       www        81: package Apache::lonsearchcat;
                     82: 
1.98      harris41   83: # ------------------------------------------------- modules used by this module
1.1       www        84: use strict;
                     85: use Apache::Constants qw(:common);
1.6       harris41   86: use Apache::lonnet();
                     87: use Apache::File();
1.7       harris41   88: use CGI qw(:standard);
1.41      harris41   89: use Text::Query;
1.101     harris41   90: use GDBM_File;
1.112     harris41   91: use Apache::loncommon();
1.1       www        92: 
1.90      harris41   93: # ---------------------------------------- variables used throughout the module
                     94: 
1.121     matthew    95: ######################################################################
                     96: ######################################################################
                     97: 
                     98: =pod 
                     99: 
                    100: =item Global variables
                    101: 
                    102: =over 4
                    103: 
                    104: =item $closebutton
                    105: 
                    106: button that closes the search window
                    107: 
                    108: =item $importbutton
                    109: 
1.134     matthew   110: button to take the select results and go to group sorting
1.121     matthew   111: 
1.142   ! matthew   112: =item %groupsearch_db   
1.121     matthew   113: 
1.142   ! matthew   114: Database hash used to save values for the groupsearch RAT interface.
1.121     matthew   115: 
                    116: =item $diropendb 
                    117: 
                    118: The full path to the (temporary) search database file.  This is set and
                    119: used in &handler() and is also used in &output_results().
                    120: 
1.139     matthew   121: =item %Views
                    122: 
                    123: Hash which associates an output view description with the function
                    124: that produces it.  Adding a new view type should be as easy as
                    125: adding a line to the definition of this hash and making sure the function
                    126: takes the proper parameters.
                    127: 
1.121     matthew   128: =back 
                    129: 
                    130: =cut
                    131: 
                    132: ######################################################################
                    133: ######################################################################
                    134: 
1.98      harris41  135: # -- dynamically rendered interface components
1.121     matthew   136: my $closebutton;  # button that closes the search window
1.98      harris41  137: my $importbutton; # button to take the selected results and go to group sorting
                    138: 
                    139: # -- miscellaneous variables
1.142   ! matthew   140: my %groupsearch_db;     # database hash
1.127     matthew   141: my $diropendb = "";    # db file
1.98      harris41  142: 
1.139     matthew   143: #             View Description           Function Pointer
                    144: my %Views = ("Detailed Citation View" => \&detailed_citation_view,
                    145:              "Summary View"           => \&summary_view,
                    146:              "Fielded Format"         => \&fielded_format_view,
                    147:              "XML/SGML"               => \&xml_sgml_view );
                    148: 
1.121     matthew   149: ######################################################################
                    150: ######################################################################
                    151: 
                    152: =pod 
                    153: 
                    154: =item &handler() - main handler invoked by httpd child
                    155: 
1.124     matthew   156: =item Variables
                    157: 
                    158: =over 4
                    159: 
                    160: =item $hidden
                    161: 
                    162: holds 'hidden' html forms
                    163: 
                    164: =item $scrout
                    165: 
                    166: string that holds portions of the screen output
                    167: 
                    168: =back 
                    169: 
1.121     matthew   170: =cut
1.101     harris41  171: 
1.121     matthew   172: ######################################################################
                    173: ######################################################################
1.98      harris41  174: sub handler {
                    175:     my $r = shift;
1.142   ! matthew   176:     untie %groupsearch_db;
1.98      harris41  177: 
                    178:     $r->content_type('text/html');
                    179:     $r->send_http_header;
                    180:     return OK if $r->header_only;
                    181: 
1.121     matthew   182:     my $domain  = $r->dir_config('lonDefDomain');
1.122     matthew   183:     $diropendb= "/home/httpd/perl/tmp/".&Apache::lonnet::escape($domain).
                    184:             "\_".&Apache::lonnet::escape($ENV{'user.name'})."_searchcat.db";
1.101     harris41  185: 
1.116     matthew   186:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.124     matthew   187:              ['catalogmode','launch','acts','mode','form','element',
                    188:               'reqinterface']);
                    189:     ##
                    190:     ## Clear out old values from database
                    191:     ##
1.101     harris41  192:     if ($ENV{'form.launch'} eq '1') {
1.142   ! matthew   193: 	if (tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1.101     harris41  194: 	    &start_fresh_session();
1.142   ! matthew   195: 	    untie %groupsearch_db;
1.122     matthew   196: 	} else {
1.101     harris41  197: 	    $r->print('<html><head></head><body>Unable to tie hash to db '.
                    198: 		      'file</body></html>');
                    199: 	    return OK;
                    200: 	}
                    201:     }
1.124     matthew   202:     ##
                    203:     ## Produce some output, so people know it is working
                    204:     ##
1.119     www       205:     $r->print("\n");
                    206:     $r->rflush;
1.124     matthew   207:     ##
                    208:     ## Configure dynamic components of interface
                    209:     ##
                    210:     my $hidden;       # Holds 'hidden' html forms
1.98      harris41  211:     if ($ENV{'form.catalogmode'} eq 'interactive') {
                    212: 	$hidden="<input type='hidden' name='catalogmode' value='interactive'>".
                    213: 	    "\n";
                    214:         $closebutton="<input type='button' name='close' value='CLOSE' ".
                    215: 	    "onClick='self.close()'>"."\n";
1.124     matthew   216:     } elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
1.98      harris41  217: 	$hidden=<<END;
                    218: <input type='hidden' name='catalogmode' value='groupsearch'>
                    219: END
                    220:         $closebutton=<<END;
                    221: <input type='button' name='close' value='CLOSE' onClick='self.close()'>
                    222: END
                    223:         $importbutton=<<END;
                    224: <input type='button' name='import' value='IMPORT'
                    225: onClick='javascript:select_group()'>
                    226: END
                    227:     }
1.133     matthew   228:     $hidden .= &make_persistent({ "form.mode"    => $ENV{'form.mode'},
                    229:                                   "form.form"    => $ENV{'form.form'},
                    230:                                   "form.element" => $ENV{'form.element'},
                    231:                                   "form.date"    => 2 });
1.124     matthew   232:     ##
                    233:     ##  What are we doing?
                    234:     ##
1.134     matthew   235:     my $searchtype;
                    236:     $searchtype = 'Basic'    if ($ENV{'form.basicsubmit'}    eq 'SEARCH');
                    237:     $searchtype = 'Advanced' if ($ENV{'form.advancedsubmit'} eq 'SEARCH');
                    238:     if ($searchtype) {
1.139     matthew   239:         # We are running a search
1.134     matthew   240:         my ($query,$customquery,$customshow,$libraries) = 
                    241:             (undef,undef,undef,undef);
                    242:         if ($searchtype eq 'Basic') {
                    243:             $query = &parse_basic_search($r);
                    244:         } elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
                    245:             ($query,$customquery,$customshow,$libraries) 
                    246:                 = &parse_advanced_search($r);
                    247:             return OK if (! defined($query));
                    248:         }
1.142   ! matthew   249:         # Output some information to the user.
        !           250:         $r->print(&search_results_header($searchtype));
        !           251:         $r->print("Sending search request to LON-CAPA servers.<br />\n");
        !           252:         $r->rflush();
1.134     matthew   253:         # Send query statements over the network to be processed by 
                    254:         # either the SQL database or a recursive scheme of 'grep'-like 
                    255:         # actions (for custom metadata).
                    256:         my $reply=&Apache::lonnet::metadata_query($query,$customquery,
                    257:                                                $customshow,$libraries);
1.142   ! matthew   258:         $r->rflush();
1.134     matthew   259:         &output_results($searchtype,$r,$reply,$hidden);
1.139     matthew   260:     } else {
                    261:         #
                    262:         # We need to get information to search on
                    263:         #
                    264:         # Set the default view if it is not already set.
                    265:         if (!defined($ENV{'form.viewselect'})) {
                    266:             $ENV{'form.viewselect'} ="Detailed Citation View";
                    267:         }
1.124     matthew   268:         # Output the advanced interface
1.139     matthew   269:         if ($ENV{'form.reqinterface'} eq 'advanced') {
                    270:             $r->print(&advanced_search_form($closebutton,$hidden));
                    271:         } else { 
                    272:             # Output normal search interface
                    273:             $r->print(&basic_search_form($closebutton,$hidden));
                    274:         }
1.124     matthew   275:     }
                    276:     return OK;
                    277: } 
1.98      harris41  278: 
1.124     matthew   279: ######################################################################
                    280: ######################################################################
                    281: 
                    282: =pod 
                    283: 
                    284: =item &basic_search_form() 
                    285: 
                    286: Returns a scalar which holds html for the basic search form.
                    287: 
                    288: =cut
                    289: 
                    290: ######################################################################
                    291: ######################################################################
1.3       harris41  292: 
1.124     matthew   293: sub basic_search_form{
                    294:     my ($closebutton,$hidden) = @_;
                    295:     my $scrout=<<"ENDDOCUMENT";
                    296: <html>
                    297: <head>
                    298: <title>The LearningOnline Network with CAPA</title>
                    299: <script type="text/javascript">
                    300:     function openhelp(val) {
                    301: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                    302: 	     'scrollbars=1,width=600,height=300');
                    303: 	openhelpwin.focus();
1.6       harris41  304:     }
1.124     matthew   305: </script>
                    306: </head>
                    307: <body bgcolor="#FFFFFF">
                    308: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
                    309: <h1>Search Catalog</h1>
                    310: <form method="post" action="/adm/searchcat">
                    311: $hidden
                    312: <h3>Basic Search</h3>
                    313: <p>
1.131     matthew   314: Enter terms or phrases separated by AND, OR, or NOT 
1.129     matthew   315: then press SEARCH below.
1.124     matthew   316: </p>
                    317: <p>
                    318: <table>
                    319: <tr><td>
                    320: ENDDOCUMENT
                    321:     $scrout.='&nbsp;'.&simpletextfield('basicexp',$ENV{'form.basicexp'},40).
                    322:         '&nbsp;';
                    323: #    $scrout.=&simplecheckbox('allversions',$ENV{'form.allversions'});
                    324: #    $scrout.='<font color="#800000">Search historic archives</font>';
1.141     matthew   325:     my $checkbox = &simplecheckbox('related',$ENV{'form.related'});
1.139     matthew   326:     $scrout.=<<END;
1.141     matthew   327: </td><td><a href="/adm/searchcat?reqinterface=advanced">Advanced Search</a></td></tr>
                    328: <tr><td>$checkbox use related words</td><td></td></tr>
                    329: </table>
1.124     matthew   330: </p>
                    331: <p>
                    332: &nbsp;<input type="submit" name="basicsubmit" value='SEARCH' />&nbsp;
                    333: $closebutton
1.139     matthew   334: END
                    335:     $scrout.=&selectbox(undef,'viewselect',
                    336: 			$ENV{'form.viewselect'},
                    337: 			undef,undef,undef,
                    338: 			sort(keys(%Views)));
                    339:     $scrout.=<<ENDDOCUMENT;
1.124     matthew   340: <input type="button" value="HELP" onClick="openhelp()" />
                    341: </p>
                    342: </form>
                    343: </body>
                    344: </html>
                    345: ENDDOCUMENT
                    346:     return $scrout;
                    347: }
                    348: ######################################################################
                    349: ######################################################################
                    350: 
                    351: =pod 
                    352: 
                    353: =item &advanced_search_form() 
                    354: 
                    355: Returns a scalar which holds html for the advanced search form.
                    356: 
                    357: =cut
                    358: 
                    359: ######################################################################
                    360: ######################################################################
                    361: 
                    362: sub advanced_search_form{
                    363:     my ($closebutton,$hidden) = @_;
1.129     matthew   364:     my $advanced_buttons = <<"END";
                    365: <p>
                    366: <input type="submit" name="advancedsubmit" value='SEARCH' />
                    367: <input type="reset" name="reset" value='RESET' />
                    368: $closebutton
                    369: <input type="button" value="HELP" onClick="openhelp()" />
                    370: </p>
                    371: END
1.139     matthew   372:     if (!defined($ENV{'form.viewselect'})) {
                    373:         $ENV{'form.viewselect'} ="Detailed Citation View";
                    374:     }
1.124     matthew   375:     my $scrout=<<"ENDHEADER";
                    376: <html>
                    377: <head>
                    378: <title>The LearningOnline Network with CAPA</title>
                    379: <script type="text/javascript">
                    380:     function openhelp(val) {
                    381: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                    382: 	     'scrollbars=1,width=600,height=300');
                    383: 	openhelpwin.focus();
1.18      harris41  384:     }
1.124     matthew   385: </script>
                    386: </head>
                    387: <body bgcolor="#FFFFFF">
                    388: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.129     matthew   389: <h1>Advanced Catalog Search</h1>
                    390: <hr />
1.131     matthew   391: Enter terms or phrases separated by search operators 
1.129     matthew   392: such as AND, OR, or NOT.<br />
1.130     matthew   393: <form method="post" action="/adm/searchcat">
1.129     matthew   394: $advanced_buttons
1.124     matthew   395: $hidden
1.129     matthew   396: <table>
1.130     matthew   397: <tr><td><font color="#800000" face="helvetica"><b>VIEW:</b></font></td>
                    398: <td>
1.124     matthew   399: ENDHEADER
1.139     matthew   400:     $scrout.=&selectbox(undef,'viewselect',
                    401: 			$ENV{'form.viewselect'},
                    402: 			undef,undef,undef,
                    403: 			sort(keys(%Views)));
1.142   ! matthew   404:     $scrout.="</td><td>Related<br />Words</td></tr>\n";
        !           405:     $scrout.=&searchphrasefield_with_related('title',   'title'   ,
        !           406:                                              $ENV{'form.title'});
1.135     matthew   407:     $scrout.=&searchphrasefield('author',  'author'  ,$ENV{'form.author'});
1.142   ! matthew   408:     $scrout.=&searchphrasefield_with_related('subject', 'subject' ,
        !           409:                                              $ENV{'form.subject'});
        !           410:     $scrout.=&searchphrasefield_with_related('keywords','keywords',
        !           411:                                              $ENV{'form.keywords'});
1.135     matthew   412:     $scrout.=&searchphrasefield('URL',     'url'     ,$ENV{'form.url'});
1.142   ! matthew   413:     $scrout.=&searchphrasefield_with_related('notes',   'notes'   ,
        !           414:                                              $ENV{'form.notes'});
        !           415:     $scrout.=&searchphrasefield_with_related('abstract','abstract',
        !           416:                                              $ENV{'form.abstract'});
1.129     matthew   417:     # Hack - an empty table row.
1.142   ! matthew   418:     $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
1.129     matthew   419:     $scrout.=&searchphrasefield('file<br />extension','mime',
                    420:                         $ENV{'form.mime'});
1.142   ! matthew   421:     $scrout.="<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>\n";
1.129     matthew   422:     $scrout.=&searchphrasefield('publisher<br />owner','owner',
                    423: 				$ENV{'form.owner'});
                    424:     $scrout.="</table>\n";
1.131     matthew   425:     $ENV{'form.category'}='any' unless length($ENV{'form.category'});
1.132     matthew   426:     $scrout.=&selectbox('File Category','category',
1.131     matthew   427: 			$ENV{'form.category'},
                    428: 			'any','Any category',
                    429: 			undef,
                    430: 			(&Apache::loncommon::filecategories()));
1.11      harris41  431:     $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.133     matthew   432:     #----------------------------------------------------------------
1.132     matthew   433:     # Allow restriction to multiple domains.
                    434:     #   I make the crazy assumption that there will never be a domain 'any'.
                    435:     #
1.133     matthew   436:     $ENV{'form.domains'} = 'any' if (! exists($ENV{'form.domains'}));
                    437:     my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} 
                    438:                            :  ($ENV{'form.domains'}) );
                    439:     my %domain_hash = ();
                    440:     foreach (@allowed_domains) {
                    441:         $domain_hash{$_}++;
                    442:     }
1.132     matthew   443:     my @domains =&Apache::loncommon::get_domains();
                    444:     # adjust the size of the select box
                    445:     my $size = 4;
                    446:     my $size = (scalar @domains < ($size - 1) ? scalar @domains + 1 : $size);
                    447:     # standalone machines do not get to choose a domain to search.
                    448:     if ((scalar @domains) == 1) {
                    449:         $scrout .='<input type="hidden" name="domains" value="any" />'."\n";
                    450:     } else {
1.133     matthew   451:         $scrout.="\n".'<font color="#800000" face="helvetica"><b>'.
1.132     matthew   452:             'DOMAINS</b></font><br />'.
                    453:                 '<select name="domains" size="'.$size.'" multiple>'."\n".
1.133     matthew   454:                     '<option name="any" value="any" '.
                    455:                         ($domain_hash{'any'}? 'selected ' :'').
                    456:                         '>all domains</option>'."\n";
1.132     matthew   457:         foreach my $dom (sort @domains) {
1.133     matthew   458:             $scrout.="<option name=\"$dom\" ".
                    459:                 ($domain_hash{$dom} ? 'selected ' :'').">$dom</option>\n";
1.132     matthew   460:         }
                    461:         $scrout.="</select>\n";
                    462:     }
1.133     matthew   463:     #----------------------------------------------------------------
1.3       harris41  464:     $scrout.=&selectbox('Limit by language','language',
1.111     harris41  465: 			$ENV{'form.language'},'any','Any Language',
                    466: 			\&{Apache::loncommon::languagedescription},
                    467: 			(&Apache::loncommon::languageids),
                    468: 			);
1.8       harris41  469: # ------------------------------------------------ Compute date selection boxes
                    470:     $scrout.=<<CREATIONDATESTART;
1.3       harris41  471: <p>
                    472: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
                    473: </font>
1.98      harris41  474: <br />
1.8       harris41  475: between:
                    476: CREATIONDATESTART
1.11      harris41  477:     $scrout.=&dateboxes('creationdatestart',1,1,1976,
                    478: 			$ENV{'form.creationdatestart_month'},
                    479: 			$ENV{'form.creationdatestart_day'},
                    480: 			$ENV{'form.creationdatestart_year'},
                    481: 			);
1.124     matthew   482:     $scrout.="and:\n";
1.11      harris41  483:     $scrout.=&dateboxes('creationdateend',12,31,2051,
                    484: 			$ENV{'form.creationdateend_month'},
                    485: 			$ENV{'form.creationdateend_day'},
                    486: 			$ENV{'form.creationdateend_year'},
                    487: 			);
1.8       harris41  488:     $scrout.="</p>";
                    489:     $scrout.=<<LASTREVISIONDATESTART;
                    490: <p>
                    491: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
                    492: </b></font>
1.98      harris41  493: <br />between:
1.8       harris41  494: LASTREVISIONDATESTART
1.11      harris41  495:     $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
                    496: 			$ENV{'form.lastrevisiondatestart_month'},
                    497: 			$ENV{'form.lastrevisiondatestart_day'},
                    498: 			$ENV{'form.lastrevisiondatestart_year'},
                    499: 			);
1.8       harris41  500:     $scrout.=<<LASTREVISIONDATEEND;
                    501: and:
                    502: LASTREVISIONDATEEND
1.11      harris41  503:     $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
                    504: 			$ENV{'form.lastrevisiondateend_month'},
                    505: 			$ENV{'form.lastrevisiondateend_day'},
                    506: 			$ENV{'form.lastrevisiondateend_year'},
                    507: 			);
1.8       harris41  508:     $scrout.='</p>';
1.11      harris41  509:     $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8       harris41  510:     $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.111     harris41  511: 			 $ENV{'form.copyright'},
                    512: 			 'any','Any copyright/distribution',
                    513: 			 \&{Apache::loncommon::copyrightdescription},
                    514: 			 (&Apache::loncommon::copyrightids),
                    515: 			 );
1.14      harris41  516: # ------------------------------------------- Compute customized metadata field
                    517:     $scrout.=<<CUSTOMMETADATA;
                    518: <p>
1.77      harris41  519: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14      harris41  520: </font>
1.77      harris41  521: For resource-specific metadata, enter in an expression in the form of 
1.100     harris41  522: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
1.14      harris41  523: <b>Example:</b> grandmother=75 OR grandfather=85
1.98      harris41  524: <br />
1.14      harris41  525: CUSTOMMETADATA
1.124     matthew   526:     $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.77      harris41  527:     $scrout.=<<CUSTOMSHOW;
                    528: <p>
                    529: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
                    530: </font>
                    531: Enter in a space-separated list of special metadata fields to show
                    532: in a fielded listing for each record result.
1.98      harris41  533: <br />
1.77      harris41  534: CUSTOMSHOW
1.124     matthew   535:     $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
                    536:     $scrout.=<<ENDDOCUMENT;
1.129     matthew   537: $advanced_buttons
1.8       harris41  538: </form>
                    539: </body>
                    540: </html>
                    541: ENDDOCUMENT
1.124     matthew   542:     return $scrout;
                    543: }
1.8       harris41  544: 
1.121     matthew   545: ######################################################################
                    546: ######################################################################
                    547: 
                    548: =pod 
                    549: 
                    550: =item &make_persistent() 
                    551: 
                    552: Returns a scalar which holds the current ENV{'form.*'} values in
1.126     matthew   553: a 'hidden' html input tag.  This allows search interface information
                    554: to be somewhat persistent.
1.122     matthew   555: 
1.121     matthew   556: =cut
                    557: 
                    558: ######################################################################
                    559: ######################################################################
                    560: 
1.98      harris41  561: sub make_persistent {
1.133     matthew   562:     my %save = %{shift()};
1.98      harris41  563:     my $persistent='';
1.133     matthew   564:     foreach (keys %save) {
1.98      harris41  565: 	if (/^form\./ && !/submit/) {
                    566: 	    my $name=$_;
1.133     matthew   567:             my @values = (ref($save{$name}) ? @{$save{$name}} : ($save{$name}));
1.98      harris41  568: 	    $name=~s/^form\.//;
1.133     matthew   569:             foreach (@values) {
                    570:                 s/\"/\'/g; # do not mess with html field syntax
                    571:                 $persistent.=<<END;
                    572: <input type="hidden" name="$name" value="$_" />
1.98      harris41  573: END
1.133     matthew   574:             }
1.98      harris41  575:         }
1.109     harris41  576:     }
1.98      harris41  577:     return $persistent;
                    578: }
                    579: 
1.122     matthew   580: ######################################################################
1.142   ! matthew   581: #                HTML form building functions                        #  
1.122     matthew   582: ######################################################################
                    583: 
                    584: =pod 
                    585: 
                    586: =item HTML form building functions
                    587: 
                    588: =over 4
                    589: 
1.142   ! matthew   590: =cut
        !           591: 
        !           592: ###############################################
        !           593: ###############################################
        !           594: 
        !           595: =pod
        !           596: 
1.122     matthew   597: =item &simpletextfield() 
                    598: 
                    599: Inputs: $name,$value,$size
                    600: 
                    601: Returns a text input field with the given name, value, and size.  
                    602: If size is not specified, a value of 20 is used.
                    603: 
1.142   ! matthew   604: =cut
        !           605: 
        !           606: ###############################################
        !           607: ###############################################
        !           608: 
        !           609: sub simpletextfield {
        !           610:     my ($name,$value,$size)=@_;
        !           611:     $size = 20 if (! defined($size));
        !           612:     return '<input type="text" name="'.$name.
        !           613:         '" size="'.$size.'" value="'.$value.'" />';
        !           614: }
        !           615: 
        !           616: ###############################################
        !           617: ###############################################
        !           618: 
        !           619: =pod
        !           620: 
1.122     matthew   621: =item &simplecheckbox()
                    622: 
                    623: Inputs: $name,$value
                    624: 
                    625: Returns a simple check box with the given $name.
                    626: If $value eq 'on' the box is checked.
                    627: 
1.142   ! matthew   628: =cut
        !           629: 
        !           630: ###############################################
        !           631: ###############################################
1.122     matthew   632: 
1.142   ! matthew   633: sub simplecheckbox {
        !           634:     my ($name,$value)=@_;
        !           635:     my $checked='';
        !           636:     $checked="checked" if $value eq 'on';
        !           637:     return '<input type="checkbox" name="'.$name.'" '. $checked . ' />';
        !           638: }
1.122     matthew   639: 
1.142   ! matthew   640: ###############################################
        !           641: ###############################################
1.122     matthew   642: 
1.142   ! matthew   643: =pod
1.122     matthew   644: 
1.142   ! matthew   645: =item &fieldtitle()
1.126     matthew   646: 
1.142   ! matthew   647: Input: $title
1.122     matthew   648: 
1.142   ! matthew   649: Returns a scalar with html which will display $title as a search
        !           650: field heading.
1.129     matthew   651: 
1.142   ! matthew   652: =cut
1.129     matthew   653: 
1.142   ! matthew   654: ###############################################
        !           655: ###############################################
1.129     matthew   656: 
1.142   ! matthew   657: sub fieldtitle {
        !           658:     my $title = uc(shift());
        !           659:     return '<font color="#800000" face="helvetica"><b>'.$title.
        !           660:         ':&nbsp;</b></font>';
        !           661: }
1.129     matthew   662: 
1.142   ! matthew   663: ###############################################
        !           664: ###############################################
1.129     matthew   665: 
1.142   ! matthew   666: =pod
1.129     matthew   667: 
1.142   ! matthew   668: =item &searchphrasefield()
1.129     matthew   669: 
1.142   ! matthew   670: Inputs: $title,$name,$value
1.129     matthew   671: 
1.142   ! matthew   672: Returns html for a title line and an input field for entering search terms.
        !           673: The entry field (which is where the $name and $value are used) is a 50 column 
        !           674: simpletextfield.  The html returned is for a row in a three column table.
1.129     matthew   675: 
1.142   ! matthew   676: =cut
1.129     matthew   677: 
1.142   ! matthew   678: ###############################################
        !           679: ###############################################
        !           680:     
        !           681: sub searchphrasefield {
        !           682:     my ($title,$name,$value)=@_;
        !           683:     return '<tr><td>'.&fieldtitle($title).'</td><td>'.
        !           684:         &simpletextfield($name,$value,50)."</td><td>&nbsp;</td></tr>\n";
        !           685: }
1.129     matthew   686: 
1.142   ! matthew   687: ###############################################
        !           688: ###############################################
1.129     matthew   689: 
1.142   ! matthew   690: =pod
1.129     matthew   691: 
1.142   ! matthew   692: =item &searchphrasefield_with_related()
1.129     matthew   693: 
1.142   ! matthew   694: Inputs: $title,$name,$value
1.129     matthew   695: 
1.142   ! matthew   696: Returns html for a title line and an input field for entering search terms
        !           697: and a check box for 'related words'.  The entry field (which is where the 
        !           698: $name and $value are used) is a 50 column simpletextfield.  The name of
        !           699: the related words checkbox is "$name_related".
1.129     matthew   700: 
1.142   ! matthew   701: =cut
1.129     matthew   702: 
1.142   ! matthew   703: ###############################################
        !           704: ###############################################
        !           705:     
        !           706: sub searchphrasefield_with_related {
        !           707:     my ($title,$name,$value)=@_;
        !           708:     return '<tr><td>'.&fieldtitle($title).'</td><td>'.
        !           709:         &simpletextfield($name,$value,50).'</td><td align="center">&nbsp;'.
        !           710:             &simplecheckbox($name.'_related',$ENV{'form.'.$name.'_related'}).
        !           711:                 "&nbsp;</td></tr>\n";
        !           712: }
1.126     matthew   713: 
1.142   ! matthew   714: ###############################################
        !           715: ###############################################
1.122     matthew   716: 
1.142   ! matthew   717: =pod
1.122     matthew   718: 
1.142   ! matthew   719: =item &dateboxes()
1.8       harris41  720: 
1.142   ! matthew   721: Returns html selection form elements for the specification of 
        !           722: the day, month, and year.
1.11      harris41  723: 
1.142   ! matthew   724: =cut
1.11      harris41  725: 
1.142   ! matthew   726: ###############################################
        !           727: ###############################################
1.3       harris41  728: 
1.8       harris41  729: sub dateboxes {
1.11      harris41  730:     my ($name,$defaultmonth,$defaultday,$defaultyear,
                    731: 	$currentmonth,$currentday,$currentyear)=@_;
                    732:     ($defaultmonth,$defaultday,$defaultyear)=('','','');
1.117     matthew   733:     #
                    734:     # Day
                    735:     my $day=<<END;
                    736: <select name="${name}_day">
                    737: <option value='$defaultday'> </option>
                    738: END
                    739:     for (my $i = 1; $i<=31; $i++) {
                    740: 	$day.="<option value=\"$i\">$i</option>\n";
                    741:     }
                    742:     $day.="</select>\n";
                    743:     $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
                    744:     #
                    745:     # Month
1.11      harris41  746:     my $month=<<END;
1.8       harris41  747: <select name="${name}_month">
1.11      harris41  748: <option value='$defaultmonth'> </option>
                    749: END
1.117     matthew   750:     my $i = 1;
                    751:     foreach (qw/January February March April May June 
                    752: 	     July August September October November December /){
                    753: 	$month .="<option value=\"$i\">$_</option>\n";
                    754: 	$i++;
                    755:     }
                    756:     $month.="</select>\n";
1.11      harris41  757:     $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
1.117     matthew   758:     #
                    759:     # Year (obviously)
1.11      harris41  760:     my $year=<<END;
1.8       harris41  761: <select name="${name}_year">
1.11      harris41  762: <option value='$defaultyear'> </option>
1.3       harris41  763: END
1.117     matthew   764:     my $maxyear = 2051; 
                    765:     for (my $i = 1976; $i<=$maxyear; $i++) {
                    766: 	$year.="<option value=\"$i\">$i</option>\n";
                    767:     }
                    768:     $year.="</select>\n";
1.11      harris41  769:     $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
                    770:     return "$month$day$year";
1.3       harris41  771: }
                    772: 
1.142   ! matthew   773: ###############################################
        !           774: ###############################################
        !           775: 
        !           776: =pod
        !           777: 
        !           778: =item &selectbox()
        !           779: 
        !           780: Returns a scalar containing an html <select> form.  
        !           781: 
        !           782: Inputs: 
        !           783: 
        !           784: =over 4
        !           785: 
        !           786: =item $title 
        !           787: 
        !           788: Printed above the select box, in uppercase.  If undefined, only a select
        !           789: box will be returned, with no additional html.
        !           790: 
        !           791: =item $name 
        !           792: 
        !           793: The name element of the <select> tag.
        !           794: 
        !           795: =item $default 
        !           796: 
        !           797: The default value of the form.  Can be $anyvalue, or in @idlist.
        !           798: 
        !           799: =item $anyvalue 
        !           800: 
        !           801: The <option value="..."> used to indicate a default of 
        !           802: none of the values.  Can be undef.
        !           803: 
        !           804: =item $anytag 
        !           805: 
        !           806: The text associate with $anyvalue above.
        !           807: 
        !           808: =item $functionref 
        !           809: 
        !           810: Each element in @idlist will be passed as a parameter 
        !           811: to the function referenced here.  The return value of the function should
        !           812: be a scalar description of the items.  If this value is undefined the 
        !           813: description of each item in @idlist will be the item name.
        !           814: 
        !           815: =item @idlist 
        !           816: 
        !           817: The items to be selected from.  One of these or $anyvalue will be the 
        !           818: value returned by the form element, $ENV{form.$name}.
        !           819: 
        !           820: =back
        !           821: 
        !           822: =cut
        !           823: 
        !           824: ###############################################
        !           825: 
1.3       harris41  826: sub selectbox {
1.129     matthew   827:     my ($title,$name,$default,$anyvalue,$anytag,$functionref,@idlist)=@_;
                    828:     if (! defined($functionref)) { $functionref = sub { $_[0]}; }
1.139     matthew   829:     my $selout='';
                    830:     if (defined($title)) {
                    831:         my $uctitle=uc($title);
                    832:         $selout="\n".'<p><font color="#800000" face="helvetica">'.
                    833:             '<b>'.$uctitle.': </b></font>';
                    834:     }
                    835:     $selout .= '<select name="'.$name.'">';
                    836:     unshift @idlist,$anyvalue if (defined($anyvalue));
                    837:     foreach (@idlist) {
1.122     matthew   838:         $selout.='<option value="'.$_.'"';
1.129     matthew   839:         if ($_ eq $default and !/^any$/) {
1.122     matthew   840: 	    $selout.=' selected >'.&{$functionref}($_).'</option>';
1.111     harris41  841: 	}
1.129     matthew   842: 	elsif ($_ eq $default and /^$anyvalue$/) {
1.122     matthew   843: 	    $selout.=' selected >'.$anytag.'</option>';
1.111     harris41  844: 	}
                    845:         else {$selout.='>'.&{$functionref}($_).'</option>';}
1.109     harris41  846:     }
1.139     matthew   847:     return $selout.'</select>'.(defined($title)?'</p>':' ');
1.6       harris41  848: }
                    849: 
1.122     matthew   850: ######################################################################
1.142   ! matthew   851: #                End of HTML form building functions                 #  
        !           852: ######################################################################
        !           853: 
        !           854: =pod
        !           855: 
        !           856: =back 
        !           857: 
        !           858: =cut
        !           859: 
        !           860: 
        !           861: ######################################################################
1.122     matthew   862: ######################################################################
                    863: 
                    864: =pod 
                    865: 
1.134     matthew   866: =item &parse_advanced_search()
                    867: 
                    868: Parse advanced search form and return the following:
                    869: 
                    870: =over 4
                    871: 
                    872: =item $query Scalar containing an SQL query.
1.126     matthew   873: 
1.134     matthew   874: =item $customquery Scalar containing a custom query.
                    875: 
                    876: =item $customshow Scalar containing commands to show custom metadata.
                    877: 
                    878: =item $libraries_to_query Reference to array of domains to search.
                    879: 
                    880: =back
1.122     matthew   881: 
                    882: =cut
                    883: 
                    884: ######################################################################
                    885: ######################################################################
1.134     matthew   886: sub parse_advanced_search {
                    887:     my ($r)=@_;
1.32      harris41  888:     my $fillflag=0;
1.64      harris41  889:     # Clean up fields for safety
                    890:     for my $field ('title','author','subject','keywords','url','version',
                    891: 		   'creationdatestart_month','creationdatestart_day',
                    892: 		   'creationdatestart_year','creationdateend_month',
                    893: 		   'creationdateend_day','creationdateend_year',
                    894: 		   'lastrevisiondatestart_month','lastrevisiondatestart_day',
                    895: 		   'lastrevisiondatestart_year','lastrevisiondateend_month',
                    896: 		   'lastrevisiondateend_day','lastrevisiondateend_year',
                    897: 		   'notes','abstract','mime','language','owner',
1.131     matthew   898: 		   'custommetadata','customshow','category') {
1.101     harris41  899: 	$ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64      harris41  900:     }
1.117     matthew   901:     foreach ('mode','form','element') {
                    902: 	# is this required?  Hmmm.
                    903: 	next unless (exists($ENV{"form.$_"}));
                    904: 	$ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
                    905: 	$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
                    906:     }
1.131     matthew   907:     # Preprocess the category form element.
                    908:     if ($ENV{'form.category'} ne 'any') {
                    909:         my @extensions = &Apache::loncommon::filecategorytypes
                    910:             ($ENV{'form.category'});
                    911:         $ENV{'form.mime'} = join ' OR ',@extensions;
                    912:     }
1.90      harris41  913:     # Check to see if enough information was filled in
1.32      harris41  914:     for my $field ('title','author','subject','keywords','url','version',
                    915: 		   'notes','abstract','mime','language','owner',
                    916: 		   'custommetadata') {
1.40      harris41  917: 	if (&filled($ENV{"form.$field"})) {
1.32      harris41  918: 	    $fillflag++;
                    919: 	}
                    920:     }
                    921:     unless ($fillflag) {
                    922: 	&output_blank_field_error($r);
1.134     matthew   923: 	return ;
1.32      harris41  924:     }
1.90      harris41  925:     # Turn the form input into a SQL-based query
1.39      harris41  926:     my $query='';
1.45      harris41  927:     my @queries;
1.90      harris41  928:     # Evaluate logical expression AND/OR/NOT phrase fields.
1.58      harris41  929:     foreach my $field ('title','author','subject','notes','abstract','url',
1.129     matthew   930: 		       'keywords','version','owner','mime') {
1.44      harris41  931: 	if ($ENV{'form.'.$field}) {
1.142   ! matthew   932:             my $searchphrase = $ENV{'form.'.$field};
        !           933:             if ($ENV{'form.'.$field.'_related'}) {
        !           934:                 $searchphrase = &related_version($searchphrase);
        !           935:                 $ENV{'form.'.$field} = $searchphrase;
        !           936:                 $ENV{'form.'.$field.'_related'} = undef;
        !           937:             }
        !           938: 	    push @queries,&build_SQL_query($field,$searchphrase);
1.131     matthew   939:         }
1.44      harris41  940:     }
1.135     matthew   941:     # I dislike the hack below.
                    942:     if ($ENV{'form.category'}) {
                    943:         $ENV{'form.mime'}='';
                    944:     }
1.90      harris41  945:     # Evaluate option lists
1.58      harris41  946:     if ($ENV{'form.language'} and $ENV{'form.language'} ne 'any') {
1.90      harris41  947: 	push @queries,"(language like \"$ENV{'form.language'}\")";
1.58      harris41  948:     }
                    949:     if ($ENV{'form.copyright'} and $ENV{'form.copyright'} ne 'any') {
1.90      harris41  950: 	push @queries,"(copyright like \"$ENV{'form.copyright'}\")";
1.58      harris41  951:     }
1.90      harris41  952:     # Evaluate date windows
1.60      harris41  953:     my $datequery=&build_date_queries(
                    954: 			$ENV{'form.creationdatestart_month'},
                    955: 			$ENV{'form.creationdatestart_day'},
                    956: 			$ENV{'form.creationdatestart_year'},
                    957: 			$ENV{'form.creationdateend_month'},
                    958: 			$ENV{'form.creationdateend_day'},
                    959: 			$ENV{'form.creationdateend_year'},
                    960: 			$ENV{'form.lastrevisiondatestart_month'},
                    961: 			$ENV{'form.lastrevisiondatestart_day'},
                    962: 			$ENV{'form.lastrevisiondatestart_year'},
                    963: 			$ENV{'form.lastrevisiondateend_month'},
                    964: 			$ENV{'form.lastrevisiondateend_day'},
                    965: 			$ENV{'form.lastrevisiondateend_year'},
                    966: 			);
1.90      harris41  967:     # Test to see if date windows are legitimate
1.61      harris41  968:     if ($datequery=~/^Incorrect/) {
                    969: 	&output_date_error($r,$datequery);
1.134     matthew   970: 	return ;
1.61      harris41  971:     }
                    972:     elsif ($datequery) {
1.60      harris41  973: 	push @queries,$datequery;
                    974:     }
1.90      harris41  975:     # Process form information for custom metadata querying
1.134     matthew   976:     my $customquery=undef;
1.64      harris41  977:     if ($ENV{'form.custommetadata'}) {
                    978: 	$customquery=&build_custommetadata_query('custommetadata',
                    979: 				      $ENV{'form.custommetadata'});
                    980:     }
1.134     matthew   981:     my $customshow=undef;
1.83      harris41  982:     if ($ENV{'form.customshow'}) {
                    983: 	$customshow=$ENV{'form.customshow'};
                    984: 	$customshow=~s/[^\w\s]//g;
                    985: 	my @fields=split(/\s+/,$customshow);
                    986: 	$customshow=join(" ",@fields);
                    987:     }
1.133     matthew   988:     ## ---------------------------------------------------------------
1.132     matthew   989:     ## Deal with restrictions to given domains
                    990:     ## 
                    991:     my $libraries_to_query = undef;
                    992:     # $ENV{'form.domains'} can be either a scalar or an array reference.
                    993:     # We need an array.
                    994:     my @allowed_domains = (ref($ENV{'form.domains'}) ? @{$ENV{'form.domains'}} 
                    995:                            :  ($ENV{'form.domains'}) );
                    996:     my %domain_hash = ();
                    997:     foreach (@allowed_domains) {
                    998:         $domain_hash{$_}++;
                    999:     }
                   1000:     foreach (keys(%Apache::lonnet::libserv)) {
                   1001:         if ($_ eq 'any') {
                   1002:             $libraries_to_query = undef;
                   1003:             last;
                   1004:         }
                   1005:         if (exists($domain_hash{$Apache::lonnet::hostdom{$_}})) {
                   1006:             push @$libraries_to_query,$_;
                   1007:         }
                   1008:     }
                   1009:     #
1.45      harris41 1010:     if (@queries) {
1.58      harris41 1011: 	$query=join(" AND ",@queries);
1.46      harris41 1012: 	$query="select * from metadata where $query";
1.126     matthew  1013:     } elsif ($customquery) {
1.134     matthew  1014:         $query = '';
1.45      harris41 1015:     }
1.134     matthew  1016:     return ($query,$customquery,$customshow,$libraries_to_query);
1.18      harris41 1017: }
                   1018: 
1.122     matthew  1019: ######################################################################
                   1020: ######################################################################
                   1021: 
                   1022: =pod 
                   1023: 
1.134     matthew  1024: =item &parse_basic_search() 
1.122     matthew  1025: 
1.134     matthew  1026: Parse the basic search form and return a scalar containing an sql query.
1.126     matthew  1027: 
1.122     matthew  1028: =cut
                   1029: 
                   1030: ######################################################################
                   1031: ######################################################################
1.134     matthew  1032: sub parse_basic_search {
                   1033:     my ($r)=@_;
1.64      harris41 1034:     # Clean up fields for safety
                   1035:     for my $field ('basicexp') {
                   1036: 	$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
                   1037:     }
1.117     matthew  1038:     foreach ('mode','form','element') {
                   1039: 	# is this required?  Hmmm.
                   1040: 	next unless (exists($ENV{"form.$_"}));
                   1041: 	$ENV{"form.$_"}=&Apache::lonnet::unescape($ENV{"form.$_"});
                   1042: 	$ENV{"form.$_"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
                   1043:     }
1.64      harris41 1044: 
1.90      harris41 1045:     # Check to see if enough is filled in
1.26      harris41 1046:     unless (&filled($ENV{'form.basicexp'})) {
1.24      harris41 1047: 	&output_blank_field_error($r);
                   1048: 	return OK;
                   1049:     }
1.142   ! matthew  1050:     my $search_string = $ENV{'form.basicexp'};
1.141     matthew  1051:     if ($ENV{'form.related'}) {
1.142   ! matthew  1052:         $search_string = &related_version($ENV{'form.basicexp'});
1.141     matthew  1053:     }
1.90      harris41 1054:     # Build SQL query string based on form page
1.39      harris41 1055:     my $query='';
1.33      harris41 1056:     my $concatarg=join(',"    ",',
1.124     matthew  1057: 		       ('title', 'author', 'subject', 'notes', 'abstract',
                   1058:                         'keywords'));
1.95      harris41 1059:     $concatarg='title' if $ENV{'form.titleonly'};
1.142   ! matthew  1060:     $query=&build_SQL_query('concat('.$concatarg.')',$search_string);
1.134     matthew  1061:     return 'select * from metadata where '.$query;
1.22      harris41 1062: }
                   1063: 
1.122     matthew  1064: 
                   1065: ######################################################################
                   1066: ######################################################################
                   1067: 
                   1068: =pod 
                   1069: 
1.142   ! matthew  1070: =item &related_version
        !          1071: 
        !          1072: Modifies an input string to include related words.  Words in the string
        !          1073: are replaced with parenthesized lists of 'OR'd words.  For example
        !          1074: "torque" is replaced with "(torque OR word1 OR word2 OR ...)".  
        !          1075: 
        !          1076: Note: Using this twice on a string is probably silly.
        !          1077: 
        !          1078: =cut
        !          1079: 
        !          1080: ######################################################################
        !          1081: ######################################################################
        !          1082: sub related_version {
        !          1083:     my $search_string = shift;
        !          1084:     my $result = $search_string;
        !          1085:     while ($search_string =~ /(\w+)/cg) {
        !          1086:         my $word = $1;
        !          1087:         next if (lc($word) =~ /\b(or|and|not)\b/);
        !          1088:         my @Words = &Apache::loncommon::get_related_words($word);
        !          1089:         my $replacement = join " OR ", ($word,
        !          1090:                                         ($#Words>4? @Words[0..4] : @Words)
        !          1091:                                         );
        !          1092:         $result =~ s/(\b)$word(\b)/$1($replacement)$2/g;
        !          1093:     }
        !          1094:     return $result;
        !          1095: }
        !          1096: 
        !          1097: ######################################################################
        !          1098: ######################################################################
        !          1099: 
        !          1100: =pod 
        !          1101: 
1.122     matthew  1102: =item &build_SQL_query() 
                   1103: 
1.126     matthew  1104: Builds a SQL query string from a logical expression with AND/OR keywords
                   1105: using Text::Query and &recursive_SQL_query_builder()
                   1106: 
1.122     matthew  1107: =cut
                   1108: 
                   1109: ######################################################################
                   1110: ######################################################################
1.98      harris41 1111: sub build_SQL_query {
                   1112:     my ($field_name,$logic_statement)=@_;
                   1113:     my $q=new Text::Query('abc',
                   1114: 			  -parse => 'Text::Query::ParseAdvanced',
                   1115: 			  -build => 'Text::Query::Build');
                   1116:     $q->prepare($logic_statement);
                   1117:     my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
                   1118:     my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
                   1119:     return $sql_query;
                   1120: }
                   1121: 
1.122     matthew  1122: ######################################################################
                   1123: ######################################################################
                   1124: 
                   1125: =pod 
                   1126: 
                   1127: =item &build_custommetadata_query() 
                   1128: 
1.126     matthew  1129: Constructs a custom metadata query using a rather heinous regular
                   1130: expression.
                   1131: 
1.122     matthew  1132: =cut
                   1133: 
                   1134: ######################################################################
                   1135: ######################################################################
1.98      harris41 1136: sub build_custommetadata_query {
                   1137:     my ($field_name,$logic_statement)=@_;
                   1138:     my $q=new Text::Query('abc',
                   1139: 			  -parse => 'Text::Query::ParseAdvanced',
                   1140: 			  -build => 'Text::Query::BuildAdvancedString');
                   1141:     $q->prepare($logic_statement);
                   1142:     my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
                   1143:     # quick fix to change literal into xml tag-matching
                   1144:     # will eventually have to write a separate builder module
1.122     matthew  1145:     # wordone=wordtwo becomes\<wordone\>[^\<] *wordtwo[^\<]*\<\/wordone\>
                   1146:     $matchexp =~ s/(\w+)\\=([\w\\\+]+)?# wordone=wordtwo is changed to 
                   1147:                  /\\<$1\\>?#           \<wordone\>
                   1148:                    \[\^\\<\]?#        [^\<]         
                   1149:                    \*$2\[\^\\<\]?#           *wordtwo[^\<]
                   1150:                    \*\\<\\\/$1\\>?#                        *\<\/wordone\>
                   1151:                    /g;
1.98      harris41 1152:     return $matchexp;
                   1153: }
                   1154: 
1.122     matthew  1155: ######################################################################
                   1156: ######################################################################
                   1157: 
                   1158: =pod 
                   1159: 
                   1160: =item &recursive_SQL_query_build() 
                   1161: 
1.126     matthew  1162: Recursively constructs an SQL query.  Takes as input $dkey and $pattern.
                   1163: 
1.122     matthew  1164: =cut
                   1165: 
                   1166: ######################################################################
                   1167: ######################################################################
1.98      harris41 1168: sub recursive_SQL_query_build {
                   1169:     my ($dkey,$pattern)=@_;
                   1170:     my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
                   1171:     return $pattern unless @matches;
                   1172:     foreach my $match (@matches) {
                   1173: 	$match=~/\[ (\w+)\s(.*) \]/;
                   1174: 	my ($key,$value)=($1,$2);
                   1175: 	my $replacement='';
                   1176: 	if ($key eq 'literal') {
                   1177: 	    $replacement="($dkey like \"\%$value\%\")";
                   1178: 	}
                   1179: 	elsif ($key eq 'not') {
                   1180: 	    $value=~s/like/not like/;
                   1181: #	    $replacement="($dkey not like $value)";
                   1182: 	    $replacement="$value";
                   1183: 	}
                   1184: 	elsif ($key eq 'and') {
                   1185: 	    $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                   1186: 	    $replacement="($1 AND $2)";
                   1187: 	}
                   1188: 	elsif ($key eq 'or') {
                   1189: 	    $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                   1190: 	    $replacement="($1 OR $2)";
                   1191: 	}
                   1192: 	substr($pattern,
                   1193: 	       index($pattern,$match),
                   1194: 	       length($match),
                   1195: 	       $replacement
                   1196: 	       );
                   1197:     }
                   1198:     &recursive_SQL_query_build($dkey,$pattern);
                   1199: }
1.22      harris41 1200: 
1.122     matthew  1201: ######################################################################
                   1202: ######################################################################
                   1203: 
                   1204: =pod 
                   1205: 
                   1206: =item &build_date_queries() 
                   1207: 
1.126     matthew  1208: Builds a SQL logic query to check time/date entries.
                   1209: Also reports errors (check for /^Incorrect/).
                   1210: 
1.122     matthew  1211: =cut
                   1212: 
                   1213: ######################################################################
                   1214: ######################################################################
1.98      harris41 1215: sub build_date_queries {
                   1216:     my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
                   1217: 	$lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
                   1218:     my @queries;
                   1219:     if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
                   1220: 	unless ($cmonth1 and $cday1 and $cyear1 and
                   1221: 		$cmonth2 and $cday2 and $cyear2) {
                   1222: 	    return "Incorrect entry for the creation date.  You must specify ".
                   1223: 		   "a starting month, day, and year and an ending month, ".
                   1224: 		   "day, and year.";
                   1225: 	}
                   1226: 	my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
                   1227: 	$cnumeric1+=0;
                   1228: 	my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
                   1229: 	$cnumeric2+=0;
                   1230: 	if ($cnumeric1>$cnumeric2) {
                   1231: 	    return "Incorrect entry for the creation date.  The starting ".
                   1232: 		   "date must occur before the ending date.";
                   1233: 	}
                   1234: 	my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
                   1235: 	           "$cyear2-$cmonth2-$cday2 23:59:59')";
                   1236: 	push @queries,$cquery;
                   1237:     }
                   1238:     if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
                   1239: 	unless ($lmonth1 and $lday1 and $lyear1 and
                   1240: 		$lmonth2 and $lday2 and $lyear2) {
                   1241: 	    return "Incorrect entry for the last revision date.  You must ".
                   1242: 		   "specify a starting month, day, and year and an ending ".
                   1243: 		   "month, day, and year.";
                   1244: 	}
                   1245: 	my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
                   1246: 	$lnumeric1+=0;
                   1247: 	my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
                   1248: 	$lnumeric2+=0;
                   1249: 	if ($lnumeric1>$lnumeric2) {
                   1250: 	    return "Incorrect entry for the last revision date.  The ".
                   1251: 		   "starting date must occur before the ending date.";
                   1252: 	}
                   1253: 	my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
                   1254: 	           "$lyear2-$lmonth2-$lday2 23:59:59')";
                   1255: 	push @queries,$lquery;
                   1256:     }
                   1257:     if (@queries) {
                   1258: 	return join(" AND ",@queries);
                   1259:     }
                   1260:     return '';
1.18      harris41 1261: }
1.6       harris41 1262: 
1.122     matthew  1263: ######################################################################
                   1264: ######################################################################
                   1265: 
                   1266: =pod 
                   1267: 
                   1268: =item &output_results() 
                   1269: 
                   1270: Format and output results based on a reply list.
                   1271: There are two windows that this function writes to.  The main search
                   1272: window ("srch") has a listing of the results.  A secondary window ("popwin")
                   1273: gives the status of the network search (time elapsed, number of machines
                   1274: contacted, etc.)
                   1275: 
                   1276: =cut
                   1277: 
                   1278: ######################################################################
                   1279: ######################################################################
1.18      harris41 1280: sub output_results {
1.126     matthew  1281: #    &Apache::lonnet::logthis("output_results:".time);
1.101     harris41 1282:     my $fnum; # search result counter
1.134     matthew  1283:     my ($mode,$r,$replyref,$hidden)=@_;
1.92      harris41 1284:     my %rhash=%{$replyref};
1.44      harris41 1285:     my $compiledresult='';
1.125     matthew  1286:     my $timeremain=300; # (seconds)
1.98      harris41 1287:     my $elapsetime=0;
1.93      harris41 1288:     my $resultflag=0;
                   1289:     my $tflag=1;
1.136     matthew  1290:     ##
                   1291:     ## Set viewing function
                   1292:     ##
1.139     matthew  1293:     my $viewfunction = $Views{$ENV{'form.viewselect'}};
1.136     matthew  1294:     if (!defined($viewfunction)) {
                   1295:         $r->print("Internal Error - Bad view selected.\n");
                   1296:         $r->rflush();
                   1297:         return;
                   1298:     }
1.125     matthew  1299:     #
1.93      harris41 1300:     # make query information persistent to allow for subsequent revision
1.133     matthew  1301:     my $persistent=&make_persistent(\%ENV);
1.136     matthew  1302:     #
                   1303:     # Begin producing output
1.98      harris41 1304:     $r->rflush();
1.136     matthew  1305:     #
1.98      harris41 1306:     # begin showing the cataloged results
1.129     matthew  1307:     my $action = "/adm/searchcat";
                   1308:     if ($mode eq 'Basic') { 
                   1309:         $action .= "?reqinterface=basic";
                   1310:     } elsif ($mode eq 'Advanced') {
                   1311:         $action .= "?reqinterface=advanced";
                   1312:     }
                   1313:     $r->print(<<CATALOGCONTROLS);
                   1314: <form name='results' method="post" action="$action">
1.118     www      1315: $hidden
1.98      harris41 1316: <input type='hidden' name='acts' value='' />
1.93      harris41 1317: <input type='button' value='Revise search request'
1.98      harris41 1318: onClick='this.form.submit();' />
                   1319: $importbutton
1.93      harris41 1320: $closebutton
                   1321: $persistent
1.98      harris41 1322: <hr />
                   1323: CATALOGCONTROLS
1.125     matthew  1324:     #
                   1325:     # make the pop-up window for status
                   1326:     $r->print(&make_popwin(%rhash));
1.92      harris41 1327:     $r->rflush();
1.125     matthew  1328:     ##
                   1329:     ## Prepare for the main loop below
                   1330:     ##
1.93      harris41 1331:     my $servercount=0;
1.98      harris41 1332:     my $hitcountsum=0;
1.125     matthew  1333:     my $servernum=(keys %rhash);
                   1334:     my $serversleft=$servernum;
                   1335:     ##
                   1336:     ## Run until we run out of time or we run out of servers
                   1337:     ##
                   1338:     while($serversleft && $timeremain) {
                   1339:       ##
                   1340:       ## %rhash has servers deleted from it as results come in 
                   1341:       ## (within the foreach loop below).
                   1342:       ##
                   1343:       foreach my $rkey (sort keys %rhash) {
1.126     matthew  1344: #        &Apache::lonnet::logthis("Server $rkey:".time);
1.93      harris41 1345: 	$servercount++;
                   1346: 	$compiledresult='';
1.92      harris41 1347: 	my $reply=$rhash{$rkey};
1.18      harris41 1348: 	my @results;
1.93      harris41 1349: 	if ($reply eq 'con_lost') {
1.125     matthew  1350: 	    &popwin_imgupdate($r,$rkey,"srvbad.gif");
                   1351: 	    $serversleft--;
                   1352:             delete $rhash{$rkey};
                   1353: 	} else {
                   1354:             # must do since 'use strict' checks for tainting
                   1355: 	    $reply=~/^([\.\w]+)$/; 
                   1356: 	    my $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
1.93      harris41 1357: 	    $reply=~/(.*?)\_/;
1.126     matthew  1358:             for (my $counter=0;$counter<2;$counter++) {
                   1359:                 if (-e $replyfile && ! -e "$replyfile.end") {
                   1360:                     &popwin_imgupdate($r,$rkey,"srvhalf.gif");
                   1361:                     &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
                   1362:                                '"still transferring..."'.';');
                   1363:                 }
                   1364:                 # Are we finished transferring data?
                   1365:                 if (-e "$replyfile.end") {
                   1366:                     $serversleft--;
                   1367:                     delete $rhash{$rkey};
                   1368:                     if (-s $replyfile) {
                   1369:                         &popwin_imgupdate($r,$rkey,"srvgood.gif");
                   1370:                         my $fh;
                   1371:                         unless ($fh=Apache::File->new($replyfile)){ 
                   1372:                             # Is it really appropriate to die on this error?
                   1373:                             $r->print('ERROR: file '.
                   1374:                                       $replyfile.' cannot be opened');
                   1375:                             return OK;
                   1376:                         }
                   1377:                         @results=<$fh> if $fh;
1.127     matthew  1378:                         my $hits =@results;
1.126     matthew  1379:                         &popwin_js($r,'popwin.hc["'.$rkey.'"]='.
1.127     matthew  1380:                                    $hits.';');
                   1381:                         $hitcountsum+=$hits;
1.126     matthew  1382:                         &popwin_js($r,'popwin.document.forms.popremain.'.
                   1383:                                    'numhits.value='.$hitcountsum.';');
                   1384:                     } else {
                   1385:                         &popwin_imgupdate($r,$rkey,"srvempty.gif");
                   1386:                         &popwin_js($r,'popwin.hc["'.$rkey.'"]=0;');
                   1387:                     }
                   1388:                     last;
                   1389:                 } # end of if ( -e "$replyfile.end")
                   1390:                 last unless $timeremain;
                   1391:                 sleep 1;    # wait for daemons to write files?
                   1392:                 $timeremain--;
                   1393:                 $elapsetime++;
                   1394:                 &popwin_js($r,"popwin.document.popremain.".
                   1395:                            "elapsetime.value=$elapsetime;");
1.93      harris41 1396: 	    }
1.117     matthew  1397: 	    &popwin_js($r,'popwin.document.whirly.'.
                   1398: 		       'src="/adm/lonIcons/lonanimend.gif";');
1.125     matthew  1399: 	} # end of if ($reply eq 'con_lost') else statement
1.126     matthew  1400:         my %Fields = undef;     # Holds the data to be sent to the various 
                   1401:                                 # *_view routines.
1.136     matthew  1402:         my ($extrashow,$customfields,$customhash) = 
                   1403:                                     &handle_custom_fields(\@results);
1.126     matthew  1404:         my @customfields = @$customfields;
                   1405:         my %customhash   = %$customhash;
1.142   ! matthew  1406: 	untie %groupsearch_db if (tied %groupsearch_db);
1.126     matthew  1407:         #
1.142   ! matthew  1408: 	if (! tie(%groupsearch_db,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
1.126     matthew  1409: 	    $r->print('<html><head></head><body>Unable to tie hash to db '.
                   1410:                       'file</body></html>');
                   1411:         } else {
1.101     harris41 1412: 	    if ($ENV{'form.launch'} eq '1') {
                   1413: 		&start_fresh_session();
                   1414: 	    }
                   1415: 	    foreach my $result (@results) {
                   1416: 		next if $result=~/^custom\=/;
                   1417: 		chomp $result;
                   1418: 		next unless $result;
1.126     matthew  1419:                 %Fields = &parse_raw_result($result,$rkey);
1.137     matthew  1420:                 #
                   1421:                 # Check copyright tags and skip results the user cannot use
                   1422:                 my (undef,undef,$resdom,$resname) = split('/',$Fields{'url'});
                   1423:                 # Check for priv
                   1424:                 if (($Fields{'copyright'} eq 'priv') && 
                   1425:                     (($ENV{'user.name'} ne $resname) &&
                   1426:                      ($ENV{'user.domain'} ne $resdom))) {
                   1427:                     next;
                   1428:                 }
                   1429:                 # Check for domain
                   1430:                 if (($Fields{'copyright'} eq 'domain') &&
                   1431:                     ($ENV{'user.domain'} ne $resdom)) {
                   1432:                     next;
                   1433:                 }
                   1434:                 #
1.126     matthew  1435: 		$Fields{'extrashow'}=$extrashow;
1.101     harris41 1436: 		if ($extrashow) {
                   1437: 		    foreach my $field (@customfields) {
                   1438: 			my $value='';
1.126     matthew  1439: 			$value = $1 if ($customhash{$Fields{'url'}}=~/\<{$field}[^\>]*\>(.*?)\<\/{$field}[^\>]*\>/s);
                   1440:                         $Fields{'extrashow'}=~s/\<\!\-\- $field \-\-\>/ $value/g;
                   1441:                     }
                   1442:                 }
                   1443:                 $compiledresult.="\n<p>\n";
                   1444:                 if ($ENV{'form.catalogmode'} eq 'interactive') {
                   1445:                     my $titleesc=$Fields{'title'};
                   1446:                     $titleesc=~s/\'/\\'/; # '
                   1447:                     $compiledresult.=<<END if ($ENV{'form.catalogmode'} eq 'interactive');
1.8       harris41 1448: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.126     matthew  1449: onClick="javascript:select_data('$titleesc','$Fields{'url'}')">
1.8       harris41 1450: </font>
1.98      harris41 1451: <br />
                   1452: END
1.115     harris41 1453:                 }
1.101     harris41 1454:                 if ($ENV{'form.catalogmode'} eq 'groupsearch') {
                   1455: 		    $fnum+=0;
1.142   ! matthew  1456: 		    $groupsearch_db{"pre_${fnum}_link"}=$Fields{'url'};
        !          1457: 		    $groupsearch_db{"pre_${fnum}_title"}=$Fields{'title'};
1.101     harris41 1458: 		    $compiledresult.=<<END;
1.118     www      1459: <font size='-1'>
                   1460: <input type="checkbox" name="returnvalues" value="SELECT"
1.98      harris41 1461: onClick="javascript:queue($fnum)" />
                   1462: </font>
                   1463: <br />
1.8       harris41 1464: END
1.101     harris41 1465: # <input type="hidden" name="title$fnum" value="$title" />
                   1466: # <input type="hidden" name="url$fnum" value="$url" />
                   1467:                     $fnum++;
                   1468: 		}
1.136     matthew  1469:                 # Render the result into html
                   1470:                 $compiledresult.= &$viewfunction(%Fields, hostname => $rkey );
1.130     matthew  1471:                 if ($compiledresult or $servercount!=$servernum) {
                   1472:                     $compiledresult.="<hr align='left' width='200' noshade />";
                   1473:                 }
1.101     harris41 1474:             }
1.142   ! matthew  1475:             untie %groupsearch_db;
1.18      harris41 1476:         }
1.93      harris41 1477: 	if ($compiledresult) {
                   1478: 	    $resultflag=1;
1.126     matthew  1479:             $r->print($compiledresult);
1.18      harris41 1480: 	}
1.126     matthew  1481:       } # End of foreach loop over servers remaining
                   1482:     }   # End of big loop - while($serversleft && $timeremain)
1.93      harris41 1483:     unless ($resultflag) {
                   1484:         $r->print("\nThere were no results that matched your query\n");
1.43      harris41 1485:     }
1.135     matthew  1486:     $r->print('<script type="text/javascript">'.'popwin.close()</script>'.
                   1487:               "\n"); 
1.126     matthew  1488:     $r->print("</body>\n</html>\n");
1.135     matthew  1489:     $r->rflush(); 
1.126     matthew  1490:     return;
                   1491: }
                   1492: 
                   1493: ###########################################################
                   1494: ###########################################################
                   1495: 
                   1496: =pod
                   1497: 
                   1498: =item &parse_raw_result()
                   1499: 
                   1500: Takes a line from the file of results and parse it.  Returns a hash 
                   1501: with keys for the following fields:
                   1502: 'title', 'author', 'subject', 'url', 'keywords', 'version', 'notes', 
                   1503: 'abstract', 'mime', 'lang', 'owner', 'copyright', 'creationdate', 
                   1504: 'lastrevisiondate'.
                   1505: 
                   1506: In addition, the following tags are set by calling the appropriate 
                   1507: lonnet function: 'language', 'cprtag', 'mimetag'.
                   1508: 
                   1509: The 'title' field is set to "Untitled" if the title field is blank.
                   1510: 
                   1511: 'abstract' and 'keywords' are truncated to 200 characters.
                   1512: 
                   1513: =cut
                   1514: 
                   1515: ###########################################################
                   1516: ###########################################################
                   1517: sub parse_raw_result {
                   1518:     my ($result,$hostname) = @_;
                   1519:     # Check for a comma - if it is there then we do not need to unescape the
                   1520:     # string.  There seems to be some kind of problem with some items in
                   1521:     # the database - the entire string gets sent out unescaped...?
                   1522:     unless ($result =~ /,/) {
                   1523:         $result = &Apache::lonnet::unescape($result);
                   1524:     }
                   1525:     my @fields=map {
                   1526:         &Apache::lonnet::unescape($_);
                   1527:     } (split(/\,/,$result));
                   1528:     my ($title,$author,$subject,$url,$keywords,$version,
                   1529:         $notes,$abstract,$mime,$lang,
                   1530:         $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
                   1531:     my %Fields = 
                   1532:         ( title     => &Apache::lonnet::unescape($title),
                   1533:           author    => &Apache::lonnet::unescape($author),
                   1534:           subject   => &Apache::lonnet::unescape($subject),
                   1535:           url       => &Apache::lonnet::unescape($url),
                   1536:           keywords  => &Apache::lonnet::unescape($keywords),
                   1537:           version   => &Apache::lonnet::unescape($version),
                   1538:           notes     => &Apache::lonnet::unescape($notes),
                   1539:           abstract  => &Apache::lonnet::unescape($abstract),
                   1540:           mime      => &Apache::lonnet::unescape($mime),
                   1541:           lang      => &Apache::lonnet::unescape($lang),
                   1542:           owner     => &Apache::lonnet::unescape($owner),
                   1543:           copyright => &Apache::lonnet::unescape($copyright),
                   1544:           creationdate     => &Apache::lonnet::unescape($creationdate),
                   1545:           lastrevisiondate => &Apache::lonnet::unescape($lastrevisiondate)
                   1546:         );
                   1547:     $Fields{'language'} = 
                   1548:         &Apache::loncommon::languagedescription($Fields{'lang'});
                   1549:     $Fields{'copyrighttag'} =
                   1550:         &Apache::loncommon::copyrightdescription($Fields{'copyright'});
                   1551:     $Fields{'mimetag'} =
                   1552:         &Apache::loncommon::filedescription($Fields{'mime'});
1.134     matthew  1553:     if ($Fields{'author'}=~/^(\s*|error)$/) {
                   1554:         $Fields{'author'}="Unknown Author";
                   1555:     }
1.126     matthew  1556:     # Put spaces in the keyword list, if needed.
                   1557:     $Fields{'keywords'}=~ s/,([A-z])/, $1/g; 
                   1558:     if ($Fields{'title'}=~ /^\s*$/ ) { 
                   1559:         $Fields{'title'}='Untitled'; 
                   1560:     }
                   1561:     unless ($ENV{'user.adv'}) {
                   1562:         $Fields{'keywords'} = '- not displayed -';
                   1563:         $Fields{'notes'}    = '- not displayed -';
                   1564:         $Fields{'abstract'} = '- not displayed -';
                   1565:         $Fields{'subject'}  = '- not displayed -';
                   1566:     }
                   1567:     if (length($Fields{'abstract'})>200) {
                   1568:         $Fields{'abstract'} = 
                   1569:             substr($Fields{'abstract'},0,200).'...';
                   1570:     }
                   1571:     if (length($Fields{'keywords'})>200) {
                   1572:         $Fields{'keywords'} =
                   1573:             substr($Fields{'keywords'},0,200).'...';
                   1574:     }
                   1575:     return %Fields;
                   1576: }
                   1577: 
                   1578: ###########################################################
                   1579: ###########################################################
                   1580: 
                   1581: =pod
                   1582: 
                   1583: =item &handle_custom_fields()
                   1584: 
                   1585: =cut
                   1586: 
                   1587: ###########################################################
                   1588: ###########################################################
                   1589: sub handle_custom_fields {
                   1590:     my @results = @{shift()};
                   1591:     my $customshow='';
                   1592:     my $extrashow='';
                   1593:     my @customfields;
                   1594:     if ($ENV{'form.customshow'}) {
                   1595:         $customshow=$ENV{'form.customshow'};
                   1596:         $customshow=~s/[^\w\s]//g;
                   1597:         my @fields=map {
                   1598:             "<font color=\"#008000\">$_:</font><!-- $_ -->";
                   1599:         } split(/\s+/,$customshow);
                   1600:         @customfields=split(/\s+/,$customshow);
                   1601:         if ($customshow) {
                   1602:             $extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
                   1603:         }
                   1604:     }
                   1605:     my $customdata='';
                   1606:     my %customhash;
                   1607:     foreach my $result (@results) {
                   1608:         if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
                   1609:             my $tmp=$result;
                   1610:             $tmp=~s/^custom\=//;
                   1611:             my ($k,$v)=map {&Apache::lonnet::unescape($_);
                   1612:                         } split(/\,/,$tmp);
                   1613:             $customhash{$k}=$v;
                   1614:         }
                   1615:     }
                   1616:     return ($extrashow,\@customfields,\%customhash);
1.41      harris41 1617: }
                   1618: 
1.122     matthew  1619: ######################################################################
                   1620: ######################################################################
                   1621: 
1.125     matthew  1622: =pod
                   1623: 
                   1624: =item &search_results_header
                   1625: 
1.130     matthew  1626: Output the proper html headers and javascript code to deal with different 
                   1627: calling modes.
                   1628: 
                   1629: Takes most inputs directly from %ENV, except $mode.  
                   1630: 
                   1631: =over 4
                   1632: 
                   1633: =item $mode is either (at this writing) 'Basic' or 'Advanced'
                   1634: 
                   1635: =back
1.126     matthew  1636: 
1.130     matthew  1637: The following environment variables are checked:
1.126     matthew  1638: 
                   1639: =over 4
                   1640: 
                   1641: =item 'form.catalogmode' 
                   1642: 
                   1643: Checked for 'interactive' and 'groupsearch'.
                   1644: 
                   1645: =item 'form.mode'
                   1646: 
                   1647: Checked for existance & 'edit' mode.
                   1648: 
                   1649: =item 'form.form'
                   1650: 
                   1651: =item 'form.element'
                   1652: 
                   1653: =back
                   1654: 
1.125     matthew  1655: =cut
                   1656: 
                   1657: ######################################################################
                   1658: ######################################################################
                   1659: sub search_results_header {
1.130     matthew  1660:     my ($mode) = @_;
                   1661:     $mode = lc($mode);
                   1662:     my $title;
                   1663:     if ($mode eq 'advanced') {
                   1664:         $title = "Advanced Search Results";
                   1665:     } elsif ($mode eq 'basic') {
                   1666:         $title = "Basic Search Results";
                   1667:     }
1.125     matthew  1668:     my $result = '';
                   1669:     # output beginning of search page
                   1670:     $result.=<<BEGINNING;
                   1671: <html>
                   1672: <head>
1.130     matthew  1673: <title>$title</title>
1.125     matthew  1674: BEGINNING
                   1675:     # conditional output of script functions dependent on the mode in
                   1676:     # which the search was invoked
                   1677:     if ($ENV{'form.catalogmode'} eq 'interactive'){
                   1678: 	if (! exists($ENV{'form.mode'}) || $ENV{'form.mode'} ne 'edit') {
                   1679:             $result.=<<SCRIPT;
                   1680: <script type="text/javascript">
                   1681:     function select_data(title,url) {
                   1682: 	changeTitle(title);
                   1683: 	changeURL(url);
                   1684: 	self.close();
                   1685:     }
                   1686:     function changeTitle(val) {
                   1687: 	if (opener.inf.document.forms.resinfo.elements.t) {
                   1688: 	    opener.inf.document.forms.resinfo.elements.t.value=val;
                   1689: 	}
                   1690:     }
                   1691:     function changeURL(val) {
                   1692: 	if (opener.inf.document.forms.resinfo.elements.u) {
                   1693: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
                   1694: 	}
                   1695:     }
                   1696: </script>
                   1697: SCRIPT
                   1698:         } elsif ($ENV{'form.mode'} eq 'edit') {
                   1699:             my $form = $ENV{'form.form'};
                   1700:             my $element = $ENV{'form.element'};
                   1701:             $result.=<<SCRIPT;
                   1702: <script type="text/javascript">
                   1703: function select_data(title,url) {
                   1704:     changeURL(url);
                   1705:     self.close();
                   1706: }
                   1707: function changeTitle(val) {
                   1708: }
                   1709: function changeURL(val) {
                   1710:     if (window.opener.document) {
                   1711:         window.opener.document.forms["$form"].elements["$element"].value=val;
                   1712:     } else {
                   1713: 	var url = 'forms[\"$form\"].elements[\"$element\"].value';
                   1714:         alert("Unable to transfer data to "+url);
                   1715:     }
                   1716: }
                   1717: </script>
                   1718: SCRIPT
                   1719:         }
                   1720:     }
                   1721:     $result.=<<SCRIPT if $ENV{'form.catalogmode'} eq 'groupsearch';
                   1722: <script type="text/javascript">
                   1723:     function select_data(title,url) {
                   1724: //	alert('DEBUG: Should be storing '+title+' and '+url);
                   1725:     }
                   1726:     function queue(val) {
                   1727: 	if (eval("document.forms.results.returnvalues["+val+"].checked")) {
                   1728: 	    document.forms.results.acts.value+='1a'+val+'b';
                   1729: 	}
                   1730: 	else {
                   1731: 	    document.forms.results.acts.value+='0a'+val+'b';
                   1732: 	}
                   1733:     }
                   1734:     function select_group() {
                   1735: 	window.location=
                   1736:     "/adm/groupsort?mode=$ENV{'form.mode'}&catalogmode=groupsearch&acts="+
                   1737: 	    document.forms.results.acts.value;
                   1738:     }
                   1739: </script>
                   1740: SCRIPT
                   1741:     $result.=<<SCRIPT;
                   1742: <script type="text/javascript">
                   1743:     function displayinfo(val) {
                   1744: 	popwin.document.forms.popremain.sdetails.value=val;
                   1745:     }
                   1746:     function openhelp(val) {
                   1747: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                   1748: 	     'scrollbars=1,width=400,height=300');
                   1749: 	openhelpwin.focus();
                   1750:     }
                   1751:     function abortsearch(val) {
                   1752: 	popwin.close();
                   1753:     }
                   1754: </script>
                   1755: SCRIPT
1.130     matthew  1756:     $result.=<<END;
                   1757: </head>
                   1758: <body bgcolor="#ffffff">
                   1759: <img align=right src=/adm/lonIcons/lonlogos.gif>
                   1760: <h1>$title</h1>
                   1761: END
1.125     matthew  1762:     return $result;
                   1763: }
                   1764: 
                   1765: ######################################################################
                   1766: ######################################################################
                   1767: 
                   1768: =pod
                   1769: 
                   1770: =item &make_popwin()
                   1771: 
                   1772: Returns html with javascript in it to open up the status window.
                   1773: 
                   1774: =cut
                   1775: 
                   1776: ######################################################################
                   1777: ######################################################################
                   1778: sub make_popwin {
                   1779:     my %rhash = @_;
                   1780:     my $servernum=(keys %rhash);
                   1781:     my $hcinit;
                   1782:     my $grid="'<br />'+\n";
                   1783:     # $sn is the server number, used ONLY to make sure we have
                   1784:     # rows of 10 each.  No longer used to index images.
                   1785:     my $sn=1;
                   1786:     foreach my $sk (sort keys %rhash) {
                   1787: 	$grid.="'<a href=\"";
                   1788: 	$grid.="javascript:opener.displayinfo('+";
                   1789: 	$grid.="\"'\"+'";
                   1790: 	$grid.=$sk;
                   1791: 	my $hc;
                   1792: 	if ($rhash{$sk} eq 'con_lost') {
1.135     matthew  1793: 	    $hc="BAD CONNECTION ";
1.125     matthew  1794: 	}
                   1795: 	else {
                   1796: 	    $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
                   1797: 	    $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
                   1798: 	}
                   1799: 	$grid.=" hitcount=".$hc;
1.127     matthew  1800: 	$grid.=" domain=".$Apache::lonnet::hostdom{$sk};
                   1801: 	$grid.=" IP=".$Apache::lonnet::hostip{$sk};
1.125     matthew  1802: 	# '+"'"+'">'+
                   1803: 	$grid.="'+\"'\"+')\">'+";
                   1804: 	$grid.="\n";
1.127     matthew  1805: 	$grid.="'<img border=\"0\" name=\"img_".$Apache::lonnet::hostdom{$sk}.
                   1806:             '_'.$sk."\" src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk.
                   1807:                 "\" /></a>'+\n";
1.125     matthew  1808: 	$grid.="'<br />'+\n" unless $sn%10;
                   1809:         $sn++;
                   1810:     }
                   1811:     my $result.=<<ENDPOP;
                   1812: <script type="text/javascript">
                   1813:     popwin=open('','popwin','scrollbars=1,width=400,height=220');
                   1814:     popwin.focus();
                   1815:     popwin.document.writeln('<'+'html>');
                   1816:     popwin.document.writeln('<'+'head>');
                   1817:     popwin.document.writeln('<'+'script>');
                   1818:     popwin.document.writeln('hc=new Array();$hcinit');
                   1819:     popwin.document.writeln('<'+'/script>');
                   1820:     popwin.document.writeln('<'+'/head>'+
                   1821:         '<'+'body bgcolor="#FFFFFF">'+
                   1822: 	'<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
                   1823: 	'lonanim.gif" '+
                   1824: 	'alt="animated logo" />'+
                   1825: 	'<'+'h3>Search Results Progress<'+'/h3>'+
                   1826:         '<'+'form name="popremain">'+
                   1827:         '<'+'tt>'+
                   1828: 	'<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
                   1829: 	'<'+'br />SCANNING $servernum SERVERS'+
                   1830: 	'<'+'br clear="all" />Number of record hits found '+
                   1831: 	'<'+'input type="text" size="10" name="numhits"'+
                   1832: 	' value="0" />'+
                   1833: 	'<'+'br clear="all" />Time elapsed '+
                   1834: 	'<'+'input type="text" size="10" name="elapsetime"'+
                   1835: 	' value="0" />'+
                   1836: 	'<'+'br />'+
                   1837: 	'SERVER GRID (click on any cell for details)'+
                   1838:         $grid
                   1839:         '<'+'br />'+
                   1840: 	'Server details '+
                   1841: 	'<'+'input type="text" size="35" name="sdetails"'+
                   1842: 	' value="" />'+
                   1843: 	'<'+'br />'+
                   1844: 	' <'+'input type="button" name="button"'+
                   1845: 	' value="close this window" '+
                   1846: 	' onClick="javascript:opener.abortsearch()" />'+
                   1847: 	' <'+'input type="button" name="button"'+
                   1848: 	' value="help" onClick="javascript:opener.openhelp()" />'+
                   1849: 	'<'+'/tt>'+
                   1850:         '<'+'/form>'+
                   1851:         '<'+'/body><'+'/html>');
                   1852:     popwin.document.close();
                   1853: </script>
                   1854: ENDPOP
                   1855:     return $result;
                   1856: }
                   1857: 
                   1858: ######################################################################
                   1859: ######################################################################
                   1860: 
1.122     matthew  1861: =pod 
                   1862: 
                   1863: =item Metadata Viewing Functions
                   1864: 
                   1865: Output is a HTML-ified string.
                   1866: Input arguments are title, author, subject, url, keywords, version,
                   1867: notes, short abstract, mime, language, creation date,
1.126     matthew  1868: last revision date, owner, copyright, hostname, and
1.122     matthew  1869: extra custom metadata to show.
                   1870: 
                   1871: =over 4
                   1872: 
                   1873: =item &detailed_citation_view() 
                   1874: 
                   1875: =cut
                   1876: 
                   1877: ######################################################################
                   1878: ######################################################################
1.50      harris41 1879: sub detailed_citation_view {
1.126     matthew  1880:     my %values = @_;
1.50      harris41 1881:     my $result=<<END;
1.126     matthew  1882: <h3><a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
                   1883:     target='search_preview'>$values{'title'}</a></h3>
1.56      harris41 1884: <p>
1.130     matthew  1885: <b>$values{'author'}</b>, <i>$values{'owner'}</i><br />
                   1886: 
                   1887: <b>Subject:       </b> $values{'subject'}<br />
                   1888: <b>Keyword(s):    </b> $values{'keywords'}<br />
                   1889: <b>Notes:         </b> $values{'notes'}<br />
                   1890: <b>MIME Type:     </b> $values{'mimetag'}<br />
                   1891: <b>Language:      </b> $values{'language'}<br />
                   1892: <b>Copyright/Distribution:</b> $values{'cprtag'}<br />
1.78      harris41 1893: </p>
1.126     matthew  1894: $values{'extrashow'}
1.78      harris41 1895: <p>
1.126     matthew  1896: $values{'shortabstract'}
1.50      harris41 1897: </p>
                   1898: END
                   1899:     return $result;
                   1900: }
                   1901: 
1.122     matthew  1902: ######################################################################
                   1903: ######################################################################
                   1904: 
                   1905: =pod 
                   1906: 
                   1907: =item &summary_view() 
                   1908: 
                   1909: =cut
                   1910: 
                   1911: ######################################################################
                   1912: ######################################################################
1.50      harris41 1913: sub summary_view {
1.126     matthew  1914:     my %values = @_;
1.50      harris41 1915:     my $result=<<END;
1.126     matthew  1916: <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
                   1917:    target='search_preview'>$values{'author'}</a><br />
                   1918: $values{'title'}<br />
                   1919: $values{'owner'} -- $values{'lastrevisiondate'}<br />
                   1920: $values{'copyrighttag'}<br />
                   1921: $values{'extrashow'}
1.50      harris41 1922: </p>
                   1923: END
                   1924:     return $result;
                   1925: }
                   1926: 
1.122     matthew  1927: ######################################################################
                   1928: ######################################################################
                   1929: 
                   1930: =pod 
                   1931: 
                   1932: =item &fielded_format_view() 
                   1933: 
                   1934: =cut
                   1935: 
                   1936: ######################################################################
                   1937: ######################################################################
1.50      harris41 1938: sub fielded_format_view {
1.126     matthew  1939:     my %values = @_;
1.50      harris41 1940:     my $result=<<END;
1.126     matthew  1941: <b>URL: </b> <a href="http://$ENV{'HTTP_HOST'}$values{'url'}" 
                   1942:               target='search_preview'>$values{'url'}</a>
1.56      harris41 1943: <br />
1.126     matthew  1944: <b>Title:</b> $values{'title'}<br />
                   1945: <b>Author(s):</b> $values{'author'}<br />
                   1946: <b>Subject:</b> $values{'subject'}<br />
                   1947: <b>Keyword(s):</b> $values{'keywords'}<br />
                   1948: <b>Notes:</b> $values{'notes'}<br />
                   1949: <b>MIME Type:</b> $values{'mimetag'}<br />
                   1950: <b>Language:</b> $values{'language'}<br />
                   1951: <b>Creation Date:</b> $values{'creationdate'}<br />
                   1952: <b>Last Revision Date:</b> $values{'lastrevisiondate'}<br />
                   1953: <b>Publisher/Owner:</b> $values{'owner'}<br />
                   1954: <b>Copyright/Distribution:</b> $values{'copyrighttag'}<br />
                   1955: <b>Repository Location:</b> $values{'hostname'}<br />
                   1956: <b>Abstract:</b> $values{'shortabstract'}<br />
                   1957: $values{'extrashow'}
1.50      harris41 1958: </p>
                   1959: END
                   1960:     return $result;
                   1961: }
                   1962: 
1.122     matthew  1963: ######################################################################
                   1964: ######################################################################
                   1965: 
                   1966: =pod 
                   1967: 
                   1968: =item &xml_sgml_view() 
                   1969: 
                   1970: =back 
                   1971: 
                   1972: =cut
                   1973: 
                   1974: ######################################################################
                   1975: ######################################################################
1.50      harris41 1976: sub xml_sgml_view {
1.126     matthew  1977:     my %values = @_;
1.50      harris41 1978:     my $result=<<END;
1.56      harris41 1979: <pre>
                   1980: &lt;LonCapaResource&gt;
1.126     matthew  1981: &lt;url&gt;$values{'url'}&lt;/url&gt;
                   1982: &lt;title&gt;$values{'title'}&lt;/title&gt;
                   1983: &lt;author&gt;$values{'author'}&lt;/author&gt;
                   1984: &lt;subject&gt;$values{'subject'}&lt;/subject&gt;
                   1985: &lt;keywords&gt;$values{'keywords'}&lt;/keywords&gt;
                   1986: &lt;notes&gt;$values{'notes'}&lt;/notes&gt;
1.56      harris41 1987: &lt;mimeInfo&gt;
1.126     matthew  1988: &lt;mime&gt;$values{'mime'}&lt;/mime&gt;
                   1989: &lt;mimetag&gt;$values{'mimetag'}&lt;/mimetag&gt;
1.56      harris41 1990: &lt;/mimeInfo&gt;
                   1991: &lt;languageInfo&gt;
1.126     matthew  1992: &lt;language&gt;$values{'lang'}&lt;/language&gt;
                   1993: &lt;languagetag&gt;$values{'language'}&lt;/languagetag&gt;
1.56      harris41 1994: &lt;/languageInfo&gt;
1.126     matthew  1995: &lt;creationdate&gt;$values{'creationdate'}&lt;/creationdate&gt;
                   1996: &lt;lastrevisiondate&gt;$values{'lastrevisiondate'}&lt;/lastrevisiondate&gt;
                   1997: &lt;owner&gt;$values{'owner'}&lt;/owner&gt;
1.56      harris41 1998: &lt;copyrightInfo&gt;
1.126     matthew  1999: &lt;copyright&gt;$values{'copyright'}&lt;/copyright&gt;
                   2000: &lt;copyrighttag&gt;$values{'copyrighttag'}&lt;/copyrighttag&gt;
1.56      harris41 2001: &lt;/copyrightInfo&gt;
1.126     matthew  2002: &lt;repositoryLocation&gt;$values{'hostname'}&lt;/repositoryLocation&gt;
                   2003: &lt;shortabstract&gt;$values{'shortabstract'}&lt;/shortabstract&gt;
1.57      harris41 2004: &lt;/LonCapaResource&gt;
1.56      harris41 2005: </pre>
1.126     matthew  2006: $values{'extrashow'}
1.50      harris41 2007: END
                   2008:     return $result;
1.60      harris41 2009: }
                   2010: 
1.122     matthew  2011: ######################################################################
                   2012: ######################################################################
                   2013: 
                   2014: =pod 
                   2015: 
                   2016: =item &filled() see if field is filled.
                   2017: 
                   2018: =cut
                   2019: 
                   2020: ######################################################################
                   2021: ######################################################################
1.98      harris41 2022: sub filled {
                   2023:     my ($field)=@_;
                   2024:     if ($field=~/\S/ && $field ne 'any') {
                   2025: 	return 1;
1.61      harris41 2026:     }
1.98      harris41 2027:     else {
                   2028: 	return 0;
1.61      harris41 2029:     }
1.60      harris41 2030: }
                   2031: 
1.122     matthew  2032: ######################################################################
                   2033: ######################################################################
                   2034: 
                   2035: =pod 
                   2036: 
                   2037: =item &output_blank_field_error()
                   2038: 
                   2039: =cut
                   2040: 
                   2041: ######################################################################
                   2042: ######################################################################
1.98      harris41 2043: sub output_blank_field_error {
                   2044:     my ($r)=@_;
                   2045:     # make query information persistent to allow for subsequent revision
1.133     matthew  2046:     my $persistent=&make_persistent(\%ENV);
1.98      harris41 2047: 
                   2048:     $r->print(<<BEGINNING);
                   2049: <html>
                   2050: <head>
                   2051: <title>The LearningOnline Network with CAPA</title>
                   2052: BEGINNING
                   2053:     $r->print(<<RESULTS);
                   2054: </head>
                   2055: <body bgcolor="#ffffff">
                   2056: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
                   2057: <h1>Search Catalog</h1>
                   2058: <form method="post" action="/adm/searchcat">
                   2059: $persistent
                   2060: <input type='button' value='Revise search request'
                   2061: onClick='this.form.submit();' />
                   2062: $closebutton
                   2063: <hr />
                   2064: <h3>Helpful Message</h3>
                   2065: <p>
                   2066: Incorrect search query due to blank entry fields.
                   2067: You need to fill in the relevant
                   2068: fields on the search page in order for a query to be
                   2069: processed.
                   2070: </p>
                   2071: </body>
                   2072: </html>
                   2073: RESULTS
                   2074: }
                   2075: 
1.122     matthew  2076: ######################################################################
                   2077: ######################################################################
                   2078: 
                   2079: =pod 
                   2080: 
                   2081: =item &output_date_error()
                   2082: 
                   2083: Output a full html page with an error message.
                   2084: 
                   2085: =cut
                   2086: 
                   2087: ######################################################################
                   2088: ######################################################################
1.60      harris41 2089: sub output_date_error {
                   2090:     my ($r,$message)=@_;
                   2091:     # make query information persistent to allow for subsequent revision
1.133     matthew  2092:     my $persistent=&make_persistent(\%ENV);
1.60      harris41 2093: 
1.122     matthew  2094:     $r->print(<<RESULTS);
1.60      harris41 2095: <html>
                   2096: <head>
                   2097: <title>The LearningOnline Network with CAPA</title>
                   2098: </head>
                   2099: <body bgcolor="#ffffff">
1.98      harris41 2100: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60      harris41 2101: <h1>Search Catalog</h1>
                   2102: <form method="post" action="/adm/searchcat">
                   2103: $persistent
                   2104: <input type='button' value='Revise search request'
1.98      harris41 2105: onClick='this.form.submit();' />
1.60      harris41 2106: $closebutton
1.98      harris41 2107: <hr />
1.60      harris41 2108: <h3>Helpful Message</h3>
                   2109: <p>
                   2110: $message
                   2111: </p>
                   2112: </body>
                   2113: </html>
                   2114: RESULTS
1.101     harris41 2115: }
                   2116: 
1.122     matthew  2117: ######################################################################
                   2118: ######################################################################
                   2119: 
                   2120: =pod 
                   2121: 
                   2122: =item &start_fresh_session()
                   2123: 
1.142   ! matthew  2124: Cleans the global %groupsearch_db by removing all fields which begin with
1.122     matthew  2125: 'pre_' or 'store'.
                   2126: 
                   2127: =cut
                   2128: 
                   2129: ######################################################################
                   2130: ######################################################################
1.101     harris41 2131: sub start_fresh_session {
1.142   ! matthew  2132:     delete $groupsearch_db{'mode_catalog'};
        !          2133:     foreach (keys %groupsearch_db) {
1.101     harris41 2134:         if ($_ =~ /^pre_/) {
1.142   ! matthew  2135:             delete $groupsearch_db{$_};
1.101     harris41 2136:         }
                   2137:         if ($_ =~ /^store/) {
1.142   ! matthew  2138: 	    delete $groupsearch_db{$_};
1.101     harris41 2139: 	}
1.109     harris41 2140:     }
1.3       harris41 2141: }
1.117     matthew  2142: 
1.122     matthew  2143: ######################################################################
                   2144: ######################################################################
                   2145: 
                   2146: =pod 
                   2147: 
                   2148: =item &popwin_js() send javascript to popwin
                   2149: 
                   2150: =cut
                   2151: 
                   2152: ######################################################################
                   2153: ######################################################################
1.117     matthew  2154: sub popwin_js {
                   2155:     # Print javascript out to popwin, but make sure we dont generate
                   2156:     # any javascript errors in doing so.
                   2157:     my ($r,$text) = @_;
                   2158:     $r->print(<<"END");
                   2159: <script type="text/javascript">
                   2160:     if (! popwin.closed) {
                   2161: 	$text
                   2162:     }
                   2163: </script>
                   2164: END
                   2165:     $r->rflush();
                   2166: }
                   2167: 
1.122     matthew  2168: ######################################################################
                   2169: ######################################################################
                   2170: 
                   2171: =pod 
                   2172: 
                   2173: =item &popwin_imgupdate()
                   2174: 
1.125     matthew  2175: Send a given image (and its location) out to the browser.  Takes as 
                   2176: input $r, loncapa server id, and an icon URL.
                   2177: 
1.122     matthew  2178: =cut
                   2179: 
                   2180: ######################################################################
                   2181: ######################################################################
1.117     matthew  2182: sub popwin_imgupdate {
1.125     matthew  2183:     my ($r,$server,$icon) = @_;
1.127     matthew  2184:     &popwin_js($r,'popwin.document.img_'.$Apache::lonnet::hostdom{$server}.
                   2185:                '_'.$server.'.'.'src="/adm/lonIcons/'.$icon.'";');
1.117     matthew  2186: }    
1.1       www      2187: 
                   2188: 1;
1.98      harris41 2189: 
1.1       www      2190: __END__
1.105     harris41 2191: 
1.121     matthew  2192: =pod
1.105     harris41 2193: 
1.121     matthew  2194: =back 
1.105     harris41 2195: 
                   2196: =cut

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