reduced code
This commit is contained in:
parent
5200138e06
commit
f8ce8e0ef0
|
@ -1220,8 +1220,10 @@ abstract class baseModule {
|
|||
* @param boolean $required this is a required field (default false)
|
||||
* @param integer $length field length
|
||||
* @param boolean $isTextArea show as text area (default false)
|
||||
* @param array $autoCompleteValues values for auto-completion
|
||||
* @param integer $fieldSize field size
|
||||
*/
|
||||
protected function addMultiValueInputTextField(&$container, $attrName, $label, $required = false, $length = null, $isTextArea = false, $autoCompleteValues = null) {
|
||||
protected function addMultiValueInputTextField(&$container, $attrName, $label, $required = false, $length = null, $isTextArea = false, $autoCompleteValues = null, $fieldSize = null) {
|
||||
$values = array();
|
||||
if (isset($this->attributes[$attrName][0])) {
|
||||
$values = $this->attributes[$attrName];
|
||||
|
@ -1231,14 +1233,22 @@ abstract class baseModule {
|
|||
}
|
||||
natcasesort($values);
|
||||
$values = array_values($values);
|
||||
$labelTextOut = new htmlOutputText($label);
|
||||
$labelTextOut->alignment = htmlElement::ALIGN_TOP;
|
||||
$container->addElement($labelTextOut);
|
||||
if ($label !== null) {
|
||||
$labelTextOut = new htmlOutputText($label);
|
||||
$labelTextOut->alignment = htmlElement::ALIGN_TOP;
|
||||
$container->addElement($labelTextOut);
|
||||
}
|
||||
$subContainer = new htmlTable();
|
||||
$subContainer->alignment = htmlElement::ALIGN_TOP;
|
||||
for ($i = 0; $i < sizeof($values); $i++) {
|
||||
if (!$isTextArea) {
|
||||
$input = new htmlInputField($attrName . '_' . $i, $values[$i]);
|
||||
if (!empty($length)) {
|
||||
$input->setFieldMaxLength($length);
|
||||
}
|
||||
if (!empty($fieldSize)) {
|
||||
$input->setFieldSize($fieldSize);
|
||||
}
|
||||
if (!empty($autoCompleteValues)) {
|
||||
$input->enableAutocompletion($autoCompleteValues);
|
||||
}
|
||||
|
@ -1282,7 +1292,11 @@ abstract class baseModule {
|
|||
unset($this->attributes[$attrName][$counter]);
|
||||
}
|
||||
elseif (($validationID != null) && ($this->attributes[$attrName][$counter] != '') && !get_preg($this->attributes[$attrName][$counter], $validationID)) {
|
||||
$errors[] = $this->messages[$attrName][0];
|
||||
$msg = $this->messages[$attrName][0];
|
||||
if (sizeof($msg) < 3) {
|
||||
$msg[] = htmlspecialchars($this->attributes[$attrName][$counter]);
|
||||
}
|
||||
$errors[] = $msg;
|
||||
}
|
||||
$counter++;
|
||||
}
|
||||
|
|
|
@ -258,13 +258,7 @@ class kolabUser extends baseModule {
|
|||
}
|
||||
// mailbox server
|
||||
if (!isset($this->orig['mailHost'][0])) { // value currently not set
|
||||
$mailHost = '';
|
||||
if (isset($this->attributes['mailHost'][0])) {
|
||||
$mailHost = $this->attributes['mailHost'][0];
|
||||
}
|
||||
$serverInput = new htmlTableExtendedInputField(_('Mailbox home server'), 'mailHost', $mailHost, 'mailHost');
|
||||
$serverInput->setRequired(true);
|
||||
$return->addElement($serverInput, true);
|
||||
$this->addSimpleInputTextField($return, 'mailHost', _('Mailbox home server'), true);
|
||||
}
|
||||
else { // input is unchangable when set
|
||||
$return->addElement(new htmlOutputText(_('Mailbox home server')));
|
||||
|
@ -309,20 +303,7 @@ class kolabUser extends baseModule {
|
|||
$return->addElement($invitationContainer, true);
|
||||
// mail aliases
|
||||
$return->addElement(new htmlSubTitle(_('Email aliases')), true);
|
||||
$mailAliasContainer = new htmlTable();
|
||||
$mailAliasContainer->colspan = 3;
|
||||
if (isset($this->attributes['alias'])) {
|
||||
for ($i = 0; $i < sizeof($this->attributes['alias']); $i++) {
|
||||
$mailAliasContainer->addElement(new htmlInputField('alias' . $i, $this->attributes['alias'][$i]));
|
||||
$mailAliasContainer->addElement(new htmlButton('delAlias' . $i, 'del.png', true));
|
||||
$mailAliasContainer->addElement(new htmlHelpLink('alias'), true);
|
||||
}
|
||||
}
|
||||
// input box for new mail alias
|
||||
$mailAliasContainer->addElement(new htmlInputField('alias'));
|
||||
$mailAliasContainer->addElement(new htmlButton('addAlias', 'add.png', true));
|
||||
$mailAliasContainer->addElement(new htmlHelpLink('alias'), true);
|
||||
$return->addElement($mailAliasContainer, true);
|
||||
$this->addMultiValueInputTextField($return, 'alias');
|
||||
// delegates
|
||||
$delegates = searchLDAPByAttribute('mail', '*', 'inetOrgPerson', array('mail'), array('user'));
|
||||
for ($i = 0; $i < sizeof($delegates); $i++) {
|
||||
|
@ -431,38 +412,8 @@ class kolabUser extends baseModule {
|
|||
if (isset($_POST['defaultInvPol']) && ($_POST['defaultInvPol'] != "")) {
|
||||
$this->attributes['kolabInvitationPolicy'][] = $policies[$_POST['defaultInvPol']];
|
||||
}
|
||||
// check old mail aliases
|
||||
$this->attributes['alias'] = array();
|
||||
$i = 0;
|
||||
while (isset($_POST['alias' . $i])) {
|
||||
if (isset($_POST['delAlias' . $i])) {
|
||||
$i++;
|
||||
continue;
|
||||
}
|
||||
if (isset($_POST['alias' . $i]) && ($_POST['alias' . $i] != "") && !in_array($_POST['alias' . $i], $this->attributes['alias'])) {
|
||||
// check mail alias
|
||||
if (!get_preg($_POST['alias' . $i], 'email')) {
|
||||
$message = $this->messages['alias'][0];
|
||||
$message[] = $_POST['alias' . $i];
|
||||
$errors[] = $message;
|
||||
}
|
||||
$this->attributes['alias'][] = $_POST['alias' . $i];
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
// check new mail alias
|
||||
if (isset($_POST['alias']) && ($_POST['alias'] != "")) {
|
||||
// check new mail alias
|
||||
if (!get_preg($_POST['alias'], 'email')) {
|
||||
$message = $this->messages['alias'][0];
|
||||
$message[] = $_POST['alias'];
|
||||
$errors[] = $message;
|
||||
}
|
||||
else {
|
||||
$this->attributes['alias'][] = $_POST['alias'];
|
||||
}
|
||||
}
|
||||
$this->attributes['alias'] = array_unique($this->attributes['alias']);
|
||||
// mail aliases
|
||||
$this->processMultiValueInputTextField('alias', $errors, 'email');
|
||||
// check old delegates
|
||||
$this->attributes['kolabDelegate'] = array();
|
||||
$i = 0;
|
||||
|
|
|
@ -61,7 +61,7 @@ class ldapPublicKey extends baseModule {
|
|||
$return['attributes'] = array('sshPublicKey');
|
||||
// help Entries
|
||||
$return['help'] = array(
|
||||
'key' => array(
|
||||
'sshPublicKey' => array(
|
||||
"Headline" => _("SSH public key"), 'attr' => 'sshPublicKey',
|
||||
"Text" => _("Please enter your public SSH key.")
|
||||
),
|
||||
|
@ -109,29 +109,7 @@ class ldapPublicKey extends baseModule {
|
|||
*/
|
||||
function display_html_attributes() {
|
||||
$return = new htmlTable();
|
||||
$keyCount = 0;
|
||||
// list current keys
|
||||
if (isset($this->attributes['sshPublicKey'])) {
|
||||
$keyCount = sizeof($this->attributes['sshPublicKey']);
|
||||
for ($i = 0; $i < sizeof($this->attributes['sshPublicKey']); $i++) {
|
||||
$return->addElement(new htmlOutputText(_('SSH public key')));
|
||||
$sshInput = new htmlInputField('sshPublicKey' . $i, $this->attributes['sshPublicKey'][$i]);
|
||||
$sshInput->setFieldSize(50);
|
||||
$sshInput->setFieldMaxLength(16384);
|
||||
$return->addElement($sshInput);
|
||||
$return->addElement(new htmlButton('delKey' . $i, 'del.png', true));
|
||||
$return->addElement(new htmlHelpLink('key'), true);
|
||||
}
|
||||
}
|
||||
// input box for new key
|
||||
$return->addElement(new htmlOutputText(_('New SSH public key')));
|
||||
$sshNewKey = new htmlInputField('sshPublicKey');
|
||||
$sshNewKey->setFieldSize(50);
|
||||
$sshNewKey->setFieldMaxLength(4096);
|
||||
$return->addElement($sshNewKey);
|
||||
$return->addElement(new htmlButton('addKey', 'add.png', true));
|
||||
$return->addElement(new htmlHelpLink('key'));
|
||||
$return->addElement(new htmlHiddenInput('key_number', $keyCount), true);
|
||||
$this->addMultiValueInputTextField($return, 'sshPublicKey', _('SSH public key'), false, '16384', false, null, '50');
|
||||
// file upload
|
||||
$return->addElement(new htmlSpacer(null, '20px'), true);
|
||||
$return->addElement(new htmlOutputText(_('Upload file')));
|
||||
|
@ -139,9 +117,9 @@ class ldapPublicKey extends baseModule {
|
|||
$uploadGroup->addElement(new htmlInputFileUpload('sshPublicKeyFile'));
|
||||
$uploadGroup->addElement(new htmlSpacer('1px', null));
|
||||
$uploadGroup->addElement(new htmlButton('sshPublicKeyFileSubmit', _('Upload')));
|
||||
$uploadGroup->addElement(new htmlSpacer('5px', null));
|
||||
$uploadGroup->addElement(new htmlHelpLink('upload'));
|
||||
$return->addElement($uploadGroup);
|
||||
$return->addElement(new htmlOutputText(''));
|
||||
$return->addElement(new htmlHelpLink('upload'));
|
||||
return $return;
|
||||
}
|
||||
|
||||
|
@ -153,20 +131,7 @@ class ldapPublicKey extends baseModule {
|
|||
*/
|
||||
function process_attributes() {
|
||||
$messages = array();
|
||||
$this->attributes['sshPublicKey'] = array();
|
||||
// check old keys
|
||||
if (isset($_POST['key_number'])) {
|
||||
for ($i = 0; $i < $_POST['key_number']; $i++) {
|
||||
if (isset($_POST['delKey' . $i])) continue;
|
||||
if (isset($_POST['sshPublicKey' . $i]) && ($_POST['sshPublicKey' . $i] != "")) {
|
||||
$this->attributes['sshPublicKey'][] = $_POST['sshPublicKey' . $i];
|
||||
}
|
||||
}
|
||||
}
|
||||
// check new key
|
||||
if (isset($_POST['sshPublicKey']) && ($_POST['sshPublicKey'] != "")) {
|
||||
$this->attributes['sshPublicKey'][] = $_POST['sshPublicKey'];
|
||||
}
|
||||
$this->processMultiValueInputTextField('sshPublicKey', $messages);
|
||||
// file upload
|
||||
if (isset($_POST['sshPublicKeyFileSubmit'])) {
|
||||
if ($_FILES['sshPublicKeyFile'] && ($_FILES['sshPublicKeyFile']['size'] > 0)) {
|
||||
|
|
Loading…
Reference in New Issue