X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fdepartments%2Fclass_departmentGeneric.inc;h=5205da94447f99145248934c108fc8bb617b3a91;hb=99b0a430dfa6d1cfad04ccf0302e1fbff0b02e28;hp=d062799a86c9965c270cdb449cf1ba78d6c1dfe2;hpb=276650eae5da9b54f28f59419c5e19278a47a9ef;p=gosa.git diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index d062799a8..5205da944 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -31,23 +31,22 @@ class department extends plugin var $telephoneNumber= ""; var $facsimileTelephoneNumber= ""; var $orig_dn= ""; + var $is_administrational_unit= false; + var $gosaUnitTag= ""; var $rec_dst=false; // Destination for recursive move var $rec_src=false; // Source for recursive move var $rec_cpy=false; // Is recursive move requested ? - function am_i_moved() - { - return $this->rec_cpy; - } - /* 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"); + "telephoneNumber", "facsimileTelephoneNumber", "gosaUnitTag"); var $objectclasses= array("top", "gosaDepartment", "organizationalUnit"); function department ($config, $dn) @@ -63,18 +62,24 @@ class department extends plugin /* Set base */ if ($this->dn == "new"){ $ui= get_userinfo(); - if(isset($_SESSION['depfilter']['depselect'])){ - $this->base = $_SESSION['depfilter']['depselect']; + if(isset($_SESSION['CurrentMainBase'])){ + $this->base= $_SESSION['CurrentMainBase']; }else{ $this->base= dn2base($ui->dn); } } else { $this->base= preg_replace ("/^[^,]+,/", "", $this->dn); } + /* set permissions */ $ui= get_userinfo(); $acl= get_permissions ($ui->dn, $ui->subtreeACL); $this->acl= get_module_permission($acl, "department", $ui->dn); + + /* Is administrational Unit? */ + if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){ + $this->is_administrational_unit= true; + } } function execute() @@ -83,11 +88,10 @@ class department extends plugin plugin::execute(); /* Reload departments */ - $this->config->departments= get_departments($this->dn); + $this->config->get_departments($this->dn); $this->config->make_idepartments(); $smarty= get_smarty(); - /* Base select dialog */ $once = true; foreach($_POST as $name => $value){ @@ -133,7 +137,17 @@ 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 */ + if ($this->is_administrational_unit) { + $smarty->assign("unitTag", "checked"); + } else { + $smarty->assign("unitTag", ""); + } + $smarty->assign("unitTag"."ACL", chkacl($this->acl, "unitTag")); + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); } @@ -148,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() @@ -170,6 +194,15 @@ class department extends plugin if (chkacl($this->acl, "create") == ""){ $this->base= $_POST['base']; } + + /* Save tagging flag */ + if (chkacl($this->acl, "unitTag") == ""){ + if (isset($_POST['unitTag'])){ + $this->is_administrational_unit= true; + } else { + $this->is_administrational_unit= false; + } + } } } @@ -177,7 +210,8 @@ class department extends plugin /* Check values */ function check() { - $message= array(); + /* Call common method to give check the hook */ + $message= plugin::check(); /* Permissions for that base? */ // $this->dn= "ou=$this->ou,".$this->base; @@ -187,8 +221,8 @@ class department extends plugin /* Check for presence of this department */ $ldap= $this->config->get_ldap_link(); - $attrs= $ldap->cat ($this->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."); @@ -202,11 +236,10 @@ class department extends plugin $message[]= _("Required field 'Description' is not set."); } - /* Validate and modify - or: spaghetti rules! */ - if ($this->ou == "incoming"){ - $message[]= _("The field 'Name' contains the reserved word 'incoming'.". - " Please choose another 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."); } @@ -224,13 +257,68 @@ class department extends plugin /* Save to LDAP */ function save() { + $ldap= $this->config->get_ldap_link(); + + /* Add tag objects if needed */ + if ($this->is_administrational_unit){ + if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){ + $this->objectclasses[]= "gosaAdministrativeUnit"; + $this->gosaUnitTag= ""; + } + + if ($this->gosaUnitTag == ""){ + + /* 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); + + $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; + } + $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); + } + } + plugin::save(); + /* 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; + } + } + $this->attrs['objectClass']= $tmp; + + 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); + $ldap->cat($this->dn, array('dn')); $a= $ldap->fetch(); $ldap->cd($this->dn); + if (count($a)){ $this->cleanup(); $ldap->modify ($this->attrs); @@ -240,29 +328,114 @@ class department extends plugin $ldap->add($this->attrs); $this->handle_post_events('add'); } - show_ldap_error($ldap->get_error()); - - /* 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($OnlySetTagFlag = false) + { + if(!$OnlySetTagFlag){ + $smarty= get_smarty(); + echo "".$smarty->fetch(get_template_path('headers.tpl')); + 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')); + } else { + $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn')); + } + + while ($attrs= $ldap->fetch()){ + + /* Skip self */ + if ($attrs['dn'] == $this->dn){ + continue; + } + + /* Check for confilicting administrative units */ + $fix= true; + foreach ($this->config->adepartments as $key => $tag){ + /* This one is shorter than our dn, its not relevant... */ + if ($len >= strlen($key)){ + continue; + } + + /* This one matches with the latter part. Break and don't fix this entry */ + if (preg_match('/(^|,)'.normalizePreg($key).'$/', $attrs['dn'])){ + $fix= false; + break; + } + } + + /* Fix entry if needed */ + if ($fix){ + if($OnlySetTagFlag){ + $this->must_be_tagged =true; + return; + } + $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); + } + } + 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; } @@ -275,21 +448,21 @@ class department extends plugin echo "".$smarty->fetch(get_template_path('headers.tpl')); echo ""; - echo "

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

"; + 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(); /* Check if destination exists - abort */ - $ldap->cat($dst_dn); + $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 "Recursive_move :$dst_dn already exists.
"; + 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); @@ -306,15 +479,15 @@ 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
"; - + echo ""._("Object").": ".@LDAP::fix($src)."
"; + if (!$this->copy($src, $dst)){ - echo "
".sprintf(_("FAILED to copy %s, aborting operation"),$src)."
"; + echo "
".sprintf(_("FAILED to copy %s, aborting operation"),@LDAP::fix($src))."
"; return (FALSE); } @@ -334,12 +507,10 @@ class department extends plugin "; echo ""; - + return (TRUE); } } - - } - +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>