diff --git a/lam/templates/massBuildAccounts.php b/lam/templates/massBuildAccounts.php
new file mode 100644
index 00000000..53ade98d
--- /dev/null
+++ b/lam/templates/massBuildAccounts.php
@@ -0,0 +1,180 @@
+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;
+}
+
+echo $_SESSION['header'];
+echo "
account upload\n";
+echo "\n";
+echo "\n";
+echo "\n";
+
+if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
+ // check if input file is well formated
+ $data = array();
+ $ids = array();
+ // get input fields from modules
+ $columns = getUploadColumns($_POST['scope']);
+ // 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;
+ }
+ // check if all required attributes are given
+ $errors = array();
+ $checkcolumns = array();
+ $columns = call_user_func_array('array_merge', $columns);
+ for ($i = 0; $i < sizeof($columns); $i++) {
+ if ($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']);
+ }
+ }
+ $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."), "");
+ }
+ // let modules build accounts
+ if (sizeof($errors) < 1) {
+ $accounts = buildUploadAccounts($_POST['scope'], $data, $ids);
+ 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!"), "");
+ // TODO check against list of possible RDN attributes
+ 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 . call_user_func(array($_SESSION['config'], "get_" . ucfirst($_POST['scope']) . "Suffix"));
+ else $account_dn = $account_dn . $data[$i][$ids['dn_suffix']];
+ $accounts[$i]['dn'] = $account_dn;
+ }
+ }
+ // accounts were built, now add them to LDAP
+ // TODO add to LDAP
+ }
+ }
+ print_r($accounts);
+ // if input data is invalid just display error messages (max 50)
+ if (sizeof($errors) > 0) {
+ for ($i = 0; (($i < sizeof($errors)) || ($i > 49)); $i++) StatusMessage("ERROR", $errors[$i][0], $errors[$i][1]);
+ }
+ else {
+ // store accounts in session
+ $_SESSION['mass_accounts'] = $_SESSION['ldap']->encrypt(serialize($accounts));
+ // 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";
+ }
+}
+
+echo "\n";
+echo "