Code

Removed show_ldap_error from gosa-core
[gosa.git] / gosa-core / plugins / admin / departments / class_departmentGeneric.inc
index 03cedf2dc19ecc5fbd78bf9da26c721a89eb62d5..fc808e028976954813300647351b1fe8ef177690 100644 (file)
@@ -1,21 +1,23 @@
 <?php
 /*
-  This code is part of GOsa (https://gosa.gonicus.de)
-  Copyright (C) 2003  Cajus Pollmeier
-
-  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
+ * 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 department extends plugin
@@ -50,13 +52,6 @@ class department extends plugin
        var $objectclasses= array("top", "gosaDepartment", "organizationalUnit");
   var $initially_was_tagged = false;
 
-  
-  /* Temporary disable the Unit Tag functionalityi.
-     This is not used anymore, cause of the new acl implementation. 
-     Setting this to TRUE will disable 
-      all POST / GET activity, "Department tagging" and the checkbox within the generic template.
-   */
-  var $UnitTagDiabled     = TRUE;
   var $orig_base = "";
   var $orig_ou = "";
 
@@ -166,13 +161,10 @@ class department extends plugin
                $smarty->assign("base_select", $this->base);
 
     /* Set admin unit flag */
-    $smarty->assign("UnitTagDiabled",$this->UnitTagDiabled);
-    if(!$this->UnitTagDiabled){
-      if ($this->is_administrational_unit) {
-        $smarty->assign("unitTag", "checked");
-      } else {
-        $smarty->assign("unitTag", "");
-      }
+    if ($this->is_administrational_unit) {
+      $smarty->assign("unitTag", "checked");
+    } else {
+      $smarty->assign("unitTag", "");
     }
 
                return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
@@ -194,7 +186,9 @@ class department extends plugin
                $ldap->cd ($this->dn);
                $ldap->recursive_remove();
     new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
-    show_ldap_error($ldap->get_error(), sprintf(_("Removing of department 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()));
+    }
 
                /* Optionally execute a command after we're done */
                $this->handle_post_events('remove');
@@ -232,13 +226,11 @@ class department extends plugin
       }
 
       /* Save tagging flag */
-      if(!$this->UnitTagDiabled){
-        if ($this->acl_is_writeable("unitTag")){
-          if (isset($_POST['unitTag'])){
-            $this->is_administrational_unit= true;
-          } else {
-            $this->is_administrational_unit= false;
-          }
+      if ($this->acl_is_writeable("unitTag")){
+        if (isset($_POST['unitTag'])){
+          $this->is_administrational_unit= true;
+        } else {
+          $this->is_administrational_unit= false;
         }
       }
     }
@@ -255,31 +247,33 @@ class department extends plugin
                $ldap= $this->config->get_ldap_link();
     $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn'));
     if ($this->orig_dn == "new" && $ldap->count()){
-                       $message[]= _("Department with that 'Name' already exists.");
+                       $message[]= msgPool::duplicated(_("Name"));
                } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
-                       $message[]= _("Department with that 'Name' already exists.");
+                       $message[]= msgPool::duplicated(_("Name"));
                }
 
                /* All required fields are set? */
                if ($this->ou == ""){
                        $message[]= _("Required field 'Name' is not set.");
+                       $message[]= msgPool::required(_("Name"));
                }
                if ($this->description == ""){
                        $message[]= _("Required field 'Description' is not set.");
+                       $message[]= msgPool::required(_("Description"));
                }
 
     if(tests::is_department_name_reserved($this->ou,$this->base)){
-      $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$this->ou);
+      $message[]= msgPool::reserved(_("Name"));
     }
 
                if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
-                       $message[]= _("The field 'Name' contains invalid characters.");
+                       $message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/");
                }
                if (!tests::is_phone_nr($this->telephoneNumber)){
-                       $message[]= _("The field 'Phone' contains an invalid phone number.");
+                       $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
                }
                if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
-                       $message[]= _("The field 'Fax' contains an invalid phone number.");
+                       $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
                }
 
                return $message;
