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