X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=plugins%2Fadmin%2Fdepartments%2Fclass_departmentGeneric.inc;h=9aecbccdff2cb3d39578dc59596a449b74e37625;hb=206abcab698395b6c61297782e8c304c4e77dc56;hp=3b50131dba4363bf2a9b8c43be0c183689176952;hpb=c1e278e85a5ff75ebc17b49a33392db4535491a9;p=gosa.git diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index 3b50131db..9aecbccdf 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -16,189 +16,519 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ + */ class department extends plugin { - /* department attributes */ - var $ou= ""; - var $description= ""; - var $base= ""; - var $st= ""; - var $l= ""; - var $postalAddress= ""; - var $businessCategory= ""; - var $telephoneNumber= ""; - var $facsimileTelephoneNumber= ""; - var $orig_dn= ""; - - /* Headpage attributes */ - var $last_dep_sorting= "invalid"; - var $departments= array(); - - /* attribute list for save action */ - var $attributes= array("ou", "description", "businessCategory", "st", "l", "postalAddress", - "telephoneNumber", "facsimileTelephoneNumber"); - var $objectclasses= array("top", "gosaDepartment", "organizationalUnit"); - - function department ($config, $dn) - { - plugin::plugin($config, $dn); - $this->is_account= TRUE; - $this->ui= get_userinfo(); - $this->dn= $dn; - $this->orig_dn= $dn; - $this->config= $config; - - /* Set base */ - if ($this->dn == "new"){ + /* department attributes */ + var $ou= ""; + var $description= ""; + var $base= ""; + var $st= ""; + var $l= ""; + var $postalAddress= ""; + var $businessCategory= ""; + 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 ? + + /* 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"); + + function department ($config, $dn) + { + + plugin::plugin($config, $dn); + $this->is_account= TRUE; + $this->ui= get_userinfo(); + $this->dn= $dn; + $this->orig_dn= $dn; + $this->config= $config; + + /* Set base */ + if ($this->dn == "new"){ + $ui= get_userinfo(); + 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(); - if(isset($_SESSION['depfilter']['depselect'])){ - $this->base = $_SESSION['depfilter']['depselect']; + $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() + { + /* Call parent execute */ + plugin::execute(); + + /* Reload departments */ + $this->config->get_departments($this->dn); + $this->config->make_idepartments(); + $smarty= get_smarty(); + + /* Base select dialog */ + $once = true; + foreach($_POST as $name => $value){ + if(preg_match("/^chooseBase/",$name) && $once){ + $once = false; + $this->dialog = new baseSelectDialog($this->config); + $this->dialog->setCurrentBase($this->base); + } + } + + /* Dialog handling */ + if(is_object($this->dialog)){ + /* Must be called before save_object */ + $this->dialog->save_object(); + + if($this->dialog->isClosed()){ + $this->dialog = false; + }elseif($this->dialog->isSelected()){ + $this->base = $this->dialog->isSelected(); + $this->dialog= false; + }else{ + return($this->dialog->execute()); + } + } + + /* Hide all departments, that are subtrees of this department */ + $bases = $this->config->idepartments; + if(($this->dn == "new")||($this->dn == "")){ + $tmp = $bases; }else{ - $this->base= dn2base($ui->dn); + $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)){ + $tmp[$dn]=$base; + } + } } - } else { - $this->base= preg_replace ("/^[^,]+,/", "", $this->dn); - } - } + $smarty->assign("bases", $tmp); - function execute() - { - /* Reload departments */ - $this->config->departments= get_departments($this->dn); - $this->config->make_idepartments(); - $smarty= get_smarty(); - - /* Hide all departments, that are subtrees of this department */ - $bases = $this->config->idepartments; - $tmp = array(); - foreach($bases as $dn=>$base){ - - /* Only attach departments which are not a subtree of this one */ - if(!preg_match("/".$this->dn."/",$dn)){ - $tmp[$dn]=$base; + foreach ($this->attributes as $val){ + $smarty->assign("$val", $this->$val); + $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); } - } - $smarty->assign("bases", $tmp); + $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")); - foreach ($this->attributes as $val){ - $smarty->assign("$val", $this->$val); - $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); + return($smarty->fetch (get_template_path('generic.tpl', TRUE))); } - $smarty->assign("base_select", $this->base); - return($smarty->fetch (get_template_path('generic.tpl', TRUE))); - } - function clear_fields() - { - $this->dn= ""; - $this->base= ""; - $this->acl= "#none#"; + function clear_fields() + { + $this->dn= ""; + $this->base= ""; + $this->acl= "#none#"; - foreach ($this->attributes as $val){ - $this->$val= ""; + foreach ($this->attributes as $val){ + $this->$val= ""; + } } - } + 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")); - function remove_from_parent() - { - $ldap= $this->config->get_ldap_link(); - $ldap->cd ($this->dn); - $ldap->recursive_remove(); + /* Optionally execute a command after we're done */ + $this->handle_post_events('remove'); + } - /* 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() - { - if (isset($_POST['base'])){ - plugin::save_object(); - /* Save base, since this is no LDAP attribute */ - if (chkacl($this->acl, "create") == ""){ - $this->base= $_POST['base']; + /* Save data to object */ + function save_object() + { + if (isset($_POST['base'])){ + plugin::save_object(); + + /* Save base, since this is no LDAP attribute */ + 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; + } + } } } - } - /* Check values */ - function check() - { - $message= array(); - - /* Permissions for that base? */ - $this->dn= "ou=$this->ou,".$this->base; - $acl= get_permissions ($this->dn, $this->ui->subtreeACL); - $acl= get_module_permission($acl, "department", $this->dn); - if (chkacl($acl, "create") != ""){ - $message[]= _("You have no permissions to create a department on this 'Base'."); - } + /* Check values */ + function check() + { + /* Call common method to give check the hook */ + $message= plugin::check(); - /* Check for presence of this department */ - $ldap= $this->config->get_ldap_link(); - $attrs= $ldap->cat ($this->dn); - if ($this->orig_dn == "new" && !($attrs === FALSE)){ - $message[]= _("Department with that 'Name' already exists."); - } elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){ - $message[]= _("Department with that 'Name' already exists."); - } + /* Permissions for that base? */ + if (chkacl($this->acl, "create") != ""){ + $message[]= _("You have no permissions to create a department on this 'Base'."); + } - /* All required fields are set? */ - if ($this->ou == ""){ - $message[]= _("Required field 'Name' is not set."); - } - if ($this->description == ""){ - $message[]= _("Required field 'Description' is not set."); - } + /* Check for presence of this department */ + $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."); + } - /* Validate and modify - or: spaghetti rules! */ - if ($this->ou == "incoming"){ - $message[]= _("The field 'Name' contains the reserved word 'incoming'.". - " Please choose another name."); - } - if (preg_match ('/[,#+:=>\\\\]/', $this->ou)){ - $message[]= _("The field 'Name' contains invalid characters."); - } - if (!is_phone_nr($this->telephoneNumber)){ - $message[]= _("The field 'Phone' contains an invalid phone number."); + /* All required fields are set? */ + if ($this->ou == ""){ + $message[]= _("Required field 'Name' is not set."); + } + if ($this->description == ""){ + $message[]= _("Required field 'Description' is not set."); + } + + 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."); + } + if (!is_phone_nr($this->telephoneNumber)){ + $message[]= _("The field 'Phone' contains an invalid phone number."); + } + if (!is_phone_nr($this->facsimileTelephoneNumber)){ + $message[]= _("The field 'Fax' contains an invalid phone number."); + } + + return $message; } - if (!is_phone_nr($this->facsimileTelephoneNumber)){ - $message[]= _("The field 'Fax' contains an invalid phone number."); + + + /* 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, array('dn')); + $a= $ldap->fetch(); + $ldap->cd($this->dn); + + if (count($a)){ + $this->cleanup(); + $ldap->modify ($this->attrs); + + $this->handle_post_events('modify'); + } else { + $ldap->add($this->attrs); + $this->handle_post_events('add'); + } + 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); } - return $message; - } + 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); + } - /* Save to LDAP */ - function save() + function ShowTagFrame() { - plugin::save(); - - /* Write back to ldap */ - $ldap= $this->config->get_ldap_link(); - $ldap->cat($this->dn); - $a= $ldap->fetch(); - $ldap->cd($this->dn); - if (count($a)){ - $ldap->modify($this->attrs); - $this->handle_post_events('modify'); - } else { - $ldap->add($this->attrs); - $this->handle_post_events('add'); + $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(); + + /* Print out html introduction */ + echo ' + +
+'; + echo ""; + } } - show_ldap_error($ldap->get_error()); - /* Optionally execute a command after we're done */ - $this->postcreate(); - } -} + /* 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(); + + /* Print out html introduction */ + echo ' + + +
'; + + echo ""; + + echo "" ; + echo ""; + + return (TRUE); + } + } +} +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?>