/[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.4 - (hide annotations)
Sun Jun 16 19:39:44 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.3: +17 -7 lines
fix here, fix there. removed unused code, more configuration
checks

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

  ViewVC Help
Powered by ViewVC 1.1.26