Code

Updated
[gosa.git] / plugins / admin / fai / class_faiHook.inc
index 047f5c150d01fbbf406cb24bcea8f2a30bab5242..aaf7f74e0c86d5d6ecf05b3615d3c5532bd5ae85 100644 (file)
@@ -74,14 +74,28 @@ class faiHook extends plugin
         }
         $this->SubObjects[$object['cn'][0]]['FAIscript']   = addslashes($this->readBinary("FAIscript",$object['dn']));
       }
-      ksort($this->SubObjects);
     }
   }
 
+  function getUsedFAItask($cn)
+  {
+    $ret = array();
+    foreach($this->SubObjects as $name => $class){
+      if($class['cn'] == $cn){
+        continue;
+      } 
+      if($class['status'] != "delete"){
+        $ret[$class['FAItask']] = $class['FAItask'];
+      }
+    }
+    return($ret);
+  }
+
   function execute()
   {
        /* Call parent execute */
        plugin::execute();
+
     /* Fill templating stuff */
     $smarty= get_smarty();
     $display= "";
@@ -89,23 +103,31 @@ class faiHook extends plugin
     /* Add new sub object */
     if(isset($_POST['AddSubObject'])){
       $this->dialog= new $this->subClassName($this->config,"new");
+      $this->dialog->parent = &$this;
       $this->is_dialog=true;
     }
-
-    $_SESSION['objectinfo']= $this->dn;
+  
+    if($this->dn != "new"){
+      $_SESSION['objectinfo']= $this->dn;
+    }
     /* Edit selected Sub Object */
     if((isset($_POST['EditSubObject']))&&(isset($_POST['SubObject']))){
-      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$_POST['SubObject']]);
-      $_SESSION['objectinfo'] = $this->SubObjects[$_POST['SubObject']]['dn'];
+      $hook = $_POST['SubObject'][0];
+    
+      $this->dialog= new $this->subClassName($this->config,$this->dn,$this->SubObjects[$hook]);
+      $this->dialog->parent = &$this;
+      $_SESSION['objectinfo'] = $this->SubObjects[$hook]['dn'];
       $this->is_dialog=true;
     }
     
     /* Remove Sub object */
     if((isset($_POST['DelSubObject']))&&(isset($_POST['SubObject']))){
-      if($this->SubObjects[$_POST['SubObject']]['status'] == "edited"){
-        $this->SubObjects[$_POST['SubObject']]['status']= "delete";
-      }else{
-        unset($this->SubObjects[$_POST['SubObject']]);
+      foreach($_POST['SubObject'] as $hook){
+        if($this->SubObjects[$hook]['status'] == "edited"){
+          $this->SubObjects[$hook]['status']= "delete";
+        }else{
+          unset($this->SubObjects[$hook]);
+        }
       }
     }
 
@@ -144,10 +166,20 @@ class faiHook extends plugin
         $this->is_dialog=false;
         unset($this->dialog);
         $this->dialog=NULL;
-        ksort($this->SubObjects);
       }
     }
 
+    /* Sort entries */
+    $tmp = $keys = array();
+    foreach($this->SubObjects as $key => $entry){
+      $keys[$key]=$key;
+    }
+    natcasesort($keys);
+    foreach($keys as $key){
+      $tmp[$key]=$this->SubObjects[$key];
+    }
+    $this->SubObjects = $tmp;
+
     /* Cancel Dialog */
     if(isset($_POST['CancelSubObject'])){
       $this->is_dialog=false; 
@@ -176,7 +208,6 @@ class faiHook extends plugin
       }
     }
 
-
     $display.= $smarty->fetch(get_template_path('faiHook.tpl', TRUE));
     return($display);
   }