added possibility to mark upload columns as containing unique entries
This commit is contained in:
parent
e8a916a68b
commit
81aa810c0c
|
@ -492,7 +492,10 @@ help:</span> help ID</li>
|
||||||
<li><span style="font-weight: bold;"><span style="font-style: italic;">string</span>
|
<li><span style="font-weight: bold;"><span style="font-style: italic;">string</span>
|
||||||
example:</span> example value</li>
|
example:</span> example value</li>
|
||||||
<li><span style="font-weight: bold;"><span style="font-style: italic;">boolean</span>
|
<li><span style="font-weight: bold;"><span style="font-style: italic;">boolean</span>
|
||||||
required:</span> true, if user must set a value for this column<br>
|
required:</span> true, if user must set a value for this column</li>
|
||||||
|
<li><span style="font-weight: bold;">boolean unique:</span> true if
|
||||||
|
all values of this column must be different values <span
|
||||||
|
style="font-style: italic; font-weight: bold;">(optional)</span><br>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<br>
|
<br>
|
||||||
|
|
|
@ -59,7 +59,9 @@ class posixGroup extends baseModule {
|
||||||
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['posixGroup_cn']];
|
$partialAccounts[$i]['cn'] = $rawAccounts[$i][$ids['posixGroup_cn']];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$errors[] =$this->messages['cn'][2];
|
$errMsg = $this->messages['cn'][3];
|
||||||
|
array_push($errMsg, array($i));
|
||||||
|
$errors[] = $errMsg;
|
||||||
}
|
}
|
||||||
// GID
|
// GID
|
||||||
if ($rawAccounts[$i][$ids['posixGroup_gid']] == "") {
|
if ($rawAccounts[$i][$ids['posixGroup_gid']] == "") {
|
||||||
|
@ -69,6 +71,11 @@ class posixGroup extends baseModule {
|
||||||
elseif (get_preg($rawAccounts[$i][$ids['posixGroup_gid']], 'digit')) {
|
elseif (get_preg($rawAccounts[$i][$ids['posixGroup_gid']], 'digit')) {
|
||||||
$partialAccounts[$i]['gidNumber'] = $rawAccounts[$i][$ids['posixGroup_gid']];
|
$partialAccounts[$i]['gidNumber'] = $rawAccounts[$i][$ids['posixGroup_gid']];
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
$errMsg = $this->messages['gidNumber'][8];
|
||||||
|
array_push($errMsg, array($i));
|
||||||
|
$errors[] = $errMsg;
|
||||||
|
}
|
||||||
// description (UTF-8, no regex check needed)
|
// description (UTF-8, no regex check needed)
|
||||||
if ($rawAccounts[$i][$ids['posixGroup_description']] == "") {
|
if ($rawAccounts[$i][$ids['posixGroup_description']] == "") {
|
||||||
$partialAccounts[$i]['description'] = $partialAccounts[$i]['cn'];
|
$partialAccounts[$i]['description'] = $partialAccounts[$i]['cn'];
|
||||||
|
@ -293,13 +300,14 @@ class posixGroup extends baseModule {
|
||||||
'description' => _('Group name'),
|
'description' => _('Group name'),
|
||||||
'help' => 'cn',
|
'help' => 'cn',
|
||||||
'example' => _('adminstrators'),
|
'example' => _('adminstrators'),
|
||||||
'required' => true
|
'required' => true,
|
||||||
|
'unique' => true
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'name' => 'posixGroup_gid',
|
'name' => 'posixGroup_gid',
|
||||||
'description' => _('GID number'),
|
'description' => _('GID number'),
|
||||||
'help' => 'gidNumber',
|
'help' => 'gidNumber',
|
||||||
'example' => _('2034'),
|
'example' => '2034',
|
||||||
'required' => false
|
'required' => false
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
|
@ -410,9 +418,11 @@ class posixGroup extends baseModule {
|
||||||
$this->messages['gidNumber'][5] = array('ERROR', _('Minimum GID number'), _('Minimum GID number is invalid or empty!'));
|
$this->messages['gidNumber'][5] = array('ERROR', _('Minimum GID number'), _('Minimum GID number is invalid or empty!'));
|
||||||
$this->messages['gidNumber'][6] = array('ERROR', _('Maximum GID number'), _('Maximum GID number is invalid or empty!'));
|
$this->messages['gidNumber'][6] = array('ERROR', _('Maximum GID number'), _('Maximum GID number is invalid or empty!'));
|
||||||
$this->messages['gidNumber'][7] = array('ERROR', _('Maximum GID number'), _('Maximum GID number must be greater than minimum GID number!'));
|
$this->messages['gidNumber'][7] = array('ERROR', _('Maximum GID number'), _('Maximum GID number must be greater than minimum GID number!'));
|
||||||
|
$this->messages['gidNumber'][8] = array('ERROR', _('Account %s: posixGroup_gid'), _('GID number has to be a numeric value!'));
|
||||||
$this->messages['cn'][0] = array('WARN', _('Groupname'), _('You are using a capital letters. This can cause problems because windows isn\'t case-sensitive.'));
|
$this->messages['cn'][0] = array('WARN', _('Groupname'), _('You are using a capital letters. This can cause problems because windows isn\'t case-sensitive.'));
|
||||||
$this->messages['cn'][1] = array('WARN', _('Groupname'), _('Groupname in use. Selected next free groupname.'));
|
$this->messages['cn'][1] = array('WARN', _('Groupname'), _('Groupname in use. Selected next free groupname.'));
|
||||||
$this->messages['cn'][2] = array('ERROR', _('Groupname'), _('Groupname contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
$this->messages['cn'][2] = array('ERROR', _('Groupname'), _('Groupname contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
||||||
|
$this->messages['cn'][3] = array('ERROR', _('Account %s: posixGroup_cn'), _('Groupname contains invalid characters. Valid characters are: a-z, A-Z, 0-9 and .-_ !'));
|
||||||
$this->messages['memberUID'][0] = array('ERROR', 'Account %s: posixGroup_members', _("This value must be a list of user names separated by semicolons."));
|
$this->messages['memberUID'][0] = array('ERROR', 'Account %s: posixGroup_members', _("This value must be a list of user names separated by semicolons."));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,8 +87,8 @@ echo "<body>\n";
|
||||||
|
|
||||||
if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
|
if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
|
||||||
// check if input file is well formated
|
// check if input file is well formated
|
||||||
$data = array();
|
$data = array(); // input values without first row
|
||||||
$ids = array();
|
$ids = array(); // <column name> => <column number for $data>
|
||||||
// get input fields from modules
|
// get input fields from modules
|
||||||
$columns = getUploadColumns($_POST['scope']);
|
$columns = getUploadColumns($_POST['scope']);
|
||||||
// read input file
|
// read input file
|
||||||
|
@ -101,8 +101,10 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
|
||||||
while (($line = fgetcsv($handle, 2000)) !== false ) { // account rows
|
while (($line = fgetcsv($handle, 2000)) !== false ) { // account rows
|
||||||
$data[] = $line;
|
$data[] = $line;
|
||||||
}
|
}
|
||||||
// check if all required attributes are given
|
|
||||||
$errors = array();
|
$errors = array();
|
||||||
|
|
||||||
|
// check if all required columns are present
|
||||||
$checkcolumns = array();
|
$checkcolumns = array();
|
||||||
$columns = call_user_func_array('array_merge', $columns);
|
$columns = call_user_func_array('array_merge', $columns);
|
||||||
for ($i = 0; $i < sizeof($columns); $i++) {
|
for ($i = 0; $i < sizeof($columns); $i++) {
|
||||||
|
@ -111,6 +113,8 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
|
||||||
else $errors[] = array(_("A required column is missing in your CSV file."), $columns[$i]['name']);
|
else $errors[] = array(_("A required column is missing in your CSV file."), $columns[$i]['name']);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if all required attributes are given
|
||||||
$invalidColumns = array();
|
$invalidColumns = array();
|
||||||
$id_names = array_keys($ids);
|
$id_names = array_keys($ids);
|
||||||
for ($i = 0; $i < sizeof($checkcolumns); $i++) {
|
for ($i = 0; $i < sizeof($checkcolumns); $i++) {
|
||||||
|
@ -130,10 +134,27 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
|
||||||
for ($i = 0; $i < sizeof($invalidColumns); $i++) {
|
for ($i = 0; $i < sizeof($invalidColumns); $i++) {
|
||||||
$errors[] = array(_("One or more values of the required column \"$invalidColumns[$i]\" are missing."), "");
|
$errors[] = array(_("One or more values of the required column \"$invalidColumns[$i]\" are missing."), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if values in unique columns are correct
|
||||||
|
for ($i = 0; $i < sizeof($columns); $i++) {
|
||||||
|
if ($columns[$i]['unique'] == true) {
|
||||||
|
$colNumber = $ids[$columns[$i]['name']];
|
||||||
|
$values_given = array();
|
||||||
|
for ($r = 0; $r < sizeof($data); $r++) {
|
||||||
|
$values_given[] = $data[$r][$colNumber];
|
||||||
|
}
|
||||||
|
$values_unique = array_unique($values_given);
|
||||||
|
if (sizeof($values_given) != sizeof($values_unique)) {
|
||||||
|
$errors[] = array(_("This column is defined to include unique entries but duplicates were found:"), $columns[$i]['name']);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if input data is invalid just display error messages (max 50)
|
// if input data is invalid just display error messages (max 50)
|
||||||
if (sizeof($errors) > 0) {
|
if (sizeof($errors) > 0) {
|
||||||
for ($i = 0; $i < sizeof($errors); $i++) StatusMessage("ERROR", $errors[$i][0], $errors[$i][1]);
|
for ($i = 0; $i < sizeof($errors); $i++) StatusMessage("ERROR", $errors[$i][0], $errors[$i][1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// let modules build accounts
|
// let modules build accounts
|
||||||
else {
|
else {
|
||||||
$accounts = buildUploadAccounts($_POST['scope'], $data, $ids);
|
$accounts = buildUploadAccounts($_POST['scope'], $data, $ids);
|
||||||
|
|
Loading…
Reference in New Issue