refactoring

This commit is contained in:
Roland Gruber 2018-12-23 13:54:08 +01:00
parent 077556a6a9
commit de2b6e1631
2 changed files with 34 additions and 30 deletions

View File

@ -190,9 +190,9 @@ abstract class htmlElement {
class htmlTable extends htmlElement { class htmlTable extends htmlElement {
/** table footer */ /** table footer */
const footer = "</table>\n"; const FOOTER = "</table>\n";
/** new line */ /** new line */
const newLine = "</tr><tr>\n"; const NEWLINE = "</tr><tr>\n";
/** list of subelements */ /** list of subelements */
private $elements = array(); private $elements = array();
@ -270,7 +270,7 @@ class htmlTable extends htmlElement {
$this->elements[] = "<tr>\n"; $this->elements[] = "<tr>\n";
} }
else { else {
$this->elements[] = htmlTable::newLine; $this->elements[] = htmlTable::NEWLINE;
} }
} }
@ -327,7 +327,7 @@ class htmlTable extends htmlElement {
} }
// print simple Strings // print simple Strings
else { else {
if ($i != (sizeof($this->elements) - 1) || !($this->elements[$i] == htmlTable::newLine) ) { if ($i != (sizeof($this->elements) - 1) || !($this->elements[$i] == htmlTable::NEWLINE) ) {
echo $this->elements[$i]; echo $this->elements[$i];
} }
} }
@ -335,7 +335,7 @@ class htmlTable extends htmlElement {
if ($this->rowOpen) { if ($this->rowOpen) {
echo "</tr>\n"; echo "</tr>\n";
} }
echo htmlTable::footer; echo htmlTable::FOOTER;
return $return; return $return;
} }
@ -349,7 +349,7 @@ class htmlTable extends htmlElement {
return; return;
} }
// remove obsolete new lines at the end // remove obsolete new lines at the end
if ($table->elements[sizeof($table->elements) - 1] == htmlTable::newLine) { if ($table->elements[sizeof($table->elements) - 1] == htmlTable::NEWLINE) {
unset($table->elements[sizeof($table->elements) - 1]); unset($table->elements[sizeof($table->elements) - 1]);
} }
// close last row of other table if needed // close last row of other table if needed
@ -358,7 +358,7 @@ class htmlTable extends htmlElement {
} }
// close last own row if needed // close last own row if needed
if ($this->rowOpen) { if ($this->rowOpen) {
if ($this->elements[sizeof($this->elements) - 1] == htmlTable::newLine) { if ($this->elements[sizeof($this->elements) - 1] == htmlTable::NEWLINE) {
unset($this->elements[sizeof($this->elements) - 1]); unset($this->elements[sizeof($this->elements) - 1]);
} }
else { else {

View File

@ -939,11 +939,12 @@ class posixGroup extends baseModule implements passwordService {
// get last character of group name // get last character of group name
$lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-1, 1); $lastchar = substr($this->attributes['cn'][0], strlen($this->attributes['cn'][0])-1, 1);
// Last character is no number // Last character is no number
if ( !preg_match('/^([0-9])+$/', $lastchar)) if (!preg_match('/^([0-9])+$/', $lastchar)) {
/* Last character is no number. Therefore we only have to /* Last character is no number. Therefore we only have to
* add "2" to it. * add "2" to it.
*/ */
$this->attributes['cn'][0] = $this->attributes['cn'][0] . '2'; $this->attributes['cn'][0] = $this->attributes['cn'][0] . '2';
}
else { else {
/* Last character is a number -> we have to increase the number until we've /* Last character is a number -> we have to increase the number until we've
* found a groupname with trailing number which is not in use. * found a groupname with trailing number which is not in use.
@ -952,11 +953,14 @@ class posixGroup extends baseModule implements passwordService {
* with the groupname and a part with the trailing number * with the groupname and a part with the trailing number
*/ */
$i = strlen($this->attributes['cn'][0]) - 1; $i = strlen($this->attributes['cn'][0]) - 1;
$mark = false;
// Set $i to the last character which is a number in $account_new->general_username // Set $i to the last character which is a number in $account_new->general_username
while (!$mark) { while (true) {
if (preg_match('/^([0-9])+$/',substr($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0])-$i))) $i--; if (preg_match('/^([0-9])+$/',substr($this->attributes['cn'][0], $i, strlen($this->attributes['cn'][0]) - $i))) {
else $mark=true; $i--;
}
else {
break;
}
} }
// increase last number with one // increase last number with one
$firstchars = substr($this->attributes['cn'][0], 0, $i+1); $firstchars = substr($this->attributes['cn'][0], 0, $i+1);
@ -1148,12 +1152,11 @@ class posixGroup extends baseModule implements passwordService {
// profile mappings in meta data // profile mappings in meta data
parent::load_profile($profile); parent::load_profile($profile);
// add extension // add extension
if (isset($profile['posixGroup_addExt'][0]) && ($profile['posixGroup_addExt'][0] == "true")) { if (isset($profile['posixGroup_addExt'][0]) && ($profile['posixGroup_addExt'][0] == "true")
if (!in_array('posixGroup', $this->attributes['objectClass'])) { && !in_array('posixGroup', $this->attributes['objectClass'])) {
$this->attributes['objectClass'][] = 'posixGroup'; $this->attributes['objectClass'][] = 'posixGroup';
} }
} }
}
/** /**
* Returns one or more free GID numbers. * Returns one or more free GID numbers.
@ -1187,7 +1190,9 @@ class posixGroup extends baseModule implements passwordService {
$gidList = $this->getGIDs($type); $gidList = $this->getGIDs($type);
$gids = array(); $gids = array();
foreach ($gidList as $gid) { foreach ($gidList as $gid) {
if (($gid <= $maxID) && ($gid >= $minID)) $gids[] = $gid; // ignore GIDs > maxID and GIDs < minID if (($gid <= $maxID) && ($gid >= $minID)) {
$gids[] = $gid; // ignore GIDs > maxID and GIDs < minID
}
} }
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
if (count($gids) != 0) { if (count($gids) != 0) {
@ -1207,8 +1212,12 @@ class posixGroup extends baseModule implements passwordService {
// find free numbers between existing ones // find free numbers between existing ones
else { else {
$k = intval($minID); $k = intval($minID);
while (in_array($k, $gids)) $k++; while (in_array($k, $gids)) {
if ($k > $maxID) return null; $k++;
}
if ($k > $maxID) {
return null;
}
else { else {
$ret[] = $k; $ret[] = $k;
$gids[] = $k; $gids[] = $k;
@ -1426,12 +1435,7 @@ class posixGroup extends baseModule implements passwordService {
* @return boolean is Windows * @return boolean is Windows
*/ */
private function isWindows() { private function isWindows() {
if (in_array('windowsGroup', $this->getAccountContainer()->get_type()->getModules())) { return (in_array('windowsGroup', $this->getAccountContainer()->get_type()->getModules()));
return true;
}
else {
return false;
}
} }
/** /**