/[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.3 - (show annotations)
Sun Jun 16 18:11:16 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.2: +3 -31 lines
support for all LIBRI, separate configuraiton files, script for
test of config files

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

  ViewVC Help
Powered by ViewVC 1.1.26