/[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.5 - (show annotations)
Mon Jun 24 13:47:06 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.4: +20 -26 lines
moved more configuration to config.pm

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 &vSendHTMLHeader($Value, undef);
2975
2976 undef(%Value);
2977 $Value{'GetSearch'} = "GetSearch";
2978 &vSendMenuBar(%Value);
2979 undef(%Value);
2980
2981
2982 # Print the header ($Value is reused from the header)
2983 print("<H3>$Value:</H3>\n");
2984
2985
2986 # We now have a list of valid databases, at least we think so,
2987 # we check that there is at least one and put up an error message if there are none
2988 if ( scalar(keys(%main::DatabaseDescriptions)) <= 0 ) {
2989 &vHandleError("Database Search", "Sorry, there were no valid databases available for searching");
2990 goto bailFromGetSearch;
2991 }
2992
2993
2994
2995 # Start the search form table
2996 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
2997
2998 # Display the collapse and expand buttons
2999 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2>\n");
3000 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
3001
3002 # List the hidden fields
3003 %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
3004 foreach $Value ( keys(%Value) ) {
3005 @ItemList = split(/\0/, $Value{$Value});
3006 foreach $ItemEntry ( @ItemList ) {
3007 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ItemEntry\">\n");
3008 }
3009 }
3010
3011 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3012 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSimpleSearch\">\n");
3013 print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'collapse'}\" BORDER=0 TYPE=IMAGE> Kliknite na trokutiæ da biste suzili formu.\n");
3014 }
3015 else {
3016 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetExpandedSearch\">\n");
3017 print("<INPUT SRC=\"$main::ConfigurationData{'image-base-path'}/$main::ImageNames{'expand'}\" BORDER=0 TYPE=IMAGE> Kliknite na trokutiæ da biste pro¹irili formu.\n");
3018 }
3019 print("</FORM></TD>\n");
3020
3021
3022
3023 # Send the start of the form and the buttons
3024 print("<TD ALIGN=RIGHT VALIGN=TOP>\n");
3025 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/GetSearchResults\" METHOD=POST> <INPUT TYPE=SUBMIT VALUE=\"Pretra¾i bazu\"> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\">\n");
3026 print("</TD></TR>\n");
3027
3028 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><BR></TD></TR>\n");
3029
3030 # Send the standard fields
3031 $Value = defined($main::FormData{'Any'}) ? "VALUE='$main::FormData{'Any'}'" : "";
3032 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");
3033
3034
3035 my $nr_fields = $main::NormalSearchDropdowns;
3036 my @SearchFieldNames = @main::NormalSearchFieldNames;
3037
3038 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3039 $nr_fields = $main::AdvancedSearchDropdowns;
3040 @SearchFieldNames = @main::AdvancedSearchFieldNames;
3041 }
3042
3043 for (my $field=1; $field<= $nr_fields; $field++) {
3044
3045 print("<TR><TD ALIGN=LEFT VALIGN=TOP>");
3046 if ($field == 1 ) {
3047 print ("Pretra¾i u odreðenom polju:");
3048 }
3049 print ("</TD><TD ALIGN=RIGHT VALIGN=TOP>");
3050
3051 print ("<SELECT NAME=\"FieldName${field}\">");
3052 for (my $i=0; $i<=$#SearchFieldNames; $i++) {
3053 my $ItemEntry = $SearchFieldNames[$i];
3054 my $Selected = "";
3055 if ($main::FormData{"FieldName${field}"} && $main::FormData{"FieldName${field}"} eq $ItemEntry) {
3056 $Selected = "SELECTED";
3057 } elsif ($i == ($field - 1)) {
3058 $Selected = "SELECTED";
3059 }
3060
3061 print("<OPTION VALUE=\"$ItemEntry\" $Selected> $main::SearchFieldDescriptions{$ItemEntry}\n");
3062 }
3063 my $Value = "";
3064 if (defined($main::FormData{"FieldContent${field}"})) {
3065 $Value = "VALUE='".$main::FormData{"FieldContent${field}"}."'";
3066 }
3067 print("</SELECT></TD><TD ALIGN=LEFT><INPUT NAME=\"FieldContent${field}\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
3068 }
3069
3070
3071 # Send a pull-down which allows the user to select what to search for
3072 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");
3073 $Value = (defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "ADJ")) ? "SELECTED" : "";
3074 print("<OPTION VALUE=\"ADJ\"> Toènu frazu\n");
3075 $Value = ((defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "AND")) || !defined($main::FormData{'Operator'})) ? "SELECTED" : "";
3076 print("<OPTION VALUE=\"AND\" $Value> Sve rijeèi (AND)\n");
3077 $Value = (defined($main::FormData{'Operator'}) && ($main::FormData{'Operator'} eq "OR")) ? "SELECTED" : "";
3078 print("<OPTION VALUE=\"OR\" $Value> Bilo koju rijeè (OR)\n");
3079 print("</SELECT> </TD></TR>\n");
3080
3081
3082 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3083
3084
3085
3086 # Database selection
3087 if ( %main::DatabaseDescriptions ) {
3088
3089 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=3> Odaberite bazu koju ¾elite pretra¾ivati: </TD></TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=4>
3090 ");
3091
3092 # Parse out the database names and put them into a
3093 # hash table, they should be separated with a '\0'
3094 undef(%Value);
3095 if ( defined($main::FormData{'Database'}) ) {
3096 @ItemList = split(/\0/, $main::FormData{'Database'});
3097 }
3098 else {
3099 $SelectedDatabases = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SelectedDatabases");
3100 if ( defined($SelectedDatabases) ) {
3101 @ItemList = split(",", $SelectedDatabases);
3102 }
3103 }
3104 foreach $ItemEntry ( @ItemList ) {
3105 $Value{$ItemEntry} = $ItemEntry;
3106 }
3107
3108
3109
3110 $Flag = 0;
3111 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0>\n");
3112
3113 my @html_database;
3114
3115 foreach my $key ( sort keys %main::DatabaseSort ) {
3116 $DatabaseName = $main::DatabaseSort{$key};
3117 $Value = ((defined($Value{$DatabaseName})) || (scalar(keys(%main::DatabaseDescriptions)) == 1) || !defined($main::RemoteUser) ) ? "CHECKED" : "";
3118 $ItemEntry = &lEncodeURLData($DatabaseName);
3119 if ($main::DatabaseDescriptions{$DatabaseName}) {
3120 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";
3121 } else {
3122 push @html_database,"<td align=left valign=top>$main::DatabaseDescriptions{$DatabaseName}</td>\n";
3123 }
3124 }
3125
3126
3127 if ($main::ConfigurationData{'output-colums'}) {
3128 # create database names in columns
3129
3130 my $cols = $main::ConfigurationData{'show-nr-colums'};
3131 my $next = int($#html_database/$cols) ;
3132
3133 for(my $i=0; $i <= $next ; $i++) {
3134 print("<tr>");
3135 for(my $j=0; $j <= $cols; $j++) {
3136 print($html_database[$i+$next*$j+$j] || '');
3137 }
3138 print("</tr>");
3139 }
3140
3141 } else {
3142 for(my $i=0; $i <= $#html_database ; $i=$i+1) {
3143 print("<tr>",$html_database[$i],"</tr>");
3144 }
3145 }
3146
3147 print("</TABLE>\n");
3148
3149 print("</TD></TR>\n");
3150
3151 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3152 }
3153
3154
3155 # Print out the RF documents
3156 if ( defined($main::FormData{'RfDocument'}) ) {
3157 print("<TR>\n");
3158 &bDisplayDocuments("Feedback Document", $main::FormData{'RfDocument'}, "RfDocument", 1, 1, 1);
3159 print("</TR>\n");
3160 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3161 }
3162
3163
3164 # Send complex search pull-downs
3165 if ( $ENV{'PATH_INFO'} eq "/GetExpandedSearch" ) {
3166
3167 if ($main::ConfigurationData{'show-past-date-list'} eq 'yes') {
3168
3169 # Send the past date list
3170 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");
3171 $Value = (!defined($main::FormData{'Past'})) ? "SELECTED" : "";
3172 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3173 foreach $ItemEntry ( @main::PastDate ) {
3174 $Value = (defined($main::FormData{'Past'}) && ($main::FormData{'Past'} eq $ItemEntry)) ? "SELECTED" : "";
3175 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
3176 }
3177 print("</SELECT> </TD></TR>\n");
3178 }
3179
3180
3181 # Send the start date
3182 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");
3183 $Value = (!defined($main::FormData{'Since'})) ? "SELECTED" : "";
3184 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3185
3186 $Year = (localtime)[5] + 1900;
3187
3188 while ( $Year >= $main::ConfigurationData{'lowest-year'} ) {
3189 $Value = (defined($main::FormData{'Since'}) && ($main::FormData{'Since'} eq $Year)) ? "SELECTED" : "";
3190 print("<OPTION VALUE=\"$Year\" $Value> $Year \n");
3191 $Year--;
3192 }
3193 print("</SELECT> </TD></TR>\n");
3194
3195
3196 # Send the end date
3197 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");
3198 $Value = (!defined($main::FormData{'Before'})) ? "SELECTED" : "";
3199 print("<OPTION VALUE=\"\" $Value>Bez ogranièenja...\n");
3200
3201 $Year = (localtime)[5] + 1900;
3202
3203 while ( $Year >= $main::ConfigurationData{'lowest-year'} ) {
3204 $Value = (defined($main::FormData{'Before'}) && ($main::FormData{'Before'} eq $Year)) ? "SELECTED" : "";
3205 print("<OPTION VALUE=\"$Year\" $Value> $Year \n");
3206 $Year--;
3207 }
3208 print("</SELECT> </TD></TR>\n");
3209
3210 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3211 }
3212
3213
3214 # Send a pull-down which allows the user to select the max number of documents
3215 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Maksimalan broj rezultata pretra¾ivanja: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Max\">\n");
3216
3217 foreach $ItemEntry ( @main::MaxDocs ) {
3218 $Value = ((defined($main::FormData{'Max'}) && ($main::FormData{'Max'} eq $ItemEntry)) || (!defined($main::FormData{'Max'}) && ($ItemEntry eq $main::DefaultMaxDoc)) ) ? "SELECTED" : "";
3219 if ( ($ItemEntry >= 500) && $ENV{'PATH_INFO'} ne "/GetExpandedSearch" ) {
3220 next;
3221 }
3222 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
3223 }
3224
3225 print("</SELECT> </TD></TR>\n");
3226
3227
3228 # Send a pull-down which allows the user to select the sort order
3229 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> Sortiranje rezultata: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"Order\">\n");
3230 # print("<OPTION VALUE=\"\"> Relevance\n");
3231 $Value = (defined($main::FormData{'Order'}) && ($main::FormData{'Order'} eq "SORT:DATE:DESC")) ? "SELECTED" : "";
3232 print("<OPTION VALUE=\"SORT:DATE:DESC\" $Value> Datum - najprije novije\n");
3233 $Value = (defined($main::FormData{'Order'}) && ($main::FormData{'Order'} eq "DATEASCSORT")) ? "SELECTED" : "";
3234 print("<OPTION VALUE=\"SORT:DATE:ASC\" $Value> Datum - najprije starije\n");
3235 print("</SELECT> </TD></TR>\n");
3236
3237
3238 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3239 print("<TR><TD ALIGN=RIGHT COLSPAN=3><INPUT TYPE=SUBMIT VALUE=\"Pretra¾i bazu\"> <INPUT TYPE=RESET VALUE=\"Pobri¹i polja\"></TD></TR>\n");
3240
3241 print("</FORM>\n");
3242 print("</TABLE>\n");
3243
3244
3245 # Bail from the search
3246 bailFromGetSearch:
3247
3248 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3249 undef(%Value);
3250 $Value{'GetSearch'} = "GetSearch";
3251 &vSendMenuBar(%Value);
3252 undef(%Value);
3253
3254 &vSendHTMLFooter;
3255
3256 return;
3257
3258 }
3259
3260
3261
3262
3263
3264
3265 #--------------------------------------------------------------------------
3266 #
3267 # Function: vGetSearchResults()
3268 #
3269 # Purpose: This function run the search and displays the results to the user
3270 #
3271 # Called by:
3272 #
3273 # Parameters: void
3274 #
3275 # Global Variables: %main::ConfigurationData, %main::FormData, $main::RemoteUser
3276 #
3277 # Returns: void
3278 #
3279 sub vGetSearchResults {
3280
3281 my (%Databases, $Databases, $SearchString, $SearchAndRfDocumentURL, $RfText);
3282 my ($Status, $DocumentText, $SearchResults, $QueryReport, $ErrorNumber, $ErrorMessage);
3283 my ($DatabaseRelevanceFeedbackFilterKey, $DatabaseRelevanceFeedbackFilterFunction);
3284 my (@Values, %Value, $Value);
3285
3286
3287
3288 # Check to see if there are any documents selected, if there are, they need
3289 # to be converted to RF documents before we put up the header, this is because
3290 # the header creates a search link from existing search fields, we also deduplicate
3291 # documents along the way
3292 if ( defined($main::FormData{'RfDocument'}) || defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) {
3293
3294 # Undefine the hash table in preparation
3295 undef(%Value);
3296
3297 # Make a hash table from the documents already selected for feedback
3298 if ( defined($main::FormData{'RfDocument'}) ) {
3299 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3300 $Value{$Value} = $Value;
3301 }
3302 }
3303
3304 # Add document that were specifically selected
3305 if ( defined($main::FormData{'Document'}) ) {
3306 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
3307 $Value{$Value} = $Value;
3308 }
3309 }
3310 # Otherwise add documents that were selected by default
3311 elsif ( defined($main::FormData{'Documents'}) ) {
3312 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
3313 $Value{$Value} = $Value;
3314 }
3315 }
3316
3317 # Assemble the new content
3318 $main::FormData{'RfDocument'} = join("\0", keys(%Value));
3319
3320 # Delete the old content
3321 delete($main::FormData{'Document'});
3322 delete($main::FormData{'Documents'});
3323 }
3324
3325
3326 # Set the database names if needed
3327 if ( !defined($main::FormData{'Database'}) && defined($main::FormData{'RfDocument'}) ) {
3328
3329 # Loop over each entry in the documents list
3330 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3331
3332 # Parse out the document entry
3333 %Value = &hParseURLIntoHashTable($Value);
3334
3335 # Add the database name to the hash table
3336 $Databases{$Value{'Database'}} = $Value{'Database'};
3337 }
3338
3339 $main::FormData{'Database'} = join("\0", keys(%Databases));
3340 }
3341
3342
3343
3344 # Make sure that we send the header
3345 &vSendHTMLHeader("Rezultati pretra¾ivanja", undef);
3346 undef(%Value);
3347 &vSendMenuBar(%Value);
3348
3349
3350 # Check that at least one database was selected
3351 if ( !defined($main::FormData{'Database'}) ) {
3352 print("<H3>Database Search:</H3>\n");
3353 print("<H3><CENTER>Sorry, no database(s) were selected for searching.</CENTER></H3>\n");
3354 print("<P>\n");
3355 print("There needs to be a least one database selected in order to perform the search.\n");
3356 print("Click <B>'back'</B> on your browser, select at least one database and try again.\n");
3357 goto bailFromGetSearchResults;
3358 }
3359
3360
3361
3362 # Extract the search information
3363 foreach $Value ( 1..100 ) {
3364
3365 my ($FieldName) = "FieldName" . $Value;
3366 my ($FieldContent) = "FieldContent" . $Value;
3367
3368 if ( defined($main::FormData{$FieldName}) ) {
3369 if ( defined($main::FormData{$FieldContent}) && ($main::FormData{$FieldContent} ne "") ) {
3370 $main::FormData{$main::FormData{$FieldName}} = $main::FormData{$FieldContent};
3371 }
3372 }
3373 }
3374
3375
3376
3377 # Set the local database names
3378 if ( defined($main::FormData{'Database'}) ) {
3379 $Databases = $main::FormData{'Database'};
3380 }
3381
3382
3383 # Convert all the '\0' to ','
3384 $Databases =~ tr/\0/,/;
3385
3386
3387 # Add the max doc restriction
3388 if ( !defined($main::FormData{'Max'}) ) {
3389 $main::FormData{'Max'} = $main::DefaultMaxDoc;
3390 }
3391
3392
3393 # Generate the search string
3394 $SearchString = &sMakeSearchString(%main::FormData);
3395
3396 # Retrieve the relevance feedback documents
3397 if ( defined($main::FormData{'RfDocument'}) ) {
3398
3399 $RfText = "";
3400
3401 # Loop over each entry in the documents list
3402 foreach $Value ( split(/\0/, $main::FormData{'RfDocument'}) ) {
3403
3404 # Parse out the document entry
3405 %Value = &hParseURLIntoHashTable($Value);
3406
3407 # Check this document can be used for relevance feedback
3408 if ( !defined($main::RFMimeTypes{$Value{'MimeType'}}) ) {
3409 next;
3410 }
3411
3412 # Get the document
3413 ($Status, $DocumentText) = MPS::GetDocument($main::MPSSession, $Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'});
3414
3415 if ( $Status ) {
3416
3417 $DatabaseRelevanceFeedbackFilterKey = "$main::DatabaseRelevanceFeedbackFilter:$Value{'Database'}:$Value{'ItemName'}:$Value{'MimeType'}";
3418
3419 # Is a filter defined for this database relevance feedback filter key ?
3420 if ( defined($main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey}) ) {
3421
3422 # Pull in the package
3423 require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Value{'Database'}"};
3424
3425 # Filter the document
3426 $Value = $main::DatabaseFilters{$DatabaseRelevanceFeedbackFilterKey};
3427 $DatabaseRelevanceFeedbackFilterFunction = \&$Value;
3428 $DocumentText = $DatabaseRelevanceFeedbackFilterFunction->($Value{'Database'}, $Value{'DocumentID'}, $Value{'ItemName'}, $Value{'MimeType'}, $DocumentText);
3429
3430 }
3431 else {
3432
3433 # Strip the HTML from the text (this is only really useful on HTML documents)
3434 if ( defined($main::HtmlMimeTypes{$Value{'MimeType'}}) ) {
3435 $DocumentText =~ s/&nbsp;//gs;
3436 $DocumentText =~ s/<.*?>//gs;
3437 }
3438 }
3439
3440 $RfText .= $DocumentText . " ";
3441 }
3442 }
3443 }
3444
3445
3446 # Run the search
3447 ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Databases, $SearchString, $RfText, 0, $main::FormData{'Max'} - 1, $main::ConfigurationData{'max-score'});
3448
3449 if ( $Status ) {
3450
3451 # Display the search results and get the query report text
3452 ($Status, $QueryReport) = &bsDisplaySearchResults("Rezultati pretra¾ivanja:", undef, undef, undef, $SearchResults, undef, $ENV{'SCRIPT_NAME'}, 1, 1, 1, %main::FormData);
3453
3454 # Save the search history
3455 if ( defined($main::RemoteUser) ) {
3456
3457 # Generate the search string
3458 $SearchAndRfDocumentURL = &sMakeSearchAndRfDocumentURL(%main::FormData);
3459
3460 # Save the search history
3461 &iSaveSearchHistory(undef, $SearchAndRfDocumentURL, $SearchResults, $QueryReport);
3462
3463 # Purge the search history files
3464 &vPurgeSearchHistory;
3465 }
3466 }
3467 else {
3468 ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
3469 &vHandleError("Database Search", "Sorry, failed to search the database(s)");
3470 print("The following error message was reported: <BR>\n");
3471 print("Error Message: $ErrorMessage <BR>\n");
3472 print("Error Number: $ErrorNumber <BR>\n");
3473 goto bailFromGetSearchResults;
3474 }
3475
3476
3477 # Bail from the search
3478 bailFromGetSearchResults:
3479
3480 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3481 undef(%Value);
3482 &vSendMenuBar(%Value);
3483
3484 &vSendHTMLFooter;
3485
3486 return;
3487
3488 }
3489
3490
3491
3492
3493
3494
3495 #--------------------------------------------------------------------------
3496 #
3497 # Function: vGetDatabaseInfo()
3498 #
3499 # Purpose: This function allows the user to get some database information
3500 # such as the description, the contents and the time period spanned
3501 # by the content.
3502 #
3503 # Called by:
3504 #
3505 # Parameters: void
3506 #
3507 # Global Variables: %main::ConfigurationData, %main::FormData
3508 #
3509 # Returns: void
3510 #
3511 sub vGetDatabaseInfo {
3512
3513 my ($DatabaseDescription, $DatabaseLanguage, $DatabaseTokenizer, $DocumentCount, $TotalWordCount, $UniqueWordCount, $StopWordCount, $AccessControl, $UpdateFrequency, $LastUpdateDate, $LastUpdateTime, $CaseSensitive);
3514 my ($FieldInformation, $FieldName, $FieldDescription);
3515 my ($Status, $Text, $Time, $Title);
3516 my ($ErrorNumber, $ErrorMessage);
3517 my ($Value, %Value);
3518
3519
3520
3521 # Check we that we got a database name
3522 if ( !defined($main::FormData{'Database'}) ) {
3523 &vHandleError("Database information", "Sorry, the database content description could not be obtained");
3524 goto bailFromGetDatabaseInfo;
3525 }
3526
3527
3528 # Make sure that we send the header
3529 $Title = "Database Information: " . (defined($main::DatabaseDescriptions{$main::FormData{'Database'}})
3530 ? $main::DatabaseDescriptions{$main::FormData{'Database'}} : "");
3531 &vSendHTMLHeader($Title, undef);
3532 undef(%Value);
3533 &vSendMenuBar(%Value);
3534
3535
3536 # Get the database information
3537 ($Status, $Text) = MPS::GetDatabaseInfo($main::MPSSession, $main::FormData{'Database'});
3538
3539 if ( $Status ) {
3540
3541 # Display the database information
3542 print("<H3>Database information:</H3>\n");
3543
3544 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
3545
3546
3547 # Send the database description
3548 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");
3549 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3550
3551 # Truncate the line
3552 chop ($Text);
3553
3554 # Parse the database information
3555 ($DatabaseDescription, $DatabaseLanguage, $DatabaseTokenizer, $DocumentCount, $TotalWordCount, $UniqueWordCount, $StopWordCount, $AccessControl, $UpdateFrequency, $LastUpdateDate, $LastUpdateTime, $CaseSensitive) = split(/\t/, $Text);
3556
3557 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");
3558 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Total number of words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $TotalWordCount </TD></TR>\n");
3559 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Number of unique words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $UniqueWordCount </TD></TR>\n");
3560 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Number of stop words: </TD> <TD ALIGN=LEFT VALIGN=TOP> $StopWordCount </TD></TR>\n");
3561
3562 # Get the time of last update of the data directory
3563 # $Time = (stat("$main::ConfigurationData{'data-directory'}/$main::FormData{'Database'}/"))[9];
3564 # $Value = &sGetPrintableDateFromTime($Time);
3565 # print("<TR><TD ALIGN=LEFT VALIGN=TOP> Data last updated on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
3566
3567 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Index last updated on: </TD> <TD ALIGN=LEFT VALIGN=TOP> $LastUpdateDate ($LastUpdateTime) </TD></TR>\n");
3568
3569 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
3570
3571 # Get the database field information
3572 ($Status, $Text) = MPS::GetDatabaseFieldInfo($main::MPSSession, $main::FormData{'Database'});
3573
3574 if ( $Status ) {
3575 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");
3576
3577 foreach $FieldInformation ( split(/\n/, $Text) ) {
3578 ($FieldName, $FieldDescription, $Value) = split(/\t/, $FieldInformation, 3);
3579 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> $FieldName </TD> <TD ALIGN=LEFT VALIGN=TOP> $FieldDescription </TD></TR>\n");
3580 }
3581 }
3582
3583 print("</TABLE>\n");
3584
3585 }
3586 else {
3587 ($ErrorNumber, $ErrorMessage) = split(/\t/, $Text, 2);
3588 &vHandleError("Database information", "Sorry, failed to get the database information");
3589 print("The following error message was reported: <BR>\n");
3590 print("Error Message: $ErrorMessage <BR>\n");
3591 print("Error Number: $ErrorNumber <BR>\n");
3592 goto bailFromGetDatabaseInfo;
3593 }
3594
3595
3596
3597 # Bail from the database info
3598 bailFromGetDatabaseInfo:
3599
3600 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3601 undef(%Value);
3602 &vSendMenuBar(%Value);
3603
3604 &vSendHTMLFooter;
3605
3606 return;
3607
3608 }
3609
3610
3611
3612
3613
3614
3615 #--------------------------------------------------------------------------
3616 #
3617 # Function: vGetDocument()
3618 #
3619 # Purpose: This function get a document from the database.
3620 #
3621 # Called by:
3622 #
3623 # Parameters: void
3624 #
3625 # Global Variables: %main::ConfigurationData, %main::FormData,
3626 # $main::FooterSent
3627 #
3628 # Returns: void
3629 #
3630 sub vGetDocument {
3631
3632 my (@DocumentList, %Document, $Document, $TextDocumentFlag);
3633 my ($Status, $Data, $ErrorNumber, $ErrorMessage);
3634 my (%QualifiedDocumentFolders, $QualifiedDocumentFolders, $FolderName, $DocumentFolderEntry);
3635 my ($DatabaseDocumentFilterFunction, $DatabaseDocumentFilterKey);
3636 my ($SelectorText, $FilteredData, $SimilarDocuments, $SearchResults);
3637 my (%Value, $Value);
3638
3639
3640
3641 # Assemble the documents selected into a list do that we keep their order
3642 if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) || defined($main::FormData{'DocumentID'}) ) {
3643
3644 # Undefine the hash table in preparation
3645 undef(%Value);
3646
3647 # Add document that were specifically selected
3648 if ( defined($main::FormData{'Document'}) ) {
3649 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
3650 if ( !defined($Value{$Value}) ) {
3651 push @DocumentList, $Value;
3652 $Value{$Value} = $Value;
3653 }
3654 }
3655 }
3656 # Otherwise add documents that were selected by default
3657 elsif ( defined($main::FormData{'Documents'}) ) {
3658 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
3659 if ( !defined($Value{$Value}) ) {
3660 push @DocumentList, $Value;
3661 $Value{$Value} = $Value;
3662 }
3663 }
3664 }
3665
3666 # Add document from the URL
3667 if ( defined($main::FormData{'DocumentID'}) ) {
3668 $Value = "";
3669 $Value .= (defined($main::FormData{'Database'}) && ($main::FormData{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($main::FormData{'Database'}) : "";
3670 $Value .= (defined($main::FormData{'DocumentID'}) && ($main::FormData{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($main::FormData{'DocumentID'}) : "";
3671 $Value .= (defined($main::FormData{'ItemName'}) && ($main::FormData{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($main::FormData{'ItemName'}) : "";
3672 $Value .= (defined($main::FormData{'MimeType'}) && ($main::FormData{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($main::FormData{'MimeType'}) : "";
3673 if ( !defined($Value{$Value}) ) {
3674 push @DocumentList, $Value;
3675 $Value{$Value} = $Value;
3676 }
3677 }
3678 }
3679
3680
3681
3682 # Catch no document selection
3683 if ( !@DocumentList || (scalar(@DocumentList) == 0) ) {
3684
3685 # Make sure that we send the header
3686 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3687 &vSendHTMLHeader("Similar Documents", undef);
3688 }
3689 else {
3690 &vSendHTMLHeader("Documents", undef);
3691 }
3692 undef(%Value);
3693 &vSendMenuBar(%Value);
3694
3695 print("<H3>Document retrieval:</H3>\n");
3696 print("<H3><CENTER>Sorry, no document(s) were selected for retrieval.</CENTER></H3>\n");
3697 print("<P>\n");
3698 print("There needs to be a least one document selected in order to perform the retrieval.\n");
3699 print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
3700 goto bailFromGetDocument;
3701 }
3702
3703
3704
3705 # Set the text document flag
3706 $TextDocumentFlag = 0;
3707
3708 # Check the documents for text based documents
3709 foreach $Document ( @DocumentList ) {
3710
3711 # Parse out the document entry
3712 %Document = &hParseURLIntoHashTable($Document);
3713
3714 # Set the text flag if there are any text documents in the list
3715 if ( $Document{'MimeType'} =~ /^text\// ) {
3716 $TextDocumentFlag = 1;
3717 }
3718 }
3719
3720
3721
3722 # If there were no text documents in our list, we display the first document in the
3723 # list, this is to handle cases where got one or more non-text documents (such as
3724 # images, pdf files, etc)
3725 if ( ! $TextDocumentFlag ) {
3726
3727 %Document = &hParseURLIntoHashTable($DocumentList[0]);
3728
3729 # Get the document
3730 ($Status, $Data) = MPS::GetDocument($main::MPSSession, $Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'});
3731
3732 if ( !$Status ) {
3733
3734 # Make sure that we send the header
3735 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3736 &vSendHTMLHeader("Similar Documents", undef);
3737 }
3738 else {
3739 &vSendHTMLHeader("Documents", undef);
3740 }
3741 undef(%Value);
3742 &vSendMenuBar(%Value);
3743
3744 ($ErrorNumber, $ErrorMessage) = split(/\t/, $Data, 2);
3745 # The database document could not be gotten, so we inform the user of the fact
3746 &vHandleError("Document retrieval", "Sorry, the database document could not be obtained");
3747 print("The following error message was reported: <BR>\n");
3748 print("Error Message: $ErrorMessage <BR>\n");
3749 print("Error Number: $ErrorNumber <BR>\n");
3750 goto bailFromGetDocument;
3751 }
3752
3753 # Send the content type
3754 print("Content-type: $Document{'MimeType'}\n\n");
3755
3756 # Send the document
3757 print("$Data");
3758
3759 return;
3760 }
3761
3762
3763
3764 # Make sure that we send the header
3765 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3766 &vSendHTMLHeader("Similar Documents", undef);
3767 }
3768 else {
3769 &vSendHTMLHeader("Documents", undef);
3770 }
3771 undef(%Value);
3772 &vSendMenuBar(%Value);
3773
3774
3775
3776 # Print the header
3777 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3778 print("<H3>Similar Documents:</H3>\n");
3779 }
3780 else {
3781 print("<H3>Dokumenti:</H3>\n");
3782 }
3783
3784
3785 # Start the form
3786 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
3787
3788 # Send the pull-down
3789 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
3790 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");
3791
3792 if ( defined($main::RemoteUser) ) {
3793 print("<SELECT NAME=\"Action\">\n");
3794 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3795 print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultate\n");
3796 }
3797 if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
3798 print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
3799 }
3800 if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
3801 print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
3802 }
3803 print("<OPTION VALUE=\"GetSaveFolder\">Save selected documents to a new document folder\n");
3804
3805 # Get the document folder hash
3806 %QualifiedDocumentFolders = &hGetDocumentFolders;
3807
3808 for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
3809
3810 $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
3811
3812 # Get the document folder file name and encode it
3813 $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
3814 $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
3815
3816 print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry\">Add selected documents to the '$FolderName' document folder\n");
3817 }
3818
3819 print("</SELECT>\n");
3820 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
3821 }
3822 else {
3823 if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
3824 print("<INPUT TYPE=HIDDEN NAME=\"Action\" VALUE=\"GetSearchResults\">\n");
3825 print("<INPUT TYPE=SUBMIT VALUE=\"Run search with documents as relevance feedback\">\n");
3826 }
3827 }
3828
3829 print("</TD></TR>\n");
3830 print("</TABLE>\n");
3831
3832
3833 # Display the documents
3834
3835 print("<TABLE BORDER=0 CELLPADDING=3 CELLSPACING=0 WIDTH=100%>\n");
3836
3837
3838 # Display the selector for all the documents
3839 $SelectorText = "";
3840
3841 foreach $Document ( @DocumentList ) {
3842
3843 # Parse out the document entry
3844 %Document = &hParseURLIntoHashTable($Document);
3845
3846 # Skip non-text documents
3847 if ( !($Document{'MimeType'} =~ /^text\//) ) {
3848 next;
3849 }
3850
3851 $Value = "";
3852 $Value .= (defined($Document{'Database'}) && ($Document{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Document{'Database'}) : "";
3853 $Value .= (defined($Document{'DocumentID'}) && ($Document{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Document{'DocumentID'}) : "";
3854 $Value .= (defined($Document{'ItemName'}) && ($Document{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($Document{'ItemName'}) : "";
3855 $Value .= (defined($Document{'MimeType'}) && ($Document{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($Document{'MimeType'}) : "";
3856 $SelectorText .= (($SelectorText ne "") ? "|" : "") . substr($Value, 1);
3857 }
3858
3859 $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
3860 print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> $SelectorText </TD></TR>\n");
3861
3862
3863
3864 # Get the similar documents value
3865 if ( defined($main::RemoteUser) ) {
3866 $SimilarDocuments = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SimilarDocuments");
3867 }
3868 else {
3869 $SimilarDocuments = $main::DefaultSimilarDocument;
3870 }
3871
3872
3873
3874 foreach $Document ( @DocumentList ) {
3875
3876 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3> <HR WIDTH=50%> </TD></TR>\n");
3877
3878
3879 # Parse out the document entry
3880 %Document = &hParseURLIntoHashTable($Document);
3881
3882 # Skip non-text documents
3883 if ( !($Document{'MimeType'} =~ /^text\//) ) {
3884 next;
3885 }
3886
3887
3888 # Get the document
3889 ($Status, $Data) = MPS::GetDocument($main::MPSSession, $Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'});
3890
3891 if ( !$Status ) {
3892 ($ErrorNumber, $ErrorMessage) = split(/\t/, $Data, 2);
3893 # The database document could not be gotten, so we inform the user of the fact
3894 &vHandleError("Document retrieval", "Sorry, the database document could not be obtained");
3895 print("The following error message was reported: <BR>\n");
3896 print("Error Message: $ErrorMessage <BR>\n");
3897 print("Error Number: $ErrorNumber <BR>\n");
3898 goto bailFromGetDocument;
3899 }
3900
3901
3902 # Create the database document filter key
3903 $DatabaseDocumentFilterKey = "$main::DatabaseDocumentFilter:$Document{'Database'}:$Document{'ItemName'}:$Document{'MimeType'}";
3904
3905 # Is a filter defined for this database document filter key ?
3906 if ( defined($main::DatabaseFilters{$DatabaseDocumentFilterKey}) ) {
3907
3908 # Pull in the package
3909 require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:$Document{'Database'}"};
3910
3911 # Filter the document
3912 $Value = $main::DatabaseFilters{$DatabaseDocumentFilterKey};
3913 $DatabaseDocumentFilterFunction = \&$Value;
3914 $FilteredData = $DatabaseDocumentFilterFunction->($Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'}, $Data);
3915 } else {
3916 # use default filter key
3917
3918 # Pull in the package
3919 require $main::DatabaseFilters{"$main::DatabaseFiltersPackage:default"};
3920
3921 # Filter the document
3922 $Value = $main::DatabaseFilters{"$main::DatabaseDocumentFilter:default:$Document{'ItemName'}:$Document{'MimeType'}"};
3923 $DatabaseDocumentFilterFunction = \&$Value;
3924 $FilteredData = $DatabaseDocumentFilterFunction->($Document{'Database'}, $Document{'DocumentID'}, $Document{'ItemName'}, $Document{'MimeType'}, $Data);
3925 }
3926
3927
3928
3929 # Create the document selector button text
3930 $SelectorText = "";
3931 $SelectorText .= (defined($Document{'Database'}) && ($Document{'Database'} ne "")) ? "&Database=" . &lEncodeURLData($Document{'Database'}) : "";
3932 $SelectorText .= (defined($Document{'DocumentID'}) && ($Document{'DocumentID'} ne "")) ? "&DocumentID=" . &lEncodeURLData($Document{'DocumentID'}) : "";
3933 $SelectorText .= (defined($Document{'ItemName'}) && ($Document{'ItemName'} ne "")) ? "&ItemName=" . &lEncodeURLData($Document{'ItemName'}) : "";
3934 $SelectorText .= (defined($Document{'MimeType'}) && ($Document{'MimeType'} ne "")) ? "&MimeType=" . &lEncodeURLData($Document{'MimeType'}) : "";
3935 $SelectorText = "<INPUT TYPE=\"checkbox\" NAME=\"Document\" VALUE=\"" . substr($SelectorText, 1) . "\"> ";
3936
3937
3938 # Send the document text
3939 print("<TR><TD ALIGN=LEFT VALIGN=TOP> $SelectorText </TD> <TD ALIGN=LEFT VALIGN=TOP>$FilteredData</TD></TR>");
3940 if ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
3941
3942 # Get the similar documents if needed
3943 if ( defined($main::ConfigurationData{'allow-similiar-search'}) && ($main::ConfigurationData{'allow-similiar-search'} eq "yes") &&
3944 defined($SimilarDocuments) ) {
3945
3946 # Run the search, discard the query report
3947 ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Document{'Database'}, "{NOREPORT}", $Data, 0, $SimilarDocuments - 1, $main::ConfigurationData{'max-score'});
3948
3949 if ( $Status ) {
3950
3951 # Display the search result
3952 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3> <HR WIDTH=25%> </TD></TR>\n");
3953 print("<TR><TD ALIGN=LEFT VALIGN=TOP></TD> <TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> \n");
3954 print("<B>Similar Documents:</B>\n");
3955 ($Status, undef) = &bsDisplaySearchResults("Similar Documents:", undef, undef, undef, $SearchResults, undef, $ENV{'SCRIPT_NAME'}, 0, 1, 1, %main::FormData);
3956 print("</TD></TR>\n");
3957 }
3958 else {
3959 ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
3960 &vHandleError("Database Search", "Sorry, failed to search the database(s)");
3961 print("The following error message was reported: <BR>\n");
3962 print("Error Message: $ErrorMessage <BR>\n");
3963 print("Error Number: $ErrorNumber <BR>\n");
3964 goto bailFromGetDocument;
3965 }
3966 }
3967 }
3968 }
3969
3970
3971 # Close off the form
3972 print("</FORM>\n");
3973
3974 # Close off the table
3975 print("</TABLE>\n");
3976
3977
3978 # Bail from getting the document
3979 bailFromGetDocument:
3980
3981 print("<CENTER><HR WIDTH=50%></CENTER>\n");
3982 undef(%Value);
3983 &vSendMenuBar(%Value);
3984
3985 &vSendHTMLFooter;
3986
3987 return;
3988
3989 }
3990
3991
3992
3993
3994
3995
3996 #--------------------------------------------------------------------------
3997 #
3998 # Function: vGetUserSettings()
3999 #
4000 # Purpose: This function displays a user settings form to the user
4001 #
4002 # Called by:
4003 #
4004 # Parameters: void
4005 #
4006 # Global Variables: %main::ConfigurationData, %main::FormData,
4007 # $main::UserSettingsFilePath, $main::RemoteUser,
4008 #
4009 # Returns: void
4010 #
4011 sub vGetUserSettings {
4012
4013 my ($UserName, $SearchHistory, $DefaultSearch, $SelectedDatabases, $EmailAddress, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SummaryType, $SummaryLength, $SimilarDocuments);
4014 my ($SearchHistoryCount, $HeaderName);
4015 my ($DatabaseName, @ItemList, $ItemEntry, $Flag);
4016 my ($Value, %Value);
4017
4018
4019 # Return an error if the remote user name/account directory is not defined
4020 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4021 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4022 &vSendHTMLFooter;
4023 return;
4024 }
4025
4026
4027
4028 # Make sure that we send the header
4029 &vSendHTMLHeader("My Settings", undef);
4030 undef(%Value);
4031 $Value{'GetUserSettings'} = "GetUserSettings";
4032 &vSendMenuBar(%Value);
4033 undef(%Value);
4034
4035
4036
4037 # Get information from the XML saved search file
4038 ($HeaderName, %Value) = &shGetHashFromXMLFile($main::UserSettingsFilePath);
4039
4040 # Check the header if it is defines, delete the file if it is not valid,
4041 # else set the variables from the hash table contents
4042 if ( defined($HeaderName) ) {
4043 if ( $HeaderName ne "UserSettings" ) {
4044 unlink($main::UserSettingsFilePath);
4045 }
4046 else {
4047 $UserName = $Value{'UserName'};
4048 $SearchHistory = $Value{'SearchHistory'};
4049 $DefaultSearch = $Value{'DefaultSearch'};
4050 $SelectedDatabases = $Value{'SelectedDatabases'};
4051 $EmailAddress = $Value{'EmailAddress'};
4052 $SearchFrequency = $Value{'SearchFrequency'};
4053 $DeliveryFormat = $Value{'DeliveryFormat'};
4054 $DeliveryMethod = $Value{'DeliveryMethod'};
4055 $SummaryType = $Value{'SummaryType'};
4056 $SummaryLength = $Value{'SummaryLength'};
4057 $SimilarDocuments = $Value{'SimilarDocuments'};
4058 }
4059 }
4060
4061
4062 # Give the user a form to fill out
4063
4064 print("<H3> Postavke: </H3>\n");
4065
4066 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4067 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetUserSettings\" METHOD=POST>\n");
4068
4069 # Send the buttons
4070 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");
4071
4072
4073
4074 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4075
4076 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Informacije o korisniku: </B> </TR>\n");
4077
4078 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Login: </TD><TD ALIGN=LEFT VALIGN=TOP> $ENV{'REMOTE_USER'} </TD></TR>\n");
4079
4080 $Value = (defined($UserName)) ? "VALUE=\"$UserName\"" : "";
4081 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");
4082
4083 # Are regular searches enabled?
4084 if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4085
4086 # Get the email address
4087 $Value = (defined($EmailAddress)) ? "VALUE=\"$EmailAddress\"" : "";
4088 print("<TR><TD ALIGN=LEFT VALIGN=TOP> E-mail adresa:");
4089 if ( !defined($EmailAddress) && defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4090 print(" (*) ");
4091 }
4092 print(": </TD> <TD ALIGN=LEFT VALIGN=TOP> <INPUT NAME=\"EmailAddress\" TYPE=TEXT $Value SIZE=45> </TD></TR>\n");
4093
4094 if ( !defined($EmailAddress) && defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4095 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");
4096 }
4097 }
4098
4099
4100 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4101
4102 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Search Preferences: </B> </TD></TR>\n");
4103
4104 # Send a pull-down which allows the user to select which search form to default to
4105 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Forma za pretra¾ivanje: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DefaultSearch\">\n");
4106 $Value = (defined($DefaultSearch) && ($DefaultSearch eq "Simple")) ? "SELECTED" : "";
4107 print("<OPTION VALUE=\"Simple\" $Value> Jednostavna forma za pretra¾ivanje\n");
4108 $Value = (defined($DefaultSearch) && ($DefaultSearch eq "Expanded")) ? "SELECTED" : "";
4109 print("<OPTION VALUE=\"Expanded\" $Value>Forma za pretra¾ivanje s vi¹e kriterija\n");
4110 print("</SELECT> </TD></TR>\n");
4111
4112 # Send a pull-down which allows the user to select how many previous searches to store
4113 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");
4114
4115 for ( $SearchHistoryCount = 5; $SearchHistoryCount <= 20; $SearchHistoryCount += 5 ) {
4116 $Value = (defined($SearchHistory) && ($SearchHistory == $SearchHistoryCount)) ? "SELECTED" : "";
4117 print("<OPTION VALUE=\"$SearchHistoryCount\" $Value> $SearchHistoryCount \n");
4118 }
4119 print("</SELECT> </TD></TR>\n");
4120
4121
4122 # Database selection preferences
4123 if ( %main::DatabaseDescriptions ) {
4124
4125 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4126
4127 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Odabrane baze: </B> </TD></TR>\n");
4128
4129 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Oznaèite baze koje uvijek ¾elite pretra¾ivati: </TD> <TD ALIGN=LEFT VALIGN=TOP>\n");
4130
4131 # Parse out the database names and put them into a
4132 # hash table, they should be separated with a '\n'
4133 undef(%Value);
4134 if ( defined($SelectedDatabases) && ($SelectedDatabases ne "") ) {
4135 @ItemList = split(",", $SelectedDatabases);
4136 foreach $ItemEntry ( @ItemList ) {
4137 $Value{$ItemEntry} = $ItemEntry;
4138 }
4139 }
4140
4141 $Flag = 0;
4142 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%\n");
4143
4144 foreach $DatabaseName ( sort(keys(%main::DatabaseDescriptions)) ) {
4145
4146 if ( $Flag == 0 ) {
4147 print("<TR>");
4148 }
4149
4150 $Value = ((defined($Value{$DatabaseName})) || (scalar(keys(%main::DatabaseDescriptions)) == 1)) ? "CHECKED" : "";
4151 $ItemEntry = &lEncodeURLData($DatabaseName);
4152 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");
4153
4154 if ( $Flag == 1 ) {
4155 print("</TR>");
4156 $Flag = 0;
4157 }
4158 else {
4159 $Flag = 1;
4160 }
4161 }
4162 print("</TABLE>\n");
4163 print("</TD></TR>\n");
4164 }
4165
4166
4167
4168 # Send a pull-down which allows the user to select whether to display summaries or not, and how long we want them
4169 if ( defined($main::ConfigurationData{'allow-summary-displays'}) && ($main::ConfigurationData{'allow-summary-displays'} eq "yes") ) {
4170
4171 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4172
4173 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Document Summary Preferences: </B> </TD></TR>\n");
4174
4175 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Document summary type: </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SummaryType\">\n");
4176 foreach $ItemEntry ( keys (%main::SummaryTypes) ) {
4177 $Value = (defined($SummaryType) && ($SummaryType eq $ItemEntry)) ? "SELECTED" : "";
4178 print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::SummaryTypes{$ItemEntry}\n");
4179 }
4180 print("</SELECT></TD></TR>\n");
4181
4182 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Document summary length in words (max): </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SummaryLength\">\n");
4183 foreach $ItemEntry ( @main::SummaryLengths ) {
4184 $Value = (defined($SummaryLength) && ($SummaryLength eq $ItemEntry)) ? "SELECTED" : "";
4185 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
4186 }
4187 print("</SELECT></TD></TR>\n");
4188 }
4189
4190
4191 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4192
4193 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Document Retrieval Preferences: </B> </TD></TR>\n");
4194
4195 # Send a pull-down which allows the user to select whether to display summaries or not, and how long we want them
4196 if ( defined($main::ConfigurationData{'allow-similiar-search'}) && ($main::ConfigurationData{'allow-similiar-search'} eq "yes") ) {
4197
4198 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Number of similar documents retrieved (max): </TD> <TD ALIGN=LEFT VALIGN=TOP><SELECT NAME=\"SimilarDocuments\">\n");
4199 foreach $ItemEntry ( @main::SimilarDocuments ) {
4200 $Value = (defined($SimilarDocuments) && ($SimilarDocuments eq $ItemEntry)) ? "SELECTED" : "";
4201 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry\n");
4202 }
4203 print("</SELECT></TD></TR>\n");
4204 }
4205
4206
4207
4208
4209 # Are regular searches enabled?
4210 if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4211
4212 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4213
4214 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> <B> Saved Searches Defaults: </B> </TD></TR>\n");
4215
4216 # Send a pull-down which allows the user to select the automatic search frequency (default to weekly)
4217 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"SearchFrequency\">\n");
4218 foreach $ItemEntry ( @main::SearchFrequencies ) {
4219 $Value = (defined($SearchFrequency) && ($SearchFrequency eq $ItemEntry)) ? "SELECTED" : "";
4220 print("<OPTION VALUE=\"$ItemEntry\" $Value> $ItemEntry \n");
4221 }
4222 print("</SELECT> </TD></TR>\n");
4223
4224 # Send a pull-down which allows the user to select the automatic search delivery format
4225 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryFormat\">\n");
4226 foreach $ItemEntry ( sort(keys(%main::DeliveryFormats)) ) {
4227 $Value = (defined($DeliveryFormat) && ($DeliveryFormat eq $ItemEntry)) ? "SELECTED" : "";
4228 print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::DeliveryFormats{$ItemEntry}\n");
4229 }
4230 print("</SELECT> </TD></TR>\n");
4231
4232 # Send a pull-down which allows the user to select the automatic delivery method
4233 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Saved search delivery method: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryMethod\">\n");
4234 foreach $ItemEntry ( sort(keys(%main::DeliveryMethods)) ) {
4235 $Value = (defined($DeliveryMethod) && ($DeliveryMethod eq $ItemEntry)) ? "SELECTED" : "";
4236 print("<OPTION VALUE=\"$ItemEntry\" $Value> $main::DeliveryMethods{$ItemEntry}\n");
4237 }
4238 print("</SELECT> </TD></TR>\n");
4239 }
4240
4241
4242 print("</FORM>\n");
4243 print("</TABLE>\n");
4244
4245
4246
4247 # Bail from the settings
4248 bailFromGetUserSettings:
4249
4250 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4251 undef(%Value);
4252 $Value{'GetUserSettings'} = "GetUserSettings";
4253 &vSendMenuBar(%Value);
4254 undef(%Value);
4255
4256 &vSendHTMLFooter;
4257
4258 return;
4259
4260 }
4261
4262
4263
4264
4265
4266
4267 #--------------------------------------------------------------------------
4268 #
4269 # Function: vSetUserSettings()
4270 #
4271 # Purpose: This function saves the user setting
4272 #
4273 # Called by:
4274 #
4275 # Parameters: void
4276 #
4277 # Global Variables: %main::ConfigurationData, %main::FormData,
4278 # $main::UserSettingsFilePath, $main::RemoteUser,
4279 #
4280 # Returns: void
4281 #
4282 sub vSetUserSettings {
4283
4284 my (%Value);
4285
4286
4287 # Return an error if the remote user name/account directory is not defined
4288 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4289 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4290 &vSendHTMLFooter;
4291 return;
4292 }
4293
4294
4295 # Make sure that we send the header
4296 &vSendHTMLHeader("My Settings", undef);
4297 undef(%Value);
4298 &vSendMenuBar(%Value);
4299
4300
4301 # Save the user settings
4302 undef(%Value);
4303 $Value{'UserName'} = $main::FormData{'UserName'};
4304 $Value{'EmailAddress'} = $main::FormData{'EmailAddress'};
4305 $Value{'DefaultSearch'} = $main::FormData{'DefaultSearch'};
4306 $Value{'SelectedDatabases'} = $main::FormData{'SelectedDatabases'};
4307 if ( defined($Value{'SelectedDatabases'}) ) {
4308 $Value{'SelectedDatabases'} =~ s/\0/,/g;
4309 }
4310 $Value{'SearchHistory'} = $main::FormData{'SearchHistory'};
4311 $Value{'SearchFrequency'} = $main::FormData{'SearchFrequency'};
4312 $Value{'DeliveryFormat'} = $main::FormData{'DeliveryFormat'};
4313 $Value{'DeliveryMethod'} = $main::FormData{'DeliveryMethod'};
4314 $Value{'SummaryType'} = $main::FormData{'SummaryType'};
4315 $Value{'SummaryLength'} = $main::FormData{'SummaryLength'};
4316 $Value{'SimilarDocuments'} = $main::FormData{'SimilarDocuments'};
4317
4318
4319 # Save the user settings file
4320 if ( &iSaveXMLFileFromHash($main::UserSettingsFilePath, "UserSettings", %Value) ) {
4321
4322 print("<H3> Postavke: </H3>\n");
4323 print("<H3><CENTER> Postavke su uspje¹no snimljene! </CENTER></H3>\n");
4324 print("<P>\n");
4325 }
4326 else {
4327
4328 # The settings could not be saved, so we inform the user of the fact
4329 &vHandleError("User Settings", "Sorry, we failed to saved your settings");
4330 }
4331
4332
4333
4334 # Bail from the settings
4335 bailFromSetUserSettings:
4336
4337 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4338 undef(%Value);
4339 &vSendMenuBar(%Value);
4340
4341 &vSendHTMLFooter;
4342
4343 return;
4344
4345 }
4346
4347
4348
4349
4350
4351
4352 #--------------------------------------------------------------------------
4353 #
4354 # Function: vPurgeSearchHistory()
4355 #
4356 # Purpose: This function purges the search history files.
4357 #
4358 # Called by:
4359 #
4360 # Parameters: void
4361 #
4362 # Global Variables: $main::DefaultMaxSearchHistory, $main::UserSettingsFilePath,
4363 # $main::SearchHistoryFileNamePrefix, $main::UserAccountDirectoryPath
4364 #
4365 # Returns: void
4366 #
4367 sub vPurgeSearchHistory {
4368
4369 my ($MaxSearchHistory, @SearchHistoryList, $SearchHistoryEntry);
4370
4371
4372 # Return if the remote user name/account directory is not defined
4373 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4374 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4375 &vSendHTMLFooter;
4376 return;
4377 }
4378
4379
4380 # Get the max number of entries in the search history
4381 $MaxSearchHistory = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "SearchHistory");
4382
4383 # Set the detault max number of entries if it was not gotten from the user settings
4384 if ( !defined($MaxSearchHistory) ) {
4385 $MaxSearchHistory = $main::DefaultMaxSearchHistory;
4386 }
4387
4388
4389 # Read all the search history files
4390 opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4391 @SearchHistoryList = map("$main::UserAccountDirectoryPath/$_" ,
4392 reverse(sort(grep(/$main::SearchHistoryFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
4393 closedir(USER_ACCOUNT_DIRECTORY);
4394
4395
4396 # Purge the excess search history files
4397 if ( scalar(@SearchHistoryList) > $MaxSearchHistory ) {
4398
4399 # Splice out the old stuff, and loop over it deleting the files
4400 for $SearchHistoryEntry ( splice(@SearchHistoryList, $MaxSearchHistory) ) {
4401 unlink($SearchHistoryEntry);
4402 }
4403 }
4404
4405 return;
4406
4407 }
4408
4409
4410
4411
4412 #--------------------------------------------------------------------------
4413 #
4414 # Function: vListSearchHistory()
4415 #
4416 # Purpose: This function lists the search history for the user, the
4417 # entries are listed in reverse chronological order (most
4418 # recent first).
4419 #
4420 # In addition, the search history will be scanned and excess
4421 # searches will be purged.
4422 #
4423 # Called by:
4424 #
4425 # Parameters: void
4426 #
4427 # Global Variables: %main::ConfigurationData, $main::UserAccountDirectoryPath,
4428 # $main::XMLFileNameExtension, $main::SearchHistoryFileNamePrefix,
4429 # $main::RemoteUser
4430 #
4431 # Returns: void
4432 #
4433 sub vListSearchHistory {
4434
4435 my (@SearchHistoryList, @QualifiedSearchHistoryList, $SearchHistoryEntry);
4436 my ($SearchString, $CreationTime, $SearchAndRfDocumentURL, $HeaderName, $Database);
4437 my ($Value, %Value, @Values);
4438
4439
4440 # Return an error if the remote user name/account directory is not defined
4441 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4442 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4443 &vSendHTMLFooter;
4444 return;
4445 }
4446
4447
4448
4449 # Make sure that we send the header
4450 &vSendHTMLHeader("Prija¹nja pretra¾ivanja", undef);
4451 undef(%Value);
4452 $Value{'ListSearchHistory'} = "ListSearchHistory";
4453 &vSendMenuBar(%Value);
4454 undef(%Value);
4455
4456
4457 # Purge the search history files
4458 &vPurgeSearchHistory;
4459
4460
4461 # Read all the search history files
4462 opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4463 @SearchHistoryList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::SearchHistoryFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
4464 closedir(USER_ACCOUNT_DIRECTORY);
4465
4466
4467 # Loop over each search history file checking that it is valid
4468 for $SearchHistoryEntry ( @SearchHistoryList ) {
4469
4470 # Get the header name from the XML search history file
4471 $HeaderName = &sGetObjectTagFromXMLFile($SearchHistoryEntry);
4472
4473 # Check that the entry is valid and add it to the qualified list
4474 if ( defined($HeaderName) && ($HeaderName eq "SearchHistory") ) {
4475 push @QualifiedSearchHistoryList, $SearchHistoryEntry;
4476 }
4477 else {
4478 # Else we delete this invalid search history file
4479 unlink($SearchHistoryEntry);
4480 }
4481 }
4482
4483
4484
4485 # Display the search history
4486 print("<H3> Prija¹nja pretra¾ivanja: </H3>\n");
4487
4488 # Print up the search history, if there is none, we put up a nice message
4489 if ( scalar(@QualifiedSearchHistoryList) > 0 ) {
4490
4491 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4492
4493
4494 for $SearchHistoryEntry ( @QualifiedSearchHistoryList ) {
4495
4496 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
4497
4498 # Get information from the XML search history file
4499 ($HeaderName, %Value) = &shGetHashFromXMLFile($SearchHistoryEntry);
4500
4501 # Get the search file name and encode it
4502 $SearchHistoryEntry = ($SearchHistoryEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $SearchHistoryEntry;
4503 $SearchHistoryEntry = &lEncodeURLData($SearchHistoryEntry);
4504
4505 $CreationTime = $Value{'CreationTime'};
4506 $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
4507 %Value = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
4508 $SearchString = &sMakeSearchString(%Value);
4509 if ( defined($SearchString) ) {
4510 $SearchString =~ s/{.*?}//gs;
4511 $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
4512 }
4513 $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
4514
4515
4516 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD><TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
4517
4518 # Get the local databases from the search and list their descriptions
4519 if ( defined($Value{'Database'}) ) {
4520
4521 # Initialize the temp list
4522 undef(@Values);
4523
4524 # Loop over each database
4525 foreach $Database ( split(/\0/, $Value{'Database'}) ) {
4526 $Value = &lEncodeURLData($Database);
4527 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> ");
4528 }
4529
4530 # Print the list if there are any entries in it
4531 if ( scalar(@Values) > 0 ) {
4532 printf("<TR><TD ALIGN=LEFT VALIGN=TOP> Database%s: </TD><TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>\n",
4533 scalar(@Values) > 1 ? "s" : "", join(", ", @Values));
4534 }
4535 }
4536
4537 if ( defined($Value{'RfDocument'}) ) {
4538 print("<TR>");
4539 &bDisplayDocuments("Feedback Document", $Value{'RfDocument'}, "RfDocument", undef, undef, 1);
4540 print("</TR>");
4541 }
4542
4543 $Value = &sGetPrintableDateFromTime($CreationTime);
4544 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD><TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
4545
4546 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");
4547
4548 }
4549
4550 print("</TABLE>\n");
4551 }
4552 else {
4553 print("<H3><CENTER> Sorry, currently there is no search history. </CENTER></H3>\n");
4554 }
4555
4556
4557
4558 # Bail from the search history
4559 bailFromListSearchHistory:
4560
4561 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4562 undef(%Value);
4563 $Value{'ListSearchHistory'} = "ListSearchHistory";
4564 &vSendMenuBar(%Value);
4565 undef(%Value);
4566
4567 &vSendHTMLFooter;
4568
4569 return;
4570
4571 }
4572
4573
4574
4575
4576
4577 #--------------------------------------------------------------------------
4578 #
4579 # Function: vGetSearchHistory()
4580 #
4581 # Purpose: This function displays a search history file to the user.
4582 #
4583 # Called by:
4584 #
4585 # Parameters: void
4586 #
4587 # Global Variables: %main::ConfigurationData, %main::FormData,
4588 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
4589 # $main::SearchHistoryFileNamePrefix, $main::RemoteUser
4590 #
4591 # Returns: void
4592 #
4593 sub vGetSearchHistory {
4594
4595 my ($SearchAndRfDocumentURL, $SearchResults, $QueryReport, $CreationTime);
4596 my ($SearchHistoryEntry, $HeaderName, $Status);
4597 my ($Value, %Value);
4598
4599
4600
4601 # Return an error if the remote user name/account directory is not defined
4602 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4603 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4604 &vSendHTMLFooter;
4605 return;
4606 }
4607
4608
4609 # Create the search history file name
4610 $SearchHistoryEntry = $main::UserAccountDirectoryPath . "/" . $main::FormData{'SearchHistoryObject'};
4611
4612
4613 # Check to see if the XML search history file requested is there
4614 if ( ! -f $SearchHistoryEntry ) {
4615 # Could not find the search history file
4616 &vHandleError("Display Search History", "Sorry, we cant to access this search history object because it is not there");
4617 goto bailFromGetSearchHistory;
4618 }
4619
4620
4621 # Get information from the XML search history file
4622 ($HeaderName, %Value) = &shGetHashFromXMLFile($SearchHistoryEntry);
4623
4624 # Check that the entry is valid
4625 if ( !(defined($HeaderName) && ($HeaderName eq "SearchHistory")) ) {
4626 &vHandleError("Display Search History", "Sorry, this search history object is invalid");
4627 goto bailFromGetSearchHistory;
4628 }
4629
4630
4631
4632 # At this point, the XML search history file is there and is valid,
4633 # so we can go ahead and display it
4634 $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
4635 $SearchResults = $Value{'SearchResults'};
4636 $QueryReport = $Value{'QueryReport'};
4637 $CreationTime = $Value{'CreationTime'};
4638
4639 %main::FormData = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
4640
4641 # Make sure that we send the header
4642 &vSendHTMLHeader("Display Search History", undef);
4643 undef(%Value);
4644 &vSendMenuBar(%Value);
4645
4646
4647 ($Status, $QueryReport) = &bsDisplaySearchResults("Rezultati prija¹njih pretra¾ivanja:", undef, undef, undef, $SearchResults, $QueryReport, $ENV{'SCRIPT_NAME'}, 1, 1, 1, %main::FormData);
4648
4649
4650 # Bail from displaying the search history
4651 bailFromGetSearchHistory:
4652
4653 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4654 undef(%Value);
4655 &vSendMenuBar(%Value);
4656
4657 &vSendHTMLFooter;
4658
4659 return;
4660
4661 }
4662
4663
4664
4665
4666
4667
4668 #--------------------------------------------------------------------------
4669 #
4670 # Function: vGetSaveSearch()
4671 #
4672 # Purpose: This function displays a form to the user allowing them to save a search
4673 #
4674 # Called by:
4675 #
4676 # Parameters: void
4677 #
4678 # Global Variables: %main::ConfigurationData, %main::FormData,
4679 # $main::UserSettingsFilePath, $main::RemoteUser,
4680 #
4681 # Returns: void
4682 #
4683 sub vGetSaveSearch {
4684
4685
4686 my ($SearchString, $Database);
4687 my ($HeaderName, $SearchFrequency, $DeliveryFormat, $DeliveryMethod);
4688 my ($JavaScript, $EmailAddress);
4689 my ($Value, @Values, %Value, $ValueEntry);
4690
4691
4692 # Return an error if the remote user name/account directory is not defined
4693 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4694 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4695 &vSendHTMLFooter;
4696 return;
4697 }
4698
4699
4700 $JavaScript = '<SCRIPT LANGUAGE="JavaScript">
4701 <!-- hide
4702 function checkForm( Form ) {
4703 if ( !checkField( Form.SearchName, "Search name" ) )
4704 return false
4705 return true
4706 }
4707 function checkField( Field, Name ) {
4708 if ( Field.value == "" ) {
4709 errMsg( Field, "Niste ispunili polje \'"+Name+"\' ." )
4710 return false
4711 }
4712 else {
4713 return true
4714 }
4715 }
4716 function errMsg( Field, Msg ) {
4717 alert( Msg )
4718 Field.focus()
4719 return
4720 }
4721 // -->
4722 </SCRIPT>
4723 ';
4724
4725
4726
4727 # Make sure that we send the header
4728 &vSendHTMLHeader("Save this Search", $JavaScript);
4729 undef(%Value);
4730 &vSendMenuBar(%Value);
4731
4732
4733 # Give the user a form to fill out
4734 print("<H3> Saving a search: </H3>\n");
4735
4736
4737
4738 # Get information from the XML saved search file
4739 ($HeaderName, %Value) = &shGetHashFromXMLFile($main::UserSettingsFilePath);
4740
4741 $SearchFrequency = $Value{'SearchFrequency'};
4742 $DeliveryFormat = $Value{'DeliveryFormat'};
4743 $DeliveryMethod = $Value{'DeliveryMethod'};
4744 $EmailAddress = $Value{'EmailAddress'};
4745
4746
4747 # Print up the table start
4748 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
4749
4750 # Start the form
4751 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetSaveSearch\" onSubmit=\"return checkForm(this)\" METHOD=POST>\n");
4752
4753 # Send the buttons
4754 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");
4755
4756 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4757
4758 # Print up the search string
4759 $SearchString = &sMakeSearchString(%main::FormData);
4760 if ( defined($SearchString) ) {
4761 $SearchString =~ s/{.*?}//gs;
4762 $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
4763 }
4764 $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
4765 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
4766
4767 # Get the local databases from the search and list their descriptions
4768 if ( defined($main::FormData{'Database'}) ) {
4769
4770 # Initialize the temp list
4771 undef(@Values);
4772
4773 foreach $Database ( sort(split(/\0/, $main::FormData{'Database'})) ) {
4774 $Value = &lEncodeURLData($Database);
4775 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> ");
4776 }
4777
4778 # Print the list if there are any entries in it
4779 if ( scalar(@Values) > 0 ) {
4780 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));
4781 }
4782 }
4783
4784 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4785
4786 # Send the search name and search description fields
4787 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");
4788
4789 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");
4790
4791 if ( defined($main::FormData{'RfDocument'}) ) {
4792 print("<TR>\n");
4793 &bDisplayDocuments("Feedback Document", $main::FormData{'RfDocument'}, "RfDocument", undef, undef, 1);
4794 print("</TR>\n");
4795 }
4796
4797
4798 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4799
4800 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");
4801
4802
4803
4804 # Are regular searches enabled?
4805 if ( defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes") ) {
4806
4807 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
4808
4809 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");
4810
4811 # Send a pull-down which allows the user to select the automatic search frequency
4812 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the search frequency: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"SearchFrequency\">\n");
4813 foreach $ValueEntry ( @main::SearchFrequencies ) {
4814 $Value = (defined($SearchFrequency) && ($SearchFrequency eq $ValueEntry)) ? "SELECTED" : "";
4815 print("<OPTION VALUE=\"$ValueEntry\" $Value> $ValueEntry \n");
4816 }
4817 print("</SELECT> </TD></TR>\n");
4818
4819 # Send a pull-down which allows the user to select the automatic search delivery format
4820 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryFormat\">\n");
4821 foreach $ValueEntry ( sort(keys(%main::DeliveryFormats)) ) {
4822 $Value = (defined($DeliveryFormat) && ($DeliveryFormat eq $ValueEntry)) ? "SELECTED" : "";
4823 print("<OPTION VALUE=\"$ValueEntry\" $Value> $main::DeliveryFormats{$ValueEntry}\n");
4824 }
4825 print("</SELECT> </TD></TR>\n");
4826
4827 # Send a pull-down which allows the user to select the automatic search delivery method
4828 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Select the delivery method: </TD> <TD ALIGN=LEFT VALIGN=TOP> <SELECT NAME=\"DeliveryMethod\">\n");
4829 foreach $ValueEntry ( sort(keys(%main::DeliveryMethods)) ) {
4830 $Value = (defined($DeliveryMethod) && ($DeliveryMethod eq $ValueEntry)) ? "SELECTED" : "";
4831 print("<OPTION VALUE=\"$ValueEntry\" $Value> $main::DeliveryMethods{$ValueEntry}\n");
4832 }
4833 print("</SELECT> </TD></TR>\n");
4834 }
4835
4836
4837 # List the hidden fields
4838 %Value = &hParseURLIntoHashTable(&sMakeSearchAndRfDocumentURL(%main::FormData));
4839 foreach $Value ( keys(%Value) ) {
4840 foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
4841 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
4842 }
4843 }
4844
4845 print("</FORM>\n");
4846 print("</TABLE>\n");
4847
4848 if ( !defined($EmailAddress) &&
4849 (defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes")) ) {
4850 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4851 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");
4852 }
4853
4854
4855 # Bail from saving the search
4856 bailFromGetSaveSearch:
4857
4858 print("<CENTER><HR WIDTH=50%></CENTER>\n");
4859 undef(%Value);
4860 &vSendMenuBar(%Value);
4861
4862 &vSendHTMLFooter;
4863
4864 return;
4865
4866 }
4867
4868
4869
4870
4871
4872
4873 #--------------------------------------------------------------------------
4874 #
4875 # Function: vSetSaveSearch()
4876 #
4877 # Purpose: This function saves that search and search name in a search file
4878 #
4879 # Called by:
4880 #
4881 # Parameters: void
4882 #
4883 # Global Variables: %main::ConfigurationData, %main::FormData,
4884 # $main::UserSettingsFilePath, $main::RemoteUser,
4885 #
4886 # Returns: void
4887 #
4888 sub vSetSaveSearch {
4889
4890
4891 my ($SearchAndRfDocumentURL, $SearchString);
4892 my (@SavedSearchList, $SavedSearchEntry, $SavedSearchFilePath);
4893 my ($EmailAddress, $SearchName, $CreationTime, $LastRunTime);
4894 my ($Value, %Value);
4895
4896
4897 # Return an error if the remote user name/account directory is not defined
4898 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
4899 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
4900 &vSendHTMLFooter;
4901 return;
4902 }
4903
4904
4905 # Make sure that we send the header
4906 &vSendHTMLHeader("Saèuvana pretra¾ivanja", undef);
4907 undef(%Value);
4908 &vSendMenuBar(%Value);
4909
4910
4911 # Check that the required fields are filled in
4912 if ( !defined($main::FormData{'SearchName'}) ) {
4913
4914 # A required field is missing, so we suggest corrective action to the user.
4915 print("<H3> Snimanje pretra¾ivanja: </H3>\n");
4916 print("<H3><CENTER> Oprostite, nedostaju neke informacije. </CENTER></H3>\n");
4917 print("<P>\n");
4918 print("Polje <B>'search name'</B> mora biti ispunjeno da bi se moglo saèuvati pretra¾ivanje.<P>\n");
4919 print("Kliknite na <B>'Back'</B> u svom browseru, popunite polje koje nedostaje i poku¹ajte ponovo.\n");
4920 print("<P>\n");
4921
4922 goto bailFromSetSaveSearch;
4923
4924 }
4925
4926
4927 # Read all the saved search files
4928 opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
4929 @SavedSearchList = map("$main::UserAccountDirectoryPath/$_", grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)));
4930 closedir(USER_ACCOUNT_DIRECTORY);
4931
4932
4933 # Loop over each saved search file checking that it is valid
4934 for $SavedSearchEntry ( @SavedSearchList ) {
4935
4936 $SearchName = &sGetTagValueFromXMLFile($SavedSearchEntry, "SearchName");
4937
4938 if ( $SearchName eq $main::FormData{'SearchName'} ) {
4939 $SavedSearchFilePath = $SavedSearchEntry;
4940 last;
4941 }
4942 }
4943
4944 # Check that the saved search file does not already exist
4945 if ( defined($SavedSearchFilePath) && ($SavedSearchFilePath ne "")
4946 && !(defined($main::FormData{'OverWrite'}) && ($main::FormData{'OverWrite'} eq "yes")) ) {
4947
4948 # There is already a saved search with this name, so we suggest corrective action to the user.
4949 print("<H3> Saving a Search: </H3>\n");
4950 print("<H3><CENTER> Sorry, there is already a saved search with this name. </CENTER></H3>\n");
4951 print("<P>\n");
4952 print("Click <B>'back'</B> on your browser, change the <B>'search name'</B> and try again, \n");
4953 print("alternatively you can check the box which allows you to automatically over-write a saved search with the same name.\n");
4954 print("<P>\n");
4955
4956 goto bailFromSetSaveSearch;
4957 }
4958
4959
4960 # Get the email address of this user
4961 $Value = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
4962
4963 # Check this user has an email address defined if they want to run the search on a regular basis
4964 if ( !defined($Value) && (defined($main::FormData{'Regular'}) && ($main::FormData{'Regular'} eq "yes")) ) {
4965
4966 # Regular delivery was requested, but the email address was not specified in the settings
4967 print("<H3> Saving a Search: </H3>\n");
4968 print("<H3><CENTER> Sorry, your email address is not specified in your settings. </CENTER></H3>\n");
4969 print("<P>\n");
4970 print("You need to specify your email address in your settings if you want this search to run on a regular basis, \n");
4971 print("without your email address, we are not able to send you the search result. <P>\n");
4972 print("Click the <B>'Settings'</B> option from the menu sidebar, fill in your email address and save the settings, \n");
4973 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");
4974 print("<P>\n");
4975
4976 goto bailFromSetSaveSearch;
4977 }
4978
4979
4980 # All the checks have been passed, so we can go ahead and save the search
4981
4982 $CreationTime = time();
4983 $LastRunTime = $CreationTime;
4984
4985 # Erase the search frequency and the delivery method if this is not a regular search
4986 if ( !(defined($main::FormData{'Regular'}) && ($main::FormData{'Regular'} eq "yes")) ) {
4987 $main::FormData{'SearchFrequency'} = "";
4988 $main::FormData{'DeliveryFormat'} = "";
4989 $main::FormData{'DeliveryMethod'} = "";
4990 $LastRunTime = "";
4991 }
4992
4993
4994 # Get the URL search string
4995 $SearchAndRfDocumentURL = &sMakeSearchAndRfDocumentURL(%main::FormData);
4996
4997 # Save the search
4998 if ( &iSaveSearch(undef, $main::FormData{'SearchName'}, $main::FormData{'SearchDescription'}, $SearchAndRfDocumentURL, $main::FormData{'SearchFrequency'}, $main::FormData{'DeliveryFormat'}, $main::FormData{'DeliveryMethod'}, "Active", $CreationTime, $LastRunTime) ) {
4999
5000 print("<H3> Saving a Search: </H3>\n");
5001 print("<P>\n");
5002 print("<H3><CENTER> Your search was successfully saved. </CENTER></H3>\n");
5003
5004 # Delete the overwritten search file
5005 if ( defined($SavedSearchFilePath) && ($SavedSearchFilePath ne "") ) {
5006 unlink($SavedSearchFilePath);
5007 }
5008 }
5009 else {
5010
5011 # The search could not be saved, so we inform the user of the fact
5012 &vHandleError("Saving a Search", "Sorry, we failed to save this search");
5013 goto bailFromSetSaveSearch;
5014 }
5015
5016
5017 # Bail from saving the search
5018 bailFromSetSaveSearch:
5019
5020 print("<CENTER><HR WIDTH=50%></CENTER>\n");
5021 undef(%Value);
5022 &vSendMenuBar(%Value);
5023
5024 &vSendHTMLFooter;
5025
5026 return;
5027
5028 }
5029
5030
5031
5032
5033
5034
5035 #--------------------------------------------------------------------------
5036 #
5037 # Function: vListSavedSearch()
5038 #
5039 # Purpose: This function allows the user list the saved searches and
5040 # sets up the links allowing the user to get a search form
5041 # filled with the search
5042 #
5043 # Called by:
5044 #
5045 # Parameters: void
5046 #
5047 # Global Variables: %main::ConfigurationData, %main::FormData,
5048 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5049 # $main::SavedSearchFileNamePrefix, $main::RemoteUser
5050 #
5051 # Returns: void
5052 #
5053 sub vListSavedSearch {
5054
5055 my (@SavedSearchList, @QualifiedSavedSearchList, $SavedSearchEntry, $HeaderName, $SearchString, $Database);
5056 my ($SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $LastRunTime);
5057 my (@Values, $Value, %Value);
5058
5059
5060 # Return an error if the remote user name/account directory is not defined
5061 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5062 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5063 &vSendHTMLFooter;
5064 return;
5065 }
5066
5067
5068 # Make sure that we send the header
5069 &vSendHTMLHeader("Saèuvana pretra¾ivanja", undef);
5070 undef(%Value);
5071 $Value{'ListSavedSearch'} = "ListSavedSearch";
5072 &vSendMenuBar(%Value);
5073 undef(%Value);
5074
5075
5076 # Read all the saved search files
5077 opendir(USER_ACCOUNT_DIRECTORY, $main::UserAccountDirectoryPath);
5078 @SavedSearchList = map("$main::UserAccountDirectoryPath/$_", reverse(sort(grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY)))));
5079 closedir(USER_ACCOUNT_DIRECTORY);
5080
5081
5082 # Loop over each search history file checking that it is valid
5083 for $SavedSearchEntry ( @SavedSearchList ) {
5084
5085 # Get the header name from the XML saved search file
5086 $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchEntry);
5087
5088 # Check that the entry is valid and add it to the qualified list
5089 if ( defined($HeaderName) && ($HeaderName eq "SavedSearch") ) {
5090 push @QualifiedSavedSearchList, $SavedSearchEntry;
5091 }
5092 else {
5093 # Else we delete this invalid saved search file
5094 unlink($SavedSearchEntry);
5095 }
5096 }
5097
5098
5099 # Print out the saved searches
5100 print("<H3> Saèuvana pretra¾ivanja: </H3>\n");
5101
5102
5103
5104 # Print up the saved searches, if there is none, we put up a nice message
5105 if ( scalar(@QualifiedSavedSearchList) > 0 ) {
5106
5107 # Start the table
5108 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
5109
5110 # Start the form
5111 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
5112
5113
5114 print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3> \n");
5115 print("<SELECT NAME=\"Action\">\n");
5116 print("<OPTION VALUE=\"ActivateSavedSearch\">Aktiviraj oznaèena saèuvana pretra¾ivanja\n");
5117 print("<OPTION VALUE=\"SuspendSavedSearch\">Stavi u mirovanje oznaèena saèuvana pretra¾ivanja\n");
5118 print("<OPTION VALUE=\"DeleteSavedSearch\">Obri¹i oznaèena saèuvana pretra¾ivanja\n");
5119 print("</SELECT>\n");
5120 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
5121 print("</TD></TR>\n");
5122
5123 for $SavedSearchEntry ( @QualifiedSavedSearchList ) {
5124
5125 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
5126
5127 # Get information from the XML saved search file
5128 ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchEntry);
5129
5130 # Get the saved search file name and encode it
5131 $SavedSearchEntry = ($SavedSearchEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $SavedSearchEntry;
5132 $SavedSearchEntry = &lEncodeURLData($SavedSearchEntry);
5133
5134
5135 $SearchName = $Value{'SearchName'};
5136 $SearchDescription = $Value{'SearchDescription'};
5137 $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
5138 $SearchFrequency = $Value{'SearchFrequency'};
5139 $SearchStatus = $Value{'SearchStatus'};
5140 $DeliveryFormat = $Value{'DeliveryFormat'};
5141 $DeliveryMethod = $Value{'DeliveryMethod'};
5142 $CreationTime = $Value{'CreationTime'};
5143 $LastRunTime = $Value{'LastRunTime'};
5144
5145 # Parse the URL Search string into a hash so that we can get at it's components
5146 %Value = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
5147
5148 $SearchString = &sMakeSearchString(%Value);
5149 if ( defined($SearchString) ) {
5150 $SearchString =~ s/{.*?}//gs;
5151 $SearchString = ($SearchString =~ /\S/) ? $SearchString : undef;
5152 }
5153 $SearchString = defined($SearchString) ? $SearchString : "(No search terms defined)";
5154
5155 # Print the link
5156 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");
5157
5158 # Print the search description
5159 $SearchDescription = defined($SearchDescription) ? $SearchDescription : "(Nije naveden)";
5160 $SearchDescription =~ s/\n/<BR>/g;
5161 $SearchDescription =~ s/\r/<BR>/g;
5162 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchDescription </TD></TR>\n");
5163
5164 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Upit: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchString </TD></TR>\n");
5165
5166 # Get the local databases from the search and list their descriptions
5167 if ( defined($Value{'Database'}) ) {
5168
5169 # Initialize the temp list
5170 undef(@Values);
5171
5172 # Loop over each database
5173 foreach $Database ( split(/\0/, $Value{'Database'}) ) {
5174 $Value = &lEncodeURLData($Database);
5175 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> ");
5176 }
5177
5178 # Print the list if there are any entries in it
5179 if ( scalar(@Values) > 0 ) {
5180 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));
5181 }
5182 }
5183
5184
5185 if ( defined($Value{'RfDocument'}) ) {
5186 print("<TR><TD></TD>\n");
5187 &bDisplayDocuments("Feedback Document", $Value{'RfDocument'}, "RfDocument", undef, undef, 1);
5188 print("</TR>\n");
5189 }
5190
5191 undef(%Value);
5192
5193
5194 if ( defined($SearchFrequency) || defined($DeliveryFormat) || defined($DeliveryMethod) ) {
5195 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Run: </TD> <TD ALIGN=LEFT VALIGN=TOP> $SearchFrequency </TD></TR>\n");
5196 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Delivery format: </TD> <TD ALIGN=LEFT VALIGN=TOP> $main::DeliveryFormats{$DeliveryFormat} </TD></TR>\n");
5197 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Delivery method : </TD> <TD ALIGN=LEFT VALIGN=TOP> $main::DeliveryMethods{$DeliveryMethod} </TD></TR>\n");
5198 }
5199
5200 $Value = &sGetPrintableDateFromTime($CreationTime);
5201 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5202
5203
5204 if ( defined($SearchFrequency) || defined($DeliveryFormat) || defined($DeliveryMethod) ) {
5205
5206 if ( defined($LastRunTime) ) {
5207 $Value = &sGetPrintableDateFromTime($LastRunTime);
5208 print("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Last Run: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
5209 }
5210
5211 printf("<TR><TD></TD><TD ALIGN=LEFT VALIGN=TOP> Status: </TD> <TD ALIGN=LEFT VALIGN=TOP> %s </TD></TR>",
5212 (defined($SearchStatus) && ($SearchStatus eq "Active")) ? "Active" : "Suspended");
5213
5214 }
5215
5216 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");
5217 }
5218
5219 print("</FORM></TABLE>\n");
5220 }
5221 else {
5222 print("<H3><CENTER> Sorry, currently, there are no saved searches. </CENTER></H3>\n");
5223 }
5224
5225
5226
5227
5228 # Bail from displaying saved searches
5229 bailFromDisplaySavedSearch:
5230
5231 print("<CENTER><HR WIDTH=50%></CENTER>\n");
5232 undef(%Value);
5233 $Value{'ListSavedSearch'} = "ListSavedSearch";
5234 &vSendMenuBar(%Value);
5235 undef(%Value);
5236
5237 &vSendHTMLFooter;
5238
5239
5240 return;
5241
5242 }
5243
5244
5245
5246
5247
5248
5249 #--------------------------------------------------------------------------
5250 #
5251 # Function: vGetSavedSearch()
5252 #
5253 # Purpose: This function gets a saved search.
5254 #
5255 # Called by:
5256 #
5257 # Parameters: void
5258 #
5259 # Global Variables: %main::ConfigurationData, %main::FormData,
5260 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5261 # $main::SavedSearchFileNamePrefix, $main::RemoteUser
5262 #
5263 # Returns: void
5264 #
5265 sub vGetSavedSearch {
5266
5267 my ($HeaderName, $SavedSearchFilePath, $SearchAndRfDocumentURL, $DefaultSearch);
5268 my ($Value, %Value);
5269
5270
5271 # Return an error if the remote user name/account directory is not defined
5272 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5273 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5274 &vSendHTMLFooter;
5275 return;
5276 }
5277
5278
5279 # Set the saved search file path
5280 $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'SavedSearchObject'};
5281
5282
5283 # Check to see if the XML saved search file requested is there
5284 if ( ! -f $SavedSearchFilePath ) {
5285 # Could not find the saved search file
5286 &vHandleError("Prikaz saèuvaniog pretra¾ivanja", "Sorry, we cant to access this saved search object because it is not there");
5287 &vSendHTMLFooter;
5288 return;
5289 }
5290
5291
5292
5293 # Get the data from the XML saved search file
5294 $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchFilePath);
5295
5296 # Check that the entry is valid
5297 if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
5298 &vHandleError("Prikaz saèuvaniog pretra¾ivanja", "Sorry, this saved search object is invalid");
5299 &vSendHTMLFooter;
5300 return;
5301 }
5302
5303
5304 # All is fine, so we hand over the hash and get the search
5305 %main::FormData = &hParseURLIntoHashTable(&sGetTagValueFromXMLFile($SavedSearchFilePath, 'SearchAndRfDocumentURL'));
5306
5307 $ENV{'PATH_INFO'} = "/GetSearch";
5308
5309 # Display the search form, it will autoset itself from %main::FormData
5310 &vGetSearch;
5311
5312 return;
5313
5314 }
5315
5316
5317
5318
5319
5320
5321 #--------------------------------------------------------------------------
5322 #
5323 # Function: vProcessSavedSearch()
5324 #
5325 # Purpose: This function processes a saved search.
5326 #
5327 # Called by:
5328 #
5329 # Parameters: void
5330 #
5331 # Global Variables: %main::ConfigurationData, %main::FormData,
5332 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5333 # $main::SavedSearchFileNamePrefix, $main::RemoteUser
5334 #
5335 # Returns: void
5336 #
5337 sub vProcessSavedSearch {
5338
5339 my ($Title, $HeaderName, $SavedSearchFilePath, $SavedSearchObject);
5340 my ($Value, %Value);
5341
5342
5343 # Return an error if the remote user name/account directory is not defined
5344 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5345 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5346 &vSendHTMLFooter;
5347 return;
5348 }
5349
5350
5351 # Set the title
5352 if ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
5353 $Title = "Obri¹i saèuvana pretra¾ivanja";
5354 }
5355 elsif ( $ENV{'PATH_INFO'} eq "/ActivateSavedSearch" ) {
5356 $Title = "Aktiviraj saèuvana pretra¾ivanja";
5357 }
5358 elsif ( $ENV{'PATH_INFO'} eq "/SuspendSavedSearch" ) {
5359 $Title = "Stavi u mirovanje saèuvana pretra¾ivanja";
5360 }
5361
5362
5363 # Make sure that we send the header
5364 &vSendHTMLHeader($Title, undef);
5365 undef(%Value);
5366 &vSendMenuBar(%Value);
5367
5368
5369 print("<H3> $Title: </H3>\n");
5370
5371 # Check to see if the saved search object is defined
5372 if ( ! defined($main::FormData{'SavedSearchObject'}) ) {
5373 # Could not find the saved search object
5374 print("<H3><CENTER> Sorry, no searches were selected. </CENTER></H3>\n");
5375 print("<P>\n");
5376 print("You need to select at least one saved search in order to be able to perform an action on it.\n");
5377 print("<P>\n");
5378 goto bailFromProcessSavedSearch;
5379 }
5380
5381
5382
5383 # Loop over each saved search
5384 foreach $SavedSearchObject ( split(/\0/, $main::FormData{'SavedSearchObject'}) ) {
5385
5386 # Set the saved search file path
5387 $SavedSearchFilePath = $main::UserAccountDirectoryPath . "/" . $SavedSearchObject;
5388
5389 # Check to see if the XML saved search file requested is there
5390 if ( ! -f $SavedSearchFilePath ) {
5391 next;
5392 }
5393
5394 # Get information from the XML saved search file
5395 ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchFilePath);
5396
5397 # Check that the entry is valid
5398 if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
5399 next;
5400 }
5401
5402
5403 if ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
5404 if ( unlink($SavedSearchFilePath) ) {
5405 printf("<P>Successfully deleted: %s\n", $Value{'SearchName'});
5406 }
5407 else {
5408 printf("<P>Failed to delete: %s\n", $Value{'SearchName'});
5409 }
5410 }
5411 elsif ( ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") || ($ENV{'PATH_INFO'} eq "/SuspendSavedSearch") ) {
5412
5413 if ( !defined($Value{'SearchStatus'}) ) {
5414 printf("<P>Could not %s: %s, as it is not a regular search\n",
5415 ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activate" : "suspend", $Value{'SearchName'});
5416 }
5417 else {
5418
5419 $Value{'SearchStatus'} = ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "Active" : "Inactive" ;
5420
5421 if ( &iSaveXMLFileFromHash($SavedSearchFilePath, "SavedSearch", %Value) ) {
5422 printf("<P>Successfully %s: %s\n",
5423 ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activated" : "suspended", $Value{'SearchName'});
5424 }
5425 else {
5426 printf("<P>Failed to %s: %s\n",
5427 ($ENV{'PATH_INFO'} eq "/ActivateSavedSearch") ? "activated" : "suspended", $Value{'SearchName'});
5428 }
5429 }
5430 }
5431 }
5432
5433 print("<P>\n");
5434
5435 # Bail from processing the saved search
5436 bailFromProcessSavedSearch:
5437
5438 print("<CENTER><HR WIDTH=50%></CENTER>\n");
5439 undef(%Value);
5440 &vSendMenuBar(%Value);
5441
5442 &vSendHTMLFooter;
5443
5444 return;
5445
5446 }
5447
5448
5449
5450
5451
5452
5453 #--------------------------------------------------------------------------
5454 #
5455 # Function: vGetSaveFolder()
5456 #
5457 # Purpose: This function displays a form to the user allowing them to
5458 # save documents to a folder
5459 #
5460 # Called by:
5461 #
5462 # Parameters: void
5463 #
5464 # Global Variables: %main::ConfigurationData, %main::FormData,
5465 # $main::UserSettingsFilePath, $main::RemoteUser,
5466 #
5467 # Returns: void
5468 #
5469 sub vGetSaveFolder {
5470
5471
5472 my ($JavaScript);
5473 my ($Value, @Values, %Value, $ValueEntry);
5474
5475
5476
5477 # Return an error if the remote user name/account directory is not defined
5478 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5479 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5480 &vSendHTMLFooter;
5481 return;
5482 }
5483
5484
5485 $JavaScript = '<SCRIPT LANGUAGE="JavaScript">
5486 <!-- hide
5487 function checkForm( Form ) {
5488 if ( !checkField( Form.FolderName, "Folder name" ) )
5489 return false
5490 return true
5491 }
5492 function checkField( Field, Name ) {
5493 if ( Field.value == "" ) {
5494 errMsg( Field, "Niste ispunili polje \'"+Name+"\'." )
5495 return false
5496 }
5497 else {
5498 return true
5499 }
5500 }
5501 function errMsg( Field, Msg ) {
5502 alert( Msg )
5503 Field.focus()
5504 return
5505 }
5506 // -->
5507 </SCRIPT>
5508 ';
5509
5510
5511 # Make sure that we send the header
5512 &vSendHTMLHeader("Saving a Document Folder", $JavaScript);
5513 undef(%Value);
5514 &vSendMenuBar(%Value);
5515
5516
5517 # Check that at least one document was selected
5518 if ( !defined($main::FormData{'Document'}) && !defined($main::FormData{'Documents'}) ) {
5519 print("<H3>Saving a Document Folder:</H3>\n");
5520 print("<H3><CENTER>Sorry, no document(s) were selected for saving.</CENTER></H3>\n");
5521 print("<P>\n");
5522 print("There needs to be a least one document selected in order to save it.\n");
5523 print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
5524 goto bailFromGetSaveFolder;
5525 }
5526
5527
5528 # Print up the title
5529 print("<H3> Snimanje foldera s dokumentima: </H3>\n");
5530
5531 # Print up the form
5532 printf("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}/SetSaveFolder\" onSubmit=\"return checkForm(this)\" METHOD=POST>\n");
5533
5534 # Print up the table start
5535 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
5536
5537 # Send the buttons
5538 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");
5539
5540 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5541
5542 # Send the fields
5543 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");
5544
5545 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");
5546
5547 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5548
5549 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");
5550
5551 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
5552
5553 # List the documents
5554 if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
5555
5556 # Undefine the hash table in preparation
5557 undef(%Value);
5558
5559 # Add document that were specifically selected
5560 if ( defined($main::FormData{'Document'}) ) {
5561 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5562 $Value{$Value} = $Value;
5563 }
5564 }
5565 # Otherwise add documents that were selected by default
5566 elsif ( defined($main::FormData{'Documents'}) ) {
5567 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5568 $Value{$Value} = $Value;
5569 }
5570 }
5571
5572 # Assemble the new content
5573 $main::FormData{'Document'} = join("\0", keys(%Value));
5574
5575 # Delete the old content
5576 delete($main::FormData{'Documents'});
5577
5578
5579 if ( defined($main::FormData{'Document'}) ) {
5580 print("<TR>\n");
5581 &bDisplayDocuments("Document", $main::FormData{'Document'}, "Document", undef, undef, 1);
5582 print("</TR>\n");
5583 }
5584 }
5585
5586
5587
5588 # List the hidden fields
5589 %Value = &hParseURLIntoHashTable(&sMakeDocumentURL(%main::FormData));
5590 foreach $Value ( keys(%Value) ) {
5591 foreach $ValueEntry ( split(/\0/, $Value{$Value}) ) {
5592 print("<INPUT TYPE=HIDDEN NAME=\"$Value\" VALUE=\"$ValueEntry\">\n");
5593 }
5594 }
5595
5596
5597 # Retain the 'from' folder name if it is defined as these documents are coming from it
5598 if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5599 print("<INPUT TYPE=HIDDEN NAME=\"FromDocumentFolderObject\" VALUE=\"$main::FormData{'FromDocumentFolderObject'}\">\n");
5600 }
5601
5602
5603 # Retain the 'merge' folder name if it is defined as these documents are coming from them
5604 if ( defined($main::FormData{'MergeDocumentFolderObject'}) ) {
5605 foreach $Value ( split(/\0/, $main::FormData{'MergeDocumentFolderObject'}) ) {
5606 print("<INPUT TYPE=HIDDEN NAME=\"MergeDocumentFolderObject\" VALUE=\"$Value\">\n");
5607 }
5608 }
5609
5610 print("</TABLE>\n");
5611 print("</FORM>\n");
5612
5613
5614 # Bail from saving the document folder
5615 bailFromGetSaveFolder:
5616
5617 print("<CENTER><HR WIDTH=50%></CENTER>\n");
5618 undef(%Value);
5619 &vSendMenuBar(%Value);
5620
5621 &vSendHTMLFooter;
5622
5623 return;
5624
5625 }
5626
5627
5628
5629
5630
5631
5632 #--------------------------------------------------------------------------
5633 #
5634 # Function: vSetSaveFolder()
5635 #
5636 # Purpose: This function saves that search and search name in a search file
5637 #
5638 # Called by:
5639 #
5640 # Parameters: void
5641 #
5642 # Global Variables: %main::ConfigurationData, %main::FormData,
5643 # $main::UserSettingsFilePath, $main::RemoteUser,
5644 #
5645 # Returns: void
5646 #
5647 sub vSetSaveFolder {
5648
5649 my ($DocumentFolderFilePath, $HeaderName);
5650 my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5651 my (@DocumentFolderList, $DocumentFolderEntry);
5652 my ($Document, %Document);
5653 my (%Value, @Values, $Value);
5654
5655
5656
5657 # Return an error if the remote user name/account directory is not defined
5658 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5659 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5660 &vSendHTMLFooter;
5661 return;
5662 }
5663
5664
5665
5666 # Make sure that we send the header
5667 &vSendHTMLHeader("Saving a Document Folder", undef);
5668 undef($Value);
5669 &vSendMenuBar(%Value);
5670
5671
5672 # Check that at least one document was selected
5673 if ( !defined($main::FormData{'Document'}) && !defined($main::FormData{'Documents'}) ) {
5674
5675 print("<H3>Saving a Document Folder:</H3>\n");
5676 print("<H3><CENTER>Sorry, no document(s) were selected for saving.</CENTER></H3>\n");
5677 print("<P>\n");
5678 print("There needs to be a least one document selected in order to save it.\n");
5679 print("Click <B>'back'</B> on your browser, select at least one document and try again.\n");
5680
5681 goto bailFromSetSaveFolder;
5682 }
5683
5684
5685 # Check that the required fields are filled in
5686 if ( !(defined($main::FormData{'FolderName'}) || defined($main::FormData{'DocumentFolderObject'})) ) {
5687
5688 # A required field is missing, so we suggest corrective action to the user.
5689 print("<H3> Spremanje foldera s dokumentima: </H3>\n");
5690 print("<H3><CENTER> Oprostite, nedostaju neke informacije. </CENTER></H3>\n");
5691 print("<P>\n");
5692 print("Polje <B>'folder name'</B> mora biti ispunjeno da bi se mogao kreirati folder s dokumentima.<P>\n");
5693 print("Kliknite na <B>'Back'</B> u svom browseru, ispunite polje koje nedostaje i poku¹ajtwe ponovo.\n");
5694 print("<P>\n");
5695
5696 goto bailFromSetSaveFolder;
5697 }
5698
5699
5700
5701 # Check that the folder is there if we are saving to an existing folder
5702 if ( defined($main::FormData{'DocumentFolderObject'}) ) {
5703
5704 # Check the old document folder if it is defined
5705 if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5706
5707 # Set the document folder file path
5708 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'FromDocumentFolderObject'};
5709
5710 # Check to see if the old XML saved search file requested is there
5711 if ( ! -f $DocumentFolderFilePath ) {
5712 # Could not find the old saved search file
5713 &vHandleError("Saving a Document Folder", "Sorry, we cant to access this document folder object because it is not there");
5714 goto bailFromSetSaveFolder;
5715 }
5716
5717 # Get information from the XML document folder file
5718 $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
5719
5720 # Check that the entry is valid
5721 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5722 &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5723 goto bailFromSetSaveFolder;
5724 }
5725 }
5726
5727
5728 # Set the document folder file path
5729 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
5730
5731 # Check to see if the XML saved search file requested is there
5732 if ( ! -f $DocumentFolderFilePath ) {
5733 # Could not find the saved search file
5734 &vHandleError("Saving a Document Folder", "Sorry, we cant to access this document folder object because it is not there");
5735 goto bailFromSetSaveFolder;
5736 }
5737
5738 # Get information from the XML document folder file
5739 $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
5740
5741 # Check that the entry is valid
5742 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5743 &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5744 goto bailFromSetSaveFolder;
5745 }
5746 }
5747 elsif ( defined($main::FormData{'FolderName'}) ) {
5748
5749 # Get the document folder hash
5750 %Value = &hGetDocumentFolders;
5751
5752 # Set the path/flag
5753 $DocumentFolderFilePath = $Value{$main::FormData{'FolderName'}};
5754
5755 # Check that the document folder file does not already exist
5756 if ( defined($DocumentFolderFilePath) && !(defined($main::FormData{'OverWrite'}) && ($main::FormData{'OverWrite'} eq "yes")) ) {
5757
5758 # There is already a document folder with this name, so we suggest corrective action to the user.
5759 print("<H3> Snimanje foldera s dokumentima: </H3>\n");
5760 print("<H3><CENTER> Oprostite, veæ postoji folder s tim imenom. </CENTER></H3>\n");
5761 print("<P>\n");
5762 print("Kliknite na <B>'Back'</B> u svom browseru, promijenite <B>'ime foldera'</B> i poku¹ate ponovo. \n");
5763 print("Alternativno, klikom na kvadratiæ, mo¾ete odabrati da ¾elite postojeæi folder zamijeniti ovim.\n");
5764 print("<P>\n");
5765
5766 goto bailFromSetSaveFolder;
5767 }
5768 }
5769
5770
5771 # Save information in the folder
5772 if ( defined($main::FormData{'DocumentFolderObject'}) ) {
5773
5774 # Get the data from the XML document folder file
5775 ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
5776
5777 # Check that the entry is valid
5778 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
5779 &vHandleError("Saving a Document Folder", "Sorry, this document folder object is invalid");
5780 goto bailFromGetSavedSearch;
5781 }
5782
5783 $FolderName = $Value{'FolderName'};
5784 $FolderDescription = $Value{'FolderDescription'};
5785 $FolderDocuments = $Value{'FolderDocuments'};
5786 $CreationTime = $Value{'CreationTime'};
5787 $UpdateTime = time();
5788
5789
5790 # Merge the documents
5791 if ( defined($FolderDocuments) || defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
5792
5793 # Undefine the hash table in preparation
5794 undef(%Value);
5795
5796 # Make a hash table from the documents already in the document folder
5797 if ( defined($FolderDocuments) ) {
5798 foreach $Value ( split(/\0/, $FolderDocuments) ) {
5799 $Value{$Value} = $Value;
5800 }
5801 }
5802
5803 # Add document that were specifically selected
5804 if ( defined($main::FormData{'Document'}) ) {
5805 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5806 $Value{$Value} = $Value;
5807 }
5808 }
5809 # Otherwise add documents that were selected by default
5810 elsif ( defined($main::FormData{'Documents'}) ) {
5811 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5812 $Value{$Value} = $Value;
5813 }
5814 }
5815
5816 # Assemble the new content
5817 $FolderDocuments = join("\0", keys(%Value));
5818
5819 # Delete the old content
5820 delete($main::FormData{'Document'});
5821 delete($main::FormData{'Documents'});
5822 }
5823
5824 }
5825 elsif ( defined($main::FormData{'FolderName'}) ) {
5826
5827 $FolderName = $main::FormData{'FolderName'};
5828 $FolderDescription = $main::FormData{'FolderDescription'};
5829
5830 # Merge the documents
5831 if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) {
5832
5833 # Undefine the hash table in preparation
5834 undef(%Value);
5835
5836 # Add document that were specifically selected
5837 if ( defined($main::FormData{'Document'}) ) {
5838 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5839 $Value{$Value} = $Value;
5840 }
5841 }
5842 # Otherwise add documents that were selected by default
5843 elsif ( defined($main::FormData{'Documents'}) ) {
5844 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
5845 $Value{$Value} = $Value;
5846 }
5847 }
5848
5849 # Assemble the new content
5850 $main::FormData{'Document'} = join("\0", keys(%Value));
5851
5852 # Delete the old content
5853 delete($main::FormData{'Documents'});
5854 }
5855
5856 $FolderDocuments = $main::FormData{'Document'};
5857 $CreationTime = time();
5858 $UpdateTime = time();
5859 }
5860
5861
5862 # Save the document folder to a new file
5863 if ( &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) ) {
5864
5865 # Are we pulling these documents from an existing folder?
5866 if ( defined($main::FormData{'FromDocumentFolderObject'}) ) {
5867
5868 # Set the document folder file path
5869 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'FromDocumentFolderObject'};
5870
5871 # Get information from the XML document folder file
5872 ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
5873
5874
5875 $FolderName = $Value{'FolderName'};
5876 $FolderDescription = $Value{'FolderDescription'};
5877 $FolderDocuments = $Value{'FolderDocuments'};
5878 $CreationTime = $Value{'CreationTime'};
5879 $UpdateTime = time();
5880
5881
5882 # Make a hash table from the documents selected for deletion, this serves as
5883 # a lookup table when we loop through the existing documents
5884 undef(%Value);
5885 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
5886 $Value{$Value} = 1;
5887 }
5888
5889 # Parse out of the existing documents into a list
5890 foreach $Value ( split(/\0/, $FolderDocuments) ) {
5891 # Add the document if it is not on the deletion list
5892 if ( !defined($Value{$Value}) ) {
5893 push @Values, $Value;
5894 }
5895 }
5896 $FolderDocuments = join("\0", @Values);
5897
5898
5899 # Save the document folder
5900 &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5901
5902 }
5903
5904 if ( defined($main::FormData{'MergeDocumentFolderObject'}) ) {
5905 @Values = split(/\0/, $main::FormData{'MergeDocumentFolderObject'});
5906 foreach $Value ( @Values ) {
5907 # Set the document folder file path
5908 if ( !(defined($main::FormData{'DocumentFolderObject'}) && ($main::FormData{'DocumentFolderObject'} eq $Value))) {
5909 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $Value;
5910 unlink($DocumentFolderFilePath);
5911 }
5912 }
5913 }
5914
5915 print("<H3> Saving a Document Folder: </H3>\n");
5916 print("<P>\n");
5917 print("<H3><CENTER> Your document folder was successfully saved. </CENTER></H3>\n");
5918
5919
5920 }
5921 else {
5922
5923 # The document folder could not be saved, so we inform the user of the fact
5924 &vHandleError("Saving a Document Folder", "Sorry, we failed to save this document folder");
5925 goto bailFromSetSaveFolder;
5926 }
5927
5928
5929 # Bail from saving the document folder
5930 bailFromSetSaveFolder:
5931
5932 print("<CENTER><HR WIDTH=50%></CENTER>\n");
5933 undef(%Value);
5934 &vSendMenuBar(%Value);
5935
5936 &vSendHTMLFooter;
5937
5938 return;
5939
5940 }
5941
5942
5943
5944
5945
5946
5947 #--------------------------------------------------------------------------
5948 #
5949 # Function: vListFolder()
5950 #
5951 # Purpose: This function allows the user list the document folders and
5952 # sets up the links allowing the user to get a list of the documents
5953 #
5954 # Called by:
5955 #
5956 # Parameters: void
5957 #
5958 # Global Variables: %main::ConfigurationData, %main::FormData,
5959 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
5960 # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
5961 #
5962 # Returns: void
5963 #
5964 sub vListFolder {
5965
5966 my (@DocumentFolderList, %QualifiedDocumentFolders, $DocumentFolderEntry, $HeaderName);
5967 my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
5968 my (@Values, $Value, %Value);
5969
5970
5971 # Return an error if the remote user name/account directory is not defined
5972 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
5973 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
5974 &vSendHTMLFooter;
5975 return;
5976 }
5977
5978
5979 # Make sure that we send the header
5980 &vSendHTMLHeader("Document Folders", undef);
5981 undef(%Value);
5982 $Value{'ListFolder'} = "ListFolder";
5983 &vSendMenuBar(%Value);
5984 undef(%Value);
5985
5986
5987
5988 # Print out the document folders
5989 print("<H3> Folderi: </H3>\n");
5990
5991
5992 # Get the document folder hash
5993 %QualifiedDocumentFolders = &hGetDocumentFolders;
5994
5995
5996 # Print up the document folders, if there is none, we put up a nice message
5997 if ( scalar(keys(%QualifiedDocumentFolders)) > 0 ) {
5998
5999 # Start the table
6000 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
6001
6002 # Start the form
6003 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
6004
6005
6006 # Print the selector
6007 print("<TR><TD ALIGN=RIGHT VALIGN=TOP COLSPAN=3>\n");
6008 print("<SELECT NAME=\"Action\">\n");
6009 print("<OPTION VALUE=\"DeleteFolder\">Obri¹i oznaèene foldere\n");
6010 print("<OPTION VALUE=\"GetMergeFolder\">Spoji oznaèene foldere u novi folder\n");
6011
6012 for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
6013
6014 $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
6015
6016 # Get the document folder file name and encode it
6017 $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
6018 $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
6019
6020 print("<OPTION VALUE=\"SetMergeFolder&ToDocumentFolderObject=$DocumentFolderEntry\">Spoji oznaèene foldere u '$FolderName' folder\n");
6021 }
6022
6023 print("</SELECT>\n");
6024 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
6025 print("</TD></TR>\n");
6026
6027
6028
6029 # List the folders
6030 for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
6031
6032 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=3><HR WIDTH=50%></TD></TR>\n");
6033
6034 $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
6035
6036 # Get information from the XML document folder file
6037 ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderEntry);
6038
6039 # Get the saved search file name and encode it
6040 $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
6041 $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
6042
6043
6044 $FolderName = $Value{'FolderName'};
6045 $FolderDescription = $Value{'FolderDescription'};
6046 $FolderDocuments = $Value{'FolderDocuments'};
6047 $CreationTime = $Value{'CreationTime'};
6048 $UpdateTime = $Value{'UpdateTime'};
6049
6050
6051 # Print the link
6052 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");
6053
6054 # Print the folder description
6055 $FolderDescription = defined($FolderDescription) ? $FolderDescription : "(Nije naveden)";
6056 $FolderDescription =~ s/\n/<BR>/g;
6057 $FolderDescription =~ s/\r/<BR>/g;
6058 print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $FolderDescription </TD></TR>\n");
6059
6060 if ( defined($FolderDocuments) ) {
6061 @Values = split(/\0/, $FolderDocuments);
6062 $Value = scalar( @Values );
6063 }
6064 else {
6065 $Value = 0;
6066 }
6067 print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Broj rezultata: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6068
6069
6070 $Value = &sGetPrintableDateFromTime($CreationTime);
6071 print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6072
6073 $Value = &sGetPrintableDateFromTime($UpdateTime);
6074 print("<TR><TD WIDTH=1%></TD><TD ALIGN=LEFT VALIGN=TOP> Datum zadnje promijene: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6075
6076 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");
6077 }
6078
6079 print("</FORM></TABLE>\n");
6080 }
6081 else {
6082 print("<H3><CENTER> Nema foldera! </CENTER></H3>\n");
6083 }
6084
6085
6086
6087
6088 # Bail from displaying document folders
6089 bailFromListFolder:
6090
6091 print("<CENTER><HR WIDTH=50%></CENTER>\n");
6092 undef(%Value);
6093 $Value{'ListFolder'} = "ListFolder";
6094 &vSendMenuBar(%Value);
6095 undef(%Value);
6096
6097 &vSendHTMLFooter;
6098
6099
6100 return;
6101
6102 }
6103
6104
6105
6106
6107
6108
6109 #--------------------------------------------------------------------------
6110 #
6111 # Function: vMergeFolder()
6112 #
6113 # Purpose: This function deletes a folder.
6114 #
6115 # Called by:
6116 #
6117 # Parameters: void
6118 #
6119 # Global Variables: %main::ConfigurationData, %main::FormData,
6120 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6121 # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6122 #
6123 # Returns: void
6124 #
6125 sub vMergeFolder {
6126
6127 my ($Title, $HeaderName, $DocumentFolderFilePath, $DocumentFolderObject, $FolderDocuments);
6128 my ($Value, %Value);
6129
6130
6131
6132 # Return an error if the remote user name/account directory is not defined
6133 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6134 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6135 &vSendHTMLFooter;
6136 return;
6137 }
6138
6139
6140
6141 # Check to see if the document folder object is defined
6142 if ( ! defined($main::FormData{'DocumentFolderObject'}) ) {
6143
6144 # Could not find the document folder file
6145 &vSendHTMLHeader("Merge Document Folders", undef);
6146 undef(%Value);
6147 &vSendMenuBar(%Value);
6148 print("<H3> Merge Document Folders: </H3>\n");
6149 print("<H3><CENTER> Sorry, no document folders were selected. </CENTER></H3>\n");
6150 print("<P>\n");
6151 print("You need to select at least one document folder in order to be able to perform an action on it.\n");
6152 print("<P>\n");
6153 return;
6154 }
6155
6156
6157 # Init the value hash
6158 undef(%Value);
6159
6160 # Loop over document folder object
6161 $Value = $main::FormData{'DocumentFolderObject'} .
6162 ((defined($main::FormData{'ToDocumentFolderObject'})) ? "\0" . $main::FormData{'ToDocumentFolderObject'} : "");
6163
6164 foreach $DocumentFolderObject ( split(/\0/, $Value) ) {
6165
6166 # Set the document folder file path
6167 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $DocumentFolderObject;
6168
6169 # Check to see if the XML saved search file requested is there
6170 if ( ! -f $DocumentFolderFilePath ) {
6171 next;
6172 }
6173
6174 # Get information from the XML saved search file
6175 $HeaderName = &sGetObjectTagFromXMLFile($DocumentFolderFilePath);
6176
6177 # Check that the entry is valid
6178 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6179 next;
6180 }
6181
6182 # Get the FolderDocuments symbol
6183 $FolderDocuments = &sGetTagValueFromXMLFile($DocumentFolderFilePath, "FolderDocuments");
6184
6185 # Add each document to the hash
6186 foreach $Value ( split(/\0/, $FolderDocuments) ) {
6187 $Value{$Value} = $Value;
6188 }
6189 }
6190
6191 # Set the document URL from the hash
6192 $main::FormData{'Document'} = join("\0", keys(%Value));
6193
6194
6195 if ( defined($main::FormData{'DocumentFolderObject'}) ) {
6196 $main::FormData{'MergeDocumentFolderObject'} = $main::FormData{'DocumentFolderObject'};
6197 delete($main::FormData{'DocumentFolderObject'});
6198 }
6199
6200 if ( defined($main::FormData{'ToDocumentFolderObject'}) ) {
6201 $main::FormData{'DocumentFolderObject'} = $main::FormData{'ToDocumentFolderObject'};
6202 delete($main::FormData{'ToDocumentFolderObject'});
6203 }
6204
6205
6206 if ( $ENV{'PATH_INFO'} eq "/GetMergeFolder" ) {
6207 &vGetSaveFolder;
6208 }
6209 elsif ( $ENV{'PATH_INFO'} eq "/SetMergeFolder" ) {
6210 &vSetSaveFolder;
6211 }
6212
6213
6214 return;
6215
6216 }
6217
6218
6219
6220
6221
6222
6223 #--------------------------------------------------------------------------
6224 #
6225 # Function: vProcessFolder()
6226 #
6227 # Purpose: This function deletes a folder.
6228 #
6229 # Called by:
6230 #
6231 # Parameters: void
6232 #
6233 # Global Variables: %main::ConfigurationData, %main::FormData,
6234 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6235 # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6236 #
6237 # Returns: void
6238 #
6239 sub vProcessFolder {
6240
6241 my ($Title, $HeaderName, $DocumentFolderFilePath, $DocumentFolderObject);
6242 my ($Value, %Value);
6243
6244
6245
6246 # Return an error if the remote user name/account directory is not defined
6247 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6248 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6249 &vSendHTMLFooter;
6250 return;
6251 }
6252
6253
6254
6255 if ( $ENV{'PATH_INFO'} eq "/DeleteFolder" ) {
6256 $Title = "Delete Document Folders";
6257 }
6258
6259
6260 # Make sure that we send the header
6261 &vSendHTMLHeader($Title, undef);
6262 undef(%Value);
6263 &vSendMenuBar(%Value);
6264
6265 print("<H3> $Title: </H3>\n");
6266
6267 # Check to see if the document folder object is defined
6268 if ( ! defined($main::FormData{'DocumentFolderObject'}) ) {
6269
6270 # Could not find the document folder file
6271 print("<H3><CENTER> Sorry, no document folders were selected. </CENTER></H3>\n");
6272 print("<P>\n");
6273 print("You need to select at least one document folder in order to be able to perform an action on it.\n");
6274 print("<P>\n");
6275
6276 goto bailFromProcessFolder;
6277 }
6278
6279
6280 # Loop over document folder object
6281 foreach $DocumentFolderObject ( split(/\0/, $main::FormData{'DocumentFolderObject'}) ) {
6282
6283 # Set the document folder file path
6284 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $DocumentFolderObject;
6285
6286 # Check to see if the XML saved search file requested is there
6287 if ( ! -f $DocumentFolderFilePath ) {
6288 printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6289 next;
6290 }
6291
6292 # Get information from the XML saved search file
6293 ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
6294
6295 # Check that the entry is valid
6296 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6297 printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6298 }
6299
6300
6301 if ( unlink($DocumentFolderFilePath) ) {
6302 printf("<P>Successfully deleted: %s\n", $Value{'FolderName'});
6303 }
6304 else {
6305 printf("<P>Failed to delete: %s\n", $Value{'FolderName'});
6306 }
6307 }
6308
6309 print("<P>\n");
6310
6311 # Bail from processing the document folder
6312 bailFromProcessFolder:
6313
6314 print("<CENTER><HR WIDTH=50%></CENTER>\n");
6315 undef(%Value);
6316 &vSendMenuBar(%Value);
6317
6318 &vSendHTMLFooter;
6319
6320 return;
6321
6322 }
6323
6324
6325
6326
6327
6328
6329 #--------------------------------------------------------------------------
6330 #
6331 # Function: vGetFolder()
6332 #
6333 # Purpose: This function displays a document folder to the user.
6334 #
6335 # Called by:
6336 #
6337 # Parameters: void
6338 #
6339 # Global Variables: %main::ConfigurationData, %main::FormData,
6340 # $main::UserAccountDirectoryPath, $main::XMLFileNameExtension,
6341 # $main::DocumentFolderFileNamePrefix, $main::RemoteUser
6342 #
6343 # Returns: void
6344 #
6345 sub vGetFolder {
6346
6347 my ($HeaderName, $FolderName, $SelectorText, %ArticleFolder);
6348 my (@DocumentFolderList, $DocumentFolderEntry, %QualifiedDocumentFolders);
6349 my ($Value, %Value);
6350
6351
6352 # Return an error if the remote user name/account directory is not defined
6353 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6354 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6355 &vSendHTMLFooter;
6356 return;
6357 }
6358
6359
6360
6361 # Make the document folder file name
6362 $DocumentFolderEntry = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
6363
6364 # Check to see if the XML document folder file requested is there
6365 if ( ! -f $DocumentFolderEntry ) {
6366 # Could not find the document folders file
6367 &vHandleError("Document Folder", "Sorry, we cant to access this document folder object because it is not there");
6368 goto bailFromGetFolder;
6369 }
6370
6371 # Get information from the XML document folder file
6372 ($HeaderName, %ArticleFolder) = &shGetHashFromXMLFile($DocumentFolderEntry);
6373
6374 # Check that the entry is valid
6375 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6376 &vHandleError("Document Folder", "Sorry, this document folder object is invalid");
6377 goto bailFromGetFolder;
6378 }
6379
6380
6381 # Make sure we send the header
6382 &vSendHTMLHeader("Document Folder", undef);
6383 undef(%Value);
6384 &vSendMenuBar(%Value);
6385
6386 print("<H3> Document Folder: </H3>\n");
6387
6388
6389 # Start the form
6390 print("<FORM ACTION=\"$ENV{'SCRIPT_NAME'}\" METHOD=POST>\n");
6391
6392
6393 # Print the selector if there are any documents
6394 if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6395 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
6396 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");
6397 print("<SELECT NAME=\"Action\">\n");
6398 print("<OPTION VALUE=\"GetDocument\">Prika¾i odabrane rezultates\n");
6399 if ( $main::ConfigurationData{'allow-similiar-search'} eq "yes" ) {
6400 print("<OPTION VALUE=\"GetSimilarDocument\">Prika¾i rezultate sliène odabranim rezultatima\n");
6401 }
6402 if ( $main::ConfigurationData{'allow-relevance-feedback-searches'} eq "yes" ) {
6403 print("<OPTION VALUE=\"GetSearchResults\">Run search with selected documents as relevance feedback\n");
6404 }
6405 print("<OPTION VALUE=\"DeleteDocument&DocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Delete selected documents from this document folder\n");
6406 print("<OPTION VALUE=\"GetSaveFolder&FromDocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Move selected documents to a new document folder\n");
6407
6408
6409 # Get the document folder hash
6410 %QualifiedDocumentFolders = &hGetDocumentFolders;
6411
6412 for $FolderName ( sort( keys(%QualifiedDocumentFolders)) ) {
6413
6414 # Skip this folder
6415 if ( $FolderName eq $ArticleFolder{'FolderName'} ) {
6416 next;
6417 }
6418
6419 $DocumentFolderEntry = $QualifiedDocumentFolders{$FolderName};
6420
6421 # Get the document folder file name and encode it
6422 $DocumentFolderEntry = ($DocumentFolderEntry =~ /^$main::UserAccountDirectoryPath\/(.*)/) ? $1 : $DocumentFolderEntry;
6423 $DocumentFolderEntry = &lEncodeURLData($DocumentFolderEntry);
6424
6425 print("<OPTION VALUE=\"SetSaveFolder&DocumentFolderObject=$DocumentFolderEntry&FromDocumentFolderObject=$main::FormData{'DocumentFolderObject'}\">Move selected documents to the '$FolderName' document folder\n");
6426 }
6427
6428 print("</SELECT>\n");
6429 print("<INPUT TYPE=SUBMIT VALUE=\"Do It!\">\n");
6430 print("</TD></TR>\n");
6431 print("</TABLE>\n");
6432 }
6433
6434 print("<CENTER><HR WIDTH=50%></CENTER>\n");
6435
6436
6437 print("<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%>\n");
6438
6439 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Naziv: </TD> <TD ALIGN=LEFT VALIGN=TOP> $ArticleFolder{'FolderName'} </TD></TR>\n");
6440
6441 # Print the folder description
6442 $ArticleFolder{'FolderDescription'} = defined($ArticleFolder{'FolderDescription'}) ? $ArticleFolder{'FolderDescription'} : "(No description defined)";
6443 $ArticleFolder{'FolderDescription'} =~ s/\n/<BR>/g;
6444 $ArticleFolder{'FolderDescription'} =~ s/\r/<BR>/g;
6445 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Opis: </TD> <TD ALIGN=LEFT VALIGN=TOP> $ArticleFolder{'FolderDescription'} </TD></TR>\n");
6446
6447
6448 $Value = &sGetPrintableDateFromTime($ArticleFolder{'CreationTime'});
6449 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum kreiranja: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6450
6451 $Value = &sGetPrintableDateFromTime($ArticleFolder{'UpdateTime'});
6452 print("<TR><TD ALIGN=LEFT VALIGN=TOP> Datum zadnje promijene: </TD> <TD ALIGN=LEFT VALIGN=TOP> $Value </TD></TR>\n");
6453
6454 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2><HR WIDTH=50%></TD></TR>\n");
6455
6456
6457 # Display a button to select all the documents if there are any
6458 if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6459
6460 $SelectorText = "";
6461
6462 # Loop over each entry folder documents
6463 foreach $Value ( split(/\0/, $ArticleFolder{'FolderDocuments'}) ) {
6464 $SelectorText .= (($SelectorText ne "") ? "|" : "") . $Value;
6465 }
6466
6467 $SelectorText = "<INPUT TYPE=\"HIDDEN\" NAME=\"Documents\" VALUE=\"" . $SelectorText . "\"> ";
6468 print("<TR><TD ALIGN=LEFT VALIGN=TOP COLSPAN=2> $SelectorText </TD></TR>\n");
6469 }
6470
6471 if ( defined($ArticleFolder{'FolderDocuments'}) ) {
6472 print("<TR>\n");
6473 &bDisplayDocuments("Document", $ArticleFolder{'FolderDocuments'}, "Document", 1, undef, 1);
6474 print("</TR>\n");
6475 }
6476 else {
6477 print("<TR><TD ALIGN=CENTER VALIGN=TOP COLSPAN=2> This document folder does not contain any documents. </TD></TR>\n");
6478 }
6479
6480 print("</FORM></TABLE>\n");
6481
6482 # Bail from displaying the document folder
6483 bailFromGetFolder:
6484
6485 print("<CENTER><HR WIDTH=50%></CENTER>\n");
6486 undef(%Value);
6487 &vSendMenuBar(%Value);
6488
6489 &vSendHTMLFooter;
6490
6491 return;
6492
6493 }
6494
6495
6496
6497
6498
6499
6500 #--------------------------------------------------------------------------
6501 #
6502 # Function: vProcessDocument()
6503 #
6504 # Purpose: This function deletes folder documents
6505 #
6506 # Called by:
6507 #
6508 # Parameters: void
6509 #
6510 # Global Variables: %main::ConfigurationData, %main::FormData,
6511 # $main::UserSettingsFilePath, $main::RemoteUser,
6512 #
6513 # Returns: void
6514 #
6515 sub vProcessDocument {
6516
6517 my ($Title, $DocumentFolderFilePath, $HeaderName);
6518 my ($FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime);
6519 my (%Value, @Values, $Value);
6520
6521
6522
6523 # Return an error if the remote user name/account directory is not defined
6524 if ( ! (defined($main::RemoteUser) && defined($main::UserAccountDirectoryPath)) ) {
6525 &vHandleError("Undefined User Account", "Sorry, there is no user account defined");
6526 &vSendHTMLFooter;
6527 return;
6528 }
6529
6530
6531 # Check to see if the XML document folder is there
6532 if ( !defined($main::FormData{'DocumentFolderObject'}) ) {
6533 # Could not find the document folders file
6534 &vHandleError($Title, "Sorry, the document folder object was not defined");
6535 goto bailFromProcessDocument;
6536 }
6537
6538
6539 # Set the title
6540 if ( $ENV{'PATH_INFO'} eq "/DeleteDocument" ) {
6541 $Title = "Delete Folder Documents";
6542 }
6543
6544
6545 # Make sure that we send the header
6546 &vSendHTMLHeader($Title, undef);
6547 undef(%Value);
6548 &vSendMenuBar(%Value);
6549
6550
6551
6552 # Check to see if the document folder object is defined
6553 if ( ! (defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'})) ) {
6554
6555 # No documents were defined
6556 print("<H3><CENTER> Sorry, no documents were selected. </CENTER></H3>\n");
6557 print("<P>\n");
6558 print("You need to select at least one document in order to be able to perform an action on it.\n");
6559 print("<P>\n");
6560
6561 goto bailFromProcessDocument;
6562 }
6563
6564
6565 # Set the document folder file path
6566 $DocumentFolderFilePath = $main::UserAccountDirectoryPath . "/" . $main::FormData{'DocumentFolderObject'};
6567
6568
6569 # Check to see if the XML document folder file requested is there
6570 if ( ! -f $DocumentFolderFilePath ) {
6571 # Could not find the document folders file
6572 &vHandleError($Title, "Sorry, we cant to access this document folder object because it is not there");
6573 goto bailFromProcessDocument;
6574 }
6575
6576
6577 # Get information from the XML document folder file
6578 ($HeaderName, %Value) = &shGetHashFromXMLFile($DocumentFolderFilePath);
6579
6580 # Check that the entry is valid
6581 if ( !(defined($HeaderName) && ($HeaderName eq "DocumentFolder")) ) {
6582 &vHandleError($Title, "Sorry, this document folder object is invalid");
6583 goto bailFromProcessDocument;
6584 }
6585
6586
6587
6588 $FolderName = $Value{'FolderName'};
6589 $FolderDescription = $Value{'FolderDescription'};
6590 $FolderDocuments = $Value{'FolderDocuments'};
6591 $CreationTime = $Value{'CreationTime'};
6592 $UpdateTime = time();
6593
6594
6595 # Make a hash table from the documents selected for deletion, this serves as
6596 # a lookup table when we loop through the existing documents
6597 # List the documents
6598 if ( defined($main::FormData{'Document'}) || defined($main::FormData{'Documents'}) ) {
6599
6600 # Undefine the hash table in preparation
6601 undef(%Value);
6602
6603 # Add document that were specifically selected
6604 if ( defined($main::FormData{'Document'}) ) {
6605 foreach $Value ( split(/\0/, $main::FormData{'Document'}) ) {
6606 $Value{$Value} = $Value;
6607 }
6608 }
6609 # Otherwise add documents that were selected by default
6610 elsif ( defined($main::FormData{'Documents'}) ) {
6611 foreach $Value ( split(/\|/, $main::FormData{'Documents'}) ) {
6612 $Value{$Value} = $Value;
6613 }
6614 }
6615 }
6616
6617
6618 # Parse out of the existing documents into a list
6619 foreach $Value ( split(/\0/, $FolderDocuments) ) {
6620 # Add the document if it is not on the deletion list
6621 if ( !defined($Value{$Value}) ) {
6622 push @Values, $Value;
6623 }
6624 }
6625 $FolderDocuments = join("\0", @Values);
6626
6627
6628 # Save the document folder (now missing the selected documents)
6629 if ( &iSaveFolder($DocumentFolderFilePath, $FolderName, $FolderDescription, $FolderDocuments, $CreationTime, $UpdateTime) ) {
6630
6631 print("<H3> $Title: </H3>\n");
6632 print("<P>\n");
6633 print("<H3><CENTER> The folder documents were successfully deleted. </CENTER></H3>\n");
6634
6635 }
6636 else {
6637
6638 # The documents coudl not be deleted, so we inform the user of the fact
6639 &vHandleError($Title, "Sorry, we failed to delete the selected folder documents");
6640 goto bailFromProcessDocument;
6641 }
6642
6643
6644 # Bail from deleting the documents
6645 bailFromProcessDocument:
6646
6647 print("<CENTER><HR WIDTH=50%></CENTER>\n");
6648 undef(%Value);
6649 &vSendMenuBar(%Value);
6650
6651 &vSendHTMLFooter;
6652
6653 return;
6654
6655 }
6656
6657
6658
6659
6660
6661
6662 #--------------------------------------------------------------------------
6663 #
6664 # Function: vRunSavedSearches()
6665 #
6666 # Purpose: Run the saved searches which are due
6667 #
6668 # Called by:
6669 #
6670 # Parameters: $PassedFrequency search frequency
6671 #
6672 # Global Variables:
6673 #
6674 # Returns: void
6675 #
6676 sub vRunSavedSearches {
6677
6678 my ($PassedFrequency) = @_;
6679 my (@UserAccountsDirectoryList, $UserAccountsDirectory, @UserSavedSearchList, $UserSavedSearch);
6680 my (@SavedSearchFilePathList, @QualifiedSaveSearchFilePathList, $SavedSearchFilePath);
6681 my ($SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchString, $DeliveryFormat, $DeliveryMethod, $SearchFrequency, $SearchStatus, $CreationTime, $LastRunTime);
6682 my ($EmailAddress, $NewLastRunTime, $Databases, $HeaderName);
6683 my ($Status, $SearchResults, $FinalSearchString, $SearchResult, $ResultCount, $QueryReport, $ErrorNumber, $ErrorMessage);
6684 my ($ItemName, $MimeType, $HTML, $SavedFileHandle);
6685 my ($Value, %Value, $ValueEntry);
6686
6687
6688 # Check that we can actually run saved searches
6689 if ( !(defined($main::ConfigurationData{'allow-regular-searches'}) && ($main::ConfigurationData{'allow-regular-searches'} eq "yes")) ) {
6690 print("Execution error - configuration setting: 'allow-regular-searches', setting not set or disabled.\n");
6691 return;
6692 }
6693
6694
6695 # Check that we have a user account directory
6696 if ( !defined($main::ConfigurationData{'user-accounts-directory'}) ) {
6697 print("Execution error - configuration setting: 'user-accounts-directory', setting not set.\n");
6698 }
6699
6700
6701 # Check that we have a script URL
6702 if ( !(defined($main::ConfigurationData{'script-url'}) && ($main::ConfigurationData{'script-url'} ne "yes")) ) {
6703 print("Execution error - configuration setting: 'script-url', setting not set.\n");
6704 }
6705
6706
6707 # Scoop up all the directories in the user accounts directory
6708 opendir(ACCOUNTS_DIRECTORY, $main::ConfigurationData{'user-accounts-directory'});
6709 @UserAccountsDirectoryList = grep(!/^\.\.?$/, readdir(ACCOUNTS_DIRECTORY));
6710 closedir(ACCOUNTS_DIRECTORY);
6711
6712 # Loop over each user account
6713 foreach $UserAccountsDirectory ( @UserAccountsDirectoryList ) {
6714
6715 # Read all the saved searches
6716 opendir(USER_ACCOUNT_DIRECTORY, $main::ConfigurationData{'user-accounts-directory'} . "/" . $UserAccountsDirectory);
6717 @UserSavedSearchList = grep(/$main::SavedSearchFileNamePrefix/, readdir(USER_ACCOUNT_DIRECTORY));
6718 closedir(USER_ACCOUNT_DIRECTORY);
6719
6720 # And add each to the saved searches list
6721 foreach $UserSavedSearch ( @UserSavedSearchList ) {
6722 push @SavedSearchFilePathList, $main::ConfigurationData{'user-accounts-directory'} . "/" . $UserAccountsDirectory . "/" . $UserSavedSearch;
6723 }
6724 }
6725
6726
6727 # Return here if there are no saved search to process
6728 if ( ! @SavedSearchFilePathList ) {
6729 print("Execution warning - no saved searches to process.\n");
6730 return;
6731 }
6732
6733
6734 # Loop over each file in the list, checking to see if it is time to
6735 # process this one, if so we add it to the qualified saved search list
6736 foreach $SavedSearchFilePath ( @SavedSearchFilePathList ) {
6737
6738 # Get the header name from the saved search file
6739 $HeaderName = &sGetObjectTagFromXMLFile($SavedSearchFilePath);
6740
6741 # Skip this saved search file entry if it is not valid
6742 if ( !(defined($HeaderName) && ($HeaderName eq "SavedSearch")) ) {
6743 print("Execution error - invalid saved search object: '$SavedSearchFilePath'.\n");
6744 next;
6745 }
6746
6747
6748 # Get the delivery format from the saved search file
6749 $DeliveryFormat = &sGetTagValueFromXMLFile($SavedSearchFilePath, "DeliveryFormat");
6750
6751 # Check the delivery format, it is undefined if the search is not a regular search
6752 if ( ! defined($DeliveryFormat) ) {
6753 next;
6754 }
6755
6756 # Check the validity of the delivery format
6757 if ( ! defined($main::DeliveryFormats{$DeliveryFormat}) ) {
6758 print("Execution error - invalid delivery method: '$DeliveryFormat' in saved search: '$SavedSearchFilePath'.\n");
6759 next;
6760 }
6761
6762
6763
6764 # Set the user settings file path name
6765 $main::UserSettingsFilePath = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/") + 1) . $main::UserSettingsFileName . $main::XMLFileNameExtension;
6766
6767 # Check that this preference file is valid
6768 $HeaderName = &sGetObjectTagFromXMLFile($main::UserSettingsFilePath);
6769
6770 # Skip this entry if it is not valid
6771 if ( !(defined($HeaderName) && ($HeaderName eq "UserSettings")) ) {
6772 print("Execution error - invalid user settings object: '$main::UserSettingsFilePath'.\n");
6773 next;
6774 }
6775
6776
6777 # Get the email address from the user settings file
6778 $EmailAddress = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
6779
6780 # Skip this entry if it is not valid
6781 if ( !defined($EmailAddress) ) {
6782 print("Execution error - invalid email address in user settings object: '$main::UserSettingsFilePath'.\n");
6783 next;
6784 }
6785
6786
6787 # Get the frequency requested for this saved search
6788 $SearchFrequency = &sGetTagValueFromXMLFile($SavedSearchFilePath, "SearchFrequency");
6789
6790 # Check the search frequency, skip if it is undefined
6791 if ( !defined($SearchFrequency)) {
6792 print("Execution error - undefined search frequency in user settings object: '$main::UserSettingsFilePath'.\n");
6793 next;
6794 }
6795
6796 # Check the search frequency, skip if it is invalid
6797 $Value = 0;
6798 foreach $ValueEntry ( @main::SearchFrequencies ) {
6799 if ( $ValueEntry eq $SearchFrequency ) {
6800 $Value = 1;
6801 last;
6802 }
6803 }
6804 if ( !$Value ) {
6805 print("Execution error - invalid search frequency: '$SearchFrequency', in user settings object: '$main::UserSettingsFilePath'.\n");
6806 next;
6807 }
6808
6809
6810 # Is this the frequency we are currently working on?
6811 if ( index($PassedFrequency, $SearchFrequency) < 0 ) {
6812 next;
6813 }
6814
6815
6816 # It is, so we concatenate the saved search file name to the list of
6817 # qualified saved search file names
6818 push @QualifiedSaveSearchFilePathList, $SavedSearchFilePath;
6819 }
6820
6821
6822
6823 # Return here if there are no qualified saved search to process
6824 if ( ! @QualifiedSaveSearchFilePathList ) {
6825 return;
6826 }
6827
6828
6829 # Get the current time, this will be used as the new last run time
6830 $NewLastRunTime = time();
6831
6832
6833 # Loop each saved search in the qualified saved search list, processing each of them
6834 foreach $SavedSearchFilePath ( @QualifiedSaveSearchFilePathList ) {
6835
6836 # Get information from the XML saved search file
6837 ($HeaderName, %Value) = &shGetHashFromXMLFile($SavedSearchFilePath);
6838
6839 $SearchName = $Value{'SearchName'};
6840 $SearchDescription = $Value{'SearchDescription'};
6841 $SearchString = $Value{'SearchString'};
6842 $SearchAndRfDocumentURL = $Value{'SearchAndRfDocumentURL'};
6843 $SearchFrequency = $Value{'SearchFrequency'};
6844 $SearchStatus = $Value{'SearchStatus'};
6845 $DeliveryFormat = $Value{'DeliveryFormat'};
6846 $DeliveryMethod = $Value{'DeliveryMethod'};
6847 $CreationTime = $Value{'CreationTime'};
6848 $LastRunTime = $Value{'LastRunTime'};
6849
6850
6851 # Check the search status, run the search if it is active
6852 if ( defined($SearchStatus) && ($SearchStatus eq "Active") ) {
6853
6854 # Get the last run time from the XML saved search file
6855 if ( !defined($LastRunTime) ) {
6856 $LastRunTime = "0";
6857 }
6858
6859
6860 # Set the remote user name
6861 $main::RemoteUser = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/"));
6862 $main::RemoteUser = substr($main::RemoteUser, rindex($main::RemoteUser,"/") + 1);
6863
6864 # Set the user directory path
6865 $main::UserAccountDirectoryPath = substr($SavedSearchFilePath, 0, rindex($SavedSearchFilePath,"/") + 1);
6866
6867 # Set the user settings file path name
6868 $main::UserSettingsFilePath = $main::UserAccountDirectoryPath . $main::UserSettingsFileName . $main::XMLFileNameExtension;
6869
6870 # Get the email address from the user settings file
6871 $EmailAddress = &sGetTagValueFromXMLFile($main::UserSettingsFilePath, "EmailAddress");
6872
6873 # Parse the URL search string into the form data global
6874 %main::FormData = &hParseURLIntoHashTable($SearchAndRfDocumentURL);
6875
6876
6877 ##########################
6878 # Uncomment this to force a check over the complete database rather than
6879 # just getting the documents which changed since the last run
6880 # $LastRunTime = 0;
6881 ##########################
6882
6883
6884 # Clear the date restriction fields, they are meaningless in this context
6885 delete($main::FormData{'Since'});
6886 delete($main::FormData{'Before'});
6887
6888 # Set the last run time restriction
6889 $main::FormData{'LastRunTime'} = $LastRunTime;
6890
6891
6892 # Generate the search string
6893 $FinalSearchString = &sMakeSearchString(%main::FormData);
6894
6895
6896 # Set the local database names
6897 if ( defined($main::FormData{'Database'}) ) {
6898
6899 # Set the database variable and convert all the '\0' to ','
6900 $Databases = $main::FormData{'Database'};
6901 $Databases =~ tr/\0/,/;
6902 }
6903
6904
6905
6906 print("Execution - saved search: '$SavedSearchFilePath', database: '$Databases', search: '$FinalSearchString', time: '$LastRunTime'.\n");
6907
6908 # Run the search
6909 ($Status, $SearchResults) = MPS::SearchDatabase($main::MPSSession, $Databases, $FinalSearchString, "", 0, $main::DefaultMaxDoc - 1, $main::ConfigurationData{'max-score'});
6910
6911 if ( ! $Status ) {
6912 ($ErrorNumber, $ErrorMessage) = split(/\t/, $SearchResults, 2);
6913 print("Execution error - failed to run the search.\n");
6914 print("The following error message was reported: <BR>\n");
6915 print("Error Message: $ErrorMessage <BR>\n");
6916 print("Error Number: $ErrorNumber <BR>\n");
6917 next;
6918 }
6919
6920
6921 # Get the number of results we got from the search
6922 $ResultCount = 0;
6923 foreach $SearchResult ( split(/\n/, $SearchResults) ) {
6924
6925 # Parse the headline, also get the first document item/type
6926 (undef, undef, undef, undef, undef undef, $ItemName, $MimeType, undef) = split(/\t/, $SearchResult, 9);
6927
6928 # Is this a query report
6929 if ( !(($ItemName eq $main::QueryReportItemName) && ($MimeType eq $main::QueryReportMimeType)) ) {
6930 # Increment the result count
6931 $ResultCount++;
6932 }
6933 }
6934
6935
6936 # Do we want to deliver email messages with no new results?
6937 if ( defined($main::ConfigurationData{'deliver-empty-results-from-regular-search'}) && ($main::ConfigurationData{'deliver-empty-results-from-regular-search'} eq "no") ) {
6938 if ( $ResultCount == 0 ) {
6939 next;
6940 }
6941 }
6942
6943
6944 # Open the mail application, put put an error message if we cant open it and loop to the next saved search
6945 if ( ! open(RESULT_FILE, "| $main::ConfigurationData{'mailer-application'} $EmailAddress ") ) {
6946 print("Execution error - failed to launch mail application: '$main::ConfigurationData{'mailer-application'}', system error: $!.\n");
6947 next;
6948 }
6949
6950
6951 # Save the file handle for stdout and select the result file handle as the default handle
6952 $SavedFileHandle = select;
6953 select RESULT_FILE;
6954
6955
6956 # Print out the message header (To:)
6957 print ("To: $EmailAddress\n");
6958
6959 # Print out the message header (From:)
6960 if ( defined($main::ConfigurationData{'site-admin-email'}) && ($main::ConfigurationData{'site-admin-email'} ne "") ) {
6961 print ("From: $main::ConfigurationData{'site-admin-email'}\n");
6962 }
6963
6964 # Print out the message header (Subject:)
6965 print ("Subject: Results for saved search: $SearchName\n");
6966
6967
6968 # Print out the message header (Content-Type)
6969 if ( $DeliveryMethod eq "attachement" ) {
6970 print("Mime-Version: 1.0\n");
6971 print("Content-Type: multipart/mixed; boundary=\"============_-1234567890==_============\"\n");
6972 }
6973 else {
6974 print("Mime-Version: 1.0\n");
6975 printf("Content-Type: %s\n\n", ($DeliveryFormat eq "text/html") ? "text/html" : "text/plain");
6976 }
6977
6978 # Print out the separating new line between message header and message body
6979 print("\n");
6980
6981
6982
6983 # Print out mime part separator and mime header for the message header
6984 if ( $DeliveryMethod eq "attachement" ) {
6985 print("--============_-1234567890==_============\n");
6986 printf("Content-Type: text/plain; charset=\"us-ascii\"\n\n\n");
6987
6988 if ( $DeliveryFormat eq "text/plain" ) {
6989 print("The search results are attached to this email message as a plain text\n");
6990 print("file. This file can be opened with a any word processor or text editor.\n");
6991 }
6992 elsif ( $DeliveryFormat eq "text/html" ) {
6993 print("The search results are attached to this email message as an HTML\n");
6994 print("file. This file can be opened with Netscape or Internet Explorer.\n");
6995 }
6996
6997 print("--============_-1234567890==_============\n");
6998 $Value = "citations." . (($DeliveryFormat eq "text/html") ? "html" : "txt");
6999 print("Content-Type: $DeliveryFormat; name=\"$Value\"\n");
7000 print("Content-Disposition: attachment; filename=\"$Value\"\n\n");
7001 }
7002
7003
7004 # Get the current date
7005 $Value = &sGetPrintableDateFromTime();
7006
7007 # Set the HTML flag
7008 $HTML = ( $DeliveryFormat eq "text/html" ) ? 1 : 0;
7009
7010 # Write out the search result header
7011 ($Status, $QueryReport) = &bsDisplaySearchResults("Search Results for: $SearchName:", $SearchDescription, $Value, $SearchFrequency, $SearchResults, undef, $main::ConfigurationData{'script-url'}, 1, 1, $HTML, %main::FormData);
7012
7013
7014
7015 # Print out mime part separator and mime header for the message footer
7016 if ( $DeliveryMethod eq "attachement" ) {
7017 print("--============_-1234567890==_============\n");
7018 printf("Content-Type: %s; charset=\"us-ascii\"\n\n\n", ($DeliveryFormat eq "text/html") ? "text/html" : "text/plain");
7019 }
7020
7021
7022 # Print out the profile result footer
7023 if ( $DeliveryFormat eq "text/html" ) {
7024 print("<BR><HR>\n");
7025 print("Saved search by the <A HREF=\"$main::ConfigurationData{'script-url'}\">MPS Information Server </A><BR>\n");
7026 print("Created by <A HREF=\"http://www.fsconsult.com/\">FS Consulting, Inc.</A><BR>\n");
7027 print("<HR><BR>\n");
7028 print("</BODY>\n");
7029 }
7030 elsif ( ($DeliveryFormat eq "text/plain") || ($DeliveryFormat eq "text/medline-citation") ) {
7031 print("----------------------------------------------------------------------\n");
7032 print("Saved search by the MPS Information Server [URL: $main::ConfigurationData{'script-url'}].\n");
7033 print("Created by FS Consulting, Inc. [URL: http://www.fsconsult.com/].\n");
7034 print("----------------------------------------------------------------------\n");
7035
7036 }
7037
7038 # Print out mime part separator for the end of the message
7039 if ( $DeliveryMethod eq "attachement" ) {
7040 print("--============_-1234567890==_============--\n");
7041 }
7042
7043
7044 # Restore the saved file handle
7045 select $SavedFileHandle;
7046
7047 # Close the result file
7048 close(RESULT_FILE);
7049
7050 }
7051 else {
7052 print("Execution - saved search: '$SavedSearchFilePath' is currently inactive.\n");
7053 }
7054
7055 # Save the search object
7056 if ( ! &iSaveSearch($SavedSearchFilePath, $SearchName, $SearchDescription, $SearchAndRfDocumentURL, $SearchFrequency, $DeliveryFormat, $DeliveryMethod, $SearchStatus, $CreationTime, $NewLastRunTime) ) {
7057 print("Execution error - failed to save search object: '$SavedSearchFilePath'.\n");
7058 }
7059
7060 } # foreach ()
7061
7062 return;
7063
7064 }
7065
7066
7067
7068
7069 #--------------------------------------------------------------------------
7070 #
7071 # Function: vLog()
7072 #
7073 # Purpose: This a logging function which logs any passed printf()
7074 # formatted string to STDOUT and the log file if it is defined.
7075 #
7076 # If the log file cannot be opened for appending, nothing will
7077 # be written to it.
7078 #
7079 # Called by:
7080 #
7081 # Parameters: @_
7082 #
7083 # Global Variables: $main::LogFilePath
7084 #
7085 # Returns: void
7086 #
7087 sub vLog {
7088
7089 # Log to defined log file
7090 if ( defined($main::LogFilePath) && ($main::LogFilePath ne "") && open(LOG_FILE, ">>$main::LogFilePath") ) {
7091 print(LOG_FILE @_);
7092 close(LOG_FILE);
7093 }
7094
7095 return;
7096
7097 }
7098
7099
7100
7101
7102
7103
7104 #--------------------------------------------------------------------------
7105 #
7106 # Function: main()
7107 #
7108 # Purpose: main
7109 #
7110 # Called by:
7111 #
7112 # Parameters:
7113 #
7114 # Global Variables:
7115 #
7116 # Returns: void
7117 #
7118
7119 my ($Status);
7120 my (%Value, $Value);
7121
7122
7123
7124 # Roll over the log file (ignore the status)
7125 # &iRolloverLog($main::LogFilePath, $main::LogFileRollOver);
7126
7127
7128 # Verify that we are running the correct perl version, assume upward compatibility
7129 if ( $] < 5.004 ) {
7130 &vLog("Error - this script needs to be run with Perl version 5.004 or better.\n");
7131 &vSendHTMLFooter;
7132 exit (-1);
7133 }
7134
7135
7136 # Load up the configuration file
7137 ($Status, %main::ConfigurationData) = &bhReadConfigurationFile($main::ConfigurationFilePath);
7138 if ( ! $Status ) {
7139 &vSendHTMLFooter;
7140 exit (-1);
7141 }
7142
7143
7144
7145 # Set any defaults in the configuration
7146 if ( ! &bSetConfigurationDefaults(\%main::ConfigurationData, \%main::DefaultSettings) ) {
7147 &vSendHTMLFooter;
7148 exit (-1);
7149 }
7150
7151
7152 # Check for a minimal configuration
7153 if ( ! &bCheckMinimalConfiguration(\%main::ConfigurationData, \@main::RequiredSettings) ) {
7154 &vSendHTMLFooter;
7155 exit (-1);
7156 }
7157
7158
7159 # Check that the configuration paths specified is correct and can be accessed
7160 if ( ! &bCheckConfiguration ) {
7161 &vSendHTMLFooter;
7162 exit (-1);
7163 }
7164
7165
7166 # Get the database descriptions
7167 if ( ! &bGetDatabaseDescriptions ) {
7168 &vSendHTMLFooter;
7169 exit (-1);
7170 }
7171
7172
7173 # Set up the server
7174 if ( ! &bInitializeServer ) {
7175 &vSendHTMLFooter;
7176 exit (-1);
7177 }
7178
7179 # fill filed descriptions
7180 &fill_SearchFieldDescriptions_fromDB('ps');
7181
7182 # Are we running as a CGI-BIN script
7183 if ( $ENV{'GATEWAY_INTERFACE'} ) {
7184
7185
7186 # Check the CGI environment
7187 if ( ! &bCheckCGIEnvironment ) {
7188 &vSendHTMLFooter;
7189 exit (-1);
7190 }
7191
7192
7193 # Set and verify the environment (dont comment this out).
7194 if ( ! &bSetupCGIEnvironment ) {
7195 &vSendHTMLFooter;
7196 exit (-1);
7197 }
7198
7199
7200 if ( defined($main::FormData{'GetSearch.x'}) ) {
7201 $ENV{'PATH_INFO'} = "/GetSearch";
7202 delete($main::FormData{'GetSearch.x'});
7203 delete($main::FormData{'GetSearch.y'});
7204 }
7205
7206 if ( defined($main::FormData{'ListSearchHistory.x'}) ) {
7207 $ENV{'PATH_INFO'} = "/ListSearchHistory";
7208 delete($main::FormData{'ListSearchHistory.x'});
7209 delete($main::FormData{'ListSearchHistory.y'});
7210 }
7211
7212 if ( defined($main::FormData{'ListSavedSearch.x'}) ) {
7213 $ENV{'PATH_INFO'} = "/ListSavedSearch";
7214 delete($main::FormData{'ListSavedSearch.x'});
7215 delete($main::FormData{'ListSavedSearch.y'});
7216 }
7217
7218 if ( defined($main::FormData{'ListFolder.x'}) ) {
7219 $ENV{'PATH_INFO'} = "/ListFolder";
7220 delete($main::FormData{'ListFolder.x'});
7221 delete($main::FormData{'ListFolder.y'});
7222 }
7223
7224 if ( defined($main::FormData{'GetUserSettings.x'}) ) {
7225 $ENV{'PATH_INFO'} = "/GetUserSettings";
7226 delete($main::FormData{'GetUserSettings.x'});
7227 delete($main::FormData{'GetUserSettings.y'});
7228 }
7229
7230
7231
7232 # foreach $Value ( keys (%main::FormData) ) {
7233 # $Status = defined($main::FormData{$Value}) ? $main::FormData{$Value} : "(undefined)";
7234 # &vLog("[\$main::FormData{'$Value'} = '$Status']\n");
7235 # }
7236
7237 # Check for 'Action', set the PATH_INFO from it if it is set
7238 if ( defined($main::FormData{'Action'}) ) {
7239
7240 if ( ($Value = index($main::FormData{'Action'}, "&")) > 0 ) {
7241 %Value = &hParseURLIntoHashTable(&lDecodeURLData(substr($main::FormData{'Action'}, $Value)));
7242 $main::FormData{'Action'} = substr($main::FormData{'Action'}, 0, $Value);
7243 foreach $Value ( keys(%Value) ) {
7244 $main::FormData{$Value} = $Value{$Value};
7245 }
7246 }
7247
7248 $ENV{'PATH_INFO'} = "/" . $main::FormData{'Action'};
7249 delete($main::FormData{'Action'});
7250 }
7251
7252
7253 # Default to search if PATH_INFO is not defined
7254 if ( !defined($ENV{'PATH_INFO'}) || ($ENV{'PATH_INFO'} eq "") ) {
7255 $ENV{'PATH_INFO'} = "/GetSearch";
7256 }
7257
7258
7259 # Check what was requested and take action appropriately
7260 if ( ($ENV{'PATH_INFO'} eq "/GetSearch") || ($ENV{'PATH_INFO'} eq "/GetSimpleSearch") || ($ENV{'PATH_INFO'} eq "/GetExpandedSearch") ) {
7261 &vGetSearch;
7262 }
7263 elsif ( $ENV{'PATH_INFO'} eq "/GetSearchResults" ) {
7264 &vGetSearchResults;
7265 }
7266 elsif ( $ENV{'PATH_INFO'} eq "/GetDatabaseInfo" ) {
7267 &vGetDatabaseInfo;
7268 }
7269 elsif ( $ENV{'PATH_INFO'} eq "/GetDocument" ) {
7270 &vGetDocument;
7271 }
7272 elsif ( $ENV{'PATH_INFO'} eq "/GetSimilarDocument" ) {
7273 &vGetDocument;
7274 }
7275 elsif ( $ENV{'PATH_INFO'} eq "/GetUserSettings" ) {
7276 &vGetUserSettings;
7277 }
7278 elsif ( $ENV{'PATH_INFO'} eq "/SetUserSettings" ) {
7279 &vSetUserSettings;
7280 }
7281 elsif ( $ENV{'PATH_INFO'} eq "/ListSearchHistory" ) {
7282 &vListSearchHistory;
7283 }
7284 elsif ( $ENV{'PATH_INFO'} eq "/GetSearchHistory" ) {
7285 &vGetSearchHistory;
7286 }
7287 elsif ( $ENV{'PATH_INFO'} eq "/GetSaveSearch" ) {
7288 &vGetSaveSearch;
7289 }
7290 elsif ( $ENV{'PATH_INFO'} eq "/SetSaveSearch" ) {
7291 &vSetSaveSearch;
7292 }
7293 elsif ( $ENV{'PATH_INFO'} eq "/ListSavedSearch" ) {
7294 &vListSavedSearch;
7295 }
7296 elsif ( $ENV{'PATH_INFO'} eq "/GetSavedSearch" ) {
7297 &vGetSavedSearch;
7298 }
7299 elsif ( $ENV{'PATH_INFO'} eq "/DeleteSavedSearch" ) {
7300 &vProcessSavedSearch;
7301 }
7302 elsif ( $ENV{'PATH_INFO'} eq "/ActivateSavedSearch" ) {
7303 &vProcessSavedSearch;
7304 }
7305 elsif ( $ENV{'PATH_INFO'} eq "/SuspendSavedSearch" ) {
7306 &vProcessSavedSearch;
7307 }
7308 elsif ( $ENV{'PATH_INFO'} eq "/GetSaveFolder" ) {
7309 &vGetSaveFolder;
7310 }
7311 elsif ( $ENV{'PATH_INFO'} eq "/SetSaveFolder" ) {
7312 &vSetSaveFolder;
7313 }
7314 elsif ( $ENV{'PATH_INFO'} eq "/ListFolder" ) {
7315 &vListFolder;
7316 }
7317 elsif ( $ENV{'PATH_INFO'} eq "/SetMergeFolder" ) {
7318 &vMergeFolder;
7319 }
7320 elsif ( $ENV{'PATH_INFO'} eq "/GetMergeFolder" ) {
7321 &vMergeFolder;
7322 }
7323 elsif ( $ENV{'PATH_INFO'} eq "/DeleteFolder" ) {
7324 &vProcessFolder;
7325 }
7326 elsif ( $ENV{'PATH_INFO'} eq "/GetFolder" ) {
7327 &vGetFolder;
7328 }
7329 elsif ( $ENV{'PATH_INFO'} eq "/DeleteDocument" ) {
7330 &vProcessDocument;
7331 }
7332 else {
7333 $ENV{'PATH_INFO'} = "/GetSearch";
7334 &vGetSearch;
7335 }
7336
7337 }
7338 else {
7339
7340 my ($RunSearches, $Param, $Frequency, $Mday, $Wday);
7341
7342
7343 # We are running as a stand alone script
7344
7345
7346 #
7347 # Initialize the variables
7348 #
7349
7350 # Run Searches?
7351 # 0 - dont run searches
7352 # 1 - run searches
7353 $RunSearches = 1;
7354
7355
7356 # Init the frequency
7357 $Frequency = "";
7358
7359 # Check for command parameters
7360 foreach $Param ( @ARGV ) {
7361
7362 if ( $Param =~ /^-nos/i ) {
7363 # Dont run searches
7364 $RunSearches = 0;
7365 }
7366 elsif ( $Param =~ /^-s/i ) {
7367 # Run searches
7368 $RunSearches = 1;
7369 }
7370 elsif ( $Param =~ /^-d/i ) {
7371 # Want to run the daily
7372 $Frequency .= "|Daily|";
7373 }
7374 elsif ( $Param =~ /^-w/i ) {
7375 # Want to run the weekly
7376 $Frequency .= "|Weekly|";
7377 }
7378 elsif ( $Param =~ /^-m/i ) {
7379 # Want to run the monthly
7380 $Frequency .= "|Monthly|";
7381 }
7382 elsif ( $Param =~ /^-h/i ) {
7383 # help
7384 print("Usage: Search.cgi [-nosearch|-search] [-daily][-weekly][-monthly][-help]\n");
7385 print("\n");
7386 print(" [-nosearch|-search] whether to run or not run searches (default = -search).\n");
7387 print(" [-daily] run daily crawls/searches (overrides default).\n");
7388 print(" [-weekly] run weekly crawls/searches (overrides default).\n");
7389 print(" [-monthly] run monthly crawls/searches (overrides default).\n");
7390 print(" [-help] print the usage and exit.\n");
7391 exit (0);
7392 }
7393 else {
7394 # Invalid param
7395 print("\tError - invalid parameter: '$Param', run 'Search.cgi -help' to get parameter information.\n");
7396 exit (-2);
7397 }
7398 }
7399
7400
7401
7402 # Did we set a frequency usign a command line parameter?
7403 if ( $Frequency eq "" ) {
7404
7405 # We did not, so we set it based on the following rules
7406 #
7407 # monday-sunday run the daily
7408 # sunday run the weekly
7409 # 1st of the month run the monthly
7410 #
7411
7412 # Create an ANSI format date/time field
7413 (undef, undef, undef, $Mday, undef, undef, $Wday, undef, undef) = localtime();
7414
7415 # Always do the daily
7416 $Frequency = "|Daily|";
7417
7418 # Check for sunday, append the weekly
7419 if ( $Wday == 0 ) {
7420 $Frequency .= "|Weekly|";
7421 }
7422
7423 # Check for the 1st of the month, append the monthly
7424 if ( $Mday == 1 ) {
7425 $Frequency .= "|Monthly|";
7426 }
7427 }
7428
7429
7430 # Log stuff
7431 print("Execution - Frequency: $Frequency\n");
7432
7433
7434 # Run the searches
7435 if ( $RunSearches == 1 ) {
7436 &vRunSavedSearches($Frequency);
7437 }
7438 }
7439
7440
7441 # Shutdown the server
7442 &bShutdownServer;
7443
7444
7445 exit (0);
7446
7447
7448
7449 #--------------------------------------------------------------------------
7450
7451 # fill SearchFieldDescriptions from one database
7452
7453 # 2002-06-08 Dobrica Pavlinusic <dpavlin@rot13.org>
7454
7455 sub fill_SearchFieldDescriptions_fromDB {
7456
7457 my ($Database) = @_;
7458
7459 # Get the database field information
7460 my ($Status, $Text) = MPS::GetDatabaseFieldInfo($main::MPSSession, $Database);
7461
7462 if ( $Status ) {
7463 foreach my $FieldInformation ( split(/\n/, $Text) ) {
7464 my ($FieldName, $FieldDescription, undef) = split(/\t/, $FieldInformation, 3);
7465 $main::SearchFieldDescriptions{$FieldName} = $FieldDescription;
7466 }
7467 }
7468 }

  ViewVC Help
Powered by ViewVC 1.1.26