Code

Apply patch for #5863
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_faiPackage.inc
index fb7ad0902621e56bc79161da4b2d2e330ecb04ff..796b72da70d7ab1277adb0e8d25e75b4e136dcf4 100644 (file)
@@ -55,6 +55,7 @@ class faiPackage extends plugin
 
   var $direct_packages_add = FALSE;
   var $configure_dialog_shown = FALSE;
+  var $debconf_configurations = FALSE;
 
   function faiPackage (&$config, $dn= NULL)
   {
@@ -80,56 +81,8 @@ class faiPackage extends plugin
         ksort($this->usedPackages);
       }  
 
-      /* Fetch all package configurations from ldap 
-       */
-      $PackageFilter = "";
-      foreach($this->usedPackages as $name => $value){
-        $PackageFilter .= "(FAIpackage=".$name.")";
-      }
-      /* Also fetch d-i */
-      $PackageFilter .= "(FAIpackage=d-i)";
-
-      $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
-
-      /* Search for configuration objects */ 
-      $ldap = $this->config->get_ldap_link();
-      $ldap->cd($this->dn);
-      $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
-            "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
-
-      /* Walk through configurations and append them to our list of ConfiguredPackages 
-       */
-      while($attr = $ldap->fetch()){
-
-        /* Skip objects, that are tagged as removed */
-        if(isset($object['FAIstate'][0])){
-          if(preg_match("/removed$/",$attr['FAIstate'][0])){
-            continue;
-          }
-        }
-
-        $tmp =array(); 
-        $tmp['Name']  = $attr['FAIvariable'][0];
-        $tmp['Type']  = $attr['FAIvariableType'][0];
-        $tmp['Save']  = TRUE;
-
-        if (isset($attr['FAIvariableContent'][0])){
-          if(!in_array($attr['FAIvariableType'],array("multiselect"))){
-            $tmp['Value'] = $attr['FAIvariableContent'][0];
-          }else{
-            $content = array();        
-            unset($attr['FAIvariableContent']['count']);
-            foreach($attr['FAIvariableContent'] as $attr){
-              $tmp['Value'][] = $attr;
-            }
-          }
-          $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
-        }
-        else {
-          $tmp['Value'] = "";
-          $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
-        }
-      }
+      /* Fetch package configurations from LDAP */
+      $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $this->dn);
 
       $this->FAIdebianSection = array();
       if(isset($this->attrs['FAIdebianSection'])){
@@ -166,6 +119,64 @@ class faiPackage extends plugin
     $this->list= $this->genPkgs(TRUE);
   }
 
