X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fdepartments%2Fclass_departmentGeneric.inc;h=9aecbccdff2cb3d39578dc59596a449b74e37625;hb=206abcab698395b6c61297782e8c304c4e77dc56;hp=3d11f25d76902769bc729ca94b4bb2720a4b6034;hpb=7d2905fd34185cf189c2071eb8f5ddec4248f77d;p=gosa.git diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index 3d11f25d7..9aecbccdf 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -42,6 +42,8 @@ class department extends plugin 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"); @@ -135,6 +137,7 @@ class department extends plugin $smarty->assign("$val", $this->$val); $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); } + $smarty->assign("baseACL", chkacl($this->acl,"base")); $smarty->assign("base_select", $this->base); /* Set admin unit flag */ @@ -144,7 +147,7 @@ class department extends plugin $smarty->assign("unitTag", ""); } $smarty->assign("unitTag"."ACL", chkacl($this->acl, "unitTag")); - + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); } @@ -159,17 +162,27 @@ class department extends plugin } } - function remove_from_parent() { $ldap= $this->config->get_ldap_link(); $ldap->cd ($this->dn); $ldap->recursive_remove(); + show_ldap_error($ldap->get_error(), _("Removing department failed")); /* Optionally execute a command after we're done */ $this->handle_post_events('remove'); } + function must_be_tagged() + { + return $this->must_be_tagged; + } + + function am_i_moved() + { + return $this->rec_cpy; + } + /* Save data to object */ function save_object() @@ -201,15 +214,14 @@ class department extends plugin $message= plugin::check(); /* Permissions for that base? */ - // $this->dn= "ou=$this->ou,".$this->base; if (chkacl($this->acl, "create") != ""){ $message[]= _("You have no permissions to create a department on this 'Base'."); } /* Check for presence of this department */ $ldap= $this->config->get_ldap_link(); - $attrs= $ldap->cat ($this->dn, array('dn')); - if ($this->orig_dn == "new" && !($attrs === FALSE)){ + $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."); } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){ $message[]= _("Department with that 'Name' already exists."); @@ -223,19 +235,11 @@ 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)){ + if (preg_match ('/["+>\\\\]/', $this->ou)){ $message[]= _("The field 'Name' contains invalid characters."); } if (!is_phone_nr($this->telephoneNumber)){ @@ -256,7 +260,11 @@ class department extends plugin /* Add tag objects if needed */ if ($this->is_administrational_unit){ - $this->objectclasses[]= "gosaAdministrativeUnit"; + if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){ + $this->objectclasses[]= "gosaAdministrativeUnit"; + $this->gosaUnitTag= ""; + } + if ($this->gosaUnitTag == ""){ /* It's unlikely, but check if already used... */ @@ -279,8 +287,6 @@ class department extends plugin } $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); } - } else { - $this->gosaUnitTag= ""; } plugin::save(); @@ -290,23 +296,28 @@ class department extends plugin $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; + } } $this->attrs['objectClass']= $tmp; - if(isset($this->attrs['gosaUnitTag'])){ + + if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){ $this->attrs['gosaUnitTag']= array(); } } - + /* Write back to ldap */ $ldap= $this->config->get_ldap_link(); $ldap->cat($this->dn, array('dn')); $a= $ldap->fetch(); $ldap->cd($this->dn); - + if (count($a)){ $this->cleanup(); $ldap->modify ($this->attrs); @@ -316,27 +327,72 @@ class department extends plugin $ldap->add($this->attrs); $this->handle_post_events('add'); } - show_ldap_error($ldap->get_error()); - $this->tag_objects(); - - /* Optionally execute a command after we're done */ + show_ldap_error($ldap->get_error(), _("Saving department failed")); + + /* The parameter forces only to set must_be_tagged, and don't touch any objects + This will be done later */ + $this->tag_objects(true); + + /* Fix tagging if needed */ + if (!$this->is_administrational_unit){ + $this->handle_object_tagging(); + } + + /* Optionally execute a command after we're done */ $this->postcreate(); + return(true); } + 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() + function tag_objects($OnlySetTagFlag = false) { + if(!$OnlySetTagFlag){ + $smarty= get_smarty(); + + /* Print out html introduction */ + echo ' + + + + + + + + '; + + echo "

".sprintf(_("Tagging '%s'."),"".@LDAP::fix($this->dn)."")."

"; + } + $add= $this->is_administrational_unit; $len= strlen($this->dn); $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); if ($add){ $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='. - $this->gosaUnitTag.')))', array('dn')); + $this->gosaUnitTag.')))', array('dn')); } else { $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn')); } + while ($attrs= $ldap->fetch()){ /* Skip self */ @@ -358,32 +414,38 @@ class department extends plugin break; } } - - /* Fix entry if needed */ - if ($fix){ - $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag); + + /* Fix entry if needed */ + if ($fix){ + if($OnlySetTagFlag){ + $this->must_be_tagged =true; + return; + } + $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); + echo "" ; } } + if(!$OnlySetTagFlag){ + echo '

 

'; + echo "
+
+
"; + } } /* Move/Rename complete trees */ function recursive_move($src_dn, $dst_dn,$force = false) { + /* If force == false prepare to recursive move this object from src to dst + on the next call. */ if(!$force){ - $this->rec_cpy = true; $this->rec_src = $src_dn; $this->rec_dst = $dst_dn; - - $smarty = get_smarty(); - - $smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove"); - - $display= $smarty->fetch(get_template_path("recursive_move.tpl",TRUE)); - return($display); - exit(); }else{ + + /* If this is called, but not wanted, abort */ if(!$this->rec_cpy){ return; } @@ -393,11 +455,19 @@ class department extends plugin /* Print header to have styles included */ $smarty= get_smarty(); - echo "".$smarty->fetch(get_template_path('headers.tpl')); - echo ""; - echo "

".sprintf(_("Moving '%s' to '%s'"),"".$src_dn."","".$dst_dn."")."

"; + /* Print out html introduction */ + echo ' + + + + + + + + '; + echo "

".sprintf(_("Moving '%s' to '%s'"),"".@LDAP::fix($src_dn)."","".@LDAP::fix($dst_dn)."")."

"; /* Check if the destination entry exists */ $ldap= $this->config->get_ldap_link(); @@ -405,12 +475,12 @@ class department extends plugin /* Check if destination exists - abort */ $ldap->cat($dst_dn, array('dn')); if ($ldap->fetch()){ - trigger_error("Recursive_move $dst_dn already exists.", + trigger_error("Recursive_move ".@LDAP::fix($dst_dn)." already exists.", E_USER_WARNING); - echo sprintf_("Recursive_move: '%s' already exists.")."
", $dst_dn); + echo sprintf("Recursive_move: '%s' already exists", @LDAP::fix($dst_dn))."
"; return (FALSE); } - + /* Perform a search for all objects to be moved */ $objects= array(); $ldap->cd($src_dn); @@ -426,19 +496,18 @@ class department extends plugin /* Copy objects from small to big indent levels by replacing src_dn by dst_dn */ foreach ($objects as $object => $len){ - - $src= str_replace("\\","\\\\",$object); $dst= preg_replace("/".str_replace("\\","\\\\",$src_dn)."$/", "$dst_dn", $object); $dst= str_replace($src_dn,$dst_dn,$object); - echo ""._("Object").": $src
"; - - if (!$this->copy($src, $dst)){ - echo "
".sprintf(_("FAILED to copy %s, aborting operation"),$src)."
"; + echo ""._("Object").": ".@LDAP::fix($src)."
"; + + if (!$this->copy($src, $dst)){ + echo "
".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."
"; return (FALSE); } + echo "" ; flush(); } @@ -454,17 +523,12 @@ class department extends plugin
"; + echo "" ; echo ""; - + return (TRUE); } } - - function am_i_moved() - { - return $this->rec_cpy; - } - } - +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>