Merge pull request #19 from LDAPAccountManager/type_api_tmp

Type api tmp
This commit is contained in:
gruberroland 2017-01-06 13:58:10 +01:00 committed by GitHub
commit dede64d746
16 changed files with 526 additions and 314 deletions

View File

@ -614,49 +614,56 @@ class LAMConfig {
$line = trim($line); // remove spaces at the beginning and end
if (($line == "")||($line[0] == "#")) continue; // ignore comments and empty lines
// search keywords
for ($i = 0; $i < sizeof($this->settings); $i++) {
$keyword = $this->settings[$i];
$keylen = strlen($keyword);
if (strtolower(substr($line, 0, $keylen + 2)) == strtolower($keyword . ": ")) {
// module settings
if (strtolower(substr($line, 0, $keylen + 2)) == "modules: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->moduleSettings[substr($option, 0, $pos)] = explode(LAMConfig::LINE_SEPARATOR, substr($option, $pos + 2));
}
// type settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "types: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->typeSettings[substr($option, 0, $pos)] = substr($option, $pos + 2);
}
// tool settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "tools: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->toolSettings[substr($option, 0, $pos)] = substr($option, $pos + 2);
}
// job settings
elseif (strtolower(substr($line, 0, $keylen + 2)) == "jobs: ") {
$option = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
$pos = strpos($option, ":");
$this->jobSettings[substr($option, 0, $pos)] = explode(LAMConfig::LINE_SEPARATOR, substr($option, $pos + 2));
}
// general settings
else {
$this->$keyword = substr($line, $keylen + 2, strlen($line) - $keylen - 2);
}
break;
$parts = explode(': ', $line);
$keyword = $parts[0];
if (!in_array($keyword, $this->settings)) {
continue;
}
$startIndex = strlen($keyword) + 2;
if (sizeof($parts) == 1) {
// empty global settings
$this->$keyword = '';
}
elseif (sizeof($parts) == 2) {
// global setting with value
$this->$keyword = substr($line, $startIndex);
}
else {
$subKeyword = $parts[1];
$startIndex = $startIndex + strlen($subKeyword) + 2;
// module settings
if ($keyword == 'modules') {
$option = substr($line, $startIndex);
$this->moduleSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
}
elseif (strtolower($line) == strtolower($keyword . ":")) {
// set empty options
$this->$keyword = '';
// type settings
if ($keyword == 'types') {
$option = substr($line, $startIndex);
$this->typeSettings[$subKeyword] = $option;
}
// tool settings
if ($keyword == 'tools') {
$option = substr($line, $startIndex);
$this->toolSettings[$subKeyword] = $option;
}
// job settings
if ($keyword == 'jobs') {
$option = substr($line, $startIndex);
$this->jobSettings[$subKeyword] = explode(LAMConfig::LINE_SEPARATOR, $option);
}
}
}
fclose($file);
}
// check types
$this->removeInvalidTypes();
$this->removeInvalidModules();
return true;
}
/**
* Removes any non-existing types from the configuration.
*/
private function removeInvalidTypes() {
$allTypes = LAM\TYPES\getTypes();
$activeTypes = $this->get_ActiveTypes();
for ($i = 0; $i < sizeof($activeTypes); $i++) {
@ -666,14 +673,23 @@ class LAMConfig {
}
$activeTypes = array_values($activeTypes);
$this->set_ActiveTypes($activeTypes);
// check modules
}
/**
* Removes any non-existing modules from the configuration.
*/
private function removeInvalidModules() {
$types = $this->get_ActiveTypes();
$availableByScope = array();
foreach ($types as $type) {
$scope = \LAM\TYPES\getScopeFromTypeId($type);
$moduleVar = "modules_" . $type;
if (isset($this->typeSettings[$moduleVar])){
$modules = explode(",", $this->typeSettings[$moduleVar]);
$available = getAvailableModules($scope);
if (empty($availableByScope[$scope])) {
$availableByScope[$scope] = getAvailableModules($scope);
}
$available = $availableByScope[$scope];
// only return available modules
$ret = array();
for ($i = 0; $i < sizeof($modules); $i++) {
@ -682,7 +698,6 @@ class LAMConfig {
$this->typeSettings[$moduleVar] = implode(",", $ret);
}
}
return true;
}
/** Saves preferences to config file */

View File

@ -690,7 +690,7 @@ class lamList {
$selAccounts[] = $id;
}
// get possible PDF structures
$pdf_structures = getPDFStructureDefinitions($this->type->getId());
$pdf_structures = \LAM\PDF\getPDFStructures($this->type->getId());
$this->listPrintHeader();

View File

@ -1,5 +1,6 @@
<?php
use LAM\TYPES\ConfiguredType;
use function LAM\TYPES\getScopeFromTypeId;
/*
$Id$
@ -401,14 +402,14 @@ function getHelp($module,$helpID,$scope='') {
/**
* Returns a list of available PDF entries.
*
* @param string $scope account type (user, group, host)
* @param string $typeId account type (user, group, host)
* @return array PDF entries (field ID => field label)
*/
function getAvailablePDFFields($scope) {
$mods = $_SESSION['config']->get_AccountModules($scope);
function getAvailablePDFFields($typeId) {
$mods = $_SESSION['config']->get_AccountModules($typeId);
$return = array();
for ($i = 0; $i < sizeof($mods); $i++) {
$module = moduleCache::getModule($mods[$i], $scope);
$module = moduleCache::getModule($mods[$i], getScopeFromTypeId($typeId));
$fields = $module->get_pdfFields();
$return[$mods[$i]] = array();
if (is_array($fields)) {
@ -1268,7 +1269,7 @@ class accountContainer {
$rightGroup = new htmlGroup();
$rightGroup->alignment = htmlElement::ALIGN_RIGHT;
// profile selection
$profilelist = getAccountProfiles($this->type->getId());
$profilelist = \LAM\PROFILES\getAccountProfiles($this->type->getId());
if (sizeof($profilelist) > 0) {
$rightGroup->addElement(new htmlSelect('accountContainerSelectLoadProfile', $profilelist, array($this->lastLoadedProfile)));
$profileButton = new htmlButton('accountContainerLoadProfile', _('Load profile'));
@ -1411,7 +1412,7 @@ class accountContainer {
*/
private function loadProfileIfRequested() {
if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) {
$profile = loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type->getId());
$profile = \LAM\PROFILES\loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type->getId());
$this->lastLoadedProfile = $_POST['accountContainerSelectLoadProfile'];
// pass profile to each module
$modules = array_keys($this->module);
@ -1706,7 +1707,7 @@ class accountContainer {
}
// sort module buttons
$this->sortModules();
$profile = loadAccountProfile('default', $this->type->getId());
$profile = \LAM\PROFILES\loadAccountProfile('default', $this->type->getId());
// pass profile to each module
$modules = array_keys($this->module);
foreach ($modules as $module) $this->module[$module]->load_profile($profile);

View File

@ -67,7 +67,7 @@ function createModulePDF($accounts, $pdf_structure="default", $returnAsString =
$account_type = $accounts[0]->get_type();
// Get PDF structure from xml file
$load = loadPDFStructureDefinitions($account_type->getId(), $pdf_structure);
$load = \LAM\PDF\loadPDFStructure($account_type->getId(), $pdf_structure);
$structure = $load['structure'];
// get list of PDF keys
$pdfKeys = array();

View File

@ -1,4 +1,8 @@
<?php
namespace LAM\PDF;
use \htmlStatusMessage;
use \LAMException;
/*
$Id$
@ -46,7 +50,7 @@ include_once("ldap.inc");
* scope. Each entry is a string being the filename that may be passed to the
* createModulePDF() function as second argument.
*/
function getPDFStructureDefinitions($scope = "user", $profile = null) {
function getPDFStructures($scope = "user", $profile = null) {
$return = array();
if (!isset($profile)) {
@ -67,22 +71,24 @@ function getPDFStructureDefinitions($scope = "user", $profile = null) {
}
/**
* This function is used to get pdf structure from xml file.
* Used in createModulePDF.
* This function is used to get the PDF structure from XML file.
*
* @param string $scope The account scope for wich the PDF structure should be returned.
* @param string $pdf_structure Structure name of selected scope wich should be returned.
* @param string $typeId the account type
* @param string $name structure name
*
* @return array PDF structure
*/
function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') {
function loadPDFStructure($typeId, $name='default') {
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
return null;
}
$parser = new xmlParser();
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $pdf_structure . '.' . $scope . '.xml';
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
$xml = $parser->parse($file);
$border = array();
$structure = array();
$complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager');
if($xml[0][$xml[1]['PDF'][0]]['attributes']['TYPE'] == $scope) {
if (!empty($xml)) {
$border['start'] = $xml[1]['PDF'][0];
$page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes'];
foreach($page_definitions as $key => $value) {
@ -90,23 +96,24 @@ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') {
unset($page_definitions[$key]);
}
$border['end'] = $xml[1]['PDF'][1];
$structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
}
$structure = array_slice($xml[0],$border['start'] + 1,$border['end'] - ($border['start'] + 1));
return array('structure' => $structure, 'page_definitions' => $complete_page_definitions);
}
/**
* Saves PDF structure definitions to XML file in format: <name>.<scope>.xml
* Saves PDF structure to XML file in format: <name>.<typeId>.xml
*
* @param string $scope account type
* @param string $definition Name of definition
* @param string $typeId account type
* @param string $name name of structure
* @return string "no perms" if access denied or "ok".
*/
function savePDFStructureDefinitions($scope,$definition) {
if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms';
if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms';
$struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml';
function savePDFStructure($typeId, $name) {
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
return 'no perms';
}
$struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) {
return 'no perms';
}
@ -115,11 +122,9 @@ function savePDFStructureDefinitions($scope,$definition) {
if (!$handle) return 'no perms';
$pdf_attributes = '';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) {
if($key != 'type') {
$pdf_attributes .= ' ' . $key . '="' . $value . '"';
}
$pdf_attributes .= ' ' . $key . '="' . $value . '"';
}
$file = '<pdf type="' . $scope . "\"" . $pdf_attributes . ">\n";
$file = '<pdf' . $pdf_attributes . ">\n";
foreach($_SESSION['currentPDFStructure'] as $entry) {
$ident = '';
for($i=0;$i<$entry['level'] -1;$i++) {
@ -156,15 +161,16 @@ function savePDFStructureDefinitions($scope,$definition) {
/**
* Deletes XML file with PDF structure definitions.
*
* @param string $scope account type
* @param string $definition Name of definition to delete
* @param string $typeId account type
* @param string $name Name of definition to delete
*
* @return boolean True if file was deleted or false if a problem occured.
*/
function deletePDFStructureDefinition($scope, $definition) {
if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false;
if (!preg_match('/[a-zA-Z]+/',$scope)) return false;
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml';
function deletePDFStructure($typeId, $name) {
if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/',$typeId)) {
return false;
}
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
if(is_file($file) && is_writable($file)) {
return unlink($file);
}
@ -195,46 +201,50 @@ function getAvailableLogos() {
return $return;
}
/**
* Copies a PDF structure from the given source to target.
*
* @param \LAM\TYPES\ConfiguredType $sourceType source type
* @param string $sourceStructureName structure name
* @param \LAM\TYPES\ConfiguredType $targetType target type
* @throws Exception
*/
function copyStructure($sourceType, $sourceStructureName, $targetType) {
if (!isValidPDFStructureName($sourceStructureName)) {
throw new LAMException(_('Failed to copy'));
}
$sourceConfig = $sourceType->getTypeManager()->getConfig()->getName();
$sourceTypeId = $sourceType->getId();
$targetConfig = $targetType->getTypeManager()->getConfig()->getName();
$targetTypeId = $targetType->getId();
$basePath = dirname(__FILE__) . '/../config/pdf/';
$src = $basePath . $sourceConfig . '/' . $sourceStructureName . '.' . $sourceTypeId . '.xml';
$dst = $basePath . $targetConfig . '/' . $sourceStructureName . '.' . $targetTypeId . '.xml';
if (!@copy($src, $dst)) {
throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceStructureName);
}
}
/**
* Copies PDF profiles to other server profiles.
* Copies a PDF structure from the given source to global templates.
*
* @param array $pdfProfiles PDF profile names
* @param String $scope account scope
* @param array $dests destinations
*
* @return boolean operation succeeded
* @param \LAM\TYPES\ConfiguredType $sourceType source type
* @param string $sourceName structure name
* @throws Exception
*/
function copyPdfProfiles($pdfProfiles, $scope, $dests = array()) {
$state = true;
$profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/pdf/';
foreach ($pdfProfiles as $profile) {
//part 1: server profile
//part 2: account profile
$tmpArr = explode('##', $profile);
$src = $profilePath . $tmpArr[0] . '/' . $tmpArr[1] . '.' . $scope . '.xml';
if (!empty($dests)) {
foreach ($dests as $dest) {
if ($dest == 'templates*') {
$dst = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/templates/pdf/' . $tmpArr[1] . '.' . $scope . '.xml';
} else {
$dst = $profilePath . $dest . '/' . $tmpArr[1] . '.' . $scope . '.xml';
}
if (!@copy($src, $dst)) {
StatusMessage('ERROR', _('Failed to export!'), $tmpArr[1] . '.' . $scope . '.xml');
$state = false;
}
}
} else {
$dst = $profilePath . $_SESSION['config']->getName() . '/' . $tmpArr[1] . '.' . $scope . '.xml';
if (!@copy($src, $dst)) {
StatusMessage('ERROR', _('Failed to import!'), $tmpArr[1] . '.' . $scope . '.xml');
$state = false;
}
}
function copyStructureToTemplates($sourceType, $sourceName) {
if (!isValidPDFStructureName($sourceName)) {
throw new LAMException(_('Failed to copy'));
}
$sourceConfig = $sourceType->getTypeManager()->getConfig()->getName();
$sourceTypeId = $sourceType->getId();
$basePath = dirname(__FILE__) . '/../config/pdf/';
$templatePath = dirname(__FILE__) . '/../config/templates/pdf/';
$src = $basePath . $sourceConfig . '/' . $sourceName . '.' . $sourceTypeId . '.xml';
$dst = $templatePath . $sourceName . '.' . $sourceType->getScope() . '.xml';
if (!@copy($src, $dst)) {
throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceName);
}
return $state;
}
/**
@ -284,12 +294,12 @@ function deletePDFLogo($name) {
// check if still in use
$activeTypes = $_SESSION['config']->get_ActiveTypes();
foreach ($activeTypes as $type) {
$structures = getPDFStructureDefinitions($type);
$structures = getPDFStructures($type);
foreach ($structures as $structure) {
$data = loadPDFStructureDefinitions($type, $structure);
$data = loadPDFStructure($type, $structure);
if ($data['page_definitions']['filename'] == $name) {
return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'),
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, LAM\TYPES\getTypeAlias($type)));
sprintf(_('Logo is still in use by PDF structure "%s" in account type "%s".'), $structure, \LAM\TYPES\getTypeAlias($type)));
}
}
}
@ -304,4 +314,49 @@ function deletePDFLogo($name) {
}
}
/**
* Returns if the give structure name is valid.
*
* @param string $name structure name
* @return boolean is valid
*/
function isValidPDFStructureName($name) {
return preg_match('/[a-zA-Z0-9\-\_]+/',$name) === 1;
}
/**
* Installs template structures to the current server profile.
*/
function installPDFTemplates() {
$templatePath = dirname(__FILE__) . '/../config/templates/pdf';
$templateDir = @dir($templatePath);
$allTemplates = array();
if ($templateDir) {
$entry = $templateDir->read();
while ($entry){
$parts = explode('.', $entry);
if ((strlen($entry) > 3) && (sizeof($parts) == 3)) {
$name = $parts[0];
$scope = $parts[1];
$allTemplates[$scope][] = $name;
}
$entry = $templateDir->read();
}
}
$basePath = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/';
$typeManager = new \LAM\TYPES\TypeManager();
foreach ($typeManager->getConfiguredTypes() as $type) {
if (empty($allTemplates[$type->getScope()])) {
continue;
}
foreach ($allTemplates[$type->getScope()] as $templateName) {
$path = $basePath . $templateName . '.' . $type->getId() . '.xml';
if (!is_file($path)) {
$template = $templatePath . '/' . $templateName . '.' . $scope . '.xml';
@copy($template, $path);
}
}
}
}
?>

View File

@ -1,4 +1,6 @@
<?php
namespace LAM\PROFILES;
use \LAMException;
/*
$Id$
@ -230,4 +232,39 @@ function copyAccountProfileToTemplates($sourceType, $sourceProfileName) {
}
}
/**
* Installs template profiles to the current server profile.
*/
function installProfileTemplates() {
$templatePath = dirname(__FILE__) . '/../config/templates/profiles';
$templateDir = @dir($templatePath);
$allTemplates = array();
if ($templateDir) {
$entry = $templateDir->read();
while ($entry){
$parts = explode('.', $entry);
if ((strlen($entry) > 3) && (sizeof($parts) == 2)) {
$name = $parts[0];
$scope = $parts[1];
$allTemplates[$scope][] = $name;
}
$entry = $templateDir->read();
}
}
$basePath = dirname(__FILE__) . '/../config/profiles/' . $_SESSION['config']->getName() . '/';
$typeManager = new \LAM\TYPES\TypeManager();
foreach ($typeManager->getConfiguredTypes() as $type) {
if (empty($allTemplates[$type->getScope()])) {
continue;
}
foreach ($allTemplates[$type->getScope()] as $templateName) {
$path = $basePath . $templateName . '.' . $type->getId();
if (!is_file($path)) {
$template = $templatePath . '/' . $templateName . '.' . $scope;
@copy($template, $path);
}
}
}
}
?>

View File

@ -160,15 +160,15 @@ class ConfiguredType {
private $id;
private $suffix;
private $suffix = null;
private $attributes;
private $attributes = null;
private $alias;
private $alias = null;
private $additionalLdapFilter;
private $additionalLdapFilter = null;
private $hidden;
private $hidden = null;
private $baseType;
@ -180,22 +180,11 @@ class ConfiguredType {
* @param TypeManager $typeManager type manager
* @param string $scope account type
* @param string $id unique ID for this configuration
* @param string $suffix LDAP base suffix
* @param array $attributes list of ListAttribute
* @param string $alias alias name for display
* @param string $ldapFilter additional LDAP filter
* @param boolean $hidden hidden in GUI
*/
public function __construct(&$typeManager, $scope, $id, $suffix, $attributes, $alias,
$ldapFilter, $hidden) {
public function __construct(&$typeManager, $scope, $id) {
$this->typeManager = &$typeManager;
$this->scope = $scope;
$this->id = $id;
$this->suffix = $suffix;
$this->attributes = $attributes;
$this->alias = $alias;
$this->additionalLdapFilter = $ldapFilter;
$this->hidden = $hidden;
}
/**
@ -231,6 +220,10 @@ class ConfiguredType {
* @return string LDAP suffix
*/
public function getSuffix() {
if ($this->suffix !== null) {
return $this->suffix;
}
$this->suffix = $this->typeManager->getConfig()->get_Suffix($this->id);
return $this->suffix;
}
@ -240,6 +233,16 @@ class ConfiguredType {
* @return ListAttribute[] list of ListAttribute
*/
public function getAttributes() {
if ($this->attributes !== null) {
return $this->attributes;
}
$attributeString = $this->typeManager->getConfig()->get_listAttributes($this->id);
$attributeSpecs = explode(';', $attributeString);
$attributes = array();
foreach ($attributeSpecs as $attributeSpec) {
$attributes[] = new ListAttribute($attributeSpec, $this->scope);
}
$this->attributes = $attributes;
return $this->attributes;
}
@ -249,6 +252,10 @@ class ConfiguredType {
* @return string alias name
*/
public function getAlias() {
if ($this->alias !== null) {
return $this->alias;
}
$this->alias = getTypeAlias($this->id, $this->typeManager->getConfig());
return $this->alias;
}
@ -258,6 +265,10 @@ class ConfiguredType {
* @return string LDAP filter
*/
public function getAdditionalLdapFilter() {
if ($this->additionalLdapFilter !== null) {
return $this->additionalLdapFilter;
}
$this->additionalLdapFilter = $this->typeManager->getConfig()->get_Suffix($typeId);
return $this->additionalLdapFilter;
}
@ -267,6 +278,10 @@ class ConfiguredType {
* @return boolean hidden
*/
public function isHidden() {
if ($this->hidden !== null) {
return $this->hidden;
}
$this->hidden = isAccountTypeHidden($this->id);
return $this->hidden;
}
@ -293,7 +308,7 @@ class ConfiguredType {
$connection = $_SESSION["ldap"]->server();
$ret = array();
$filter = $this->getBaseType()->getSuffixFilter();
$sr = @ldap_search($connection, escapeDN($this->suffix), $filter, array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
$sr = @ldap_search($connection, escapeDN($this->getSuffix()), $filter, array('dn', 'objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
if ($sr) {
$units = ldap_get_entries($connection, $sr);
cleanLDAPResult($units);
@ -312,13 +327,13 @@ class ConfiguredType {
// add root suffix if needed
$found = false;
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive
if (strtolower($this->suffix) == strtolower($ret[$i])) {
if (strtolower($this->getSuffix()) == strtolower($ret[$i])) {
$found = true;
break;
}
}
if (!$found) {
$ret[] = $this->suffix;
$ret[] = $this->getSuffix();
}
usort($ret, 'compareDN');
return $ret;
@ -466,29 +481,7 @@ class TypeManager {
*/
private function buildConfiguredType($typeId) {
$scope = getScopeFromTypeId($typeId);
$suffix = $this->config->get_Suffix($typeId);
$attributes = $this->getAttributes($typeId, $scope);
$alias = getTypeAlias($typeId, $this->config);
$ldapFilter = $this->config->get_Suffix($typeId);
$hidden = isAccountTypeHidden($typeId);
return new ConfiguredType($this, $scope, $typeId, $suffix, $attributes, $alias, $ldapFilter, $hidden);
}
/**
* Builds the list of account list attributes.
*
* @param string $typeId type id
* @param string $scope account type
* @return \LAM\TYPES\ListAttribute[] list attributes
*/
private function getAttributes($typeId, $scope) {
$attributeString = $this->config->get_listAttributes($typeId);
$attributeSpecs = explode(';', $attributeString);
$attributes = array();
foreach ($attributeSpecs as $attributeSpec) {
$attributes[] = new ListAttribute($attributeSpec, $scope);
}
return $attributes;
return new ConfiguredType($this, $scope, $typeId);
}
/**

View File

@ -112,13 +112,6 @@ function upgradeConfigToServerProfileFolders($profiles) {
return;
}
// copy default configs
if (!file_exists('../config/templates')) {
@mkdir('../config/templates', 0700);
recursiveCopy('../config/pdf/', '../config/templates/pdf/', $profiles, 'default.');
recursiveCopy('../config/profiles/', '../config/templates/profiles/', $profiles, 'default.');
}
foreach ($profiles as $profile) {
// upgrade PDF configs
$dir = '../config/pdf/' . $profile;

View File

@ -1,9 +1,11 @@
<?php
namespace LAM\PDF;
/*
$Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner
2017 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
@ -22,44 +24,44 @@ $Id$
/**
* Simple XML parser.
*
*
* @author Michael Duergner
* @package PDF
*/
/**
* Simple XML parser.
*
*
* @author Michael Duergner
* @package PDF
*/
class xmlParser {
/** XML parser */
private $xmlParser;
/**
* Constructor
*/
function __construct() {
$this->xmlParser = xml_parser_create();
xml_set_object($this->xmlParser,$this);
xml_set_object($this->xmlParser, $this);
xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, 1);
xml_parser_set_option($this->xmlParser, XML_OPTION_SKIP_WHITE, 1);
}
/**
* Starts the parsing.
*
* @param String $filename file name
*
* @param String $filename file name
* @return array XML structure
*/
function parse($filename) {
if(file_exists($filename)) {
$xmlStructure = array();
$xmlIndex = array();
xml_parse_into_struct($this->xmlParser,implode("\n",file($filename)),$xmlStructure,$xmlIndex);
return array($xmlStructure,$xmlIndex);
xml_parse_into_struct($this->xmlParser, implode("\n", file($filename)), $xmlStructure, $xmlIndex);
return array($xmlStructure, $xmlIndex);
}
return array();
}

View File

@ -1,4 +1,5 @@
<?php
namespace LAM\INIT;
/*
$Id$
@ -29,18 +30,23 @@ $Id$
*/
/** config object */
include_once('../lib/config.inc');
include_once '../lib/config.inc';
/** profiles */
include_once '../lib/profiles.inc';
// start session
startSecureSession();
setlanguage();
\LAM\PROFILES\installProfileTemplates();
\LAM\PDF\installPDFTemplates();
// check if all suffixes in conf-file exist
$conf = $_SESSION['config'];
$new_suffs = array();
// get list of active types
$typeManager = new LAM\TYPES\TypeManager();
$typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER);
@ -68,4 +74,5 @@ else {
metaRefresh("tree/treeViewContainer.php");
}
}
?>

View File

@ -40,7 +40,7 @@ $Id$
*/
/**
* This is the main window of the pdf structure editor.
* This is the main window of the PDF structure editor.
*
* @author Michael Duergner
* @author Roland Gruber
@ -72,10 +72,9 @@ if (!empty($_POST)) {
setlanguage();
// Unset pdf structure definitions in session if set
// Unset PDF structure definitions in session if set
if(isset($_SESSION['currentPDFStructure'])) {
unset($_SESSION['currentPDFStructure']);
unset($_SESSION['availablePDFFields']);
unset($_SESSION['currentPageDefinitions']);
}
@ -107,7 +106,7 @@ $container->addElement(new htmlTitle(_('PDF editor')), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
// delete structure
if (deletePDFStructureDefinition($_POST['profileDeleteType'], $_POST['profileDeleteName'])) {
if (\LAM\PDF\deletePDFStructure($_POST['profileDeleteType'], $_POST['profileDeleteName'])) {
$message = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
@ -119,29 +118,57 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
}
}
if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
$configProfiles = getConfigProfiles();
$serverProfiles = array();
foreach ($configProfiles as $profileName) {
$serverProfiles[$profileName] = new \LAMConfig($profileName);
}
// import structures
if (!empty($_POST['import'])) {
$cfg = new LAMCfgMain();
$impExpMessage = null;
if (isset($_POST['importProfiles_' . $_POST['typeId']])) {
// check master password
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyPdfProfiles($_POST['importProfiles_' . $_POST['typeId']], $_POST['typeId'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Import successful'));
}
} else if (isset($_POST['exportProfiles'])) {
// check master password
if (!$cfg->checkPassword($_POST['passwd'])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (copyPdfProfiles($_POST['exportProfiles'], $_POST['typeId'], $_POST['destServerProfiles'])) {
$impExpMessage = new htmlStatusMessage('INFO', _('Export successful'));
}
$typeId = $_POST['typeId'];
// check master password
$errMessage = null;
if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) {
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
if ($impExpMessage != null) {
$impExpMessage->colspan = 10;
$container->addElement($impExpMessage, true);
elseif (!empty($_POST['importProfiles_' . $typeId])) {
$options = array();
foreach ($_POST['importProfiles_' . $typeId] as $importProfiles) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]);
}
$errMessage = importStructures($_POST['typeId'], $options, $serverProfiles, $typeManager);
}
if ($errMessage != null) {
$errMessage->colspan = 10;
$container->addElement($errMessage, true);
}
}
// export structures
if (!empty($_POST['export'])) {
$cfg = new LAMCfgMain();
$typeId = $_POST['typeId'];
// check master password
$errMessage = null;
if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) {
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (!empty($_POST['exportProfiles_' . $typeId])) {
$options = array();
foreach ($_POST['exportProfiles_' . $typeId] as $importProfiles) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1]);
}
$typeId = $_POST['typeId'];
$name = $_POST['name_' . $typeId];
$errMessage = exportStructures($typeId, $name, $options, $serverProfiles, $typeManager);
}
if ($errMessage != null) {
$errMessage->colspan = 10;
$container->addElement($errMessage, true);
}
}
@ -149,13 +176,13 @@ if (isset($_POST['importexport']) && ($_POST['importexport'] === '1')) {
if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) {
$file = $_FILES['logoUpload']['tmp_name'];
$filename = $_FILES['logoUpload']['name'];
$container->addElement(uploadPDFLogo($file, $filename), true);
$container->addElement(\LAM\PDF\uploadPDFLogo($file, $filename), true);
}
// delete logo file
if (isset($_POST['delLogo'])) {
$toDel = $_POST['logo'];
$container->addElement(deletePDFLogo($toDel), true);
$container->addElement(\LAM\PDF\deletePDFLogo($toDel), true);
}
// get list of account types
@ -172,7 +199,7 @@ foreach ($sortedTypes as $typeId => $title) {
}
// get list of templates for each account type
for ($i = 0; $i < sizeof($templateClasses); $i++) {
$templateClasses[$i]['templates'] = getPDFStructureDefinitions($templateClasses[$i]['typeId']);
$templateClasses[$i]['templates'] = \LAM\PDF\getPDFStructures($templateClasses[$i]['typeId']);
}
// check if a template should be edited
@ -210,8 +237,6 @@ include '../main_header.php';
}
// existing templates
$configProfiles = getConfigProfiles();
$container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true);
$existingContainer = new htmlTable();
for ($i = 0; $i < sizeof($templateClasses); $i++) {
@ -255,7 +280,7 @@ include '../main_header.php';
$logoContainer = new htmlTable();
$logoContainer->addElement(new htmlSpacer(null, '30px'), true);
$logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true);
$logos = getAvailableLogos();
$logos = \LAM\PDF\getAvailableLogos();
$logoOptions = array();
foreach ($logos as $logo) {
$file = $logo['filename'];
@ -284,12 +309,19 @@ include '../main_header.php';
for ($i = 0; $i < sizeof($templateClasses); $i++) {
$typeId = $templateClasses[$i]['typeId'];
$tmpArr = array();
$scope = $templateClasses[$i]['scope'];
$importOptions = array();
foreach ($configProfiles as $profile) {
if ($profile != $_SESSION['config']->getName()) {
$accountProfiles = getPDFStructureDefinitions($typeId, $profile);
for ($p = 0; $p < sizeof($accountProfiles); $p++) {
$tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p];
$typeManagerImport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$typesImport = $typeManagerImport->getConfiguredTypesForScope($scope);
foreach ($typesImport as $typeImport) {
if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) {
$accountProfiles = \LAM\PDF\getPDFStructures($typeImport->getId(), $profile);
if (!empty($accountProfiles)) {
foreach ($accountProfiles as $accountProfile) {
$importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfile] = $profile . '##' . $typeImport->getId() . '##' . $accountProfile;
}
}
}
}
}
@ -301,7 +333,7 @@ include '../main_header.php';
$container = new htmlTable();
$container->addElement(new htmlOutputText(_('PDF structures')), true);
$select = new htmlSelect('importProfiles_' . $typeId, $tmpArr, array(), count($tmpArr, 1) < 15 ? count($tmpArr, 1) : 15);
$select = new htmlSelect('importProfiles_' . $typeId, $importOptions, array(), count($importOptions, 1) < 15 ? count($importOptions, 1) : 15);
$select->setMultiSelect(true);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
@ -313,11 +345,11 @@ include '../main_header.php';
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_' . $typeId);
$exportPasswd = new htmlInputField('passwd_i_' . $typeId);
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'));
$container->addElement(new htmlHiddenInput('import', '1'));
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
addSecurityTokenToMetaHTML($container);
@ -325,54 +357,52 @@ include '../main_header.php';
echo '</form>';
echo "</div>\n";
//export dialog
echo "<div id=\"exportDialog_$typeId\" class=\"hidden\">\n";
echo "<form id=\"exportDialogForm_$typeId\" method=\"post\" action=\"pdfmain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_("Target server profile")), true);
$exportOptions = array();
foreach ($configProfiles as $profile) {
$typeManagerExport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$typesExport = $typeManagerExport->getConfiguredTypesForScope($scope);
foreach ($typesExport as $typeExport) {
if (($profile != $_SESSION['config']->getName()) || ($typeExport->getId() != $typeId)) {
$exportOptions[$typeManagerExport->getConfig()->getName()][$typeExport->getAlias()] = $profile . '##' . $typeExport->getId();
}
}
}
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##';
$select = new htmlSelect('exportProfiles_' . $typeId, $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions, 1) : 10);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
$select->setMultiSelect(true);
$container->addElement($select);
$container->addElement(new htmlHelpLink('363'), true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_e_' . $typeId);
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('export', '1'), true);
$container->addElement(new htmlHiddenInput('typeId', $typeId), true);
$container->addElement(new htmlHiddenInput('name_' . $typeId, '_'), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
echo '</form>';
echo "</div>\n";
}
//export dialog
echo "<div id=\"exportDialog\" class=\"hidden\">\n";
echo "<form id=\"exportDialogForm\" method=\"post\" action=\"pdfmain.php\">\n";
$container = new htmlTable();
$container->addElement(new htmlOutputText(_('PDF structure')), true);
$expStructGroup = new htmlTable();
$expStructGroup->addElement(new htmlSpacer('10px', null));
$expStructGroup->addElement(new htmlDiv('exportName', ''));
$container->addElement($expStructGroup, true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Target server profile")), true);
foreach ($configProfiles as $key => $value) {
$tmpProfiles[$value] = $value;
}
natcasesort($tmpProfiles);
$tmpProfiles['*' . _('Global templates')] = 'templates*';
$findProfile = array_search($_SESSION['config']->getName(), $tmpProfiles);
if ($findProfile !== false) {
unset($tmpProfiles[$findProfile]);
}
$select = new htmlSelect('destServerProfiles', $tmpProfiles, array(), count($tmpProfiles) < 10 ? count($tmpProfiles) : 10);
$select->setHasDescriptiveElements(true);
$select->setSortElements(false);
$select->setMultiSelect(true);
$container->addElement($select);
$container->addElement(new htmlHelpLink('409'), true);
$container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd');
$exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1'), true);
addSecurityTokenToMetaHTML($container);
parseHtml(null, $container, array(), false, $tabindex, 'user');
echo '</form>';
echo "</div>\n";
// form for delete action
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">';
echo _("Do you really want to delete this PDF structure?");
@ -385,4 +415,77 @@ echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm"
echo '</form></div>';
include '../main_footer.php';
/**
* Imports the selected PDF structures.
*
* @param string $typeId type id
* @param array $options options
* @param \LAMConfig[] $serverProfiles server profiles (name => profile object)
* @param \LAM\TYPES\TypeManager $typeManager type manager
* @return \htmlStatusMessage message or null
*/
function importStructures($typeId, $options, &$serverProfiles, &$typeManager) {
foreach ($options as $option) {
$sourceConfName = $option['conf'];
$sourceTypeId = $option['typeId'];
$sourceName = $option['name'];
$sourceTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$sourceConfName]);
$sourceType = $sourceTypeManager->getConfiguredType($sourceTypeId);
$targetType = $typeManager->getConfiguredType($typeId);
if (($sourceType != null) && ($targetType != null)) {
try {
\LAM\PDF\copyStructure($sourceType, $sourceName, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
}
return new \htmlStatusMessage('INFO', _('Import successful'));
}
/**
* Exports the selected account profile.
*
* @param string $typeId source type id
* @param string $name profile name
* @param array $options options
* @param \LAMConfig[] $serverProfiles server profiles (name => profile object)
* @param \LAM\TYPES\TypeManager $typeManager type manager
* @return \htmlStatusMessage message or null
*/
function exportStructures($typeId, $name, $options, &$serverProfiles, &$typeManager) {
$sourceType = $typeManager->getConfiguredType($typeId);
if ($sourceType == null) {
return null;
}
foreach ($options as $option) {
$targetConfName = $option['conf'];
if ($targetConfName == 'templates*') {
try {
\LAM\PDF\copyStructureToTemplates($sourceType, $name);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
else {
$targetTypeId = $option['typeId'];
$targetTypeManager = new \LAM\TYPES\TypeManager($serverProfiles[$targetConfName]);
$targetType = $targetTypeManager->getConfiguredType($targetTypeId);
if ($targetType != null) {
try {
\LAM\PDF\copyStructure($sourceType, $name, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
}
}
}
}
return new \htmlStatusMessage('INFO', _('Export successful'));
}
?>

View File

@ -129,7 +129,7 @@ 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($type->getId(), $_GET['pdfname']);
$return = \LAM\PDF\savePDFStructure($type->getId(), $_GET['pdfname']);
if($return == 'ok') {
metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']);
exit;
@ -356,23 +356,20 @@ foreach ($_GET as $key => $value) {
if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit
if(isset($_GET['edit'])) {
$load = loadPDFStructureDefinitions($type->getId(), $_GET['edit']);
$load = \LAM\PDF\loadPDFStructure($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($type->getId());
$load = \LAM\PDF\loadPDFStructure($type->getId());
$_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions'];
}
}
// Load available fields from modules when not set in session
if(!isset($_SESSION['availablePDFFields'])) {
$_SESSION['availablePDFFields'] = getAvailablePDFFields($type->getId());
}
$availablePDFFields = getAvailablePDFFields($type->getId());
// Create the values for the dropdown boxes for section headline defined by
// value entries and fetch all available modules
@ -380,7 +377,7 @@ $modules = array();
$section_items_array = array();
$section_items = '';
$sortedModules = array();
foreach($_SESSION['availablePDFFields'] as $module => $fields) {
foreach($availablePDFFields as $module => $fields) {
if ($module != 'main') {
$title = getModuleAlias($module, $type->getScope());
}
@ -391,7 +388,7 @@ foreach($_SESSION['availablePDFFields'] as $module => $fields) {
}
natcasesort($sortedModules);
foreach($sortedModules as $module => $title) {
$values = $_SESSION['availablePDFFields'][$module];
$values = $availablePDFFields[$module];
if (!is_array($values) || (sizeof($values) < 1)) {
continue;
}
@ -419,7 +416,7 @@ if (sizeof($saveErrors) > 0) {
$newFieldFieldElements = array();
foreach($sortedModules as $module => $title) {
$fields = $_SESSION['availablePDFFields'][$module];
$fields = $availablePDFFields[$module];
if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) {
$moduleFields = array();
foreach ($fields as $field => $fieldLabel) {
@ -446,7 +443,7 @@ if (isset($_SESSION['currentPageDefinitions']['headline'])) {
$headline = $_SESSION['currentPageDefinitions']['headline'];
}
// logo
$logoFiles = getAvailableLogos();
$logoFiles = \LAM\PDF\getAvailableLogos();
$logos = array(_('No logo') => 'none');
foreach($logoFiles as $logoFile) {
$logos[$logoFile['filename'] . ' (' . $logoFile['infos'][0] . ' x ' . $logoFile['infos'][1] . ")"] = $logoFile['filename'];
@ -459,7 +456,7 @@ if (isset($_SESSION['currentPageDefinitions']['filename'])) {
?>
<form id="inputForm" action="pdfpage.php" method="post" onSubmit="saveScrollPosition('inputForm')">
<?php
$sectionElements = array(_('Beginning') => 0);
$sectionElements = array();
$nonTextSectionElements = array();
$container = new htmlTable();
@ -498,10 +495,10 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$linkRemove->setTitle(_("Remove"));
$emptyBox = new htmlOutputText('');
// We have a new section to start
if($entry['tag'] == "SECTION" && $entry['type'] == "open") {
if(($entry['tag'] == "SECTION") && ($entry['type'] == 'open')) {
$name = $entry['attributes']['NAME'];
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) {
$section_headline = translateFieldIDToName(substr($name,1), $type->getScope());
$section_headline = translateFieldIDToName(substr($name,1), $type->getScope(), $availablePDFFields);
}
else {
$section_headline = $name;
@ -513,7 +510,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, $type->getScope())] = '_' . $item;
$headlineElements[translateFieldIDToName($item, $type->getScope(), $availablePDFFields)] = '_' . $item;
}
$sectionHeadlineSelect = new htmlSelect('section_' . $key, $headlineElements, array($name));
$sectionHeadlineSelect->setHasDescriptiveElements(true);
@ -583,7 +580,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, $type->getScope()));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope(), $availablePDFFields));
$structureContent->addElement($fieldOutput);
if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkUp);
@ -600,6 +597,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$structureContent->addElement($linkRemove, true);
}
}
$sectionElements[_('End')] = sizeof($_SESSION['currentPDFStructure']);
$structureContent->colspan = 3;
$mainContent->addElement($structureContent);
$container->addElement(new htmlFieldset($mainContent), true);
@ -638,19 +636,21 @@ $newTextFieldContent->addElement(new htmlButton('add_text', _('Add')));
$container->addElement(new htmlFieldset($newTextFieldContent, _("Text field")), true);
// new field
$container->addElement(new htmlSubTitle(_('New field')), true);
$newFieldContainer = new htmlTable();
$newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements);
$newFieldFieldSelect->setHasDescriptiveElements(true);
$newFieldFieldSelect->setContainsOptgroups(true);
$newFieldContainer->addElement($newFieldFieldSelect);
$newFieldContainer->addElement(new htmlSpacer('10px', null));
$newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position'));
$newFieldSectionSelect->setHasDescriptiveElements(true);
$newFieldContainer->addElement($newFieldSectionSelect);
$newFieldContainer->addElement(new htmlButton('add_new_field', _('Add')));
$container->addElement(new htmlFieldset($newFieldContainer), true);
$container->addElement(new htmlSpacer(null, '20px'), true);
if (!empty($nonTextSectionElements)) {
$container->addElement(new htmlSubTitle(_('New field')), true);
$newFieldContainer = new htmlTable();
$newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements);
$newFieldFieldSelect->setHasDescriptiveElements(true);
$newFieldFieldSelect->setContainsOptgroups(true);
$newFieldContainer->addElement($newFieldFieldSelect);
$newFieldContainer->addElement(new htmlSpacer('10px', null));
$newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position'));
$newFieldSectionSelect->setHasDescriptiveElements(true);
$newFieldContainer->addElement($newFieldSectionSelect);
$newFieldContainer->addElement(new htmlButton('add_new_field', _('Add')));
$container->addElement(new htmlFieldset($newFieldContainer), true);
$container->addElement(new htmlSpacer(null, '20px'), true);
}
// buttons
$buttonContainer = new htmlTable();
@ -688,9 +688,10 @@ include '../main_footer.php';
*
* @param String $id field ID
* @param String $scope account type
* @param array $availablePDFFields available PDF fields
*/
function translateFieldIDToName($id, $scope) {
foreach ($_SESSION['availablePDFFields'] as $module => $fields) {
function translateFieldIDToName($id, $scope, $availablePDFFields) {
foreach ($availablePDFFields as $module => $fields) {
if (!(strpos($id, $module . '_') === 0)) {
continue;
}

View File

@ -14,7 +14,6 @@ use \htmlOutputText;
use \htmlHelpLink;
use \htmlHiddenInput;
use \htmlInputField;
use \htmlDiv;
/*
$Id$
@ -123,7 +122,7 @@ if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
die();
}
// delete profile
if (delAccountProfile($_POST['profileDeleteName'], $_POST['profileDeleteType'])) {
if (\LAM\PROFILES\delAccountProfile($_POST['profileDeleteName'], $_POST['profileDeleteType'])) {
$message = new htmlStatusMessage('INFO', _('Deleted profile.'), $type->getAlias() . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10;
$container->addElement($message, true);
@ -145,9 +144,9 @@ foreach ($configProfiles as $profileName) {
if (!empty($_POST['import'])) {
$cfg = new LAMCfgMain();
// check master password
$impMessage = null;
$errMessage = null;
if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) {
$impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (!empty($_POST['importProfiles'])) {
$options = array();
@ -155,20 +154,20 @@ if (!empty($_POST['import'])) {
$parts = explode('##', $importProfiles);
$options[] = array('conf' => $parts[0], 'typeId' => $parts[1], 'name' => $parts[2]);
}
$impMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager);
$errMessage = importProfiles($_POST['typeId'], $options, $serverProfiles, $typeManager);
}
if ($impMessage != null) {
$impMessage->colspan = 10;
$container->addElement($impMessage, true);
if ($errMessage != null) {
$errMessage->colspan = 10;
$container->addElement($errMessage, true);
}
}
// export profiles
if (!empty($_POST['export'])) {
$cfg = new LAMCfgMain();
// check master password
$impMessage = null;
$errMessage = null;
if (!$cfg->checkPassword($_POST['passwd_e_' . $_POST['typeId']])) {
$impMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
$errMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!'));
}
elseif (!empty($_POST['exportProfiles'])) {
$options = array();
@ -178,17 +177,17 @@ if (!empty($_POST['export'])) {
}
$typeId = $_POST['typeId'];
$name = $_POST['name_' . $typeId];
$impMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager);
$errMessage = exportProfiles($typeId, $name, $options, $serverProfiles, $typeManager);
}
if ($impMessage != null) {
$impMessage->colspan = 10;
$container->addElement($impMessage, true);
if ($errMessage != null) {
$errMessage->colspan = 10;
$container->addElement($errMessage, true);
}
}
// get list of profiles for each account type
for ($i = 0; $i < sizeof($profileClasses); $i++) {
$profileList = getAccountProfiles($profileClasses[$i]['typeId']);
$profileList = \LAM\PROFILES\getAccountProfiles($profileClasses[$i]['typeId']);
natcasesort($profileList);
$profileClasses[$i]['profiles'] = $profileList;
}
@ -277,7 +276,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
$typesImport = $typeManagerImport->getConfiguredTypesForScope($scope);
foreach ($typesImport as $typeImport) {
if (($profile != $_SESSION['config']->getName()) || ($typeImport->getId() != $typeId)) {
$accountProfiles = getAccountProfiles($typeImport->getId(), $profile);
$accountProfiles = \LAM\PROFILES\getAccountProfiles($typeImport->getId(), $profile);
if (!empty($accountProfiles)) {
for ($p = 0; $p < sizeof($accountProfiles); $p++) {
$importOptions[$profile][$typeImport->getAlias() . ': ' . $accountProfiles[$p]] = $profile . '##' . $typeImport->getId() . '##' . $accountProfiles[$p];
@ -338,7 +337,7 @@ for ($i = 0; $i < sizeof($profileClasses); $i++) {
}
$exportOptions['*' . _('Global templates')][_('Global templates')] = 'templates*##';
$select = new htmlSelect('exportProfiles', $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions) : 10);
$select = new htmlSelect('exportProfiles', $exportOptions, array(), count($exportOptions) < 10 ? count($exportOptions, 1) : 10);
$select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true);
$select->setMultiSelect(true);
@ -397,7 +396,7 @@ function importProfiles($typeId, $options, &$serverProfiles, &$typeManager) {
$targetType = $typeManager->getConfiguredType($typeId);
if (($sourceType != null) && ($targetType != null)) {
try {
\copyAccountProfile($sourceType, $sourceName, $targetType);
\LAM\PROFILES\copyAccountProfile($sourceType, $sourceName, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
@ -426,7 +425,7 @@ function exportProfiles($typeId, $name, $options, &$serverProfiles, &$typeManage
$targetConfName = $option['conf'];
if ($targetConfName == 'templates*') {
try {
\copyAccountProfileToTemplates($sourceType, $name);
\LAM\PROFILES\copyAccountProfileToTemplates($sourceType, $name);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());
@ -438,7 +437,7 @@ function exportProfiles($typeId, $name, $options, &$serverProfiles, &$typeManage
$targetType = $targetTypeManager->getConfiguredType($targetTypeId);
if ($targetType != null) {
try {
\copyAccountProfile($sourceType, $name, $targetType);
\LAM\PROFILES\copyAccountProfile($sourceType, $name, $targetType);
}
catch (\LAMException $e) {
return new \htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage());

View File

@ -135,7 +135,7 @@ if (isset($_POST['save'])) {
$errors = checkProfileOptions($_POST['accounttype'], $options);
if (sizeof($errors) == 0) { // input data is valid, save profile
// save profile
if (saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) {
if (\LAM\PROFILES\saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) {
metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']);
exit();
}
@ -181,7 +181,7 @@ if (isset($_POST['save'])) {
}
}
elseif (isset($_GET['edit'])) {
$old_options = loadAccountProfile($_GET['edit'], $type->getId());
$old_options = \LAM\PROFILES\loadAccountProfile($_GET['edit'], $type->getId());
}
// display formular

View File

@ -267,7 +267,7 @@ function showMainPage($scope, $selectedModules) {
$pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files'));
$pdfCheckbox->setTableRowsToShow(array('pdfStructure'));
$inputContainer->addElement($pdfCheckbox, true);
$pdfStructures = getPDFStructureDefinitions($scope);
$pdfStructures = \LAM\PDF\getPDFStructures($scope);
$pdfSelected = array();
if (isset($_POST['pdfStructure'])) {
$pdfSelected = array($_POST['pdfStructure']);

View File

@ -252,6 +252,12 @@ class LAMConfigTest extends PHPUnit_Framework_TestCase {
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
$this->doSave();
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
// empty script
$val = '';
$this->lAMConfig->set_scriptPath($val);
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
$this->doSave();
$this->assertEquals($val, $this->lAMConfig->get_scriptPath());
}
/**