Code

Centered actions icons
[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         var $del_dn                                             = "";
15         var $ui;
16         var $acl;
17         
18         function SnapShotDialog($config,$dn,$parent)
19         {
20                 plugin::plugin($config,$dn);
21                 $this->parent   = $parent;
22                 $this->ui               = get_userinfo();
23         }
24         
25         
26         /* Display snapshot dialog */
27         function execute()
28         {
29                 plugin::execute();
30                 $smarty = get_smarty();
31         
32                 $once = true;
33                 foreach($_POST as $name => $value){
34                         if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
35                                 $once = false;
36         
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();                    
90                         
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);
99         
100                         /* Add Elements to divlist */   
101                         foreach($list_of_elements as $entry){
103                                 $actions = "<input type='image' src='images/edittrash.png' name='RemoveSnapShot_%KEY' 
104                                                                 class='center' title='"._("Remove snapshot")."'>&nbsp;";
105                                 $actions.= "<input type='image' src='images/restore.png' name='RestoreSnapShot_%KEY' 
106                                                                 class='center' title='"._("Restore snapshot")."'>&nbsp;";
108                                 $time_stamp     = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
109                                 $display_data   = $entry['description'][0];
111                                 if($this->display_all_removed_objects){
112                                         $display_data.= " - ".$entry['gosaSnapshotDN'][0];
113                                 }
115                                 $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'");
116                                 $field1 = array("string"=> htmlentities (utf8_decode($display_data)), "attach"=> "");
117                                 $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) , 
118                                                                 "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'");
119                                 $DivListSnapShots->AddEntry(array($field0,$field1,$field2));
120                         }               
122                         $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList());       
123                         $smarty->assign("CountSnapShots",count($list_of_elements));
124                 }
126                 $smarty->assign("RestoreMode",$this->display_restore_dialog);
127                 $smarty->assign("CurrentDate",date("d.m.Y H:i"));
128                 $smarty->assign("CurrentDN",$this->dn);
129                 $smarty->assign("CurrentDescription",$this->CurrentDescription);
130                 return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
131         }
134         function check()
135         {
136                 $message = plugin::check();
137                 if(!$this->display_restore_dialog){
138                         if(empty($this->CurrentDescription)){
139                                 $message[]  = _("Please specify a valid description for this snapshot.");
140                         }
141                 }
142                 return($message);
143         }
146         function save_object()
147         {       
148                 plugin::save_object();
149                 foreach($this->attributes as $name){
150                         if(isset($_POST[$name])){
151                                 $this->$name = stripslashes($_POST[$name]);
152                         }
153                 }
154         }
157 ?>