class_SnapShotDialog.inc 6.87 KB
Newer Older
1
2
3
4
5
<?php

/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
6
  Copyright (C) 2011-2015  FusionDirectory
7
8
9
10
11
12
13
14
15
16
17
18
19

  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
20
  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
21
22
*/

23
/*!
24
 * \file class_SnapShotDialog.inc
25
 * Source code for SnapShotDialog
26
 */
27
28
29

/*!
 * \brief This class contains all the function needed to make dialogs
Benoit Mortier's avatar
Benoit Mortier committed
30
 * for the snapshot functionality
31
32
 *
 * \see plugin
Benoit Mortier's avatar
Benoit Mortier committed
33
 */
34
class SnapShotDialog extends plugin
35
{
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
  var $attributes                   = array("CurrentDescription");
  var $CurrentDescription           = "";

  var $display_restore_dialog       = FALSE;
  /* Defines the restore mode */

  var $display_all_removed_objects  = FALSE;
  /* Specifies which objects will be listed,
   * all snapshots for a single entry or
   * all snapshots of already deleted objects  */

  var $del_dn     = "";
  var $last_list  = array();

  var $snapHandler;
51

52
53
54
55
56
57
58
  /*!
   * \brief Create a SnapShotDialog
   *
   * \param string $config
   *
   * \param string $dn The DN
   *
59
60
   * \param string $parent
   */
61
  function __construct(&$config, $dn, &$parent)
62
  {
63
64
    parent::__construct($config, $dn);
    $this->snapHandler = new SnapshotHandler($this->config);
65
  }
66

67
68
69
  /*!
   * \brief Get all deleted snapshots
   */
70
  function getAllDeletedSnapshots($base_of_object, $raw = FALSE)
71
  {
72
    return $this->snapHandler->getAllDeletedSnapshots($base_of_object, $raw);
73
74
  }

Côme Bernigaud's avatar
Côme Bernigaud committed
75
76
77
78
79
80
81
  /*
   * \brief Return available snapshots for the given base
   *
   * \param string $dn The DN
   *
   * \param string boolean $raw FALSE
   */
82
  function Available_SnapsShots($dn, $raw = FALSE)
Côme Bernigaud's avatar
Côme Bernigaud committed
83
  {
84
    return $this->snapHandler->Available_SnapsShots($dn, $raw);
Côme Bernigaud's avatar
Côme Bernigaud committed
85
86
  }

87
88
89
90
91
92
93
  /*!
   * \brief Remove a snapshot
   *
   * \param string $dn The DN
   */
  function remove_snapshot($dn)
  {
94
    $this->snapHandler->remove_snapshot($dn);
95
96
  }

97

98
99
100
101
102
103
104
  /*!
   * \brief Set a snapshot base
   *
   * Show deleted snapshots from these bases
   *
   * \param string $bases
   */
105
106
  function set_snapshot_bases($bases)
  {
107
    $this->snapHandler->setSnapshotBases($bases);
108
  }
109
110


111
112
113
  /*!
   * \brief Display snapshot dialog
   */
114
115
  function execute()
  {
116
    parent::execute();
117
    $smarty = get_smarty();
118

119
    $matches = array();
120
121
    foreach ($_POST as $name => $value) {
      if (preg_match("/^RemoveSnapshot_(.*)_[xy]$/", $name, $matches)) {
122
        $entry = intval($matches[1]);
123

124
125
        if (isset($this->last_list[$entry])) {
          $this->del_dn = $this->last_list[$entry]['dn'];
126
127

          $smarty = get_smarty();
128
          $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), LDAP::fix($this->del_dn)));
129
          return $smarty->fetch (get_template_path('remove.tpl'));
130
        }
131
132

        break;
133
134
135
136
      }
    }

    /* Remove snapshot */
137
    if (isset($_POST['delete_confirm']) && !empty($this->del_dn)) {
138
139
      $this->remove_snapshot($this->del_dn);
      $this->del_dn = "";
140
    }
141

