diff --git a/include/class_template.inc b/include/class_template.inc index 7560af4e10eb4f67b6e67dde7e8be317f2f1dc5e..a18b4e385c6b3c19353a5c43784508d3541ab4c7 100644 --- a/include/class_template.inc +++ b/include/class_template.inc @@ -171,6 +171,8 @@ class template } } + /*! \brief Serialize this template for webservice + */ function serialize() { $ret = array(); @@ -188,6 +190,8 @@ class template return $ret; } + /*! \brief Deserialize values into the template + */ function deserialize($values) { foreach ($values as $class => $class_values) { @@ -199,6 +203,34 @@ class template return TRUE; } + /*! \brief Get all attribute values + * + * this produces a format that you can send to setValues later (after a reset for instance) + */ + function getValues() + { + $ret = array(); + foreach ($this->tabObject->by_object as $class => $plugin) { + $ret[$class] = array(); + foreach ($plugin->attributesAccess as $name => $attr) { + $ret[$class][$name] = $attr->getValue(); + } + } + + return $ret; + } + + /*! \brief Set values + */ + function setValues($values) + { + foreach ($values as $class => $class_values) { + foreach ($class_values as $name => $value) { + $this->tabObject->by_object[$class]->attributesAccess[$name]->setValue($value); + } + } + } + function save_object() { foreach ($this->tabObject->by_object as $plugin) { diff --git a/include/simpleplugin/attributes/class_FileAttribute.inc b/include/simpleplugin/attributes/class_FileAttribute.inc index 8686570d3447b8b8ccf06ff6202e222798a0e1bf..2ad49b65e6dbe934fd9954d67ee6b5159419653b 100644 --- a/include/simpleplugin/attributes/class_FileAttribute.inc +++ b/include/simpleplugin/attributes/class_FileAttribute.inc @@ -85,13 +85,27 @@ class FileAttribute extends Attribute parent::serializeAttribute($attributes, $form); if ($this->binary) { - $attributes[$this->getLdapName()]['value'] = base64_encode($attributes[$this->getLdapName()]['value']); - $attributes[$this->getLdapName()]['default'] = base64_encode($attributes[$this->getLdapName()]['default']); $attributes[$this->getLdapName()]['binary'] = TRUE; } } } + /*! \brief Serialize value for RPC requests + * + * \param mixed $value the value + */ + function serializeValue($value = NULL) + { + if ($value === NULL) { + $value = $this->getValue(); + } + if ($this->binary) { + return base64_encode($value); + } else { + return $value; + } + } + /*! \brief Apply value from RPC requests * * \param mixed $value the value diff --git a/include/simpleplugin/class_Attribute.inc b/include/simpleplugin/class_Attribute.inc index e27224749c58fef0864c358950042df4ef77a134..2629af7923ea5d33a08511f2454dab2698ac65ce 100644 --- a/include/simpleplugin/class_Attribute.inc +++ b/include/simpleplugin/class_Attribute.inc @@ -618,8 +618,8 @@ class Attribute 'required' => $this->isRequired(), 'disabled' => $this->disabled, 'description' => $this->getDescription(), - 'value' => $this->getValue(), - 'default' => $this->defaultValue, + 'value' => $this->serializeValue(), + 'default' => $this->serializeValue($this->defaultValue), 'type' => $type, ); if (!$form) { @@ -643,6 +643,18 @@ class Attribute $this->setValue($value); } + /*! \brief Serialize value for RPC requests + * + * \param mixed $value the value + */ + function serializeValue($value = NULL) + { + if ($value === NULL) { + $value = $this->getValue(); + } + return $value; + } + /*! \brief Add ACL information around display * * \param string $display the display information to pass through ACL diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 6d6ce3d90226e76dfec5c58a877cdbff7a3b0f66..52f0812f304819ba6bade0d738178012a7512cd9 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -124,6 +124,9 @@ class UserPasswordAttribute extends CompositeAttribute function setValue ($value) { + if (!is_array($value)) { + $value = $this->inputValue($value); + } reset($value); $key = key($value); if ($this->attributes[0]->isDisabled() || ($value[$key] == '')) { @@ -143,7 +146,7 @@ class UserPasswordAttribute extends CompositeAttribute { $method = $this->attributes[0]->getValue(); if ($method != $this->previousMethod) { - if ($this->needPassword[$method]) { + if (isset($this->needPassword[$method]) && $this->needPassword[$method]) { $hashEmpty = ($this->attributes[3]->getValue() == ''); $this->attributes[1]->setVisible(TRUE); $this->attributes[1]->setRequired($hashEmpty); @@ -167,7 +170,10 @@ class UserPasswordAttribute extends CompositeAttribute $pw_storage = $config->get_cfg_value('passwordDefaultHash', 'ssha'); $locked = FALSE; $password = ''; - if ($this->plugin->is_template) { + if ($this->plugin->is_template && !empty($value)) { + if ($value == '%askme%') { + return array('%askme%', '', '', $value, $locked); + } list($value, $password) = explode('|', $value, 2); } if (preg_match ('/^{[^}]+}/', $value)) { @@ -189,12 +195,11 @@ class UserPasswordAttribute extends CompositeAttribute function writeValues(array $values) { - if ($this->needPassword[$values[0]] && ($values[1] == '')) { - if ($this->plugin->is_template) { - return ''; - } else { - return $values[3]; - } + if ($this->plugin->is_template && ($values[0] == '%askme%')) { + return '%askme%'; + } + if (!$this->plugin->is_template && $this->needPassword[$values[0]] && ($values[1] == '')) { + return $values[3]; } $temp = passwordMethod::get_available_methods(); if (!isset($temp[$values[0]])) {