Commit 998dd3be authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) WIP for modular management classes

parent d5b15bd1
......@@ -12,8 +12,8 @@
<tr>
{if $BASE}<td>{$ROOT}&nbsp;</td><td>{$BACK}&nbsp;</td><td>{$HOME}&nbsp;</td>{/if}
<td class="optional">{$RELOAD}&nbsp;</td>
{if $BASE}<td>{$SEPARATOR}&nbsp;</td><td>{t}Base{/t} {$BASE}&nbsp;</td>{/if}
{if $ACTIONS}<td>{$SEPARATOR}&nbsp;</td><td>{$ACTIONS}</td>{/if}
{if $BASE}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{t}Base{/t} {$BASE}&nbsp;</td>{/if}
{if $ACTIONS}<td><img src="images/lists/seperator.png" alt="-" height="16" width="1" class="center"/>&nbsp;</td><td>{$ACTIONS}</td>{/if}
</tr>
</tbody>
</table>
......
......@@ -141,7 +141,7 @@ class ldapFilterLeaf extends ldapFilter
function __construct($left, $operator, $right)
{
if (strrpos($left, ':dn:', -4) !== FALSE) {
if (@strrpos($left, ':dn:', -4) !== FALSE) {
$this->dnFilter = TRUE;
$left = substr($left, 0, -4);
}
......
......@@ -496,9 +496,6 @@ class listing
$smarty->assign("ACTIONS", $this->renderActionMenu());
$smarty->assign("BASE", $this->renderBase());
// Assign separator
$smarty->assign("SEPARATOR", "<img src='images/lists/seperator.png' alt='-' height='16' width='1' class='center'>");
// Assign summary
$smarty->assign("HEADLINE", $this->headline);
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 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.
*/
/*!
* \brief Management base class
*/
class management
{
/* Object types we are currently managing */
public $objectTypes;
/* managementListing instance which manages the entries */
protected $listing;
// The currently used object(s) (e.g. in edit, removal)
protected $dn = '';
protected $dns = array();
// The last used object(s).
protected $last_dn = '';
protected $last_dns = array();
// The opened object.
protected $tabObject = NULL;
protected $dialogObject = NULL;
// The last opened object.
protected $last_tabObject = NULL;
protected $last_dialogObject = NULL;
protected $headline;
protected $title;
protected $icon;
protected $actions = array();
// Whether to display a header or not.
protected $skipHeader = FALSE;
function __construct($objectTypes = FALSE)
{
global $config;
$plInfos = pluglist::pluginInfos(get_class($this));
if ($objectTypes === FALSE) {
$objectTypes = $plInfos['plManages'];
}
$this->headline = $plInfos['plShortName'];
$this->title = $plInfos['plTitle'];
$this->icon = $plInfos['plIcon'];
if (!preg_match('/^geticon/', $this->icon)) {
$this->icon = get_template_path($this->icon);
}
$this->objectTypes = $objectTypes;
$this->listing = new managementListing($this);
// Build filter
//~ if (session::global_is_set(get_class($this).'_filter')) {
//~ $filter = session::global_get(get_class($this).'_filter');
//~ } else {
//~ $filter = new filter();
//~ $filter->setObjectStorage($this->storagePoints);
//~ }
//~ $this->setFilter($filter);
// Build headpage
//~ $this->headpage = new $this->headpageClass($this->parseXML($this->listXMLPath));
//~ $this->headpage->setFilter($filter);
// Register default actions
$this->registerAction('new', 'newEntry');
$this->registerAction('edit', 'editEntry');
$this->registerAction('apply', 'applyChanges');
$this->registerAction('save', 'saveChanges');
$this->registerAction('cancel', 'cancelEdit');
$this->registerAction('cancelDelete', 'cancelEdit');
$this->registerAction('remove', 'removeEntryRequested');
$this->registerAction('removeConfirmed', 'removeEntryConfirmed');
//~ $this->configureHeadpage();
//~ $this->configureFilter();
//~ if ($this->baseMode === FALSE) {
//~ $this->headpage->setBase($config->current['BASE']);
//~ }
}
/*!
* \brief Every click in the list user interface sends an event
* here can we connect those events to a method.
* eg. see simpleManagement::registerEvent('new','createUser')
* When the action/event new is send, the method 'createUser'
* will be called.
*/
function registerAction($action, $target)
{
$this->actions[$action] = $target;
}
/*!
* \brief Detects actions/events send by the ui
* and the corresponding targets.
*/
function detectPostActions()
{
//~ if (!is_object($this->headpage)) {
//~ trigger_error("No valid headpage given....!");
//~ return array();
//~ }
//~ $action = $this->headpage->getAction();
$action = array('action' => '');
if (isset($_POST['edit_cancel'])) {
$action['action'] = 'cancel';
} elseif (isset($_POST['edit_finish'])) {
$action['action'] = 'save';
} elseif (isset($_POST['edit_apply'])) {
$action['action'] = 'apply';
}
if (!$this->is_modal_dialog()) {
if (isset($_POST['delete_confirmed'])) {
$action['action'] = 'removeConfirmed';
}
if (isset($_POST['delete_cancel'])) {
$action['action'] = 'cancelDelete';
}
}
return $action;
}
/*!
* \brief Calls the registered method for a given action/event.
*/
function handleActions($action)
{
// Start action
if (isset($this->actions[$action['action']])) {
$func = $this->actions[$action['action']];
if (!isset($action['targets'])) {
$action['targets'] = array();
}
return $this->$func($action['action'], $action['targets'], $action);
}
}
/*!
* \brief Execute this plugin
* Handle actions/events, locking, snapshots, dialogs, tabs,...
*/
function execute()
{
// Ensure that html posts and gets are kept even if we see a 'Entry islocked' dialog.
//~ $vars = array('/^act$/','/^listing/','/^PID$/');
//~ session::set('LOCK_VARS_TO_USE', $vars);
// Handle actions (POSTs and GETs)
$str = $this->handleActions($this->detectPostActions());
if ($str) {
return $this->getHeader().$str;
}
// Open single dialog objects
if (is_object($this->dialogObject)) {
if (method_exists($this->dialogObject, 'save_object')) {
$this->dialogObject->save_object();
}
if (method_exists($this->dialogObject, 'execute')) {
$display = $this->dialogObject->execute();
$display .= $this->_getTabFooter();
return $this->getHeader().$display;
}
}
// Display tab object.
if ($this->tabObject instanceOf simpleTabs) {
$this->tabObject->save_object();
$display = $this->tabObject->execute();
$display .= $this->_getTabFooter();
return $this->getHeader().$display;
}
// Update filter
//~ if ($this->filter) {
//~ $this->filter->update();
//~ session::global_set(get_class($this).'_filter', $this->filter);
//~ session::set('autocomplete', $this->filter);
//~ if (!$this->filter->isValid()) {
//~ msg_dialog::display(_('Filter error'), _('The filter is incomplete!'), ERROR_DIALOG);
//~ }
//~ }
// Update list
$this->listing->update();
// Display list
return $this->renderList();
}
function renderList()
{
global $config;
//~ $smarty = get_smarty();
//~ $filters = array();
//~ foreach ($this->objectTypes as $object) {
//~ $filters[] = array(
//~ 'id' => 'FILTER'.$object,
//~ 'label' => sprintf(_('Show %s'), $config->data['OBJECTS'][$object]['name'])
//~ );
//~ }
//~ if (!static::$skipTemplates) {
//~ $filters[] = array(
//~ 'id' => 'FILTERTEMPLATE',
//~ 'label' => sprintf(_('Show %s'), _('Template'))
//~ );
//~ }
//~ $smarty->assign('objectFilters', $filters);
//~ $this->headpage->update();
//~ $display = $this->headpage->render();
//~ return $this->getHeader().$display;
$smarty = get_smarty();
$smarty->assign('usePrototype', 'true');
$smarty->assign('FILTER', '');
//~ $smarty->assign("FILTER", $this->filter->render());
$smarty->assign('SIZELIMIT', print_sizelimit_warning());
$smarty->assign('LIST', $this->listing->render());
$smarty->assign('MULTISELECT', $this->listing->multiSelect);
// Assign navigation elements
$nav = $this->listing->renderNavigation(); // TODO: move here?
foreach ($nav as $key => $html) {
$smarty->assign($key, $html);
}
//~ // Assign action menu / base
$smarty->assign('ACTIONS', $this->listing->renderActionMenu());
$smarty->assign('BASE', $this->listing->renderBase()); // TODO: move here?
// Assign summary
$smarty->assign('HEADLINE', $this->headline);
return $this->getHeader().$smarty->fetch(get_template_path('simple-list.tpl'));
}
/*!
* \brief Removes ldap object locks created by this class.
* Whenever an object is edited, we create locks to avoid
* concurrent modifications.
* This locks will automatically removed here.
*/
function remove_lock()
{
if (!empty($this->dn) && $this->dn != "new") {
del_lock($this->dn);
}
if (count($this->dns)) {
del_lock($this->dns);
}
}
function is_modal_dialog()
{
return (is_object($this->tabObject) || is_object($this->dialogObject));
}
/*!
* \brief Generates the plugin header which is displayed whenever a tab object is opened.
*/
protected function getHeader()
{
if ($this->skipHeader) {
return '';
}
return print_header($this->icon, $this->title, get_object_info());
}
static function mainInc ($classname, $objectTypes = FALSE)
{
global $remove_lock, $cleanup, $display;
/* Remove locks */
if ($remove_lock && session::is_set($classname)) {
$macl = session::get($classname);
$macl->remove_lock();
}
if ($cleanup) {
/* Clean up */
session::un_set($classname);
} else {
if (!session::is_set($classname) || (isset($_GET['reset']) && $_GET['reset'] == 1)) {
/* Create the object if missing or reset requested */
$managementObject = new $classname($objectTypes);
} else {
/* Retrieve the object from session */
$managementObject = session::get($classname);
}
/* Execute and display */
$display = $managementObject->execute();
/* Store the object in the session */
session::set($classname, $managementObject);
}
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2017-2018 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.
*/
/*!
* \brief Column base class
*/
class StringColumn
{
protected $attribute;
protected $label;
protected $type = 'string';
function __construct($attribute, $label)
{
$this->attribute = $attribute;
$this->label = $label;
}
function isSortable()
{
return TRUE;
}
function getRowClasses()
{
return array();
}
function getHtmlProps()
{
return '';
}
function getHtmlCellProps()
{
return '';
}
function getLabel()
{
return _($this->label);
//~ return $this->label;
}
function fillNeededAttributes(array &$attrs)
{
$attrs[$this->attribute] = '1';
}
function renderCell(string $pid, int $row, string $dn, array $entry)
{
if (isset($entry[$this->attribute])) {
return htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8');
} else {
return '&nbsp;';
}
}
function compare($ao, $bo)
{
if ($this->attribute == 'sort-attribute') {
// Override sort attribute from data if needed
$attribute_a = $ao['sort-attribute'];
$attribute_b = $bo['sort-attribute'];
} else {
$attribute_a = $this->attribute;
$attribute_b = $this->attribute;
}
// Extract values from ao and bo
$a = $b = '';
if (isset($ao[$attribute_a])) {
$a = $ao[$attribute_a];
if (is_array($a)) {
$a = $a[0];
}
}
if (isset($bo[$attribute_b])) {
$b = $bo[$attribute_b];
if (is_array($b)) {
$b = $b[0];
}
}
// Take a look at the several types
switch ($this->type) {
// Sort for string by default
default:
case 'string':
return strcoll($a, $b);
case 'department':
return strnatcmp($a, $b);
case 'integer':
return $b - $a;
case 'date':
if ($a == '') {
$a = '31.12.0000';
}
if ($b == '') {
$b = '31.12.0000';
}
list($d, $m, $y) = explode('.', $a);
$a = (int)sprintf('%04d%02d%02d', $y, $m, $d);
list($d, $m, $y) = explode('.', $b);
$b = (int)sprintf('%04d%02d%02d', $y, $m, $d);
return $b - $a;
case 'ip':
$parts_a = explode('.', $a, 4);
$parts_b = explode('.', $b, 4);
for ($i = 0; $i < 4; $i++) {
if ((int)($parts_a[$i]) != (int)($parts_b[$i])) {
return (int)($parts_a[$i]) - (int)($parts_b[$i]);
}
}
return 0;
}
}
}
class LinkColumn extends StringColumn
{
function renderCell(string $pid, int $row, string $dn, array $entry)
{
if (isset($entry[$this->attribute])) {
return '<a href="?plug='.$_GET['plug'].'&amp;PID='.$pid.'&amp;act=listing_edit_'.$row.'" title="'.$dn.'">'.htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8').'</a>';
} else {
return '&nbsp;';
}
}
}
This diff is collapsed.
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-2018 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
......@@ -20,17 +19,11 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class userManagement extends simpleManagement
class userManagement extends management
{
protected $objectTypes = array('user');
protected $departmentBrowser = TRUE;
protected $departmentRootVisible = FALSE;
protected $baseMode = TRUE;
protected $multiSelect = TRUE;
protected $filterXMLPath = NULL;
protected $listXMLPath = NULL;
protected $autoFilter = FALSE;
protected $autoActions = FALSE;
......@@ -51,14 +44,6 @@ class userManagement extends simpleManagement
);
}
function __construct()
{
$this->filterXMLPath = get_template_path('user-filter.xml', TRUE, dirname(__FILE__));
$this->listXMLPath = get_template_path('user-list.xml', TRUE, dirname(__FILE__));
parent::__construct();
}
function configureHeadpage ()
{
parent::configureHeadpage();
......@@ -71,9 +56,9 @@ class userManagement extends simpleManagement
$this->registerAction('lockUsers', 'lockUsers');
$this->registerAction('unlockUsers', 'lockUsers');
$this->headpage->registerElementFilter('lockLabel', 'userManagement::filterLockLabel');
$this->headpage->registerElementFilter('lockImage', 'userManagement::filterLockImage');
$this->headpage->registerElementFilter('filterProperties', 'userManagement::filterProperties');
//~ $this->headpage->registerElementFilter('lockLabel', 'userManagement::filterLockLabel');
//~ $this->headpage->registerElementFilter('lockImage', 'userManagement::filterLockImage');
//~ $this->headpage->registerElementFilter('filterProperties', 'userManagement::filterProperties');
}
function configureFilter ()
......@@ -110,14 +95,14 @@ class userManagement extends simpleManagement
}
}
function renderList ()
{
$smarty = get_smarty();
$smarty->assign('USE_POSIX', class_available('posixAccount'));
$smarty->assign('USE_MAIL', class_available('mailAccount'));
$smarty->assign('USE_SAMBA', class_available('sambaAccount'));
return parent::renderList();
}
//~ function renderList ()
//~ {
//~ $smarty = get_smarty();
//~ $smarty->assign('USE_POSIX', class_available('posixAccount'));
//~ $smarty->assign('USE_MAIL', class_available('mailAccount'));
//~ $smarty->assign('USE_SAMBA', class_available('sambaAccount'));
//~ return parent::renderList();
//~ }
/* !\brief Lock/unlock multiple users.
*/
......
......@@ -19,5 +19,6 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
simpleManagement::mainInc('userManagement');
management::mainInc('userManagement');
//~ simpleManagement::mainInc('userManagement');
?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment