class_ListingEntry.inc 3.1 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

  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
{
24
25
26
  /*!
   * \brief LDAP dn if any, unique id otherwise
   */
27
  public $dn;
28
29
30
31
32
33
34
35
36

  /*!
   * \brief DN to use for ACL checks, usually the same as $dn
   */
  public $aclBase;

  /*!
   * \brief Row number
   */
37
  public $row;
38
39
40
41

  /*!
   * \brief Object type
   */
42
  public $type;
43

44
45
46
  private $attrs;
  protected $listing;

47
  /* Cache where columns may store stuff */
48
  public $cache = [];
49

50
  public function __construct (managementListing $listing, string $type, string $dn, array $attrs, int $row = NULL)
51
  {
52
53
54
    $this->listing  = $listing;
    $this->type     = $type;
    $this->dn       = $dn;
55
    $this->aclBase  = $dn;
56
57
58
59
    $this->attrs    = $attrs;
    $this->row      = $row;
  }

60
  public function offsetSet ($offset, $value)
61
  {
62
    $this->attrs[$offset] = $value;
63
64
  }

65
  public function offsetExists ($offset)
66
  {
67
68
69
    return isset($this->attrs[$offset]);
  }

70
  public function offsetUnset ($offset)
71
  {
72
73
74
    unset($this->attrs[$offset]);
  }

75
  public function offsetGet ($offset)
76
  {
77
78
79
    return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
  }

80
  public function getPid (): string
81
82
83
84
  {
    return $this->listing->pid;
  }

85
  public function isTemplate (): bool
86
87
88
89
  {
    return preg_match('/^template_/', $this->type);
  }

90
  public function getTemplatedType (): string
91
92
93
94
  {
    return preg_replace('/^template_/', '', $this->type);
  }

95
  public function getTemplatedFields (): array
96
97
98
99
  {
    return templateHandling::fieldsFromLDAP($this->attrs);
  }

100
  public function checkAcl (string $acls): bool
101
102
103
104
  {
    global $ui;

    $infos  = objects::infos($this->getTemplatedType());
105
    $rights = $ui->get_permissions($this->aclBase, $infos['aclCategory'].'/'.($this->isTemplate() ? 'template' : $infos['mainTab']));
106
107
108
109
110
111
112
113
    foreach (str_split($acls) as $acl) {
      if (strpos($rights, $acl) === FALSE) {
        return FALSE;
      }
    }

    return TRUE;
  }
114

115
  public function snapshotCreationAllowed (): bool
116
117
118
119
  {
    global $ui;

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

123
  public function snapshotRestoreAllowed (): bool
124
125
126
127
  {
    global $ui;

    $infos  = objects::infos($this->getTemplatedType());
128
    return $ui->allow_snapshot_restore($this->aclBase, $infos['aclCategory'], FALSE);
129
  }
130
}