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