/[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.25 - (show annotations)
Fri Sep 6 23:48:41 2002 UTC (21 years, 7 months ago) by dpavlin
Branch: MAIN
Changes since 1.24: +3 -3 lines
fix for perl 5.8

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

  ViewVC Help
Powered by ViewVC 1.1.26