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

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

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