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
|
|
|
$orientation = 'P';
|
|
|
|
$body_table_params = "style='width:210mm;'";
|
2017-09-07 16:51:14 +02:00
|
|
|
$table = 'margin-left:1.7mm';
|
2017-08-04 16:28:16 +02:00
|
|
|
$font_size = '10pt';
|
|
|
|
|
|
|
|
// 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-07 16:51:14 +02:00
|
|
|
// Impostazioni della stampa
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
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-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';
|
|
|
|
} 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();
|
|
|
|
|
|
|
|
if (empty($foot)) {
|
|
|
|
$foot = '$pagination$';
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 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
|
|
|
|
|
|
|
$report = str_replace('$docroot$', $docroot, $report);
|
|
|
|
$report = str_replace('$rootdir$', $rootdir, $report);
|
|
|
|
|
|
|
|
// 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-07 16:51:14 +02:00
|
|
|
$mpdf = new mPDF('utf-8', $settings['dimension'], $settings['font-size'], '', 12, 12, $settings['header'], $settings['footer'], 9, 9, $settings['orientation']);
|
|
|
|
$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 {
|
|
|
|
// HTML
|
|
|
|
$html = (get_var('Formato report') == 'html');
|
|
|
|
|
|
|
|
try {
|
|
|
|
ob_end_clean();
|
|
|
|
$html2pdf = new HTML2PDF($orientation, 'A4', 'it', true, 'UTF-8');
|
|
|
|
|
|
|
|
$html2pdf->writeHTML($report, $html);
|
|
|
|
$html2pdf->pdf->setTitle($title);
|
|
|
|
|
|
|
|
$html2pdf->output($filename, $mode);
|
|
|
|
} catch (HTML2PDF_exception $e) {
|
|
|
|
echo $e;
|
|
|
|
exit();
|
|
|
|
}
|
2017-08-04 16:28:16 +02:00
|
|
|
}
|