2 # Actually do an import of time ranges
4 require './itsecur-lib.pl';
5 &can_edit_error("import");
6 &error_setup($text{'import_err'});
10 if (!$in{'src_def'}) {
11 -r $in{'src'} || &error_cleanup($text{'restore_esrc'});
12 $data = `cat $in{'src'}`;
15 $in{'file'} || &error_cleanup($text{'restore_efile'});
19 %times = map { $_->{'name'}, $_ } &list_times();
20 %daynum = ( "sun", 0, "mon", 1, "tue", 2, "wed", 3, "thu", 4, "fri", 5, "sat", 6 );
25 foreach $line (split(/\n/, $data)) {
31 while($line && $line =~ /^,?("([^"]*)"|([^,]*))(.*)$/) {
35 @row >= 1 || &error(&text('import_erow', $i, $oldline));
38 $row[0] =~ /\S/ || &error(text('import_etimename', $i));
39 $times{$row[0]} && &error(text('import_etimeclash', $i, $row[0]));
40 $time = { 'name' => $row[0] };
43 foreach $d (split(/[\s|,]+/, $row[1])) {
44 local $dn = $daynum{lc($d)};
45 defined($dn) || &error(text('import_etimeday', $i, $d));
48 $time->{'days'} = join(",", @days);
51 $time->{'days'} = '*';
55 $row[2] =~ /^(\d+):(\d+)\-(\d+):(\d+)$/ &&
60 &error(&text('import_etimehour', $i, $row[2]));
61 $time->{'hours'} = $row[2];
64 $time->{'hours'} = '*';
66 $time->{'days'} eq '*' && $time->{'hours'} eq '*' &&
67 &error(text('import_etimenone', $i));
68 push(@newtimes, $time);
72 &lock_itsecur_files();
73 @times = &list_times();
74 push(@times, @newtimes);
77 &unlock_itsecur_files();
80 &header($text{'import_title'}, "",
81 undef, undef, undef, undef, &apply_button());
84 print "<p>",&text('import_done4', scalar(@newtimes)),"<p>\n";
87 &footer("", $text{'index_return'});
88 &remote_webmin_log("import", "times", $in{'src_def'} ? undef : $in{'src'});