added htmlAccordion and option to specify user name suggestion format

This commit is contained in:
Roland Gruber 2013-03-24 18:39:08 +00:00
parent 76d207f19f
commit 5932e0abc6
3 changed files with 118 additions and 16 deletions

View File

@ -19,6 +19,7 @@
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-15"><title>Upgrade notes</title>
@ -35,7 +36,10 @@ This is a list of API changes for all LAM releases.
<br>
<h2>4.0 -&gt; 4.1</h2>CSS changes:<br>
<h2>4.1 -&gt; 4.2</h2>New meta HTML classes: htmlEqualHeight, htmlAccordion<br>
<br>
<h2>4.0 -&gt; 4.1</h2>
CSS changes:<br>
<ul>
<li>type specific "td.{TYPE}nav-activepage" was replaced by common "td.activepage" in layout.css</li>
<li>renamed ".{TYPE}list-bright" to ".{TYPE}-bright" and ".{TYPE}list-dark" to ".{TYPE}-dark"</li>

View File

@ -2973,4 +2973,78 @@ class htmlSortableList extends htmlElement {
}
/**
* Creates a list of content elements in accordion style.
* HTML special characters must be escaped before providing to htmlAccordion.
*/
class htmlAccordion extends htmlElement {
private $id = null;
private $elements = null;
private $openInitial = '1';
private $collapsible = false;
/**
* Constructor.
*
* @param String $id HTML ID
* @param array $elements list of content elements array('title' => htmlElement)
* @param String $openInitial index of element that is initially opened (default: 0), set to 'false' to close all
* @param boolean $collapsible specifies if all elements may be closed at the same time (default: false, true if $openInitial is false)
*/
function __construct($id, $elements, $openInitial = '0', $collapsible = false) {
$this->id = $id;
$this->elements = $elements;
$this->openInitial = $openInitial;
if (($openInitial === 'false') || ($openInitial === false)) {
$this->collapsible = true;
}
else {
$this->collapsible = $collapsible;
}
}
/**
* Prints the HTML code for this element.
*
* @param string $module Name of account module
* @param array $input List of meta-HTML elements
* @param array $values List of values which override the defaults in $input (name => value)
* @param boolean $restricted If true then no buttons will be displayed
* @param integer $tabindex Start value of tabulator index for input fields
* @param string $scope Account type
* @return array List of input field names and their type (name => type)
*/
function generateHTML($module, $input, $values, $restricted, &$tabindex, $scope) {
$result = array();
$collapsible = 'false';
if ($this->collapsible) {
$collapsible = 'true';
}
$active = 'false';
if ($this->openInitial !== false) {
$active = $this->openInitial;
}
echo '<div id="' . $this->id . '">';
foreach ($this->elements as $label => $content) {
echo '<h3>' . $label . '</h3>';
echo '<div>';
$result = array_merge($result, $content->generateHTML($module, $input, $values, $restricted, $tabindex, $scope));
echo '</div>';
}
echo '</div>';
$script = 'jQuery(function() {
$( "#' . $this->id . '" ).accordion({
collapsible: ' . $collapsible . ',
active: ' . $active . '
});
});';
$js = new htmlJavaScript($script);
$js->generateHTML($module, $input, $values, $restricted, $tabindex, $scope);
return $result;
}
}
?>

View File

