new type API for PDF

This commit is contained in:
Roland Gruber 2017-01-06 10:11:47 +01:00
parent 164433343c
commit 695f94e322
1 changed files with 73 additions and 52 deletions

View File

@ -40,7 +40,7 @@ $Id$
*/ */
/** /**
* This is the main window of the pdf structure editor. * This is the main window of the PDF structure editor.
* *
* @author Michael Duergner * @author Michael Duergner
* @author Roland Gruber * @author Roland Gruber
@ -72,7 +72,7 @@ if (!empty($_POST)) {
setlanguage(); setlanguage();
// Unset pdf structure definitions in session if set // Unset PDF structure definitions in session if set
if(isset($_SESSION['currentPDFStructure'])) { if(isset($_SESSION['currentPDFStructure'])) {
unset($_SESSION['currentPDFStructure']); unset($_SESSION['currentPDFStructure']);
unset($_SESSION['currentPageDefinitions']); unset($_SESSION['currentPageDefinitions']);
@ -124,7 +124,7 @@ foreach ($configProfiles as $profileName) {
$serverProfiles[$profileName] = new \LAMConfig($profileName); $serverProfiles[$profileName] = new \LAMConfig($profileName);
} }
// import profiles // import structures
if (!empty($_POST['import'])) { if (!empty($_POST['import'])) {
$cfg = new LAMCfgMain(); $cfg = new LAMCfgMain();
$typeId = $_POST['typeId']; $typeId = $_POST['typeId'];
@ -147,7 +147,30 @@ if (!empty($_POST['import'])) {
} }
} }
// 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 = array();
foreach ($_POST['exportProfiles_' . $typeId] as $importProfiles) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1]);
}
$typeId = $_POST['typeId'];
$name = $_POST['name_' . $typeId];
$errMessage = exportStructures($typeId, $name, $options, $serverProfiles, $typeManager);
}
if ($errMessage != null) {
$errMessage->colspan = 10;
$container->addElement($errMessage, true);
}
}
// upload logo file // upload logo file
if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) {
@ -334,53 +357,51 @@ include '../main_header.php';
echo '</form>'; echo '</form>';
echo "</div>\n"; echo "</div>\n";
}
//export dialog //export dialog
echo "<div id=\"exportDialog\" class=\"hidden\">\n"; echo "<div id=\"exportDialog_$typeId\" class=\"hidden\">\n";
echo "<form id=\"exportDialogForm\" method=\"post\" action=\"pdfmain.php\">\n"; echo "<form id=\"exportDialogForm_$typeId\" method=\"post\" action=\"pdfmain.php\">\n";
$container = new htmlTable(); $container = new htmlTable();
$container->addElement(new htmlOutputText(_('PDF structure')), true);
$expStructGroup = new htmlTable();
$expStructGroup->addElement(new htmlSpacer('10px', null));
$expStructGroup->addElement(new htmlDiv('exportName', ''));
$container->addElement($expStructGroup, true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Target server profile")), true); $container->addElement(new htmlOutputText(_("Target server profile")), true);
foreach ($configProfiles as $key => $value) { $exportOptions = array();
$tmpProfiles[$value] = $value; foreach ($configProfiles as $profile) {
$typeManagerExport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$typesExport = $typeManagerExport->getConfiguredTypesForScope($scope);
foreach ($typesExport as $typeExport) {
if (($profile != $_SESSION['config']->getName()) || ($typeExport->getId() != $typeId)) {
$exportOptions[$typeManagerExport->getConfig()->getName()][$typeExport->getAlias()] = $profile . '##' . $typeExport->getId();
} }
natcasesort($tmpProfiles); }
$tmpProfiles['*' . _('Global templates')] = 'templates*'; }
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##';
$findProfile = array_search($_SESSION['config']->getName(), $tmpProfiles); $select = new htmlSelect('exportProfiles_' . $typeId, $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions, 1) : 10);
if ($findProfile !== false) {
unset($tmpProfiles[$findProfile]);
}
$select = new htmlSelect('destServerProfiles', $tmpProfiles, array(), count($tmpProfiles) < 10 ? count($tmpProfiles) : 10);
$select->setHasDescriptiveElements(true); $select->setHasDescriptiveElements(true);
$select->setSortElements(false); $select->setContainsOptgroups(true);
$select->setMultiSelect(true); $select->setMultiSelect(true);
$container->addElement($select); $container->addElement($select);
$container->addElement(new htmlHelpLink('409'), true); $container->addElement(new htmlHelpLink('363'), true);
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true); $container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd'); $exportPasswd = new htmlInputField('passwd_e_' . $typeId);
$exportPasswd->setIsPassword(true); $exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd); $container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236')); $container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'), true); $container->addElement(new htmlHiddenInput('export', '1'), true);
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
$container->addElement(new htmlHiddenInput('name_' . $typeId, '_'), true);
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user'); parseHtml(null, $container, array(), false, $tabindex, 'user');
echo '</form>'; echo '</form>';
echo "</div>\n"; echo "</div>\n";
}
// form for delete action // form for delete action
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">'; echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">';
@ -444,7 +465,7 @@ function exportStructures($typeId, $name, $options, &$serverProfiles, &$typeMana
$targetConfName = $option['conf']; $targetConfName = $option['conf'];
if ($targetConfName == 'templates*') { if ($targetConfName == 'templates*') {
try { try {
\copyAccountProfileToTemplates($sourceType, $name); \LAM\PDF\copyStructureToTemplates($sourceType, $name);
} }
catch (\LAMException $e) { catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
@ -456,7 +477,7 @@ function exportStructures($typeId, $name, $options, &$serverProfiles, &$typeMana
$targetType = $targetTypeManager->getConfiguredType($targetTypeId); $targetType = $targetTypeManager->getConfiguredType($targetTypeId);
if ($targetType != null) { if ($targetType != null) {
try { try {
\copyAccountProfile($sourceType, $name, $targetType); \LAM\PDF\copyStructure($sourceType, $name, $targetType);
} }
catch (\LAMException $e) { catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());