/[local]/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.22 - (show annotations)
Tue Jul 2 17:18:43 2002 UTC (21 years, 9 months ago) by dpavlin
Branch: MAIN
Changes since 1.21: +44 -40 lines
prijevod, fix accent chars u Any polju

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

  ViewVC Help
Powered by ViewVC 1.1.26