@@ -291,70 +285,64 @@ class department extends plugin
        {
                $ldap= $this->config->get_ldap_link();
 
-    if(!$this->UnitTagDiabled){
-
-      /* Add tag objects if needed */
-      if ($this->is_administrational_unit){
+    /* Add tag objects if needed */
+    if ($this->is_administrational_unit){
 
-        /* If this wasn't tagged before add oc an reset unit tag */
-        if(!$this->initially_was_tagged){
-          $this->objectclasses[]= "gosaAdministrativeUnit";
-          $this->gosaUnitTag= "";
+      /* If this wasn't tagged before add oc an reset unit tag */
+      if(!$this->initially_was_tagged){
+        $this->objectclasses[]= "gosaAdministrativeUnit";
+        $this->gosaUnitTag= "";
 
-          /* It seams that this method is called twice, 
-             set this to true. to avoid adding this oc twice */
-          $this->initially_was_tagged = true;
-        }
+        /* It seams that this method is called twice, 
+           set this to true. to avoid adding this oc twice */
+        $this->initially_was_tagged = true;
+      }
 
-        if ($this->gosaUnitTag == ""){
+      if ($this->gosaUnitTag == ""){
 
-          /* It's unlikely, but check if already used... */
-          $try= 5;
-          $ldap->cd($this->config->current['BASE']);
-          while ($try--){
+        /* It's unlikely, but check if already used... */
+        $try= 5;
+        $ldap->cd($this->config->current['BASE']);
+        while ($try--){
 
-            /* Generate microtime stamp as tag */
-            list($usec, $sec)= explode(" ", microtime());
-            $time_stamp= preg_replace("/\./", "", $sec.$usec);
+          /* Generate microtime stamp as tag */
+          list($usec, $sec)= explode(" ", microtime());
+          $time_stamp= preg_replace("/\./", "", $sec.$usec);
 
-            $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag"));
-            if ($ldap->count() == 0){
-              break;
-            }
-          }
-          if($try == 0) {
-            print_red(_("Fatal error: Can't find an unused tag to mark the administrative unit!"));
-            return;
+          $ldap->search("(&(objectClass=gosaAdministrativeUnit)(gosaUnitTag=$time_stamp))",array("gosaUnitTag"));
+          if ($ldap->count() == 0){
+            break;
           }
-          $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
         }
+        if($try == 0) {
+          msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG);
+          return;
+        }
+        $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
       }
     }
-               plugin::save();
+    $this->skipTagging = TRUE;
+    plugin::save();
 
-    if(!$this->UnitTagDiabled){
+    $this->attrs['gosaUnitTag'] = $this->gosaUnitTag;
 
-      /* Remove tag information if needed */
-      if (!$this->is_administrational_unit){
-        $tmp= array();
+    /* Remove tag information if needed */
+    if (!$this->is_administrational_unit){
+      $tmp= array();
 
-        /* Remove gosaAdministrativeUnit from this plugin */
-        $has_unit_tag= false;
-        foreach($this->attrs['objectClass'] as $oc){
-          if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
-            $tmp[]= $oc;
-          }
-          if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
-            $has_unit_tag= true;
-          }
+      /* Remove gosaAdministrativeUnit from this plugin */
+      $has_unit_tag= false;
+      foreach($this->attrs['objectClass'] as $oc){
+        if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
+          $tmp[]= $oc;
         }
-        $this->attrs['objectClass']= $tmp;
-
-        if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){
-          $this->attrs['gosaUnitTag']= array();
+        if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
+          $has_unit_tag= true;
         }
-        $this->gosaUnitTag = "";
       }
+      $this->attrs['objectClass']= $tmp;
+      $this->attrs['gosaUnitTag']= array();
+      $this->gosaUnitTag = "";
     }
 
                /* Write back to ldap */
@@ -373,14 +361,13 @@ class department extends plugin
                        $this->handle_post_events('add');
       new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
                }
-    show_ldap_error($ldap->get_error(), sprintf(_("Saving of department with dn '%s' failed."),$this->dn));
-
-
-    if(!$this->UnitTagDiabled){
-      /* The parameter forces only to set must_be_tagged, and don't touch any objects 
-         This will be done later */
-      $this->tag_objects(true);
+    if (!$ldap->success()){
+      msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class()));
     }
+
+    /* The parameter forces only to set must_be_tagged, and don't touch any objects 
+       This will be done later */
+    $this->tag_objects(true);
     
     /* Optionally execute a command after we're done */
                $this->postcreate();
@@ -669,7 +656,9 @@ class department extends plugin
         $nattrs['objectClass'][]= "gosaAdministrativeUnitTag";
         $ldap->cd($dn);
         $ldap->modify($nattrs);
-        show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
+        }
       } else {
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not tagging ($tag) $dn - seems to have moved away", "Tagging");
       }
@@ -698,7 +687,9 @@ class department extends plugin
         }
         $ldap->cd($dn);
         $ldap->modify($nattrs);
-        show_ldap_error($ldap->get_error(), sprintf(_("Handle object tagging with dn '%s' failed."),$dn));
+        if (!$ldap->success()){
+          msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $dn, LDAP_MOD, get_class()));
+        }
       } else {
         @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "Not removing tag ($tag) $dn - seems to have moved away", "Tagging");
       }