/[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.6 - (show annotations)
Mon Jun 24 14:50:44 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.5: +24 -2 lines
Javascript select all/none

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

  ViewVC Help
Powered by ViewVC 1.1.26