refactoring

This commit is contained in:
Roland Gruber 2018-01-07 17:33:46 +01:00
parent 7db09169be
commit c370ab7e09
1 changed files with 24 additions and 24 deletions

View File

@ -79,17 +79,17 @@ if (isset($_GET['showldif'])) {
echo "DN: " . $account['dn'] . "\n"; echo "DN: " . $account['dn'] . "\n";
unset($account['dn']); unset($account['dn']);
$keys = array_keys($account); $keys = array_keys($account);
for ($k = 0; $k < sizeof($keys); $k++) { foreach ($keys as $key) {
if (strpos($keys[$k], 'INFO.') === 0) { if (strpos($key, 'INFO.') === 0) {
continue; continue;
} }
if (is_array($account[$keys[$k]])) { if (is_array($account[$key])) {
for ($x = 0; $x < sizeof($account[$keys[$k]]); $x++) { foreach ($account[$key] as $value) {
echo $keys[$k] . ": " . $account[$keys[$k]][$x] . "\n"; echo $key . ": " . $value . "\n";
} }
} }
else { else {
echo $keys[$k] . ": " . $account[$keys[$k]] . "\n"; echo $key . ": " . $account[$key] . "\n";
} }
} }
echo "\n"; echo "\n";
@ -126,8 +126,8 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// read input file // read input file
$handle = fopen ($_FILES['inputfile']['tmp_name'], "r"); $handle = fopen ($_FILES['inputfile']['tmp_name'], "r");
if (($head = fgetcsv($handle, 2000)) !== false ) { // head row if (($head = fgetcsv($handle, 2000)) !== false ) { // head row
for ($i = 0; $i < sizeof($head); $i++) { foreach ($head as $i => $headItem) {
$ids[$head[$i]] = $i; $ids[$headItem] = $i;
} }
} }
while (($line = fgetcsv($handle, 2000)) !== false ) { // account rows while (($line = fgetcsv($handle, 2000)) !== false ) { // account rows
@ -139,10 +139,10 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// check if all required columns are present // 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++) { foreach ($columns as $column) {
if (isset($columns[$i]['required']) && ($columns[$i]['required'] === true)) { if (isset($column['required']) && ($column['required'] === true)) {
if (isset($ids[$columns[$i]['name']])) $checkcolumns[] = $ids[$columns[$i]['name']]; if (isset($ids[$column['name']])) $checkcolumns[] = $ids[$column['name']];
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."), $column['name']);
} }
} }
@ -163,14 +163,14 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
break; break;
} }
} }
for ($i = 0; $i < sizeof($invalidColumns); $i++) { foreach ($invalidColumns as $invalidColumn) {
$errors[] = array(_("One or more values of the required column \"$invalidColumns[$i]\" are missing."), ""); $errors[] = array(_("One or more values of the required column \"$invalidColumn\" are missing."), "");
} }
// check if values in unique columns are correct // check if values in unique columns are correct
for ($i = 0; $i < sizeof($columns); $i++) { foreach ($columns as $column) {
if (isset($columns[$i]['unique']) && ($columns[$i]['unique'] === true) && isset($ids[$columns[$i]['name']])) { if (isset($column['unique']) && ($column['unique'] === true) && isset($ids[$column['name']])) {
$colNumber = $ids[$columns[$i]['name']]; $colNumber = $ids[$column['name']];
$values_given = array(); $values_given = array();
foreach ($data as $dataRow) { foreach ($data as $dataRow) {
$values_given[] = $dataRow[$colNumber]; $values_given[] = $dataRow[$colNumber];
@ -184,15 +184,15 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
} }
} }
$duplicates = array_values(array_unique($duplicates)); $duplicates = array_values(array_unique($duplicates));
$errors[] = array(_("This column is defined to include unique entries but duplicates were found:") . ' ' . $columns[$i]['name'], implode(', ', $duplicates)); $errors[] = array(_("This column is defined to include unique entries but duplicates were found:") . ' ' . $column['name'], implode(', ', $duplicates));
} }
} }
} }
// 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++) { foreach ($errors as $error) {
$container->addElement(new htmlStatusMessage("ERROR", $errors[$i][0], $errors[$i][1]), true); $container->addElement(new htmlStatusMessage("ERROR", $error[0], $error[1]), true);
} }
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
@ -219,8 +219,8 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
} }
// print errors if DN could not be built // print errors if DN could not be built
if (sizeof($errors) > 0) { if (sizeof($errors) > 0) {
for ($i = 0; $i < sizeof($errors); $i++) { foreach ($errors as $error) {
$container->addElement(new htmlStatusMessage("ERROR", $errors[$i][0], $errors[$i][1], $errors[$i][2]), true); $container->addElement(new htmlStatusMessage("ERROR", $error[0], $error[1], $error[2]), true);
} }
} }
else { else {
@ -294,8 +294,8 @@ function massPrintBackButton($typeId, $selectedModules, htmlTable &$container) {
} }
$container->addElement(new htmlHiddenInput('createPDF', $createPDF)); $container->addElement(new htmlHiddenInput('createPDF', $createPDF));
$container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure'])); $container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']));
for ($i = 0; $i < sizeof($selectedModules); $i++) { foreach ($selectedModules as $selectedModule) {
$container->addElement(new htmlHiddenInput($typeId . '___' . $selectedModules[$i], 'on')); $container->addElement(new htmlHiddenInput($typeId . '___' . $selectedModule, 'on'));
} }
} }