Code

Requrie new schema for gosaAccount
[gosa.git] / gosa-core / include / class_SnapShotDialog.inc
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();
42         
43         function SnapShotDialog(&$config, $dn, &$parent)
44         {
45     plugin::plugin($config,$dn);
46     $this->parent       = &$parent;
47                 $this->ui                 = get_userinfo();
48         }
50   
51   /* Show deleted snapshots from these bases */
52   function set_snapshot_bases($bases)
53   {
54     $this->snap_shot_bases = $bases;
55   }
56         
57         
58         /* Display snapshot dialog */
59         function execute()
60         {
61                 plugin::execute();
62                 $smarty = get_smarty();
64     if(!isset($this->parent->acl_module) || !count($this->parent->acl_module)){
65       trigger_error("Could not detect acl_module in parent object (".get_class($this->parent).").");
66       return("");
67     }
69     $ui = get_userinfo();
71                 $once = true;
72                 foreach($_POST as $name => $value){
73                         if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
74                                 $once = false;
75         
76         $entry = preg_replace("/^RemoveSnapShot_/","",$name);
77         $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
79         $found = false;
80         foreach($this->last_list as $t_stamp => $obj){
81           if($obj['dn'] == $entry){
82             $found = true;
83             break;
84           }
85         }
87         if($found){
88           $this->del_dn         = $entry;
89           $smarty= get_smarty();
90           $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), LDAP::fix($this->del_dn)));
91           return($smarty->fetch (get_template_path('remove.tpl')));
92         }
93       }
94     }
96     /* Remove snapshot */
97     if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
98       $this->remove_snapshot($this->del_dn);
99       $this->del_dn = "";
100                 }
102                 /* We must restore a snapshot */
104                 if($this->display_restore_dialog){
106                         /* Should we only display all snapshots of already deleted objects 
107                 or the snapshots for the given object dn */
108                         $res = array();
109                         $tmp = array();
110                         if($this->display_all_removed_objects){
111                                 if(count($this->snap_shot_bases)){
112                                         foreach($this->snap_shot_bases as $dn){
113                                                 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
114                                         }
115                                 }else{
116                                         $tmp = $this->getAllDeletedSnapshots($this->snap_shot_bases,true);
117                                 }
118                         }else{
119                                 $tmp = $this->Available_SnapsShots($this->dn,true);
120                         }
122                         $DivListSnapShots = new divSelectBox("SnapShotRestore");
123                         $DivListSnapShots->SetHeight(180);
125                         $list_of_elements = array();                    
126                         
127                         /* Walk through all entries and setup the display text */
128                         foreach($tmp as $key => $entry){
129     
130         /* Check permissions */
131         $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
132         $list_of_elements[$TimeStamp] = $entry;
133                         }
135                         /* Sort generated list */
136                         krsort($list_of_elements);
137         
138                         /* Add Elements to divlist */   
139       $this->last_list = $list_of_elements;
140                         foreach($list_of_elements as $entry){
142         $actions= "<input type='image' src='images/lists/restore.png' name='RestoreSnapShot_%KEY' 
143           class='center' title='"._("Restore snapshot")."'>&nbsp;";
144         $actions.= "<input type='image' src='images/lists/trash.png' name='RemoveSnapShot_%KEY' 
145           class='center' title='"._("Remove snapshot")."'>&nbsp;";
147                                 $time_stamp     = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
148                                 $display_data   = $entry['description'][0];
150                                 if($this->display_all_removed_objects){
151                                         $display_data.= " - ".$entry['gosaSnapshotDN'][0];
152                                 }
154                                 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
155                                 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
156                                 $field2 = array("string"=> str_replace("%KEY",base64_encode($entry['dn']),$actions) , 
157                                                                 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
158                                 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
159                         }               
161                         $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());       
162                         $smarty->assign("CountSnapShots",count($list_of_elements));
163                 }
165                 $smarty->assign("restore_deleted",$this->display_all_removed_objects);
166                 $smarty->assign("RestoreMode",$this->display_restore_dialog);
167                 $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
168                 $smarty->assign("CurrentDN",$this->dn);
169                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
170                 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
171         }
174         function check()
175         {
176                 $message = plugin::check();
177                 if(!$this->display_restore_dialog){
178                         if(empty($this->CurrentDescription)){
179         $message[]= msgPool::invalid(_("Description"));
180                         }
181                 }
182                 return($message);
183         }
186         function save_object()
187         {       
188                 plugin::save_object();
189                 foreach($this->attributes as $name){
190                         if(isset($_POST[$name])){
191                                 $this->$name = stripslashes($_POST[$name]);
192                         }
193                 }
194         }
197 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
198 ?>