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

@ -324,4 +324,39 @@ 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

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

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