File:  [LON-CAPA] / loncom / interface / lonsearchcat.pm
Revision 1.131: download - view: text, annotated - select for diffs
Wed Jun 26 18:19:41 2002 UTC (21 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
&advanced_search_form
    Added file categories selection list.
&selectbox
    Removed <br /> between text and selection form.
&output_results
    Handle the file categories via mime type.  Currently the mime fill-in
        form and the file categories selection box are mutually exclusive,
        with the latter overriding the former.

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

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