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 */
12 var $dialog = true;
14 function SnapShotDialog($config,$dn,$parent)
15 {
16 plugin::plugin($config,$dn);
17 $this->parent = $parent;
18 }
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->display_restore_dialog){
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->display_all_removed_objects){
34 if(is_array($this->dn)){
35 $tmp = array();
36 foreach($this->dn as $dn){
37 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
38 }
39 }else{
40 $tmp = $this->getAllDeletedSnapshots($this->dn,true);
41 }
42 }else{
43 $tmp = $this->Available_SnapsShots($this->dn,true);
44 }
46 /* Walk through all entries and setup the display text */
47 foreach($tmp as $key => $entry){
49 $data = $entry['description'][0];
50 $date = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
51 if($this->display_all_removed_objects){
52 $data.= " - ".$entry['gosaSnapshotDN'][0];
53 }
55 if(strlen($data) > 83){
56 $data= substr($data,0,80)." ...";
57 }
59 $res[base64_encode($entry['dn'])] = $date." - ".$data;
60 }
61 natcasesort($res);
62 $smarty->assign("SnapShots",array_reverse($res));
63 $smarty->assign("CountSnapShots",count($res));
64 }
66 $smarty->assign("RestoreMode",$this->display_restore_dialog);
67 $smarty->assign("CurrentDate",date("d.m.Y H:i"));
68 $smarty->assign("CurrentDN",$this->dn);
69 $smarty->assign("CurrentDescription",$this->CurrentDescription);
70 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
71 }
74 function check()
75 {
76 $message = plugin::check();
77 if(!$this->display_restore_dialog){
78 if(empty($this->CurrentDescription)){
79 $message[] = _("Please specify a valid description for this snapshot.");
80 }
81 }
82 return($message);
83 }
86 function save_object()
87 {
88 plugin::save_object();
89 foreach($this->attributes as $name){
90 if(isset($_POST[$name])){
91 $this->$name = stripslashes($_POST[$name]);
92 }
93 }
94 }
95 }
97 ?>