From 630f65a639a91ff713549ca1c8d80d65b98d9754 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Fri, 7 Jan 2005 10:55:05 +0000 Subject: [PATCH] implemented profile loading interface --- lam/lib/baseModule.inc | 16 +++++++++ lam/lib/modules.inc | 38 +++++++--------------- lam/lib/modules/inetLocalMailRecipient.inc | 8 +++-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index acfca3cc..0637d1a8 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -305,6 +305,22 @@ class baseModule { return $messages; } + /** + * Loads the values of an account profile into internal variables. + * + * @param array $profile hash array with profile values (identifier => value) + */ + function load_profile($profile) { + if (isset($this->meta['profile_mappings'])) { + $identifiers = array_keys($this->meta['profile_mappings']); + for ($i = 0; $i < sizeof($identifiers); $i++) { + if (isset($profile[$identifiers[$i]])) { + $this->attributes[$this->meta['profile_mappings'][$identifiers[$i]]] = $profile[$identifiers[$i]]; + } + } + } + } + /** * Returns a list of elements for the configuration. * diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index c208a736..3a65cca1 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -597,11 +597,10 @@ class accountContainer { // load profile if ($post['selectLoadProfile'] && $post['loadProfile']) { - // *** fixme load*Profile must return array in the same way ldap_get_attributes does. - $newattributes = loadAccountProfile($post['selectLoadProfile'], $scope); - // pass newattributes to each module + $profile = loadAccountProfile($post['selectLoadProfile'], $this->type); + // pass profile to each module $modules = array_keys($this->module); - foreach ($modules as $module) $this->module[$module]->load_attributes($newattributes); + foreach ($modules as $module) $this->module[$module]->load_profile($profile); $result = 0; } // save account @@ -611,17 +610,6 @@ class accountContainer { // return name of subpage $result = 'finish'; } - // save profile - if ($post['saveProfile']) { - if ($post['selectSaveProfile']=='') $errors['saveProfile'][] = array('ERROR', _('Save profile'), _('No profilename given.')); - else { - //saveAccountProfile($scope); // TODO missing parameters, remove? - if ($function) $errors['saveProfile'][] = array('INFO', _('Save profile'), _('New profile created.')); - else $errors['saveProfile'][] = array('ERROR', _('Save profile'), _('Wrong profilename given.')); - } - if (is_array($errors)) $result = $errors; - else $result = 0; - } } if ($this->subpage=='finish') { if ($post['createagain']) { @@ -747,17 +735,15 @@ class accountContainer { // Get list of profiles $profilelist = getAccountProfiles($this->type); if (count($profilelist)!=0) { - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Load profile") ), - 1 => array ( 'kind' => 'select', 'name' => 'selectLoadProfile', 'options' => $profilelist ), - 2 => array ('kind' => 'help', 'value' => 'selectLoadProfile')); - } - $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => _("Save profile") ), - 1 => array ( 'kind' => 'table', 'value' => array ( 0 => array ( - 0 => array ( 'kind' => 'input', 'name' => 'selectSaveProfile', 'type' => 'text', 'size' => '30', - 'maxlength' => '255', ), - 1 => array ('kind' => 'input', 'name' => 'saveProfile', 'type' => 'submit', - 'value' => _('Save profile'), 'disabled' => $disabled))) ), - 2 => array ('kind' => 'help', 'value' => 'saveProfile')); + $return[] = array( + 0 => array('kind' => 'text', 'text' => _("Load profile")), + 1 => array('kind' => 'table', 'value' => array(0 => array( + 0 => array('kind' => 'select', 'name' => 'selectLoadProfile', 'options' => $profilelist), + 1 => array('kind' => 'input', 'type' => 'submit', 'name' => 'loadProfile', 'value' => _('Load profile')) + )), + 2 => array('kind' => 'help', 'value' => 'selectLoadProfile')) + ); + } if ($this->dn_orig!='') $text = _('Modify Account'); else $text = _('Create Account'); $return[] = array ( 0 => array ( 'kind' => 'text', 'text' => $text ), diff --git a/lam/lib/modules/inetLocalMailRecipient.inc b/lam/lib/modules/inetLocalMailRecipient.inc index acc28d02..5ba5654a 100644 --- a/lam/lib/modules/inetLocalMailRecipient.inc +++ b/lam/lib/modules/inetLocalMailRecipient.inc @@ -80,6 +80,10 @@ class inetLocalMailRecipient extends baseModule { 'type' => 'ext_preg', 'regex' => 'DNSname', 'error_message' => $this->messages['host'][0]); + // profile mappings + $return['profile_mappings'] = array( + 'inetLocalMailRecipient_host' => 'mailHost' + ); // upload fields $return['upload_columns'] = array( array( @@ -232,7 +236,7 @@ class inetLocalMailRecipient extends baseModule { if (isset($post['routingAdr']) && ($post['routingAdr'] != "")) { // check if address has correct format if (get_preg($post['routingAdr'], 'email')) { - $this->attributes['mailRoutingAddress'][] = $post['routingAdr']; + $this->attributes['mailRoutingAddress'][0] = $post['routingAdr']; } else { $message = $this->messages['routingAdr'][0]; @@ -244,7 +248,7 @@ class inetLocalMailRecipient extends baseModule { if (isset($post['host']) && ($post['host'] != "")) { // check if address has correct format if (get_preg($post['host'], 'DNSname')) { - $this->attributes['mailHost'][] = $post['host']; + $this->attributes['mailHost'][0] = $post['host']; } else { $message = $this->messages['host'][0];