File:  [LON-CAPA] / loncom / interface / lonsearchcat.pm
Revision 1.135: download - view: text, annotated - select for diffs
Wed Jul 3 20:10:14 2002 UTC (21 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: version_0_4, stable_2002_july, HEAD
Minor aesthetic cleanups.
Fixed a 'bug' where selecting the category of files would result in values
being set for mime type (aka file extension).

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

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