Code

66211bfd029c91e024cf433d78f4d7cee8691317
[gosa.git] / include / class_SnapShotDialog.inc
1 <?php
3 /* Snap shot dialog class */
4 class SnapShotDialog extends plugin 
5 {
6         var $config;
7         var $attributes= array("CurrentDescription");
8         var $CurrentDescription= "";
9         var $parent= NULL;
10         var $display_restore_dialog= false;                   /* Defines the restore mode */
11         var $display_all_removed_objects= false;                /* Specifies which objects will be listed, all
12                                                  snapshots for a single entry or all snapshots
13                                                  of already deleted objects  */ 
14         var $dialog= true;
15         var $del_dn= "";
16         var $ui;
17         var $acl;
18   var $dns = array();
19   var $snap_shot_bases = array();
20   var $last_list = array();
22         
23         function SnapShotDialog($config,$dn,$parent)
24         {
25     plugin::plugin($config,$dn);
26     $this->parent       = $parent;
27                 $this->ui                 = get_userinfo();
28         }
30   
31   /* Show deleted snapshots from these bases */
32   function set_snapshot_bases($bases)
33   {
34     $this->snap_shot_bases = $bases;
35   }
36         
37         
38         /* Display snapshot dialog */
39         function execute()
40         {
41                 plugin::execute();
42                 $smarty = get_smarty();
44                 $once = true;
45                 foreach($_POST as $name => $value){
46                         if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
47                                 $once = false;
48         
49                                 $entry = preg_replace("/^RemoveSnapShot_/","",$name);
50                                 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
52         $found = false;
53         foreach($this->last_list as $t_stamp => $obj){
54           if($obj['dn'] == $entry){
55             $found = true;
56             break;
57           }
58         }
60         if($found){
61           $this->del_dn         = $entry;
62           $smarty= get_smarty();
63           $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), @LDAP::fix($this->del_dn)));
64           return($smarty->fetch (get_template_path('remove.tpl')));
65         }
66       }
67     }
69     /* Remove snapshot */
70     if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
71       $this->remove_snapshot($this->del_dn);
72       $this->del_dn = "";
73                 }
75                 /* We must restore a snapshot */
76                 if($this->display_restore_dialog){
78                         /* Should we only display all snapshots of already deleted objects 
79                 or the snapshots for the given object dn */
80                         $res = array();
81                         $tmp = array();
82                         if($this->display_all_removed_objects){
83                                 if(count($this->snap_shot_bases)){
84                                         foreach($this->snap_shot_bases as $dn){
85                                                 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
86                                         }
87                                 }else{
88                                         $tmp = $this->getAllDeletedSnapshots($this->snap_shot_bases,true);
89                                 }
90                         }else{
91                                 $tmp = $this->Available_SnapsShots($this->dn,true);
92                         }
94                         $DivListSnapShots = new DivSelectBox("SnapShotRestore");
95                         $DivListSnapShots->SetHeight(180);
97                         $list_of_elements = array();                    
98                         
99                         /* Walk through all entries and setup the display text */
100                         foreach($tmp as $key => $entry){
101                                 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
102                                 $list_of_elements[$TimeStamp] = $entry;
103                         }
105                         /* Sort generated list */
106                         krsort($list_of_elements);
107         
108                         /* Add Elements to divlist */   
109       $this->last_list = $list_of_elements;
110                         foreach($list_of_elements as $entry){
112                                 $actions= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY' 
113                                                                 class='center' title='"._("Restore snapshot")."'>&nbsp;";
114                                 $actions.= "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY' 
115                                                                 class='center' title='"._("Remove snapshot")."'>&nbsp;";
117                                 $time_stamp     = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
118                                 $display_data   = $entry['description'][0];
120                                 if($this->display_all_removed_objects){
121                                         $display_data.= " - ".$entry['gosaSnapshotDN'][0];
122                                 }
124                                 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
125                                 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
126                                 $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) , 
127                                                                 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
128                                 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
129                         }               
131                         $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());       
132                         $smarty->assign("CountSnapShots",count($list_of_elements));
133                 }
135                 $smarty->assign("restore_deleted",$this->display_all_removed_objects);
136                 $smarty->assign("RestoreMode",$this->display_restore_dialog);
137                 $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
138                 $smarty->assign("CurrentDN",$this->dn);
139                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
140                 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
141         }
144         function check()
145         {
146                 $message = plugin::check();
147                 if(!$this->display_restore_dialog){
148                         if(empty($this->CurrentDescription)){
149                                 $message[]  = _("Please specify a valid description for this snapshot.");
150                         }
151                 }
152                 return($message);
153         }
156         function save_object()
157         {       
158                 plugin::save_object();
159                 foreach($this->attributes as $name){
160                         if(isset($_POST[$name])){
161                                 $this->$name = stripslashes($_POST[$name]);
162                         }
163                 }
164         }
167 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
168 ?>