Added backup mkdir option, converted form to ui-lib.pl
authorJamie Cameron <jcameron@webmin.com>
Sat, 29 Sep 2007 22:35:04 +0000 (22:35 +0000)
committerJamie Cameron <jcameron@webmin.com>
Sat, 29 Sep 2007 22:35:04 +0000 (22:35 +0000)
postgresql/CHANGELOG
postgresql/backup.cgi
postgresql/backup_form.cgi
postgresql/lang/en

index 04ed961..6eb7f8e 100644 (file)
@@ -56,3 +56,6 @@ When there are too many databases or tables to display, a menu for editing a spe
 Use HTML format output from the pgsql command, to handle queries for rows containing newlines and special characters.
 ---- Changes since 1.350 ----
 Fixed a bug that prevented the 'valid until' date from being displayed for existing users.
+---- Changes since 1.370 ----
+Added an option on the backup form to create the destination directory if missing.
+Re-wrote the backup form to use the new Webmin UI library.
index cecc149..24687ca 100755 (executable)
@@ -20,7 +20,7 @@ else {
 $access{'backup'} || &error($text{'backup_ecannot'});
 if (!$in{'save'} || $in{'sched'}) {
        if ($in{'all'}) {
-               -d $in{'path'} || -d &date_subs($in{'path'}) ||
+               -d $in{'path'} || -d &date_subs($in{'path'}) || $in{'mkdir'} ||
                        &error(&text('backup_pe4', $in{'path'})) ;
                }
        else {
@@ -77,6 +77,7 @@ if ($module_info{'usermin'}) {
        }
 else {
        $config{'backup_'.$in{'db'}} = $in{'path'};
+       $config{'backup_mkdir_'.$in{'db'}} = $in{'mkdir'};
        $config{'backup_format_'.$in{'db'}} = $in{'format'};
        $config{'backup_tables_'.$in{'db'}} = join(" ", @tables);
        &write_file("$module_config_directory/config", \%config);
@@ -103,7 +104,9 @@ if (!$in{'save'}) {
                        next;
                        }
                if ($in{'all'}) {
-                       $path = &date_subs("$in{'path'}/$db.$suf");
+                       $dir = &date_subs($in{'path'});
+                       &make_dir($dir, 0755) if ($in{'mkdir'});
+                       $path = $dir."/".$db.".".$suf;
                        }
                else {
                        $path = &date_subs($in{'path'});
index 106c4f4..4ac0bea 100755 (executable)
@@ -36,116 +36,115 @@ if ($cron) {
 print "<p>\n";
 %c = $module_info{'usermin'} ? %userconfig : %config;
 
-print "<form action=backup.cgi method=post>\n" ;
-print "<input type=hidden name=db value=\"$in{'db'}\">\n" ;
-print "<input type=hidden name=all value=\"$in{'all'}\">\n" ;
-print "<table border>\n" ;
-print "<tr $tb> <td><b>$text{'backup_header'}</b></td> </tr>\n" ;
-print "<tr $cb> <td><table>\n" ;
+print &ui_form_start("backup.cgi", "post");
+print &ui_hidden("db", $in{'db'});
+print &ui_hidden("all", $in{'all'});
+print &ui_hidden_table_start($text{'backup_header1'}, undef, 2, "main", 1,
+                            [ "width=30%" ]);
 
+# Destination file or directory
 $p = $c{'backup_'.$in{'db'}} || "$config{'repository'}/";
+print &ui_table_row($in{'all'} ? $text{'backup_path2'}
+                              : $text{'backup_path'},
+       &ui_textbox("path", $p, 60)." ".
+       &file_chooser_button("path"));
+
+# Create destination dir
 if ($in{'all'}) {
-       print "<tr> <td><b>$text{'backup_path2'}</b></td>\n" ;
-       }
-else {
-       print "<tr> <td><b>$text{'backup_path'}</b></td>\n" ;
+       print &ui_table_row($text{'backup_mkdir'},
+               &ui_yesno_radio("mkdir", int($c{'backup_mkdir_'.$in{'db'}})));
        }
-print "<td><input type=text name=path value='$p' size=64>",
-      &file_chooser_button("path"),"</td></tr>\n" ;
 
 # Show backup format input
 $f = $c{'backup_format_'.$in{'db'}};
-print "<tr> <td><b>$text{'backup_format'}</b></td>\n";
-print "<td><select name=format>\n";
-foreach $t ('p', 't', 'c') {
-       printf "<option value=%s %s>%s\n",
-               $t, $f eq $t ? "selected" : "", $text{'backup_format_'.$t};
-       }
-print "</select></td> </tr>\n";
+print &ui_table_row($text{'backup_format'},
+       &ui_select("format", $f,
+               [ [ 'p', $text{'backup_format_p'} ],
+                 [ 't', $text{'backup_format_t'} ],
+                 [ 'c', $text{'backup_format_c'} ] ]));
 
 if (!$in{'all'}) {
        # Show input to select tables
        $t = $c{'backup_tables_'.$in{'db'}};
-       print "<tr> <td valign=top><b>$text{'backup_tables'}</b></td> <td>\n";
-       printf "<input type=radio name=tables_def value=1 %s> %s\n",
-               $t ? "" : "checked", $text{'backup_alltables'};
-       printf "<input type=radio name=tables_def value=0 %s> %s\n",
-               $t ? "checked" : "", $text{'backup_seltables'};
        @tables = &list_tables($in{'db'});
-       %got = map { $_, 1 } split(/\s+/, $t);
-       print "<select name=tables>\n";
-       foreach $t (sort @tables) {
-               printf "<option %s>%s\n",
-                       $got{$t} ? "selected" : "", $t;
-               }
-       print "</select></td> </tr>\n";
+       print &ui_table_row($text{'backup_tables'},
+               &ui_radio("tables_def", $t ? 0 : 1,
+                         [ [ 1, $text{'backup_alltables'} ],
+                           [ 0, $text{'backup_seltables'} ] ])."<br>".
+               &ui_select("tables", [ split(/\s+/, $t) ],
+                          [ sort @tables ], 5, 1));
        }
 
+print &ui_hidden_table_end("main");
+
 if ($cron) {
        if ($access{'cmds'}) {
+               print &ui_hidden_table_start($text{'backup_header2'}, undef, 2,
+                                            "opts", 0, [ "width=30%" ]);
+
                $b = $c{'backup_before_'.$in{'db'}};
-               print "<tr> <td><b>$text{'backup_before'}</b></td>\n";
-               print "<td>",&ui_textbox("before", $b, 50),"</td> </tr>\n";
+               print &ui_table_row($text{'backup_before'},
+                       &ui_textbox("before", $b, 50));
 
                $a = $c{'backup_after_'.$in{'db'}};
-               print "<tr> <td><b>$text{'backup_after'}</b></td>\n";
-               print "<td>",&ui_textbox("after", $a, 50),"</td> </tr>\n";
+               print &ui_table_row($text{'backup_after'},
+                       &ui_textbox("after", $a, 50));
 
                if ($in{'all'}) {
                        # Command mode option
                        $cmode = $c{'backup_cmode_'.$in{'db'}};
-                       print "<tr> <td><b>$text{'backup_cmode'}</b></td>\n";
-                       print "<td>",&ui_radio("cmode", int($cmode),
-                               [ [ 0, $text{'backup_cmode0'} ],
-                                 [ 1, $text{'backup_cmode1'} ] ]),
-                             "</td> </tr>\n";
+                       print &ui_table_row($text{'backup_cmode'},
+                               &ui_radio("cmode", int($cmode),
+                                       [ [ 0, $text{'backup_cmode0'} ],
+                                         [ 1, $text{'backup_cmode1'} ] ]));
                        }
+
+               print &ui_hidden_table_end("opts");
                 }
 
+       print &ui_hidden_table_start($text{'backup_header3'}, undef, 2, "sched",
+                                    1, [ "width=30%" ]);
+
        &foreign_require("cron", "cron-lib.pl");
        @jobs = &cron::list_cron_jobs();
        $cmd = $in{'all'} ? "$cron_cmd --all" : "$cron_cmd $in{'db'}";
        ($job) = grep { $_->{'command'} eq $cmd } @jobs;
 
-       print "<tr> <td><b>$text{'backup_sched'}</b></td>\n";
-       printf "<td><input type=radio name=sched value=0 %s> %s\n",
-               $job ? "" : "checked", $text{'no'};
-       printf "<input type=radio name=sched value=1 %s> %s</td> </tr>\n",
-               $job ? "checked" : "", $text{'backup_sched1'};
+       print &ui_table_row($text{'backup_sched'},
+               &ui_radio("sched", $job ? 1 : 0,
+                 [ [ 0, $text{'no'} ], [ 1, $text{'backup_sched1'} ] ]));
 
        if (!$config{'simple_sched'} || ($dump && !$dump->{'special'})) {
                # Complex Cron time input
-               print "<tr> <td colspan=2><table border width=100%>\n";
                $job ||= { 'mins' => 0,
                           'hours' => 0,
                           'days' => '*',
                           'months' => '*',
                           'weekdays' => '*' };
-               &cron::show_times_input($job);
-               print "</table></td> </tr>\n";
+               print &ui_table_row(undef,
+                       "<table border=2 width=100%>".
+                       &capture_function_output(\&cron::show_times_input,$job).
+                       "</table>", 2);
                }
        else {
                # Simple Cron time input
                $job ||= { 'special' => 'daily' };
                print &ui_hidden("special_def", 1),"\n";
-               print "<tr> <td><b>$text{'backup_special'}</b></td>\n";
-               print "<td>",&ui_select("special", $job->{'special'},
+               print &ui_table_row($text{'backup_special'},
+                   &ui_select("special", $job->{'special'},
                        [ map { [ $_, $cron::text{'edit_special_'.$_} ] }
-                         ('hourly', 'daily', 'weekly', 'monthly', 'yearly') ]),
-                     "</td> </tr>\n";
+                         ('hourly', 'daily', 'weekly', 'monthly', 'yearly')]));
                }
+       print &ui_hidden_table_end("sched");
        }
-print "</table></td></tr></table>\n" ;
 
 if ($cron) {
-       print "<input type=submit name=backup value='$text{'backup_ok1'}'>\n";
-       print "<input type=submit name=save value='$text{'backup_ok2'}'>\n";
+       print &ui_form_end([ [ "backup", $text{'backup_ok'} ],
+                            [ "save", $text{'backup_ok2'} ] ]);
        }
 else {
-       print "<input type=submit name=backup value='$text{'backup_ok'}'>\n";
+       print &ui_form_end([ [ "backup", $text{'backup_ok'} ] ]);
        }
-print "<br>\n";
-print "</form>\n";
 
 if ($in{'all'}) {
        &ui_print_footer("", $text{'index_return'});
index bdb8f06..5722089 100644 (file)
@@ -441,13 +441,16 @@ restore_failed=Restore failed : $1
 
 backup_title=Backup Database
 backup_title2=Backup All Databases
-backup_header=Backup database options
+backup_header1=Backup destination
+backup_header2=Other backup options
+backup_header3=Backup schedule
 backup_db=Database name
 backup_desc=This form allows you to backup the database $1 as either a file of SQL statements or an archive.
 backup_desc2=The backup can be performed immediately, or automatically on a selected schedule.
 backup_desc3=This form allows you to backup all databases as either files of SQL statements or archive.
 backup_path=Backup file path
 backup_path2=Backup files directory
+backup_mkdir=Create destination directory?
 backup_err=Failed to backup database
 backup_eacl=You must be allowed to create and drop database
 backup_edb=Missing or invalid database name