-
Notifications
You must be signed in to change notification settings - Fork 0
/
genPlanner
executable file
·70 lines (66 loc) · 2.4 KB
/
genPlanner
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env php
<?php
chdir(__DIR__);
system("rm -rf out");
@mkdir("out");
system("rm -rf tpl");
@mkdir("tpl");
chdir("tpl");
system("unzip ../planer.ods");
chdir(__DIR__);
if (isset($_SERVER['argv'][3])) {
setlocale(LC_ALL, $_SERVER['argv'][3]);
} else {
setlocale(LC_ALL, "de_DE.utf8");
}
$from = strtotime($_SERVER['argv'][1]);
if (!$from) $from = strtotime("first day of next month");
$days = $_SERVER['argv'][2];
if (!$days) $days = cal_days_in_month(CAL_GREGORIAN, date("m", $from), date("Y", $from));
$tpl = file_get_contents("tpl/content.xml");
@mkdir("out");
while ($days > 0) {
$days--;
$now = $from + $days * 60 * 60 * 24 - 1;
$folderName = "./out/" . date("Y-m-d", $now);
system("rm -rf $folderName");
@mkdir("$folderName");
chdir("$folderName");
system("unzip ../../planer.ods");
chdir(__DIR__);
$data = preg_replace_callback("/{{([^:}]*)(:([^:}]*))?}}/m", function ($match) use ($now) {
$type = $match[1];
$param = $match[3];
switch ($type) {
case "DATE":
return strftime($param, $now);
break;
default:
return "UNKNOWN COMMAND " . $match[0];
}
}, $tpl);
file_put_contents("$folderName/content.xml", $data);
chdir("$folderName");
system("zip -r " . basename($folderName) . ".ods .");
system("loffice --nologo --norestore --invisible --nolockcheck --nodefault --convert-to pdf " . basename($folderName) . ".ods");
chdir(__DIR__);
}
copy("notizen.ods", "out/notizen.ods");
chdir("out");
system("loffice --nologo --norestore --invisible --nolockcheck --nodefault --convert-to pdf notizen.ods");
system('find -type f -not -name "*.pdf" -delete');
system('find -name "*.pdf" -not -name notizen.pdf -exec mv "{}" . \;');
system("find -type d -delete");
foreach (glob('*.pdf') as $pdf) {
if ($pdf === "notizen.pdf") continue;
system(" pdfjam --nup 2x1 $pdf notizen.pdf --landscape --a3paper --outfile tmp-$pdf");
system("gs -o full-$pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress tmp-$pdf");
unlink("tmp-$pdf");
}
system('find -name "*.pdf" -not -name "full-*" -delete');
system("pdfunite *.pdf all-mangled.pdf");
system("gs -o all-fixed.pdf -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress all-mangled.pdf");
system("pdfjam --outfile all.pdf --paper a4paper --landscape all-fixed.pdf");
unlink("all-fixed.pdf");
unlink("all-mangled.pdf");
system("rm -rf ../tpl");