is_account= TRUE;
$this->ui= get_userinfo();
$this->dn= $dn;
$this->orig_dn= $dn;
$this->orig_ou= $this->ou;
$this->config= $config;
/* Set base */
if ($this->dn == "new"){
$ui= get_userinfo();
if(session::is_set('CurrentMainBase')){
$this->base = session::get('CurrentMainBase');
}else{
$this->base= dn2base($ui->dn);
}
} else {
$this->base= preg_replace ("/^[^,]+,/", "", $this->dn);
}
$this->orig_base = $this->base;
/* Is administrational Unit? */
if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){
$this->is_administrational_unit= true;
$this->initially_was_tagged = true;
}
}
function execute()
{
echo __FUNCTION__."
";
/* Call parent execute */
plugin::execute();
/* Log view */
if($this->is_account && !$this->view_logged){
$this->view_logged = TRUE;
new log("view","department/".get_class($this),$this->dn);
}
/* Reload departments */
$this->config->get_departments($this->dn);
$this->config->make_idepartments();
$smarty= get_smarty();
$tmp = $this->plInfo();
foreach($tmp['plProvidedAcls'] as $name => $translation){
$smarty->assign($name."ACL",$this->getacl($name));
}
/* Base select dialog */
$once = true;
foreach($_POST as $name => $value){
if((preg_match("/^chooseBase/",$name) && $once) && ($this->acl_is_moveable())){
$once = false;
$this->dialog = new baseSelectDialog($this->config,$this,$this->get_allowed_bases());
$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()){
/* A new base was selected, check if it is a valid one */
$tmp = $this->get_allowed_bases();
if(isset($tmp[$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->get_allowed_bases();
if(($this->dn == "new")||($this->dn == "")){
$tmp = $bases;
}else{
$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;
}
}
}
$smarty->assign("bases", $tmp);
foreach ($this->attributes as $val){
$smarty->assign("$val", $this->$val);
}
$smarty->assign("base_select", $this->base);
/* Set admin unit flag */
if ($this->is_administrational_unit) {
$smarty->assign("unitTag", "checked");
} else {
$smarty->assign("unitTag", "");
}
return($smarty->fetch (get_template_path('generic.tpl', TRUE)));
}
function clear_fields()
{
echo __FUNCTION__."
";
$this->dn = "";
$this->base = "";
foreach ($this->attributes as $val){
$this->$val= "";
}
}
function remove_from_parent()
{
echo __FUNCTION__."
";
$ldap= $this->config->get_ldap_link();
$ldap->cd ($this->dn);
$ldap->recursive_remove();
new log("remove","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
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');
}
function must_be_tagged()
{
echo __FUNCTION__."
";
return $this->must_be_tagged;
}
function am_i_moved()
{
echo __FUNCTION__."
";
return $this->rec_cpy;
}
/* Save data to object */
function save_object()
{
echo __FUNCTION__."
";
if (isset($_POST['dep_generic_posted'])){
/* Create a base backup and reset the
base directly after calling plugin::save_object();
Base will be set seperatly a few lines below */
$base_tmp = $this->base;
plugin::save_object();
$this->base = $base_tmp;
/* Set new base if allowed */
$tmp = $this->get_allowed_bases();
if(isset($_POST['base'])){
if(isset($tmp[$_POST['base']])){
$this->base= $_POST['base'];
}
}
/* Save tagging flag */
if ($this->acl_is_writeable("unitTag")){
if (isset($_POST['unitTag'])){
$this->is_administrational_unit= true;
} else {
$this->is_administrational_unit= false;
}
}
}
}
/* Check values */
function check()
{
echo __FUNCTION__."
";
/* Call common method to give check the hook */
$message= plugin::check();
/* 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[]= msgPool::duplicated(_("Name"));
} elseif ($this->orig_dn != $this->dn && !($attrs === FALSE)){
$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(tests::is_department_name_reserved($this->ou,$this->base)){
$message[]= msgPool::reserved(_("Name"));
}
if (preg_match ('/[#+:=>\\\\\/]/', $this->ou)){
$message[]= msgPool::invalid(_("Name"), $this->ou, "/[^#+:=>\\\\\/]/");
}
if (!tests::is_phone_nr($this->telephoneNumber)){
$message[]= msgPool::invalid(_("Phone"), $this->telephoneNumber, "/[\/0-9 ()+*-]/");
}
if (!tests::is_phone_nr($this->facsimileTelephoneNumber)){
$message[]= msgPool::invalid(_("Fax"), $this->facsimileTelephoneNumber, "/[\/0-9 ()+*-]/");
}
return $message;
}
/* Save to LDAP */
function save()
{
echo __FUNCTION__."
";
$ldap= $this->config->get_ldap_link();
/* 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= "";
/* 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 == ""){
/* 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) {
msg_dialog::display(_("Fatal error"), _("Cannot find an unused tag for this administrative unit!"), WARNING_DIALOG);
return;
}
$this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec);
}
}
$this->skipTagging = TRUE;
plugin::save();
/* Remove tag information if needed */
if (!$this->is_administrational_unit){
$tmp= array();
/* Remove gosaAdministrativeUnit from this plugin */
foreach($this->attrs['objectClass'] as $oc){
if (!preg_match("/^gosaAdministrativeUnit$/i", $oc)){
$tmp[]= $oc;
}
}
$this->attrs['objectClass']= $tmp;
}
/* Do we need to remove the tag itself? */
$has_unit_tag= false;
foreach($this->attrs['objectClass'] as $oc){
if (preg_match("/^gosaAdministrativeUnitTag$/i", $oc)){
$has_unit_tag= true;
}
}
if ($has_unit_tag == false && $this->is_administrational_unit == false){
$this->attrs['gosaUnitTag']= array();
} else {
$this->attrs['gosaUnitTag']= $this->gosaUnitTag;
}
/* Write back to ldap */
$ldap->cat($this->dn, array('dn'));
$ldap->cd($this->dn);
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());
$this->handle_post_events('modify');
} else {
$ldap->add($this->attrs);
$this->handle_post_events('add');
new log("create","department/".get_class($this),$this->dn,array_keys($this->attrs),$ldap->get_error());
}
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();
return(false);
}
function ShowMoveFrame()
{
echo __FUNCTION__."
";
$smarty = get_smarty();
$smarty->assign("src","?plug=".$_GET['plug']."&PerformRecMove&no_output_compression");
$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()
{
echo __FUNCTION__."
";
$smarty = get_smarty();
$smarty->assign("src","?plug=".$_GET['plug']."&TagDepartment&no_output_compression");
$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)
{
echo __FUNCTION__."
";
if(!$OnlySetTagFlag){
$smarty= get_smarty();
/* Print out html introduction */
echo '
'; echo ""; } } /* Move/Rename complete trees */ function recursive_move($src_dn, $dst_dn,$force = false) { echo __FUNCTION__."
'; echo ""; echo "" ; echo ""; return (TRUE); } } /* Return plugin informations for acl handling */ static function plInfo() { echo __FUNCTION__."