142
    /* We must restore a snapshot */
143

144
    if ($this->display_restore_dialog) {
145

146
      /* Should we only display all snapshots of already deleted objects
147
                or the snapshots for the given object dn */
148
      $tmp = array();
149
      if ($this->display_all_removed_objects) {
150
151
152
153
        $snap_shot_bases = $this->snapHandler->getSnapshotBases();
        if (count($snap_shot_bases)) {
          foreach ($snap_shot_bases as $dn) {
            $tmp = array_merge($tmp, $this->getAllDeletedSnapshots($dn, TRUE));
154
          }
155
        } else {
156
          $tmp = $this->getAllDeletedSnapshots($snap_shot_bases, TRUE);
157
        }
158
      } else {
159
        $tmp = $this->Available_SnapsShots($this->dn, TRUE);
160
161
162
163
164
      }

      $DivListSnapShots = new divSelectBox("SnapShotRestore");
      $DivListSnapShots->SetHeight(180);

165
166
      $list_of_elements = array();

167
      /* Walk through all entries and setup the display text */
168
169
      foreach ($tmp as $entry) {
        $list_of_elements[$entry['gosaSnapshotTimestamp'][0]] = $entry;
170
      }
171

172
173
      /* Sort generated list */
      krsort($list_of_elements);
174

175
      /* Add Elements to divselectbox */
176
      $this->last_list = array_values($list_of_elements);
177
      foreach ($this->last_list as $key => $entry) {
178
        $actions = "<input type='image' src='geticon.php?context=actions&icon=document-restore&size=16' name='RestoreSnapshot_$key'
179
          class='center' title='"._("Restore snapshot")."'>&nbsp;";
180
        $actions .= "<input type='image' src='geticon.php?context=actions&icon=edit-delete&size=16' name='RemoveSnapshot_$key'
181
182
          class='center' title='"._("Remove snapshot")."'>&nbsp;";

183
        $time_stamp     = date(_("Y-m-d, H:i:s"), preg_replace("/\-.*$/", "", $entry['gosaSnapshotTimestamp'][0]));
184
        $display_data   = $entry['description'][0];
185

186
187
        if ($this->display_all_removed_objects) {
          $display_data .= " - ".$entry['gosaSnapshotDN'][0];
188
189
        }

190
191
192
193
        $field0 = array("html" => $time_stamp, "attach" => "style='vertical-align:top;width:120px;'");
        $field1 = array("html" => htmlentities(utf8_decode(LDAP::fix($display_data))), "attach" => "");
        $field2 = array("html" => $actions,
                "attach" => "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
194
        $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
195
      }
196

197
198
      $smarty->assign("SnapShotDivlist", $DivListSnapShots->DrawList());
      $smarty->assign("CountSnapShots", count($list_of_elements));
199
200
    }

201
202
203
204
205
206
    $smarty->assign("restore_deleted", $this->display_all_removed_objects);
    $smarty->assign("RestoreMode",  $this->display_restore_dialog);
    $smarty->assign("CurrentDate", date(_("Y-m-d, H:i:s")));
    $smarty->assign("CurrentDN", LDAP::fix($this->dn));
    $smarty->assign("CurrentDescription", $this->CurrentDescription);
    return $smarty->fetch(get_template_path("snapshotdialog.tpl"));
207
208
  }

209
210
  /*!
   * \brief Check the snapshot dialog
211
   */
212
213
214
  function check()
  {
    $message = plugin::check();
215
216
217
    if (!$this->display_restore_dialog) {
      if (empty($this->CurrentDescription)) {
        $message[] = msgPool::required(_("Description"));
218
219
      }
    }
220
    return $message;
221
222
  }

223
224
  /*!
   * \brief Save an object
225
   */
226
  function save_object()
227
  {
228
    plugin::save_object();
229
230
    foreach ($this->attributes as $name) {
      if (isset($_POST[$name])) {
231
232
233
234
        $this->$name = stripslashes($_POST[$name]);
      }
    }
  }
235
236
237
}

?>