LDAPAccountManager/lam/templates/pdfedit/pdfpage.php

693 lines
23 KiB
PHP
Raw Permalink Normal View History

<?php
2016-12-26 09:26:26 +00:00
namespace LAM\TOOLS\PDF_EDITOR;
2018-05-10 07:06:19 +00:00
use \htmlResponsiveRow;
use \htmlResponsiveSelect;
use \htmlResponsiveInputField;
2016-12-26 09:26:26 +00:00
use \htmlTitle;
use \htmlButton;
use \htmlOutputText;
use \htmlGroup;
use \htmlSelect;
use \htmlInputField;
use \htmlSubTitle;
2018-05-10 07:06:19 +00:00
use \htmlResponsiveInputTextarea;
2016-12-26 09:26:26 +00:00
use \htmlHiddenInput;
2018-05-10 07:06:19 +00:00
use \htmlSpacer;
2017-06-25 13:19:11 +00:00
use LAM\PDF\PDFStructureReader;
use LAM\PDF\PDFTextSection;
use LAM\PDF\PDFEntrySection;
2017-07-01 07:50:49 +00:00
use LAM\PDF\PDFStructure;
2017-07-01 07:59:51 +00:00
use LAM\PDF\PDFSectionEntry;
2017-07-02 07:00:14 +00:00
use LAM\PDF\PDFStructureWriter;
/*
2009-10-27 18:47:12 +00:00
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
2007-11-22 19:50:26 +00:00
Copyright (C) 2003 - 2006 Michael Duergner
2020-05-03 08:59:35 +00:00
2007 - 2020 Roland Gruber
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Manages creating/changing of pdf structures.
*/
/**
* Displays the main page of the PDF editor where the user can select the displayed entries.
*
2007-10-24 17:31:14 +00:00
* @author Michael Duergner
* @author Roland Gruber
* @package PDF
*/
2006-03-26 17:51:25 +00:00
/** security functions */
2018-12-23 16:45:01 +00:00
include_once(__DIR__ . "/../../lib/security.inc");
/** access to PDF configuration files */
2018-12-23 16:45:01 +00:00
include_once(__DIR__ . '/../../lib/pdfstruct.inc');
/** LDAP object */
2018-12-23 16:45:01 +00:00
include_once(__DIR__ . '/../../lib/ldap.inc');
/** LAM configuration */
2018-12-23 16:45:01 +00:00
include_once(__DIR__ . '/../../lib/config.inc');
/** module functions */
2018-12-23 16:45:01 +00:00
include_once(__DIR__ . '/../../lib/modules.inc');
// start session
2006-03-26 17:51:25 +00:00
startSecureSession();
2017-02-11 16:11:37 +00:00
enforceUserIsLoggedIn();
2007-12-30 13:15:39 +00:00
// die if no write access
if (!checkIfWriteAccessIsAllowed()) {
die();
}
2007-12-30 13:15:39 +00:00
2012-08-13 17:43:48 +00:00
checkIfToolIsActive('toolPDFEditor');
setlanguage();
2015-05-15 19:16:46 +00:00
if (!empty($_POST)) {
validateSecurityToken();
}
// check if user is logged in, if not go to login
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
metaRefresh("../login.php");
exit;
}
// Write $_POST variables to $_GET when form was submitted via post
2016-12-26 09:26:26 +00:00
if (isset($_POST['type'])) {
$_GET = $_POST;
}
2016-12-26 09:26:26 +00:00
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to access hidden PDF structure: ' . $type->getId());
die();
}
// Abort and go back to main pdf structure page
if(isset($_GET['abort'])) {
metarefresh('pdfmain.php');
exit;
}
// Load PDF structure from file if it is not defined in session
if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit
2020-05-07 18:22:41 +00:00
$reader = new PDFStructureReader($_SESSION['config']->getName());
2017-07-02 07:00:14 +00:00
try {
if(isset($_GET['edit'])) {
$_SESSION['currentPDFStructure'] = $reader->read($type->getId(), $_GET['edit']);
}
// Load default structure file when creating a new one
else {
$_SESSION['currentPDFStructure'] = $reader->read($type->getId(), 'default');
}
}
2017-07-02 07:00:14 +00:00
catch (\LAMException $e) {
metaRefresh('pdfmain.php?loadFailed=1&name=' . $_GET['edit']);
exit;
}
}
2017-07-01 07:50:49 +00:00
if (!empty($_POST['form_submit'])) {
updateBasicSettings($_SESSION['currentPDFStructure']);
updateSectionTitles($_SESSION['currentPDFStructure']);
addSection($_SESSION['currentPDFStructure']);
2017-07-01 07:59:51 +00:00
addSectionEntry($_SESSION['currentPDFStructure']);
2017-07-01 09:21:53 +00:00
removeItem($_SESSION['currentPDFStructure']);
2017-07-02 07:00:14 +00:00
moveUp($_SESSION['currentPDFStructure']);
moveDown($_SESSION['currentPDFStructure']);
}
// Check if pdfname is valid, then save current structure to file and go to
// main pdf structure page
$saveErrors = array();
if(isset($_GET['submit'])) {
2020-05-07 18:27:50 +00:00
$writer = new PDFStructureWriter($_SESSION['config']->getName());
2017-07-02 07:00:14 +00:00
try {
$writer->write($type->getId(), $_POST['pdfname'], $_SESSION['currentPDFStructure']);
unset($_SESSION['currentPDFStructure']);
metaRefresh('pdfmain.php?savedSuccessfully=' . $_POST['pdfname']);
exit;
}
catch (\LAMException $e) {
$saveErrors[] = array('ERROR', $e->getTitle(), $e->getMessage());
}
2017-07-01 07:50:49 +00:00
}
2017-01-04 19:52:51 +00:00
$availablePDFFields = getAvailablePDFFields($type->getId());
// Create the values for the dropdown boxes for section headline defined by
// value entries and fetch all available modules
$modules = array();
$section_items_array = array();
$section_items = '';
2010-04-05 10:13:37 +00:00
$sortedModules = array();
2017-01-04 19:52:51 +00:00
foreach($availablePDFFields as $module => $fields) {
2010-04-05 10:13:37 +00:00
if ($module != 'main') {
2016-12-26 09:26:26 +00:00
$title = getModuleAlias($module, $type->getScope());
2010-04-05 10:13:37 +00:00
}
else {
$title = _('Main');
}
$sortedModules[$module] = $title;
}
natcasesort($sortedModules);
foreach($sortedModules as $module => $title) {
2017-01-04 19:52:51 +00:00
$values = $availablePDFFields[$module];
2010-04-05 10:13:37 +00:00
if (!is_array($values) || (sizeof($values) < 1)) {
continue;
}
$modules[] = $module;
2010-04-05 10:13:37 +00:00
$section_items .= "<optgroup label=\"" . $title . "\"\n>";
natcasesort($values);
foreach($values as $attribute => $attributeLabel) {
$section_items_array[] = $module . '_' . $attribute;
2010-04-05 10:13:37 +00:00
$section_items .= "<option value=\"" . $module . '_' . $attribute . "\">" . $attributeLabel . "</option>\n";
}
2010-04-05 10:13:37 +00:00
$section_items .= "</optgroup>\n";
}
$modules = join(',',$modules);
// print header
2018-12-23 16:45:01 +00:00
include __DIR__ . '/../../lib/adminHeader.inc';
2018-05-10 07:06:19 +00:00
?>
<div class="user-bright smallPaddingContent">
<?php
// print error messages if any
if (sizeof($saveErrors) > 0) {
2017-11-04 18:27:02 +00:00
foreach ($saveErrors as $saveError) {
call_user_func_array('StatusMessage', $saveError);
}
echo "<br>\n";
}
2010-12-21 14:30:42 +00:00
$newFieldFieldElements = array();
foreach($sortedModules as $module => $title) {
2017-01-04 19:52:51 +00:00
$fields = $availablePDFFields[$module];
2010-12-21 14:30:42 +00:00
if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) {
$moduleFields = array();
foreach ($fields as $field => $fieldLabel) {
$moduleFields[$fieldLabel] = $module . "_" . $field;
}
$newFieldFieldElements[$title] = $moduleFields;
}
}
// structure name
$structureName = '';
if (isset($_GET['edit'])) {
$structureName = $_GET['edit'];
}
else if (isset($_POST['pdfname'])) {
$structureName = $_POST['pdfname'];
}
// headline
2017-07-01 07:50:49 +00:00
$headline = $_SESSION['currentPDFStructure']->getTitle();
2010-12-21 14:30:42 +00:00
// logo
2020-05-03 08:59:35 +00:00
$logoFiles = \LAM\PDF\getAvailableLogos($_SESSION['config']->getName());
2010-12-21 14:30:42 +00:00
$logos = array(_('No logo') => 'none');
foreach($logoFiles as $logoFile) {
2016-12-26 09:26:26 +00:00
$logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename'];
2010-12-21 14:30:42 +00:00
}
$selectedLogo = array('printLogo.jpg');
2017-06-25 13:19:11 +00:00
if (isset($_SESSION['currentPDFStructure'])) {
$selectedLogo = array($_SESSION['currentPDFStructure']->getLogo());
2010-12-21 14:30:42 +00:00
}
?>
2013-07-24 19:58:49 +00:00
<form id="inputForm" action="pdfpage.php" method="post" onSubmit="saveScrollPosition('inputForm')">
<?php
2017-01-04 19:52:51 +00:00
$sectionElements = array();
2010-12-21 14:30:42 +00:00
$nonTextSectionElements = array();
2018-05-10 07:06:19 +00:00
$container = new htmlResponsiveRow();
$container->add(new htmlTitle(_('PDF editor')), 12);
2010-12-21 14:30:42 +00:00
// main content
2018-05-10 07:06:19 +00:00
$mainContent = new htmlResponsiveRow();
$structureNameInput = new htmlResponsiveInputField(_("Structure name"), 'pdfname', $structureName, '360');
2010-12-21 14:30:42 +00:00
$structureNameInput->setRequired(true);
2018-05-10 07:06:19 +00:00
$mainContent->add($structureNameInput, 12);
$mainContent->add(new htmlResponsiveInputField(_('Headline'), 'headline', $headline), 12);
$logoSelect = new htmlResponsiveSelect('logoFile', $logos, $selectedLogo, _('Logo'));
2010-12-21 14:30:42 +00:00
$logoSelect->setHasDescriptiveElements(true);
2018-05-10 07:06:19 +00:00
$mainContent->add($logoSelect, 12);
2013-03-16 13:39:33 +00:00
$foldingMarks = 'no';
2017-06-25 13:19:11 +00:00
if (isset($_SESSION['currentPDFStructure'])) {
$foldingMarks = $_SESSION['currentPDFStructure']->getFoldingMarks();
2013-03-16 13:39:33 +00:00
}
$possibleFoldingMarks = array(_('No') => 'no', _('Yes') => 'standard');
2018-05-10 07:06:19 +00:00
$foldingMarksSelect = new htmlResponsiveSelect('foldingmarks', $possibleFoldingMarks, array($foldingMarks), _('Folding marks'));
2013-03-16 13:39:33 +00:00
$foldingMarksSelect->setHasDescriptiveElements(true);
2018-05-10 07:06:19 +00:00
$mainContent->add($foldingMarksSelect, 12);
$mainContent->addVerticalSpacer('3rem');
2010-12-21 14:30:42 +00:00
// PDF structure
2017-06-25 13:19:11 +00:00
$structure = $_SESSION['currentPDFStructure'];
2010-12-21 14:30:42 +00:00
// print every entry in the current structure
2018-05-10 07:06:19 +00:00
$structureContent = new htmlResponsiveRow();
2017-06-25 13:19:11 +00:00
$sections = $structure->getSections();
2017-11-04 18:27:02 +00:00
foreach ($sections as $key => $section) {
2010-12-21 14:30:42 +00:00
// create the up/down/remove links
2017-07-01 07:50:49 +00:00
$linkUp = new htmlButton('up_section_' . $key, 'up.gif', true);
2010-12-21 14:30:42 +00:00
$linkUp->setTitle(_("Up"));
2017-07-01 07:50:49 +00:00
$linkDown = new htmlButton('down_section_' . $key, 'down.gif', true);
2010-12-21 14:30:42 +00:00
$linkDown->setTitle(_("Down"));
2017-07-01 07:50:49 +00:00
$linkRemove = new htmlButton('remove_section_' . $key, 'delete.gif', true);
2010-12-21 14:30:42 +00:00
$linkRemove->setTitle(_("Remove"));
2018-05-10 07:06:19 +00:00
$emptyBox = new htmlSpacer('19px', null);
// We have a new section to start
2017-06-25 13:19:11 +00:00
if($section instanceof PDFEntrySection) {
if($section->isAttributeTitle()) {
$section_headline = translateFieldIDToName($section->getPdfKey(), $type->getScope(), $availablePDFFields);
if ($section_headline === null) {
continue;
}
2008-03-23 10:57:34 +00:00
}
else {
2017-06-25 13:19:11 +00:00
$section_headline = $section->getTitle();
2008-03-23 10:57:34 +00:00
}
2010-12-21 14:30:42 +00:00
$nonTextSectionElements[$section_headline] = $key;
$sectionElements[$section_headline] = $key;
2018-05-10 07:06:19 +00:00
$structureContent->addVerticalSpacer('2rem');
// Section headline is a value entry
2017-06-25 13:19:11 +00:00
if($section->isAttributeTitle()) {
2010-12-21 14:30:42 +00:00
$headlineElements = array();
foreach($section_items_array as $item) {
2017-01-04 19:52:51 +00:00
$headlineElements[translateFieldIDToName($item, $type->getScope(), $availablePDFFields)] = '_' . $item;
}
2017-06-25 13:19:11 +00:00
$sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array('_' . $section->getPdfKey()));
2010-12-21 14:30:42 +00:00
$sectionHeadlineSelect->setHasDescriptiveElements(true);
2018-05-10 07:06:19 +00:00
$structureContent->addLabel($sectionHeadlineSelect);
}
// Section headline is a user text
else {
2010-12-21 14:30:42 +00:00
$sectionHeadlineInput = new htmlInputField('section_' . $key, $section_headline);
2018-05-10 07:06:19 +00:00
$structureContent->addLabel($sectionHeadlineInput);
}
2018-05-10 07:06:19 +00:00
$actionGroup = new htmlGroup();
if ($key != 0) {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkUp);
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
}
2017-06-25 13:19:11 +00:00
$hasAdditionalSections = $key < (sizeof($sections) - 1);
if ($hasAdditionalSections) {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkDown);
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
}
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkRemove);
$structureContent->addField($actionGroup);
2017-06-25 13:19:11 +00:00
// add section entries
$sectionEntries = $section->getEntries();
2017-11-04 18:27:02 +00:00
foreach ($sectionEntries as $e => $sectionEntry) {
$fieldLabel = translateFieldIDToName($sectionEntry->getKey(), $type->getScope(), $availablePDFFields);
if ($fieldLabel === null) {
continue;
}
2018-05-10 07:06:19 +00:00
$structureContent->addVerticalSpacer('1rem');
$fieldOutput = new htmlOutputText($fieldLabel);
2018-05-10 07:06:19 +00:00
$structureContent->addLabel($fieldOutput);
$actionGroup = new htmlGroup();
2017-06-25 13:19:11 +00:00
if ($e != 0) {
2017-07-01 07:50:49 +00:00
$entryLinkUp = new htmlButton('up_entry_' . $key . '_' . $e, 'up.gif', true);
$entryLinkUp->setTitle(_("Up"));
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($entryLinkUp);
2017-06-25 13:19:11 +00:00
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
2017-06-25 13:19:11 +00:00
}
if ($e < (sizeof($sectionEntries) - 1)) {
2017-07-01 07:50:49 +00:00
$linkDown = new htmlButton('down_entry_' . $key . '_' . $e, 'down.gif', true);
$linkDown->setTitle(_("Down"));
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkDown);
2017-06-25 13:19:11 +00:00
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
2017-06-25 13:19:11 +00:00
}
2017-07-01 07:50:49 +00:00
$entryLinkRemove = new htmlButton('remove_entry_' . $key . '_' . $e, 'delete.gif', true);
$entryLinkRemove->setTitle(_("Remove"));
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($entryLinkRemove, true);
$structureContent->addField($actionGroup);
2017-06-25 13:19:11 +00:00
}
}
// We have to include a static text.
2017-06-25 13:19:11 +00:00
elseif($section instanceof PDFTextSection) {
// Add current satic text for dropdown box needed for the position when inserting a new
// section or static text entry
2017-07-01 07:50:49 +00:00
$textSnippet = $section->getText();
$textSnippet = str_replace(array("\n", "\r"), array(" ", " "), $textSnippet);
$textSnippet = trim($textSnippet);
if (strlen($textSnippet) > 15) {
$textSnippet = substr($textSnippet, 0, 15) . '...';
}
$textSnippet = htmlspecialchars($textSnippet);
$sectionElements[_('Static text') . ': ' . $textSnippet] = $key;
2010-12-21 14:30:42 +00:00
$sectionHeadlineOutput = new htmlOutputText(_('Static text'));
2018-05-10 07:06:19 +00:00
$structureContent->addLabel($sectionHeadlineOutput);
$actionGroup = new htmlGroup();
if ($key != 0) {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkUp);
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
}
2017-07-01 07:50:49 +00:00
if ($key != sizeof($sections) - 1) {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkDown);
}
else {
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($emptyBox);
}
2018-05-10 07:06:19 +00:00
$actionGroup->addElement($linkRemove, true);
$structureContent->addField($actionGroup);
$structureContent->addVerticalSpacer('1rem');
2017-06-25 13:19:11 +00:00
$staticTextOutput = new htmlOutputText($section->getText());
2017-06-25 07:47:32 +00:00
$staticTextOutput->setPreformatted();
2018-05-10 07:06:19 +00:00
$structureContent->add($staticTextOutput, 12);
}
}
2017-06-25 13:19:11 +00:00
$sectionElements[_('End')] = sizeof($structure->getSections());
2018-05-10 07:06:19 +00:00
$mainContent->add($structureContent, 12);
$container->add($mainContent, 12);
$container->addVerticalSpacer('2rem');
// new field
if (!empty($nonTextSectionElements)) {
$newFieldContainer = new htmlResponsiveRow();
$newFieldContainer->add(new htmlSubTitle(_('New field')), 12);
$newFieldFieldSelect = new htmlResponsiveSelect('new_field', $newFieldFieldElements, array(), _('Field'));
$newFieldFieldSelect->setHasDescriptiveElements(true);
$newFieldFieldSelect->setContainsOptgroups(true);
$newFieldContainer->add($newFieldFieldSelect, 12);
$newFieldSectionSelect = new htmlResponsiveSelect('add_field_position', $nonTextSectionElements, array(), _('Position'));
$newFieldSectionSelect->setHasDescriptiveElements(true);
$newFieldContainer->add($newFieldSectionSelect, 12);
$newFieldContainer->addLabel(new htmlOutputText('&nbsp;', false));
$newFieldContainer->addField(new htmlButton('add_new_field', _('Add')));
$container->add($newFieldContainer, 12);
}
2010-04-05 10:13:37 +00:00
2010-12-21 14:30:42 +00:00
// new section
2018-05-10 07:06:19 +00:00
$container->addVerticalSpacer('1rem');
$newSectionContent = new htmlResponsiveRow();
$newSectionContent->add(new htmlSubTitle(_('New section')), 12);
2010-12-21 14:30:42 +00:00
// add new section with text title
2018-05-10 07:06:19 +00:00
$newSectionContent->add(new htmlResponsiveInputField(_("Headline"), 'new_section_text'), 12);
$newSectionPositionSelect1 = new htmlResponsiveSelect('add_sectionText_position', $sectionElements, array(), _('Position'));
2010-12-21 14:30:42 +00:00
$newSectionPositionSelect1->setHasDescriptiveElements(true);
$newSectionPositionSelect1->setSortElements(false);
2018-05-10 07:06:19 +00:00
$newSectionContent->add($newSectionPositionSelect1, 12);
$newSectionContent->addLabel(new htmlOutputText('&nbsp;', false));
$newSectionContent->addField(new htmlButton('add_sectionText', _('Add')));
$newSectionContent->addVerticalSpacer('2rem');
2010-12-21 14:30:42 +00:00
// add new section with field title
2018-05-10 07:06:19 +00:00
$newSectionFieldSelect = new htmlResponsiveSelect('new_section_item', $newFieldFieldElements, array(), _("Headline"));
2010-12-21 14:30:42 +00:00
$newSectionFieldSelect->setHasDescriptiveElements(true);
$newSectionFieldSelect->setContainsOptgroups(true);
2018-05-10 07:06:19 +00:00
$newSectionContent->add($newSectionFieldSelect, 12);
$newSectionPositionSelect2 = new htmlResponsiveSelect('add_section_position', $sectionElements, array(), _('Position'));
2010-12-21 14:30:42 +00:00
$newSectionPositionSelect2->setHasDescriptiveElements(true);
$newSectionPositionSelect2->setSortElements(false);
2018-05-10 07:06:19 +00:00
$newSectionContent->add($newSectionPositionSelect2, 12);
$newSectionContent->addLabel(new htmlOutputText('&nbsp;', false));
$newSectionContent->addField(new htmlButton('add_section', _('Add')));
// new text area
$container->add($newSectionContent, 12);
$container->addVerticalSpacer('1rem');
$newTextFieldContent = new htmlResponsiveRow();
$newTextFieldContent->add(new htmlSubTitle(_('New text area')), 12);
$newTextFieldContent->add(new htmlResponsiveInputTextarea('text_text', '', 40, 3, _('Static text')), 12);
$newTextFieldPositionSelect = new htmlResponsiveSelect('add_text_position', $sectionElements, array(), _('Position'));
2010-12-21 14:30:42 +00:00
$newTextFieldPositionSelect->setHasDescriptiveElements(true);
$newTextFieldPositionSelect->setSortElements(false);
2018-05-10 07:06:19 +00:00
$newTextFieldContent->add($newTextFieldPositionSelect, 12);
$newTextFieldContent->addLabel(new htmlOutputText('&nbsp;', false));
$newTextFieldContent->addField(new htmlButton('add_text', _('Add')));
$newTextFieldContent->addVerticalSpacer('2rem');
$container->add($newTextFieldContent, 12);
2010-12-21 14:30:42 +00:00
// buttons
2018-05-10 07:06:19 +00:00
$buttonContainer = new htmlResponsiveRow();
2010-12-21 14:30:42 +00:00
$saveButton = new htmlButton('submit', _("Save"));
$saveButton->setIconClass('saveButton');
$cancelButton = new htmlButton('abort', _("Cancel"));
$cancelButton->setIconClass('cancelButton');
2018-05-10 07:06:19 +00:00
$buttonGroup = new htmlGroup();
$buttonGroup->addElement($saveButton);
$buttonGroup->addElement($cancelButton);
$buttonContainer->add($buttonGroup, 12);
$buttonContainer->add(new htmlHiddenInput('modules', $modules), 4);
$buttonContainer->add(new htmlHiddenInput('type', $type->getId()), 4);
$buttonContainer->add(new htmlHiddenInput('form_submit', 'true'), 4);
$container->add($buttonContainer, 12);
2015-05-15 19:16:46 +00:00
addSecurityTokenToMetaHTML($container);
2010-12-21 14:30:42 +00:00
$tabindex = 1;
2016-12-26 09:26:26 +00:00
parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
2010-12-21 14:30:42 +00:00
2013-07-24 19:58:49 +00:00
if ((sizeof($saveErrors) == 0) && isset($_POST['scrollPositionTop']) && isset($_POST['scrollPositionLeft'])) {
// scroll to last position
echo '<script type="text/javascript">
jQuery(document).ready(function() {
jQuery(window).scrollTop(' . $_POST['scrollPositionTop'] . ');
jQuery(window).scrollLeft('. $_POST['scrollPositionLeft'] . ');
});
</script>';
}
2018-05-10 07:06:19 +00:00
echo '</form></div>';
2018-12-23 16:45:01 +00:00
include __DIR__ . '/../../lib/adminFooter.inc';
2010-08-21 09:43:52 +00:00
2010-04-05 10:13:37 +00:00
/**
* Translates a given field ID (e.g. inetOrgPerson_givenName) to its descriptive name.
*
* @param String $id field ID
* @param String $scope account type
2017-01-04 19:52:51 +00:00
* @param array $availablePDFFields available PDF fields
* @return string|null field label or null if no matching module found
2010-04-05 10:13:37 +00:00
*/
2017-01-04 19:52:51 +00:00
function translateFieldIDToName($id, $scope, $availablePDFFields) {
foreach ($availablePDFFields as $module => $fields) {
2010-04-05 10:13:37 +00:00
if (!(strpos($id, $module . '_') === 0)) {
continue;
}
foreach ($fields as $name => $label) {
if ($id == $module . '_' . $name) {
if ($module == 'main') {
return _('Main') . ': ' . $label;
}
else {
return getModuleAlias($module, $scope) . ': ' . $label;
}
}
}
}
return null;
2010-04-05 10:13:37 +00:00
}
2017-07-01 07:50:49 +00:00
/**
* Updates basic settings such as logo and head line.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function updateBasicSettings(PDFStructure &$structure) {
2017-07-01 07:50:49 +00:00
// set headline
if (isset($_POST['headline'])) {
$structure->setTitle(str_replace('<', '', str_replace('>', '', $_POST['headline'])));
}
// set logo
if (isset($_POST['logoFile'])) {
$structure->setLogo($_POST['logoFile']);
}
// set folding marks
if (isset($_POST['foldingmarks'])) {
$structure->setFoldingMarks($_POST['foldingmarks']);
}
}
/**
* Updates section titles.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function updateSectionTitles(PDFStructure &$structure) {
2017-07-01 07:50:49 +00:00
$sections = $structure->getSections();
foreach ($_POST as $key => $value) {
if (strpos($key, 'section_') === 0) {
$pos = substr($key, strlen('section_'));
$sections[$pos]->setTitle($value);
}
}
}
/**
* Adds a new section if requested.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function addSection(PDFStructure &$structure) {
2017-07-01 07:50:49 +00:00
$sections = $structure->getSections();
// add a new text field
if(isset($_POST['add_text'])) {
// Check if text for static text field is specified
if(empty($_POST['text_text'])) {
StatusMessage('ERROR',_('No static text specified'),_('The static text must contain at least one character.'));
}
else {
$section = new PDFTextSection(str_replace("\r", "", $_POST['text_text']));
array_splice($sections, $_POST['add_text_position'], 0, array($section));
$structure->setSections($sections);
}
}
// add a new section with text headline
elseif(isset($_POST['add_sectionText'])) {
// Check if name for new section is specified when needed
if(empty($_POST['new_section_text'])) {
StatusMessage('ERROR',_('No section text specified'),_('The headline for a new section must contain at least one character.'));
}
else {
$section = new PDFEntrySection($_POST['new_section_text']);
array_splice($sections, $_POST['add_sectionText_position'], 0, array($section));
2017-07-01 07:50:49 +00:00
$structure->setSections($sections);
}
}
// Add a new section with item as headline
elseif(isset($_POST['add_section'])) {
$section = new PDFEntrySection('_' . $_POST['new_section_item']);
array_splice($sections, $_POST['add_section_position'], 0, array($section));
2017-07-01 07:50:49 +00:00
$structure->setSections($sections);
}
}
2017-07-01 07:59:51 +00:00
/**
* Adds a new entry to a section if requested.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function addSectionEntry(PDFStructure &$structure) {
2017-07-01 07:59:51 +00:00
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);
}
}
2017-07-01 09:21:53 +00:00
/**
* Removes a section or entry if requested.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function removeItem(PDFStructure &$structure) {
2017-07-01 09:21:53 +00:00
$sections = $structure->getSections();
foreach ($_POST as $key => $value) {
// remove section
if (strpos($key, 'remove_section_') === 0) {
$pos = substr($key, strlen('remove_section_'));
unset($sections[$pos]);
$sections = array_values($sections);
$structure->setSections($sections);
}
// remove section entry
if (strpos($key, 'remove_entry_') === 0) {
$parts = substr($key, strlen('remove_entry_'));
$parts = explode('_', $parts);
$sectionPos = $parts[0];
$entryPos = $parts[1];
$entries = $sections[$sectionPos]->getEntries();
unset($entries[$entryPos]);
$entries = array_values($entries);
$sections[$sectionPos]->setEntries($entries);
$structure->setSections($sections);
}
}
}
2017-07-02 07:00:14 +00:00
/**
* Moves up a section or entry if requested.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function moveUp(PDFStructure &$structure) {
2017-07-02 07:00:14 +00:00
$sections = $structure->getSections();
foreach ($_POST as $key => $value) {
// move section
if (strpos($key, 'up_section_') === 0) {
$pos = substr($key, strlen('up_section_'));
$sectionTmp = $sections[$pos - 1];
$sections[$pos - 1] = $sections[$pos];
$sections[$pos] = $sectionTmp;
$structure->setSections($sections);
}
// move section entry
if (strpos($key, 'up_entry_') === 0) {
$parts = substr($key, strlen('up_entry_'));
$parts = explode('_', $parts);
$sectionPos = $parts[0];
$entryPos = $parts[1];
$entries = $sections[$sectionPos]->getEntries();
$entryTmp = $entries[$entryPos - 1];
$entries[$entryPos - 1] = $entries[$entryPos];
$entries[$entryPos] = $entryTmp;
$sections[$sectionPos]->setEntries($entries);
$structure->setSections($sections);
}
}
}
/**
* Moves down a section or entry if requested.
*
* @param PDFStructure $structure
*/
2017-09-17 08:17:13 +00:00
function moveDown(PDFStructure &$structure) {
2017-07-02 07:00:14 +00:00
$sections = $structure->getSections();
foreach ($_POST as $key => $value) {
// move section
if (strpos($key, 'down_section_') === 0) {
$pos = substr($key, strlen('down_section_'));
$sectionTmp = $sections[$pos + 1];
$sections[$pos + 1] = $sections[$pos];
$sections[$pos] = $sectionTmp;
$structure->setSections($sections);
}
// move section entry
if (strpos($key, 'down_entry_') === 0) {
$parts = substr($key, strlen('down_entry_'));
$parts = explode('_', $parts);
$sectionPos = $parts[0];
$entryPos = $parts[1];
$entries = $sections[$sectionPos]->getEntries();
$entryTmp = $entries[$entryPos + 1];
$entries[$entryPos + 1] = $entries[$entryPos];
$entries[$entryPos] = $entryTmp;
$sections[$sectionPos]->setEntries($entries);
$structure->setSections($sections);
}
}
}
2010-04-05 10:13:37 +00:00
?>