common function to upload multi-value attributes

This commit is contained in:
Roland Gruber 2015-07-12 12:41:47 +00:00
parent 15570725e2
commit 224c4ede8d
2 changed files with 94 additions and 185 deletions

View File

@ -959,12 +959,15 @@ abstract class baseModule {
* @param String $regexID for get_preg() (e.g. 'ascii')
* @param array $message error message to add if regex does not match
* @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. "/;[ ]?/")
*/
protected function mapSimpleUploadField(&$rawAccounts, &$ids, &$partialAccounts, $position, $colName, $attrName, $regex = null, &$message = array(), &$errors = array()) {
protected function mapSimpleUploadField(&$rawAccounts, &$ids, &$partialAccounts, $position, $colName, $attrName, $regex = null, &$message = array(), &$errors = array(), $regexSplit = null) {
if (!isset($ids[$colName])) {
return;
}
if (!empty($rawAccounts[$position][$ids[$colName]])) {
// single value
if ($regexSplit == null) {
if (!empty($regex) && !get_preg($rawAccounts[$position][$ids[$colName]], $regex)) {
$errMsg = $message;
array_push($errMsg, array($position));
@ -972,6 +975,22 @@ abstract class baseModule {
}
$partialAccounts[$position][$attrName] = $rawAccounts[$position][$ids[$colName]];
}
// multi-value
else {
$list = preg_split($regexSplit, trim($rawAccounts[$position][$ids[$colName]]));
$partialAccounts[$position][$attrName] = $list;
if (!empty($regex)) {
for ($x = 0; $x < sizeof($list); $x++) {
if (!get_preg($list[$x], $regex)) {
$errMsg = $message;
array_push($errMsg, array($position));
$errors[] = $errMsg;
break;
}
}
}
}
}
}
/**

View File

@ -2211,62 +2211,18 @@ class inetOrgPerson extends baseModule implements passwordService {
// description
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_description', 'description');
// title
if (isset($ids['inetOrgPerson_title']) && ($rawAccounts[$i][$ids['inetOrgPerson_title']] != "")) {
$titleList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_title']]);
$partialAccounts[$i]['title'] = $titleList;
for ($x = 0; $x < sizeof($titleList); $x++) {
if (!get_preg($titleList[$x], 'title')) {
$errMsg = $this->messages['title'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_title', 'title', 'title', $this->messages['title'][1], $errors, '/;[ ]*/');
// employee number
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_employeeNumber', 'employeeNumber');
// employee type
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_type', 'employeeType',
'employeeType', $this->messages['employeeType'][1], $errors);
// business category
if (isset($ids['inetOrgPerson_businessCategory']) && ($rawAccounts[$i][$ids['inetOrgPerson_businessCategory']] != "")) {
$businessCategoryList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_businessCategory']]);
$partialAccounts[$i]['businessCategory'] = $businessCategoryList;
for ($x = 0; $x < sizeof($businessCategoryList); $x++) {
if (!get_preg($businessCategoryList[$x], 'businessCategory')) {
$errMsg = $this->messages['businessCategory'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_businessCategory', 'businessCategory', 'businessCategory', $this->messages['businessCategory'][1], $errors, '/;[ ]*/');
// manager
if (isset($ids['inetOrgPerson_manager']) && ($rawAccounts[$i][$ids['inetOrgPerson_manager']] != "")) {
$managerList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_manager']]);
$partialAccounts[$i]['manager'] = $managerList;
for ($x = 0; $x < sizeof($managerList); $x++) {
if (!get_preg($managerList[$x], 'dn')) {
$errMsg = $this->messages['manager'][0];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_manager', 'manager', 'dn', $this->messages['manager'][0], $errors, '/;[ ]*/');
// street
if (isset($ids['inetOrgPerson_street']) && ($rawAccounts[$i][$ids['inetOrgPerson_street']] != "")) {
$streetList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_street']]);
$partialAccounts[$i]['street'] = $streetList;
for ($x = 0; $x < sizeof($streetList); $x++) {
if (!get_preg($streetList[$x], 'street')) {
$errMsg = $this->messages['street'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_street', 'street', 'street', $this->messages['street'][1], $errors, '/;[ ]*/');
// post office box
if (isset($ids['inetOrgPerson_postOfficeBox']) && ($rawAccounts[$i][$ids['inetOrgPerson_postOfficeBox']] != "")) {
$partialAccounts[$i]['postOfficeBox'] = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_postOfficeBox']]);
@ -2302,18 +2258,7 @@ class inetOrgPerson extends baseModule implements passwordService {
// carLicense
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_carLicense', 'carLicense');
// postal code
if (isset($ids['inetOrgPerson_postalCode']) && ($rawAccounts[$i][$ids['inetOrgPerson_postalCode']] != "")) {
$postalCodeList = preg_split('/;[ ]*/', $rawAccounts[$i][$ids['inetOrgPerson_postalCode']]);
$partialAccounts[$i]['postalCode'] = $postalCodeList;
for ($x = 0; $x < sizeof($postalCodeList); $x++) {
if (!get_preg($postalCodeList[$x], 'postalCode')) {
$errMsg = $this->messages['postalCode'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_postalCode', 'postalCode', 'postalCode', $this->messages['postalCode'][1], $errors, '/;[ ]*/');
// postal address
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_address', 'postalAddress',
'postalAddress',$this->messages['postalAddress'][1] , $errors);
@ -2321,70 +2266,15 @@ class inetOrgPerson extends baseModule implements passwordService {
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_registeredAddress', 'registeredAddress',
'postalAddress',$this->messages['registeredAddress'][1] , $errors);
// telephone
if (isset($ids['inetOrgPerson_telephone']) && ($rawAccounts[$i][$ids['inetOrgPerson_telephone']] != "")) {
$telephoneList = preg_split('/;[ ]*/', trim($rawAccounts[$i][$ids['inetOrgPerson_telephone']]));
$partialAccounts[$i]['telephoneNumber'] = $telephoneList;
for ($x = 0; $x < sizeof($telephoneList); $x++) {
if (!get_preg($telephoneList[$x], 'telephone')) {
$errMsg = $this->messages['telephoneNumber'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_telephone', 'telephoneNumber', 'telephone', $this->messages['telephoneNumber'][1], $errors, '/;[ ]*/');
// home telephone
if (isset($ids['inetOrgPerson_homePhone']) && ($rawAccounts[$i][$ids['inetOrgPerson_homePhone']] != "")) {
$homePhoneList = preg_split('/;[ ]*/', trim($rawAccounts[$i][$ids['inetOrgPerson_homePhone']]));
$partialAccounts[$i]['homePhone'] = $homePhoneList;
for ($x = 0; $x < sizeof($homePhoneList); $x++) {
if (!get_preg($homePhoneList[$x], 'telephone')) {
$errMsg = $this->messages['homePhone'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_homePhone', 'homePhone', 'telephone', $this->messages['homePhone'][1], $errors, '/;[ ]*/');
// mobile
if (isset($ids['inetOrgPerson_mobile']) && ($rawAccounts[$i][$ids['inetOrgPerson_mobile']] != "")) {
$mobileList = preg_split('/;[ ]*/', trim($rawAccounts[$i][$ids['inetOrgPerson_mobile']]));
$partialAccounts[$i]['mobile'] = $mobileList;
for ($x = 0; $x < sizeof($mobileList); $x++) {
if (!get_preg($mobileList[$x], 'telephone')) {
$errMsg = $this->messages['mobileTelephone'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_mobile', 'mobile', 'telephone', $this->messages['mobileTelephone'][1], $errors, '/;[ ]*/');
// facsimile
if (isset($ids['inetOrgPerson_fax']) && ($rawAccounts[$i][$ids['inetOrgPerson_fax']] != "")) {
$facsimileTelephoneNumberList = preg_split('/;[ ]*/', trim($rawAccounts[$i][$ids['inetOrgPerson_fax']]));
$partialAccounts[$i]['facsimileTelephoneNumber'] = $facsimileTelephoneNumberList;
for ($x = 0; $x < sizeof($facsimileTelephoneNumberList); $x++) {
if (!get_preg($facsimileTelephoneNumberList[$x], 'telephone')) {
$errMsg = $this->messages['facsimileNumber'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_fax', 'facsimileTelephoneNumber', 'telephone', $this->messages['facsimileNumber'][1], $errors, '/;[ ]*/');
// pager
if (isset($ids['inetOrgPerson_pager']) && ($rawAccounts[$i][$ids['inetOrgPerson_pager']] != "")) {
$pagerList = preg_split('/;[ ]*/', trim($rawAccounts[$i][$ids['inetOrgPerson_pager']]));
$partialAccounts[$i]['pager'] = $pagerList;
for ($x = 0; $x < sizeof($pagerList); $x++) {
if (!get_preg($pagerList[$x], 'telephone')) {
$errMsg = $this->messages['pager'][1];
array_push($errMsg, array($i));
$errors[] = $errMsg;
break;
}
}
}
$this->mapSimpleUploadField($rawAccounts, $ids, $partialAccounts, $i, 'inetOrgPerson_pager', 'pager', 'telephone', $this->messages['pager'][1], $errors, '/;[ ]*/');
// eMail
if (isset($ids['inetOrgPerson_email']) && ($rawAccounts[$i][$ids['inetOrgPerson_email']] != "")) {
foreach ($replacements as $wildcard => $value) {