7f5a06f376b8c4d0c15875d2935c8915eb9ab75b
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 var $del_dn = "";
15 var $ui;
16 var $acl;
18 function SnapShotDialog($config,$dn,$parent)
19 {
20 plugin::plugin($config,$dn);
21 $this->parent = $parent;
22 $this->ui = get_userinfo();
23 }
26 /* Display snapshot dialog */
27 function execute()
28 {
29 plugin::execute();
30 $smarty = get_smarty();
32 $once = true;
33 foreach($_POST as $name => $value){
34 if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
35 $once = false;
37 $entry = preg_replace("/^RemoveSnapShot_/","",$name);
38 $entry = base64_decode(preg_replace("/_[xy]$/","",$entry));
40 $acl = get_permissions ($entry, $this->ui->subtreeACL);
41 $this->acl = get_module_permission($acl, "snapshot", $entry );
43 if (chkacl($this->acl, "delete") == ""){
44 $this->del_dn = $entry;
45 $smarty= get_smarty();
46 $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), @LDAP::fix($this->del_dn)));
47 return($smarty->fetch (get_template_path('remove.tpl')));
48 } else {
50 /* Obviously the user isn't allowed to delete. Show message and
51 clean session. */
52 print_red (_("You are not allowed to delete this snap shot!"));
53 }
54 }
55 }
57 /* Remove snapshot */
58 if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
59 $acl = get_permissions ($this->del_dn, $this->ui->subtreeACL);
60 $this->acl = get_module_permission($acl, "snapshot", $this->del_dn);
61 if (chkacl($this->acl, "delete") == ""){
62 $this->remove_snapshot($this->del_dn);
63 $this->del_dn = "";
64 }
65 }
67 /* We must restore a snapshot */
68 if($this->display_restore_dialog){
70 /* Should we only display all snapshots of already deleted objects
71 or the snapshots for the given object dn */
72 $res = array();
73 if($this->display_all_removed_objects){
74 if(is_array($this->dn)){
75 $tmp = array();
76 foreach($this->dn as $dn){
77 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
78 }
79 }else{
80 $tmp = $this->getAllDeletedSnapshots($this->dn,true);
81 }
82 }else{
83 $tmp = $this->Available_SnapsShots($this->dn,true);
84 }
86 $DivListSnapShots = new DivSelectBox("SnapShotRestore");
87 $DivListSnapShots->SetHeight(180);
89 $list_of_elements = array();
91 /* Walk through all entries and setup the display text */
92 foreach($tmp as $key => $entry){
93 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
94 $list_of_elements[$TimeStamp] = $entry;
95 }
97 /* Sort generated list */
98 krsort($list_of_elements);
100 /* Add Elements to divlist */
101 foreach($list_of_elements as $entry){
103 $actions = "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY' title='"._("Remove snapshot")."'> ";
104 $actions.= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY' title='"._("Restore snapshot")."'> ";
106 $time_stamp = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
107 $display_data = $entry['description'][0];
109 if($this->display_all_removed_objects){
110 $display_data.= " - ".$entry['gosaSnapshotDN'][0];
111 }
113 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
114 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
115 $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) ,
116 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
117 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
118 }
120 $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());
121 $smarty->assign("CountSnapShots",count($list_of_elements));
122 }
124 $smarty->assign("RestoreMode",$this->display_restore_dialog);
125 $smarty->assign("CurrentDate",date("d.m.Y H:i"));
126 $smarty->assign("CurrentDN",$this->dn);
127 $smarty->assign("CurrentDescription",$this->CurrentDescription);
128 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
129 }
132 function check()
133 {
134 $message = plugin::check();
135 if(!$this->display_restore_dialog){
136 if(empty($this->CurrentDescription)){
137 $message[] = _("Please specify a valid description for this snapshot.");
138 }
139 }
140 return($message);
141 }
144 function save_object()
145 {
146 plugin::save_object();
147 foreach($this->attributes as $name){
148 if(isset($_POST[$name])){
149 $this->$name = stripslashes($_POST[$name]);
150 }
151 }
152 }
153 }
155 ?>