File: class_SnapShotDialog.inc

package info (click to toggle)
fusiondirectory 1.0.8.2-5
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 28,984 kB
  • sloc: php: 74,645; xml: 3,645; perl: 1,555; pascal: 705; sh: 135; sql: 45; makefile: 19
file content (249 lines) | stat: -rw-r--r-- 7,364 bytes parent folder | download | duplicates (2)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
<?php

/*
  This code is part of FusionDirectory (http://www.fusiondirectory.org/)
  Copyright (C) 2003-2010  Cajus Pollmeier
  Copyright (C) 2011-2013  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.
*/

/*!
 * \file class_SnapShotDialog.inc
 * Source code for SnapShotDialog
 */

/*!
 * \brief This class contains all the function needed to make dialogs
 * for the snapshot functionality
 *
 * \see plugin
 */
class SnapShotDialog extends plugin
{
  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;

  /*!
   * \brief Create a SnapShotDialog
   *
   * \param string $config
   *
   * \param string $dn The DN
   *
   * \param string $parent
   */
  function __construct(&$config, $dn, &$parent)
  {
    parent::__construct($config, $dn);
    $this->snapHandler = new SnapshotHandler($this->config);
  }

  /*! \brief Test if snapshoting is enabled
   *
   * Test weither snapshotting is enabled or not. There will also be some errors posted,
   * if the configuration failed
   *
   * \return TRUE if snapshots are enabled, and FALSE if it is disabled
   */
  function snapshotEnabled()
  {
    return $this->snapHandler->enabled();
  }

  /*!
   * \brief Get all deleted snapshots
   */
  function getAllDeletedSnapshots($base_of_object, $raw = FALSE)
  {
    return $this->snapHandler->getAllDeletedSnapshots($base_of_object, $raw);
  }

  /*
   * \brief Return available snapshots for the given base
   *
   * \param string $dn The DN
   *
   * \param string boolean $raw FALSE
   */
  function Available_SnapsShots($dn, $raw = FALSE)
  {
    return $this->snapHandler->Available_SnapsShots($dn, $raw);
  }

  /*!
   * \brief Remove a snapshot
   *
   * \param string $dn The DN
   */
  function remove_snapshot($dn)
  {
    $this->snapHandler->remove_snapshot($dn);
  }


  /*!
   * \brief Set a snapshot base
   *
   * Show deleted snapshots from these bases
   *
   * \param string $bases
   */
  function set_snapshot_bases($bases)
  {
    $this->snapHandler->setSnapshotBases($bases);
  }


  /*!
   * \brief Display snapshot dialog
   */
  function execute()
  {
    parent::execute();
    $smarty = get_smarty();

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

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

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

        break;
      }
    }

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

    /* We must restore a snapshot */

    if ($this->display_restore_dialog) {

      /* Should we only display all snapshots of already deleted objects
                or the snapshots for the given object dn */
      $tmp = array();
      if ($this->display_all_removed_objects) {
        $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));
          }
        } else {
          $tmp = $this->getAllDeletedSnapshots($snap_shot_bases, TRUE);
        }
      } else {
        $tmp = $this->Available_SnapsShots($this->dn, TRUE);
      }

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

      $list_of_elements = array();

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

      /* Sort generated list */
      krsort($list_of_elements);

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

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

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

        $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;'");
        $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
      }

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

    $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"));
  }

  /*!
   * \brief Check the snapshot dialog
   */
  function check()
  {
    $message = plugin::check();
    if (!$this->display_restore_dialog) {
      if (empty($this->CurrentDescription)) {
        $message[] = msgPool::required(_("Description"));
      }
    }
    return $message;
  }

  /*!
   * \brief Save an object
   */
  function save_object()
  {
    plugin::save_object();
    foreach ($this->attributes as $name) {
      if (isset($_POST[$name])) {
        $this->$name = stripslashes($_POST[$name]);
      }
    }
  }
}

?>