responsive tools

This commit is contained in:
Roland Gruber 2018-05-08 20:11:53 +02:00
parent 38164082ce
commit 26356262aa
2 changed files with 48 additions and 54 deletions

View File

@ -4,11 +4,9 @@ namespace LAM\PDF;
use \htmlStatusMessage; use \htmlStatusMessage;
use \LAMException; use \LAMException;
/* /*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner Copyright (C) 2003 - 2006 Michael Duergner
2011 - 2017 Roland Gruber 2011 - 2018 Roland Gruber
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@ -207,13 +205,19 @@ function deletePDFLogo($name) {
// check if still in use // check if still in use
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$activeTypes = $typeManager->getConfiguredTypes(); $activeTypes = $typeManager->getConfiguredTypes();
$reader = new PDFStructureReader();
foreach ($activeTypes as $type) { foreach ($activeTypes as $type) {
$structures = getPDFStructures($type->getId()); $structures = getPDFStructures($type->getId());
foreach ($structures as $structure) { foreach ($structures as $structure) {
$data = loadPDFStructure($type->getId(), $structure); try {
if ($data['page_definitions']['filename'] == $name) { $data = $reader->read($type->getId(), $structure);
return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), if ($data->getLogo() == $name) {
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, $type->getAlias())); return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'),
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, $type->getAlias()));
}
}
catch (LAMException $e) {
logNewMessage(LOG_ERR, 'Error reading PDF file ' . $e->getMessage());
} }
} }
} }
@ -367,7 +371,7 @@ class PDFStructureReader {
$sections[] = $this->readSection($xml); $sections[] = $this->readSection($xml);
} }
else { else {
logNewMessage(LOG_ERR, 'Unexpected tag name: ' . $xml->name); logNewMessage(LOG_ERR, 'Unexpected tag name: ' . $xml->name . ' in ' . $file);
throw new \LAMException(_('Unable to read PDF structure.')); throw new \LAMException(_('Unable to read PDF structure.'));
} }
} }

View File

@ -1,6 +1,5 @@
<?php <?php
namespace LAM\TOOLS\PDF_EDITOR; namespace LAM\TOOLS\PDF_EDITOR;
use \htmlTable;
use \htmlTitle; use \htmlTitle;
use \htmlStatusMessage; use \htmlStatusMessage;
use \LAMCfgMain; use \LAMCfgMain;
@ -16,7 +15,6 @@ use \htmlHelpLink;
use \htmlInputField; use \htmlInputField;
use \htmlHiddenInput; use \htmlHiddenInput;
use \htmlResponsiveRow; use \htmlResponsiveRow;
use \htmlResponsiveSelect;
use \htmlGroup; use \htmlGroup;
use \LAM\TYPES\TypeManager; use \LAM\TYPES\TypeManager;
/* /*
@ -104,21 +102,19 @@ foreach ($types as $type) {
} }
natcasesort($sortedTypes); natcasesort($sortedTypes);
$container = new htmlTable(); $container = new htmlResponsiveRow();
$container->addElement(new htmlTitle(_('PDF editor')), true); $container->add(new htmlTitle(_('PDF editor')), 12);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
$typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']); $typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']);
// delete structure // delete structure
if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) { if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) {
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10; $container->add($message, 12);
$container->addElement($message, true);
} }
else { else {
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); $message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10; $container->add($message, 12);
$container->addElement($message, true);
} }
} }
@ -147,7 +143,7 @@ if (!empty($_POST['import'])) {
} }
if ($errMessage !== null) { if ($errMessage !== null) {
$errMessage->colspan = 10; $errMessage->colspan = 10;
$container->addElement($errMessage, true); $container->add($errMessage, 12);
} }
} }
@ -172,7 +168,7 @@ if (!empty($_POST['export'])) {
} }
if ($errMessage !== null) { if ($errMessage !== null) {
$errMessage->colspan = 10; $errMessage->colspan = 10;
$container->addElement($errMessage, true); $container->add($errMessage, 12);
} }
} }
@ -180,13 +176,13 @@ if (!empty($_POST['export'])) {
if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) {
$file = $_FILES['logoUpload']['tmp_name']; $file = $_FILES['logoUpload']['tmp_name'];
$filename = $_FILES['logoUpload']['name']; $filename = $_FILES['logoUpload']['name'];
$container->addElement(\LAM\PDF\uploadPDFLogo($file, $filename), true); $container->add(\LAM\PDF\uploadPDFLogo($file, $filename), 12);
} }
// delete logo file // delete logo file
if (isset($_POST['delLogo'])) { if (isset($_POST['delLogo'])) {
$toDel = $_POST['logo']; $toDel = $_POST['logo'];
$container->addElement(\LAM\PDF\deletePDFLogo($toDel), true); $container->add(\LAM\PDF\deletePDFLogo($toDel), 12);
} }
// get list of account types // get list of account types
@ -218,70 +214,64 @@ include '../../lib/adminHeader.inc';
<?php <?php
if (isset($_GET['savedSuccessfully'])) { if (isset($_GET['savedSuccessfully'])) {
$message = new htmlStatusMessage("INFO", _("PDF structure was successfully saved."), htmlspecialchars($_GET['savedSuccessfully'])); $message = new htmlStatusMessage("INFO", _("PDF structure was successfully saved."), htmlspecialchars($_GET['savedSuccessfully']));
$message->colspan = 10; $container->add($message, 12);
$container->addElement($message, true);
} }
if (isset($_GET['loadFailed'])) { if (isset($_GET['loadFailed'])) {
$message = new htmlStatusMessage("ERROR", _("Unable to read PDF structure."), htmlspecialchars($_GET['name'])); $message = new htmlStatusMessage("ERROR", _("Unable to read PDF structure."), htmlspecialchars($_GET['name']));
$message->colspan = 10; $container->add($message, 12);
$container->addElement($message, true);
} }
// new template // new template
if (!empty($availableTypes)) { if (!empty($availableTypes)) {
$container->addElement(new htmlSubTitle(_('Create a new PDF structure')), true); $container->add(new htmlSubTitle(_('Create a new PDF structure')), 12);
$newPDFContainer = new htmlTable();
$newProfileSelect = new htmlSelect('typeId', $availableTypes); $newProfileSelect = new htmlSelect('typeId', $availableTypes);
$newProfileSelect->setHasDescriptiveElements(true); $newProfileSelect->setHasDescriptiveElements(true);
$newProfileSelect->setWidth('15em'); $newProfileSelect->setWidth('15em');
$newPDFContainer->addElement($newProfileSelect); $container->addLabel($newProfileSelect);
$newPDFContainer->addElement(new htmlSpacer('10px', null)); $container->addField(new htmlButton('createNewTemplate', _('Create')));
$newPDFContainer->addElement(new htmlButton('createNewTemplate', _('Create'))); $container->addVerticalSpacer('2rem');
$container->addElement($newPDFContainer, true);
$container->addElement(new htmlSpacer(null, '10px'), true);
} }
// existing templates // existing templates
$container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true); $container->add(new htmlSubTitle(_("Manage existing PDF structures")), 12);
$existingContainer = new htmlTable();
foreach ($templateClasses as $templateClass) { foreach ($templateClasses as $templateClass) {
$existingContainer->addElement(new htmlImage('../../graphics/' . $templateClass['icon'])); $labelGroup = new htmlGroup();
$existingContainer->addElement(new htmlSpacer('3px', null)); $labelGroup->addElement(new htmlImage('../../graphics/' . $templateClass['icon']));
$existingContainer->addElement(new htmlOutputText($templateClass['title'])); $labelGroup->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlSpacer('3px', null)); $labelGroup->addElement(new htmlOutputText($templateClass['title']));
$container->add($labelGroup, 12, 4);
$select = new htmlSelect('template_' . $templateClass['typeId'], $templateClass['templates']); $select = new htmlSelect('template_' . $templateClass['typeId'], $templateClass['templates']);
$select->setWidth('15em'); $select->setWidth('15em');
$existingContainer->addElement($select); $container->add($select, 12, 4);
$existingContainer->addElement(new htmlSpacer('3px', null)); $buttonGroup = new htmlGroup();
$exEditButton = new htmlButton('editTemplate_' . $templateClass['typeId'], 'edit.png', true); $exEditButton = new htmlButton('editTemplate_' . $templateClass['typeId'], 'edit.png', true);
$exEditButton->setTitle(_('Edit')); $exEditButton->setTitle(_('Edit'));
$existingContainer->addElement($exEditButton); $buttonGroup->addElement($exEditButton);
$deleteLink = new htmlLink(null, '#', '../../graphics/delete.png'); $deleteLink = new htmlLink(null, '#', '../../graphics/delete.png');
$deleteLink->setTitle(_('Delete')); $deleteLink->setTitle(_('Delete'));
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', '" . 'template_' . $templateClass['typeId'] . "');"); $deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', '" . 'template_' . $templateClass['typeId'] . "');");
$existingContainer->addElement($deleteLink); $buttonGroup->addElement($deleteLink);
if (count($configProfiles) > 1) { if (count($configProfiles) > 1) {
$importLink = new htmlLink(null, '#', '../../graphics/import.png'); $importLink = new htmlLink(null, '#', '../../graphics/import.png');
$importLink->setTitle(_('Import PDF structures')); $importLink->setTitle(_('Import PDF structures'));
$importLink->setOnClick("showDistributionDialog('" . _("Import PDF structures") . "', '" . $importLink->setOnClick("showDistributionDialog('" . _("Import PDF structures") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', 'import');"); _('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', 'import');");
$existingContainer->addElement($importLink); $buttonGroup->addElement($importLink);
} }
$exportLink = new htmlLink(null, '#', '../../graphics/export.png'); $exportLink = new htmlLink(null, '#', '../../graphics/export.png');
$exportLink->setTitle(_('Export PDF structure')); $exportLink->setTitle(_('Export PDF structure'));
$exportLink->setOnClick("showDistributionDialog('" . _("Export PDF structure") . "', '" . $exportLink->setOnClick("showDistributionDialog('" . _("Export PDF structure") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', 'export', '" . 'template_' . $templateClass['typeId'] . "', '" . $_SESSION['config']->getName() . "');"); _('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . "', 'export', '" . 'template_' . $templateClass['typeId'] . "', '" . $_SESSION['config']->getName() . "');");
$existingContainer->addElement($exportLink); $buttonGroup->addElement($exportLink);
$existingContainer->addNewLine(); $container->add($buttonGroup, 12, 4);
$container->addVerticalSpacer('1rem');
} }
$container->addElement($existingContainer, true);
// manage logos // manage logos
$logoContainer = new htmlTable(); $container->addVerticalSpacer('4rem');
$logoContainer->addElement(new htmlSpacer(null, '30px'), true); $container->add(new htmlSubTitle(_('Manage logos')), 12);
$logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true);
$logos = \LAM\PDF\getAvailableLogos(); $logos = \LAM\PDF\getAvailableLogos();
$logoOptions = array(); $logoOptions = array();
foreach ($logos as $logo) { foreach ($logos as $logo) {
@ -291,17 +281,17 @@ include '../../lib/adminHeader.inc';
} }
$logoSelect = new htmlSelect('logo', $logoOptions, null); $logoSelect = new htmlSelect('logo', $logoOptions, null);
$logoSelect->setHasDescriptiveElements(true); $logoSelect->setHasDescriptiveElements(true);
$logoContainer->addElement($logoSelect); $container->addLabel($logoSelect);
$delLogo = new htmlButton('delLogo', _('Delete')); $delLogo = new htmlButton('delLogo', _('Delete'));
$delLogo->setIconClass('deleteButton'); $delLogo->setIconClass('deleteButton');
$logoContainer->addElement($delLogo, true); $container->addField($delLogo);
$logoContainer->addElement(new htmlInputFileUpload('logoUpload')); $container->addVerticalSpacer('2rem');
$container->addLabel(new htmlInputFileUpload('logoUpload'));
$logoUpload = new htmlButton('uploadLogo', _('Upload')); $logoUpload = new htmlButton('uploadLogo', _('Upload'));
$logoUpload->setIconClass('upButton'); $logoUpload->setIconClass('upButton');
$logoContainer->addElement($logoUpload); $container->addField($logoUpload);
$container->addElement($logoContainer, true);
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addVerticalSpacer('2rem');
// generate content // generate content
$tabindex = 1; $tabindex = 1;
parseHtml(null, $container, array(), false, $tabindex, 'user'); parseHtml(null, $container, array(), false, $tabindex, 'user');