class_ListingEntry.inc 2.77 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2017-2018  FusionDirectory

  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;

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

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

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

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

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

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

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

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

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

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

81
  public function checkAcl ($acls)
82
83
84
85
86
87
88
89
90
91
92
93
94
  {
    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;
  }
95

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

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

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

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