Commit 7c0f4019 authored by Côme Bernigaud's avatar Côme Bernigaud Committed by Benoit Mortier
Browse files

Fixes #3600 Added a group section to dashboard

parent 395245f8
......@@ -62,7 +62,7 @@ class dashboard extends simplePlugin
$nb = objects::count($type);
} catch (Exception $e) {
$nb = 0;
trigger_error($e->getMessage());
trigger_error("Problem with $type:".$e->getMessage());
}
if ($nb == 0) {
continue;
......
......@@ -23,17 +23,50 @@
class dashboardUsers extends simplePlugin
{
static function plInfo()
{
return array(
'plShortName' => _('Users'),
'plDescription' => _('Statistics about users'),
'plObjectType' => array('dashboard'),
'plProvidedAcls' => array()
);
}
static function getAttributesInfo()
{
return array(
'userstats' => array(
'name' => _('Users statistics'),
'attrs' => array(new FakeAttribute('users_stats')),
'template' => get_template_path('users_stats.tpl', TRUE, dirname(__FILE__)),
),
'groupstats' => array(
'name' => _('Groups statistics'),
'attrs' => array(new FakeAttribute('groups_stats')),
'template' => get_template_path('groups_stats.tpl', TRUE, dirname(__FILE__)),
),
'expired_accounts' => array(
'name' => _('Expired accounts'),
'attrs' => array(new FakeAttribute('expired')),
'template' => get_template_path('users_accounts.tpl', TRUE, dirname(__FILE__)),
),
);
}
function __construct(&$config, $dn = NULL, $object = NULL)
{
parent::__construct($config, $dn, $object);
$this->stats = $this->users_stats();
$this->expired = $this->expired_accounts_info();
$this->users_stats = $this->computeUsersStats();
$this->groups_stats = $this->computeGroupsStats();
$this->expired = $this->expired_accounts_info();
}
function users_stats ()
function computeUsersStats ()
{
/* User accounts statistics */
/* User statistics */
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search("(&(!(objectClass=gosaUserTemplate))(objectClass=gosaAccount))", array("userPassword"));
......@@ -59,12 +92,34 @@ class dashboardUsers extends simplePlugin
array('name' => 'posix', 'nb' => $nb_posix_accounts, 'img' => 'geticon.php?context=applications&icon=os-linux&size=16'),
array('name' => 'samba', 'nb' => $nb_samba_accounts, 'img' => 'geticon.php?context=applications&icon=os-windows&size=16')
),
'nb_accounts' => $nb_accounts,
'user_img' => 'geticon.php?context=types&icon=user&size=16',
'nb' => $nb_accounts,
'img' => 'geticon.php?context=types&icon=user&size=16',
'locked_accounts' => array('nb' => $nb_locked_accounts, 'img' => "geticon.php?context=status&icon=object-locked&size=16"),
);
}
function computeGroupsStats ()
{
/* Group statistics */
$ldap = $this->config->get_ldap_link();
$ldap->cd($this->config->current['BASE']);
$ldap->search('(objectClass=posixGroup)', array('cn'));
$nb = $ldap->count();
$ldap->search('(&(objectClass=posixGroup)(objectClass=gosaMailAccount))', array('cn'));
$nb_mail_groups = $ldap->count();
$ldap->search('(&(objectClass=posixGroup)(objectClass=sambaSamAccount))', array('cn'));
$nb_samba_groups = $ldap->count();
return array(
'groups' => array(
array('name' => 'mail', 'nb' => $nb_mail_groups, 'img' => 'geticon.php?context=applications&icon=internet-mail&size=16'),
array('name' => 'samba', 'nb' => $nb_samba_groups, 'img' => 'geticon.php?context=applications&icon=os-windows&size=16')
),
'nb' => $nb,
'img' => 'geticon.php?context=types&icon=user-group&size=16',
);
}
function expired_accounts_info ()
{
/*
......@@ -130,33 +185,5 @@ class dashboardUsers extends simplePlugin
'shadowExpire' => $human_shadowExpire,
);
}
static function getAttributesInfo()
{
return array(
'stats' => array(
'name' => _('Statistics'),
'attrs' => array(new FakeAttribute('stats')),
'template' => get_template_path('users_stats.tpl', TRUE, dirname(__FILE__)),
),
'expired_accounts' => array(
'name' => _('Expired accounts'),
'attrs' => array(new FakeAttribute('expired')),
'template' => get_template_path('users_accounts.tpl', TRUE, dirname(__FILE__)),
),
);
}
/* Return plugin informations for acl handling */
static function plInfo()
{
return array(
'plShortName' => _('Users'),
'plDescription' => _('Statistics about users'),
'plObjectType' => array('dashboard'),
'plProvidedAcls' => array()
);
}
}
?>
<div id="{$sectionId}" class="plugin_section">
<span class="legend">
{$section}
</span>
<div>
<img src="{$attributes.groups_stats.img}" alt="group icon"/>
{t count=$attributes.groups_stats.nb 1=$attributes.groups_stats.nb plural="There are %1 groups:"}There is 1 group:{/t}
<ul>
{foreach from=$attributes.groups_stats.groups item=g}
<li style="list-style-image:url({$g.img})">
{if $g.nb > 0}
{t count=$g.nb 1=$g.name 2=$g.nb plural="%2 are %1 groups"}One of them is a %1 group{/t}
{else}
{t 1=$g.name}There is no %1 group{/t}
{/if}
</li>
{/foreach}
</ul>
</div>
</div>
......@@ -3,10 +3,10 @@
{$section}
</span>
<div>
<img src="{$attributes.stats.user_img}" alt="user icon"/>
{t count=$attributes.stats.nb_accounts 1=$attributes.stats.nb_accounts plural="There are %1 users:"}There is 1 user:{/t}
<img src="{$attributes.users_stats.img}" alt="user icon"/>
{t count=$attributes.users_stats.nb 1=$attributes.users_stats.nb plural="There are %1 users:"}There is 1 user:{/t}
<ul>
{foreach from=$attributes.stats.accounts item=acc}
{foreach from=$attributes.users_stats.accounts item=acc}
<li style="list-style-image:url({$acc.img})">
{if $acc.nb > 0}
{t count=$acc.nb 1=$acc.name 2=$acc.nb plural="%2 of them have a %1 account"}One of them have a %1 account{/t}
......@@ -15,9 +15,9 @@
{/if}
</li>
{/foreach}
<li style="list-style-image:url({$attributes.stats.locked_accounts.img})">
{if $attributes.stats.locked_accounts.nb > 0}
{t count=$attributes.stats.locked_accounts.nb 1=$attributes.stats.locked_accounts.nb plural="%1 of them are locked"}One of them is locked{/t}
<li style="list-style-image:url({$attributes.users_stats.locked_accounts.img})">
{if $attributes.users_stats.locked_accounts.nb > 0}
{t count=$attributes.users_stats.locked_accounts.nb 1=$attributes.users_stats.locked_accounts.nb plural="%1 of them are locked"}One of them is locked{/t}
{else}
{t}None of them is locked{/t}
{/if}
......
Supports Markdown
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