Code

9e42c81a6a733d5c27516016bcd87c1c0c0beee6
[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 snapshots for a single entry 
12                                                                                                                 or all snapshots of already deleted objects  */ 
13         var $dialog                                             = true;
14         
15         function SnapShotDialog($config,$dn,$parent)
16         {
17                 plugin::plugin($config,$dn);
18                 $this->parent = $parent;
19         }
20         
21         
22         /* Display snapshot dialog */
23         function execute()
24         {
25                 plugin::execute();
26                 $smarty = get_smarty();
28                 /* We must restore a snapshot */
29                 if($this->display_restore_dialog){
31                         /* Should we only display all snapshots of already deleted objects 
32                 or the snapshots for the given object dn */
33                         $res = array();
34                         if($this->display_all_removed_objects){
35                                 if(is_array($this->dn)){
36                                         $tmp = array();
37                                         foreach($this->dn as $dn){
38                                                 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
39                                         }
40                                 }else{
41                                         $tmp = $this->getAllDeletedSnapshots($this->dn,true);
42                                 }
43                         }else{
44                                 $tmp = $this->Available_SnapsShots($this->dn,true);
45                         }
46                 
47                         /* Walk through all entries and setup the display text */
48                         foreach($tmp as $key => $entry){
49                         
50                                 $data = $entry['description'][0];
51                                 $date = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
52                                 if($this->display_all_removed_objects){
53                                         $data.= " - ".$entry['gosaSnapshotDN'][0];
54                                 }
55         
56                                 if(strlen($data) > 83){
57                                         $data= substr($data,0,80)." ...";
58                                 }
59         
60                                 $res[base64_encode($entry['dn'])] = $date." - ".$data;
61                         }
62                         natcasesort($res);
63                         $smarty->assign("SnapShots",array_reverse($res));
64                         $smarty->assign("CountSnapShots",count($res));
65                 }
67                 $smarty->assign("RestoreMode",$this->display_restore_dialog);
68                 $smarty->assign("CurrentDate",date("d.m.Y H:i"));
69                 $smarty->assign("CurrentDN",$this->dn);
70                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
71                 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
72         }
75         function check()
76         {
77                 $message = plugin::check();
78                 if(!$this->display_restore_dialog){
79                         if(empty($this->CurrentDescription)){
80                                 $message[]  = _("Please specify a valid description for this snapshot.");
81                         }
82                 }
83                 return($message);
84         }
87         function save_object()
88         {       
89                 plugin::save_object();
90                 foreach($this->attributes as $name){
91                         if(isset($_POST[$name])){
92                                 $this->$name = stripslashes($_POST[$name]);
93                         }
94                 }
95         }
96 }
98 ?>