support to filter by account status
This commit is contained in:
parent
e6861152ec
commit
50c5a65b98
|
@ -392,26 +392,36 @@ class lamList {
|
||||||
parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type);
|
parseHtml(null, $filterGroup, array(), false, $this->tabindex, $this->type);
|
||||||
echo "</td>\n";
|
echo "</td>\n";
|
||||||
// print input boxes for filters
|
// print input boxes for filters
|
||||||
for ($k = 0; $k < sizeof ($this->descArray); $k++) {
|
for ($k = 0; $k < sizeof($this->descArray); $k++) {
|
||||||
echo "<td align=\"left\">";
|
echo "<td align=\"left\">";
|
||||||
if ($this->canBeFiltered($this->attrArray[$k])) {
|
if ($this->canBeFiltered($this->attrArray[$k])) {
|
||||||
$value = "";
|
$this->printFilterArea($this->attrArray[$k], isset($_POST['clear_filter']));
|
||||||
if (!isset($_POST['clear_filter'])) {
|
|
||||||
if (isset($this->filters[strtolower($this->attrArray[$k])])) {
|
|
||||||
$value = $this->filters[strtolower($this->attrArray[$k])];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$filterInput = new htmlInputField('filter' . strtolower($this->attrArray[$k]), $value);
|
|
||||||
$filterInput->setCSSClasses(array($this->type . '-dark'));
|
|
||||||
$filterInput->setFieldSize('15');
|
|
||||||
$filterInput->setOnKeyPress("SubmitForm('apply_filter', event);");
|
|
||||||
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type);
|
|
||||||
}
|
}
|
||||||
echo "</td>\n";
|
echo "</td>\n";
|
||||||
}
|
}
|
||||||
echo "</tr></thead>\n";
|
echo "</tr></thead>\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the content of a single attribute filter area.
|
||||||
|
*
|
||||||
|
* @param String $attrName attribute name
|
||||||
|
* @param boolean $clearFilter true if filter value should be cleared
|
||||||
|
*/
|
||||||
|
protected function printFilterArea($attrName, $clearFilter) {
|
||||||
|
$value = "";
|
||||||
|
if (!$clearFilter) {
|
||||||
|
if (isset($this->filters[strtolower($attrName)])) {
|
||||||
|
$value = $this->filters[strtolower($attrName)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$filterInput = new htmlInputField('filter' . strtolower($attrName), $value);
|
||||||
|
$filterInput->setCSSClasses(array($this->type . '-dark'));
|
||||||
|
$filterInput->setFieldSize('15');
|
||||||
|
$filterInput->setOnKeyPress("SubmitForm('apply_filter', event);");
|
||||||
|
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns if the given attribute can be filtered.
|
* Returns if the given attribute can be filtered.
|
||||||
* If filtering is not possible then no filter box will be displayed.
|
* If filtering is not possible then no filter box will be displayed.
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
$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) 2005 - 2014 Roland Gruber
|
Copyright (C) 2005 - 2015 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
|
||||||
|
@ -509,6 +509,9 @@ class lamUserList extends lamList {
|
||||||
/** translates GID to group name */
|
/** translates GID to group name */
|
||||||
private $trans_primary_hash = array();
|
private $trans_primary_hash = array();
|
||||||
|
|
||||||
|
/** filter value for account status */
|
||||||
|
private $accountStatusFilter = null;
|
||||||
|
|
||||||
/** ID for config option to translate primary group GIDs to group names */
|
/** ID for config option to translate primary group GIDs to group names */
|
||||||
const TRANS_PRIMARY_OPTION_NAME = "LU_TP";
|
const TRANS_PRIMARY_OPTION_NAME = "LU_TP";
|
||||||
/** ID for config option to show account status */
|
/** ID for config option to show account status */
|
||||||
|
@ -517,6 +520,13 @@ class lamUserList extends lamList {
|
||||||
/** virtual attribute name for account status column */
|
/** virtual attribute name for account status column */
|
||||||
const ATTR_ACCOUNT_STATUS = 'lam_virtual_account_status';
|
const ATTR_ACCOUNT_STATUS = 'lam_virtual_account_status';
|
||||||
|
|
||||||
|
/** filter value for locked accounts */
|
||||||
|
const FILTER_LOCKED = 2;
|
||||||
|
/** filter value for partially locked accounts */
|
||||||
|
const FILTER_SEMILOCKED = 3;
|
||||||
|
/** filter value for unlocked accounts */
|
||||||
|
const FILTER_UNLOCKED = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
@ -548,11 +558,13 @@ class lamUserList extends lamList {
|
||||||
*/
|
*/
|
||||||
protected function listRefreshData() {
|
protected function listRefreshData() {
|
||||||
parent::listRefreshData();
|
parent::listRefreshData();
|
||||||
|
// show group names
|
||||||
if ($this->trans_primary == "on") {
|
if ($this->trans_primary == "on") {
|
||||||
$this->refreshPrimaryGroupTranslation();
|
$this->refreshPrimaryGroupTranslation();
|
||||||
}
|
}
|
||||||
|
// show account status
|
||||||
if ($this->showAccountStatus) {
|
if ($this->showAccountStatus) {
|
||||||
$this->injectAccountStatusAttribute();
|
$this->injectAccountStatusAttributeAndFilterByStatus();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -726,15 +738,60 @@ class lamUserList extends lamList {
|
||||||
* @return boolean filtering possible
|
* @return boolean filtering possible
|
||||||
*/
|
*/
|
||||||
protected function canBeFiltered($attr) {
|
protected function canBeFiltered($attr) {
|
||||||
if ($attr == self::ATTR_ACCOUNT_STATUS) {
|
if (strtolower($attr) == 'jpegphoto') {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
elseif (strtolower($attr) == 'jpegphoto') {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Prints the content of a single attribute filter area.
|
||||||
|
*
|
||||||
|
* @param String $attrName attribute name
|
||||||
|
* @param boolean $clearFilter true if filter value should be cleared
|
||||||
|
*/
|
||||||
|
protected function printFilterArea($attrName, $clearFilter) {
|
||||||
|
if ($attrName != self::ATTR_ACCOUNT_STATUS) {
|
||||||
|
parent::printFilterArea($attrName, $clearFilter);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$value = "-";
|
||||||
|
if (!$clearFilter) {
|
||||||
|
if (isset($this->filters[strtolower($attrName)])) {
|
||||||
|
$value = $this->filters[strtolower($attrName)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$filterOptions = array(
|
||||||
|
'' => '',
|
||||||
|
_('Unlocked') => self::FILTER_UNLOCKED,
|
||||||
|
_('Partially locked') => self::FILTER_SEMILOCKED,
|
||||||
|
_('Locked') => self::FILTER_LOCKED
|
||||||
|
);
|
||||||
|
$filterInput = new htmlSelect('filter' . strtolower($attrName), $filterOptions, array($value));
|
||||||
|
$filterInput->setCSSClasses(array($this->type . '-dark'));
|
||||||
|
$filterInput->setHasDescriptiveElements(true);
|
||||||
|
$filterInput->setOnchangeEvent('document.getElementsByName(\'apply_filter\')[0].click();');
|
||||||
|
parseHtml(null, $filterInput, array(), false, $this->tabindex, $this->type);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the LDAP filter based on the filter entries in the GUI.
|
||||||
|
*
|
||||||
|
* @return String LDAP filter
|
||||||
|
*/
|
||||||
|
protected function buildLDAPAttributeFilter() {
|
||||||
|
$this->accountStatusFilter = null;
|
||||||
|
$text = '';
|
||||||
|
foreach ($this->filters as $attr => $filter) {
|
||||||
|
if ($attr == self::ATTR_ACCOUNT_STATUS) {
|
||||||
|
$this->accountStatusFilter = $filter;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$text .= '(' . $attr . '=' . $filter . ')';
|
||||||
|
}
|
||||||
|
return $text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of additional LDAP attributes that should be read.
|
* Returns a list of additional LDAP attributes that should be read.
|
||||||
* This can be used to show additional data even if the user selected other attributes to show in the list.
|
* This can be used to show additional data even if the user selected other attributes to show in the list.
|
||||||
|
@ -758,24 +815,43 @@ class lamUserList extends lamList {
|
||||||
/**
|
/**
|
||||||
* Injects values for the virtual account status attribute to make it sortable.
|
* Injects values for the virtual account status attribute to make it sortable.
|
||||||
*/
|
*/
|
||||||
private function injectAccountStatusAttribute() {
|
private function injectAccountStatusAttributeAndFilterByStatus() {
|
||||||
$entryCount = sizeof($this->entries);
|
$entryCount = sizeof($this->entries);
|
||||||
for ($i = 0; $i < $entryCount; $i++) {
|
for ($i = 0; $i < $entryCount; $i++) {
|
||||||
$status = 0;
|
$unixAvailable = self::isUnixAvailable($this->entries[$i]);
|
||||||
if (!self::isUnixLocked($this->entries[$i])) {
|
$sambaAvailable = self::isSambaAvailable($this->entries[$i]);
|
||||||
$status++;
|
$ppolicyAvailable = self::isPPolicyAvailable($this->entries[$i]);
|
||||||
|
$windowsAvailable = self::isWindowsAvailable($this->entries[$i]);
|
||||||
|
$unixLocked = self::isUnixLocked($this->entries[$i]);
|
||||||
|
$sambaLocked = self::isSambaLocked($this->entries[$i]);
|
||||||
|
$ppolicyLocked = self::isPPolicyLocked($this->entries[$i]);
|
||||||
|
$windowsLocked = self::isWindowsLocked($this->entries[$i]);
|
||||||
|
$hasLocked = ($unixAvailable && $unixLocked)
|
||||||
|
|| ($sambaAvailable && $sambaLocked)
|
||||||
|
|| ($ppolicyAvailable && $ppolicyLocked)
|
||||||
|
|| ($windowsAvailable && $windowsLocked);
|
||||||
|
$hasUnlocked = ($unixAvailable && !$unixLocked)
|
||||||
|
|| ($sambaAvailable && !$sambaLocked)
|
||||||
|
|| ($ppolicyAvailable && !$ppolicyLocked)
|
||||||
|
|| ($windowsAvailable && !$windowsLocked);
|
||||||
|
$status = self::FILTER_UNLOCKED;
|
||||||
|
if ($hasLocked && $hasUnlocked) {
|
||||||
|
$status = self::FILTER_SEMILOCKED;
|
||||||
}
|
}
|
||||||
if (!self::isSambaLocked($this->entries[$i])) {
|
elseif (!$hasUnlocked && $hasLocked) {
|
||||||
$status++;
|
$status = self::FILTER_LOCKED;
|
||||||
}
|
}
|
||||||
if (!self::isPPolicyLocked($this->entries[$i])) {
|
// filter accounts
|
||||||
$status++;
|
if (!empty($this->accountStatusFilter)) {
|
||||||
|
if ($status != $this->accountStatusFilter) {
|
||||||
|
unset($this->entries[$i]);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!self::isWindowsLocked($this->entries[$i])) {
|
|
||||||
$status++;
|
|
||||||
}
|
}
|
||||||
|
// add virtual attribute
|
||||||
$this->entries[$i][self::ATTR_ACCOUNT_STATUS][0] = $status;
|
$this->entries[$i][self::ATTR_ACCOUNT_STATUS][0] = $status;
|
||||||
}
|
}
|
||||||
|
$this->entries = array_values($this->entries);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue