
require 'mysql-lib.pl';

# acl_security_form(&options)
# Output HTML for editing security options for the mysql module
sub acl_security_form
{
print "<tr> <td valign=top rowspan=3><b>$text{'acl_dbs'}</b></td>\n";
print "<td rowspan=3 valign=top>\n";
printf "<input type=radio name=dbs_def value=1 %s> %s\n",
	$_[0]->{'dbs'} eq '*' ? 'checked' : '', $text{'acl_dall'};
printf "<input type=radio name=dbs_def value=0 %s> %s<br>\n",
	$_[0]->{'dbs'} eq '*' ? '' : 'checked', $text{'acl_dsel'};
print "<select name=dbs size=3 multiple width=100>\n";
map { $dcan{$_}++ } split(/\s+/, $_[0]->{'dbs'});
foreach $d (&list_databases()) {
	printf "<option %s>%s\n",
		$dcan{$d} ? 'selected' : '', $d;
	}
print "</select></td>\n";

print "<td><b>$text{'acl_create'}</b></td> <td>\n";
printf "<input type=radio name=create value=1 %s> %s\n",
	$_[0]->{'create'} ? 'checked' : '', $text{'yes'};
printf "<input type=radio name=create value=0 %s> %s</td> </tr>\n",
	$_[0]->{'create'} ? '' : 'checked', $text{'no'};

print "<tr> <td><b>$text{'acl_delete'}</b></td> <td>\n";
printf "<input type=radio name=delete value=1 %s> %s\n",
	$_[0]->{'delete'} ? 'checked' : '', $text{'yes'};
printf "<input type=radio name=delete value=0 %s> %s</td> </tr>\n",
	$_[0]->{'delete'} ? '' : 'checked', $text{'no'};

print "<tr> <td><b>$text{'acl_stop'}</b></td> <td>\n";
printf "<input type=radio name=stop value=1 %s> %s\n",
	$_[0]->{'stop'} ? 'checked' : '', $text{'yes'};
printf "<input type=radio name=stop value=0 %s> %s</td> </tr>\n",
	$_[0]->{'stop'} ? '' : 'checked', $text{'no'};

print "<tr> <td><b>$text{'acl_perms'}</b></td>\n";
print "<td><select name=perms>\n";
printf "<option value=1 %s> %s\n",
	$_[0]->{'perms'} == 1 ? 'selected' : '', $text{'yes'};
printf "<option value=2 %s> %s\n",
	$_[0]->{'perms'} == 2 ? 'selected' : '', $text{'acl_only'};
printf "<option value=0 %s> %s\n",
	$_[0]->{'perms'} == 0 ? 'selected' : '', $text{'no'};
print "</select></td>\n";

print "<td><b>$text{'acl_edonly'}</b></td>\n";
printf "<td><input type=radio name=edonly value=1 %s> %s\n",
	$_[0]->{'edonly'} ? 'checked' : '', $text{'yes'};
printf "<input type=radio name=edonly value=0 %s> %s</td> </tr>\n",
	$_[0]->{'edonly'} ? '' : 'checked', $text{'no'};

print "<tr> <td valign=top><b>$text{'acl_login'}</b></td> <td colspan=3>\n";
printf "<input type=radio name=user_def value=1 %s> %s<br>\n",
	$_[0]->{'user'} ? '' : 'checked', $text{'acl_user_def'};
printf "<input type=radio name=user_def value=0 %s>\n",
	$_[0]->{'user'} ? 'checked' : '';
printf "%s <input name=user size=10 value='%s'>\n",
	$text{'acl_user'}, $_[0]->{'user'};
printf "%s <input name=pass size=10 value='%s'></td> </tr>\n",
	$text{'acl_pass'}, $_[0]->{'pass'};

print "<tr> <td><b>$text{'acl_bpath'}</b></td>\n";
printf "<td><input name=bpath size=20 value='%s'> %s</td>\n",
	$_[0]->{'bpath'}, &file_chooser_button("bpath", 1);

print "<td><b>$text{'acl_buser'}</b></td>\n";
printf "<td><input name=buser size=8 value='%s'> %s</td> </tr>\n",
	$_[0]->{'buser'}, &user_chooser_button("buser");
}

# acl_security_save(&options)
# Parse the form for security options for the mysql module
sub acl_security_save
{
if ($in{'dbs_def'}) {
	$_[0]->{'dbs'} = '*';
	}
else {
	$_[0]->{'dbs'} = join(" ", split(/\0/, $in{'dbs'}));
	}
$_[0]->{'create'} = $in{'create'};
$_[0]->{'delete'} = $in{'delete'};
$_[0]->{'bpath'} = $in{'bpath'};
$_[0]->{'buser'} = $in{'buser'};
$_[0]->{'stop'} = $in{'stop'};
$_[0]->{'perms'} = $in{'perms'};
$_[0]->{'edonly'} = $in{'edonly'};
if ($in{'user_def'}) {
	delete($_[0]->{'user'});
	delete($_[0]->{'pass'});
	}
else {
	$_[0]->{'user'} = $in{'user'};
	$_[0]->{'pass'} = $in{'pass'};
	}
}

