new API: add section entries

This commit is contained in:
Roland Gruber 2017-07-01 09:59:51 +02:00
parent 677a34e9a9
commit e9bfa90336
1 changed files with 19 additions and 19 deletions

View File

@ -18,6 +18,7 @@ use LAM\PDF\PDFStructureReader;
use LAM\PDF\PDFTextSection; use LAM\PDF\PDFTextSection;
use LAM\PDF\PDFEntrySection; use LAM\PDF\PDFEntrySection;
use LAM\PDF\PDFStructure; use LAM\PDF\PDFStructure;
use LAM\PDF\PDFSectionEntry;
/* /*
$Id$ $Id$
@ -123,25 +124,6 @@ if(isset($_GET['submit'])) {
} }
} }
} }
// Add a new value field
elseif(isset($_GET['add_new_field'])) {
$field = array('tag' => 'ENTRY','type' => 'complete','level' => '3','attributes' => array('NAME' => $_GET['new_field']));
$pos = 0;
// Find begin section to insert into
while($pos < $_GET['add_field_position']) {
next($_SESSION['currentPDFStructure']);
$pos++;
}
$current = next($_SESSION['currentPDFStructure']);
$pos++;
// End of section to insert into
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
// Insert new entry before closing section tag
array_splice($_SESSION['currentPDFStructure'],$pos,0,array($field));
}
foreach ($_GET as $key => $value) { foreach ($_GET as $key => $value) {
// remove entry or section // remove entry or section
@ -320,6 +302,7 @@ if (!empty($_POST['form_submit'])) {
updateBasicSettings($_SESSION['currentPDFStructure']); updateBasicSettings($_SESSION['currentPDFStructure']);
updateSectionTitles($_SESSION['currentPDFStructure']); updateSectionTitles($_SESSION['currentPDFStructure']);
addSection($_SESSION['currentPDFStructure']); addSection($_SESSION['currentPDFStructure']);
addSectionEntry($_SESSION['currentPDFStructure']);
} }
$availablePDFFields = getAvailablePDFFields($type->getId()); $availablePDFFields = getAvailablePDFFields($type->getId());
@ -741,4 +724,21 @@ function addSection(&$structure) {
} }
} }
/**
* Adds a new entry to a section if requested.
*
* @param PDFStructure $structure
*/
function addSectionEntry(&$structure) {
if(isset($_POST['add_new_field'])) {
$field = new PDFSectionEntry($_POST['new_field']);
$sections = $structure->getSections();
$pos = $_POST['add_field_position'];
$entries = $sections[$pos]->getEntries();
$entries[] = $field;
$sections[$pos]->setEntries($entries);
$structure->setSections($sections);
}
}
?> ?>