#!/usr/local/bin/perl
# edit_dump.cgi
# Edit or create a filesystem backup

require './fsdump-lib.pl';
&foreign_require("cron", "cron-lib.pl");
&ReadParse();

if (!$in{'id'}) {
	# Adding a new backup of some type
	&error_setup($text{'edit_err'});
	$in{'dir'} || &error($text{'edit_edir'});
	$fs = &directory_filesystem($in{'dir'});
	@supp = &supported_filesystems();
	&indexof($fs, @supp) >= 0 || &error(&text('edit_efs', uc($fs)));
	&header($text{'edit_title'}, "", "edit");
	$dump = { 'dir' => $in{'dir'},
		  'fs' => $fs,
		  'mins' => '0',
		  'hours' => '0',
		  'days' => '*',
		  'months' => '*',
		  'weekdays' => '*' };
	}
else {
	# Editing an existing backup
	$dump = &get_dump($in{'id'});
	&header($text{'edit_title2'}, "", "create");
	}
print "<hr>\n";

print "<form action=save_dump.cgi>\n";
print "<input type=hidden name=id value='$in{'id'}'>\n";
print "<input type=hidden name=fs value='$dump->{'fs'}'>\n";
print "<table border width=100%>\n";
print "<tr $tb> <td><b>",&text('edit_header', uc($dump->{'fs'})),
      "</b></td> </tr>\n";

if (!$multiple_directory_support) {
	print "<tr $cb> <td><table width=100%>\n";
	print "<tr> <td><b>",&hlink($text{'dump_dir'}, "dir"),"</b></td>\n";
	printf "<td colspan=3>".
	       "<input name=dir size=50 value='%s'> %s</td> </tr>\n",
		$dump->{'dir'}, &file_chooser_button("dir", 1);
	}
else {
	print "<tr $cb> <td><table width=100%>\n";
	print "<tr> <td><b>",&hlink($text{'dump_dirs'}, "dirs"),"</b></td>\n";
	printf "<td colspan=3><input name=dir size=50 value='%s'></td> </tr>\n",
		$dump->{'dir'};
	}

&dump_form($dump);

print "<tr> <td><b>",&hlink($text{'dump_before'},"before"),"</b></td>\n";
printf "<td colspan=3><input name=before size=60 value='%s'></td> </tr>\n",
	$dump->{'before'};

print "<tr> <td><b>",&hlink($text{'dump_after'},"after"),"</b></td>\n";
printf "<td colspan=3><input name=after size=60 value='%s'></td> </tr>\n",
	$dump->{'after'};

print "<tr> <td colspan=4><hr></td> </tr>\n";

print "<tr> <td><b>",&hlink($text{'edit_enabled'}, "enabled"),"</b></td>\n";
printf "<td colspan=3><input type=radio name=enabled value=0 %s> %s\n",
	$dump->{'enabled'} ? '' : 'checked', $text{'edit_enabled_no'};
printf "<input type=radio name=enabled value=1 %s> %s</td> </tr>\n",
	$dump->{'enabled'} ? 'checked' : '', $text{'edit_enabled_yes'};

print "<tr> <td><b>",&hlink($text{'edit_email'}, "email"),"</b></td>\n";
printf "<td colspan=3><input name=email size=30 value='%s'></td> </tr>\n",
	$dump->{'email'};

print "<tr> <td><b>",&hlink($text{'edit_subject'}, "subject"),"</b></td>\n";
printf "<td colspan=3><input type=radio name=subject_def value=1 %s> %s\n",
	$dump->{'subject'} ? "" : "checked", $text{'default'};
printf "<input type=radio name=subject_def value=0 %s>\n",
	$dump->{'subject'} ? "checked" : "";
printf "<input name=subject size=40 value='%s'></td> </tr>\n",
	$dump->{'subject'};
print "</table>\n";

print "<table border width=100%> <tr $tb>\n";
&foreign_call("cron", "show_times_input", $dump);
print "</table>\n";
print "</td></tr></table>\n";

print "<table width=100%><tr>\n";
if ($in{'id'}) {
	print "<td><input type=submit value='$text{'save'}'></td>\n";
	print "<td align=middle><input type=submit name=savenow ",
	      "value='$text{'edit_savenow'}'></td>\n";
	print "<td align=middle><input type=submit name=backup ",
	      "value='$text{'edit_now'}'></td>\n";
	print "<td align=right><input type=submit name=delete ",
	      "value='$text{'delete'}'></td>\n";
	}
else {
	print "<td><input type=submit value='$text{'create'}'></td>\n";
	print "<td align=right><input type=submit name=savenow ",
	      "value='$text{'edit_createnow'}'></td>\n";
	}
print "</tr></table></form>\n";

print "<hr>\n";
&footer("", $text{'index_return'});

