From: hickert Date: Fri, 23 Jun 2006 11:08:16 +0000 (+0000) Subject: Rworked tagging && moving behavior, must be TESTED X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=293276a55ee983a93d85b88883a9191d78fa0830;p=gosa.git Rworked tagging && moving behavior, must be TESTED git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3871 594d385d-05f5-0310-b6e9-bd551577e9d8 --- diff --git a/plugins/admin/departments/class_departmentGeneric.inc b/plugins/admin/departments/class_departmentGeneric.inc index ed1216cdf..c508b614e 100644 --- a/plugins/admin/departments/class_departmentGeneric.inc +++ b/plugins/admin/departments/class_departmentGeneric.inc @@ -21,43 +21,45 @@ 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 $rec_dst=false; // Destination for recursive move - var $rec_src=false; // Source for recursive move - var $rec_cpy=false; // Is recursive move requested ? + 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 = ""; /* Headpage attributes */ - var $last_dep_sorting= "invalid"; - var $departments= array(); + var $last_dep_sorting = "invalid"; + var $departments = array(); - var $must_be_tagged = false; + /* Used to indicate that a new tagging is required */ + var $must_be_tagged = false; + var $MustBeMoved = ""; + var $MoveDestination = ""; + var $MoveSource = ""; + var $MoveOu = ""; /* 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"){ @@ -72,9 +74,8 @@ class department extends plugin } /* set permissions */ - $ui= get_userinfo(); - $acl= get_permissions ($ui->dn, $ui->subtreeACL); - $this->acl= get_module_permission($acl, "department", $ui->dn); + $acl = get_permissions ($this->ui->dn, $this->ui->subtreeACL); + $this->acl= get_module_permission($acl, "department", $this->ui->dn); /* Is administrational Unit? */ if ($dn != "new" && in_array_ics('gosaAdministrativeUnit', $this->attrs['objectClass'])){ @@ -82,6 +83,7 @@ class department extends plugin } } + function execute() { /* Call parent execute */ @@ -102,11 +104,13 @@ class department extends plugin } } - /* Dialog handling */ + /* BASE select dialog handling */ if(is_object($this->dialog)){ - /* Must be called before save_object */ + + /* save sub dialog vars */ $this->dialog->save_object(); + /* Check if dialog was closed */ if($this->dialog->isClosed()){ $this->dialog = false; }elseif($this->dialog->isSelected()){ @@ -125,6 +129,7 @@ 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; @@ -133,6 +138,7 @@ 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")); @@ -147,23 +153,14 @@ 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(); @@ -173,23 +170,6 @@ 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() @@ -268,9 +248,14 @@ 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... */ @@ -278,15 +263,16 @@ class department extends plugin $ldap->cd($this->config->current['BASE']); while ($try--){ - /* Generate microtime stamp as tag */ + /* Generate microtime stamp as tag, and check if this tag was already used somewhere */ 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; @@ -294,6 +280,8 @@ class department extends plugin $this->gosaUnitTag= preg_replace("/\./", "", $sec.$usec); } } else { + + /* Set tag to "" if department isn't tagged */ $this->gosaUnitTag= ""; } @@ -330,7 +318,12 @@ class department extends plugin $ldap->add($this->attrs); $this->handle_post_events('add'); } - show_ldap_error($ldap->get_error(), _("Saving department failed")); + + 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); /* Optionally execute a command after we're done */ $this->postcreate(); @@ -338,27 +331,10 @@ 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')); @@ -366,16 +342,19 @@ class department extends plugin echo "

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

"; } - $add= $this->is_administrational_unit; - $len= strlen($this->dn); + /* Get all object that must be tagged, or the tag removed */ $ldap= $this->config->get_ldap_link(); $ldap->cd($this->dn); - if ($add){ - $ldap->search('(!(&(objectClass=gosaAdministrativeUnitTag)(gosaUnitTag='. - $this->gosaUnitTag.')))', array('dn')); + if ($this->is_administrational_unit){ + $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 */ @@ -386,6 +365,7 @@ 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; @@ -400,13 +380,18 @@ 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 "
@@ -417,40 +402,25 @@ class department extends plugin /* Move/Rename complete trees */ - function recursive_move($src_dn, $dst_dn,$force = false) + function recursive_move() { - /* 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; - } + /* Check if the destination entry exists */ + $ldap= $this->config->get_ldap_link(); - $src_dn = $this->rec_src; - $dst_dn = $this->rec_dst; + /* Get destination && source dn */ + $src_dn = $this->MoveSource; + $dst_dn = $this->MoveDestination; /* 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); } @@ -471,7 +441,6 @@ 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); @@ -493,16 +462,37 @@ 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 128639d12..dbfcab0b4 100644 --- a/plugins/admin/departments/class_departmentManagement.inc +++ b/plugins/admin/departments/class_departmentManagement.inc @@ -39,11 +39,8 @@ class departmentManagement extends plugin var $attributes= array(); var $objectclasses= array(); - /* 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 + /* Tagging || Moving in progress */ + var $AfterSaveProcedure = false; function departmentManagement ($config, $ui) { @@ -182,53 +179,14 @@ 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(); } @@ -239,43 +197,57 @@ class departmentManagement extends plugin /* initiate recursive remove (Is called from iframe, generates output)*/ if(isset($_GET['PerformRecMove'])){ - $this->deptabs->by_object['department']->recursive_move("","",true); + $this->deptabs->by_object['department']->recursive_move(); + $this->deptabs->by_object['department']->MustBeMoved = false; exit(); } + /*************** - Return iframes, which call tagging / recusrsive move + Edit department finished ***************/ - /* 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()); - } + if (($this->AfterSaveProcedure || isset($_POST['edit_finish'])) && (isset($this->deptabs->config))){ + /* Check tabs, will feed message array */ + $message= $this->deptabs->check(); - /*************** - In case of tagging/moving the object wasn't deleted, do it know - ***************/ + /* Save, or display error message? */ + if (count($message) == 0){ - /* 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); + /* 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()); + } + + 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); } - 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 e1b7b98d0..deccb02c4 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,31 +16,40 @@ class deptabs extends tabs } - function save($justsave = false) + /* Save all changes (generic tab will do our tagging) + if source dn != destination dn then MustBeMoved will be set */ + function save() { - $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; - } + $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)); } }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: + ?>