/[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.1 - (show annotations)
Thu Jun 13 17:01:56 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Branch point for: DbP
Initial revision

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

  ViewVC Help
Powered by ViewVC 1.1.26