Commit 3bcd7058 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

feat(management) Added Action column and Properties column

Acls are not handled yet in those columns
parent 76bddcb2
......@@ -177,7 +177,7 @@ class management
/*!
* \brief Calls the registered method for a given action/event.
*/
function handleActions($action)
function handleActions(array $action)
{
// Start action
if (isset($this->actions[$action['action']])) {
......@@ -188,6 +188,20 @@ class management
}
}
protected function handleSubAction(array $action)
{
if (preg_match('/^tab_/', $action['subaction'])) {
$tab = preg_replace('/^tab_/', '', $action['subaction']);
if (isset($this->tabObject->by_object[$tab])) {
$this->tabObject->current = $tab;
} else {
trigger_error('Unknown tab: '.$tab);
}
return TRUE;
}
return FALSE;
}
/*!
* \brief Execute this plugin
* Handle actions/events, locking, snapshots, dialogs, tabs,...
......@@ -305,6 +319,18 @@ class management
return '<div id="pulldown">'.$result.'</ul></li></ul></div>'."\n";
}
function renderActionColumn($pid, $row, $dn, $type, array $entry)
{
// Go thru all actions
$result = '';
$emptyimg = '<img src="images/empty.png" alt=" " class="center optional"/>';
foreach ($this->actions as $action) {
$result .= $action->renderColumnIcons($pid, $row, $dn, $type, $entry);
}
return $result;
}
/*!
* \brief Removes ldap object locks created by this class.
* Whenever an object is edited, we create locks to avoid
......
......@@ -120,6 +120,22 @@ class Action
.'<img src="'.htmlentities($this->icon, ENT_COMPAT, 'UTF-8').'" alt="'.$this->name.'" class="center">&nbsp;'.$this->label.'</a>'
.'</li>'."\n";
}
function renderColumnIcons($pid, $row, $dn, $type, array $entry)
{
// TODO Skip the entry completely if there's no permission to execute it
//~ if (!$this->hasActionPermission($action, $dn, $row)) {
//~ $result .= $emptyimg;
//~ continue;
//~ }
// TODO? Skip entry if the pseudo filter does not fit
// TODO? Skip depending on type
// Render
return '<input class="center" type="image" src="'.htmlentities($this->icon, ENT_COMPAT, 'UTF-8').'"'.
' title="'.$this->label.'" alt="'.$this->label.'" name="listing_'.$this->name.'_'.$row.'"/>';
}
}
/*!
......@@ -175,4 +191,8 @@ class ActionSubMenu extends Action
}
return $result.'</li></ul>'."\n";
}
function renderColumnIcons($pid, $row, $dn, $type, array $entry)
{
}
}
......@@ -27,12 +27,20 @@ class StringColumn
protected $label;
protected $type = 'string';
function __construct($attribute, $label)
/* management class instance */
protected $parent = NULL;
function __construct($attribute = NULL, $label = NULL)
{
$this->attribute = $attribute;
$this->label = $label;
}
function setParent(managementListing $parent)
{
$this->parent = $parent;
}
function isSortable()
{
return TRUE;
......@@ -55,18 +63,23 @@ class StringColumn
function getLabel()
{
return _($this->label);
//~ return $this->label;
if (isset($this->label)) {
return _($this->label);
} else {
return '&nbsp;';
}
}
function fillNeededAttributes(array &$attrs)
{
$attrs[$this->attribute] = '1';
if (isset($this->attribute)) {
$attrs[$this->attribute] = '1';
}
}
function renderCell(string $pid, int $row, string $dn, array $entry)
function renderCell($pid, $row, $dn, $type, array $entry)
{
if (isset($entry[$this->attribute])) {
if (isset($this->attribute) && isset($entry[$this->attribute])) {
return htmlentities($entry[$this->attribute], ENT_COMPAT, 'UTF-8');
} else {
return '&nbsp;';
......@@ -140,7 +153,7 @@ class StringColumn
class LinkColumn extends StringColumn
{
function renderCell(string $pid, int $row, string $dn, array $entry)
function renderCell($pid, $row, $dn, $type, 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>';
......@@ -149,3 +162,97 @@ class LinkColumn extends StringColumn
}
}
}
class ObjectTypeColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function renderCell($pid, $row, $dn, $type, array $entry)
{
if ($type) {
$infos = objects::infos($type);
return '<img class="center" title="'.$dn.'" src="'.htmlentities($infos['icon'], ENT_COMPAT, 'UTF-8').'" alt="'.$infos['name'].'"/>';
} else {
return '&nbsp;';
}
}
}
class ActionsColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function renderCell($pid, $row, $dn, $type, array $entry)
{
return $this->parent->parent->renderActionColumn($pid, $row, $dn, $type, $entry);
}
}
class PropertiesColumn extends StringColumn
{
function isSortable()
{
return FALSE;
}
function fillNeededAttributes(array &$attrs)
{
$attrs['objectClass'] = '*';
}
function renderCell($pid, $row, $dn, $type, array $entry)
{
global $config;
$infos = objects::infos($type);
static $tabs = array();
if (empty($tabs[$type])) {
$tabs[$type] = array();
foreach ($config->data['TABS'][$infos['tabGroup']] as $plug) {
if ($plug['CLASS'] == $infos['mainTab']) {
continue;
}
if (class_available($plug['CLASS'])) {
$name = $plug['CLASS'];
$tabs[$type][$name] = new $name('new');
}
}
}
/* Main tab is always there */
$pInfos = pluglist::pluginInfos($infos['mainTab']);
$result = '<input class="center" type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$infos['mainTab'].'_'.$row.'"/>';
if (!empty($entry)) {
//~ if (in_array_ics ('fdTemplate', $attrs['objectClass'])) {
//~ $attrs = templateHandling::fieldsFromLDAP($attrs);
//~ }
foreach ($tabs[$type] as $class => $tab) {
if ($tab->is_this_account($entry)) {
$pInfos = pluglist::pluginInfos($class);
if (isset($pInfos['plSmallIcon'])) {
$result .= '<input class="center" type="image" src="'.htmlentities($pInfos['plSmallIcon'], ENT_COMPAT, 'UTF-8').'" '.
'alt="'.$pInfos['plShortName'].'" title="'.$pInfos['plShortName'].'" '.
'name="listing_edit_tab_'.$class.'_'.$row.'"/>';
} else {
@DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $pInfos['plShortName']." ($class)", 'No icon for');
}
} else {
$result .= '<img src="images/empty.png" alt="" class="center optional '.$class.'"/>';
}
}
}
return $result;
}
}
......@@ -157,7 +157,7 @@ class managementListing
//~ protected $filterCache = array();
/* The management class */
protected $parent;
public $parent;
protected $columns;
......@@ -213,10 +213,17 @@ class managementListing
$this->baseSelector = new baseSelector($this->bases, $this->base);
$this->columns = array(
new ObjectTypeColumn(),
new LinkColumn('sn', 'Last name'),
new LinkColumn('givenName', 'First name'),
new StringColumn('uid', 'Login'),
new PropertiesColumn(NULL, 'Properties'),
new ActionsColumn(NULL, 'Actions'),
);
foreach ($this->columns as $column) {
$column->setParent($this);
}
}
/*!
......@@ -380,7 +387,7 @@ class managementListing
}
foreach ($this->columns as $index => $column) {
$renderedCell = $column->renderCell($this->pid, $row, $dn, $entry);
$renderedCell = $column->renderCell($this->pid, $row, $dn, $this->entriesTypes[$dn], $entry);
$trow .= '<td '.$column->getHtmlCellProps().'>'.$renderedCell.'</td>'."\n";
$rowclasses = array_merge($rowclasses, $column->getRowClasses());
}
......@@ -666,32 +673,6 @@ class managementListing
return $result;
}
function renderCell($table, $index, $data, $cfg, $row)
{
// Replace flat attributes in data string
$offset = 0;
while (preg_match('/%{([^}:]+)}/', $data, $m, PREG_OFFSET_CAPTURE, $offset)) {
if (isset($cfg[$m[1][0]])) {
$replace = $cfg[$m[1][0]];
if (is_array($replace)) {
$replace = $replace[0];
}
$replace = htmlentities($replace, ENT_COMPAT, 'UTF-8');
} else {
$replace = '&nbsp;';
}
$data = substr_replace($data, $replace, $m[0][1], strlen($m[0][0]));
$offset = $m[0][1] + strlen($replace);
}
// Watch out for filters and prepare to execute them
$data = $this->processElementFilter($table, $index, $data, $cfg, $row);
return $data;
}
function renderBase()
{
if (!$this->baseMode) {
......
......@@ -47,14 +47,14 @@ class userManagement extends management
function configureHeadpage ()
{
parent::configureHeadpage();
$this->registerAction('new_user', 'newEntry');
$this->registerAction('new_template_user', 'newEntryTemplate');
$this->registerAction('template_apply_to_user', 'applyTemplateToEntry');
$this->registerAction('template_apply_user', 'newEntryFromTemplate');
//~ $this->registerAction('new_user', 'newEntry');
//~ $this->registerAction('new_template_user', 'newEntryTemplate');
//~ $this->registerAction('template_apply_to_user', 'applyTemplateToEntry');
//~ $this->registerAction('template_apply_user', 'newEntryFromTemplate');
$this->registerAction('lock', 'lockEntry');
$this->registerAction('lockUsers', 'lockUsers');
$this->registerAction('unlockUsers', 'lockUsers');
//~ $this->registerAction('lock', 'lockEntry');
//~ $this->registerAction('lockUsers', 'lockUsers');
//~ $this->registerAction('unlockUsers', 'lockUsers');
//~ $this->headpage->registerElementFilter('lockLabel', 'userManagement::filterLockLabel');
//~ $this->headpage->registerElementFilter('lockImage', 'userManagement::filterLockImage');
......
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