#!/usr/local/bin/perl
# view.cgi
# Display a file for editing

require './custom-lib.pl';
&ReadParse();
@cmds = &list_commands();
$edit = $cmds[$in{'idx'}];
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});

# Show the editor window
&header($text{'view_title'}, "");
print "<center><font size=+1>",$edit->{'edit'},"</font></center>\n";
print "<hr>\n";

$w = $config{'width'} || 80;
$h = $config{'height'} || 20;
$wrap = $config{'wrap'} ? "wrap=$config{'wrap'}" : "";
print "<form action=save.cgi method=post enctype=multipart/form-data>\n";
print "<input type=hidden name=idx value='$in{'idx'}'>\n";
print "<textarea rows=$h cols=$w $wrap name=data>";
$file = $edit->{'edit'};
if ($file !~ /^\//) {
	@uinfo = getpwnam($remote_user);
	$file = "$uinfo[7]/$file" if (@uinfo);
	}
open(FILE, $file);
while(<FILE>) { print &html_escape($_); }
close(FILE);
print "</textarea><br>\n";
print "<input type=submit value='$text{'save'}'></form>\n";

print "<hr>\n";
&footer("", $text{'index_return'});