+  function get_configured_packages($packages, $base)
+  {
+    /* Fetch all package configurations from ldap 
+     */
+    $PackageFilter = "";
+    foreach($packages as $name => $value){
+      $PackageFilter .= "(FAIpackage=".$name.")";
+    }
+    /* Also fetch d-i */
+    $PackageFilter .= "(FAIpackage=d-i)";
+
+    $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
+
+    /* Search for configuration objects */ 
+    $ldap = $this->config->get_ldap_link();
+    $ldap->cd($base);
+    $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType",
+          "FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
+
+    $configured_packages = array();
+
+    /* Walk through configurations and append them to our list of ConfiguredPackages 
+     */
+    while($attr = $ldap->fetch()){
+
+      /* Skip objects, that are tagged as removed */
+      if(isset($object['FAIstate'][0])){
+        if(preg_match("/removed$/",$attr['FAIstate'][0])){
+          continue;
+        }
+      }
+
+      $tmp =array(); 
+      $tmp['Name']  = $attr['FAIvariable'][0];
+      $tmp['Type']  = $attr['FAIvariableType'][0];
+      $tmp['Save']  = TRUE;
+
+      if (isset($attr['FAIvariableContent'][0])){
+        if(!in_array($attr['FAIvariableType'],array("multiselect"))){
+          $tmp['Value'] = $attr['FAIvariableContent'][0];
+        }else{
+          $content = array();        
+          unset($attr['FAIvariableContent']['count']);
+          foreach($attr['FAIvariableContent'] as $attr){
+            $tmp['Value'][] = $attr;
+          }
+        }
+        $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
+      }
+      else {
+        $tmp['Value'] = "";
+        $configured_packages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
+      }
+    }
+  
+    return $configured_packages;
+  }
+
 
   function execute()
   {
@@ -288,7 +299,7 @@ class faiPackage extends plugin
     }
 
     if(isset($_POST['EditConfigurations']) &&
-      $this->acl_is_writeable("FAIpackage")) {
+      $this->acl_is_writeable("FAIdebconfInfo")) {
         $this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
         $this->dialog->set_acl_base($this->acl_base);
         $this->is_dialog = true;
@@ -535,6 +546,10 @@ class faiPackage extends plugin
     foreach($tmp['plProvidedAcls'] as $name => $translated){
       $smarty->assign($name."ACL",$this->getacl($name,preg_match("/freeze/",$this->FAIstate)));
     }
+
+    if ($this->acl_is_writeable("FAIdebconfInfo")) {
+      $this->debconf_configurations = TRUE;
+    }
  
     $smarty->assign("freeze", preg_match("/freeze/",$this->FAIstate));
     $smarty->assign("divlist",$divlist->DrawList());
@@ -542,6 +557,7 @@ class faiPackage extends plugin
     $smarty->assign("sections",$this->sections);
     $smarty->assign("section" ,$strsec);
     $smarty->assign("direct_packages_add", $this->direct_packages_add);
+    $smarty->assign("debconf_configurations", $this->debconf_configurations);
     $display.= $smarty->fetch(get_template_path('faiPackage.tpl', TRUE));
     return($display);
   }
@@ -696,8 +712,7 @@ class faiPackage extends plugin
         $ldap = $this->config->get_ldap_link();
         $ldap->cat($dn);
         if ($ldap->count()) {
-          $ldap->cd($dn);
-          $ldap->rmdir($dn);
+          FAI::prepare_to_save_FAI_object($dn,array(),true);
         }
       }
     }
@@ -723,8 +738,7 @@ class faiPackage extends plugin
           $ldap = $this->config->get_ldap_link();
           $ldap->cat($pkgdn);
           if ($ldap->count()) {
-            $ldap->cd($pkgdn);
-            $ldap->rmdir($pkgdn);
+            FAI::prepare_to_save_FAI_object($pkgdn,array(),true);
           }
           else {
             unset($this->ConfiguredPackages[$pkgname][$name]);
@@ -822,47 +836,8 @@ class faiPackage extends plugin
         $this->FAIdebianSection[$source['FAIdebianSection'][$i]]=$source['FAIdebianSection'][$i];
       }
     }
+    $this->ConfiguredPackages = $this->get_configured_packages($this->usedPackages, $source['dn']);
 
-    /* Create one filter with all package names, 
-       instead of calling $ldap->search for every single package 
-     */
-    $PackageFilter = "";
-    foreach($this->usedPackages as $name){
-      $PackageFilter .= "(FAIpackage=".$name.")";
-    }
-
-    /* Search for configuration objects */ 
-    $ldap = $this->config->get_ldap_link();
-    $ldap->cd($source['dn']);
-    $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection","FAIstate"));
-
-    /* Walk through configurations and append them to our list of ConfiguredPackages */
-    while($attr = $ldap->fetch()){
-
-      /* Skip objects, that are tagged as removed */
-      if(isset($object['FAIstate'][0])){
-        if(preg_match("/removed$/",$attr['FAIstate'][0])){
-          continue;
-        }
-      }
-
-      $tmp =array(); 
-      $tmp['Name']  = $attr['FAIvariable'][0];
-      $tmp['Type']  = $attr['FAIvariableType'][0];
-
-      if (isset($attr['FAIvariableContent'][0])){
-        if(!in_array($attr['FAIvariableType'],array("multiselect"))){
-          $tmp['Value'] = $attr['FAIvariableContent'][0];
-        }else{
-          $content = array();        
-          unset($attr['FAIvariableContent']['count']);
-          foreach($attr['FAIvariableContent'] as $attr){
-            $tmp['Value'][] = $attr;
-          }
-        }
-        $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
-      }
-    }
   }