2017-08-04 16:28:16 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
include_once __DIR__.'/core.php';
|
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
ob_end_clean();
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Assegnazione di tutte le variabile GET
|
|
|
|
foreach ($get as $key => $value) {
|
|
|
|
${$key} = !empty(${$key}) ? ${$key} : $value;
|
|
|
|
}
|
|
|
|
|
2017-09-21 10:01:07 +02:00
|
|
|
// Impostazione automatica della precisione a 2 numeri decimali
|
|
|
|
Translator::getFormatter()->setPrecision(2);
|
|
|
|
|
2017-09-15 12:50:59 +02:00
|
|
|
// Individuazione del formato della stampa
|
|
|
|
$old_format = file_exists($docroot.'/templates/'.$ptype.'/pdfgen.'.$ptype.'.php') || file_exists($docroot.'/templates/'.$ptype.'/custom/pdfgen.'.$ptype.'.php');
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Nuovo sistema di generazione stampe
|
2017-09-15 12:50:59 +02:00
|
|
|
if (!$old_format) {
|
2017-09-08 13:24:48 +02:00
|
|
|
// Impostazioni di default
|
2017-09-07 16:51:14 +02:00
|
|
|
if (file_exists($docroot.'/templates/base/custom/settings.php')) {
|
|
|
|
$default = include $docroot.'/templates/base/custom/settings.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2017-09-07 16:51:14 +02:00
|
|
|
$default = include $docroot.'/templates/base/settings.php';
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
// Impostazioni personalizzate della stampa
|
2017-09-07 16:51:14 +02:00
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/settings.php')) {
|
|
|
|
$custom = include $docroot.'/templates/'.$ptype.'/custom/settings.php';
|
|
|
|
} elseif (file_exists($docroot.'/templates/'.$ptype.'/settings.php')) {
|
|
|
|
$custom = include $docroot.'/templates/'.$ptype.'/settings.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
// Individuazione delle impostazioni finali
|
2017-09-07 16:51:14 +02:00
|
|
|
$settings = array_merge($default, (array) $custom);
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Individuazione delle variabili fondamentali per la sostituzione dei contenuti
|
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/init.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/custom/init.php';
|
2017-09-15 12:50:59 +02:00
|
|
|
} elseif (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
|
2017-08-04 16:28:16 +02:00
|
|
|
include $docroot.'/templates/'.$ptype.'/init.php';
|
|
|
|
}
|
|
|
|
|
2017-09-08 18:19:39 +02:00
|
|
|
// Individuazione delle variabili per la sostituzione
|
|
|
|
include_once __DIR__.'/templates/info.php';
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
if (!empty($id_module)) {
|
|
|
|
Permissions::addModule($id_module);
|
|
|
|
}
|
|
|
|
Permissions::check();
|
|
|
|
|
2017-09-08 18:19:39 +02:00
|
|
|
// Operazioni di sostituzione
|
2017-09-11 13:08:50 +02:00
|
|
|
include $docroot.'/templates/info.php';
|
2017-09-08 18:19:39 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Generazione dei contenuti della stampa
|
|
|
|
ob_start();
|
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/body.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/custom/body.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2017-09-07 16:51:14 +02:00
|
|
|
include $docroot.'/templates/'.$ptype.'/body.php';
|
|
|
|
}
|
|
|
|
$report = ob_get_clean();
|
|
|
|
|
2017-09-08 18:19:39 +02:00
|
|
|
if (!empty($autofill)) {
|
2017-09-08 17:03:47 +02:00
|
|
|
$result = '';
|
|
|
|
|
|
|
|
// max($autofill['additional']) = $autofill['rows'] - 1
|
|
|
|
for ($i = (floor($autofill['count']) % $autofill['rows']); $i < $autofill['additional']; ++$i) {
|
|
|
|
$result .= '
|
|
|
|
<tr>';
|
2017-09-08 18:19:39 +02:00
|
|
|
for ($c = 0; $c < $autofill['columns']; ++$c) {
|
2017-09-08 17:03:47 +02:00
|
|
|
$result .= '
|
|
|
|
<td> </td>';
|
|
|
|
}
|
|
|
|
$result .= '
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
|
|
|
|
$report = str_replace('|autofill|', $result, $report);
|
|
|
|
}
|
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Generazione dei contenuti dell'header
|
|
|
|
ob_start();
|
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/header.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/custom/header.php';
|
|
|
|
} elseif (file_exists($docroot.'/templates/'.$ptype.'/header.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/header.php';
|
|
|
|
}
|
|
|
|
$head = ob_get_clean();
|
|
|
|
|
2017-09-21 10:18:08 +02:00
|
|
|
// Footer di default
|
|
|
|
$head = !empty($head) ? $head : '$default_header$';
|
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Generazione dei contenuti del footer
|
|
|
|
ob_start();
|
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/footer.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/custom/footer.php';
|
|
|
|
} elseif (file_exists($docroot.'/templates/'.$ptype.'/footer.php')) {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/footer.php';
|
|
|
|
}
|
|
|
|
$foot = ob_get_clean();
|
2017-08-04 16:28:16 +02:00
|
|
|
} else {
|
2017-09-08 13:24:48 +02:00
|
|
|
$orientation = 'P';
|
|
|
|
$body_table_params = "style='width:210mm;'";
|
|
|
|
$table = 'margin-left:1.7mm';
|
|
|
|
$font_size = '10pt';
|
|
|
|
|
2017-08-04 16:28:16 +02:00
|
|
|
// Decido se usare la stampa personalizzata (se esiste) oppure quella standard
|
2017-12-21 14:57:46 +01:00
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/custom/pdfgen.'.$ptype.'.php')) {
|
2017-08-04 16:28:16 +02:00
|
|
|
include $docroot.'/templates/'.$ptype.'/custom/pdfgen.'.$ptype.'.php';
|
|
|
|
} else {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/pdfgen.'.$ptype.'.php';
|
|
|
|
}
|
2017-09-06 11:59:47 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Sostituzione di variabili generiche
|
|
|
|
$report = str_replace('$body$', $body, $report);
|
|
|
|
$report = str_replace('$footer$', $footer, $report);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
$report = str_replace('$font_size$', $font_size, $report);
|
|
|
|
$report = str_replace('$body_table_params$', $body_table_params, $report);
|
|
|
|
$report = str_replace('$table$', $table, $report);
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-10 14:35:41 +02:00
|
|
|
// Footer di default
|
2017-09-21 10:18:08 +02:00
|
|
|
$foot = !empty($foot) ? $foot : '$default_footer$';
|
2017-09-10 14:35:41 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
// Operazioni di sostituzione
|
2017-09-08 18:19:39 +02:00
|
|
|
include $docroot.'/templates/replace.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Individuazione dellla configurazione
|
|
|
|
$directory = dirname($filename);
|
2017-09-11 17:49:03 +02:00
|
|
|
if (!empty($filename) && !directory($directory)) {
|
2017-09-10 14:35:41 +02:00
|
|
|
$error = tr('Non hai i permessi per creare directory e files in _DIRECTORY_', [
|
|
|
|
'_DIRECTORY_' => $directory,
|
|
|
|
]);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
$_SESSION['errors'][] = $error;
|
|
|
|
|
|
|
|
echo '
|
|
|
|
<p align="center">'.$error.'</p>';
|
|
|
|
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
$mode = !empty($filename) ? 'F' : 'I';
|
|
|
|
|
|
|
|
$filename = !empty($filename) ? $filename : sanitizeFilename($report_name);
|
|
|
|
$title = basename($filename);
|
|
|
|
|
2017-09-15 12:50:59 +02:00
|
|
|
if (!$old_format) {
|
2017-09-07 16:51:14 +02:00
|
|
|
$styles = [
|
|
|
|
'templates/base/bootstrap.css',
|
|
|
|
'templates/base/style.css',
|
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-15 12:50:59 +02:00
|
|
|
$settings['orientation'] = strtoupper($settings['orientation']) == 'L' ? 'L' : 'P';
|
|
|
|
$settings['format'] = is_string($settings['format']) ? $settings['format'].($settings['orientation'] == 'L' ? '-L' : '') : $settings['format'];
|
|
|
|
|
2017-09-12 17:04:38 +02:00
|
|
|
// Instanziamento dell'oggetto mPDF
|
2018-01-02 17:01:47 +01:00
|
|
|
$mpdf = new \Mpdf\Mpdf([
|
|
|
|
'mode' => 'c',
|
|
|
|
'format' => $settings['format'],
|
|
|
|
'orientation' => $settings['orientation'],
|
|
|
|
'font-size' => $settings['font-size'],
|
|
|
|
'margin_left' => $settings['margins']['left'],
|
|
|
|
'margin_right' => $settings['margins']['right'],
|
|
|
|
'margin_top' => $settings['margins']['top'] + $settings['header-height'],
|
|
|
|
'margin_bottom' => $settings['margins']['bottom'] + $settings['footer-height'],
|
|
|
|
'margin_header' => $settings['margins']['top'],
|
|
|
|
'margin_footer' => $settings['margins']['bottom'],
|
|
|
|
]);
|
2017-09-07 17:50:42 +02:00
|
|
|
|
2017-09-12 17:04:38 +02:00
|
|
|
// Impostazione di header e footer
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->SetHTMLFooter($foot);
|
|
|
|
$mpdf->SetHTMLHeader($head);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-12 17:04:38 +02:00
|
|
|
// Impostazione del titolo del PDF
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->SetTitle($title);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-12 17:04:38 +02:00
|
|
|
// Inclusione dei fogli di stile CSS
|
2017-09-07 16:51:14 +02:00
|
|
|
foreach ($styles as $value) {
|
|
|
|
$mpdf->WriteHTML(file_get_contents(__DIR__.'/'.$value), 1);
|
|
|
|
}
|
2017-09-12 17:04:38 +02:00
|
|
|
|
|
|
|
// Impostazione del font-size
|
|
|
|
$mpdf->WriteHTML('body {font-size: '.$settings['font-size'].'pt;}', 1);
|
|
|
|
|
2017-09-15 12:50:59 +02:00
|
|
|
$mpdf->shrink_tables_to_fit = 1;
|
2017-09-12 17:04:38 +02:00
|
|
|
// Aggiunta dei contenuti
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->WriteHTML($report);
|
|
|
|
|
2017-09-12 17:04:38 +02:00
|
|
|
// Creazione effettiva del PDF
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->Output($filename, $mode);
|
|
|
|
} else {
|
2017-09-10 14:35:41 +02:00
|
|
|
if (!str_contains($report, '<page_footer>')) {
|
|
|
|
$report .= '<page_footer>'.$foot.'</page_footer>';
|
|
|
|
}
|
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
$html2pdf = new Spipu\Html2Pdf\Html2Pdf($orientation, 'A4', 'it', true, 'UTF-8');
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
$html2pdf->writeHTML($report);
|
|
|
|
$html2pdf->pdf->setTitle($title);
|
2017-09-07 16:51:14 +02:00
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
$html2pdf->output($filename, $mode);
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|