Code

Save scroll position
[gosa.git] / gosa-core / include / class_management.inc
index 59a848199df94fa10ceb6e41104d456971470205..98f02cee2fa00e1f020fc4958dc88d4833b15697 100644 (file)
@@ -3,7 +3,7 @@
  * This code is part of GOsa (http://www.gosa-project.org)
  * Copyright (C) 2003-2008 GONICUS GmbH
  *
- * ID: $$Id: class_plugin.inc 14584 2009-10-12 14:04:22Z hickert $$
+ * ID: $$Id$$
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -58,7 +58,13 @@ class management
   protected $last_dialogObject = null;
 
   // Whether to display the apply button or not
-  protected $displayApplyBtn = "";
+  protected $displayApplyBtn = FALSE;
+
+  // Whether to display a header or not.
+  protected $skipHeader = false;
+
+  // Whether to display a footer or not.
+  protected $skipFooter = false;
 
   // Copy&Paste handler
   protected $cpHandler = null;
@@ -76,7 +82,10 @@ class management
   // A list of configured actions/events
   protected $actions = array();
 
-  function  __construct($config,$ui,$plugname, $headpage)
+  // Attributes managed by this plugin, can be used in post events;
+  protected $attributes = array(); 
+
+  function  __construct(&$config,$ui,$plugname, $headpage)
   {
     $this->plugname = $plugname;
     $this->headpage = $headpage;
@@ -197,6 +206,8 @@ class management
    */
   protected function getHeader()
   {
+    if($this->skipHeader) return("");
+
     if (get_object_info() != ""){
       $display= print_header(get_template_path($this->plIcon),_($this->plDescription),
           "<img alt=\"\" class=\"center\" src=\"".get_template_path('images/lists/locked.png')."\">".
@@ -226,6 +237,9 @@ class management
       }
     }
 
+    // Skip footer if requested;
+    if($this->skipFooter) return("");
+
     // In case an of locked entry, we may have opened a read-only tab.
     $str = "";
     if(isset($this->tabObject->read_only) && $this->tabObject->read_only == TRUE){
@@ -327,10 +341,10 @@ class management
 
         // Delete the object
         $this->dn = $dn;
-        $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
+        $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory, true, true);
         $this->tabObject->set_acl_base($this->dn);
-        $this->tabObject->delete ();
         $this->tabObject->parent = &$this;
+        $this->tabObject->delete ();
 
         // Remove the lock for the current object.
         del_lock($this->dn);        
@@ -657,8 +671,8 @@ class management
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dns,"Edit entry initiated!");
 
         // Now lock entries.
-        $tmp->lock_entries($this->ui->dn);
         if($tmp->multiple_available()){
+          $tmp->lock_entries($this->ui->dn);
           $this->tabObject = $tmp;
           set_object_info($this->tabObject->get_object_info());
         }
@@ -737,6 +751,7 @@ class management
     $this->dns = array();
     $this->tabObject = null;
     $this->dialogObject = null;
+    $this->skipFooter = FALSE;
     set_object_info();
   }
 
@@ -844,6 +859,59 @@ class management
     $this->filter = $str;
   }
 
+
+  function postcreate() {
+    $this->_handlePostEvent('POSTCREATE');
+  }
+  function postmodify(){
+    $this->_handlePostEvent('POSTMODIFY');
+  }
+  function postremove(){
+    $this->_handlePostEvent('POSTREMOVE');
+  }
+
+  function _handlePostEvent($type)
+  {
+
+    /* Find postcreate entries for this class */
+    $command= $this->config->search(get_class($this), $type,array('menu', 'tabs'));
+    if ($command != ""){
+
+      /* Walk through attribute list */
+      foreach ($this->attributes as $attr){
+        if (!is_array($this->$attr)){
+          $add_attrs[$attr] = $this->$attr;
+        }
+      }
+      $add_attrs['dn']=$this->dn;
+
+      $tmp = array();
+      foreach($add_attrs as $name => $value){
+        $tmp[$name] =  strlen($name);
+      }
+      arsort($tmp);
+
+      /* Additional attributes */
+      foreach ($tmp as $name => $len){
+        $value = $add_attrs[$name];
+        $command= str_replace("%$name", "$value", $command);
+      }
+
+      if (check_command($command)){
+        @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+            $command, "Execute");
+        exec($command,$arr);
+        foreach($arr as $str){
+          @DEBUG (DEBUG_SHELL, __LINE__, __FUNCTION__, __FILE__,
+              $command, "Result: ".$str);
+        }
+      } else {
+        $message= msgPool::cmdnotfound($type, get_class($this));
+        msg_dialog::display(_("Error"), $message, ERROR_DIALOG);
+      }
+    }
+
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: