From a9234c15375bd5a3009a4d6acab53c17938dde1a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Wed, 4 Jan 2017 20:52:51 +0100 Subject: [PATCH 1/7] new type API for PDF --- lam/lib/lists.inc | 2 +- lam/lib/modules.inc | 9 +++-- lam/lib/pdf.inc | 2 +- lam/lib/pdfstruct.inc | 19 ++++----- lam/lib/xml_parser.inc | 22 +++++----- lam/templates/pdfedit/pdfmain.php | 17 ++++---- lam/templates/pdfedit/pdfpage.php | 63 +++++++++++++++-------------- lam/templates/upload/masscreate.php | 2 +- 8 files changed, 70 insertions(+), 66 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index bfd687a9..f64771c3 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -690,7 +690,7 @@ class lamList { $selAccounts[] = $id; } // get possible PDF structures - $pdf_structures = getPDFStructureDefinitions($this->type->getId()); + $pdf_structures = \LAM\PDF\getPDFStructureDefinitions($this->type->getId()); $this->listPrintHeader(); diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 39de01e8..dc14b2cd 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -1,5 +1,6 @@ field label) */ -function getAvailablePDFFields($scope) { - $mods = $_SESSION['config']->get_AccountModules($scope); +function getAvailablePDFFields($typeId) { + $mods = $_SESSION['config']->get_AccountModules($typeId); $return = array(); for ($i = 0; $i < sizeof($mods); $i++) { - $module = moduleCache::getModule($mods[$i], $scope); + $module = moduleCache::getModule($mods[$i], getScopeFromTypeId($typeId)); $fields = $module->get_pdfFields(); $return[$mods[$i]] = array(); if (is_array($fields)) { diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index 65d2b895..ec902d13 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -67,7 +67,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = $account_type = $accounts[0]->get_type(); // Get PDF structure from xml file - $load = loadPDFStructureDefinitions($account_type->getId(), $pdf_structure); + $load = \LAM\PDF\loadPDFStructureDefinitions($account_type->getId(), $pdf_structure); $structure = $load['structure']; // get list of PDF keys $pdfKeys = array(); diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 9c07d619..2fae7541 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -1,4 +1,7 @@ getName() . '/' . $pdf_structure . '.' . $scope . '.xml'; $xml = $parser->parse($file); $border = array(); $structure = array(); $complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager'); - if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) { + if (!empty($xml)) { $border['start'] = $xml[1]['PDF'][0]; $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes']; foreach($page_definitions as $key => $value) { @@ -90,8 +93,8 @@ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') { unset($page_definitions[$key]); } $border['end'] = $xml[1]['PDF'][1]; + $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); } - $structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1)); return array('structure' => $structure, 'page_definitions' => $complete_page_definitions); } @@ -103,7 +106,7 @@ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') { * @param string $definition Name of definition * @return string "no perms" if access denied or "ok". */ -function savePDFStructureDefinitions($scope,$definition) { +function savePDFStructureDefinitions($scope, $definition) { if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms'; if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms'; $struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; @@ -115,11 +118,9 @@ function savePDFStructureDefinitions($scope,$definition) { if (!$handle) return 'no perms'; $pdf_attributes = ''; foreach($_SESSION['currentPageDefinitions'] as $key => $value) { - if($key != 'type') { - $pdf_attributes .= ' ' . $key . '="' . $value . '"'; - } + $pdf_attributes .= ' ' . $key . '="' . $value . '"'; } - $file = '\n"; + $file = '\n"; foreach($_SESSION['currentPDFStructure'] as $entry) { $ident = ''; for($i=0;$i<$entry['level'] -1;$i++) { @@ -289,7 +290,7 @@ function deletePDFLogo($name) { $data = loadPDFStructureDefinitions($type, $structure); if ($data['page_definitions']['filename'] == $name) { return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), - sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, LAM\TYPES\getTypeAlias($type))); + sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, \LAM\TYPES\getTypeAlias($type))); } } } diff --git a/lam/lib/xml_parser.inc b/lam/lib/xml_parser.inc index e44e0a8c..f06bb328 100644 --- a/lam/lib/xml_parser.inc +++ b/lam/lib/xml_parser.inc @@ -1,9 +1,11 @@ xmlParser = xml_parser_create(); - xml_set_object($this->xmlParser,$this); + xml_set_object($this->xmlParser, $this); xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, 1); xml_parser_set_option($this->xmlParser, XML_OPTION_SKIP_WHITE, 1); } - + /** * Starts the parsing. - * - * @param String $filename file name + * + * @param String $filename file name * @return array XML structure */ function parse($filename) { if(file_exists($filename)) { $xmlStructure = array(); $xmlIndex = array(); - xml_parse_into_struct($this->xmlParser,implode("\n",file($filename)),$xmlStructure,$xmlIndex); - return array($xmlStructure,$xmlIndex); + xml_parse_into_struct($this->xmlParser, implode("\n", file($filename)), $xmlStructure, $xmlIndex); + return array($xmlStructure, $xmlIndex); } return array(); } diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 596a3e02..39a640f5 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -75,7 +75,6 @@ setlanguage(); // Unset pdf structure definitions in session if set if(isset($_SESSION['currentPDFStructure'])) { unset($_SESSION['currentPDFStructure']); - unset($_SESSION['availablePDFFields']); unset($_SESSION['currentPageDefinitions']); } @@ -107,7 +106,7 @@ $container->addElement(new htmlTitle(_('PDF editor')), true); if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { // delete structure - if (deletePDFStructureDefinition($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { + if (\LAM\PDF\deletePDFStructureDefinition($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { $message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $message->colspan = 10; $container->addElement($message, true); @@ -127,7 +126,7 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) { $impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } - elseif (copyPdfProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) { + elseif (\LAM\PDF\copyPdfProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) { $impExpMessage = new htmlStatusMessage('INFO', _('Import successful')); } } else if (isset($_POST['exportProfiles'])) { @@ -135,7 +134,7 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { if (!$cfg->checkPassword($_POST['passwd'])) { $impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } - elseif (copyPdfProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) { + elseif (\LAM\PDF\copyPdfProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) { $impExpMessage = new htmlStatusMessage('INFO', _('Export successful')); } } @@ -149,13 +148,13 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { $file = $_FILES['logoUpload']['tmp_name']; $filename = $_FILES['logoUpload']['name']; - $container->addElement(uploadPDFLogo($file, $filename), true); + $container->addElement(\LAM\PDF\uploadPDFLogo($file, $filename), true); } // delete logo file if (isset($_POST['delLogo'])) { $toDel = $_POST['logo']; - $container->addElement(deletePDFLogo($toDel), true); + $container->addElement(\LAM\PDF\deletePDFLogo($toDel), true); } // get list of account types @@ -172,7 +171,7 @@ foreach ($sortedTypes as $typeId => $title) { } // get list of templates for each account type for ($i = 0; $i < sizeof($templateClasses); $i++) { - $templateClasses[$i]['templates'] = getPDFStructureDefinitions($templateClasses[$i]['typeId']); + $templateClasses[$i]['templates'] = \LAM\PDF\getPDFStructureDefinitions($templateClasses[$i]['typeId']); } // check if a template should be edited @@ -255,7 +254,7 @@ include '../main_header.php'; $logoContainer = new htmlTable(); $logoContainer->addElement(new htmlSpacer(null, '30px'), true); $logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true); - $logos = getAvailableLogos(); + $logos = \LAM\PDF\getAvailableLogos(); $logoOptions = array(); foreach ($logos as $logo) { $file = $logo['filename']; @@ -287,7 +286,7 @@ include '../main_header.php'; $tmpArr = array(); foreach ($configProfiles as $profile) { if ($profile != $_SESSION['config']->getName()) { - $accountProfiles = getPDFStructureDefinitions($typeId, $profile); + $accountProfiles = \LAM\PDF\getPDFStructureDefinitions($typeId, $profile); for ($p = 0; $p < sizeof($accountProfiles); $p++) { $tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p]; } diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index 40568bf8..b264a5a6 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -129,7 +129,7 @@ if(isset($_GET['submit'])) { $saveErrors[] = array('ERROR', _('PDF structure name not valid'), _('The name for that PDF-structure you submitted is not valid. A valid name must consist of the following characters: \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\'.')); } else { - $return = savePDFStructureDefinitions($type->getId(), $_GET['pdfname']); + $return = \LAM\PDF\savePDFStructureDefinitions($type->getId(), $_GET['pdfname']); if($return == 'ok') { metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']); exit; @@ -356,23 +356,20 @@ foreach ($_GET as $key => $value) { if(!isset($_SESSION['currentPDFStructure'])) { // Load structure file to be edit if(isset($_GET['edit'])) { - $load = loadPDFStructureDefinitions($type->getId(), $_GET['edit']); + $load = \LAM\PDF\loadPDFStructureDefinitions($type->getId(), $_GET['edit']); $_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPageDefinitions'] = $load['page_definitions']; $_GET['pdfname'] = $_GET['edit']; } // Load default structure file when creating a new one else { - $load = loadPDFStructureDefinitions($type->getId()); + $load = \LAM\PDF\loadPDFStructureDefinitions($type->getId()); $_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPageDefinitions'] = $load['page_definitions']; } } -// Load available fields from modules when not set in session -if(!isset($_SESSION['availablePDFFields'])) { - $_SESSION['availablePDFFields'] = getAvailablePDFFields($type->getId()); -} +$availablePDFFields = getAvailablePDFFields($type->getId()); // Create the values for the dropdown boxes for section headline defined by // value entries and fetch all available modules @@ -380,7 +377,7 @@ $modules = array(); $section_items_array = array(); $section_items = ''; $sortedModules = array(); -foreach($_SESSION['availablePDFFields'] as $module => $fields) { +foreach($availablePDFFields as $module => $fields) { if ($module != 'main') { $title = getModuleAlias($module, $type->getScope()); } @@ -391,7 +388,7 @@ foreach($_SESSION['availablePDFFields'] as $module => $fields) { } natcasesort($sortedModules); foreach($sortedModules as $module => $title) { - $values = $_SESSION['availablePDFFields'][$module]; + $values = $availablePDFFields[$module]; if (!is_array($values) || (sizeof($values) < 1)) { continue; } @@ -419,7 +416,7 @@ if (sizeof($saveErrors) > 0) { $newFieldFieldElements = array(); foreach($sortedModules as $module => $title) { - $fields = $_SESSION['availablePDFFields'][$module]; + $fields = $availablePDFFields[$module]; if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) { $moduleFields = array(); foreach ($fields as $field => $fieldLabel) { @@ -446,7 +443,7 @@ if (isset($_SESSION['currentPageDefinitions']['headline'])) { $headline = $_SESSION['currentPageDefinitions']['headline']; } // logo -$logoFiles = getAvailableLogos(); +$logoFiles = \LAM\PDF\getAvailableLogos(); $logos = array(_('No logo') => 'none'); foreach($logoFiles as $logoFile) { $logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename']; @@ -459,7 +456,7 @@ if (isset($_SESSION['currentPageDefinitions']['filename'])) { ?>
0); +$sectionElements = array(); $nonTextSectionElements = array(); $container = new htmlTable(); @@ -498,10 +495,10 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) { $linkRemove->setTitle(_("Remove")); $emptyBox = new htmlOutputText(''); // We have a new section to start - if($entry['tag'] == "SECTION" && $entry['type'] == "open") { + if(($entry['tag'] == "SECTION") && ($entry['type'] == 'open')) { $name = $entry['attributes']['NAME']; if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) { - $section_headline = translateFieldIDToName(substr($name,1), $type->getScope()); + $section_headline = translateFieldIDToName(substr($name,1), $type->getScope(), $availablePDFFields); } else { $section_headline = $name; @@ -513,7 +510,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) { if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) { $headlineElements = array(); foreach($section_items_array as $item) { - $headlineElements[translateFieldIDToName($item, $type->getScope())] = '_' . $item; + $headlineElements[translateFieldIDToName($item, $type->getScope(), $availablePDFFields)] = '_' . $item; } $sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array($name)); $sectionHeadlineSelect->setHasDescriptiveElements(true); @@ -583,7 +580,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) { // Get name of current entry $name = $entry['attributes']['NAME']; $structureContent->addElement(new htmlSpacer('10px', null)); - $fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope())); + $fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope(), $availablePDFFields)); $structureContent->addElement($fieldOutput); if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') { $structureContent->addElement($linkUp); @@ -600,6 +597,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) { $structureContent->addElement($linkRemove, true); } } +$sectionElements[_('End')] = sizeof($_SESSION['currentPDFStructure']); $structureContent->colspan = 3; $mainContent->addElement($structureContent); $container->addElement(new htmlFieldset($mainContent), true); @@ -638,19 +636,21 @@ $newTextFieldContent->addElement(new htmlButton('add_text', _('Add'))); $container->addElement(new htmlFieldset($newTextFieldContent, _("Text field")), true); // new field -$container->addElement(new htmlSubTitle(_('New field')), true); -$newFieldContainer = new htmlTable(); -$newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements); -$newFieldFieldSelect->setHasDescriptiveElements(true); -$newFieldFieldSelect->setContainsOptgroups(true); -$newFieldContainer->addElement($newFieldFieldSelect); -$newFieldContainer->addElement(new htmlSpacer('10px', null)); -$newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position')); -$newFieldSectionSelect->setHasDescriptiveElements(true); -$newFieldContainer->addElement($newFieldSectionSelect); -$newFieldContainer->addElement(new htmlButton('add_new_field', _('Add'))); -$container->addElement(new htmlFieldset($newFieldContainer), true); -$container->addElement(new htmlSpacer(null, '20px'), true); +if (!empty($nonTextSectionElements)) { + $container->addElement(new htmlSubTitle(_('New field')), true); + $newFieldContainer = new htmlTable(); + $newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements); + $newFieldFieldSelect->setHasDescriptiveElements(true); + $newFieldFieldSelect->setContainsOptgroups(true); + $newFieldContainer->addElement($newFieldFieldSelect); + $newFieldContainer->addElement(new htmlSpacer('10px', null)); + $newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position')); + $newFieldSectionSelect->setHasDescriptiveElements(true); + $newFieldContainer->addElement($newFieldSectionSelect); + $newFieldContainer->addElement(new htmlButton('add_new_field', _('Add'))); + $container->addElement(new htmlFieldset($newFieldContainer), true); + $container->addElement(new htmlSpacer(null, '20px'), true); +} // buttons $buttonContainer = new htmlTable(); @@ -688,9 +688,10 @@ include '../main_footer.php'; * * @param String $id field ID * @param String $scope account type + * @param array $availablePDFFields available PDF fields */ -function translateFieldIDToName($id, $scope) { - foreach ($_SESSION['availablePDFFields'] as $module => $fields) { +function translateFieldIDToName($id, $scope, $availablePDFFields) { + foreach ($availablePDFFields as $module => $fields) { if (!(strpos($id, $module . '_') === 0)) { continue; } diff --git a/lam/templates/upload/masscreate.php b/lam/templates/upload/masscreate.php index 35ac8816..3cba31c9 100644 --- a/lam/templates/upload/masscreate.php +++ b/lam/templates/upload/masscreate.php @@ -267,7 +267,7 @@ function showMainPage($scope, $selectedModules) { $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); $pdfCheckbox->setTableRowsToShow(array('pdfStructure')); $inputContainer->addElement($pdfCheckbox, true); - $pdfStructures = getPDFStructureDefinitions($scope); + $pdfStructures = \LAM\PDF\getPDFStructureDefinitions($scope); $pdfSelected = array(); if (isset($_POST['pdfStructure'])) { $pdfSelected = array($_POST['pdfStructure']); From 8774583532b744799961fa3cf5ee01db62d805ba Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 5 Jan 2017 21:05:17 +0100 Subject: [PATCH 2/7] new type API for PDF --- lam/lib/lists.inc | 2 +- lam/lib/pdf.inc | 2 +- lam/lib/pdfstruct.inc | 133 ++++++++++++++----------- lam/templates/pdfedit/pdfmain.php | 6 +- lam/templates/pdfedit/pdfpage.php | 6 +- lam/templates/profedit/profilemain.php | 24 ++--- lam/templates/upload/masscreate.php | 2 +- 7 files changed, 97 insertions(+), 78 deletions(-) diff --git a/lam/lib/lists.inc b/lam/lib/lists.inc index f64771c3..0e174adb 100644 --- a/lam/lib/lists.inc +++ b/lam/lib/lists.inc @@ -690,7 +690,7 @@ class lamList { $selAccounts[] = $id; } // get possible PDF structures - $pdf_structures = \LAM\PDF\getPDFStructureDefinitions($this->type->getId()); + $pdf_structures = \LAM\PDF\getPDFStructures($this->type->getId()); $this->listPrintHeader(); diff --git a/lam/lib/pdf.inc b/lam/lib/pdf.inc index ec902d13..80d82f21 100644 --- a/lam/lib/pdf.inc +++ b/lam/lib/pdf.inc @@ -67,7 +67,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString = $account_type = $accounts[0]->get_type(); // Get PDF structure from xml file - $load = \LAM\PDF\loadPDFStructureDefinitions($account_type->getId(), $pdf_structure); + $load = \LAM\PDF\loadPDFStructure($account_type->getId(), $pdf_structure); $structure = $load['structure']; // get list of PDF keys $pdfKeys = array(); diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 2fae7541..2c7132bb 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -2,6 +2,7 @@ namespace LAM\PDF; use \htmlStatusMessage; +use \LAMException; /* $Id$ @@ -49,7 +50,7 @@ include_once("ldap.inc"); * scope. Each entry is a string being the filename that may be passed to the * createModulePDF() function as second argument. */ -function getPDFStructureDefinitions($scope = "user", $profile = null) { +function getPDFStructures($scope = "user", $profile = null) { $return = array(); if (!isset($profile)) { @@ -70,17 +71,19 @@ function getPDFStructureDefinitions($scope = "user", $profile = null) { } /** - * This function is used to get pdf structure from xml file. - * Used in createModulePDF. + * This function is used to get the PDF structure from XML file. * - * @param string $scope The account scope for wich the PDF structure should be returned. - * @param string $pdf_structure Structure name of selected scope wich should be returned. + * @param string $typeId the account type + * @param string $name structure name * * @return array PDF structure */ -function loadPDFStructureDefinitions($scope='user', $pdf_structure='default') { +function loadPDFStructure($typeId, $name='default') { + if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) { + return null; + } $parser = new xmlParser(); - $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $pdf_structure . '.' . $scope . '.xml'; + $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml'; $xml = $parser->parse($file); $border = array(); $structure = array(); @@ -100,16 +103,17 @@ function loadPDFStructureDefinitions($scope='user', $pdf_structure='default') { /** - * Saves PDF structure definitions to XML file in format: ..xml + * Saves PDF structure to XML file in format: ..xml * - * @param string $scope account type - * @param string $definition Name of definition + * @param string $typeId account type + * @param string $name name of structure * @return string "no perms" if access denied or "ok". */ -function savePDFStructureDefinitions($scope, $definition) { - if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms'; - if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms'; - $struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; +function savePDFStructure($typeId, $name) { + if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) { + return 'no perms'; + } + $struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml'; if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) { return 'no perms'; } @@ -157,15 +161,16 @@ function savePDFStructureDefinitions($scope, $definition) { /** * Deletes XML file with PDF structure definitions. * - * @param string $scope account type - * @param string $definition Name of definition to delete + * @param string $typeId account type + * @param string $name Name of definition to delete * * @return boolean True if file was deleted or false if a problem occured. */ -function deletePDFStructureDefinition($scope, $definition) { - if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false; - if (!preg_match('/[a-zA-Z]+/',$scope)) return false; - $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; +function deletePDFStructure($typeId, $name) { + if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/',$typeId)) { + return false; + } + $file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml'; if(is_file($file) && is_writable($file)) { return unlink($file); } @@ -196,46 +201,50 @@ function getAvailableLogos() { return $return; } +/** + * Copies a PDF structure from the given source to target. + * + * @param \LAM\TYPES\ConfiguredType $sourceType source type + * @param string $sourceStructureName structure name + * @param \LAM\TYPES\ConfiguredType $targetType target type + * @throws Exception + */ +function copyStructure($sourceType, $sourceStructureName, $targetType) { + if (!isValidPDFStructureName($sourceStructureName)) { + throw new LAMException(_('Failed to copy')); + } + $sourceConfig = $sourceType->getTypeManager()->getConfig()->getName(); + $sourceTypeId = $sourceType->getId(); + $targetConfig = $targetType->getTypeManager()->getConfig()->getName(); + $targetTypeId = $targetType->getId(); + $basePath = dirname(__FILE__) . '/../config/pdf/'; + $src = $basePath . $sourceConfig . '/' . $sourceStructureName . '.' . $sourceTypeId; + $dst = $basePath . $targetConfig . '/' . $sourceStructureName . '.' . $targetTypeId; + if (!@copy($src, $dst)) { + throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceStructureName); + } +} /** - * Copies PDF profiles to other server profiles. + * Copies a PDF structure from the given source to global templates. * - * @param array $pdfProfiles PDF profile names - * @param String $scope account scope - * @param array $dests destinations - * - * @return boolean operation succeeded + * @param \LAM\TYPES\ConfiguredType $sourceType source type + * @param string $sourceName structure name + * @throws Exception */ -function copyPdfProfiles($pdfProfiles, $scope, $dests = array()) { - $state = true; - $profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/pdf/'; - foreach ($pdfProfiles as $profile) { - //part 1: server profile - //part 2: account profile - $tmpArr = explode('##', $profile); - $src = $profilePath . $tmpArr[0] . '/' . $tmpArr[1] . '.' . $scope . '.xml'; - if (!empty($dests)) { - foreach ($dests as $dest) { - if ($dest == 'templates*') { - $dst = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/templates/pdf/' . $tmpArr[1] . '.' . $scope . '.xml'; - } else { - $dst = $profilePath . $dest . '/' . $tmpArr[1] . '.' . $scope . '.xml'; - } - if (!@copy($src, $dst)) { - StatusMessage('ERROR', _('Failed to export!'), $tmpArr[1] . '.' . $scope . '.xml'); - $state = false; - } - } - } else { - $dst = $profilePath . $_SESSION['config']->getName() . '/' . $tmpArr[1] . '.' . $scope . '.xml'; - if (!@copy($src, $dst)) { - StatusMessage('ERROR', _('Failed to import!'), $tmpArr[1] . '.' . $scope . '.xml'); - $state = false; - } - } +function copyStructureToTemplates($sourceType, $sourceName) { + if (!isValidPDFStructureName($sourceName)) { + throw new LAMException(_('Failed to copy')); + } + $sourceConfig = $sourceType->getTypeManager()->getConfig()->getName(); + $sourceTypeId = $sourceType->getId(); + $basePath = dirname(__FILE__) . '/../config/pdf/'; + $templatePath = dirname(__FILE__) . '/../config/templates/pdf/'; + $src = $basePath . $sourceConfig . '/' . $sourceName . '.' . $sourceTypeId; + $dst = $templatePath . $sourceName . '.' . $sourceType->getScope(); + if (!@copy($src, $dst)) { + throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceName); } - - return $state; } /** @@ -285,9 +294,9 @@ function deletePDFLogo($name) { // check if still in use $activeTypes = $_SESSION['config']->get_ActiveTypes(); foreach ($activeTypes as $type) { - $structures = getPDFStructureDefinitions($type); + $structures = getPDFStructures($type); foreach ($structures as $structure) { - $data = loadPDFStructureDefinitions($type, $structure); + $data = loadPDFStructure($type, $structure); if ($data['page_definitions']['filename'] == $name) { return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, \LAM\TYPES\getTypeAlias($type))); @@ -305,4 +314,14 @@ function deletePDFLogo($name) { } } +/** + * Returns if the give structure name is valid. + * + * @param string $name structure name + * @return boolean is valid + */ +function isValidPDFStructureName($name) { + return preg_match('/[a-zA-Z0-9\-\_]+/',$name) === 1; +} + ?> diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 39a640f5..91164844 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -106,7 +106,7 @@ $container->addElement(new htmlTitle(_('PDF editor')), true); if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { // delete structure - if (\LAM\PDF\deletePDFStructureDefinition($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { + if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { $message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $message->colspan = 10; $container->addElement($message, true); @@ -171,7 +171,7 @@ foreach ($sortedTypes as $typeId => $title) { } // get list of templates for each account type for ($i = 0; $i < sizeof($templateClasses); $i++) { - $templateClasses[$i]['templates'] = \LAM\PDF\getPDFStructureDefinitions($templateClasses[$i]['typeId']); + $templateClasses[$i]['templates'] = \LAM\PDF\getPDFStructures($templateClasses[$i]['typeId']); } // check if a template should be edited @@ -286,7 +286,7 @@ include '../main_header.php'; $tmpArr = array(); foreach ($configProfiles as $profile) { if ($profile != $_SESSION['config']->getName()) { - $accountProfiles = \LAM\PDF\getPDFStructureDefinitions($typeId, $profile); + $accountProfiles = \LAM\PDF\getPDFStructures($typeId, $profile); for ($p = 0; $p < sizeof($accountProfiles); $p++) { $tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p]; } diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index b264a5a6..e1c0f225 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -129,7 +129,7 @@ if(isset($_GET['submit'])) { $saveErrors[] = array('ERROR', _('PDF structure name not valid'), _('The name for that PDF-structure you submitted is not valid. A valid name must consist of the following characters: \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\'.')); } else { - $return = \LAM\PDF\savePDFStructureDefinitions($type->getId(), $_GET['pdfname']); + $return = \LAM\PDF\savePDFStructure($type->getId(), $_GET['pdfname']); if($return == 'ok') { metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']); exit; @@ -356,14 +356,14 @@ foreach ($_GET as $key => $value) { if(!isset($_SESSION['currentPDFStructure'])) { // Load structure file to be edit if(isset($_GET['edit'])) { - $load = \LAM\PDF\loadPDFStructureDefinitions($type->getId(), $_GET['edit']); + $load = \LAM\PDF\loadPDFStructure($type->getId(), $_GET['edit']); $_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPageDefinitions'] = $load['page_definitions']; $_GET['pdfname'] = $_GET['edit']; } // Load default structure file when creating a new one else { - $load = \LAM\PDF\loadPDFStructureDefinitions($type->getId()); + $load = \LAM\PDF\loadPDFStructure($type->getId()); $_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPageDefinitions'] = $load['page_definitions']; } diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index 5701ae8f..9b580d95 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -145,9 +145,9 @@ foreach ($configProfiles as $profileName) { if (!empty($_POST['import'])) { $cfg = new LAMCfgMain(); // check master password - $impMessage = null; + $errMessage = null; if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) { - $impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); + $errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } elseif (!empty($_POST['importProfiles'])) { $options = array(); @@ -155,20 +155,20 @@ if (!empty($_POST['import'])) { $parts = explode('##', $importProfiles); $options[] = array('conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]); } - $impMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager); + $errMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager); } - if ($impMessage != null) { - $impMessage->colspan = 10; - $container->addElement($impMessage, true); + if ($errMessage != null) { + $errMessage->colspan = 10; + $container->addElement($errMessage, true); } } // export profiles if (!empty($_POST['export'])) { $cfg = new LAMCfgMain(); // check master password - $impMessage = null; + $errMessage = null; if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) { - $impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); + $errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } elseif (!empty($_POST['exportProfiles'])) { $options = array(); @@ -178,11 +178,11 @@ if (!empty($_POST['export'])) { } $typeId = $_POST['typeId']; $name = $_POST['name_' . $typeId]; - $impMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager); + $errMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager); } - if ($impMessage != null) { - $impMessage->colspan = 10; - $container->addElement($impMessage, true); + if ($errMessage != null) { + $errMessage->colspan = 10; + $container->addElement($errMessage, true); } } diff --git a/lam/templates/upload/masscreate.php b/lam/templates/upload/masscreate.php index 3cba31c9..9fad8e51 100644 --- a/lam/templates/upload/masscreate.php +++ b/lam/templates/upload/masscreate.php @@ -267,7 +267,7 @@ function showMainPage($scope, $selectedModules) { $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); $pdfCheckbox->setTableRowsToShow(array('pdfStructure')); $inputContainer->addElement($pdfCheckbox, true); - $pdfStructures = \LAM\PDF\getPDFStructureDefinitions($scope); + $pdfStructures = \LAM\PDF\getPDFStructures($scope); $pdfSelected = array(); if (isset($_POST['pdfStructure'])) { $pdfSelected = array($_POST['pdfStructure']); From 61647ed008559b921a91588a9ef48c42b3382ddf Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Thu, 5 Jan 2017 21:40:48 +0100 Subject: [PATCH 3/7] PDF import with new type API --- lam/lib/pdfstruct.inc | 8 +- lam/templates/pdfedit/pdfmain.php | 145 +++++++++++++++++++------ lam/templates/profedit/profilemain.php | 1 - 3 files changed, 118 insertions(+), 36 deletions(-) diff --git a/lam/lib/pdfstruct.inc b/lam/lib/pdfstruct.inc index 2c7132bb..977beb96 100644 --- a/lam/lib/pdfstruct.inc +++ b/lam/lib/pdfstruct.inc @@ -218,8 +218,8 @@ function copyStructure($sourceType, $sourceStructureName, $targetType) { $targetConfig = $targetType->getTypeManager()->getConfig()->getName(); $targetTypeId = $targetType->getId(); $basePath = dirname(__FILE__) . '/../config/pdf/'; - $src = $basePath . $sourceConfig . '/' . $sourceStructureName . '.' . $sourceTypeId; - $dst = $basePath . $targetConfig . '/' . $sourceStructureName . '.' . $targetTypeId; + $src = $basePath . $sourceConfig . '/' . $sourceStructureName . '.' . $sourceTypeId . '.xml'; + $dst = $basePath . $targetConfig . '/' . $sourceStructureName . '.' . $targetTypeId . '.xml'; if (!@copy($src, $dst)) { throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceStructureName); } @@ -240,8 +240,8 @@ function copyStructureToTemplates($sourceType, $sourceName) { $sourceTypeId = $sourceType->getId(); $basePath = dirname(__FILE__) . '/../config/pdf/'; $templatePath = dirname(__FILE__) . '/../config/templates/pdf/'; - $src = $basePath . $sourceConfig . '/' . $sourceName . '.' . $sourceTypeId; - $dst = $templatePath . $sourceName . '.' . $sourceType->getScope(); + $src = $basePath . $sourceConfig . '/' . $sourceName . '.' . $sourceTypeId . '.xml'; + $dst = $templatePath . $sourceName . '.' . $sourceType->getScope() . '.xml'; if (!@copy($src, $dst)) { throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceName); } diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 91164844..43470fc8 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -118,32 +118,37 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { } } -if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) { +$configProfiles = getConfigProfiles(); +$serverProfiles = array(); +foreach ($configProfiles as $profileName) { + $serverProfiles[$profileName] = new \LAMConfig($profileName); +} + +// import profiles +if (!empty($_POST['import'])) { $cfg = new LAMCfgMain(); - $impExpMessage = null; - if (isset($_POST['importProfiles_' . $_POST['typeId']])) { - // check master password - if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) { - $impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); - } - elseif (\LAM\PDF\copyPdfProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) { - $impExpMessage = new htmlStatusMessage('INFO', _('Import successful')); - } - } else if (isset($_POST['exportProfiles'])) { - // check master password - if (!$cfg->checkPassword($_POST['passwd'])) { - $impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); - } - elseif (\LAM\PDF\copyPdfProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) { - $impExpMessage = new htmlStatusMessage('INFO', _('Export successful')); - } + $typeId = $_POST['typeId']; + // check master password + $errMessage = null; + if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) { + $errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); } - if ($impExpMessage != null) { - $impExpMessage->colspan = 10; - $container->addElement($impExpMessage, true); + elseif (!empty($_POST['importProfiles_' . $typeId])) { + $options = array(); + foreach ($_POST['importProfiles_' . $typeId] as $importProfiles) { + $parts = explode('##', $importProfiles); + $options[] = array('conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]); + } + $errMessage = importStructures($_POST['typeId'], $options, $serverProfiles, $typeManager); + } + if ($errMessage != null) { + $errMessage->colspan = 10; + $container->addElement($errMessage, true); } } + + // upload logo file if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { $file = $_FILES['logoUpload']['tmp_name']; @@ -209,8 +214,6 @@ include '../main_header.php'; } // existing templates - $configProfiles = getConfigProfiles(); - $container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true); $existingContainer = new htmlTable(); for ($i = 0; $i < sizeof($templateClasses); $i++) { @@ -283,12 +286,19 @@ include '../main_header.php'; for ($i = 0; $i < sizeof($templateClasses); $i++) { $typeId = $templateClasses[$i]['typeId']; - $tmpArr = array(); + $scope = $templateClasses[$i]['scope']; + $importOptions = array(); foreach ($configProfiles as $profile) { - if ($profile != $_SESSION['config']->getName()) { - $accountProfiles = \LAM\PDF\getPDFStructures($typeId, $profile); - for ($p = 0; $p < sizeof($accountProfiles); $p++) { - $tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p]; + $typeManagerImport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]); + $typesImport = $typeManagerImport->getConfiguredTypesForScope($scope); + foreach ($typesImport as $typeImport) { + if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) { + $accountProfiles = \LAM\PDF\getPDFStructures($typeImport->getId(), $profile); + if (!empty($accountProfiles)) { + foreach ($accountProfiles as $accountProfile) { + $importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfile] = $profile . '##' . $typeImport->getId() . '##' . $accountProfile; + } + } } } } @@ -300,7 +310,7 @@ include '../main_header.php'; $container = new htmlTable(); $container->addElement(new htmlOutputText(_('PDF structures')), true); - $select = new htmlSelect('importProfiles_' . $typeId, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15); + $select = new htmlSelect('importProfiles_' . $typeId, $importOptions, array(), count($importOptions, 1) < 15 ? count($importOptions, 1) : 15); $select->setMultiSelect(true); $select->setHasDescriptiveElements(true); $select->setContainsOptgroups(true); @@ -312,11 +322,11 @@ include '../main_header.php'; $container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlOutputText(_("Master password")), true); - $exportPasswd = new htmlInputField('passwd_' . $typeId); + $exportPasswd = new htmlInputField('passwd_i_' . $typeId); $exportPasswd->setIsPassword(true); $container->addElement($exportPasswd); $container->addElement(new htmlHelpLink('236')); - $container->addElement(new htmlHiddenInput('importexport', '1')); + $container->addElement(new htmlHiddenInput('import', '1')); $container->addElement(new htmlHiddenInput('typeId', $typeId), true); addSecurityTokenToMetaHTML($container); @@ -384,4 +394,77 @@ echo ''; include '../main_footer.php'; + + +/** + * Imports the selected PDF structures. + * + * @param string $typeId type id + * @param array $options options + * @param \LAMConfig[] $serverProfiles server profiles (name => profile object) + * @param \LAM\TYPES\TypeManager $typeManager type manager + * @return \htmlStatusMessage message or null + */ +function importStructures($typeId, $options, &$serverProfiles, &$typeManager) { + foreach ($options as $option) { + $sourceConfName = $option['conf']; + $sourceTypeId = $option['typeId']; + $sourceName = $option['name']; + $sourceTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$sourceConfName]); + $sourceType = $sourceTypeManager->getConfiguredType($sourceTypeId); + $targetType = $typeManager->getConfiguredType($typeId); + if (($sourceType != null) && ($targetType != null)) { + try { + \LAM\PDF\copyStructure($sourceType, $sourceName, $targetType); + } + catch (\LAMException $e) { + return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); + } + } + } + return new \htmlStatusMessage('INFO', _('Import successful')); +} + +/** + * Exports the selected account profile. + * + * @param string $typeId source type id + * @param string $name profile name + * @param array $options options + * @param \LAMConfig[] $serverProfiles server profiles (name => profile object) + * @param \LAM\TYPES\TypeManager $typeManager type manager + * @return \htmlStatusMessage message or null + */ +function exportStructures($typeId, $name, $options, &$serverProfiles, &$typeManager) { + $sourceType = $typeManager->getConfiguredType($typeId); + if ($sourceType == null) { + return null; + } + foreach ($options as $option) { + $targetConfName = $option['conf']; + if ($targetConfName == 'templates*') { + try { + \copyAccountProfileToTemplates($sourceType, $name); + } + catch (\LAMException $e) { + return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); + } + } + else { + $targetTypeId = $option['typeId']; + $targetTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$targetConfName]); + $targetType = $targetTypeManager->getConfiguredType($targetTypeId); + if ($targetType != null) { + try { + \copyAccountProfile($sourceType, $name, $targetType); + } + catch (\LAMException $e) { + return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); + } + } + } + } + return new \htmlStatusMessage('INFO', _('Export successful')); +} + ?> diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index 9b580d95..9297e8e3 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -14,7 +14,6 @@ use \htmlOutputText; use \htmlHelpLink; use \htmlHiddenInput; use \htmlInputField; -use \htmlDiv; /* $Id$ From 164433343c4a5b5273186515d9b0b1e3917c257a Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 6 Jan 2017 10:11:29 +0100 Subject: [PATCH 4/7] fixed select --- lam/templates/profedit/profilemain.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lam/templates/profedit/profilemain.php b/lam/templates/profedit/profilemain.php index 9297e8e3..aac6bd3c 100644 --- a/lam/templates/profedit/profilemain.php +++ b/lam/templates/profedit/profilemain.php @@ -337,7 +337,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) { } $exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##'; - $select = new htmlSelect('exportProfiles', $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions) : 10); + $select = new htmlSelect('exportProfiles', $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions, 1) : 10); $select->setHasDescriptiveElements(true); $select->setContainsOptgroups(true); $select->setMultiSelect(true); From 695f94e3227ccfd0469f98232b3cbf5e85606f0e Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 6 Jan 2017 10:11:47 +0100 Subject: [PATCH 5/7] new type API for PDF --- lam/templates/pdfedit/pdfmain.php | 125 +++++++++++++++++------------- 1 file changed, 73 insertions(+), 52 deletions(-) diff --git a/lam/templates/pdfedit/pdfmain.php b/lam/templates/pdfedit/pdfmain.php index 43470fc8..acec5114 100644 --- a/lam/templates/pdfedit/pdfmain.php +++ b/lam/templates/pdfedit/pdfmain.php @@ -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 Roland Gruber @@ -72,7 +72,7 @@ if (!empty($_POST)) { setlanguage(); -// Unset pdf structure definitions in session if set +// Unset PDF structure definitions in session if set if(isset($_SESSION['currentPDFStructure'])) { unset($_SESSION['currentPDFStructure']); unset($_SESSION['currentPageDefinitions']); @@ -124,7 +124,7 @@ foreach ($configProfiles as $profileName) { $serverProfiles[$profileName] = new \LAMConfig($profileName); } -// import profiles +// import structures if (!empty($_POST['import'])) { $cfg = new LAMCfgMain(); $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 if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { @@ -334,54 +357,52 @@ include '../main_header.php'; echo ''; echo "\n"; + + //export dialog + echo "
\n"; + echo "
\n"; + + $container = new htmlTable(); + + $container->addElement(new htmlOutputText(_("Target server profile")), true); + $exportOptions = array(); + 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(); + } + } + } + $exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##'; + + $select = new htmlSelect('exportProfiles_' . $typeId, $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions, 1) : 10); + $select->setHasDescriptiveElements(true); + $select->setContainsOptgroups(true); + $select->setMultiSelect(true); + + $container->addElement($select); + $container->addElement(new htmlHelpLink('363'), true); + + $container->addElement(new htmlSpacer(null, '10px'), true); + + $container->addElement(new htmlOutputText(_("Master password")), true); + $exportPasswd = new htmlInputField('passwd_e_' . $typeId); + $exportPasswd->setIsPassword(true); + $container->addElement($exportPasswd); + $container->addElement(new htmlHelpLink('236')); + $container->addElement(new htmlHiddenInput('export', '1'), true); + $container->addElement(new htmlHiddenInput('typeId', $typeId), true); + $container->addElement(new htmlHiddenInput('name_' . $typeId, '_'), true); + addSecurityTokenToMetaHTML($container); + + parseHtml(null, $container, array(), false, $tabindex, 'user'); + + echo '
'; + echo "
\n"; } - //export dialog - echo "
\n"; - echo "
\n"; - - $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); - foreach ($configProfiles as $key => $value) { - $tmpProfiles[$value] = $value; - } - natcasesort($tmpProfiles); - $tmpProfiles['*' . _('Global templates')] = 'templates*'; - - $findProfile = array_search($_SESSION['config']->getName(), $tmpProfiles); - if ($findProfile !== false) { - unset($tmpProfiles[$findProfile]); - } - $select = new htmlSelect('destServerProfiles', $tmpProfiles, array(), count($tmpProfiles) < 10 ? count($tmpProfiles) : 10); - $select->setHasDescriptiveElements(true); - $select->setSortElements(false); - $select->setMultiSelect(true); - - $container->addElement($select); - $container->addElement(new htmlHelpLink('409'), true); - $container->addElement(new htmlSpacer(null, '10px'), true); - - $container->addElement(new htmlOutputText(_("Master password")), true); - $exportPasswd = new htmlInputField('passwd'); - $exportPasswd->setIsPassword(true); - $container->addElement($exportPasswd); - $container->addElement(new htmlHelpLink('236')); - $container->addElement(new htmlHiddenInput('importexport', '1'), true); - addSecurityTokenToMetaHTML($container); - - parseHtml(null, $container, array(), false, $tabindex, 'user'); - - echo '
'; - echo "
\n"; - // form for delete action echo '