From: cajus Date: Sat, 24 Jun 2006 03:43:22 +0000 (+0000) Subject: Forgot to revert 3871 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=868bf9105ab6c9528d2c83d115ec2dc78668d35e;p=gosa.git Forgot to revert 3871 git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3875 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index c508b614e..ed1216cdf 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -21,45 +21,43 @@ 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 = ""; - var $is_administrational_unit = false; - var $gosaUnitTag = ""; + 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 $last_dep_sorting= "invalid"; + var $departments= array(); - /* Used to indicate that a new tagging is required */ - var $must_be_tagged = false; - var $MustBeMoved = ""; - var $MoveDestination = ""; - var $MoveSource = ""; - var $MoveOu = ""; + 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"); - + 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; + $this->is_account= TRUE; + $this->ui= get_userinfo(); + $this->dn= $dn; + $this->orig_dn= $dn; + $this->config= $config; /* Set base */ if ($this->dn == "new"){ @@ -74,8 +72,9 @@ class department extends plugin } /* set permissions */ - $acl = get_permissions ($this->ui->dn, $this->ui->subtreeACL); - $this->acl= get_module_permission($acl, "department", $this->ui->dn); + $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'])){ @@ -83,7 +82,6 @@ class department extends plugin } } - function execute() { /* Call parent execute */ @@ -104,13 +102,11 @@ class department extends plugin } } - /* BASE select dialog handling */ + /* Dialog handling */ if(is_object($this->dialog)){ - - /* save sub dialog vars */ + /* Must be called before save_object */ $this->dialog->save_object(); - /* Check if dialog was closed */ if($this->dialog->isClosed()){ $this->dialog = false; }elseif($this->dialog->isSelected()){ @@ -129,7 +125,6 @@ class department extends plugin $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; @@ -138,7 +133,6 @@ class department extends plugin } $smarty->assign("bases", $tmp); - /* Report class vars to smarty */ foreach ($this->attributes as $val){ $smarty->assign("$val", $this->$val); $smarty->assign("$val"."ACL", chkacl($this->acl, "$val")); @@ -153,14 +147,23 @@ class department extends plugin $smarty->assign("unitTag", ""); } $smarty->assign("unitTag"."ACL", chkacl($this->acl, "unitTag")); + 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= ""; + } + } - /* Remove department && all sub objects from ldap */ function remove_from_parent() { - /* Remove the current department from ldap */ $ldap= $this->config->get_ldap_link(); $ldap->cd ($this->dn); $ldap->recursive_remove(); @@ -170,6 +173,23 @@ class department extends plugin $this->handle_post_events('remove'); } + function must_be_tagged() + { + if((isset($this->attrs['gosaUnitTag'][0])) && ($this->is_administrational_unit)){ + $this->must_be_tagged = false; + }elseif((!isset($this->attrs['gosaUnitTag'][0])) && (!$this->is_administrational_unit)){ + $this->must_be_tagged = false; + }else{ + $this->must_be_tagged = true; + } + return $this->must_be_tagged; + } + + function am_i_moved() + { + return $this->rec_cpy; + } + /* Save data to object */ function save_object() @@ -248,14 +268,9 @@ class department extends plugin /* Add tag objects if needed */ if ($this->is_administrational_unit){ - - /* Add tagging objectClass if it is not available */ if(!in_array_ics("gosaAdministrativeUnit",$this->objectclasses)){ $this->objectclasses[]= "gosaAdministrativeUnit"; } - - - /* If tag wasn't set right now */ if ($this->gosaUnitTag == ""){ /* It's unlikely, but check if already used... */ @@ -263,16 +278,15 @@ class department extends plugin $ldap->cd($this->config->current['BASE']); while ($try--){ - /* Generate microtime stamp as tag, and check if this tag was already used somewhere */ + /* 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; } - } - - /* Last try, and all generated tag are already in use */ + } if($try == 0) { print_red(_("Fatal error: Can't find an unused tag to mark the administrative unit!")); return; @@ -280,8 +294,6 @@ class department extends plugin $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); } } else { - - /* Set tag to "" if department isn't tagged */ $this->gosaUnitTag= ""; } @@ -318,12 +330,7 @@ class department extends plugin $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); + show_ldap_error($ldap->get_error(), _("Saving department failed")); /* Optionally execute a command after we're done */ $this->postcreate(); @@ -331,10 +338,27 @@ 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) { - /* Skip output */ if(!$OnlySetTagFlag){ $smarty= get_smarty(); echo "".$smarty->fetch(get_template_path('headers.tpl')); @@ -342,19 +366,16 @@ class department extends plugin echo "

".sprintf(_("Tagging '%s'."),"".@LDAP::fix($this->dn)."")."

"; } - /* Get all object that must be tagged, or the tag removed */ + $add= $this->is_administrational_unit; + $len= strlen($this->dn); $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); - if ($this->is_administrational_unit){ - $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='.$this->gosaUnitTag.')))', array('dn')); + if ($add){ + $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='. + $this->gosaUnitTag.')))', array('dn')); } else { $ldap->search('objectClass=gosaAdministrativeUnitTag', array('dn')); } - - /* Get dn length, it is used to validate the fetched dns */ - $len= strlen($this->dn); - - /* Walk through all objects && verify if fetch object musst be touched */ while ($attrs= $ldap->fetch()){ /* Skip self */ @@ -365,7 +386,6 @@ class department extends plugin /* 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; @@ -380,18 +400,13 @@ class department extends plugin /* Fix entry if needed */ if ($fix){ - - /* If OnlySetTagFlag is true, then only set must_be_tagged to true, and skip tagging. */ if($OnlySetTagFlag){ $this->must_be_tagged =true; return; - }else{ - $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); } + $this->handle_object_tagging($attrs['dn'], $this->gosaUnitTag, TRUE ); } } - - /* Hide all output, if we only want to if we must tag */ if(!$OnlySetTagFlag){ echo '

 

'; echo "
@@ -402,25 +417,40 @@ class department extends plugin /* Move/Rename complete trees */ - function recursive_move() + function recursive_move($src_dn, $dst_dn,$force = false) { - /* Check if the destination entry exists */ - $ldap= $this->config->get_ldap_link(); + /* 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; + } - /* Get destination && source dn */ - $src_dn = $this->MoveSource; - $dst_dn = $this->MoveDestination; + $src_dn = $this->rec_src; + $dst_dn = $this->rec_dst; /* Print header to have styles included */ $smarty= get_smarty(); echo "".$smarty->fetch(get_template_path('headers.tpl')); echo ""; + echo "

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

"; + + /* Check if the destination entry exists */ + $ldap= $this->config->get_ldap_link(); + /* Check if destination exists - abort */ $ldap->cat($dst_dn, array('dn')); if ($ldap->fetch()){ - trigger_error("Recursive_move $dst_dn already exists.", E_USER_WARNING); + trigger_error("Recursive_move $dst_dn already exists.", + E_USER_WARNING); echo sprintf("Recursive_move: '%s' already exists", $dst_dn)."
"; return (FALSE); } @@ -441,6 +471,7 @@ 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); @@ -462,37 +493,16 @@ class department extends plugin $this->rec_cpy =false; echo '

 

'; + echo "

"; echo ""; + return (TRUE); + } } - - - /* Return an iframe, that calls the recursive move function of departmentManagement */ - 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); - } - - - /* return an iframe, that will initiate the tagging process */ - 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); - } - - } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/departments/class_departmentManagement.inc b/plugins/admin/departments/class_departmentManagement.inc index dbfcab0b4..128639d12 100644 --- a/plugins/admin/departments/class_departmentManagement.inc +++ b/plugins/admin/departments/class_departmentManagement.inc @@ -39,8 +39,11 @@ class departmentManagement extends plugin var $attributes= array(); var $objectclasses= array(); - /* Tagging || Moving in progress */ - var $AfterSaveProcedure = false; + /* Vars to handle operations after saving the department + Recursive move && tagging */ + var $ObjectInSaveMode = false; // Is true, if current object wasn't saved right now + var $ObjectTaggingRequested = false; // Object must be tagged, an iframe will be shown. + var $RecursiveRemoveRequested = false; // Is true, if this object must be moved, an iframe will be displayed in this case function departmentManagement ($config, $ui) { @@ -179,14 +182,53 @@ class departmentManagement extends plugin } } + + /*************** + Edit department finished + ***************/ + + if ((isset($_POST['edit_finish'])) && (isset($this->deptabs->config))){ + + /* Check tabs, will feed message array */ + $message= $this->deptabs->check(); + + /* Save, or display error message? */ + if (count($message) == 0){ + + $this->deptabs->save(true); + + if(!$this->deptabs->by_object['department']->am_i_moved()){ + $this->deptabs->save(true); + } + + /* This object must be tagged, so set ObjectTaggingRequested to true */ + if($this->deptabs->by_object['department']->must_be_tagged()){ + $this->ObjectTaggingRequested = true; + } + + /* Get recursive move is required, set RecursiveRemoveRequested to true */ + if($this->deptabs->by_object['department']->am_i_moved()){ + $this->RecursiveRemoveRequested = true; + } + + /* This var indicated that there is an object which isn't saved right now. */ + $this->ObjectInSaveMode = true; + + } else { + /* Ok. There seem to be errors regarding to the tab data, + show message and continue as usual. */ + show_errors($message); + } + } + + /*************** Handle Tagging (Return output for an iframe) ***************/ - /* This department must be tagged (Is called from iframe, generates output) */ + /* This department must be tagged (Is called from iframe, generates output)*/ if(isset($_GET['TagDepartment'])){ $this->deptabs->by_object['department']->tag_objects(); - $this->deptabs->by_object['department']->must_be_tagged = false; exit(); } @@ -197,57 +239,43 @@ class departmentManagement extends plugin /* initiate recursive remove (Is called from iframe, generates output)*/ if(isset($_GET['PerformRecMove'])){ - $this->deptabs->by_object['department']->recursive_move(); - $this->deptabs->by_object['department']->MustBeMoved = false; + $this->deptabs->by_object['department']->recursive_move("","",true); exit(); } - /*************** - Edit department finished + Return iframes, which call tagging / recusrsive move ***************/ - if (($this->AfterSaveProcedure || isset($_POST['edit_finish'])) && (isset($this->deptabs->config))){ - - /* Check tabs, will feed message array */ - $message= $this->deptabs->check(); + /* While one of these vars below isset, we must return an iframe, + to perform requested operation */ + if($this->ObjectTaggingRequested){ + $this->ObjectTaggingRequested = false; + return($this->deptabs->by_object['department']->ShowTagFrame()); + } + if($this->RecursiveRemoveRequested){ + $this->RecursiveRemoveRequested = false; + return($this->deptabs->by_object['department']->ShowMoveFrame()); + } - /* Save, or display error message? */ - if (count($message) == 0){ - /* Save current changes */ - if(!$this->AfterSaveProcedure){ - $this->deptabs->save(true); - } - - /* Check if we have to tag this department */ - if($this->deptabs->by_object['department']->must_be_tagged){ - $this->AfterSaveProcedure = true; - $this->deptabs->by_object['department']->must_be_tagged = false; - return($this->deptabs->by_object['department']->ShowTagFrame()); - } - - /* Saving and tagging, is done now, lets move the dep if required */ - if($this->deptabs->by_object['department']->MustBeMoved){ - $this->AfterSaveProcedure = true; - $this->deptabs->by_object['department']->MustBeMoved = false; - return($this->deptabs->by_object['department']->ShowMoveFrame()); - } + /*************** + In case of tagging/moving the object wasn't deleted, do it know + ***************/ - if ($this->dn != "new"){ - del_lock ($this->dn); - } - gosa_log ("Department object'".$this->dn."' has been saved"); - unset ($this->deptabs); - $this->deptabs= NULL; - $this->AfterSaveProcedure = false; - unset ($_SESSION['objectinfo']); - } else { - /* Ok. There seem to be errors regarding to the tab data, - show message and continue as usual. */ - show_errors($message); + /* If there is an unsaved object and all operations are done + remove locks & save object tab & unset current object */ + if($this->ObjectInSaveMode && (!$this->RecursiveRemoveRequested) && (!$this->ObjectTaggingRequested)){ + $this->deptabs->save(); + $this->ObjectInSaveMode = false; + if ($this->dn != "new"){ + del_lock ($this->dn); } + gosa_log ("Department object'".$this->dn."' has been saved"); + unset ($this->deptabs); + $this->deptabs= NULL; + unset ($_SESSION['objectinfo']); } diff --git a/plugins/admin/departments/tabs_department.inc b/plugins/admin/departments/tabs_department.inc index deccb02c4..e1b7b98d0 100644 --- a/plugins/admin/departments/tabs_department.inc +++ b/plugins/admin/departments/tabs_department.inc @@ -2,7 +2,7 @@ class deptabs extends tabs { - var $base = ""; + var $base= ""; function deptabs($config, $data, $dn) { @@ -16,40 +16,31 @@ class deptabs extends tabs } - /* Save all changes (generic tab will do our tagging) - if source dn != destination dn then MustBeMoved will be set */ - function save() + function save($justsave = false) { - $baseobject = $this->by_object['department']; - - $ou = preg_replace('/,/', '\,', $baseobject->ou); - $new_dn = @LDAP::convert('ou='.$ou.','.$baseobject->base); - - /* If dn has changed move dep & sub entries */ - if ($this->dn != $new_dn && $this->dn != "new"){ - /* if( new_dn is subtree of this->dn ) */ - $cnt1 = count(split(",",$this->dn)); - $cnt2 = count(split(",",$new_dn)); - if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){ - print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); - }else{ - $this->by_object['department']->MustBeMoved = true; - $this->by_object['department']->MoveDestination = $new_dn; - $this->by_object['department']->MoveSource = $this->dn; - $this->by_object['department']->MoveOu = $ou; - $this->dn = $this->dn; - $baseobject->dn = $this->dn; - $this->by_object['department']->ou = $baseobject->attrs['ou'][0]; - $this->by_object['department'] = $baseobject; - return(tabs::save(TRUE)); + $baseobject= $this->by_object['department']; + $ou= preg_replace('/,/', '\,', $baseobject->ou); + $new_dn= @LDAP::convert('ou='.$ou.','.$baseobject->base); + if($justsave){ + if ($this->dn != $new_dn && $this->dn != "new"){ + /* if( new_dn is subtree of this->dn ) */ + $cnt1 = count(split(",",$this->dn)); + $cnt2 = count(split(",",$new_dn)); + if((strstr($new_dn,$this->dn))&&($cnt1<$cnt2)){ + print_red(_("Try to move tree failed. Destination tree is subtree of source tree.")); + }else{ + /* Prepare to be moved */ + $baseobject->recursive_move($this->dn, $new_dn); + $this->by_object['department'] = $baseobject; + return; + } } }else{ $this->dn= $new_dn; - $baseobject->dn= $this->dn; - $this->by_object['department']= $baseobject; return(tabs::save(TRUE)); } } + } - // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: - ?> +// vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: +?>