From 4f1b9681ce9d265edf34ee9dee35914d29feaa4a Mon Sep 17 00:00:00 2001
From: Roland Gruber
Date: Sun, 10 Oct 2004 11:16:34 +0000
Subject: [PATCH] fixed error handling, updated to changed specification
---
lam/templates/massBuildAccounts.php | 44 ++++++++++++++++-------------
lam/templates/masscreate.php | 2 +-
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/lam/templates/massBuildAccounts.php b/lam/templates/massBuildAccounts.php
index 043943db..96bc9f31 100644
--- a/lam/templates/massBuildAccounts.php
+++ b/lam/templates/massBuildAccounts.php
@@ -108,7 +108,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$checkcolumns = array();
$columns = call_user_func_array('array_merge', $columns);
for ($i = 0; $i < sizeof($columns); $i++) {
- if ($columns[$i]['required'] == true) {
+ if (isset($columns[$i]['required']) && ($columns[$i]['required'] == true)) {
if (isset($ids[$columns[$i]['name']])) $checkcolumns[] = $ids[$columns[$i]['name']];
else $errors[] = array(_("A required column is missing in your CSV file."), $columns[$i]['name']);
}
@@ -161,7 +161,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
if ($accounts != false) {
// set DN
for ($i = 0; $i < sizeof($accounts); $i++) {
- if (!isset($accounts[$i][$data[$i][$ids['dn_rdn']]])) $errors[] = array(_("Data field for RDN is empty for account $i!"), "");
+ if (!isset($accounts[$i][$data[$i][$ids['dn_rdn']]])) $errors[] = array(_('Account %s: dn_rdn'), _("Data field for RDN is empty!"), array($i));
// TODO check against list of possible RDN attributes
else {
$account_dn = $data[$i][$ids['dn_rdn']] . "=" . $accounts[$i][$data[$i][$ids['dn_rdn']]] . ",";
@@ -170,23 +170,29 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$accounts[$i]['dn'] = $account_dn;
}
}
- // store accounts in session
- $_SESSION['mass_accounts'] = $_SESSION['ldap']->encrypt(serialize($accounts));
- $_SESSION['mass_counter'] = 0;
- $_SESSION['mass_errors'] = array();
- // show links for upload and LDIF export
- echo "" . _("LAM has checked your input and is now ready to create the accounts.") . "
\n";
- echo "
\n";
- echo "\n";
- echo "
\n";
- echo "
\n";
+ // print errors if DN could not be built
+ if (sizeof($errors) > 0) {
+ for ($i = 0; $i < sizeof($errors); $i++) StatusMessage("ERROR", $errors[$i][0], $errors[$i][1], $errors[$i][2]);
+ }
+ else {
+ // store accounts in session
+ $_SESSION['mass_accounts'] = $_SESSION['ldap']->encrypt(serialize($accounts));
+ $_SESSION['mass_counter'] = 0;
+ $_SESSION['mass_errors'] = array();
+ // show links for upload and LDIF export
+ echo "" . _("LAM has checked your input and is now ready to create the accounts.") . "
\n";
+ echo "
\n";
+ echo "\n";
+ echo "
\n";
+ echo "\n";
+ }
}
}
}
diff --git a/lam/templates/masscreate.php b/lam/templates/masscreate.php
index b75d67d5..3af9f656 100644
--- a/lam/templates/masscreate.php
+++ b/lam/templates/masscreate.php
@@ -225,7 +225,7 @@ function showMainPage($scope) {
* @param array $data field data from modules
*/
function showColumnData($module, $data) {
- if ($data['required']) {
+ if (isset($data['required']) && ($data['required'] == true)) {
echo "\n";
echo $data['description'];
echo "\n";