Code

Added snapshot to groups && fixed restore dialog
[gosa.git] / plugins / admin / systems / 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 $Restore                    = false;                /* Defines the restore mode */
11         var $DeletedOnes                = false;                /* Specifies which objects will be listed */    
12         var $dialog                             = true;
13         
14         function SnapShotDialog($config,$dn,$parent)
15         {
16                 plugin::plugin($config,$dn);
17                 $this->parent = $parent;
18         }
19         
20         
21         /* Display snapshot dialog */
22         function execute()
23         {
24                 plugin::execute();
25                 $smarty = get_smarty();
27                 /* We must restore a snapshot, so get snapshots  */
28                 if($this->Restore){
30                         /* Should we only display all snapshots of already deleted objects 
31                 or the snapshots for the given object dn */
32                         $res = array();
33                         if($this->DeletedOnes){
34                                 $tmp = $this->getAllDeletedSnapshots($this->dn,true);
35                         }else{
36                                 $tmp = $this->Available_SnapsShots($this->dn,true);
37                         }
38                 
39                         /* Walk through all entries and setup the display text */
40                         foreach($tmp as $key => $entry){
41                         
42                                 $data = $entry['description'][0];
43                                 $date = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
44                                 if($this->DeletedOnes){
45                                         $data.= " - ".$entry['gosaSnapshotDN'][0];
46                                 }
47         
48                                 if(strlen($data) > 83){
49                                         $data= substr($data,0,80)." ...";
50                                 }
51         
52                                 $res[base64_encode($entry['dn'])] = $date." - ".$data;
53                         }
54                         $smarty->assign("SnapShots",$res);
55                         $smarty->assign("CountSnapShots",count($res));
56                 }
58                 $smarty->assign("RestoreMode",$this->Restore);
59                 $smarty->assign("CurrentDate",date("d.m.Y H:i"));
60                 $smarty->assign("CurrentDN",$this->dn);
61                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
62                 return($smarty->fetch(get_template_path("snapshotdialog.tpl",TRUE,dirname(__FILE__))));
63         }
66         function check()
67         {
68                 $message = plugin::check();
69                 if(!$this->Restore){
70                         if(empty($this->CurrentDescription)){
71                                 $message[]  = _("Please specify a valid description for this snapshot.");
72                         }
73                 }
74                 return($message);
75         }
78         function save_object()
79         {       
80                 plugin::save_object();
81                 foreach($this->attributes as $name){
82                         if(isset($_POST[$name])){
83                                 $this->$name = stripslashes($_POST[$name]);
84                         }
85                 }
86         }
87 }
89 ?>