server()) {
metaRefresh("../login.php");
exit;
}
// Write $_POST variables to $_GET when the form was submitted via post
if (isset($_POST['type'])) {
$_GET = $_POST;
}
$typeManager = new TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
if (($type === null) || $type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to access hidden PDF structure: ' . $_GET['type']);
die();
}
// Abort and go back to the main PDF structure page
if (isset($_GET['abort'])) {
metarefresh('pdfmain.php');
exit;
}
$pdfStructurePersistenceManager = new PdfStructurePersistenceManager();
// Load PDF structure from the file if it is not defined in session
if (!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edited
try {
if (isset($_GET['edit'])) {
$_SESSION['currentPDFStructure'] = $pdfStructurePersistenceManager->readPdfStructure($_SESSION['config']->getName(),
$type->getId(), $_GET['edit']);
}
// Load the default structure file when creating a new one
else {
$structureNames = $pdfStructurePersistenceManager->getPDFStructures($_SESSION['config']->getName(),
$type->getId());
if (in_array('default', $structureNames)) {
$_SESSION['currentPDFStructure'] = $pdfStructurePersistenceManager->readPdfStructure($_SESSION['config']->getName(),
$type->getId(), 'default');
}
else {
$_SESSION['currentPDFStructure'] = new PDFStructure();
}
}
}
catch (LAMException $e) {
logNewMessage(LOG_ERR, $e->getTitle());
metaRefresh('pdfmain.php?loadFailed=1&name=' . $_GET['edit']);
exit;
}
}
$logoFiles = $pdfStructurePersistenceManager->getPdfLogos($_SESSION['config']->getName(), true);
if (!empty($_POST['form_submit'])) {
updateBasicSettings($_SESSION['currentPDFStructure'], $logoFiles);
updateSectionTitles($_SESSION['currentPDFStructure']);
addSection($_SESSION['currentPDFStructure']);
addSectionEntry($_SESSION['currentPDFStructure']);
removeItem($_SESSION['currentPDFStructure']);
moveUp($_SESSION['currentPDFStructure']);
moveDown($_SESSION['currentPDFStructure']);
}
// Check if pdfname is valid, then save current structure to file and go to
// main pdf structure page
$saveErrors = [];
if (isset($_GET['submit'])) {
try {
$pdfStructurePersistenceManager->savePdfStructure($_SESSION['config']->getName(), $type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
unset($_SESSION['currentPDFStructure']);
metaRefresh('pdfmain.php?savedSuccessfully=' . $_POST['pdfname']);
exit;
}
catch (LAMException $e) {
$saveErrors[] = ['ERROR', $e->getTitle(), $e->getMessage()];
}
}
$availablePDFFields = getAvailablePDFFields($type->getId());
// Create the values for the dropdown boxes for section headline defined by
// value entries and fetch all available modules
$modules = [];
$section_items_array = [];
$section_items = '';
$sortedModules = [];
foreach ($availablePDFFields as $module => $fields) {
$title = ($module != 'main') ? getModuleAlias($module, $type->getScope()) : _('Main');
$sortedModules[$module] = $title;
}
natcasesort($sortedModules);
foreach ($sortedModules as $module => $title) {
$values = $availablePDFFields[$module];
if (count($values) < 1) {
continue;
}
$modules[] = $module;
$section_items .= "\n";
}
$modules = implode(',', $modules);
// print header
include __DIR__ . '/../../lib/adminHeader.inc';
?>