Code

Removed duplicated addslashes
[gosa.git] / plugins / admin / fai / class_faiPackage.inc
index 260957797c1585d60ff65c8ac092655dd7c3806f..c91282532bf8c2fbeb9251b61fc629022e843f04 100644 (file)
@@ -112,10 +112,18 @@ class faiPackage extends plugin
     
     /* Search for configuration objects */ 
     $ldap = $this->config->get_ldap_link();
-    $ldap->search($PackageFilter,array("FAIvariable","FAIvariableType","FAIvariableContent","FAIpackage","FAIdebianSection"));
+    $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];
@@ -286,7 +294,6 @@ class faiPackage extends plugin
           $this->usedPackages[$pkg]= $pkg;
         }
       }
-      print_a($this->usedPackages);
     }
 
     /* Save Configuration */
@@ -336,9 +343,25 @@ class faiPackage extends plugin
   {
     $ldap = $this->config->get_ldap_link();
     $ldap->cd ($this->dn);
-    $ldap->rmdir_recursive($this->dn);
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of FAI/package list with dn '%s' failed."),$this->dn));
-    $this->handle_post_events("remove");    
+
+    $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $this->dn);
+    if($_SESSION['faifilter']['branch'] == "main"){
+      $use_dn = $this->dn;
+    }
+
+    prepare_to_save_FAI_object($use_dn,array(),true);
+
+    foreach($this->ConfiguredPackages as $pkgname => $attrs){
+      foreach($attrs as $name => $attr){
+        $pkgdn =  "FAIvariable=".$name.",".$this->dn;
+        $use_dn = str_ireplace( get_release_dn($this->dn), $_SESSION['faifilter']['branch'], $pkgdn);
+        if($_SESSION['faifilter']['branch'] == "main"){
+          $use_dn = $obj['dn'];
+        }
+        prepare_to_save_FAI_object($use_dn,array(),true);
+      }
+    }
+    $this->handle_post_events("remove");
   }
 
 
@@ -398,13 +421,15 @@ class faiPackage extends plugin
         $dsc= "";
         if (preg_match('/^-/', $usedName)){
           $dsc= " - "._("Package marked for removal");
-          $usedName= preg_replace('/^-/', '! ', $usedName);
+          $usedName2= preg_replace('/^-/', '! ', $usedName);
+        }else{
+          $usedName2= $usedName;
         }
 
         if(isset($this->list[$usedName][1])){
-          $a_ret[$usedName] = $usedName." [".$this->list[$usedName][1]."]".$c_str.$dsc;
+          $a_ret[$usedName] = $usedName2." [".$this->list[$usedName][1]."]".$c_str.$dsc;
         }else{
-          $a_ret[$usedName] = $usedName.$c_str.$dsc;
+          $a_ret[$usedName] = $usedName2.$c_str.$dsc;
         }
       }
     }
@@ -465,22 +490,7 @@ class faiPackage extends plugin
       $this->attrs['FAIdebianSection'][] = $sec;
     }
 
-    //    $this->attrs["FAIinstallMethod"]= "aptitude";
-
-    $ldap->cat($this->dn, array('dn'));
-    if($ldap->count()!=0){
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->dn);
-      $this->cleanup();
-      $ldap->modify ($this->attrs); 
-
-    }else{
-      /* Write FAIscript to ldap*/
-      $ldap->cd($this->config->current['BASE']);
-      $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $this->dn));
-      $ldap->cd($this->dn);
-      $ldap->add($this->attrs);
-    }
+    prepare_to_save_FAI_object($this->dn,$this->attrs);
     show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/package list with dn '%s' failed."),$this->dn));
 
     /* Do object tagging */
@@ -514,25 +524,35 @@ class faiPackage extends plugin
         if((isset($attrs['objectClass'])) && (in_array_ics("gosaAdministrativeUnitTag",$attrs['objectClass']))){
           $pkgattrs['objectClass'][] = "gosaAdministrativeUnitTag";
         }
-    
-        if($ldap->count()!=0){
-          $ldap->cd($pkgdn);
-          $this->cleanup();
-          $ldap->modify ($pkgattrs); 
 
-        }else{
-          $ldap->cd($this->config->current['BASE']);
-          $ldap->create_missing_trees(preg_replace('/^[^,]+,/', '', $pkgdn));
-          $ldap->cd($pkgdn);
-          $ldap->add($pkgattrs);
-        }
-        show_ldap_error($ldap->get_error(), sprintf(_("Saving of FAI/package list with dn '%s' failed."),$this->dn));
+        prepare_to_save_FAI_object($pkgdn,$pkgattrs);
 
         /* Handle tagging */
         $this->handle_object_tagging($pkgdn, $this->gosaUnitTag);
       }
     }
   }
+
+  /* Return plugin informations for acl handling */ 
+  function plInfo()
+  {
+    return (array( 
+          "plShortName" => _("Package"),
+          "plDescription" => _("FAI Package list"),
+          "plSelfModify"  => FALSE,
+          "plDepends"     => array(),
+          "plPriority"    => 0,
+          "plSection"     => array("administration"),
+          "plCategory"    => array("fai"),
+          "plProvidedAcls" => array(
+            "cn"                => _("Name"),
+            "description"       => _("Description"),
+            "FAIpackage"        => _("Packages"),
+            "FAIdebianSection"  => _("Section"),
+            "FAIinstallMethod"  => _("Install Method"),
+            "FAIdebianRelease"  => _("Release"))
+          ));
+  }
 }
 
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: