From d9076ca7458dfb4e8082f5a170ffdea241b9ae01 Mon Sep 17 00:00:00 2001 From: hickert Date: Tue, 25 Apr 2006 11:46:42 +0000 Subject: [PATCH] Some copy & paste fixes added some comments git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@3108 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_CopyPasteHandler.inc | 99 ++++------- include/functions.inc | 14 ++ plugins/admin/users/class_userManagement.inc | 163 +++++++++--------- .../gofon/phoneaccount/class_phoneAccount.inc | 3 + plugins/personal/mail/class_mailAccount.inc | 2 + plugins/personal/posix/class_posixAccount.inc | 12 +- 6 files changed, 147 insertions(+), 146 deletions(-) diff --git a/include/class_CopyPasteHandler.inc b/include/class_CopyPasteHandler.inc index 996407c30..4ec220be5 100644 --- a/include/class_CopyPasteHandler.inc +++ b/include/class_CopyPasteHandler.inc @@ -1,5 +1,4 @@ config = $config; $this->current= NULL; } - /* Returns wether the current object can be pasted - */ + /* Returns wether the current object can be pasted */ function isCurrentObjectPastAble(){ - /* Check if we got a valid object - */ + /* Check if we got a valid object */ if($this->current == NULL){ return(false); } @@ -36,8 +32,7 @@ class CopyPasteHandler { } - /* Clears all copy & paste informations - */ + /* Clears all copy & paste informations */ function Clear() { $this->copyCurrent = false; @@ -47,25 +42,25 @@ class CopyPasteHandler { } - /* return current obejct dn - */ + /* return current obejct dn */ function GetCurrentDn() { return($this->objectdn); } - /* Add Object which should be copied - */ + /* Add Object which should be copied */ function Copy($obj,$emptyObj) { $this->copyCurrent = true; $this->objectdn = $obj->dn; $this->current = $emptyObj; foreach($obj->by_object as $name => $obj){ - + + /* Prepare every single class, to be copied */ $this->current->by_object[$name]->PrepareForCopyPaste($obj); - + + /* handle some special vars */ foreach(array("is_account") as $attr){ if(isset($obj->$attr)){ $this->current->by_object[$name]->$attr = $obj->$attr; @@ -82,8 +77,7 @@ class CopyPasteHandler { } - /* Add Object which should be cutted - */ + /* Add Object which should be cutted */ function Cut($obj){ $this->cutCurrent = true; $this->current = $obj; @@ -99,36 +93,31 @@ class CopyPasteHandler { /* Returns true if current object - * is cutted. And awaits to be pasted anywhere - */ + * is cutted. And awaits to be pasted anywhere */ function isCurrentCutted(){ return($this->cutCurrent); } /* Returns true if current object - * was copied, and awaits to be pasted again - */ + * was copied, and awaits to be pasted again */ function isCurrentCopied(){ return($this->copyCurrent); } - /* stillOpen - */ + /* Returns true if the copy$paste dialog is still open */ function stillOpen(){ if(isset($_POST['AbortCopyPaste'])){ $this->dialogOpen = false; } - return($this->dialogOpen); } /* Displays a dialog which allows the user to fix all dependencies of this object. - Create unique names, ids, or what ever - */ - function execute($displayMessageOnSuccess = true) + Create unique names, ids, or what ever */ + function execute() { $this->dialogOpen = true; @@ -137,11 +126,7 @@ class CopyPasteHandler { if($this->cutCurrent){ $this->current->save(); $this->dialogOpen =false; - $smarty = get_smarty(); - $smarty->assign("Complete",true); - $this->lastdn= $this->current->dn; $this->Clear(); - return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); /* Copy & paste */ @@ -155,42 +140,34 @@ class CopyPasteHandler { }else{ $this->current->save(); $this->dialogOpen =false; - $smarty = get_smarty(); - $smarty->assign("Complete",true); - $this->lastdn = $this->current->dn; $this->Clear(); - if($displayMessageOnSuccess){ - return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); - }else{ - //FIXME: Types!!! Either use strings, or use bool. But don't mix it! - return( false); - } } } - $smarty = get_smarty(); - $smarty->assign("Complete",false); - $smarty->assign("AttributesToFix",$this->generateAttributesToFix()); - $smarty->assign("SubDialog",$this->current->SubDialog); - - $smarty->assign("objectDN" ,$this->objectdn); - $smarty->assign("message", sprintf(_("You are going to copy the entry '%s'."), $this->objectdn)); - return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); + if($this->current){ + $smarty = get_smarty(); + $smarty->assign("Complete",false); + $smarty->assign("AttributesToFix",$this->generateAttributesToFix()); + $smarty->assign("SubDialog",$this->current->SubDialog); + $smarty->assign("objectDN" ,$this->objectdn); + $smarty->assign("message", sprintf(_("You are going to copy the entry '%s'."), $this->objectdn)); + return($smarty->fetch(get_template_path("copyPasteDialog.tpl",FALSE))); + } } } - /* Create dialog which asks unique attributes values ... - * calls tabs -> getCopyDialog() - * which calls tab -> getCopyDialog() - */ + /* Create dialog which asks unique attributes/values ... + * call tabs -> getCopyDialog() + * which calls tab -> getCopyDialog() */ function generateAttributesToFix() { - return($this->current->getCopyDialog()); + if($this->current){ + return($this->current->getCopyDialog()); + } } /* Set a single attribute to specified value - * example : ("base", $newBase ); - */ + * example : ("base", $newBase ); */ function SetVar($name,$value) { foreach($this-> current->by_object as $key => $obj){ @@ -201,18 +178,18 @@ class CopyPasteHandler { } - /* Save new values posted by copy & paste dialog - */ + /* Save new values posted by copy & paste dialog */ function save_object() { /* Assign posted var to all tabs */ - $this->current->saveCopyDialog(); + if($this->current){ + $this->current->saveCopyDialog(); + } } - /* Returns possible errors returned from all including tabs .. - */ + /* Returns errors from including tabs. */ function check() { $ret = array(); @@ -221,11 +198,11 @@ class CopyPasteHandler { $ret = array_merge($ret , $obj->check()); } } - return($ret); } + /* returns the paste icon for headpages */ function generatePasteIcon() { $Copy_Paste= "  "; diff --git a/include/functions.inc b/include/functions.inc index dcd4ccaaf..98b739af9 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -1951,5 +1951,19 @@ function normalizeLdap($input) } +/* Resturns the difference between to microtime() results in float */ +function get_MicroTimeDiff($start , $stop) +{ + $a = split("\ ",$start); + $b = split("\ ",$stop); + + $secs = $b[1] - $a[1]; + $msecs= $b[0] - $a[0]; + + $ret = (float) ($secs+ $msecs); + return($ret); +} + + // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: ?> diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index a23d11d2a..f3e3596cd 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -35,8 +35,8 @@ class userManagement extends plugin var $templates= array(); var $got_uid= false; var $departments= array(); - var $CopyPasteHandler= NULL; - + var $CopyPasteHandler = NULL; + var $CPPasswordChange = ""; // Contains the entry id which should get a new password function userManagement($config, $ui) { @@ -112,7 +112,7 @@ class userManagement extends plugin "back" => "dep_back", "new" => "user_new", "home" => "dep_home", "new_tpl" => "user_tplnew", "change_pw" => "user_chgpw", "root" => "dep_root", - "editpaste" => "editpaste", "copy" => "copy", + "editPaste" => "editPaste", "copy" => "copy", "cut" => "cut") as $act => $name){ if (preg_match("/".$name.".*/", $key)){ @@ -168,87 +168,10 @@ class userManagement extends plugin } } -# |||| ----------------------- copy and paste - move it into a seperate function -//FIXME: I've mostly skipped reviewing this. Just a few comments have been -// added. Fact is, that we've an execute() function with more than 800 -// lines. I personally tend to make this shorter. Even the complete new -// list management is a huge copy'n paste factor which can be sourced out -// to another function. - - /* Only perform copy/paste if it is enabled */ - if($this->CopyPasteHandler){ - - /* Paste copied/cutted object in here */ - //FIXME: Sure? Does this comment describe what happens below? - if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){ - $this->CopyPasteHandler->save_object(); - $this->CopyPasteHandler->SetVar("base", $_SESSION['CurrentMainBase']); - - /* Execute copy and paste without showing message on success. */ - //FIXME: It is not clear what really happens, or why we're stopping - // to process data here. See the FIXME in class_CopyAndPasteHandler. - // Normally we don't have something in $ret, because we've fired - // up with (false) <=> which seems to mean "no messages". - if( ($ret= $this->CopyPasteHandler->execute(false))){ - return ($ret); - } - - /* Reload to have freshly copied entries in the list */ - $this->reload(); - - /* Use the last dn to search for it's ID in the newly generated list. */ - $dn= $this->CopyPasteHandler->lastdn; - foreach($this->list as $id => $entry){ - if($entry['dn'] == $dn){ - $s_entry= $id; - break; - } - } - - /* Change action to "change_pw" if user has requested to do so. */ - if($_POST['passwordTodo'] == "new"){ - $s_action= "change_pw"; - } - } - - /* Copy current object to CopyHandler */ - if($s_action == "copy"){ - $this->CopyPasteHandler->Clear(); - - $dn= $this->list[trim($s_entry)]['dn']; - $acl= get_permissions ($dn, $this->ui->subtreeACL); - - $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); - $objNew= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new"); - - $obj->set_acl($acl); - $objNew->set_acl($acl); - - foreach($obj->by_object as $name => $tab){ - foreach(array("photoData","jpegPhoto","is_account") as $attr){ - if(isset($obj->by_object[$name]->$attr)){ - $objNew->by_object[$name]->$attr = $obj->by_object[$name]->$attr; - } - } - } - $this->CopyPasteHandler->Copy($obj,$objNew); - } - - /* Copy current object to CopyHandler */ - //FIXME: Again? This is cut. Hopefully it works without touching the special - // attributes from above. - if($s_action == "cut"){ - $this->CopyPasteHandler->Clear(); - $dn= $this->list[trim($s_entry)]['dn']; - $acl= get_permissions ($dn, $this->ui->subtreeACL); - - $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); - $obj->set_acl($acl); - - $this->CopyPasteHandler->Cut($obj); - } + $ret = $this->copyPasteHandling($s_action,$s_entry); + if($ret){ + return($ret); } -# ^^^^^ ----------------------- copy and paste - move it into a seperate function /* Save filter data if we are in the headpage */ if(!isset($this->usertab)){ @@ -308,7 +231,12 @@ class userManagement extends plugin } /* Password change requested */ - if ($s_action == "change_pw"){ + if (($s_action == "change_pw") || (!empty($this->CPPasswordChange))){ + + if(!empty($this->CPPasswordChange)){ + $s_entry = $this->CPPasswordChange; + $this->CPPasswordChange = ""; + } /* Get 'dn' from posted 'uid' */ $this->dn= $this->list[trim($s_entry)]['dn']; @@ -1124,6 +1052,73 @@ class userManagement extends plugin } } + + /* Perform copy & paste requests + If copy&paste is in progress this returns a dialog to fix required attributes + */ + function copyPasteHandling($s_action,$s_entry) + { + /* Only perform copy/paste if it is enabled */ + if($this->CopyPasteHandler){ + + /* Prepare current object to be pasted */ + if( $s_action == "editPaste" || $this->CopyPasteHandler->stillOpen()){ + + $this->CopyPasteHandler->save_object(); + $this->CopyPasteHandler->SetVar("base", $_SESSION['CurrentMainBase']); + + /* Execute copy & paste dialog and display returned data, normaly a dialog which allows + us to solve all attribute mismatches for this object. + If nothing is returned, copy & paste was succesfully or aborted */ + if(($ret= $this->CopyPasteHandler->execute())){ + return ($ret); + } + + /* Reload to have freshly copied entries in the list */ + $this->reload(); + + /* Use the last dn to search for it's ID in the newly generated list. */ + $dn= $this->CopyPasteHandler->lastdn; + foreach($this->list as $id => $entry){ + if($entry['dn'] == $dn){ + $s_entry= $id; + break; + } + } + + /* Set CPPasswordChange to s_entry which indicates that this entry requires a new password. */ + if(isset($_POST['passwordTodo']) && ($_POST['passwordTodo'] == "new")){ + $this->CPPasswordChange = $s_entry; + } + } + + /* Copy selected object + Create a new empty object and the current selected object. + Send both to copy&paste class*/ + if($s_action == "copy"){ + $this->CopyPasteHandler->Clear(); + $dn= $this->list[trim($s_entry)]['dn']; + $acl= get_permissions ($dn, $this->ui->subtreeACL); + $obj = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); + $objNew = new usertabs($this->config, $this->config->data['TABS']['USERTABS'], "new"); + $obj-> set_acl($acl); + $objNew-> set_acl($acl); + $this->CopyPasteHandler->Copy($obj,$objNew); + } + + /* Cut selected object. + Open user object and send it to the copy & paste handler */ + if($s_action == "cut"){ + $this->CopyPasteHandler->Clear(); + $dn= $this->list[trim($s_entry)]['dn']; + $acl= get_permissions ($dn, $this->ui->subtreeACL); + $obj= new usertabs($this->config, $this->config->data['TABS']['USERTABS'], $dn); + $obj->set_acl($acl); + $this->CopyPasteHandler->Cut($obj); + } + } + } + /* A set of disabled and therefore overloaded functions. They are not needed in this class. */ diff --git a/plugins/gofon/phoneaccount/class_phoneAccount.inc b/plugins/gofon/phoneaccount/class_phoneAccount.inc index 80660f27e..0c4363cde 100644 --- a/plugins/gofon/phoneaccount/class_phoneAccount.inc +++ b/plugins/gofon/phoneaccount/class_phoneAccount.inc @@ -1157,6 +1157,8 @@ $ldap->modify ($this->attrs); } } + + /* Create phoneAccount part of copy & paste dialog */ function getCopyDialog() { if(!$this->is_account) return(""); @@ -1177,6 +1179,7 @@ $ldap->modify ($this->attrs); return($ret); } + /* Save posts from copy & paste dialog dialog */ function saveCopyDialog() { if(!$this->is_account) return; diff --git a/plugins/personal/mail/class_mailAccount.inc b/plugins/personal/mail/class_mailAccount.inc index 94bd81e8a..65686eeb4 100644 --- a/plugins/personal/mail/class_mailAccount.inc +++ b/plugins/personal/mail/class_mailAccount.inc @@ -868,6 +868,8 @@ $ldap->modify ($this->attrs); return ($name); } + + /* Create the mail part for the copy & paste dialog */ function getCopyDialog() { if(!$this->is_account) return(""); diff --git a/plugins/personal/posix/class_posixAccount.inc b/plugins/personal/posix/class_posixAccount.inc index 18724b25f..86e8a892f 100644 --- a/plugins/personal/posix/class_posixAccount.inc +++ b/plugins/personal/posix/class_posixAccount.inc @@ -1144,8 +1144,11 @@ $ldap->modify ($this->attrs); reset ($this->grouplist); } + + /* Create the posix dialog part for copy & paste */ function getCopyDialog() { + /* Skip dialog creation if this is not a valid account*/ if(!$this->is_account) return(""); if ($this->force_ids == 1){ $force_ids = "checked"; @@ -1162,11 +1165,14 @@ $ldap->modify ($this->attrs); $sta = ""; + /* Open group add dialog */ if(isset($_POST['edit_groupmembership'])){ $this->group_dialog = TRUE; $sta = "SubDialog"; } + /* If the group-add dialog is closed, call execute + to ensure that the membership is updatd */ if(isset($_POST['add_groups_finish']) || isset($_POST['add_groups_cancel'])){ $this->execute(); $this->group_dialog =FALSE; @@ -1180,21 +1186,25 @@ $ldap->modify ($this->attrs); return($ret); } + /* If a group member should be deleted, simply call execute */ if(isset($_POST['delete_groupmembership'])){ $this->execute(); } + /* Assigned informations to smarty */ $smarty = get_smarty(); $smarty->assign("homeDirectory",$this->homeDirectory); $smarty->assign("uidNumber",$this->uidNumber); $smarty->assign("gidNumber",$this->gidNumber); $smarty->assign("forceMode",$forceMode); $smarty->assign("force_ids",$force_ids); - if (!count($this->groupMembership)){ + if (!count($this->groupMembership)){ $smarty->assign("groupMembership", array(" ")); } else { $smarty->assign("groupMembership", $this->groupMembership); } + + /* Display wars message if there are more than 16 group members */ if (count($this->groupMembership) > 16){ $smarty->assign("groups", "too_many_for_nfs"); } else { -- 2.30.2