Code

Removed show_errors
[gosa.git] / gosa-plugins / goto / admin / applications / class_applicationGeneric.inc
index 247acf97278aac3f39452d5eadd6ca5fef353b35..c1e152c2c46a15a6d60ec3de36c5b4338c478f1c 100644 (file)
@@ -1,11 +1,6 @@
 <?php
 class application extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Handling of GOsa's application object";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* application attributes */
   var $cn= "";
   var $description= "";
@@ -232,7 +227,55 @@ class application extends plugin
 
   function remove_from_parent()
   {
+    restore_error_handler();
+
+    /* Parse release out of object dn */
+    $release = preg_replace("/".get_ou("applicationou").normalizePreg($this->base)."$/","",$this->dn);
+    $release = preg_replace("/^cn=[^,]+,/","",$release);
+
+    /* Get a list of all groups 
+     */
+    $groups = array();
     $ldap= $this->config->get_ldap_link();
+    $ldap->cd($this->config->current['BASE']);
+    $ldap->search("(objectClass=posixGroup)",array("dn"));
+    while($attrs = $ldap->fetch()){
+      $groups[$attrs['dn']] = array();
+    }
+    
+    /* Check if there are groups, useing this application 
+     */
+    $found = array();
+    foreach($groups as $group => $data){
+      $ldap->cd($release.$group);
+      $ldap->search("(objectClass=gotoMenuEntry)",array("dn"));
+      while($attrs = $ldap->fetch()){
+        $info = preg_replace("/".normalizePreg($release.$group)."$/","",$attrs['dn']); 
+        if(preg_match("/^cn=".$this->cn."/",$info) && !preg_match("/ou=[^,]+,/",$info)){
+          $found[] = $attrs['dn'];
+        }
+      }
+    }
+
+    /* Create an error message an skip remove, if 
+        this application is still in use. 
+     */
+    if(count($found)){
+      $objs = "";
+      $cnt = 3;
+      for($i = 0 ; $i < $cnt ; $i++ ){
+        if(isset($found[$i])){
+          $objs .= "&nbsp;".$found[$i].",";
+        }
+      }
+      if(count($found) > $cnt){
+        $objs .= "... ";
+      }
+      $objs = trim($objs,", ");
+      print_red(sprintf(_("Can not remove application, it is still in use by these objects: %s."),$objs));
+      return(FALSE);
+    }
+
     $ldap->rmDir($this->dn);
     new log("remove","application/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
     show_ldap_error($ldap->get_error(), sprintf(_("Removing of application with dn '%s' failed."),$this->dn));
@@ -249,14 +292,6 @@ class application extends plugin
       $og->save ();
       show_ldap_error($ldap->get_error(), sprintf(_("Removing application from objectgroup '%s' failed"), $og->dn));
     }
-    $ldap->search ("(&(objectClass=posixGroup)(gosaMemberApplication=".$this->cn."))", array("cn"));
-    while ($attrs= $ldap->fetch()){
-      $ag= new appgroup($this->config, $ldap->getDN());
-      $ag->removeApp($this->cn);
-      $ag->save ();
-      show_ldap_error($ldap->get_error(), sprintf(_("Removing application from group '%s' failed"), $ag->dn));
-    }
-
   }