Code

Followup commit for #774
[gosa.git] / trunk / gosa-plugins / fai / admin / fai / class_faiPackage.inc
index f801ece82281382189d3ebc78f5e0efd5ef0ce86..fb7ad0902621e56bc79161da4b2d2e330ecb04ff 100644 (file)
@@ -23,7 +23,7 @@ class faiPackage extends plugin
   var $sub64coded       = array();
 
   var $ConfiguredPackages = array();
-  var $ConfigurationsToRemove = array();
+  var $Removal = array();
 
   /* Specific attributes */
   var $cn               = "";       // The class name for this object
@@ -111,6 +111,7 @@ class faiPackage extends plugin
         $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"))){
@@ -306,10 +307,20 @@ class faiPackage extends plugin
      */
     foreach($_POST as $name => $value){
 
+      /*****
+       * Remove configuration
+       *****/
+      if(!preg_match('/freeze/i', $this->FAIstate) && preg_match('/^remove_configuration_/', $name)){
+        $id = base64_decode(preg_replace("/^remove_configuration_(.*)_[xy]*$/","\\1",$name));
+        if(isset($this->ConfiguredPackages[$id])) {
+          $this->Removal[$id] = $this->ConfiguredPackages[$id];
+          unset($this->ConfiguredPackages[$id]);
+        }
+      }
+
       /******
        * Mark as removed  
        ******/
-      
       if(!preg_match('/freeze/i', $this->FAIstate) && preg_match("/^removal_package_/",$name)){
         $id = @base64_decode(preg_replace("/^removal_package_(.*)_[xy]*$/","\\1",$name));
         if(isset($this->usedPackages[$id])){
@@ -406,7 +417,23 @@ class faiPackage extends plugin
       } else {
         if(!preg_match("/^freeze/", $this->FAIstate)){
           $this->ConfiguredPackages= $this->dialog->save();
-          $this->ConfigurationsToRemove = $this->dialog->to_remove;
+          foreach($this->ConfiguredPackages as $package => $attrs) {
+            foreach($attrs as $name => $data) {
+              if (isset($data['Save']) && !($data['Save'])) {
+                $dn = "FAIvariable=".$name.",".$this->dn;
+                $ldap = $this->config->get_ldap_link();
+                $ldap->cat($dn);
+                if (!$ldap->count()) {
+                  unset($this->ConfiguredPackages[$package][$name]);
+                }
+              }
+            }
+            if (is_array($this->ConfiguredPackages[$package])) {
+              if (count($this->ConfiguredPackages[$package]) == 0) {
+                unset($this->ConfiguredPackages[$package]);
+              }
+            }
+          }
         }
         $this->dialog = false;
         $this->is_dialog = false;
@@ -445,8 +472,8 @@ class faiPackage extends plugin
         /* Append message if package is configured */
         $configured = "<img src='images/empty.png' alt=' '  class='center'>";
         if(isset($this->ConfiguredPackages[$usedName])){
-          $configured = "<img src='plugins/fai/images/package_configure.png' alt='"._("Configured")."'
-                      title='"._("Configured")."' class='center'>";
+          $configured = "<input type='image' name='remove_configuration_".base64_encode($usedName)."' src='plugins/fai/images/package_configure.png' title='"._("Remove configuration")."'
+            title='"._("Remove configuration")."' class='center'>";
         }
 
         /* Adapt used name if we're marked for removal */
@@ -576,6 +603,15 @@ class faiPackage extends plugin
         $message[] = msgPool::duplicated(_("Name"));
       }
     }
+
+    if (preg_match("/^-/", $this->cn)) {
+      $message[] = sprintf(_("The specified classname '%s' is invalid. Classnames must not start with a dash."), $this->cn);
+    }
+
+    if($this->cn != preg_replace("/ /","",trim($this->cn))){
+      $message[] = msgPool::invalid(_("Name"),preg_replace("/ /","_",$this->cn),"/[^_]/");
+    }
+
     return ($message);
   }
 
@@ -650,6 +686,22 @@ class faiPackage extends plugin
     $ldap->cd($this->dn);
 
     /* Save Package configurations */
+    foreach($this->Removal as $pkgname => $attrs){
+      /* Skip entries which are back in the ConfiguredPackages array */
+      if (isset($this->ConfiguredPackages[$pkgname])) {
+        continue;
+      }
+      foreach($attrs as $name => $attr){
+        $dn = "FAIvariable=".$name.",".$this->dn;
+        $ldap = $this->config->get_ldap_link();
+        $ldap->cat($dn);
+        if ($ldap->count()) {
+          $ldap->cd($dn);
+          $ldap->rmdir($dn);
+        }
+      }
+    }
+
     foreach($this->ConfiguredPackages as $pkgname => $attrs){
       foreach($attrs as $name => $attr){
         $pkgattrs = array();
@@ -667,6 +719,28 @@ class faiPackage extends plugin
         $pkgattrs['FAIvariableContent']   = $attr['Value'];
         $pkgdn =  "FAIvariable=".$name.",".$this->dn;
 
+        if (!$attr['Save']) {
+          $ldap = $this->config->get_ldap_link();
+          $ldap->cat($pkgdn);
+          if ($ldap->count()) {
+            $ldap->cd($pkgdn);
+            $ldap->rmdir($pkgdn);
+          }
+          else {
+            unset($this->ConfiguredPackages[$pkgname][$name]);
+          }
+          if (is_array($this->ConfiguredPackages[$pkgname]) && count($this->ConfiguredPackages[$pkgname]) == 0) {
+            unset($this->ConfiguredPackages[$pkgname]);
+          }
+
+          continue;
+
+        }
+
+        if (empty($pkgattrs['FAIvariableContent'])) {
+          $pkgattrs['FAIvariableContent'] = array();
+        }
+
         if (is_array($pkgattrs['FAIvariableContent'])) {
           $ldap = $this->config->get_ldap_link();
           $ldap->cat($pkgdn);
@@ -691,16 +765,6 @@ 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);
-      }
-    }
   }