/[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.20 - (show annotations)
Tue Jun 25 19:31:07 2002 UTC (21 years, 10 months ago) by dpavlin
Branch: MAIN
Changes since 1.19: +35 -33 lines
prijevod

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

  ViewVC Help
Powered by ViewVC 1.1.26