init PDF and account profiles

This commit is contained in:
Roland Gruber 2017-01-06 13:56:17 +01:00
parent 752417f355
commit 9355b55982
7 changed files with 92 additions and 20 deletions

View File

@ -1269,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'));
@ -1412,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);
@ -1707,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

@ -324,4 +324,39 @@ function isValidPDFStructureName($name) {
return preg_match('/[a-zA-Z0-9\-\_]+/',$name) === 1; 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

@ -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,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

@ -122,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);
@ -187,7 +187,7 @@ if (!empty($_POST['export'])) {
// 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;
} }
@ -276,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];
@ -396,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());
@ -425,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());
@ -437,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