/[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

Contents of /search/Search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Sat Jun 15 17:37:32 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.1: +10 -6 lines
output in multiple colums (different than two)

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

  ViewVC Help
Powered by ViewVC 1.1.26