class_ListingEntry.inc 2.69 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
30
  public function __construct(managementListing $listing, $type, $dn, array $attrs, $row = NULL)
  {
31
32
33
34
35
36
37
    $this->listing  = $listing;
    $this->type     = $type;
    $this->dn       = $dn;
    $this->attrs    = $attrs;
    $this->row      = $row;
  }

38
39
  public function offsetSet($offset, $value)
  {
40
    $this->attrs[$offset] = $value;
41
42
  }

43
44
  public function offsetExists($offset)
  {
45
46
47
    return isset($this->attrs[$offset]);
  }

48
49
  public function offsetUnset($offset)
  {
50
51
52
    unset($this->attrs[$offset]);
  }

53
54
  public function offsetGet($offset)
  {
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
    return (isset($this->attrs[$offset]) ? $this->attrs[$offset] : NULL);
  }

  public function getPid()
  {
    return $this->listing->pid;
  }

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

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

  public function getTemplatedFields()
  {
    return templateHandling::fieldsFromLDAP($this->attrs);
  }

  public function checkAcl($acls)
  {
    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;
  }
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107

  public function snapshotCreationAllowed()
  {
    global $ui;

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

  public function snapshotRestoreAllowed()
  {
    global $ui;

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