X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;ds=sidebyside;f=gosa-core%2Fplugins%2Fadmin%2Fdepartments%2Fclass_departmentGeneric.inc;h=78e514f1e2af041e3b302cd4d85cb3c5cc4e9713;hb=10100c5c8d92e45a0719bc321a3767f65966d9d7;hp=390db7341d2ce0ad547a3571962b65d367a9633a;hpb=a99f4d58066ed84d8e2945d4574825d6dca66d10;p=gosa.git diff --git a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc index 390db7341..78e514f1e 100644 --- a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc +++ b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc @@ -32,38 +32,66 @@ class department extends plugin var $businessCategory= ""; var $telephoneNumber= ""; var $facsimileTelephoneNumber= ""; - var $orig_dn= ""; var $is_administrational_unit= false; var $gosaUnitTag= ""; var $view_logged = FALSE; - var $rec_dst=false; // Destination for recursive move - var $rec_src=false; // Source for recursive move - var $rec_cpy=false; // Is recursive move requested ? + + var $type ="organizationalUnit"; + var $namingAttr = "ou"; /* Headpage attributes */ var $last_dep_sorting= "invalid"; var $departments= array(); - var $must_be_tagged = false; /* attribute list for save action */ var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress", "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag"); - var $objectclasses= array("top", "gosaDepartment", "organizationalUnit"); - var $initially_was_tagged = false; + /* Do not append the structural object classes here, they are added dynamically in the constructor */ + var $objectclasses= array("top", "gosaDepartment"); + var $structuralOC = array("organizationalUnit"); + + var $initially_was_tagged = false; var $orig_base = ""; var $orig_ou = ""; function department (&$config, $dn) { + /* Add the default structural obejct class 'locality' if this is a new entry + */ + $ldap = $config->get_ldap_link(); + $ldap->cd($config->current['BASE']); + if($dn == "" || $dn == "new" || !$ldap->dn_exists($dn)){ + $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses); + }else{ + $ldap->cat($dn, array("structuralObjectClass")); + $attrs= $ldap->fetch(); + if(isset($attrs['structuralObjectClass']['count'])){ + for($i = 0 ; $i < $attrs['structuralObjectClass']['count'] ; $i++){ + $this->objectclasses[] = $attrs['structuralObjectClass'][$i]; + } + }else{ + + /* Could not detect structural object class for this object, fall back to the default 'locality' + */ + $this->objectclasses = array_merge($this->structuralOC,$this->objectclasses); + } + } + $this->objectclasses = array_unique($this->objectclasses); plugin::plugin($config, $dn); $this->is_account= TRUE; $this->ui= get_userinfo(); $this->dn= $dn; $this->orig_dn= $dn; - $this->orig_ou= $this->ou; + + /* Save current naming attribuet + */ + $nA = $this->namingAttr; + $orig_nA = "orig_".$nA; + $this->$orig_nA = $this->$nA; + $this->config= $config; /* Set base */ @@ -108,6 +136,15 @@ class department extends plugin $smarty->assign($name."ACL",$this->getacl($name)); } + /* Hide base selector, if this object represents the base itself + */ + $smarty->assign("is_root_dse", FALSE); + if($this->dn == $this->config->current['BASE']){ + $smarty->assign("is_root_dse", TRUE); + $nA = $this->namingAttr."ACL"; + $smarty->assign($nA,$this->getacl($this->namingAttr,TRUE)); + } + /* Base select dialog */ $once = true; foreach($_POST as $name => $value){ @@ -146,9 +183,8 @@ class department extends plugin }else{ $tmp = array(); foreach($bases as $dn=>$base){ - $fixed = str_replace("/","\\",$this->dn); /* Only attach departments which are not a subtree of this one */ - if(!preg_match("/".$fixed."/",$dn)){ + if(!preg_match("/".preg_quote($this->dn)."/",$dn)){ $tmp[$dn]=$base; } } @@ -162,12 +198,27 @@ class department extends plugin /* Set admin unit flag */ if ($this->is_administrational_unit) { - $smarty->assign("unitTag", "checked"); + $smarty->assign("gosaUnitTag", "checked"); } else { - $smarty->assign("unitTag", ""); + $smarty->assign("gosaUnitTag", ""); } - return($smarty->fetch (get_template_path('generic.tpl', TRUE))); + $smarty->assign("dep_type",$this->type); + + + $dep_types = departmentManagement::get_support_departments(); + $tpl =""; + foreach($dep_types as $key => $data){ + if($data['OC'] == $this->type){ + $tpl = $data['TPL']; + break; + } + } + if($tpl == "") { + trigger_error("No template specified for container type '".$this->type."', please update epartmentManagement::get_support_departments()."); + $tpl = "generic.tpl"; + } + return($smarty->fetch (get_template_path($tpl, TRUE))); } function clear_fields() @@ -184,7 +235,7 @@ class department extends plugin { $ldap= $this->config->get_ldap_link(); $ldap->cd ($this->dn); - $ldap->recursive_remove(); + $ldap->rmdir_recursive($this->dn); new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); if (!$ldap->success()){ msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); @@ -199,16 +250,15 @@ class department extends plugin return $this->must_be_tagged; } - function am_i_moved() - { - return $this->rec_cpy; - } - - /* Save data to object */ function save_object() { - if (isset($_POST['dep_generic_posted'])){ + if (isset($_POST['dep_generic_posted'])){ + + $nA = $this->namingAttr; + $old_nA = $this->$nA; + + /* Create a base backup and reset the base directly after calling plugin::save_object(); @@ -226,13 +276,20 @@ class department extends plugin } /* Save tagging flag */ - if ($this->acl_is_writeable("unitTag")){ - if (isset($_POST['unitTag'])){ + if ($this->acl_is_writeable("gosaUnitTag")){ + if (isset($_POST['is_administrational_unit'])){ $this->is_administrational_unit= true; } else { $this->is_administrational_unit= false; } } + + /* If this is the root directory service entry then avoid + changing the naming attribute of this entry. + */ + if($this->dn == $this->config->current['BASE']){ + $this->$nA = $old_nA; + } } } @@ -248,17 +305,15 @@ class department extends plugin $ldap->ls ("(&(ou=".$this->ou.")(objectClass=organizationalUnit))", $this->base, array('dn')); if ($this->orig_dn == "new" && $ldap->count()){ $message[]= msgPool::duplicated(_("Name")); - } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){ + } elseif ($this->orig_dn != $this->dn && $ldap->count()){ $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")); } @@ -276,7 +331,15 @@ class department extends plugin $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/"); } - return $message; + /* 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; } @@ -285,6 +348,11 @@ class department extends plugin { $ldap= $this->config->get_ldap_link(); + /* Ensure that ou is saved too, it is required by objectClass gosaDepartment + */ + $nA = $this->namingAttr; + $this->ou = $this->$nA; + /* Add tag objects if needed */ if ($this->is_administrational_unit){ @@ -325,31 +393,24 @@ class department extends plugin plugin::save(); /* Remove tag information if needed */ - if (!$this->is_administrational_unit){ + if (!$this->is_administrational_unit && $this->initially_was_tagged){ $tmp= array(); /* Remove gosaAdministrativeUnit from this plugin */ foreach($this->attrs['objectClass'] as $oc){ + if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){ + continue; + } if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){ $tmp[]= $oc; } } $this->attrs['objectClass']= $tmp; - } - - /* Do we need to remove the tag itself? */ - $has_unit_tag= false; - foreach($this->attrs['objectClass'] as $oc){ - if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){ - $has_unit_tag= true; - } - } - if ($has_unit_tag == false && $this->is_administrational_unit == false){ $this->attrs['gosaUnitTag']= array(); - } else { - $this->attrs['gosaUnitTag']= $this->gosaUnitTag; + $this->gosaUnitTag = ""; } + /* Write back to ldap */ $ldap->cat($this->dn, array('dn')); $ldap->cd($this->dn); @@ -378,24 +439,6 @@ class department extends plugin } - function ShowMoveFrame() - { - $smarty = get_smarty(); - $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove"); - $smarty->assign("message","As soon as the move operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog."); - $display= $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE)); - return($display); - } - - function ShowTagFrame() - { - $smarty = get_smarty(); - $smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment"); - $smarty->assign("message","As soon as the tag operation has finished, you can scroll down to end of the page and press the 'Continue' button to continue with the department management dialog."); - $display= $smarty->fetch(get_template_path("dep_iframe.tpl",TRUE)); - return($display); - } - /* Tag objects to have the gosaAdministrativeUnitTag */ function tag_objects($OnlySetTagFlag = false) { @@ -411,7 +454,7 @@ class department extends plugin
'; - echo "'; - echo ""; + echo "
'; + echo '
'; - echo ""; + echo ""; - echo "" ; - echo ""; + echo "" ; + echo ""; - return (TRUE); - } - } + return (TRUE); + } /* Return plugin informations for acl handling */ @@ -577,21 +611,22 @@ class department extends plugin "plSelfModify" => FALSE, "plPriority" => 0, "plDepends" => array(), - "plSection" => array("admin"), + "plSection" => array("administration"), "plCategory" => array("department" => array("objectClass" => "gosaDepartment", "description" => _("Departments"))), "plProvidedAcls" => array( - "description" => _("Description"), - "c" => _("Country"), - "base" => _("Base"), - "l" => _("Location"), - "telephoneNumber" => _("Telephone"), "ou" => _("Department name"), + "description" => _("Description"), "businessCategory" => _("Category"), + "base" => _("Base"), + "st" => _("State"), + "l" => _("Location"), "postalAddress" => _("Address"), - "gosaUnitTag" => _("Administrative settings"), - "facsimileTelephoneNumber" => _("Fax")) + "telephoneNumber" => _("Telephone"), + "facsimileTelephoneNumber" => _("Fax"), + + "gosaUnitTag" => _("Administrative settings")) )); } @@ -615,7 +650,7 @@ class department extends plugin } /* This one matches with the latter part. Break and don't fix this entry */ - if (preg_match('/(^|,)'.normalizePreg($key).'$/', $dn)){ + if (preg_match('/(^|,)'.preg_quote($key, '/').'$/', $dn)){ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging"); $relevant[strlen($key)]= $ntag; continue; @@ -642,14 +677,14 @@ class department extends plugin $attrs= $ldap->fetch(); if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ if ($show) { - echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."