Code

Implement a debconf configuration overview (Trac #2025)
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_faiPackage.inc
index e877dfd1515aa858d6ff25f08f8b8245762da3ec..f801ece82281382189d3ebc78f5e0efd5ef0ce86 100644 (file)
@@ -23,6 +23,7 @@ class faiPackage extends plugin
   var $sub64coded       = array();
 
   var $ConfiguredPackages = array();
+  var $ConfigurationsToRemove = array();
 
   /* Specific attributes */
   var $cn               = "";       // The class name for this object
@@ -53,7 +54,7 @@ class faiPackage extends plugin
       "pending", "dpkgc" );
 
   var $direct_packages_add = FALSE;
-
+  var $configure_dialog_shown = FALSE;
 
   function faiPackage (&$config, $dn= NULL)
   {
@@ -85,6 +86,9 @@ class faiPackage extends plugin
       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 */ 
@@ -120,6 +124,10 @@ class faiPackage extends plugin
           }
           $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
         }
+        else {
+          $tmp['Value'] = "";
+          $this->ConfiguredPackages[$attr['FAIpackage'][0]][$attr['FAIvariable'][0]]=$tmp;
+        }
       }
 
       $this->FAIdebianSection = array();
@@ -247,7 +255,6 @@ class faiPackage extends plugin
 
 
           foreach ($valid_packages as $value) {
-            
             if( $do_si_query == true ) {
               $res = $daemon->FAI_get_packages($this->FAIdebianRelease,$query_attrs,array($value),0,1);
               if( ! $daemon->is_error()){
@@ -279,6 +286,13 @@ class faiPackage extends plugin
       }
     }
 
+    if(isset($_POST['EditConfigurations']) &&
+      $this->acl_is_writeable("FAIpackage")) {
+        $this->dialog = new faiDebconfConfigurations($this->config, $this->dn, $this);
+        $this->dialog->set_acl_base($this->acl_base);
+        $this->is_dialog = true;
+    }
+
     /* + was pressed to open the package dialog */
     if(isset($_POST['Addpkg']) && 
         $this->acl_is_writeable("FAIpackage") && 
@@ -334,6 +348,7 @@ class faiPackage extends plugin
           if(isset($this->ConfiguredPackages[$pkg])){
             $pkg_config = $this->ConfiguredPackages[$pkg];
           }
+          $this->configure_dialog_shown = TRUE;
           $this->dialog = new faiPackageConfiguration($this->config, $this->dn,$pkg, $this->FAIdebianRelease , $pkg_config);
           $this->is_dialog =true;
         }
@@ -372,18 +387,37 @@ class faiPackage extends plugin
     }
 
     /* Save Configuration */
-    if(isset($_POST['SaveObjectConfig'])){
+    if(isset($_POST['SaveObjectConfig']) && $this->configure_dialog_shown){
       if(!preg_match("/^freeze/", $this->FAIstate)){
         $this->ConfiguredPackages= array_merge($this->ConfiguredPackages,$this->dialog->save());
       }
       $this->dialog = false;
       $this->is_dialog=false;
+      $this->configure_dialog_shown=false;
+    }
+
+    if (isset($_POST['SaveDebconfConfig'])){
+      $this->dialog->save_object();
+      $msgs = $this->dialog->check();
+      if(count($msgs)>0) {
+        foreach($msgs as $msg){
+          msg_dialog::display(_("Error"), $msg, ERROR_DIALOG);
+        }
+      } else {
+        if(!preg_match("/^freeze/", $this->FAIstate)){
+          $this->ConfiguredPackages= $this->dialog->save();
+          $this->ConfigurationsToRemove = $this->dialog->to_remove;
+        }
+        $this->dialog = false;
+        $this->is_dialog = false;
+      }
     }
 
     /* cancel configuration */     
-    if(isset($_POST['CancelObjectConfig'])){
+    if(isset($_POST['CancelObjectConfig']) && $this->configure_dialog_shown){
       $this->dialog = false;
       $this->is_dialog=false;
+      $this->configure_dialog_shown=false;
     }
 
     /* Display dialog */ 
@@ -400,6 +434,7 @@ class faiPackage extends plugin
     /* Create divlist to display a list of all currently used packages
      */
     $divlist = new divSelectBox("faiPackages");
+    $divlist->setHeight(600);
 
     ksort($this->usedPackages);
     if(is_array($this->usedPackages)){
@@ -617,7 +652,6 @@ class faiPackage extends plugin
     /* Save Package configurations */
     foreach($this->ConfiguredPackages as $pkgname => $attrs){
       foreach($attrs as $name => $attr){
-      
         $pkgattrs = array();
 
         foreach($attr as $n=>$v){
@@ -633,6 +667,16 @@ class faiPackage extends plugin
         $pkgattrs['FAIvariableContent']   = $attr['Value'];
         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
 
+        if (is_array($pkgattrs['FAIvariableContent'])) {
+          $ldap = $this->config->get_ldap_link();
+          $ldap->cat($pkgdn);
+          if (!$ldap->count()) {
+            /* Do not try to set FAIvariableContent to empty array if this
+             * debconfInfo object is new */
+            unset($pkgattrs['FAIvariableContent']);
+          }
+        }
+
         /* Tag object */
        $ui= get_userinfo();
         $this->tag_attrs($pkgattrs, $pkgdn, $ui->gosaUnitTag);
@@ -647,6 +691,16 @@ class faiPackage extends plugin
         }
       }
     }
+
+    /* Remove obsolete configurations */
+    foreach($this->ConfigurationsToRemove as $package => $attr) {
+      foreach($attr as $name => $attr) {
+        $dn = "FAIvariable=".$name.",".$this->dn;
+        $ldap = $this->config->get_ldap_link();
+        $ldap->cd($dn);
+        $ldap->rmdir($dn);
+      }
+    }
   }
 
 
@@ -712,7 +766,6 @@ class faiPackage extends plugin
     foreach($this->usedPackages as $name){
       $PackageFilter .= "(FAIpackage=".$name.")";
     }
-    $PackageFilter = "(&(objectClass=FAIdebconfInfo)(|".$PackageFilter."))";
 
     /* Search for configuration objects */ 
     $ldap = $this->config->get_ldap_link();