Code

Renanmed opsi class
[gosa.git] / gosa-plugins / systems / admin / systems / class_componentGeneric.inc
index 583625188ab6e8c2063b5ba4f5025d699feb759d..294e9a0ede38867d304d63b9f602128ded60f153 100644 (file)
@@ -1,12 +1,27 @@
 <?php
+/*
+ * This code is part of GOsa (http://www.gosa-project.org)
+ * Copyright (C) 2003-2008 GONICUS GmbH
+ *
+ * ID: $$Id$$
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
 
 class componentGeneric extends plugin
 {
-  /* CLI vars */
-  var $cli_summary= "Manage component base objects";
-  var $cli_description= "Some longer text\nfor help";
-  var $cli_parameters= array("eins" => "Eins ist toll", "zwei" => "Zwei ist noch besser");
-
   /* Generic terminal attributes */
   var $interfaces= array();
   var $ignore_account= TRUE;
@@ -16,6 +31,8 @@ class componentGeneric extends plugin
   var $cn= "";
   var $description= "";
   var $orig_dn= "";
+  var $orig_cn= "";
+  var $orig_base= "";
 
   /* attribute list for save action */
   var $attributes= array("cn", "description");
@@ -33,11 +50,14 @@ class componentGeneric extends plugin
       $this->base= dn2base($ui->dn);
       $this->cn= "";
     } else {
-      $this->base= preg_replace ("/^[^,]+,[^,]+,[^,]+,/", "", $this->dn);
+      $this->base= preg_replace ("/^[^,]+,".normalizePreg(get_ou("componentou"))."/", "", $this->dn);
     }
     $this->netConfigDNS = new termDNS($this->config,$this,$this->objectclasses, true);
     /* Save dn for later references */
     $this->orig_dn= $this->dn;
+
+    $this->orig_base = $this->base;
+    $this->orig_cn = $this->cn;
   }
 
 
@@ -53,8 +73,8 @@ class componentGeneric extends plugin
 
     /* Do we represent a valid phone? */
     if (!$this->is_account && $this->parent === NULL){
-      $display= "<img alt=\"\" src=\"images/stop.png\" align=middle>&nbsp;<b>".
-        _("This 'dn' has no network features.")."</b>";
+      $display= "<img alt=\"\" src=\"images/small-error.png\" align=middle>&nbsp;<b>".
+        msgPool::noValidExtension(_("component"))."</b>";
       return($display);
     }
 
@@ -136,7 +156,10 @@ class componentGeneric extends plugin
     
     new log("remove","component/".get_class($this),$this->dn,$this->attributes,$ldap->get_error());
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of system component/generic with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
+    }
+
     $this->handle_post_events(array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
 
     /* Delete references to object groups */
@@ -183,20 +206,20 @@ class componentGeneric extends plugin
     $this->dn= "cn=".$this->cn.",".get_ou('componentou').$this->base;
 
     if ($this->cn == "" ){
-      $message[]= _("The required field 'Component name' is not set.");
+      $message[]= msgPool::required(_("Component name"));
     }
 
     /* Check if given name is a valid host/dns name */
     if(!tests::is_dns_name($this->cn)){
-      $message[] = _("Please specify a valid name for this object.");
+      $message[]= msgPool::invalid(_("Component name"), $this->cn, "/[a-z0-9\.\-]/i");
     }
 
     /* To check for valid ip*/
     if($this->netConfigDNS->ipHostNumber == ""){
-       $message[]= _("The required field IP address is empty.");
+       $message[]= msgPool::required(_("IP address"));
     } else {
       if (!tests::is_ip($this->netConfigDNS->ipHostNumber)){
-        $message[]= _("The field IP address contains an invalid address.");
+        $message[]= msgPool::invalid(_("IP address"), "", "", "192.168.1.2");
       }
     }
 
@@ -209,14 +232,22 @@ class componentGeneric extends plugin
           if(preg_match("/cn=dhcp,/",$attrs['dn'])){
             continue;
           }
-          if ($attrs['dn'] != $this->orig_dn){
-            $message[]= sprintf (_("There is already an entry '%s' in the base choosen by you"), $this->cn);
+          if ($attrs['dn'] != $this->orig_dn && preg_match("/".normalizePreg(get_ou("componentou"))."/",$attrs['dn'])){
+            $message[]= msgPool::duplicated(_("Component name"));
             break;
           }
         }
       }
     }
 
+    /* Check if we are allowed to create or move this object
+     */
+    if($this->orig_dn == "new" && !$this->acl_is_createable($this->base)){
+      $message[] = msgPool::permCreate();
+    }elseif($this->orig_dn != "new" && $this->base != $this->orig_base && !$this->acl_is_moveable($this->base)){
+      $message[] = msgPool::permMove();
+    }
+
     return ($message);
   }
 
@@ -256,10 +287,6 @@ class componentGeneric extends plugin
       $this->handle_post_events("add",array("macAddress" => $this->netConfigDNS->macAddress,"ipHostNumber" => $this->netConfigDNS->ipHostNumber));
       
     } else {
-      if ($this->orig_dn != $this->dn){
-        $this->move($this->orig_dn, $this->dn);
-      }
-
       $ldap->cd($this->dn);
       $this->cleanup();
       $ldap->modify ($this->attrs); 
@@ -270,7 +297,9 @@ class componentGeneric extends plugin
     $this->netConfigDNS->cn = $this->cn;
     $this->netConfigDNS->save();
 
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of system component/generic with dn '%s' failed."),$this->dn));
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class()));
+    }
   }
 
   /* Return plugin informations for acl handling */