';
// create accounts
$accounts = unserialize(lamDecrypt($_SESSION['mass_accounts']));
if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_postActions']['finished']) || !isset($_SESSION['mass_pdf']['finished'])) {
$startTime = time();
$maxTime = get_cfg_var('max_execution_time') - 5;
if ($maxTime > 60) $maxTime = 60;
if ($maxTime <= 0) $maxTime = 60;
echo "
\n";
echo "
" . _("LDAP upload in progress. Please wait.") . "
\n";
echo "";
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
?>
time())) {
// create accounts as long as max_execution_time is not near
$attrs = $accounts[$_SESSION['mass_counter']];
$dn = $attrs['dn'];
unset($attrs['dn']);
// remove informational attributes
foreach ($attrs as $key => $value) {
if (strpos($key, 'INFO.') === 0) {
unset($attrs[$key]);
}
}
// run preactions
$preAttributes = array();
foreach ($attrs as $key => $value) {
$preAttributes[$key] = &$attrs[$key];
}
$preAttributes['dn'] = &$dn;
$preMessages = doUploadPreActions($scope, $_SESSION['mass_selectedModules'], $preAttributes);
$preActionOk = true;
for ($i = 0; $i < sizeof($preMessages); $i++) {
if (($preMessages[$i][0] == 'ERROR') || ($preMessages[$i][0] == 'WARN')) {
$preActionOk = false;
$_SESSION['mass_errors'][] = $preMessages[$i];
}
}
if ($preActionOk) {
// add LDAP entry
$success = @ldap_add($_SESSION['ldap']->server(), $dn, $attrs);
if (!$success) {
$errorMessage = array(
"ERROR",
_("LAM was unable to create account %s! An LDAP error occured."),
getDefaultLDAPErrorString($_SESSION['ldap']->server()),
array($_SESSION['mass_counter']));
$_SESSION['mass_errors'][] = $errorMessage;
$_SESSION['mass_failed'][] = $_SESSION['mass_counter'];
}
}
$_SESSION['mass_counter']++;
}
$progress = ($_SESSION['mass_counter'] * 100) / sizeof($accounts);
?>
= sizeof($accounts)) && !isset($_SESSION['mass_postActions']['finished'])) {
$data = unserialize(lamDecrypt($_SESSION['mass_data']));
$return = doUploadPostActions($scope, $data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $accounts);
if ($return['status'] == 'finished') {
$_SESSION['mass_postActions']['finished'] = true;
}
for ($i = 0; $i < sizeof($return['errors']); $i++) $_SESSION['mass_errors'][] = $return['errors'][$i];
echo "" . _("Additional tasks for module:") . ' ' . getModuleAlias($return['module'], $scope) . "
\n";
?>
time())) {
$return = doUploadPostActions($scope, $data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $accounts);
if ($return['status'] == 'finished') {
$_SESSION['mass_postActions']['finished'] = true;
}
if (isset($return['errors'])) {
for ($i = 0; $i < sizeof($return['errors']); $i++) {
$_SESSION['mass_errors'][] = $return['errors'][$i];
}
}
}
}
// create PDF when upload post actions are done
if (isset($_SESSION['mass_postActions']['finished'])) {
if (($_SESSION['mass_pdf']['structure'] != null) && !isset($_SESSION['mass_pdf']['finished'])) {
$file = $_SESSION['mass_pdf']['file'];
$pdfStructure = $_SESSION['mass_pdf']['structure'];
$pdfZip = new ZipArchive();
if ($_SESSION['mass_pdf']['counter'] == 0) {
$pdfZipResult = @$pdfZip->open($_SESSION['mass_pdf']['file'], ZipArchive::CREATE);
if (!$pdfZipResult === true) {
$_SESSION['mass_errors'][] = array('ERROR', _('Unable to create ZIP file for PDF export.'), $file);
$_SESSION['mass_pdf']['finished'] = true;
}
}
else {
@$pdfZip->open($_SESSION['mass_pdf']['file']);
}
// show progress bar
$progress = ($_SESSION['mass_pdf']['counter'] * 100) / sizeof($accounts);
echo "" . _('Create PDF files') . "
\n";
?>
time())) {
$attrs = $accounts[$_SESSION['mass_pdf']['counter']];
$dn = $attrs['dn'];
// get informational attributes
$infoAttributes = array();
foreach ($attrs as $key => $value) {
if (strpos($key, 'INFO.') === 0) {
$infoAttributes[$key] = $value;
}
}
// load account
$_SESSION['pdfAccount'] = new accountContainer($scope, 'pdfAccount');
$pdfErrors = $_SESSION['pdfAccount']->load_account($dn, $infoAttributes);
if (sizeof($pdfErrors) > 0) {
$_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors);
$_SESSION['mass_pdf']['finished'] = true;
break;
}
// create and save PDF
$pdfContent = createModulePDF(array($_SESSION['pdfAccount']), $pdfStructure, true);
$fileName = $dn . '.pdf';
$pdfZip->addFromString($fileName, $pdfContent);
$_SESSION['mass_pdf']['counter'] ++;
if ($_SESSION['mass_pdf']['counter'] >= sizeof($accounts)) {
$_SESSION['mass_pdf']['finished'] = true;
}
}
@$pdfZip->close();
}
else {
$_SESSION['mass_pdf']['finished'] = true;
}
}
// refresh with JavaScript
echo "\n";
}
// all accounts have been created
else {
echo "\n";
echo "
" . _("Upload has finished") . "
\n";
echo "";
if (sizeof($_SESSION['mass_errors']) > 0) {
echo "\n";
echo "
" . _("There were errors while uploading:") . "
\n";
echo "";
for ($i = 0; $i < sizeof($_SESSION['mass_errors']); $i++) {
call_user_func_array('StatusMessage', $_SESSION['mass_errors'][$i]);
echo "
";
}
}
else {
// redirect to list if no errors occured
echo "\n";
}
}
echo '';
include 'main_footer.php';
?>