34 protected $validTypes;
43 protected $enabledCallable;
45 protected $minTargets;
46 protected $maxTargets;
48 protected $separator = FALSE;
52 function __construct (
string $name, $label, $icon,
string $targets, $callable, array $acls = [],
bool $inmenu = TRUE,
bool $inline = TRUE, array $validTypes = [])
54 if ($targets ==
'0') {
59 $this->label = $label;
61 $this->targets = $targets;
62 $this->callable = $callable;
63 $this->inmenu = $inmenu;
64 $this->
inline = $inline;
65 $this->validTypes = array_map(
'strtoupper', $validTypes);
76 foreach ($acls as $acl) {
80 if (strpos($acl,
'/') !== FALSE) {
81 list($category, $class, $acl) = explode(
'/', $acl, 3);
83 if (strpos($acl,
':') !== FALSE) {
84 list($attribute, $acl) = explode(
':', $acl, 2);
87 'category' => $category,
89 'attribute' => $attribute,
90 'acl' => str_split($acl),
94 switch ($this->targets) {
96 $this->minTargets = 0;
97 $this->maxTargets = 0;
100 $this->minTargets = 1;
101 $this->maxTargets = 1;
104 $this->minTargets = 0;
105 $this->maxTargets = 1;
108 $this->minTargets = 1;
109 $this->maxTargets = FALSE;
112 $this->minTargets = 0;
113 $this->maxTargets = FALSE;
122 $this->parent = $parent;
125 function getName ():
string 135 function setSeparator (
bool $bool)
137 $this->separator = $bool;
140 function setEnableFunction (callable $callable)
142 $this->enabledCallable = $callable;
145 function setInMenu (
bool $inmenu)
147 $this->inmenu = $inmenu;
150 function listActions (): array
152 return [$this->name];
155 function execute (
management $management, array $action)
157 if ($this->callable === FALSE) {
160 foreach ($action[
'targets'] as $targetDn) {
161 if (!$this->hasPermission($management->listing->getEntry($targetDn))) {
162 throw new FusionDirectoryException(sprintf(_(
'You are not allowed to execute action "%s" on target "%s"'), $this->name, $targetDn));
165 if (count($action[
'targets']) < $this->minTargets) {
166 throw new FusionDirectoryException(sprintf(_(
'Not enough targets (%d) passed for action "%s"'), count($action[
'targets']), $this->name));
168 if (($this->maxTargets !== FALSE) && (count($action[
'targets']) > $this->maxTargets)) {
169 throw new FusionDirectoryException(sprintf(_(
'Too many targets (%d) passed for action "%s"'), count($action[
'targets']), $this->name));
171 $func = $this->callable;
172 if (!is_array($func)) {
173 $func = [$management, $func];
175 return call_user_func($func, $action);
178 function fillMenuItems (array &$actions)
180 if (!$this->inmenu) {
184 if (!$this->hasPermission()) {
189 'name' => $this->name,
190 'icon' => $this->icon,
191 'label' => $this->label,
192 'enabled' => $this->isEnabledFor(),
193 'separator' => $this->separator,
197 function fillRowClasses (array &$classes,
ListingEntry $entry)
201 function renderColumnIcons (
ListingEntry $entry):
string 203 if (!$this->
inline) {
207 if (!empty($this->validTypes) && !($entry->isTemplate() && in_array(
'TEMPLATE', $this->validTypes)) && !in_array($entry->type, $this->validTypes)) {
212 if (!$this->hasPermission($entry)) {
213 return '<img src="images/empty.png" alt=" " class="optional"/>';
216 if (!$this->isEnabledFor($entry)) {
217 return '<img src="'.htmlescape($this->icon.
'&disabled=1').
'"'.
218 ' title="'.htmlescape($this->label).
'" alt="'.
htmlescape($this->label).
'"/>';
222 return '<input type="image" src="'.htmlescape($this->icon).
'"'.
223 ' title="'.htmlescape($this->label).
'" alt="'.
htmlescape($this->label).
'" name="listing_'.$this->name.
'_'.$entry->row.
'"/>';
226 function isEnabledFor (
ListingEntry $entry = NULL):
bool 228 if (isset($this->enabledCallable)) {
229 return call_user_func($this->enabledCallable, $this->name, $entry);
234 function hasPermission (
ListingEntry $entry = NULL):
bool 238 if ($entry === NULL) {
239 $dn = $this->parent->listing->getBase();
240 $types = $this->parent->objectTypes;
243 $dn = $entry->aclBase;
244 $types = [$entry->getTemplatedType()];
245 $template = $entry->isTemplate();
252 foreach ($this->
acl as $acl) {
254 if (!empty($acl[
'category'])) {
255 $checkAcl = $ui->get_permissions($dn, $acl[
'category'].
'/'.$acl[
'class'], $acl[
'attribute']);
256 } elseif (empty($acl[
'class']) && ($acl[
'attribute'] !=
'0')) {
257 foreach ($types as $type) {
258 $module = $ui->getAttributeCategory($type, $acl[
'attribute']);
259 $checkAcl .= $ui->get_permissions($dn, $module, $acl[
'attribute']);
262 foreach ($types as $type) {
263 $infos = objects::infos($type);
264 if (!empty($acl[
'class'])) {
266 $module = $infos[
'aclCategory'].
'/'.$acl[
'class'];
267 } elseif ($template) {
268 $module = $infos[
'aclCategory'].
'/template';
270 $module = $infos[
'aclCategory'].
'/'.$infos[
'mainTab'];
272 $checkAcl .= $ui->get_permissions($dn, $module, $acl[
'attribute']);
277 foreach ($acl[
'acl'] as $part) {
278 if (strpos($checkAcl, $part) === FALSE) {
htmlescape(string $str)
Escape string for HTML output.
Parent class for all exceptions thrown in FusionDirectory.
This class contains all the function needed to manage acl.