/[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

Annotation of /search/Search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations)
Tue Jun 25 14:37:37 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.11: +27 -70 lines
don't use images for navigation

1 dpavlin 1.1 #!/usr/bin/perl -w
2    
3     #*****************************************************************************
4 dpavlin 1.9 # 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 dpavlin 1.1 #*****************************************************************************
14    
15 dpavlin 1.4 #print "Content-type: text/plain\n\n";
16    
17 dpavlin 1.10 #use Data::Dumper;
18 dpavlin 1.9
19 dpavlin 1.1 #--------------------------------------------------------------------------
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 dpavlin 1.3 # read configuration fields
187 dpavlin 1.4 require "config.pm";
188 dpavlin 1.1
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 dpavlin 1.4
380 dpavlin 1.1 # 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("</HEAD>\n<BODY BGCOLOR=\"#FFFFFF\">\n");
396    
397    
398     # Send the header snippet file
399     &vPrintFileContent($main::ConfigurationData{'html-header-snippet-file'});
400    
401    
402     # Send the banner
403     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
404 dpavlin 1.5 # 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");
405    
406     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");
407    
408     print("</TABLE>\n");
409 dpavlin 1.1
410    
411     # Set the flag saying that the header has been sent
412     $main::HeaderSent = 1;
413    
414     return;
415    
416     }
417    
418    
419    
420     #--------------------------------------------------------------------------
421     #
422     # Function: vSendHTMLFooter()
423     #
424     # Purpose: This function send the HTML footer
425     #
426     # Called by:
427     #
428     # Parameters: void
429     #
430     # Global Variables: $main::FooterSent
431     #
432     # Returns: void
433     #
434     sub vSendHTMLFooter {
435    
436    
437     # Bail if we are not running as a CGI-BIN script
438     if ( ! $ENV{'GATEWAY_INTERFACE'} ) {
439     return;
440     }
441    
442     # Bail if we have already sent the footer
443     if ( $main::FooterSent ) {
444     return;
445     }
446    
447    
448     # Send the footer snippet file
449     &vPrintFileContent($main::ConfigurationData{'html-footer-snippet-file'});
450    
451    
452     # Send the end of body tag and end of HTML tag
453     print("</BODY>\n</HTML>\n");
454    
455    
456     # Set the flag saying that the footer has been sent
457     $main::FooterSent = 1;
458    
459     return;
460    
461     }
462    
463    
464    
465     #--------------------------------------------------------------------------
466     #
467     # Function: vSendMenuBar()
468     #
469     # Purpose: This function send the mneu bar
470     #
471     # Called by:
472     #
473     # Parameters: %MenuBar menu bar exclusion hash table
474     #
475     # Global Variables:
476     #
477     # Returns: void
478     #
479     sub vSendMenuBar {
480    
481     my (%MenuBar) = @_;
482    
483     my (%Value, $Value, $ValueEntry);
484    
485    
486     # Start the table
487     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
488    
489     # Start the menu bar cell
490     print("<TR><TD VALIGN=CENTER ALIGN=CENTER>\n");
491    
492     # Start the form
493     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
494    
495    
496    
497     # List the hidden fields
498     %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
499     foreach $Value ( keys(%Value) ) {
500     foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
501     print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
502     }
503     }
504    
505 dpavlin 1.12 my $DISABLED;
506 dpavlin 1.5
507 dpavlin 1.12 $DISABLED = ( %MenuBar && defined($MenuBar{'GetSearch'}) ) ? "DISABLED" : "";
508     print("<INPUT NAME=\"GetSearch\" TYPE=SUBMIT VALUE=\"Forma za pretra¾ivanje\" $DISABLED>");
509 dpavlin 1.1
510     if ( defined($main::RemoteUser) ) {
511 dpavlin 1.12 $DISABLED = ( %MenuBar && defined($MenuBar{'ListSearchHistory'}) ) ? "DISABLED" : "";
512     print"<INPUT NAME=\"ListSearchHistory\" TYPE=SUBMIT VALUE=\"Search History\" $DISABLED>";
513 dpavlin 1.1
514 dpavlin 1.12 $DISABLED = ( %MenuBar && defined($MenuBar{'ListSavedSearch'}) ) ? "DISABLED" : "";
515     print"<INPUT NAME=\"ListSavedSearch\" TYPE=SUBMIT VALUE=\"List Saved Search\" $DISABLED>";
516 dpavlin 1.1
517 dpavlin 1.12 $DISABLED = ( %MenuBar && defined($MenuBar{'ListFolder'}) ) ? "DISABLED" : "";
518     print"<INPUT NAME=\"ListFolder\" TYPE=SUBMIT VALUE=\"List Folder\" $DISABLED>";
519    
520     $DISABLED = ( %MenuBar && defined($MenuBar{'GetUserSettings'}) ) ? "DISABLED" : "";
521     print"<INPUT NAME=\"GetUserSettings\" TYPE=SUBMIT VALUE=\"Get User Settings\" $DISABLED>";
522 dpavlin 1.1 }
523    
524    
525     print("</FORM>\n");
526    
527     # Close off the menu bar cell
528     print("</TD></TR>\n");
529    
530     print("</TABLE>\n");
531    
532    
533     return;
534     }
535    
536    
537    
538    
539    
540    
541     #--------------------------------------------------------------------------
542     #
543     # Function: vHandleError()
544     #
545     # Purpose: This function handles any errors messages that need to be
546     # reported when an error occurs
547     #
548     # This error handler also displays the header if needed
549     #
550     # Called by:
551     #
552     # Parameters: $Header header
553     # $Message message
554     #
555     # Global Variables:
556     #
557     # Returns: void
558     #
559     sub vHandleError {
560    
561     my ($Header, $Message) = @_;
562    
563     my ($Package, $FileName, $Line);
564    
565    
566     # Make sure we send the header
567     &vSendHTMLHeader("Error", undef);
568    
569    
570     printf("<H3> %s: </H3>\n", defined($Header) ? $Header : "No header supplied");
571     printf("<H3><CENTER> %s. </CENTER></H3>\n", defined($Message) ? $Message : "No error message supplied");
572     print("<P>\n");
573     if ( defined($main::ConfigurationData{'site-admin-url'}) ) {
574     print("<CENTER> Please <A HREF=\"$main::ConfigurationData{'site-admin-url'}\"> contact the administrator </A> of this system to correct the problem. </CENTER>\n");
575     }
576     else {
577     print("<CENTER> Please contact the administrator of this system to correct the problem. </CENTER>\n");
578     }
579     print("<P><HR WIDTH=50%><P>\n");
580    
581    
582     # Send package information
583     # ($Package, $FileName, $Line) = caller;
584     # print("Package = [$Package], FileName = [$FileName], Line = [$Line] <BR>\n");
585    
586     return;
587     }
588    
589    
590    
591    
592    
593     #--------------------------------------------------------------------------
594     #
595     # Function: bCheckConfiguration()
596     #
597     # Purpose: This function checks that the configuration settings
598     # specified are correct and that any directory paths and
599     # files specified are there and can be accessed.
600     #
601     # We check both required settings and optional setting if
602     # they have been set.
603     #
604     # An error here should be considered fatal.
605     #
606     # Called by:
607     #
608     # Parameters: void
609     #
610     # Global Variables: %main::ConfigurationData
611     #
612     # Returns: Boolean status
613     #
614     sub bCheckConfiguration {
615    
616     my ($Value, $Status);
617    
618    
619     # Init the status
620     $Status = 1;
621    
622    
623     # Check 'user-accounts-directory' (optional)
624     if ( defined($main::ConfigurationData{'user-accounts-directory'}) ) {
625    
626     $main::ConfigurationData{'user-accounts-directory'} = &sCleanSetting('user-accounts-directory', $main::ConfigurationData{'user-accounts-directory'}, $main::RootDirectoryPath);
627     $Value = $main::ConfigurationData{'user-accounts-directory'};
628    
629     # Check that the directory exists
630     if ( ! (-d $Value) ) {
631     &vLog("Error - configuration setting: 'user-accounts-directory', directory: '$Value' does not exist.\n");
632     $Status = 0;
633     }
634     else {
635    
636     # The directory exists, now check that it can be accessed
637     if ( ! ((-r $Value) && (-w $Value) && (-x $Value)) ) {
638     &vLog("Error - configuration setting: 'user-accounts-directory', directory: '$Value' cannot be accessed.\n");
639     $Status = 0;
640     }
641     }
642     }
643    
644    
645    
646     # Check 'database-description-file' (optional)
647     if ( defined($main::ConfigurationData{'database-description-file'}) ) {
648    
649     $main::ConfigurationData{'database-description-file'} = &sCleanSetting('database-description-file', $main::ConfigurationData{'database-description-file'}, $main::RootDirectoryPath);
650     $Value = $main::ConfigurationData{'database-description-file'};
651    
652     # Check that the file exists
653     if ( ! ((-f $Value) && (-r $Value)) ) {
654     &vLog("Error - configuration setting: 'database-description-file', file: '$Value' does not exist.\n");
655     $Status = 0;
656     }
657     }
658    
659    
660    
661     # Check 'allow-summary-displays' (optional)
662     if ( defined($main::ConfigurationData{'allow-summary-displays'}) ) {
663    
664     # Clean the setting and convert to lower case
665     $main::ConfigurationData{'allow-summary-displays'} = &sCleanSetting('allow-summary-displays', $main::ConfigurationData{'allow-summary-displays'});
666     $main::ConfigurationData{'allow-summary-displays'} = lc($main::ConfigurationData{'allow-summary-displays'});
667    
668     # Check that the setting is valid
669     if ( ($main::ConfigurationData{'allow-summary-displays'} ne "yes") && ($main::ConfigurationData{'allow-summary-displays'} ne "no")) {
670     &vLog("Warning - configuration setting: 'allow-summary-displays', setting not recognized: $main::ConfigurationData{'allow-summary-displays'}.\n");
671     }
672     }
673    
674    
675    
676     # Check 'allow-similiar-search' (optional)
677     if ( defined($main::ConfigurationData{'allow-similiar-search'}) ) {
678    
679     # Clean the setting and convert to lower case
680     $main::ConfigurationData{'allow-similiar-search'} = &sCleanSetting('allow-similiar-search', $main::ConfigurationData{'allow-similiar-search'});
681     $main::ConfigurationData{'allow-similiar-search'} = lc($main::ConfigurationData{'allow-similiar-search'});
682    
683     # Check that the setting is valid
684     if ( ($main::ConfigurationData{'allow-similiar-search'} ne "yes") && ($main::ConfigurationData{'allow-similiar-search'} ne "no")) {
685     &vLog("Warning - configuration setting: 'allow-similiar-search', setting not recognized: $main::ConfigurationData{'allow-similiar-search'}.\n");
686     }
687     }
688    
689    
690    
691     # Check 'allow-regular-searches' (optional)
692     if ( defined($main::ConfigurationData{'allow-regular-searches'}) ) {
693    
694     # Clean the setting and convert to lower case
695     $main::ConfigurationData{'allow-regular-searches'} = &sCleanSetting('allow-regular-searches', $main::ConfigurationData{'allow-regular-searches'});
696     $main::ConfigurationData{'allow-regular-searches'} = lc($main::ConfigurationData{'allow-regular-searches'});
697    
698     # Check that the setting is valid
699     if ( ($main::ConfigurationData{'allow-regular-searches'} ne "yes") && ($main::ConfigurationData{'allow-regular-searches'} ne "no")) {
700     &vLog("Warning - configuration setting: 'allow-regular-searches', setting not recognized: $main::ConfigurationData{'allow-regular-searches'}.\n");
701     }
702     }
703    
704    
705    
706     # Check 'deliver-empty-results-from-regular-search' (optional)
707     if ( defined($main::ConfigurationData{'deliver-empty-results-from-regular-search'}) ) {
708    
709     # Clean the setting and convert to lower case
710     $main::ConfigurationData{'deliver-empty-results-from-regular-search'} = &sCleanSetting('deliver-empty-results-from-regular-search', $main::ConfigurationData{'deliver-empty-results-from-regular-search'});
711     $main::ConfigurationData{'deliver-empty-results-from-regular-search'} = lc($main::ConfigurationData{'deliver-empty-results-from-regular-search'});
712    
713     # Check that the setting is valid
714     if ( ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} ne "yes") && ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} ne "no")) {
715     &vLog("Warning - configuration setting: 'deliver-empty-results-from-regular-search', setting not recognized: $main::ConfigurationData{'deliver-empty-results-from-regular-search'}.\n");
716     }
717     }
718    
719    
720    
721     # Check 'allow-relevance-feedback-searches' (optional)
722     if ( defined($main::ConfigurationData{'allow-relevance-feedback-searches'}) ) {
723    
724     # Clean the setting and convert to lower case
725     $main::ConfigurationData{'allow-relevance-feedback-searches'} = &sCleanSetting('allow-relevance-feedback-searches', $main::ConfigurationData{'allow-relevance-feedback-searches'});
726     $main::ConfigurationData{'allow-relevance-feedback-searches'} = lc($main::ConfigurationData{'allow-relevance-feedback-searches'});
727    
728     # Check that the setting is valid
729     if ( ($main::ConfigurationData{'allow-relevance-feedback-searches'} ne "yes") && ($main::ConfigurationData{'allow-relevance-feedback-searches'} ne "no")) {
730     &vLog("Warning - configuration setting: 'allow-relevance-feedback-searches', setting not recognized: $main::ConfigurationData{'allow-relevance-feedback-searches'}.\n");
731     }
732     }
733    
734    
735    
736     # Check 'html-directory' (required)
737     $main::ConfigurationData{'html-directory'} = &sCleanSetting('html-directory', $main::ConfigurationData{'html-directory'}, $main::RootDirectoryPath);
738     $Value = $main::ConfigurationData{'html-directory'};
739    
740     # Check that the directory exists
741     if ( ! (-d $Value) ) {
742     &vLog("Error - configuration setting: 'html-directory', directory: '$Value' does not exist.\n");
743     $Status = 0;
744     }
745     else {
746    
747     # The directory exists, now check that it can be accessed
748     if ( ! ((-r $Value) && (-x $Value)) ) {
749     &vLog("Error - configuration setting: 'html-directory', directory: '$Value' cannot be accessed.\n");
750     $Status = 0;
751     }
752     }
753    
754    
755    
756     # Check 'image-base-path' (required)
757     $main::ConfigurationData{'image-base-path'} = &sCleanSetting('image-base-path', $main::ConfigurationData{'image-base-path'});
758     $Value = $main::ConfigurationData{'html-directory'} . $main::ConfigurationData{'image-base-path'};
759    
760     # Check that the directory exists
761     if ( ! (-d $Value) ) {
762     &vLog("Error - configuration setting: 'image-base-path', directory: '$Value' does not exist.\n");
763     $Status = 0;
764     }
765     else {
766    
767     my ($ImageName);
768    
769     # The directory exists, now check that it can be accessed
770     if ( ! ((-r $Value) && (-x $Value)) ) {
771     &vLog("Error - configuration setting: 'image-base-path', directory: '$Value' cannot be accessed.\n");
772     $Status = 0;
773     }
774    
775    
776     # Check the general icons
777     foreach $ImageName ( values(%main::ImageNames) ) {
778    
779     $Value = $main::ConfigurationData{'html-directory'} . $main::ConfigurationData{'image-base-path'} . "/" . $ImageName;
780    
781     # Check that the file exists
782     if ( ! ((-f $Value) && (-r $Value)) ) {
783     &vLog("Error - configuration setting: 'image-base-path', file: '$Value' does not exist.\n");
784     $Status = 0;
785     }
786     }
787     }
788    
789    
790    
791     # Check 'html-header-snippet-file' (optional)
792     if ( defined($main::ConfigurationData{'html-header-snippet-file'}) ) {
793    
794     $main::ConfigurationData{'html-header-snippet-file'} = &sCleanSetting('html-header-snippet-file', $main::ConfigurationData{'html-header-snippet-file'}, $main::RootDirectoryPath);
795     $Value = $main::ConfigurationData{'html-header-snippet-file'};
796    
797     # Check that the file exists
798     if ( ! ((-f $Value) && (-r $Value)) ) {
799     &vLog("Error - configuration setting: 'html-header-snippet-file', file: '$Value' does not exist.\n");
800     $Status = 0;
801     }
802     }
803    
804    
805    
806     # Check 'html-footer-snippet-file' (optional)
807     if ( defined($main::ConfigurationData{'html-footer-snippet-file'}) ) {
808    
809     $main::ConfigurationData{'html-footer-snippet-file'} = &sCleanSetting('html-footer-snippet-file', $main::ConfigurationData{'html-footer-snippet-file'}, $main::RootDirectoryPath);
810     $Value = $main::ConfigurationData{'html-footer-snippet-file'};
811    
812     # Check that the file exists
813     if ( ! ((-f $Value) && (-r $Value)) ) {
814     &vLog("Error - configuration setting: 'html-footer-snippet-file', file: '$Value' does not exist.\n");
815     $Status = 0;
816     }
817     }
818    
819    
820    
821     # Check 'logs-directory' (required)
822     $main::ConfigurationData{'logs-directory'} = &sCleanSetting('logs-directory', $main::ConfigurationData{'logs-directory'}, $main::RootDirectoryPath);
823     $Value = $main::ConfigurationData{'logs-directory'};
824    
825     # Check that the directory exists
826     if ( ! (-d $Value) ) {
827     &vLog("Error - configuration setting: 'logs-directory', directory: '$Value' does not exist.\n");
828     $Status = 0;
829     }
830     else {
831    
832     # The directory exists, now check that it can be accessed
833     if ( ! ((-r $Value) && (-w $Value) && (-x $Value)) ) {
834     &vLog("Error - configuration setting: 'logs-directory', directory: '$Value' cannot be accessed.\n");
835     $Status = 0;
836     }
837     }
838    
839    
840    
841     # Check 'database-directory' (required)
842     $main::ConfigurationData{'database-directory'} = &sCleanSetting('database-directory', $main::ConfigurationData{'database-directory'}, $main::RootDirectoryPath);
843     $Value = $main::ConfigurationData{'database-directory'};
844    
845     # Check that the directory exists
846     if ( ! (-d $Value) ) {
847     &vLog("Error - configuration setting: 'database-directory', directory: '$Value' does not exist.\n");
848     $Status = 0;
849     }
850     else {
851    
852     # The directory exists, now check that it can be accessed
853     if ( ! ((-r $Value) && (-x $Value)) ) {
854     &vLog("Error - configuration setting: 'database-directory, directory: '$Value' cannot be accessed.\n");
855     $Status = 0;
856     }
857     }
858    
859    
860    
861     # Check 'configuration-directory' (required)
862     $main::ConfigurationData{'configuration-directory'} = &sCleanSetting('configuration-directory', $main::ConfigurationData{'configuration-directory'}, $main::RootDirectoryPath);
863     $Value = $main::ConfigurationData{'configuration-directory'};
864    
865     # Check that the directory exists
866     if ( ! (-d $Value) ) {
867     &vLog("Error - configuration setting: 'configuration-directory', directory: '$Value' does not exist.\n");
868     $Status = 0;
869     }
870     else {
871    
872     # The directory exists, now check that it can be accessed
873     if ( ! ((-r $Value) && (-x $Value)) ) {
874     &vLog("Error - configuration setting: 'configuration-directory, directory: '$Value' cannot be accessed.\n");
875     $Status = 0;
876     }
877     }
878    
879    
880    
881     # Check 'server-log' (optional with default)
882     $main::ConfigurationData{'server-log'} = &sCleanSetting('server-log', $main::ConfigurationData{'server-log'});
883     $Value = $main::ConfigurationData{'logs-directory'} . "/" . $main::ConfigurationData{'server-log'};
884    
885     # Check that we can write to the log file if it exists
886     if ( -f $Value ) {
887    
888     # The file exists, now check that it can be accessed
889     if ( ! -w $Value ) {
890     &vLog("Error - configuration setting: 'server-log', directory: '$Value' cannot be accessed.\n");
891     $Status = 0;
892     }
893     }
894    
895    
896    
897     # Check 'mailer-application' (optional with default)
898     if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
899    
900     $main::ConfigurationData{'mailer-application'} = &sCleanSetting('mailer-application', $main::ConfigurationData{'mailer-application'}, $main::RootDirectoryPath);
901     $Value = $main::ConfigurationData{'mailer-application'};
902    
903     # Check that the application can be executed
904     if ( ! (-x $Value) ) {
905     &vLog("Error - configuration setting: 'mailer-application', application: '$Value' cannot be executed.\n");
906     $Status = 0;
907     }
908     }
909    
910    
911     return ($Status);
912    
913     }
914    
915    
916    
917    
918    
919     #--------------------------------------------------------------------------
920     #
921     # Function: bGetDatabaseDescriptions()
922     #
923     # Purpose: This function reads the database description file and places it in the
924     # hash table global, note that the hash table is not cleared before
925     # we start to add kay/value pairs to it.
926     #
927     # Any line which starts with a '#' or is empty will be skipped.
928     #
929     # An error will be generated if we try to redefine a value for a
930     # key that has already been defined.
931     #
932     # An error here should be considered fatal.
933     #
934     # Called by:
935     #
936     # Parameters: void
937     #
938     # Global Variables: %main::ConfigurationData, %main::DatabaseDescriptions
939     #
940     # Returns: Boolean status
941     #
942     sub bGetDatabaseDescriptions {
943    
944     my ($Status, $Key, $KeyValue, $KeyBase, $KeyLeaf, $Database);
945    
946    
947     # Init the status
948     $Status = 1;
949    
950    
951     # Only check the database description file if it is available
952     if ( defined($main::ConfigurationData{'database-description-file'}) ) {
953    
954     # Open the database description file
955     if ( ! open(FILE, "$main::ConfigurationData{'database-description-file'}") ) {
956     &vLog("Error - could not open database description file: '$main::ConfigurationData{'database-description-file'}'.\n");
957     return (0);
958     }
959    
960     # Read in each line in the file, ignore empty
961     # lines and lines which start with a '#'
962     while (<FILE>) {
963    
964     chop $_;
965    
966     # Check to see if this line is empty or is a comment, and skip them
967     if ( (length($_) == 0) || ($_ =~ /^#/) ) {
968     next;
969     }
970    
971     # Split the configuration string into a set of key/value pairs
972     ($Key, $KeyValue) = split(/=/, $_);
973    
974     # Only add values which are defined
975     if ( defined($KeyValue) && ($KeyValue ne "") ) {
976    
977     # Split the key into a key and a subkey
978     ($KeyBase, $KeyLeaf) = split(/:/, $Key, 2);
979    
980     if ( $KeyBase eq $main::DatabaseName ) {
981    
982     # Add the key/value pairs to the hash table
983     if ( defined($main::DatabaseDescriptions{$KeyLeaf}) ) {
984     # Fail if the value for this key is already defined
985     &vLog("Error - value for: '$KeyLeaf', is already defined as: '$main::DatabaseDescriptions{$KeyLeaf}', tried to redefine it to: '$KeyValue'.\n");
986     $Status = 0;
987     }
988     else {
989     # Add the value for this key
990     if ($KeyValue =~ s/(##sort[^#]+##)//) {
991     $main::DatabaseSort{$1} = $KeyLeaf;
992     } else {
993     $main::DatabaseSort{$KeyValue} = $KeyLeaf;
994     }
995     $main::DatabaseDescriptions{$KeyLeaf} = $KeyValue;
996     }
997     }
998     elsif ( $KeyBase eq $main::DatabaseFiltersPackage ) {
999    
1000     # Add the key/value pairs to the hash table
1001     if ( defined($main::DatabaseFilters{$Key}) ) {
1002     # Fail if the value for this key is already defined
1003     &vLog("Error - value for: '$Key', is already defined as: '$main::DatabaseFilters{$Key}', tried to redefine it to: '$KeyValue'.\n");
1004     $Status = 0;
1005     }
1006     else {
1007    
1008     # Check that this filters package exists
1009     if ( ! -x $KeyValue ) {
1010     # Fail we cant find it
1011     &vLog("Error - filter: '$KeyValue' for: '$Key' could not be found.\n");
1012     $Status = 0;
1013     }
1014    
1015     # Add the value for this key
1016     $main::DatabaseFilters{$Key} = $KeyValue;
1017     }
1018     }
1019     else {
1020    
1021     ($Database) = split(/:/, $KeyLeaf);
1022    
1023     # Add the key/value pairs to the hash table
1024     if ( ! defined($main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Database"}) ) {
1025     # Fail if we dont have the package for this function
1026     &vLog("Error - package file for function: '$KeyValue', defined for: '$Key', cound not be found.\n");
1027     $Status = 0;
1028     }
1029     elsif ( defined($main::DatabaseFilters{$Key}) ) {
1030     # Fail if the value for this key is already defined
1031     &vLog("Error - value for: '$Key', is already defined as: '$main::DatabaseFilters{$Key}', tried to redefine it to: '$KeyValue'.\n");
1032     $Status = 0;
1033     }
1034     else {
1035    
1036     # Add the value for this key
1037     $main::DatabaseFilters{$Key} = $KeyValue;
1038     }
1039     }
1040     }
1041     }
1042     close(FILE);
1043     }
1044    
1045     # fill defaults for rest
1046     $main::DatabaseFilters{$Key} = $main::DatabaseFilters{default} if (! defined($main::DatabaseFilters{$Key}));
1047    
1048     return ($Status);
1049    
1050     }
1051    
1052    
1053    
1054    
1055    
1056     #--------------------------------------------------------------------------
1057     #
1058     # Function: bInitializeServer()
1059     #
1060     # Purpose: This function sets up the server
1061     #
1062     # An error here should be considered fatal.
1063     #
1064     # Called by:
1065     #
1066     # Parameters: void
1067     #
1068     # Global Variables: %main::ConfigurationData
1069     #
1070     # Returns: Boolean status
1071     #
1072     sub bInitializeServer {
1073    
1074     my ($Status, $Text);
1075     my ($ErrorNumber, $ErrorMessage);
1076    
1077    
1078     # Initialize the server
1079     ($Status, $Text) = MPS::InitializeServer($main::ConfigurationData{'database-directory'}, $main::ConfigurationData{'configuration-directory'}, $main::ConfigurationData{'logs-directory'} . "/". $main::ConfigurationData{'server-log'}, MPS_LOG_MEDIUM);
1080    
1081     # Check the return code
1082     if ( ! $Status ) {
1083     ($ErrorNumber, $ErrorMessage) = split(/\t/, $Text, 2);
1084     &vHandleError("Database Search", "Sorry, failed to initialize the server");
1085     print("The following error message was reported: <BR>\n");
1086     print("Error Message: $ErrorMessage <BR>\n");
1087     print("Error Number: $ErrorNumber <BR>\n");
1088     }
1089    
1090     $main::MPSSession = $Text;
1091    
1092     return ($Status);
1093     }
1094    
1095    
1096    
1097    
1098    
1099     #--------------------------------------------------------------------------
1100     #
1101     # Function: bShutdownServer()
1102     #
1103     # Purpose: This function shuts down the server
1104     #
1105     # An error here should be considered fatal.
1106     #
1107     # Called by:
1108     #
1109     # Parameters: void
1110     #
1111     # Global Variables: %main::ConfigurationData
1112     #
1113     # Returns: Boolean status
1114     #
1115     sub bShutdownServer {
1116    
1117    
1118     # Shutdown the server
1119     MPS::ShutdownServer($main::MPSSession);
1120    
1121     return (1);
1122    
1123     }
1124    
1125    
1126    
1127    
1128    
1129     #--------------------------------------------------------------------------
1130     #
1131     # Function: bCheckCGIEnvironment()
1132     #
1133     # Purpose: This function checks that all the CGI environment variables we
1134     # need are available. It will exit if any of the variables are
1135     # not found, but it will first list all the variables that are
1136     # not available.
1137     #
1138     # An error here should be considered fatal.
1139     #
1140     # Called by:
1141     #
1142     # Parameters: void
1143     #
1144     # Global Variables: $ENV{}
1145     #
1146     # Returns: Boolean status
1147     #
1148     sub bCheckCGIEnvironment {
1149    
1150     my ($Status);
1151    
1152    
1153     # Init the status
1154     $Status = 1;
1155    
1156    
1157     # Check that REQUEST_METHOD is specified
1158     if ( ! (defined($ENV{'REQUEST_METHOD'}) && ($ENV{'REQUEST_METHOD'} ne "")) ) {
1159     &vLog("Error - missing 'REQUEST_METHOD' environment variable.\n");
1160     $Status = 0;
1161     }
1162    
1163    
1164     # Check that SCRIPT_NAME is specified
1165     if ( ! (defined($ENV{'SCRIPT_NAME'}) && ($ENV{'SCRIPT_NAME'} ne "")) ) {
1166     &vLog("Error - missing 'SCRIPT_NAME' environment variable.\n");
1167     $Status = 0;
1168     }
1169    
1170    
1171     # Force guest
1172     #$ENV{'REMOTE_USER'} = "guest";
1173    
1174     # Make sure that REMOTE_USER is defined, we set it to an empty string if it is not
1175     if ( ! (defined($ENV{'REMOTE_USER'}) && ($ENV{'REMOTE_USER'} ne "")) ) {
1176     $ENV{'REMOTE_USER'} = "";
1177     }
1178     else {
1179     # REMOTE_USER is defined, we check to see if the guest account name is defined
1180     if ( defined($main::ConfigurationData{'guest-account-name'}) ) {
1181     # Set the REMOTE_USER to an empty string if it is the same as the guest account
1182     if ( $ENV{'REMOTE_USER'} eq $main::ConfigurationData{'guest-account-name'} ) {
1183     $ENV{'REMOTE_USER'} = "";
1184     }
1185     }
1186     }
1187    
1188    
1189     # Adjust the path info if needed
1190     if ( defined($ENV{'PATH_INFO'}) && defined($ENV{'SCRIPT_NAME'}) && (length($ENV{'PATH_INFO'}) > length($ENV{'SCRIPT_NAME'})) ) {
1191     if ( substr($ENV{'PATH_INFO'}, 0, length($ENV{'SCRIPT_NAME'})) eq $ENV{'SCRIPT_NAME'} ) {
1192     $ENV{'PATH_INFO'} = substr($ENV{'PATH_INFO'}, length($ENV{'SCRIPT_NAME'}));
1193     $ENV{'PATH_INFO'} = undef if ($ENV{'PATH_INFO'} eq "");
1194     }
1195     }
1196    
1197    
1198     return ($Status);
1199    
1200     }
1201    
1202    
1203    
1204    
1205     #--------------------------------------------------------------------------
1206     #
1207     # Function: bSetupCGIEnvironment()
1208     #
1209     # Purpose: This function sets up the environment for the CGI mode, it will
1210     # also check that all the globals are correct and that any
1211     # required directories can be accessed and written to
1212     #
1213     # An error here should be considered fatal.
1214     #
1215     # Called by:
1216     #
1217     # Parameters: void
1218     #
1219     # Global Variables: $main::UserAccountDirectoryPath, $main::UserSettingsFilePath, $main::RemoteUser,
1220     # %main::FormData, %main::ConfigurationData
1221     #
1222     # Returns: Boolean status
1223     #
1224     sub bSetupCGIEnvironment {
1225    
1226     my ($Status, $URLString);
1227    
1228    
1229     # Init the status
1230     $Status = 1;
1231    
1232    
1233     # Get the query string from the environment
1234     if ( $ENV{'REQUEST_METHOD'} eq "GET" ) {
1235     $URLString = $ENV{'QUERY_STRING'};
1236     }
1237     # Get the query string from stdin
1238     elsif ( $ENV{'REQUEST_METHOD'} eq "POST" ) {
1239     read("STDIN", $URLString, $ENV{'CONTENT_LENGTH'});
1240    
1241     # Append the query string if it is defined
1242     if ( defined($ENV{'QUERY_STRING'}) && ($ENV{'QUERY_STRING'} ne "") ) {
1243     $URLString = $ENV{'QUERY_STRING'} . "&". $URLString;
1244     }
1245     }
1246    
1247    
1248     # Parse the form data that was passed
1249     if ( defined($URLString) && ($URLString ne "") ) {
1250     %main::FormData = &hParseURLIntoHashTable($URLString);
1251     }
1252    
1253    
1254     # Get the REMOTE_USER from the CGI environment and set the user account directory path
1255     if ( (defined($ENV{'REMOTE_USER'})) && ($ENV{'REMOTE_USER'} ne "") && defined($main::ConfigurationData{'user-accounts-directory'}) ) {
1256     $main::RemoteUser = $ENV{'REMOTE_USER'};
1257     $main::UserAccountDirectoryPath = $main::ConfigurationData{'user-accounts-directory'} . "/". $main::RemoteUser;
1258     $main::UserAccountDirectoryPath =~ tr/\+/ /;
1259     $main::UserSettingsFilePath = $main::UserAccountDirectoryPath . "/". $main::UserSettingsFileName . $main::XMLFileNameExtension;
1260     }
1261     else {
1262     undef($main::RemoteUser);
1263     undef($main::UserAccountDirectoryPath);
1264     undef($main::UserSettingsFilePath);
1265     }
1266    
1267    
1268     # Check that the user account directory exists if it is specified
1269     if ( defined($main::UserAccountDirectoryPath) ) {
1270    
1271     # Try to create the user account directory if it does not exist
1272     if ( ! -d $main::UserAccountDirectoryPath ) {
1273    
1274     if ( mkdir($main::UserAccountDirectoryPath, 0700) ) {
1275    
1276     # Set the user account directory so that it can be accessed by ourselves only
1277     chmod(0700, $main::UserAccountDirectoryPath);
1278    
1279     }
1280     else {
1281    
1282     # The directory could not be created, so we inform the user of the fact
1283     &vHandleError("User Account Error", "Sorry, the account directory could not be created");
1284     $Status = 0;
1285     }
1286     }
1287    
1288    
1289     # Check that we can access user account directory
1290     if ( ! ((-r $main::UserAccountDirectoryPath) && (-w $main::UserAccountDirectoryPath) && (-x $main::UserAccountDirectoryPath)) ) {
1291    
1292     # The directory cannot be accessed, so we inform the user of the fact
1293     &vHandleError("User Account Error", "Sorry, the account directory could not be accessed");
1294     $Status = 0;
1295     }
1296     }
1297    
1298    
1299     return ($Status);
1300    
1301     }
1302    
1303    
1304    
1305    
1306     #--------------------------------------------------------------------------
1307     #
1308     # Function: sMakeSearchURL()
1309     #
1310     # Purpose: This function makes a search URL from the passed content hash.
1311     #
1312     # Called by:
1313     #
1314     # Parameters: %Content content hash
1315     #
1316     # Global Variables: none
1317     #
1318     # Returns: the URL search string, and an empty string if
1319     # nothing relevant is defined in the content
1320     #
1321     sub sMakeSearchURL {
1322    
1323     my (%Content) = @_;
1324    
1325     my ($SearchURL, $Value);
1326     my (@InternalFieldNames) = ('Any', 'Operator', 'Past', 'Since', 'Before', 'LastRunTime', 'Order', 'Max', 'Database');
1327    
1328    
1329     # Initialize the search URL
1330     $SearchURL = "";
1331    
1332    
1333     # Add the generic field names
1334     foreach $Value ( 1..100 ) {
1335    
1336     my ($FieldName) = "FieldName" . $Value;
1337     my ($FieldContent) = "FieldContent" . $Value;
1338    
1339     if ( defined($Content{$FieldName}) ) {
1340     $SearchURL .= "&$FieldName=" . &lEncodeURLData($Content{$FieldName});
1341     $SearchURL .= defined($Content{$FieldContent}) ? "&$FieldContent=" . &lEncodeURLData($Content{$FieldContent}) : "";
1342     }
1343     }
1344    
1345    
1346     # Add the internal search terms
1347     foreach $Value ( @InternalFieldNames ) {
1348     $SearchURL .= defined($Content{$Value}) ? "&$Value=" . join("&$Value=", &lEncodeURLData(split(/\0/, $Content{$Value}))) : "";
1349     }
1350    
1351    
1352     # Return the URL, choping out the initial '&'
1353     return (($SearchURL ne "") ? substr($SearchURL, 1) : "");
1354    
1355     }
1356    
1357    
1358    
1359    
1360    
1361     #--------------------------------------------------------------------------
1362     #
1363     # Function: sMakeDocumentURL()
1364     #
1365     # Purpose: This function makes a document URL from the passed content hash.
1366     #
1367     # Called by:
1368     #
1369     # Parameters: %Content content hash
1370     #
1371     # Global Variables: none
1372     #
1373     # Returns: the URL document string, and an empty string if
1374     # nothing relevant is defined in the content
1375     #
1376     sub sMakeDocumentURL {
1377    
1378     my (%Content) = @_;
1379    
1380     my ($DocumentURL);
1381    
1382    
1383     # Initialize the document URL
1384     $DocumentURL = "";
1385    
1386    
1387     # Add the document URLs
1388     if ( defined($Content{'Document'}) ) {
1389     $DocumentURL .= "&Document=" . join("&Document=", &lEncodeURLData(split(/\0/, $Content{'Document'})));
1390     }
1391    
1392    
1393     # Return the URL, choping out the initial '&'
1394     return (($DocumentURL ne "") ? substr($DocumentURL, 1) : "");
1395    
1396     }
1397    
1398    
1399    
1400    
1401    
1402     #--------------------------------------------------------------------------
1403     #
1404     # Function: sMakeRfDocumentURL()
1405     #
1406     # Purpose: This function makes an RF document URL from the passed content hash.
1407     #
1408     # Called by:
1409     #
1410     # Parameters: %Content content hash
1411     #
1412     # Global Variables: none
1413     #
1414     # Returns: the URL RF document string, and an empty string if
1415     # nothing relevant is defined in the content
1416     #
1417     sub sMakeRfDocumentURL {
1418    
1419     my (%Content) = @_;
1420    
1421     my ($RfDocumentURL);
1422    
1423    
1424     # Initialize the RF document URL
1425     $RfDocumentURL = "";
1426    
1427    
1428     # Add the RF document URLs
1429     if ( defined($Content{'RfDocument'}) ) {
1430     $RfDocumentURL .= "&RfDocument=" . join("&RfDocument=", &lEncodeURLData(split(/\0/, $Content{'RfDocument'})));
1431     }
1432    
1433    
1434     # Return the URL, choping out the initial '&'
1435     return (($RfDocumentURL ne "") ? substr($RfDocumentURL, 1) : "");
1436    
1437     }
1438    
1439    
1440    
1441    
1442    
1443     #--------------------------------------------------------------------------
1444     #
1445     # Function: sMakeSearchAndRfDocumentURL()
1446     #
1447     # Purpose: This function makes a URL string from the search
1448     # and RF document URLs
1449     #
1450     # Called by:
1451     #
1452     # Parameters: %Content content hash
1453     #
1454     # Global Variables: none
1455     #
1456     # Returns: the URL query string, and an empty string if
1457     # nothing relevant is defined in %Content
1458     #
1459     sub sMakeSearchAndRfDocumentURL {
1460    
1461     my (%Content) = @_;
1462    
1463     my ($SearchURL, $RfDocumentURL, $SearchRfDocumentURL);
1464    
1465    
1466     # Get the search URL and the RF document URL
1467     $SearchURL = &sMakeSearchURL(%Content);
1468     $RfDocumentURL = &sMakeRfDocumentURL(%Content);
1469    
1470    
1471     # Concatenate them intelligently
1472     $SearchRfDocumentURL = $SearchURL . ((($SearchURL ne "") && ($RfDocumentURL ne "")) ? "&" : "") . $RfDocumentURL;
1473    
1474    
1475     # Return the URL
1476     return ($SearchRfDocumentURL);
1477    
1478     }
1479    
1480    
1481    
1482    
1483     #--------------------------------------------------------------------------
1484     #
1485     # Function: sMakeSearchString()
1486     #
1487     # Purpose: This function makes a search string from the search
1488     # variables in the content hash
1489     #
1490     # Called by:
1491     #
1492     # Parameters: %Content content hash
1493     #
1494     # Global Variables: void
1495     #
1496     # Returns: the search string, and an empty string if
1497     # nothing relevant is defined in the content hash
1498     #
1499     sub sMakeSearchString {
1500    
1501     my (%Content) = @_;
1502    
1503     my ($SearchString);
1504     my ($FieldName, $Time, $Date);
1505     my ($Value);
1506    
1507    
1508     # Initialize the search string
1509     $SearchString = "";
1510    
1511    
1512     # Add the search terms
1513     $SearchString .= defined($Content{'Any'}) ? ((($SearchString ne "") ? " AND " : "") . $Content{'Any'}) : "";
1514    
1515    
1516     # Add the generic field names
1517     foreach $Value ( 1..100 ) {
1518    
1519     my ($FieldName) = "FieldName" . $Value;
1520     my ($FieldContent) = "FieldContent" . $Value;
1521    
1522    
1523     if ( defined($Content{$FieldName}) ) {
1524     $SearchString .= defined($Content{$FieldContent}) ?
1525     (($SearchString ne "") ? " AND " : "") . "$Content{$FieldName}=(" . $Content{$FieldContent} . ")" : "";
1526     }
1527     }
1528    
1529     # nuke accented chars
1530     $SearchString =~ tr/Çüéâäùæç³ëÕõî¬ÄÆÉÅåôö¥µ¦¶ÖÜ«»£èáíóú¡±®¾Êê¼ÈºÁÂ̪¯¿ÃãðÐÏËïÒÍÎìÞÙÓÔÑñò©¹ÀÚàÛýÝþ´­½²·¢¸¨ÿØø/CueaauccleOoiZACELlooLlSsOUTtLcaiouAaZzEezCsAAESZzAadDDEdNIIeTUOoNnnSsRUrUyYt'-".'',"'Rr/;
1531 dpavlin 1.11 # convert search string to lower case -> make search case insensitive
1532     $SearchString =~ tr/A-Z/a-z/;
1533 dpavlin 1.1
1534     # Add the internal search terms
1535    
1536    
1537     # Add the date restriction on the load time
1538     if ( defined($Content{'LastRunTime'}) && ($Content{'LastRunTime'} > 0) ) {
1539     $SearchString .= (($SearchString ne "") ? " AND " : "") . "time_t>=$Content{'LastRunTime'}";
1540     }
1541    
1542    
1543     # Add the Past date restriction
1544     if ( defined($Content{'Past'}) && ($Content{'Past'} ne "0") ) {
1545    
1546     $Time = time();
1547     if ( $Content{'Past'} eq "Day" ) {
1548     $Time = &tSubstractFromTime($Time, undef, undef, 1);
1549     }
1550     elsif ( $Content{'Past'} eq "Week" ) {
1551     $Time = &tSubstractFromTime($Time, undef, undef, 7);
1552     }
1553     elsif ( $Content{'Past'} eq "Month" ) {
1554     $Time = &tSubstractFromTime($Time, undef, 1, undef);
1555     }
1556     elsif ( $Content{'Past'} eq "3 Months" ) {
1557     $Time = &tSubstractFromTime($Time, undef, 3, undef);
1558     }
1559     elsif ( $Content{'Past'} eq "6 Months" ) {
1560     $Time = &tSubstractFromTime($Time, undef, 6, undef);
1561     }
1562     elsif ( $Content{'Past'} eq "9 Months" ) {
1563     $Time = &tSubstractFromTime($Time, undef, 9, undef);
1564     }
1565     elsif ( $Content{'Past'} eq "Year" ) {
1566     $Time = &tSubstractFromTime($Time, 1, undef undef);
1567     }
1568    
1569     # Create an ANSI format date/time field
1570     $Date = &sGetAnsiDateFromTime($Time);
1571     $SearchString .= " {DATE>=$Date}";
1572     }
1573    
1574    
1575     # Add the Since date restriction
1576     if ( defined($Content{'Since'}) && ($Content{'Since'} ne "0") ) {
1577     $SearchString .= " {DATE>=$Content{'Since'}0000}";
1578     }
1579    
1580    
1581     # Add the Before date restriction
1582     if ( defined($Content{'Before'}) && ($Content{'Before'} ne "0") ) {
1583     $SearchString .= " {DATE<$Content{'Before'}0000}";
1584     }
1585    
1586    
1587     # Add the document sort order
1588     $SearchString .= defined($Content{'Order'}) ? " {" . $Content{'Order'} . "}" : "";
1589    
1590     # Add the operator
1591     $SearchString .= defined($Content{'Operator'}) ? " {" . $Content{'Operator'} . "}" : "";
1592    
1593    
1594     return (($SearchString ne "") ? $SearchString : undef);
1595    
1596     }
1597    
1598    
1599    
1600    
1601    
1602     #--------------------------------------------------------------------------
1603     #
1604     # Function: hGetSearchStringHash()
1605     #
1606     # Purpose: This function makes a search string hash table from the search
1607     # variables in the content hash
1608     #
1609     # Called by:
1610     #
1611     # Parameters: %Content content hash
1612     #
1613     # Global Variables: void
1614     #
1615     # Returns: the search string hash table, and an empty string if
1616     # nothing relevant is defined in the content hash
1617     #
1618     sub hGetSearchStringHash {
1619    
1620     my (%Content) = @_;
1621    
1622     my ($Content);
1623     my (%Value, @Values, $Value);
1624    
1625    
1626     @Values = split(/ /, defined($Content{'Any'}) ? $Content{'Any'} : "");
1627     foreach $Value ( @Values ) { $Value = lc($Value); $Value{$Value} = $Value };
1628    
1629    
1630     # Add the generic field names
1631     foreach $Value ( 1..100 ) {
1632    
1633     my ($FieldName) = "FieldName" . $Value;
1634     my ($FieldContent) = "FieldContent" . $Value;
1635    
1636     if ( defined($Content{$FieldName}) ) {
1637     @Values = split(/ /, defined($Content{$FieldContent}) ? $Content{$FieldContent} : "");
1638     foreach $Value ( @Values ) { $Value = lc($Value); $Value{$Value} = $Value };
1639     }
1640     }
1641    
1642    
1643     return (%Value);
1644    
1645     }
1646    
1647    
1648    
1649    
1650    
1651     #--------------------------------------------------------------------------
1652     #
1653     # Function: hGetDocumentFolders()
1654     #
1655     # Purpose: This function returns a hash table of all the document folders
1656     #
1657     # Called by:
1658     #
1659     # Parameters: void
1660     #
1661     # Global Variables: void
1662     #
1663     # Returns: a hash table of document folders, the key being the folder name
1664     # and the content being the folder file name
1665     #
1666     sub hGetDocumentFolders {
1667    
1668     my (@DocumentFolderList, $DocumentFolderEntry, $HeaderName, $FolderName, %QualifiedDocumentFolders);
1669    
1670     # Read all the document folder files
1671     opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
1672     @DocumentFolderList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::DocumentFolderFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
1673     closedir(USER_ACCOUNT_DIRECTORY);
1674    
1675    
1676     # Loop over each document folder file checking that it is valid
1677     for $DocumentFolderEntry ( @DocumentFolderList ) {
1678    
1679     # Get the header name from the XML document folder file
1680     $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderEntry);
1681    
1682     # Check that the entry is valid and add it to the qualified list
1683     if ( defined($HeaderName) && ($HeaderName eq "DocumentFolder") ) {
1684     $FolderName = &sGetTagValueFromXMLFile($DocumentFolderEntry, "FolderName");
1685     $QualifiedDocumentFolders{$FolderName} = $DocumentFolderEntry;
1686     }
1687     else {
1688     # Else we delete this invalid document folder file
1689     unlink($DocumentFolderEntry);
1690     }
1691     }
1692    
1693    
1694     return (%QualifiedDocumentFolders);
1695    
1696     }
1697    
1698    
1699    
1700    
1701    
1702     #--------------------------------------------------------------------------
1703     #
1704     # Function: iSaveSearchHistory()
1705     #
1706     # Purpose: This function saves the passed search to a new
1707     # search history XML file.
1708     #
1709     # Called by:
1710     #
1711     # Parameters: $FileName search history file name ('undef' means create a new file name)
1712     # $SearchAndRfDocumentURL search and RF document URL
1713     # $SearchResults search results
1714     # $QueryReport query report
1715     #
1716     # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1717     # $main::SearchHistoryFileNamePrefix
1718     #
1719     # Returns: 0 on error, 1 on success
1720     #
1721     sub iSaveSearchHistory {
1722    
1723     my ($FileName, $SearchAndRfDocumentURL, $SearchResults, $QueryReport) = @_;
1724     my ($SearchHistoryFilePath, %Value);
1725     my ($AnsiDateTime);
1726    
1727    
1728     # Return an error if the user account directory is not defined
1729     if ( !(defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
1730     return (0);
1731     }
1732    
1733     # Create a file name if one was not passed
1734     if ( !defined($FileName) ) {
1735     $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1736     $SearchHistoryFilePath = $main::UserAccountDirectoryPath . "/". $main::SearchHistoryFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1737     }
1738     else {
1739     $SearchHistoryFilePath = $FileName;
1740     }
1741    
1742    
1743     # Set the hash from the history information
1744     undef(%Value);
1745     $Value{'CreationTime'} = time();
1746     $Value{'SearchAndRfDocumentURL'} = $SearchAndRfDocumentURL;
1747     $Value{'QueryReport'} = $QueryReport;
1748     $Value{'SearchResults'} = $SearchResults;
1749    
1750    
1751     # Save the search information
1752     if ( ! &iSaveXMLFileFromHash($SearchHistoryFilePath, "SearchHistory", %Value) ) {
1753     # Failed to save the information, so we return an error
1754     return (0);
1755     }
1756    
1757     return (1);
1758    
1759     }
1760    
1761    
1762    
1763    
1764    
1765     #--------------------------------------------------------------------------
1766     #
1767     # Function: iSaveSearch()
1768     #
1769     # Purpose: This function saves the passed search to a new
1770     # search XML file.
1771     #
1772     # Called by:
1773     #
1774     # Parameters: $FileName saved search file name ('undef' means create a new file name)
1775     # $SearchName search name
1776     # $SearchDescription search description
1777     # $SearchAndRfDocumentURL search and RF document URL
1778     # $SearchFrequency search frequency
1779     # $DeliveryFormat delivery format
1780     # $DeliveryMethod delivery method
1781     # $SearchStatus search status
1782     # $CreationTime creation time
1783     # $LastRunTime last run time
1784     #
1785     # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1786     # $main::SavedSearchFileNamePrefix
1787     #
1788     # Returns: 0 on error, 1 on success
1789     #
1790     sub iSaveSearch {
1791    
1792     my ($FileName, $SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $LastRunTime) = @_;
1793     my ($SavedSearchFilePath, %Value);
1794     my ($AnsiDateTime);
1795    
1796    
1797     # Return an error if the user account directory is not defined
1798     if ( !(defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
1799     return (0);
1800     }
1801    
1802     # Create a file name if one was not passed
1803     if ( !defined($FileName) ) {
1804     $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1805     $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/". $main::SavedSearchFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1806     }
1807     else {
1808     $SavedSearchFilePath = $FileName;
1809     }
1810    
1811    
1812    
1813     # Set the hash from the search information
1814     undef(%Value);
1815     $Value{'SearchName'} = $SearchName;
1816     $Value{'SearchDescription'} = $SearchDescription;
1817     $Value{'SearchAndRfDocumentURL'} = $SearchAndRfDocumentURL;
1818     $Value{'SearchFrequency'} = $SearchFrequency;
1819     $Value{'DeliveryFormat'} = $DeliveryFormat;
1820     $Value{'DeliveryMethod'} = $DeliveryMethod;
1821     $Value{'SearchStatus'} = $SearchStatus;
1822     $Value{'CreationTime'} = $CreationTime;
1823     $Value{'LastRunTime'} = $LastRunTime;
1824    
1825    
1826     # Save the search information
1827     if ( ! &iSaveXMLFileFromHash($SavedSearchFilePath, "SavedSearch", %Value) ) {
1828     # Failed to save the information, so we return an error
1829     return (0);
1830     }
1831    
1832     return (1);
1833    
1834     }
1835    
1836    
1837    
1838    
1839    
1840     #--------------------------------------------------------------------------
1841     #
1842     # Function: iSaveFolder()
1843     #
1844     # Purpose: This function saves the passed folder to a new
1845     # document folder XML file.
1846     #
1847     # Called by:
1848     #
1849     # Parameters: $FileName document folder file name ('undef' means create a new file name)
1850     # $FolderName folder name
1851     # $FolderDescription folder description
1852     # $FolderDocuments folder document
1853     # $CreationTime creation time
1854     # $UpdateTime update time
1855     #
1856     # Global Variables: $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
1857     # $main::DocumentFolderFileNamePrefix
1858     #
1859     # Returns: 0 on error, 1 on success
1860     #
1861     sub iSaveFolder {
1862    
1863     my ($FileName, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) = @_;
1864     my ($DocumentFolderFilePath, %Value);
1865     my ($AnsiDateTime);
1866    
1867    
1868     # Return an error if the user account directory is not defined
1869     if ( !defined($main::RemoteUser) || !defined($main::UserAccountDirectoryPath) ) {
1870     return (0);
1871     }
1872    
1873     # Create a file name if one was not passed
1874     if ( !defined($FileName) ) {
1875     $AnsiDateTime = &sGetAnsiDateFromTime() . &sGetAnsiTimeFromTime();
1876     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/". $main::DocumentFolderFileNamePrefix . "-" . $AnsiDateTime . $main::XMLFileNameExtension;
1877     }
1878     else {
1879     $DocumentFolderFilePath = $FileName;
1880     }
1881    
1882    
1883    
1884     # Set the hash from the folder information
1885     undef(%Value);
1886     $Value{'FolderName'} = $FolderName;
1887     $Value{'FolderDescription'} = $FolderDescription;
1888     $Value{'FolderDocuments'} = $FolderDocuments;
1889     $Value{'CreationTime'} = $CreationTime;
1890     $Value{'UpdateTime'} = $UpdateTime;
1891    
1892    
1893     # Save the document folder information
1894     if ( ! &iSaveXMLFileFromHash($DocumentFolderFilePath, "DocumentFolder", %Value) ) {
1895     # Failed to save the information, so we return an error
1896     return (0);
1897     }
1898    
1899     return (1);
1900    
1901     }
1902    
1903    
1904    
1905    
1906    
1907     #--------------------------------------------------------------------------
1908     #
1909     # Function: bDisplayDocuments()
1910     #
1911     # Purpose: This function displays the document
1912     #
1913     # Called by:
1914     #
1915     # Parameters: $Title title
1916     # $Documents \0 separated document URL
1917     # $FieldName field name
1918     # $Selector true to display selector
1919     # $Selected selector is selected
1920     # $HTML true to display HTML
1921     #
1922     #
1923     # Global Variables: void
1924     #
1925     # Returns: the status
1926     #
1927     sub bDisplayDocuments {
1928    
1929     my ($Title, $Documents, $FieldName, $Selector, $Selected, $HTML) = @_;
1930    
1931     my (@Documents, $Document, $Status, $DocumentInfo, $SelectorText, $SelectedText, $LinkText);
1932     my ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder);
1933     my (%Value, $Value, @Values);
1934    
1935    
1936     # Check input parameters
1937     if ( !defined($Documents) ) {
1938     return (0);
1939     }
1940    
1941    
1942     # Split the documents text into a documents list
1943     @Documents = split(/\0/, $Documents);
1944    
1945    
1946     # Set the field name
1947     $FieldName = (defined($FieldName ) && ($FieldName ne "")) ? $FieldName : "Document";
1948    
1949     # Set the selected text
1950     $SelectedText = ((defined($Selector) && $Selector) && (defined($Selected) && $Selected)) ? "CHECKED" : "";
1951    
1952    
1953     # Print the title
1954     if ( $HTML ) {
1955     printf("<TD ALIGN=LEFT VALIGN=TOP>%s%s:</TD><TD ALIGN=LEFT VALIGN=TOP>\n",
1956     defined($Title) ? $Title : "Document", (scalar(@Documents) > 1) ? "s" : "");
1957     }
1958     else {
1959     printf("%s%s:\n", defined($Title) ? $Title : "Document", (scalar(@Documents) > 1) ? "s" : "");
1960     }
1961    
1962    
1963     # Loop over each entry in the documents list
1964     foreach $Document ( @Documents ) {
1965    
1966     # Parse out the document entry
1967     %Value = &hParseURLIntoHashTable($Document);
1968    
1969     # Get the document information
1970     ($Status, $DocumentInfo) = MPS::GetDocumentInfo($main::MPSSession, $Value{'Database'}, $Value{'DocumentID'});
1971    
1972     if ( $Status ) {
1973     ($Headline, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $DocumentInfo, 8);
1974    
1975     # Decode the headline and strip the HTML
1976     $Headline = &lDecodeURLData($Headline);
1977     $Headline =~ s/&nbsp;//gs;
1978     $Headline =~ s/<.*?>//gs;
1979     $Headline =~ s/\s+/ /gs;
1980    
1981     # Create a generic link for this document
1982     $Value = "";
1983     $Value .= (defined($Value{'Database'}) && ($Value{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Value{'Database'}) : "";
1984     $Value .= (defined($Value{'DocumentID'}) && ($Value{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Value{'DocumentID'}) : "";
1985     $Value .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
1986     $Value .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
1987    
1988    
1989     # Create the selector text
1990     if ( defined($Selector) && $Selector ) {
1991     $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"$FieldName\" VALUE=\"" . substr($Value, 1) . "\" $SelectedText> ";
1992     }
1993     else {
1994     $SelectorText = " - ";
1995     }
1996    
1997     # Create the link text, we use the URL if it is there
1998     if ( defined($URL) && ($URL ne "") ) {
1999     $LinkText = $URL;
2000     }
2001     elsif ( defined($Value{'DocumentID'}) && ($Value{'DocumentID'} ne "") ) {
2002     $LinkText = "$ENV{'SCRIPT_NAME'}/GetDocument?" . substr($Value, 1);
2003     }
2004     else {
2005     $LinkText = "";
2006     }
2007    
2008     # Put up the headline and the score, this one links to the document
2009     if ( $HTML ) {
2010     print("$SelectorText <A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $Headline <I> ( $main::DatabaseDescriptions{$Value{'Database'}} ) </I> </A> <BR>\n");
2011    
2012     # if ( defined($URL) && ($URL ne "") ) {
2013     # $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2014     # print("<FONT SIZE=-2><A HREF=\"$URL\"> $Value </A></FONT><BR>\n");
2015     # }
2016     }
2017     else {
2018     print("- $Headline ($main::DatabaseDescriptions{$Value{'Database'}})\n URL: $LinkText\n");
2019     }
2020     }
2021     }
2022    
2023     if ( $HTML ) {
2024     print("</TD>\n");
2025     }
2026    
2027    
2028     return (1);
2029    
2030     }
2031    
2032    
2033    
2034    
2035    
2036    
2037     #--------------------------------------------------------------------------
2038     #
2039     # Function: bsDisplaySearchResults()
2040     #
2041     # Purpose: This function displays the search results
2042     #
2043     # Called by:
2044     #
2045     # Parameters: $Title title
2046     # $SearchResults search results
2047     # $SearchDate search date
2048     # $SearchFrequency search frequency
2049     # $SearchDescription search description
2050     # $QueryReport query report
2051     # $ScriptName script name
2052     # $Header true to display header
2053     # $Selector true to display selector
2054     # $HTML true to display HTML
2055     # %Content content hash table
2056     #
2057     #
2058     # Global Variables: %main::ConfigurationData, $main::RemoteUser,
2059     # $main::QueryReportItemName, $main::QueryReportMimeType
2060     #
2061     # Returns: the status and a the query report
2062     #
2063     sub bsDisplaySearchResults {
2064    
2065     my ($Title, $SearchDescription, $SearchDate, $SearchFrequency, $SearchResults, $QueryReport, $ScriptName, $Header, $Selector, $HTML, %Content) = @_;
2066    
2067     my ($SearchString, $SummaryType, $SummaryLength, @SearchResults, $SearchResult, $FinalQueryReport, $ResultCount, %SearchStringHash);
2068     my ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder);
2069     my ($Status, $Text, $MimeTypeName, $SummaryText, $SelectorText, $LinkText, $RuleFlag, $LastItemName);
2070     my (@DocumentFolderList, %QualifiedDocumentFolders, $DocumentFolderEntry, $HeaderName, $FolderName, $Index);
2071     my (@Words, $Word, @OffsetPairs, $OffsetPair, %Offsets, $Offset, $Start, $End, $OldStart, $OldEnd, $CurrentSummaryLength);
2072     my ($DatabaseSummaryFilterKey, $DatabaseSummaryFilterFunction);
2073     my ($Value, %Value, @Values, $ValueEntry);
2074 dpavlin 1.9
2075    
2076 dpavlin 1.1 # Check input parameters
2077     if ( !defined($SearchResults) || !%Content ) {
2078     return (0);
2079     }
2080    
2081     # Split the search results text into a search results list
2082     @SearchResults = split(/\n/, $SearchResults);
2083    
2084    
2085     # First we count up the number of results and scoop up
2086     # any query reports if we need to
2087    
2088     # Initialize the final query report
2089     if ( !defined($QueryReport) ) {
2090     $FinalQueryReport = "";
2091     }
2092     else {
2093     $FinalQueryReport = $QueryReport;
2094     }
2095    
2096    
2097     # Loop over each entry in the search results list
2098     $ResultCount = 0;
2099     foreach $SearchResult ( @SearchResults ) {
2100    
2101     # Parse the headline, also get the first document item/type
2102     ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2103    
2104     # Is this a query report
2105     if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2106    
2107     # Retrieve the query report if it was not passed to us
2108     if ( !defined($QueryReport) ) {
2109     ($Status, $Text) = MPS::GetDocument($main::MPSSession, $Database, $DocumentID, $ItemName, $MimeType);
2110    
2111     if ( $Status ) {
2112     # Concatenate it to the query report text we have already got
2113     $FinalQueryReport .= $Text;
2114     }
2115     }
2116     }
2117     else {
2118     # Increment the result count
2119     $ResultCount++;
2120     }
2121     }
2122    
2123    
2124    
2125    
2126     # Finally, we get information we are going to need later on
2127    
2128     # Get the search string
2129     $SearchString = &sMakeSearchString(%Content);
2130     if ( defined($SearchString) ) {
2131     $SearchString =~ s/{.*?}//gs;
2132     $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
2133     }
2134     $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
2135    
2136     # Get the search string hash
2137     %SearchStringHash = &hGetSearchStringHash(%Content);
2138    
2139     # Do some very basic plural stemming
2140     foreach $Value ( keys (%SearchStringHash) ) {
2141     $Value =~ s/ies\Z/y/g;
2142     $Value =~ s/s\Z//g;
2143     $SearchStringHash{$Value} = $Value;
2144     }
2145    
2146    
2147    
2148     # Get the summary information
2149     if ( defined($main::RemoteUser) ) {
2150    
2151     $SummaryType = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SummaryType");
2152     $SummaryLength = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SummaryLength");
2153    
2154     if ( !(defined($SummaryLength) && ($SummaryLength ne "")) ) {
2155     $SummaryLength = $main::DefaultSummaryLength;
2156     }
2157     if ( !(defined($SummaryType) && ($SummaryType ne "")) ) {
2158     $SummaryType = $main::DefaultSummaryType;
2159     }
2160     }
2161     else {
2162     $SummaryType = $main::DefaultSummaryType;
2163     $SummaryLength = $main::DefaultSummaryLength;
2164     }
2165    
2166    
2167     # Print the header if needed
2168     if ( $Header ) {
2169    
2170     if ( $HTML ) {
2171     # Print the title and the start of the form
2172     printf("<H3>%s</H3>\n", defined($Title) ? $Title : "Rezultati pretra¾ivanja:");
2173    
2174     # Start the form
2175     print("<FORM ACTION=\"$ScriptName\" METHOD=POST>\n");
2176    
2177    
2178     # List the hidden fields
2179     %Value = &hParseURLIntoHashTable(&sMakeSearchURL(%Content));
2180     foreach $Value ( keys(%Value) ) {
2181     foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
2182     print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
2183     }
2184     }
2185    
2186    
2187     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2188    
2189     # Print the selector
2190     print("<TR><TD ALIGN=LEFT VALIGN=TOP>Odabranima se smatraju svi rezultati ukoliko niste uèinili nikakav dodatan odabir.</TD><TD ALIGN=RIGHT VALIGN=TOP> \n");
2191    
2192     if ( $ResultCount > 0 ) {
2193    
2194     if ( defined($main::RemoteUser) ) {
2195     print("<SELECT NAME=\"Action\">\n");
2196    
2197     print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
2198     if
2199     ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
2200     print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
2201     }
2202     if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
2203     print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
2204     }
2205     print("<OPTION VALUE=\"GetSaveSearch\">Saèuvaj rezultate pretra¾ivanja\n");
2206     print("<OPTION VALUE=\"GetSaveFolder\">Saèuvaj odabrane rezultate u novi folder\n");
2207    
2208     # Get the document folder hash
2209     %QualifiedDocumentFolders = &hGetDocumentFolders;
2210    
2211     for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
2212    
2213     $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
2214    
2215     # Get the document folder file name and encode it
2216     $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
2217     $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
2218    
2219     print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry\">Dodaj odabrane rezultate u '$FolderName' folder\n");
2220     }
2221     print("</SELECT>\n");
2222     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
2223     }
2224     else {
2225     print("<SELECT NAME=\"Action\">\n");
2226     print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
2227     if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
2228     print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
2229     }
2230     if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
2231     print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
2232     }
2233     print("</SELECT>\n");
2234     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
2235     }
2236     }
2237     else {
2238     if ( defined($main::RemoteUser) ) {
2239     print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSaveSearch\">\n");
2240     print("<INPUT TYPE=SUBMIT VALUE=\"Save this search\">\n");
2241     }
2242     }
2243    
2244     print("</TD></TR>\n");
2245     print("</TABLE>\n");
2246     }
2247     else {
2248     printf("%s\n", defined($Title) ? $Title : "Rezultati pretra¾ivanja:");
2249     }
2250    
2251    
2252     # Display the search string
2253     if ( $HTML ) {
2254     print("<CENTER><HR WIDTH=50%></CENTER>\n");
2255     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2256     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
2257     }
2258     else {
2259     print("--------------------------------------------------------------\n");
2260     print(" - Search for : $SearchString\n");
2261     }
2262    
2263    
2264     # Display the description
2265     if ( defined($SearchDescription) ) {
2266     if ( $HTML ) {
2267     $SearchDescription =~ s/\n/<BR>/g;
2268     $SearchDescription =~ s/\r/<BR>/g;
2269     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDescription </TD></TR>\n");
2270     }
2271     else {
2272     print(" - Description : $SearchDescription\n");
2273     }
2274     }
2275    
2276     # Display the date
2277     if ( defined($SearchDate) ) {
2278     if ( $HTML ) {
2279     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Run on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDate </TD></TR>\n");
2280     }
2281     else {
2282     print(" - Run on : $SearchDate\n");
2283     }
2284     }
2285    
2286     # Display the frequency
2287     if ( defined($SearchFrequency) ) {
2288     if ( $HTML ) {
2289     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchFrequency </TD></TR>\n");
2290     }
2291     else {
2292     print(" - Frequency : $SearchFrequency\n");
2293     }
2294     }
2295    
2296    
2297    
2298     # Get the databases from the search and list their descriptions
2299     if ( defined($Content{'Database'}) ) {
2300    
2301     # Initialize the temp list
2302     undef(@Values);
2303    
2304     # Loop over each database
2305     foreach $Database ( split(/\0/, $Content{'Database'}) ) {
2306     $Value = &lEncodeURLData($Database);
2307     if ( $HTML ) {
2308     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> ");
2309     }
2310     else {
2311     push @Values, sprintf("$main::DatabaseDescriptions{$Database} ");
2312     }
2313     }
2314    
2315     # Print the list if there are any entries in it
2316     if ( scalar(@Values) > 0 ) {
2317     if ( $HTML ) {
2318     printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n",
2319     (scalar(@Values) > 1) ? "s" : "", join(", ", @Values));
2320     }
2321     else {
2322     printf(" - Database%s : %s\n", (scalar(@Values) > 1) ? "s" : " ", join(", ", @Values));
2323     }
2324     }
2325     }
2326    
2327    
2328     # Display any feedback documents
2329     if ( defined($Content{'RfDocument'}) ) {
2330     if ( $HTML ) {
2331     print("<TR>\n");
2332     }
2333     &bDisplayDocuments("Feedback Document", $Content{'RfDocument'}, "RfDocument", 1, 1, $HTML);
2334     if ( $HTML ) {
2335     print("</TR>\n");
2336     }
2337     }
2338    
2339    
2340     if ( $HTML ) {
2341     printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Pronaðeno: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s rezultata (Maksimalni broj pode¹en na: $Content{'Max'} ) </TD></TR>\n",
2342     ($ResultCount > 0) ? $ResultCount : "no");
2343    
2344     print("</TABLE>\n");
2345     print("<CENTER><HR WIDTH=50%></CENTER>\n");
2346     }
2347     else {
2348     printf(" - Results : %s\n", ($ResultCount > 0) ? $ResultCount : "no");
2349     print("--------------------------------------------------------------\n\n");
2350     }
2351     }
2352    
2353    
2354     # Start the table
2355     if ( $HTML ) {
2356     print("<!-- searchResults -->\n");
2357     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2358    
2359     # Display a button to select all the documents
2360     if ( $ResultCount > 0 ) {
2361    
2362     if ( defined($Selector) && $Selector ) {
2363    
2364     $SelectorText = "";
2365    
2366     # Loop over each entry in the hits list
2367     foreach $SearchResult ( @SearchResults ) {
2368    
2369     # Parse the headline, also get the first document item/type
2370     ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2371    
2372     # Skip query reports
2373     if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2374     next;
2375     }
2376    
2377     $Value = "";
2378     $Value .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2379     $Value .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2380     $Value .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2381     $Value .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2382     $SelectorText .= (($SelectorText ne "") ? "|" : "") . substr($Value, 1);
2383     }
2384    
2385     $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
2386     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> $SelectorText </TD></TR>\n");
2387     }
2388     }
2389     }
2390    
2391    
2392 dpavlin 1.9 ### FIX:: ADD SORT HERE
2393 dpavlin 1.1 if ( $ResultCount > 0 ) {
2394    
2395     # Loop over each entry in the hits list
2396     foreach $SearchResult ( @SearchResults ) {
2397    
2398     # Parse the headline, also get the first document item/type
2399     ($Database, $Headline, $Score, $DocumentID, $Date, $Time, $ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $SearchResult, 11);
2400    
2401     # Skip query reports
2402     if ( ($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType) ) {
2403     next;
2404     }
2405    
2406    
2407     # Put a separator between each entry
2408     if ( defined($Remainder) ) {
2409    
2410     if ( defined($RuleFlag) && ($RuleFlag) ) {
2411     if ( $HTML ) {
2412     print("<TR><TD COLSPAN=3><HR WIDTH=25%></TD></TR>\n");
2413     }
2414     else {
2415     print("--------------------------------------------------------------\n\n");
2416     }
2417     }
2418    
2419     $RuleFlag = 1;
2420     }
2421    
2422    
2423     # Get the summary if needed
2424     if ( defined($main::ConfigurationData{'allow-summary-displays'}) && ($main::ConfigurationData{'allow-summary-displays'} eq "yes") &&
2425     ($SummaryType ne "none") ) {
2426    
2427     ($Status, $Text) = MPS::GetDocument($main::MPSSession, $Database, $DocumentID, $ItemName, $MimeType);
2428    
2429     if ( $Status ) {
2430    
2431     # Then process for each summary type
2432     if ( $SummaryType eq "default" ) {
2433    
2434     $DatabaseSummaryFilterKey = "$main::DatabaseSummaryFilter:$Database:$ItemName:$MimeType";
2435    
2436     # Is a filter defined for this database summary filter key ?
2437     if ( defined($main::DatabaseFilters{$DatabaseSummaryFilterKey}) ) {
2438    
2439     # Pull in the package
2440     require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Database"};
2441    
2442     # Filter the document
2443     $Value = $main::DatabaseFilters{$DatabaseSummaryFilterKey};
2444     $DatabaseSummaryFilterFunction = \&$Value;
2445     $Text = $DatabaseSummaryFilterFunction->($Database, $DocumentID, $ItemName, $MimeType, $Text);
2446    
2447     }
2448    
2449     # Truncate the summary to the length requested
2450     if ( defined ($Text) && ($Text ne "") ) {
2451    
2452     $CurrentSummaryLength = 0;
2453     $SummaryText = "";
2454    
2455     # Split the document text
2456     @Words = split(/(\W)/, $Text);
2457    
2458     # Loop over each word
2459     foreach $Offset ( 0..scalar(@Words) ) {
2460    
2461     # Skip undefined words
2462     if ( !defined($Words[$Offset]) ) {
2463     next;
2464     }
2465    
2466     # Increment and check the summary length
2467     if ( $Words[$Offset] ne " " ) {
2468    
2469     $CurrentSummaryLength++;
2470    
2471     if ( $CurrentSummaryLength > $SummaryLength ) {
2472     # Append a diaresys at the end and bail
2473     $SummaryText .= "...";
2474     last;
2475     }
2476     }
2477    
2478     # Append the current word to the end of the summary
2479     $SummaryText .= $Words[$Offset];
2480     }
2481     }
2482     else {
2483     $SummaryText = "(Document summary unavailable)";
2484     }
2485     }
2486     elsif ( $SummaryType eq "keyword" ) {
2487    
2488     # First clean up the text
2489     if ( index($Text, "\r\n") >= 0 ) {
2490     $Text =~ s/\r//gs;
2491     }
2492     elsif ( index($Text, "\r") >= 0 ) {
2493     $Text =~ s/\r/\n/gs;
2494     }
2495     if ( defined($main::HtmlMimeTypes{$MimeType}) ) {
2496     if ( ($Index = index($Text, "\n\n")) >= 0 ) {
2497     $Text = substr($Text, $Index);
2498     }
2499     $Text =~ s/&nbsp;//gs;
2500     $Text =~ s/<.*?>//gs;
2501     }
2502     $Text =~ s/\n/ /gs;
2503     $Text =~ s/\s+/ /gs;
2504     $Text = ucfirst($Text);
2505    
2506     # Initialize our variables
2507     $OldStart = -1;
2508     $OldEnd = -1;
2509    
2510     $Start = -1;
2511     $End = -1;
2512    
2513     $CurrentSummaryLength = 0;
2514    
2515     # Reset the offset pairs and offsets
2516     undef(@OffsetPairs);
2517     undef(%Offsets);
2518    
2519    
2520     # Split the document text
2521     @Words = split(/(\W)/, $Text);
2522    
2523    
2524     # Loop over each word, checking to see if it is in the search string hash table
2525     # and build the offset list as we go along, check with the previous offset to see
2526     # if there is an overlap
2527     foreach $Offset ( 0..scalar(@Words) ) {
2528    
2529     if ( !defined($Words[$Offset]) ) {
2530     next;
2531     }
2532    
2533     # Downcase the word
2534     $Word = lc($Words[$Offset]);
2535    
2536     # Very basic plural stemming
2537     $Word =~ s/ies\Z/y/g;
2538     $Word =~ s/s\Z//g;
2539    
2540     if ( !defined($SearchStringHash{$Word}) ) {
2541     next;
2542     }
2543    
2544     $Start = ($Offset < $main::SummaryKeywordSpan) ? 0 : $Offset - $main::SummaryKeywordSpan;
2545     $End = (($Offset + $main::SummaryKeywordSpan) > (scalar(@Words) - 1)) ? (scalar(@Words) - 1) : $Offset + $main::SummaryKeywordSpan;
2546    
2547     if ( @OffsetPairs ) {
2548     ($OldStart, $OldEnd) = split(/,/, $OffsetPairs[scalar(@OffsetPairs) - 1]);
2549     }
2550    
2551     if ( $OldEnd >= $Start ) {
2552     $OffsetPairs[scalar(@OffsetPairs) - 1] = "$OldStart,$End";
2553     }
2554     else {
2555     push @OffsetPairs, "$Start,$End";
2556     }
2557     $Offsets{$Offset} = $Offset;
2558     }
2559    
2560    
2561     # Now we rebuild the sentence from the words
2562     $SummaryText = "";
2563     foreach $OffsetPair ( @OffsetPairs ) {
2564    
2565     ($Start, $End) = split(/,/, $OffsetPair);
2566    
2567     if ( $Start > 0 ) {
2568     $SummaryText .= " ...";
2569     }
2570    
2571     foreach $Offset ( $Start..$End ) {
2572    
2573     if ( !defined($Words[$Offset]) ) {
2574     next;
2575     }
2576    
2577     if ( defined($Offsets{$Offset}) ) {
2578     $SummaryText .= "<FONT COLOR=\"GREEN\">$Words[$Offset]</FONT> ";
2579     }
2580     else {
2581     $SummaryText .= $Words[$Offset] . " ";
2582     }
2583    
2584     # Increment the summary length
2585     $CurrentSummaryLength++;
2586     }
2587    
2588     # Append a diaresys at the end
2589     if ( $End < scalar(@Words) ) {
2590     $SummaryText .= "... ";
2591     }
2592    
2593     # Bail if we have reached the max summary length
2594     if ( $CurrentSummaryLength > $SummaryLength ) {
2595     last;
2596     }
2597     }
2598     }
2599     }
2600     else {
2601     undef($SummaryText);
2602     }
2603     }
2604    
2605    
2606     # Decode the headline and strip the HTML
2607     $Headline = &lDecodeURLData($Headline);
2608     $Headline =~ s/&nbsp;//gs;
2609     $Headline =~ s/<.*?>//gs;
2610     $Headline =~ s/\s+/ /gs;
2611    
2612    
2613     # Create the selector text
2614     $SelectorText = "";
2615     if ( defined($Selector) && $Selector ) {
2616     $SelectorText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2617     $SelectorText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2618     $SelectorText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2619     $SelectorText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2620     $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"Document\" VALUE=\"" . substr($SelectorText, 1) . "\"> ";
2621     }
2622    
2623    
2624     # Put up the headline, the headline becomes the link to the document
2625    
2626     # Create the link, we use the URL if it is there,
2627     # otherwise we create a link from the document ID
2628     if ( defined($URL) && ($URL ne "") ) {
2629     $LinkText = $URL;
2630     }
2631     elsif ( defined($DocumentID) && ($DocumentID ne "") ) {
2632     $LinkText = "";
2633     $LinkText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2634     $LinkText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2635     $LinkText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2636     $LinkText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2637     $LinkText = "$ScriptName/GetDocument?" . substr($LinkText, 1);
2638     }
2639     else {
2640     $LinkText = "";
2641     }
2642    
2643     # Get the mime type name
2644     $MimeTypeName = (defined($main::MimeTypeNames{$MimeType})) ? $main::MimeTypeNames{$MimeType} : $MimeType;
2645    
2646     # Put up the headline and the score, this one links to the document
2647     if ( $HTML ) {
2648     print("<!-- resultItem -->\n");
2649 dpavlin 1.5 #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>");
2650 dpavlin 1.8 # decode some basic html from headline <b> <i>
2651     $Headline =~ s/&lt;(\/?[bi])&gt;/<$1>/g;
2652    
2653 dpavlin 1.5 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;");
2654     } else {
2655 dpavlin 1.1 printf("%3d $Headline ($main::DatabaseDescriptions{$Database})\n", $Score);
2656     }
2657    
2658 dpavlin 1.5 if (0) { ## don't display description
2659 dpavlin 1.1
2660     # Put up the summary
2661     if ( defined($SummaryText) && ($SummaryText ne "") ) {
2662     if ( $HTML ) {
2663     print(" <I> $SummaryText </I><BR>\n");
2664     }
2665     else {
2666     print(" $SummaryText\n");
2667     }
2668     }
2669    
2670    
2671     # Put up the mime type name
2672     if ( ! defined($Remainder) ) {
2673     if ( $HTML ) {
2674     print("Formatttt: $MimeTypeName, ");
2675 dpavlin 1.5
2676 dpavlin 1.1 }
2677     else {
2678     print(" Format: $MimeTypeName, ");
2679     }
2680     }
2681    
2682    
2683     # Put up the date if we got it
2684 dpavlin 1.5 if ( defined($Date) && ($Date ne "") ) {
2685 dpavlin 1.1 print("Date: $Date");
2686    
2687     # Put up the time if we got it
2688 dpavlin 1.5 if ( defined($Time) && ($Time ne "") ) {
2689 dpavlin 1.1 print(" $Time");
2690     }
2691    
2692     print(", ");
2693     }
2694    
2695    
2696     # Put up the document size, remember that there is only one
2697     # item name/mime type for this document if the remainder is undefined
2698     if ( ! defined($Remainder) ) {
2699     # Put up the length if it is defined
2700     if ( defined($Length) && ($Length ne "") ) {
2701     print("Size: $Length, ");
2702     }
2703    
2704     # Put up the link
2705     if ( $HTML ) {
2706     if ( defined($URL) && ($URL ne "") ) {
2707     $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2708     print("<A HREF=\"$URL\"> $Value </A>\n");
2709     }
2710     }
2711     else {
2712     print(" URL: $LinkText\n");
2713     }
2714    
2715     # Finish off the entry
2716     if ( $HTML ) {
2717     print("</FONT></TD></TR>");
2718     print("<!-- /resultItem -->\n");
2719     }
2720     print("\n");
2721     }
2722     else {
2723    
2724     # There is a remainder, so there is more than one item name/mime type for this document,
2725     # the item names/mime types are listed as an un-numbered list
2726     if ( $HTML ) {
2727     print("<UL>");
2728     }
2729     print("\n");
2730    
2731     # Set the last item to an empty string, this is also used as a flag
2732     $LastItemName = "";
2733    
2734     # Loop while there are item names/mime types to be parsed
2735     do {
2736    
2737     # Get the next item name/mime type if the last item is set
2738     if ( $LastItemName ne "" ) {
2739     ($ItemName, $MimeType, $URL, $Length, $Remainder) = split(/\t/, $Remainder, 5);
2740     }
2741    
2742    
2743     # If the item name has changed, so we close of the current list and start a new one
2744     if ( $ItemName ne $LastItemName ) {
2745     if ( $LastItemName ne "" ) {
2746     if ( $HTML ) {
2747     print("</UL>");
2748     }
2749     print("\n");
2750     }
2751     $Value = ucfirst($ItemName);
2752     if ( $HTML ) {
2753     print("<LI> $Value </LI>\n<UL>\n");
2754     }
2755     else {
2756     print("$Value\n");
2757     }
2758    
2759     # Set the last item name
2760     $LastItemName = $ItemName;
2761     }
2762    
2763    
2764     # Create the link, we use the URL if it is there,
2765     # otherwise we create a link from the document ID
2766     if ( defined($URL) && ($URL ne "") ) {
2767     $LinkText = $URL;
2768     }
2769     elsif ( defined($DocumentID) && ($DocumentID ne "") ) {
2770     $LinkText = "";
2771     $LinkText .= (defined($Database) && ($Database ne "")) ? "&Database=" . &lEncodeURLData($Database) : "";
2772     $LinkText .= (defined($DocumentID) && ($DocumentID ne "")) ? "&DocumentID=" . &lEncodeURLData($DocumentID) : "";
2773     $LinkText .= (defined($ItemName) && ($ItemName ne "")) ? "&ItemName=" . &lEncodeURLData($ItemName) : "";
2774     $LinkText .= (defined($MimeType) && ($MimeType ne "")) ? "&MimeType=" . &lEncodeURLData($MimeType) : "";
2775     $LinkText = "$ScriptName/GetDocument?" . substr($LinkText, 1);
2776     }
2777     else {
2778     $LinkText = "";
2779     }
2780    
2781    
2782     # Get the mime type name
2783     $MimeTypeName = defined($main::MimeTypeNames{$MimeType}) ? $main::MimeTypeNames{$MimeType} : $MimeType;
2784    
2785    
2786     # Put up the mime type, this one links to the document
2787     if ( $HTML ) {
2788     print("<LI><A HREF=\"$LinkText\" OnMouseOver=\"self.status='Retrieve this document'; return true\"> $MimeTypeName </A>");
2789     }
2790     else {
2791     print("$MimeTypeName ");
2792     }
2793    
2794     # Put up the length if it is defined
2795     if ( defined($Length) && ($Length ne "") ) {
2796     print("Size: $Length, ");
2797     }
2798    
2799     if ( $HTML ) {
2800     if ( defined($URL) && ($URL ne "") ) {
2801     $Value = (length($URL) > $main::DefaultMaxVisibleUrlLength) ? substr($URL, 0, $main::DefaultMaxVisibleUrlLength) . "..." : $URL;
2802     print("<A HREF=\"$URL\"> $Value </A>\n");
2803     }
2804     print("</LI>\n");
2805     }
2806     else {
2807     print("URL: $LinkText\n");
2808     }
2809    
2810    
2811     } while ( defined($Remainder) ); # Keep looping while there are item names/mime types to process
2812    
2813     # Close off both un-numbered lists
2814     if ( $HTML ) {
2815     print("</UL></UL>");
2816     }
2817     print("\n");
2818    
2819 dpavlin 1.5 } #if
2820 dpavlin 1.1 # Finish off the entry
2821     if ( $HTML ) {
2822     print("</FONT></TD></TR>\n");
2823     print("<!-- /resultItem -->\n");
2824     }
2825     }
2826     }
2827     }
2828    
2829    
2830     # Print up the query report if it is defined
2831     if ( defined($FinalQueryReport) && ($FinalQueryReport ne "") ) {
2832    
2833     if ( $ResultCount > 0 ) {
2834     if ( $HTML ) {
2835     print("<TR><TD COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
2836     }
2837     else {
2838     print("--------------------------------------------------------------\n\n");
2839     }
2840     }
2841    
2842     if ( $HTML ) {
2843     print("<TR><TD COLSPAN=2></TD><TD ALIGN=LEFT VALIGN=TOP>\n");
2844     }
2845    
2846     $Value = $FinalQueryReport;
2847     if ( $HTML ) {
2848     $Value =~ s/\n/\<BR\>\n/g;
2849     }
2850    
2851     if ( $HTML ) {
2852     print("<SMALL>\n");
2853     }
2854    
2855     print("$Value");
2856    
2857     if ( $HTML ) {
2858     print("</SMALL>\n");
2859     print("</TD></TR>\n");
2860     }
2861     }
2862    
2863    
2864     if ( $HTML ) {
2865    
2866     # Close off the table
2867     print("<!-- /searchResults -->\n");
2868     print("</TABLE>\n");
2869    
2870     if ( $Header ) {
2871     # Close off the form
2872     print("</FORM>\n");
2873     }
2874     }
2875    
2876     # Return the status and the query report
2877     return (1, $FinalQueryReport);
2878    
2879     }
2880    
2881    
2882    
2883     #--------------------------------------------------------------------------
2884     #
2885     # Function: vGetSearch()
2886     #
2887     # Purpose: This function displays a search form to the user
2888     #
2889     # Called by:
2890     #
2891     # Parameters: void
2892     #
2893     # Global Variables: %main::ConfigurationData, %main::FormData, $main::RemoteUser
2894     #
2895     # Returns: void
2896     #
2897     sub vGetSearch {
2898    
2899     my (@ItemList, $ItemEntry, $Flag);
2900     my ($DatabaseName, $SelectedDatabases, $Year);
2901     my ($Value, %Value);
2902    
2903    
2904     # If we are getting the default search, we check to see if there is a
2905     # user name defined and if they chose to have a default search
2906     if ( $ENV{'PATH_INFO'} eq "/GetSearch" ) {
2907    
2908     if ( defined($main::RemoteUser) && defined($main::UserSettingsFilePath) ) {
2909    
2910     # Get the default search symbol
2911     $Value = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "DefaultSearch");
2912    
2913     # Set the default search
2914     if ( defined($Value) && ($Value eq "Simple") ) {
2915     $ENV{'PATH_INFO'} = "/GetSimpleSearch";
2916     }
2917     elsif ( defined($Value) && ($Value eq "Expanded") ) {
2918     $ENV{'PATH_INFO'} = "/GetExpandedSearch";
2919     }
2920     }
2921    
2922     # Override the default search if there is field from the expanded form defined
2923     foreach $Value ('FieldContent3', 'Past', 'Since', 'Before') {
2924     if ( defined($main::FormData{$Value}) ) {
2925     $ENV{'PATH_INFO'} = "/GetExpandedSearch";
2926     last;
2927     }
2928     }
2929     }
2930    
2931    
2932    
2933     # Make sure that we send the header
2934     $Value = ($ENV{'PATH_INFO'} eq "/GetExpandedSearch") ? "Pretra¾ivanje s vi¹e kriterija" : "Jednostavno pretra¾ivanje";
2935 dpavlin 1.6 my $JavaScript = '<SCRIPT LANGUAGE="JavaScript">
2936     <!-- hide
2937     function SetChecked(val) {
2938     dml=document.Search;
2939     len = dml.elements.length;
2940     var i=0;
2941     for( i=0 ; i<len ; i++) {
2942     if (dml.elements[i].name==\'Database\') {
2943     dml.elements[i].checked=val;
2944     }
2945     }
2946     }
2947     // -->
2948     </SCRIPT>
2949     ';
2950    
2951     &vSendHTMLHeader($Value, $JavaScript);
2952 dpavlin 1.1
2953     undef(%Value);
2954     $Value{'GetSearch'} = "GetSearch";
2955     &vSendMenuBar(%Value);
2956     undef(%Value);
2957    
2958    
2959     # Print the header ($Value is reused from the header)
2960     print("<H3>$Value:</H3>\n");
2961    
2962    
2963     # We now have a list of valid databases, at least we think so,
2964     # we check that there is at least one and put up an error message if there are none
2965     if ( scalar(keys(%main::DatabaseDescriptions)) <= 0 ) {
2966     &vHandleError("Database Search", "Sorry, there were no valid databases available for searching");
2967     goto bailFromGetSearch;
2968     }
2969    
2970    
2971    
2972     # Start the search form table
2973     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2974    
2975     # Display the collapse and expand buttons
2976     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2>\n");
2977     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
2978    
2979     # List the hidden fields
2980     %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
2981     foreach $Value ( keys(%Value) ) {
2982     @ItemList = split(/\0/, $Value{$Value});
2983     foreach $ItemEntry ( @ItemList ) {
2984     print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ItemEntry\">\n");
2985     }
2986     }
2987    
2988     if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
2989     print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSimpleSearch\">\n");
2990     print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'collapse'}\" BORDER=0 TYPE=IMAGE> Kliknite na trokutiæ da biste suzili formu.\n");
2991     }
2992     else {
2993     print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetExpandedSearch\">\n");
2994     print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'expand'}\" BORDER=0 TYPE=IMAGE> Kliknite na trokutiæ da biste pro¹irili formu.\n");
2995     }
2996     print("</FORM></TD>\n");
2997    
2998    
2999    
3000     # Send the start of the form and the buttons
3001     print("<TD ALIGN=RIGHT VALIGN=TOP>\n");
3002 dpavlin 1.6 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/GetSearchResults\" NAME=\"Search\" METHOD=POST> <INPUT TYPE=SUBMIT VALUE=\"Pretra¾i bazu\"> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\">\n");
3003 dpavlin 1.1 print("</TD></TR>\n");
3004    
3005     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><BR></TD></TR>\n");
3006    
3007     # Send the standard fields
3008     $Value = defined($main::FormData{'Any'}) ? "VALUE='$main::FormData{'Any'}'" : "";
3009     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");
3010    
3011    
3012     my $nr_fields = $main::NormalSearchDropdowns;
3013     my @SearchFieldNames = @main::NormalSearchFieldNames;
3014    
3015     if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3016     $nr_fields = $main::AdvancedSearchDropdowns;
3017     @SearchFieldNames = @main::AdvancedSearchFieldNames;
3018     }
3019    
3020     for (my $field=1; $field<= $nr_fields; $field++) {
3021    
3022     print("<TR><TD ALIGN=LEFT VALIGN=TOP>");
3023     if ($field == 1 ) {
3024     print ("Pretra¾i u odreðenom polju:");
3025     }
3026     print ("</TD><TD ALIGN=RIGHT VALIGN=TOP>");
3027    
3028     print ("<SELECT NAME=\"FieldName${field}\">");
3029     for (my $i=0; $i<=$#SearchFieldNames; $i++) {
3030     my $ItemEntry = $SearchFieldNames[$i];
3031 dpavlin 1.4 my $Selected = "";
3032     if ($main::FormData{"FieldName${field}"} && $main::FormData{"FieldName${field}"} eq $ItemEntry) {
3033     $Selected = "SELECTED";
3034     } elsif ($i == ($field - 1)) {
3035     $Selected = "SELECTED";
3036     }
3037    
3038 dpavlin 1.1 print("<OPTION VALUE=\"$ItemEntry\" $Selected> $main::SearchFieldDescriptions{$ItemEntry}\n");
3039     }
3040 dpavlin 1.4 my $Value = "";
3041     if (defined($main::FormData{"FieldContent${field}"})) {
3042     $Value = "VALUE='".$main::FormData{"FieldContent${field}"}."'";
3043     }
3044 dpavlin 1.1 print("</SELECT></TD><TD ALIGN=LEFT><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    
3059     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3060    
3061    
3062    
3063     # Database selection
3064     if ( %main::DatabaseDescriptions ) {
3065    
3066 dpavlin 1.7 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Odaberite bazu koju ¾elite pretra¾ivati:
3067     </td><td>
3068     <font size=-1>Oznaèi
3069     <a href=\"javascript:SetChecked(1)\">sve</a>,
3070     <a href=\"javascript:SetChecked(0)\">niti jednu</a>.
3071     </font>
3072     </TD></TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=4>
3073 dpavlin 1.5 ");
3074 dpavlin 1.1
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 dpavlin 1.7 &ShowDatabaseCheckBoxes(@ItemList);
3089 dpavlin 1.1
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 dpavlin 1.9 ### FIX:: SORT
3177     # print("<OPTION VALUE=\"SORT:700+:DESC\"> autor\n");
3178     # print("<OPTION VALUE=\"SORT:200+:DESC\"> naslov\n");
3179 dpavlin 1.1 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=\"Pobri¹i polja\"></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    
3231    
3232     # Check to see if there are any documents selected, if there are, they need
3233     # to be converted to RF documents before we put up the header, this is because
3234     # the header creates a search link from existing search fields, we also deduplicate
3235     # documents along the way
3236     if ( defined($main::FormData{'RfDocument'}) || defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) {
3237    
3238     # Undefine the hash table in preparation
3239     undef(%Value);
3240    
3241     # Make a hash table from the documents already selected for feedback
3242     if ( defined($main::FormData{'RfDocument'}) ) {
3243     foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3244     $Value{$Value} = $Value;
3245     }
3246     }
3247    
3248     # Add document that were specifically selected
3249     if ( defined($main::FormData{'Document'}) ) {
3250     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
3251     $Value{$Value} = $Value;
3252     }
3253     }
3254     # Otherwise add documents that were selected by default
3255     elsif ( defined($main::FormData{'Documents'}) ) {
3256     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
3257     $Value{$Value} = $Value;
3258     }
3259     }
3260    
3261     # Assemble the new content
3262     $main::FormData{'RfDocument'} = join("\0", keys(%Value));
3263    
3264     # Delete the old content
3265     delete($main::FormData{'Document'});
3266     delete($main::FormData{'Documents'});
3267     }
3268    
3269    
3270     # Set the database names if needed
3271     if ( !defined($main::FormData{'Database'}) && defined($main::FormData{'RfDocument'}) ) {
3272    
3273     # Loop over each entry in the documents list
3274     foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3275    
3276     # Parse out the document entry
3277     %Value = &hParseURLIntoHashTable($Value);
3278    
3279     # Add the database name to the hash table
3280     $Databases{$Value{'Database'}} = $Value{'Database'};
3281     }
3282    
3283     $main::FormData{'Database'} = join("\0", keys(%Databases));
3284     }
3285    
3286    
3287    
3288     # Make sure that we send the header
3289     &vSendHTMLHeader("Rezultati pretra¾ivanja", undef);
3290     undef(%Value);
3291     &vSendMenuBar(%Value);
3292    
3293    
3294     # Check that at least one database was selected
3295     if ( !defined($main::FormData{'Database'}) ) {
3296     print("<H3>Database Search:</H3>\n");
3297     print("<H3><CENTER>Sorry, no database(s) were selected for searching.</CENTER></H3>\n");
3298     print("<P>\n");
3299     print("There needs to be a least one database selected in order to perform the search.\n");
3300     print("Click <B>'back'</B> on your browser, select at least one database and try again.\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    
3331     # Add the max doc restriction
3332     if ( !defined($main::FormData{'Max'}) ) {
3333     $main::FormData{'Max'} = $main::DefaultMaxDoc;
3334     }
3335    
3336    
3337     # Generate the search string
3338     $SearchString = &sMakeSearchString(%main::FormData);
3339    
3340     # Retrieve the relevance feedback documents
3341     if ( defined($main::FormData{'RfDocument'}) ) {
3342    
3343     $RfText = "";
3344    
3345     # Loop over each entry in the documents list
3346     foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3347    
3348     # Parse out the document entry
3349     %Value = &hParseURLIntoHashTable($Value);
3350    
3351     # Check this document can be used for relevance feedback
3352     if ( !defined($main::RFMimeTypes{$Value{'MimeType'}}) ) {
3353     next;
3354     }
3355    
3356     # Get the document
3357     ($Status, $DocumentText) = MPS::GetDocument($main::MPSSession, $Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'});
3358    
3359     if ( $Status ) {
3360    
3361     $DatabaseRelevanceFeedbackFilterKey = "$main::DatabaseRelevanceFeedbackFilter:$Value{'Database'}:$Value{'ItemName'}:$Value{'MimeType'}";
3362    
3363     # Is a filter defined for this database relevance feedback filter key ?
3364     if ( defined($main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey}) ) {
3365    
3366     # Pull in the package
3367     require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Value{'Database'}"};
3368    
3369     # Filter the document
3370     $Value = $main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey};
3371     $DatabaseRelevanceFeedbackFilterFunction = \&$Value;
3372     $DocumentText = $DatabaseRelevanceFeedbackFilterFunction->($Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'}, $DocumentText);
3373    
3374     }
3375     else {
3376    
3377     # Strip the HTML from the text (this is only really useful on HTML documents)
3378     if ( defined($main::HtmlMimeTypes{$Value{'MimeType'}}) ) {
3379     $DocumentText =~ s/&nbsp;//gs;
3380     $DocumentText =~ s/<.*?>//gs;
3381     }
3382     }
3383    
3384     $RfText .= $DocumentText . " ";
3385     }
3386     }
3387     }
3388    
3389    
3390     # Run the search
3391     ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Databases, $SearchString, $RfText, 0, $main::FormData{'Max'} - 1, $main::ConfigurationData{'max-score'});
3392    
3393     if ( $Status ) {
3394    
3395     # Display the search results and get the query report text
3396     ($Status, $QueryReport) = &bsDisplaySearchResults("Rezultati pretra¾ivanja:", undef, undef, undef, $SearchResults, undef, $ENV{'SCRIPT_NAME'}, 1, 1, 1, %main::FormData);
3397    
3398     # Save the search history
3399     if ( defined($main::RemoteUser) ) {
3400    
3401     # Generate the search string
3402     $SearchAndRfDocumentURL = &sMakeSearchAndRfDocumentURL(%main::FormData);
3403    
3404     # Save the search history
3405     &iSaveSearchHistory(undef, $SearchAndRfDocumentURL, $SearchResults, $QueryReport);
3406    
3407     # Purge the search history files
3408     &vPurgeSearchHistory;
3409     }
3410     }
3411     else {
3412     ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
3413     &vHandleError("Database Search", "Sorry, failed to search the database(s)");
3414     print("The following error message was reported: <BR>\n");
3415     print("Error Message: $ErrorMessage <BR>\n");
3416     print("Error Number: $ErrorNumber <BR>\n");
3417     goto bailFromGetSearchResults;
3418     }
3419    
3420    
3421     # Bail from the search
3422     bailFromGetSearchResults:
3423    
3424     print("<CENTER><HR WIDTH=50%></CENTER>\n");
3425     undef(%Value);
3426     &vSendMenuBar(%Value);
3427    
3428     &vSendHTMLFooter;
3429    
3430     return;
3431    
3432     }
3433    
3434    
3435    
3436    
3437    
3438    
3439     #--------------------------------------------------------------------------
3440     #
3441     # Function: vGetDatabaseInfo()
3442     #
3443     # Purpose: This function allows the user to get some database information
3444     # such as the description, the contents and the time period spanned
3445     # by the content.
3446     #
3447     # Called by:
3448     #
3449     # Parameters: void
3450     #
3451     # Global Variables: %main::ConfigurationData, %main::FormData
3452     #
3453     # Returns: void
3454     #
3455     sub vGetDatabaseInfo {
3456    
3457     my ($DatabaseDescription, $DatabaseLanguage, $DatabaseTokenizer, $DocumentCount, $TotalWordCount, $UniqueWordCount, $StopWordCount, $AccessControl, $UpdateFrequency, $LastUpdateDate, $LastUpdateTime, $CaseSensitive);
3458     my ($FieldInformation, $FieldName, $FieldDescription);
3459     my ($Status, $Text, $Time, $Title);
3460     my ($ErrorNumber, $ErrorMessage);
3461     my ($Value, %Value);
3462    
3463    
3464    
3465     # Check we that we got a database name
3466     if ( !defined($main::FormData{'Database'}) ) {
3467     &vHandleError("Database information", "Sorry, the database content description could not be obtained");
3468     goto bailFromGetDatabaseInfo;
3469     }
3470    
3471    
3472     # Make sure that we send the header
3473     $Title = "Database Information: " . (defined($main::DatabaseDescriptions{$main::FormData{'Database'}})
3474     ? $main::DatabaseDescriptions{$main::FormData{'Database'}} : "");
3475     &vSendHTMLHeader($Title, undef);
3476     undef(%Value);
3477     &vSendMenuBar(%Value);
3478    
3479    
3480     # Get the database information
3481     ($Status, $Text) = MPS::GetDatabaseInfo($main::MPSSession, $main::FormData{'Database'});
3482    
3483     if ( $Status ) {
3484    
3485     # Display the database information
3486     print("<H3>Database information:</H3>\n");
3487    
3488     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
3489    
3490    
3491     # Send the database description
3492     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Database description: </TD> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> $main::DatabaseDescriptions{$main::FormData{'Database'}} </TD></TR>\n");
3493     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3494    
3495     # Truncate the line
3496     chop ($Text);
3497    
3498     # Parse the database information
3499     ($DatabaseDescription, $DatabaseLanguage, $DatabaseTokenizer, $DocumentCount, $TotalWordCount, $UniqueWordCount, $StopWordCount, $AccessControl, $UpdateFrequency, $LastUpdateDate, $LastUpdateTime, $CaseSensitive) = split(/\t/, $Text);
3500    
3501     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Database information: </TD><TD ALIGN=LEFT VALIGN=TOP> Broj rezultata: </TD> <TD ALIGN=LEFT VALIGN=TOP> $DocumentCount </TD></TR>\n");
3502     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Total number of words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $TotalWordCount </TD></TR>\n");
3503     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Number of unique words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $UniqueWordCount </TD></TR>\n");
3504     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Number of stop words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $StopWordCount </TD></TR>\n");
3505    
3506     # Get the time of last update of the data directory
3507     # $Time = (stat("$main::ConfigurationData{'data-directory'}/$main::FormData{'Database'}/"))[9];
3508     # $Value = &sGetPrintableDateFromTime($Time);
3509     # print("<TR><TD ALIGN=LEFT VALIGN=TOP> Data last updated on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
3510    
3511     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Index last updated on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $LastUpdateDate ($LastUpdateTime) </TD></TR>\n");
3512    
3513     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3514    
3515     # Get the database field information
3516     ($Status, $Text) = MPS::GetDatabaseFieldInfo($main::MPSSession, $main::FormData{'Database'});
3517    
3518     if ( $Status ) {
3519     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Database Field Information: </TD> <TD ALIGN=LEFT VALIGN=TOP> Field Name: </TD> <TD ALIGN=LEFT VALIGN=TOP> Field Description: </TD></TR> \n");
3520    
3521     foreach $FieldInformation ( split(/\n/, $Text) ) {
3522     ($FieldName, $FieldDescription, $Value) = split(/\t/, $FieldInformation, 3);
3523     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> $FieldName </TD> <TD ALIGN=LEFT VALIGN=TOP> $FieldDescription </TD></TR>\n");
3524     }
3525     }
3526    
3527     print("</TABLE>\n");
3528    
3529     }
3530     else {
3531     ($ErrorNumber, $ErrorMessage) = split(/\t/, $Text, 2);
3532     &vHandleError("Database information", "Sorry, failed to get the database information");
3533     print("The following error message was reported: <BR>\n");
3534     print("Error Message: $ErrorMessage <BR>\n");
3535     print("Error Number: $ErrorNumber <BR>\n");
3536     goto bailFromGetDatabaseInfo;
3537     }
3538    
3539    
3540    
3541     # Bail from the database info
3542     bailFromGetDatabaseInfo:
3543    
3544     print("<CENTER><HR WIDTH=50%></CENTER>\n");
3545     undef(%Value);
3546     &vSendMenuBar(%Value);
3547    
3548     &vSendHTMLFooter;
3549    
3550     return;
3551    
3552     }
3553    
3554    
3555    
3556    
3557    
3558    
3559     #--------------------------------------------------------------------------
3560     #
3561     # Function: vGetDocument()
3562     #
3563     # Purpose: This function get a document from the database.
3564     #
3565     # Called by:
3566     #
3567     # Parameters: void
3568     #
3569     # Global Variables: %main::ConfigurationData, %main::FormData,
3570     # $main::FooterSent
3571     #
3572     # Returns: void
3573     #
3574     sub vGetDocument {
3575    
3576     my (@DocumentList, %Document, $Document, $TextDocumentFlag);
3577     my ($Status, $Data, $ErrorNumber, $ErrorMessage);
3578     my (%QualifiedDocumentFolders, $QualifiedDocumentFolders, $FolderName, $DocumentFolderEntry);
3579     my ($DatabaseDocumentFilterFunction, $DatabaseDocumentFilterKey);
3580     my ($SelectorText, $FilteredData, $SimilarDocuments, $SearchResults);
3581     my (%Value, $Value);
3582    
3583    
3584    
3585     # Assemble the documents selected into a list do that we keep their order
3586     if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) || defined($main::FormData{'DocumentID'}) ) {
3587    
3588     # Undefine the hash table in preparation
3589     undef(%Value);
3590    
3591     # Add document that were specifically selected
3592     if ( defined($main::FormData{'Document'}) ) {
3593     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
3594     if ( !defined($Value{$Value}) ) {
3595     push @DocumentList, $Value;
3596     $Value{$Value} = $Value;
3597     }
3598     }
3599     }
3600     # Otherwise add documents that were selected by default
3601     elsif ( defined($main::FormData{'Documents'}) ) {
3602     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
3603     if ( !defined($Value{$Value}) ) {
3604     push @DocumentList, $Value;
3605     $Value{$Value} = $Value;
3606     }
3607     }
3608     }
3609    
3610     # Add document from the URL
3611     if ( defined($main::FormData{'DocumentID'}) ) {
3612     $Value = "";
3613     $Value .= (defined($main::FormData{'Database'}) && ($main::FormData{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($main::FormData{'Database'}) : "";
3614     $Value .= (defined($main::FormData{'DocumentID'}) && ($main::FormData{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($main::FormData{'DocumentID'}) : "";
3615     $Value .= (defined($main::FormData{'ItemName'}) && ($main::FormData{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($main::FormData{'ItemName'}) : "";
3616     $Value .= (defined($main::FormData{'MimeType'}) && ($main::FormData{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($main::FormData{'MimeType'}) : "";
3617     if ( !defined($Value{$Value}) ) {
3618     push @DocumentList, $Value;
3619     $Value{$Value} = $Value;
3620     }
3621     }
3622     }
3623    
3624    
3625    
3626     # Catch no document selection
3627     if ( !@DocumentList || (scalar(@DocumentList) == 0) ) {
3628    
3629     # Make sure that we send the header
3630     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3631     &vSendHTMLHeader("Similar Documents", undef);
3632     }
3633     else {
3634     &vSendHTMLHeader("Documents", undef);
3635     }
3636     undef(%Value);
3637     &vSendMenuBar(%Value);
3638    
3639     print("<H3>Document retrieval:</H3>\n");
3640     print("<H3><CENTER>Sorry, no document(s) were selected for retrieval.</CENTER></H3>\n");
3641     print("<P>\n");
3642     print("There needs to be a least one document selected in order to perform the retrieval.\n");
3643     print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
3644     goto bailFromGetDocument;
3645     }
3646    
3647    
3648    
3649     # Set the text document flag
3650     $TextDocumentFlag = 0;
3651    
3652     # Check the documents for text based documents
3653     foreach $Document ( @DocumentList ) {
3654    
3655     # Parse out the document entry
3656     %Document = &hParseURLIntoHashTable($Document);
3657    
3658     # Set the text flag if there are any text documents in the list
3659     if ( $Document{'MimeType'} =~ /^text\// ) {
3660     $TextDocumentFlag = 1;
3661     }
3662     }
3663    
3664    
3665    
3666     # If there were no text documents in our list, we display the first document in the
3667     # list, this is to handle cases where got one or more non-text documents (such as
3668     # images, pdf files, etc)
3669     if ( ! $TextDocumentFlag ) {
3670    
3671     %Document = &hParseURLIntoHashTable($DocumentList[0]);
3672    
3673     # Get the document
3674     ($Status, $Data) = MPS::GetDocument($main::MPSSession, $Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'});
3675    
3676     if ( !$Status ) {
3677    
3678     # Make sure that we send the header
3679     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3680     &vSendHTMLHeader("Similar Documents", undef);
3681     }
3682     else {
3683     &vSendHTMLHeader("Documents", undef);
3684     }
3685     undef(%Value);
3686     &vSendMenuBar(%Value);
3687    
3688     ($ErrorNumber, $ErrorMessage) = split(/\t/, $Data, 2);
3689     # The database document could not be gotten, so we inform the user of the fact
3690     &vHandleError("Document retrieval", "Sorry, the database document could not be obtained");
3691     print("The following error message was reported: <BR>\n");
3692     print("Error Message: $ErrorMessage <BR>\n");
3693     print("Error Number: $ErrorNumber <BR>\n");
3694     goto bailFromGetDocument;
3695     }
3696    
3697     # Send the content type
3698     print("Content-type: $Document{'MimeType'}\n\n");
3699    
3700     # Send the document
3701     print("$Data");
3702    
3703     return;
3704     }
3705    
3706    
3707    
3708     # Make sure that we send the header
3709     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3710     &vSendHTMLHeader("Similar Documents", undef);
3711     }
3712     else {
3713     &vSendHTMLHeader("Documents", undef);
3714     }
3715     undef(%Value);
3716     &vSendMenuBar(%Value);
3717    
3718    
3719    
3720     # Print the header
3721     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3722     print("<H3>Similar Documents:</H3>\n");
3723     }
3724     else {
3725     print("<H3>Dokumenti:</H3>\n");
3726     }
3727    
3728    
3729     # Start the form
3730     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
3731    
3732     # Send the pull-down
3733     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
3734     print("<TR><TD ALIGN=LEFT VALIGN=TOP>Odabranima se smatraju svi rezultati ukoliko niste uèinili nikakav dodatan odabir.</TD><TD ALIGN=RIGHT VALIGN=TOP> \n");
3735    
3736     if ( defined($main::RemoteUser) ) {
3737     print("<SELECT NAME=\"Action\">\n");
3738     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3739     print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
3740     }
3741     if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
3742     print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
3743     }
3744     if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
3745     print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
3746     }
3747     print("<OPTION VALUE=\"GetSaveFolder\">Save selected documents to a new document folder\n");
3748    
3749     # Get the document folder hash
3750     %QualifiedDocumentFolders = &hGetDocumentFolders;
3751    
3752     for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
3753    
3754     $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
3755    
3756     # Get the document folder file name and encode it
3757     $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
3758     $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
3759    
3760     print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry\">Add selected documents to the '$FolderName' document folder\n");
3761     }
3762    
3763     print("</SELECT>\n");
3764     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
3765     }
3766     else {
3767     if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
3768     print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSearchResults\">\n");
3769     print("<INPUT TYPE=SUBMIT VALUE=\"Run search with documents as relevance feedback\">\n");
3770     }
3771     }
3772    
3773     print("</TD></TR>\n");
3774     print("</TABLE>\n");
3775    
3776    
3777     # Display the documents
3778    
3779     print("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>\n");
3780    
3781    
3782     # Display the selector for all the documents
3783     $SelectorText = "";
3784    
3785     foreach $Document ( @DocumentList ) {
3786    
3787     # Parse out the document entry
3788     %Document = &hParseURLIntoHashTable($Document);
3789    
3790     # Skip non-text documents
3791     if ( !($Document{'MimeType'} =~ /^text\//) ) {
3792     next;
3793     }
3794    
3795     $Value = "";
3796     $Value .= (defined($Document{'Database'}) && ($Document{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Document{'Database'}) : "";
3797     $Value .= (defined($Document{'DocumentID'}) && ($Document{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Document{'DocumentID'}) : "";
3798     $Value .= (defined($Document{'ItemName'}) && ($Document{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($Document{'ItemName'}) : "";
3799     $Value .= (defined($Document{'MimeType'}) && ($Document{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($Document{'MimeType'}) : "";
3800     $SelectorText .= (($SelectorText ne "") ? "|" : "") . substr($Value, 1);
3801     }
3802    
3803     $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
3804     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> $SelectorText </TD></TR>\n");
3805    
3806    
3807    
3808     # Get the similar documents value
3809     if ( defined($main::RemoteUser) ) {
3810     $SimilarDocuments = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SimilarDocuments");
3811     }
3812     else {
3813     $SimilarDocuments = $main::DefaultSimilarDocument;
3814     }
3815    
3816    
3817    
3818     foreach $Document ( @DocumentList ) {
3819    
3820     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3> <HR WIDTH=50%> </TD></TR>\n");
3821    
3822    
3823     # Parse out the document entry
3824     %Document = &hParseURLIntoHashTable($Document);
3825    
3826     # Skip non-text documents
3827     if ( !($Document{'MimeType'} =~ /^text\//) ) {
3828     next;
3829     }
3830    
3831    
3832     # Get the document
3833     ($Status, $Data) = MPS::GetDocument($main::MPSSession, $Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'});
3834    
3835     if ( !$Status ) {
3836     ($ErrorNumber, $ErrorMessage) = split(/\t/, $Data, 2);
3837     # The database document could not be gotten, so we inform the user of the fact
3838     &vHandleError("Document retrieval", "Sorry, the database document could not be obtained");
3839     print("The following error message was reported: <BR>\n");
3840     print("Error Message: $ErrorMessage <BR>\n");
3841     print("Error Number: $ErrorNumber <BR>\n");
3842     goto bailFromGetDocument;
3843     }
3844    
3845    
3846     # Create the database document filter key
3847     $DatabaseDocumentFilterKey = "$main::DatabaseDocumentFilter:$Document{'Database'}:$Document{'ItemName'}:$Document{'MimeType'}";
3848    
3849     # Is a filter defined for this database document filter key ?
3850     if ( defined($main::DatabaseFilters{$DatabaseDocumentFilterKey}) ) {
3851    
3852     # Pull in the package
3853     require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Document{'Database'}"};
3854    
3855     # Filter the document
3856     $Value = $main::DatabaseFilters{$DatabaseDocumentFilterKey};
3857     $DatabaseDocumentFilterFunction = \&$Value;
3858     $FilteredData = $DatabaseDocumentFilterFunction->($Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'}, $Data);
3859     } else {
3860     # use default filter key
3861    
3862     # Pull in the package
3863     require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:default"};
3864    
3865     # Filter the document
3866     $Value = $main::DatabaseFilters{"$main::DatabaseDocumentFilter:default:$Document{'ItemName'}:$Document{'MimeType'}"};
3867     $DatabaseDocumentFilterFunction = \&$Value;
3868     $FilteredData = $DatabaseDocumentFilterFunction->($Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'}, $Data);
3869     }
3870    
3871    
3872    
3873     # Create the document selector button text
3874     $SelectorText = "";
3875     $SelectorText .= (defined($Document{'Database'}) && ($Document{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Document{'Database'}) : "";
3876     $SelectorText .= (defined($Document{'DocumentID'}) && ($Document{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Document{'DocumentID'}) : "";
3877     $SelectorText .= (defined($Document{'ItemName'}) && ($Document{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($Document{'ItemName'}) : "";
3878     $SelectorText .= (defined($Document{'MimeType'}) && ($Document{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($Document{'MimeType'}) : "";
3879     $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"Document\" VALUE=\"" . substr($SelectorText, 1) . "\"> ";
3880    
3881    
3882     # Send the document text
3883     print("<TR><TD ALIGN=LEFT VALIGN=TOP> $SelectorText </TD> <TD ALIGN=LEFT VALIGN=TOP>$FilteredData</TD></TR>");
3884     if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3885    
3886     # Get the similar documents if needed
3887     if ( defined($main::ConfigurationData{'allow-similiar-search'}) && ($main::ConfigurationData{'allow-similiar-search'} eq "yes") &&
3888     defined($SimilarDocuments) ) {
3889    
3890     # Run the search, discard the query report
3891     ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Document{'Database'}, "{NOREPORT}", $Data, 0, $SimilarDocuments - 1, $main::ConfigurationData{'max-score'});
3892    
3893     if ( $Status ) {
3894    
3895     # Display the search result
3896     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3> <HR WIDTH=25%> </TD></TR>\n");
3897     print("<TR><TD ALIGN=LEFT VALIGN=TOP></TD> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> \n");
3898     print("<B>Similar Documents:</B>\n");
3899     ($Status, undef) = &bsDisplaySearchResults("Similar Documents:", undef, undef, undef, $SearchResults, undef, $ENV{'SCRIPT_NAME'}, 0, 1, 1, %main::FormData);
3900     print("</TD></TR>\n");
3901     }
3902     else {
3903     ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
3904     &vHandleError("Database Search", "Sorry, failed to search the database(s)");
3905     print("The following error message was reported: <BR>\n");
3906     print("Error Message: $ErrorMessage <BR>\n");
3907     print("Error Number: $ErrorNumber <BR>\n");
3908     goto bailFromGetDocument;
3909     }
3910     }
3911     }
3912     }
3913    
3914    
3915     # Close off the form
3916     print("</FORM>\n");
3917    
3918     # Close off the table
3919     print("</TABLE>\n");
3920    
3921    
3922     # Bail from getting the document
3923     bailFromGetDocument:
3924    
3925     print("<CENTER><HR WIDTH=50%></CENTER>\n");
3926     undef(%Value);
3927     &vSendMenuBar(%Value);
3928    
3929     &vSendHTMLFooter;
3930    
3931     return;
3932    
3933     }
3934    
3935    
3936    
3937    
3938    
3939    
3940     #--------------------------------------------------------------------------
3941     #
3942     # Function: vGetUserSettings()
3943     #
3944     # Purpose: This function displays a user settings form to the user
3945     #
3946     # Called by:
3947     #
3948     # Parameters: void
3949     #
3950     # Global Variables: %main::ConfigurationData, %main::FormData,
3951     # $main::UserSettingsFilePath, $main::RemoteUser,
3952     #
3953     # Returns: void
3954     #
3955     sub vGetUserSettings {
3956    
3957     my ($UserName, $SearchHistory, $DefaultSearch, $SelectedDatabases, $EmailAddress, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SummaryType, $SummaryLength, $SimilarDocuments);
3958     my ($SearchHistoryCount, $HeaderName);
3959     my ($DatabaseName, @ItemList, $ItemEntry, $Flag);
3960     my ($Value, %Value);
3961    
3962    
3963     # Return an error if the remote user name/account directory is not defined
3964     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
3965     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
3966     &vSendHTMLFooter;
3967     return;
3968     }
3969    
3970    
3971    
3972     # Make sure that we send the header
3973     &vSendHTMLHeader("My Settings", undef);
3974     undef(%Value);
3975     $Value{'GetUserSettings'} = "GetUserSettings";
3976     &vSendMenuBar(%Value);
3977     undef(%Value);
3978    
3979    
3980    
3981     # Get information from the XML saved search file
3982     ($HeaderName, %Value) = &shGetHashFromXMLFile($main::UserSettingsFilePath);
3983    
3984     # Check the header if it is defines, delete the file if it is not valid,
3985     # else set the variables from the hash table contents
3986     if ( defined($HeaderName) ) {
3987     if ( $HeaderName ne "UserSettings" ) {
3988     unlink($main::UserSettingsFilePath);
3989     }
3990     else {
3991     $UserName = $Value{'UserName'};
3992     $SearchHistory = $Value{'SearchHistory'};
3993     $DefaultSearch = $Value{'DefaultSearch'};
3994     $SelectedDatabases = $Value{'SelectedDatabases'};
3995     $EmailAddress = $Value{'EmailAddress'};
3996     $SearchFrequency = $Value{'SearchFrequency'};
3997     $DeliveryFormat = $Value{'DeliveryFormat'};
3998     $DeliveryMethod = $Value{'DeliveryMethod'};
3999     $SummaryType = $Value{'SummaryType'};
4000     $SummaryLength = $Value{'SummaryLength'};
4001     $SimilarDocuments = $Value{'SimilarDocuments'};
4002     }
4003     }
4004    
4005    
4006     # Give the user a form to fill out
4007    
4008     print("<H3> Postavke: </H3>\n");
4009    
4010     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4011     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetUserSettings\" METHOD=POST>\n");
4012    
4013     # Send the buttons
4014     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=2> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\"> <INPUT TYPE=SUBMIT VALUE=\"Saèuvaj postavke\"> </TD></TR>\n");
4015    
4016    
4017    
4018     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4019    
4020     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Informacije o korisniku: </B> </TR>\n");
4021    
4022     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Login: </TD><TD ALIGN=LEFT VALIGN=TOP> $ENV{'REMOTE_USER'} </TD></TR>\n");
4023    
4024     $Value = (defined($UserName)) ? "VALUE=\"$UserName\"" : "";
4025     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Ime korisnika: </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"UserName\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
4026    
4027     # Are regular searches enabled?
4028     if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4029    
4030     # Get the email address
4031     $Value = (defined($EmailAddress)) ? "VALUE=\"$EmailAddress\"" : "";
4032     print("<TR><TD ALIGN=LEFT VALIGN=TOP> E-mail adresa:");
4033     if ( !defined($EmailAddress) && defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4034     print(" (*) ");
4035     }
4036     print(": </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"EmailAddress\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
4037    
4038     if ( !defined($EmailAddress) && defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4039     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> (*) Please fill in the email address if you are going to want to have your automatic searches delivered to you. </TD></TR>\n");
4040     }
4041     }
4042    
4043    
4044     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4045    
4046     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Search Preferences: </B> </TD></TR>\n");
4047    
4048     # Send a pull-down which allows the user to select which search form to default to
4049     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Forma za pretra¾ivanje: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DefaultSearch\">\n");
4050     $Value = (defined($DefaultSearch) && ($DefaultSearch eq "Simple")) ? "SELECTED" : "";
4051     print("<OPTION VALUE=\"Simple\" $Value> Jednostavna forma za pretra¾ivanje\n");
4052     $Value = (defined($DefaultSearch) && ($DefaultSearch eq "Expanded")) ? "SELECTED" : "";
4053     print("<OPTION VALUE=\"Expanded\" $Value>Forma za pretra¾ivanje s vi¹e kriterija\n");
4054     print("</SELECT> </TD></TR>\n");
4055    
4056     # Send a pull-down which allows the user to select how many previous searches to store
4057     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Broj pretra¾ivanja koja ostaju zapamæena (maksimalno): </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"SearchHistory\">\n");
4058    
4059     for ( $SearchHistoryCount = 5; $SearchHistoryCount <= 20; $SearchHistoryCount += 5 ) {
4060     $Value = (defined($SearchHistory) && ($SearchHistory == $SearchHistoryCount)) ? "SELECTED" : "";
4061     print("<OPTION VALUE=\"$SearchHistoryCount\" $Value> $SearchHistoryCount \n");
4062     }
4063     print("</SELECT> </TD></TR>\n");
4064    
4065    
4066     # Database selection preferences
4067     if ( %main::DatabaseDescriptions ) {
4068    
4069     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4070    
4071     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Odabrane baze: </B> </TD></TR>\n");
4072    
4073 dpavlin 1.7 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Oznaèite baze koje uvijek ¾elite pretra¾ivati:</TD> <TD ALIGN=LEFT VALIGN=TOP>\n");
4074 dpavlin 1.1
4075     # Parse out the database names and put them into a
4076     # hash table, they should be separated with a '\n'
4077     if ( defined($SelectedDatabases) && ($SelectedDatabases ne "") ) {
4078     @ItemList = split(",", $SelectedDatabases);
4079     }
4080 dpavlin 1.7
4081     &ShowDatabaseCheckBoxes(@ItemList);
4082    
4083 dpavlin 1.1 print("</TD></TR>\n");
4084     }
4085    
4086    
4087    
4088     # Send a pull-down which allows the user to select whether to display summaries or not, and how long we want them
4089     if ( defined($main::ConfigurationData{'allow-summary-displays'}) && ($main::ConfigurationData{'allow-summary-displays'} eq "yes") ) {
4090    
4091     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4092    
4093     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Document Summary Preferences: </B> </TD></TR>\n");
4094    
4095     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Document summary type: </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SummaryType\">\n");
4096     foreach $ItemEntry ( keys (%main::SummaryTypes) ) {
4097     $Value = (defined($SummaryType) && ($SummaryType eq $ItemEntry)) ? "SELECTED" : "";
4098     print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::SummaryTypes{$ItemEntry}\n");
4099     }
4100     print("</SELECT></TD></TR>\n");
4101    
4102     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Document summary length in words (max): </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SummaryLength\">\n");
4103     foreach $ItemEntry ( @main::SummaryLengths ) {
4104     $Value = (defined($SummaryLength) && ($SummaryLength eq $ItemEntry)) ? "SELECTED" : "";
4105     print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
4106     }
4107     print("</SELECT></TD></TR>\n");
4108     }
4109    
4110    
4111     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4112    
4113     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Document Retrieval Preferences: </B> </TD></TR>\n");
4114    
4115     # Send a pull-down which allows the user to select whether to display summaries or not, and how long we want them
4116     if ( defined($main::ConfigurationData{'allow-similiar-search'}) && ($main::ConfigurationData{'allow-similiar-search'} eq "yes") ) {
4117    
4118     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Number of similar documents retrieved (max): </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SimilarDocuments\">\n");
4119     foreach $ItemEntry ( @main::SimilarDocuments ) {
4120     $Value = (defined($SimilarDocuments) && ($SimilarDocuments eq $ItemEntry)) ? "SELECTED" : "";
4121     print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
4122     }
4123     print("</SELECT></TD></TR>\n");
4124     }
4125    
4126    
4127    
4128    
4129     # Are regular searches enabled?
4130     if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4131    
4132     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4133    
4134     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Saved Searches Defaults: </B> </TD></TR>\n");
4135    
4136     # Send a pull-down which allows the user to select the automatic search frequency (default to weekly)
4137     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"SearchFrequency\">\n");
4138     foreach $ItemEntry ( @main::SearchFrequencies ) {
4139     $Value = (defined($SearchFrequency) && ($SearchFrequency eq $ItemEntry)) ? "SELECTED" : "";
4140     print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry \n");
4141     }
4142     print("</SELECT> </TD></TR>\n");
4143    
4144     # Send a pull-down which allows the user to select the automatic search delivery format
4145     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryFormat\">\n");
4146     foreach $ItemEntry ( sort(keys(%main::DeliveryFormats)) ) {
4147     $Value = (defined($DeliveryFormat) && ($DeliveryFormat eq $ItemEntry)) ? "SELECTED" : "";
4148     print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::DeliveryFormats{$ItemEntry}\n");
4149     }
4150     print("</SELECT> </TD></TR>\n");
4151    
4152     # Send a pull-down which allows the user to select the automatic delivery method
4153     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search delivery method: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryMethod\">\n");
4154     foreach $ItemEntry ( sort(keys(%main::DeliveryMethods)) ) {
4155     $Value = (defined($DeliveryMethod) && ($DeliveryMethod eq $ItemEntry)) ? "SELECTED" : "";
4156     print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::DeliveryMethods{$ItemEntry}\n");
4157     }
4158     print("</SELECT> </TD></TR>\n");
4159     }
4160    
4161    
4162     print("</FORM>\n");
4163     print("</TABLE>\n");
4164    
4165    
4166    
4167     # Bail from the settings
4168     bailFromGetUserSettings:
4169    
4170     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4171     undef(%Value);
4172     $Value{'GetUserSettings'} = "GetUserSettings";
4173     &vSendMenuBar(%Value);
4174     undef(%Value);
4175    
4176     &vSendHTMLFooter;
4177    
4178     return;
4179    
4180     }
4181    
4182    
4183    
4184    
4185    
4186    
4187     #--------------------------------------------------------------------------
4188     #
4189     # Function: vSetUserSettings()
4190     #
4191     # Purpose: This function saves the user setting
4192     #
4193     # Called by:
4194     #
4195     # Parameters: void
4196     #
4197     # Global Variables: %main::ConfigurationData, %main::FormData,
4198     # $main::UserSettingsFilePath, $main::RemoteUser,
4199     #
4200     # Returns: void
4201     #
4202     sub vSetUserSettings {
4203    
4204     my (%Value);
4205    
4206    
4207     # Return an error if the remote user name/account directory is not defined
4208     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4209     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4210     &vSendHTMLFooter;
4211     return;
4212     }
4213    
4214    
4215     # Make sure that we send the header
4216     &vSendHTMLHeader("My Settings", undef);
4217     undef(%Value);
4218     &vSendMenuBar(%Value);
4219    
4220    
4221     # Save the user settings
4222     undef(%Value);
4223     $Value{'UserName'} = $main::FormData{'UserName'};
4224     $Value{'EmailAddress'} = $main::FormData{'EmailAddress'};
4225     $Value{'DefaultSearch'} = $main::FormData{'DefaultSearch'};
4226     $Value{'SelectedDatabases'} = $main::FormData{'SelectedDatabases'};
4227     if ( defined($Value{'SelectedDatabases'}) ) {
4228     $Value{'SelectedDatabases'} =~ s/\0/,/g;
4229     }
4230     $Value{'SearchHistory'} = $main::FormData{'SearchHistory'};
4231     $Value{'SearchFrequency'} = $main::FormData{'SearchFrequency'};
4232     $Value{'DeliveryFormat'} = $main::FormData{'DeliveryFormat'};
4233     $Value{'DeliveryMethod'} = $main::FormData{'DeliveryMethod'};
4234     $Value{'SummaryType'} = $main::FormData{'SummaryType'};
4235     $Value{'SummaryLength'} = $main::FormData{'SummaryLength'};
4236     $Value{'SimilarDocuments'} = $main::FormData{'SimilarDocuments'};
4237    
4238    
4239     # Save the user settings file
4240     if ( &iSaveXMLFileFromHash($main::UserSettingsFilePath, "UserSettings", %Value) ) {
4241    
4242     print("<H3> Postavke: </H3>\n");
4243     print("<H3><CENTER> Postavke su uspje¹no snimljene! </CENTER></H3>\n");
4244     print("<P>\n");
4245     }
4246     else {
4247    
4248     # The settings could not be saved, so we inform the user of the fact
4249     &vHandleError("User Settings", "Sorry, we failed to saved your settings");
4250     }
4251    
4252    
4253    
4254     # Bail from the settings
4255     bailFromSetUserSettings:
4256    
4257     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4258     undef(%Value);
4259     &vSendMenuBar(%Value);
4260    
4261     &vSendHTMLFooter;
4262    
4263     return;
4264    
4265     }
4266    
4267    
4268    
4269    
4270    
4271    
4272     #--------------------------------------------------------------------------
4273     #
4274     # Function: vPurgeSearchHistory()
4275     #
4276     # Purpose: This function purges the search history files.
4277     #
4278     # Called by:
4279     #
4280     # Parameters: void
4281     #
4282     # Global Variables: $main::DefaultMaxSearchHistory, $main::UserSettingsFilePath,
4283     # $main::SearchHistoryFileNamePrefix, $main::UserAccountDirectoryPath
4284     #
4285     # Returns: void
4286     #
4287     sub vPurgeSearchHistory {
4288    
4289     my ($MaxSearchHistory, @SearchHistoryList, $SearchHistoryEntry);
4290    
4291    
4292     # Return if the remote user name/account directory is not defined
4293     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4294     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4295     &vSendHTMLFooter;
4296     return;
4297     }
4298    
4299    
4300     # Get the max number of entries in the search history
4301     $MaxSearchHistory = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SearchHistory");
4302    
4303     # Set the detault max number of entries if it was not gotten from the user settings
4304     if ( !defined($MaxSearchHistory) ) {
4305     $MaxSearchHistory = $main::DefaultMaxSearchHistory;
4306     }
4307    
4308    
4309     # Read all the search history files
4310     opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4311     @SearchHistoryList = map("$main::UserAccountDirectoryPath/$_" ,
4312     reverse(sort(grep(/$main::SearchHistoryFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
4313     closedir(USER_ACCOUNT_DIRECTORY);
4314    
4315    
4316     # Purge the excess search history files
4317     if ( scalar(@SearchHistoryList) > $MaxSearchHistory ) {
4318    
4319     # Splice out the old stuff, and loop over it deleting the files
4320     for $SearchHistoryEntry ( splice(@SearchHistoryList, $MaxSearchHistory) ) {
4321     unlink($SearchHistoryEntry);
4322     }
4323     }
4324    
4325     return;
4326    
4327     }
4328    
4329    
4330    
4331    
4332     #--------------------------------------------------------------------------
4333     #
4334     # Function: vListSearchHistory()
4335     #
4336     # Purpose: This function lists the search history for the user, the
4337     # entries are listed in reverse chronological order (most
4338     # recent first).
4339     #
4340     # In addition, the search history will be scanned and excess
4341     # searches will be purged.
4342     #
4343     # Called by:
4344     #
4345     # Parameters: void
4346     #
4347     # Global Variables: %main::ConfigurationData, $main::UserAccountDirectoryPath,
4348     # $main::XMLFileNameExtension, $main::SearchHistoryFileNamePrefix,
4349     # $main::RemoteUser
4350     #
4351     # Returns: void
4352     #
4353     sub vListSearchHistory {
4354    
4355     my (@SearchHistoryList, @QualifiedSearchHistoryList, $SearchHistoryEntry);
4356     my ($SearchString, $CreationTime, $SearchAndRfDocumentURL, $HeaderName, $Database);
4357     my ($Value, %Value, @Values);
4358    
4359    
4360     # Return an error if the remote user name/account directory is not defined
4361     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4362     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4363     &vSendHTMLFooter;
4364     return;
4365     }
4366    
4367    
4368    
4369     # Make sure that we send the header
4370     &vSendHTMLHeader("Prija¹nja pretra¾ivanja", undef);
4371     undef(%Value);
4372     $Value{'ListSearchHistory'} = "ListSearchHistory";
4373     &vSendMenuBar(%Value);
4374     undef(%Value);
4375    
4376    
4377     # Purge the search history files
4378     &vPurgeSearchHistory;
4379    
4380    
4381     # Read all the search history files
4382     opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4383     @SearchHistoryList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::SearchHistoryFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
4384     closedir(USER_ACCOUNT_DIRECTORY);
4385    
4386    
4387     # Loop over each search history file checking that it is valid
4388     for $SearchHistoryEntry ( @SearchHistoryList ) {
4389    
4390     # Get the header name from the XML search history file
4391     $HeaderName = &sGetObjectTagFromXMLFile($SearchHistoryEntry);
4392    
4393     # Check that the entry is valid and add it to the qualified list
4394     if ( defined($HeaderName) && ($HeaderName eq "SearchHistory") ) {
4395     push @QualifiedSearchHistoryList, $SearchHistoryEntry;
4396     }
4397     else {
4398     # Else we delete this invalid search history file
4399     unlink($SearchHistoryEntry);
4400     }
4401     }
4402    
4403    
4404    
4405     # Display the search history
4406     print("<H3> Prija¹nja pretra¾ivanja: </H3>\n");
4407    
4408     # Print up the search history, if there is none, we put up a nice message
4409     if ( scalar(@QualifiedSearchHistoryList) > 0 ) {
4410    
4411     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4412    
4413    
4414     for $SearchHistoryEntry ( @QualifiedSearchHistoryList ) {
4415    
4416     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
4417    
4418     # Get information from the XML search history file
4419     ($HeaderName, %Value) = &shGetHashFromXMLFile($SearchHistoryEntry);
4420    
4421     # Get the search file name and encode it
4422     $SearchHistoryEntry = ($SearchHistoryEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $SearchHistoryEntry;
4423     $SearchHistoryEntry = &lEncodeURLData($SearchHistoryEntry);
4424    
4425     $CreationTime = $Value{'CreationTime'};
4426     $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
4427     %Value = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
4428     $SearchString = &sMakeSearchString(%Value);
4429     if ( defined($SearchString) ) {
4430     $SearchString =~ s/{.*?}//gs;
4431     $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
4432     }
4433     $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
4434    
4435    
4436     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD><TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
4437    
4438     # Get the local databases from the search and list their descriptions
4439     if ( defined($Value{'Database'}) ) {
4440    
4441     # Initialize the temp list
4442     undef(@Values);
4443    
4444     # Loop over each database
4445     foreach $Database ( split(/\0/, $Value{'Database'}) ) {
4446     $Value = &lEncodeURLData($Database);
4447     push @Values, sprintf("<A HREF=\"$ENV{'SCRIPT_NAME'}/GetDatabaseInfo?Database=$Value\" OnMouseOver=\"self.status='Informacije o bazi $main::DatabaseDescriptions{$Database}'; return true\"> $main::DatabaseDescriptions{$Database} </A> ");
4448     }
4449    
4450     # Print the list if there are any entries in it
4451     if ( scalar(@Values) > 0 ) {
4452     printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD><TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n",
4453     scalar(@Values) > 1 ? "s" : "", join(", ", @Values));
4454     }
4455     }
4456    
4457     if ( defined($Value{'RfDocument'}) ) {
4458     print("<TR>");
4459     &bDisplayDocuments("Feedback Document", $Value{'RfDocument'}, "RfDocument", undef, undef, 1);
4460     print("</TR>");
4461     }
4462    
4463     $Value = &sGetPrintableDateFromTime($CreationTime);
4464     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD><TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
4465    
4466     print("<TR><TD ALIGN=LEFT VALIGN=TOP> </TD><TD ALIGN=LEFT VALIGN=TOP> <A HREF=\"$ENV{'SCRIPT_NAME'}/GetSearchHistory?SearchHistoryObject=$SearchHistoryEntry\" > [ Prika¾i rezultate pretra¾ivanja ] </A> </TD></TR>\n");
4467    
4468     }
4469    
4470     print("</TABLE>\n");
4471     }
4472     else {
4473     print("<H3><CENTER> Sorry, currently there is no search history. </CENTER></H3>\n");
4474     }
4475    
4476    
4477    
4478     # Bail from the search history
4479     bailFromListSearchHistory:
4480    
4481     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4482     undef(%Value);
4483     $Value{'ListSearchHistory'} = "ListSearchHistory";
4484     &vSendMenuBar(%Value);
4485     undef(%Value);
4486    
4487     &vSendHTMLFooter;
4488    
4489     return;
4490    
4491     }
4492    
4493    
4494    
4495    
4496    
4497     #--------------------------------------------------------------------------
4498     #
4499     # Function: vGetSearchHistory()
4500     #
4501     # Purpose: This function displays a search history file to the user.
4502     #
4503     # Called by:
4504     #
4505     # Parameters: void
4506     #
4507     # Global Variables: %main::ConfigurationData, %main::FormData,
4508     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
4509     # $main::SearchHistoryFileNamePrefix, $main::RemoteUser
4510     #
4511     # Returns: void
4512     #
4513     sub vGetSearchHistory {
4514    
4515     my ($SearchAndRfDocumentURL, $SearchResults, $QueryReport, $CreationTime);
4516     my ($SearchHistoryEntry, $HeaderName, $Status);
4517     my ($Value, %Value);
4518    
4519    
4520    
4521     # Return an error if the remote user name/account directory is not defined
4522     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4523     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4524     &vSendHTMLFooter;
4525     return;
4526     }
4527    
4528    
4529     # Create the search history file name
4530     $SearchHistoryEntry = $main::UserAccountDirectoryPath . "/" . $main::FormData{'SearchHistoryObject'};
4531    
4532    
4533     # Check to see if the XML search history file requested is there
4534     if ( ! -f $SearchHistoryEntry ) {
4535     # Could not find the search history file
4536     &vHandleError("Display Search History", "Sorry, we cant to access this search history object because it is not there");
4537     goto bailFromGetSearchHistory;
4538     }
4539    
4540    
4541     # Get information from the XML search history file
4542     ($HeaderName, %Value) = &shGetHashFromXMLFile($SearchHistoryEntry);
4543    
4544     # Check that the entry is valid
4545     if ( !(defined($HeaderName) && ($HeaderName eq "SearchHistory")) ) {
4546     &vHandleError("Display Search History", "Sorry, this search history object is invalid");
4547     goto bailFromGetSearchHistory;
4548     }
4549    
4550    
4551    
4552     # At this point, the XML search history file is there and is valid,
4553     # so we can go ahead and display it
4554     $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
4555     $SearchResults = $Value{'SearchResults'};
4556     $QueryReport = $Value{'QueryReport'};
4557     $CreationTime = $Value{'CreationTime'};
4558    
4559     %main::FormData = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
4560    
4561     # Make sure that we send the header
4562     &vSendHTMLHeader("Display Search History", undef);
4563     undef(%Value);
4564     &vSendMenuBar(%Value);
4565    
4566    
4567     ($Status, $QueryReport) = &bsDisplaySearchResults("Rezultati prija¹njih pretra¾ivanja:", undef, undef, undef, $SearchResults, $QueryReport, $ENV{'SCRIPT_NAME'}, 1, 1, 1, %main::FormData);
4568    
4569    
4570     # Bail from displaying the search history
4571     bailFromGetSearchHistory:
4572    
4573     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4574     undef(%Value);
4575     &vSendMenuBar(%Value);
4576    
4577     &vSendHTMLFooter;
4578    
4579     return;
4580    
4581     }
4582    
4583    
4584    
4585    
4586    
4587    
4588     #--------------------------------------------------------------------------
4589     #
4590     # Function: vGetSaveSearch()
4591     #
4592     # Purpose: This function displays a form to the user allowing them to save a search
4593     #
4594     # Called by:
4595     #
4596     # Parameters: void
4597     #
4598     # Global Variables: %main::ConfigurationData, %main::FormData,
4599     # $main::UserSettingsFilePath, $main::RemoteUser,
4600     #
4601     # Returns: void
4602     #
4603     sub vGetSaveSearch {
4604    
4605    
4606     my ($SearchString, $Database);
4607     my ($HeaderName, $SearchFrequency, $DeliveryFormat, $DeliveryMethod);
4608     my ($JavaScript, $EmailAddress);
4609     my ($Value, @Values, %Value, $ValueEntry);
4610    
4611    
4612     # Return an error if the remote user name/account directory is not defined
4613     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4614     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4615     &vSendHTMLFooter;
4616     return;
4617     }
4618    
4619    
4620     $JavaScript = '<SCRIPT LANGUAGE="JavaScript">
4621     <!-- hide
4622     function checkForm( Form ) {
4623     if ( !checkField( Form.SearchName, "Search name" ) )
4624     return false
4625     return true
4626     }
4627     function checkField( Field, Name ) {
4628     if ( Field.value == "" ) {
4629     errMsg( Field, "Niste ispunili polje \'"+Name+"\' ." )
4630     return false
4631     }
4632     else {
4633     return true
4634     }
4635     }
4636     function errMsg( Field, Msg ) {
4637     alert( Msg )
4638     Field.focus()
4639     return
4640     }
4641     // -->
4642     </SCRIPT>
4643     ';
4644    
4645    
4646    
4647     # Make sure that we send the header
4648     &vSendHTMLHeader("Save this Search", $JavaScript);
4649     undef(%Value);
4650     &vSendMenuBar(%Value);
4651    
4652    
4653     # Give the user a form to fill out
4654     print("<H3> Saving a search: </H3>\n");
4655    
4656    
4657    
4658     # Get information from the XML saved search file
4659     ($HeaderName, %Value) = &shGetHashFromXMLFile($main::UserSettingsFilePath);
4660    
4661     $SearchFrequency = $Value{'SearchFrequency'};
4662     $DeliveryFormat = $Value{'DeliveryFormat'};
4663     $DeliveryMethod = $Value{'DeliveryMethod'};
4664     $EmailAddress = $Value{'EmailAddress'};
4665    
4666    
4667     # Print up the table start
4668     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4669    
4670     # Start the form
4671     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetSaveSearch\" onSubmit=\"return checkForm(this)\" METHOD=POST>\n");
4672    
4673     # Send the buttons
4674     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=2> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\"> <INPUT TYPE=SUBMIT VALUE=\"Save this Search\"> </TD></TR>\n");
4675    
4676     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4677    
4678     # Print up the search string
4679     $SearchString = &sMakeSearchString(%main::FormData);
4680     if ( defined($SearchString) ) {
4681     $SearchString =~ s/{.*?}//gs;
4682     $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
4683     }
4684     $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
4685     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
4686    
4687     # Get the local databases from the search and list their descriptions
4688     if ( defined($main::FormData{'Database'}) ) {
4689    
4690     # Initialize the temp list
4691     undef(@Values);
4692    
4693     foreach $Database ( sort(split(/\0/, $main::FormData{'Database'})) ) {
4694     $Value = &lEncodeURLData($Database);
4695     push @Values, sprintf("<A HREF=\"$ENV{'SCRIPT_NAME'}/GetDatabaseInfo?Database=$Value\" OnMouseOver=\"self.status='Get Information about the $main::DatabaseDescriptions{$Database} database'; return true\"> $main::DatabaseDescriptions{$Database} </A> ");
4696     }
4697    
4698     # Print the list if there are any entries in it
4699     if ( scalar(@Values) > 0 ) {
4700     printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n", (scalar(@Values) > 1) ? "s" : "", join(", ", @Values));
4701     }
4702     }
4703    
4704     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4705    
4706     # Send the search name and search description fields
4707     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Search Name (required): </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"SearchName\" TYPE=TEXT SIZE=45> </TD></TR>\n");
4708    
4709     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Search Description: </TD> <TD ALIGN=LEFT VALIGN=TOP> <TEXTAREA INPUT NAME=\"SearchDescription\" COLS=45 ROWS=6 WRAP=VIRTUAL></TEXTAREA> </TD></TR>\n");
4710    
4711     if ( defined($main::FormData{'RfDocument'}) ) {
4712     print("<TR>\n");
4713     &bDisplayDocuments("Feedback Document", $main::FormData{'RfDocument'}, "RfDocument", undef, undef, 1);
4714     print("</TR>\n");
4715     }
4716    
4717    
4718     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4719    
4720     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Kliknite na ovaj kvadratiæ ako ¾elite postojeæi folder s istim imenom zamijeniti ovim novim: </TD> <TD ALIGN=LEFT VALIGN=TOP><INPUT TYPE=\"checkbox\" NAME=\"OverWrite\" VALUE=\"yes\"> </TD></TR>\n");
4721    
4722    
4723    
4724     # Are regular searches enabled?
4725     if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4726    
4727     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4728    
4729     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Check to run this search on a regular basis: </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT TYPE=CHECKBOX VALUE=\"yes\" NAME=\"Regular\"> </TD></TR>\n");
4730    
4731     # Send a pull-down which allows the user to select the automatic search frequency
4732     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the search frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"SearchFrequency\">\n");
4733     foreach $ValueEntry ( @main::SearchFrequencies ) {
4734     $Value = (defined($SearchFrequency) && ($SearchFrequency eq $ValueEntry)) ? "SELECTED" : "";
4735     print("<OPTION VALUE=\"$ValueEntry\" $Value> $ValueEntry \n");
4736     }
4737     print("</SELECT> </TD></TR>\n");
4738    
4739     # Send a pull-down which allows the user to select the automatic search delivery format
4740     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryFormat\">\n");
4741     foreach $ValueEntry ( sort(keys(%main::DeliveryFormats)) ) {
4742     $Value = (defined($DeliveryFormat) && ($DeliveryFormat eq $ValueEntry)) ? "SELECTED" : "";
4743     print("<OPTION VALUE=\"$ValueEntry\" $Value> $main::DeliveryFormats{$ValueEntry}\n");
4744     }
4745     print("</SELECT> </TD></TR>\n");
4746    
4747     # Send a pull-down which allows the user to select the automatic search delivery method
4748     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the delivery method: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryMethod\">\n");
4749     foreach $ValueEntry ( sort(keys(%main::DeliveryMethods)) ) {
4750     $Value = (defined($DeliveryMethod) && ($DeliveryMethod eq $ValueEntry)) ? "SELECTED" : "";
4751     print("<OPTION VALUE=\"$ValueEntry\" $Value> $main::DeliveryMethods{$ValueEntry}\n");
4752     }
4753     print("</SELECT> </TD></TR>\n");
4754     }
4755    
4756    
4757     # List the hidden fields
4758     %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
4759     foreach $Value ( keys(%Value) ) {
4760     foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
4761     print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
4762     }
4763     }
4764    
4765     print("</FORM>\n");
4766     print("</TABLE>\n");
4767    
4768     if ( !defined($EmailAddress) &&
4769     (defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes")) ) {
4770     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4771     print("<B>Note: </B> You have not specified an email address in your settings, you will need to specify it if you want to run this search on a regular basis. <P>\n");
4772     }
4773    
4774    
4775     # Bail from saving the search
4776     bailFromGetSaveSearch:
4777    
4778     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4779     undef(%Value);
4780     &vSendMenuBar(%Value);
4781    
4782     &vSendHTMLFooter;
4783    
4784     return;
4785    
4786     }
4787    
4788    
4789    
4790    
4791    
4792    
4793     #--------------------------------------------------------------------------
4794     #
4795     # Function: vSetSaveSearch()
4796     #
4797     # Purpose: This function saves that search and search name in a search file
4798     #
4799     # Called by:
4800     #
4801     # Parameters: void
4802     #
4803     # Global Variables: %main::ConfigurationData, %main::FormData,
4804     # $main::UserSettingsFilePath, $main::RemoteUser,
4805     #
4806     # Returns: void
4807     #
4808     sub vSetSaveSearch {
4809    
4810    
4811     my ($SearchAndRfDocumentURL, $SearchString);
4812     my (@SavedSearchList, $SavedSearchEntry, $SavedSearchFilePath);
4813     my ($EmailAddress, $SearchName, $CreationTime, $LastRunTime);
4814     my ($Value, %Value);
4815    
4816    
4817     # Return an error if the remote user name/account directory is not defined
4818     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4819     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4820     &vSendHTMLFooter;
4821     return;
4822     }
4823    
4824    
4825     # Make sure that we send the header
4826     &vSendHTMLHeader("Saèuvana pretra¾ivanja", undef);
4827     undef(%Value);
4828     &vSendMenuBar(%Value);
4829    
4830    
4831     # Check that the required fields are filled in
4832     if ( !defined($main::FormData{'SearchName'}) ) {
4833    
4834     # A required field is missing, so we suggest corrective action to the user.
4835     print("<H3> Snimanje pretra¾ivanja: </H3>\n");
4836     print("<H3><CENTER> Oprostite, nedostaju neke informacije. </CENTER></H3>\n");
4837     print("<P>\n");
4838     print("Polje <B>'search name'</B> mora biti ispunjeno da bi se moglo saèuvati pretra¾ivanje.<P>\n");
4839     print("Kliknite na <B>'Back'</B> u svom browseru, popunite polje koje nedostaje i poku¹ajte ponovo.\n");
4840     print("<P>\n");
4841    
4842     goto bailFromSetSaveSearch;
4843    
4844     }
4845    
4846    
4847     # Read all the saved search files
4848     opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4849     @SavedSearchList = map("$main::UserAccountDirectoryPath/$_", grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)));
4850     closedir(USER_ACCOUNT_DIRECTORY);
4851    
4852    
4853     # Loop over each saved search file checking that it is valid
4854     for $SavedSearchEntry ( @SavedSearchList ) {
4855    
4856     $SearchName = &sGetTagValueFromXMLFile($SavedSearchEntry, "SearchName");
4857    
4858     if ( $SearchName eq $main::FormData{'SearchName'} ) {
4859     $SavedSearchFilePath = $SavedSearchEntry;
4860     last;
4861     }
4862     }
4863    
4864     # Check that the saved search file does not already exist
4865     if ( defined($SavedSearchFilePath) && ($SavedSearchFilePath ne "")
4866     && !(defined($main::FormData{'OverWrite'}) && ($main::FormData{'OverWrite'} eq "yes")) ) {
4867    
4868     # There is already a saved search with this name, so we suggest corrective action to the user.
4869     print("<H3> Saving a Search: </H3>\n");
4870     print("<H3><CENTER> Sorry, there is already a saved search with this name. </CENTER></H3>\n");
4871     print("<P>\n");
4872     print("Click <B>'back'</B> on your browser, change the <B>'search name'</B> and try again, \n");
4873     print("alternatively you can check the box which allows you to automatically over-write a saved search with the same name.\n");
4874     print("<P>\n");
4875    
4876     goto bailFromSetSaveSearch;
4877     }
4878    
4879    
4880     # Get the email address of this user
4881     $Value = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
4882    
4883     # Check this user has an email address defined if they want to run the search on a regular basis
4884     if ( !defined($Value) && (defined($main::FormData{'Regular'}) && ($main::FormData{'Regular'} eq "yes")) ) {
4885    
4886     # Regular delivery was requested, but the email address was not specified in the settings
4887     print("<H3> Saving a Search: </H3>\n");
4888     print("<H3><CENTER> Sorry, your email address is not specified in your settings. </CENTER></H3>\n");
4889     print("<P>\n");
4890     print("You need to specify your email address in your settings if you want this search to run on a regular basis, \n");
4891     print("without your email address, we are not able to send you the search result. <P>\n");
4892     print("Click the <B>'Settings'</B> option from the menu sidebar, fill in your email address and save the settings, \n");
4893     print("then click <B>'back'</B> on your browser three times to go back to the form which allows you to save a search.\n");
4894     print("<P>\n");
4895    
4896     goto bailFromSetSaveSearch;
4897     }
4898    
4899    
4900     # All the checks have been passed, so we can go ahead and save the search
4901    
4902     $CreationTime = time();
4903     $LastRunTime = $CreationTime;
4904    
4905     # Erase the search frequency and the delivery method if this is not a regular search
4906     if ( !(defined($main::FormData{'Regular'}) && ($main::FormData{'Regular'} eq "yes")) ) {
4907     $main::FormData{'SearchFrequency'} = "";
4908     $main::FormData{'DeliveryFormat'} = "";
4909     $main::FormData{'DeliveryMethod'} = "";
4910     $LastRunTime = "";
4911     }
4912    
4913    
4914     # Get the URL search string
4915     $SearchAndRfDocumentURL = &sMakeSearchAndRfDocumentURL(%main::FormData);
4916    
4917     # Save the search
4918     if ( &iSaveSearch(undef, $main::FormData{'SearchName'}, $main::FormData{'SearchDescription'}, $SearchAndRfDocumentURL, $main::FormData{'SearchFrequency'}, $main::FormData{'DeliveryFormat'}, $main::FormData{'DeliveryMethod'}, "Active", $CreationTime, $LastRunTime) ) {
4919    
4920     print("<H3> Saving a Search: </H3>\n");
4921     print("<P>\n");
4922     print("<H3><CENTER> Your search was successfully saved. </CENTER></H3>\n");
4923    
4924     # Delete the overwritten search file
4925     if ( defined($SavedSearchFilePath) && ($SavedSearchFilePath ne "") ) {
4926     unlink($SavedSearchFilePath);
4927     }
4928     }
4929     else {
4930    
4931     # The search could not be saved, so we inform the user of the fact
4932     &vHandleError("Saving a Search", "Sorry, we failed to save this search");
4933     goto bailFromSetSaveSearch;
4934     }
4935    
4936    
4937     # Bail from saving the search
4938     bailFromSetSaveSearch:
4939    
4940     print("<CENTER><HR WIDTH=50%></CENTER>\n");
4941     undef(%Value);
4942     &vSendMenuBar(%Value);
4943    
4944     &vSendHTMLFooter;
4945    
4946     return;
4947    
4948     }
4949    
4950    
4951    
4952    
4953    
4954    
4955     #--------------------------------------------------------------------------
4956     #
4957     # Function: vListSavedSearch()
4958     #
4959     # Purpose: This function allows the user list the saved searches and
4960     # sets up the links allowing the user to get a search form
4961     # filled with the search
4962     #
4963     # Called by:
4964     #
4965     # Parameters: void
4966     #
4967     # Global Variables: %main::ConfigurationData, %main::FormData,
4968     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
4969     # $main::SavedSearchFileNamePrefix, $main::RemoteUser
4970     #
4971     # Returns: void
4972     #
4973     sub vListSavedSearch {
4974    
4975     my (@SavedSearchList, @QualifiedSavedSearchList, $SavedSearchEntry, $HeaderName, $SearchString, $Database);
4976     my ($SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $LastRunTime);
4977     my (@Values, $Value, %Value);
4978    
4979    
4980     # Return an error if the remote user name/account directory is not defined
4981     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4982     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4983     &vSendHTMLFooter;
4984     return;
4985     }
4986    
4987    
4988     # Make sure that we send the header
4989     &vSendHTMLHeader("Saèuvana pretra¾ivanja", undef);
4990     undef(%Value);
4991     $Value{'ListSavedSearch'} = "ListSavedSearch";
4992     &vSendMenuBar(%Value);
4993     undef(%Value);
4994    
4995    
4996     # Read all the saved search files
4997     opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4998     @SavedSearchList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
4999     closedir(USER_ACCOUNT_DIRECTORY);
5000    
5001    
5002     # Loop over each search history file checking that it is valid
5003     for $SavedSearchEntry ( @SavedSearchList ) {
5004    
5005     # Get the header name from the XML saved search file
5006     $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchEntry);
5007    
5008     # Check that the entry is valid and add it to the qualified list
5009     if ( defined($HeaderName) && ($HeaderName eq "SavedSearch") ) {
5010     push @QualifiedSavedSearchList, $SavedSearchEntry;
5011     }
5012     else {
5013     # Else we delete this invalid saved search file
5014     unlink($SavedSearchEntry);
5015     }
5016     }
5017    
5018    
5019     # Print out the saved searches
5020     print("<H3> Saèuvana pretra¾ivanja: </H3>\n");
5021    
5022    
5023    
5024     # Print up the saved searches, if there is none, we put up a nice message
5025     if ( scalar(@QualifiedSavedSearchList) > 0 ) {
5026    
5027     # Start the table
5028     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
5029    
5030     # Start the form
5031     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
5032    
5033    
5034     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> \n");
5035     print("<SELECT NAME=\"Action\">\n");
5036     print("<OPTION VALUE=\"ActivateSavedSearch\">Aktiviraj oznaèena saèuvana pretra¾ivanja\n");
5037     print("<OPTION VALUE=\"SuspendSavedSearch\">Stavi u mirovanje oznaèena saèuvana pretra¾ivanja\n");
5038     print("<OPTION VALUE=\"DeleteSavedSearch\">Obri¹i oznaèena saèuvana pretra¾ivanja\n");
5039     print("</SELECT>\n");
5040     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
5041     print("</TD></TR>\n");
5042    
5043     for $SavedSearchEntry ( @QualifiedSavedSearchList ) {
5044    
5045     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
5046    
5047     # Get information from the XML saved search file
5048     ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchEntry);
5049    
5050     # Get the saved search file name and encode it
5051     $SavedSearchEntry = ($SavedSearchEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $SavedSearchEntry;
5052     $SavedSearchEntry = &lEncodeURLData($SavedSearchEntry);
5053    
5054    
5055     $SearchName = $Value{'SearchName'};
5056     $SearchDescription = $Value{'SearchDescription'};
5057     $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
5058     $SearchFrequency = $Value{'SearchFrequency'};
5059     $SearchStatus = $Value{'SearchStatus'};
5060     $DeliveryFormat = $Value{'DeliveryFormat'};
5061     $DeliveryMethod = $Value{'DeliveryMethod'};
5062     $CreationTime = $Value{'CreationTime'};
5063     $LastRunTime = $Value{'LastRunTime'};
5064    
5065     # Parse the URL Search string into a hash so that we can get at it's components
5066     %Value = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
5067    
5068     $SearchString = &sMakeSearchString(%Value);
5069     if ( defined($SearchString) ) {
5070     $SearchString =~ s/{.*?}//gs;
5071     $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
5072     }
5073     $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
5074    
5075     # Print the link
5076     print("<TR><TD ALIGN=LEFT VALIGN=TOP><INPUT TYPE=\"checkbox\" NAME=\"SavedSearchObject\" VALUE=\"$SavedSearchEntry\"> </TD><TD ALIGN=LEFT VALIGN=TOP> Naziv: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchName </TD></TR>\n");
5077    
5078     # Print the search description
5079     $SearchDescription = defined($SearchDescription) ? $SearchDescription : "(Nije naveden)";
5080     $SearchDescription =~ s/\n/<BR>/g;
5081     $SearchDescription =~ s/\r/<BR>/g;
5082     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDescription </TD></TR>\n");
5083    
5084     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
5085    
5086     # Get the local databases from the search and list their descriptions
5087     if ( defined($Value{'Database'}) ) {
5088    
5089     # Initialize the temp list
5090     undef(@Values);
5091    
5092     # Loop over each database
5093     foreach $Database ( split(/\0/, $Value{'Database'}) ) {
5094     $Value = &lEncodeURLData($Database);
5095     push @Values, sprintf("<A HREF=\"$ENV{'SCRIPT_NAME'}/GetDatabaseInfo?Database=$Value\" OnMouseOver=\"self.status='Get Information about the $main::DatabaseDescriptions{$Database} database'; return true\"> $main::DatabaseDescriptions{$Database} </A> ");
5096     }
5097    
5098     # Print the list if there are any entries in it
5099     if ( scalar(@Values) > 0 ) {
5100     printf("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n", (scalar(@Values) > 1) ? "s" : "", join(", ", @Values));
5101     }
5102     }
5103    
5104    
5105     if ( defined($Value{'RfDocument'}) ) {
5106     print("<TR><TD></TD>\n");
5107     &bDisplayDocuments("Feedback Document", $Value{'RfDocument'}, "RfDocument", undef, undef, 1);
5108     print("</TR>\n");
5109     }
5110    
5111     undef(%Value);
5112    
5113    
5114     if ( defined($SearchFrequency) || defined($DeliveryFormat) || defined($DeliveryMethod) ) {
5115     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Run: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchFrequency </TD></TR>\n");
5116     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> $main::DeliveryFormats{$DeliveryFormat} </TD></TR>\n");
5117     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Delivery method : </TD> <TD ALIGN=LEFT VALIGN=TOP> $main::DeliveryMethods{$DeliveryMethod} </TD></TR>\n");
5118     }
5119    
5120     $Value = &sGetPrintableDateFromTime($CreationTime);
5121     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5122    
5123    
5124     if ( defined($SearchFrequency) || defined($DeliveryFormat) || defined($DeliveryMethod) ) {
5125    
5126     if ( defined($LastRunTime) ) {
5127     $Value = &sGetPrintableDateFromTime($LastRunTime);
5128     print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Last Run: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5129     }
5130    
5131     printf("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Status: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>",
5132     (defined($SearchStatus) && ($SearchStatus eq "Active")) ? "Active" : "Suspended");
5133    
5134     }
5135    
5136     print("<TR><TD ALIGN=LEFT VALIGN=TOP></TD><TD ALIGN=LEFT VALIGN=TOP></TD> <TD ALIGN=LEFT VALIGN=TOP> <A HREF=\"$ENV{'SCRIPT_NAME'}/GetSavedSearch?SavedSearchObject=$SavedSearchEntry\" OnMouseOver=\"self.status='Display the search form with this search'; return true\"> [ Otvori formu za pretra¾ivanje s upisanim ovim pretra¾ivanjem ] </A> </TD></TR>\n");
5137     }
5138    
5139     print("</FORM></TABLE>\n");
5140     }
5141     else {
5142     print("<H3><CENTER> Sorry, currently, there are no saved searches. </CENTER></H3>\n");
5143     }
5144    
5145    
5146    
5147    
5148     # Bail from displaying saved searches
5149     bailFromDisplaySavedSearch:
5150    
5151     print("<CENTER><HR WIDTH=50%></CENTER>\n");
5152     undef(%Value);
5153     $Value{'ListSavedSearch'} = "ListSavedSearch";
5154     &vSendMenuBar(%Value);
5155     undef(%Value);
5156    
5157     &vSendHTMLFooter;
5158    
5159    
5160     return;
5161    
5162     }
5163    
5164    
5165    
5166    
5167    
5168    
5169     #--------------------------------------------------------------------------
5170     #
5171     # Function: vGetSavedSearch()
5172     #
5173     # Purpose: This function gets a saved search.
5174     #
5175     # Called by:
5176     #
5177     # Parameters: void
5178     #
5179     # Global Variables: %main::ConfigurationData, %main::FormData,
5180     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5181     # $main::SavedSearchFileNamePrefix, $main::RemoteUser
5182     #
5183     # Returns: void
5184     #
5185     sub vGetSavedSearch {
5186    
5187     my ($HeaderName, $SavedSearchFilePath, $SearchAndRfDocumentURL, $DefaultSearch);
5188     my ($Value, %Value);
5189    
5190    
5191     # Return an error if the remote user name/account directory is not defined
5192     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5193     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5194     &vSendHTMLFooter;
5195     return;
5196     }
5197    
5198    
5199     # Set the saved search file path
5200     $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'SavedSearchObject'};
5201    
5202    
5203     # Check to see if the XML saved search file requested is there
5204     if ( ! -f $SavedSearchFilePath ) {
5205     # Could not find the saved search file
5206     &vHandleError("Prikaz saèuvaniog pretra¾ivanja", "Sorry, we cant to access this saved search object because it is not there");
5207     &vSendHTMLFooter;
5208     return;
5209     }
5210    
5211    
5212    
5213     # Get the data from the XML saved search file
5214     $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchFilePath);
5215    
5216     # Check that the entry is valid
5217     if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
5218     &vHandleError("Prikaz saèuvaniog pretra¾ivanja", "Sorry, this saved search object is invalid");
5219     &vSendHTMLFooter;
5220     return;
5221     }
5222    
5223    
5224     # All is fine, so we hand over the hash and get the search
5225     %main::FormData = &hParseURLIntoHashTable(&sGetTagValueFromXMLFile($SavedSearchFilePath, 'SearchAndRfDocumentURL'));
5226    
5227     $ENV{'PATH_INFO'} = "/GetSearch";
5228    
5229     # Display the search form, it will autoset itself from %main::FormData
5230     &vGetSearch;
5231    
5232     return;
5233    
5234     }
5235    
5236    
5237    
5238    
5239    
5240    
5241     #--------------------------------------------------------------------------
5242     #
5243     # Function: vProcessSavedSearch()
5244     #
5245     # Purpose: This function processes a saved search.
5246     #
5247     # Called by:
5248     #
5249     # Parameters: void
5250     #
5251     # Global Variables: %main::ConfigurationData, %main::FormData,
5252     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5253     # $main::SavedSearchFileNamePrefix, $main::RemoteUser
5254     #
5255     # Returns: void
5256     #
5257     sub vProcessSavedSearch {
5258    
5259     my ($Title, $HeaderName, $SavedSearchFilePath, $SavedSearchObject);
5260     my ($Value, %Value);
5261    
5262    
5263     # Return an error if the remote user name/account directory is not defined
5264     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5265     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5266     &vSendHTMLFooter;
5267     return;
5268     }
5269    
5270    
5271     # Set the title
5272     if ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
5273     $Title = "Obri¹i saèuvana pretra¾ivanja";
5274     }
5275     elsif ( $ENV{'PATH_INFO'} eq "/ActivateSavedSearch" ) {
5276     $Title = "Aktiviraj saèuvana pretra¾ivanja";
5277     }
5278     elsif ( $ENV{'PATH_INFO'} eq "/SuspendSavedSearch" ) {
5279     $Title = "Stavi u mirovanje saèuvana pretra¾ivanja";
5280     }
5281    
5282    
5283     # Make sure that we send the header
5284     &vSendHTMLHeader($Title, undef);
5285     undef(%Value);
5286     &vSendMenuBar(%Value);
5287    
5288    
5289     print("<H3> $Title: </H3>\n");
5290    
5291     # Check to see if the saved search object is defined
5292     if ( ! defined($main::FormData{'SavedSearchObject'}) ) {
5293     # Could not find the saved search object
5294     print("<H3><CENTER> Sorry, no searches were selected. </CENTER></H3>\n");
5295     print("<P>\n");
5296     print("You need to select at least one saved search in order to be able to perform an action on it.\n");
5297     print("<P>\n");
5298     goto bailFromProcessSavedSearch;
5299     }
5300    
5301    
5302    
5303     # Loop over each saved search
5304     foreach $SavedSearchObject ( split(/\0/, $main::FormData{'SavedSearchObject'}) ) {
5305    
5306     # Set the saved search file path
5307     $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/" . $SavedSearchObject;
5308    
5309     # Check to see if the XML saved search file requested is there
5310     if ( ! -f $SavedSearchFilePath ) {
5311     next;
5312     }
5313    
5314     # Get information from the XML saved search file
5315     ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchFilePath);
5316    
5317     # Check that the entry is valid
5318     if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
5319     next;
5320     }
5321    
5322    
5323     if ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
5324     if ( unlink($SavedSearchFilePath) ) {
5325     printf("<P>Successfully deleted: %s\n", $Value{'SearchName'});
5326     }
5327     else {
5328     printf("<P>Failed to delete: %s\n", $Value{'SearchName'});
5329     }
5330     }
5331     elsif ( ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") || ($ENV{'PATH_INFO'} eq "/SuspendSavedSearch") ) {
5332    
5333     if ( !defined($Value{'SearchStatus'}) ) {
5334     printf("<P>Could not %s: %s, as it is not a regular search\n",
5335     ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activate" : "suspend", $Value{'SearchName'});
5336     }
5337     else {
5338    
5339     $Value{'SearchStatus'} = ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "Active" : "Inactive" ;
5340    
5341     if ( &iSaveXMLFileFromHash($SavedSearchFilePath, "SavedSearch", %Value) ) {
5342     printf("<P>Successfully %s: %s\n",
5343     ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activated" : "suspended", $Value{'SearchName'});
5344     }
5345     else {
5346     printf("<P>Failed to %s: %s\n",
5347     ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activated" : "suspended", $Value{'SearchName'});
5348     }
5349     }
5350     }
5351     }
5352    
5353     print("<P>\n");
5354    
5355     # Bail from processing the saved search
5356     bailFromProcessSavedSearch:
5357    
5358     print("<CENTER><HR WIDTH=50%></CENTER>\n");
5359     undef(%Value);
5360     &vSendMenuBar(%Value);
5361    
5362     &vSendHTMLFooter;
5363    
5364     return;
5365    
5366     }
5367    
5368    
5369    
5370    
5371    
5372    
5373     #--------------------------------------------------------------------------
5374     #
5375     # Function: vGetSaveFolder()
5376     #
5377     # Purpose: This function displays a form to the user allowing them to
5378     # save documents to a folder
5379     #
5380     # Called by:
5381     #
5382     # Parameters: void
5383     #
5384     # Global Variables: %main::ConfigurationData, %main::FormData,
5385     # $main::UserSettingsFilePath, $main::RemoteUser,
5386     #
5387     # Returns: void
5388     #
5389     sub vGetSaveFolder {
5390    
5391    
5392     my ($JavaScript);
5393     my ($Value, @Values, %Value, $ValueEntry);
5394    
5395    
5396    
5397     # Return an error if the remote user name/account directory is not defined
5398     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5399     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5400     &vSendHTMLFooter;
5401     return;
5402     }
5403    
5404    
5405     $JavaScript = '<SCRIPT LANGUAGE="JavaScript">
5406     <!-- hide
5407     function checkForm( Form ) {
5408     if ( !checkField( Form.FolderName, "Folder name" ) )
5409     return false
5410     return true
5411     }
5412     function checkField( Field, Name ) {
5413     if ( Field.value == "" ) {
5414     errMsg( Field, "Niste ispunili polje \'"+Name+"\'." )
5415     return false
5416     }
5417     else {
5418     return true
5419     }
5420     }
5421     function errMsg( Field, Msg ) {
5422     alert( Msg )
5423     Field.focus()
5424     return
5425     }
5426     // -->
5427     </SCRIPT>
5428     ';
5429    
5430    
5431     # Make sure that we send the header
5432     &vSendHTMLHeader("Saving a Document Folder", $JavaScript);
5433     undef(%Value);
5434     &vSendMenuBar(%Value);
5435    
5436    
5437     # Check that at least one document was selected
5438     if ( !defined($main::FormData{'Document'}) && !defined($main::FormData{'Documents'}) ) {
5439     print("<H3>Saving a Document Folder:</H3>\n");
5440     print("<H3><CENTER>Sorry, no document(s) were selected for saving.</CENTER></H3>\n");
5441     print("<P>\n");
5442     print("There needs to be a least one document selected in order to save it.\n");
5443     print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
5444     goto bailFromGetSaveFolder;
5445     }
5446    
5447    
5448     # Print up the title
5449     print("<H3> Snimanje foldera s dokumentima: </H3>\n");
5450    
5451     # Print up the form
5452     printf("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetSaveFolder\" onSubmit=\"return checkForm(this)\" METHOD=POST>\n");
5453    
5454     # Print up the table start
5455     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
5456    
5457     # Send the buttons
5458     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=2> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\"> <INPUT TYPE=SUBMIT VALUE=\"Save this Folder\"> </TD></TR>\n");
5459    
5460     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5461    
5462     # Send the fields
5463     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Ime foldera: </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"FolderName\" TYPE=TEXT SIZE=45> </TD></TR>\n");
5464    
5465     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Opis foldera: </TD> <TD ALIGN=LEFT VALIGN=TOP> <TEXTAREA INPUT NAME=\"FolderDescription\" COLS=45 ROWS=6 WRAP=VIRTUAL></TEXTAREA> </TD></TR>\n");
5466    
5467     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5468    
5469     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Kliknite na ovaj kvadratiæ ako ¾elite postojeæi folder s istim imenom zamijeniti ovim novim: </TD> <TD ALIGN=LEFT VALIGN=TOP><INPUT TYPE=\"checkbox\" NAME=\"OverWrite\" VALUE=\"yes\"> </TD></TR>\n");
5470    
5471     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5472    
5473     # List the documents
5474     if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
5475    
5476     # Undefine the hash table in preparation
5477     undef(%Value);
5478    
5479     # Add document that were specifically selected
5480     if ( defined($main::FormData{'Document'}) ) {
5481     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5482     $Value{$Value} = $Value;
5483     }
5484     }
5485     # Otherwise add documents that were selected by default
5486     elsif ( defined($main::FormData{'Documents'}) ) {
5487     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5488     $Value{$Value} = $Value;
5489     }
5490     }
5491    
5492     # Assemble the new content
5493     $main::FormData{'Document'} = join("\0", keys(%Value));
5494    
5495     # Delete the old content
5496     delete($main::FormData{'Documents'});
5497    
5498    
5499     if ( defined($main::FormData{'Document'}) ) {
5500     print("<TR>\n");
5501     &bDisplayDocuments("Document", $main::FormData{'Document'}, "Document", undef, undef, 1);
5502     print("</TR>\n");
5503     }
5504     }
5505    
5506    
5507    
5508     # List the hidden fields
5509     %Value = &hParseURLIntoHashTable(&sMakeDocumentURL(%main::FormData));
5510     foreach $Value ( keys(%Value) ) {
5511     foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
5512     print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
5513     }
5514     }
5515    
5516    
5517     # Retain the 'from' folder name if it is defined as these documents are coming from it
5518     if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5519     print("<INPUT TYPE=HIDDEN NAME=\"FromDocumentFolderObject\" VALUE=\"$main::FormData{'FromDocumentFolderObject'}\">\n");
5520     }
5521    
5522    
5523     # Retain the 'merge' folder name if it is defined as these documents are coming from them
5524     if ( defined($main::FormData{'MergeDocumentFolderObject'}) ) {
5525     foreach $Value ( split(/\0/, $main::FormData{'MergeDocumentFolderObject'}) ) {
5526     print("<INPUT TYPE=HIDDEN NAME=\"MergeDocumentFolderObject\" VALUE=\"$Value\">\n");
5527     }
5528     }
5529    
5530     print("</TABLE>\n");
5531     print("</FORM>\n");
5532    
5533    
5534     # Bail from saving the document folder
5535     bailFromGetSaveFolder:
5536    
5537     print("<CENTER><HR WIDTH=50%></CENTER>\n");
5538     undef(%Value);
5539     &vSendMenuBar(%Value);
5540    
5541     &vSendHTMLFooter;
5542    
5543     return;
5544    
5545     }
5546    
5547    
5548    
5549    
5550    
5551    
5552     #--------------------------------------------------------------------------
5553     #
5554     # Function: vSetSaveFolder()
5555     #
5556     # Purpose: This function saves that search and search name in a search file
5557     #
5558     # Called by:
5559     #
5560     # Parameters: void
5561     #
5562     # Global Variables: %main::ConfigurationData, %main::FormData,
5563     # $main::UserSettingsFilePath, $main::RemoteUser,
5564     #
5565     # Returns: void
5566     #
5567     sub vSetSaveFolder {
5568    
5569     my ($DocumentFolderFilePath, $HeaderName);
5570     my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5571     my (@DocumentFolderList, $DocumentFolderEntry);
5572     my ($Document, %Document);
5573     my (%Value, @Values, $Value);
5574    
5575    
5576    
5577     # Return an error if the remote user name/account directory is not defined
5578     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5579     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5580     &vSendHTMLFooter;
5581     return;
5582     }
5583    
5584    
5585    
5586     # Make sure that we send the header
5587     &vSendHTMLHeader("Saving a Document Folder", undef);
5588     undef($Value);
5589     &vSendMenuBar(%Value);
5590    
5591    
5592     # Check that at least one document was selected
5593     if ( !defined($main::FormData{'Document'}) && !defined($main::FormData{'Documents'}) ) {
5594    
5595     print("<H3>Saving a Document Folder:</H3>\n");
5596     print("<H3><CENTER>Sorry, no document(s) were selected for saving.</CENTER></H3>\n");
5597     print("<P>\n");
5598     print("There needs to be a least one document selected in order to save it.\n");
5599     print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
5600    
5601     goto bailFromSetSaveFolder;
5602     }
5603    
5604    
5605     # Check that the required fields are filled in
5606     if ( !(defined($main::FormData{'FolderName'}) || defined($main::FormData{'DocumentFolderObject'})) ) {
5607    
5608     # A required field is missing, so we suggest corrective action to the user.
5609     print("<H3> Spremanje foldera s dokumentima: </H3>\n");
5610     print("<H3><CENTER> Oprostite, nedostaju neke informacije. </CENTER></H3>\n");
5611     print("<P>\n");
5612     print("Polje <B>'folder name'</B> mora biti ispunjeno da bi se mogao kreirati folder s dokumentima.<P>\n");
5613     print("Kliknite na <B>'Back'</B> u svom browseru, ispunite polje koje nedostaje i poku¹ajtwe ponovo.\n");
5614     print("<P>\n");
5615    
5616     goto bailFromSetSaveFolder;
5617     }
5618    
5619    
5620    
5621     # Check that the folder is there if we are saving to an existing folder
5622     if ( defined($main::FormData{'DocumentFolderObject'}) ) {
5623    
5624     # Check the old document folder if it is defined
5625     if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5626    
5627     # Set the document folder file path
5628     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'FromDocumentFolderObject'};
5629    
5630     # Check to see if the old XML saved search file requested is there
5631     if ( ! -f $DocumentFolderFilePath ) {
5632     # Could not find the old saved search file
5633     &vHandleError("Saving a Document Folder", "Sorry, we cant to access this document folder object because it is not there");
5634     goto bailFromSetSaveFolder;
5635     }
5636    
5637     # Get information from the XML document folder file
5638     $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
5639    
5640     # Check that the entry is valid
5641     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5642     &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5643     goto bailFromSetSaveFolder;
5644     }
5645     }
5646    
5647    
5648     # Set the document folder file path
5649     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
5650    
5651     # Check to see if the XML saved search file requested is there
5652     if ( ! -f $DocumentFolderFilePath ) {
5653     # Could not find the saved search file
5654     &vHandleError("Saving a Document Folder", "Sorry, we cant to access this document folder object because it is not there");
5655     goto bailFromSetSaveFolder;
5656     }
5657    
5658     # Get information from the XML document folder file
5659     $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
5660    
5661     # Check that the entry is valid
5662     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5663     &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5664     goto bailFromSetSaveFolder;
5665     }
5666     }
5667     elsif ( defined($main::FormData{'FolderName'}) ) {
5668    
5669     # Get the document folder hash
5670     %Value = &hGetDocumentFolders;
5671    
5672     # Set the path/flag
5673     $DocumentFolderFilePath = $Value{$main::FormData{'FolderName'}};
5674    
5675     # Check that the document folder file does not already exist
5676     if ( defined($DocumentFolderFilePath) && !(defined($main::FormData{'OverWrite'}) && ($main::FormData{'OverWrite'} eq "yes")) ) {
5677    
5678     # There is already a document folder with this name, so we suggest corrective action to the user.
5679     print("<H3> Snimanje foldera s dokumentima: </H3>\n");
5680     print("<H3><CENTER> Oprostite, veæ postoji folder s tim imenom. </CENTER></H3>\n");
5681     print("<P>\n");
5682     print("Kliknite na <B>'Back'</B> u svom browseru, promijenite <B>'ime foldera'</B> i poku¹ate ponovo. \n");
5683     print("Alternativno, klikom na kvadratiæ, mo¾ete odabrati da ¾elite postojeæi folder zamijeniti ovim.\n");
5684     print("<P>\n");
5685    
5686     goto bailFromSetSaveFolder;
5687     }
5688     }
5689    
5690    
5691     # Save information in the folder
5692     if ( defined($main::FormData{'DocumentFolderObject'}) ) {
5693    
5694     # Get the data from the XML document folder file
5695     ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
5696    
5697     # Check that the entry is valid
5698     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5699     &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5700     goto bailFromGetSavedSearch;
5701     }
5702    
5703     $FolderName = $Value{'FolderName'};
5704     $FolderDescription = $Value{'FolderDescription'};
5705     $FolderDocuments = $Value{'FolderDocuments'};
5706     $CreationTime = $Value{'CreationTime'};
5707     $UpdateTime = time();
5708    
5709    
5710     # Merge the documents
5711     if ( defined($FolderDocuments) || defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
5712    
5713     # Undefine the hash table in preparation
5714     undef(%Value);
5715    
5716     # Make a hash table from the documents already in the document folder
5717     if ( defined($FolderDocuments) ) {
5718     foreach $Value ( split(/\0/, $FolderDocuments) ) {
5719     $Value{$Value} = $Value;
5720     }
5721     }
5722    
5723     # Add document that were specifically selected
5724     if ( defined($main::FormData{'Document'}) ) {
5725     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5726     $Value{$Value} = $Value;
5727     }
5728     }
5729     # Otherwise add documents that were selected by default
5730     elsif ( defined($main::FormData{'Documents'}) ) {
5731     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5732     $Value{$Value} = $Value;
5733     }
5734     }
5735    
5736     # Assemble the new content
5737     $FolderDocuments = join("\0", keys(%Value));
5738    
5739     # Delete the old content
5740     delete($main::FormData{'Document'});
5741     delete($main::FormData{'Documents'});
5742     }
5743    
5744     }
5745     elsif ( defined($main::FormData{'FolderName'}) ) {
5746    
5747     $FolderName = $main::FormData{'FolderName'};
5748     $FolderDescription = $main::FormData{'FolderDescription'};
5749    
5750     # Merge the documents
5751     if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) {
5752    
5753     # Undefine the hash table in preparation
5754     undef(%Value);
5755    
5756     # Add document that were specifically selected
5757     if ( defined($main::FormData{'Document'}) ) {
5758     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5759     $Value{$Value} = $Value;
5760     }
5761     }
5762     # Otherwise add documents that were selected by default
5763     elsif ( defined($main::FormData{'Documents'}) ) {
5764     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5765     $Value{$Value} = $Value;
5766     }
5767     }
5768    
5769     # Assemble the new content
5770     $main::FormData{'Document'} = join("\0", keys(%Value));
5771    
5772     # Delete the old content
5773     delete($main::FormData{'Documents'});
5774     }
5775    
5776     $FolderDocuments = $main::FormData{'Document'};
5777     $CreationTime = time();
5778     $UpdateTime = time();
5779     }
5780    
5781    
5782     # Save the document folder to a new file
5783     if ( &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) ) {
5784    
5785     # Are we pulling these documents from an existing folder?
5786     if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5787    
5788     # Set the document folder file path
5789     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'FromDocumentFolderObject'};
5790    
5791     # Get information from the XML document folder file
5792     ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
5793    
5794    
5795     $FolderName = $Value{'FolderName'};
5796     $FolderDescription = $Value{'FolderDescription'};
5797     $FolderDocuments = $Value{'FolderDocuments'};
5798     $CreationTime = $Value{'CreationTime'};
5799     $UpdateTime = time();
5800    
5801    
5802     # Make a hash table from the documents selected for deletion, this serves as
5803     # a lookup table when we loop through the existing documents
5804     undef(%Value);
5805     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5806     $Value{$Value} = 1;
5807     }
5808    
5809     # Parse out of the existing documents into a list
5810     foreach $Value ( split(/\0/, $FolderDocuments) ) {
5811     # Add the document if it is not on the deletion list
5812     if ( !defined($Value{$Value}) ) {
5813     push @Values, $Value;
5814     }
5815     }
5816     $FolderDocuments = join("\0", @Values);
5817    
5818    
5819     # Save the document folder
5820     &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5821    
5822     }
5823    
5824     if ( defined($main::FormData{'MergeDocumentFolderObject'}) ) {
5825     @Values = split(/\0/, $main::FormData{'MergeDocumentFolderObject'});
5826     foreach $Value ( @Values ) {
5827     # Set the document folder file path
5828     if ( !(defined($main::FormData{'DocumentFolderObject'}) && ($main::FormData{'DocumentFolderObject'} eq $Value))) {
5829     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $Value;
5830     unlink($DocumentFolderFilePath);
5831     }
5832     }
5833     }
5834    
5835     print("<H3> Saving a Document Folder: </H3>\n");
5836     print("<P>\n");
5837     print("<H3><CENTER> Your document folder was successfully saved. </CENTER></H3>\n");
5838    
5839    
5840     }
5841     else {
5842    
5843     # The document folder could not be saved, so we inform the user of the fact
5844     &vHandleError("Saving a Document Folder", "Sorry, we failed to save this document folder");
5845     goto bailFromSetSaveFolder;
5846     }
5847    
5848    
5849     # Bail from saving the document folder
5850     bailFromSetSaveFolder:
5851    
5852     print("<CENTER><HR WIDTH=50%></CENTER>\n");
5853     undef(%Value);
5854     &vSendMenuBar(%Value);
5855    
5856     &vSendHTMLFooter;
5857    
5858     return;
5859    
5860     }
5861    
5862    
5863    
5864    
5865    
5866    
5867     #--------------------------------------------------------------------------
5868     #
5869     # Function: vListFolder()
5870     #
5871     # Purpose: This function allows the user list the document folders and
5872     # sets up the links allowing the user to get a list of the documents
5873     #
5874     # Called by:
5875     #
5876     # Parameters: void
5877     #
5878     # Global Variables: %main::ConfigurationData, %main::FormData,
5879     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5880     # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
5881     #
5882     # Returns: void
5883     #
5884     sub vListFolder {
5885    
5886     my (@DocumentFolderList, %QualifiedDocumentFolders, $DocumentFolderEntry, $HeaderName);
5887     my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5888     my (@Values, $Value, %Value);
5889    
5890    
5891     # Return an error if the remote user name/account directory is not defined
5892     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5893     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5894     &vSendHTMLFooter;
5895     return;
5896     }
5897    
5898    
5899     # Make sure that we send the header
5900     &vSendHTMLHeader("Document Folders", undef);
5901     undef(%Value);
5902     $Value{'ListFolder'} = "ListFolder";
5903     &vSendMenuBar(%Value);
5904     undef(%Value);
5905    
5906    
5907    
5908     # Print out the document folders
5909     print("<H3> Folderi: </H3>\n");
5910    
5911    
5912     # Get the document folder hash
5913     %QualifiedDocumentFolders = &hGetDocumentFolders;
5914    
5915    
5916     # Print up the document folders, if there is none, we put up a nice message
5917     if ( scalar(keys(%QualifiedDocumentFolders)) > 0 ) {
5918    
5919     # Start the table
5920     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
5921    
5922     # Start the form
5923     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
5924    
5925    
5926     # Print the selector
5927     print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3>\n");
5928     print("<SELECT NAME=\"Action\">\n");
5929     print("<OPTION VALUE=\"DeleteFolder\">Obri¹i oznaèene foldere\n");
5930     print("<OPTION VALUE=\"GetMergeFolder\">Spoji oznaèene foldere u novi folder\n");
5931    
5932     for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
5933    
5934     $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
5935    
5936     # Get the document folder file name and encode it
5937     $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
5938     $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
5939    
5940     print("<OPTION VALUE=\"SetMergeFolder&ToDocumentFolderObject=$DocumentFolderEntry\">Spoji oznaèene foldere u '$FolderName' folder\n");
5941     }
5942    
5943     print("</SELECT>\n");
5944     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
5945     print("</TD></TR>\n");
5946    
5947    
5948    
5949     # List the folders
5950     for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
5951    
5952     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
5953    
5954     $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
5955    
5956     # Get information from the XML document folder file
5957     ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderEntry);
5958    
5959     # Get the saved search file name and encode it
5960     $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
5961     $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
5962    
5963    
5964     $FolderName = $Value{'FolderName'};
5965     $FolderDescription = $Value{'FolderDescription'};
5966     $FolderDocuments = $Value{'FolderDocuments'};
5967     $CreationTime = $Value{'CreationTime'};
5968     $UpdateTime = $Value{'UpdateTime'};
5969    
5970    
5971     # Print the link
5972     print("<TR><TD ALIGN=LEFT VALIGN=TOP WIDTH=1%><INPUT TYPE=\"checkbox\" NAME=\"DocumentFolderObject\" VALUE=\"$DocumentFolderEntry\"> </TD><TD ALIGN=LEFT VALIGN=TOP> Naziv: </TD> <TD ALIGN=LEFT VALIGN=TOP> $FolderName </TD></TR>\n");
5973    
5974     # Print the folder description
5975     $FolderDescription = defined($FolderDescription) ? $FolderDescription : "(Nije naveden)";
5976     $FolderDescription =~ s/\n/<BR>/g;
5977     $FolderDescription =~ s/\r/<BR>/g;
5978     print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $FolderDescription </TD></TR>\n");
5979    
5980     if ( defined($FolderDocuments) ) {
5981     @Values = split(/\0/, $FolderDocuments);
5982     $Value = scalar( @Values );
5983     }
5984     else {
5985     $Value = 0;
5986     }
5987     print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Broj rezultata: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5988    
5989    
5990     $Value = &sGetPrintableDateFromTime($CreationTime);
5991     print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5992    
5993     $Value = &sGetPrintableDateFromTime($UpdateTime);
5994     print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Datum zadnje promijene: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5995    
5996     print("<TR><TD WIDTH=1%> </TD><TD ALIGN=LEFT VALIGN=TOP> </TD> <TD ALIGN=LEFT VALIGN=TOP> <A HREF=\"$ENV{'SCRIPT_NAME'}/GetFolder?DocumentFolderObject=$DocumentFolderEntry\" OnMouseOver=\"self.status='Display the documents in this document folder'; return true\">[ Otvori ovaj folder ] </A> </TD></TR>\n");
5997     }
5998    
5999     print("</FORM></TABLE>\n");
6000     }
6001     else {
6002     print("<H3><CENTER> Nema foldera! </CENTER></H3>\n");
6003     }
6004    
6005    
6006    
6007    
6008     # Bail from displaying document folders
6009     bailFromListFolder:
6010    
6011     print("<CENTER><HR WIDTH=50%></CENTER>\n");
6012     undef(%Value);
6013     $Value{'ListFolder'} = "ListFolder";
6014     &vSendMenuBar(%Value);
6015     undef(%Value);
6016    
6017     &vSendHTMLFooter;
6018    
6019    
6020     return;
6021    
6022     }
6023    
6024    
6025    
6026    
6027    
6028    
6029     #--------------------------------------------------------------------------
6030     #
6031     # Function: vMergeFolder()
6032     #
6033     # Purpose: This function deletes a folder.
6034     #
6035     # Called by:
6036     #
6037     # Parameters: void
6038     #
6039     # Global Variables: %main::ConfigurationData, %main::FormData,
6040     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6041     # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6042     #
6043     # Returns: void
6044     #
6045     sub vMergeFolder {
6046    
6047     my ($Title, $HeaderName, $DocumentFolderFilePath, $DocumentFolderObject, $FolderDocuments);
6048     my ($Value, %Value);
6049    
6050    
6051    
6052     # Return an error if the remote user name/account directory is not defined
6053     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6054     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6055     &vSendHTMLFooter;
6056     return;
6057     }
6058    
6059    
6060    
6061     # Check to see if the document folder object is defined
6062     if ( ! defined($main::FormData{'DocumentFolderObject'}) ) {
6063    
6064     # Could not find the document folder file
6065     &vSendHTMLHeader("Merge Document Folders", undef);
6066     undef(%Value);
6067     &vSendMenuBar(%Value);
6068     print("<H3> Merge Document Folders: </H3>\n");
6069     print("<H3><CENTER> Sorry, no document folders were selected. </CENTER></H3>\n");
6070     print("<P>\n");
6071     print("You need to select at least one document folder in order to be able to perform an action on it.\n");
6072     print("<P>\n");
6073     return;
6074     }
6075    
6076    
6077     # Init the value hash
6078     undef(%Value);
6079    
6080     # Loop over document folder object
6081     $Value = $main::FormData{'DocumentFolderObject'} .
6082     ((defined($main::FormData{'ToDocumentFolderObject'})) ? "\0" . $main::FormData{'ToDocumentFolderObject'} : "");
6083    
6084     foreach $DocumentFolderObject ( split(/\0/, $Value) ) {
6085    
6086     # Set the document folder file path
6087     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $DocumentFolderObject;
6088    
6089     # Check to see if the XML saved search file requested is there
6090     if ( ! -f $DocumentFolderFilePath ) {
6091     next;
6092     }
6093    
6094     # Get information from the XML saved search file
6095     $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
6096    
6097     # Check that the entry is valid
6098     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6099     next;
6100     }
6101    
6102     # Get the FolderDocuments symbol
6103     $FolderDocuments = &sGetTagValueFromXMLFile($DocumentFolderFilePath, "FolderDocuments");
6104    
6105     # Add each document to the hash
6106     foreach $Value ( split(/\0/, $FolderDocuments) ) {
6107     $Value{$Value} = $Value;
6108     }
6109     }
6110    
6111     # Set the document URL from the hash
6112     $main::FormData{'Document'} = join("\0", keys(%Value));
6113    
6114    
6115     if ( defined($main::FormData{'DocumentFolderObject'}) ) {
6116     $main::FormData{'MergeDocumentFolderObject'} = $main::FormData{'DocumentFolderObject'};
6117     delete($main::FormData{'DocumentFolderObject'});
6118     }
6119    
6120     if ( defined($main::FormData{'ToDocumentFolderObject'}) ) {
6121     $main::FormData{'DocumentFolderObject'} = $main::FormData{'ToDocumentFolderObject'};
6122     delete($main::FormData{'ToDocumentFolderObject'});
6123     }
6124    
6125    
6126     if ( $ENV{'PATH_INFO'} eq "/GetMergeFolder" ) {
6127     &vGetSaveFolder;
6128     }
6129     elsif ( $ENV{'PATH_INFO'} eq "/SetMergeFolder" ) {
6130     &vSetSaveFolder;
6131     }
6132    
6133    
6134     return;
6135    
6136     }
6137    
6138    
6139    
6140    
6141    
6142    
6143     #--------------------------------------------------------------------------
6144     #
6145     # Function: vProcessFolder()
6146     #
6147     # Purpose: This function deletes a folder.
6148     #
6149     # Called by:
6150     #
6151     # Parameters: void
6152     #
6153     # Global Variables: %main::ConfigurationData, %main::FormData,
6154     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6155     # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6156     #
6157     # Returns: void
6158     #
6159     sub vProcessFolder {
6160    
6161     my ($Title, $HeaderName, $DocumentFolderFilePath, $DocumentFolderObject);
6162     my ($Value, %Value);
6163    
6164    
6165    
6166     # Return an error if the remote user name/account directory is not defined
6167     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6168     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6169     &vSendHTMLFooter;
6170     return;
6171     }
6172    
6173    
6174    
6175     if ( $ENV{'PATH_INFO'} eq "/DeleteFolder" ) {
6176     $Title = "Delete Document Folders";
6177     }
6178    
6179    
6180     # Make sure that we send the header
6181     &vSendHTMLHeader($Title, undef);
6182     undef(%Value);
6183     &vSendMenuBar(%Value);
6184    
6185     print("<H3> $Title: </H3>\n");
6186    
6187     # Check to see if the document folder object is defined
6188     if ( ! defined($main::FormData{'DocumentFolderObject'}) ) {
6189    
6190     # Could not find the document folder file
6191     print("<H3><CENTER> Sorry, no document folders were selected. </CENTER></H3>\n");
6192     print("<P>\n");
6193     print("You need to select at least one document folder in order to be able to perform an action on it.\n");
6194     print("<P>\n");
6195    
6196     goto bailFromProcessFolder;
6197     }
6198    
6199    
6200     # Loop over document folder object
6201     foreach $DocumentFolderObject ( split(/\0/, $main::FormData{'DocumentFolderObject'}) ) {
6202    
6203     # Set the document folder file path
6204     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $DocumentFolderObject;
6205    
6206     # Check to see if the XML saved search file requested is there
6207     if ( ! -f $DocumentFolderFilePath ) {
6208     printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6209     next;
6210     }
6211    
6212     # Get information from the XML saved search file
6213     ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
6214    
6215     # Check that the entry is valid
6216     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6217     printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6218     }
6219    
6220    
6221     if ( unlink($DocumentFolderFilePath) ) {
6222     printf("<P>Successfully deleted: %s\n", $Value{'FolderName'});
6223     }
6224     else {
6225     printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6226     }
6227     }
6228    
6229     print("<P>\n");
6230    
6231     # Bail from processing the document folder
6232     bailFromProcessFolder:
6233    
6234     print("<CENTER><HR WIDTH=50%></CENTER>\n");
6235     undef(%Value);
6236     &vSendMenuBar(%Value);
6237    
6238     &vSendHTMLFooter;
6239    
6240     return;
6241    
6242     }
6243    
6244    
6245    
6246    
6247    
6248    
6249     #--------------------------------------------------------------------------
6250     #
6251     # Function: vGetFolder()
6252     #
6253     # Purpose: This function displays a document folder to the user.
6254     #
6255     # Called by:
6256     #
6257     # Parameters: void
6258     #
6259     # Global Variables: %main::ConfigurationData, %main::FormData,
6260     # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6261     # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6262     #
6263     # Returns: void
6264     #
6265     sub vGetFolder {
6266    
6267     my ($HeaderName, $FolderName, $SelectorText, %ArticleFolder);
6268     my (@DocumentFolderList, $DocumentFolderEntry, %QualifiedDocumentFolders);
6269     my ($Value, %Value);
6270    
6271    
6272     # Return an error if the remote user name/account directory is not defined
6273     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6274     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6275     &vSendHTMLFooter;
6276     return;
6277     }
6278    
6279    
6280    
6281     # Make the document folder file name
6282     $DocumentFolderEntry = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
6283    
6284     # Check to see if the XML document folder file requested is there
6285     if ( ! -f $DocumentFolderEntry ) {
6286     # Could not find the document folders file
6287     &vHandleError("Document Folder", "Sorry, we cant to access this document folder object because it is not there");
6288     goto bailFromGetFolder;
6289     }
6290    
6291     # Get information from the XML document folder file
6292     ($HeaderName, %ArticleFolder) = &shGetHashFromXMLFile($DocumentFolderEntry);
6293    
6294     # Check that the entry is valid
6295     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6296     &vHandleError("Document Folder", "Sorry, this document folder object is invalid");
6297     goto bailFromGetFolder;
6298     }
6299    
6300    
6301     # Make sure we send the header
6302     &vSendHTMLHeader("Document Folder", undef);
6303     undef(%Value);
6304     &vSendMenuBar(%Value);
6305    
6306     print("<H3> Document Folder: </H3>\n");
6307    
6308    
6309     # Start the form
6310     print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
6311    
6312    
6313     # Print the selector if there are any documents
6314     if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6315     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
6316     print("<TR><TD ALIGN=LEFT VALIGN=TOP>Odabranima se smatraju svi rezultati ukoliko niste uèinili nikakav dodatan odabir.</TD><TD ALIGN=RIGHT VALIGN=TOP> \n");
6317     print("<SELECT NAME=\"Action\">\n");
6318     print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultates\n");
6319     if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
6320     print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
6321     }
6322     if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
6323     print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
6324     }
6325     print("<OPTION VALUE=\"DeleteDocument&DocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Delete selected documents from this document folder\n");
6326     print("<OPTION VALUE=\"GetSaveFolder&FromDocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Move selected documents to a new document folder\n");
6327    
6328    
6329     # Get the document folder hash
6330     %QualifiedDocumentFolders = &hGetDocumentFolders;
6331    
6332     for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
6333    
6334     # Skip this folder
6335     if ( $FolderName eq $ArticleFolder{'FolderName'} ) {
6336     next;
6337     }
6338    
6339     $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
6340    
6341     # Get the document folder file name and encode it
6342     $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
6343     $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
6344    
6345     print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry&FromDocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Move selected documents to the '$FolderName' document folder\n");
6346     }
6347    
6348     print("</SELECT>\n");
6349     print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
6350     print("</TD></TR>\n");
6351     print("</TABLE>\n");
6352     }
6353    
6354     print("<CENTER><HR WIDTH=50%></CENTER>\n");
6355    
6356    
6357     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
6358    
6359     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Naziv: </TD> <TD ALIGN=LEFT VALIGN=TOP> $ArticleFolder{'FolderName'} </TD></TR>\n");
6360    
6361     # Print the folder description
6362     $ArticleFolder{'FolderDescription'} = defined($ArticleFolder{'FolderDescription'}) ? $ArticleFolder{'FolderDescription'} : "(No description defined)";
6363     $ArticleFolder{'FolderDescription'} =~ s/\n/<BR>/g;
6364     $ArticleFolder{'FolderDescription'} =~ s/\r/<BR>/g;
6365     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $ArticleFolder{'FolderDescription'} </TD></TR>\n");
6366    
6367    
6368     $Value = &sGetPrintableDateFromTime($ArticleFolder{'CreationTime'});
6369     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6370    
6371     $Value = &sGetPrintableDateFromTime($ArticleFolder{'UpdateTime'});
6372     print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum zadnje promijene: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6373    
6374     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
6375    
6376    
6377     # Display a button to select all the documents if there are any
6378     if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6379    
6380     $SelectorText = "";
6381    
6382     # Loop over each entry folder documents
6383     foreach $Value ( split(/\0/, $ArticleFolder{'FolderDocuments'}) ) {
6384     $SelectorText .= (($SelectorText ne "") ? "|" : "") . $Value;
6385     }
6386    
6387     $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
6388     print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> $SelectorText </TD></TR>\n");
6389     }
6390    
6391     if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6392     print("<TR>\n");
6393     &bDisplayDocuments("Document", $ArticleFolder{'FolderDocuments'}, "Document", 1, undef, 1);
6394     print("</TR>\n");
6395     }
6396     else {
6397     print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2> This document folder does not contain any documents. </TD></TR>\n");
6398     }
6399    
6400     print("</FORM></TABLE>\n");
6401    
6402     # Bail from displaying the document folder
6403     bailFromGetFolder:
6404    
6405     print("<CENTER><HR WIDTH=50%></CENTER>\n");
6406     undef(%Value);
6407     &vSendMenuBar(%Value);
6408    
6409     &vSendHTMLFooter;
6410    
6411     return;
6412    
6413     }
6414    
6415    
6416    
6417    
6418    
6419    
6420     #--------------------------------------------------------------------------
6421     #
6422     # Function: vProcessDocument()
6423     #
6424     # Purpose: This function deletes folder documents
6425     #
6426     # Called by:
6427     #
6428     # Parameters: void
6429     #
6430     # Global Variables: %main::ConfigurationData, %main::FormData,
6431     # $main::UserSettingsFilePath, $main::RemoteUser,
6432     #
6433     # Returns: void
6434     #
6435     sub vProcessDocument {
6436    
6437     my ($Title, $DocumentFolderFilePath, $HeaderName);
6438     my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
6439     my (%Value, @Values, $Value);
6440    
6441    
6442    
6443     # Return an error if the remote user name/account directory is not defined
6444     if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6445     &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6446     &vSendHTMLFooter;
6447     return;
6448     }
6449    
6450    
6451     # Check to see if the XML document folder is there
6452     if ( !defined($main::FormData{'DocumentFolderObject'}) ) {
6453     # Could not find the document folders file
6454     &vHandleError($Title, "Sorry, the document folder object was not defined");
6455     goto bailFromProcessDocument;
6456     }
6457    
6458    
6459     # Set the title
6460     if ( $ENV{'PATH_INFO'} eq "/DeleteDocument" ) {
6461     $Title = "Delete Folder Documents";
6462     }
6463    
6464    
6465     # Make sure that we send the header
6466     &vSendHTMLHeader($Title, undef);
6467     undef(%Value);
6468     &vSendMenuBar(%Value);
6469    
6470    
6471    
6472     # Check to see if the document folder object is defined
6473     if ( ! (defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) ) {
6474    
6475     # No documents were defined
6476     print("<H3><CENTER> Sorry, no documents were selected. </CENTER></H3>\n");
6477     print("<P>\n");
6478     print("You need to select at least one document in order to be able to perform an action on it.\n");
6479     print("<P>\n");
6480    
6481     goto bailFromProcessDocument;
6482     }
6483    
6484    
6485     # Set the document folder file path
6486     $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
6487    
6488    
6489     # Check to see if the XML document folder file requested is there
6490     if ( ! -f $DocumentFolderFilePath ) {
6491     # Could not find the document folders file
6492     &vHandleError($Title, "Sorry, we cant to access this document folder object because it is not there");
6493     goto bailFromProcessDocument;
6494     }
6495    
6496    
6497     # Get information from the XML document folder file
6498     ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
6499    
6500     # Check that the entry is valid
6501     if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6502     &vHandleError($Title, "Sorry, this document folder object is invalid");
6503     goto bailFromProcessDocument;
6504     }
6505    
6506    
6507    
6508     $FolderName = $Value{'FolderName'};
6509     $FolderDescription = $Value{'FolderDescription'};
6510     $FolderDocuments = $Value{'FolderDocuments'};
6511     $CreationTime = $Value{'CreationTime'};
6512     $UpdateTime = time();
6513    
6514    
6515     # Make a hash table from the documents selected for deletion, this serves as
6516     # a lookup table when we loop through the existing documents
6517     # List the documents
6518     if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
6519    
6520     # Undefine the hash table in preparation
6521     undef(%Value);
6522    
6523     # Add document that were specifically selected
6524     if ( defined($main::FormData{'Document'}) ) {
6525     foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
6526     $Value{$Value} = $Value;
6527     }
6528     }
6529     # Otherwise add documents that were selected by default
6530     elsif ( defined($main::FormData{'Documents'}) ) {
6531     foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
6532     $Value{$Value} = $Value;
6533     }
6534     }
6535     }
6536    
6537    
6538     # Parse out of the existing documents into a list
6539     foreach $Value ( split(/\0/, $FolderDocuments) ) {
6540     # Add the document if it is not on the deletion list
6541     if ( !defined($Value{$Value}) ) {
6542     push @Values, $Value;
6543     }
6544     }
6545     $FolderDocuments = join("\0", @Values);
6546    
6547    
6548     # Save the document folder (now missing the selected documents)
6549     if ( &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) ) {
6550    
6551     print("<H3> $Title: </H3>\n");
6552     print("<P>\n");
6553     print("<H3><CENTER> The folder documents were successfully deleted. </CENTER></H3>\n");
6554    
6555     }
6556     else {
6557    
6558     # The documents coudl not be deleted, so we inform the user of the fact
6559     &vHandleError($Title, "Sorry, we failed to delete the selected folder documents");
6560     goto bailFromProcessDocument;
6561     }
6562    
6563    
6564     # Bail from deleting the documents
6565     bailFromProcessDocument:
6566    
6567     print("<CENTER><HR WIDTH=50%></CENTER>\n");
6568     undef(%Value);
6569     &vSendMenuBar(%Value);
6570    
6571     &vSendHTMLFooter;
6572    
6573     return;
6574    
6575     }
6576    
6577    
6578    
6579    
6580    
6581    
6582     #--------------------------------------------------------------------------
6583     #
6584     # Function: vRunSavedSearches()
6585     #
6586     # Purpose: Run the saved searches which are due
6587     #
6588     # Called by:
6589     #
6590     # Parameters: $PassedFrequency search frequency
6591     #
6592     # Global Variables:
6593     #
6594     # Returns: void
6595     #
6596     sub vRunSavedSearches {
6597    
6598     my ($PassedFrequency) = @_;
6599     my (@UserAccountsDirectoryList, $UserAccountsDirectory, @UserSavedSearchList, $UserSavedSearch);
6600     my (@SavedSearchFilePathList, @QualifiedSaveSearchFilePathList, $SavedSearchFilePath);
6601     my ($SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchString, $DeliveryFormat, $DeliveryMethod, $SearchFrequency, $SearchStatus, $CreationTime, $LastRunTime);
6602     my ($EmailAddress, $NewLastRunTime, $Databases, $HeaderName);
6603     my ($Status, $SearchResults, $FinalSearchString, $SearchResult, $ResultCount, $QueryReport, $ErrorNumber, $ErrorMessage);
6604     my ($ItemName, $MimeType, $HTML, $SavedFileHandle);
6605     my ($Value, %Value, $ValueEntry);
6606    
6607    
6608     # Check that we can actually run saved searches
6609     if ( !(defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes")) ) {
6610     print("Execution error - configuration setting: 'allow-regular-searches', setting not set or disabled.\n");
6611     return;
6612     }
6613    
6614    
6615     # Check that we have a user account directory
6616     if ( !defined($main::ConfigurationData{'user-accounts-directory'}) ) {
6617     print("Execution error - configuration setting: 'user-accounts-directory', setting not set.\n");
6618     }
6619    
6620    
6621     # Check that we have a script URL
6622     if ( !(defined($main::ConfigurationData{'script-url'}) && ($main::ConfigurationData{'script-url'} ne "yes")) ) {
6623     print("Execution error - configuration setting: 'script-url', setting not set.\n");
6624     }
6625    
6626    
6627     # Scoop up all the directories in the user accounts directory
6628     opendir(ACCOUNTS_DIRECTORY, $main::ConfigurationData{'user-accounts-directory'});
6629     @UserAccountsDirectoryList = grep(!/^\.\.?$/, readdir(ACCOUNTS_DIRECTORY));
6630     closedir(ACCOUNTS_DIRECTORY);
6631    
6632     # Loop over each user account
6633     foreach $UserAccountsDirectory ( @UserAccountsDirectoryList ) {
6634    
6635     # Read all the saved searches
6636     opendir(USER_ACCOUNT_DIRECTORY, $main::ConfigurationData{'user-accounts-directory'} . "/" . $UserAccountsDirectory);
6637     @UserSavedSearchList = grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY));
6638     closedir(USER_ACCOUNT_DIRECTORY);
6639    
6640     # And add each to the saved searches list
6641     foreach $UserSavedSearch ( @UserSavedSearchList ) {
6642     push @SavedSearchFilePathList, $main::ConfigurationData{'user-accounts-directory'} . "/" . $UserAccountsDirectory . "/" . $UserSavedSearch;
6643     }
6644     }
6645    
6646    
6647     # Return here if there are no saved search to process
6648     if ( ! @SavedSearchFilePathList ) {
6649     print("Execution warning - no saved searches to process.\n");
6650     return;
6651     }
6652    
6653    
6654     # Loop over each file in the list, checking to see if it is time to
6655     # process this one, if so we add it to the qualified saved search list
6656     foreach $SavedSearchFilePath ( @SavedSearchFilePathList ) {
6657    
6658     # Get the header name from the saved search file
6659     $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchFilePath);
6660    
6661     # Skip this saved search file entry if it is not valid
6662     if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
6663     print("Execution error - invalid saved search object: '$SavedSearchFilePath'.\n");
6664     next;
6665     }
6666    
6667    
6668     # Get the delivery format from the saved search file
6669     $DeliveryFormat = &sGetTagValueFromXMLFile($SavedSearchFilePath, "DeliveryFormat");
6670    
6671     # Check the delivery format, it is undefined if the search is not a regular search
6672     if ( ! defined($DeliveryFormat) ) {
6673     next;
6674     }
6675    
6676     # Check the validity of the delivery format
6677     if ( ! defined($main::DeliveryFormats{$DeliveryFormat}) ) {
6678     print("Execution error - invalid delivery method: '$DeliveryFormat' in saved search: '$SavedSearchFilePath'.\n");
6679     next;
6680     }
6681    
6682    
6683    
6684     # Set the user settings file path name
6685     $main::UserSettingsFilePath = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/") + 1) . $main::UserSettingsFileName . $main::XMLFileNameExtension;
6686    
6687     # Check that this preference file is valid
6688     $HeaderName = &sGetObjectTagFromXMLFile($main::UserSettingsFilePath);
6689    
6690     # Skip this entry if it is not valid
6691     if ( !(defined($HeaderName) && ($HeaderName eq "UserSettings")) ) {
6692     print("Execution error - invalid user settings object: '$main::UserSettingsFilePath'.\n");
6693     next;
6694     }
6695    
6696    
6697     # Get the email address from the user settings file
6698     $EmailAddress = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
6699    
6700     # Skip this entry if it is not valid
6701     if ( !defined($EmailAddress) ) {
6702     print("Execution error - invalid email address in user settings object: '$main::UserSettingsFilePath'.\n");
6703     next;
6704     }
6705    
6706    
6707     # Get the frequency requested for this saved search
6708     $SearchFrequency = &sGetTagValueFromXMLFile($SavedSearchFilePath, "SearchFrequency");
6709    
6710     # Check the search frequency, skip if it is undefined
6711     if ( !defined($SearchFrequency)) {
6712     print("Execution error - undefined search frequency in user settings object: '$main::UserSettingsFilePath'.\n");
6713     next;
6714     }
6715    
6716     # Check the search frequency, skip if it is invalid
6717     $Value = 0;
6718     foreach $ValueEntry ( @main::SearchFrequencies ) {
6719     if ( $ValueEntry eq $SearchFrequency ) {
6720     $Value = 1;
6721     last;
6722     }
6723     }
6724     if ( !$Value ) {
6725     print("Execution error - invalid search frequency: '$SearchFrequency', in user settings object: '$main::UserSettingsFilePath'.\n");
6726     next;
6727     }
6728    
6729    
6730     # Is this the frequency we are currently working on?
6731     if ( index($PassedFrequency, $SearchFrequency) < 0 ) {
6732     next;
6733     }
6734    
6735    
6736     # It is, so we concatenate the saved search file name to the list of
6737     # qualified saved search file names
6738     push @QualifiedSaveSearchFilePathList, $SavedSearchFilePath;
6739     }
6740    
6741    
6742    
6743     # Return here if there are no qualified saved search to process
6744     if ( ! @QualifiedSaveSearchFilePathList ) {
6745     return;
6746     }
6747    
6748    
6749     # Get the current time, this will be used as the new last run time
6750     $NewLastRunTime = time();
6751    
6752    
6753     # Loop each saved search in the qualified saved search list, processing each of them
6754     foreach $SavedSearchFilePath ( @QualifiedSaveSearchFilePathList ) {
6755    
6756     # Get information from the XML saved search file
6757     ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchFilePath);
6758    
6759     $SearchName = $Value{'SearchName'};
6760     $SearchDescription = $Value{'SearchDescription'};
6761     $SearchString = $Value{'SearchString'};
6762     $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
6763     $SearchFrequency = $Value{'SearchFrequency'};
6764     $SearchStatus = $Value{'SearchStatus'};
6765     $DeliveryFormat = $Value{'DeliveryFormat'};
6766     $DeliveryMethod = $Value{'DeliveryMethod'};
6767     $CreationTime = $Value{'CreationTime'};
6768     $LastRunTime = $Value{'LastRunTime'};
6769    
6770    
6771     # Check the search status, run the search if it is active
6772     if ( defined($SearchStatus) && ($SearchStatus eq "Active") ) {
6773    
6774     # Get the last run time from the XML saved search file
6775     if ( !defined($LastRunTime) ) {
6776     $LastRunTime = "0";
6777     }
6778    
6779    
6780     # Set the remote user name
6781     $main::RemoteUser = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/"));
6782     $main::RemoteUser = substr($main::RemoteUser, rindex($main::RemoteUser,"/") + 1);
6783    
6784     # Set the user directory path
6785     $main::UserAccountDirectoryPath = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/") + 1);
6786    
6787     # Set the user settings file path name
6788     $main::UserSettingsFilePath = $main::UserAccountDirectoryPath . $main::UserSettingsFileName . $main::XMLFileNameExtension;
6789    
6790     # Get the email address from the user settings file
6791     $EmailAddress = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
6792    
6793     # Parse the URL search string into the form data global
6794     %main::FormData = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
6795    
6796    
6797     ##########################
6798     # Uncomment this to force a check over the complete database rather than
6799     # just getting the documents which changed since the last run
6800     # $LastRunTime = 0;
6801     ##########################
6802    
6803    
6804     # Clear the date restriction fields, they are meaningless in this context
6805     delete($main::FormData{'Since'});
6806     delete($main::FormData{'Before'});
6807    
6808     # Set the last run time restriction
6809     $main::FormData{'LastRunTime'} = $LastRunTime;
6810    
6811    
6812     # Generate the search string
6813     $FinalSearchString = &sMakeSearchString(%main::FormData);
6814    
6815    
6816     # Set the local database names
6817     if ( defined($main::FormData{'Database'}) ) {
6818    
6819     # Set the database variable and convert all the '\0' to ','
6820     $Databases = $main::FormData{'Database'};
6821     $Databases =~ tr/\0/,/;
6822     }
6823    
6824    
6825    
6826     print("Execution - saved search: '$SavedSearchFilePath', database: '$Databases', search: '$FinalSearchString', time: '$LastRunTime'.\n");
6827    
6828     # Run the search
6829     ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Databases, $FinalSearchString, "", 0, $main::DefaultMaxDoc - 1, $main::ConfigurationData{'max-score'});
6830    
6831     if ( ! $Status ) {
6832     ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
6833     print("Execution error - failed to run the search.\n");
6834     print("The following error message was reported: <BR>\n");
6835     print("Error Message: $ErrorMessage <BR>\n");
6836     print("Error Number: $ErrorNumber <BR>\n");
6837     next;
6838     }
6839    
6840    
6841     # Get the number of results we got from the search
6842     $ResultCount = 0;
6843     foreach $SearchResult ( split(/\n/, $SearchResults) ) {
6844    
6845     # Parse the headline, also get the first document item/type
6846     (undef, undef, undef, undef, undef undef, $ItemName, $MimeType, undef) = split(/\t/, $SearchResult, 9);
6847    
6848     # Is this a query report
6849     if ( !(($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType)) ) {
6850     # Increment the result count
6851     $ResultCount++;
6852     }
6853     }
6854    
6855    
6856     # Do we want to deliver email messages with no new results?
6857     if ( defined($main::ConfigurationData{'deliver-empty-results-from-regular-search'}) && ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} eq "no") ) {
6858     if ( $ResultCount == 0 ) {
6859     next;
6860     }
6861     }
6862    
6863    
6864     # Open the mail application, put put an error message if we cant open it and loop to the next saved search
6865     if ( ! open(RESULT_FILE, "| $main::ConfigurationData{'mailer-application'} $EmailAddress ") ) {
6866     print("Execution error - failed to launch mail application: '$main::ConfigurationData{'mailer-application'}', system error: $!.\n");
6867     next;
6868     }
6869    
6870    
6871     # Save the file handle for stdout and select the result file handle as the default handle
6872     $SavedFileHandle = select;
6873     select RESULT_FILE;
6874    
6875    
6876     # Print out the message header (To:)
6877     print ("To: $EmailAddress\n");
6878    
6879     # Print out the message header (From:)
6880     if ( defined($main::ConfigurationData{'site-admin-email'}) && ($main::ConfigurationData{'site-admin-email'} ne "") ) {
6881     print ("From: $main::ConfigurationData{'site-admin-email'}\n");
6882     }
6883    
6884     # Print out the message header (Subject:)
6885     print ("Subject: Results for saved search: $SearchName\n");
6886    
6887    
6888     # Print out the message header (Content-Type)
6889     if ( $DeliveryMethod eq "attachement" ) {
6890     print("Mime-Version: 1.0\n");
6891     print("Content-Type: multipart/mixed; boundary=\"============_-1234567890==_============\"\n");
6892     }
6893     else {
6894     print("Mime-Version: 1.0\n");
6895     printf("Content-Type: %s\n\n", ($DeliveryFormat eq "text/html") ? "text/html" : "text/plain");
6896     }
6897    
6898     # Print out the separating new line between message header and message body
6899     print("\n");
6900    
6901    
6902    
6903     # Print out mime part separator and mime header for the message header
6904     if ( $DeliveryMethod eq "attachement" ) {
6905     print("--============_-1234567890==_============\n");
6906     printf("Content-Type: text/plain; charset=\"us-ascii\"\n\n\n");
6907    
6908     if ( $DeliveryFormat eq "text/plain" ) {
6909     print("The search results are attached to this email message as a plain text\n");
6910     print("file. This file can be opened with a any word processor or text editor.\n");
6911     }
6912     elsif ( $DeliveryFormat eq "text/html" ) {
6913     print("The search results are attached to this email message as an HTML\n");
6914     print("file. This file can be opened with Netscape or Internet Explorer.\n");
6915     }
6916    
6917     print("--============_-1234567890==_============\n");
6918     $Value = "citations." . (($DeliveryFormat eq "text/html") ? "html" : "txt");
6919     print("Content-Type: $DeliveryFormat; name=\"$Value\"\n");
6920     print("Content-Disposition: attachment; filename=\"$Value\"\n\n");
6921     }
6922    
6923    
6924     # Get the current date
6925     $Value = &sGetPrintableDateFromTime();
6926    
6927     # Set the HTML flag
6928     $HTML = ( $DeliveryFormat eq "text/html" ) ? 1 : 0;
6929    
6930     # Write out the search result header
6931     ($Status, $QueryReport) = &bsDisplaySearchResults("Search Results for: $SearchName:", $SearchDescription, $Value, $SearchFrequency, $SearchResults, undef, $main::ConfigurationData{'script-url'}, 1, 1, $HTML, %main::FormData);
6932    
6933    
6934    
6935     # Print out mime part separator and mime header for the message footer
6936     if ( $DeliveryMethod eq "attachement" ) {
6937     print("--============_-1234567890==_============\n");
6938     printf("Content-Type: %s; charset=\"us-ascii\"\n\n\n", ($DeliveryFormat eq "text/html") ? "text/html" : "text/plain");
6939     }
6940    
6941    
6942     # Print out the profile result footer
6943     if ( $DeliveryFormat eq "text/html" ) {
6944     print("<BR><HR>\n");
6945     print("Saved search by the <A HREF=\"$main::ConfigurationData{'script-url'}\">MPS Information Server </A><BR>\n");
6946     print("Created by <A HREF=\"http://www.fsconsult.com/\">FS Consulting, Inc.</A><BR>\n");
6947     print("<HR><BR>\n");
6948     print("</BODY>\n");
6949     }
6950     elsif ( ($DeliveryFormat eq "text/plain") || ($DeliveryFormat eq "text/medline-citation") ) {
6951     print("----------------------------------------------------------------------\n");
6952     print("Saved search by the MPS Information Server [URL: $main::ConfigurationData{'script-url'}].\n");
6953     print("Created by FS Consulting, Inc. [URL: http://www.fsconsult.com/].\n");
6954     print("----------------------------------------------------------------------\n");
6955    
6956     }
6957    
6958     # Print out mime part separator for the end of the message
6959     if ( $DeliveryMethod eq "attachement" ) {
6960     print("--============_-1234567890==_============--\n");
6961     }
6962    
6963    
6964     # Restore the saved file handle
6965     select $SavedFileHandle;
6966    
6967     # Close the result file
6968     close(RESULT_FILE);
6969    
6970     }
6971     else {
6972     print("Execution - saved search: '$SavedSearchFilePath' is currently inactive.\n");
6973     }
6974    
6975     # Save the search object
6976     if ( ! &iSaveSearch($SavedSearchFilePath, $SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $NewLastRunTime) ) {
6977     print("Execution error - failed to save search object: '$SavedSearchFilePath'.\n");
6978     }
6979    
6980     } # foreach ()
6981    
6982     return;
6983    
6984     }
6985    
6986    
6987    
6988    
6989     #--------------------------------------------------------------------------
6990     #
6991     # Function: vLog()
6992     #
6993     # Purpose: This a logging function which logs any passed printf()
6994     # formatted string to STDOUT and the log file if it is defined.
6995     #
6996     # If the log file cannot be opened for appending, nothing will
6997     # be written to it.
6998     #
6999     # Called by:
7000     #
7001     # Parameters: @_
7002     #
7003     # Global Variables: $main::LogFilePath
7004     #
7005     # Returns: void
7006     #
7007     sub vLog {
7008    
7009     # Log to defined log file
7010     if ( defined($main::LogFilePath) && ($main::LogFilePath ne "") && open(LOG_FILE, ">>$main::LogFilePath") ) {
7011     print(LOG_FILE @_);
7012     close(LOG_FILE);
7013     }
7014    
7015     return;
7016    
7017     }
7018    
7019    
7020    
7021    
7022    
7023    
7024     #--------------------------------------------------------------------------
7025     #
7026     # Function: main()
7027     #
7028     # Purpose: main
7029     #
7030     # Called by:
7031     #
7032     # Parameters:
7033     #
7034     # Global Variables:
7035     #
7036     # Returns: void
7037     #
7038    
7039     my ($Status);
7040     my (%Value, $Value);
7041    
7042    
7043    
7044     # Roll over the log file (ignore the status)
7045     # &iRolloverLog($main::LogFilePath, $main::LogFileRollOver);
7046    
7047    
7048     # Verify that we are running the correct perl version, assume upward compatibility
7049     if ( $] < 5.004 ) {
7050     &vLog("Error - this script needs to be run with Perl version 5.004 or better.\n");
7051     &vSendHTMLFooter;
7052     exit (-1);
7053     }
7054    
7055    
7056     # Load up the configuration file
7057     ($Status, %main::ConfigurationData) = &bhReadConfigurationFile($main::ConfigurationFilePath);
7058     if ( ! $Status ) {
7059     &vSendHTMLFooter;
7060     exit (-1);
7061     }
7062    
7063    
7064    
7065     # Set any defaults in the configuration
7066     if ( ! &bSetConfigurationDefaults(\%main::ConfigurationData, \%main::DefaultSettings) ) {
7067     &vSendHTMLFooter;
7068     exit (-1);
7069     }
7070    
7071    
7072     # Check for a minimal configuration
7073     if ( ! &bCheckMinimalConfiguration(\%main::ConfigurationData, \@main::RequiredSettings) ) {
7074     &vSendHTMLFooter;
7075     exit (-1);
7076     }
7077    
7078    
7079     # Check that the configuration paths specified is correct and can be accessed
7080     if ( ! &bCheckConfiguration ) {
7081     &vSendHTMLFooter;
7082     exit (-1);
7083     }
7084    
7085    
7086     # Get the database descriptions
7087     if ( ! &bGetDatabaseDescriptions ) {
7088     &vSendHTMLFooter;
7089     exit (-1);
7090     }
7091    
7092    
7093     # Set up the server
7094     if ( ! &bInitializeServer ) {
7095     &vSendHTMLFooter;
7096     exit (-1);
7097     }
7098    
7099     # fill filed descriptions
7100     &fill_SearchFieldDescriptions_fromDB('ps');
7101    
7102     # Are we running as a CGI-BIN script
7103     if ( $ENV{'GATEWAY_INTERFACE'} ) {
7104    
7105    
7106     # Check the CGI environment
7107     if ( ! &bCheckCGIEnvironment ) {
7108     &vSendHTMLFooter;
7109     exit (-1);
7110     }
7111    
7112    
7113     # Set and verify the environment (dont comment this out).
7114     if ( ! &bSetupCGIEnvironment ) {
7115     &vSendHTMLFooter;
7116     exit (-1);
7117     }
7118    
7119    
7120 dpavlin 1.12 if ( defined($main::FormData{'GetSearch'}) ) {
7121 dpavlin 1.1 $ENV{'PATH_INFO'} = "/GetSearch";
7122 dpavlin 1.12 delete($main::FormData{'GetSearch'});
7123     delete($main::FormData{'GetSearch'});
7124 dpavlin 1.1 }
7125    
7126 dpavlin 1.12 if ( defined($main::FormData{'ListSearchHistory'}) ) {
7127 dpavlin 1.1 $ENV{'PATH_INFO'} = "/ListSearchHistory";
7128 dpavlin 1.12 delete($main::FormData{'ListSearchHistory'});
7129     delete($main::FormData{'ListSearchHistory'});
7130 dpavlin 1.1 }
7131    
7132 dpavlin 1.12 if ( defined($main::FormData{'ListSavedSearch'}) ) {
7133 dpavlin 1.1 $ENV{'PATH_INFO'} = "/ListSavedSearch";
7134 dpavlin 1.12 delete($main::FormData{'ListSavedSearch'});
7135     delete($main::FormData{'ListSavedSearch'});
7136 dpavlin 1.1 }
7137    
7138 dpavlin 1.12 if ( defined($main::FormData{'ListFolder'}) ) {
7139 dpavlin 1.1 $ENV{'PATH_INFO'} = "/ListFolder";
7140 dpavlin 1.12 delete($main::FormData{'ListFolder'});
7141     delete($main::FormData{'ListFolder'});
7142 dpavlin 1.1 }
7143    
7144 dpavlin 1.12 if ( defined($main::FormData{'GetUserSettings'}) ) {
7145 dpavlin 1.1 $ENV{'PATH_INFO'} = "/GetUserSettings";
7146 dpavlin 1.12 delete($main::FormData{'GetUserSettings'});
7147     delete($main::FormData{'GetUserSettings'});
7148 dpavlin 1.1 }
7149    
7150    
7151    
7152     # foreach $Value ( keys (%main::FormData) ) {
7153     # $Status = defined($main::FormData{$Value}) ? $main::FormData{$Value} : "(undefined)";
7154     # &vLog("[\$main::FormData{'$Value'} = '$Status']\n");
7155     # }
7156    
7157     # Check for 'Action', set the PATH_INFO from it if it is set
7158     if ( defined($main::FormData{'Action'}) ) {
7159    
7160     if ( ($Value = index($main::FormData{'Action'}, "&")) > 0 ) {
7161     %Value = &hParseURLIntoHashTable(&lDecodeURLData(substr($main::FormData{'Action'}, $Value)));
7162     $main::FormData{'Action'} = substr($main::FormData{'Action'}, 0, $Value);
7163     foreach $Value ( keys(%Value) ) {
7164     $main::FormData{$Value} = $Value{$Value};
7165     }
7166     }
7167    
7168     $ENV{'PATH_INFO'} = "/" . $main::FormData{'Action'};
7169     delete($main::FormData{'Action'});
7170     }
7171    
7172    
7173     # Default to search if PATH_INFO is not defined
7174     if ( !defined($ENV{'PATH_INFO'}) || ($ENV{'PATH_INFO'} eq "") ) {
7175     $ENV{'PATH_INFO'} = "/GetSearch";
7176     }
7177    
7178    
7179     # Check what was requested and take action appropriately
7180     if ( ($ENV{'PATH_INFO'} eq "/GetSearch") || ($ENV{'PATH_INFO'} eq "/GetSimpleSearch") || ($ENV{'PATH_INFO'} eq "/GetExpandedSearch") ) {
7181     &vGetSearch;
7182     }
7183     elsif ( $ENV{'PATH_INFO'} eq "/GetSearchResults" ) {
7184     &vGetSearchResults;
7185     }
7186     elsif ( $ENV{'PATH_INFO'} eq "/GetDatabaseInfo" ) {
7187     &vGetDatabaseInfo;
7188     }
7189     elsif ( $ENV{'PATH_INFO'} eq "/GetDocument" ) {
7190     &vGetDocument;
7191     }
7192     elsif ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
7193     &vGetDocument;
7194     }
7195     elsif ( $ENV{'PATH_INFO'} eq "/GetUserSettings" ) {
7196     &vGetUserSettings;
7197     }
7198     elsif ( $ENV{'PATH_INFO'} eq "/SetUserSettings" ) {
7199     &vSetUserSettings;
7200     }
7201     elsif ( $ENV{'PATH_INFO'} eq "/ListSearchHistory" ) {
7202     &vListSearchHistory;
7203     }
7204     elsif ( $ENV{'PATH_INFO'} eq "/GetSearchHistory" ) {
7205     &vGetSearchHistory;
7206     }
7207     elsif ( $ENV{'PATH_INFO'} eq "/GetSaveSearch" ) {
7208     &vGetSaveSearch;
7209     }
7210     elsif ( $ENV{'PATH_INFO'} eq "/SetSaveSearch" ) {
7211     &vSetSaveSearch;
7212     }
7213     elsif ( $ENV{'PATH_INFO'} eq "/ListSavedSearch" ) {
7214     &vListSavedSearch;
7215     }
7216     elsif ( $ENV{'PATH_INFO'} eq "/GetSavedSearch" ) {
7217     &vGetSavedSearch;
7218     }
7219     elsif ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
7220     &vProcessSavedSearch;
7221     }
7222     elsif ( $ENV{'PATH_INFO'} eq "/ActivateSavedSearch" ) {
7223     &vProcessSavedSearch;
7224     }
7225     elsif ( $ENV{'PATH_INFO'} eq "/SuspendSavedSearch" ) {
7226     &vProcessSavedSearch;
7227     }
7228     elsif ( $ENV{'PATH_INFO'} eq "/GetSaveFolder" ) {
7229     &vGetSaveFolder;
7230     }
7231     elsif ( $ENV{'PATH_INFO'} eq "/SetSaveFolder" ) {
7232     &vSetSaveFolder;
7233     }
7234     elsif ( $ENV{'PATH_INFO'} eq "/ListFolder" ) {
7235     &vListFolder;
7236     }
7237     elsif ( $ENV{'PATH_INFO'} eq "/SetMergeFolder" ) {
7238     &vMergeFolder;
7239     }
7240     elsif ( $ENV{'PATH_INFO'} eq "/GetMergeFolder" ) {
7241     &vMergeFolder;
7242     }
7243     elsif ( $ENV{'PATH_INFO'} eq "/DeleteFolder" ) {
7244     &vProcessFolder;
7245     }
7246     elsif ( $ENV{'PATH_INFO'} eq "/GetFolder" ) {
7247     &vGetFolder;
7248     }
7249     elsif ( $ENV{'PATH_INFO'} eq "/DeleteDocument" ) {
7250     &vProcessDocument;
7251     }
7252     else {
7253     $ENV{'PATH_INFO'} = "/GetSearch";
7254     &vGetSearch;
7255     }
7256    
7257     }
7258     else {
7259    
7260     my ($RunSearches, $Param, $Frequency, $Mday, $Wday);
7261    
7262    
7263     # We are running as a stand alone script
7264    
7265    
7266     #
7267     # Initialize the variables
7268     #
7269    
7270     # Run Searches?
7271     # 0 - dont run searches
7272     # 1 - run searches
7273     $RunSearches = 1;
7274    
7275    
7276     # Init the frequency
7277     $Frequency = "";
7278    
7279     # Check for command parameters
7280     foreach $Param ( @ARGV ) {
7281    
7282     if ( $Param =~ /^-nos/i ) {
7283     # Dont run searches
7284     $RunSearches = 0;
7285     }
7286     elsif ( $Param =~ /^-s/i ) {
7287     # Run searches
7288     $RunSearches = 1;
7289     }
7290     elsif ( $Param =~ /^-d/i ) {
7291     # Want to run the daily
7292     $Frequency .= "|Daily|";
7293     }
7294     elsif ( $Param =~ /^-w/i ) {
7295     # Want to run the weekly
7296     $Frequency .= "|Weekly|";
7297     }
7298     elsif ( $Param =~ /^-m/i ) {
7299     # Want to run the monthly
7300     $Frequency .= "|Monthly|";
7301     }
7302     elsif ( $Param =~ /^-h/i ) {
7303     # help
7304     print("Usage: Search.cgi [-nosearch|-search] [-daily][-weekly][-monthly][-help]\n");
7305     print("\n");
7306     print(" [-nosearch|-search] whether to run or not run searches (default = -search).\n");
7307     print(" [-daily] run daily crawls/searches (overrides default).\n");
7308     print(" [-weekly] run weekly crawls/searches (overrides default).\n");
7309     print(" [-monthly] run monthly crawls/searches (overrides default).\n");
7310     print(" [-help] print the usage and exit.\n");
7311     exit (0);
7312     }
7313     else {
7314     # Invalid param
7315     print("\tError - invalid parameter: '$Param', run 'Search.cgi -help' to get parameter information.\n");
7316     exit (-2);
7317     }
7318     }
7319    
7320    
7321    
7322     # Did we set a frequency usign a command line parameter?
7323     if ( $Frequency eq "" ) {
7324    
7325     # We did not, so we set it based on the following rules
7326     #
7327     # monday-sunday run the daily
7328     # sunday run the weekly
7329     # 1st of the month run the monthly
7330     #
7331    
7332     # Create an ANSI format date/time field
7333     (undef, undef, undef, $Mday, undef, undef, $Wday, undef, undef) = localtime();
7334    
7335     # Always do the daily
7336     $Frequency = "|Daily|";
7337    
7338     # Check for sunday, append the weekly
7339     if ( $Wday == 0 ) {
7340     $Frequency .= "|Weekly|";
7341     }
7342    
7343     # Check for the 1st of the month, append the monthly
7344     if ( $Mday == 1 ) {
7345     $Frequency .= "|Monthly|";
7346     }
7347     }
7348    
7349    
7350     # Log stuff
7351     print("Execution - Frequency: $Frequency\n");
7352    
7353    
7354     # Run the searches
7355     if ( $RunSearches == 1 ) {
7356     &vRunSavedSearches($Frequency);
7357     }
7358     }
7359    
7360    
7361     # Shutdown the server
7362     &bShutdownServer;
7363    
7364    
7365     exit (0);
7366    
7367    
7368    
7369     #--------------------------------------------------------------------------
7370    
7371     # fill SearchFieldDescriptions from one database
7372    
7373     # 2002-06-08 Dobrica Pavlinusic <dpavlin@rot13.org>
7374    
7375     sub fill_SearchFieldDescriptions_fromDB {
7376    
7377     my ($Database) = @_;
7378    
7379     # Get the database field information
7380     my ($Status, $Text) = MPS::GetDatabaseFieldInfo($main::MPSSession, $Database);
7381    
7382     if ( $Status ) {
7383     foreach my $FieldInformation ( split(/\n/, $Text) ) {
7384     my ($FieldName, $FieldDescription, undef) = split(/\t/, $FieldInformation, 3);
7385     $main::SearchFieldDescriptions{$FieldName} = $FieldDescription;
7386     }
7387     }
7388 dpavlin 1.7 }
7389    
7390     #--------------------------------------------------------------------------
7391     # show list of all databases
7392     #
7393     # usage: ShowDatabaseCheckBoxes(@SelectedDatabases)
7394    
7395     sub ShowDatabaseCheckBoxes {
7396     # Parse out the database names and put them into a
7397     # hash table, they should be separated with a '\0'
7398     my %Value;
7399    
7400     foreach my $ItemEntry ( @_ ) {
7401     $Value{$ItemEntry} = $ItemEntry;
7402     }
7403    
7404     print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n");
7405    
7406     my @html_database;
7407    
7408     foreach my $key ( sort keys %main::DatabaseSort ) {
7409     my $DatabaseName = $main::DatabaseSort{$key};
7410     my $Value = ((defined($Value{$DatabaseName})) || (scalar(keys(%main::DatabaseDescriptions)) == 1) || !defined($main::RemoteUser) ) ? "CHECKED" : "";
7411     my $ItemEntry = &lEncodeURLData($DatabaseName);
7412     if ($main::DatabaseDescriptions{$DatabaseName}) {
7413     push @html_database,"<TD ALIGN=LEFT VALIGN=TOP><INPUT TYPE=\"checkbox\" NAME=\"Database\" VALUE=\"$DatabaseName\" $Value> <A HREF=\"$ENV{'SCRIPT_NAME'}/GetDatabaseInfo?Database=$ItemEntry\" OnMouseOver=\"self.status='Informacije io bazi $main::DatabaseDescriptions{$DatabaseName} '; return true\"> $main::DatabaseDescriptions{$DatabaseName} </A> </TD>\n";
7414     } else {
7415     push @html_database,"<td align=left valign=top>$main::DatabaseDescriptions{$DatabaseName}</td>\n";
7416     }
7417     }
7418    
7419    
7420     if ($main::ConfigurationData{'output-colums'}) {
7421     # create database names in columns
7422    
7423     my $cols = $main::ConfigurationData{'show-nr-colums'};
7424     my $next = int($#html_database/$cols) ;
7425    
7426     for(my $i=0; $i <= $next ; $i++) {
7427     print("<tr>");
7428     for(my $j=0; $j <= $cols; $j++) {
7429     print($html_database[$i+$next*$j+$j] || '');
7430     }
7431     print("</tr>");
7432     }
7433    
7434     } else {
7435     for(my $i=0; $i <= $#html_database ; $i=$i+1) {
7436     print("<tr>",$html_database[$i],"</tr>");
7437     }
7438     }
7439    
7440     print("</TABLE>\n");
7441 dpavlin 1.1 }

  ViewVC Help
Powered by ViewVC 1.1.26