Code

Fixed copy & paste
[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();
21         
22         function SnapShotDialog($config,$dn,$parent)
23         {
24     plugin::plugin($config,$dn);
25     $this->parent       = $parent;
26                 $this->ui                 = get_userinfo();
27         }
29   
30   /* Show deleted snapshots from these bases */
31   function set_snapshot_bases($bases)
32   {
33     $this->snap_shot_bases = $bases;
34   }
35         
36         
37         /* Display snapshot dialog */
38         function execute()
39         {
40                 plugin::execute();
41                 $smarty = get_smarty();
43                 $once = true;
44                 foreach($_POST as $name => $value){
45                         if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
46                                 $once = false;
47         
48                                 $entry = preg_replace("/^RemoveSnapShot_/","",$name);
49                                 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
51         $this->del_dn   = $entry;
52         $smarty= get_smarty();
53         $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), @LDAP::fix($this->del_dn)));
54         return($smarty->fetch (get_template_path('remove.tpl')));
56         /* Obviously the user isn't allowed to delete. Show message and
57            clean session. 
58            print_red (_("You are not allowed to delete this snapshot!"));
59          */
60       }
61     }
63     /* Remove snapshot */
64     if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
65       $this->remove_snapshot($this->del_dn);
66       $this->del_dn = "";
67                 }
69                 /* We must restore a snapshot */
70                 if($this->display_restore_dialog){
72                         /* Should we only display all snapshots of already deleted objects 
73                 or the snapshots for the given object dn */
74                         $res = array();
75                         $tmp = array();
76                         if($this->display_all_removed_objects){
77                                 if(count($this->snap_shot_bases)){
78                                         foreach($this->snap_shot_bases as $dn){
79                                                 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
80                                         }
81                                 }else{
82                                         $tmp = $this->getAllDeletedSnapshots($this->snap_shot_bases,true);
83                                 }
84                         }else{
85                                 $tmp = $this->Available_SnapsShots($this->dn,true);
86                         }
88                         $DivListSnapShots = new DivSelectBox("SnapShotRestore");
89                         $DivListSnapShots->SetHeight(180);
91                         $list_of_elements = array();                    
92                         
93                         /* Walk through all entries and setup the display text */
94                         foreach($tmp as $key => $entry){
95                                 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
96                                 $list_of_elements[$TimeStamp] = $entry;
97                         }
99                         /* Sort generated list */
100                         krsort($list_of_elements);
101         
102                         /* Add Elements to divlist */   
103                         foreach($list_of_elements as $entry){
105                                 $actions= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY' 
106                                                                 class='center' title='"._("Restore snapshot")."'>&nbsp;";
107                                 $actions.= "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY' 
108                                                                 class='center' title='"._("Remove snapshot")."'>&nbsp;";
110                                 $time_stamp     = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
111                                 $display_data   = $entry['description'][0];
113                                 if($this->display_all_removed_objects){
114                                         $display_data.= " - ".$entry['gosaSnapshotDN'][0];
115                                 }
117                                 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
118                                 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
119                                 $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) , 
120                                                                 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
121                                 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
122                         }               
124                         $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());       
125                         $smarty->assign("CountSnapShots",count($list_of_elements));
126                 }
128                 $smarty->assign("restore_deleted",$this->display_all_removed_objects);
129                 $smarty->assign("RestoreMode",$this->display_restore_dialog);
130                 $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
131                 $smarty->assign("CurrentDN",$this->dn);
132                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
133                 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
134         }
137         function check()
138         {
139                 $message = plugin::check();
140                 if(!$this->display_restore_dialog){
141                         if(empty($this->CurrentDescription)){
142                                 $message[]  = _("Please specify a valid description for this snapshot.");
143                         }
144                 }
145                 return($message);
146         }
149         function save_object()
150         {       
151                 plugin::save_object();
152                 foreach($this->attributes as $name){
153                         if(isset($_POST[$name])){
154                                 $this->$name = stripslashes($_POST[$name]);
155                         }
156                 }
157         }
160 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
161 ?>