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

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

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