#!/usr/local/bin/perl
# newdb.cgi
# Create a new database with one optional table

require './postgresql-lib.pl';
&ReadParse();
$access{'create'} || &error($text{'newdb_ecannot'});
&error_setup($text{'newdb_err'});

$in{'db'} =~ /^[A-z0-9\.\-]+$/ || &error($text{'newdb_edb'});
if ($in{'path_def'}) {
	&execute_sql_logged($config{'basedb'}, "create database $in{'db'}");
	}
else {
	$in{'path'} || &error($text{'newdb_epath'});
	&execute_sql_logged($config{'basedb'}, "create database $in{'db'} ".
					       "with location = '$in{'path'}'");
	}
&webmin_log("create", "db", $in{'db'});
if ($access{'dbs'} ne '*') {
	$access{'dbs'} .= " $in{'db'}";
	&save_module_acl(\%access);
	}
&redirect("");

