Code

Completed lvm partition changes
[gosa.git] / gosa-plugins / fai / admin / fai / class_askClassName.inc
index c803e64dc49e1bbf34206ba3a38604d138ab8c3b..945c0d54f4a3dd7c23e43592494a3c756580b7c3 100644 (file)
@@ -11,15 +11,13 @@ class askClassName extends plugin
   var $forbidden          = array();
   var $ClassName          = "";  
   var $ClassAlreadyExists = false;
+  var $parent;
 
   function askClassName (&$config,$dn,$ui,$objectClass)
   {
     $this->ui = $ui;
     $this->objectClass = $objectClass;
     plugin::plugin ($config, $dn);
-    if(!session::is_set('CurrentMainBase')){
-      session::set('CurrentMainBase',$this->config->current['BASE']);
-    }
   }
 
   function execute()
@@ -31,44 +29,45 @@ class askClassName extends plugin
     $smarty = get_smarty();
     $display= "";
 
-    /* The faifilter contais 
-     * The base for all fai objects 
-     */
-    $faifilter  = session::get('faifilter');
-
     /* First search for every ou, in given fai base
      * With a second search detect all object that belong to the different ous. 
      */
 
-    $base = get_ou('faiou').session::get('CurrentMainBase');
-    if($faifilter['branch'] != "main"){
-      $base = $faifilter['branch'];
-    }
+    $base = $this->parent->fai_release;
     $ldap = $this->config->get_ldap_link();
-    
-    $res= get_list("(&(objectClass=organizationalUnit)(!(objectClass=FAIbranch)))", "fai", $base,
-                   array("cn","description","objectClass"), GL_SIZELIMIT );
+
+    $type_acl_mapping = array(
+        "FAIpartitionTable"  => "faiPartitionTable",
+        "FAIpackageList"     => "faiPackage",
+        "FAIscript"          => "faiScript",
+        "FAIvariable"        => "faiVariable",
+        "FAIhook"            => "faiHook",
+        "FAIprofile"         => "faiProfile",
+        "FAItemplate"        => "faiTemplate");
+
+    $filter = "";
+    foreach($type_acl_mapping as $map){
+      $filter .= "(objectClass=".$map.")";
+    }
+
+    $res = FAI::get_all_objects_for_given_base($base,"(|".$filter.")",TRUE);
 
     $delete = array();
     $used   = array();
-    foreach($res as $objecttypes){
-      $res2= get_list("(objectClass=*)", "fai", $objecttypes['dn'],
-                      array("cn","description","objectClass","FAIclass","FAIstate"), GL_SIZELIMIT | GL_CONVERT );
-      foreach($res2 as $object){
-
-        /* skip class names with this name */ 
-        if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
-          if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
-            continue;
-          }
-          $delete[] = $object['cn'][0];
+    foreach($res as $object){
+
+      /* skip class names with this name */ 
+      if(in_array($this->objectClass,$object['objectClass']) || in_array("FAIprofile",$object['objectClass'])){
+        if(isset($object['FAIstate'][0]) && preg_match("/removed$/",$object['FAIstate'][0])){
+          continue;
         }
-    
-        /* Skip profiles */
-        if(!in_array("FAIprofile",$object['objectClass'])){
-          if(isset($object['cn'])){
-            $used[$object['cn'][0]]= $object['cn'][0];
-          }
+        $delete[] = $object['cn'][0];
+      }
+
+      /* Skip profiles */
+      if(!in_array("FAIprofile",$object['objectClass'])){
+        if(isset($object['cn'])){
+          $used[$object['cn'][0]]= $object['cn'][0];
         }
       }
     }
@@ -138,12 +137,16 @@ class askClassName extends plugin
   {
     /* Call common method to give check the hook */
     $message= plugin::check();
-  
+
+    if($this->objectClass == "FAIscript" && preg_match("/^-/", $this->ClassName)) { 
+      $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->ClassName),"/[^_]/");
+    }   
+
     if($this->ClassName != preg_replace("/ /","",trim($this->ClassName))){
       $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->ClassName),"/[^_]/");
     }
 
-    if(empty($this->ClassName)){
+    if($this->ClassName == ""){
       $message[]= msgPool::required(_("Name"));
     }