When commands are shown in a table and no parameters are needed, the names now link directly to run the command.
---- Changes since 1.400 ----
Added a popup progress tracker to commands with file upload fields.
+---- Changes since 1.410 ----
+All links to commands are via an ID number rather than an index, which makes them easier to link to from other web pages.
return @rv;
}
+# get_command(id)
+# Returns the command with some ID
+sub get_command
+{
+local ($id, $idx) = @_;
+local @cmds = &list_commands();
+local $cmd;
+if ($id) {
+ ($cmd) = grep { $_->{'id'} eq $id } &list_commands();
+ }
+else {
+ $cmd = $cmds[$idx];
+ }
+return $cmd;
+}
+
# save_command(&command)
sub save_command
{
}
else {
&ui_print_header(undef, $text{'edit_title'}, "", "edit");
- @cmds = &list_commands();
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
}
# Form header
print &ui_form_start("save_cmd.cgi", "post");
print &ui_hidden("new", $in{'new'});
-print &ui_hidden("idx", $in{'idx'});
+print &ui_hidden("id", $cmd->{'id'});
print &ui_table_start($text{'edit_details'}, "width=100%", 4);
# Command ID
}
else {
&ui_print_header(undef, $text{'fedit_title'}, "", "fedit");
- @cmds = &list_commands();
- $edit = $cmds[$in{'idx'}];
+ $edit = &get_command($in{'id'}, $in{'idx'});
}
print &ui_form_start("save_file.cgi", "post");
print &ui_hidden("new", $in{'new'});
-print &ui_hidden("idx", $in{'idx'});
+print &ui_hidden("id", $edit->{'id'});
print &ui_table_start($text{'file_details'}, "width=100%", 2);
if (!$in{'new'}) {
}
else {
&ui_print_header(undef, $text{'sql_title2'}, "");
- @cmds = &list_commands();
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
}
print &ui_form_start("save_sql.cgi", "post");
print &ui_hidden("new", $in{'new'}),"\n";
-print &ui_hidden("idx", $in{'idx'}),"\n";
+print &ui_hidden("id", $cmd->{'id'}),"\n";
print &ui_table_start($text{'sql_header'}, "width=100%", 2);
# Show command info
require './custom-lib.pl';
&ReadParse();
-@cmds = &list_commands();
-$cmd = $cmds[$in{'idx'}];
+$cmd = &get_command($in{'id'}, $in{'idx'});
&can_run_command($cmd) || &error($text{'form_ecannot'});
# Display form for command parameters
else {
print &ui_form_start("run.cgi");
}
-print &ui_hidden("idx", $in{'idx'});
+print &ui_hidden("id", $cmd->{'id'});
print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4,
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
print &ui_table_row(undef, $cmd->{'html'}, 4) if ($cmd->{'html'});
$html .= &ui_form_start("run.cgi");
}
}
- $html .= &ui_hidden("idx", $c->{'index'});
+ $html .= &ui_hidden("id", $c->{'id'});
$w = $config{'columns'} == 2 ? 2 : 4;
$html .= &ui_table_start(undef, undef, $w,
$config{'columns'} == 1 ? [ "width=20%", "width=30%" ]
}
if ($access{'edit'}) {
if ($c->{'edit'}) {
- $link = "<a href='edit_file.cgi?idx=$c->{'index'}'>$text{'index_fedit'}</a>";
+ $link = "<a href='edit_file.cgi?id=$c->{'id'}'>$text{'index_fedit'}</a>";
}
elsif ($c->{'sql'}) {
- $link = "<a href='edit_sql.cgi?idx=$c->{'index'}'>$text{'index_sedit'}</a>";
+ $link = "<a href='edit_sql.cgi?id=$c->{'id'}'>$text{'index_sedit'}</a>";
}
else {
- $link = "<a href='edit_cmd.cgi?idx=$c->{'index'}'>$text{'index_edit'}</a>";
+ $link = "<a href='edit_cmd.cgi?id=$c->{'id'}'>$text{'index_edit'}</a>";
}
$html .= &ui_table_row(undef,
&ui_links_row([ $link ]), $w);
local $e = $c->{'edit'} ? "edit_file.cgi" :
$c->{'sql'} ? "edit_sql.cgi" :
"edit_cmd.cgi";
- push(@links, "<a href='$e?idx=$c->{'index'}'>".
+ push(@links, "<a href='$e?id=$c->{'id'}'>".
"$text{'index_ed'}</a>");
}
if ($c->{'edit'} && !@{$c->{'args'}}) {
# Open file editor directly, as file is known
- push(@cols, "<a href='view.cgi?idx=$c->{'index'}'>".
+ push(@cols, "<a href='view.cgi?id=$c->{'id'}'>".
&html_escape($c->{'desc'})."</a>");
- push(@links, "<a href='view.cgi?idx=$c->{'index'}'>".
+ push(@links, "<a href='view.cgi?id=$c->{'id'}'>".
$text{'index_acted'}."</a>");
}
elsif ($c->{'sql'} && !@{$c->{'args'}}) {
# Execute SQL directorly, as no args
- push(@cols, "<a href='sql.cgi?idx=$c->{'index'}'>".
+ push(@cols, "<a href='sql.cgi?id=$c->{'id'}'>".
&html_escape($c->{'desc'})."</a>");
- push(@links, "<a href='sql.cgi?idx=$c->{'index'}'>".
+ push(@links, "<a href='sql.cgi?id=$c->{'id'}'>".
$text{'index_actrun'}."</a>");
}
elsif ($c->{'sql'}) {
# Link to SQL query form
- push(@cols, "<a href='sqlform.cgi?idx=$c->{'index'}'>".
+ push(@cols, "<a href='sqlform.cgi?id=$c->{'id'}'>".
&html_escape($c->{'desc'})."</a>");
- push(@links, "<a href='sqlform.cgi?idx=$c->{'index'}'>".
+ push(@links, "<a href='sqlform.cgi?id=$c->{'id'}'>".
$text{'index_actsql'}."</a>");
}
elsif (!@{$c->{'args'}}) {
# Link direct to execute page
- push(@cols, "<a href='run.cgi?idx=$c->{'index'}'>".
+ push(@cols, "<a href='run.cgi?id=$c->{'id'}'>".
&html_escape($c->{'desc'})."</a>");
- push(@links, "<a href='run.cgi?idx=$c->{'index'}'>".
+ push(@links, "<a href='run.cgi?id=$c->{'id'}'>".
$text{'index_actrun'}."</a>");
}
else {
# Link to parameters form
- push(@cols, "<a href='form.cgi?idx=$c->{'index'}'>".
+ push(@cols, "<a href='form.cgi?id=$c->{'id'}'>".
&html_escape($c->{'desc'})."</a>");
- push(@links, "<a href='form.cgi?idx=$c->{'index'}'>".
+ push(@links, "<a href='form.cgi?id=$c->{'id'}'>".
$text{'index_actform'}."</a>");
}
push(@cols, $c->{'html'});
}
$| = 1;
&error_setup($text{'run_err'});
-@cmds = &list_commands();
-$cmd = $cmds[$in{'idx'}];
+$cmd = &get_command($in{'id'}, $in{'idx'});
&can_run_command($cmd) || &error($text{'run_ecannot'});
if (&supports_users()) {
$user = $cmd->{'user'} eq '*' ? $remote_user : $cmd->{'user'};
require './custom-lib.pl';
&ReadParseMime();
-@cmds = &list_commands();
-$edit = $cmds[$in{'idx'}];
+$edit = &get_command($in{'id'}, $in{'idx'});
&error_setup($text{'view_err'});
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
&ReadParse();
$access{'edit'} || &error($text{'save_ecannot'});
-@cmds = &list_commands();
if ($in{'delete'}) {
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
&delete_command($cmd);
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
}
else {
&error_setup($text{'save_err'});
if (!$in{'new'}) {
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
}
else {
$cmd = { 'id' => time() };
&ReadParse();
$access{'edit'} || &error($text{'file_ecannot'});
-@cmds = &list_commands();
if ($in{'delete'}) {
- $edit = $cmds[$in{'idx'}];
+ $edit = &get_command($in{'id'}, $in{'idx'});
&delete_command($edit);
&webmin_log("delete", "edit", $edit->{'id'}, $edit);
}
else {
&error_setup($text{'file_err'});
if (!$in{'new'}) {
- $edit = $cmds[$in{'idx'}];
+ $edit = &get_command($in{'id'}, $in{'idx'});
}
else {
$edit = { 'id' => time() };
&ReadParse();
$access{'edit'} || &error($text{'save_ecannot'});
-@cmds = &list_commands();
if ($in{'delete'}) {
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
&delete_command($cmd);
&webmin_log("delete", "command", $cmd->{'id'}, $cmd);
}
else {
&error_setup($text{'sql_err'});
if (!$in{'new'}) {
- $cmd = $cmds[$in{'idx'}];
+ $cmd = &get_command($in{'id'}, $in{'idx'});
}
else {
$cmd = { 'id' => time() };
&ReadParse();
}
&error_setup($text{'srun_err'});
-@cmds = &list_commands();
-$cmd = $cmds[$in{'idx'}];
+$cmd = &get_command($in{'id'}, $in{'idx'});
&can_run_command($cmd) || &error($text{'run_ecannot'});
# Connect to the DB
require './custom-lib.pl';
&ReadParse();
-@cmds = &list_commands();
-$cmd = $cmds[$in{'idx'}];
+$cmd = &get_command($in{'id'}, $in{'idx'});
&can_run_command($cmd) || &error($text{'form_ecannot'});
# Display form for command parameters
else {
print &ui_form_start("sql.cgi");
}
-print &ui_hidden("idx", $in{'idx'});
+print &ui_hidden("id", $cmd->{'id'});
print &ui_table_start(&html_escape($cmd->{'desc'}), "width=100%", 4,
[ "width=20%", "width=30%", "width=20%", "width=30%" ]);
print &ui_table_row(undef, $cmd->{'html'}, 4);
require './custom-lib.pl';
&ReadParse();
-@cmds = &list_commands();
-$edit = $cmds[$in{'idx'}];
+$edit = &get_command($in{'id'}, $in{'idx'});
$edit->{'edit'} && &can_run_command($edit) || &error($text{'edit_ecannot'});
# Work out proper filename