/[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.11 - (hide annotations)
Tue Jun 25 13:48:12 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.10: +2 -0 lines
convert search string to lower case -> make search case insensitive

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

  ViewVC Help
Powered by ViewVC 1.1.26