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

View File

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

View File

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

View File

@ -1,4 +1,8 @@
<?php <?php
namespace LAM\PDF;
use \htmlStatusMessage;
use \LAMException;
/* /*
$Id$ $Id$
@ -46,7 +50,7 @@ include_once("ldap.inc");
* scope. Each entry is a string being the filename that may be passed to the * scope. Each entry is a string being the filename that may be passed to the
* createModulePDF() function as second argument. * createModulePDF() function as second argument.
*/ */
function getPDFStructureDefinitions($scope = "user", $profile = null) { function getPDFStructures($scope = "user", $profile = null) {
$return = array(); $return = array();
if (!isset($profile)) { if (!isset($profile)) {
@ -67,22 +71,24 @@ function getPDFStructureDefinitions($scope = "user", $profile = null) {
} }
/** /**
* This function is used to get pdf structure from xml file. * This function is used to get the PDF structure from XML file.
* Used in createModulePDF.
* *
* @param string $scope The account scope for wich the PDF structure should be returned. * @param string $typeId the account type
* @param string $pdf_structure Structure name of selected scope wich should be returned. * @param string $name structure name
* *
* @return array PDF structure * @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(); $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); $xml = $parser->parse($file);
$border = array(); $border = array();
$structure = array(); $structure = array();
$complete_page_definitions = array('filename' => 'printLogo.jpg', 'headline' => 'LDAP Account Manager'); $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]; $border['start'] = $xml[1]['PDF'][0];
$page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes']; $page_definitions = $xml[0][$xml[1]['PDF'][0]]['attributes'];
foreach($page_definitions as $key => $value) { foreach($page_definitions as $key => $value) {
@ -90,23 +96,24 @@ function loadPDFStructureDefinitions($scope='user',$pdf_structure='default') {
unset($page_definitions[$key]); unset($page_definitions[$key]);
} }
$border['end'] = $xml[1]['PDF'][1]; $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); 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 $typeId account type
* @param string $definition Name of definition * @param string $name name of structure
* @return string "no perms" if access denied or "ok". * @return string "no perms" if access denied or "ok".
*/ */
function savePDFStructureDefinitions($scope,$definition) { function savePDFStructure($typeId, $name) {
if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return 'no perms'; if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/', $typeId)) {
if (!preg_match('/[a-zA-Z]+/',$scope)) return 'no perms'; return 'no perms';
$struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; }
$struct_file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) { if(!is_writable(dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName())) {
return 'no perms'; return 'no perms';
} }
@ -115,11 +122,9 @@ function savePDFStructureDefinitions($scope,$definition) {
if (!$handle) return 'no perms'; if (!$handle) return 'no perms';
$pdf_attributes = ''; $pdf_attributes = '';
foreach($_SESSION['currentPageDefinitions'] as $key => $value) { 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) { foreach($_SESSION['currentPDFStructure'] as $entry) {
$ident = ''; $ident = '';
for($i=0;$i<$entry['level'] -1;$i++) { for($i=0;$i<$entry['level'] -1;$i++) {
@ -156,15 +161,16 @@ function savePDFStructureDefinitions($scope,$definition) {
/** /**
* Deletes XML file with PDF structure definitions. * Deletes XML file with PDF structure definitions.
* *
* @param string $scope account type * @param string $typeId account type
* @param string $definition Name of definition to delete * @param string $name Name of definition to delete
* *
* @return boolean True if file was deleted or false if a problem occured. * @return boolean True if file was deleted or false if a problem occured.
*/ */
function deletePDFStructureDefinition($scope, $definition) { function deletePDFStructure($typeId, $name) {
if (!preg_match('/[a-zA-Z0-9\-\_]+/',$definition)) return false; if (!isValidPDFStructureName($name) || !preg_match('/[a-zA-Z]+/',$typeId)) {
if (!preg_match('/[a-zA-Z]+/',$scope)) return false; return false;
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $definition . '.' . $scope . '.xml'; }
$file = dirname(__FILE__) . '/../config/pdf/' . $_SESSION['config']->getName() . '/' . $name . '.' . $typeId . '.xml';
if(is_file($file) && is_writable($file)) { if(is_file($file) && is_writable($file)) {
return unlink($file); return unlink($file);
} }
@ -195,46 +201,50 @@ function getAvailableLogos() {
return $return; 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 \LAM\TYPES\ConfiguredType $sourceType source type
* @param String $scope account scope * @param string $sourceName structure name
* @param array $dests destinations * @throws Exception
*
* @return boolean operation succeeded
*/ */
function copyPdfProfiles($pdfProfiles, $scope, $dests = array()) { function copyStructureToTemplates($sourceType, $sourceName) {
$state = true; if (!isValidPDFStructureName($sourceName)) {
$profilePath = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/pdf/'; throw new LAMException(_('Failed to copy'));
foreach ($pdfProfiles as $profile) { }
//part 1: server profile $sourceConfig = $sourceType->getTypeManager()->getConfig()->getName();
//part 2: account profile $sourceTypeId = $sourceType->getId();
$tmpArr = explode('##', $profile); $basePath = dirname(__FILE__) . '/../config/pdf/';
$src = $profilePath . $tmpArr[0] . '/' . $tmpArr[1] . '.' . $scope . '.xml'; $templatePath = dirname(__FILE__) . '/../config/templates/pdf/';
if (!empty($dests)) { $src = $basePath . $sourceConfig . '/' . $sourceName . '.' . $sourceTypeId . '.xml';
foreach ($dests as $dest) { $dst = $templatePath . $sourceName . '.' . $sourceType->getScope() . '.xml';
if ($dest == 'templates*') { if (!@copy($src, $dst)) {
$dst = substr(__FILE__, 0, strlen(__FILE__) - 17) . 'config/templates/pdf/' . $tmpArr[1] . '.' . $scope . '.xml'; throw new LAMException(_('Failed to copy'), $sourceConfig . ': ' . $sourceName);
} 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;
}
}
} }
return $state;
} }
/** /**
@ -284,12 +294,12 @@ function deletePDFLogo($name) {
// check if still in use // check if still in use
$activeTypes = $_SESSION['config']->get_ActiveTypes(); $activeTypes = $_SESSION['config']->get_ActiveTypes();
foreach ($activeTypes as $type) { foreach ($activeTypes as $type) {
$structures = getPDFStructureDefinitions($type); $structures = getPDFStructures($type);
foreach ($structures as $structure) { foreach ($structures as $structure) {
$data = loadPDFStructureDefinitions($type, $structure); $data = loadPDFStructure($type, $structure);
if ($data['page_definitions']['filename'] == $name) { if ($data['page_definitions']['filename'] == $name) {
return new htmlStatusMessage('ERROR', _('Unable to delete logo file.'), 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 <?php
namespace LAM\PROFILES;
use \LAMException;
/* /*
$Id$ $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 $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; private $baseType;
@ -180,22 +180,11 @@ class ConfiguredType {
* @param TypeManager $typeManager type manager * @param TypeManager $typeManager type manager
* @param string $scope account type * @param string $scope account type
* @param string $id unique ID for this configuration * @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, public function __construct(&$typeManager, $scope, $id) {
$ldapFilter, $hidden) {
$this->typeManager = &$typeManager; $this->typeManager = &$typeManager;
$this->scope = $scope; $this->scope = $scope;
$this->id = $id; $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 * @return string LDAP suffix
*/ */
public function getSuffix() { public function getSuffix() {
if ($this->suffix !== null) {
return $this->suffix;
}
$this->suffix = $this->typeManager->getConfig()->get_Suffix($this->id);
return $this->suffix; return $this->suffix;
} }
@ -240,6 +233,16 @@ class ConfiguredType {
* @return ListAttribute[] list of ListAttribute * @return ListAttribute[] list of ListAttribute
*/ */
public function getAttributes() { 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; return $this->attributes;
} }
@ -249,6 +252,10 @@ class ConfiguredType {
* @return string alias name * @return string alias name
*/ */
public function getAlias() { public function getAlias() {
if ($this->alias !== null) {
return $this->alias;
}
$this->alias = getTypeAlias($this->id, $this->typeManager->getConfig());
return $this->alias; return $this->alias;
} }
@ -258,6 +265,10 @@ class ConfiguredType {
* @return string LDAP filter * @return string LDAP filter
*/ */
public function getAdditionalLdapFilter() { public function getAdditionalLdapFilter() {
if ($this->additionalLdapFilter !== null) {
return $this->additionalLdapFilter;
}
$this->additionalLdapFilter = $this->typeManager->getConfig()->get_Suffix($typeId);
return $this->additionalLdapFilter; return $this->additionalLdapFilter;
} }
@ -267,6 +278,10 @@ class ConfiguredType {
* @return boolean hidden * @return boolean hidden
*/ */
public function isHidden() { public function isHidden() {
if ($this->hidden !== null) {
return $this->hidden;
}
$this->hidden = isAccountTypeHidden($this->id);
return $this->hidden; return $this->hidden;
} }
@ -293,7 +308,7 @@ class ConfiguredType {
$connection = $_SESSION["ldap"]->server(); $connection = $_SESSION["ldap"]->server();
$ret = array(); $ret = array();
$filter = $this->getBaseType()->getSuffixFilter(); $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) { if ($sr) {
$units = ldap_get_entries($connection, $sr); $units = ldap_get_entries($connection, $sr);
cleanLDAPResult($units); cleanLDAPResult($units);
@ -312,13 +327,13 @@ class ConfiguredType {
// add root suffix if needed // add root suffix if needed
$found = false; $found = false;
for ($i = 0; $i < sizeof($ret); $i++) { // search suffix case-intensitive 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; $found = true;
break; break;
} }
} }
if (!$found) { if (!$found) {
$ret[] = $this->suffix; $ret[] = $this->getSuffix();
} }
usort($ret, 'compareDN'); usort($ret, 'compareDN');
return $ret; return $ret;
@ -466,29 +481,7 @@ class TypeManager {
*/ */
private function buildConfiguredType($typeId) { private function buildConfiguredType($typeId) {
$scope = getScopeFromTypeId($typeId); $scope = getScopeFromTypeId($typeId);
$suffix = $this->config->get_Suffix($typeId); return new ConfiguredType($this, $scope, $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;
} }
/** /**

View File

@ -112,13 +112,6 @@ function upgradeConfigToServerProfileFolders($profiles) {
return; 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) { foreach ($profiles as $profile) {
// upgrade PDF configs // upgrade PDF configs
$dir = '../config/pdf/' . $profile; $dir = '../config/pdf/' . $profile;

View File

@ -1,9 +1,11 @@
<?php <?php
namespace LAM\PDF;
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2006 Michael Duergner Copyright (C) 2003 - 2006 Michael Duergner
2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -43,7 +45,7 @@ class xmlParser {
*/ */
function __construct() { function __construct() {
$this->xmlParser = xml_parser_create(); $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_CASE_FOLDING, 1);
xml_parser_set_option($this->xmlParser, XML_OPTION_SKIP_WHITE, 1); xml_parser_set_option($this->xmlParser, XML_OPTION_SKIP_WHITE, 1);
} }
@ -58,8 +60,8 @@ class xmlParser {
if(file_exists($filename)) { if(file_exists($filename)) {
$xmlStructure = array(); $xmlStructure = array();
$xmlIndex = array(); $xmlIndex = array();
xml_parse_into_struct($this->xmlParser,implode("\n",file($filename)),$xmlStructure,$xmlIndex); xml_parse_into_struct($this->xmlParser, implode("\n", file($filename)), $xmlStructure, $xmlIndex);
return array($xmlStructure,$xmlIndex); return array($xmlStructure, $xmlIndex);
} }
return array(); return array();
} }

View File

@ -1,4 +1,5 @@
<?php <?php
namespace LAM\INIT;
/* /*
$Id$ $Id$
@ -29,18 +30,23 @@ $Id$
*/ */
/** config object */ /** config object */
include_once('../lib/config.inc'); include_once '../lib/config.inc';
/** profiles */
include_once '../lib/profiles.inc';
// start session // start session
startSecureSession(); startSecureSession();
setlanguage(); setlanguage();
\LAM\PROFILES\installProfileTemplates();
\LAM\PDF\installPDFTemplates();
// check if all suffixes in conf-file exist // check if all suffixes in conf-file exist
$conf = $_SESSION['config']; $conf = $_SESSION['config'];
$new_suffs = array(); $new_suffs = array();
// get list of active types // get list of active types
$typeManager = new LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes(); $types = $typeManager->getConfiguredTypes();
foreach ($types as $type) { foreach ($types as $type) {
$info = @ldap_read($_SESSION['ldap']->server(), escapeDN($type->getSuffix()), "(objectClass=*)", array('objectClass'), 0, 0, 0, LDAP_DEREF_NEVER); $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"); 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 Michael Duergner
* @author Roland Gruber * @author Roland Gruber
@ -72,10 +72,9 @@ if (!empty($_POST)) {
setlanguage(); setlanguage();
// Unset pdf structure definitions in session if set // Unset PDF structure definitions in session if set
if(isset($_SESSION['currentPDFStructure'])) { if(isset($_SESSION['currentPDFStructure'])) {
unset($_SESSION['currentPDFStructure']); unset($_SESSION['currentPDFStructure']);
unset($_SESSION['availablePDFFields']);
unset($_SESSION['currentPageDefinitions']); unset($_SESSION['currentPageDefinitions']);
} }
@ -107,7 +106,7 @@ $container->addElement(new htmlTitle(_('PDF editor')), true);
if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) { if (isset($_POST['deleteProfile']) && ($_POST['deleteProfile'] == 'true')) {
// delete structure // 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 = new htmlStatusMessage('INFO', _('Deleted PDF structure.'), \LAM\TYPES\getTypeAlias($_POST['profileDeleteType']) . ': ' . htmlspecialchars($_POST['profileDeleteName']));
$message->colspan = 10; $message->colspan = 10;
$container->addElement($message, true); $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(); $cfg = new LAMCfgMain();
$impExpMessage = null; $typeId = $_POST['typeId'];
if (isset($_POST['importProfiles_' . $_POST['typeId']])) { // check master password
// check master password $errMessage = null;
if (!$cfg->checkPassword($_POST['passwd_' . $_POST['typeId']])) { if (!$cfg->checkPassword($_POST['passwd_i_' . $_POST['typeId']])) {
$impExpMessage = new htmlStatusMessage('ERROR', _('Master password is wrong!')); $errMessage = 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'));
}
} }
if ($impExpMessage != null) { elseif (!empty($_POST['importProfiles_' . $typeId])) {
$impExpMessage->colspan = 10; $options = array();
$container->addElement($impExpMessage, true); 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'])) { if (isset($_POST['uploadLogo']) && !empty($_FILES['logoUpload']) && !empty($_FILES['logoUpload']['size'])) {
$file = $_FILES['logoUpload']['tmp_name']; $file = $_FILES['logoUpload']['tmp_name'];
$filename = $_FILES['logoUpload']['name']; $filename = $_FILES['logoUpload']['name'];
$container->addElement(uploadPDFLogo($file, $filename), true); $container->addElement(\LAM\PDF\uploadPDFLogo($file, $filename), true);
} }
// delete logo file // delete logo file
if (isset($_POST['delLogo'])) { if (isset($_POST['delLogo'])) {
$toDel = $_POST['logo']; $toDel = $_POST['logo'];
$container->addElement(deletePDFLogo($toDel), true); $container->addElement(\LAM\PDF\deletePDFLogo($toDel), true);
} }
// get list of account types // get list of account types
@ -172,7 +199,7 @@ foreach ($sortedTypes as $typeId => $title) {
} }
// get list of templates for each account type // get list of templates for each account type
for ($i = 0; $i < sizeof($templateClasses); $i++) { 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 // check if a template should be edited
@ -210,8 +237,6 @@ include '../main_header.php';
} }
// existing templates // existing templates
$configProfiles = getConfigProfiles();
$container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true); $container->addElement(new htmlSubTitle(_("Manage existing PDF structures")), true);
$existingContainer = new htmlTable(); $existingContainer = new htmlTable();
for ($i = 0; $i < sizeof($templateClasses); $i++) { for ($i = 0; $i < sizeof($templateClasses); $i++) {
@ -255,7 +280,7 @@ include '../main_header.php';
$logoContainer = new htmlTable(); $logoContainer = new htmlTable();
$logoContainer->addElement(new htmlSpacer(null, '30px'), true); $logoContainer->addElement(new htmlSpacer(null, '30px'), true);
$logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true); $logoContainer->addElement(new htmlSubTitle(_('Manage logos')), true);
$logos = getAvailableLogos(); $logos = \LAM\PDF\getAvailableLogos();
$logoOptions = array(); $logoOptions = array();
foreach ($logos as $logo) { foreach ($logos as $logo) {
$file = $logo['filename']; $file = $logo['filename'];
@ -284,12 +309,19 @@ include '../main_header.php';
for ($i = 0; $i < sizeof($templateClasses); $i++) { for ($i = 0; $i < sizeof($templateClasses); $i++) {
$typeId = $templateClasses[$i]['typeId']; $typeId = $templateClasses[$i]['typeId'];
$tmpArr = array(); $scope = $templateClasses[$i]['scope'];
$importOptions = array();
foreach ($configProfiles as $profile) { foreach ($configProfiles as $profile) {
if ($profile != $_SESSION['config']->getName()) { $typeManagerImport = new \LAM\TYPES\TypeManager($serverProfiles[$profile]);
$accountProfiles = getPDFStructureDefinitions($typeId, $profile); $typesImport = $typeManagerImport->getConfiguredTypesForScope($scope);
for ($p = 0; $p < sizeof($accountProfiles); $p++) { foreach ($typesImport as $typeImport) {
$tmpArr[$profile][$accountProfiles[$p]] = $profile . '##' . $accountProfiles[$p]; 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 = new htmlTable();
$container->addElement(new htmlOutputText(_('PDF structures')), true); $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->setMultiSelect(true);
$select->setHasDescriptiveElements(true); $select->setHasDescriptiveElements(true);
$select->setContainsOptgroups(true); $select->setContainsOptgroups(true);
@ -313,11 +345,11 @@ include '../main_header.php';
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
$container->addElement(new htmlOutputText(_("Master password")), true); $container->addElement(new htmlOutputText(_("Master password")), true);
$exportPasswd = new htmlInputField('passwd_' . $typeId); $exportPasswd = new htmlInputField('passwd_i_' . $typeId);
$exportPasswd->setIsPassword(true); $exportPasswd->setIsPassword(true);
$container->addElement($exportPasswd); $container->addElement($exportPasswd);
$container->addElement(new htmlHelpLink('236')); $container->addElement(new htmlHelpLink('236'));
$container->addElement(new htmlHiddenInput('importexport', '1')); $container->addElement(new htmlHiddenInput('import', '1'));
$container->addElement(new htmlHiddenInput('typeId', $typeId), true); $container->addElement(new htmlHiddenInput('typeId', $typeId), true);
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
@ -325,54 +357,52 @@ include '../main_header.php';
echo '</form>'; echo '</form>';
echo "</div>\n"; 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 // form for delete action
echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">'; echo '<div id="deleteProfileDialog" class="hidden"><form id="deleteProfileForm" action="pdfmain.php" method="post">';
echo _("Do you really want to delete this PDF structure?"); 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>'; echo '</form></div>';
include '../main_footer.php'; 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\',\'_\',\'-\'.')); $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 { else {
$return = savePDFStructureDefinitions($type->getId(), $_GET['pdfname']); $return = \LAM\PDF\savePDFStructure($type->getId(), $_GET['pdfname']);
if($return == 'ok') { if($return == 'ok') {
metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']); metaRefresh('pdfmain.php?savedSuccessfully=' . $_GET['pdfname']);
exit; exit;
@ -356,23 +356,20 @@ foreach ($_GET as $key => $value) {
if(!isset($_SESSION['currentPDFStructure'])) { if(!isset($_SESSION['currentPDFStructure'])) {
// Load structure file to be edit // Load structure file to be edit
if(isset($_GET['edit'])) { if(isset($_GET['edit'])) {
$load = loadPDFStructureDefinitions($type->getId(), $_GET['edit']); $load = \LAM\PDF\loadPDFStructure($type->getId(), $_GET['edit']);
$_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions']; $_SESSION['currentPageDefinitions'] = $load['page_definitions'];
$_GET['pdfname'] = $_GET['edit']; $_GET['pdfname'] = $_GET['edit'];
} }
// Load default structure file when creating a new one // Load default structure file when creating a new one
else { else {
$load = loadPDFStructureDefinitions($type->getId()); $load = \LAM\PDF\loadPDFStructure($type->getId());
$_SESSION['currentPDFStructure'] = $load['structure']; $_SESSION['currentPDFStructure'] = $load['structure'];
$_SESSION['currentPageDefinitions'] = $load['page_definitions']; $_SESSION['currentPageDefinitions'] = $load['page_definitions'];
} }
} }
// Load available fields from modules when not set in session $availablePDFFields = getAvailablePDFFields($type->getId());
if(!isset($_SESSION['availablePDFFields'])) {
$_SESSION['availablePDFFields'] = getAvailablePDFFields($type->getId());
}
// Create the values for the dropdown boxes for section headline defined by // Create the values for the dropdown boxes for section headline defined by
// value entries and fetch all available modules // value entries and fetch all available modules
@ -380,7 +377,7 @@ $modules = array();
$section_items_array = array(); $section_items_array = array();
$section_items = ''; $section_items = '';
$sortedModules = array(); $sortedModules = array();
foreach($_SESSION['availablePDFFields'] as $module => $fields) { foreach($availablePDFFields as $module => $fields) {
if ($module != 'main') { if ($module != 'main') {
$title = getModuleAlias($module, $type->getScope()); $title = getModuleAlias($module, $type->getScope());
} }
@ -391,7 +388,7 @@ foreach($_SESSION['availablePDFFields'] as $module => $fields) {
} }
natcasesort($sortedModules); natcasesort($sortedModules);
foreach($sortedModules as $module => $title) { foreach($sortedModules as $module => $title) {
$values = $_SESSION['availablePDFFields'][$module]; $values = $availablePDFFields[$module];
if (!is_array($values) || (sizeof($values) < 1)) { if (!is_array($values) || (sizeof($values) < 1)) {
continue; continue;
} }
@ -419,7 +416,7 @@ if (sizeof($saveErrors) > 0) {
$newFieldFieldElements = array(); $newFieldFieldElements = array();
foreach($sortedModules as $module => $title) { foreach($sortedModules as $module => $title) {
$fields = $_SESSION['availablePDFFields'][$module]; $fields = $availablePDFFields[$module];
if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) { if (isset($fields) && is_array($fields) && (sizeof($fields) > 0)) {
$moduleFields = array(); $moduleFields = array();
foreach ($fields as $field => $fieldLabel) { foreach ($fields as $field => $fieldLabel) {
@ -446,7 +443,7 @@ if (isset($_SESSION['currentPageDefinitions']['headline'])) {
$headline = $_SESSION['currentPageDefinitions']['headline']; $headline = $_SESSION['currentPageDefinitions']['headline'];
} }
// logo // logo
$logoFiles = getAvailableLogos(); $logoFiles = \LAM\PDF\getAvailableLogos();
$logos = array(_('No logo') => 'none'); $logos = array(_('No logo') => 'none');
foreach($logoFiles as $logoFile) { 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'];
@ -459,7 +456,7 @@ if (isset($_SESSION['currentPageDefinitions']['filename'])) {
?> ?>
<form id="inputForm" action="pdfpage.php" method="post" onSubmit="saveScrollPosition('inputForm')"> <form id="inputForm" action="pdfpage.php" method="post" onSubmit="saveScrollPosition('inputForm')">
<?php <?php
$sectionElements = array(_('Beginning') => 0); $sectionElements = array();
$nonTextSectionElements = array(); $nonTextSectionElements = array();
$container = new htmlTable(); $container = new htmlTable();
@ -498,10 +495,10 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$linkRemove->setTitle(_("Remove")); $linkRemove->setTitle(_("Remove"));
$emptyBox = new htmlOutputText(''); $emptyBox = new htmlOutputText('');
// We have a new section to start // 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']; $name = $entry['attributes']['NAME'];
if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$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 { else {
$section_headline = $name; $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)) { if(preg_match("/^_[a-zA-Z0-9_]+_[a-zA-Z0-9_]+/",$name)) {
$headlineElements = array(); $headlineElements = array();
foreach($section_items_array as $item) { 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 = new htmlSelect('section_' . $key, $headlineElements, array($name));
$sectionHeadlineSelect->setHasDescriptiveElements(true); $sectionHeadlineSelect->setHasDescriptiveElements(true);
@ -583,7 +580,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
// Get name of current entry // Get name of current entry
$name = $entry['attributes']['NAME']; $name = $entry['attributes']['NAME'];
$structureContent->addElement(new htmlSpacer('10px', null)); $structureContent->addElement(new htmlSpacer('10px', null));
$fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope())); $fieldOutput = new htmlOutputText(translateFieldIDToName($name, $type->getScope(), $availablePDFFields));
$structureContent->addElement($fieldOutput); $structureContent->addElement($fieldOutput);
if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') { if ($_SESSION['currentPDFStructure'][$key - 1]['tag'] != 'SECTION') {
$structureContent->addElement($linkUp); $structureContent->addElement($linkUp);
@ -600,6 +597,7 @@ for ($key = 0; $key < sizeof($_SESSION['currentPDFStructure']); $key++) {
$structureContent->addElement($linkRemove, true); $structureContent->addElement($linkRemove, true);
} }
} }
$sectionElements[_('End')] = sizeof($_SESSION['currentPDFStructure']);
$structureContent->colspan = 3; $structureContent->colspan = 3;
$mainContent->addElement($structureContent); $mainContent->addElement($structureContent);
$container->addElement(new htmlFieldset($mainContent), true); $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); $container->addElement(new htmlFieldset($newTextFieldContent, _("Text field")), true);
// new field // new field
$container->addElement(new htmlSubTitle(_('New field')), true); if (!empty($nonTextSectionElements)) {
$newFieldContainer = new htmlTable(); $container->addElement(new htmlSubTitle(_('New field')), true);
$newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements); $newFieldContainer = new htmlTable();
$newFieldFieldSelect->setHasDescriptiveElements(true); $newFieldFieldSelect = new htmlSelect('new_field', $newFieldFieldElements);
$newFieldFieldSelect->setContainsOptgroups(true); $newFieldFieldSelect->setHasDescriptiveElements(true);
$newFieldContainer->addElement($newFieldFieldSelect); $newFieldFieldSelect->setContainsOptgroups(true);
$newFieldContainer->addElement(new htmlSpacer('10px', null)); $newFieldContainer->addElement($newFieldFieldSelect);
$newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position')); $newFieldContainer->addElement(new htmlSpacer('10px', null));
$newFieldSectionSelect->setHasDescriptiveElements(true); $newFieldSectionSelect = new htmlTableExtendedSelect('add_field_position', $nonTextSectionElements, array(), _('Position'));
$newFieldContainer->addElement($newFieldSectionSelect); $newFieldSectionSelect->setHasDescriptiveElements(true);
$newFieldContainer->addElement(new htmlButton('add_new_field', _('Add'))); $newFieldContainer->addElement($newFieldSectionSelect);
$container->addElement(new htmlFieldset($newFieldContainer), true); $newFieldContainer->addElement(new htmlButton('add_new_field', _('Add')));
$container->addElement(new htmlSpacer(null, '20px'), true); $container->addElement(new htmlFieldset($newFieldContainer), true);
$container->addElement(new htmlSpacer(null, '20px'), true);
}
// buttons // buttons
$buttonContainer = new htmlTable(); $buttonContainer = new htmlTable();
@ -688,9 +688,10 @@ include '../main_footer.php';
* *
* @param String $id field ID * @param String $id field ID
* @param String $scope account type * @param String $scope account type
* @param array $availablePDFFields available PDF fields
*/ */
function translateFieldIDToName($id, $scope) { function translateFieldIDToName($id, $scope, $availablePDFFields) {
foreach ($_SESSION['availablePDFFields'] as $module => $fields) { foreach ($availablePDFFields as $module => $fields) {
if (!(strpos($id, $module . '_') === 0)) { if (!(strpos($id, $module . '_') === 0)) {
continue; continue;
} }

View File

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

View File

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

View File

@ -267,7 +267,7 @@ function showMainPage($scope, $selectedModules) {
$pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files'));
$pdfCheckbox->setTableRowsToShow(array('pdfStructure')); $pdfCheckbox->setTableRowsToShow(array('pdfStructure'));
$inputContainer->addElement($pdfCheckbox, true); $inputContainer->addElement($pdfCheckbox, true);
$pdfStructures = getPDFStructureDefinitions($scope); $pdfStructures = \LAM\PDF\getPDFStructures($scope);
$pdfSelected = array(); $pdfSelected = array();
if (isset($_POST['pdfStructure'])) { if (isset($_POST['pdfStructure'])) {
$pdfSelected = array($_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->assertEquals($val, $this->lAMConfig->get_scriptPath());
$this->doSave(); $this->doSave();
$this->assertEquals($val, $this->lAMConfig->get_scriptPath()); $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());
} }
/** /**