Code

Updated strings
[gosa.git] / gosa-core / include / class_SnapShotDialog.inc
1 <?php
2 /*
3  * This code is part of GOsa (http://www.gosa-project.org)
4  * Copyright (C) 2003-2008 GONICUS GmbH
5  *
6  * ID: $$Id$$
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
23 /* Snap shot dialog class */
24 class SnapShotDialog extends plugin 
25 {
26     var $config;
27     var $attributes= array("CurrentDescription");
28     var $CurrentDescription= "";
29     var $parent= NULL;
30     var $display_restore_dialog= false;               /* Defines the restore mode */
31     var $display_all_removed_objects= false;            /* Specifies which objects will be listed, all
32                                                        snapshots for a single entry or all snapshots
33                                                        of already deleted objects  */   
34     var $dialog= true;
35     var $del_dn= "";
36     var $ui;
37     var $acl;
38     var $dns = array();
39     var $snap_shot_bases = array();
40     var $last_list = array();
43     function SnapShotDialog(&$config, $dn, &$parent)
44     {
45         plugin::plugin($config,$dn);
46         $this->parent   = &$parent;
47         $this->ui                 = get_userinfo();
49         // Prepare lists
50         $this->snapList = new sortableListing();
51         $this->snapList->setDeleteable(false);
52         $this->snapList->setEditable(false);
53         $this->snapList->setWidth("100%");
54         $this->snapList->setHeight("200px");
55         $this->snapList->setHeader(array(_("Date"), _("Name") ));
56         $this->snapList->setColspecs(array('140px','*','60px'));
57         $this->snapList->setDefaultSortColumn(0);
59     }
62     /* Show deleted snapshots from these bases */
63     function set_snapshot_bases($bases)
64     {
65         $this->snap_shot_bases = $bases;
66     }
69     /* Display snapshot dialog */
70     function execute()
71     {
72         plugin::execute();
73         $smarty = get_smarty();
75         $ui = get_userinfo();
76         $once = true;
77         foreach($_POST as $name => $value){
78             if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){
79                 $once = false;
80                 $entry = preg_replace("/^RemoveSnapShot_/","",$name);
81                 $entry = base64_decode($entry);
82                 $found = false;
83                 foreach($this->last_list as $t_stamp => $obj){
84                     if($obj['dn'] == $entry){
85                         $found = true;
86                         break;
87                     }
88                 }
90                 if($found){
91                     $this->del_dn       = $entry;
92                     $smarty= get_smarty();
93                     $smarty->assign("info", sprintf(_("You are about to delete the snapshot '%s'."), LDAP::fix($this->del_dn)));
94                     return($smarty->fetch (get_template_path('removeEntries.tpl')));
95                 }
96             }
97         }
99         /* Remove snapshot */
100         if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){
101             $this->remove_snapshot($this->del_dn);
102             $this->del_dn = "";
103         }
105         /* We must restore a snapshot */
107         if($this->display_restore_dialog){
109             /* Should we only display all snapshots of already deleted objects 
110                or the snapshots for the given object dn */
111             $res = array();
112             $tmp = array();
113             if($this->display_all_removed_objects){
114                 if(count($this->snap_shot_bases)){
115                     foreach($this->snap_shot_bases as $dn){
116                         $tmp = array_merge($tmp,$this->getAllDeletedSnapshots($dn,true));
117                     }
118                 }else{
119                     $tmp = $this->getAllDeletedSnapshots($this->snap_shot_bases,true);
120                 }
121             }else{
122                 $tmp = $this->Available_SnapsShots($this->dn,true);
123             }
125             $this->snapList->setAcl('rwcdm');
127             $list_of_elements = array();                        
129             /* Walk through all entries and setup the display text */
130             foreach($tmp as $key => $entry){
132                 /* Check permissions */
133                 $TimeStamp = $entry['gosaSnapshotTimestamp'][0];
134                 $list_of_elements[$TimeStamp] = $entry;
135             }
137             /* Sort generated list */
138             krsort($list_of_elements);
140             /* Add Elements to list */  
141             $this->last_list = $list_of_elements;
143             $data = $lData = array();
144             foreach($list_of_elements as $entry){
145                 $actions=  image('images/lists/restore.png','RestoreSnapShot_%KEY',_("Restore snapshot"));
146                 $actions.= image('images/lists/trash.png','RemoveSnapShot_%KEY',_("Delete snapshot"));
147                 $time_stamp     = date(_("Y-m-d, H:i:s"),preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0]));
148                 $display_data   = $entry['description'][0];
149                 $data[$entry['dn']] = $entry;
150                 $lData[$entry['dn']] = array('data'=>
151                         array(
152                             $time_stamp,
153                             htmlentities(utf8_decode(LDAP::fix($display_data))),
154                             str_replace("%KEY",base64_encode($entry['dn']), $actions)));
155             }           
157             $this->snapList->setListData($data, $lData);
158             $this->snapList->update();
159             $smarty->assign("SnapShotList",$this->snapList->render());
160             $smarty->assign("CountSnapShots",count($list_of_elements));
161         }
163         $smarty->assign("restore_deleted",$this->display_all_removed_objects);
164         $smarty->assign("RestoreMode",$this->display_restore_dialog);
165         $smarty->assign("CurrentDate",date(_("Y-m-d, H:i:s")));
166         $smarty->assign("CurrentDN",LDAP::fix($this->dn));
167         $smarty->assign("CurrentDescription",$this->CurrentDescription);
168         return($smarty->fetch(get_template_path("snapshotdialog.tpl")));
169     }
172     function check()
173     {
174         $message = plugin::check();
175         if(!$this->display_restore_dialog){
176             if(empty($this->CurrentDescription)){
177                 $message[]= msgPool::invalid(_("Description"));
178             }
179         }
180         return($message);
181     }
184     function save_object()
185     {   
186         plugin::save_object();
187         foreach($this->attributes as $name){
188             if(isset($_POST[$name])){
189                 $this->$name = stripslashes($_POST[$name]);
190             }
191         }
192     }
195 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
196 ?>