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 );
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')));
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 snapshot!"));
53 */
54 }
55 }
57 /* Remove snapshot */
58 if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
59 $this->remove_snapshot($this->del_dn);
60 $this->del_dn = "";
61 }
63 /* We must restore a snapshot */
64 if($this->display_restore_dialog){
66 /* Should we only display all snapshots of already deleted objects
67 or the snapshots for the given object dn */
68 $res = array();
69 if($this->display_all_removed_objects){
70 if(is_array($this->dn)){
71 $tmp = array();
72 foreach($this->dn as $dn){
73 $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
74 }
75 }else{
76 $tmp = $this->getAllDeletedSnapshots($this->dn,true);
77 }
78 }else{
79 $tmp = $this->Available_SnapsShots($this->dn,true);
80 }
82 $DivListSnapShots = new DivSelectBox("SnapShotRestore");
83 $DivListSnapShots->SetHeight(180);
85 $list_of_elements = array();
87 /* Walk through all entries and setup the display text */
88 foreach($tmp as $key => $entry){
89 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
90 $list_of_elements[$TimeStamp] = $entry;
91 }
93 /* Sort generated list */
94 krsort($list_of_elements);
96 /* Add Elements to divlist */
97 foreach($list_of_elements as $entry){
99 $actions= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY'
100 class='center' title='"._("Restore snapshot")."'> ";
101 $actions.= "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY'
102 class='center' title='"._("Remove snapshot")."'> ";
104 $time_stamp = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
105 $display_data = $entry['description'][0];
107 if($this->display_all_removed_objects){
108 $display_data.= " - ".$entry['gosaSnapshotDN'][0];
109 }
111 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
112 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
113 $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) ,
114 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
115 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
116 }
118 $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());
119 $smarty->assign("CountSnapShots",count($list_of_elements));
120 }
122 $smarty->assign("restore_deleted",$this->display_all_removed_objects);
123 $smarty->assign("RestoreMode",$this->display_restore_dialog);
124 $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
125 $smarty->assign("CurrentDN",$this->dn);
126 $smarty->assign("CurrentDescription",$this->CurrentDescription);
127 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
128 }
131 function check()
132 {
133 $message = plugin::check();
134 if(!$this->display_restore_dialog){
135 if(empty($this->CurrentDescription)){
136 $message[] = _("Please specify a valid description for this snapshot.");
137 }
138 }
139 return($message);
140 }
143 function save_object()
144 {
145 plugin::save_object();
146 foreach($this->attributes as $name){
147 if(isset($_POST[$name])){
148 $this->$name = stripslashes($_POST[$name]);
149 }
150 }
151 }
152 }
154 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
155 ?>