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

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

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