display as text box when > 50 recipients

This commit is contained in:
Roland Gruber 2014-01-27 19:40:50 +00:00
parent c62a5693af
commit 6a8f3e5c4e
1 changed files with 81 additions and 43 deletions

View File

@ -38,6 +38,8 @@ class nisMailAlias extends baseModule {
private $cachedMailList = null;
/** user cache */
private $cachedUserList = null;
/** display limit */
const DISPLAY_LIMIT = 50;
/**
* Returns meta data that is interpreted by parent class
@ -73,8 +75,8 @@ class nisMailAlias extends baseModule {
"Text" => _("Mails to this name are forwarded to the recipients.")
),
'recipient' => array(
"Headline" => _("Recipient"), 'attr' => 'rfc822MailMember',
"Text" => _("This is one recipient for this alias.")
"Headline" => _("Recipients"), 'attr' => 'rfc822MailMember',
"Text" => _("Please enter the recipients for this alias.")
),
'recipientList' => array(
"Headline" => _("Recipient list"), 'attr' => 'rfc822MailMember',
@ -166,8 +168,17 @@ class nisMailAlias extends baseModule {
natcasesort($this->attributes['rfc822MailMember']);
$this->attributes['rfc822MailMember'] = array_values($this->attributes['rfc822MailMember']);
$recipientCount = sizeof($this->attributes['rfc822MailMember']);
if ($recipientCount < nisMailAlias::DISPLAY_LIMIT) {
for ($i = 0; $i < $recipientCount; $i++) {
if (($i == 0) && ($recipientCount == 1)) {
$return->addElement(new htmlOutputText(_('Recipient')));
}
elseif (($i == 0) && ($recipientCount > 1)) {
$return->addElement(new htmlOutputText(_('Recipients')));
}
else {
$return->addElement(new htmlOutputText(''));
}
$mailField = new htmlInputField('rfc822MailMember' . $i, $this->attributes['rfc822MailMember'][$i]);
if (sizeof($autoList) > 0) {
$mailField->enableAutocompletion($autoList);
@ -179,6 +190,13 @@ class nisMailAlias extends baseModule {
$return->addElement(new htmlHelpLink('recipient'), true);
}
}
else {
$memberText = implode("\r\n", $this->attributes['rfc822MailMember']);
$return->addElement(new htmlTableExtendedInputTextarea('rfc822MailMember', $memberText, 50, 30, _('Recipients'), 'recipient'), true);
$return->addElement(new htmlEqualWidth(array('cn', 'rfc822MailMember')), true);
}
}
if ($recipientCount < nisMailAlias::DISPLAY_LIMIT) {
// input box for new recipient
$return->addElement(new htmlOutputText(_('New recipient')));
$newMailField = new htmlInputField('rfc822MailMember');
@ -192,6 +210,7 @@ class nisMailAlias extends baseModule {
$return->addElement(new htmlButton('addRec', 'add.png', true));
$return->addElement(new htmlHelpLink('recipient'));
$return->addElement(new htmlHiddenInput('rec_number', $recipientCount));
}
return $return;
}
@ -204,6 +223,7 @@ class nisMailAlias extends baseModule {
function process_attributes() {
$errors = array();
$this->attributes['cn'] = array();
$recipientCount = !empty($this->attributes['rfc822MailMember']) ? sizeof($this->attributes['rfc822MailMember']) : 0;
$this->attributes['rfc822MailMember'] = array();
// check alias name
if (isset($_POST['cn']) && ($_POST['cn'] != "") && get_preg($_POST['cn'], 'nis_alias')) {
@ -215,6 +235,7 @@ class nisMailAlias extends baseModule {
$message[] = $_POST['cn'];
$errors[] = $message;
}
if ($recipientCount < nisMailAlias::DISPLAY_LIMIT) {
// check old recipients
if (isset($_POST['rec_number'])) {
for ($i = 0; $i < $_POST['rec_number']; $i++) {
@ -232,7 +253,7 @@ class nisMailAlias extends baseModule {
}
// check new recipient
if (isset($_POST['rfc822MailMember']) && ($_POST['rfc822MailMember'] != "")) {
// check if address has correct format
// check if recipient has correct format
if (get_preg($_POST['rfc822MailMember'], 'nis_recipient') || get_preg($_POST['rfc822MailMember'], 'email')) {
$this->attributes['rfc822MailMember'][] = $_POST['rfc822MailMember'];
}
@ -242,6 +263,23 @@ class nisMailAlias extends baseModule {
$errors[] = $message;
}
}
}
else {
$recipients = explode("\r\n", $_POST['rfc822MailMember']);
foreach ($recipients as $recipient) {
$recipient = trim($recipient);
if (empty($recipient)) {
continue;
}
$this->attributes['rfc822MailMember'][] = $recipient;
// check if recipient has correct format
if (!get_preg($recipient, 'nis_recipient') && !get_preg($recipient, 'email')) {
$message = $this->messages['recipient'][0];
$message[] = htmlspecialchars($recipient);
$errors[] = $message;
}
}
}
$this->attributes['rfc822MailMember'] = array_unique($this->attributes['rfc822MailMember']);
return $errors;
}