#  This software was derived from SATAN 1.1.1 by Dan Farmer and Wietse Venema
#  (http://www.porcupine.org/satan).
#
#
# Open a data base and keep the user informed.
#
($_directory) = split(/,/, $html_script_args);

#
# Make sure they specified a directory at all.
#
$_directory = $_sara_dir if $_directory eq "";

if ($_directory eq "") {
	print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>Error - Missing input </TITLE>
<LINK REV="made" HREF="mailto:sara\@fish.com">
</HEAD>
<BODY>
<H1><IMG WIDTH="150" SRC=$HTML_ROOT/images/sara.gif> Error - Missing input </H1>
<hr>
No data base name was specified.
</BODY>
</HTML>
EOF
	die "\n";
}
 if ($_directory =~ /^[0-9]/) {
       print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>Error - Illegal Data Base Name </TITLE>
<LINK REV="made" HREF="mailto:satan\@fish.com">
<LINK REV="update" HREF="mailto:sara\@arc.com">
</HEAD>
<BODY>
<H1><IMG WIDTH="150" SRC=$HTML_ROOT/images/sara.gif> Error - Illegal Data Base Name </H1>
<hr>
Data base name must start with an alpha character [a-zA-Z]
</BODY>
</HTML>
EOF
        die "\n";
}
#
# Create data base when it does not exist
#
$sara_data = $_directory;
&find_sara_data();

#
# Read the data base, after resetting the in-core data structures.
#
print CLIENT <<EOF;
<HTML>
<HEAD>
<TITLE>SARA Data Management</TITLE>
<LINK REV="made" HREF="mailto:sara\@fish.com">
</HEAD>
<BODY>
<H1><IMG WIDTH="150" SRC=$HTML_ROOT/images/sara.gif> SARA Data Management</H1>
<HR>
EOF

if (-s "$facts_file") {
	print CLIENT <<EOF;
<strong>merging data from <i> $_directory. </i> This may take some time. <p>
EOF
}

&merge_sara_data();

print CLIENT <<EOF;
<strong>Data base selection completed successfully.</strong>
<hr> <a href=/sara.html> Back to the SARA start page </a>
| <a href=../reporting/analysis.pl>Continue with report and analysis</a>
</BODY>
</HTML>
EOF
