File:  [LON-CAPA] / loncom / interface / lonsearchcat.pm
Revision 1.127: download - view: text, annotated - select for diffs
Mon Jun 24 15:26:28 2002 UTC (21 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Removed global variables:
   %hostdomains
   %hostips
   %hitcount
   $yourself
Removed BEGIN block as all it did was initalize the globals above.

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

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