';
+echo '
';
$container = new htmlTable();
$selectedModules = explode(',', $_POST['selectedModules']);
@@ -111,7 +121,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$data = array(); // input values without first row
$ids = array(); // =>
// get input fields from modules
- $columns = getUploadColumns($scope, $selectedModules);
+ $columns = getUploadColumns($type->getScope(), $selectedModules);
// read input file
$handle = fopen ($_FILES['inputfile']['tmp_name'], "r");
if (($head = fgetcsv($handle, 2000)) !== false ) { // head row
@@ -184,15 +194,15 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$container->addElement(new htmlStatusMessage("ERROR", $errors[$i][0], $errors[$i][1]), true);
}
$container->addElement(new htmlSpacer(null, '10px'), true);
- massPrintBackButton($scope, $selectedModules, $container);
+ massPrintBackButton($type->getId(), $selectedModules, $container);
}
// let modules build accounts
else {
- $accounts = buildUploadAccounts($scope, $data, $ids, $selectedModules);
+ $accounts = buildUploadAccounts($type->getId(), $data, $ids, $selectedModules);
if ($accounts != false) {
- $rdnList = getRDNAttributes($scope, $selectedModules);
- $suffix = $_SESSION['config']->get_Suffix($scope);
+ $rdnList = getRDNAttributes($type->getId(), $selectedModules);
+ $suffix = $type->getSuffix();
// set DN
foreach ($accounts as $i => $account) {
// check against list of possible RDN attributes
@@ -220,7 +230,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$_SESSION['mass_postActions'] = array();
$_SESSION['mass_data'] = lamEncrypt(serialize($data));
$_SESSION['mass_ids'] = $ids;
- $_SESSION['mass_scope'] = $scope;
+ $_SESSION['mass_typeId'] = $type->getId();
$_SESSION['mass_selectedModules'] = $selectedModules;
if (isset($_SESSION['mass_pdf'])) {
unset($_SESSION['mass_pdf']);
@@ -240,25 +250,25 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$buttonContainer->addElement(new htmlLink(_("Upload accounts to LDAP"), 'massDoUpload.php', '../../graphics/up.gif', true));
$buttonContainer->addElement(new htmlLink(_("Show LDIF file"), 'massBuildAccounts.php?showldif=true', '../../graphics/edit.png', true));
$buttonContainer->addElement(new htmlSpacer('10px', null));
- massPrintBackButton($scope, $selectedModules, $buttonContainer);
+ massPrintBackButton($type->getId(), $selectedModules, $buttonContainer);
$container->addElement($buttonContainer, true);
}
}
else {
$container->addElement(new htmlSpacer(null, '10px'), true);
- massPrintBackButton($scope, $selectedModules, $container);
+ massPrintBackButton($type->getId(), $selectedModules, $container);
}
}
}
else {
$container->addElement(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), true);
$container->addElement(new htmlSpacer(null, '10px'), true);
- massPrintBackButton($scope, $selectedModules, $container);
+ massPrintBackButton($type->getId(), $selectedModules, $container);
}
addSecurityTokenToMetaHTML($container);
$tabindex = 1;
-parseHtml(null, $container, array(), false, $tabindex, $scope);
+parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
echo '
';
echo '';
@@ -267,15 +277,15 @@ 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 String $typeId account type (e.g. user)
* @param array $selectedModules selected modules for upload
* @param htmlTable $container table container
*/
-function massPrintBackButton($scope, $selectedModules, &$container) {
+function massPrintBackButton($typeId, $selectedModules, &$container) {
$backButton = new htmlButton('submit', _('Back'));
$backButton->setIconClass('backButton');
$container->addElement($backButton);
- $container->addElement(new htmlHiddenInput('type', $scope));
+ $container->addElement(new htmlHiddenInput('type', $typeId));
$createPDF = 0;
if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) {
$createPDF = 1;
@@ -283,7 +293,7 @@ function massPrintBackButton($scope, $selectedModules, &$container) {
$container->addElement(new htmlHiddenInput('createPDF', $createPDF));
$container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']));
for ($i = 0; $i < sizeof($selectedModules); $i++) {
- $container->addElement(new htmlHiddenInput($scope . '_' . $selectedModules[$i], 'on'));
+ $container->addElement(new htmlHiddenInput($typeId . '___' . $selectedModules[$i], 'on'));
}
}
diff --git a/lam/templates/upload/massDoUpload.php b/lam/templates/upload/massDoUpload.php
index b0fca7dc..bbc5b3b9 100644
--- a/lam/templates/upload/massDoUpload.php
+++ b/lam/templates/upload/massDoUpload.php
@@ -1,9 +1,10 @@
getConfiguredType($typeId);
// check if account type is ok
-if (isAccountTypeHidden($scope)) {
- logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $scope);
+if ($type->isHidden()) {
+ logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $type->getId());
die();
}
-if (!checkIfNewEntriesAreAllowed($scope) || !checkIfWriteAccessIsAllowed($scope)) {
- logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $scope);
+if (!checkIfNewEntriesAreAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
+ logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $type->getId());
die();
}
-echo '
';
+echo '
';
$tokenPrefix = '?' . getSecurityTokenName() . '=' . getSecurityTokenValue();
?>
diff --git a/lam/templates/upload/masscreate.php b/lam/templates/upload/masscreate.php
index 9fad8e51..6b29a4eb 100644
--- a/lam/templates/upload/masscreate.php
+++ b/lam/templates/upload/masscreate.php
@@ -1,9 +1,28 @@
get_ActiveTypes();
+$typeManager = new \LAM\TYPES\TypeManager();
+$types = $typeManager->getConfiguredTypes();
$count = sizeof($types);
for ($i = 0; $i < $count; $i++) {
- $myType = new $types[$i]();
- if (!$myType->supportsFileUpload() || isAccountTypeHidden($types[$i])
- || !checkIfNewEntriesAreAllowed($types[$i]) || !checkIfWriteAccessIsAllowed($types[$i])) {
+ $myType = $types[$i];
+ if (!$myType->getBaseType()->supportsFileUpload() || $myType->isHidden()
+ || !checkIfNewEntriesAreAllowed($myType->getId()) || !checkIfWriteAccessIsAllowed($myType->getId())) {
unset($types[$i]);
}
}
@@ -93,26 +113,27 @@ $types = array_values($types);
// check if account specific page should be shown
if (isset($_POST['type'])) {
// get selected type
- $scope = htmlspecialchars($_POST['type']);
+ $typeId = htmlspecialchars($_POST['type']);
+ $type = $typeManager->getConfiguredType($typeId);
// get selected modules
$selectedModules = array();
$checkedBoxes = array_keys($_POST, 'on');
for ($i = 0; $i < sizeof($checkedBoxes); $i++) {
- if (strpos($checkedBoxes[$i], $scope . '_') === 0) {
- $selectedModules[] = substr($checkedBoxes[$i], strlen($scope) + 1);
+ if (strpos($checkedBoxes[$i], $typeId . '___') === 0) {
+ $selectedModules[] = substr($checkedBoxes[$i], strlen($typeId) + strlen('___'));
}
}
- $deps = getModulesDependencies($scope);
+ $deps = getModulesDependencies($type->getScope());
$depErrors = check_module_depends($selectedModules, $deps);
if (is_array($depErrors) && (sizeof($depErrors) > 0)) {
for ($i = 0; $i < sizeof($depErrors); $i++) {
StatusMessage('ERROR', _("Unsolved dependency:") . ' ' .
- getModuleAlias($depErrors[$i][0], $scope) . " (" .
- getModuleAlias($depErrors[$i][1], $scope) . ")");
+ getModuleAlias($depErrors[$i][0], $type->getScope()) . " (" .
+ getModuleAlias($depErrors[$i][1], $type->getScope()) . ")");
}
}
else {
- showMainPage($scope, $selectedModules);
+ showMainPage($type, $selectedModules);
exit;
}
}
@@ -120,7 +141,7 @@ if (isset($_POST['type'])) {
// show start page
$divClass = 'user';
if (isset($_REQUEST['type'])) {
- $divClass = $_REQUEST['type'];
+ $divClass = \LAM\TYPES\getScopeFromTypeId($_REQUEST['type']);
}
echo '
';
echo "
\n";
@@ -141,15 +162,15 @@ $table = new htmlTable();
// account type
$typeList = array();
-for ($i = 0; $i < sizeof($types); $i++) {
- $typeList[LAM\TYPES\getTypeAlias($types[$i])] = $types[$i];
+foreach ($types as $type) {
+ $typeList[$type->getAlias()] = $type->getId();
}
$selectedType = array();
if (isset($_REQUEST['type'])) {
$selectedType[] = $_REQUEST['type'];
}
elseif (!empty($types)) {
- $selectedType[] = $types[0];
+ $selectedType[] = $types[0]->getId();
}
$typeSelect = new htmlTableExtendedSelect('type', $typeList, $selectedType, _("Account type"));
$typeSelect->setHasDescriptiveElements(true);
@@ -162,32 +183,32 @@ $moduleLabel = new htmlOutputText(_('Selected modules'));
$moduleLabel->alignment = htmlElement::ALIGN_TOP;
$table->addElement($moduleLabel);
$moduleGroup = new htmlGroup();
-for ($i = 0; $i < sizeof($types); $i++) {
+foreach ($types as $type) {
$divClasses = array('typeOptions');
- if ((!isset($_REQUEST['type']) && ($i != 0)) || (isset($_REQUEST['type']) && ($_REQUEST['type'] != $types[$i]))) {
+ if ((!isset($_REQUEST['type']) && ($i != 0)) || (isset($_REQUEST['type']) && ($_REQUEST['type'] != $type->getId()))) {
$divClasses[] = 'hidden';
}
$innerTable = new htmlTable();
- $modules = $_SESSION['config']->get_AccountModules($types[$i]);
+ $modules = $_SESSION['config']->get_AccountModules($type->getId());
for ($m = 0; $m < sizeof($modules); $m++) {
if (($m != 0) && ($m%3 == 0)) {
echo $innerTable->addNewLine();
}
- $module = moduleCache::getModule($modules[$m], $types[$i]);
+ $module = moduleCache::getModule($modules[$m], $type->getScope());
$iconImage = $module->getIcon();
if (!is_null($iconImage) && !(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) {
$iconImage = '../../graphics/' . $iconImage;
}
$innerTable->addElement(new htmlImage($iconImage));
$enabled = true;
- if (is_base_module($modules[$m], $types[$i])) {
+ if (is_base_module($modules[$m], $type->getScope())) {
$enabled = false;
}
$checked = true;
- if (isset($_POST['submit']) && !isset($_POST[$types[$i] . '_' . $modules[$m]])) {
+ if (isset($_POST['submit']) && !isset($_POST[$type->getId() . '___' . $modules[$m]])) {
$checked = false;
}
- $checkbox = new htmlTableExtendedInputCheckbox($types[$i] . '_' . $modules[$m], $checked, getModuleAlias($modules[$m], $types[$i]), null, false);
+ $checkbox = new htmlTableExtendedInputCheckbox($type->getId() . '___' . $modules[$m], $checked, getModuleAlias($modules[$m], $type->getScope()), null, false);
$checkbox->setIsEnabled($enabled);
if ($enabled) {
$innerTable->addElement($checkbox);
@@ -196,12 +217,12 @@ for ($i = 0; $i < sizeof($types); $i++) {
$boxGroup = new htmlGroup();
$boxGroup->addElement($checkbox);
// add hidden field to fake disabled checkbox value
- $boxGroup->addElement(new htmlHiddenInput($types[$i] . '_' . $modules[$m], 'on'));
+ $boxGroup->addElement(new htmlHiddenInput($type->getId() . '___' . $modules[$m], 'on'));
$innerTable->addElement($boxGroup);
}
$innerTable->addElement(new htmlSpacer('10px', null));
}
- $typeDiv = new htmlDiv($types[$i], $innerTable);
+ $typeDiv = new htmlDiv($type->getId(), $innerTable);
$typeDiv->setCSSClasses($divClasses);
$moduleGroup->addElement($typeDiv);
}
@@ -231,10 +252,11 @@ include '../main_footer.php';
/**
* Displays the acount type specific main page of the upload.
*
-* @param string $scope account type
+* @param \LAM\TYPES\ConfiguredType $type account type
* @param array $selectedModules list of selected account modules
*/
-function showMainPage($scope, $selectedModules) {
+function showMainPage($type, $selectedModules) {
+ $scope = $type->getScope();
echo '
';
// get input fields from modules
$columns = getUploadColumns($scope, $selectedModules);
@@ -257,7 +279,7 @@ function showMainPage($scope, $selectedModules) {
$inputContainer->addElement(new htmlInputFileUpload('inputfile'));
$inputContainer->addElement(new htmlSpacer('10px', null));
$inputContainer->addElement(new htmlLink(_("Download sample CSV file"), 'masscreate.php?getCSV=1', '../../graphics/save.png', true));
- $inputContainer->addElement(new htmlHiddenInput('scope', $scope));
+ $inputContainer->addElement(new htmlHiddenInput('typeId', $type->getId()));
$inputContainer->addElement(new htmlHiddenInput('selectedModules', implode(',', $selectedModules)), true);
// PDF
$createPDF = false;
@@ -267,7 +289,7 @@ function showMainPage($scope, $selectedModules) {
$pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files'));
$pdfCheckbox->setTableRowsToShow(array('pdfStructure'));
$inputContainer->addElement($pdfCheckbox, true);
- $pdfStructures = \LAM\PDF\getPDFStructures($scope);
+ $pdfStructures = \LAM\PDF\getPDFStructures($type->getId());
$pdfSelected = array();
if (isset($_POST['pdfStructure'])) {
$pdfSelected = array($_POST['pdfStructure']);
@@ -321,9 +343,9 @@ function showMainPage($scope, $selectedModules) {
$dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText('dn_suffix');
$dnSuffixRowCells[] = $columnSpacer;
- $dnSuffixRowCells[] = new htmlOutputText($_SESSION['config']->get_Suffix($scope));
+ $dnSuffixRowCells[] = new htmlOutputText($type->getSuffix());
$dnSuffixRowCells[] = $columnSpacer;
- $dnSuffixRowCells[] = new htmlOutputText($_SESSION['config']->get_Suffix($scope));
+ $dnSuffixRowCells[] = new htmlOutputText($type->getSuffix());
$dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText('');
$dnSuffixRowCells[] = new htmlSpacer(null, '25px');
@@ -340,7 +362,7 @@ function showMainPage($scope, $selectedModules) {
$dnRDNRowCells[] = $columnSpacer;
$dnRDNRowCells[] = new htmlOutputText('dn_rdn');
$dnRDNRowCells[] = $columnSpacer;
- $rdnAttributes = getRDNAttributes($scope, $selectedModules);
+ $rdnAttributes = getRDNAttributes($type->getId(), $selectedModules);
$dnRDNRowCells[] = new htmlOutputText($rdnAttributes[0]);
$dnRDNRowCells[] = $columnSpacer;
$dnRDNRowCells[] = new htmlOutputText('');
@@ -456,9 +478,9 @@ function showMainPage($scope, $selectedModules) {
$sampleCSV_head[] = "\"" . $columns[$modules[$m]][$i]['name'] . "\"";
}
}
- $RDNs = getRDNAttributes($scope, $selectedModules);
+ $RDNs = getRDNAttributes($type->getId(), $selectedModules);
// DN attributes
- $sampleCSV_row[] = "\"" . $_SESSION['config']->get_Suffix($scope) . "\"";
+ $sampleCSV_row[] = "\"" . $type->getSuffix() . "\"";
$sampleCSV_row[] = "\"" . $RDNs[0] . "\"";
// module attributes
for ($m = 0; $m < sizeof($modules); $m++) {