Link by ids rather than indexes
authorJamie Cameron <jcameron@webmin.com>
Wed, 23 Apr 2008 17:41:36 +0000 (17:41 +0000)
committerJamie Cameron <jcameron@webmin.com>
Wed, 23 Apr 2008 17:41:36 +0000 (17:41 +0000)
15 files changed:
custom/CHANGELOG
custom/custom-lib.pl
custom/edit_cmd.cgi
custom/edit_file.cgi
custom/edit_sql.cgi
custom/form.cgi
custom/index.cgi
custom/run.cgi
custom/save.cgi
custom/save_cmd.cgi
custom/save_file.cgi
custom/save_sql.cgi
custom/sql.cgi
custom/sqlform.cgi
custom/view.cgi

index bb3f9db..f1664a3 100644 (file)
@@ -20,3 +20,5 @@ Re-designed the user interface somewhat, and converted all code to use the new W
 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.
index a2be39d..e9b768a 100644 (file)
@@ -101,6 +101,22 @@ closedir(DIR);
 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
 {
index 1ea86b3..a762808 100755 (executable)
@@ -11,14 +11,13 @@ if ($in{'new'}) {
        }
 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
index 4871e3b..b0d2b52 100755 (executable)
@@ -11,13 +11,12 @@ if ($in{'new'}) {
        }
 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'}) {
index e7853f9..265c09f 100755 (executable)
@@ -26,13 +26,12 @@ 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
index 38be4c6..d985550 100755 (executable)
@@ -4,8 +4,7 @@
 
 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
@@ -29,7 +28,7 @@ elsif (@a) {
 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'});
index 408ba90..6955f4c 100755 (executable)
@@ -52,7 +52,7 @@ elsif ($config{'display_mode'} == 0) {
                                $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%" ]
@@ -72,13 +72,13 @@ elsif ($config{'display_mode'} == 0) {
                        }
                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);
@@ -107,42 +107,42 @@ else {
                        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'});
index fd916d9..7308455 100755 (executable)
@@ -13,8 +13,7 @@ else {
        }
 $| = 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'};
index e8c6e66..ae7fe94 100755 (executable)
@@ -4,8 +4,7 @@
 
 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'});
 
index 8b2aad1..3bdf38b 100755 (executable)
@@ -6,16 +6,15 @@ require './custom-lib.pl';
 &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() };
index 775cfda..c282ad0 100755 (executable)
@@ -6,16 +6,15 @@ require './custom-lib.pl';
 &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() };
index 77af3ec..5888762 100755 (executable)
@@ -5,16 +5,15 @@ require './custom-lib.pl';
 &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() };
index 4086943..fc07a66 100755 (executable)
@@ -9,8 +9,7 @@ else {
        &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
index 6daeede..4999f52 100755 (executable)
@@ -4,8 +4,7 @@
 
 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
@@ -21,7 +20,7 @@ elsif (@a) {
 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);
index 5946387..b7330a5 100755 (executable)
@@ -4,8 +4,7 @@
 
 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