From 2624ef41958622317cffbe7f2d808bd9dd81f770 Mon Sep 17 00:00:00 2001 From: hickert Date: Fri, 7 Dec 2007 13:02:05 +0000 Subject: [PATCH] Updated Multiple edit git-svn-id: https://oss.gonicus.de/repositories/gosa/trunk@8058 594d385d-05f5-0310-b6e9-bd551577e9d8 --- include/class_multi_plug.inc | 51 ++++++-- include/class_plugin.inc | 130 +++++++++++++------ include/class_tabs.inc | 27 +++- plugins/admin/users/class_userManagement.inc | 4 +- plugins/personal/generic/class_user.inc | 89 ++++--------- plugins/personal/generic/generic.tpl | 19 ++- 6 files changed, 194 insertions(+), 126 deletions(-) diff --git a/include/class_multi_plug.inc b/include/class_multi_plug.inc index 9e944fe64..066d83028 100644 --- a/include/class_multi_plug.inc +++ b/include/class_multi_plug.inc @@ -20,8 +20,8 @@ /* -Data structure : - +Data structure : +================ |->o_tab <-- dummy object, collects HTML posts, displays ui |->a_handles <-- tab object for each given dn |->tab object for dn 1 @@ -29,6 +29,26 @@ Data structure : ... |->tab object for dn n +Using this class: +================= + Simple Example: + + $dn = array(dn1,dn2,dn3); + $tmp = new multi_plug($config,"usertabs",$config->data['TABS']['USERTABS'],$dn); + echo $tmp->execute(); + + $tmp can now be used like the normal tab class, execute, save_object ... + + To enable multipe edit for a specific plugin, + just set the plugin variable 'multiple_support' to true: + + var $multiple_support = TRUE; + + If plugin::multiple_support is true, the member function + multiple_execute() will be called and displayed, NOT execute(). + + (I will put this in the wiki, later. This are just notes for me.) + */ @@ -62,7 +82,7 @@ class multi_plug @param array $dns The object dns we want to edit. @return object multi_plug */ - public function __construct($config,$class,$tab,$dns) + public function __construct($config,$class,$tab,$dns,$acl_base,$acl_category) { $this->dn = $dns; $this->config = $config; @@ -71,7 +91,8 @@ class multi_plug /* Initialize collector object * Used to display the ui and to collect the user input. */ - $this->o_tab = new $class($config,$tab,"new"); + $this->o_tab = new $class($config,$tab,"new",$acl_category); + $this->o_tab->set_acl_base($acl_base); /* Check if the specified tab object supports multiple edits */ @@ -84,7 +105,9 @@ class multi_plug /* Initialize the objects we want to edit at once */ foreach($dns as $dn){ - $this->a_handles[] = new $class($config,$tab,$dn); + $obj = new $class($config,$tab,$dn,$acl_category); + $obj->set_acl_base($acl_base); + $this->a_handles[] = $obj; } } } @@ -166,12 +189,6 @@ class multi_plug { $this->populate_values(); $messages = $this->o_tab->check(); - foreach($this->a_handles as $key => $obj){ - $msgs = $obj->check(); - foreach($msgs as $msg){ - $messages[] = $msg; - } - } return($messages); } @@ -181,6 +198,12 @@ class multi_plug */ public function password_change_needed() { + foreach($this->a_handles as $i_id => $o_handle){ + if($o_handle->password_change_needed() && isset($o_handle->by_object['user'])){ + new msg_dialog(_("Password reset"),_("The user password was resetted, please set a new password value!"),WARNING_DIALOG); + change_password ($o_handle->dn, "",0, $o_handle->by_object['user']->pw_storage); + } + } return(FALSE); } @@ -192,10 +215,12 @@ class multi_plug if($this->multiple_available() && is_array($this->a_handles)){ foreach($this->o_tab->by_object as $name => $obj){ + $values = $this->o_tab->by_object[$name]->get_multi_edit_values(); foreach($values as $a_name => $a_value){ foreach($this->a_handles as $i_id => $o_handle){ - $o_handle->by_object[$name]->$a_name = $a_value; + $this->a_handles[$i_id]->by_object[$name]->$a_name = $a_value; + echo $name."->".$a_name." = ".$a_value."
"; } } } @@ -210,7 +235,7 @@ class multi_plug if($this->multiple_available() && is_array($this->a_handles)){ $this->populate_values(); foreach($this->a_handles as $i_id => $o_handle){ - $o_handle->save(); + $o_handle->save(TRUE); } } } diff --git a/include/class_plugin.inc b/include/class_plugin.inc index db615d67b..51547403d 100644 --- a/include/class_plugin.inc +++ b/include/class_plugin.inc @@ -229,23 +229,6 @@ class plugin } - /*! \brief execute plugin - - Generates the html output for this node - */ - function execute_multiple() - { - /* This one is empty currently. Fabian - please fill in the docu code */ - $_SESSION['current_class_for_help'] = get_class($this); - - /* Reset Lock message POST/GET check array, to prevent perg_match errors*/ - $_SESSION['LOCK_VARS_TO_USE'] = $_SESSION['LOCK_VARS_USED'] =array(); - - return("Multiple edit is currently not implemented for this plugin."); - } - - - /*! \brief execute plugin Generates the html output for this node @@ -307,20 +290,6 @@ class plugin $this->entryCSN = getEntryCSN($this->dn); } - /* MULTIPLE_EDIT - Ensures that only selected values will be used. - Should be rewritten. - */ - if($this->multiple_support_active){ - foreach($this->attributes as $attr){ - if(isset($_POST["use_".$attr])){ - $this->selected_edit_values[$attr] = TRUE; - }else{ - $this->selected_edit_values[$attr] = FALSE; - } - } - } - /* Save values to object */ foreach ($this->attributes as $val){ if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){ @@ -1707,17 +1676,6 @@ class plugin } - function get_multi_edit_values() - { - $ret = array(); - foreach($this->selected_edit_values as $attr => $active){ - if($active){ - $ret[$attr] = $this->$attr; - } - } - return($ret); - } - /* This function enables the entry Serial ID check. * If an entry was edited while we have edited the entry too, @@ -1731,11 +1689,99 @@ class plugin } + + function set_multi_edit_value() { } + + /*! \brief Prepares the plugin to be used for multiple edit + */ + function init_multiple_support() + { + foreach($this->attributes as $attr){ + if(isset($this->$attr) && is_string($this->$attr)){ + $this->$attr = "{default}"; + } + } + } + + + /*! \brief Returns all values that have been modfied in multiple edit mode. + @return array Cotaining all mdofied values. + */ + function get_multi_edit_values() + { + $ret = array(); + foreach($this->attributes as $attr){ + if($this->$attr != "{default}"){ + $ret[$attr] = $this->$attr; + } + } + return($ret); + } + + + /*! \brief execute plugin + + Generates the html output for this node + */ + function multiple_execute() + { + /* This one is empty currently. Fabian - please fill in the docu code */ + $_SESSION['current_class_for_help'] = get_class($this); + + /* Reset Lock message POST/GET check array, to prevent perg_match errors*/ + $_SESSION['LOCK_VARS_TO_USE'] = $_SESSION['LOCK_VARS_USED'] =array(); + + return("Multiple edit is currently not implemented for this plugin."); + } + + + /*! \brief Save HTML posted data to object for multiple edit + */ + function multiple_save_object() + { + if(empty($this->entryCSN) && $this->CSN_check_active){ + $this->entryCSN = getEntryCSN($this->dn); + } + + /* Save values to object */ + foreach ($this->attributes as $val){ + if ($this->acl_is_writeable($val) && isset ($_POST["$val"])){ + + /* Check for modifications */ + if (get_magic_quotes_gpc()) { + $data= stripcslashes($_POST["$val"]); + } else { + $data= $this->$val = $_POST["$val"]; + } + if ($this->$val != $data && $data != "{default}"){ + $this->is_modified= TRUE; + } + + /* IE post fix */ + if(isset($data[0]) && $data[0] == chr(194)) { + $data = ""; + } + if($data != "{default}"){ + $this->$val= $data; + } + } + } + } + + + /*! \brief Check given values in multiple edit + @return array Error messages + */ + function multiple_check() + { + $message = plugin::check(); + return($message); + } } // vim:tabstop=2:expandtab:shiftwidth=2:filetype=php:syntax:ruler: diff --git a/include/class_tabs.inc b/include/class_tabs.inc index 9d4a3cedb..b6060399a 100644 --- a/include/class_tabs.inc +++ b/include/class_tabs.inc @@ -33,7 +33,7 @@ class tabs var $by_object= array(); var $SubDialog = false; - var $multiple_support = FALSE; + var $multiple_support_active = FALSE; function tabs(&$config, $data, $dn, $acl_category= "") { @@ -94,10 +94,10 @@ class tabs /* If multiple edit is enabled for this tab, we have tho display different templates */ - if(!$this->multiple_support){ + if(!$this->multiple_support_active){ $display.= $this->by_object[$this->current]->execute(); }else{ - $display.= $this->by_object[$this->current]->execute_multiple(); + $display.= $this->by_object[$this->current]->multiple_execute(); } /* Footer for tabbed dialog */ @@ -113,7 +113,11 @@ class tabs @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->last, "Saving"); - $this->by_object[$this->last]->save_object (); + if(!$this->multiple_support_active){ + $this->by_object[$this->last]->save_object (); + }else{ + $this->by_object[$this->last]->multiple_save_object(); + } } /* Skip if curent and last are the same object */ @@ -128,7 +132,11 @@ class tabs @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->current, "Saving (current)"); - $obj->save_object (); + if(!$this->multiple_support_active){ + $obj->save_object(); + }else{ + $obj->multiple_save_object(); + } } } @@ -233,7 +241,11 @@ class tabs if ($obj->is_account || $ignore_account || $obj->ignore_account){ @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__,$key, "Checking"); - $msg = $obj->check(); + if(!$this->multiple_support_active){ + $msg = $obj->check(); + }else{ + $msg = $obj->multiple_check(); + } if (count($msg)){ $obj->pl_notify= TRUE; @@ -368,10 +380,11 @@ class tabs if(!$this->multiple_support_available()){ return(FALSE); }else{ - $this->multiple_support = TRUE; + $this->multiple_support_active = TRUE; foreach($this->by_object as $name => $obj){ if($obj->multiple_support){ $this->by_object[$name]->multiple_support_active = TRUE; + $this->by_object[$name]->init_multiple_support(); }else{ unset($this->by_object[$name]); unset($this->by_name[$name]); diff --git a/plugins/admin/users/class_userManagement.inc b/plugins/admin/users/class_userManagement.inc index 26058ead4..a2f6f70a2 100644 --- a/plugins/admin/users/class_userManagement.inc +++ b/plugins/admin/users/class_userManagement.inc @@ -331,7 +331,6 @@ class userManagement extends plugin $_SESSION['objectinfo']= $this->dn; } - /******************** Edit multiple entries @@ -344,7 +343,8 @@ class userManagement extends plugin foreach($this->list_get_selected_items() as $id){ $this->dn[] = $this->list[$id]['dn'];; } - $tmp = new multi_plug($this->config,"usertabs",$this->config->data['TABS']['USERTABS'],$this->dn); + $tmp = new multi_plug($this->config,"usertabs",$this->config->data['TABS']['USERTABS'], + $this->dn,$this->DivListUsers->selectedBase,"user"); if ($tmp->entries_locked()){ return($tmp->display_lock_message()); } diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 157b5b8d3..30178739f 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -557,6 +557,7 @@ class user extends plugin $temp= passwordMethod::get_available_methods(); $is_configurable= FALSE; $hashes = $temp['name']; + $hashes["{default}"] = "{default}"; if(isset($temp[$this->pw_storage])){ $test= new $temp[$this->pw_storage]($this->config); $is_configurable= $test->is_configurable(); @@ -627,6 +628,7 @@ class user extends plugin } else { $smarty->assign("has_phoneaccount", "false"); } + $smarty->assign("multiple_support" , $this->multiple_support_active); return($smarty->fetch (get_template_path('generic.tpl', TRUE, dirname(__FILE__)))); } @@ -686,9 +688,6 @@ class user extends plugin /* Save data to object */ function save_object() { - if (isset($_POST['multiple_user_posted'])){ - $this->save_object_multiple(); - } if(isset($_POST['generic']) || isset($_POST['multiple_user_posted'])){ /* Make a backup of the current selected base */ @@ -773,7 +772,7 @@ class user extends plugin */ if($this->gender=="0") $this->gender =""; if($this->preferredLanguage=="0") $this->preferredLanguage =""; - + /* First use parents methods to do some basic fillup in $this->attrs */ plugin::save (); @@ -1454,78 +1453,46 @@ class user extends plugin } + function init_multiple_support() + { + plugin::init_multiple_support(); + $this->pw_storage = "{default}"; + } - - - - - function get_values_to_update() + function get_multi_edit_values() { $ret = plugin::get_multi_edit_values(); + if($this->pw_storage != "{default}"){ + $ret['pw_storage'] = $this->pw_storage; + } return($ret); } - function save_object_multiple() + function multiple_save_object() { - foreach(array("pw_storage","base","edit_cert") as $attr){ - if(isset($_POST["use_".$attr])){ - $this->selected_edit_values[$attr] = TRUE; - }else{ - $this->selected_edit_values[$attr] = FALSE; + plugin::multiple_save_object(); + + /* Get pw_storage mode */ + if (isset($_POST['pw_storage'])){ + foreach(array("pw_storage") as $val){ + if(isset($_POST[$val])){ + $data= validate($_POST[$val]); + if ($data != $this->$val){ + $this->is_modified= TRUE; + } + $this->$val= $data; + } } } + } - function execute_multiple() + function multiple_execute() { - $smarty =get_smarty(); - $language= array_merge(array(0 => " ") ,get_languages(TRUE)); - $smarty->assign("preferredLanguage_list", $language); - @$smarty->assign("bases", $this->allowedBasesToMoveTo()); - $smarty->assign("base_select", $this->base); - - /* Save government mode attributes */ - if (isset($this->config->current['GOVERNMENTMODE']) && - preg_match('/true/i', $this->config->current['GOVERNMENTMODE'])){ - $smarty->assign("governmentmode", "true"); - $ivbbmodes= array("nein", "ivbv", "testa", "ivbv,testa", "internet", - "internet,ivbv", "internet,testa", "internet,ivbv,testa"); - $smarty->assign("ivbbmodes", $ivbbmodes); - foreach ($this->govattrs as $val){ - $smarty->assign("$val", $this->$val); - $smarty->assign("$val"."ACL", $this->getacl($val,(!is_object($this->parent) && !isset($_SESSION['edit'])))); - } - } else { - $smarty->assign("governmentmode", "false"); - } - - $temp= passwordMethod::get_available_methods(); - $hashes = $temp['name']; - $test= new $temp[$this->pw_storage]($this->config); - $is_configurable= $test->is_configurable(); - $smarty->assign("pwmode", $hashes); - $smarty->assign("pwmode_select", $this->pw_storage); - $smarty->assign("pw_configurable", $is_configurable); - - foreach($this->attributes as $attr){ - if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){ - $smarty->assign("use_".$attr,TRUE); - }else{ - $smarty->assign("use_".$attr,FALSE); - } - $smarty->assign($attr,$this->$attr); - } - foreach(array("pw_storage","base","edit_cert") as $attr){ - if(isset($this->selected_edit_values[$attr]) && $this->selected_edit_values[$attr] == TRUE){ - $smarty->assign("use_".$attr,TRUE); - }else{ - $smarty->assign("use_".$attr,FALSE); - } - } - return($smarty->fetch (get_template_path('multiple_generic.tpl', TRUE, dirname(__FILE__)))); + return($this->execute()); } diff --git a/plugins/personal/generic/generic.tpl b/plugins/personal/generic/generic.tpl index f96d764b2..d5e1fcbed 100644 --- a/plugins/personal/generic/generic.tpl +++ b/plugins/personal/generic/generic.tpl @@ -4,6 +4,15 @@

{t}Personal information{/t}

+ +{if $multiple_support} +

+ You are currently editing multiple entries at once. Some attributes may be disabled.
+ All touched values will be written. +
+

+{/if} + @@ -63,7 +72,15 @@ - {render acl=$uidACL}{/render} + + {if !$multiple_support} + {render acl=$uidACL} + + {/render} + {else} + + {/if} + {/if} -- 2.30.2