-
Côme Chilliet authored
This replaces save_object and execute methods by 3 methods: readPost - Reads POST data update - Update object state render - Render HTML UI The point is to avoid reading POST and rendering HTML when this is not needed (when doing stuff through the webservice for instance). It’s also more consisent across FD with all classes handling some kind of dialog implementing the new interface FusionDirectoryDialog which makes sure these 3 methods are implemented. issue #6072
Unverified94eaa6ba
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2007 Fabian Hickert
Copyright (C) 2011-2019 FusionDirectory
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
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class setupStepConfigBeforeInit extends setupStep
{
function update_strings ()
{
global $config;
if (!isset($config->current['BASE'])) {
$config->current['BASE'] = '';
}
$infos = configInLdap::plInfo();
$this->header_image = $infos['plIcon'];
$this->s_short_name = $infos['plShortName'];
$this->s_title = $infos['plTitle'];
$this->s_description = $infos['plDescription'];
}
}
class setupStepConfig extends configInLdap
{
var $is_active = FALSE;
var $is_enabled = FALSE;
var $is_completed = FALSE;
var $header_image;
protected $objectclasses = ['fusionDirectoryConf'];
static function plInfo (): array
{
return [];
}
function __construct ($parent, $cv)
{
global $config;
parent::__construct(CONFIGRDN.$config->current['BASE'], NULL, $parent, TRUE);
$this->attributesInfo['miscellaneous']['class'] = ['invisible'];
$this->attributesInfo['debug']['class'] = ['invisible'];
$this->fdLanguage = $cv['lang_selected'];
}
function update_strings ()
{
$infos = parent::plInfo();
$this->header_image = $infos['plIcon'];
}
function get_short_name ()
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
{
$infos = parent::plInfo();
return $infos['plTitle'];
}
function get_title ()
{
return $this->get_description();
}
function get_description ()
{
$infos = parent::plInfo();
return $infos['plDescription'];
}
/* Return attributes handled by this setup step */
function get_attributes ()
{
$tmp = [];
foreach (array_keys($this->attributesAccess) as $attr) {
$tmp[$attr] = $this->$attr;
}
return $tmp;
}
function update ()
{
global $config, $plist;
parent::update();
$this->is_completed = FALSE;
$tmp = $this->check();
if (count($tmp) == 0) {
/* Create root object if missing */
$ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']);
try {
$ldap->create_missing_trees($config->current['BASE'], FALSE);
} catch (FusionDirectoryError $error) {
$error->display();
return;
}
/* Save in LDAP */
$errors = $this->save();
if (!empty($errors)) {
msg_dialog::displayChecks($errors);
return;
}
/* Insert default config values, even for installed plugin */
session::un_set('plist');
pluglist::load();
$config->loadPlist($plist);
$config->checkLdapConfig(TRUE);
/* Reload config from LDAP */
$config->set_current($config->current['NAME']);
/* Set as completed and reload step */
$this->is_completed = TRUE;
$this->parent->reBuildConfigStep(TRUE);
}
}
function is_active ()
{
return $this->is_active;
}
function is_enabled ()
{
return $this->is_enabled;
}
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
function is_completed ()
{
return $this->is_completed;
}
function set_active ($value = TRUE)
{
$this->is_active = (bool) $value;
}
function set_enabled ($value = TRUE)
{
$this->is_enabled = (bool) $value;
}
function set_completed ($value = TRUE)
{
$this->is_completed = (bool) $value;
}
/* bypass acl system as there is no user login */
function acl_is_writeable ($attribute, bool $skip_write = FALSE): bool
{
return TRUE;
}
function acl_is_readable ($attribute): bool
{
return TRUE;
}
function acl_is_createable (string $base = NULL): bool
{
return TRUE;
}
function acl_is_removeable (string $base = NULL): bool
{
return TRUE;
}
function acl_is_moveable (string $base = NULL): bool
{
return TRUE;
}
function aclGetPermissions ($attribute = '0', string $base = NULL, bool $skipWrite = FALSE): string
{
return 'cmdrw';
}
/* We need static method to work as if we were configInLdap */
static function isAccount ($attrs)
{
return configInLdap::isAccount($attrs);
}
}