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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mostro o nascondo i costi dell'intervento...
|
|
|
|
$visualizza_costi = get_var('Visualizza i costi sulle stampe degli interventi');
|
|
|
|
|
|
|
|
// Nuovo sistema di generazione stampe
|
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
|
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-09-08 13:24:48 +02:00
|
|
|
// Fix per l'altezza minima del margine in alto
|
|
|
|
$settings['header-height'] = ($settings['header-height'] < $settings['margins']['top']) ? $settings['margins']['top'] : $settings['header-height'];
|
|
|
|
|
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';
|
|
|
|
} else {
|
|
|
|
include $docroot.'/templates/'.$ptype.'/init.php';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!empty($id_module)) {
|
|
|
|
Permissions::addModule($id_module);
|
|
|
|
}
|
|
|
|
Permissions::check();
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// 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();
|
|
|
|
|
|
|
|
// 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-09-08 13:24:48 +02:00
|
|
|
// Footer di default
|
|
|
|
$foot = !empty($foot) ? $foot : '$pagination$';
|
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
|
|
|
|
if (file_exists($ptype.'/custom/pdfgen.'.$ptype.'.php')) {
|
|
|
|
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-07 16:51:14 +02:00
|
|
|
// Operazioni di sostituzione
|
|
|
|
include $docroot.'/templates/pdfgen_variables.php';
|
2017-08-04 16:28:16 +02:00
|
|
|
|
|
|
|
// Individuazione dellla configurazione
|
|
|
|
$directory = dirname($filename);
|
2017-09-07 16:54:58 +02:00
|
|
|
if (!empty($filename) && ((is_dir($directory) && !is_writable($directory)) || (!is_dir($directory) && !create_dir($directory)))) {
|
2017-09-04 12:02:29 +02:00
|
|
|
$error = str_replace('_DIRECTORY_', $directory, tr('Non hai i permessi per creare directory e files in _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-07 16:51:14 +02:00
|
|
|
if (file_exists($docroot.'/templates/'.$ptype.'/init.php')) {
|
|
|
|
$styles = [
|
|
|
|
'templates/base/bootstrap.css',
|
|
|
|
'templates/base/style.css',
|
|
|
|
];
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-08 13:24:48 +02:00
|
|
|
$mpdf = new mPDF(
|
|
|
|
'c',
|
|
|
|
$settings['dimension'],
|
|
|
|
$settings['font-size'],
|
|
|
|
'helvetica',
|
|
|
|
$settings['margins']['left'],
|
|
|
|
$settings['margins']['right'],
|
|
|
|
$settings['header-height'],
|
|
|
|
$settings['footer-height'],
|
|
|
|
$settings['margins']['top'],
|
|
|
|
$settings['margins']['bottom'],
|
|
|
|
strtolower($settings['orientation']) == 'l' ? 'l' : 'p'
|
|
|
|
);
|
2017-09-07 17:50:42 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->SetHTMLFooter($foot);
|
|
|
|
$mpdf->SetHTMLHeader($head);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
$mpdf->SetTitle($title);
|
2017-08-04 16:28:16 +02:00
|
|
|
|
2017-09-07 16:51:14 +02:00
|
|
|
foreach ($styles as $value) {
|
|
|
|
$mpdf->WriteHTML(file_get_contents(__DIR__.'/'.$value), 1);
|
|
|
|
}
|
|
|
|
$mpdf->WriteHTML($report);
|
|
|
|
|
|
|
|
$mpdf->Output($filename, $mode);
|
|
|
|
} else {
|
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
|
|
|
}
|