File:  [LON-CAPA] / loncom / interface / lonsearchcat.pm
Revision 1.132: download - view: text, annotated - select for diffs
Thu Jun 27 14:46:00 2002 UTC (21 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Added domain restricted search interface to &advanced_search_form.
Support added in &advancedsearch.
NOTES:
    Assumes no domain will be named 'any'.
    Standalone machines do not get to choose - the dialog box does not appear.
    Selections are not currently restored on 'revise search request'.
        This is my next priority.
    Selecting none of the domains is the same as selecting 'any'.
    Selecting 'any domain' and other domains as well will search all domains.
    There are no plans for machine-level restrictions at this time.

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

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