new PDF API

This commit is contained in:
Roland Gruber 2017-06-25 15:19:11 +02:00
parent ba3782b685
commit 6800df7985
1 changed files with 45 additions and 51 deletions

View File

@ -14,6 +14,9 @@ use \htmlSubTitle;
use \htmlFieldset; use \htmlFieldset;
use \htmlInputTextarea; use \htmlInputTextarea;
use \htmlHiddenInput; use \htmlHiddenInput;
use LAM\PDF\PDFStructureReader;
use LAM\PDF\PDFTextSection;
use LAM\PDF\PDFEntrySection;
/* /*
$Id$ $Id$
@ -356,17 +359,14 @@ foreach ($_GET as $key => $value) {
// Load PDF structure from file if it is not defined in session // Load PDF structure from file if it is not defined in session
if(!isset($_SESSION['currentPDFStructure'])) { if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit // Load structure file to be edit
$reader = new PDFStructureReader();
if(isset($_GET['edit'])) { if(isset($_GET['edit'])) {
$load = \LAM\PDF\loadPDFStructure($type->getId(), $_GET['edit']); $_SESSION['currentPDFStructure'] = $reader->read($type->getId(), $_GET['edit']);
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
$_GET['pdfname'] = $_GET['edit']; $_GET['pdfname'] = $_GET['edit'];
} }
// Load default structure file when creating a new one // Load default structure file when creating a new one
else { else {
$load = \LAM\PDF\loadPDFStructure($type->getId()); $_SESSION['currentPDFStructure'] = $reader->read($type->getId(), 'default');
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
} }
} }
@ -450,8 +450,8 @@ foreach($logoFiles as $logoFile) {
$logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename']; $logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename'];
} }
$selectedLogo = array('printLogo.jpg'); $selectedLogo = array('printLogo.jpg');
if (isset($_SESSION['currentPageDefinitions']['filename'])) { if (isset($_SESSION['currentPDFStructure'])) {
$selectedLogo = array($_SESSION['currentPageDefinitions']['filename']); $selectedLogo = array($_SESSION['currentPDFStructure']->getLogo());
} }
?> ?>
@ -473,8 +473,8 @@ $logoSelect = new htmlTableExtendedSelect('logoFile', $logos, $selectedLogo, _('
$logoSelect->setHasDescriptiveElements(true); $logoSelect->setHasDescriptiveElements(true);
$mainContent->addElement($logoSelect, true); $mainContent->addElement($logoSelect, true);
$foldingMarks = 'no'; $foldingMarks = 'no';
if (isset($_SESSION['currentPageDefinitions']['foldingmarks'])) { if (isset($_SESSION['currentPDFStructure'])) {
$foldingMarks = $_SESSION['currentPageDefinitions']['foldingmarks']; $foldingMarks = $_SESSION['currentPDFStructure']->getFoldingMarks();
} }
$possibleFoldingMarks = array(_('No') => 'no', _('Yes') => 'standard'); $possibleFoldingMarks = array(_('No') => 'no', _('Yes') => 'standard');
$foldingMarksSelect = new htmlTableExtendedSelect('foldingmarks', $possibleFoldingMarks, array($foldingMarks), _('Folding marks')); $foldingMarksSelect = new htmlTableExtendedSelect('foldingmarks', $possibleFoldingMarks, array($foldingMarks), _('Folding marks'));
@ -482,10 +482,12 @@ $foldingMarksSelect->setHasDescriptiveElements(true);
$mainContent->addElement($foldingMarksSelect, true); $mainContent->addElement($foldingMarksSelect, true);
$mainContent->addElement(new htmlSpacer(null, '30px'), true); $mainContent->addElement(new htmlSpacer(null, '30px'), true);
// PDF structure // PDF structure
$structure = $_SESSION['currentPDFStructure'];
// print every entry in the current structure // print every entry in the current structure
$structureContent = new htmlTable(); $structureContent = new htmlTable();
for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) { $sections = $structure->getSections();
$entry = $_SESSION['currentPDFStructure'][$key]; for ($key = 0; $key < sizeof($sections); $key++) {
$section = $sections[$key];
// create the up/down/remove links // create the up/down/remove links
$linkBase = 'pdfpage.php?type=' . $type->getId() . '&pdfname=' . $structureName . '&headline=' . $headline . '&logoFile=' . $selectedLogo[0] . '&foldingmarks=' . $foldingMarks; $linkBase = 'pdfpage.php?type=' . $type->getId() . '&pdfname=' . $structureName . '&headline=' . $headline . '&logoFile=' . $selectedLogo[0] . '&foldingmarks=' . $foldingMarks;
$linkUp = new htmlButton('up_' . $key, 'up.gif', true); $linkUp = new htmlButton('up_' . $key, 'up.gif', true);
@ -496,24 +498,23 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$linkRemove->setTitle(_("Remove")); $linkRemove->setTitle(_("Remove"));
$emptyBox = new htmlOutputText(''); $emptyBox = new htmlOutputText('');
// We have a new section to start // We have a new section to start
if(($entry['tag'] == "SECTION") && ($entry['type'] == 'open')) { if($section instanceof PDFEntrySection) {
$name = $entry['attributes']['NAME']; if($section->isAttributeTitle()) {
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) { $section_headline = translateFieldIDToName($section->getPdfKey(), $type->getScope(), $availablePDFFields);
$section_headline = translateFieldIDToName(substr($name,1), $type->getScope(), $availablePDFFields);
} }
else { else {
$section_headline = $name; $section_headline = $section->getTitle();
} }
$nonTextSectionElements[$section_headline] = $key; $nonTextSectionElements[$section_headline] = $key;
$sectionElements[$section_headline] = $key; $sectionElements[$section_headline] = $key;
$structureContent->addElement(new htmlSpacer(null, '15px'), true); $structureContent->addElement(new htmlSpacer(null, '15px'), true);
// Section headline is a value entry // Section headline is a value entry
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) { if($section->isAttributeTitle()) {
$headlineElements = array(); $headlineElements = array();
foreach($section_items_array as $item) { foreach($section_items_array as $item) {
$headlineElements[translateFieldIDToName($item, $type->getScope(), $availablePDFFields)] = '_' . $item; $headlineElements[translateFieldIDToName($item, $type->getScope(), $availablePDFFields)] = '_' . $item;
} }
$sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array($name)); $sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array('_' . $section->getPdfKey()));
$sectionHeadlineSelect->setHasDescriptiveElements(true); $sectionHeadlineSelect->setHasDescriptiveElements(true);
$sectionHeadlineGroup = new htmlGroup(); $sectionHeadlineGroup = new htmlGroup();
$sectionHeadlineGroup->addElement($sectionHeadlineSelect); $sectionHeadlineGroup->addElement($sectionHeadlineSelect);
@ -534,14 +535,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
else { else {
$structureContent->addElement($emptyBox); $structureContent->addElement($emptyBox);
} }
$hasAdditionalSections = false; $hasAdditionalSections = $key < (sizeof($sections) - 1);
for ($a = $key + 1; $a < sizeof($_SESSION['currentPDFStructure']); $a++) {
if ((($_SESSION['currentPDFStructure'][$a]['tag'] == "SECTION") && ($_SESSION['currentPDFStructure'][$a]['type'] == "open"))
|| ($_SESSION['currentPDFStructure'][$a]['tag'] == "TEXT")) {
$hasAdditionalSections = true;
break;
}
}
if ($hasAdditionalSections) { if ($hasAdditionalSections) {
$structureContent->addElement($linkDown); $structureContent->addElement($linkDown);
} }
@ -549,9 +543,30 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$structureContent->addElement($emptyBox); $structureContent->addElement($emptyBox);
} }
$structureContent->addElement($linkRemove, true); $structureContent->addElement($linkRemove, true);
// add section entries
$sectionEntries = $section->getEntries();
for ($e = 0; $e < sizeof($sectionEntries); $e++) {
$sectionEntry = $sectionEntries[$e];
$structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($sectionEntry->getKey(), $type->getScope(), $availablePDFFields));
$structureContent->addElement($fieldOutput);
if ($e != 0) {
$structureContent->addElement($linkUp);
}
else {
$structureContent->addElement($emptyBox);
}
if ($e < (sizeof($sectionEntries) - 1)) {
$structureContent->addElement($linkDown);
}
else {
$structureContent->addElement($emptyBox);
}
$structureContent->addElement($linkRemove, true);
}
} }
// We have to include a static text. // We have to include a static text.
elseif($entry['tag'] == "TEXT") { elseif($section instanceof PDFTextSection) {
// Add current satic text for dropdown box needed for the position when inserting a new // Add current satic text for dropdown box needed for the position when inserting a new
// section or static text entry // section or static text entry
$sectionElements[_('Static text')] = $key + 1; $sectionElements[_('Static text')] = $key + 1;
@ -573,33 +588,12 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
} }
$structureContent->addElement($linkRemove, true); $structureContent->addElement($linkRemove, true);
$structureContent->addElement(new htmlSpacer('10px', null)); $structureContent->addElement(new htmlSpacer('10px', null));
$staticTextOutput = new htmlOutputText($entry['value']); $staticTextOutput = new htmlOutputText($section->getText());
$staticTextOutput->setPreformatted(); $staticTextOutput->setPreformatted();
$structureContent->addElement($staticTextOutput, true); $structureContent->addElement($staticTextOutput, true);
} }
// We have to include an entry from the account
elseif($entry['tag'] == "ENTRY") {
// Get name of current entry
$name = $entry['attributes']['NAME'];
$structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope(), $availablePDFFields));
$structureContent->addElement($fieldOutput);
if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkUp);
}
else {
$structureContent->addElement($emptyBox);
}
if ($_SESSION['currentPDFStructure'][$key + 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkDown);
}
else {
$structureContent->addElement($emptyBox);
}
$structureContent->addElement($linkRemove, true);
}
} }
$sectionElements[_('End')] = sizeof($_SESSION['currentPDFStructure']); $sectionElements[_('End')] = sizeof($structure->getSections());
$structureContent->colspan = 3; $structureContent->colspan = 3;
$mainContent->addElement($structureContent); $mainContent->addElement($structureContent);
$container->addElement(new htmlFieldset($mainContent), true); $container->addElement(new htmlFieldset($mainContent), true);