/[webpac-proto]/search/Search.cgi
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /search/Search.cgi

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.27 - (show annotations)
Thu Oct 24 18:42:18 2002 UTC (21 years, 5 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.26: +2 -3 lines
output of types are configurable

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

  ViewVC Help
Powered by ViewVC 1.1.26