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

1.98      harris41    1: # The LearningOnline Network with CAPA
                      2: #
1.1       www         3: # Search Catalog
                      4: #
1.97      harris41    5: # YEAR=2001
1.2       harris41    6: # 03/08/2001 Scott Harrison
1.42      harris41    7: # Scott Harrison: 03/12/2001, 03/13/2001, 03/14/2001, 03/15/2001, 03/19/2001
1.91      harris41    8: # Scott Harrison: 03/20/2001, 03/21/2001, 03/22/2001, 03/26/2001, 03/27/2001
1.98      harris41    9: # Scott Harrison: 04/02/2001, 08/15/2001, 08/24/2001, 08/25/2001
1.102     harris41   10: # 10/12,10/14,10/15,10/16 Scott Harrison
1.98      harris41   11: ###############################################################################
                     12: ##                                                                           ##
                     13: ## ORGANIZATION OF THIS PERL MODULE                                          ##
                     14: ##                                                                           ##
                     15: ## 1. Description of functions                                               ##
                     16: ## 2. Modules used by this module                                            ##
                     17: ## 3. Choices for different output views (detailed, summary, xml, etc)       ##
                     18: ## 4. BEGIN block (to be run once after compilation)                         ##
                     19: ## 5. Handling routine called via Apache and mod_perl                        ##
                     20: ## 6. Other subroutines                                                      ##
                     21: ##                                                                           ##
                     22: ###############################################################################
                     23: 
                     24: # ---------------------------------------------------- Description of functions
1.1       www        25: #
1.41      harris41   26: #
1.98      harris41   27: # === WEB HANDLER FUNCTIONS
                     28: # BEGIN() : run once after compilation to initialize values
1.41      harris41   29: # handler(server reference) : interacts with the Apache server layer
                     30: #                             (for /adm/searchcat URLs)
1.98      harris41   31: # get_unprocessed_cgi() : reads in critical name/value pairs that may have not
                     32: #                         been processed and passed into %ENV by the web server
                     33: # make_persistent() : makes a set of hidden HTML fields to make
                     34: #                     SQL search interface information to be persistent
                     35: #
                     36: #
                     37: # === WEB INTERFACE COMPONENT FUNCTIONS
1.41      harris41   38: # simpletextfield(name,value) : returns HTML formatted string for simple text
                     39: #                               field
                     40: # simplecheckbox(name,value) : returns HTML formatted string for simple
                     41: #                              checkbox
                     42: # searchphrasefield(title,name,value) : returns HTML formatted string for
                     43: #                                       a search expression phrase field
                     44: # dateboxes(name, defaultmonth, defaultday, defaultyear) : returns HTML
                     45: #                                                          formatted string
                     46: #                                                          for a calendar date
                     47: # selectbox(title,name,value,%HASH=options) : returns HTML formatted string for
                     48: #                                             a selection box field
1.98      harris41   49: #
                     50: #
                     51: # === SEARCH FUNCTIONS
1.42      harris41   52: # advancedsearch(server reference, environment reference) : perform a complex
                     53: #                                  multi-field logical query
                     54: # basicsearch(server reference, environment reference) : perform a simple
                     55: #                               single-field logical query
1.43      harris41   56: # build_SQL_query(field name, logic) : builds a SQL query string from a
                     57: #                                      logical expression with AND/OR keywords
1.98      harris41   58: # build_custommetadata_query(field_name, logic_statement) : builds a perl
                     59: #                 regular expression from a logical expression with AND/OR
                     60: #                 keywords
1.43      harris41   61: # recursive_SQL_query_build(field name, reverse notation expression) : 
                     62: #                 builds a SQL query string from a reverse notation expression
                     63: #                 logical expression with AND/OR keywords
1.90      harris41   64: # build_date_queries(cmonth1, cday1, cyear1, cmonth2, cday2, cyear2,
                     65: #                    lmonth1, lday1, lyear1, lmonth2, lday2, lyear2) :
1.98      harris41   66: #                 Builds a SQL logic query to check time/date entries.
                     67: #
                     68: #
                     69: # === OUTPUTTING RESULTS FUNCTION
                     70: # output_results(output mode,
                     71: #                server reference, 
                     72: #                environment reference,
                     73: #                reply list reference) : outputs results from search
                     74: #
                     75: #
                     76: # === DIFFERENT WAYS TO VIEW METADATA RECORDS
                     77: # detailed_citation_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
                     78: #          see metadata viewing notes below 
                     79: # summary_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
                     80: #          see metadata viewing notes below 
                     81: # fielded_format_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
                     82: #          see metadata viewing notes below 
                     83: # xml_sgml_view(ORDERED METADATA LIST FOR A RESULT OBJECT INSTANCE) :
                     84: #          see metadata viewing notes below 
                     85: #  ___________________________________________________________________________
                     86: # | * Metadata viewing notes                                                  |
                     87: # | Output is a HTML-ified string.                                            |
                     88: # | Input arguments are title, author, subject, url, keywords, version, notes,|
                     89: # | short abstract, mime, language, creation date, last revision date, owner, |
                     90: # | copyright, hostname, httphost, and extra custom metadata to show.         |
                     91: #  ---------------------------------------------------------------------------
                     92: #
                     93: #
                     94: # === TEST CONDITIONAL FUNCTIONS
                     95: # filled(field) : determines whether a given field has been filled
                     96: #
                     97: #
                     98: # === ERROR FUNCTIONS
                     99: # output_blank_field_error(server reference) : outputs a message saying that
                    100: #                                              more fields need to be filled in
1.90      harris41  101: # output_date_error(server reference, error message) : outputs
                    102: #         an error message specific to bad date format.
1.41      harris41  103: 
1.1       www       104: package Apache::lonsearchcat;
                    105: 
1.98      harris41  106: # ------------------------------------------------- modules used by this module
1.1       www       107: use strict;
                    108: use Apache::Constants qw(:common);
1.6       harris41  109: use Apache::lonnet();
                    110: use Apache::File();
1.7       harris41  111: use CGI qw(:standard);
1.41      harris41  112: use Text::Query;
1.101     harris41  113: use GDBM_File;
1.1       www       114: 
1.90      harris41  115: # ---------------------------------------- variables used throughout the module
                    116: 
1.98      harris41  117: # -- information holders
                    118: my %language; # holds contents of language.tab
                    119: my %cprtag; # holds contents of copyright.tab
                    120: my %mimetag; # holds contents of filetypes.tab
                    121: my %hostdomains; # matches host name to host domain
                    122: my %hostips; # matches host name to host ip
                    123: my %hitcount; # stores number of hits per host
                    124: 
                    125: # -- dynamically rendered interface components
                    126: my $closebutton; # button that closes the search window
                    127: my $importbutton; # button to take the selected results and go to group sorting
                    128: 
                    129: # -- miscellaneous variables
                    130: my $scrout; # string that holds portions of the screen output
                    131: my $yourself; # allows for quickly limiting to oneself
1.101     harris41  132: my %hash;
1.98      harris41  133: 
                    134: # ------------------------------------------ choices for different output views
                    135: # Detailed Citation View ---> sub detailed_citation_view
1.90      harris41  136: # Summary View ---> sub summary_view
                    137: # Fielded Format ---> sub fielded_format_view
                    138: # XML/SGML ---> sub xml_sgml_view
1.55      harris41  139: my $basicviewselect=<<END;
                    140: <select name='basicviewselect'>
                    141: <option value='Detailed Citation View'>Detailed Citation View</option>
                    142: <option value='Summary View'>Summary View</option>
                    143: <option value='Fielded Format'>Fielded Format</option>
                    144: <option value='XML/SGML'>XML/SGML</option>
                    145: </select>
                    146: END
                    147: my $advancedviewselect=<<END;
                    148: <select name='advancedviewselect'>
1.50      harris41  149: <option value='Detailed Citation View'>Detailed Citation View</option>
                    150: <option value='Summary View'>Summary View</option>
                    151: <option value='Fielded Format'>Fielded Format</option>
                    152: <option value='XML/SGML'>XML/SGML</option>
1.46      harris41  153: </select>
                    154: END
1.3       harris41  155: 
1.98      harris41  156: # ----------------------------------------------------------------------- BEGIN
                    157: sub BEGIN {
1.8       harris41  158: # --------------------------------- Compute various listings of metadata values
1.3       harris41  159:     $language{'any'}='Any language';
                    160:     {
1.98      harris41  161: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    162: 				 '/language.tab');
1.3       harris41  163: 	map {
1.57      harris41  164: 	    $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3       harris41  165: 	    $language{$1}=$2;
                    166: 	} <$fh>;
                    167:     }
                    168:     $cprtag{'any'}='Any copyright/distribution';
                    169:     {
1.98      harris41  170: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonIncludes'}.
                    171: 				 '/copyright.tab');
1.3       harris41  172: 	map {
1.57      harris41  173: 	    $_=~/(\w+)\s+([\w\s\-]+)/; chomp;
1.3       harris41  174: 	    $cprtag{$1}=$2;
                    175: 	} <$fh>;
                    176:     }
                    177:     $mimetag{'any'}='Any type';
                    178:     {
1.98      harris41  179: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    180: 				 '/filetypes.tab');
1.3       harris41  181: 	map {
1.57      harris41  182: 	    $_=~/(\w+)\s+(\w+)\s+([\w\s\-]+)/; chomp;
1.3       harris41  183: 	    $mimetag{$1}=".$1 $3";
                    184: 	} <$fh>;
                    185:     }
1.98      harris41  186:     {
                    187: 	my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.
                    188: 				 '/hosts.tab');
                    189: 	map {
                    190: 	    $_=~/(\w+?)\:(\w+?)\:(\w+?)\:(.*)/; chomp;
                    191: 	    if ($3 eq 'library') {
                    192: 		$hostdomains{$1}=$2;
                    193: 		$hostips{$1}=$4;
                    194: 	    }
                    195: 	} <$fh>;
                    196:     }
                    197: }
                    198: 
