From 365b69553ef4d084fd7bc6bd4fd8aada5918c0ec Mon Sep 17 00:00:00 2001 From: hickert Date: Mon, 26 Jun 2006 09:24:25 +0000 Subject: [PATCH] Added a divlist that allows us to delete existing snap shots This is an initial commit, there possibly follow some fixes git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3897 594d385d-05f5-0310-b6e9-bd551577e9d8 --- ihtml/themes/default/snapshotdialog.tpl | 9 +-- include/class_MultiSelectWindow.inc | 4 +- include/class_SnapShotDialog.inc | 89 ++++++++++++++++++++----- include/class_plugin.inc | 62 ++++++++--------- 4 files changed, 105 insertions(+), 59 deletions(-) diff --git a/ihtml/themes/default/snapshotdialog.tpl b/ihtml/themes/default/snapshotdialog.tpl index c71b07041..677bc17ec 100755 --- a/ihtml/themes/default/snapshotdialog.tpl +++ b/ihtml/themes/default/snapshotdialog.tpl @@ -30,14 +30,7 @@ - + {$SnapShotDivlist} diff --git a/include/class_MultiSelectWindow.inc b/include/class_MultiSelectWindow.inc index 8481095f0..59aa9eb22 100644 --- a/include/class_MultiSelectWindow.inc +++ b/include/class_MultiSelectWindow.inc @@ -491,11 +491,11 @@ class MultiSelectWindow{ if($this->parent->snapshotEnabled()){ $str .=" "; + alt='"._("Create snapshot")."' name='CreateSnapShotDialog_".base64_encode($dn)."' title='"._("Create a new snapshot from this object")."'> "; if(count($this->parent->Available_SnapsShots($dn))){ $str .=" "; + alt='"._("Restore snapshot")."' name='RestoreSnapShotDialog_".base64_encode($dn)."' title='"._("Restore snapshot")."'> "; }else{ $str.= " "; } diff --git a/include/class_SnapShotDialog.inc b/include/class_SnapShotDialog.inc index 9e42c81a6..9391c1370 100755 --- a/include/class_SnapShotDialog.inc +++ b/include/class_SnapShotDialog.inc @@ -11,11 +11,15 @@ class SnapShotDialog extends plugin var $display_all_removed_objects= false; /* Specifies which objects will be listed, all snapshots for a single entry or all snapshots of already deleted objects */ var $dialog = true; + var $del_dn = ""; + var $ui; + var $acl; function SnapShotDialog($config,$dn,$parent) { plugin::plugin($config,$dn); - $this->parent = $parent; + $this->parent = $parent; + $this->ui = get_userinfo(); } @@ -24,6 +28,41 @@ class SnapShotDialog extends plugin { plugin::execute(); $smarty = get_smarty(); + + $once = true; + foreach($_POST as $name => $value){ + if((preg_match("/^RemoveSnapShot_/",$name)) && ($once)){ + $once = false; + + $entry = preg_replace("/^RemoveSnapShot_/","",$name); + $entry = base64_decode(preg_replace("/_[xy]$/","",$entry)); + + $acl = get_permissions ($entry, $this->ui->subtreeACL); + $this->acl = get_module_permission($acl, "snapshot", $entry ); + + if (chkacl($this->acl, "delete") == ""){ + $this->del_dn = $entry; + $smarty= get_smarty(); + $smarty->assign("intro", sprintf(_("You're about to delete the snapshot '%s'."), @LDAP::fix($this->del_dn))); + return($smarty->fetch (get_template_path('remove.tpl'))); + } else { + + /* Obviously the user isn't allowed to delete. Show message and + clean session. */ + print_red (_("You are not allowed to delete this snap shot!")); + } + } + } + + /* Remove snapshot */ + if(isset($_POST['delete_confirm']) && !empty($this->del_dn)){ + $acl = get_permissions ($this->del_dn, $this->ui->subtreeACL); + $this->acl = get_module_permission($acl, "snapshot", $this->del_dn); + if (chkacl($this->acl, "delete") == ""){ + $this->remove_snapshot($this->del_dn); + $this->del_dn = ""; + } + } /* We must restore a snapshot */ if($this->display_restore_dialog){ @@ -43,25 +82,43 @@ class SnapShotDialog extends plugin }else{ $tmp = $this->Available_SnapsShots($this->dn,true); } - + + $DivListSnapShots = new DivSelectBox("SnapShotRestore"); + $DivListSnapShots->SetHeight(180); + + $list_of_elements = array(); + /* Walk through all entries and setup the display text */ foreach($tmp as $key => $entry){ - - $data = $entry['description'][0]; - $date = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0])); - if($this->display_all_removed_objects){ - $data.= " - ".$entry['gosaSnapshotDN'][0]; - } + $TimeStamp = $entry['gosaSnapshotTimestamp'][0]; + $list_of_elements[$TimeStamp] = $entry; + } + + /* Sort generated list */ + krsort($list_of_elements); - if(strlen($data) > 83){ - $data= substr($data,0,80)." ..."; + /* Add Elements to divlist */ + foreach($list_of_elements as $entry){ + + $actions = " "; + $actions.= " "; + + $time_stamp = date("d.m.Y H.i.s",preg_replace("/\-.*$/","",$entry['gosaSnapshotTimestamp'][0])); + $display_data = $entry['description'][0]; + + if($this->display_all_removed_objects){ + $display_data.= " - ".$entry['gosaSnapshotDN'][0]; } - - $res[base64_encode($entry['dn'])] = $date." - ".$data; - } - natcasesort($res); - $smarty->assign("SnapShots",array_reverse($res)); - $smarty->assign("CountSnapShots",count($res)); + + $field0 = array("string"=> $time_stamp , "attach"=> "style='vertical-align:top;width:120px;'"); + $field1 = array("string"=> $display_data , "attach"=> ""); + $field2 = array("string"=> preg_replace("/%KEY/",base64_encode($entry['dn']),$actions) , + "attach"=> "style='border-right:0px;vertical-align:top;width:40px;text-align:right;'"); + $DivListSnapShots->AddEntry(array($field0,$field1,$field2)); + } + + $smarty->assign("SnapShotDivlist",$DivListSnapShots->DrawList()); + $smarty->assign("CountSnapShots",count($list_of_elements)); } $smarty->assign("RestoreMode",$this->display_restore_dialog); diff --git a/include/class_plugin.inc b/include/class_plugin.inc index 323fbeddf..c56cfae68 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -996,12 +996,6 @@ class plugin /* Get configuration from gosa.conf */ $tmp = $this->config->current; - /* Check if the undo level is specified */ - if(isset($tmp['SNAPSHOT_UNDO_LEVEL'])){ - $UndoLvl = $tmp['SNAPSHOT_UNDO_LEVEL']; - }else{ - $UndoLvl = 5; - } /* Create lokal ldap connection */ $ldap= $this->config->get_ldap_link(); @@ -1025,7 +1019,6 @@ class plugin show_ldap_error($ldap_to->get_error(), _("Snapshot failed.")); } - /* check if the dn exists */ if ($ldap->dn_exists($this->dn)){ @@ -1071,23 +1064,21 @@ class plugin show_ldap_error($ldap_to->get_error(), _("Create snapshot failed.")); show_ldap_error($ldap->get_error(), _("Create snapshot failed.")); + } + } - /* Check amount of used snapshots, and remove old ones if necessary */ - $test = $this->Available_SnapsShots($this->dn,true); - if(count($test) > $UndoLvl){ - $toDel = array(); - foreach($test as $entry){ - $toDel[preg_replace("/-/","",$entry['gosaSnapshotTimestamp'][0])] = $entry['dn']; - } - krsort($toDel); - $i = 0 ; - foreach($toDel as $entryID => $entry){ - $i ++ ; - if($i > $UndoLvl){ - $ldap_to->rmdir_recursive($entry); - } - } - } + function remove_snapshot($dn) + { + $ui = get_userinfo(); + $acl = get_permissions ($dn, $ui->subtreeACL); + $acl = get_module_permission($acl, "snapshot", $dn); + + if (chkacl($this->acl, "delete") == ""){ + $ldap = $this->config->get_ldap_link(); + $ldap->cd($this->config->current['BASE']); + $ldap->rmdir_recursive($dn); + }else{ + print_red (_("You are not allowed to delete this snap shot!")); } } @@ -1290,17 +1281,17 @@ class plugin foreach($_POST as $name => $value){ /* Create a new snapshot, display a dialog */ - if(preg_match("/^CreateSnapShot_/",$name) && $once){ + if(preg_match("/^CreateSnapShotDialog_/",$name) && $once){ $once = false; - $entry = preg_replace("/^CreateSnapShot_/","",$name); + $entry = preg_replace("/^CreateSnapShotDialog_/","",$name); $entry = base64_decode(preg_replace("/_[xy]$/","",$entry)); $this->snapDialog = new SnapShotDialog($this->config,$entry,$this); } /* Restore a snapshot, display a dialog with all snapshots of the current object */ - if(preg_match("/^RestoreSnapShot_/",$name) && $once){ + if(preg_match("/^RestoreSnapShotDialog_/",$name) && $once){ $once = false; - $entry = preg_replace("/^RestoreSnapShot_/","",$name); + $entry = preg_replace("/^RestoreSnapShotDialog_/","",$name); $entry = base64_decode(preg_replace("/_[xy]$/","",$entry)); $this->snapDialog = new SnapShotDialog($this->config,$entry,$this); $this->snapDialog->display_restore_dialog = true; @@ -1313,6 +1304,17 @@ class plugin $this->snapDialog->display_restore_dialog = true; $this->snapDialog->display_all_removed_objects = true; } + + /* Restore selected snapshot */ + if(preg_match("/^RestoreSnapShot_/",$name) && $once){ + $once = false; + $entry = preg_replace("/^RestoreSnapShot_/","",$name); + $entry = base64_decode(trim(preg_replace("/_[xy]$/","",$entry))); + if(!empty($entry)){ + $this->restore_snapshot($entry); + $this->snapDialog = NULL; + } + } } /* Create a new snapshot requested, check @@ -1333,12 +1335,6 @@ class plugin /* Restore is requested, restore the object with the posted dn .*/ if((isset($_POST['RestoreSnapshot'])) && (isset($_POST['SnapShot']))){ - $entry =trim($_POST['SnapShot']); - if(!empty($entry)){ - $entry = base64_decode($entry); - $this->restore_snapshot($entry); - $this->snapDialog = NULL; - } } if(isset($_POST['CancelSnapshot'])){ -- 2.30.2