Merge pull request #12 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2016-12-26 10:31:13 +01:00 committed by GitHub
commit 2cde29e040
5 changed files with 122 additions and 59 deletions

View File

@ -1,4 +1,5 @@
<?php
namespace LAM\HEADER;
/*
$Id$
@ -204,7 +205,7 @@ jQuery(document).ready(function() {
<?php
function printTypeTabs($headerPrefix) {
$typeManager = new LAM\TYPES\TypeManager();
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$linkList = array();
foreach ($types as $type) {

View File

@ -1,4 +1,21 @@
<?php
namespace LAM\TOOLS\PDF_EDITOR;
use \htmlTable;
use \htmlTitle;
use \htmlStatusMessage;
use \LAMCfgMain;
use \htmlSubTitle;
use \htmlSelect;
use \htmlImage;
use \htmlSpacer;
use \htmlButton;
use \htmlLink;
use \htmlOutputText;
use \htmlInputFileUpload;
use \htmlHelpLink;
use \htmlInputField;
use \htmlHiddenInput;
use \htmlDiv;
/*
$Id$
@ -70,19 +87,20 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
// check if new template should be created
if(isset($_POST['createNewTemplate'])) {
metaRefresh('pdfpage.php?type=' . htmlspecialchars($_POST['scope']));
metaRefresh('pdfpage.php?type=' . htmlspecialchars($_POST['typeId']));
exit();
}
$scopes = $_SESSION['config']->get_ActiveTypes();
$sortedScopes = array();
for ($i = 0; $i < sizeof($scopes); $i++) {
if (isAccountTypeHidden($scopes[$i]) || !checkIfWriteAccessIsAllowed($scopes[$i])) {
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$sortedTypes = array();
foreach ($types as $type) {
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($type->getId())) {
continue;
}
$sortedScopes[$scopes[$i]] = LAM\TYPES\getTypeAlias($scopes[$i]);
$sortedTypes[$type->getId()] = $type->getAlias();
}
natcasesort($sortedScopes);
natcasesort($sortedTypes);
$container = new htmlTable();
$container->addElement(new htmlTitle(_('PDF editor')), true);
@ -90,12 +108,12 @@ $container->addElement(new htmlTitle(_('PDF editor')), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
// delete structure
if (deletePDFStructureDefinition($_POST['profileDeleteType'], $_POST['profileDeleteName'])) {
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}
else {
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message = new htmlStatusMessage('ERROR', _('Unable to delete PDF structure!'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
}
@ -104,12 +122,12 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
$cfg = new LAMCfgMain();
$impExpMessage = null;
if (isset($_POST['importProfiles_' . $_POST['scope']])) {
if (isset($_POST['importProfiles_' . $_POST['typeId']])) {
// check master password
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['scope']])) {
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyPdfProfiles($_POST['importProfiles_' . $_POST['scope']], $_POST['scope'])) {
elseif (copyPdfProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Import successful'));
}
} else if (isset($_POST['exportProfiles'])) {
@ -117,7 +135,7 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
if (!$cfg->checkPassword($_POST['passwd'])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyPdfProfiles($_POST['exportProfiles'], $_POST['scope'], $_POST['destServerProfiles'])) {
elseif (copyPdfProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Export successful'));
}
}
@ -141,24 +159,26 @@ if (isset($_POST['delLogo'])) {
}
// get list of account types
$availableScopes = '';
$availableTypes = array();
$templateClasses = array();
foreach ($sortedScopes as $scope => $title) {
foreach ($sortedTypes as $typeId => $title) {
$type = $typeManager->getConfiguredType($typeId);
$templateClasses[] = array(
'scope' => $scope,
'typeId' => $type->getId(),
'scope' => $type->getScope(),
'title' => $title,
'templates' => "");
$availableScopes[$title] = $scope;
$availableTypes[$title] = $type->getId();
}
// get list of templates for each account type
for ($i = 0; $i < sizeof($templateClasses); $i++) {
$templateClasses[$i]['templates'] = getPDFStructureDefinitions($templateClasses[$i]['scope']);
$templateClasses[$i]['templates'] = getPDFStructureDefinitions($templateClasses[$i]['typeId']);
}
// check if a template should be edited
for ($i = 0; $i < sizeof($templateClasses); $i++) {
if (isset($_POST['editTemplate_' . $templateClasses[$i]['scope']]) || isset($_POST['editTemplate_' . $templateClasses[$i]['scope'] . '_x'])) {
metaRefresh('pdfpage.php?type=' . htmlspecialchars($templateClasses[$i]['scope']) . '&edit=' . htmlspecialchars($_POST['template_' . $templateClasses[$i]['scope']]));
if (isset($_POST['editTemplate_' . $templateClasses[$i]['typeId']]) || isset($_POST['editTemplate_' . $templateClasses[$i]['typeId'] . '_x'])) {
metaRefresh('pdfpage.php?type=' . htmlspecialchars($templateClasses[$i]['typeId']) . '&edit=' . htmlspecialchars($_POST['template_' . $templateClasses[$i]['typeId']]));
exit;
}
}
@ -176,13 +196,13 @@ include '../main_header.php';
}
// new template
if (!empty($availableScopes)) {
if (!empty($availableTypes)) {
$container->addElement(new htmlSubTitle(_('Create a new PDF structure')), true);
$newPDFContainer = new htmlTable();
$newScopeSelect = new htmlSelect('scope', $availableScopes);
$newScopeSelect->setHasDescriptiveElements(true);
$newScopeSelect->setWidth('15em');
$newPDFContainer->addElement($newScopeSelect);
$newProfileSelect = new htmlSelect('typeId', $availableTypes);
$newProfileSelect->setHasDescriptiveElements(true);
$newProfileSelect->setWidth('15em');
$newPDFContainer->addElement($newProfileSelect);
$newPDFContainer->addElement(new htmlSpacer('10px', null));
$newPDFContainer->addElement(new htmlButton('createNewTemplate', _('Create')));
$container->addElement($newPDFContainer, true);
@ -203,29 +223,29 @@ include '../main_header.php';
$existingContainer->addElement(new htmlSpacer('3px', null));
$existingContainer->addElement(new htmlOutputText($templateClasses[$i]['title']));
$existingContainer->addElement(new htmlSpacer('3px', null));
$select = new htmlSelect('template_' . $templateClasses[$i]['scope'], $templateClasses[$i]['templates']);
$select = new htmlSelect('template_' . $templateClasses[$i]['typeId'], $templateClasses[$i]['templates']);
$select->setWidth('15em');
$existingContainer->addElement($select);
$existingContainer->addElement(new htmlSpacer('3px', null));
$exEditButton = new htmlButton('editTemplate_' . $templateClasses[$i]['scope'], 'edit.png', true);
$exEditButton = new htmlButton('editTemplate_' . $templateClasses[$i]['typeId'], 'edit.png', true);
$exEditButton->setTitle(_('Edit'));
$existingContainer->addElement($exEditButton);
$deleteLink = new htmlLink(null, '#', '../../graphics/delete.png');
$deleteLink->setTitle(_('Delete'));
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['scope'] . "', '" . 'template_' . $templateClasses[$i]['scope'] . "');");
$deleteLink->setOnClick("profileShowDeleteDialog('" . _('Delete') . "', '" . _('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['typeId'] . "', '" . 'template_' . $templateClasses[$i]['typeId'] . "');");
$existingContainer->addElement($deleteLink);
if (count($configProfiles) > 1) {
$importLink = new htmlLink(null, '#', '../../graphics/import.png');
$importLink->setTitle(_('Import PDF structures'));
$importLink->setOnClick("showDistributionDialog('" . _("Import PDF structures") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['scope'] . "', 'import');");
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['typeId'] . "', 'import');");
$existingContainer->addElement($importLink);
}
$exportLink = new htmlLink(null, '#', '../../graphics/export.png');
$exportLink->setTitle(_('Export PDF structure'));
$exportLink->setOnClick("showDistributionDialog('" . _("Export PDF structure") . "', '" .
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['scope'] . "', 'export', '" . 'template_' . $templateClasses[$i]['scope'] . "', '" . $_SESSION['config']->getName() . "');");
_('Ok') . "', '" . _('Cancel') . "', '" . $templateClasses[$i]['typeId'] . "', 'export', '" . 'template_' . $templateClasses[$i]['typeId'] . "', '" . $_SESSION['config']->getName() . "');");
$existingContainer->addElement($exportLink);
$existingContainer->addNewLine();
}
@ -263,11 +283,11 @@ include '../main_header.php';
echo "</div>\n";
for ($i = 0; $i < sizeof($templateClasses); $i++) {
$scope = $templateClasses[$i]['scope'];
$typeId = $templateClasses[$i]['typeId'];
$tmpArr = array();
foreach ($configProfiles as $profile) {
if ($profile != $_SESSION['config']->getName()) {
$accountProfiles = getPDFStructureDefinitions($scope, $profile);
$accountProfiles = getPDFStructureDefinitions($typeId, $profile);
for ($p = 0; $p < sizeof($accountProfiles); $p++) {
$tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p];
}
@ -275,13 +295,13 @@ include '../main_header.php';
}
//import dialog
echo "<div id=\"importDialog_$scope\" class=\"hidden\">\n";
echo "<form id=\"importDialogForm_$scope\" method=\"post\" action=\"pdfmain.php\">\n";
echo "<div id=\"importDialog_$typeId\" class=\"hidden\">\n";
echo "<form id=\"importDialogForm_$typeId\" method=\"post\" action=\"pdfmain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_('PDF structures')), true);
$select = new htmlSelect('importProfiles_' . $scope, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15);
$select = new htmlSelect('importProfiles_' . $typeId, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15);
$select->setMultiSelect(true);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
@ -293,12 +313,12 @@ include '../main_header.php';
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_' . $scope);
$exportPasswd = new htmlInputField('passwd_' . $typeId);
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'));
$container->addElement(new htmlHiddenInput('scope', $scope), true);
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');

View File

@ -1,10 +1,25 @@
<?php
namespace LAM\TOOLS\PDF_EDITOR;
use \htmlTable;
use \htmlTitle;
use \htmlTableExtendedInputField;
use \htmlSpacer;
use \htmlTableExtendedSelect;
use \htmlButton;
use \htmlOutputText;
use \htmlGroup;
use \htmlSelect;
use \htmlInputField;
use \htmlSubTitle;
use \htmlFieldset;
use \htmlInputTextarea;
use \htmlHiddenInput;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner
2007 - 2015 Roland Gruber
2007 - 2016 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
@ -66,15 +81,17 @@ if (!$_SESSION['ldap'] || !$_SESSION['ldap']->server()) {
}
// Write $_POST variables to $_GET when form was submitted via post
if(isset($_POST['type'])) {
if (isset($_POST['type'])) {
$_GET = $_POST;
if($_POST['pdfname'] == '') {
if ($_POST['pdfname'] == '') {
unset($_GET['pdfname']);
}
}
if (isAccountTypeHidden($_GET['type']) || !checkIfWriteAccessIsAllowed($_GET['type'])) {
logNewMessage(LOG_ERR, 'User tried to access hidden PDF structure: ' . $_GET['type']);
$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();
}
@ -112,11 +129,11 @@ if(isset($_GET['submit'])) {
$saveErrors[] = array('ERROR', _('PDF structure name not valid'), _('The name for that PDF-structure you submitted is not valid. A valid name must consist of the following characters: \'a-z\',\'A-Z\',\'0-9\',\'_\',\'-\'.'));
}
else {
$return = savePDFStructureDefinitions($_GET['type'],$_GET['pdfname']);
$return = savePDFStructureDefinitions($type->getId(), $_GET['pdfname']);
if($return == 'ok') {
metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']);
exit;
}
}
elseif($return == 'no perms'){
$saveErrors[] = array('ERROR', _("Could not save PDF structure, access denied."), $_GET['pdfname']);
}
@ -141,7 +158,7 @@ elseif(isset($_GET['add_sectionText'])) {
StatusMessage('ERROR',_('No section text specified'),_('The headline for a new section must contain at least one character.'));
}
else {
$attributes = array();
$attributes = array();
$attributes['NAME'] = $_GET['new_section_text'];
$entry = array(array('tag' => 'SECTION','type' => 'open','level' => '2','attributes' => $attributes),array('tag' => 'SECTION','type' => 'close','level' => '2'));
// Insert new field in structure
@ -339,14 +356,14 @@ foreach ($_GET as $key => $value) {
if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit
if(isset($_GET['edit'])) {
$load = loadPDFStructureDefinitions($_GET['type'],$_GET['edit']);
$load = loadPDFStructureDefinitions($type->getId(), $_GET['edit']);
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
$_GET['pdfname'] = $_GET['edit'];
}
// Load default structure file when creating a new one
else {
$load = loadPDFStructureDefinitions($_GET['type']);
$load = loadPDFStructureDefinitions($type->getId());
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
}
@ -354,7 +371,7 @@ if(!isset($_SESSION['currentPDFStructure'])) {
// Load available fields from modules when not set in session
if(!isset($_SESSION['availablePDFFields'])) {
$_SESSION['availablePDFFields'] = getAvailablePDFFields($_GET['type']);
$_SESSION['availablePDFFields'] = getAvailablePDFFields($type->getId());
}
// Create the values for the dropdown boxes for section headline defined by
@ -365,7 +382,7 @@ $section_items = '';
$sortedModules = array();
foreach($_SESSION['availablePDFFields'] as $module => $fields) {
if ($module != 'main') {
$title = getModuleAlias($module, $_GET['type']);
$title = getModuleAlias($module, $type->getScope());
}
else {
$title = _('Main');
@ -432,7 +449,7 @@ if (isset($_SESSION['currentPageDefinitions']['headline'])) {
$logoFiles = getAvailableLogos();
$logos = array(_('No logo') => 'none');
foreach($logoFiles as $logoFile) {
$logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename'];
$logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename'];
}
$selectedLogo = array('printLogo.jpg');
if (isset($_SESSION['currentPageDefinitions']['filename'])) {
@ -472,7 +489,7 @@ $structureContent = new htmlTable();
for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$entry = $_SESSION['currentPDFStructure'][$key];
// 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=' . $type->getId() . '&pdfname=' . $structureName . '&headline=' . $headline . '&logoFile=' . $selectedLogo[0] . '&foldingmarks=' . $foldingMarks;
$linkUp = new htmlButton('up_' . $key, 'up.gif', true);
$linkUp->setTitle(_("Up"));
$linkDown = new htmlButton('down_' . $key, 'down.gif', true);
@ -484,7 +501,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
if($entry['tag'] == "SECTION" && $entry['type'] == "open") {
$name = $entry['attributes']['NAME'];
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) {
$section_headline = translateFieldIDToName(substr($name,1), $_GET['type']);
$section_headline = translateFieldIDToName(substr($name,1), $type->getScope());
}
else {
$section_headline = $name;
@ -496,7 +513,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) {
$headlineElements = array();
foreach($section_items_array as $item) {
$headlineElements[translateFieldIDToName($item, $_GET['type'])] = '_' . $item;
$headlineElements[translateFieldIDToName($item, $type->getScope())] = '_' . $item;
}
$sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array($name));
$sectionHeadlineSelect->setHasDescriptiveElements(true);
@ -566,7 +583,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
// Get name of current entry
$name = $entry['attributes']['NAME'];
$structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $_GET['type']));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope()));
$structureContent->addElement($fieldOutput);
if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkUp);
@ -644,13 +661,13 @@ $cancelButton->setIconClass('cancelButton');
$buttonContainer->addElement($saveButton);
$buttonContainer->addElement($cancelButton);
$buttonContainer->addElement(new htmlHiddenInput('modules', $modules));
$buttonContainer->addElement(new htmlHiddenInput('type', $_GET['type']));
$buttonContainer->addElement(new htmlHiddenInput('type', $type->getId()));
$container->addElement($buttonContainer, true);
addSecurityTokenToMetaHTML($container);
$tabindex = 1;
parseHtml(null, $container, array(), false, $tabindex, $_GET['type']);
parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
if ((sizeof($saveErrors) == 0) && isset($_POST['scrollPositionTop']) && isset($_POST['scrollPositionLeft'])) {
// scroll to last position

View File

@ -1,4 +1,20 @@
<?php
namespace LAM\TOOLS\PROFILE_EDITOR;
use \htmlTable;
use \htmlTitle;
use \htmlStatusMessage;
use \LAMCfgMain;
use \htmlSubTitle;
use \htmlSpacer;
use \htmlSelect;
use \htmlButton;
use \htmlImage;
use \htmlLink;
use \htmlOutputText;
use \htmlHelpLink;
use \htmlHiddenInput;
use \htmlInputField;
use \htmlDiv;
/*
$Id$
@ -51,7 +67,7 @@ if (!empty($_POST)) {
validateSecurityToken();
}
$typeManager = new LAM\TYPES\TypeManager();
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$profileClasses = array();
$profileClassesTemp = array();

View File

@ -1,4 +1,13 @@
<?php
namespace LAM\TOOLS\PROFILE_EDITOR;
use \htmlTable;
use \htmlTitle;
use \htmlTableExtendedInputField;
use \htmlSpacer;
use \htmlTableExtendedSelect;
use \htmlFieldset;
use \htmlButton;
use \htmlHiddenInput;
/*
$Id$
@ -69,7 +78,7 @@ if (isset($_POST['accounttype'])) {
$_GET['type'] = $_POST['accounttype'];
}
$typeManager = new LAM\TYPES\TypeManager();
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($_GET['type']);
if ($type->isHidden() || !checkIfWriteAccessIsAllowed($_GET['type'])) {
logNewMessage(LOG_ERR, 'User tried to access hidden account type profile: ' . $_GET['type']);