/[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.8 - (hide annotations)
Mon Jun 24 16:49:54 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.7: +3 -0 lines
save html encoded in headline, decode in Search.cgi

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

  ViewVC Help
Powered by ViewVC 1.1.26