/[local]/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.19 - (hide annotations)
Tue Jun 25 17:48:55 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.18: +28 -24 lines
prijevod, popravljeno muglvanje nasih znakova i slova u mala slova (vise
ne unistava nazive polja), a usput dodaje i * na kraj ISBN-a tako da bi
pretrazivanje radilo [?!!!]

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

  ViewVC Help
Powered by ViewVC 1.1.26