From 4638db3d33839bf72802f634ea7e545821b39768 Mon Sep 17 00:00:00 2001 From: Roland Gruber Date: Tue, 19 Oct 2004 18:18:46 +0000 Subject: [PATCH] added post upload actions --- lam/lib/baseModule.inc | 23 +++++++++++++- lam/lib/modules.inc | 47 +++++++++++++++++++++++++++++ lam/session-vars.txt | 6 +++- lam/templates/massBuildAccounts.php | 5 +++ lam/templates/massDoUpload.php | 26 +++++++++++++++- 5 files changed, 104 insertions(+), 3 deletions(-) diff --git a/lam/lib/baseModule.inc b/lam/lib/baseModule.inc index 9748bba2..006dd1f8 100644 --- a/lam/lib/baseModule.inc +++ b/lam/lib/baseModule.inc @@ -507,8 +507,29 @@ class baseModule { } } + /** + * This function executes one post upload action. + * + * @param array $data array containing one account in each element + * @param array $ids array( => ) + * @param array $failed list of accounts which were not created successfully + * @param array $temp variable to store temporary data between two post actions + * @return array current status + *
array ( + *
'status' => 'finished' | 'inProgress' + *
'progress' => 0..100 + *
'errors' => array () + *
) + */ + function doUploadPostActions($data, $ids, $failed, &$temp) { + return array( + 'status' => 'finished', + 'progress' => 100, + 'errors' => array() + ); + } + } - ?> \ No newline at end of file diff --git a/lam/lib/modules.inc b/lam/lib/modules.inc index 4ef93c63..48d47762 100644 --- a/lam/lib/modules.inc +++ b/lam/lib/modules.inc @@ -479,6 +479,53 @@ function buildUploadAccounts($scope, $data, $ids) { else return $partialAccounts; } +/** +* This function executes one post upload action. +* +* @param string $scope account type +* @param array $data array containing one account in each element +* @param array $ids array( => ) +* @param array $failed list of accounts which were not created successfully +* @return array current status +*
array ( +*
'status' => 'finished' | 'inProgress' +*
'module' => +*
'progress' => 0..100 +*
'errors' => array () +*
) +*/ +function doUploadPostActions($scope, $data, $ids, $failed) { + // check if function is called the first time + if (! isset($_SESSION['mass_postActions']['remainingModules'])) { + // make list of remaining modules + $moduleList = $_SESSION['config']->get_AccountModules($scope); + $_SESSION['mass_postActions']['remainingModules'] = $moduleList; + } + $activeModule = $_SESSION['mass_postActions']['remainingModules'][0]; + // initialize temporary variable + if (!isset($_SESSION['mass_postActions'][$activeModule])) { + $_SESSION['mass_postActions'][$activeModule] = array(); + } + // let first module do one post action + $module = new $activeModule($scope); + $return = $module->doUploadPostActions($data, $ids, $failed, $_SESSION['mass_postActions'][$activeModule]); + // remove active module from list if already finished + if ($return['status'] == 'finished') { + unset($_SESSION['mass_postActions']['remainingModules'][0]); + $_SESSION['mass_postActions']['remainingModules'] = array_values($_SESSION['mass_postActions']['remainingModules']); + } + // update status and return back to upload page + $return['module'] = $activeModule; + if (sizeof($_SESSION['mass_postActions']['remainingModules']) > 0) { + $return['status'] = 'inProgress'; + } + else { + $return['status'] = 'finished'; + } + return $return; +} + + /** * This class includes all modules and attributes of an account. * diff --git a/lam/session-vars.txt b/lam/session-vars.txt index 7ef8bf34..28bb0684 100644 --- a/lam/session-vars.txt +++ b/lam/session-vars.txt @@ -13,7 +13,11 @@ masscreate: - mass_counter: aktuelle Position im Account-Array - mass_errors: Fehlermeldungen beim Upload - mass_csv: CSV-Datei als Vorlage für Upload - +- mass_failed: Liste der Accounts, die nicht erzeugt werden konnten +- mass_postActions: temporäre Daten für den Upload +- mass_data: Eingabedaten +- mass_ids: Tabelle Spaltenname => Spaltennummer +- mass_scope: Account-Typ main: - domain_message: Wird auf der "neue Domain" Seite ausgegeben, wenn keine Domäne gefunden wurde diff --git a/lam/templates/massBuildAccounts.php b/lam/templates/massBuildAccounts.php index 96bc9f31..03a9aecd 100644 --- a/lam/templates/massBuildAccounts.php +++ b/lam/templates/massBuildAccounts.php @@ -179,6 +179,11 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) { $_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']; // show links for upload and LDIF export echo "

" . _("LAM has checked your input and is now ready to create the accounts.") . "

\n"; echo "

 

\n"; diff --git a/lam/templates/massDoUpload.php b/lam/templates/massDoUpload.php index 87a51574..a06c4e38 100644 --- a/lam/templates/massDoUpload.php +++ b/lam/templates/massDoUpload.php @@ -57,7 +57,7 @@ echo "\n // create accounts $accounts = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_accounts'])); -if ($_SESSION['mass_counter'] < sizeof($accounts)) { +if (($_SESSION['mass_counter'] < sizeof($accounts)) || !isset($_SESSION['mass_postActions']['finished'])) { $maxTime = get_cfg_var('max_execution_time') - 5; $refreshTime = get_cfg_var('max_execution_time') + 1; $startTime = time(); @@ -69,6 +69,7 @@ if ($_SESSION['mass_counter'] < sizeof($accounts)) { echo " \n"; echo ""; flush(); // send HTML to browser + // add accounts to LDAP while (($_SESSION['mass_counter'] < sizeof($accounts)) && ($startTime + $maxTime > time())) { // create accounts as long as max_execution_time is not near $attrs = $accounts[$_SESSION['mass_counter']]; @@ -82,9 +83,32 @@ if ($_SESSION['mass_counter'] < sizeof($accounts)) { ldap_errno($_SESSION[ldap]->server) . ": " . ldap_error($_SESSION[ldap]->server), array($_SESSION['mass_counter'])); $_SESSION['mass_errors'][] = $errorMessage; + $_SESSION['mass_failed'][] = $_SESSION['mass_counter']; } $_SESSION['mass_counter']++; } + // do post upload actions + if ($_SESSION['mass_counter'] >= sizeof($accounts)) { + $data = unserialize($_SESSION['ldap']->decrypt($_SESSION['mass_data'])); + $return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $failed); + 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: ") . $return['module'] . "

\n"; + echo "\n"; + echo ""; + echo "\n"; + echo "
  
"; + flush(); + while (!isset($_SESSION['mass_postActions']['finished']) && ($startTime + $maxTime > time())) { + $return = doUploadPostActions($_SESSION['mass_scope'], $data, $_SESSION['mass_ids'], $failed); + if ($return['status'] == 'finished') { + $_SESSION['mass_postActions']['finished'] = true; + } + for ($i = 0; $i < sizeof($return['errors']); $i++) $_SESSION['mass_errors'][] = $return['errors'][$i]; + } + } echo ""; } // all accounts have been created