| 1 |
<?php |
| 2 |
namespace LAM\TOOLS\PDF_EDITOR; |
| 3 |
use htmlDiv; |
| 4 |
use htmlForm; |
| 5 |
use htmlResponsiveInputField; |
| 6 |
use htmlResponsiveSelect; |
| 7 |
use htmlTitle; |
| 8 |
use htmlStatusMessage; |
| 9 |
use LAM\PDF\PdfStructurePersistenceManager; |
| 10 |
use LAMCfgMain; |
| 11 |
use htmlSubTitle; |
| 12 |
use htmlSelect; |
| 13 |
use htmlImage; |
| 14 |
use htmlSpacer; |
| 15 |
use htmlButton; |
| 16 |
use htmlLink; |
| 17 |
use htmlOutputText; |
| 18 |
use htmlInputFileUpload; |
| 19 |
use htmlHelpLink; |
| 20 |
use htmlInputField; |
| 21 |
use htmlHiddenInput; |
| 22 |
use htmlResponsiveRow; |
| 23 |
use htmlGroup; |
| 24 |
use LAM\TYPES\TypeManager; |
| 25 |
use LAMConfig; |
| 26 |
use LAMException; |
| 27 |
use ServerProfilePersistenceManager; |
| 28 |
|
| 29 |
/* |
| 30 |
|
| 31 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 32 |
Copyright (C) 2003 - 2006 Michael Duergner |
| 33 |
2005 - 2026 Roland Gruber |
| 34 |
|
| 35 |
This program is free software; you can redistribute it and/or modify |
| 36 |
it under the terms of the GNU General Public License as published by |
| 37 |
the Free Software Foundation; either version 2 of the License, or |
| 38 |
(at your option) any later version. |
| 39 |
|
| 40 |
This program is distributed in the hope that it will be useful, |
| 41 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 |
GNU General Public License for more details. |
| 44 |
|
| 45 |
You should have received a copy of the GNU General Public License |
| 46 |
along with this program; if not, write to the Free Software |
| 47 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 48 |
|
| 49 |
*/ |
| 50 |
|
| 51 |
/** |
| 52 |
* This is the main window of the PDF structure editor. |
| 53 |
* |
| 54 |
* @author Michael Duergner |
| 55 |
* @author Roland Gruber |
| 56 |
* @package PDF |
| 57 |
*/ |
| 58 |
|
| 59 |
/** security functions */ |
| 60 |
include_once(__DIR__ . "/../../lib/security.inc"); |
| 61 |
/** access to PDF configuration files */ |
| 62 |
include_once(__DIR__ . "/../../lib/pdfstruct.inc"); |
| 63 |
/** LDAP object */ |
| 64 |
include_once(__DIR__ . "/../../lib/ldap.inc"); |
| 65 |
/** for language settings */ |
| 66 |
include_once(__DIR__ . "/../../lib/config.inc"); |
| 67 |
/** module functions */ |
| 68 |
include_once(__DIR__ . "/../../lib/modules.inc"); |
| 69 |
|
| 70 |
// start session |
| 71 |
startSecureSession(); |
| 72 |
enforceUserIsLoggedIn(); |
| 73 |
|
| 74 |
// die if no write access |
| 75 |
if (!checkIfWriteAccessIsAllowed()) { |
| 76 |
die(); |
| 77 |
} |
| 78 |
|
| 79 |
checkIfToolIsActive('toolPDFEditor'); |
| 80 |
|
| 81 |
if (!empty($_POST)) { |
| 82 |
validateSecurityToken(); |
| 83 |
} |
| 84 |
|
| 85 |
setlanguage(); |
| 86 |
|
| 87 |
// Unset PDF structure definitions in session if set |
| 88 |
if(isset($_SESSION['currentPDFStructure'])) { |
| 89 |
unset($_SESSION['currentPDFStructure']); |
| 90 |
} |
| 91 |
|
| 92 |
// check if user is logged in, if not go to login |
| 93 |
if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) { |
| 94 |
metaRefresh("../login.php"); |
| 95 |
exit; |
| 96 |
} |
| 97 |
|
| 98 |
// check if new template should be created |
| 99 |
if(isset($_POST['createNewTemplate'])) { |
| 100 |
metaRefresh('pdfpage.php?type=' . htmlspecialchars($_POST['typeId'])); |
| 101 |
exit(); |
| 102 |
} |
| 103 |
|
| 104 |
$typeManager = new TypeManager(); |
| 105 |
$types = $typeManager->getConfiguredTypes(); |
| 106 |
$sortedTypes = []; |
| 107 |
foreach ($types as $type) { |
| 108 |
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) { |
| 109 |
continue; |
| 110 |
} |
| 111 |
$sortedTypes[$type->getId()] = $type->getAlias(); |
| 112 |
} |
| 113 |
natcasesort($sortedTypes); |
| 114 |
|
| 115 |
$pdfStructurePersistenceManager = new PdfStructurePersistenceManager(); |
| 116 |
|
| 117 |
$container = new htmlResponsiveRow(); |
| 118 |
$container->add(new htmlTitle(_('PDF editor'))); |
| 119 |
|
| 120 |
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { |
| 121 |
$typeToDelete = $typeManager->getConfiguredType($_POST['profileDeleteType']); |
| 122 |
// delete structure |
| 123 |
try { |
| 124 |
if ($typeToDelete !== null) { |
| 125 |
$pdfStructurePersistenceManager->deletePdfStructure($_SESSION['config']->getName(), $_POST['profileDeleteType'], $_POST['profileDeleteName']); |
| 126 |
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); |
| 127 |
$container->add($message); |
| 128 |
} |
| 129 |
} |
| 130 |
catch (LAMException $e) { |
| 131 |
logNewMessage(LOG_ERR, $e->getTitle() . ' ' . $e->getMessage()); |
| 132 |
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), $typeToDelete->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName'])); |
| 133 |
$container->add($message); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
// delete global template |
| 138 |
if (isset($_POST['deleteGlobalTemplate']) && !empty($_POST['globalTemplatesDelete'])) { |
| 139 |
$cfg = new LAMCfgMain(); |
| 140 |
if (empty($_POST['globalTemplateDeletePassword']) || !$cfg->checkPassword($_POST['globalTemplateDeletePassword'])) { |
| 141 |
$container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); |
| 142 |
} |
| 143 |
else { |
| 144 |
$selectedOptions = explode(':', $_POST['globalTemplatesDelete']); |
| 145 |
$selectedScope = $selectedOptions[0]; |
| 146 |
$selectedName = $selectedOptions[1]; |
| 147 |
try { |
| 148 |
$pdfStructurePersistenceManager->deletePdfStructureTemplate($selectedScope, $selectedName); |
| 149 |
$container->add(new htmlStatusMessage('INFO', _('Deleted profile.'), $selectedName)); |
| 150 |
} catch (LAMException $e) { |
| 151 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
|
| 156 |
// delete global logo |
| 157 |
if (isset($_POST['deleteGlobalLogo']) && !empty($_POST['globalLogoDelete'])) { |
| 158 |
$cfg = new LAMCfgMain(); |
| 159 |
if (empty($_POST['globalLogoDeletePassword']) || !$cfg->checkPassword($_POST['globalLogoDeletePassword'])) { |
| 160 |
$container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); |
| 161 |
} |
| 162 |
else { |
| 163 |
$selectedLogo = $_POST['globalLogoDelete']; |
| 164 |
try { |
| 165 |
$pdfStructurePersistenceManager->deletePdfTemplateLogo($selectedLogo); |
| 166 |
$container->add(new htmlStatusMessage('INFO', _('Logo file deleted.'), $selectedLogo)); |
| 167 |
} catch (LAMException $e) { |
| 168 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 169 |
} |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
$serverProfilePersistenceManager = new ServerProfilePersistenceManager(); |
| 174 |
$serverProfiles = []; |
| 175 |
$configProfiles = []; |
| 176 |
try { |
| 177 |
$configProfiles = $serverProfilePersistenceManager->getProfiles(); |
| 178 |
foreach ($configProfiles as $profileName) { |
| 179 |
$serverProfiles[$profileName] = $serverProfilePersistenceManager->loadProfile($profileName); |
| 180 |
} |
| 181 |
} catch (LAMException $e) { |
| 182 |
logNewMessage(LOG_ERR, 'Unable to read server profiles: ' . $e->getTitle()); |
| 183 |
} |
| 184 |
|
| 185 |
// import structures |
| 186 |
if (!empty($_POST['import'])) { |
| 187 |
$cfg = new LAMCfgMain(); |
| 188 |
$typeId = $_POST['typeId']; |
| 189 |
// check master password |
| 190 |
$errMessage = null; |
| 191 |
if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) { |
| 192 |
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); |
| 193 |
} |
| 194 |
elseif (!empty($_POST['importProfiles_' . $typeId])) { |
| 195 |
$options = []; |
| 196 |
foreach ($_POST['importProfiles_' . $typeId] as $importProfiles) { |
| 197 |
$parts = explode('##', $importProfiles); |
| 198 |
$options[] = ['conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]]; |
| 199 |
} |
| 200 |
$errMessage = importStructures($_POST['typeId'], $options, $serverProfiles, $typeManager); |
| 201 |
} |
| 202 |
if ($errMessage !== null) { |
| 203 |
$container->add($errMessage); |
| 204 |
} |
| 205 |
} |
| 206 |
|
| 207 |
// export structures |
| 208 |
if (!empty($_POST['export'])) { |
| 209 |
$cfg = new LAMCfgMain(); |
| 210 |
$typeId = $_POST['typeId']; |
| 211 |
// check master password |
| 212 |
$errMessage = null; |
| 213 |
if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) { |
| 214 |
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); |
| 215 |
} |
| 216 |
elseif (!empty($_POST['exportProfiles_' . $typeId])) { |
| 217 |
$options = []; |
| 218 |
foreach ($_POST['exportProfiles_' . $typeId] as $importProfiles) { |
| 219 |
$parts = explode('##', $importProfiles); |
| 220 |
$options[] = ['conf' => $parts[0], 'typeId' => $parts[1]]; |
| 221 |
} |
| 222 |
$name = $_POST['name_' . $typeId]; |
| 223 |
$errMessage = exportStructures($typeId, $name, $options, $serverProfiles, $typeManager); |
| 224 |
} |
| 225 |
if ($errMessage !== null) { |
| 226 |
$container->add($errMessage); |
| 227 |
} |
| 228 |
} |
| 229 |
|
| 230 |
// upload logo file |
| 231 |
if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) { |
| 232 |
$file = $_FILES['logoUpload']['tmp_name']; |
| 233 |
$handle = fopen($file, "r"); |
| 234 |
try { |
| 235 |
if ($handle === false) { |
| 236 |
throw new LAMException(_('Unable to create temporary file.')); |
| 237 |
} |
| 238 |
$data = fread($handle, 100_000_000); |
| 239 |
if ($data === false) { |
| 240 |
throw new LAMException(_('Unable to create temporary file.')); |
| 241 |
} |
| 242 |
fclose($handle); |
| 243 |
$filename = trim((string) $_FILES['logoUpload']['name']); |
| 244 |
$pdfStructurePersistenceManager->savePdfLogo($_SESSION['config']->getName(), $filename, $data); |
| 245 |
$container->add(new htmlStatusMessage('INFO', _('Uploaded logo file.'), $filename)); |
| 246 |
} |
| 247 |
catch (LAMException $e) { |
| 248 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 249 |
} |
| 250 |
} |
| 251 |
|
| 252 |
// delete logo file |
| 253 |
if (isset($_POST['delLogo'])) { |
| 254 |
$toDel = $_POST['logo']; |
| 255 |
try { |
| 256 |
$pdfStructurePersistenceManager->deletePdfLogo($_SESSION['config']->getName(), $toDel); |
| 257 |
$container->add(new htmlStatusMessage('INFO', _('Logo file deleted.'), $toDel)); |
| 258 |
} |
| 259 |
catch (LAMException $e) { |
| 260 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
// export logo |
| 265 |
if (!empty($_POST['exportLogoTargetProfile'])) { |
| 266 |
$cfg = new LAMCfgMain(); |
| 267 |
if (!$cfg->checkPassword($_POST['exportLogoPassword'])) { |
| 268 |
$container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); |
| 269 |
} |
| 270 |
else { |
| 271 |
try { |
| 272 |
foreach ($_POST['exportLogoTargetProfile'] as $targetProfile) { |
| 273 |
$fileName = $_POST['exportLogoName']; |
| 274 |
$binary = $pdfStructurePersistenceManager->getPdfLogoBinary($_SESSION['config']->getName(), $fileName); |
| 275 |
if ($targetProfile === 'templates*') { |
| 276 |
$pdfStructurePersistenceManager->savePdfTemplateLogo($fileName, $binary); |
| 277 |
} |
| 278 |
else { |
| 279 |
$pdfStructurePersistenceManager->savePdfLogo($targetProfile, $fileName, $binary); |
| 280 |
} |
| 281 |
} |
| 282 |
$container->add(new htmlStatusMessage('INFO', _('Exported logo file.'))); |
| 283 |
} |
| 284 |
catch (LAMException $e) { |
| 285 |
$container->add(new htmlStatusMessage($e->getTitle(), $e->getMessage())); |
| 286 |
} |
| 287 |
} |
| 288 |
} |
| 289 |
|
| 290 |
// import logo |
| 291 |
if (!empty($_POST['importLogoSourceProfile'])) { |
| 292 |
$cfg = new LAMCfgMain(); |
| 293 |
if (!$cfg->checkPassword($_POST['importLogoPassword'])) { |
| 294 |
$container->add(new htmlStatusMessage('ERROR', _('Master password is wrong!'))); |
| 295 |
} |
| 296 |
else { |
| 297 |
try { |
| 298 |
foreach ($_POST['importLogoSourceProfile'] as $sourceLogo) { |
| 299 |
$parts = explode('##', $sourceLogo); |
| 300 |
if (count($parts) !== 2) { |
| 301 |
continue; |
| 302 |
} |
| 303 |
$profileName = $parts[0]; |
| 304 |
$fileName = $parts[1]; |
| 305 |
$binary = $pdfStructurePersistenceManager->getPdfLogoBinary($profileName, $fileName); |
| 306 |
$pdfStructurePersistenceManager->savePdfLogo($_SESSION['config']->getName(), $fileName, $binary); |
| 307 |
} |
| 308 |
$container->add(new htmlStatusMessage('INFO', _('Logo import successful.'))); |
| 309 |
} |
| 310 |
catch (LAMException $e) { |
| 311 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 312 |
} |
| 313 |
} |
| 314 |
} |
| 315 |
|
| 316 |
// get list of account types |
| 317 |
$availableTypes = []; |
| 318 |
$templateClasses = []; |
| 319 |
foreach ($sortedTypes as $typeId => $title) { |
| 320 |
$type = $typeManager->getConfiguredType($typeId); |
| 321 |
if ($type === null) { |
| 322 |
continue; |
| 323 |
} |
| 324 |
$templateClasses[] = [ |
| 325 |
'typeId' => $type->getId(), |
| 326 |
'scope' => $type->getScope(), |
| 327 |
'title' => $title, |
| 328 |
'icon' => $type->getIcon(), |
| 329 |
'templates' => $pdfStructurePersistenceManager->getPDFStructures($_SESSION['config']->getName(), $type->getId()) |
| 330 |
]; |
| 331 |
$availableTypes[$title] = $type->getId(); |
| 332 |
} |
| 333 |
// check if a template should be edited |
| 334 |
foreach ($templateClasses as $templateClass) { |
| 335 |
if (isset($_POST['editTemplate_' . $templateClass['typeId']]) || isset($_POST['editTemplate_' . $templateClass['typeId'] . '_x'])) { |
| 336 |
metaRefresh('pdfpage.php?type=' . htmlspecialchars($templateClass['typeId']) . '&edit=' . htmlspecialchars($_POST['template_' . $templateClass['typeId']])); |
| 337 |
exit; |
| 338 |
} |
| 339 |
} |
| 340 |
include __DIR__ . '/../../lib/adminHeader.inc'; |
| 341 |
|
| 342 |
?> |
| 343 |
<div class="smallPaddingContent"> |
| 344 |
<form enctype="multipart/form-data" action="pdfmain.php" method="post" name="pdfmainForm" > |
| 345 |
<input type="hidden" name="<?php echo getSecurityTokenName(); ?>" value="<?php echo getSecurityTokenValue(); ?>"> |
| 346 |
<?php |
| 347 |
if (isset($_GET['savedSuccessfully'])) { |
| 348 |
$message = new htmlStatusMessage("INFO", _("PDF structure was successfully saved."), htmlspecialchars($_GET['savedSuccessfully'])); |
| 349 |
$container->add($message); |
| 350 |
} |
| 351 |
|
| 352 |
if (isset($_GET['loadFailed'])) { |
| 353 |
$message = new htmlStatusMessage("ERROR", _("Unable to read PDF structure."), htmlspecialchars($_GET['name'])); |
| 354 |
$container->add($message); |
| 355 |
} |
| 356 |
|
| 357 |
// new template |
| 358 |
if (!empty($availableTypes)) { |
| 359 |
$container->add(new htmlSubTitle(_('Create a new PDF structure'))); |
| 360 |
$newProfileSelect = new htmlSelect('typeId', $availableTypes); |
| 361 |
$newProfileSelect->setHasDescriptiveElements(true); |
| 362 |
$container->addLabel($newProfileSelect); |
| 363 |
$createButton = new htmlButton('createNewTemplate', _('Create')); |
| 364 |
$createButton->setCSSClasses(['lam-primary']); |
| 365 |
$container->addField($createButton); |
| 366 |
$container->addVerticalSpacer('2rem'); |
| 367 |
} |
| 368 |
|
| 369 |
// existing templates |
| 370 |
$container->add(new htmlSubTitle(_("Manage existing PDF structures"))); |
| 371 |
foreach ($templateClasses as $templateClass) { |
| 372 |
$labelGroup = new htmlGroup(); |
| 373 |
$labelGroup->addElement(new htmlImage('../../graphics/' . $templateClass['icon'], '16px', '16px')); |
| 374 |
$labelGroup->addElement(new htmlSpacer('3px', null)); |
| 375 |
$labelGroup->addElement(new htmlOutputText($templateClass['title'])); |
| 376 |
$container->add($labelGroup, 12, 4); |
| 377 |
$select = new htmlSelect('template_' . $templateClass['typeId'], $templateClass['templates']); |
| 378 |
$container->add($select, 12, 4); |
| 379 |
$buttonGroup = new htmlGroup(); |
| 380 |
$exEditButton = new htmlButton('editTemplate_' . $templateClass['typeId'], 'edit.svg', true); |
| 381 |
$exEditButton->setTitle(_('Edit')); |
| 382 |
$buttonGroup->addElement($exEditButton); |
| 383 |
$deleteLink = new htmlLink('', '#', '../../graphics/del.svg'); |
| 384 |
$deleteLink->setTitle(_('Delete')); |
| 385 |
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . |
| 386 |
_('Cancel') . "', '" . $templateClass['typeId'] . "', '" . 'template_' . |
| 387 |
$templateClass['typeId'] . "'); return false;"); |
| 388 |
$deleteLink->setCSSClasses(['margin3']); |
| 389 |
$buttonGroup->addElement($deleteLink); |
| 390 |
|
| 391 |
if (count($configProfiles) > 1) { |
| 392 |
$importLink = new htmlLink('', '#', '../../graphics/import.svg'); |
| 393 |
$importLink->setTitle(_('Import PDF structures')); |
| 394 |
$importLink->setOnClick("window.lam.profilePdfEditor.showDistributionDialog('" . _("Import PDF structures") . "', '" . |
| 395 |
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . |
| 396 |
"', 'import'); return false;"); |
| 397 |
$importLink->setCSSClasses(['margin3']); |
| 398 |
$buttonGroup->addElement($importLink); |
| 399 |
} |
| 400 |
$exportLink = new htmlLink('', '#', '../../graphics/export.svg'); |
| 401 |
$exportLink->setTitle(_('Export PDF structure')); |
| 402 |
$exportLink->setOnClick("window.lam.profilePdfEditor.showDistributionDialog('" . _("Export PDF structure") . "', '" . |
| 403 |
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClass['typeId'] . |
| 404 |
"', 'export', '" . 'template_' . $templateClass['typeId'] . "', '" . |
| 405 |
$_SESSION['config']->getName() . "'); return false;"); |
| 406 |
$exportLink->setCSSClasses(['margin3']); |
| 407 |
$buttonGroup->addElement($exportLink); |
| 408 |
$container->add($buttonGroup, 12, 4); |
| 409 |
$container->addVerticalSpacer('1rem'); |
| 410 |
} |
| 411 |
|
| 412 |
// manage logos |
| 413 |
$container->addVerticalSpacer('4rem'); |
| 414 |
$container->add(new htmlSubTitle(_('Manage logos'))); |
| 415 |
$logoOptions = []; |
| 416 |
try { |
| 417 |
$logos = $pdfStructurePersistenceManager->getPdfLogos($_SESSION['config']->getName(), true); |
| 418 |
foreach ($logos as $logo) { |
| 419 |
$file = $logo->getName(); |
| 420 |
$label = $file . ' (' . $logo->getWidth() . ' x ' . $logo->getHeight() . ")"; |
| 421 |
$logoOptions[$label] = $file; |
| 422 |
} |
| 423 |
} catch (LAMException $e) { |
| 424 |
$container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage())); |
| 425 |
} |
| 426 |
$logoSelect = new htmlSelect('logo', $logoOptions, []); |
| 427 |
$logoSelect->setHasDescriptiveElements(true); |
| 428 |
$container->addLabel($logoSelect); |
| 429 |
$logoButtonGroup = new htmlGroup(); |
| 430 |
$delLogo = new htmlButton('delLogo', 'del.svg', true); |
| 431 |
$delLogo->setTitle(_('Delete')); |
| 432 |
$logoButtonGroup->addElement($delLogo); |
| 433 |
$importLogoLink = new htmlLink('', '#', '../../graphics/import.svg'); |
| 434 |
$importLogoLink->setTitle(_('Import logo')); |
| 435 |
$importLogoLink->setOnClick("window.lam.profilePdfEditor.showPdfLogoImportDialog('" . _("Import logo") . "', '" . |
| 436 |
_('Ok') . "', '" . _('Cancel') . "'); return false;"); |
| 437 |
$importLogoLink->setCSSClasses(['margin3']); |
| 438 |
$logoButtonGroup->addElement($importLogoLink); |
| 439 |
$exportLogoLink = new htmlLink('', '#', '../../graphics/export.svg'); |
| 440 |
$exportLogoLink->setTitle(_('Export logo')); |
| 441 |
$exportLogoLink->setOnClick("window.lam.profilePdfEditor.showPdfLogoExportDialog('" . _("Export logo") . "', '" . |
| 442 |
_('Ok') . "', '" . _('Cancel') . "'); return false;"); |
| 443 |
$exportLogoLink->setCSSClasses(['margin3']); |
| 444 |
$logoButtonGroup->addElement($exportLogoLink); |
| 445 |
$container->addField($logoButtonGroup); |
| 446 |
$container->addVerticalSpacer('2rem'); |
| 447 |
$container->addLabel(new htmlInputFileUpload('logoUpload')); |
| 448 |
$logoUpload = new htmlButton('uploadLogo', _('Upload')); |
| 449 |
$logoUpload->setCSSClasses(['lam-secondary']); |
| 450 |
$container->addField($logoUpload); |
| 451 |
|
| 452 |
$container->addVerticalSpacer('4rem'); |
| 453 |
// generate content |
| 454 |
parseHtml(null, $container, [], false, 'user'); |
| 455 |
|
| 456 |
echo "</form>\n"; |
| 457 |
|
| 458 |
// export logo form |
| 459 |
$container = new htmlResponsiveRow(); |
| 460 |
$logoExportFormContent = new htmlResponsiveRow(); |
| 461 |
$exportOptions = []; |
| 462 |
foreach ($configProfiles as $profile) { |
| 463 |
if ($profile != $_SESSION['config']->getName()) { |
| 464 |
$exportOptions[$profile] = $profile; |
| 465 |
} |
| 466 |
} |
| 467 |
asort($exportOptions); |
| 468 |
$exportOptions['*' . _('Global templates')] = 'templates*'; |
| 469 |
$logoExportConfigSelect = new htmlResponsiveSelect('exportLogoTargetProfile', $exportOptions, [], _('Target server profile'), null, 5); |
| 470 |
$logoExportConfigSelect->setHasDescriptiveElements(true); |
| 471 |
$logoExportConfigSelect->setSortElements(false); |
| 472 |
$logoExportConfigSelect->setMultiSelect(true); |
| 473 |
$logoExportFormContent->add($logoExportConfigSelect); |
| 474 |
$logoExportFormContent->addVerticalSpacer('1rem'); |
| 475 |
$logoExportFormContent->addLabel(new htmlOutputText('')); |
| 476 |
$logoExportFormContent->addField(new htmlHiddenInput('exportLogoName', '')); |
| 477 |
$logoExportFormPwd = new htmlResponsiveInputField(_("Master password"), 'exportLogoPassword', null, '236'); |
| 478 |
$logoExportFormPwd->setIsPassword(true); |
| 479 |
$logoExportFormContent->add($logoExportFormPwd); |
| 480 |
addSecurityTokenToMetaHTML($logoExportFormContent); |
| 481 |
$logoExportForm = new htmlForm('logoExportForm', 'pdfmain.php', $logoExportFormContent); |
| 482 |
$logoExportDialog = new htmlDiv('logoExportDiv', $logoExportForm, ['hidden']); |
| 483 |
$container->add($logoExportDialog); |
| 484 |
parseHtml(null, $container, [], false, 'user'); |
| 485 |
|
| 486 |
// import logo form |
| 487 |
$container = new htmlResponsiveRow(); |
| 488 |
$logoImportFormContent = new htmlResponsiveRow(); |
| 489 |
$importOptions = []; |
| 490 |
foreach ($configProfiles as $profileName) { |
| 491 |
if ($profileName != $_SESSION['config']->getName()) { |
| 492 |
$availableLogos = $pdfStructurePersistenceManager->getPdfLogos($profileName); |
| 493 |
foreach ($availableLogos as $availableLogo) { |
| 494 |
$fileName = $availableLogo->getName(); |
| 495 |
$importOptions[$profileName][$fileName] = $profileName . '##' . $fileName; |
| 496 |
} |
| 497 |
} |
| 498 |
} |
| 499 |
$logoImportConfigSelect = new htmlResponsiveSelect('importLogoSourceProfile', $importOptions, [], _('PDF structures'), null, 5); |
| 500 |
$logoImportConfigSelect->setHasDescriptiveElements(true); |
| 501 |
$logoImportConfigSelect->setContainsOptgroups(true); |
| 502 |
$logoImportConfigSelect->setMultiSelect(true); |
| 503 |
$logoImportFormContent->add($logoImportConfigSelect); |
| 504 |
$logoImportFormContent->addVerticalSpacer('1rem'); |
| 505 |
$logoImportFormContent->addLabel(new htmlOutputText('')); |
| 506 |
$logoImportFormPwd = new htmlResponsiveInputField(_("Master password"), 'importLogoPassword', null, '236'); |
| 507 |
$logoImportFormPwd->setIsPassword(true); |
| 508 |
$logoImportFormContent->add($logoImportFormPwd); |
| 509 |
addSecurityTokenToMetaHTML($logoImportFormContent); |
| 510 |
$logoImportForm = new htmlForm('logoImportForm', 'pdfmain.php', $logoImportFormContent); |
| 511 |
$logoImportDialog = new htmlDiv('logoImportDiv', $logoImportForm, ['hidden']); |
| 512 |
$container->add($logoImportDialog); |
| 513 |
parseHtml(null, $container, [], false, 'user'); |
| 514 |
|
| 515 |
foreach ($templateClasses as $templateClass) { |
| 516 |
$typeId = $templateClass['typeId']; |
| 517 |
$scope = $templateClass['scope']; |
| 518 |
$importOptions = []; |
| 519 |
foreach ($configProfiles as $profile) { |
| 520 |
$typeManagerImport = new TypeManager($serverProfiles[$profile]); |
| 521 |
$typesImport = $typeManagerImport->getConfiguredTypesForScope($scope); |
| 522 |
foreach ($typesImport as $typeImport) { |
| 523 |
if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) { |
| 524 |
$accountProfiles = $pdfStructurePersistenceManager->getPDFStructures($profile, $typeImport->getId()); |
| 525 |
foreach ($accountProfiles as $accountProfile) { |
| 526 |
$importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfile] = $profile . '##' . $typeImport->getId() . '##' . $accountProfile; |
| 527 |
} |
| 528 |
} |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
//import dialog |
| 533 |
echo "<div id=\"importDialog_$typeId\" class=\"hidden\">\n"; |
| 534 |
echo "<form id=\"importDialogForm_$typeId\" method=\"post\" action=\"pdfmain.php\">\n"; |
| 535 |
|
| 536 |
$containerStructures = new htmlResponsiveRow(); |
| 537 |
$containerStructures->add(new htmlOutputText(_('PDF structures'))); |
| 538 |
|
| 539 |
$select = new htmlSelect('importProfiles_' . $typeId, $importOptions, [], min(count($importOptions, 1), 15)); |
| 540 |
$select->setMultiSelect(true); |
| 541 |
$select->setHasDescriptiveElements(true); |
| 542 |
$select->setContainsOptgroups(true); |
| 543 |
|
| 544 |
$containerStructures->add($select, 11); |
| 545 |
$containerStructures->add(new htmlHelpLink('408'), 1); |
| 546 |
|
| 547 |
$containerStructures->addVerticalSpacer('2rem'); |
| 548 |
|
| 549 |
$containerStructures->add(new htmlOutputText(_("Master password"))); |
| 550 |
$exportPasswd = new htmlInputField('passwd_i_' . $typeId); |
| 551 |
$exportPasswd->setIsPassword(true); |
| 552 |
$containerStructures->add($exportPasswd, 11); |
| 553 |
$containerStructures->add(new htmlHelpLink('236'), 1); |
| 554 |
$containerStructures->add(new htmlHiddenInput('import', '1')); |
| 555 |
$containerStructures->add(new htmlHiddenInput('typeId', $typeId)); |
| 556 |
addSecurityTokenToMetaHTML($containerStructures); |
| 557 |
|
| 558 |
parseHtml(null, $containerStructures, [], false, 'user'); |
| 559 |
|
| 560 |
echo '</form>'; |
| 561 |
echo "</div>\n"; |
| 562 |
|
| 563 |
//export dialog |
| 564 |
echo "<div id=\"exportDialog_$typeId\" class=\"hidden\">\n"; |
| 565 |
echo "<form id=\"exportDialogForm_$typeId\" method=\"post\" action=\"pdfmain.php\">\n"; |
| 566 |
|
| 567 |
$containerTarget = new htmlResponsiveRow(); |
| 568 |
|
| 569 |
$containerTarget->add(new htmlOutputText(_("Target server profile"))); |
| 570 |
$exportOptions = []; |
| 571 |
foreach ($configProfiles as $profile) { |
| 572 |
$typeManagerExport = new TypeManager($serverProfiles[$profile]); |
| 573 |
$typesExport = $typeManagerExport->getConfiguredTypesForScope($scope); |
| 574 |
foreach ($typesExport as $typeExport) { |
| 575 |
if ((($profile != $_SESSION['config']->getName()) || ($typeExport->getId() != $typeId)) |
| 576 |
&& ($typeManagerExport->getConfig() !== null)) { |
| 577 |
$exportOptions[$typeManagerExport->getConfig()->getName()][$typeExport->getAlias()] = $profile . '##' . $typeExport->getId(); |
| 578 |
} |
| 579 |
} |
| 580 |
} |
| 581 |
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##'; |
| 582 |
|
| 583 |
$exportSize = count($exportOptions) < 10 ? count($exportOptions, 1) : 10; |
| 584 |
$select = new htmlSelect('exportProfiles_' . $typeId, $exportOptions, [], $exportSize); |
| 585 |
$select->setHasDescriptiveElements(true); |
| 586 |
$select->setContainsOptgroups(true); |
| 587 |
$select->setMultiSelect(true); |
| 588 |
|
| 589 |
$containerTarget->add($select, 11); |
| 590 |
$containerTarget->add(new htmlHelpLink('363'), 1); |
| 591 |
|
| 592 |
$containerTarget->addVerticalSpacer('2rem'); |
| 593 |
|
| 594 |
$containerTarget->add(new htmlOutputText(_("Master password"))); |
| 595 |
$exportPasswd = new htmlInputField('passwd_e_' . $typeId); |
| 596 |
$exportPasswd->setIsPassword(true); |
| 597 |
$containerTarget->add($exportPasswd, 11); |
| 598 |
$containerTarget->add(new htmlHelpLink('236'), 1); |
| 599 |
$containerTarget->add(new htmlHiddenInput('export', '1')); |
| 600 |
$containerTarget->add(new htmlHiddenInput('typeId', $typeId)); |
| 601 |
$containerTarget->add(new htmlHiddenInput('name_' . $typeId, '_')); |
| 602 |
addSecurityTokenToMetaHTML($containerTarget); |
| 603 |
|
| 604 |
parseHtml(null, $containerTarget, [], false, 'user'); |
| 605 |
|
| 606 |
echo '</form>'; |
| 607 |
echo "</div>\n"; |
| 608 |
} |
| 609 |
|
| 610 |
// form for delete action |
| 611 |
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">'; |
| 612 |
echo _("Do you really want to delete this PDF structure?"); |
| 613 |
echo '<br><br><div class="nowrap">'; |
| 614 |
echo _("Structure name") . ': <div id="deleteText" style="display: inline;"></div></div>'; |
| 615 |
echo '<input id="profileDeleteType" type="hidden" name="profileDeleteType" value="">'; |
| 616 |
echo '<input id="profileDeleteName" type="hidden" name="profileDeleteName" value="">'; |
| 617 |
echo '<input type="hidden" name="deleteProfile" value="true">'; |
| 618 |
echo '<input type="hidden" name="' . getSecurityTokenName() . '" value="' . getSecurityTokenValue() . '">'; |
| 619 |
echo '</form></div>'; |
| 620 |
|
| 621 |
// delete global templates |
| 622 |
$globalTemplates = $pdfStructurePersistenceManager->getPdfStructureTemplateNames(); |
| 623 |
$globalDeletableTemplates = []; |
| 624 |
foreach ($globalTemplates as $typeId => $availableTemplates) { |
| 625 |
if (empty($availableTemplates)) { |
| 626 |
continue; |
| 627 |
} |
| 628 |
foreach ($availableTemplates as $availableTemplate) { |
| 629 |
if ($availableTemplate !== 'default') { |
| 630 |
$globalDeletableTemplates[$typeId][$availableTemplate] = $typeId . ':' . $availableTemplate; |
| 631 |
} |
| 632 |
} |
| 633 |
} |
| 634 |
|
| 635 |
if (!empty($globalDeletableTemplates)) { |
| 636 |
$container = new htmlResponsiveRow(); |
| 637 |
$globalTemplatesSubtitle = new htmlSubTitle(_('Global templates')); |
| 638 |
$globalTemplatesSubtitle->setHelpId('364'); |
| 639 |
$container->add($globalTemplatesSubtitle); |
| 640 |
$globalTemplatesSelect = new htmlResponsiveSelect('globalTemplatesDelete', $globalDeletableTemplates, [], _('Delete')); |
| 641 |
$globalTemplatesSelect->setContainsOptgroups(true); |
| 642 |
$globalTemplatesSelect->setHasDescriptiveElements(true); |
| 643 |
$container->add($globalTemplatesSelect); |
| 644 |
$container->addVerticalSpacer('1rem'); |
| 645 |
$globalTemplateDeleteButton = new htmlButton('deleteGlobalProfileButton', _('Delete')); |
| 646 |
$globalTemplateDeleteButton->setCSSClasses(['lam-danger']); |
| 647 |
$globalTemplateDeleteButton->setOnClick("window.lam.dialog.requestPasswordAndSendForm('" . _('Do you really want to delete this profile?') . "', '" . |
| 648 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'globalTemplateDeletePassword', 'deleteGlobalTemplatesForm'); return false;"); |
| 649 |
$container->addLabel(new htmlOutputText(' ', false)); |
| 650 |
$container->addField($globalTemplateDeleteButton); |
| 651 |
addSecurityTokenToMetaHTML($container); |
| 652 |
$container->add(new htmlHiddenInput('deleteGlobalTemplate', 'true')); |
| 653 |
$container->addVerticalSpacer('1rem'); |
| 654 |
$globalTemplateDeleteForm = new htmlForm('deleteGlobalTemplatesForm', 'pdfmain.php', $container); |
| 655 |
parseHtml(null, $globalTemplateDeleteForm, [], false, 'user'); |
| 656 |
} |
| 657 |
|
| 658 |
// delete global PDF logos |
| 659 |
$globalPdfLogos = $pdfStructurePersistenceManager->getPdfTemplateLogoNames(); |
| 660 |
if (!empty($globalPdfLogos)) { |
| 661 |
$container = new htmlResponsiveRow(); |
| 662 |
$globalLogosSubtitle = new htmlSubTitle(_('Global template logos')); |
| 663 |
$globalLogosSubtitle->setHelpId('365'); |
| 664 |
$container->add($globalLogosSubtitle); |
| 665 |
$globalTemplateLogosSelect = new htmlResponsiveSelect('globalLogoDelete', $globalPdfLogos, [], _('Delete')); |
| 666 |
$container->add($globalTemplateLogosSelect); |
| 667 |
$container->addVerticalSpacer('1rem'); |
| 668 |
$globalLogoDeleteButton = new htmlButton('deleteGlobalLogoButton', _('Delete')); |
| 669 |
$globalLogoDeleteButton->setCSSClasses(['lam-danger']); |
| 670 |
$globalLogoDeleteButton->setOnClick("window.lam.dialog.requestPasswordAndSendForm('" . _('Do you really want to delete this logo?') . "', '" . |
| 671 |
_('Ok') . "', '" . _('Cancel') . "', '" . _('Master password') . "', 'globalLogoDeletePassword', 'deleteGlobalLogoForm'); return false;"); |
| 672 |
$container->addLabel(new htmlOutputText(' ', false)); |
| 673 |
$container->addField($globalLogoDeleteButton); |
| 674 |
addSecurityTokenToMetaHTML($container); |
| 675 |
$container->add(new htmlHiddenInput('deleteGlobalLogo', 'true')); |
| 676 |
$container->addVerticalSpacer('1rem'); |
| 677 |
$globalLogoDeleteForm = new htmlForm('deleteGlobalLogoForm', 'pdfmain.php', $container); |
| 678 |
parseHtml(null, $globalLogoDeleteForm, [], false, 'user'); |
| 679 |
} |
| 680 |
|
| 681 |
echo "</div>\n"; |
| 682 |
|
| 683 |
include __DIR__ . '/../../lib/adminFooter.inc'; |
| 684 |
|
| 685 |
|
| 686 |
/** |
| 687 |
* Imports the selected PDF structures. |
| 688 |
* |
| 689 |
* @param string $typeId type id |
| 690 |
* @param array<mixed> $options options |
| 691 |
* @param LAMConfig[] $serverProfiles server profiles (name => profile object) |
| 692 |
* @param TypeManager $typeManager type manager |
| 693 |
* @return htmlStatusMessage message or null |
| 694 |
*/ |
| 695 |
function importStructures($typeId, $options, $serverProfiles, TypeManager $typeManager) { |
| 696 |
$pdfStructurePersistenceManager = new PdfStructurePersistenceManager(); |
| 697 |
foreach ($options as $option) { |
| 698 |
$sourceConfName = $option['conf']; |
| 699 |
$sourceTypeId = $option['typeId']; |
| 700 |
$sourceName = $option['name']; |
| 701 |
$sourceTypeManager = new TypeManager($serverProfiles[$sourceConfName]); |
| 702 |
$sourceType = $sourceTypeManager->getConfiguredType($sourceTypeId); |
| 703 |
$targetType = $typeManager->getConfiguredType($typeId); |
| 704 |
if (($sourceType !== null) && ($targetType !== null)) { |
| 705 |
try { |
| 706 |
$structure = $pdfStructurePersistenceManager->readPdfStructure($sourceConfName, $sourceTypeId, $sourceName); |
| 707 |
$pdfStructurePersistenceManager->savePdfStructure($_SESSION['config']->getName(), $sourceTypeId, $sourceName, $structure); |
| 708 |
} |
| 709 |
catch (LAMException $e) { |
| 710 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 711 |
} |
| 712 |
} |
| 713 |
} |
| 714 |
return new htmlStatusMessage('INFO', _('Import successful')); |
| 715 |
} |
| 716 |
|
| 717 |
/** |
| 718 |
* Exports the selected account profile. |
| 719 |
* |
| 720 |
* @param string $typeId source type id |
| 721 |
* @param string $name profile name |
| 722 |
* @param array<mixed> $options options |
| 723 |
* @param LAMConfig[] $serverProfiles server profiles (name => profile object) |
| 724 |
* @param TypeManager $typeManager type manager |
| 725 |
* @return htmlStatusMessage message or null |
| 726 |
*/ |
| 727 |
function exportStructures($typeId, $name, $options, $serverProfiles, TypeManager $typeManager): ?htmlStatusMessage { |
| 728 |
$sourceType = $typeManager->getConfiguredType($typeId); |
| 729 |
if ($sourceType === null) { |
| 730 |
return null; |
| 731 |
} |
| 732 |
$pdfStructurePersistenceManager = new PdfStructurePersistenceManager(); |
| 733 |
foreach ($options as $option) { |
| 734 |
$targetConfName = $option['conf']; |
| 735 |
if ($targetConfName == 'templates*') { |
| 736 |
try { |
| 737 |
$structure = $pdfStructurePersistenceManager->readPdfStructure($_SESSION['config']->getName(), $typeId, $name); |
| 738 |
$pdfStructurePersistenceManager->savePdfStructureTemplate($sourceType->getScope(), $name, $structure); |
| 739 |
} |
| 740 |
catch (LAMException $e) { |
| 741 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 742 |
} |
| 743 |
} |
| 744 |
else { |
| 745 |
$targetTypeId = $option['typeId']; |
| 746 |
$targetTypeManager = new TypeManager($serverProfiles[$targetConfName]); |
| 747 |
$targetType = $targetTypeManager->getConfiguredType($targetTypeId); |
| 748 |
if ($targetType !== null) { |
| 749 |
try { |
| 750 |
$structure = $pdfStructurePersistenceManager->readPdfStructure($_SESSION['config']->getName(), $typeId, $name); |
| 751 |
$pdfStructurePersistenceManager->savePdfStructure($targetConfName, $targetTypeId, $name, $structure); |
| 752 |
} |
| 753 |
catch (LAMException $e) { |
| 754 |
return new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()); |
| 755 |
} |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
return new htmlStatusMessage('INFO', _('Export successful')); |
| 760 |
} |