decrypt($_SESSION['mass_accounts']));
for ($i = 0; $i < sizeof($accounts); $i++) {
echo "DN: " . $accounts[$i]['dn'] . "\n";
unset($accounts[$i]['dn']);
$keys = array_keys($accounts[$i]);
for ($k = 0; $k < sizeof($keys); $k++) {
if (is_array($accounts[$i][$keys[$k]])) {
for ($x = 0; $x < sizeof($accounts[$i][$keys[$k]]); $x++) {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]][$x] . "\n";
}
}
else {
echo $keys[$k] . ": " . $accounts[$i][$keys[$k]] . "\n";
}
}
echo "\n";
}
exit;
}
include 'main_header.php';
echo '
';
$selectedModules = explode(',', $_POST['selectedModules']);
if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// check if input file is well formated
$data = array(); // input values without first row
$ids = array(); //
=>
// get input fields from modules
$columns = getUploadColumns($_POST['scope'], $selectedModules);
// read input file
$handle = fopen ($_FILES['inputfile']['tmp_name'], "r");
if (($head = fgetcsv($handle, 2000)) !== false ) { // head row
for ($i = 0; $i < sizeof($head); $i++) {
$ids[$head[$i]] = $i;
}
}
while (($line = fgetcsv($handle, 2000)) !== false ) { // account rows
$data[] = $line;
}
$errors = array();
// check if all required columns are present
$checkcolumns = array();
$columns = call_user_func_array('array_merge', $columns);
for ($i = 0; $i < sizeof($columns); $i++) {
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']);
}
}
// check if all required attributes are given
$invalidColumns = array();
$id_names = array_keys($ids);
for ($i = 0; $i < sizeof($checkcolumns); $i++) {
for ($r = 0; $r < sizeof($data); $r++) {
if ($data[$r][$checkcolumns[$i]] == "") {
$invalidColumns[] = $id_names[$checkcolumns[$i]];
break;
}
}
}
for ($i = 0; $i < sizeof($data); $i++) {
if ($data[$i][$ids['dn_rdn']] == "") {
$invalidColumns[] = 'dn_rdn';
break;
}
}
for ($i = 0; $i < sizeof($invalidColumns); $i++) {
$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 (isset($columns[$i]['unique']) && ($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 (sizeof($errors) > 0) {
for ($i = 0; $i < sizeof($errors); $i++) StatusMessage("ERROR", $errors[$i][0], $errors[$i][1]);
massPrintBackButton($_POST['scope'], $selectedModules);
}
// let modules build accounts
else {
$accounts = buildUploadAccounts($_POST['scope'], $data, $ids, $selectedModules);
if ($accounts != false) {
$rdnList = getRDNAttributes($_POST['scope'], $selectedModules);
$suffix = $_SESSION['config']->get_Suffix($_POST['scope']);
// set DN
for ($i = 0; $i < sizeof($accounts); $i++) {
// check against list of possible RDN attributes
if (!in_array($data[$i][$ids['dn_rdn']], $rdnList)) {
$errors[] = array(_('Account %s:') . ' dn_rdn' . $accounts[$i][$data[$i][$ids['dn_rdn']]], _("Invalid RDN attribute!"), array($i));
}
else {
$account_dn = $data[$i][$ids['dn_rdn']] . "=" . $accounts[$i][$data[$i][$ids['dn_rdn']]] . ",";
if ($data[$i][$ids['dn_suffix']] == "") $account_dn = $account_dn . $suffix;
else $account_dn = $account_dn . $data[$i][$ids['dn_suffix']];
$accounts[$i]['dn'] = $account_dn;
}
}
// 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();
$_SESSION['mass_failed'] = array();
$_SESSION['mass_postActions'] = array();
$_SESSION['mass_data'] = $_SESSION['ldap']->encrypt(serialize($data));
$_SESSION['mass_ids'] = $ids;
$_SESSION['mass_scope'] = $_POST['scope'];
$_SESSION['mass_selectedModules'] = $selectedModules;
// show links for upload and LDIF export
echo "\n";
echo "
" . _("LAM has checked your input and is now ready to create the accounts.") . "
\n";
echo "";
echo "
\n";
echo "" . _("Upload accounts to LDAP") . "";
echo " ";
echo "" . _("Show LDIF file") . "";
?>
';
include 'main_footer.php';
/**
* Prints a back button to the page where the user enters a file to upload.
*
* @param String $scope account type (e.g. user)
* @param array $selectedModules selected modules for upload
*/
function massPrintBackButton($scope, $selectedModules) {
echo '';
}
?>