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

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

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