server()) { metaRefresh("../login.php"); exit; } // check if new template should be created if(isset($_POST['createNewTemplate'])) { metaRefresh('pdfpage.php?type=' . htmlspecialchars($_POST['typeId'])); exit(); } $typeManager = new TypeManager(); $types = $typeManager->getConfiguredTypes(); $sortedTypes = []; foreach ($types as $type) { if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) { continue; } $sortedTypes[$type->getId()] = $type->getAlias(); } natcasesort($sortedTypes); $pdfStructurePersistenceManager = new PdfStructurePersistenceManager(); $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_('PDF editor'))); if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { $typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']); // delete structure try { if ($typeToDelete !== null) { $pdfStructurePersistenceManager->deletePdfStructure($_SESSION['config']->getName(), $_POST['profileDeleteType'], $_POST['profileDeleteName']); $message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $container->add($message); } } catch (LAMException $e) { logNewMessage(LOG_ERR, $e->getTitle() . ' ' . $e->getMessage()); $message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $container->add($message); } } // delete global template if (isset($_POST['deleteGlobalTemplate']) && !empty($_POST['globalTemplatesDelete'])) { $cfg = new LAMCfgMain(); if (empty($_POST['globalTemplateDeletePassword']) || !$cfg->checkPassword($_POST['globalTemplateDeletePassword'])) { $container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); } else { $selectedOptions = explode(':', $_POST['globalTemplatesDelete']); $selectedScope = $selectedOptions[0]; $selectedName = $selectedOptions[1]; try { $pdfStructurePersistenceManager->deletePdfStructureTemplate($selectedScope, $selectedName); $container->add(new htmlStatusMessage('INFO', _('Deleted profile.'), $selectedName)); } catch (LAMException $e) { $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); } } } // delete global logo if (isset($_POST['deleteGlobalLogo']) && !empty($_POST['globalLogoDelete'])) { $cfg = new LAMCfgMain(); if (empty($_POST['globalLogoDeletePassword']) || !$cfg->checkPassword($_POST['globalLogoDeletePassword'])) { $container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); } else { $selectedLogo = $_POST['globalLogoDelete']; try { $pdfStructurePersistenceManager->deletePdfTemplateLogo($selectedLogo); $container->add(new htmlStatusMessage('INFO', _('Logo file deleted.'), $selectedLogo)); } catch (LAMException $e) { $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); } } } $serverProfilePersistenceManager = new ServerProfilePersistenceManager(); $serverProfiles = []; $configProfiles = []; try { $configProfiles = $serverProfilePersistenceManager->getProfiles(); foreach ($configProfiles as $profileName) { $serverProfiles[$profileName] = $serverProfilePersistenceManager->loadProfile($profileName); } } catch (LAMException $e) { logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); } // import structures if (!empty($_POST['import'])) { $cfg = new LAMCfgMain(); $typeId = $_POST['typeId']; // check master password $errMessage = null; if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) { $errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } elseif (!empty($_POST['importProfiles_' . $typeId])) { $options = []; foreach ($_POST['importProfiles_' . $typeId] as $importProfiles) { $parts = explode('##', $importProfiles); $options[] = ['conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]]; } $errMessage = importStructures($_POST['typeId'], $options, $serverProfiles, $typeManager); } if ($errMessage !== null) { $container->add($errMessage); } } // export structures if (!empty($_POST['export'])) { $cfg = new LAMCfgMain(); $typeId = $_POST['typeId']; // check master password $errMessage = null; if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) { $errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } elseif (!empty($_POST['exportProfiles_' . $typeId])) { $options = []; foreach ($_POST['exportProfiles_' . $typeId] as $importProfiles) { $parts = explode('##', $importProfiles); $options[] = ['conf' => $parts[0], 'typeId' => $parts[1]]; } $name = $_POST['name_' . $typeId]; $errMessage = exportStructures($typeId, $name, $options, $serverProfiles, $typeManager); } if ($errMessage !== null) { $container->add($errMessage); } } // upload logo file if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { $file = $_FILES['logoUpload']['tmp_name']; $handle = fopen($file, "r"); try { if ($handle === false) { throw new LAMException(_('Unable to create temporary file.')); } $data = fread($handle, 100_000_000); if ($data === false) { throw new LAMException(_('Unable to create temporary file.')); } fclose($handle); $filename = trim((string) $_FILES['logoUpload']['name']); $pdfStructurePersistenceManager->savePdfLogo($_SESSION['config']->getName(), $filename, $data); $container->add(new htmlStatusMessage('INFO', _('Uploaded logo file.'), $filename)); } catch (LAMException $e) { $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); } } // delete logo file if (isset($_POST['delLogo'])) { $toDel = $_POST['logo']; try { $pdfStructurePersistenceManager->deletePdfLogo($_SESSION['config']->getName(), $toDel); $container->add(new htmlStatusMessage('INFO', _('Logo file deleted.'), $toDel)); } catch (LAMException $e) { $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); } } // export logo if (!empty($_POST['exportLogoTargetProfile'])) { $cfg = new LAMCfgMain(); if (!$cfg->checkPassword($_POST['exportLogoPassword'])) { $container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); } else { try { foreach ($_POST['exportLogoTargetProfile'] as $targetProfile) { $fileName = $_POST['exportLogoName']; $binary = $pdfStructurePersistenceManager->getPdfLogoBinary($_SESSION['config']->getName(), $fileName); if ($targetProfile === 'templates*') { $pdfStructurePersistenceManager->savePdfTemplateLogo($fileName, $binary); } else { $pdfStructurePersistenceManager->savePdfLogo($targetProfile, $fileName, $binary); } } $container->add(new htmlStatusMessage('INFO', _('Exported logo file.'))); } catch (LAMException $e) { $container->add(new htmlStatusMessage($e->getTitle(), $e->getMessage())); } } } // import logo if (!empty($_POST['importLogoSourceProfile'])) { $cfg = new LAMCfgMain(); if (!$cfg->checkPassword($_POST['importLogoPassword'])) { $container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); } else { try { foreach ($_POST['importLogoSourceProfile'] as $sourceLogo) { $parts = explode('##', $sourceLogo); if (count($parts) !== 2) { continue; } $profileName = $parts[0]; $fileName = $parts[1]; $binary = $pdfStructurePersistenceManager->getPdfLogoBinary($profileName, $fileName); $pdfStructurePersistenceManager->savePdfLogo($_SESSION['config']->getName(), $fileName, $binary); } $container->add(new htmlStatusMessage('INFO', _('Logo import successful.'))); } catch (LAMException $e) { $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); } } } // get list of account types $availableTypes = []; $templateClasses = []; foreach ($sortedTypes as $typeId => $title) { $type = $typeManager->getConfiguredType($typeId); if ($type === null) { continue; } $templateClasses[] = [ 'typeId' => $type->getId(), 'scope' => $type->getScope(), 'title' => $title, 'icon' => $type->getIcon(), 'templates' => $pdfStructurePersistenceManager->getPDFStructures($_SESSION['config']->getName(), $type->getId()) ]; $availableTypes[$title] = $type->getId(); } // check if a template should be edited foreach ($templateClasses as $templateClass) { if (isset($_POST['editTemplate_' . $templateClass['typeId']]) || isset($_POST['editTemplate_' . $templateClass['typeId'] . '_x'])) { metaRefresh('pdfpage.php?type=' . htmlspecialchars($templateClass['typeId']) . '&edit=' . htmlspecialchars($_POST['template_' . $templateClass['typeId']])); exit; } } include __DIR__ . '/../../lib/adminHeader.inc'; ?>