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

Annotation of /search/Search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.23 - (hide annotations)
Wed Jul 17 16:55:07 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.22: +2 -1 lines
more error messages

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

  ViewVC Help
Powered by ViewVC 1.1.26