Code

Added missing class variable var $dns.
[gosa.git] / gosa-plugins / gofon / gofon / macro / class_gofonMacroManagement.inc
index ebeb181318ee7332b2e1b7860bac4dff63023667..785afd18d2edb0a8f6e4109a4382c01bb6b11f6e 100644 (file)
@@ -33,6 +33,8 @@ class goFonMacro extends plugin
   var $CopyPasteHandler = NULL;
   var $start_pasting_copied_objects = FALSE;
 
+  var $dns              = array();
+
   function gofonMacro(&$config, $ui)
   {
     /* Save configuration for internal use */
@@ -52,7 +54,7 @@ class goFonMacro extends plugin
     /* Call parent execute */
     plugin::execute();
 
-    session::set('LOCK_VARS_TO_USE',array("/^goFonMacro_/","/^act$/","/^id$/","/^item_selected/","/^remove_multiple_macros/"));
+    session::set('LOCK_VARS_TO_USE',array("/^menu_action/","/^goFonMacro_/","/^act$/","/^id$/","/^item_selected/","/^remove_multiple_macros/"));
 
     /*****************
       Variable initialisation
@@ -159,7 +161,7 @@ class goFonMacro extends plugin
 
     /* Cancel dialogs */
     if (isset($_POST['edit_cancel'])){
-      del_lock ($this->macrotabs->dn);
+      $this->remove_lock();
       unset ($this->macrotabs);
       $this->macrotabs= NULL;
       session::un_set('objectinfo');
@@ -190,12 +192,18 @@ class goFonMacro extends plugin
           /* macro has been saved successfully, remove lock from
              LDAP. */
           if ($this->dn != "new"){
-            del_lock ($this->dn);
+            $this->remove_lock();
           }
 
           unset ($this->macrotabs);
           $this->macrotabs= NULL;
           session::un_set('objectinfo');
+        }else{
+
+          /* Reinitialize tab */
+          if($this->macrotabs instanceof tabs){
+            $this->macrotabs->re_init();
+          }
         }
       } else {
         /* Ok. There seem to be errors regarding to the tab data,
@@ -226,6 +234,7 @@ class goFonMacro extends plugin
         /* Lock the current entry, so everyone will get the
            above dialog */
         add_lock ($this->dn, $this->ui->dn);
+
         /* Register macrotabs to trigger edit dialog */
         $this->macrotabs= new macrotabs($this->config,
             $this->config->data['TABS']['MACROTABS'], $this->dn,"gofonmacro");
@@ -244,23 +253,26 @@ class goFonMacro extends plugin
 
       if(count($ids)){
 
+        /* Collect dns */
         foreach($ids as $id){
-          $dn = $this->macros[$id]['dn'];
-          if (($user= get_lock($dn)) != ""){
-            return(gen_locked_message ($user, $dn));
-          }
-          $this->dns[$id] = $dn;
+          $this->dns[$id] = $this->macros[$id]['dn'];
+        }
+
+        /* Check locks */
+        if ($user= get_multiple_locks($this->dns)){
+          return(gen_locked_message($user,$this->dns));
         }
 
-        $dns_names = "<br><pre>";
+        $dns_names = array();
         foreach($this->dns as $dn){
-          add_lock ($dn, $this->ui->dn);
-          $dns_names .= $dn."\n";
+          $dns_names[] = @LDAP::fix($dn);
         }
-        $dns_names .="</pre>";
+
+        /* Add entry locks */
+        add_lock ($this->dns, $this->ui->dn);
 
         /* Lock the current entry, so nobody will edit it during deletion */
-        $smarty->assign("intro",     sprintf(_("You're about to delete the following macro(s) %s"), @LDAP::fix($dns_names)));
+        $smarty->assign("intro", msgPool::deleteInfo($dns_names,("macro")));
         $smarty->assign("multiple", true);
         return($smarty->fetch(get_template_path('remove.tpl', TRUE)));
       }
@@ -287,13 +299,14 @@ class goFonMacro extends plugin
           $this->macrotabs= NULL;
 
         } else {
-          msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
+          msg_dialog::display(_("Permission error"),msgPool::permDelete(), ERROR_DIALOG);
         }
 
-        /* Remove lock file after successfull deletion */
-        del_lock ($dn);
-        unset($this->dns[$key]);
       }
+
+      /* Remove lock file after successfull deletion */
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -303,10 +316,8 @@ class goFonMacro extends plugin
 
     /* Remove lock */
     if(isset($_POST['delete_multiple_macro_cancel'])){
-      foreach($this->dns as $key => $dn){
-        del_lock ($dn);
-        unset($this->dns[$key]);
-      }
+      $this->remove_lock();
+      $this->dns = array();
     }
 
 
@@ -334,14 +345,14 @@ class goFonMacro extends plugin
         /* Lock the current entry, so nobody will edit it during deletion */
         add_lock ($this->dn, $this->ui->dn);
         $smarty= get_smarty();
-        $smarty->assign("intro", sprintf(_("You're about to delete the macro '%s'."), $this->dn));
+        $smarty->assign("intro", msgPool::deleteInfo(@LDAP::fix($this->dn),_("macro")));
         $smarty->assign("multiple", false);
         return($smarty->fetch (get_template_path('remove.tpl', TRUE)));
       } else {
 
         /* Obviously the user isn't allowed to delete. Show message and
            clean session. */
-        msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
       }
     }
 
@@ -365,11 +376,12 @@ class goFonMacro extends plugin
       } else {
         /* Normally this shouldn't be reached, send some extra
            logs to notify the administrator */
-        msg_dialog::display(_("Permission error"), _("You have not permission to delete this entry!"), ERROR_DIALOG);
+        msg_dialog::display(_("Permission error"), msgPool::permDelete(), ERROR_DIALOG);
         new log("security","gofonmacro/".get_class($this),$this->dn,array(),"Tried to trick deletion.");
       }
+
       /* Remove lock file after successfull deletion */
-      del_lock ($this->dn);
+      $this->remove_lock();
     }
 
 
@@ -529,6 +541,9 @@ class goFonMacro extends plugin
   function save_object()
   {
     $this->DivListMacro->save_object();
+    if(is_object($this->CopyPasteHandler)){
+      $this->CopyPasteHandler->save_object();
+    }
   }
 
 
@@ -544,8 +559,15 @@ class goFonMacro extends plugin
     return($ids);
   }
 
+  /*! \brief Remove entry locks if the plugin was aborted. 
+   */
+  function remove_lock()
+  {
+    if($this->dn) del_lock($this->dn);
+    if(is_array($this->dns) && count($this->dns)) del_lock($this->dns);
+  }
 
-  function adapt_from_template($dn)  { }
+  function adapt_from_template($dn, $skip= array())  { }
   function check() { }
 }
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: