move buttons are no more links; removed buttons to change section titles

This commit is contained in:
Roland Gruber 2013-07-30 19:48:34 +00:00
parent 2940462f96
commit 135feeaa7f
1 changed files with 201 additions and 166 deletions

View File

@ -92,6 +92,14 @@ if ((isset($_GET['foldingmarks'])) && (!isset($_SESSION['currentPageDefinitions'
$_SESSION['currentPageDefinitions']['foldingmarks'] = $_GET['foldingmarks']; $_SESSION['currentPageDefinitions']['foldingmarks'] = $_GET['foldingmarks'];
} }
// Change section headline
foreach ($_GET as $key => $value) {
if (strpos($key, 'section_') === 0) {
$pos = substr($key, strlen('section_'));
$_SESSION['currentPDFStructure'][$pos]['attributes']['NAME'] = $value;
}
}
// Check if pdfname is valid, then save current structure to file and go to // Check if pdfname is valid, then save current structure to file and go to
// main pdf structure page // main pdf structure page
$saveErrors = array(); $saveErrors = array();
@ -125,12 +133,12 @@ elseif(isset($_GET['add_text'])) {
// add a new section with text headline // add a new section with text headline
elseif(isset($_GET['add_sectionText'])) { elseif(isset($_GET['add_sectionText'])) {
// Check if name for new section is specified when needed // Check if name for new section is specified when needed
if(!isset($_GET['section_text']) || ($_GET['section_text'] == '')) { if(!isset($_GET['new_section_text']) || ($_GET['new_section_text'] == '')) {
StatusMessage('ERROR',_('No section text specified'),_('The headline for a new section must contain at least one character.')); StatusMessage('ERROR',_('No section text specified'),_('The headline for a new section must contain at least one character.'));
} }
else { else {
$attributes = array(); $attributes = array();
$attributes['NAME'] = $_GET['section_text']; $attributes['NAME'] = $_GET['new_section_text'];
$entry = array(array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes),array('tag' => 'SECTION','type' => 'close','level' => '2')); $entry = array(array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes),array('tag' => 'SECTION','type' => 'close','level' => '2'));
// Insert new field in structure // Insert new field in structure
array_splice($_SESSION['currentPDFStructure'],$_GET['add_sectionText_position'],0,$entry); array_splice($_SESSION['currentPDFStructure'],$_GET['add_sectionText_position'],0,$entry);
@ -139,7 +147,7 @@ elseif(isset($_GET['add_sectionText'])) {
// Add a new section with item as headline // Add a new section with item as headline
elseif(isset($_GET['add_section'])) { elseif(isset($_GET['add_section'])) {
$attributes = array(); $attributes = array();
$attributes['NAME'] = '_' . $_GET['section_item']; $attributes['NAME'] = '_' . $_GET['new_section_item'];
$entry = array(array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes),array('tag' => 'SECTION','type' => 'close','level' => '2')); $entry = array(array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes),array('tag' => 'SECTION','type' => 'close','level' => '2'));
// Insert new field in structure // Insert new field in structure
array_splice($_SESSION['currentPDFStructure'],$_GET['add_section_position'],0,$entry); array_splice($_SESSION['currentPDFStructure'],$_GET['add_section_position'],0,$entry);
@ -163,105 +171,43 @@ elseif(isset($_GET['add_new_field'])) {
// Insert new entry before closing section tag // Insert new entry before closing section tag
array_splice($_SESSION['currentPDFStructure'],$pos,0,array($field)); array_splice($_SESSION['currentPDFStructure'],$pos,0,array($field));
} }
// Remove section, static text or value entry from structure
elseif(isset($_GET['remove'])) { foreach ($_GET as $key => $value) {
$start = 0; // remove entry or section
// Find element to remove if (strpos($key, 'remove_') === 0) {
while($start < $_GET['remove']) { $pos = substr($key, strlen('remove_'));
next($_SESSION['currentPDFStructure']); $remove = $_SESSION['currentPDFStructure'][$pos];
$start++;
}
$remove = current($_SESSION['currentPDFStructure']);
// We have a section to remove // We have a section to remove
if($remove['tag'] == "SECTION") { if($remove['tag'] == "SECTION") {
$end = $start; $end = $pos + 1;
$current = next($_SESSION['currentPDFStructure']);
$end++;
// Find end of section to remove // Find end of section to remove
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') { while (isset($_SESSION['currentPDFStructure'][$end]) && ($_SESSION['currentPDFStructure'][$end]['tag'] != 'SECTION')
$current = next($_SESSION['currentPDFStructure']); && ($_SESSION['currentPDFStructure'][$end]['type'] != 'close')) {
$end++; $end++;
} }
// Remove complete section with all value entries in it from structure // Remove complete section with all value entries in it from structure
array_splice($_SESSION['currentPDFStructure'],$start,$end - $start + 1); array_splice($_SESSION['currentPDFStructure'], $pos, $end - $pos + 1);
} }
// We have a value entry to remove // We have a value entry to remove
elseif($remove['tag'] == "ENTRY") { elseif($remove['tag'] == "ENTRY") {
array_splice($_SESSION['currentPDFStructure'],$start,1); array_splice($_SESSION['currentPDFStructure'], $pos, 1);
} }
// We hava a static text to remove // We hava a static text to remove
elseif($remove['tag'] == "TEXT") { elseif($remove['tag'] == "TEXT") {
array_splice($_SESSION['currentPDFStructure'],$start,1); array_splice($_SESSION['currentPDFStructure'], $pos, 1);
}
}
// Move a section, static text or value entry upwards
elseif(isset($_GET['up'])) {
$tmp = $_SESSION['currentPDFStructure'][$_GET['up']];
$prev = $_SESSION['currentPDFStructure'][$_GET['up'] - 1];
// We have a section or static text to move
if($tmp['tag'] == 'SECTION' || $tmp['tag'] == 'TEXT') {
$pos = 0;
$borders = array();
$current = current($_SESSION['currentPDFStructure']);
// Add borders of sections and static text entry to array
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
elseif($current['tag'] == 'TEXT') {
$borders['open'][] = $pos;
$borders['close'][] = $pos;
}
// Find all sections and statci text fields before the section or static
// text entry to move upwards
while($pos < $_GET['up']) {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
elseif($current['tag'] == 'TEXT') {
$borders['open'][] = $pos;
$borders['close'][] = $pos;
} }
} }
// Move only when not topmost element // Move a section, static text field or value entry downwards
if(count($borders['close']) > 0) { elseif (strpos($key, 'down_') === 0) {
// We have a section to move up $index = substr($key, strlen('down_'));
if($current['tag'] == 'SECTION') { $tmp = $_SESSION['currentPDFStructure'][$index];
$current = next($_SESSION['currentPDFStructure']); $next = $_SESSION['currentPDFStructure'][$index + 1];
$pos++;
// Find end of section to move
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders['close'][] = $pos;
}
// Calculate the entries to move and move them
$cut_start = $borders['open'][count($borders['open']) - 1];
$cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1;
$insert_pos = $borders['open'][count($borders['open']) - 2];
$tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count);
array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove);
}
}
// We have a value entry to move; move it only if its not the topmost
// entry in this section
elseif($tmp['tag'] == 'ENTRY' && $prev['tag'] == 'ENTRY') {
$_SESSION['currentPDFStructure'][$_GET['up']] = $prev;
$_SESSION['currentPDFStructure'][$_GET['up'] - 1] = $tmp;
}
}
// Move a section, static text field or value entry downwards
elseif(isset($_GET['down'])) {
$tmp = $_SESSION['currentPDFStructure'][$_GET['down']];
$next = $_SESSION['currentPDFStructure'][$_GET['down'] + 1];
// We have a section or static text to move // We have a section or static text to move
if($tmp['tag'] == 'SECTION' || $tmp['tag'] == 'TEXT') { if($tmp['tag'] == 'SECTION' || $tmp['tag'] == 'TEXT') {
$pos = 0; $pos = 0;
$current = current($_SESSION['currentPDFStructure']); $current = current($_SESSION['currentPDFStructure']);
// Find section or static text entry to move // Find section or static text entry to move
while($pos < $_GET['down']) { while($pos < $index) {
$current = next($_SESSION['currentPDFStructure']); $current = next($_SESSION['currentPDFStructure']);
$pos++; $pos++;
} }
@ -320,17 +266,68 @@ elseif(isset($_GET['down'])) {
// We have a value entry to move; move it only if it is not the bottmmost // We have a value entry to move; move it only if it is not the bottmmost
// element of this section. // element of this section.
elseif($tmp['tag'] == 'ENTRY' && $next['tag'] == 'ENTRY') { elseif($tmp['tag'] == 'ENTRY' && $next['tag'] == 'ENTRY') {
$_SESSION['currentPDFStructure'][$_GET['down']] = $_SESSION['currentPDFStructure'][$_GET['down'] + 1]; $_SESSION['currentPDFStructure'][$index] = $_SESSION['currentPDFStructure'][$index + 1];
$_SESSION['currentPDFStructure'][$_GET['down'] + 1] = $tmp; $_SESSION['currentPDFStructure'][$index + 1] = $tmp;
}
}
// Move a section, static text or value entry upwards
elseif (strpos($key, 'up_') === 0) {
$index = substr($key, strlen('up_'));
$tmp = $_SESSION['currentPDFStructure'][$index];
$prev = $_SESSION['currentPDFStructure'][$index - 1];
// We have a section or static text to move
if($tmp['tag'] == 'SECTION' || $tmp['tag'] == 'TEXT') {
$pos = 0;
$borders = array();
$current = current($_SESSION['currentPDFStructure']);
// Add borders of sections and static text entry to array
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
elseif($current['tag'] == 'TEXT') {
$borders['open'][] = $pos;
$borders['close'][] = $pos;
}
// Find all sections and statci text fields before the section or static
// text entry to move upwards
while($pos < $index) {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
if($current['tag'] == 'SECTION') {
$borders[$current['type']][] = $pos;
}
elseif($current['tag'] == 'TEXT') {
$borders['open'][] = $pos;
$borders['close'][] = $pos;
}
}
// Move only when not topmost element
if(count($borders['close']) > 0) {
// We have a section to move up
if($current['tag'] == 'SECTION') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
// Find end of section to move
while($current && $current['tag'] != 'SECTION' && $current['type'] != 'close') {
$current = next($_SESSION['currentPDFStructure']);
$pos++;
}
$borders['close'][] = $pos;
}
// Calculate the entries to move and move them
$cut_start = $borders['open'][count($borders['open']) - 1];
$cut_count = $borders['close'][count($borders['close']) - 1] - $borders['open'][count($borders['open']) - 1] + 1;
$insert_pos = $borders['open'][count($borders['open']) - 2];
$tomove = array_splice($_SESSION['currentPDFStructure'],$cut_start,$cut_count);
array_splice($_SESSION['currentPDFStructure'],$insert_pos,0,$tomove);
}
}
// We have a value entry to move; move it only if its not the topmost
// entry in this section
elseif($tmp['tag'] == 'ENTRY' && $prev['tag'] == 'ENTRY') {
$_SESSION['currentPDFStructure'][$index] = $prev;
$_SESSION['currentPDFStructure'][$index - 1] = $tmp;
} }
}
// Change section headline
foreach ($_GET as $key => $value) {
if(strpos($key, 'change_') === 0) {
$alter = explode('_', $key);
$newvalue = $_GET['section_' . $alter[1]];
$_SESSION['currentPDFStructure'][$alter[1]]['attributes']['NAME'] = $newvalue;
} }
} }
@ -468,15 +465,17 @@ $mainContent->addElement(new htmlSpacer(null, '30px'), true);
// PDF structure // PDF structure
// print every entry in the current structure // print every entry in the current structure
$structureContent = new htmlTable(); $structureContent = new htmlTable();
foreach($_SESSION['currentPDFStructure'] as $key => $entry) { for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$entry = $_SESSION['currentPDFStructure'][$key];
// create the up/down/remove links // create the up/down/remove links
$linkBase = 'pdfpage.php?type=' . $_GET['type'] . '&pdfname=' . $structureName . '&headline=' . $headline . '&logoFile=' . $selectedLogo[0] . '&foldingmarks=' . $foldingMarks; $linkBase = 'pdfpage.php?type=' . $_GET['type'] . '&pdfname=' . $structureName . '&headline=' . $headline . '&logoFile=' . $selectedLogo[0] . '&foldingmarks=' . $foldingMarks;
$linkUp = new htmlLink(null, $linkBase . '&up=' . $key, '../../graphics/up.gif'); $linkUp = new htmlButton('up_' . $key, 'up.gif', true);
$linkUp->setTitle(_("Up")); $linkUp->setTitle(_("Up"));
$linkDown = new htmlLink(null, $linkBase . '&down=' . $key, '../../graphics/down.gif'); $linkDown = new htmlButton('down_' . $key, 'down.gif', true);
$linkDown->setTitle(_("Down")); $linkDown->setTitle(_("Down"));
$linkRemove = new htmlLink(null, $linkBase . '&remove=' . $key, '../../graphics/delete.gif'); $linkRemove = new htmlButton('remove_' . $key, 'delete.gif', true);
$linkRemove->setTitle(_("Remove")); $linkRemove->setTitle(_("Remove"));
$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($entry['tag'] == "SECTION" && $entry['type'] == "open") {
$name = $entry['attributes']['NAME']; $name = $entry['attributes']['NAME'];
@ -499,7 +498,6 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
$sectionHeadlineSelect->setHasDescriptiveElements(true); $sectionHeadlineSelect->setHasDescriptiveElements(true);
$sectionHeadlineGroup = new htmlGroup(); $sectionHeadlineGroup = new htmlGroup();
$sectionHeadlineGroup->addElement($sectionHeadlineSelect); $sectionHeadlineGroup->addElement($sectionHeadlineSelect);
$sectionHeadlineGroup->addElement(new htmlButton('change_' . $key, _('Change')));
$sectionHeadlineGroup->colspan = 2; $sectionHeadlineGroup->colspan = 2;
$structureContent->addElement($sectionHeadlineGroup); $structureContent->addElement($sectionHeadlineGroup);
} }
@ -508,12 +506,29 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
$sectionHeadlineInput = new htmlInputField('section_' . $key, $section_headline); $sectionHeadlineInput = new htmlInputField('section_' . $key, $section_headline);
$sectionHeadlineGroup = new htmlGroup(); $sectionHeadlineGroup = new htmlGroup();
$sectionHeadlineGroup->addElement($sectionHeadlineInput); $sectionHeadlineGroup->addElement($sectionHeadlineInput);
$sectionHeadlineGroup->addElement(new htmlButton('change_' . $key, _('Change')));
$sectionHeadlineGroup->colspan = 2; $sectionHeadlineGroup->colspan = 2;
$structureContent->addElement($sectionHeadlineGroup); $structureContent->addElement($sectionHeadlineGroup);
} }
if ($key != 0) {
$structureContent->addElement($linkUp); $structureContent->addElement($linkUp);
}
else {
$structureContent->addElement($emptyBox);
}
$hasAdditionalSections = false;
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) {
$structureContent->addElement($linkDown); $structureContent->addElement($linkDown);
}
else {
$structureContent->addElement($emptyBox);
}
$structureContent->addElement($linkRemove, true); $structureContent->addElement($linkRemove, true);
} }
// We have to include a static text. // We have to include a static text.
@ -525,8 +540,18 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
$sectionHeadlineOutput = new htmlOutputText(_('Static text')); $sectionHeadlineOutput = new htmlOutputText(_('Static text'));
$sectionHeadlineOutput->colspan = 2; $sectionHeadlineOutput->colspan = 2;
$structureContent->addElement($sectionHeadlineOutput); $structureContent->addElement($sectionHeadlineOutput);
if ($key != 0) {
$structureContent->addElement($linkUp); $structureContent->addElement($linkUp);
}
else {
$structureContent->addElement($emptyBox);
}
if ($key != sizeof($_SESSION['currentPDFStructure']) - 1) {
$structureContent->addElement($linkDown); $structureContent->addElement($linkDown);
}
else {
$structureContent->addElement($emptyBox);
}
$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($entry['value']);
@ -539,8 +564,18 @@ foreach($_SESSION['currentPDFStructure'] as $key => $entry) {
$structureContent->addElement(new htmlSpacer('10px', null)); $structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $_GET['type'])); $fieldOutput = new htmlOutputText(translateFieldIDToName($name, $_GET['type']));
$structureContent->addElement($fieldOutput); $structureContent->addElement($fieldOutput);
if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkUp); $structureContent->addElement($linkUp);
}
else {
$structureContent->addElement($emptyBox);
}
if ($_SESSION['currentPDFStructure'][$key + 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkDown); $structureContent->addElement($linkDown);
}
else {
$structureContent->addElement($emptyBox);
}
$structureContent->addElement($linkRemove, true); $structureContent->addElement($linkRemove, true);
} }
} }
@ -553,14 +588,14 @@ $container->addElement(new htmlSpacer(null, '15px'), true);
$container->addElement(new htmlSubTitle(_('New section')), true); $container->addElement(new htmlSubTitle(_('New section')), true);
$newSectionContent = new htmlTable(); $newSectionContent = new htmlTable();
// add new section with text title // add new section with text title
$newSectionContent->addElement(new htmlTableExtendedInputField(_("Headline"), 'section_text')); $newSectionContent->addElement(new htmlTableExtendedInputField(_("Headline"), 'new_section_text'));
$newSectionPositionSelect1 = new htmlTableExtendedSelect('add_sectionText_position', $sectionElements, array(), _('Position')); $newSectionPositionSelect1 = new htmlTableExtendedSelect('add_sectionText_position', $sectionElements, array(), _('Position'));
$newSectionPositionSelect1->setHasDescriptiveElements(true); $newSectionPositionSelect1->setHasDescriptiveElements(true);
$newSectionPositionSelect1->setSortElements(false); $newSectionPositionSelect1->setSortElements(false);
$newSectionContent->addElement($newSectionPositionSelect1); $newSectionContent->addElement($newSectionPositionSelect1);
$newSectionContent->addElement(new htmlButton('add_sectionText', _('Add')), true); $newSectionContent->addElement(new htmlButton('add_sectionText', _('Add')), true);
// add new section with field title // add new section with field title
$newSectionFieldSelect = new htmlTableExtendedSelect('section_item', $newFieldFieldElements, array(), _("Headline")); $newSectionFieldSelect = new htmlTableExtendedSelect('new_section_item', $newFieldFieldElements, array(), _("Headline"));
$newSectionFieldSelect->setHasDescriptiveElements(true); $newSectionFieldSelect->setHasDescriptiveElements(true);
$newSectionFieldSelect->setContainsOptgroups(true); $newSectionFieldSelect->setContainsOptgroups(true);
$newSectionContent->addElement($newSectionFieldSelect); $newSectionContent->addElement($newSectionFieldSelect);