server()) {
metaRefresh("../login.php");
exit;
}
// Write $_POST variables to $_GET when form was submitted via post
if (isset($_POST['type'])) {
$_GET = $_POST;
}
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to access hidden PDF structure: ' . $type->getId());
die();
}
// Abort and go back to main pdf structure page
if(isset($_GET['abort'])) {
metarefresh('pdfmain.php');
exit;
}
// Load PDF structure from file if it is not defined in session
if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit
$reader = new PDFStructureReader($_SESSION['config']->getName());
try {
if(isset($_GET['edit'])) {
$_SESSION['currentPDFStructure'] = $reader->read($type->getId(), $_GET['edit']);
}
// Load default structure file when creating a new one
else {
$_SESSION['currentPDFStructure'] = $reader->read($type->getId(), 'default');
}
}
catch (\LAMException $e) {
metaRefresh('pdfmain.php?loadFailed=1&name=' . $_GET['edit']);
exit;
}
}
if (!empty($_POST['form_submit'])) {
updateBasicSettings($_SESSION['currentPDFStructure']);
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 = array();
if(isset($_GET['submit'])) {
$writer = new PDFStructureWriter($_SESSION['config']->getName());
try {
$writer->write($type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
unset($_SESSION['currentPDFStructure']);
metaRefresh('pdfmain.php?savedSuccessfully=' . $_POST['pdfname']);
exit;
}
catch (\LAMException $e) {
$saveErrors[] = array('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 = array();
$section_items_array = array();
$section_items = '';
$sortedModules = array();
foreach($availablePDFFields as $module => $fields) {
if ($module != 'main') {
$title = getModuleAlias($module, $type->getScope());
}
else {
$title = _('Main');
}
$sortedModules[$module] = $title;
}
natcasesort($sortedModules);
foreach($sortedModules as $module => $title) {
$values = $availablePDFFields[$module];
if (!is_array($values) || (sizeof($values) < 1)) {
continue;
}
$modules[] = $module;
$section_items .= "\n";
}
$modules = join(',',$modules);
// print header
include __DIR__ . '/../../lib/adminHeader.inc';
?>