1.101     harris41  199: my $diropendb = "";
                    200: my $domain = "";
                    201: 
1.98      harris41  202: # ----------------------------- Handling routine called via Apache and mod_perl
                    203: sub handler {
                    204:     my $r = shift;
1.103   ! harris41  205:     untie %hash;
1.98      harris41  206:     &get_unprocessed_cgi();
                    207: 
                    208:     $r->content_type('text/html');
                    209:     $r->send_http_header;
                    210:     return OK if $r->header_only;
                    211: 
1.101     harris41  212:     $domain  = $r->dir_config('lonDefDomain');
                    213: 
                    214:     $diropendb = "/home/httpd/perl/tmp/$domain\_$ENV{'user.name'}_indexer.db";
                    215: 
                    216:     if ($ENV{'form.launch'} eq '1') {
                    217: 	if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
                    218: 	    &start_fresh_session();
                    219: 	    untie %hash;
                    220: 	}
                    221: 	else {
                    222: 	    $r->print('<html><head></head><body>Unable to tie hash to db '.
                    223: 		      'file</body></html>');
                    224: 	    return OK;
                    225: 	}
                    226:     }
                    227: 
1.98      harris41  228: # ----------------------------------- configure dynamic components of interface
                    229:     my $hidden='';
                    230:     if ($ENV{'form.catalogmode'} eq 'interactive') {
                    231: 	$hidden="<input type='hidden' name='catalogmode' value='interactive'>".
                    232: 	    "\n";
                    233:         $closebutton="<input type='button' name='close' value='CLOSE' ".
                    234: 	    "onClick='self.close()'>"."\n";
                    235:     }
                    236:     elsif ($ENV{'form.catalogmode'} eq 'groupsearch') {
                    237: 	$hidden=<<END;
                    238: <input type='hidden' name='catalogmode' value='groupsearch'>
                    239: END
                    240:         $closebutton=<<END;
                    241: <input type='button' name='close' value='CLOSE' onClick='self.close()'>
                    242: END
                    243:         $importbutton=<<END;
                    244: <input type='button' name='import' value='IMPORT'
                    245: onClick='javascript:select_group()'>
                    246: END
                    247:     }
                    248: 
                    249: # ------------------------------------------------------ Determine current user
                    250:     $yourself=$ENV{'user.name'}.'@'.$ENV{'user.domain'};
                    251: 
                    252: # --- Now, depending on the interface actions, do one of three things here:
                    253: # --- 1. a basic search
                    254: # --- 2. an advanced search
                    255: # --- 3. output a search interface
1.3       harris41  256: 
1.90      harris41  257: # ----------------------------------- See if a search invocation should be done
1.6       harris41  258:     if ($ENV{'form.basicsubmit'} eq 'SEARCH') {
1.101     harris41  259: 	untie %hash; return &basicsearch($r,\%ENV);
1.6       harris41  260:     }
1.18      harris41  261:     elsif ($ENV{'form.advancedsubmit'} eq 'SEARCH') {
1.101     harris41  262: 	untie %hash; return &advancedsearch($r,\%ENV);
1.18      harris41  263:     }
1.6       harris41  264: 
1.90      harris41  265: # ----------------------------- Else, begin building search interface to output
1.8       harris41  266:     $scrout=''; # building a part of screen output
1.3       harris41  267:     $scrout.=&searchphrasefield('Limit by title','title',
1.11      harris41  268: 			$ENV{'form.title'});
1.3       harris41  269: 
                    270:     $scrout.=&searchphrasefield('Limit by author','author',
1.11      harris41  271: 			$ENV{'form.author'});
1.3       harris41  272: 
                    273:     $scrout.=&searchphrasefield('Limit by subject','subject',
1.11      harris41  274: 			$ENV{'form.subject'});
                    275: 
                    276:     $scrout.=&searchphrasefield('Limit by keywords','keywords',
                    277: 			$ENV{'form.keywords'});
                    278: 
                    279:     $scrout.=&searchphrasefield('Limit by URL','url',
                    280: 			$ENV{'form.url'});
                    281: 
1.96      harris41  282: #    $scrout.=&searchphrasefield('Limit by version','version',
                    283: #			$ENV{'form.version'});
1.3       harris41  284: 
                    285:     $scrout.=&searchphrasefield('Limit by notes','notes',
1.11      harris41  286: 			$ENV{'form.notes'});
1.3       harris41  287: 
                    288:     $scrout.=&searchphrasefield('Limit by abstract','abstract',
1.11      harris41  289: 			$ENV{'form.abstract'});
1.3       harris41  290: 
1.11      harris41  291:     $ENV{'form.mime'}='notxxx' unless length($ENV{'form.mime'});
1.3       harris41  292:     $scrout.=&selectbox('Limit by MIME type','mime',
1.11      harris41  293: 			$ENV{'form.mime'},%mimetag);
                    294: 
                    295:     $ENV{'form.language'}='any' unless length($ENV{'form.language'});
1.3       harris41  296: 
                    297:     $scrout.=&selectbox('Limit by language','language',
1.11      harris41  298: 			$ENV{'form.language'},%language);
1.3       harris41  299:     
1.8       harris41  300: 
                    301: # ------------------------------------------------ Compute date selection boxes
                    302:     $scrout.=<<CREATIONDATESTART;
1.3       harris41  303: <p>
                    304: <font color="#800000" face="helvetica"><b>LIMIT BY CREATION DATE RANGE:</b>
                    305: </font>
1.98      harris41  306: <br />
1.8       harris41  307: between:
                    308: CREATIONDATESTART
1.11      harris41  309:     $scrout.=&dateboxes('creationdatestart',1,1,1976,
                    310: 			$ENV{'form.creationdatestart_month'},
                    311: 			$ENV{'form.creationdatestart_day'},
                    312: 			$ENV{'form.creationdatestart_year'},
                    313: 			);
1.8       harris41  314:     $scrout.=<<CREATIONDATEEND;
                    315: and:
                    316: CREATIONDATEEND
1.11      harris41  317:     $scrout.=&dateboxes('creationdateend',12,31,2051,
                    318: 			$ENV{'form.creationdateend_month'},
                    319: 			$ENV{'form.creationdateend_day'},
                    320: 			$ENV{'form.creationdateend_year'},
                    321: 			);
1.8       harris41  322:     $scrout.="</p>";
                    323: 
                    324:     $scrout.=<<LASTREVISIONDATESTART;
                    325: <p>
                    326: <font color="#800000" face="helvetica"><b>LIMIT BY LAST REVISION DATE RANGE:
                    327: </b></font>
1.98      harris41  328: <br />between:
1.8       harris41  329: LASTREVISIONDATESTART
1.11      harris41  330:     $scrout.=&dateboxes('lastrevisiondatestart',1,1,1976,
                    331: 			$ENV{'form.lastrevisiondatestart_month'},
                    332: 			$ENV{'form.lastrevisiondatestart_day'},
                    333: 			$ENV{'form.lastrevisiondatestart_year'},
                    334: 			);
1.8       harris41  335:     $scrout.=<<LASTREVISIONDATEEND;
                    336: and:
                    337: LASTREVISIONDATEEND
1.11      harris41  338:     $scrout.=&dateboxes('lastrevisiondateend',12,31,2051,
                    339: 			$ENV{'form.lastrevisiondateend_month'},
                    340: 			$ENV{'form.lastrevisiondateend_day'},
                    341: 			$ENV{'form.lastrevisiondateend_year'},
                    342: 			);
1.8       harris41  343:     $scrout.='</p>';
                    344: 
                    345:     $scrout.=&searchphrasefield('Limit by publisher/owner','owner',
1.11      harris41  346: 				$ENV{'form.owner'});
1.8       harris41  347: 
1.11      harris41  348:     $ENV{'form.copyright'}='any' unless length($ENV{'form.copyright'});
1.8       harris41  349:     $scrout.=&selectbox('Limit by copyright/distribution','copyright',
1.11      harris41  350: 			$ENV{'form.copyright'},%cprtag);
1.8       harris41  351: 
1.14      harris41  352: # ------------------------------------------- Compute customized metadata field
                    353:     $scrout.=<<CUSTOMMETADATA;
                    354: <p>
1.77      harris41  355: <font color="#800000" face="helvetica"><b>LIMIT BY SPECIAL METADATA FIELDS:</b>
1.14      harris41  356: </font>
1.77      harris41  357: For resource-specific metadata, enter in an expression in the form of 
1.100     harris41  358: <i>key</i>=<i>value</i> separated by operators such as AND, OR or NOT.<br />
1.14      harris41  359: <b>Example:</b> grandmother=75 OR grandfather=85
1.98      harris41  360: <br />
1.14      harris41  361: CUSTOMMETADATA
                    362: $scrout.=&simpletextfield('custommetadata',$ENV{'form.custommetadata'});
1.15      harris41  363: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
1.14      harris41  364: 
1.77      harris41  365:     $scrout.=<<CUSTOMSHOW;
                    366: <p>
                    367: <font color="#800000" face="helvetica"><b>SHOW SPECIAL METADATA FIELDS:</b>
                    368: </font>
                    369: Enter in a space-separated list of special metadata fields to show
                    370: in a fielded listing for each record result.
1.98      harris41  371: <br />
1.77      harris41  372: CUSTOMSHOW
                    373: $scrout.=&simpletextfield('customshow',$ENV{'form.customshow'});
                    374: $scrout.=' <i>initial users of this system do not need to worry about this option</i>';
                    375: 
1.8       harris41  376: # ---------------------------------------------------------------- Print screen
                    377:     $r->print(<<ENDDOCUMENT);
                    378: <html>
                    379: <head>
                    380: <title>The LearningOnline Network with CAPA</title>
