use OpenCA::DBI;
if( (my $ret = $dbiconfig->loadCfg( "$DBICONFIG" )) == undef ) {
	print "Content-type: text/html\n\n";
	configError( i18nGettext ("Error while Loading Configuration (__FILE__)!", "__FILE__", $DBICONFIG));
}

if ( $DEBUG or getRequired ("DEBUG", $dbiconfig) ) {
	## if we do not set the Content-Type here then we will get an
	## Internal Server Error because the header is malformed
	print "Content-type: text/html\n\n";
	print "Debugging is activated!<br>\n";
}

## setup of the environment
my $db_type = getRequired ("DB_Type", $dbiconfig);
for ($i = 1;
     $i <= getRequired ('DB_ENV_'.$db_type.'_OPTIONS', $dbiconfig);
     $i++) {
  $ENV {getRequired ('DB_ENV_'.$db_type.'_OPTION_'.$i, $dbiconfig)} =
    getRequired ('DB_ENV_'.$db_type.'_VALUE_'.$i, $dbiconfig);
  print "NUMBER: $i<br>\n".
        "OPTION: getRequired ('DB_ENV_'.$db_type.'_OPTION_'.$i, $dbiconfig)<br>\n".
        "VALUE:  getRequired ('DB_ENV_'.$db_type.'_VALUE_'.$i, $dbiconfig)<br>\n" if ($DEBUG);
}

$db = new OpenCA::DBI (
	SHELL          	=> $cryptoShell,
	DEBUG          	=> getRequired ('DEBUG',		$dbiconfig),
	DB_Type     	=> getRequired ('DB_Type',		$dbiconfig),
	DB_Name     	=> getRequired ('DB_Name',		$dbiconfig),
	DB_Host     	=> getRequired ('DB_Host',		$dbiconfig),
	DB_Port     	=> getRequired ('DB_Port',		$dbiconfig),
	DB_User     	=> getRequired ('DB_User',		$dbiconfig),
	DB_Passwd   	=> getRequired ('DB_Passwd',		$dbiconfig),
);

if ( not $db ) {
	print "Content-type: text/html\n\n";
	configError( i18nGettext (
	                 "Cannot initialize OpenCA::DBI class! The database returns errorcode __ERRNO__. (__ERRVAL__)",
	                 "__ERRNO__", $OpenCA::DBI::errno,
	                 "__ERRVAL__", $OpenCA::DBI::errval
	                         ) );
}

$versions->{DB}	= OpenCA::DBI->VERSION;

1;
