Annotation of loncom/interface/lonsearchcat.pm, revision 1.122

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

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