#!/usr/local/bin/perl
# exec.cgi
# Execute some SQL command and display output

require './postgresql-lib.pl';
&ReadParse();
&can_edit_db($in{'db'}) || &error($text{'dbase_ecannot'});
&error_setup($text{'exec_err'});
$d = &execute_sql_logged($in{'db'}, $in{'cmd'});

&header($text{'exec_title'}, "");
print "<hr>\n";
print "<p>",&text('exec_out', "<tt>$in{'cmd'}</tt>"),"<p>\n";
@data = @{$d->{'data'}};
if (@data) {
	print "<table border> <tr $tb>\n";
	foreach $t (@{$d->{'titles'}}) {
		print "<td><b>$t</b></td>\n";
		}
	print "</tr>\n";
	foreach $r (@data) {
		print "<tr $cb>\n";
		foreach $c (@$r) {
			print "<td>",$c ne '' ? &html_escape($c)
					      : "<br>","</td>\n";
			}
		print "</tr>\n";
		}
	print "</table><p>\n";
	}
else {
	print "<b>$text{'exec_none'}</b> <p>\n";
	}
&webmin_log("exec", undef, $in{'db'}, \%in);

print "<hr>\n";
&footer("edit_dbase.cgi?db=$in{'db'}", $text{'dbase_return'});

