class_ListingEntry.inc 2.84 KB
Newer Older
1
2
3
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4
5

  Copyright (C) 2017-2019 FusionDirectory
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

  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
  the Free Software Foundation; either version 2 of the License, or
  (at your option) any later version.

  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.

  You should have received a copy of the GNU General Public License
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/

class ListingEntry implements ArrayAccess
{
  public $dn;
  public $row;
  public $type;
  private $attrs;
  protected $listing;

30
  /* Cache where columns may store stuff */
31
  public $cache = [];
32

33
  public function __construct (managementListing $listing, string $type, string $dn, array $attrs, int $row = NULL)
34
  {
35
36
37
38
39
40
41
    $this->listing  = $listing;
    $this->type     = $type;
    $this->dn       = $dn;
    $this->attrs    = $attrs;
    $this->row      = $row;
  }

42
  public function offsetSet ($offset, $value)
43
  {
44
    $this->attrs[$offset] = $value;
45
46
  }

47
  public function offsetExists ($offset)
48
  {
49
50
51
    return isset($this->attrs[$offset]);
  }

52
  public function offsetUnset ($offset)
53
  {
54
55
56
    unset($this->attrs[$offset]);
  }

57
  public function offsetGet ($offset)
58
  {
59
60
61
    return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
  }

62
  public function getPid (): string
63
64
65
66
  {
    return $this->listing->pid;
  }

67
  public function isTemplate (): bool
68
69
70
71
  {
    return preg_match('/^template_/', $this->type);
  }

72
  public function getTemplatedType (): string
73
74
75
76
  {
    return preg_replace('/^template_/', '', $this->type);
  }

77
  public function getTemplatedFields (): array
78
79
80
81
  {
    return templateHandling::fieldsFromLDAP($this->attrs);
  }

82
  public function checkAcl (string $acls): bool
83
84
85
86
87
88
89
90
91
92
93
94
95
  {
    global $ui;

    $infos  = objects::infos($this->getTemplatedType());
    $rights = $ui->get_permissions($this->dn, $infos['aclCategory'].'/'.($this->isTemplate() ? 'template' : $infos['mainTab']));
    foreach (str_split($acls) as $acl) {
      if (strpos($rights, $acl) === FALSE) {
        return FALSE;
      }
    }

    return TRUE;
  }
96

97
  public function snapshotCreationAllowed (): bool
98
99
100
101
102
103
104
  {
    global $ui;

    $infos  = objects::infos($this->getTemplatedType());
    return $ui->allow_snapshot_create($this->dn, $infos['aclCategory']);
  }

105
  public function snapshotRestoreAllowed (): bool
106
107
108
109
110
111
  {
    global $ui;

    $infos  = objects::infos($this->getTemplatedType());
    return $ui->allow_snapshot_restore($this->dn, $infos['aclCategory'], FALSE);
  }
112
}