refactoring

This commit is contained in:
Roland Gruber 2020-05-02 18:51:33 +02:00
parent 7fcc2cf38d
commit c9d32bf2de
3 changed files with 18 additions and 16 deletions

View File

@ -1454,7 +1454,7 @@ class accountContainer {
*/ */
private function loadProfileIfRequested() { private function loadProfileIfRequested() {
if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) { if (isset($_POST['accountContainerLoadProfile']) && isset($_POST['accountContainerSelectLoadProfile'])) {
$profile = \LAM\PROFILES\loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type->getId()); $profile = \LAM\PROFILES\loadAccountProfile($_POST['accountContainerSelectLoadProfile'], $this->type->getId(), $_SESSION['config']->getName());
$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);
@ -1775,7 +1775,7 @@ class accountContainer {
$this->lastLoadedProfile = $cookieProfileName; $this->lastLoadedProfile = $cookieProfileName;
} }
} }
$profile = \LAM\PROFILES\loadAccountProfile($profileName, $this->type->getId()); $profile = \LAM\PROFILES\loadAccountProfile($profileName, $this->type->getId(), $_SESSION['config']->getName());
// 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

@ -5,7 +5,7 @@ use \LAMException;
$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 - 2018 Roland Gruber Copyright (C) 2003 - 2020 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
@ -80,20 +80,21 @@ function profileExists($name, $typeId) {
} }
/** /**
* Loads an profile of the given account type * Loads an profile of the given account type
* *
* @param string $profile name of the profile (without .<scope> extension) * @param string $profile name of the profile (without .<scope> extension)
* @param string $typeId account type * @param string $typeId account type
* @return array hash array (attribute => value) * @param string $serverProfileName server profile name
*/ * @return array hash array (attribute => value)
function loadAccountProfile($profile, $typeId) { */
function loadAccountProfile($profile, $typeId, $serverProfileName) {
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId); $type = $typeManager->getConfiguredType($typeId);
if (!isValidProfileName($profile) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($type == null)) { if (!isValidProfileName($profile) || !preg_match("/^[a-z0-9_]+$/i", $typeId) || ($type == null)) {
return false; return false;
} }
$settings = array(); $settings = array();
$file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $typeId; $file = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $serverProfileName . '/' . $profile . "." . $typeId;
if (is_file($file)) { if (is_file($file)) {
$file = @fopen($file, "r"); $file = @fopen($file, "r");
if ($file) { if ($file) {
@ -133,9 +134,10 @@ function loadAccountProfile($profile, $typeId) {
* @param array $attributes hash array (attribute => value) * @param array $attributes hash array (attribute => value)
* @param string $profile name of the account profile (without .<scope> extension) * @param string $profile name of the account profile (without .<scope> extension)
* @param string $typeId account type * @param string $typeId account type
* @param string $serverProfileName server profile name
* @return boolean true, if saving succeeded * @return boolean true, if saving succeeded
*/ */
function saveAccountProfile($attributes, $profile, $typeId) { function saveAccountProfile($attributes, $profile, $typeId, $serverProfileName) {
if (!isLoggedIn()) return false; if (!isLoggedIn()) return false;
// check profile name and type id // check profile name and type id
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
@ -146,7 +148,7 @@ function saveAccountProfile($attributes, $profile, $typeId) {
if (!is_array($attributes)) { if (!is_array($attributes)) {
return false; return false;
} }
$path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $_SESSION['config']->getName() . '/' . $profile . "." . $typeId; $path = substr(__FILE__, 0, strlen(__FILE__) - 17) . "/config/profiles/" . $serverProfileName . '/' . $profile . "." . $typeId;
$file = @fopen($path, "w"); $file = @fopen($path, "w");
if ($file) { if ($file) {
// write attributes // write attributes

View File

@ -10,7 +10,7 @@ use \htmlSubTitle;
/* /*
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 - 2019 Roland Gruber Copyright (C) 2003 - 2020 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
@ -127,7 +127,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 (\LAM\PROFILES\saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'])) { if (\LAM\PROFILES\saveAccountProfile($options, $_POST['profname'], $_POST['accounttype'], $_SESSION['config']->getName())) {
metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']); metaRefresh('profilemain.php?savedSuccessfully=' . $_POST['profname']);
exit(); exit();
} }
@ -168,7 +168,7 @@ if (isset($_POST['save'])) {
} }
} }
elseif (isset($_GET['edit'])) { elseif (isset($_GET['edit'])) {
$old_options = \LAM\PROFILES\loadAccountProfile($_GET['edit'], $type->getId()); $old_options = \LAM\PROFILES\loadAccountProfile($_GET['edit'], $type->getId(), $_SESSION['config']->getName());
} }
// display formular // display formular