Code

Added pChart classes and GOsa mapping class to enable auto-include
[gosa.git] / gosa-core / include / class_management.inc
index 4bfc64edf4e8baa31daa129608b4bbd8a1f9fdb0..e4b9c9ac500e193cba50ab45f3ca0b6622eba106 100644 (file)
@@ -92,6 +92,11 @@ class management
     $this->headpage = $headpage;
     $this->ui = $ui;
     $this->config = $config;
+    $this->initTime = microtime(TRUE);
+
+    // Create statistic table entry 
+    stats::log('management', $class = get_class($this), $this->getAclCategories(),  $action = 'open', 
+            $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
 
     if($this->cpHandler) $this->headpage->setCopyPasteHandler($this->cpHandler);
     if($this->snapHandler) $this->headpage->setSnapshotHandler($this->snapHandler);
@@ -118,6 +123,7 @@ class management
     $this->registerAction("restore",     "restoreSnapshotDialog");
     $this->registerAction("saveSnapshot","saveSnapshot");
     $this->registerAction("restoreSnapshot","restoreSnapshot");
+    $this->registerAction("removeSnapshotConfirmed","removeSnapshotConfirmed");
     $this->registerAction("cancelSnapshot","closeDialogs");
 
     $this->registerAction("config-filter","editFilter");
@@ -128,6 +134,17 @@ class management
     #session::global_un_set(get_class($this)."_filter");
   }
 
+  
+  /*! \brief  Returns an array with all ACL-Categories we are responsible for.
+   */
+  function getAclCategories()
+  {
+      $ret= $this->aclCategory;
+      if(!is_array($ret)) $ret = array($ret);
+      return($ret);
+  }    
+
+
   /*! \brief  Execute this plugin
    *          Handle actions/events, locking, snapshots, dialogs, tabs,...
    */
@@ -186,7 +203,11 @@ class management
 
       $this->snapHandler->setSnapshotBases($bases);
     }
-  
+    // Create statistic table entry 
+    stats::log('management', $class = get_class($this), $this->getAclCategories(),  $action = 'view',
+            $amount = 1, $duration = (microtime(TRUE) - $this->initTime));
     // Display list
     return($this->renderList());
   }
@@ -406,6 +427,7 @@ class management
     if(isset($_POST['edit_finish'])) $action['action'] = "save";    
     if(isset($_POST['edit_cancel'])) $action['action'] = "cancel";    
     if(isset($_POST['delete_confirmed'])) $action['action'] = "removeConfirmed";   
+    if(isset($_POST['delete_snapshot_confirm'])) $action['action'] = "removeSnapshotConfirmed";   
     if(isset($_POST['delete_cancel'])) $action['action'] = "cancelDelete";   
     if(isset($_POST['saveFilter'])) $action['action'] = "saveFilter";   
     if(isset($_POST['cancelFilter'])) $action['action'] = "cancelFilter";   
@@ -435,6 +457,11 @@ class management
     if(isset($this->actions[$action['action']])){
       $func = $this->actions[$action['action']];
       if(!isset($action['targets']))$action['targets']= array(); 
+
+      // Create statistic table entry 
+      stats::log('management', $class = get_class($this), $this->getAclCategories(),  $action['action'],
+              $amount = count($action['targets']), $duration = (microtime(TRUE) - $this->initTime));
+
       return($this->$func($action['action'],$action['targets'],$action));
     }
   } 
@@ -510,6 +537,21 @@ class management
   }
 
 
+  /*! \brief  Removes a snapshot object.
+   */
+  function removeSnapshotConfirmed($action="",$target=array(),$all=array())
+  {
+    $entry = $this->dialogObject->del_dn;
+    if(!empty($entry) && $this->ui->allow_snapshot_create($entry,$this->aclCategory)){
+      $this->snapHandler->remove_snapshot($entry);
+      @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$entry,"Snaptshot removed!");
+    }else{
+      msg_dialog::display(_("Permission"),sprintf(_("You are not allowed to remove a snapshot for %s!"), bold($entry)),
+          ERROR_DIALOG);
+    }
+  }
+
+
   /*! \brief  Displays the "Restore snapshot dialog" for a given target. 
    *          If no target is specified, open the restore removed object 
    *           dialog.
@@ -608,11 +650,21 @@ class management
     if(empty($tabClass) || empty($tabType)){
       // No tab type defined
     }else{
-      if (isset($this->config->data['TABS'][$tabType])) {
-        $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
-        $this->tabObject->set_acl_base($this->headpage->getBase());
-        $this->tabObject->parent = &$this;
-        @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
+
+        if (isset($this->config->data['TABS'][$tabType])) {
+
+            // Check if the base plugin is available - it is mostly responsible for object creation and removal.
+            $first  = $this->config->data['TABS'][$tabType][0];
+            if(!class_available($first['CLASS'])){
+                msg_dialog::display(_("Internal error"),
+                        sprintf(_("Cannot instantiate tabbed-plug-in, the base plugin (%s) is not available!"), $first['CLASS']),
+                        ERROR_DIALOG);
+            }else{
+                $this->tabObject= new $tabClass($this->config,$this->config->data['TABS'][$tabType], $this->dn, $aclCategory);
+                $this->tabObject->set_acl_base($this->headpage->getBase());
+                $this->tabObject->parent = &$this;
+                @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Create new entry initiated!");
+            }
       } else {
         msg_dialog::display(_("Error"), sprintf(_("No tab definition for %s found in configuration file: cannot create plugin instance!"), bold($tabType)), ERROR_DIALOG);
       }
@@ -661,9 +713,10 @@ class management
     if(!empty($altTabType)) $tabType = $altTabType;
     if(!empty($altAclCategory)) $aclCategory = $altAclCategory;
 
+    $this->displayApplyBtn = count($target) == 1;
+
     // Single edit - we only got one object dn.
     if(count($target) == 1){
-      $this->displayApplyBtn = TRUE;
       $this->is_new = FALSE;
       $this->is_single_edit = TRUE;
       $this->is_multiple_edit = FALSE;
@@ -681,11 +734,21 @@ class management
       if(empty($tabClass) || empty($tabType)){
         trigger_error("We can't edit any object(s). 'tabClass' or 'tabType' is empty!");
       }else{
+
         $tab = $tabClass;
-        $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
-        @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
-        $this->tabObject->set_acl_base($this->dn);
-        $this->tabObject->parent = &$this;
+        
+        // Check if the base plugin is available - it is mostly responsible for object creation and removal.
+        $first  = $this->config->data['TABS'][$tabType][0];
+        if(!class_available($first['CLASS'])){
+            msg_dialog::display(_("Internal error"), 
+                    sprintf(_("Cannot instantiate tabbed-plug-in, the base plugin (%s) is not available!"), $first['CLASS']), 
+                    ERROR_DIALOG);
+        }else{
+            $this->tabObject= new $tab($this->config,$this->config->data['TABS'][$tabType], $this->dn,$aclCategory);
+            @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$this->dn,"Edit entry initiated!");
+            $this->tabObject->set_acl_base($this->dn);
+            $this->tabObject->parent = &$this;
+        }
       }
     }else{
 
@@ -933,55 +996,13 @@ class management
 
 
   function postcreate() {
-    $this->_handlePostEvent('POSTCREATE');
+    $this->handle_post_events('add');
   }
   function postmodify(){
-    $this->_handlePostEvent('POSTMODIFY');
+    $this->handle_post_events('modify');
   }
   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);
-      }
-    }
+    $this->handle_post_events('remove');
   }
 
   function is_modal_dialog()