#!/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
&ui_print_header($edit->{'edit'}, $text{'view_title'}, "");

$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 !~ /^\//) {
	# File is relative to user's home directory
	@uinfo = getpwnam($remote_user);
	$file = "$uinfo[7]/$file" if (@uinfo);
	}
if ($edit->{'envs'}) {
	# Do environment variable substitution
	chop($file = `echo "$file"`);
	}
open(FILE, $file);
while(<FILE>) { print &html_escape($_); }
close(FILE);
print "</textarea><br>\n";
print "<input type=submit value='$text{'save'}'></form>\n";

&ui_print_footer("", $text{'index_return'});