@ -66,8 +66,6 @@ class posixAccount extends baseModule implements passwordService {
private $cachedUIDList = null;
/** caches the list of known user names */
private $cachedUserNameList = null;
/** if set to true the suggested user name for John Doe will be john.doe instead of jdoe */
protected $SUGGEST_LONG_USER_NAME = false;
/**
* This function fills the error message array with messages.
@ -219,7 +217,6 @@ class posixAccount extends baseModule implements passwordService {
$configOptionsContainer->addElement(new htmlSubTitle(_('Options')), true);
$configOptionsContainer->addElement(new htmlTableExtendedSelect('posixAccount_pwdHash', getSupportedHashTypes(),
array('SSHA'), _("Password hash type"), 'pwdHash'), true);
$configOptionsContainer->addElement(new htmlTableExtendedInputCheckbox('posixAccount_primaryGroupAsSecondary', false, _('Set primary group as memberUid'), 'primaryGroupAsSecondary'), true);
$configOptionsContainer->addElement(new htmlTableExtendedInputTextarea('posixAccount_shells', implode("\r\n", $this->getShells()), 30, 4, _('Login shells'), 'loginShells'), true);
$hiddenOptionsContainer = new htmlGroup();
$hiddenOptionsContainer->colspan = 5;
@ -239,7 +236,13 @@ class posixAccount extends baseModule implements passwordService {
}
}
$hiddenOptionsContainer->addElement($configContainerOptions);
$configOptionsContainer->addElement($hiddenOptionsContainer);
$configOptionsContainer->addElement($hiddenOptionsContainer, true);
$advancedOptions = new htmlTable();
$advancedOptions->addElement(new htmlTableExtendedInputCheckbox('posixAccount_primaryGroupAsSecondary', false, _('Set primary group as memberUid'), 'primaryGroupAsSecondary'), true);
$advancedOptions->addElement(new htmlTableExtendedInputField(_('User name suggestion'), 'posixAccount_userNameSuggestion', '@givenname@%sn%', 'userNameSuggestion'));
$advancedOptionsAccordion = new htmlAccordion('posixAccountAdvancedOptions', array(_('Advanced options') => $advancedOptions), false);
$advancedOptionsAccordion->colspan = 5;
$configOptionsContainer->addElement($advancedOptionsAccordion);
$return['config_options']['all'] = $configOptionsContainer;
// upload
@ -393,6 +396,11 @@ class posixAccount extends baseModule implements passwordService {
}
// help Entries
$return['help'] = array(
'userNameSuggestion' => array(
"Headline" => _("User name suggestion"),
"Text" => _("LAM will suggest a user name based on e.g. first and last name. Here you can specify the suggestion. %sn% will be replaced by the last name. @givenname@ will be replaced by the first character of first name. Only attributes of tab Personal may be used.")
. '<br>' . _('Common examples are "@givenname@%sn%" or "%givenname%.%sn%".')
),
'hiddenOptions' => array(
"Headline" => _("Hidden options"),
"Text" => _("The selected options will not be managed inside LAM. You can use this to reduce the number of displayed input fields.")
@ -2630,20 +2638,36 @@ class posixAccount extends baseModule implements passwordService {
* @return String user name
*/
protected function getUserNameSuggestion($attrs) {
if (isset($attrs['sn'][0])) {
if (isset($attrs['givenName'][0]) && ($attrs['givenName'][0] != '')) {
if ($this->SUGGEST_LONG_USER_NAME) {
return preg_replace('/[^a-z0-9_\\.-]/', '', strtolower($attrs['givenName'][0] . '.' . $attrs['sn'][0]));
$attributes = array_change_key_case($attrs, CASE_LOWER);
$format = '@givenname@%sn%';
if (isset($this->moduleSettings['posixAccount_userNameSuggestion'][0])) {
$format = strtolower($this->moduleSettings['posixAccount_userNameSuggestion'][0]);
}
else {
return preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['givenName'][0][0] . $attrs['sn'][0]));
// search for @key@ wildcards in format string and replace with first character of attribute
$wildcards = array();
if (preg_match_all('/@([^@]|[a-zA-Z_-])+@/', $format, $wildcards) > 0) {
for ($i = 0; $i < sizeof($wildcards[0]); $i++) {
$wc = substr($wildcards[0][$i], 1, strlen($wildcards[0][$i]) - 2);
$value = '';
if (isset($attributes[$wc][0])) {
$value = $attributes[$wc][0][0];
}
$format = str_replace('@' . $wc . '@', $value, $format);
}
}
else {
return preg_replace('/[^a-z0-9_-]/', '', strtolower($attrs['sn'][0]));
// search for %key% wildcards in format string and replace with attribute
$wildcards = array();
if (preg_match_all('/%([^%]|[a-zA-Z_-])+%/', $format, $wildcards) > 0) {
for ($i = 0; $i < sizeof($wildcards[0]); $i++) {
$wc = substr($wildcards[0][$i], 1, strlen($wildcards[0][$i]) - 2);
$value = '';
if (isset($attributes[$wc][0])) {
$value = $attributes[$wc][0];
}
$format = str_replace('%' . $wc . '%', $value, $format);
}
}
return null;
return $format;
}
/**