1.100     harris41  381: <script type="text/javascript">
                    382:     function openhelp(val) {
                    383: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                    384: 	     'scrollbars=1,width=400,height=300');
                    385: 	openhelpwin.focus();
                    386:     }
                    387: </script>
1.8       harris41  388: </head>
                    389: <body bgcolor="#FFFFFF">
1.98      harris41  390: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.8       harris41  391: <h1>Search Catalog</h1>
                    392: <form method="post" action="/adm/searchcat">
                    393: $hidden
1.98      harris41  394: <hr />
1.8       harris41  395: <h3>Basic Search</h3>
                    396: <p>
                    397: Enter terms or phrases separated by search operators
1.100     harris41  398: such as AND, OR, or NOT then press SEARCH below.  Terms should be specific
1.8       harris41  399: to the title, author, subject, notes, or abstract information associated
                    400: with a resource.
1.98      harris41  401: <br />
1.11      harris41  402: ENDDOCUMENT
                    403:     $r->print(&simpletextfield('basicexp',$ENV{'form.basicexp'}));
                    404:     $r->print(' ');
                    405:     $r->print(&simplecheckbox('titleonly',$ENV{'form.titleonly'}));
                    406:     $r->print('<font color="#800000">Title only</font> ');
1.96      harris41  407: #    $r->print(&simplecheckbox('allversions',$ENV{'form.allversions'}));
                    408: # <font color="#800000">Search historic archives</font>
1.11      harris41  409:     $r->print(<<ENDDOCUMENT);
1.98      harris41  410: <br />
1.68      harris41  411: <input type="submit" name="basicsubmit" value='SEARCH' />
                    412: <input type="reset" name="reset" value='RESET' />
1.46      harris41  413: $closebutton
1.55      harris41  414: $basicviewselect
1.100     harris41  415: <input type="button" value="HELP" onClick="openhelp()" />
1.8       harris41  416: </p>
1.98      harris41  417: <hr />
1.8       harris41  418: <h3>Advanced Search</h3>
                    419: $scrout
                    420: <p>
1.68      harris41  421: <input type="submit" name="advancedsubmit" value='SEARCH' />
                    422: <input type="reset" name="reset" value='RESET' />
1.46      harris41  423: $closebutton
1.55      harris41  424: $advancedviewselect
1.100     harris41  425: <input type="button" value="HELP" onClick="openhelp()" />
1.3       harris41  426: </p>
1.8       harris41  427: </form>
                    428: </body>
                    429: </html>
                    430: ENDDOCUMENT
                    431:     return OK;
                    432: } 
                    433: 
1.98      harris41  434: # ----------- grab unprocessed CGI variables that may have been appended to URL
                    435: sub get_unprocessed_cgi {
                    436:     map {
                    437:        my ($name, $value) = split(/=/,$_);
                    438:        $value =~ tr/+/ /;
                    439:        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.101     harris41  440:        if ($name eq 'catalogmode' or $name eq 'launch' or $name eq 'acts') {
1.98      harris41  441: 	   $ENV{'form.'.$name}=$value;
                    442:        }
                    443:     } (split(/&/,$ENV{'QUERY_STRING'}));
                    444: }
                    445: 
                    446: # ------------------------------------------------------------- make persistent
                    447: sub make_persistent {
                    448:     my $persistent='';
                    449:     
                    450:     map {
                    451: 	if (/^form\./ && !/submit/) {
                    452: 	    my $name=$_;
                    453: 	    my $key=$name;
                    454: 	    $ENV{$key}=~s/\'//g; # do not mess with html field syntax
                    455: 	    $name=~s/^form\.//;
                    456: 	    $persistent.=<<END;
                    457: <input type='hidden' name='$name' value='$ENV{$key}' />
                    458: END
                    459:         }
                    460:     } (keys %ENV);
                    461:     return $persistent;
                    462: }
                    463: 
1.8       harris41  464: # --------------------------------------------------------- Various form fields
                    465: 
1.11      harris41  466: sub simpletextfield {
                    467:     my ($name,$value)=@_;
1.68      harris41  468:     return '<input type=text name=\''.$name.
                    469: 	   '\' size=20 value=\''.$value.'\' />';
1.11      harris41  470: }
                    471: 
                    472: sub simplecheckbox {
                    473:     my ($name,$value)=@_;
                    474:     my $checked='';
                    475:     $checked="CHECKED" if $value eq 'on';
1.68      harris41  476:     return '<input type=checkbox name=\''.$name.'\' '. $checked . '>';
1.11      harris41  477: }
                    478: 
