From e9bfa903364268e24a64cbf2d7227b49b2c908a8 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Sat, 1 Jul 2017 09:59:51 +0200 Subject: [PATCH] new API: add section entries --- lam/templates/pdfedit/pdfpage.php | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lam/templates/pdfedit/pdfpage.php b/lam/templates/pdfedit/pdfpage.php index 8bb5d1f7..fab153af 100644 --- a/lam/templates/pdfedit/pdfpage.php +++ b/lam/templates/pdfedit/pdfpage.php @@ -18,6 +18,7 @@ use LAM\PDF\PDFStructureReader; use LAM\PDF\PDFTextSection; use LAM\PDF\PDFEntrySection; use LAM\PDF\PDFStructure; +use LAM\PDF\PDFSectionEntry; /* $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) { // remove entry or section @@ -320,6 +302,7 @@ if (!empty($_POST['form_submit'])) { updateBasicSettings($_SESSION['currentPDFStructure']); updateSectionTitles($_SESSION['currentPDFStructure']); addSection($_SESSION['currentPDFStructure']); + addSectionEntry($_SESSION['currentPDFStructure']); } $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); + } +} + ?>