Code

Added function that checks if a department name is allowed in specified base
authorhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 May 2006 04:32:19 +0000 (04:32 +0000)
committerhickert <hickert@594d385d-05f5-0310-b6e9-bd551577e9d8>
Tue, 23 May 2006 04:32:19 +0000 (04:32 +0000)
git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3492 594d385d-05f5-0310-b6e9-bd551577e9d8

include/functions.inc
plugins/admin/departments/class_departmentGeneric.inc

index 0cb50d54baef4386113ee88aef4807ff8d92f4bb..45ae25876fe246c7a5ac71d15d24ce69ff5a50a5 100644 (file)
@@ -1976,5 +1976,29 @@ function get_MicroTimeDiff($start , $stop)
 }
 
 
+/* Check if the given department name is valid */
+function is_department_name_reserved($name,$base)
+{
+  $reservedName = array("systems","apps","incomming","internal","accounts","fax","addressbook",
+                          preg_replace("/ou=(.*),/","\\1",get_people_ou()),
+                          preg_replace("/ou=(.*),/","\\1",get_groups_ou()));
+
+  $follwedNames['/ou=fai,ou=configs,ou=systems,/'] = array("fai","hooks","templates","scripts","disks","packages","variables","profiles");
+
+  /* Check if name is one of the reserved names */
+  if(in_array_ics($name,$reservedName)) {
+    return(true);
+  }
+
+  /* Check all follow combinations if name is in array && parent base == array_key, return false*/
+  foreach($follwedNames as $key => $names){
+    if((in_array_ics($name,$names)) && (preg_match($key,$base))){
+      return(true);
+    }
+  }
+  return(false);
+}
+
+
 // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler:
 ?>
index df8c51e78fba7c40606b8c74a0adce06897cbea5..64d631deb83355f3e6e9d874f50cdac520e24764 100644 (file)
@@ -236,17 +236,9 @@ class department extends plugin
                        $message[]= _("Required field 'Description' is not set.");
                }
 
-               /* Validate and modify - or: spaghetti rules! */
-               $SkipNames = array(     "incoming","apps","systems","fai","config",     
-                               preg_replace("/ou=(.*),/","\\1",get_people_ou()),
-                               preg_replace("/ou=(.*),/","\\1",get_groups_ou())
-                               );      
-               foreach($SkipNames as $name){
-                       if ($this->ou == $name){
-                               $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$name);
-                       }
-               }
-
+    if(is_department_name_reserved($this->ou,$this->base)){
+      $message[]= sprintf(_("The field 'Name' contains the reserved word '%s'. Please choose another name."),$this->ou);
+    }
 
                if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
                        $message[]= _("The field 'Name' contains invalid characters.");