reduced code

This commit is contained in:
Roland Gruber 2013-10-22 17:41:24 +00:00
parent 1d94d8e12d
commit 1710cd8b40
1 changed files with 34 additions and 30 deletions

View File

@ -57,7 +57,7 @@ class inetLocalMailRecipient extends baseModule {
$return['attributes'] = array('mailLocalAddress', 'mailHost', 'mailRoutingAddress'); $return['attributes'] = array('mailLocalAddress', 'mailHost', 'mailRoutingAddress');
// help Entries // help Entries
$return['help'] = array( $return['help'] = array(
'routingAdr' => array( 'mailRoutingAddress' => array(
"Headline" => _("Routing address"), 'attr' => 'mailRoutingAddress', "Headline" => _("Routing address"), 'attr' => 'mailRoutingAddress',
"Text" => _("This is the target email address for the user's mails.") "Text" => _("This is the target email address for the user's mails.")
), ),
@ -69,19 +69,19 @@ class inetLocalMailRecipient extends baseModule {
"Headline" => _("Local address list"), 'attr' => 'mailLocalAddress', "Headline" => _("Local address list"), 'attr' => 'mailLocalAddress',
"Text" => _("This is a comma separated list of the users public email addresses.") "Text" => _("This is a comma separated list of the users public email addresses.")
), ),
'host' => array( 'mailHost' => array(
"Headline" => _("Mail server"), 'attr' => 'mailHost', "Headline" => _("Mail server"), 'attr' => 'mailHost',
"Text" => _("This is the mail server for the user.") "Text" => _("This is the mail server for the user.")
)); ));
// profile options // profile options
$profileContainer = new htmlTable(); $profileContainer = new htmlTable();
$profileContainer->addElement(new htmlTableExtendedInputField(_('Mail server'), 'inetLocalMailRecipient_host', null, 'host')); $profileContainer->addElement(new htmlTableExtendedInputField(_('Mail server'), 'inetLocalMailRecipient_host', null, 'mailHost'));
$return['profile_options'] = $profileContainer; $return['profile_options'] = $profileContainer;
// profile checks // profile checks
$return['profile_checks']['inetLocalMailRecipient_host'] = array( $return['profile_checks']['inetLocalMailRecipient_host'] = array(
'type' => 'ext_preg', 'type' => 'ext_preg',
'regex' => 'DNSname', 'regex' => 'DNSname',
'error_message' => $this->messages['host'][0]); 'error_message' => $this->messages['mailHost'][0]);
// profile mappings // profile mappings
$return['profile_mappings'] = array( $return['profile_mappings'] = array(
'inetLocalMailRecipient_host' => 'mailHost' 'inetLocalMailRecipient_host' => 'mailHost'
@ -91,7 +91,7 @@ class inetLocalMailRecipient extends baseModule {
array( array(
'name' => 'inetLocalMailRecipient_routingAdr', 'name' => 'inetLocalMailRecipient_routingAdr',
'description' => _('Routing address'), 'description' => _('Routing address'),
'help' => 'routingAdr', 'help' => 'mailRoutingAddress',
'example' => _('smiller@otherdomain.org') 'example' => _('smiller@otherdomain.org')
), ),
array( array(
@ -103,7 +103,7 @@ class inetLocalMailRecipient extends baseModule {
array( array(
'name' => 'inetLocalMailRecipient_server', 'name' => 'inetLocalMailRecipient_server',
'description' => _('Mail server'), 'description' => _('Mail server'),
'help' => 'host', 'help' => 'mailHost',
'example' => _('mail.yourdomain.org') 'example' => _('mail.yourdomain.org')
) )
); );
@ -120,12 +120,12 @@ class inetLocalMailRecipient extends baseModule {
* This function fills the error message array with messages * This function fills the error message array with messages
*/ */
function load_Messages() { function load_Messages() {
$this->messages['routingAdr'][0] = array('ERROR', 'Routing address is invalid!'); // third array value is set dynamically $this->messages['mailRoutingAddress'][0] = array('ERROR', 'Routing address is invalid!'); // third array value is set dynamically
$this->messages['routingAdr'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_routingAdr', 'Routing address is invalid!'); $this->messages['mailRoutingAddress'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_routingAdr', 'Routing address is invalid!');
$this->messages['localAdr'][0] = array('ERROR', 'Local address is invalid!'); // third array value is set dynamically $this->messages['localAdr'][0] = array('ERROR', 'Local address is invalid!'); // third array value is set dynamically
$this->messages['localAdr'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_localAdr', 'Local address is invalid!'); $this->messages['localAdr'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_localAdr', 'Local address is invalid!');
$this->messages['host'][0] = array('ERROR', 'Mail server is invalid!'); // third array value is set dynamically $this->messages['mailHost'][0] = array('ERROR', 'Mail server is invalid!'); // third array value is set dynamically
$this->messages['host'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_server', 'Mail server is invalid!'); $this->messages['mailHost'][1] = array('ERROR', _('Account %s:') . ' inetLocalMailRecipient_server', 'Mail server is invalid!');
} }
/** /**
@ -136,21 +136,25 @@ class inetLocalMailRecipient extends baseModule {
function display_html_attributes() { function display_html_attributes() {
$return = new htmlTable(); $return = new htmlTable();
// mail routing address // mail routing address
$routingAddress = ''; $this->addSimpleInputTextField($return, 'mailRoutingAddress', _('Routing address'));
if (isset($this->attributes['mailRoutingAddress'][0])) $routingAddress = $this->attributes['mailRoutingAddress'][0];
$return->addElement(new htmlTableExtendedInputField(_('Routing address'), 'routingAdr', $routingAddress, 'routingAdr'), true);
// mail server // mail server
$mailServer = ''; $this->addSimpleInputTextField($return, 'mailHost', _('Mail server'));
if (isset($this->attributes['mailHost'][0])) $mailServer = $this->attributes['mailHost'][0];
$return->addElement(new htmlTableExtendedInputField(_('Mail server'), 'host', $mailServer, 'host'), true);
// list current local addresses // list current local addresses
$localAdresses = array(); $localAdresses = array();
if (isset($this->attributes['mailLocalAddress'])) $localAdresses = $this->attributes['mailLocalAddress']; if (isset($this->attributes['mailLocalAddress'])) $localAdresses = $this->attributes['mailLocalAddress'];
for ($i = 0; $i < sizeof($localAdresses); $i++) { for ($i = 0; $i < sizeof($localAdresses); $i++) {
$return->addElement(new htmlOutputText(_('Local address'))); if ($i == 0) {
$return->addElement(new htmlOutputText(_('Local address')));
}
else {
$return->addElement(new htmlOutputText(''));
}
$return->addElement(new htmlInputField('localAdr' . $i, $localAdresses[$i])); $return->addElement(new htmlInputField('localAdr' . $i, $localAdresses[$i]));
$return->addElement(new htmlButton('delAdr' . $i, 'del.png', true)); $return->addElement(new htmlButton('delAdr' . $i, 'del.png', true));
$return->addElement(new htmlHelpLink('localAdr'), true); if ($i == 0) {
$return->addElement(new htmlHelpLink('localAdr'));
}
$return->addNewLine();
} }
// input box for new local addresses // input box for new local addresses
$return->addElement(new htmlOutputText(_('New local address'))); $return->addElement(new htmlOutputText(_('New local address')));
@ -173,26 +177,26 @@ class inetLocalMailRecipient extends baseModule {
$this->attributes['mailLocalAddress'] = array(); $this->attributes['mailLocalAddress'] = array();
$this->attributes['mailHost'] = array(); $this->attributes['mailHost'] = array();
// check routing address // check routing address
if (isset($_POST['routingAdr']) && ($_POST['routingAdr'] != "")) { if (isset($_POST['mailRoutingAddress']) && ($_POST['mailRoutingAddress'] != "")) {
// check if address has correct format // check if address has correct format
if (get_preg($_POST['routingAdr'], 'email')) { if (get_preg($_POST['mailRoutingAddress'], 'email')) {
$this->attributes['mailRoutingAddress'][0] = $_POST['routingAdr']; $this->attributes['mailRoutingAddress'][0] = $_POST['mailRoutingAddress'];
} }
else { else {
$message = $this->messages['routingAdr'][0]; $message = $this->messages['mailRoutingAddress'][0];
$message[] = $_POST['routingAdr']; $message[] = $_POST['mailRoutingAddress'];
$errors[] = $message; $errors[] = $message;
} }
} }
// check mail server // check mail server
if (isset($_POST['host']) && ($_POST['host'] != "")) { if (isset($_POST['mailHost']) && ($_POST['mailHost'] != "")) {
// check if address has correct format // check if address has correct format
if (get_preg($_POST['host'], 'DNSname')) { if (get_preg($_POST['mailHost'], 'DNSname')) {
$this->attributes['mailHost'][0] = $_POST['host']; $this->attributes['mailHost'][0] = $_POST['mailHost'];
} }
else { else {
$message = $this->messages['host'][0]; $message = $this->messages['mailHost'][0];
$message[] = $_POST['host']; $message[] = $_POST['mailHost'];
$errors[] = $message; $errors[] = $message;
} }
} }
@ -268,7 +272,7 @@ class inetLocalMailRecipient extends baseModule {
$partialAccounts[$i]['mailRoutingAddress'][] = $rawAccounts[$i][$ids['inetLocalMailRecipient_routingAdr']]; $partialAccounts[$i]['mailRoutingAddress'][] = $rawAccounts[$i][$ids['inetLocalMailRecipient_routingAdr']];
} }
else { else {
$errMsg = $this->messages['routingAdr'][1]; $errMsg = $this->messages['mailRoutingAddress'][1];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$messages[] = $errMsg; $messages[] = $errMsg;
} }
@ -280,7 +284,7 @@ class inetLocalMailRecipient extends baseModule {
$partialAccounts[$i]['mailHost'][] = $rawAccounts[$i][$ids['inetLocalMailRecipient_server']]; $partialAccounts[$i]['mailHost'][] = $rawAccounts[$i][$ids['inetLocalMailRecipient_server']];
} }
else { else {
$errMsg = $this->messages['host'][1]; $errMsg = $this->messages['mailHost'][1];
array_push($errMsg, array($i)); array_push($errMsg, array($i));
$messages[] = $errMsg; $messages[] = $errMsg;
} }