/[webpac-proto]/search/Search.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /search/Search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (show annotations)
Thu Oct 24 18:42:18 2002 UTC (16 years, 10 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.26: +2 -3 lines
output of types are configurable

1 #!/usr/bin/perl -w
2
3 #*****************************************************************************
4 # Copyright (C) 1993-2000, FS Consulting Inc. All rights reserved *
5 # *
6 # *
7 # This notice is intended as a precaution against inadvertent publication *
8 # and does not constitute an admission or acknowledgement that publication *
9 # has occurred or constitute a waiver of confidentiality. *
10 # *
11 # This software is the proprietary and confidential property *
12 # of FS Consulting, Inc. *
13 #*****************************************************************************
14
15 #print "Content-type: text/plain\n\n";
16
17 #use Data::Dumper;
18
19 #--------------------------------------------------------------------------
20 #
21 # Author: Francois Schiettecatte (FS Consulting, Inc.)
22 # Creation Date: 8/9/96
23
24
25 #--------------------------------------------------------------------------
26 #
27 # Description:
28 #
29 # This script implements the search interface into the search engine. We
30 # interface with the search engine using the Direct protocol.
31 #
32
33
34 #--------------------------------------------------------------------------
35 #
36 # Modification Log
37 #
38 # Date:
39 # Author:
40 # Organization:
41 # Email:
42 # Description:
43 #
44 #
45 # Date: 8/9/96
46 # Author: Francois Schiettecatte
47 # Organization: FS Consulting, Inc.
48 # Email: francois@fsconsult.com
49 # Description: First cut.
50
51
52 #--------------------------------------------------------------------------
53 #
54 # CGI-BIN mode usage
55 #
56
57 # We use the following environment variables from the cgi-bin environment:
58 #
59 # $PATH_INFO - action requested
60 # $QUERY_STRING - contains the query
61 # $REMOTE_USER - user account name
62 # $REQUEST_METHOD - request method
63 # $SCRIPT_NAME - script name
64 #
65
66
67 # We create the following variables as we go along,
68 # these will both be empty if this is a guest user
69 #
70 # $main::RemoteUser - contains the remote user name
71 # $main::UserAccountDirectoryPath - contains the path name to the user account directory
72 # $main::UserSettingsFilePath - contains the path name to the user information file
73 #
74
75
76 # User directory structure
77 #
78 # /AccountName (user directory)
79 #
80
81
82 #--------------------------------------------------------------------------
83 #
84 # Pragmatic modules
85 #
86
87 use strict;
88
89
90 #--------------------------------------------------------------------------
91 #
92 # Set the default configuration directories, files & parameters
93 #
94
95
96 # Root directory path
97 $main::RootDirectoryPath = (($main::Index = rindex($0, "/")) >= 0) ? substr($0, 0, $main::Index) : ".";
98
99 # Program name
100 $main::ProgramName = (($main::Index = rindex($0, "/")) >= 0) ? substr($0, $main::Index + 1) : $0;
101
102 # Program base name
103 $main::ProgramBaseName = (($main::Index = rindex($main::ProgramName, ".")) >= 0) ? substr($main::ProgramName, 0, $main::Index) : $main::ProgramName;
104
105
106 # Log directory path
107 $main::LogDirectoryPath = $main::RootDirectoryPath . "/logs";
108
109
110 # Configuration file path
111 $main::ConfigurationFilePath = $main::RootDirectoryPath . "/" . $main::ProgramBaseName . ".cf";
112
113 # Log file path
114 $main::LogFilePath = $main::LogDirectoryPath . "/" . lc($main::ProgramBaseName) . ".log";
115
116
117
118 # Log file roll-over
119 #$main::LogFileRollOver = 0;
120
121
122
123 #--------------------------------------------------------------------------
124 #
125 # Required packages
126 #
127
128 # Load the libraries
129 push @INC, $main::RootDirectoryPath;
130 require "Library.pl";
131
132
133 # Load the MPS Information Server library
134 use MPS;
135
136 #--------------------------------------------------------------------------
137 #
138 # Environment variables
139 #
140
141 # Set up the environment so that we can find the external applications we need
142 $ENV{'PATH'} = "/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/etc";
143 $ENV{'LD_LIBRARY_PATH'} = "/usr/lib";
144
145
146 #--------------------------------------------------------------------------
147 #
148 # Global
149 #
150
151 # Configuration global (used to store the information read in from the configuration file)
152 undef(%main::ConfigurationData);
153
154
155 # Database descriptions global (used to store the information read in from the database description file)
156 undef(%main::DatabaseDescriptions);
157 undef(%main::DatabaseSort);
158
159
160 # Database Filters global (used to store the information read in from the database description file)
161 undef(%main::DatabaseFilters);
162
163
164 # Global flags which are set after sending the html header and footer
165 $main::HeaderSent = 0;
166 $main::FooterSent = 0;
167
168 # Form data global (this is used to store the information decoded from a form)
169 undef(%main::FormData);
170
171
172 # User account information
173 undef($main::UserSettingsFilePath);
174 undef($main::UserAccountDirectoryPath);
175 undef($main::RemoteUser);
176
177
178 $main::MPSSession = 0;
179
180 #--------------------------------------------------------------------------
181 #
182 # Configuration Constants
183 #
184
185
186 # read configuration fields
187 require "config.pm";
188
189 # List of required configuration settings
190 @main::RequiredSettings = (
191 'html-directory',
192 'logs-directory',
193 'image-base-path',
194 'database-directory',
195 'configuration-directory'
196 );
197
198
199
200 $main::DatabaseName = "database-name";
201 $main::DatabaseFiltersPackage = "database-filters-package";
202 $main::DatabaseDocumentFilter = "database-document-filter";
203 $main::DatabaseSummaryFilter = "database-summary-filter";
204 $main::DatabaseRelevanceFeedbackFilter = "database-relevance-feedback-filter";
205
206
207 #--------------------------------------------------------------------------
208 #
209 # Application Constants
210 #
211
212
213 # XML file name extension
214 $main::XMLFileNameExtension = ".xml";
215
216
217 # User Settings file
218 $main::UserSettingsFileName = "UserSettings";
219
220 # Saved Search file preamble
221 $main::SavedSearchFileNamePrefix = "SavedSearch";
222
223 # Search history file preamble
224 $main::SearchHistoryFileNamePrefix = "SearchHistory";
225
226 # Document Folder file preamble
227 $main::DocumentFolderFileNamePrefix = "DocumentFolder";
228
229
230 # Query report item name and mime type
231 $main::QueryReportItemName = "document";
232 $main::QueryReportMimeType = "application/x-wais-report";
233
234
235 # Array of mime type names, we use this to map
236 # mime types to mime type names (which are more readable)
237 %main::MimeTypeNames = (
238 'text/plain', 'Text',
239 'text/html', 'HTML',
240 'text/http', 'HTML',
241 'text/http', 'HTML',
242 'image/gif', 'GIF Image',
243 'image/tif', 'TIF Image',
244 'image/jpeg', 'JPEG Image',
245 'image/jfif', 'JPEG Image',
246 );
247
248
249 # Array of mime types that we can resonably use for relevance feedback
250 %main::RFMimeTypes = (
251 'text/plain', 'text/plain',
252 'text/html', 'text/html',
253 'text/http', 'text/http',
254 );
255
256
257 # Array of mime types that are in HTML
258 %main::HtmlMimeTypes = (
259 'text/html', 'text/html',
260 'text/http', 'text/http',
261 );
262
263
264 # DbP: replaced by NormalSearchFieldNames and AdvancedSearchFieldNames
265 # Search fields
266 #@main::SearchFieldNames = (
267 # '200-ae',
268 # '700,701,702,710,711',
269 # '610'
270 #);
271
272 # DbP: this variable will be filled using MPS::GetDatabaseFieldInfo
273 %main::SearchFieldDescriptions = (
274 # 'title', 'Title',
275 # 'abstract', 'Abstract',
276 # 'author', 'Author',
277 # 'journal', 'Journal',
278 );
279
280
281 # Date list
282 @main::PastDate = (
283 'Week',
284 'Month',
285 '3 Months',
286 '6 Months',
287 '9 Months',
288 'Year'
289 );
290
291 # Default maximum number of documents
292 $main::DefaultMaxDoc = 50;
293
294 # Maximum docs list used for the search form pull-down
295 @main::MaxDocs = ( '10', '25', '50', '100', '250', '500', '750');
296
297
298 # Default maximum search history
299 $main::DefaultMaxSearchHistory = 15;
300
301
302 # Summary type for the settings form pull-down
303 %main::SummaryTypes = (
304 'none', 'None',
305 'keyword', 'Keywords in Context',
306 'default', 'Default summary',
307 );
308
309
310 # Summary length for the settings form pull-down
311 @main::SummaryLengths = ( '20', '40', '60', '80', '100', '120' );
312
313 # Default summary length
314 $main::DefaultSummaryLength = 40;
315
316 # Default summary type
317 $main::DefaultSummaryType = "default";
318
319
320 # Similar documents for the settings form pull-down
321 @main::SimilarDocuments = ( '1', '3', '5', '10' );
322
323 # Default similar document
324 $main::DefaultSimilarDocument = 5;
325
326 # Token span on either side of the summary keyword
327 $main::SummaryKeywordSpan = 9;
328
329
330 # Delivery format
331 %main::DeliveryFormats = (
332 'text/plain', 'Plain text',
333 'text/html', 'HTML',
334 );
335
336 # Delivery methods
337 %main::DeliveryMethods = (
338 'message', 'Email message',
339 'attachement', 'Email attachement',
340 );
341
342
343 # Search frequency
344 @main::SearchFrequencies = (
345 'Daily',
346 'Weekly',
347 'Monthly'
348 );
349
350
351 # Default maximum visible URL length
352 $main::DefaultMaxVisibleUrlLength = 80;
353
354
355 #--------------------------------------------------------------------------
356 #
357 # Function: vSendHTMLHeader()
358 #
359 # Purpose: This function send the HTML header
360 #
361 # Called by:
362 #
363 # Parameters: $Title HTML page title
364 # $JavaScript JavaScript to send
365 #
366 # Global Variables: $main::HeaderSent
367 #
368 # Returns: void
369 #
370 sub vSendHTMLHeader {
371
372 my ($Title, $JavaScript) = @_;
373
374
375 # Bail if we are not running as a CGI-BIN script
376 if ( ! $ENV{'GATEWAY_INTERFACE'} ) {
377 return;
378 }
379
380 # Bail if we have already sent the header
381 if ( $main::HeaderSent ) {
382 return;
383 }
384
385
386 # Send the CGI-BIN response header
387 print("Content-type: text/html\n\n");
388
389 # Put out the html document header
390 printf("<HTML>\n<HEAD>\n<TITLE>\n%s\n</TITLE>\n", defined($Title) ? $Title : "FS Consulting - MPS Direct Search Interface");
391 if ( defined($JavaScript) ) {
392 print("$JavaScript\n");
393 }
394 print '<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-2">';
395 print '<link rel="STYLESHEET" type="text/css" href="'.$main::ConfigurationData{'image-base-path'}.'/stil.css">';
396 print("</HEAD>\n<BODY BGCOLOR=\"ffffe8\">\n");
397
398
399 # Send the header snippet file
400 &vPrintFileContent($main::ConfigurationData{'html-header-snippet-file'});
401
402
403 # Send the banner
404 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
405 # print("<TR><TD VALIGN=TOP ALIGN=RIGHT> <A HREF=\"/\" OnMouseOver=\"self.status='Return Home'; return true\"><IMG SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'banner'}\" ALT=\"Return Home\" BORDER=0></A> </TD></TR>\n");
406
407 print("<TR><TD VALIGN=TOP ALIGN=RIGHT> <A HREF=\"/\" OnMouseOver=\"self.status='Return Home'; return true\"><H3>Katalozi knji¾nica Filozofskog fakulteta</H3> </A> </TD></TR>\n");
408
409 print("</TABLE>\n");
410
411
412 # Set the flag saying that the header has been sent
413 $main::HeaderSent = 1;
414
415 return;
416
417 }
418
419
420
421 #--------------------------------------------------------------------------
422 #
423 # Function: vSendHTMLFooter()
424 #
425 # Purpose: This function send the HTML footer
426 #
427 # Called by:
428 #
429 # Parameters: void
430 #
431 # Global Variables: $main::FooterSent
432 #
433 # Returns: void
434 #
435 sub vSendHTMLFooter {
436
437
438 # Bail if we are not running as a CGI-BIN script
439 if ( ! $ENV{'GATEWAY_INTERFACE'} ) {
440 return;
441 }
442
443 # Bail if we have already sent the footer
444 if ( $main::FooterSent ) {
445 return;
446 }
447
448
449 # Send the footer snippet file
450 &vPrintFileContent($main::ConfigurationData{'html-footer-snippet-file'});
451
452
453 # Send the end of body tag and end of HTML tag
454 print("</BODY>\n</HTML>\n");
455
456
457 # Set the flag saying that the footer has been sent
458 $main::FooterSent = 1;
459
460 return;
461
462 }
463
464
465
466 #--------------------------------------------------------------------------
467 #
468 # Function: vSendMenuBar()
469 #
470 # Purpose: This function send the mneu bar
471 #
472 # Called by:
473 #
474 # Parameters: %MenuBar menu bar exclusion hash table
475 #
476 # Global Variables:
477 #
478 # Returns: void
479 #
480 sub vSendMenuBar {
481
482 my (%MenuBar) = @_;
483
484 my (%Value, $Value, $ValueEntry);
485
486
487 # Start the table
488 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
489
490 # Start the menu bar cell
491 print("<TR><TD VALIGN=CENTER ALIGN=CENTER>\n");
492
493 # Start the form
494 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
495
496
497
498 # List the hidden fields
499 %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
500 foreach $Value ( keys(%Value) ) {
501 foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
502 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
503 }
504 }
505
506 my $DISABLED;
507
508 $DISABLED = ( %MenuBar && defined($MenuBar{'GetSearch'}) ) ? "DISABLED" : "";
509 print("<INPUT NAME=\"GetSearch\" TYPE=SUBMIT VALUE=\"Pretra¾ivanje\" $DISABLED class=\"navigacija${DISABLED}\">");
510
511 if ( defined($main::RemoteUser) ) {
512 $DISABLED = ( %MenuBar && defined($MenuBar{'ListSearchHistory'}) ) ? "DISABLED" : "";
513 print"<INPUT NAME=\"ListSearchHistory\" TYPE=SUBMIT VALUE=\"Prija¹nja pretra¾ivanja\" $DISABLED class=\"navigacija${DISABLED}\">";
514
515 $DISABLED = ( %MenuBar && defined($MenuBar{'ListSavedSearch'}) ) ? "DISABLED" : "";
516 print"<INPUT NAME=\"ListSavedSearch\" TYPE=SUBMIT VALUE=\"Saèuvani upiti\" $DISABLED class=\"navigacija${DISABLED}\">";
517
518 $DISABLED = ( %MenuBar && defined($MenuBar{'ListFolder'}) ) ? "DISABLED" : "";
519 print"<INPUT NAME=\"ListFolder\" TYPE=SUBMIT VALUE=\"Korisnièki folderi\" $DISABLED class=\"navigacija${DISABLED}\">";
520
521 $DISABLED = ( %MenuBar && defined($MenuBar{'GetUserSettings'}) ) ? "DISABLED" : "";
522 print"<INPUT NAME=\"GetUserSettings\" TYPE=SUBMIT VALUE=\"Korisnièke postavke\" $DISABLED class=\"navigacija${DISABLED}\">";
523 }
524
525
526 print("</FORM>\n");
527
528 # Close off the menu bar cell
529 print("</TD></TR>\n");
530
531 print("</TABLE>\n");
532
533
534 return;
535 }
536
537
538
539
540
541
542 #--------------------------------------------------------------------------
543 #
544 # Function: vHandleError()
545 #
546 # Purpose: This function handles any errors messages that need to be
547 # reported when an error occurs
548 #
549 # This error handler also displays the header if needed
550 #
551 # Called by:
552 #
553 # Parameters: $Header header
554 # $Message message
555 #
556 # Global Variables:
557 #
558 # Returns: void
559 #
560 sub vHandleError {
561
562 my ($Header, $Message) = @_;
563
564 my ($Package, $FileName, $Line);
565
566
567 # Make sure we send the header
568 &vSendHTMLHeader("Error", undef);
569
570
571 printf("<H3> %s: </H3>\n", defined($Header) ? $Header : "No header supplied");
572 printf("<H3><CENTER> %s. </CENTER></H3>\n", defined($Message) ? $Message : "No error message supplied");
573 print("<P>\n");
574 if ( defined($main::ConfigurationData{'site-admin-url'}) ) {
575 print("<CENTER> Please <A HREF=\"$main::ConfigurationData{'site-admin-url'}\"> contact the administrator </A> of this system to correct the problem. </CENTER>\n");
576 }
577 else {
578 print("<CENTER> Please contact the administrator of this system to correct the problem. </CENTER>\n");
579 }
580 print("<P><HR WIDTH=50%><P>\n");
581
582
583 # Send package information
584 # ($Package, $FileName, $Line) = caller;
585 # print("Package = [$Package], FileName = [$FileName], Line = [$Line] <BR>\n");
586
587 return;
588 }
589
590
591
592
593
594 #--------------------------------------------------------------------------
595 #
596 # Function: bCheckConfiguration()
597 #
598 # Purpose: This function checks that the configuration settings
599 # specified are correct and that any directory paths and
600 # files specified are there and can be accessed.
601 #
602 # We check both required settings and optional setting if
603 # they have been set.
604 #
605 # An error here should be considered fatal.
606 #
607 # Called by:
608 #
609 # Parameters: void
610 #
611 # Global Variables: %main::ConfigurationData
612 #
613 # Returns: Boolean status
614 #
615 sub bCheckConfiguration {
616
617 my ($Value, $Status);
618
619
620 # Init the status
621 $Status = 1;
622
623
624 # Check 'user-accounts-directory' (optional)
625 if ( defined($main::ConfigurationData{'user-accounts-directory'}) ) {
626
627 $main::ConfigurationData{'user-accounts-directory'} = &sCleanSetting('user-accounts-directory', $main::ConfigurationData{'user-accounts-directory'}, $main::RootDirectoryPath);
628 $Value = $main::ConfigurationData{'user-accounts-directory'};
629
630 # Check that the directory exists
631 if ( ! (-d $Value) ) {
632 &vLog("Error - configuration setting: 'user-accounts-directory', directory: '$Value' does not exist.\n");
633 $Status = 0;
634 }
635 else {
636
637 # The directory exists, now check that it can be accessed
638 if ( ! ((-r $Value) && (-w $Value) && (-x $Value)) ) {
639 &vLog("Error - configuration setting: 'user-accounts-directory', directory: '$Value' cannot be accessed.\n");
640 $Status = 0;
641 }
642 }
643 }
644
645
646
647 # Check 'database-description-file' (optional)
648 if ( defined($main::ConfigurationData{'database-description-file'}) ) {
649
650 $main::ConfigurationData{'database-description-file'} = &sCleanSetting('database-description-file', $main::ConfigurationData{'database-description-file'}, $main::RootDirectoryPath);
651 $Value = $main::ConfigurationData{'database-description-file'};
652
653 # Check that the file exists
654 if ( ! ((-f $Value) && (-r $Value)) ) {
655 &vLog("Error - configuration setting: 'database-description-file', file: '$Value' does not exist.\n");
656 $Status = 0;
657 }
658 }
659
660
661
662 # Check 'allow-summary-displays' (optional)
663 if ( defined($main::ConfigurationData{'allow-summary-displays'}) ) {
664
665 # Clean the setting and convert to lower case
666 $main::ConfigurationData{'allow-summary-displays'} = &sCleanSetting('allow-summary-displays', $main::ConfigurationData{'allow-summary-displays'});
667 $main::ConfigurationData{'allow-summary-displays'} = lc($main::ConfigurationData{'allow-summary-displays'});
668
669 # Check that the setting is valid
670 if ( ($main::ConfigurationData{'allow-summary-displays'} ne "yes") && ($main::ConfigurationData{'allow-summary-displays'} ne "no")) {
671 &vLog("Warning - configuration setting: 'allow-summary-displays', setting not recognized: $main::ConfigurationData{'allow-summary-displays'}.\n");
672 }
673 }
674
675
676
677 # Check 'allow-similiar-search' (optional)
678 if ( defined($main::ConfigurationData{'allow-similiar-search'}) ) {
679
680 # Clean the setting and convert to lower case
681 $main::ConfigurationData{'allow-similiar-search'} = &sCleanSetting('allow-similiar-search', $main::ConfigurationData{'allow-similiar-search'});
682 $main::ConfigurationData{'allow-similiar-search'} = lc($main::ConfigurationData{'allow-similiar-search'});
683
684 # Check that the setting is valid
685 if ( ($main::ConfigurationData{'allow-similiar-search'} ne "yes") && ($main::ConfigurationData{'allow-similiar-search'} ne "no")) {
686 &vLog("Warning - configuration setting: 'allow-similiar-search', setting not recognized: $main::ConfigurationData{'allow-similiar-search'}.\n");
687 }
688 }
689
690
691
692 # Check 'allow-regular-searches' (optional)
693 if ( defined($main::ConfigurationData{'allow-regular-searches'}) ) {
694
695 # Clean the setting and convert to lower case
696 $main::ConfigurationData{'allow-regular-searches'} = &sCleanSetting('allow-regular-searches', $main::ConfigurationData{'allow-regular-searches'});
697 $main::ConfigurationData{'allow-regular-searches'} = lc($main::ConfigurationData{'allow-regular-searches'});
698
699 # Check that the setting is valid
700 if ( ($main::ConfigurationData{'allow-regular-searches'} ne "yes") && ($main::ConfigurationData{'allow-regular-searches'} ne "no")) {
701 &vLog("Warning - configuration setting: 'allow-regular-searches', setting not recognized: $main::ConfigurationData{'allow-regular-searches'}.\n");
702 }
703 }
704
705
706
707 # Check 'deliver-empty-results-from-regular-search' (optional)
708 if ( defined($main::ConfigurationData{'deliver-empty-results-from-regular-search'}) ) {
709
710 # Clean the setting and convert to lower case
711 $main::ConfigurationData{'deliver-empty-results-from-regular-search'} = &sCleanSetting('deliver-empty-results-from-regular-search', $main::ConfigurationData{'deliver-empty-results-from-regular-search'});
712 $main::ConfigurationData{'deliver-empty-results-from-regular-search'} = lc($main::ConfigurationData{'deliver-empty-results-from-regular-search'});
713
714 # Check that the setting is valid
715 if ( ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} ne "yes") && ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} ne "no")) {
716 &vLog("Warning - configuration setting: 'deliver-empty-results-from-regular-search', setting not recognized: $main::ConfigurationData{'deliver-empty-results-from-regular-search'}.\n");
717 }
718 }
719
720
721
722 # Check 'allow-relevance-feedback-searches' (optional)
723 if ( defined($main::ConfigurationData{'allow-relevance-feedback-searches'}) ) {
724
725 # Clean the setting and convert to lower case
726 $main::ConfigurationData{'allow-relevance-feedback-searches'} = &sCleanSetting('allow-relevance-feedback-searches', $main::ConfigurationData{'allow-relevance-feedback-searches'});
727 $main::ConfigurationData{'allow-relevance-feedback-searches'} = lc($main::ConfigurationData{'allow-relevance-feedback-searches'});
728
729 # Check that the setting is valid
730 if ( ($main::ConfigurationData{'allow-relevance-feedback-searches'} ne "yes") && ($main::ConfigurationData{'allow-relevance-feedback-searches'} ne "no")) {
731 &vLog("Warning - configuration setting: 'allow-relevance-feedback-searches', setting not recognized: $main::ConfigurationData{'allow-relevance-feedback-searches'}.\n");
732 }
733 }
734
735
736
737 # Check 'html-directory' (required)
738 $main::ConfigurationData{'html-directory'} = &sCleanSetting('html-directory', $main::ConfigurationData{'html-directory'}, $main::RootDirectoryPath);
739 $Value = $main::ConfigurationData{'html-directory'};
740
741 # Check that the directory exists
742 if ( ! (-d $Value) ) {
743 &vLog("Error - configuration setting: 'html-directory', directory: '$Value' does not exist.\n");
744 $Status = 0;
745 }
746 else {
747
748 # The directory exists, now check that it can be accessed
749 if ( ! ((-r $Value) && (-x $Value)) ) {
750 &vLog("Error - configuration setting: 'html-directory', directory: '$Value' cannot be accessed.\n");
751 $Status = 0;
752 }
753 }
754
755
756
757 # Check 'image-base-path' (required)
758 $main::ConfigurationData{'image-base-path'} = &sCleanSetting('image-base-path', $main::ConfigurationData{'image-base-path'});
759 $Value = $main::ConfigurationData{'html-directory'} . $main::ConfigurationData{'image-base-path'};
760
761 # Check that the directory exists
762 if ( ! (-d $Value) ) {
763 &vLog("Error - configuration setting: 'image-base-path', directory: '$Value' does not exist.\n");
764 $Status = 0;
765 }
766 else {
767
768 my ($ImageName);
769
770 # The directory exists, now check that it can be accessed
771 if ( ! ((-r $Value) && (-x $Value)) ) {
772 &vLog("Error - configuration setting: 'image-base-path', directory: '$Value' cannot be accessed.\n");
773 $Status = 0;
774 }
775
776
777 # Check the general icons
778 foreach $ImageName ( values(%main::ImageNames) ) {
779
780 $Value = $main::ConfigurationData{'html-directory'} . $main::ConfigurationData{'image-base-path'} . "/" . $ImageName;
781
782 # Check that the file exists
783 if ( ! ((-f $Value) && (-r $Value)) ) {
784 &vLog("Error - configuration setting: 'image-base-path', file: '$Value' does not exist.\n");
785 $Status = 0;
786 }
787 }
788 }
789
790
791
792 # Check 'html-header-snippet-file' (optional)
793 if ( defined($main::ConfigurationData{'html-header-snippet-file'}) ) {
794
795 $main::ConfigurationData{'html-header-snippet-file'} = &sCleanSetting('html-header-snippet-file', $main::ConfigurationData{'html-header-snippet-file'}, $main::RootDirectoryPath);
796 $Value = $main::ConfigurationData{'html-header-snippet-file'};
797
798 # Check that the file exists
799 if ( ! ((-f $Value) && (-r $Value)) ) {
800 &vLog("Error - configuration setting: 'html-header-snippet-file', file: '$Value' does not exist.\n");
801 $Status = 0;
802 }
803 }
804
805
806
807 # Check 'html-footer-snippet-file' (optional)
808 if ( defined($main::ConfigurationData{'html-footer-snippet-file'}) ) {
809
810 $main::ConfigurationData{'html-footer-snippet-file'} = &sCleanSetting('html-footer-snippet-file', $main::ConfigurationData{'html-footer-snippet-file'}, $main::RootDirectoryPath);
811 $Value = $main::ConfigurationData{'html-footer-snippet-file'};
812
813 # Check that the file exists
814 if ( ! ((-f $Value) && (-r $Value)) ) {
815 &vLog("Error - configuration setting: 'html-footer-snippet-file', file: '$Value' does not exist.\n");
816 $Status = 0;
817 }
818 }
819
820
821
822 # Check 'logs-directory' (required)
823 $main::ConfigurationData{'logs-directory'} = &sCleanSetting('logs-directory', $main::ConfigurationData{'logs-directory'}, $main::RootDirectoryPath);
824 $Value = $main::ConfigurationData{'logs-directory'};
825
826 # Check that the directory exists
827 if ( ! (-d $Value) ) {
828 &vLog("Error - configuration setting: 'logs-directory', directory: '$Value' does not exist.\n");
829 $Status = 0;
830 }
831 else {
832
833 # The directory exists, now check that it can be accessed
834 if ( ! ((-r $Value) && (-w $Value) && (-x $Value)) ) {
835 &vLog("Error - configuration setting: 'logs-directory', directory: '$Value' cannot be accessed.\n");
836 $Status = 0;
837 }
838 }
839
840
841
842 # Check 'database-directory' (required)
843 $main::ConfigurationData{'database-directory'} = &sCleanSetting('database-directory', $main::ConfigurationData{'database-directory'}, $main::RootDirectoryPath);
844 $Value = $main::ConfigurationData{'database-directory'};
845
846 # Check that the directory exists
847 if ( ! (-d $Value) ) {
848 &vLog("Error - configuration setting: 'database-directory', directory: '$Value' does not exist.\n");
849 $Status = 0;
850 }
851 else {
852
853 # The directory exists, now check that it can be accessed
854 if ( ! ((-r $Value) && (-x $Value)) ) {
855 &vLog("Error - configuration setting: 'database-directory, directory: '$Value' cannot be accessed.\n");
856 $Status = 0;
857 }
858 }
859
860
861
862 # Check 'configuration-directory' (required)
863 $main::ConfigurationData{'configuration-directory'} = &sCleanSetting('configuration-directory', $main::ConfigurationData{'configuration-directory'}, $main::RootDirectoryPath);
864 $Value = $main::ConfigurationData{'configuration-directory'};
865
866 # Check that the directory exists
867 if ( ! (-d $Value) ) {
868 &vLog("Error - configuration setting: 'configuration-directory', directory: '$Value' does not exist.\n");
869 $Status = 0;
870 }
871 else {
872
873 # The directory exists, now check that it can be accessed
874 if ( ! ((-r $Value) && (-x $Value)) ) {
875 &vLog("Error - configuration setting: 'configuration-directory, directory: '$Value' cannot be accessed.\n");
876 $Status = 0;
877 }
878 }
879
880
881
882 # Check 'server-log' (optional with default)
883 $main::ConfigurationData{'server-log'} = &sCleanSetting('server-log', $main::ConfigurationData{'server-log'});
884 $Value = $main::ConfigurationData{'logs-directory'} . "/" . $main::ConfigurationData{'server-log'};
885
886 # Check that we can write to the log file if it exists
887 if ( -f $Value ) {
888
889 # The file exists, now check that it can be accessed
890 if ( ! -w $Value ) {
891 &vLog("Error - configuration setting: 'server-log', directory: '$Value' cannot be accessed.\n");
892 $Status = 0;
893 }
894 }
895
896
897
898 # Check 'mailer-application' (optional with default)
899 if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
900
901 $main::ConfigurationData{'mailer-application'} = &sCleanSetting('mailer-application', $main::ConfigurationData{'mailer-application'}, $main::RootDirectoryPath);
902 $Value = $main::ConfigurationData{'mailer-application'};
903
904 # Check that the application can be executed
905 if ( ! (-x $Value) ) {
906 &vLog("Error - configuration setting: 'mailer-application', application: '$Value' cannot be executed.\n");
907 $Status = 0;
908 }
909 }
910
911
912 return ($Status);
913
914 }
915
916
917
918
919
920 #--------------------------------------------------------------------------
921 #
922 # Function: bGetDatabaseDescriptions()
923 #
924 # Purpose: This function reads the database description file and places it in the
925 # hash table global, note that the hash table is not cleared before
926 # we start to add kay/value pairs to it.
927 #
928 # Any line which starts with a '#' or is empty will be skipped.
929 #
930 # An error will be generated if we try to redefine a value for a
931 # key that has already been defined.
932 #
933 # An error here should be considered fatal.
934 #
935 # Called by:
936 #
937 # Parameters: void
938 #
939 # Global Variables: %main::ConfigurationData, %main::DatabaseDescriptions
940 #
941 # Returns: Boolean status
942 #
943 sub bGetDatabaseDescriptions {
944
945 my ($Status, $Key, $KeyValue, $KeyBase, $KeyLeaf, $Database);
946
947
948 # Init the status
949 $Status = 1;
950
951
952 # Only check the database description file if it is available
953 if ( defined($main::ConfigurationData{'database-description-file'}) ) {
954
955 # Open the database description file
956 if ( ! open(FILE, "$main::ConfigurationData{'database-description-file'}") ) {
957 &vLog("Error - could not open database description file: '$main::ConfigurationData{'database-description-file'}'.\n");
958 return (0);
959 }
960
961 # Read in each line in the file, ignore empty
962 # lines and lines which start with a '#'
963 while (<FILE>) {
964
965 chop $_;
966
967 # Check to see if this line is empty or is a comment, and skip them
968 if ( (length($_) == 0) || ($_ =~ /^#/) ) {
969 next;
970 }
971
972 # Split the configuration string into a set of key/value pairs
973 ($Key, $KeyValue) = split(/=/, $_);
974
975 # Only add values which are defined
976 if ( defined($KeyValue) && ($KeyValue ne "") ) {
977
978 # Split the key into a key and a subkey
979 ($KeyBase, $KeyLeaf) = split(/:/, $Key, 2);
980
981 if ( $KeyBase eq $main::DatabaseName ) {
982
983 # Add the key/value pairs to the hash table
984 if ( defined($main::DatabaseDescriptions{$KeyLeaf}) ) {
985 # Fail if the value for this key is already defined
986 &vLog("Error - value for: '$KeyLeaf', is already defined as: '$main::DatabaseDescriptions{$KeyLeaf}', tried to redefine it to: '$KeyValue'.\n");
987 $Status = 0;
988 }
989 else {
990 # Add the value for this key
991 if ($KeyValue =~ s/(##sort[^#]+##)//) {
992 $main::DatabaseSort{$1} = $KeyLeaf;
993 } else {
994 $main::DatabaseSort{$KeyValue} = $KeyLeaf;
995 }
996 $main::DatabaseDescriptions{$KeyLeaf} = $KeyValue;
997 }
998 }
999 elsif ( $KeyBase eq $main::DatabaseFiltersPackage ) {
1000
1001 # Add the key/value pairs to the hash table
1002 if ( defined($main::DatabaseFilters{$Key}) ) {
1003 # Fail if the value for this key is already defined
1004 &vLog("Error - value for: '$Key', is already defined as: '$main::DatabaseFilters{$Key}', tried to redefine it to: '$KeyValue'.\n");
1005 $Status = 0;
1006 }
1007 else {
1008
1009 # Check that this filters package exists
1010 if ( ! -x $KeyValue ) {
1011 # Fail we cant find it
1012 &vLog("Error - filter: '$KeyValue' for: '$Key' could not be found.\n");
1013 $Status = 0;
1014 }
1015
1016 # Add the value for this key
1017 $main::DatabaseFilters{$Key} = $KeyValue;
1018 }
1019 }
1020 else {
1021
1022 ($Database) = split(/:/, $KeyLeaf);
1023
1024 # Add the key/value pairs to the hash table
1025 if ( ! defined($main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Database"}) ) {
1026 # Fail if we dont have the package for this function
1027 &vLog("Error - package file for function: '$KeyValue', defined for: '$Key', cound not be found.\n");
1028 $Status = 0;
1029 }
1030 elsif ( defined($main::DatabaseFilters{$Key}) ) {
1031 # Fail if the value for this key is already defined
1032 &vLog("Error - value for: '$Key', is already defined as: '$main::DatabaseFilters{$Key}', tried to redefine it to: '$KeyValue'.\n");
1033 $Status = 0;
1034 }
1035 else {
1036
1037 # Add the value for this key
1038 $main::DatabaseFilters{$Key} = $KeyValue;
1039 }
1040 }
1041 }
1042 }
1043 close(FILE);
1044 }
1045
1046 # fill defaults for rest
1047 $main::DatabaseFilters{$Key} = $main::DatabaseFilters{default} if (! defined($main::DatabaseFilters{$Key}));
1048
1049 return ($Status);
1050
1051 }
1052
1053
1054
1055
1056
1057 #--------------------------------------------------------------------------
1058 #
1059 # Function: bInitializeServer()
1060 #
1061 # Purpose: This function sets up the server
1062 #
1063 # An error here should be considered fatal.
1064 #
1065 # Called by:
1066 #
1067 # Parameters: void
1068 #
1069 # Global Variables: %main::ConfigurationData
1070 #
1071 # Returns: Boolean status
1072 #
1073 sub bInitializeServer {
1074
1075 my ($Status, $Text);
1076 my ($ErrorNumber, $ErrorMessage);
1077
1078
1079 # Initialize the server
1080 ($Status, $Text) = MPS::InitializeServer($main::ConfigurationData{'database-directory'}, $main::ConfigurationData{'configuration-directory'}, $main::ConfigurationData{'logs-directory'} . "/". $main::ConfigurationData{'server-log'}, MPS_LOG_MEDIUM);
1081
1082 # Check the return code
1083 if ( ! $Status ) {
1084 ($ErrorNumber, $ErrorMessage) = split(/\t/, $Text, 2);
1085 &vHandleError("Database Search", "Sorry, failed to initialize the server");
1086 print("The following error message was reported: <BR>\n");
1087 print("Error Message: $ErrorMessage <BR>\n");
1088 print("Error Number: $ErrorNumber <BR>\n");
1089 }
1090
1091 $main::MPSSession = $Text;
1092
1093 return ($Status);
1094 }
1095
1096
1097
1098
1099
1100 #--------------------------------------------------------------------------
1101 #
1102 # Function: bShutdownServer()
1103 #
1104 # Purpose: This function shuts down the server
1105 #
1106 # An error here should be considered fatal.
1107 #
1108 # Called by:
1109 #
1110 # Parameters: void
1111 #
1112 # Global Variables: %main::ConfigurationData
1113 #
1114 # Returns: Boolean status
1115 #
1116 sub bShutdownServer {
1117
1118
1119 # Shutdown the server
1120 MPS::ShutdownServer($main::MPSSession);
1121
1122 return (1);
1123
1124 }
1125
1126
1127
1128
1129
1130 #--------------------------------------------------------------------------
1131 #
1132 # Function: bCheckCGIEnvironment()
1133 #
1134 # Purpose: This function checks that all the CGI environment variables we
1135 # need are available. It will exit if any of the variables are
1136 # not found, but it will first list all the variables that are
1137 # not available.
1138 #
1139 # An error here should be considered fatal.
1140 #
1141 # Called by:
1142 #
1143 # Parameters: void
1144 #
1145 # Global Variables: $ENV{}
1146 #
1147 # Returns: Boolean status
1148 #
1149 sub bCheckCGIEnvironment {
1150
1151 my ($Status);
1152
1153
1154 # Init the status
1155 $Status = 1;
1156
1157
1158 # Check that REQUEST_METHOD is specified
1159 if ( ! (defined($ENV{'REQUEST_METHOD'}) && ($ENV{'REQUEST_METHOD'} ne "")) ) {
1160 &vLog("Error - missing 'REQUEST_METHOD' environment variable.\n");
1161 $Status = 0;
1162 }
1163
1164
1165 # Check that SCRIPT_NAME is specified
1166 if ( ! (defined($ENV{'SCRIPT_NAME'}) && ($ENV{'SCRIPT_NAME'} ne "")) ) {
1167 &vLog("Error - missing 'SCRIPT_NAME' environment variable.\n");
1168 $Status = 0;
1169 }
1170
1171
1172 # Force guest
1173 #$ENV{'REMOTE_USER'} = "guest";
1174
1175 # Make sure that REMOTE_USER is defined, we set it to an empty string if it is not
1176 if ( ! (defined($ENV{'REMOTE_USER'}) && ($ENV{'REMOTE_USER'} ne "")) ) {
1177 $ENV{'REMOTE_USER'} = "";
1178 }
1179 else {
1180 # REMOTE_USER is defined, we check to see if the guest account name is defined
1181 if ( defined($main::ConfigurationData{'guest-account-name'}) ) {
1182 # Set the REMOTE_USER to an empty string if it is the same as the guest account
1183 if ( $ENV{'REMOTE_USER'} eq $main::ConfigurationData{'guest-account-name'} ) {
1184 $ENV{'REMOTE_USER'} = "";
1185 }
1186 }
1187 }
1188
1189
1190 # Adjust the path info if needed
1191 if ( defined($ENV{'PATH_INFO'}) && defined($ENV{'SCRIPT_NAME'}) && (length($ENV{'PATH_INFO'}) > length($ENV{'SCRIPT_NAME'})) ) {
1192 if ( substr($ENV{'PATH_INFO'}, 0, length($ENV{'SCRIPT_NAME'})) eq $ENV{'SCRIPT_NAME'} ) {
1193 $ENV{'PATH_INFO'} = substr($ENV{'PATH_INFO'}, length($ENV{'SCRIPT_NAME'}));
1194 $ENV{'PATH_INFO'} = undef if ($ENV{'PATH_INFO'} eq "");
1195 }
1196 }
1197
1198
1199 return ($Status);
1200
1201 }
1202
1203
1204
1205
1206 #--------------------------------------------------------------------------
1207 #
1208 # Function: bSetupCGIEnvironment()
1209 #
1210 # Purpose: This function sets up the environment for the CGI mode, it will
1211 # also check that all the globals are correct and that any
1212 # required directories can be accessed and written to
1213 #
1214 # An error here should be considered fatal.
1215 #
1216 # Called by:
1217 #
1218 # Parameters: void
1219 #
1220 # Global Variables: $main::UserAccountDirectoryPath, $main::UserSettingsFilePath, $main::RemoteUser,
1221 # %main::FormData, %main::ConfigurationData
1222 #
1223 # Returns: Boolean status
1224 #
1225 sub bSetupCGIEnvironment {
1226
1227 my ($Status, $URLString);
1228
1229
1230 # Init the status
1231 $Status = 1;
1232
1233
1234 # Get the query string from the environment
1235 if ( $ENV{'REQUEST_METHOD'} eq "GET" ) {
1236 $URLString = $ENV{'QUERY_STRING'};
1237 }
1238 # Get the query string from stdin
1239 elsif ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
1240 read("STDIN", $URLString, $ENV{'CONTENT_LENGTH'});
1241
1242 # Append the query string if it is defined
1243 if ( defined($ENV{'QUERY_STRING'}) && ($ENV{'QUERY_STRING'} ne "") ) {
1244 $URLString = $ENV{'QUERY_STRING'} . "&". $URLString;
1245 }
1246 }
1247
1248
1249 # Parse the form data that was passed
1250 if ( defined($URLString) && ($URLString ne "") ) {
1251 %main::FormData = &hParseURLIntoHashTable($URLString);
1252 }
1253
1254
1255 # Get the REMOTE_USER from the CGI environment and set the user account directory path
1256 if ( (defined($ENV{'REMOTE_USER'})) && ($ENV{'REMOTE_USER'} ne "") && defined($main::ConfigurationData{'user-accounts-directory'}) ) {
1257 $main::RemoteUser = $ENV{'REMOTE_USER'};
1258 $main::UserAccountDirectoryPath = $main::ConfigurationData{'user-accounts-directory'} . "/". $main::RemoteUser;
1259 $main::UserAccountDirectoryPath =~ tr/\+/ /;
1260 $main::UserSettingsFilePath = $main::UserAccountDirectoryPath . "/". $main::UserSettingsFileName . $main::XMLFileNameExtension;
1261 }
1262 else {
1263 undef($main::RemoteUser);
1264 undef($main::UserAccountDirectoryPath);
1265 undef($main::UserSettingsFilePath);
1266 }
1267
1268
1269 # Check that the user account directory exists if it is specified
1270 if ( defined($main::UserAccountDirectoryPath) ) {
1271
1272 # Try to create the user account directory if it does not exist
1273 if ( ! -d $main::UserAccountDirectoryPath ) {
1274
1275 if ( mkdir($main::UserAccountDirectoryPath, 0700) ) {
1276
1277 # Set the user account directory so that it can be accessed by ourselves only
1278 chmod(0700, $main::UserAccountDirectoryPath);
1279
1280 }
1281 else {
1282
1283 # The directory could not be created, so we inform the user of the fact
1284 &vHandleError("User Account Error", "Sorry, the account directory could not be created");
1285 $Status = 0;
1286 }
1287 }
1288
1289
1290 # Check that we can access user account directory
1291 if ( ! ((-r $main::UserAccountDirectoryPath) && (-w $main::UserAccountDirectoryPath) && (-x $main::UserAccountDirectoryPath)) ) {
1292
1293 # The directory cannot be accessed, so we inform the user of the fact
1294 &vHandleError("User Account Error", "Sorry, the account directory could not be accessed");
1295 $Status = 0;
1296 }
1297 }
1298
1299
1300 return ($Status);
1301
1302 }
1303
1304
1305
1306
1307 #--------------------------------------------------------------------------
1308 #
1309 # Function: sMakeSearchURL()
1310 #
1311 # Purpose: This function makes a search URL from the passed content hash.
1312 #
1313 # Called by:
1314 #
1315 # Parameters: %Content content hash
1316 #
1317 # Global Variables: none
1318 #
1319 # Returns: the URL search string, and an empty string if
1320 # nothing relevant is defined in the content
1321 #
1322 sub sMakeSearchURL {
1323
1324 my (%Content) = @_;
1325
1326 my ($SearchURL, $Value);
1327 my (@InternalFieldNames) = ('Any', 'Operator', 'Past', 'Since', 'Before', 'LastRunTime', 'Order', 'Max', 'Database');
1328
1329
1330 # Initialize the search URL
1331 $SearchURL = "";
1332
1333
1334 # Add the generic field names
1335 foreach $Value ( 1..100 ) {
1336
1337 my ($FieldName) = "FieldName" . $Value;
1338 my ($FieldContent) = "FieldContent" . $Value;
1339
1340 if ( defined($Content{$FieldName}) ) {
1341 $SearchURL .= "&$FieldName=" . &lEncodeURLData($Content{$FieldName});
1342 $SearchURL .= defined($Content{$FieldContent}) ? "&$FieldContent=" . &lEncodeURLData($Content{$FieldContent}) : "";
1343 }
1344 }
1345
1346
1347 # Add the internal search terms
1348 foreach $Value ( @InternalFieldNames ) {
1349 $SearchURL .= defined($Content{$Value}) ? "&$Value=" . join("&$Value=", &lEncodeURLData(split(/\0/, $Content{$Value}))) : "";
1350 }
1351
1352
1353 # Return the URL, choping out the initial '&'
1354 return (($SearchURL ne "") ? substr($SearchURL, 1) : "");
1355
1356 }
1357
1358
1359
1360
1361
1362 #--------------------------------------------------------------------------
1363 #
1364 # Function: sMakeDocumentURL()
1365 #
1366 # Purpose: This function makes a document URL from the passed content hash.
1367 #
1368 # Called by:
1369 #
1370 # Parameters: %Content content hash
1371 #
1372 # Global Variables: none
1373 #
1374 # Returns: the URL document string, and an empty string if
1375 # nothing relevant is defined in the content
1376 #
1377 sub sMakeDocumentURL {
1378
1379 my (%Content) = @_;
1380
1381 my ($DocumentURL);
1382
1383
1384 # Initialize the document URL
1385 $DocumentURL = "";
1386
1387
1388 # Add the document URLs
1389 if ( defined($Content{'Document'}) ) {
1390 $DocumentURL .= "&Document=" . join("&Document=", &lEncodeURLData(split(/\0/, $Content{'Document'})));
1391 }
1392
1393
1394 # Return the URL, choping out the initial '&'
1395 return (($DocumentURL ne "") ? substr($DocumentURL, 1) : "");
1396
1397 }
1398
1399
1400
1401
1402
1403 #--------------------------------------------------------------------------
1404 #
1405 # Function: sMakeRfDocumentURL()
1406 #
1407 # Purpose: This function makes an RF document URL from the passed content hash.
1408 #
1409 # Called by:
1410 #
1411 # Parameters: %Content content hash
1412 #
1413 # Global Variables: none
1414 #
1415 # Returns: the URL RF document string, and an empty string if
1416 # nothing relevant is defined in the content
1417 #
1418 sub sMakeRfDocumentURL {
1419
1420 my (%Content) = @_;
1421
1422 my ($RfDocumentURL);
1423
1424
1425 # Initialize the RF document URL
1426 $RfDocumentURL = "";
1427
1428
1429 # Add the RF document URLs
1430 if ( defined($Content{'RfDocument'}) ) {
1431 $RfDocumentURL .= "&RfDocument=" . join("&RfDocument=", &lEncodeURLData(split(/\0/, $Content{'RfDocument'})));
1432 }
1433
1434
1435 # Return the URL, choping out the initial '&'
1436 return (($RfDocumentURL ne "") ? substr($RfDocumentURL, 1) : "");
1437
1438 }
1439
1440
1441
1442
1443
1444 #--------------------------------------------------------------------------
1445 #
1446 # Function: sMakeSearchAndRfDocumentURL()
1447 #
1448 # Purpose: This function makes a URL string from the search
1449 # and RF document URLs
1450 #
1451 # Called by:
1452 #
1453 # Parameters: %Content content hash
1454 #
1455 # Global Variables: none
1456 #
1457 # Returns: the URL query string, and an empty string if
1458 # nothing relevant is defined in %Content
1459 #
1460 sub sMakeSearchAndRfDocumentURL {
1461
1462 my (%Content) = @_;
1463
1464 my ($SearchURL, $RfDocumentURL, $SearchRfDocumentURL);
1465
1466
1467 # Get the search URL and the RF document URL
1468 $SearchURL = &sMakeSearchURL(%Content);
1469 $RfDocumentURL = &sMakeRfDocumentURL(%Content);
1470
1471
1472 # Concatenate them intelligently
1473 $SearchRfDocumentURL = $SearchURL . ((($SearchURL ne "") && ($RfDocumentURL ne "")) ? "&" : "") . $RfDocumentURL;
1474
1475
1476 # Return the URL
1477 return ($SearchRfDocumentURL);
1478
1479 }
1480
1481
1482
1483
1484 #--------------------------------------------------------------------------
1485 #
1486 # Function: sMakeSearchString()
1487 #
1488 # Purpose: This function makes a search string from the search
1489 # variables in the content hash
1490 #
1491 # Called by:
1492 #
1493 # Parameters: %Content content hash
1494 #
1495 # Global Variables: void
1496 #
1497 # Returns: the search string, and an empty string if
1498 # nothing relevant is defined in the content hash
1499 #
1500 sub sMakeSearchString {
1501
1502 my (%Content) = @_;
1503
1504 my ($SearchString);
1505 my ($FieldName, $Time, $Date);
1506 my ($Value);
1507
1508
1509 # Initialize the search string
1510 $SearchString = "";
1511
1512 # tip gradje
1513 if ( defined($main::FormData{'tip'}) ) {
1514 my @t;
1515 foreach my $tip ( split(/\0/, $main::FormData{'tip'}) ) {
1516 push @t,"tip=$tip";
1517 }
1518 $SearchString .= "(".join(" or ",@t).") and ";
1519 }
1520
1521 # Add the search terms
1522 $SearchString .= defined($Content{'Any'}) ? ((($SearchString ne "") ? " AND " : "") . nuke_accents($Content{'Any'}) ) : "";
1523
1524
1525 # Add the generic field names
1526 foreach $Value ( 1..100 ) {
1527
1528 my ($FieldName) = "FieldName" . $Value;
1529 my ($FieldContent) = "FieldContent" . $Value;
1530
1531
1532 if ( defined($Content{$FieldName}) && defined($Content{$FieldContent}) ) {
1533
1534 if ($Content{$FieldName} eq "ISBN") {
1535 # fix stupid problem with dashes in data
1536 $Content{$FieldContent} .= "*";
1537 }
1538
1539 $SearchString .= ($SearchString ne "") ? " AND " : "";
1540 $SearchString .= "$Content{$FieldName}=(" . nuke_accents($Content{$FieldContent}) . ")";
1541 }
1542 }
1543
1544 # Add the internal search terms
1545
1546 # Add the date restriction on the load time
1547 if ( defined($Content{'LastRunTime'}) && ($Content{'LastRunTime'} > 0) ) {
1548 $SearchString .= (($SearchString ne "") ? " AND " : "") . "time_t>=$Content{'LastRunTime'}";
1549 }
1550
1551
1552 # Add the Past date restriction
1553 if ( defined($Content{'Past'}) && ($Content{'Past'} ne "0") ) {
1554
1555 $Time = time();
1556 if ( $Content{'Past'} eq "Day" ) {
1557 $Time = &tSubstractFromTime($Time, undef, undef, 1);
1558 }
1559 elsif ( $Content{'Past'} eq "Week" ) {
1560 $Time = &tSubstractFromTime($Time, undef, undef, 7);
1561 }
1562 elsif ( $Content{'Past'} eq "Month" ) {
1563 $Time = &tSubstractFromTime($Time, undef, 1, undef);
1564 }
1565 elsif ( $Content{'Past'} eq "3 Months" ) {
1566 $Time = &tSubstractFromTime($Time, undef, 3, undef);
1567 }
1568 elsif ( $Content{'Past'} eq "6 Months" ) {
1569 $Time = &tSubstractFromTime($Time, undef, 6, undef);
1570 }
1571 elsif ( $Content{'Past'} eq "9 Months" ) {
1572 $Time = &tSubstractFromTime($Time, undef, 9, undef);
1573 }
1574 elsif ( $Content{'Past'} eq "Year" ) {
1575 $Time = &tSubstractFromTime($Time, 1, undef undef);
1576 }
1577
1578 # Create an ANSI format date/time field
1579 $Date = &sGetAnsiDateFromTime($Time);
1580 $SearchString .= " {DATE>=$Date}";
1581 }
1582
1583
1584 # Add the Since date restriction
1585 if ( defined($Content{'Since'}) && ($Content{'Since'} ne "0") ) {
1586 $SearchString .= " {DATE>=$Content{'Since'}0000}";
1587 }
1588
1589
1590 # Add the Before date restriction
1591 if ( defined($Content{'Before'}) && ($Content{'Before'} ne "0") ) {
1592 $SearchString .= " {DATE<$Content{'Before'}0000}";
1593 }
1594
1595
1596 # Add the document sort order
1597 $SearchString .= defined($Content{'Order'}) ? " {" . $Content{'Order'} . "}" : "";
1598
1599 # Add the operator
1600 $SearchString .= defined($Content{'Operator'}) ? " {" . $Content{'Operator'} . "}" : "";
1601
1602
1603 return (($SearchString ne "") ? $SearchString : undef);
1604
1605 }
1606
1607
1608
1609
1610
1611 #--------------------------------------------------------------------------
1612 #
1613 # Function: hGetSearchStringHash()
1614 #
1615 # Purpose: This function makes a search string hash table from the search
1616 # variables in the content hash
1617 #
1618 # Called by:
1619 #
1620 # Parameters: %Content content hash
1621 #
1622 # Global Variables: void
1623 #
1624 # Returns: the search string hash table, and an empty string if
1625 # nothing relevant is defined in the content hash
1626 #
1627 sub hGetSearchStringHash {
1628
1629 my (%Content) = @_;
1630
1631 my ($Content);
1632 my (%Value, @Values, $Value);
1633
1634
1635 @Values = split(/ /, defined($Content{'Any'}) ? $Content{'Any'} : "");
1636 foreach $Value ( @Values ) { $Value = lc($Value); $Value{$Value} = $Value };
1637
1638
1639 # Add the generic field names
1640 foreach $Value ( 1..100 ) {
1641
1642 my ($FieldName) = "FieldName" . $Value;
1643 my ($FieldContent) = "FieldContent" . $Value;
1644
1645 if ( defined($Content{$FieldName}) ) {
1646 @Values = split(/ /, defined($Content{$FieldContent}) ? $Content{$FieldContent} : "");
1647 foreach $Value ( @Values ) { $Value = lc($Value); $Value{$Value} = $Value };
1648 }
1649 }
1650
1651
1652 return (%Value);
1653
1654 }
1655
1656
1657
1658
1659
1660 #--------------------------------------------------------------------------
1661 #
1662 # Function: hGetDocumentFolders()
1663 #
1664 # Purpose: This function returns a hash table of all the document folders
1665 #
1666 # Called by:
1667 #
1668 # Parameters: void
1669 #
1670 # Global Variables: void
1671 #
1672 # Returns: a hash table of document folders, the key being the folder name
1673 # and the content being the folder file name
1674 #
1675 sub hGetDocumentFolders {
1676
1677 my (@DocumentFolderList, $DocumentFolderEntry, $HeaderName, $FolderName, %QualifiedDocumentFolders);
1678
1679 # Read all the document folder files
1680 opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
1681 @DocumentFolderList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::DocumentFolderFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
1682 closedir(USER_ACCOUNT_DIRECTORY);
1683
1684
1685 # Loop over each document folder file checking that it is valid
1686 for $DocumentFolderEntry ( @DocumentFolderList ) {
1687
1688 # Get the header name from the XML document folder file
1689 $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderEntry);
1690
1691 # Check that the entry is valid and add it to the qualified list
1692 if ( defined($HeaderName) && ($HeaderName eq "DocumentFolder") ) {
1693 $FolderName = &sGetTagValueFromXMLFile($DocumentFolderEntry, "FolderName");
1694 $QualifiedDocumentFolders{$FolderName} = $DocumentFolderEntry;
1695 }
1696 else {
1697 # Else we delete this invalid document folder file
1698 unlink($DocumentFolderEntry);
1699 }
1700 }
1701
1702
1703 return (%QualifiedDocumentFolders);
1704
1705 }
1706
1707
1708
1709
1710
1711 #--------------------------------------------------------------------------
1712 #
1713 # Function: iSaveSearchHistory()
1714 #
1715 # Purpose: This function saves the passed search to a new
1716 # search history XML file.
1717 #
1718 # Called by:
1719 #
1720 # Parameters: $FileName search history file name ('undef' means create a new file name)
1721 # $SearchAndRfDocumentURL search and RF document URL
1722 # $SearchResults search results
1723 # $QueryReport query report
1724 #
1725 # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1726 # $main::SearchHistoryFileNamePrefix
1727 #
1728 # Returns: 0 on error, 1 on success
1729 #
1730 sub iSaveSearchHistory {
1731
1732 my ($FileName, $SearchAndRfDocumentURL, $SearchResults, $QueryReport) = @_;
1733 my ($SearchHistoryFilePath, %Value);
1734 my ($AnsiDateTime);
1735
1736
1737 # Return an error if the user account directory is not defined
1738 if ( !(defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
1739 return (0);
1740 }
1741
1742 # Create a file name if one was not passed
1743 if ( !defined($FileName) ) {
1744 $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1745 $SearchHistoryFilePath = $main::UserAccountDirectoryPath . "/". $main::SearchHistoryFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1746 }
1747 else {
1748 $SearchHistoryFilePath = $FileName;
1749 }
1750
1751
1752 # Set the hash from the history information
1753 undef(%Value);
1754 $Value{'CreationTime'} = time();
1755 $Value{'SearchAndRfDocumentURL'} = $SearchAndRfDocumentURL;
1756 $Value{'QueryReport'} = $QueryReport;
1757 $Value{'SearchResults'} = $SearchResults;
1758
1759
1760 # Save the search information
1761 if ( ! &iSaveXMLFileFromHash($SearchHistoryFilePath, "SearchHistory", %Value) ) {
1762 # Failed to save the information, so we return an error
1763 return (0);
1764 }
1765
1766 return (1);
1767
1768 }
1769
1770
1771
1772
1773
1774 #--------------------------------------------------------------------------
1775 #
1776 # Function: iSaveSearch()
1777 #
1778 # Purpose: This function saves the passed search to a new
1779 # search XML file.
1780 #
1781 # Called by:
1782 #
1783 # Parameters: $FileName saved search file name ('undef' means create a new file name)
1784 # $SearchName search name
1785 # $SearchDescription search description
1786 # $SearchAndRfDocumentURL search and RF document URL
1787 # $SearchFrequency search frequency
1788 # $DeliveryFormat delivery format
1789 # $DeliveryMethod delivery method
1790 # $SearchStatus search status
1791 # $CreationTime creation time
1792 # $LastRunTime last run time
1793 #
1794 # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1795 # $main::SavedSearchFileNamePrefix
1796 #
1797 # Returns: 0 on error, 1 on success
1798 #
1799 sub iSaveSearch {
1800
1801 my ($FileName, $SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $LastRunTime) = @_;
1802 my ($SavedSearchFilePath, %Value);
1803 my ($AnsiDateTime);
1804
1805
1806 # Return an error if the user account directory is not defined
1807 if ( !(defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
1808 return (0);
1809 }
1810
1811 # Create a file name if one was not passed
1812 if ( !defined($FileName) ) {
1813 $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1814 $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/". $main::SavedSearchFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1815 }
1816 else {
1817 $SavedSearchFilePath = $FileName;
1818 }
1819
1820
1821
1822 # Set the hash from the search information
1823 undef(%Value);
1824 $Value{'SearchName'} = $SearchName;
1825 $Value{'SearchDescription'} = $SearchDescription;
1826 $Value{'SearchAndRfDocumentURL'} = $SearchAndRfDocumentURL;
1827 $Value{'SearchFrequency'} = $SearchFrequency;
1828 $Value{'DeliveryFormat'} = $DeliveryFormat;
1829 $Value{'DeliveryMethod'} = $DeliveryMethod;
1830 $Value{'SearchStatus'} = $SearchStatus;
1831 $Value{'CreationTime'} = $CreationTime;
1832 $Value{'LastRunTime'} = $LastRunTime;
1833
1834
1835 # Save the search information
1836 if ( ! &iSaveXMLFileFromHash($SavedSearchFilePath, "SavedSearch", %Value) ) {
1837 # Failed to save the information, so we return an error
1838 return (0);
1839 }
1840
1841 return (1);
1842
1843 }
1844
1845
1846
1847
1848
1849 #--------------------------------------------------------------------------
1850 #
1851 # Function: iSaveFolder()
1852 #
1853 # Purpose: This function saves the passed folder to a new
1854 # document folder XML file.
1855 #
1856 # Called by:
1857 #
1858 # Parameters: $FileName document folder file name ('undef' means create a new file name)
1859 # $FolderName folder name
1860 # $FolderDescription folder description
1861 # $FolderDocuments folder document
1862 # $CreationTime creation time
1863 # $UpdateTime update time
1864 #
1865 # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1866 # $main::DocumentFolderFileNamePrefix
1867 #
1868 # Returns: 0 on error, 1 on success
1869 #
1870 sub iSaveFolder {
1871
1872 my ($FileName, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) = @_;
1873 my ($DocumentFolderFilePath, %Value);
1874 my ($AnsiDateTime);
1875
1876
1877 # Return an error if the user account directory is not defined
1878 if ( !defined($main::RemoteUser) || !defined($main::UserAccountDirectoryPath) ) {
1879 return (0);
1880 }
1881
1882 # Create a file name if one was not passed
1883 if ( !defined($FileName) ) {
1884 $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1885 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/". $main::DocumentFolderFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1886 }
1887 else {
1888 $DocumentFolderFilePath = $FileName;
1889 }
1890
1891
1892
1893 # Set the hash from the folder information
1894 undef(%Value);
1895 $Value{'FolderName'} = $FolderName;
1896 $Value{'FolderDescription'} = $FolderDescription;
1897 $Value{'FolderDocuments'} = $FolderDocuments;
1898 $Value{'CreationTime'} = $CreationTime;
1899 $Value{'UpdateTime'} = $UpdateTime;
1900
1901
1902 # Save the document folder information
1903 if ( ! &iSaveXMLFileFromHash($DocumentFolderFilePath, "DocumentFolder", %Value) ) {
1904 # Failed to save the information, so we return an error
1905 return (0);
1906 }
1907
1908 return (1);
1909
1910 }
1911
1912
1913
1914
1915
1916 #--------------------------------------------------------------------------
1917 #
1918 # Function: bDisplayDocuments()
1919 #
1920 # Purpose: This function displays the document
1921 #
1922 # Called by:
1923 #
1924 # Parameters: $Title title
1925 # $Documents \0 separated document URL
1926 # $FieldName field name
1927 # $Selector true to display selector
1928 # $Selected selector is selected
1929 # $HTML true to display HTML
1930 #
1931 #
1932 # Global Variables: void
1933 #
1934 # Returns: the status
1935 #
1936 sub bDisplayDocuments {
1937
1938 my ($Title, $Documents, $FieldName, $Selector, $Selected, $HTML) = @_;
1939
1940 my (@Documents, $Document, $Status, $DocumentInfo, $SelectorText, $SelectedText, $LinkText);
1941 my ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder);
1942 my (%Value, $Value, @Values);
1943
1944
1945 # Check input parameters
1946 if ( !defined($Documents) ) {
1947 return (0);
1948 }
1949
1950
1951 # Split the documents text into a documents list
1952 @Documents = split(/\0/, $Documents);
1953
1954
1955 # Set the field name
1956 $FieldName = (defined($FieldName ) && ($FieldName ne "")) ? $FieldName : "Document";
1957
1958 # Set the selected text
1959 $SelectedText = ((defined($Selector) && $Selector) && (defined($Selected) && $Selected)) ? "CHECKED" : "";
1960
1961
1962 # Print the title
1963 if ( $HTML ) {
1964 printf("<TD ALIGN=LEFT VALIGN=TOP>%s%s:</TD><TD ALIGN=LEFT VALIGN=TOP>\n",
1965 # defined($Title) ? $Title : "Document", (scalar(@Documents) > 1) ? "s" : "");
1966 $Title);
1967 }
1968 else {
1969 # printf("%s%s:\n", defined($Title) ? $Title : "Document", (scalar(@Documents) > 1) ? "s" : "");
1970 print $Title;
1971 }
1972
1973
1974 # Loop over each entry in the documents list
1975 foreach $Document ( @Documents ) {
1976
1977 # Parse out the document entry
1978 %Value = &hParseURLIntoHashTable($Document);
1979
1980 # Get the document information
1981 ($Status, $DocumentInfo) = MPS::GetDocumentInfo($main::MPSSession, $Value{'Database'}, $Value{'DocumentID'});
1982
1983 if ( $Status ) {
1984 ($Headline, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $DocumentInfo, 8);
1985
1986 # Decode the headline and strip the HTML
1987 $Headline = &lDecodeURLData($Headline);
1988 $Headline =~ s/&nbsp;//gs;
1989 $Headline =~ s/<.*?>//gs;
1990 $Headline =~ s/\s+/ /gs;
1991 # decode some basic html from headline <b> <i>
1992 $Headline =~ s/&lt;(\/?[bi])&gt;/<$1>/g;
1993
1994 # Create a generic link for this document
1995 $Value = "";
1996 $Value .= (defined($Value{'Database'}) && ($Value{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Value{'Database'}) : "";
1997 $Value .= (defined($Value{'DocumentID'}) && ($Value{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Value{'DocumentID'}) : "";
1998 $Value .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
1999 $Value .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2000
2001
2002 # Create the selector text
2003 if ( defined($Selector) && $Selector ) {
2004 $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"$FieldName\" VALUE=\"" . substr($Value, 1) . "\" $SelectedText> ";
2005 }
2006 else {
2007 $SelectorText = " - ";
2008 }
2009
2010 # Create the link text, we use the URL if it is there
2011 if ( defined($URL) && ($URL ne "") ) {
2012 $LinkText = $URL;
2013 }
2014 elsif ( defined($Value{'DocumentID'}) && ($Value{'DocumentID'} ne "") ) {
2015 $LinkText = "$ENV{'SCRIPT_NAME'}/GetDocument?" . substr($Value, 1);
2016 }
2017 else {
2018 $LinkText = "";
2019 }
2020
2021 # Put up the headline and the score, this one links to the document
2022 if ( $HTML ) {
2023 # print("$SelectorText <A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $Headline <I> ( $main::DatabaseDescriptions{$Value{'Database'}} ) </I> </A> <BR>\n");
2024 print("$SelectorText <A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $Headline </A> <BR>\n");
2025
2026 # if ( defined($URL) && ($URL ne "") ) {
2027 # $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2028 # print("<FONT SIZE=-2><A HREF=\"$URL\"> $Value </A></FONT><BR>\n");
2029 # }
2030 }
2031 else {
2032 print("- $Headline ($main::DatabaseDescriptions{$Value{'Database'}})\n URL: $LinkText\n");
2033 }
2034 }
2035 }
2036
2037 if ( $HTML ) {
2038 print("</TD>\n");
2039 }
2040
2041
2042 return (1);
2043
2044 }
2045
2046
2047
2048
2049
2050
2051 #--------------------------------------------------------------------------
2052 #
2053 # Function: bsDisplaySearchResults()
2054 #
2055 # Purpose: This function displays the search results
2056 #
2057 # Called by:
2058 #
2059 # Parameters: $Title title
2060 # $SearchResults search results
2061 # $SearchDate search date
2062 # $SearchFrequency search frequency
2063 # $SearchDescription search description
2064 # $QueryReport query report
2065 # $ScriptName script name
2066 # $Header true to display header
2067 # $Selector true to display selector
2068 # $HTML true to display HTML
2069 # %Content content hash table
2070 #
2071 #
2072 # Global Variables: %main::ConfigurationData, $main::RemoteUser,
2073 # $main::QueryReportItemName, $main::QueryReportMimeType
2074 #
2075 # Returns: the status and a the query report
2076 #
2077 sub bsDisplaySearchResults {
2078
2079 my ($Title, $SearchDescription, $SearchDate, $SearchFrequency, $SearchResults, $QueryReport, $ScriptName, $Header, $Selector, $HTML, %Content) = @_;
2080
2081 my ($SearchString, $SummaryType, $SummaryLength, @SearchResults, $SearchResult, $FinalQueryReport, $ResultCount, %SearchStringHash);
2082 my ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder);
2083 my ($Status, $Text, $MimeTypeName, $SummaryText, $SelectorText, $LinkText, $RuleFlag, $LastItemName);
2084 my (@DocumentFolderList, %QualifiedDocumentFolders, $DocumentFolderEntry, $HeaderName, $FolderName, $Index);
2085 my (@Words, $Word, @OffsetPairs, $OffsetPair, %Offsets, $Offset, $Start, $End, $OldStart, $OldEnd, $CurrentSummaryLength);
2086 my ($DatabaseSummaryFilterKey, $DatabaseSummaryFilterFunction);
2087 my ($Value, %Value, @Values, $ValueEntry);
2088
2089
2090 # Check input parameters
2091 if ( !defined($SearchResults) || !%Content ) {
2092 return (0);
2093 }
2094
2095 # Split the search results text into a search results list
2096 @SearchResults = split(/\n/, $SearchResults);
2097
2098
2099 # First we count up the number of results and scoop up
2100 # any query reports if we need to
2101
2102 # Initialize the final query report
2103 if ( !defined($QueryReport) ) {
2104 $FinalQueryReport = "";
2105 }
2106 else {
2107 $FinalQueryReport = $QueryReport;
2108 }
2109
2110
2111 # Loop over each entry in the search results list
2112 $ResultCount = 0;
2113 foreach $SearchResult ( @SearchResults ) {
2114
2115 # Parse the headline, also get the first document item/type
2116 ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2117
2118 # Is this a query report
2119 if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2120
2121 # Retrieve the query report if it was not passed to us
2122 if ( !defined($QueryReport) ) {
2123 ($Status, $Text) = MPS::GetDocument($main::MPSSession, $Database, $DocumentID, $ItemName, $MimeType);
2124
2125 if ( $Status ) {
2126 # Concatenate it to the query report text we have already got
2127 $FinalQueryReport .= $Text;
2128 }
2129 }
2130 }
2131 else {
2132 # Increment the result count
2133 $ResultCount++;
2134 }
2135 }
2136
2137
2138
2139
2140 # Finally, we get information we are going to need later on
2141
2142 # Get the search string
2143 $SearchString = &sMakeSearchString(%Content);
2144 if ( defined($SearchString) ) {
2145 $SearchString =~ s/{.*?}//gs;
2146 $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
2147 }
2148 $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
2149
2150 # Get the search string hash
2151 %SearchStringHash = &hGetSearchStringHash(%Content);
2152
2153 # Do some very basic plural stemming
2154 foreach $Value ( keys (%SearchStringHash) ) {
2155 $Value =~ s/ies\Z/y/g;
2156 $Value =~ s/s\Z//g;
2157 $SearchStringHash{$Value} = $Value;
2158 }
2159
2160
2161
2162 # Get the summary information
2163 if ( defined($main::RemoteUser) ) {
2164
2165 $SummaryType = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SummaryType");
2166 $SummaryLength = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SummaryLength");
2167
2168 if ( !(defined($SummaryLength) && ($SummaryLength ne "")) ) {
2169 $SummaryLength = $main::DefaultSummaryLength;
2170 }
2171 if ( !(defined($SummaryType) && ($SummaryType ne "")) ) {
2172 $SummaryType = $main::DefaultSummaryType;
2173 }
2174 }
2175 else {
2176 $SummaryType = $main::DefaultSummaryType;
2177 $SummaryLength = $main::DefaultSummaryLength;
2178 }
2179
2180
2181 # Print the header if needed
2182 if ( $Header ) {
2183
2184 if ( $HTML ) {
2185 # Print the title and the start of the form
2186 printf("<H3>%s</H3>\n", defined($Title) ? $Title : "Rezultati pretra¾ivanja:");
2187
2188 # Start the form
2189 print("<FORM ACTION=\"$ScriptName\" METHOD=POST>\n");
2190
2191
2192 # List the hidden fields
2193 %Value = &hParseURLIntoHashTable(&sMakeSearchURL(%Content));
2194 foreach $Value ( keys(%Value) ) {
2195 foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
2196 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
2197 }
2198 }
2199
2200
2201 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2202
2203 # Print the selector
2204 print("<TR><TD ALIGN=LEFT VALIGN=TOP>Odabrani su svi rezultati ukoliko niste uèinili nikakav dodatan odabir.</TD><TD ALIGN=RIGHT VALIGN=TOP> \n");
2205
2206 if ( $ResultCount > 0 ) {
2207
2208 if ( defined($main::RemoteUser) ) {
2209 print("<SELECT NAME=\"Action\">\n");
2210
2211 print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
2212 if
2213 ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
2214 print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
2215 }
2216 if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
2217 print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
2218 }
2219 print("<OPTION VALUE=\"GetSaveSearch\">Saèuvaj upit\n");
2220 print("<OPTION VALUE=\"GetSaveFolder\">Saèuvaj odabrane rezultate u novi folder\n");
2221
2222 # Get the document folder hash
2223 %QualifiedDocumentFolders = &hGetDocumentFolders;
2224
2225 for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
2226
2227 $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
2228
2229 # Get the document folder file name and encode it
2230 $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
2231 $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
2232
2233 print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry\">Dodaj odabrane rezultate u '$FolderName' folder\n");
2234 }
2235 print("</SELECT>\n");
2236 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
2237 }
2238 else {
2239 print("<SELECT NAME=\"Action\">\n");
2240 print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
2241 if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
2242 print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
2243 }
2244 if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
2245 print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
2246 }
2247 print("</SELECT>\n");
2248 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
2249 }
2250 }
2251 else {
2252 if ( defined($main::RemoteUser) ) {
2253 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSaveSearch\">\n");
2254 print("<INPUT TYPE=SUBMIT VALUE=\"Save this search\">\n");
2255 }
2256 }
2257
2258 print("</TD></TR>\n");
2259 print("</TABLE>\n");
2260 }
2261 else {
2262 printf("%s\n", defined($Title) ? $Title : "Rezultati pretra¾ivanja:");
2263 }
2264
2265
2266 # Display the search string
2267 if ( $HTML ) {
2268 print("<CENTER><HR WIDTH=50%></CENTER>\n");
2269 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2270 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
2271 }
2272 else {
2273 print("--------------------------------------------------------------\n");
2274 print(" - Search for : $SearchString\n");
2275 }
2276
2277
2278 # Display the description
2279 if ( defined($SearchDescription) ) {
2280 if ( $HTML ) {
2281 $SearchDescription =~ s/\n/<BR>/g;
2282 $SearchDescription =~ s/\r/<BR>/g;
2283 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDescription </TD></TR>\n");
2284 }
2285 else {
2286 print(" - Description : $SearchDescription\n");
2287 }
2288 }
2289
2290 # Display the date
2291 if ( defined($SearchDate) ) {
2292 if ( $HTML ) {
2293 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Run on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDate </TD></TR>\n");
2294 }
2295 else {
2296 print(" - Run on : $SearchDate\n");
2297 }
2298 }
2299
2300 # Display the frequency
2301 if ( defined($SearchFrequency) ) {
2302 if ( $HTML ) {
2303 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchFrequency </TD></TR>\n");
2304 }
2305 else {
2306 print(" - Frequency : $SearchFrequency\n");
2307 }
2308 }
2309
2310
2311
2312 # Get the databases from the search and list their descriptions
2313 if ( defined($Content{'Database'}) ) {
2314
2315 # Initialize the temp list
2316 undef(@Values);
2317
2318 # Loop over each database
2319 foreach $Database ( split(/\0/, $Content{'Database'}) ) {
2320 $Value = &lEncodeURLData($Database);
2321 if ( $HTML ) {
2322 push @Values, sprintf("<A HREF=\"$ScriptName/GetDatabaseInfo?Database=$Value\" OnMouseOver=\"self.status='Get Information about the $main::DatabaseDescriptions{$Database} database'; return true\"> $main::DatabaseDescriptions{$Database} </A> ");
2323 }
2324 else {
2325 push @Values, sprintf("$main::DatabaseDescriptions{$Database} ");
2326 }
2327 }
2328
2329 # Print the list if there are any entries in it
2330 if ( scalar(@Values) > 0 ) {
2331 if ( $HTML ) {
2332 printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n",
2333 (scalar(@Values) > 1) ? "s" : "", join(", ", @Values));
2334 }
2335 else {
2336 printf(" - Database%s : %s\n", (scalar(@Values) > 1) ? "s" : " ", join(", ", @Values));
2337 }
2338 }
2339 }
2340
2341
2342 # Display any feedback documents
2343 if ( defined($Content{'RfDocument'}) ) {
2344 if ( $HTML ) {
2345 print("<TR>\n");
2346 }
2347 &bDisplayDocuments("Feedback Document", $Content{'RfDocument'}, "RfDocument", 1, 1, $HTML);
2348 if ( $HTML ) {
2349 print("</TR>\n");
2350 }
2351 }
2352
2353
2354 if ( $HTML ) {
2355 printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Pronaðeno: </TD> <TD ALIGN=LEFT VALIGN=TOP> <font color=\"#990000\"> %s rezultata </font>(Maksimalni broj pode¹en na: $Content{'Max'} ) </TD></TR>\n",
2356 ($ResultCount > 0) ? $ResultCount : "no");
2357
2358 print("</TABLE>\n");
2359 print("<CENTER><HR WIDTH=50%></CENTER>\n");
2360 }
2361 else {
2362 printf(" - Results : %s\n", ($ResultCount > 0) ? $ResultCount : "no");
2363 print("--------------------------------------------------------------\n\n");
2364 }
2365 }
2366
2367
2368 # Start the table
2369 if ( $HTML ) {
2370 print("<!-- searchResults -->\n");
2371 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2372
2373 # Display a button to select all the documents
2374 if ( $ResultCount > 0 ) {
2375
2376 if ( defined($Selector) && $Selector ) {
2377
2378 $SelectorText = "";
2379
2380 # Loop over each entry in the hits list
2381 foreach $SearchResult ( @SearchResults ) {
2382
2383 # Parse the headline, also get the first document item/type
2384 ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2385
2386 # Skip query reports
2387 if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2388 next;
2389 }
2390
2391 $Value = "";
2392 $Value .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2393 $Value .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2394 $Value .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2395 $Value .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2396 $SelectorText .= (($SelectorText ne "") ? "|" : "") . substr($Value, 1);
2397 }
2398
2399 $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
2400 print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> $SelectorText </TD></TR>\n");
2401 }
2402 }
2403 }
2404
2405
2406 ### FIX:: ADD SORT HERE
2407 if ( $ResultCount > 0 ) {
2408
2409 # Loop over each entry in the hits list
2410 foreach $SearchResult ( @SearchResults ) {
2411
2412 # Parse the headline, also get the first document item/type
2413 ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2414
2415 # Skip query reports
2416 if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2417 next;
2418 }
2419
2420
2421 # Put a separator between each entry
2422 if ( defined($Remainder) ) {
2423
2424 if ( defined($RuleFlag) && ($RuleFlag) ) {
2425 if ( $HTML ) {
2426 print("<TR><TD COLSPAN=3><HR WIDTH=25%></TD></TR>\n");
2427 }
2428 else {
2429 print("--------------------------------------------------------------\n\n");
2430 }
2431 }
2432
2433 $RuleFlag = 1;
2434 }
2435
2436
2437 # Get the summary if needed
2438 if ( defined($main::ConfigurationData{'allow-summary-displays'}) && ($main::ConfigurationData{'allow-summary-displays'} eq "yes") &&
2439 ($SummaryType ne "none") ) {
2440
2441 ($Status, $Text) = MPS::GetDocument($main::MPSSession, $Database, $DocumentID, $ItemName, $MimeType);
2442
2443 if ( $Status ) {
2444
2445 # Then process for each summary type
2446 if ( $SummaryType eq "default" ) {
2447
2448 $DatabaseSummaryFilterKey = "$main::DatabaseSummaryFilter:$Database:$ItemName:$MimeType";
2449
2450 # Is a filter defined for this database summary filter key ?
2451 if ( defined($main::DatabaseFilters{$DatabaseSummaryFilterKey}) ) {
2452
2453 # Pull in the package
2454 require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Database"};
2455
2456 # Filter the document
2457 $Value = $main::DatabaseFilters{$DatabaseSummaryFilterKey};
2458 $DatabaseSummaryFilterFunction = \&$Value;
2459 $Text = $DatabaseSummaryFilterFunction->($Database, $DocumentID, $ItemName, $MimeType, $Text);
2460
2461 }
2462
2463 # Truncate the summary to the length requested
2464 if ( defined ($Text) && ($Text ne "") ) {
2465
2466 $CurrentSummaryLength = 0;
2467 $SummaryText = "";
2468
2469 # Split the document text
2470 @Words = split(/(\W)/, $Text);
2471
2472 # Loop over each word
2473 foreach $Offset ( 0..scalar(@Words) ) {
2474
2475 # Skip undefined words
2476 if ( !defined($Words[$Offset]) ) {
2477 next;
2478 }
2479
2480 # Increment and check the summary length
2481 if ( $Words[$Offset] ne " " ) {
2482
2483 $CurrentSummaryLength++;
2484
2485 if ( $CurrentSummaryLength > $SummaryLength ) {
2486 # Append a diaresys at the end and bail
2487 $SummaryText .= "...";
2488 last;
2489 }
2490 }
2491
2492 # Append the current word to the end of the summary
2493 $SummaryText .= $Words[$Offset];
2494 }
2495 }
2496 else {
2497 $SummaryText = "(Document summary unavailable)";
2498 }
2499 }
2500 elsif ( $SummaryType eq "keyword" ) {
2501
2502 # First clean up the text
2503 if ( index($Text, "\r\n") >= 0 ) {
2504 $Text =~ s/\r//gs;
2505 }
2506 elsif ( index($Text, "\r") >= 0 ) {
2507 $Text =~ s/\r/\n/gs;
2508 }
2509 if ( defined($main::HtmlMimeTypes{$MimeType}) ) {
2510 if ( ($Index = index($Text, "\n\n")) >= 0 ) {
2511 $Text = substr($Text, $Index);
2512 }
2513 $Text =~ s/&nbsp;//gs;
2514 $Text =~ s/<.*?>//gs;
2515 }
2516 $Text =~ s/\n/ /gs;
2517 $Text =~ s/\s+/ /gs;
2518 $Text = ucfirst($Text);
2519
2520 # Initialize our variables
2521 $OldStart = -1;
2522 $OldEnd = -1;
2523
2524 $Start = -1;
2525 $End = -1;
2526
2527 $CurrentSummaryLength = 0;
2528
2529 # Reset the offset pairs and offsets
2530 undef(@OffsetPairs);
2531 undef(%Offsets);
2532
2533
2534 # Split the document text
2535 @Words = split(/(\W)/, $Text);
2536
2537
2538 # Loop over each word, checking to see if it is in the search string hash table
2539 # and build the offset list as we go along, check with the previous offset to see
2540 # if there is an overlap
2541 foreach $Offset ( 0..scalar(@Words) ) {
2542
2543 if ( !defined($Words[$Offset]) ) {
2544 next;
2545 }
2546
2547 # Downcase the word
2548 $Word = lc($Words[$Offset]);
2549
2550 # Very basic plural stemming
2551 $Word =~ s/ies\Z/y/g;
2552 $Word =~ s/s\Z//g;
2553
2554 if ( !defined($SearchStringHash{$Word}) ) {
2555 next;
2556 }
2557
2558 $Start = ($Offset < $main::SummaryKeywordSpan) ? 0 : $Offset - $main::SummaryKeywordSpan;
2559 $End = (($Offset + $main::SummaryKeywordSpan) > (scalar(@Words) - 1)) ? (scalar(@Words) - 1) : $Offset + $main::SummaryKeywordSpan;
2560
2561 if ( @OffsetPairs ) {
2562 ($OldStart, $OldEnd) = split(/,/, $OffsetPairs[scalar(@OffsetPairs) - 1]);
2563 }
2564
2565 if ( $OldEnd >= $Start ) {
2566 $OffsetPairs[scalar(@OffsetPairs) - 1] = "$OldStart,$End";
2567 }
2568 else {
2569 push @OffsetPairs, "$Start,$End";
2570 }
2571 $Offsets{$Offset} = $Offset;
2572 }
2573
2574
2575 # Now we rebuild the sentence from the words
2576 $SummaryText = "";
2577 foreach $OffsetPair ( @OffsetPairs ) {
2578
2579 ($Start, $End) = split(/,/, $OffsetPair);
2580
2581 if ( $Start > 0 ) {
2582 $SummaryText .= " ...";
2583 }
2584
2585 foreach $Offset ( $Start..$End ) {
2586
2587 if ( !defined($Words[$Offset]) ) {
2588 next;
2589 }
2590
2591 if ( defined($Offsets{$Offset}) ) {
2592 $SummaryText .= "<FONT COLOR=\"GREEN\">$Words[$Offset]</FONT> ";
2593 }
2594 else {
2595 $SummaryText .= $Words[$Offset] . " ";
2596 }
2597
2598 # Increment the summary length
2599 $CurrentSummaryLength++;
2600 }
2601
2602 # Append a diaresys at the end
2603 if ( $End < scalar(@Words) ) {
2604 $SummaryText .= "... ";
2605 }
2606
2607 # Bail if we have reached the max summary length
2608 if ( $CurrentSummaryLength > $SummaryLength ) {
2609 last;
2610 }
2611 }
2612 }
2613 }
2614 else {
2615 undef($SummaryText);
2616 }
2617 }
2618
2619
2620 # Decode the headline and strip the HTML
2621 $Headline = &lDecodeURLData($Headline);
2622 $Headline =~ s/&nbsp;//gs;
2623 $Headline =~ s/<.*?>//gs;
2624 $Headline =~ s/\s+/ /gs;
2625
2626
2627 # Create the selector text
2628 $SelectorText = "";
2629 if ( defined($Selector) && $Selector ) {
2630 $SelectorText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2631 $SelectorText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2632 $SelectorText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2633 $SelectorText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2634 $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"Document\" VALUE=\"" . substr($SelectorText, 1) . "\"> ";
2635 }
2636
2637
2638 # Put up the headline, the headline becomes the link to the document
2639
2640 # Create the link, we use the URL if it is there,
2641 # otherwise we create a link from the document ID
2642 if ( defined($URL) && ($URL ne "") ) {
2643 $LinkText = $URL;
2644 }
2645 elsif ( defined($DocumentID) && ($DocumentID ne "") ) {
2646 $LinkText = "";
2647 $LinkText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2648 $LinkText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2649 $LinkText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2650 $LinkText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2651 $LinkText = "$ScriptName/GetDocument?" . substr($LinkText, 1);
2652 }
2653 else {
2654 $LinkText = "";
2655 }
2656
2657 # Get the mime type name
2658 $MimeTypeName = (defined($main::MimeTypeNames{$MimeType})) ? $main::MimeTypeNames{$MimeType} : $MimeType;
2659
2660 # Put up the headline and the score, this one links to the document
2661 if ( $HTML ) {
2662 print("<!-- resultItem -->\n");
2663 #print("<TR><TD ALIGN=LEFT VALIGN=TOP WIDTH=1%> $SelectorText </TD> <TD ALIGN=LEFT VALIGN=TOP WIDTH=1%> <!-- relevance --> <B> $Score </B> <!-- /relevance --> </TD> <TD ALIGN=LEFT VALIGN=TOP> <A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $Headline <I> ( $main::DatabaseDescriptions{$Database} ) </I> </A> <BR> <FONT SIZE=-2>");
2664 # decode some basic html from headline <b> <i>
2665 $Headline =~ s/&lt;(\/?[bi])&gt;/<$1>/g;
2666
2667 print("<TR><TD ALIGN=LEFT VALIGN=TOP WIDTH=1%> $SelectorText </TD><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $Headline </A> <BR> <FONT SIZE=-2>&nbsp;");
2668 } else {
2669 printf("%3d $Headline \n", $Score);
2670 }
2671
2672 if (0) { ## don't display description
2673
2674 # Put up the summary
2675 if ( defined($SummaryText) && ($SummaryText ne "") ) {
2676 if ( $HTML ) {
2677 print(" <I> $SummaryText </I><BR>\n");
2678 }
2679 else {
2680 print(" $SummaryText\n");
2681 }
2682 }
2683
2684
2685 # Put up the mime type name
2686 if ( ! defined($Remainder) ) {
2687 if ( $HTML ) {
2688 print("Formatttt: $MimeTypeName, ");
2689
2690 }
2691 else {
2692 print(" Format: $MimeTypeName, ");
2693 }
2694 }
2695
2696
2697 # Put up the date if we got it
2698 if ( defined($Date) && ($Date ne "") ) {
2699 print("Date: $Date");
2700
2701 # Put up the time if we got it
2702 if ( defined($Time) && ($Time ne "") ) {
2703 print(" $Time");
2704 }
2705
2706 print(", ");
2707 }
2708
2709
2710 # Put up the document size, remember that there is only one
2711 # item name/mime type for this document if the remainder is undefined
2712 if ( ! defined($Remainder) ) {
2713 # Put up the length if it is defined
2714 if ( defined($Length) && ($Length ne "") ) {
2715 print("Size: $Length, ");
2716 }
2717
2718 # Put up the link
2719 if ( $HTML ) {
2720 if ( defined($URL) && ($URL ne "") ) {
2721 $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2722 print("<A HREF=\"$URL\"> $Value </A>\n");
2723 }
2724 }
2725 else {
2726 print(" URL: $LinkText\n");
2727 }
2728
2729 # Finish off the entry
2730 if ( $HTML ) {
2731 print("</FONT></TD></TR>");
2732 print("<!-- /resultItem -->\n");
2733 }
2734 print("\n");
2735 }
2736 else {
2737
2738 # There is a remainder, so there is more than one item name/mime type for this document,
2739 # the item names/mime types are listed as an un-numbered list
2740 if ( $HTML ) {
2741 print("<UL>");
2742 }
2743 print("\n");
2744
2745 # Set the last item to an empty string, this is also used as a flag
2746 $LastItemName = "";
2747
2748 # Loop while there are item names/mime types to be parsed
2749 do {
2750
2751 # Get the next item name/mime type if the last item is set
2752 if ( $LastItemName ne "" ) {
2753 ($ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $Remainder, 5);
2754 }
2755
2756
2757 # If the item name has changed, so we close of the current list and start a new one
2758 if ( $ItemName ne $LastItemName ) {
2759 if ( $LastItemName ne "" ) {
2760 if ( $HTML ) {
2761 print("</UL>");
2762 }
2763 print("\n");
2764 }
2765 $Value = ucfirst($ItemName);
2766 if ( $HTML ) {
2767 print("<LI> $Value </LI>\n<UL>\n");
2768 }
2769 else {
2770 print("$Value\n");
2771 }
2772
2773 # Set the last item name
2774 $LastItemName = $ItemName;
2775 }
2776
2777
2778 # Create the link, we use the URL if it is there,
2779 # otherwise we create a link from the document ID
2780 if ( defined($URL) && ($URL ne "") ) {
2781 $LinkText = $URL;
2782 }
2783 elsif ( defined($DocumentID) && ($DocumentID ne "") ) {
2784 $LinkText = "";
2785 $LinkText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2786 $LinkText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2787 $LinkText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2788 $LinkText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2789 $LinkText = "$ScriptName/GetDocument?" . substr($LinkText, 1);
2790 }
2791 else {
2792 $LinkText = "";
2793 }
2794
2795
2796 # Get the mime type name
2797 $MimeTypeName = defined($main::MimeTypeNames{$MimeType}) ? $main::MimeTypeNames{$MimeType} : $MimeType;
2798
2799
2800 # Put up the mime type, this one links to the document
2801 if ( $HTML ) {
2802 print("<LI><A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $MimeTypeName </A>");
2803 }
2804 else {
2805 print("$MimeTypeName ");
2806 }
2807
2808 # Put up the length if it is defined
2809 if ( defined($Length) && ($Length ne "") ) {
2810 print("Size: $Length, ");
2811 }
2812
2813 if ( $HTML ) {
2814 if ( defined($URL) && ($URL ne "") ) {
2815 $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2816 print("<A HREF=\"$URL\"> $Value </A>\n");
2817 }
2818 print("</LI>\n");
2819 }
2820 else {
2821 print("URL: $LinkText\n");
2822 }
2823
2824
2825 } while ( defined($Remainder) ); # Keep looping while there are item names/mime types to process
2826
2827 # Close off both un-numbered lists
2828 if ( $HTML ) {
2829 print("</UL></UL>");
2830 }
2831 print("\n");
2832
2833 } #if
2834 # Finish off the entry
2835 if ( $HTML ) {
2836 print("</FONT></TD></TR>\n");
2837 print("<!-- /resultItem -->\n");
2838 }
2839 }
2840 }
2841 }
2842
2843
2844 # Print up the query report if it is defined
2845 if ( defined($FinalQueryReport) && ($FinalQueryReport ne "") ) {
2846
2847 if ( $ResultCount > 0 ) {
2848 if ( $HTML ) {
2849 print("<TR><TD COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
2850 }
2851 else {
2852 print("--------------------------------------------------------------\n\n");
2853 }
2854 }
2855
2856 if ( $HTML ) {
2857 print("<TR><TD COLSPAN=2></TD><TD ALIGN=LEFT VALIGN=TOP>\n");
2858 }
2859
2860 $Value = $FinalQueryReport;
2861 if ( $HTML ) {
2862 $Value =~ s/\n/\<BR\>\n/g;
2863 }
2864
2865 if ( $HTML ) {
2866 print("<SMALL>\n");
2867 }
2868
2869 print("$Value");
2870
2871 if ( $HTML ) {
2872 print("</SMALL>\n");
2873 print("</TD></TR>\n");
2874 }
2875 }
2876
2877
2878 if ( $HTML ) {
2879
2880 # Close off the table
2881 print("<!-- /searchResults -->\n");
2882 print("</TABLE>\n");
2883
2884 if ( $Header ) {
2885 # Close off the form
2886 print("</FORM>\n");
2887 }
2888 }
2889
2890 # Return the status and the query report
2891 return (1, $FinalQueryReport);
2892
2893 }
2894
2895
2896
2897 #--------------------------------------------------------------------------
2898 #
2899 # Function: vGetSearch()
2900 #
2901 # Purpose: This function displays a search form to the user
2902 #
2903 # Called by:
2904 #
2905 # Parameters: void
2906 #
2907 # Global Variables: %main::ConfigurationData, %main::FormData, $main::RemoteUser
2908 #
2909 # Returns: void
2910 #
2911 sub vGetSearch {
2912
2913 my (@ItemList, $ItemEntry, $Flag);
2914 my ($DatabaseName, $SelectedDatabases, $Year);
2915 my ($Value, %Value);
2916
2917
2918 # If we are getting the default search, we check to see if there is a
2919 # user name defined and if they chose to have a default search
2920 if ( $ENV{'PATH_INFO'} eq "/GetSearch" ) {
2921
2922 if ( defined($main::RemoteUser) && defined($main::UserSettingsFilePath) ) {
2923
2924 # Get the default search symbol
2925 $Value = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "DefaultSearch");
2926
2927 # Set the default search
2928 if ( defined($Value) && ($Value eq "Simple") ) {
2929 $ENV{'PATH_INFO'} = "/GetSimpleSearch";
2930 }
2931 elsif ( defined($Value) && ($Value eq "Expanded") ) {
2932 $ENV{'PATH_INFO'} = "/GetExpandedSearch";
2933 }
2934 }
2935
2936 # Override the default search if there is field from the expanded form defined
2937 foreach $Value ('FieldContent3', 'Past', 'Since', 'Before') {
2938 if ( defined($main::FormData{$Value}) ) {
2939 $ENV{'PATH_INFO'} = "/GetExpandedSearch";
2940 last;
2941 }
2942 }
2943 }
2944
2945
2946
2947 # Make sure that we send the header
2948 $Value = ($ENV{'PATH_INFO'} eq "/GetExpandedSearch") ? "Slo¾eno pretra¾ivanje" : "Jednostavno pretra¾ivanje";
2949
2950 &vSendHTMLHeader($Value, $main::JavaScript_SetChecked);
2951
2952 undef(%Value);
2953 $Value{'GetSearch'} = "GetSearch";
2954 &vSendMenuBar(%Value);
2955 undef(%Value);
2956
2957
2958 # Print the header ($Value is reused from the header)
2959 print("<H3>$Value:</H3>\n");
2960
2961
2962 # We now have a list of valid databases, at least we think so,
2963 # we check that there is at least one and put up an error message if there are none
2964 if ( scalar(keys(%main::DatabaseDescriptions)) <= 0 ) {
2965 &vHandleError("Database Search", "Sorry, there were no valid databases available for searching");
2966 goto bailFromGetSearch;
2967 }
2968
2969
2970
2971 # Start the search form table
2972 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2973
2974 # Display the collapse and expand buttons
2975 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2>\n");
2976 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
2977
2978 # List the hidden fields
2979 %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
2980 foreach $Value ( keys(%Value) ) {
2981 @ItemList = split(/\0/, $Value{$Value});
2982 foreach $ItemEntry ( @ItemList ) {
2983 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ItemEntry\">\n");
2984 }
2985 }
2986
2987 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
2988 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSimpleSearch\">\n");
2989 print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'collapse'}\" BORDER=0 TYPE=IMAGE> Jednostavno pretra¾ivanje (kliknite na trokutiæ)\n");
2990 }
2991 else {
2992 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetExpandedSearch\">\n");
2993 print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'expand'}\" BORDER=0 TYPE=IMAGE> Slo¾eno pretra¾ivanje (kliknite na trokutiæ)\n");
2994 }
2995 print("</FORM></TD>\n");
2996
2997
2998
2999 # Send the start of the form and the buttons
3000 print("<TD ALIGN=RIGHT VALIGN=TOP>\n");
3001 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/GetSearchResults\" NAME=\"Search\" METHOD=POST> <INPUT TYPE=SUBMIT VALUE=\"Pretra¾i bazu\"> <INPUT TYPE=RESET VALUE=\"Vrati poèetne vrijednosti\">\n");
3002 print("</TD></TR>\n");
3003
3004 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><BR></TD></TR>\n");
3005
3006 # Send the standard fields
3007 $Value = defined($main::FormData{'Any'}) ? "VALUE='$main::FormData{'Any'}'" : "";
3008 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Pretra¾i u bilo kojem polju: </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"Any\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
3009
3010
3011 my $nr_fields = $main::NormalSearchDropdowns;
3012 my @SearchFieldNames = @main::NormalSearchFieldNames;
3013
3014 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3015 $nr_fields = $main::AdvancedSearchDropdowns;
3016 @SearchFieldNames = @main::AdvancedSearchFieldNames;
3017 }
3018
3019 for (my $field=1; $field<= $nr_fields; $field++) {
3020
3021 print "<TR>";
3022 if ($field == 1 ) {
3023 print "<TD ALIGN=LEFT VALIGN=TOP ROWSPAN=$nr_fields>";
3024 print "Pretra¾i u odabranom polju:";
3025 print "</td>";
3026 }
3027 print ("<TD ALIGN=RIGHT VALIGN=TOP>");
3028
3029 print ("<SELECT NAME=\"FieldName${field}\">");
3030 for (my $i=0; $i<=$#SearchFieldNames; $i++) {
3031 my $ItemEntry = $SearchFieldNames[$i];
3032 my $Selected = "";
3033 if ($main::FormData{"FieldName${field}"} && $main::FormData{"FieldName${field}"} eq $ItemEntry) {
3034 $Selected = "SELECTED";
3035 } elsif ($i == ($field - 1)) {
3036 $Selected = "SELECTED";
3037 }
3038 print("<OPTION VALUE=\"$ItemEntry\" $Selected> $main::SearchFieldDescriptions{$ItemEntry}\n");
3039 }
3040 my $Value = "";
3041 if (defined($main::FormData{"FieldContent${field}"})) {
3042 $Value = "VALUE='".$main::FormData{"FieldContent${field}"}."'";
3043 }
3044 print("</SELECT></TD><TD ALIGN=LEFT VALIGN=TOP><INPUT NAME=\"FieldContent${field}\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
3045 }
3046
3047
3048 # Send a pull-down which allows the user to select what to search for
3049 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Tra¾eni zapis mora sadr¾avati: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Operator\">\n");
3050 $Value = (defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "ADJ")) ? "SELECTED" : "";
3051 print("<OPTION VALUE=\"ADJ\"> Toènu frazu\n");
3052 $Value = ((defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "AND")) || !defined($main::FormData{'Operator'})) ? "SELECTED" : "";
3053 print("<OPTION VALUE=\"AND\" $Value> Sve rijeèi (AND)\n");
3054 $Value = (defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "OR")) ? "SELECTED" : "";
3055 print("<OPTION VALUE=\"OR\" $Value> Bilo koju rijeè (OR)\n");
3056 print("</SELECT> </TD></TR>\n");
3057
3058 print "<tr><td align=left valign=top> Prika¾i samo tip graðe: </td><td align=left valign=top colspan=2>";
3059 while (@default::tip_html) {
3060 print '<input TYPE="checkbox" NAME="tip" VALUE="',nuke_accents(shift @default::tip_html),'" >',shift @default::tip_html,"&nbsp&nbsp;";
3061 }
3062 print "</td></tr>\n";
3063
3064 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3065
3066
3067
3068 # Database selection
3069 if ( %main::DatabaseDescriptions ) {
3070
3071 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Odaberite knji¾nicu èiji fond ¾elite pretra¾ivati:</TD></TR>
3072 <TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=4>
3073 ");
3074
3075 # Parse out the database names and put them into a
3076 # hash table, they should be separated with a '\0'
3077 undef(%Value);
3078 if ( defined($main::FormData{'Database'}) ) {
3079 @ItemList = split(/\0/, $main::FormData{'Database'});
3080 }
3081 else {
3082 $SelectedDatabases = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SelectedDatabases");
3083 if ( defined($SelectedDatabases) ) {
3084 @ItemList = split(",", $SelectedDatabases);
3085 }
3086 }
3087
3088 &ShowDatabaseCheckBoxes(@ItemList);
3089
3090 print("</TD></TR>\n");
3091
3092 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3093 }
3094
3095
3096 # Print out the RF documents
3097 if ( defined($main::FormData{'RfDocument'}) ) {
3098 print("<TR>\n");
3099 &bDisplayDocuments("Feedback Document", $main::FormData{'RfDocument'}, "RfDocument", 1, 1, 1);
3100 print("</TR>\n");
3101 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3102 }
3103
3104
3105 # Send complex search pull-downs
3106 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3107
3108 if ($main::ConfigurationData{'show-past-date-list'} eq 'yes') {
3109
3110 # Send the past date list
3111 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Ogranièi na knjige koje su izdane u zadnjih : </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Past\">\n");
3112 $Value = (!defined($main::FormData{'Past'})) ? "SELECTED" : "";
3113 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3114 foreach $ItemEntry ( @main::PastDate ) {
3115 $Value = (defined($main::FormData{'Past'}) && ($main::FormData{'Past'} eq $ItemEntry)) ? "SELECTED" : "";
3116 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
3117 }
3118 print("</SELECT> </TD></TR>\n");
3119 }
3120
3121
3122 # Send the start date
3123 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Ogranièi na knjige izdane od godine: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Since\">\n");
3124 $Value = (!defined($main::FormData{'Since'})) ? "SELECTED" : "";
3125 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3126
3127 $Year = (localtime)[5] + 1900;
3128
3129 while ( $Year >= $main::ConfigurationData{'lowest-year'} ) {
3130 $Value = (defined($main::FormData{'Since'}) && ($main::FormData{'Since'} eq $Year)) ? "SELECTED" : "";
3131 print("<OPTION VALUE=\"$Year\" $Value> $Year \n");
3132 $Year--;
3133 }
3134 print("</SELECT> </TD></TR>\n");
3135
3136
3137 # Send the end date
3138 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Ogranièi na knjige izdane prije godine: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Before\">\n");
3139 $Value = (!defined($main::FormData{'Before'})) ? "SELECTED" : "";
3140 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3141
3142 $Year = (localtime)[5] + 1900;
3143
3144 while ( $Year >= $main::ConfigurationData{'lowest-year'} ) {
3145 $Value = (defined($main::FormData{'Before'}) && ($main::FormData{'Before'} eq $Year)) ? "SELECTED" : "";
3146 print("<OPTION VALUE=\"$Year\" $Value> $Year \n");
3147 $Year--;
3148 }
3149 print("</SELECT> </TD></TR>\n");
3150
3151 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3152 }
3153
3154
3155 # Send a pull-down which allows the user to select the max number of documents
3156 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Maksimalan broj rezultata pretra¾ivanja: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Max\">\n");
3157
3158 foreach $ItemEntry ( @main::MaxDocs ) {
3159 $Value = ((defined($main::FormData{'Max'}) && ($main::FormData{'Max'} eq $ItemEntry)) || (!defined($main::FormData{'Max'}) && ($ItemEntry eq $main::DefaultMaxDoc)) ) ? "SELECTED" : "";
3160 if ( ($ItemEntry >= 500) && $ENV{'PATH_INFO'} ne "/GetExpandedSearch" ) {
3161 next;
3162 }
3163 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
3164 }
3165
3166 print("</SELECT> </TD></TR>\n");
3167
3168
3169 # Send a pull-down which allows the user to select the sort order
3170 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Sortiranje rezultata: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Order\">\n");
3171 # print("<OPTION VALUE=\"\"> Relevance\n");
3172 $Value = (defined($main::FormData{'Order'}) && ($main::FormData{'Order'} eq "SORT:DATE:DESC")) ? "SELECTED" : "";
3173 print("<OPTION VALUE=\"SORT:DATE:DESC\" $Value> Datum - najprije novije\n");
3174 $Value = (defined($main::FormData{'Order'}) && ($main::FormData{'Order'} eq "DATEASCSORT")) ? "SELECTED" : "";
3175 print("<OPTION VALUE=\"SORT:DATE:ASC\" $Value> Datum - najprije starije\n");
3176 ### FIX:: SORT
3177 # print("<OPTION VALUE=\"SORT:700+:DESC\"> autor\n");
3178 # print("<OPTION VALUE=\"SORT:200+:DESC\"> naslov\n");
3179 print("</SELECT> </TD></TR>\n");
3180
3181
3182 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3183 print("<TR><TD ALIGN=RIGHT COLSPAN=3><INPUT TYPE=SUBMIT VALUE=\"Pretra¾i bazu\"> <INPUT TYPE=RESET VALUE=\"Vrati poèetne vrijednosti\"></TD></TR>\n");
3184
3185 print("</FORM>\n");
3186 print("</TABLE>\n");
3187
3188
3189 # Bail from the search
3190 bailFromGetSearch:
3191
3192 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3193 undef(%Value);
3194 $Value{'GetSearch'} = "GetSearch";
3195 &vSendMenuBar(%Value);
3196 undef(%Value);
3197
3198 &vSendHTMLFooter;
3199
3200 return;
3201
3202 }
3203
3204
3205
3206
3207
3208
3209 #--------------------------------------------------------------------------
3210 #
3211 # Function: vGetSearchResults()
3212 #
3213 # Purpose: This function run the search and displays the results to the user
3214 #
3215 # Called by:
3216 #
3217 # Parameters: void
3218 #
3219 # Global Variables: %main::ConfigurationData, %main::FormData, $main::RemoteUser
3220 #
3221 # Returns: void
3222 #
3223 sub vGetSearchResults {
3224
3225 my (%Databases, $Databases, $SearchString, $SearchAndRfDocumentURL, $RfText);
3226 my ($Status, $DocumentText, $SearchResults, $QueryReport, $ErrorNumber, $ErrorMessage);
3227 my ($DatabaseRelevanceFeedbackFilterKey, $DatabaseRelevanceFeedbackFilterFunction);
3228 my (@Values, %Value, $Value);
3229
3230 # Check to see if there are any documents selected, if there are, they need
3231 # to be converted to RF documents before we put up the header, this is because
3232 # the header creates a search link from existing search fields, we also deduplicate
3233 # documents along the way
3234 if ( defined($main::FormData{'RfDocument'}) || defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) {
3235
3236 # Undefine the hash table in preparation
3237 undef(%Value);
3238
3239 # Make a hash table from the documents already selected for feedback
3240 if ( defined($main::FormData{'RfDocument'}) ) {
3241 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3242 $Value{$Value} = $Value;
3243 }
3244 }
3245
3246 # Add document that were specifically selected
3247 if ( defined($main::FormData{'Document'}) ) {
3248 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
3249 $Value{$Value} = $Value;
3250 }
3251 }
3252 # Otherwise add documents that were selected by default
3253 elsif ( defined($main::FormData{'Documents'}) ) {
3254 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
3255 $Value{$Value} = $Value;
3256 }
3257 }
3258
3259 # Assemble the new content
3260 $main::FormData{'RfDocument'} = join("\0", keys(%Value));
3261
3262 # Delete the old content
3263 delete($main::FormData{'Document'});
3264 delete($main::FormData{'Documents'});
3265 }
3266
3267
3268 # Set the database names if needed
3269 if ( !defined($main::FormData{'Database'}) && defined($main::FormData{'RfDocument'}) ) {
3270
3271 # Loop over each entry in the documents list
3272 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3273
3274 # Parse out the document entry
3275 %Value = &hParseURLIntoHashTable($Value);
3276
3277 # Add the database name to the hash table
3278 $Databases{$Value{'Database'}} = $Value{'Database'};
3279 }
3280
3281 $main::FormData{'Database'} = join("\0", keys(%Databases));
3282 }
3283
3284 # now add all databases that had to be included always
3285 foreach (my $db = @main::always_selected_databases) {
3286 $Databases{$db} = $Value{$db};
3287 }
3288
3289 # Make sure that we send the header
3290 &vSendHTMLHeader("Rezultati pretra¾ivanja", undef);
3291 undef(%Value);
3292 &vSendMenuBar(%Value);
3293
3294 # Check that at least one database was selected
3295 if ( !defined($main::FormData{'Database'}) && $#main::always_selected_databases < 0 ) {
3296 print("<H3>Pretra¾ivanje baza:</H3>\n");
3297 print("<H3><CENTER>Niste odabrali knji¾nicu koju ¾elite pretra¾ivati.</CENTER></H3>\n");
3298 print("<P>\n");
3299 print("Potrebno je da barem jedna knji¾nica bude odabrana, kako biste mogli pretra¾ivati.\n");
3300 print("Kliknite na <B>'back'</B> u svom browseru, odaberite barem jednu knji¾nicu i poku¹ajte ponovo.\n");
3301 goto bailFromGetSearchResults;
3302 }
3303
3304
3305
3306 # Extract the search information
3307 foreach $Value ( 1..100 ) {
3308
3309 my ($FieldName) = "FieldName" . $Value;
3310 my ($FieldContent) = "FieldContent" . $Value;
3311
3312 if ( defined($main::FormData{$FieldName}) ) {
3313 if ( defined($main::FormData{$FieldContent}) && ($main::FormData{$FieldContent} ne "") ) {
3314 $main::FormData{$main::FormData{$FieldName}} = $main::FormData{$FieldContent};
3315 }
3316 }
3317 }
3318
3319
3320
3321 # Set the local database names
3322 if ( defined($main::FormData{'Database'}) ) {
3323 $Databases = $main::FormData{'Database'};
3324 }
3325
3326
3327 # Convert all the '\0' to ','
3328 $Databases =~ tr/\0/,/;
3329
3330 # add always selected databases
3331 if (@main::always_selected_databases) {
3332 $Databases .= ",".join(",",@main::always_selected_databases);
3333 }
3334
3335 # Add the max doc restriction
3336 if ( !defined($main::FormData{'Max'}) ) {
3337 $main::FormData{'Max'} = $main::DefaultMaxDoc;
3338 }
3339
3340 # Generate the search string
3341 $SearchString = &sMakeSearchString(%main::FormData);
3342
3343 # Retrieve the relevance feedback documents
3344 if ( defined($main::FormData{'RfDocument'}) ) {
3345
3346 $RfText = "";
3347
3348 # Loop over each entry in the documents list
3349 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3350
3351 # Parse out the document entry
3352 %Value = &hParseURLIntoHashTable($Value);
3353
3354 # Check this document can be used for relevance feedback
3355 if ( !defined($main::RFMimeTypes{$Value{'MimeType'}}) ) {
3356 next;
3357 }
3358
3359 # Get the document
3360 ($Status, $DocumentText) = MPS::GetDocument($main::MPSSession, $Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'});
3361
3362 if ( $Status ) {
3363
3364 $DatabaseRelevanceFeedbackFilterKey = "$main::DatabaseRelevanceFeedbackFilter:$Value{'Database'}:$Value{'ItemName'}:$Value{'MimeType'}";
3365
3366 # Is a filter defined for this database relevance feedback filter key ?
3367 if ( defined($main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey}) ) {
3368
3369 # Pull in the package
3370 require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Value{'Database'}"};
3371
3372 # Filter the document
3373 $Value = $main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey};
3374 $DatabaseRelevanceFeedbackFilterFunction = \&$Value;
3375 $DocumentText = $DatabaseRelevanceFeedbackFilterFunction->($Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'}, $DocumentText);
3376
3377 }
3378 else {
3379
3380 # Strip the HTML from the text (this is only really useful on HTML documents)
3381 if ( defined($main::HtmlMimeTypes{$Value{'MimeType'}}) ) {
3382 $DocumentText =~ s/&nbsp;//gs;
3383 $DocumentText =~ s/<.*?>//gs;
3384 }
3385 }
3386
3387 $RfText .= $DocumentText . " ";
3388 }
3389 }
3390 }
3391
3392
3393 # Run the search
3394 ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Databases, $SearchString, $RfText, 0, $main::FormData{'Max'} - 1, $main::ConfigurationData{'max-score'});
3395
3396 if ( $Status ) {
3397
3398 # Display the search results and get the query report text
3399 ($Status, $QueryReport) = &bsDisplaySearchResults("Rezultati pretra¾ivanja:", undef, undef, undef, $SearchResults, undef, $ENV{'SCRIPT_NAME'}, 1, 1, 1, %main::FormData);
3400
3401 # Save the search history
3402 if ( defined($main::RemoteUser) ) {
3403
3404 # Generate the search string
3405 $SearchAndRfDocumentURL = &sMakeSearchAndRfDocumentURL(%main::FormData);
3406
3407 # Save the search history
3408 &iSaveSearchHistory(undef, $SearchAndRfDocumentURL, $SearchResults, $QueryReport);
3409
3410 # Purge the search history files
3411 &vPurgeSearchHistory;
3412 }
3413 }
3414 else {
3415 ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
3416 &vHandleError("Database Search", "Sorry, failed to search the database(s)");
3417 print("The following error message was reported: <BR>\n");
3418 print("Error Message: $ErrorMessage <BR>\n");
3419 print("Error Number: $ErrorNumber <BR>\n");
3420 goto bailFromGetSearchResults;
3421 }
3422
3423
3424 # Bail from the search
3425 bailFromGetSearchResults:
3426
3427 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3428 undef(%Value);
3429 &vSendMenuBar(%Value);
3430
3431 &vSendHTMLFooter;
3432
3433 return;
3434
3435 }
3436
3437
3438
3439
3440
3441
3442 #--------------------------------------------------------------------------
3443 #
3444 # Function: vGetDatabaseInfo()
3445 #
3446 # Purpose: This function allows the user to get some database information
3447 # such as the description, the contents and the time period spanned
3448 # by the content.
3449 #
3450 # Called by:
3451 #
3452 # Parameters: void
3453 #
3454 # Global Variables: %main::ConfigurationData, %main::FormData
3455 #
3456 # Returns: void
3457 #
3458 sub vGetDatabaseInfo {
3459
3460 my ($DatabaseDescription, $DatabaseLanguage, $DatabaseTokenizer, $DocumentCount, $TotalWordCount, $UniqueWordCount, $StopWordCount, $AccessControl, $UpdateFrequency, $LastUpdateDate, $LastUpdateTime, $CaseSensitive);
3461 my ($FieldInformation, $FieldName, $FieldDescription);
3462 my ($Status, $Text, $Time, $Title);
3463 my ($ErrorNumber, $ErrorMessage);
3464 my ($Value, %Value);
3465
3466
3467
3468 # Check we that we got a database name
3469 if ( !defined($main::FormData{'Database'}) ) {
3470 &vHandleError("Database information", "Sorry, the database content description could not be obtained");
3471 goto bailFromGetDatabaseInfo;
3472 }
3473
3474
3475 # Make sure that we send the header
3476 $Title = "Database Information: " . (defined($main::DatabaseDescriptions{$main::FormData{'Database'