support multiple regex IDs for upload check

This commit is contained in:
Roland Gruber 2019-02-27 19:22:39 +01:00
parent 3d1ce91759
commit 1eac04648a
2 changed files with 53 additions and 13 deletions

View File

@ -974,7 +974,7 @@ abstract class baseModule {
* @param String $position current position in CSV * @param String $position current position in CSV
* @param String $colName column name * @param String $colName column name
* @param String $attrName LDAP attribute name * @param String $attrName LDAP attribute name
* @param String $regexID for get_preg() (e.g. 'ascii') * @param String|String[] $regex for get_preg() (e.g. 'ascii')
* @param array $message error message to add if regex does not match * @param array $message error message to add if regex does not match
* @param array $errors list of error messages if any * @param array $errors list of error messages if any
* @param String $regexSplit multiple values are separated and can be split with this preg_split expression (e.g. "/;[ ]?/") * @param String $regexSplit multiple values are separated and can be split with this preg_split expression (e.g. "/;[ ]?/")
@ -984,12 +984,11 @@ abstract class baseModule {
return; return;
} }
if (!empty($rawAccounts[$position][$ids[$colName]])) { if (!empty($rawAccounts[$position][$ids[$colName]])) {
$regexIDs = is_array($regex) ? $regex : array($regex);
// single value // single value
if ($regexSplit == null) { if ($regexSplit == null) {
if (!empty($regex) && !get_preg($rawAccounts[$position][$ids[$colName]], $regex)) { if (!empty($regex)) {
$errMsg = $message; $this->checkUploadRegex($regexIDs, $rawAccounts[$position][$ids[$colName]], $message, $position, $errors);
array_push($errMsg, array($position));
$errors[] = $errMsg;
} }
$partialAccounts[$position][$attrName] = trim($rawAccounts[$position][$ids[$colName]]); $partialAccounts[$position][$attrName] = trim($rawAccounts[$position][$ids[$colName]]);
} }
@ -999,10 +998,7 @@ abstract class baseModule {
$partialAccounts[$position][$attrName] = $list; $partialAccounts[$position][$attrName] = $list;
if (!empty($regex)) { if (!empty($regex)) {
for ($x = 0; $x < sizeof($list); $x++) { for ($x = 0; $x < sizeof($list); $x++) {
if (!get_preg($list[$x], $regex)) { if (!$this->checkUploadRegex($regexIDs, $list[$x], $message, $position, $errors)) {
$errMsg = $message;
array_push($errMsg, array($position));
$errors[] = $errMsg;
break; break;
} }
} }
@ -1011,6 +1007,34 @@ abstract class baseModule {
} }
} }
/**
* Checks the upload value against a list of regular expressions.
*
* @param string[] $regexIDs regular expression IDs for get_preg()
* @param string $value value to check
* @param array $message error message array if not matching
* @param int $position upload position
* @param array $errors error messages
* @return value is ok
* @see get_preg()
*/
private function checkUploadRegex($regexIDs, $value, $message, $position, &$errors) {
$matched = false;
foreach ($regexIDs as $regexID) {
if (get_preg($value, $regexID)) {
$matched = true;
break;
}
}
if (!$matched) {
$errMsg = $message;
array_push($errMsg, array($position));
$errors[] = $errMsg;
return false;
}
return true;
}
/** /**
* This function returns the help entry array for a specific help id. * This function returns the help entry array for a specific help id.
* *
@ -1281,7 +1305,7 @@ abstract class baseModule {
* The field name will be the same as the attribute name. There must also be a help entry with the attribute name as ID. * The field name will be the same as the attribute name. There must also be a help entry with the attribute name as ID.
* A new line will also be added after this entry so multiple calls will show the fields one below the other. * A new line will also be added after this entry so multiple calls will show the fields one below the other.
* *
* @param htmlTable $container parent container * @param htmlTable|htmlResponsiveRow $container parent container
* @param String $attrName attribute name * @param String $attrName attribute name
* @param String $label label name * @param String $label label name
* @param boolean $required this is a required field (default false) * @param boolean $required this is a required field (default false)
@ -1300,10 +1324,20 @@ abstract class baseModule {
if ($length != null) { if ($length != null) {
$cols = $length; $cols = $length;
} }
$input = new htmlTableExtendedInputTextarea($attrName, $value, $cols, 3, $label, $attrName); if ($container instanceof htmlResponsiveRow) {
$input = new htmlResponsiveInputTextarea($attrName, $value, $cols, 3, $label, $attrName);
}
else {
$input = new htmlTableExtendedInputTextarea($attrName, $value, $cols, 3, $label, $attrName);
}
} }
else { else {
$input = new htmlTableExtendedInputField($label, $attrName, $value, $attrName); if ($container instanceof htmlResponsiveRow) {
$input = new htmlResponsiveInputField($label, $attrName, $value, $attrName);
}
else {
$input = new htmlTableExtendedInputField($label, $attrName, $value, $attrName);
}
if ($length != null) { if ($length != null) {
$input->setFieldSize($length); $input->setFieldSize($length);
} }
@ -1312,7 +1346,12 @@ abstract class baseModule {
} }
} }
$input->setRequired($required); $input->setRequired($required);
$container->addElement($input, true); if ($container instanceof htmlResponsiveRow) {
$container->add($input, 12);
}
else {
$container->addElement($input, true);
}
return $input; return $input;
} }

View File

@ -43,3 +43,4 @@
/pegasus /pegasus
/nPosixGroup.inc /nPosixGroup.inc
/nPosixUser.inc /nPosixUser.inc
/bindDLZXfr.inc