FusionDirectory
 All Data Structures Files Functions Variables
class_SnapshotDialogs.inc
1 <?php
2 /*
3  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
4  Copyright (C) 2003-2010 Cajus Pollmeier
5  Copyright (C) 2011-2016 FusionDirectory
6 
7  This program is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
20 */
21 
23 {
24  public $aclCategory;
25 
26  static function getAttributesInfo ()
27  {
28  return array(
29  'main' => array(
30  'name' => _('Creating an object snapshot'),
31  'attrs' => array(
32  new DisplayAttribute (
33  _('Object'), _('DN of the object you are creating a snapshot of'),
34  'object_dn', FALSE
35  ),
36  new DisplayAttribute (
37  _('Timestamp'), _('Timestamp of this snapshot creation'),
38  'timestamp', FALSE
39  ),
40  new TextAreaAttribute (
41  _('Reason'), _('Reason for creating this snapshot'),
42  'description', TRUE
43  ),
44  )
45  ),
46  );
47  }
48 
49  function __construct ($dn, $parent, $aclCategory)
50  {
51  parent::__construct();
52  $this->attributesAccess['description']->setInLdap(FALSE);
53  $this->object_dn = $dn;
54  $this->parent = $parent;
55  $this->aclCategory = $aclCategory;
56  }
57 
58  function execute ()
59  {
60  $this->timestamp = date(_('Y-m-d, H:i:s'));
61  $str = parent::execute();
62 
63  $str .= '<p class="plugbottom">'.
64  ' <input type="submit" name="edit_finish" value="'.msgPool::saveButton().'"/>&nbsp;'.
65  ' <input type="submit" name="edit_cancel" value="'.msgPool::cancelButton().'"/>'.
66  '</p>';
67 
68  return $str;
69  }
70 
71  function save ()
72  {
73  $this->parent->createSnapshot($this->object_dn, $this->description);
74  }
75 }
76 
78 {
79  function __construct ($label, $description, $ldapName, $required = FALSE, $defaultValue = array(), $acl = '')
80  {
81  Attribute::__construct($label, $description, $ldapName, $required, $defaultValue, $acl);
82  $this->edit_enabled = FALSE;
83  $this->order = FALSE;
84  $this->attribute = FALSE;
85  $this->setInLdap(FALSE);
86  }
87 
88  function loadPostValue ()
89  {
90  if ($this->isVisible()) {
91  parent::loadPostValue();
92  parent::applyPostValue();
93  }
94  }
95 
96  protected function handleEdit($key)
97  {
98  }
99 
100  function applyPostValue ()
101  {
102  }
103 
104  function addValue($value)
105  {
106  $this->value[] = $value;
107  $this->reIndexValues();
108  }
109 
110  function renderButtons ()
111  {
112  return '';
113  }
114 
115  protected function getAttributeArrayValue($key, $value)
116  {
117  $values = array(
118  date(_('Y-m-d, H:i:s'), preg_replace('/\-.*$/', '', $value['gosaSnapshotTimestamp'][0])),
119  $value['description'][0]
120  );
121  if ($this->plugin->global) {
122  array_unshift($values, $value['gosaSnapshotDN'][0]);
123  }
124  return $values;
125  }
126 
127  protected function genRowIcons($key, $value)
128  {
129  $id = $this->getHtmlId();
130  list ($img, $nbicons) = parent::genRowIcons($key, $value);
131  $img = $this->renderInputField(
132  'image', $id.'_restore_'.$key,
133  array(
134  'src' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
135  'title' => _('Restore'),
136  'alt' => _('Restore'),
137  'class' => 'center'
138  )
139  ).$img;
140  $nbicons++;
141 
142  return array ($img, $nbicons);
143  }
144 
145  protected function handlePostValueActions($id, $postValue)
146  {
147  if (parent::handlePostValueActions($id, $postValue)) {
148  return TRUE;
149  }
150  if (preg_match('/^'.$id.'_restore_/', $postValue)) {
151  $key = preg_replace('/^'.$id.'_restore_/', '', $postValue);
152  $key = preg_replace('/_[xy]$/', '', $key);
153 
154  $this->plugin->triggerRestore($this->value[$key]['dn']);
155  return TRUE;
156  }
157  return FALSE;
158  }
159 
160  function delPostValue ($key)
161  {
162  $this->plugin->triggerDelete($this->value[$key]['dn']);
163  }
164 }
165 
167 {
168  public $global;
169  public $aclCategory;
170 
171  protected $snapDn;
172  protected $snapAction;
173 
174  static function getAttributesInfo ()
175  {
176  return array(
177  'main' => array(
178  'name' => _('Restoring snapshots'),
179  'class' => array('fullwidth'),
180  'attrs' => array(
181  new DisplayAttribute (
182  _('Object'), _('DN of the object you are creating a snapshot of'),
183  'object_dn', FALSE
184  ),
185  new SnapshotsAttribute (
186  _('Snapshots'), _('Existing snapshots for this object'),
187  'snapshots', FALSE
188  ),
189  )
190  ),
191  );
192  }
193 
194  function __construct ($dn, $parent, $global, $aclCategory)
195  {
196  parent::__construct();
197  $this->object_dn = $dn;
198  $this->parent = $parent;
199  $this->global = $global;
200  $this->aclCategory = $aclCategory;
201  if ($this->global) {
202  $this->attributesAccess['object_dn']->setVisible(FALSE);
203  }
204  $this->updateList();
205  }
206 
207  function updateList ()
208  {
209  if ($this->global) {
210  $this->snapshots = $this->parent->getAllDeletedSnapshots();
211  } else {
212  $this->snapshots = $this->parent->getAvailableSnapsShots($this->object_dn);
213  }
214  }
215 
216  function execute ()
217  {
218  if ($this->dialog == 'delete') {
219  $objects = array(
220  array(
221  'name' => 'snapshot',
222  'dn' => $this->snapDn,
223  'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
224  'type' => 'Snapshot'
225  )
226  );
227 
228  // Display confirmation dialog.
229  $smarty = get_smarty();
230  $smarty->assign('objects', $objects);
231  $str = $smarty->fetch(get_template_path('simple-remove.tpl'));
232  } elseif ($this->dialog == 'restore') {
233  $objects = array(
234  array(
235  'name' => 'snapshot',
236  'dn' => $this->snapDn,
237  'icon' => 'geticon.php?context=actions&amp;icon=document-restore&amp;size=16',
238  'type' => 'Snapshot'
239  )
240  );
241 
242  // Display confirmation dialog.
243  $smarty = get_smarty();
244  $smarty->assign('objects', $objects);
245  $str = $smarty->fetch(get_template_path('restore-confirm.tpl'));
246  } else {
247  $str = parent::execute();
248  $str .= '<p class="plugbottom">'.
249  ' <input type="submit" name="edit_cancel" value="'.msgPool::backButton().'"/>'.
250  '</p>';
251  }
252 
253  return $str;
254  }
255 
256  function triggerRestore($dn)
257  {
258  $this->dialog = 'restore';
259  $this->snapDn = $dn;
260  }
261 
262  function triggerDelete($dn)
263  {
264  $this->dialog = 'delete';
265  $this->snapDn = $dn;
266  }
267 
268  function save_object()
269  {
270  if ($this->dialog == 'delete') {
271  if (isset($_POST['delete_confirmed'])) {
272  $this->parent->removeSnapshot($this->snapDn);
273  $this->closeDialog();
274  } elseif (isset($_POST['delete_cancel'])) {
275  $this->closeDialog();
276  }
277  } elseif ($this->dialog == 'restore') {
278  if (isset($_POST['restore_confirmed'])) {
279  $this->parent->restoreSnapshot($this->snapDn);
280  $this->closeDialog();
281  } elseif (isset($_POST['restore_cancel'])) {
282  $this->closeDialog();
283  }
284  } else {
285  parent::save_object();
286  }
287  }
288 
289  function closeDialog ()
290  {
291  parent::closeDialog();
292  $this->snapDn = NULL;
293  $this->updateList();
294  }
295 
296  function save ()
297  {
298  }
299 }
300 ?>
$parent
Reference to parent object.
This class is made for easy plugin creation for editing LDAP attributes.
$dn
dn of the opened object
get_template_path($filename= '', $plugin=FALSE, $path= '')
Return themed path for specified base file.
Definition: functions.inc:315
& get_smarty()
Get global smarty object.
Definition: functions.inc:953
This class allow to display a text in front of an attribute.
This class allow to handle easily a String LDAP attribute that appears as a text area.
__construct($label, $description, $ldapName, $required=FALSE, $defaultValue="", $acl="")
The constructor of Attribute.