/[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.10 - (hide annotations)
Mon Jun 24 17:53:11 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.9: +1 -1 lines
don't use data::dumper

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

  ViewVC Help
Powered by ViewVC 1.1.26