FusionDirectory
class_SnapshotAttribute.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4 
5  Copyright (C) 2003-2010 Cajus Pollmeier
6  Copyright (C) 2011-2019 FusionDirectory
7 
8  This program is free software; you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 2 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21 */
22 
27 {
28  function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = [], $acl = '')
29  {
30  \FusionDirectory\Core\SimplePlugin\Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
31  $this->edit_enabled = FALSE;
32  $this->order = FALSE;
33  $this->attribute = FALSE;
34  $this->setInLdap(FALSE);
35  }
36 
37  function setParent (&$plugin)
38  {
39  parent::setParent($plugin);
40  if (is_object($this->plugin)) {
41  if ($this->plugin->global) {
42  $this->setHeaders([
43  _('DN'),
44  _('Date'),
45  _('Description'),
46  ''
47  ]);
48  } else {
49  $this->setHeaders([
50  _('Date'),
51  _('Description'),
52  ''
53  ]);
54  }
55  }
56  }
57 
58  function loadPostValue ()
59  {
60  if ($this->isVisible()) {
61  parent::loadPostValue();
62  parent::applyPostValue();
63  }
64  }
65 
66  protected function handleEdit ($key)
67  {
68  }
69 
70  function applyPostValue ()
71  {
72  }
73 
74  function addValue (string $dn, $entry = NULL)
75  {
76  if ($entry !== NULL) {
77  $this->value[] = $entry;
78  $this->reIndexValues();
79  }
80  }
81 
82  function renderButtons ()
83  {
84  return '';
85  }
86 
87  protected function getAttributeArrayValue ($key, $value)
88  {
89  $values = [
90  date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])),
91  $value['description'][0]
92  ];
93  if ($this->plugin->global) {
94  array_unshift($values, $value['gosaSnapshotDN'][0]);
95  }
96  return $values;
97  }
98 
99  protected function genRowIcons ($key, $value)
100  {
101  $id = $this->getHtmlId();
102  list ($img, $nbicons) = parent::genRowIcons($key, $value);
103  $img = $this->renderInputField(
104  'image', $id.'_restore_'.$key,
105  [
106  'src' => 'geticon.php?context=actions&icon=document-restore&size=16',
107  'title' => _('Restore'),
108  'alt' => _('Restore'),
109  'class' => 'center'
110  ],
111  FALSE
112  ).$img;
113  $nbicons++;
114 
115  return [$img, $nbicons];
116  }
117 
118  protected function handlePostValueActions ($id, $postValue)
119  {
120  if (parent::handlePostValueActions($id, $postValue)) {
121  return TRUE;
122  }
123  if (preg_match('/^'.$id.'_restore_/', $postValue)) {
124  $key = preg_replace('/^'.$id.'_restore_/', '', $postValue);
125  $key = preg_replace('/_[xy]$/', '', $key);
126 
127  $this->plugin->triggerRestore($this->value[$key]['dn']);
128  return TRUE;
129  }
130  return FALSE;
131  }
132 
133  function delPostValue ($key)
134  {
135  $this->plugin->triggerDelete($this->value[$key]['dn']);
136  }
137 }
Attribute which list the snapshots.
Multivalued attribute displayed as a columned table. May allow ordering and/or editing.
__construct(string $label, string $description, string $ldapName, bool $required=FALSE, $defaultValue='', string $acl='')
The constructor of Attribute.