#!/usr/local/bin/perl
# edit_text.cgi
# Display a form for manually editing a records file

require './bind8-lib.pl';
&ReadParse();
$conf = &get_config();
if ($in{'view'} ne '') {
	$conf = $conf->[$in{'view'}]->{'members'};
	}
$zconf = $conf->[$in{'index'}]->{'members'};
$file = &absolute_path(&find("file", $zconf)->{'value'});
%access = &get_module_acl();
&can_edit_zone(\%access, $conf->[$in{'index'}]) ||
	&error($text{'master_ecannot'});
$access{'file'} || &error($text{'text_ecannot'});
&header($text{'text_title'}, "");
print "<center><font size=+1>$file</font></center>\n";
print "<hr>\n";

open(FILE, $config{'chroot'}.$file);
while(<FILE>) {
	push(@lines, &html_escape($_));
	}
close(FILE);

if (!$access{'ro'}) {
	print &text('text_desc', "<tt>$in{'file'}</tt>"),"<p>\n";
	}

print "<form action=save_text.cgi method=post enctype=multipart/form-data>\n";
print "<input type=hidden name=index value=\"$in{'index'}\">\n";
print "<input type=hidden name=view value=\"$in{'view'}\">\n";
print "<textarea name=text rows=20 cols=80>",
	join("", @lines),"</textarea><p>\n";
print "<input type=submit value=\"$text{'save'}\"> ",
      "<input type=reset value=\"$text{'text_undo'}\">\n"
	if (!$access{'ro'});
print "</form>\n";

print "<hr>\n";
&footer("edit_master.cgi?index=$in{'index'}&view=$in{'view'}",
	$text{'master_return'});

