From: hickert Date: Tue, 23 May 2006 04:32:19 +0000 (+0000) Subject: Added function that checks if a department name is allowed in specified base X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;ds=sidebyside;h=78ff273400c1bfc84cfea5ce4f338349602fe8f2;hp=64666111bd2f20f4d23d3a55a0346280014990e5;p=gosa.git Added function that checks if a department name is allowed in specified base git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3492 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/include/functions.inc b/include/functions.inc index 0cb50d54b..45ae25876 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -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: ?> diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index df8c51e78..64d631deb 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -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.");