X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=gosa-core%2Fplugins%2Fadmin%2Fdepartments%2Fclass_departmentGeneric.inc;h=b3c8819e37d164da25dcdc2e26b0e6ed5a9ef8ee;hb=aef3764e59812f70fa8345505c4cdcf22bb4ebb0;hp=429b454f23f2751892d9633f1387ca5ba988f664;hpb=ede91cea993d38464d47f6ef573ed70ce2cec357;p=gosa.git diff --git a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc index 429b454f2..b3c8819e3 100644 --- a/gosa-core/plugins/admin/departments/class_departmentGeneric.inc +++ b/gosa-core/plugins/admin/departments/class_departmentGeneric.inc @@ -1,21 +1,23 @@ assign("base_select", $this->base); /* Set admin unit flag */ - $smarty->assign("UnitTagDiabled",$this->UnitTagDiabled); - if(!$this->UnitTagDiabled){ - if ($this->is_administrational_unit) { - $smarty->assign("unitTag", "checked"); - } else { - $smarty->assign("unitTag", ""); - } + if ($this->is_administrational_unit) { + $smarty->assign("unitTag", "checked"); + } else { + $smarty->assign("unitTag", ""); } return($smarty->fetch (get_template_path('generic.tpl', TRUE))); @@ -194,7 +182,9 @@ class department extends plugin $ldap->cd ($this->dn); $ldap->recursive_remove(); new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); - show_ldap_error($ldap->get_error(), sprintf(_("Removing of department with dn '%s' failed."),$this->dn)); + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, LDAP_DEL, get_class())); + } /* Optionally execute a command after we're done */ $this->handle_post_events('remove'); @@ -205,12 +195,6 @@ class department extends plugin return $this->must_be_tagged; } - function am_i_moved() - { - return $this->rec_cpy; - } - - /* Save data to object */ function save_object() { @@ -232,13 +216,11 @@ class department extends plugin } /* Save tagging flag */ - if(!$this->UnitTagDiabled){ - if ($this->acl_is_writeable("unitTag")){ - if (isset($_POST['unitTag'])){ - $this->is_administrational_unit= true; - } else { - $this->is_administrational_unit= false; - } + if ($this->acl_is_writeable("unitTag")){ + if (isset($_POST['unitTag'])){ + $this->is_administrational_unit= true; + } else { + $this->is_administrational_unit= false; } } } @@ -255,31 +237,31 @@ class department extends plugin $ldap= $this->config->get_ldap_link(); $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."); + $message[]= msgPool::duplicated(_("Name")); + } 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")); } - 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(tests::is_department_name_reserved($this->ou,$this->base)){ + $message[]= msgPool::reserved(_("Name")); } if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){ - $message[]= _("The field 'Name' contains invalid characters."); + $message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/"); } - if (!is_phone_nr($this->telephoneNumber)){ - $message[]= _("The field 'Phone' contains an invalid phone number."); + if (!tests::is_phone_nr($this->telephoneNumber)){ + $message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/"); } - if (!is_phone_nr($this->facsimileTelephoneNumber)){ - $message[]= _("The field 'Fax' contains an invalid phone number."); + if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){ + $message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/"); } return $message; @@ -291,79 +273,71 @@ class department extends plugin { $ldap= $this->config->get_ldap_link(); - if(!$this->UnitTagDiabled){ - - /* Add tag objects if needed */ - if ($this->is_administrational_unit){ + /* Add tag objects if needed */ + if ($this->is_administrational_unit){ - /* If this wasn't tagged before add oc an reset unit tag */ - if(!$this->initially_was_tagged){ - $this->objectclasses[]= "gosaAdministrativeUnit"; - $this->gosaUnitTag= ""; + /* If this wasn't tagged before add oc an reset unit tag */ + if(!$this->initially_was_tagged){ + $this->objectclasses[]= "gosaAdministrativeUnit"; + $this->gosaUnitTag= ""; - /* It seams that this method is called twice, - set this to true. to avoid adding this oc twice */ - $this->initially_was_tagged = true; - } + /* It seams that this method is called twice, + set this to true. to avoid adding this oc twice */ + $this->initially_was_tagged = true; + } - if ($this->gosaUnitTag == ""){ + if ($this->gosaUnitTag == ""){ - /* It's unlikely, but check if already used... */ - $try= 5; - $ldap->cd($this->config->current['BASE']); - while ($try--){ + /* 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); + /* 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; - } + $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); } + if($try == 0) { + msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG); + return; + } + $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); } } - plugin::save(); + $this->skipTagging = TRUE; + plugin::save(); - if(!$this->UnitTagDiabled){ - /* Remove tag information if needed */ - if (!$this->is_administrational_unit){ - $tmp= array(); + /* Remove tag information if needed */ + if (!$this->is_administrational_unit && $this->initially_was_tagged){ + $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; - } + /* Remove gosaAdministrativeUnit from this plugin */ + $has_unit_tag= false; + foreach($this->attrs['objectClass'] as $oc){ + if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){ + $tmp[]= $oc; } - $this->attrs['objectClass']= $tmp; - - if(!$has_unit_tag && isset($this->attrs['gosaUnitTag'])){ - $this->attrs['gosaUnitTag']= array(); + if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){ + $has_unit_tag= true; } - $this->gosaUnitTag = ""; } + $this->attrs['objectClass']= $tmp; + $this->attrs['gosaUnitTag']= array(); + $this->gosaUnitTag = ""; } + /* 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)){ + if ($ldap->count()){ $this->cleanup(); $ldap->modify ($this->attrs); new log("modify","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); @@ -373,19 +347,13 @@ class department extends plugin $this->handle_post_events('add'); new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error()); } - show_ldap_error($ldap->get_error(), sprintf(_("Saving of department with dn '%s' failed."),$this->dn)); - - - if(!$this->UnitTagDiabled){ - /* 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(); - } + if (!$ldap->success()){ + msg_dialog::display(_("LDAP error"), msgPool::ldaperror($ldap->get_error(), $this->dn, 0, get_class())); } + + /* The parameter forces only to set must_be_tagged, and don't touch any objects + This will be done later */ + $this->tag_objects(true); /* Optionally execute a command after we're done */ $this->postcreate(); @@ -393,24 +361,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) { @@ -429,53 +379,61 @@ class department extends plugin echo "
'; + $this->must_be_tagged = FALSE; + echo '
'; echo ""; + echo "" ; } } @@ -483,101 +441,84 @@ class department extends plugin /* 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; - }else{ - - /* If this is called, but not wanted, abort */ - if(!$this->rec_cpy){ - return; - } - - $src_dn = $this->rec_src; - $dst_dn = $this->rec_dst; - - /* Print header to have styles included */ - $smarty= get_smarty(); - - echo ' - - -
'; + echo '
'; - echo ""; + echo ""; - echo "" ; - echo ""; + echo "" ; + echo ""; - return (TRUE); - } - } + return (TRUE); + } /* Return plugin informations for acl handling */ @@ -605,6 +546,157 @@ class department extends plugin "facsimileTelephoneNumber" => _("Fax")) )); } + + function handle_object_tagging($dn= "", $tag= "", $show= false) + { + /* No dn? Self-operation... */ + if ($dn == ""){ + $dn= $this->dn; + + /* No tag? Find it yourself... */ + if ($tag == ""){ + $len= strlen($dn); + + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "No tag for $dn - looking for one...", "Tagging"); + $relevant= array(); + foreach ($this->config->adepartments as $key => $ntag){ + + /* This one is bigger 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).'$/', $dn)){ + @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, "DEBUG: Possibly relevant: $key", "Tagging"); + $relevant[strlen($key)]= $ntag; + continue; + } + + } + + /* If we've some relevant tags to set, just get the longest one */ + if (count($relevant)){ + ksort($relevant); + $tmp= array_keys($relevant); + $idx= end($tmp); + $tag= $relevant[$idx]; + $this->gosaUnitTag= $tag; + } + } + } + + /* Set tag? */ + if ($tag != ""){ + /* Set objectclass and attribute */ + $ldap= $this->config->get_ldap_link(); + $ldap->cat($dn, array('gosaUnitTag', 'objectClass')); + $attrs= $ldap->fetch(); + if(isset($attrs['gosaUnitTag'][0]) && $attrs['gosaUnitTag'][0] == $tag){ + if ($show) { + echo sprintf(_("Object '%s' is already tagged"), @LDAP::fix($dn))."