';
}
}
return $return;
}
/**
* Returns the meta HTML code for each input field.
* format: array( => array(), ...)
* It is not possible to display help links.
*
* @param array $fields list of active fields
* @param array $attributes attributes of LDAP account
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array list of meta HTML elements (field name => htmlTableRow)
*/
function getSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = array();
if ($passwordChangeOnly) {
return $return; // no fields as long no LDAP content can be read
}
if (in_array('sshPublicKey', $fields)) {
$sshPublicKeys = array();
if (isset($attributes['sshPublicKey'][0])) {
$sshPublicKeys = $attributes['sshPublicKey'];
}
$sshPublicKeyField = new htmlInputTextarea('ldapPublicKey_sshPublicKey', implode("\r\n", $sshPublicKeys), 100, 4);
if (in_array('sshPublicKey', $readOnlyFields)) {
$text = '';
for ($i = 0; $i < sizeof($sshPublicKeys); $i++) {
if ($i > 0) {
$text .= ' ';
}
$text .= htmlspecialchars($sshPublicKeys[$i]);
}
$sshPublicKeyField = new htmlOutputText($text, false);
}
$label = new htmlOutputText(_('SSH public keys'));
$label->alignment = htmlElement::ALIGN_TOP;
$return['sshPublicKey'] = new htmlTableRow(array(
$label, $sshPublicKeyField
));
}
return $return;
}
/**
* Checks if all input values are correct and returns the LDAP attributes which should be changed.
* Return values:
* messages: array of parameters to create status messages
* add: array of attributes to add
* del: array of attributes to remove
* mod: array of attributes to modify
* info: array of values with informational value (e.g. to be used later by pre/postModify actions)
*
* Calling this method does not require the existence of an enclosing {@link accountContainer}.
*
* @param string $fields input fields
* @param array $attributes LDAP attributes
* @param boolean $passwordChangeOnly indicates that the user is only allowed to change his password and no LDAP content is readable
* @param array $readOnlyFields list of read-only fields
* @return array messages and attributes (array('messages' => array(), 'add' => array('mail' => array('test@test.com')), 'del' => array(), 'mod' => array(), 'info' => array()))
*/
public function checkSelfServiceOptions($fields, $attributes, $passwordChangeOnly, $readOnlyFields) {
$return = array('messages' => array(), 'add' => array(), 'del' => array(), 'mod' => array(), 'info' => array());
if ($passwordChangeOnly) {
return $return; // skip processing if only a password change is done
}
if (in_array('sshPublicKey', $fields)) {
$newKeys = explode("\r\n", trim($_POST['ldapPublicKey_sshPublicKey']));
$count = sizeof($newKeys);
for ($i = 0; $i < $count; $i++) {
if (trim($newKeys[$i]) == '') {
unset($newKeys[$i]);
}
}
$newKeys = array_values(array_unique($newKeys));
$oldKeys = array();
if (isset($attributes['sshPublicKey'][0])) {
$oldKeys = $attributes['sshPublicKey'];
}
$update = false;
if (sizeof($newKeys) != sizeof($oldKeys)) {
$update = true;
}
else {
for ($i = 0; $i < sizeof($newKeys); $i++) {
if (!in_array($newKeys[$i], $oldKeys)) {
$update = true;
break;
}
}
}
if ($update) {
if (sizeof($oldKeys) == 0) {
$return['add']['sshPublicKey'] = $newKeys;
}
elseif (sizeof($newKeys) == 0) {
$return['del']['sshPublicKey'] = $newKeys;
}
else {
$return['mod']['sshPublicKey'] = $newKeys;
}
}
}
return $return;
}
}
?>