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(); $this->base= dn2base($ui->dn); } else { $this->base= preg_replace ("/^[^,]+,/", "", $this->dn); } } function execute() { /* Reload departments */ $this->config->departments= get_departments($this->dn); $this->config->make_idepartments(); $smarty= get_smarty(); /* Show main page */ $smarty->assign("bases", $this->config->idepartments); foreach ($this->attributes as $val){ $smarty->assign("$val", $this->$val); $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); } $smarty->assign("bases", $this->config->idepartments); $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#"; foreach ($this->attributes as $val){ $this->$val= ""; } } 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'); } /* 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']; } } } /* 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 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."); } /* 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."); } /* 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."); } if (!is_phone_nr($this->facsimileTelephoneNumber)){ $message[]= _("The field 'Fax' contains an invalid phone number."); } return $message; } /* Save to LDAP */ function save() { 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'); } show_ldap_error($ldap->get_error()); /* Optionally execute a command after we're done */ $this->postcreate(); } } ?>