new type API for upload

This commit is contained in:
Roland Gruber 2017-01-07 18:23:04 +01:00
parent 9355b55982
commit cdaa9a8a12
6 changed files with 119 additions and 81 deletions

View File

@ -6,7 +6,7 @@ use accountContainer;
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2016 Roland Gruber Copyright (C) 2016 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -46,7 +46,7 @@ class Uploader {
private $accounts = null; private $accounts = null;
private $data = null; private $data = null;
private $scope = null; private $type = null;
private $endTime; private $endTime;
const TIME_LIMIT = 10; const TIME_LIMIT = 10;
@ -61,11 +61,13 @@ class Uploader {
/** /**
* Constructor * Constructor
*
* @param \LAM\TYPES\ConfiguredType $type account type
*/ */
public function __construct($scope) { public function __construct($type) {
$this->accounts = unserialize(lamDecrypt($_SESSION['mass_accounts'])); $this->accounts = unserialize(lamDecrypt($_SESSION['mass_accounts']));
$this->data = unserialize(lamDecrypt($_SESSION['mass_data'])); $this->data = unserialize(lamDecrypt($_SESSION['mass_data']));
$this->scope = $scope; $this->type = $type;
$startTime = time(); $startTime = time();
$maxTime = get_cfg_var('max_execution_time') - 5; $maxTime = get_cfg_var('max_execution_time') - 5;
if ($maxTime > Uploader::TIME_LIMIT) $maxTime = Uploader::TIME_LIMIT; if ($maxTime > Uploader::TIME_LIMIT) $maxTime = Uploader::TIME_LIMIT;
@ -131,7 +133,7 @@ class Uploader {
$preAttributes[$key] = &$attrs[$key]; $preAttributes[$key] = &$attrs[$key];
} }
$preAttributes['dn'] = &$dn; $preAttributes['dn'] = &$dn;
$preMessages = doUploadPreActions($this->scope, $_SESSION['mass_selectedModules'], $preAttributes); $preMessages = doUploadPreActions($this->type->getScope(), $_SESSION['mass_selectedModules'], $preAttributes);
$preActionOk = true; $preActionOk = true;
for ($i = 0; $i < sizeof($preMessages); $i++) { for ($i = 0; $i < sizeof($preMessages); $i++) {
if (($preMessages[$i][0] == 'ERROR') || ($preMessages[$i][0] == 'WARN')) { if (($preMessages[$i][0] == 'ERROR') || ($preMessages[$i][0] == 'WARN')) {
@ -202,7 +204,7 @@ class Uploader {
'pdfFinished' => $pdfFinished, 'pdfFinished' => $pdfFinished,
'allDone' => $allDone, 'allDone' => $allDone,
'errorHtml' => $errorHtml, 'errorHtml' => $errorHtml,
'scope' => $this->scope 'typeId' => $this->type->getId()
); );
return json_encode($status); return json_encode($status);
} }
@ -211,10 +213,10 @@ class Uploader {
* Checks for security violations and stops processing if needed. * Checks for security violations and stops processing if needed.
*/ */
private function securityCheck() { private function securityCheck() {
if (!isLoggedIn() || empty($this->scope) if (!isLoggedIn() || empty($this->type)
|| isAccountTypeHidden($this->scope) || $this->type->isHidden()
|| !checkIfNewEntriesAreAllowed($this->scope) || !checkIfNewEntriesAreAllowed($this->type->getId())
|| !checkIfWriteAccessIsAllowed($this->scope)) { || !checkIfWriteAccessIsAllowed($this->type->getId())) {
die; die;
} }
} }
@ -229,7 +231,7 @@ class Uploader {
while (!isset($_SESSION['mass_postActions']['finished']) && ($this->endTime > time())) { while (!isset($_SESSION['mass_postActions']['finished']) && ($this->endTime > time())) {
$return = $this->runModulePostActions(); $return = $this->runModulePostActions();
} }
$title = _("Additional tasks for module:") . ' ' . getModuleAlias($return['module'], $this->scope); $title = _("Additional tasks for module:") . ' ' . getModuleAlias($return['module'], $this->type->getScope());
$progress = round($return['progress'], 2); $progress = round($return['progress'], 2);
$finished = isset($_SESSION['mass_postActions']['finished']); $finished = isset($_SESSION['mass_postActions']['finished']);
return $this->buildUploadStatus(100, true, $title, $progress, $finished); return $this->buildUploadStatus(100, true, $title, $progress, $finished);
@ -241,7 +243,7 @@ class Uploader {
* @return array status array * @return array status array
*/ */
private function runModulePostActions() { private function runModulePostActions() {
$return = doUploadPostActions($this->scope, $this->data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $this->accounts); $return = doUploadPostActions($this->type->getScope(), $this->data, $_SESSION['mass_ids'], $_SESSION['mass_failed'], $_SESSION['mass_selectedModules'], $this->accounts);
if ($return['status'] == 'finished') { if ($return['status'] == 'finished') {
$_SESSION['mass_postActions']['finished'] = true; $_SESSION['mass_postActions']['finished'] = true;
} }
@ -284,7 +286,7 @@ class Uploader {
} }
// load account // load account
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$_SESSION['mass_pdfAccount'] = new accountContainer($typeManager->getConfiguredType($this->scope), 'mass_pdfAccount'); $_SESSION['mass_pdfAccount'] = new accountContainer($this->type, 'mass_pdfAccount');
$pdfErrors = $_SESSION['mass_pdfAccount']->load_account($dn, $infoAttributes); $pdfErrors = $_SESSION['mass_pdfAccount']->load_account($dn, $infoAttributes);
if (sizeof($pdfErrors) > 0) { if (sizeof($pdfErrors) > 0) {
$_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors); $_SESSION['mass_errors'] = array_merge($_SESSION['mass_errors'], $pdfErrors);

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2003 - 2016 Roland Gruber Copyright (C) 2003 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -757,6 +757,6 @@ window.lam.upload.uploadDone = function(jsonData) {
jQuery('#uploadContent').html(htmlOut); jQuery('#uploadContent').html(htmlOut);
} }
else { else {
top.location.href = '../lists/list.php?type=' + jsonData.scope + '&uploadAllOk'; top.location.href = '../lists/list.php?type=' + jsonData.typeId + '&uploadAllOk';
} }
} }

View File

@ -3,7 +3,7 @@
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2011 - 2016 Roland Gruber Copyright (C) 2011 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -90,7 +90,8 @@ class lamAjax {
} }
elseif ($function == 'upload') { elseif ($function == 'upload') {
include_once('../../lib/upload.inc'); include_once('../../lib/upload.inc');
$uploader = new LAM\UPLOAD\Uploader($_GET['scope']); $typeManager = new \LAM\TYPES\TypeManager();
$uploader = new LAM\UPLOAD\Uploader($typeManager->getConfiguredType($_GET['typeId']));
ob_start(); ob_start();
$jsonOut = $uploader->doUpload(); $jsonOut = $uploader->doUpload();
ob_end_clean(); ob_end_clean();

View File

@ -1,9 +1,17 @@
<?php <?php
namespace LAM\UPLOAD;
use \htmlTable;
use \htmlSpacer;
use \htmlStatusMessage;
use \htmlLink;
use \htmlTitle;
use \htmlButton;
use \htmlHiddenInput;
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2016 Roland Gruber Copyright (C) 2004 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -89,20 +97,22 @@ if (isset($_GET['showldif'])) {
} }
include '../main_header.php'; include '../main_header.php';
$scope = htmlspecialchars($_POST['scope']); $typeId = htmlspecialchars($_POST['typeId']);
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
// check if account type is ok // check if account type is ok
if (isAccountTypeHidden($scope)) { if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $scope); logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $type->getId());
die(); die();
} }
if (!checkIfNewEntriesAreAllowed($scope) || !checkIfWriteAccessIsAllowed($scope)) { if (!checkIfNewEntriesAreAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $scope); logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $type->getId());
die(); die();
} }
echo '<form enctype="multipart/form-data" action="masscreate.php" method="post">'; echo '<form enctype="multipart/form-data" action="masscreate.php" method="post">';
echo '<div class="' . $scope . '-bright smallPaddingContent">'; echo '<div class="' . $type->getScope() . '-bright smallPaddingContent">';
$container = new htmlTable(); $container = new htmlTable();
$selectedModules = explode(',', $_POST['selectedModules']); $selectedModules = explode(',', $_POST['selectedModules']);
@ -111,7 +121,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$data = array(); // input values without first row $data = array(); // input values without first row
$ids = array(); // <column name> => <column number for $data> $ids = array(); // <column name> => <column number for $data>
// get input fields from modules // get input fields from modules
$columns = getUploadColumns($scope, $selectedModules); $columns = getUploadColumns($type->getScope(), $selectedModules);
// read input file // read input file
$handle = fopen ($_FILES['inputfile']['tmp_name'], "r"); $handle = fopen ($_FILES['inputfile']['tmp_name'], "r");
if (($head = fgetcsv($handle, 2000)) !== false ) { // head row 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 htmlStatusMessage("ERROR", $errors[$i][0], $errors[$i][1]), true);
} }
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
massPrintBackButton($scope, $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
// let modules build accounts // let modules build accounts
else { else {
$accounts = buildUploadAccounts($scope, $data, $ids, $selectedModules); $accounts = buildUploadAccounts($type->getId(), $data, $ids, $selectedModules);
if ($accounts != false) { if ($accounts != false) {
$rdnList = getRDNAttributes($scope, $selectedModules); $rdnList = getRDNAttributes($type->getId(), $selectedModules);
$suffix = $_SESSION['config']->get_Suffix($scope); $suffix = $type->getSuffix();
// set DN // set DN
foreach ($accounts as $i => $account) { foreach ($accounts as $i => $account) {
// check against list of possible RDN attributes // check against list of possible RDN attributes
@ -220,7 +230,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$_SESSION['mass_postActions'] = array(); $_SESSION['mass_postActions'] = array();
$_SESSION['mass_data'] = lamEncrypt(serialize($data)); $_SESSION['mass_data'] = lamEncrypt(serialize($data));
$_SESSION['mass_ids'] = $ids; $_SESSION['mass_ids'] = $ids;
$_SESSION['mass_scope'] = $scope; $_SESSION['mass_typeId'] = $type->getId();
$_SESSION['mass_selectedModules'] = $selectedModules; $_SESSION['mass_selectedModules'] = $selectedModules;
if (isset($_SESSION['mass_pdf'])) { if (isset($_SESSION['mass_pdf'])) {
unset($_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(_("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 htmlLink(_("Show LDIF file"), 'massBuildAccounts.php?showldif=true', '../../graphics/edit.png', true));
$buttonContainer->addElement(new htmlSpacer('10px', null)); $buttonContainer->addElement(new htmlSpacer('10px', null));
massPrintBackButton($scope, $selectedModules, $buttonContainer); massPrintBackButton($type->getId(), $selectedModules, $buttonContainer);
$container->addElement($buttonContainer, true); $container->addElement($buttonContainer, true);
} }
} }
else { else {
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
massPrintBackButton($scope, $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
} }
} }
else { else {
$container->addElement(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), true); $container->addElement(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), true);
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addElement(new htmlSpacer(null, '10px'), true);
massPrintBackButton($scope, $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
addSecurityTokenToMetaHTML($container); addSecurityTokenToMetaHTML($container);
$tabindex = 1; $tabindex = 1;
parseHtml(null, $container, array(), false, $tabindex, $scope); parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
@ -267,15 +277,15 @@ include '../main_footer.php';
/** /**
* Prints a back button to the page where the user enters a file to upload. * 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 array $selectedModules selected modules for upload
* @param htmlTable $container table container * @param htmlTable $container table container
*/ */
function massPrintBackButton($scope, $selectedModules, &$container) { function massPrintBackButton($typeId, $selectedModules, &$container) {
$backButton = new htmlButton('submit', _('Back')); $backButton = new htmlButton('submit', _('Back'));
$backButton->setIconClass('backButton'); $backButton->setIconClass('backButton');
$container->addElement($backButton); $container->addElement($backButton);
$container->addElement(new htmlHiddenInput('type', $scope)); $container->addElement(new htmlHiddenInput('type', $typeId));
$createPDF = 0; $createPDF = 0;
if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) {
$createPDF = 1; $createPDF = 1;
@ -283,7 +293,7 @@ function massPrintBackButton($scope, $selectedModules, &$container) {
$container->addElement(new htmlHiddenInput('createPDF', $createPDF)); $container->addElement(new htmlHiddenInput('createPDF', $createPDF));
$container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure'])); $container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']));
for ($i = 0; $i < sizeof($selectedModules); $i++) { for ($i = 0; $i < sizeof($selectedModules); $i++) {
$container->addElement(new htmlHiddenInput($scope . '_' . $selectedModules[$i], 'on')); $container->addElement(new htmlHiddenInput($typeId . '___' . $selectedModules[$i], 'on'));
} }
} }

View File

@ -1,9 +1,10 @@
<?php <?php
namespace LAM\UPLOAD;
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2013 Roland Gruber Copyright (C) 2004 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -61,24 +62,26 @@ if (!isLoggedIn()) {
setlanguage(); setlanguage();
include '../main_header.php'; include '../main_header.php';
$scope = htmlspecialchars($_SESSION['mass_scope']); $typeId = htmlspecialchars($_SESSION['mass_typeId']);
$typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId);
// check if account type is ok // check if account type is ok
if (isAccountTypeHidden($scope)) { if ($type->isHidden()) {
logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $scope); logNewMessage(LOG_ERR, 'User tried to access hidden upload: ' . $type->getId());
die(); die();
} }
if (!checkIfNewEntriesAreAllowed($scope) || !checkIfWriteAccessIsAllowed($scope)) { if (!checkIfNewEntriesAreAllowed($type->getId()) || !checkIfWriteAccessIsAllowed($type->getId())) {
logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $scope); logNewMessage(LOG_ERR, 'User tried to access forbidden upload: ' . $type->getId());
die(); die();
} }
echo '<div id="uploadContent" class="' . $scope . '-bright smallPaddingContent">'; echo '<div id="uploadContent" class="' . $type->getScope() . '-bright smallPaddingContent">';
$tokenPrefix = '?' . getSecurityTokenName() . '=' . getSecurityTokenValue(); $tokenPrefix = '?' . getSecurityTokenName() . '=' . getSecurityTokenValue();
?> ?>
<script type="text/javascript"> <script type="text/javascript">
jQuery(document).ready(function(){ jQuery(document).ready(function(){
window.lam.upload.continueUpload('../misc/ajax.php' + '<?php echo $tokenPrefix; ?>' + '&function=upload&scope=' + '<?php echo $scope ?>'); window.lam.upload.continueUpload('../misc/ajax.php' + '<?php echo $tokenPrefix; ?>' + '&function=upload&typeId=' + '<?php echo $type->getId() ?>');
}); });
</script> </script>

View File

@ -1,9 +1,28 @@
<?php <?php
namespace LAM\UPLOAD;
use \htmlTable;
use \htmlTableExtendedSelect;
use \htmlSpacer;
use \htmlOutputText;
use \htmlGroup;
use \htmlElement;
use \htmlImage;
use \htmlTableExtendedInputCheckbox;
use \htmlDiv;
use \htmlHiddenInput;
use \htmlButton;
use \htmlTitle;
use \htmlInputFileUpload;
use \htmlLink;
use \htmlSubTitle;
use \htmlHelpLink;
use \htmlTableRow;
use \moduleCache;
/* /*
$Id$ $Id$
This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/) This code is part of LDAP Account Manager (http://www.ldap-account-manager.org/)
Copyright (C) 2004 - 2016 Roland Gruber Copyright (C) 2004 - 2017 Roland Gruber
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@ -74,17 +93,18 @@ if (isset($_GET['getCSV'])) {
exit; exit;
} }
LAM\UPLOAD\Uploader::cleanSession(); Uploader::cleanSession();
include '../main_header.php'; include '../main_header.php';
// get possible types and remove those which do not support file upload // get possible types and remove those which do not support file upload
$types = $_SESSION['config']->get_ActiveTypes(); $typeManager = new \LAM\TYPES\TypeManager();
$types = $typeManager->getConfiguredTypes();
$count = sizeof($types); $count = sizeof($types);
for ($i = 0; $i < $count; $i++) { for ($i = 0; $i < $count; $i++) {
$myType = new $types[$i](); $myType = $types[$i];
if (!$myType->supportsFileUpload() || isAccountTypeHidden($types[$i]) if (!$myType->getBaseType()->supportsFileUpload() || $myType->isHidden()
|| !checkIfNewEntriesAreAllowed($types[$i]) || !checkIfWriteAccessIsAllowed($types[$i])) { || !checkIfNewEntriesAreAllowed($myType->getId()) || !checkIfWriteAccessIsAllowed($myType->getId())) {
unset($types[$i]); unset($types[$i]);
} }
} }
@ -93,26 +113,27 @@ $types = array_values($types);
// check if account specific page should be shown // check if account specific page should be shown
if (isset($_POST['type'])) { if (isset($_POST['type'])) {
// get selected type // get selected type
$scope = htmlspecialchars($_POST['type']); $typeId = htmlspecialchars($_POST['type']);
$type = $typeManager->getConfiguredType($typeId);
// get selected modules // get selected modules
$selectedModules = array(); $selectedModules = array();
$checkedBoxes = array_keys($_POST, 'on'); $checkedBoxes = array_keys($_POST, 'on');
for ($i = 0; $i < sizeof($checkedBoxes); $i++) { for ($i = 0; $i < sizeof($checkedBoxes); $i++) {
if (strpos($checkedBoxes[$i], $scope . '_') === 0) { if (strpos($checkedBoxes[$i], $typeId . '___') === 0) {
$selectedModules[] = substr($checkedBoxes[$i], strlen($scope) + 1); $selectedModules[] = substr($checkedBoxes[$i], strlen($typeId) + strlen('___'));
} }
} }
$deps = getModulesDependencies($scope); $deps = getModulesDependencies($type->getScope());
$depErrors = check_module_depends($selectedModules, $deps); $depErrors = check_module_depends($selectedModules, $deps);
if (is_array($depErrors) && (sizeof($depErrors) > 0)) { if (is_array($depErrors) && (sizeof($depErrors) > 0)) {
for ($i = 0; $i < sizeof($depErrors); $i++) { for ($i = 0; $i < sizeof($depErrors); $i++) {
StatusMessage('ERROR', _("Unsolved dependency:") . ' ' . StatusMessage('ERROR', _("Unsolved dependency:") . ' ' .
getModuleAlias($depErrors[$i][0], $scope) . " (" . getModuleAlias($depErrors[$i][0], $type->getScope()) . " (" .
getModuleAlias($depErrors[$i][1], $scope) . ")"); getModuleAlias($depErrors[$i][1], $type->getScope()) . ")");
} }
} }
else { else {
showMainPage($scope, $selectedModules); showMainPage($type, $selectedModules);
exit; exit;
} }
} }
@ -120,7 +141,7 @@ if (isset($_POST['type'])) {
// show start page // show start page
$divClass = 'user'; $divClass = 'user';
if (isset($_REQUEST['type'])) { if (isset($_REQUEST['type'])) {
$divClass = $_REQUEST['type']; $divClass = \LAM\TYPES\getScopeFromTypeId($_REQUEST['type']);
} }
echo '<div class="' . $divClass . '-bright smallPaddingContent">'; echo '<div class="' . $divClass . '-bright smallPaddingContent">';
echo "<div class=\"title\">\n"; echo "<div class=\"title\">\n";
@ -141,15 +162,15 @@ $table = new htmlTable();
// account type // account type
$typeList = array(); $typeList = array();
for ($i = 0; $i < sizeof($types); $i++) { foreach ($types as $type) {
$typeList[LAM\TYPES\getTypeAlias($types[$i])] = $types[$i]; $typeList[$type->getAlias()] = $type->getId();
} }
$selectedType = array(); $selectedType = array();
if (isset($_REQUEST['type'])) { if (isset($_REQUEST['type'])) {
$selectedType[] = $_REQUEST['type']; $selectedType[] = $_REQUEST['type'];
} }
elseif (!empty($types)) { elseif (!empty($types)) {
$selectedType[] = $types[0]; $selectedType[] = $types[0]->getId();
} }
$typeSelect = new htmlTableExtendedSelect('type', $typeList, $selectedType, _("Account type")); $typeSelect = new htmlTableExtendedSelect('type', $typeList, $selectedType, _("Account type"));
$typeSelect->setHasDescriptiveElements(true); $typeSelect->setHasDescriptiveElements(true);
@ -162,32 +183,32 @@ $moduleLabel = new htmlOutputText(_('Selected modules'));
$moduleLabel->alignment = htmlElement::ALIGN_TOP; $moduleLabel->alignment = htmlElement::ALIGN_TOP;
$table->addElement($moduleLabel); $table->addElement($moduleLabel);
$moduleGroup = new htmlGroup(); $moduleGroup = new htmlGroup();
for ($i = 0; $i < sizeof($types); $i++) { foreach ($types as $type) {
$divClasses = array('typeOptions'); $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'; $divClasses[] = 'hidden';
} }
$innerTable = new htmlTable(); $innerTable = new htmlTable();
$modules = $_SESSION['config']->get_AccountModules($types[$i]); $modules = $_SESSION['config']->get_AccountModules($type->getId());
for ($m = 0; $m < sizeof($modules); $m++) { for ($m = 0; $m < sizeof($modules); $m++) {
if (($m != 0) && ($m%3 == 0)) { if (($m != 0) && ($m%3 == 0)) {
echo $innerTable->addNewLine(); echo $innerTable->addNewLine();
} }
$module = moduleCache::getModule($modules[$m], $types[$i]); $module = moduleCache::getModule($modules[$m], $type->getScope());
$iconImage = $module->getIcon(); $iconImage = $module->getIcon();
if (!is_null($iconImage) && !(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) { if (!is_null($iconImage) && !(strpos($iconImage, 'http') === 0) && !(strpos($iconImage, '/') === 0)) {
$iconImage = '../../graphics/' . $iconImage; $iconImage = '../../graphics/' . $iconImage;
} }
$innerTable->addElement(new htmlImage($iconImage)); $innerTable->addElement(new htmlImage($iconImage));
$enabled = true; $enabled = true;
if (is_base_module($modules[$m], $types[$i])) { if (is_base_module($modules[$m], $type->getScope())) {
$enabled = false; $enabled = false;
} }
$checked = true; $checked = true;
if (isset($_POST['submit']) && !isset($_POST[$types[$i] . '_' . $modules[$m]])) { if (isset($_POST['submit']) && !isset($_POST[$type->getId() . '___' . $modules[$m]])) {
$checked = false; $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); $checkbox->setIsEnabled($enabled);
if ($enabled) { if ($enabled) {
$innerTable->addElement($checkbox); $innerTable->addElement($checkbox);
@ -196,12 +217,12 @@ for ($i = 0; $i < sizeof($types); $i++) {
$boxGroup = new htmlGroup(); $boxGroup = new htmlGroup();
$boxGroup->addElement($checkbox); $boxGroup->addElement($checkbox);
// add hidden field to fake disabled checkbox value // 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($boxGroup);
} }
$innerTable->addElement(new htmlSpacer('10px', null)); $innerTable->addElement(new htmlSpacer('10px', null));
} }
$typeDiv = new htmlDiv($types[$i], $innerTable); $typeDiv = new htmlDiv($type->getId(), $innerTable);
$typeDiv->setCSSClasses($divClasses); $typeDiv->setCSSClasses($divClasses);
$moduleGroup->addElement($typeDiv); $moduleGroup->addElement($typeDiv);
} }
@ -231,10 +252,11 @@ include '../main_footer.php';
/** /**
* Displays the acount type specific main page of the upload. * 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 * @param array $selectedModules list of selected account modules
*/ */
function showMainPage($scope, $selectedModules) { function showMainPage($type, $selectedModules) {
$scope = $type->getScope();
echo '<div class="' . $scope . '-bright smallPaddingContent">'; echo '<div class="' . $scope . '-bright smallPaddingContent">';
// get input fields from modules // get input fields from modules
$columns = getUploadColumns($scope, $selectedModules); $columns = getUploadColumns($scope, $selectedModules);
@ -257,7 +279,7 @@ function showMainPage($scope, $selectedModules) {
$inputContainer->addElement(new htmlInputFileUpload('inputfile')); $inputContainer->addElement(new htmlInputFileUpload('inputfile'));
$inputContainer->addElement(new htmlSpacer('10px', null)); $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 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); $inputContainer->addElement(new htmlHiddenInput('selectedModules', implode(',', $selectedModules)), true);
// PDF // PDF
$createPDF = false; $createPDF = false;
@ -267,7 +289,7 @@ function showMainPage($scope, $selectedModules) {
$pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files')); $pdfCheckbox = new htmlTableExtendedInputCheckbox('createPDF', $createPDF, _('Create PDF files'));
$pdfCheckbox->setTableRowsToShow(array('pdfStructure')); $pdfCheckbox->setTableRowsToShow(array('pdfStructure'));
$inputContainer->addElement($pdfCheckbox, true); $inputContainer->addElement($pdfCheckbox, true);
$pdfStructures = \LAM\PDF\getPDFStructures($scope); $pdfStructures = \LAM\PDF\getPDFStructures($type->getId());
$pdfSelected = array(); $pdfSelected = array();
if (isset($_POST['pdfStructure'])) { if (isset($_POST['pdfStructure'])) {
$pdfSelected = array($_POST['pdfStructure']); $pdfSelected = array($_POST['pdfStructure']);
@ -321,9 +343,9 @@ function showMainPage($scope, $selectedModules) {
$dnSuffixRowCells[] = $columnSpacer; $dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText('dn_suffix'); $dnSuffixRowCells[] = new htmlOutputText('dn_suffix');
$dnSuffixRowCells[] = $columnSpacer; $dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText($_SESSION['config']->get_Suffix($scope)); $dnSuffixRowCells[] = new htmlOutputText($type->getSuffix());
$dnSuffixRowCells[] = $columnSpacer; $dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText($_SESSION['config']->get_Suffix($scope)); $dnSuffixRowCells[] = new htmlOutputText($type->getSuffix());
$dnSuffixRowCells[] = $columnSpacer; $dnSuffixRowCells[] = $columnSpacer;
$dnSuffixRowCells[] = new htmlOutputText(''); $dnSuffixRowCells[] = new htmlOutputText('');
$dnSuffixRowCells[] = new htmlSpacer(null, '25px'); $dnSuffixRowCells[] = new htmlSpacer(null, '25px');
@ -340,7 +362,7 @@ function showMainPage($scope, $selectedModules) {
$dnRDNRowCells[] = $columnSpacer; $dnRDNRowCells[] = $columnSpacer;
$dnRDNRowCells[] = new htmlOutputText('dn_rdn'); $dnRDNRowCells[] = new htmlOutputText('dn_rdn');
$dnRDNRowCells[] = $columnSpacer; $dnRDNRowCells[] = $columnSpacer;
$rdnAttributes = getRDNAttributes($scope, $selectedModules); $rdnAttributes = getRDNAttributes($type->getId(), $selectedModules);
$dnRDNRowCells[] = new htmlOutputText($rdnAttributes[0]); $dnRDNRowCells[] = new htmlOutputText($rdnAttributes[0]);
$dnRDNRowCells[] = $columnSpacer; $dnRDNRowCells[] = $columnSpacer;
$dnRDNRowCells[] = new htmlOutputText(''); $dnRDNRowCells[] = new htmlOutputText('');
@ -456,9 +478,9 @@ function showMainPage($scope, $selectedModules) {
$sampleCSV_head[] = "\"" . $columns[$modules[$m]][$i]['name'] . "\""; $sampleCSV_head[] = "\"" . $columns[$modules[$m]][$i]['name'] . "\"";
} }
} }
$RDNs = getRDNAttributes($scope, $selectedModules); $RDNs = getRDNAttributes($type->getId(), $selectedModules);
// DN attributes // DN attributes
$sampleCSV_row[] = "\"" . $_SESSION['config']->get_Suffix($scope) . "\""; $sampleCSV_row[] = "\"" . $type->getSuffix() . "\"";
$sampleCSV_row[] = "\"" . $RDNs[0] . "\""; $sampleCSV_row[] = "\"" . $RDNs[0] . "\"";
// module attributes // module attributes
for ($m = 0; $m < sizeof($modules); $m++) { for ($m = 0; $m < sizeof($modules); $m++) {