File:  [LON-CAPA] / loncom / interface / lonsearchcat.pm
Revision 1.129: download - view: text, annotated - select for diffs
Tue Jun 25 15:08:59 2002 UTC (21 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Advanced search interface:
    Changed valid field directions.
    Place submit, reset, view select buttons at head and foot of page.
    Removed "Limit by" text (it should be obvious).
    Changed mime type to 'file extension' fill-in box instead of select box.
    Wrapped part of search interface in <table></table>
&searchphrasefield
    Inserted table tags.
    Changed field length from 80 to 50.
    Removed repetative instructions for entering fields.
&selectbox
    Added POD documentation
    changed $value to $default.
    Provide default function for $functionref.

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

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