-
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathresult-pdf.php
115 lines (92 loc) · 4.23 KB
/
result-pdf.php
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
/*
Termination of Transfer - tool to help in returning authors rights.
Copyright (C) 2016, 2017 Creative Commons Corporation.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
require __DIR__ . '/../vendor/autoload.php';
////////////////////////////////////////////////////////////////////////////////
// Make sure we have the data to decode
////////////////////////////////////////////////////////////////////////////////
if (! isset($_POST['data'])) {
exit('No data provided.');
}
////////////////////////////////////////////////////////////////////////////////
// Decode the data
////////////////////////////////////////////////////////////////////////////////
$data = json_decode($_POST['data'], true);
////////////////////////////////////////////////////////////////////////////////
// Make sure the data is well-structured
////////////////////////////////////////////////////////////////////////////////
if (!isset($data['report_timestamp'])) {
exit('Report timestamp not provided.');
}
if (!isset($data['conclusion'])) {
exit('Conclusion not provided.');
}
if (!isset($data['flags'])) {
exit('Flags not provided.');
}
if (!isset($data['details'])) {
exit('Details not provided.');
}
////////////////////////////////////////////////////////////////////////////////
// Flag and conclusion expansion
////////////////////////////////////////////////////////////////////////////////
$results_json = file_get_contents(__DIR__ . '/js/results.json');
$results_strings = json_decode($results_json, $assoc=true);
function flag_title_and_description ($spec)
{
global $results_strings;
$path = explode('.', $spec);
// A, B, C, D
$section = $results_strings['Flag'][$path[0]];
// i, ii, iii
$subsection = $section[$path[1]];
// For historical reasons, some flags take their section title and have
// their description under 'b', and others have their own title and their
// description under 'description'
if (array_key_exists('description', $subsection)) {
$title = $subsection['title'];
$description = $subsection['description'];
} else {
$title = $section['title'];
$description = $subsection['b'];
}
return [$title, $description];
}
$flags = array_map('flag_title_and_description', $data['flags']);
$conclusion_path = explode('.', $data['conclusion']);
$conclusion_section = $results_strings['Conclusion'][$conclusion_path[0]];
$conclusion_title = $conclusion_section['title'];
$conclusion_details = $conclusion_section[$conclusion_path[1]];
$conclusion_subtitle = $conclusion_details['title'];
$conclusion_description = $conclusion_details['description'];
////////////////////////////////////////////////////////////////////////////////
// Fill out the template with the details from the provided data
////////////////////////////////////////////////////////////////////////////////
$now_timestamp = intval($data['report_timestamp']);
$smarty = new Smarty;
$smarty->setCompileDir(__DIR__ . '/../templates_c');
$smarty->assign('date', date('jS F Y', $now_timestamp));
$smarty->assign('flags', $flags);
$smarty->assign('details', $data['details']);
$smarty->assign('conclusion_title', $conclusion_title);
$smarty->assign('conclusion_subtitle', $conclusion_subtitle);
$smarty->assign('conclusion_description', $conclusion_description);
$html = $smarty->fetch(__DIR__ . '/../template/result.tpl');
////////////////////////////////////////////////////////////////////////////////
// Generate and return the PDF
////////////////////////////////////////////////////////////////////////////////
$mpdf = new mPDF();
$mpdf->WriteHTML($html);
$mpdf->Output('ToT.pdf', 'I');