| 1 |
<?php |
| 2 |
/* |
| 3 |
|
| 4 |
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) |
| 5 |
Copyright (C) 2011 - 2024 Roland Gruber |
| 6 |
|
| 7 |
This program is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 2 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
This program is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program; if not, write to the Free Software |
| 19 |
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 20 |
*/ |
| 21 |
|
| 22 |
/** |
| 23 |
* Shows general information like the creation time of an account. |
| 24 |
* |
| 25 |
* @package modules |
| 26 |
* @author Roland Gruber |
| 27 |
*/ |
| 28 |
|
| 29 |
use LAM\TYPES\ConfiguredType; |
| 30 |
use LAM\TYPES\TypeManager; |
| 31 |
|
| 32 |
/** |
| 33 |
* Shows general information like the creation time of an account. |
| 34 |
* |
| 35 |
* @package modules |
| 36 |
*/ |
| 37 |
class generalInformation extends baseModule { |
| 38 |
|
| 39 |
/** |
| 40 |
* {@inheritDoc} |
| 41 |
*/ |
| 42 |
public function can_manage(): bool { |
| 43 |
return in_array($this->get_scope(), LAM\TYPES\getTypes()); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* {@inheritDoc} |
| 48 |
*/ |
| 49 |
public function get_metaData(): array { |
| 50 |
$return = []; |
| 51 |
// icon |
| 52 |
$return['icon'] = 'info.svg'; |
| 53 |
// alias name |
| 54 |
$return["alias"] = _("General information"); |
| 55 |
// module dependencies |
| 56 |
$return['dependencies'] = ['depends' => [], 'conflicts' => []]; |
| 57 |
// managed attributes |
| 58 |
$return['attributes'] = ['creatorsname', 'createtimestamp', 'modifiersname', |
| 59 |
'modifytimestamp', 'hassubordinates', 'memberof']; |
| 60 |
$return['hiddenAttributes'] = ['creatorsname', 'createtimestamp', 'modifiersname', |
| 61 |
'modifytimestamp', 'hassubordinates']; |
| 62 |
return $return; |
| 63 |
} |
| 64 |
|
| 65 |
/** |
| 66 |
* {@inheritDoc} |
| 67 |
*/ |
| 68 |
public function display_html_attributes(): htmlElement|array { |
| 69 |
$return = new htmlResponsiveRow(); |
| 70 |
// creation info |
| 71 |
if (isset($this->attributes['creatorsname'][0])) { |
| 72 |
$return->addLabel(new htmlOutputText(_('Created by'))); |
| 73 |
$return->addField(new htmlOutputText(getAbstractDN($this->attributes['creatorsname'][0]))); |
| 74 |
} |
| 75 |
if (isset($this->attributes['createtimestamp'][0])) { |
| 76 |
$return->addLabel(new htmlOutputText(_('Creation time'))); |
| 77 |
$return->addField(new htmlOutputText(formatLDAPTimestamp($this->attributes['createtimestamp'][0]))); |
| 78 |
} |
| 79 |
if (isset($this->attributes['creatorsname'][0]) || isset($this->attributes['createtimestamp'][0])) { |
| 80 |
$return->addVerticalSpacer('1rem'); |
| 81 |
} |
| 82 |
// modification info |
| 83 |
if (isset($this->attributes['modifiersname'][0])) { |
| 84 |
$return->addLabel(new htmlOutputText(_('Modified by'))); |
| 85 |
$return->addField(new htmlOutputText(getAbstractDN($this->attributes['modifiersname'][0]))); |
| 86 |
} |
| 87 |
if (isset($this->attributes['modifytimestamp'][0])) { |
| 88 |
$return->addLabel(new htmlOutputText(_('Modification time'))); |
| 89 |
$return->addField(new htmlOutputText(formatLDAPTimestamp($this->attributes['modifytimestamp'][0]))); |
| 90 |
} |
| 91 |
if (isset($this->attributes['modifiersname'][0]) || isset($this->attributes['modifytimestamp'][0])) { |
| 92 |
$return->addVerticalSpacer('1rem'); |
| 93 |
} |
| 94 |
// children |
| 95 |
if (isset($this->attributes['hassubordinates'][0])) { |
| 96 |
$hasChilds = _('no'); |
| 97 |
if ($this->attributes['hassubordinates'][0] == 'TRUE') { |
| 98 |
$hasChilds = _('yes'); |
| 99 |
} |
| 100 |
$return->addLabel(new htmlOutputText(_('Has subentries'))); |
| 101 |
$return->addField(new htmlOutputText($hasChilds)); |
| 102 |
$return->addVerticalSpacer('1rem'); |
| 103 |
} |
| 104 |
// group memberships |
| 105 |
if (isset($this->attributes['memberof'][0])) { |
| 106 |
$typeManager = new TypeManager(); |
| 107 |
$scopes = ['gon', 'group']; |
| 108 |
$types = $typeManager->getConfiguredTypesForScopes($scopes); |
| 109 |
$suffixList = []; |
| 110 |
foreach ($types as $type) { |
| 111 |
$suffix = $type->getSuffix(); |
| 112 |
// continue if suffixes are not unique |
| 113 |
if (isset($suffixList[$suffix])) { |
| 114 |
continue; |
| 115 |
} |
| 116 |
if (!empty($suffix)) { |
| 117 |
$suffixList[$suffix] = $type->getId(); |
| 118 |
} |
| 119 |
} |
| 120 |
$groupLabel = new htmlOutputText(_('Groups')); |
| 121 |
$groupLabel->alignment = htmlElement::ALIGN_TOP; |
| 122 |
$return->addLabel($groupLabel); |
| 123 |
$groups = new htmlTable(); |
| 124 |
foreach ($this->attributes['memberof'] as $memberOf) { |
| 125 |
$groupEntry = new htmlOutputText(getAbstractDN($memberOf)); |
| 126 |
foreach ($suffixList as $suffix => $type) { |
| 127 |
if ((stripos($memberOf, $suffix) > 0) && !isAccountTypeHidden($type)) { |
| 128 |
$groupEntry = new htmlLink(getAbstractDN($memberOf), 'edit.php?type=' . $type . '&DN=\'' . $memberOf . '\''); |
| 129 |
$groupEntry->setTargetWindow('_blank'); |
| 130 |
break; |
| 131 |
} |
| 132 |
} |
| 133 |
$groups->addElement($groupEntry, true); |
| 134 |
} |
| 135 |
$return->addField($groups); |
| 136 |
} |
| 137 |
return $return; |
| 138 |
} |
| 139 |
|
| 140 |
/** |
| 141 |
* {@inheritDoc} |
| 142 |
*/ |
| 143 |
public function process_attributes(): array { |
| 144 |
return []; |
| 145 |
} |
| 146 |
|
| 147 |
/** |
| 148 |
* {@inheritDoc} |
| 149 |
*/ |
| 150 |
public function loadAttributesFromAccountCopy(array $ldapAttributes, array $attributesToIgnore = []): void { |
| 151 |
// no action for this module |
| 152 |
} |
| 153 |
|
| 154 |
/** |
| 155 |
* @inheritDoc |
| 156 |
*/ |
| 157 |
public function getListAttributeDescriptions(ConfiguredType $type): array { |
| 158 |
return [ |
| 159 |
'creatorsname' => _('Created by'), |
| 160 |
'createtimestamp' => _('Creation time'), |
| 161 |
'modifiersname' => _('Modified by'), |
| 162 |
'modifytimestamp' => _('Modification time'), |
| 163 |
'hassubordinates' => _('Has subentries'), |
| 164 |
'memberof' => _('Groups') |
| 165 |
]; |
| 166 |
} |
| 167 |
|
| 168 |
} |
| 169 |
|