1.8       harris41  479: sub searchphrasefield {
                    480:     my ($title,$name,$value)=@_;
                    481:     my $instruction=<<END;
                    482: Enter terms or phrases separated by search operators such
1.100     harris41  483: as AND, OR, or NOT.
1.8       harris41  484: END
                    485:     my $uctitle=uc($title);
                    486:     return "\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:</b>".
1.98      harris41  487: 	   "</FONT> $instruction<br />".
1.68      harris41  488:            '<input type=text name="'.$name.'" size=80 value=\''.$value.'\'>';
1.8       harris41  489: }
1.3       harris41  490: 
1.8       harris41  491: sub dateboxes {
1.11      harris41  492:     my ($name,$defaultmonth,$defaultday,$defaultyear,
                    493: 	$currentmonth,$currentday,$currentyear)=@_;
                    494:     ($defaultmonth,$defaultday,$defaultyear)=('','','');
                    495:     my $month=<<END;
1.8       harris41  496: <select name="${name}_month">
1.11      harris41  497: <option value='$defaultmonth'> </option>
                    498: <option value="1">January</option>
                    499: <option value="2">February</option>
                    500: <option value="3">March</option>
                    501: <option value="4">April</option>
                    502: <option value="5">May</option>
                    503: <option value="6">June</option>
                    504: <option value="7">July</option>
                    505: <option value="8">August</option>
                    506: <option value="9">September</option>
1.3       harris41  507: <option value="10">October</option>
                    508: <option value="11">November</option>
                    509: <option value="12">December</option>
                    510: </select>
1.11      harris41  511: END
                    512:     $month=~s/(\"$currentmonth\")/$1 SELECTED/ if length($currentmonth);
                    513:     my $day=<<END;
1.8       harris41  514: <select name="${name}_day">
1.11      harris41  515: <option value='$defaultday'> </option>
                    516: <option value="1">1</option>
                    517: <option value="2">2</option>
                    518: <option value="3">3</option>
                    519: <option value="4">4</option>
                    520: <option value="5">5</option>
                    521: <option value="6">6</option>
                    522: <option value="7">7</option>
                    523: <option value="8">8</option>
                    524: <option value="9">9</option>
                    525: <option value="10">10</option>
                    526: <option value="11">11</option>
                    527: <option value="12">12</option>
                    528: <option value="13">13</option>
                    529: <option value="14">14</option>
                    530: <option value="15">15</option>
                    531: <option value="16">16</option>
                    532: <option value="17">17</option>
                    533: <option value="18">18</option>
                    534: <option value="19">19</option>
                    535: <option value="20">20</option>
                    536: <option value="21">21</option>
                    537: <option value="22">22</option>
                    538: <option value="23">23</option>
                    539: <option value="24">24</option>
                    540: <option value="25">25</option>
                    541: <option value="26">26</option>
                    542: <option value="27">27</option>
                    543: <option value="28">28</option>
                    544: <option value="29">29</option>
                    545: <option value="30">30</option>
                    546: <option value="31">31</option>
1.3       harris41  547: </select>
1.11      harris41  548: END
                    549:     $day=~s/(\"$currentday\")/$1 SELECTED/ if length($currentday);
                    550:     my $year=<<END;
1.8       harris41  551: <select name="${name}_year">
1.11      harris41  552: <option value='$defaultyear'> </option>
                    553: <option value="1976">1976</option>
                    554: <option value="1977">1977</option>
                    555: <option value="1978">1978</option>
                    556: <option value="1979">1979</option>
                    557: <option value="1980">1980</option>
                    558: <option value="1981">1981</option>
                    559: <option value="1982">1982</option>
                    560: <option value="1983">1983</option>
                    561: <option value="1984">1984</option>
                    562: <option value="1985">1985</option>
                    563: <option value="1986">1986</option>
                    564: <option value="1987">1987</option>
                    565: <option value="1988">1988</option>
                    566: <option value="1989">1989</option>
                    567: <option value="1990">1990</option>
                    568: <option value="1991">1991</option>
                    569: <option value="1992">1992</option>
                    570: <option value="1993">1993</option>
                    571: <option value="1994">1994</option>
                    572: <option value="1995">1995</option>
                    573: <option value="1996">1996</option>
                    574: <option value="1997">1997</option>
                    575: <option value="1998">1998</option>
                    576: <option value="1999">1999</option>
                    577: <option value="2000">2000</option>
                    578: <option value="2001">2001</option>
                    579: <option value="2002">2002</option>
                    580: <option value="2003">2003</option>
                    581: <option value="2004">2004</option>
                    582: <option value="2005">2005</option>
                    583: <option value="2006">2006</option>
                    584: <option value="2007">2007</option>
                    585: <option value="2008">2008</option>
                    586: <option value="2009">2009</option>
                    587: <option value="2010">2010</option>
                    588: <option value="2011">2011</option>
                    589: <option value="2012">2012</option>
                    590: <option value="2013">2013</option>
                    591: <option value="2014">2014</option>
                    592: <option value="2015">2015</option>
                    593: <option value="2016">2016</option>
                    594: <option value="2017">2017</option>
                    595: <option value="2018">2018</option>
                    596: <option value="2019">2019</option>
                    597: <option value="2020">2020</option>
                    598: <option value="2021">2021</option>
                    599: <option value="2022">2022</option>
                    600: <option value="2023">2023</option>
                    601: <option value="2024">2024</option>
                    602: <option value="2025">2025</option>
                    603: <option value="2026">2026</option>
                    604: <option value="2027">2027</option>
                    605: <option value="2028">2028</option>
                    606: <option value="2029">2029</option>
                    607: <option value="2030">2030</option>
                    608: <option value="2031">2031</option>
                    609: <option value="2032">2032</option>
                    610: <option value="2033">2033</option>
                    611: <option value="2034">2034</option>
                    612: <option value="2035">2035</option>
                    613: <option value="2036">2036</option>
                    614: <option value="2037">2037</option>
                    615: <option value="2038">2038</option>
                    616: <option value="2039">2039</option>
                    617: <option value="2040">2040</option>
                    618: <option value="2041">2041</option>
                    619: <option value="2042">2042</option>
                    620: <option value="2043">2043</option>
                    621: <option value="2044">2044</option>
                    622: <option value="2045">2045</option>
                    623: <option value="2046">2046</option>
                    624: <option value="2047">2047</option>
                    625: <option value="2048">2048</option>
                    626: <option value="2049">2049</option>
                    627: <option value="2050">2050</option>
                    628: <option value="2051">2051</option>
1.3       harris41  629: </select>
                    630: END
1.11      harris41  631:     $year=~s/(\"$currentyear\")/$1 SELECTED/ if length($currentyear);
                    632:     return "$month$day$year";
1.3       harris41  633: }
                    634: 
                    635: sub selectbox {
                    636:     my ($title,$name,$value,%options)=@_;
                    637:     my $uctitle=uc($title);
                    638:     my $selout="\n<p><font color=\"#800000\" face=\"helvetica\"><b>$uctitle:".
1.98      harris41  639: 	"</b></font><br />".'<select name="'.$name.'">';
1.3       harris41  640:     map {
1.68      harris41  641:         $selout.='<option value=\''.$_.'\'';
1.3       harris41  642:         if ($_ eq $value) { $selout.=' selected'; }
                    643:         $selout.='>'.$options{$_}.'</option>';
                    644:     } sort keys %options;
                    645:     return $selout.'</select>';
1.6       harris41  646: }
                    647: 
1.45      harris41  648: # ----------------------------------------------- Performing an advanced search
1.18      harris41  649: sub advancedsearch {
                    650:     my ($r,$envhash)=@_;
                    651:     my %ENV=%{$envhash};
                    652: 
1.32      harris41  653:     my $fillflag=0;
1.64      harris41  654:     # Clean up fields for safety
                    655:     for my $field ('title','author','subject','keywords','url','version',
                    656: 		   'creationdatestart_month','creationdatestart_day',
                    657: 		   'creationdatestart_year','creationdateend_month',
                    658: 		   'creationdateend_day','creationdateend_year',
                    659: 		   'lastrevisiondatestart_month','lastrevisiondatestart_day',
                    660: 		   'lastrevisiondatestart_year','lastrevisiondateend_month',
                    661: 		   'lastrevisiondateend_day','lastrevisiondateend_year',
                    662: 		   'notes','abstract','mime','language','owner',
1.77      harris41  663: 		   'custommetadata','customshow') {
1.101     harris41  664: 	$ENV{"form.$field"}=~s/[^\w\/\s\(\)\=\-\"\']//g;
1.64      harris41  665:     }
1.90      harris41  666: 
                    667:     # Check to see if enough information was filled in
1.32      harris41  668:     for my $field ('title','author','subject','keywords','url','version',
                    669: 		   'notes','abstract','mime','language','owner',
                    670: 		   'custommetadata') {
1.40      harris41  671: 	if (&filled($ENV{"form.$field"})) {
1.32      harris41  672: 	    $fillflag++;
                    673: 	}
                    674:     }
                    675:     unless ($fillflag) {
                    676: 	&output_blank_field_error($r);
                    677: 	return OK;
                    678:     }
1.39      harris41  679: 
1.90      harris41  680: 
                    681:     # Turn the form input into a SQL-based query
1.39      harris41  682:     my $query='';
1.44      harris41  683: 
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: 
                    726:     # Process form information for custom metadata querying
1.76      harris41  727:     my $customquery='';
1.64      harris41  728:     if ($ENV{'form.custommetadata'}) {
                    729: 	$customquery=&build_custommetadata_query('custommetadata',
                    730: 				      $ENV{'form.custommetadata'});
                    731:     }
1.83      harris41  732:     my $customshow='';
                    733:     if ($ENV{'form.customshow'}) {
                    734: 	$customshow=$ENV{'form.customshow'};
                    735: 	$customshow=~s/[^\w\s]//g;
                    736: 	my @fields=split(/\s+/,$customshow);
                    737: 	$customshow=join(" ",@fields);
                    738:     }
1.90      harris41  739:     # Send query statements over the network to be processed by either the SQL
                    740:     # database or a recursive scheme of 'grep'-like actions (for custom
                    741:     # metadata).
1.45      harris41  742:     if (@queries) {
1.58      harris41  743: 	$query=join(" AND ",@queries);
1.46      harris41  744: 	$query="select * from metadata where $query";
1.90      harris41  745: 	my $reply; # reply hash reference
1.83      harris41  746: 	unless ($customquery or $customshow) {
1.76      harris41  747: 	    $reply=&Apache::lonnet::metadata_query($query);
                    748: 	}
                    749: 	else {
1.83      harris41  750: 	    $reply=&Apache::lonnet::metadata_query($query,
                    751: 						   $customquery,$customshow);
1.76      harris41  752: 	}
1.64      harris41  753: 	&output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45      harris41  754:     }
1.86      harris41  755:     elsif ($customquery) {
1.90      harris41  756: 	my $reply; # reply hash reference
1.86      harris41  757: 	$reply=&Apache::lonnet::metadata_query('',
                    758: 					       $customquery,$customshow);
                    759: 	&output_results('Advanced',$r,$envhash,$customquery,$reply);
1.45      harris41  760:     }
1.92      harris41  761:     # should not get to this point
                    762:     return 'Error.  Should not have gone to this point.';
1.18      harris41  763: }
                    764: 
1.6       harris41  765: # --------------------------------------------------- Performing a basic search
                    766: sub basicsearch {
1.19      harris41  767:     my ($r,$envhash)=@_;
                    768:     my %ENV=%{$envhash};
1.64      harris41  769:     # Clean up fields for safety
                    770:     for my $field ('basicexp') {
                    771: 	$ENV{"form.$field"}=~s/[^\w\s\(\)\-]//g;
                    772:     }
                    773: 
1.90      harris41  774:     # Check to see if enough is filled in
1.26      harris41  775:     unless (&filled($ENV{'form.basicexp'})) {
1.24      harris41  776: 	&output_blank_field_error($r);
                    777: 	return OK;
                    778:     }
1.22      harris41  779: 
1.90      harris41  780:     # Build SQL query string based on form page
1.39      harris41  781:     my $query='';
1.33      harris41  782:     my $concatarg=join(',"    ",',
                    783: 		       ('title', 'author', 'subject', 'notes', 'abstract'));
1.95      harris41  784:     $concatarg='title' if $ENV{'form.titleonly'};
1.94      harris41  785: 
                    786:     $query=&build_SQL_query('concat('.$concatarg.')',$ENV{'form.'.'basicexp'});
                    787: 
1.90      harris41  788:     # Get reply (either a hash reference to filehandles or bad connection)
1.94      harris41  789:     my $reply=&Apache::lonnet::metadata_query('select * from metadata where '.$query);
1.90      harris41  790: 
                    791:     # Output search results
1.98      harris41  792: 
1.44      harris41  793:     &output_results('Basic',$r,$envhash,$query,$reply);
1.90      harris41  794: 
1.18      harris41  795:     return OK;
1.22      harris41  796: }
                    797: 
1.98      harris41  798: # ------------------------------------------------------------- build_SQL_query
                    799: sub build_SQL_query {
                    800:     my ($field_name,$logic_statement)=@_;
                    801:     my $q=new Text::Query('abc',
                    802: 			  -parse => 'Text::Query::ParseAdvanced',
                    803: 			  -build => 'Text::Query::Build');
                    804:     $q->prepare($logic_statement);
                    805:     my $matchexp=${$q}{'matchexp'}; chomp $matchexp;
                    806:     my $sql_query=&recursive_SQL_query_build($field_name,$matchexp);
                    807:     return $sql_query;
                    808: }
                    809: 
                    810: # ------------------------------------------------- build custom metadata query
                    811: sub build_custommetadata_query {
                    812:     my ($field_name,$logic_statement)=@_;
                    813:     my $q=new Text::Query('abc',
                    814: 			  -parse => 'Text::Query::ParseAdvanced',
                    815: 			  -build => 'Text::Query::BuildAdvancedString');
                    816:     $q->prepare($logic_statement);
                    817:     my $matchexp=${$q}{'-parse'}{'-build'}{'matchstring'};
                    818:     # quick fix to change literal into xml tag-matching
                    819:     # will eventually have to write a separate builder module
                    820:     my $oldmatchexp=$matchexp;
                    821:     $matchexp=~s/(\w+)\\\=([\w\\\+]+)/\\\<$1\\\>\[\^\\\<\]\*$2\[\^\\\<\]\*\\\<\\\/$1\\\>/g;
                    822:     return $matchexp;
                    823: }
                    824: 
                    825: # - Recursively parse a reverse notation expression into a SQL query expression
                    826: sub recursive_SQL_query_build {
                    827:     my ($dkey,$pattern)=@_;
                    828:     my @matches=($pattern=~/(\[[^\]|\[]*\])/g);
                    829:     return $pattern unless @matches;
                    830:     foreach my $match (@matches) {
                    831: 	$match=~/\[ (\w+)\s(.*) \]/;
                    832: 	my ($key,$value)=($1,$2);
                    833: 	my $replacement='';
                    834: 	if ($key eq 'literal') {
                    835: 	    $replacement="($dkey like \"\%$value\%\")";
                    836: 	}
                    837: 	elsif ($key eq 'not') {
                    838: 	    $value=~s/like/not like/;
                    839: #	    $replacement="($dkey not like $value)";
                    840: 	    $replacement="$value";
                    841: 	}
                    842: 	elsif ($key eq 'and') {
                    843: 	    $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                    844: 	    $replacement="($1 AND $2)";
                    845: 	}
                    846: 	elsif ($key eq 'or') {
                    847: 	    $value=~/(.*[\"|\)]) ([|\(|\^].*)/;
                    848: 	    $replacement="($1 OR $2)";
                    849: 	}
                    850: 	substr($pattern,
                    851: 	       index($pattern,$match),
                    852: 	       length($match),
                    853: 	       $replacement
                    854: 	       );
                    855:     }
                    856:     &recursive_SQL_query_build($dkey,$pattern);
                    857: }
1.22      harris41  858: 
1.98      harris41  859: # ------------------------------------------------------------ Build date query
                    860: sub build_date_queries {
                    861:     my ($cmonth1,$cday1,$cyear1,$cmonth2,$cday2,$cyear2,
                    862: 	$lmonth1,$lday1,$lyear1,$lmonth2,$lday2,$lyear2)=@_;
                    863:     my @queries;
                    864:     if ($cmonth1 or $cday1 or $cyear1 or $cmonth2 or $cday2 or $cyear2) {
                    865: 	unless ($cmonth1 and $cday1 and $cyear1 and
                    866: 		$cmonth2 and $cday2 and $cyear2) {
                    867: 	    return "Incorrect entry for the creation date.  You must specify ".
                    868: 		   "a starting month, day, and year and an ending month, ".
                    869: 		   "day, and year.";
                    870: 	}
                    871: 	my $cnumeric1=sprintf("%d%2d%2d",$cyear1,$cmonth1,$cday1);
                    872: 	$cnumeric1+=0;
                    873: 	my $cnumeric2=sprintf("%d%2d%2d",$cyear2,$cmonth2,$cday2);
                    874: 	$cnumeric2+=0;
                    875: 	if ($cnumeric1>$cnumeric2) {
                    876: 	    return "Incorrect entry for the creation date.  The starting ".
                    877: 		   "date must occur before the ending date.";
                    878: 	}
                    879: 	my $cquery="(creationdate BETWEEN '$cyear1-$cmonth1-$cday1' AND '".
                    880: 	           "$cyear2-$cmonth2-$cday2 23:59:59')";
                    881: 	push @queries,$cquery;
                    882:     }
                    883:     if ($lmonth1 or $lday1 or $lyear1 or $lmonth2 or $lday2 or $lyear2) {
                    884: 	unless ($lmonth1 and $lday1 and $lyear1 and
                    885: 		$lmonth2 and $lday2 and $lyear2) {
                    886: 	    return "Incorrect entry for the last revision date.  You must ".
                    887: 		   "specify a starting month, day, and year and an ending ".
                    888: 		   "month, day, and year.";
                    889: 	}
                    890: 	my $lnumeric1=sprintf("%d%2d%2d",$lyear1,$lmonth1,$lday1);
                    891: 	$lnumeric1+=0;
                    892: 	my $lnumeric2=sprintf("%d%2d%2d",$lyear2,$lmonth2,$lday2);
                    893: 	$lnumeric2+=0;
                    894: 	if ($lnumeric1>$lnumeric2) {
                    895: 	    return "Incorrect entry for the last revision date.  The ".
                    896: 		   "starting date must occur before the ending date.";
                    897: 	}
                    898: 	my $lquery="(lastrevisiondate BETWEEN '$lyear1-$lmonth1-$lday1' AND '".
                    899: 	           "$lyear2-$lmonth2-$lday2 23:59:59')";
                    900: 	push @queries,$lquery;
                    901:     }
                    902:     if (@queries) {
                    903: 	return join(" AND ",@queries);
                    904:     }
                    905:     return '';
1.18      harris41  906: }
1.6       harris41  907: 
1.18      harris41  908: # ----------------------------- format and output results based on a reply list
1.98      harris41  909: # There are two windows that this function writes to.  The main search
                    910: # window ("srch") has a listing of the results.  A secondary window ("popwin")
                    911: # gives the status of the network search (time elapsed, number of machines
                    912: # contacted, etc.)
1.18      harris41  913: sub output_results {
1.101     harris41  914:     my $fnum; # search result counter
1.92      harris41  915:     my ($mode,$r,$envhash,$query,$replyref)=@_;
1.19      harris41  916:     my %ENV=%{$envhash};
1.92      harris41  917:     my %rhash=%{$replyref};
1.44      harris41  918:     my $compiledresult='';
1.102     harris41  919:     my $timeremain=300;
1.98      harris41  920:     my $elapsetime=0;
1.93      harris41  921:     my $resultflag=0;
                    922:     my $tflag=1;
                    923: 
                    924:     # make query information persistent to allow for subsequent revision
                    925:     my $persistent=&make_persistent();
                    926: 
                    927:     # output beginning of search page
1.92      harris41  928: 	$r->print(<<BEGINNING);
                    929: <html>
                    930: <head>
                    931: <title>The LearningOnline Network with CAPA</title>
                    932: BEGINNING
1.98      harris41  933: 
                    934:     # conditional output of script functions dependent on the mode in
                    935:     # which the search was invoked
1.92      harris41  936:         $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'interactive';
1.100     harris41  937: <script type="text/javascript">
1.92      harris41  938:     function select_data(title,url) {
                    939: 	changeTitle(title);
                    940: 	changeURL(url);
1.97      harris41  941: 	self.close();
1.92      harris41  942:     }
                    943:     function changeTitle(val) {
                    944: 	if (opener.inf.document.forms.resinfo.elements.t) {
                    945: 	    opener.inf.document.forms.resinfo.elements.t.value=val;
                    946: 	}
                    947:     }
                    948:     function changeURL(val) {
                    949: 	if (opener.inf.document.forms.resinfo.elements.u) {
                    950: 	    opener.inf.document.forms.resinfo.elements.u.value=val;
                    951: 	}
                    952:     }
                    953: </script>
                    954: SCRIPT
1.98      harris41  955:         $r->print(<<SCRIPT) if $ENV{'form.catalogmode'} eq 'groupsearch';
1.100     harris41  956: <script type="text/javascript">
1.98      harris41  957:     function select_data(title,url) {
1.101     harris41  958: //	alert('DEBUG: Should be storing '+title+' and '+url);
1.98      harris41  959:     }
                    960:     function queue(val) {
1.101     harris41  961: 	if (eval("document.forms.results.returnvalues["+val+"].checked")) {
1.98      harris41  962: 	    document.forms.results.acts.value+='1a'+val+'b';
                    963: 	}
                    964: 	else {
                    965: 	    document.forms.results.acts.value+='0a'+val+'b';
                    966: 	}
                    967:     }
                    968:     function select_group() {
1.101     harris41  969: 	window.location="/adm/groupsort?catalogmode=groupsearch&acts="+
                    970: 	    document.forms.results.acts.value;
1.98      harris41  971:     }
                    972: </script>
                    973: SCRIPT
1.100     harris41  974:         $r->print(<<SCRIPT);
                    975: <script type="text/javascript">
1.98      harris41  976:     function displayinfo(val) {
                    977: 	popwin.document.forms.popremain.sdetails.value=val;
                    978:     }
1.100     harris41  979:     function openhelp(val) {
                    980: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                    981: 	     'scrollbars=1,width=400,height=300');
                    982: 	openhelpwin.focus();
                    983:     }
1.102     harris41  984:     function abortsearch(val) {
                    985: 	openhelpwin=open('/adm/help/searchcat.html','helpscreen',
                    986: 	     'scrollbars=1,width=400,height=300');
                    987: 	openhelpwin.focus();
                    988:     }
1.98      harris41  989: </script>
                    990: SCRIPT
                    991:     $r->rflush();
                    992: 
                    993:     # begin showing the cataloged results
1.92      harris41  994:     $r->print(<<CATALOGBEGIN);
                    995: </head>
                    996: <body bgcolor="#ffffff">
                    997: <img align=right src=/adm/lonIcons/lonlogos.gif>
                    998: <h1>Search Catalog</h1>
                    999: CATALOGBEGIN
1.98      harris41 1000:         $r->print(<<CATALOGCONTROLS);
                   1001: <form name='results' method="post" action="/adm/searchcat">
                   1002: <input type='hidden' name='acts' value='' />
1.93      harris41 1003: <input type='button' value='Revise search request'
1.98      harris41 1004: onClick='this.form.submit();' />
                   1005: $importbutton
1.93      harris41 1006: $closebutton
                   1007: $persistent
1.98      harris41 1008: <hr />
1.93      harris41 1009: <h3>Search Query</h3>
1.98      harris41 1010: CATALOGCONTROLS
1.93      harris41 1011:     if ($mode eq 'Basic') {
                   1012: 	$r->print(<<RESULTS);
                   1013: <p>
                   1014: <b>Basic search:</b> $ENV{'form.basicexp'}
                   1015: </p>
                   1016: RESULTS
                   1017:     }
                   1018:     elsif ($mode eq 'Advanced') {
                   1019: 	$r->print(<<RESULTS);
                   1020: <p>
                   1021: <b>Advanced search</b>
                   1022: $query
                   1023: </p>
                   1024: RESULTS
                   1025:     }
                   1026:     $r->print('<h3>Search Results</h3>');
1.92      harris41 1027:     $r->rflush();
1.98      harris41 1028:     my $servernum=(keys %rhash)+0;
                   1029: 
                   1030:     # define server grid (shows status of multiple machines)
                   1031:     my $hcinit;
                   1032:     my $grid="'<br />'+";
                   1033:     $grid.="\n";
                   1034:     my $sn=1;
                   1035:     for my $sk (sort keys %rhash) {
                   1036: 	# '<a href="
                   1037: 	$grid.="'<a href=\"";
                   1038: 	# javascript:displayinfo('+
                   1039: 	$grid.="javascript:opener.displayinfo('+";
                   1040: 	# "'"+'key
                   1041: 	$grid.="\"'\"+'";
1.99      harris41 1042: 	$grid.=$sk;
1.98      harris41 1043: 	my $hc;
                   1044: 	if ($rhash{$sk} eq 'con_lost') {
                   1045: 	    $hc="!!!BAD CONNECTION, CONTACT SYSTEM ADMINISTRATOR!!!";
                   1046: 	}
                   1047: 	else {
                   1048: 	    $hc="'+\"'\"+\"+hc['$sk']+\"+\"'\"+'";
1.99      harris41 1049: 	    $hcinit.="hc[\"$sk\"]=\"not yet connected...\";";
1.98      harris41 1050: 	}
                   1051: 	$grid.=" hitcount=".$hc;
1.99      harris41 1052: 	$grid.=" domain=".$hostdomains{$sk};
1.98      harris41 1053: 	$grid.=" IP=".$hostips{$sk};
                   1054: 	# '+"'"+'">'+
                   1055: 	$grid.="'+\"'\"+')\">'+";
                   1056: 	$grid.="\n";
                   1057: 	$grid.="'<img border=\"0\" name=\"img".$sn."\"".
1.99      harris41 1058: 	    " src=\"/adm/lonIcons/srvnull.gif\" alt=\"".$sk."\" /></a>'+\n";
1.98      harris41 1059: 	$grid.="'<br />'+\n" unless $sn%10;
                   1060:         $sn++;
                   1061:     }
1.92      harris41 1062: 	    $r->print(<<ENDPOP);
1.100     harris41 1063: <script type="text/javascript">
1.98      harris41 1064:     popwin=open('','popwin','scrollbars=1,width=400,height=200');
                   1065:     popwin.focus();
                   1066:     popwin.document.writeln('<'+'html>');
                   1067:     popwin.document.writeln('<'+'head>');
                   1068:     popwin.document.writeln('<'+'script>');
                   1069:     popwin.document.writeln('hc=new Array();$hcinit');
                   1070:     popwin.document.writeln('<'+'/script>');
                   1071:     popwin.document.writeln('<'+'/head>'+
                   1072:         '<'+'body bgcolor="#FFFFFF">'+
1.100     harris41 1073: 	'<'+'image name="whirly" align="right" src="/adm/lonIcons/'+
1.99      harris41 1074: 	'lonanim.gif" '+
                   1075: 	'alt="animated logo" />'+
1.98      harris41 1076: 	'<'+'h3>Search Results Progress<'+'/h3>'+
                   1077:         '<'+'form name="popremain">'+
                   1078:         '<'+'tt>'+
1.99      harris41 1079: 	'<'+'br clear="all"/><i>PLEASE BE PATIENT</i>'+
1.98      harris41 1080: 	'<'+'br />SCANNING $servernum SERVERS'+
                   1081: 	'<'+'br clear="all" />Number of record hits found '+
                   1082: 	'<'+'input type="text" size="10" name="numhits"'+
                   1083: 	' value="0" />'+
                   1084: 	'<'+'br clear="all" />Time elapsed '+
                   1085: 	'<'+'input type="text" size="10" name="elapsetime"'+
                   1086: 	' value="0" />'+
                   1087: 	'<'+'br />'+
                   1088: 	'SERVER GRID (click on any cell for details)'+
                   1089:         $grid
                   1090:         '<'+'br />'+
                   1091: 	'Server details '+
                   1092: 	'<'+'input type="text" size="25" name="sdetails"'+
                   1093: 	' value="" />'+
                   1094: 	'<'+'br />'+
                   1095: 	' <'+'input type="button" name="button"'+
1.100     harris41 1096: 	' value="abort search and view current results" '+
1.102     harris41 1097: 	' onClick="javascript:opener.abortsearch()" />'+
1.98      harris41 1098: 	' <'+'input type="button" name="button"'+
1.100     harris41 1099: 	' value="help" onClick="javascript:opener.openhelp()" />'+
1.98      harris41 1100: 	'<'+'/tt>'+
                   1101:         '<'+'/form>'+
                   1102:         '<'+'/body><'+'/html>');
1.92      harris41 1103:     popwin.document.close();
                   1104: </script>
                   1105: ENDPOP
                   1106:     $r->rflush();
1.44      harris41 1107: 
1.93      harris41 1108:     my $servercount=0;
1.98      harris41 1109:     my $hitcountsum=0;
1.102     harris41 1110:     my $bloop=$servernum;
                   1111:     my %orkey;
                   1112:   BLOOP: while(1) {
                   1113:       my $sn=0;
                   1114:       last BLOOP unless $bloop;
                   1115:     RLOOP: foreach my $rkey (sort keys %rhash) {
1.98      harris41 1116: 	$sn++;
1.102     harris41 1117: 	next RLOOP if $orkey{$rkey};
1.93      harris41 1118: 	$servercount++;
                   1119: 	$tflag=1;
                   1120: 	$compiledresult='';
                   1121: 	my $hostname=$rkey;
1.92      harris41 1122: 	my $reply=$rhash{$rkey};
1.18      harris41 1123: 	my @results;
1.92      harris41 1124: 	
1.18      harris41 1125: 	my $replyfile='';
1.93      harris41 1126: 
                   1127: 	if ($reply eq 'con_lost') {
1.100     harris41 1128: 	    $r->print('<script type="text/javascript">popwin.document.img'.
                   1129: 		      $sn.'.'.
1.99      harris41 1130: 		      'src="/adm/lonIcons/srvbad.gif";</script>'.
                   1131: 		      "\n");
                   1132: 	    $r->rflush();
1.102     harris41 1133: 	    $bloop--;
                   1134: 	    $orkey{$rkey}=1;
1.93      harris41 1135: 	}
                   1136: 	else {
                   1137: 	    $reply=~/^([\.\w]+)$/; # must do since 'use strict' checks for tainting
                   1138: 	    $replyfile=$r->dir_config('lonDaemons').'/tmp/'.$1;
                   1139: 	    $reply=~/(.*?)\_/;
                   1140: 	    {
1.98      harris41 1141: 		my $temp=0;
                   1142: 	      WLOOP: while (1) {
                   1143: 		  if (-e $replyfile && $tflag) {
1.100     harris41 1144: 		      $r->print('<script type="text/javascript">'.
                   1145: 				'popwin.document.img'.$sn.'.'.
1.99      harris41 1146: 				'src="/adm/lonIcons/srvhalf.gif";</script>'.
1.98      harris41 1147: 				"\n");
                   1148: 		      $r->rflush();
1.100     harris41 1149: 		      $r->print('<script type="text/javascript">'.
                   1150: 				'popwin.hc["'.$rkey.'"]='.
1.99      harris41 1151: 				'"still transferring..."'.';</script>'.
1.98      harris41 1152: 				"\n");
                   1153: 		      $r->rflush();
                   1154: 		      $tflag=0;
                   1155: 		  }
1.102     harris41 1156: 		  last WLOOP if $temp>1;
1.98      harris41 1157: 		  if (-e "$replyfile.end") {
1.102     harris41 1158: 		      $bloop--;
                   1159: 		      $orkey{$rkey}=1;
1.98      harris41 1160: 		      if (-s $replyfile) {
1.100     harris41 1161: 			  $r->print('<script type="text/javascript">'.
                   1162: 				    'popwin.document.img'.$sn.'.'.
                   1163: 				    'src="/adm/lonIcons/srvgood.gif";'.
                   1164: 				    '</script>'."\n");
1.98      harris41 1165: 			  $r->rflush();
                   1166: 			  my $fh=Apache::File->new($replyfile) or 
                   1167: 			      ($r->print('ERROR: file '.
                   1168: 					 $replyfile.' cannot be opened') and
                   1169: 			       return OK);
                   1170: 			  @results=<$fh> if $fh;
                   1171: 			  $hitcount{$rkey}=@results+0;
1.100     harris41 1172: 			  $r->print('<script type="text/javascript">'.
                   1173: 				    'popwin.hc["'.$rkey.'"]='.
1.98      harris41 1174: 				    $hitcount{$rkey}.';</script>'.
                   1175: 				    "\n");
                   1176: 			  $r->rflush();
                   1177: 			  $hitcountsum+=$hitcount{$rkey};
1.100     harris41 1178: 			  $r->print('<script type="text/javascript">'.
                   1179: 				    'popwin.document.forms.popremain.'.
1.98      harris41 1180: 				    'numhits.value='.$hitcountsum.
                   1181: 				    ';</script>'.
                   1182: 				    "\n");
                   1183: 			  $r->rflush();
                   1184: 		      }
1.99      harris41 1185: 		      else {
1.100     harris41 1186: 			  $r->print('<script type="text/javascript">'.
                   1187: 				    'popwin.document.img'.$sn.'.'.
                   1188: 				    'src="/adm/lonIcons/srvempty.gif";'.
                   1189: 				    '</script>'.
                   1190: 				    "\n");
1.99      harris41 1191: 			  $r->rflush();
1.100     harris41 1192: 			  $r->print('<script type="text/javascript">'.
                   1193: 				    'popwin.hc["'.$rkey.'"]=0'.
1.99      harris41 1194: 				    ';</script>'.
                   1195: 				    "\n");
                   1196: 			  $r->rflush();
                   1197: 		      }
1.98      harris41 1198: 		      last WLOOP;
                   1199: 		  }
                   1200: 		  last WLOOP unless $timeremain;
                   1201: 		  sleep 1;
                   1202: 		  $timeremain--;
                   1203: 		  $elapsetime++;
1.100     harris41 1204: 		  $r->print('<script type="text/javascript">'.
                   1205: 			    'popwin.document.popremain.elapsetime.'.
1.98      harris41 1206: 			    'value="'.$elapsetime.'";</script>'."\n");
                   1207: 		  $r->rflush();
                   1208: 		  $temp++;
                   1209: 	      }
1.93      harris41 1210: 	    }
1.100     harris41 1211: 	    $r->print('<script type="text/javascript">'.
                   1212: 		      'popwin.document.whirly.'.
                   1213: 		      'src="'.'/adm/lonIcons/lonanimend.gif'.
                   1214: 		      '";</script>'."\n");
                   1215: 	    $r->rflush();
1.6       harris41 1216: 	}
1.77      harris41 1217: 	my $customshow='';
                   1218: 	my $extrashow='';
1.87      harris41 1219: 	my @customfields;
1.77      harris41 1220: 	if ($ENV{'form.customshow'}) {
                   1221: 	    $customshow=$ENV{'form.customshow'};
                   1222: 	    $customshow=~s/[^\w\s]//g;
1.87      harris41 1223: 	    my @fields=map {"<font color=\"#008000\">$_:</font><!-- $_ -->"} 
1.93      harris41 1224: 	    split(/\s+/,$customshow);
1.88      harris41 1225: 	    @customfields=split(/\s+/,$customshow);
1.81      harris41 1226: 	    if ($customshow) {
                   1227: 		$extrashow="<ul><li>".join("</li><li>",@fields)."</li></ul>\n";
                   1228: 	    }
1.77      harris41 1229: 	}
1.79      harris41 1230: 	my $customdata='';
1.87      harris41 1231: 	my %customhash;
1.79      harris41 1232: 	foreach my $result (@results) {
1.82      harris41 1233: 	    if ($result=~/^(custom\=.*)$/) { # grab all custom metadata
1.87      harris41 1234: 		my $tmp=$result;
                   1235: 		$tmp=~s/^custom\=//;
                   1236: 		my ($k,$v)=map {&Apache::lonnet::unescape($_);
                   1237: 			    } split(/\,/,$tmp);
                   1238: 		$customhash{$k}=$v;
1.82      harris41 1239: 	    }
1.79      harris41 1240: 	}
1.101     harris41 1241: 	if (keys %hash) {
                   1242: 	    untie %hash;
                   1243: 	}
                   1244: 	if (tie(%hash,'GDBM_File',$diropendb,&GDBM_WRCREAT,0640)) {
                   1245: 	    if ($ENV{'form.launch'} eq '1') {
                   1246: 		&start_fresh_session();
                   1247: 	    }
                   1248: 	    foreach my $result (@results) {
                   1249: 		next if $result=~/^custom\=/;
                   1250: 		chomp $result;
                   1251: 		next unless $result;
                   1252: 		my @fields=map
                   1253: 		{&Apache::lonnet::unescape($_)}
                   1254: 		(split(/\,/,$result));
                   1255: 		my ($title,$author,$subject,$url,$keywords,$version,
                   1256: 		    $notes,$abstract,$mime,$lang,
                   1257: 		    $creationdate,$lastrevisiondate,$owner,$copyright)=@fields;
1.102     harris41 1258: 
                   1259: 		unless ($ENV{'user.adv'}) {
                   1260: 		    $keywords='<i>- not displayed -</i>';
                   1261: 		    $fields[4]=$keywords;
                   1262: 		    $notes='<i>- not displayed -</i>';
                   1263: 		    $fields[6]=$notes;
                   1264: 		    $abstract='<i>- not displayed -</i>';
                   1265: 		    $fields[7]=$abstract;
                   1266: 		    $subject='<i>- not displayed -</i>';
                   1267: 		    $fields[2]=$subject;
                   1268: 		}
                   1269: 
1.101     harris41 1270: 		my $shortabstract=$abstract;
1.102     harris41 1271: 		$shortabstract=substr($abstract,0,200).'...' if length($abstract)>200;
1.101     harris41 1272: 		$fields[7]=$shortabstract;
1.102     harris41 1273: 		my $shortkeywords=$keywords;
                   1274: 		$shortkeywords=substr($keywords,0,200).'...' if length($keywords)>200;
                   1275: 		$fields[4]=$shortkeywords;
                   1276: 
1.101     harris41 1277: 		my $extrashow2=$extrashow;
                   1278: 		if ($extrashow) {
                   1279: 		    foreach my $field (@customfields) {
                   1280: 			my $value='';
                   1281: 			if ($customhash{$url}=~/\<${field}[^\>]*\>(.*?)\<\/${field}[^\>]*\>/s) {
                   1282: 		            $value=$1;
                   1283: 			}
                   1284: 		        $extrashow2=~s/\<\!\-\- $field \-\-\>/ $value/g;
                   1285: 	            }
                   1286:                 }
1.93      harris41 1287: 	
1.101     harris41 1288: 	        $compiledresult.=<<END if $compiledresult or $servercount!=$servernum;
1.89      harris41 1289: <hr align='left' width='200' noshade />
                   1290: END
1.101     harris41 1291:                 $compiledresult.=<<END;
1.56      harris41 1292: <p>
1.8       harris41 1293: END
1.101     harris41 1294:                 $compiledresult.=<<END if $ENV{'form.catalogmode'} eq 'interactive';
1.8       harris41 1295: <font size='-1'><INPUT TYPE="button" NAME="returnvalues" VALUE="SELECT"
1.10      harris41 1296: onClick="javascript:select_data('$title','$url')">
1.8       harris41 1297: </font>
1.98      harris41 1298: <br />
                   1299: END
1.101     harris41 1300:                 if ($ENV{'form.catalogmode'} eq 'groupsearch') {
                   1301: 		    $fnum+=0;
                   1302: 		    $hash{"pre_${fnum}_link"}=$url;
                   1303: 		    $hash{"pre_${fnum}_title"}=$title;
                   1304: 		    $compiledresult.=<<END;
1.98      harris41 1305: <font size='-1'><input type="checkbox" name="returnvalues" value="SELECT"
                   1306: onClick="javascript:queue($fnum)" />
                   1307: </font>
                   1308: <br />
1.8       harris41 1309: END
1.101     harris41 1310: # <input type="hidden" name="title$fnum" value="$title" />
                   1311: # <input type="hidden" name="url$fnum" value="$url" />
                   1312:                     $fnum++;
                   1313: 		}
                   1314: 	        my $httphost=$ENV{'HTTP_HOST'};
                   1315: 
                   1316: 	        my $viewselect;
                   1317: 	        if ($mode eq 'Basic') {
                   1318: 		    $viewselect=$ENV{'form.basicviewselect'};
                   1319: 		}
                   1320: 	        elsif ($mode eq 'Advanced') {
                   1321: 		    $viewselect=$ENV{'form.advancedviewselect'};
                   1322: 		}
1.55      harris41 1323: 
1.101     harris41 1324: 	        if ($viewselect eq 'Detailed Citation View') {
                   1325: 		    $compiledresult.=&detailed_citation_view(@fields,
1.93      harris41 1326: 						 $hostname,$httphost,
                   1327: 						 $extrashow2);
1.101     harris41 1328: 		}
                   1329:                 elsif ($viewselect eq 'Summary View') {
                   1330: 		    $compiledresult.=&summary_view(@fields,$hostname,$httphost,
1.93      harris41 1331: 				       $extrashow2);
1.101     harris41 1332: 	        }
                   1333:                 elsif ($viewselect eq 'Fielded Format') {
                   1334: 		    $compiledresult.=&fielded_format_view(@fields,$hostname,
1.93      harris41 1335: 					      $httphost,$extrashow2);
1.101     harris41 1336: 	        }
                   1337:                 elsif ($viewselect eq 'XML/SGML') {
                   1338: 		    $compiledresult.=&xml_sgml_view(@fields,$hostname,$httphost,
1.93      harris41 1339: 					$extrashow2);
1.101     harris41 1340: 		}
1.93      harris41 1341:     
1.101     harris41 1342:             }
                   1343: 
                   1344:             untie %hash;
1.18      harris41 1345:         }
1.101     harris41 1346:         else {
                   1347: 	    $r->print('<html><head></head><body>Unable to tie hash to db '.
                   1348: 		  'file</body></html>');
                   1349: 	}
1.93      harris41 1350: 	if ($compiledresult) {
                   1351: 	    $resultflag=1;
1.18      harris41 1352: 	}
1.6       harris41 1353: 
1.43      harris41 1354: 	$r->print(<<RESULTS);
1.93      harris41 1355: $compiledresult
1.43      harris41 1356: RESULTS
1.93      harris41 1357:         my $percent=sprintf('%3.0f',($servercount/$servernum*100));
1.44      harris41 1358:     }
1.102     harris41 1359:   }
1.93      harris41 1360:     unless ($resultflag) {
                   1361:         $r->print("\nThere were no results that matched your query\n");
1.43      harris41 1362:     }
1.100     harris41 1363: #    $r->print('<script type="text/javascript">'.'popwin.close()</script>'."\n"); $r->rflush(); 
1.93      harris41 1364:     $r->print(<<RESULTS);
1.6       harris41 1365: </body>
                   1366: </html>
                   1367: RESULTS
1.41      harris41 1368: }
                   1369: 
1.50      harris41 1370: # ------------------------------------------------------ Detailed Citation View
                   1371: sub detailed_citation_view {
                   1372:     my ($title,$author,$subject,$url,$keywords,$version,
1.51      harris41 1373: 	$notes,$shortabstract,$mime,$lang,
                   1374: 	$creationdate,$lastrevisiondate,$owner,$copyright,
1.77      harris41 1375: 	$hostname,$httphost,$extrashow)=@_;
1.50      harris41 1376:     my $result=<<END;
1.56      harris41 1377: <i>$owner</i>, last revised $lastrevisiondate
                   1378: <h3><A HREF="http://$httphost$url" TARGET='search_preview'>$title</A></h3>
                   1379: <h3>$author</h3>
                   1380: </p>
                   1381: <p>
1.98      harris41 1382: <b>Subject:</b> $subject<br />
                   1383: <b>Keyword(s):</b> $keywords<br />
                   1384: <b>Notes:</b> $notes<br />
                   1385: <b>MIME Type:</b> $mimetag{$mime}<br />
                   1386: <b>Language:</b> $language{$lang}<br />
                   1387: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
1.78      harris41 1388: </p>
1.77      harris41 1389: $extrashow
1.78      harris41 1390: <p>
1.56      harris41 1391: $shortabstract
1.50      harris41 1392: </p>
                   1393: END
                   1394:     return $result;
                   1395: }
                   1396: 
                   1397: # ---------------------------------------------------------------- Summary View
                   1398: sub summary_view {
                   1399:     my ($title,$author,$subject,$url,$keywords,$version,
1.51      harris41 1400: 	$notes,$shortabstract,$mime,$lang,
                   1401: 	$creationdate,$lastrevisiondate,$owner,$copyright,
1.77      harris41 1402: 	$hostname,$httphost,$extrashow)=@_;
1.50      harris41 1403:     my $result=<<END;
1.56      harris41 1404: <a href="http://$httphost$url" TARGET='search_preview'>$author</a><br />
                   1405: $title<br />
                   1406: $owner -- $lastrevisiondate<br />
                   1407: $cprtag{$copyright}<br />
1.77      harris41 1408: $extrashow
1.50      harris41 1409: </p>
                   1410: END
                   1411:     return $result;
                   1412: }
                   1413: 
                   1414: # -------------------------------------------------------------- Fielded Format
                   1415: sub fielded_format_view {
                   1416:     my ($title,$author,$subject,$url,$keywords,$version,
1.51      harris41 1417: 	$notes,$shortabstract,$mime,$lang,
                   1418: 	$creationdate,$lastrevisiondate,$owner,$copyright,
1.77      harris41 1419: 	$hostname,$httphost,$extrashow)=@_;
1.50      harris41 1420:     my $result=<<END;
1.51      harris41 1421: <b>URL: </b> <A HREF="http://$httphost$url" TARGET='search_preview'>$url</A>
1.56      harris41 1422: <br />
                   1423: <b>Title:</b> $title<br />
                   1424: <b>Author(s):</b> $author<br />
                   1425: <b>Subject:</b> $subject<br />
                   1426: <b>Keyword(s):</b> $keywords<br />
                   1427: <b>Notes:</b> $notes<br />
                   1428: <b>MIME Type:</b> $mimetag{$mime}<br />
                   1429: <b>Language:</b> $language{$lang}<br />
                   1430: <b>Creation Date:</b> $creationdate<br />
                   1431: <b>Last Revision Date:</b> $lastrevisiondate<br />
                   1432: <b>Publisher/Owner:</b> $owner<br />
                   1433: <b>Copyright/Distribution:</b> $cprtag{$copyright}<br />
                   1434: <b>Repository Location:</b> $hostname<br />
                   1435: <b>Abstract:</b> $shortabstract<br />
1.77      harris41 1436: $extrashow
1.50      harris41 1437: </p>
                   1438: END
                   1439:     return $result;
                   1440: }
                   1441: 
                   1442: # -------------------------------------------------------------------- XML/SGML
                   1443: sub xml_sgml_view {
                   1444:     my ($title,$author,$subject,$url,$keywords,$version,
1.51      harris41 1445: 	$notes,$shortabstract,$mime,$lang,
                   1446: 	$creationdate,$lastrevisiondate,$owner,$copyright,
1.77      harris41 1447: 	$hostname,$httphost,$extrashow)=@_;
1.50      harris41 1448:     my $result=<<END;
1.56      harris41 1449: <pre>
                   1450: &lt;LonCapaResource&gt;
1.57      harris41 1451: &lt;url&gt;$url&lt;/url&gt;
1.56      harris41 1452: &lt;title&gt;$title&lt;/title&gt;
                   1453: &lt;author&gt;$author&lt;/author&gt;
                   1454: &lt;subject&gt;$subject&lt;/subject&gt;
                   1455: &lt;keywords&gt;$keywords&lt;/keywords&gt;
                   1456: &lt;notes&gt;$notes&lt;/notes&gt;
                   1457: &lt;mimeInfo&gt;
                   1458: &lt;mime&gt;$mime&lt;/mime&gt;
                   1459: &lt;mimetag&gt;$mimetag{$mime}&lt;/mimetag&gt;
                   1460: &lt;/mimeInfo&gt;
                   1461: &lt;languageInfo&gt;
                   1462: &lt;language&gt;$lang&lt;/language&gt;
                   1463: &lt;languagetag&gt;$language{$lang}&lt;/languagetag&gt;
                   1464: &lt;/languageInfo&gt;
                   1465: &lt;creationdate&gt;$creationdate&lt;/creationdate&gt;
                   1466: &lt;lastrevisiondate&gt;$lastrevisiondate&lt;/lastrevisiondate&gt;
                   1467: &lt;owner&gt;$owner&lt;/owner&gt;
                   1468: &lt;copyrightInfo&gt;
                   1469: &lt;copyright&gt;$copyright&lt;/copyright&gt;
                   1470: &lt;copyrighttag&gt;$cprtag{$copyright}&lt;/copyrighttag&gt;
                   1471: &lt;/copyrightInfo&gt;
                   1472: &lt;repositoryLocation&gt;$hostname&lt;/repositoryLocation&gt;
                   1473: &lt;shortabstract&gt;$shortabstract&lt;/shortabstract&gt;
1.57      harris41 1474: &lt;/LonCapaResource&gt;
1.56      harris41 1475: </pre>
1.77      harris41 1476: $extrashow
1.50      harris41 1477: END
                   1478:     return $result;
1.60      harris41 1479: }
                   1480: 
1.98      harris41 1481: # ---------------------------------------------------- see if a field is filled
                   1482: sub filled {
                   1483:     my ($field)=@_;
                   1484:     if ($field=~/\S/ && $field ne 'any') {
                   1485: 	return 1;
1.61      harris41 1486:     }
1.98      harris41 1487:     else {
                   1488: 	return 0;
1.61      harris41 1489:     }
1.60      harris41 1490: }
                   1491: 
1.98      harris41 1492: # ---------------- Message to output when there are not enough fields filled in
                   1493: sub output_blank_field_error {
                   1494:     my ($r)=@_;
                   1495:     # make query information persistent to allow for subsequent revision
                   1496:     my $persistent=&make_persistent();
                   1497: 
                   1498:     $r->print(<<BEGINNING);
                   1499: <html>
                   1500: <head>
                   1501: <title>The LearningOnline Network with CAPA</title>
                   1502: BEGINNING
                   1503:     $r->print(<<RESULTS);
                   1504: </head>
                   1505: <body bgcolor="#ffffff">
                   1506: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
                   1507: <h1>Search Catalog</h1>
                   1508: <form method="post" action="/adm/searchcat">
                   1509: $persistent
                   1510: <input type='button' value='Revise search request'
                   1511: onClick='this.form.submit();' />
                   1512: $closebutton
                   1513: <hr />
                   1514: <h3>Helpful Message</h3>
                   1515: <p>
                   1516: Incorrect search query due to blank entry fields.
                   1517: You need to fill in the relevant
                   1518: fields on the search page in order for a query to be
                   1519: processed.
                   1520: </p>
                   1521: </body>
                   1522: </html>
                   1523: RESULTS
                   1524: }
                   1525: 
                   1526: # ----------------------------------------------------------- Output date error
1.60      harris41 1527: sub output_date_error {
                   1528:     my ($r,$message)=@_;
                   1529:     # make query information persistent to allow for subsequent revision
1.65      harris41 1530:     my $persistent=&make_persistent();
1.60      harris41 1531: 
                   1532:     $r->print(<<BEGINNING);
                   1533: <html>
                   1534: <head>
                   1535: <title>The LearningOnline Network with CAPA</title>
                   1536: BEGINNING
                   1537:     $r->print(<<RESULTS);
                   1538: </head>
                   1539: <body bgcolor="#ffffff">
1.98      harris41 1540: <img align='right' src='/adm/lonIcons/lonlogos.gif' />
1.60      harris41 1541: <h1>Search Catalog</h1>
                   1542: <form method="post" action="/adm/searchcat">
                   1543: $persistent
                   1544: <input type='button' value='Revise search request'
1.98      harris41 1545: onClick='this.form.submit();' />
1.60      harris41 1546: $closebutton
1.98      harris41 1547: <hr />
1.60      harris41 1548: <h3>Helpful Message</h3>
                   1549: <p>
                   1550: $message
                   1551: </p>
                   1552: </body>
                   1553: </html>
                   1554: RESULTS
1.101     harris41 1555: }
                   1556: 
                   1557: # --------- settings whenever the user causes the indexer window to be launched
                   1558: sub start_fresh_session {
                   1559:     delete $hash{'mode_catalog'};
                   1560:     map {
                   1561:         if ($_ =~ /^pre_/) {
                   1562:             delete $hash{$_};
                   1563:         }
                   1564:         if ($_ =~ /^store/) {
                   1565: 	    delete $hash{$_};
                   1566: 	}
                   1567:     } keys %hash;
1.3       harris41 1568: }
1.1       www      1569: 
                   1570: 1;
1.98      harris41 1571: 
1.1       www      1572: __END__

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