Code

Sudo update
[gosa.git] / gosa-plugins / sudo / admin / sudo / class_sudoManagement.inc
index 89e4e38d6cc5c91cd4ffa07fdf6a35d16e83332e..47fd657a70b349c030866375670d5c6183d0d860 100644 (file)
@@ -35,8 +35,7 @@ class sudoManagement extends plugin
   private $sudotabs       = NULL;
   private $base           = "";
  
-
-   
+  /*! \brief */ 
   public function __construct(&$config, &$ui)
   {
     /* Save configuration for internal use */
@@ -49,6 +48,8 @@ class sudoManagement extends plugin
   }
 
 
+  /*! \brief Generate && Display HTML content 
+   */
   public function execute()
   {
     /* Call parent execute */
@@ -138,7 +139,6 @@ class sudoManagement extends plugin
           if ($this->dn != "new"){
             del_lock ($this->dn);
           }
-
           unset ($this->sudotabs);
           $this->sudotabs= NULL;
           session::un_set('objectinfo');
@@ -184,28 +184,30 @@ class sudoManagement extends plugin
      ********************/
 
     if ($s_action=="del_role"){
-
       $ids = $this->list_get_selected_items();
-
       if(!count($ids) && $s_entry!=""){
         $ids = array($s_entry);
       }
 
       if(count($ids)){
+
+        /* Create list of entries to delete */
         $this->dns = array();
+        $dns_names = array();
         foreach($ids as $id){
           $dn = $this->list[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
-          }
           $this->dns[$id] = $dn;
-        }
-
-        $dns_names = array();
-        foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
           $dns_names[] =@LDAP::fix($dn);
         }
+      
+        /* Check locking of entries */
+        $users = get_multiple_locks($this->dns);
+        if(count($users)){
+          return(gen_locked_message($users,$this->dns));
+        }
+    
+        /* Add locks */
+        add_lock($this->dns,$this->ui->dn);
 
         /* Lock the current entry, so nobody will edit it during deletion */
         $smarty->assign("info", msgPool::deleteInfo($dns_names,_("Sudo role")));
@@ -256,10 +258,8 @@ class sudoManagement extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_sudo_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+      del_lock ($this->dns);
+      unset($this->dns);
     }
 
     /********************
@@ -267,7 +267,7 @@ class sudoManagement extends plugin
      ********************/
 
     /* Cancel dialogs */
-    if (isset($_POST['edit_cancel'])){
+    if (isset($_POST['edit_cancel']) && is_object($this->sudotabs)){
       if(isset($this->sudotabs->dn)){
         del_lock ($this->sudotabs->dn);
       }
@@ -282,7 +282,7 @@ class sudoManagement extends plugin
      ********************/
 
     /* Show tab dialog if object is present */
-    if (isset($this->sudotabs->config)){
+    if (is_object($this->sudotabs)){
       $display= $this->sudotabs->execute();
 
       /* Don't show buttons if tab dialog requests this */
@@ -303,14 +303,16 @@ class sudoManagement extends plugin
     }
 
     /* Display dialog with sudo list */
-    $this->DivListSudo->parent = &$this;
     $this->DivListSudo->execute();
     $this->reload ();
     $this->DivListSudo->setEntries($this->list);
     return($this->DivListSudo->Draw());
   }
 
-
+  
+  /*! \brief  Return all selected elements from HTML list 
+      @return Array List of all selected list elements 
+    */
   private function list_get_selected_items()
   {
     $ids = array();
@@ -324,6 +326,8 @@ class sudoManagement extends plugin
   }
 
 
+  /*! \brief  Reload the list of sudo roles. 
+   */
   private function reload($CreatePosixsList=false)
   {
     $this->list             = array();
@@ -352,12 +356,16 @@ class sudoManagement extends plugin
   }
 
 
-  /* Save data to object */
+  /*! \brief Save HTML post data to object 
+   */
   public function save_object()
   {
     $this->DivListSudo->save_object();
   }
 
+  
+  /*! \brief Remove this account 
+   */
   public function remove_from_parent()
   {
     /* Optionally execute a command after we're done */
@@ -365,12 +373,26 @@ class sudoManagement extends plugin
   }
 
 
-  /* Save to LDAP */
+  /*! \brief Save to LDAP 
+   */
   public function save()
   {
     /* Optionally execute a command after we're done */
     $this->postcreate();
   }
+
+  
+  /*! \brief Remove lock from entry 
+   */
+  public function remove_lock()
+  {
+    if (is_object($this->sudotabs) && $this->sudotabs->dn != "new"){
+      del_lock ($this->sudotabs->dn);
+    }
+    if(isset($this->dns) && is_array($this->dns) && count($this->dns)){
+      del_lock($this->dns);
+    }
+  }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>