1 <?php
2 /*
3 * This code is part of GOsa (http://www.gosa-project.org)
4 * Copyright (C) 2003-2008 GONICUS GmbH
5 *
6 * ID: $$Id$$
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
23 /* Snap shot dialog class */
24 class SnapShotDialog extends plugin
25 {
26 var $config;
27 var $attributes= array("CurrentDescription");
28 var $CurrentDescription= "";
29 var $parent= NULL;
30 var $display_restore_dialog= false; /* Defines the restore mode */
31 var $display_all_removed_objects= false; /* Specifies which objects will be listed, all
32 snapshots for a single entry or all snapshots
33 of already deleted objects */
34 var $dialog= true;
35 var $del_dn= "";
36 var $ui;
37 var $acl;
38 var $dns = array();
39 var $snap_shot_bases = array();
40 var $last_list = array();
43 function SnapShotDialog(&$config, $dn, &$parent)
44 {
45 plugin::plugin($config,$dn);
46 $this->parent = &$parent;
47 $this->ui = get_userinfo();
48 }
51 /* Show deleted snapshots from these bases */
52 function set_snapshot_bases($bases)
53 {
54 $this->snap_shot_bases = $bases;
55 }
58 /* Display snapshot dialog */
59 function execute()
60 {
61 plugin::execute();
62 $smarty = get_smarty();
64 $ui = get_userinfo();
65 $once = true;
66 foreach($_POST as $name => $value){
67 if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
68 $once = false;
69 $entry = preg_replace("/^RemoveSnapShot_/","",$name);
70 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
71 $found = false;
72 foreach($this->last_list as $t_stamp => $obj){
73 if($obj['dn'] == $entry){
74 $found = true;
75 break;
76 }
77 }
79 if($found){
80 $this->del_dn = $entry;
81 $smarty= get_smarty();
82 $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), LDAP::fix($this->del_dn)));
83 return($smarty->fetch (get_template_path('remove.tpl')));
84 }
85 }
86 }
88 /* Remove snapshot */
89 if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
90 $this->remove_snapshot($this->del_dn);
91 $this->del_dn = "";
92 }
94 /* We must restore a snapshot */
96 if($this->display_restore_dialog){
98 /* Should we only display all snapshots of already deleted objects
99 or the snapshots for the given object dn */
100 $res = array();
101 $tmp = array();
102 if($this->display_all_removed_objects){
103 if(count($this->snap_shot_bases)){
104 foreach($this->snap_shot_bases as $dn){
105 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
106 }
107 }else{
108 $tmp = $this->getAllDeletedSnapshots($this->snap_shot_bases,true);
109 }
110 }else{
111 $tmp = $this->Available_SnapsShots($this->dn,true);
112 }
114 $DivListSnapShots = new divSelectBox("SnapShotRestore");
115 $DivListSnapShots->SetHeight(180);
117 $list_of_elements = array();
119 /* Walk through all entries and setup the display text */
120 foreach($tmp as $key => $entry){
122 /* Check permissions */
123 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
124 $list_of_elements[$TimeStamp] = $entry;
125 }
127 /* Sort generated list */
128 krsort($list_of_elements);
130 /* Add Elements to divlist */
131 $this->last_list = $list_of_elements;
132 foreach($list_of_elements as $entry){
134 $actions= "<input type='image' src='images/lists/restore.png' name='RestoreSnapShot_%KEY'
135 class='center' title='"._("Restore snapshot")."'> ";
136 $actions.= "<input type='image' src='images/lists/trash.png' name='RemoveSnapShot_%KEY'
137 class='center' title='"._("Remove snapshot")."'> ";
139 $time_stamp = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
140 $display_data = $entry['description'][0];
142 if($this->display_all_removed_objects){
143 $display_data.= " - ".$entry['gosaSnapshotDN'][0];
144 }
146 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
147 $field1 = array("string"=> htmlentities (utf8_decode(LDAP::fix($display_data))), "attach"=> "");
148 $field2 = array("string"=> str_replace("%KEY",base64_encode($entry['dn']),$actions) ,
149 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
150 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
151 }
153 $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());
154 $smarty->assign("CountSnapShots",count($list_of_elements));
155 }
157 $smarty->assign("restore_deleted",$this->display_all_removed_objects);
158 $smarty->assign("RestoreMode",$this->display_restore_dialog);
159 $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
160 $smarty->assign("CurrentDN",LDAP::fix($this->dn));
161 $smarty->assign("CurrentDescription",$this->CurrentDescription);
162 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
163 }
166 function check()
167 {
168 $message = plugin::check();
169 if(!$this->display_restore_dialog){
170 if(empty($this->CurrentDescription)){
171 $message[]= msgPool::invalid(_("Description"));
172 }
173 }
174 return($message);
175 }
178 function save_object()
179 {
180 plugin::save_object();
181 foreach($this->attributes as $name){
182 if(isset($_POST[$name])){
183 $this->$name = stripslashes($_POST[$name]);
184 }
185 }
186 }
187 }
189 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
190 ?>