responsive upload

This commit is contained in:
Roland Gruber 2018-04-18 19:08:51 +02:00
parent 9e71a67953
commit c0df2e6a27
2 changed files with 36 additions and 32 deletions

View File

@ -468,9 +468,10 @@ function getUploadColumns(&$type, $selectedModules) {
* @param array $data array containing one account in each element * @param array $data array containing one account in each element
* @param array $ids array(<column_name> => <column number>) * @param array $ids array(<column_name> => <column number>)
* @param array $selectedModules selected account modules * @param array $selectedModules selected account modules
* @param htmlResponsiveRow $container HTML container
* @return mixed array including accounts or false if there were errors * @return mixed array including accounts or false if there were errors
*/ */
function buildUploadAccounts($type, $data, $ids, $selectedModules) { function buildUploadAccounts($type, $data, $ids, $selectedModules, htmlResponsiveRow $container) {
// build module order // build module order
$unOrdered = $selectedModules; $unOrdered = $selectedModules;
$ordered = array(); $ordered = array();
@ -512,7 +513,7 @@ function buildUploadAccounts($type, $data, $ids, $selectedModules) {
} }
if ($newRound) continue; if ($newRound) continue;
// this point should never be reached, LAM was unable to find a correct module order // this point should never be reached, LAM was unable to find a correct module order
StatusMessage("ERROR", "Internal Error: Unable to find correct module order.", ""); $container->add(new htmlStatusMessage("ERROR", "Internal Error: Unable to find correct module order."), 12);
return false; return false;
} }
// give raw data to modules // give raw data to modules
@ -532,7 +533,9 @@ function buildUploadAccounts($type, $data, $ids, $selectedModules) {
} }
if (sizeof($errors) > 0) { if (sizeof($errors) > 0) {
for ($i = 0; (($i < sizeof($errors)) || ($i > 49)); $i++) { for ($i = 0; (($i < sizeof($errors)) || ($i > 49)); $i++) {
call_user_func_array("StatusMessage", $errors[$i]); $text = empty($errors[$i][2]) ? null : $errors[$i][2];
$values = empty($errors[$i][3]) ? null : $errors[$i][3];
$container->add(new htmlStatusMessage($errors[$i][0], $errors[$i][1], $text, $values), 12);
} }
return false; return false;
} }

View File

@ -1,14 +1,12 @@
<?php <?php
namespace LAM\UPLOAD; namespace LAM\UPLOAD;
use \htmlTable;
use \htmlSpacer;
use \htmlStatusMessage; use \htmlStatusMessage;
use \htmlLink; use \htmlLink;
use \htmlTitle; use \htmlOutputText;
use \htmlButton; use \htmlButton;
use \htmlHiddenInput; use \htmlHiddenInput;
use \htmlResponsiveRow;
/* /*
$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 - 2018 Roland Gruber Copyright (C) 2004 - 2018 Roland Gruber
@ -97,7 +95,7 @@ if (isset($_GET['showldif'])) {
exit; exit;
} }
include '../main_header.php'; include '../../lib/adminHeader.inc';
$typeId = htmlspecialchars($_POST['typeId']); $typeId = htmlspecialchars($_POST['typeId']);
$typeManager = new \LAM\TYPES\TypeManager(); $typeManager = new \LAM\TYPES\TypeManager();
$type = $typeManager->getConfiguredType($typeId); $type = $typeManager->getConfiguredType($typeId);
@ -114,7 +112,7 @@ if (!checkIfNewEntriesAreAllowed($type->getId()) || !checkIfWriteAccessIsAllowed
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="' . $type->getScope() . '-bright smallPaddingContent">'; echo '<div class="' . $type->getScope() . '-bright smallPaddingContent">';
$container = new htmlTable(); $container = new htmlResponsiveRow();
$selectedModules = explode(',', $_POST['selectedModules']); $selectedModules = explode(',', $_POST['selectedModules']);
if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) { if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
@ -192,15 +190,15 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// if input data is invalid just display error messages (max 50) // if input data is invalid just display error messages (max 50)
if (sizeof($errors) > 0) { if (sizeof($errors) > 0) {
foreach ($errors as $error) { foreach ($errors as $error) {
$container->addElement(new htmlStatusMessage("ERROR", $error[0], $error[1]), true); $container->add(new htmlStatusMessage("ERROR", $error[0], $error[1]), 12);
} }
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
// let modules build accounts // let modules build accounts
else { else {
$accounts = buildUploadAccounts($type, $data, $ids, $selectedModules); $accounts = buildUploadAccounts($type, $data, $ids, $selectedModules, $container);
if ($accounts !== false) { if ($accounts !== false) {
$rdnList = getRDNAttributes($type->getId(), $selectedModules); $rdnList = getRDNAttributes($type->getId(), $selectedModules);
$suffix = $type->getSuffix(); $suffix = $type->getSuffix();
@ -220,7 +218,7 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
// print errors if DN could not be built // print errors if DN could not be built
if (sizeof($errors) > 0) { if (sizeof($errors) > 0) {
foreach ($errors as $error) { foreach ($errors as $error) {
$container->addElement(new htmlStatusMessage("ERROR", $error[0], $error[1], $error[2]), true); $container->add(new htmlStatusMessage("ERROR", $error[0], $error[1], $error[2]), 12);
} }
} }
else { else {
@ -246,25 +244,28 @@ if ($_FILES['inputfile'] && ($_FILES['inputfile']['size'] > 0)) {
$_SESSION['mass_pdf']['structure'] = null; $_SESSION['mass_pdf']['structure'] = null;
} }
// show links for upload and LDIF export // show links for upload and LDIF export
$container->addElement(new htmlTitle(_("LAM has checked your input and is now ready to create the accounts.")), true); $container->addVerticalSpacer('2rem');
$container->addElement(new htmlSpacer(null, '10px'), true); $container->add(new htmlOutputText(_("LAM has checked your input and is now ready to create the accounts.")), 12);
$buttonContainer = new htmlTable(); $container->addVerticalSpacer('4rem');
$buttonContainer->addElement(new htmlLink(_("Upload accounts to LDAP"), 'massDoUpload.php', '../../graphics/up.gif', true)); $link = 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)); $link->setCSSClasses(array('margin3'));
$buttonContainer->addElement(new htmlSpacer('10px', null)); $container->addLabel($link);
massPrintBackButton($type->getId(), $selectedModules, $buttonContainer); $link = new htmlLink(_("Show LDIF file"), 'massBuildAccounts.php?showldif=true', '../../graphics/edit.png', true);
$container->addElement($buttonContainer, true); $link->setCSSClasses(array('margin3'));
$container->addField($link);
$container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container);
} }
} }
else { else {
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
} }
} }
else { else {
$container->addElement(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), true); $container->add(new htmlStatusMessage('ERROR', _('Please provide a file to upload.')), 12);
$container->addElement(new htmlSpacer(null, '10px'), true); $container->addVerticalSpacer('2rem');
massPrintBackButton($type->getId(), $selectedModules, $container); massPrintBackButton($type->getId(), $selectedModules, $container);
} }
@ -274,28 +275,28 @@ parseHtml(null, $container, array(), false, $tabindex, $type->getScope());
echo '</div>'; echo '</div>';
echo '</form>'; echo '</form>';
include '../main_footer.php'; include '../../lib/adminFooter.inc';
/** /**
* 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 $typeId 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 htmlResponsiveRow $container table container
*/ */
function massPrintBackButton($typeId, $selectedModules, htmlTable &$container) { function massPrintBackButton($typeId, $selectedModules, htmlResponsiveRow &$container) {
$backButton = new htmlButton('submit', _('Back')); $backButton = new htmlButton('submit', _('Back'));
$backButton->setIconClass('backButton'); $backButton->setIconClass('backButton');
$container->addElement($backButton); $container->add($backButton, 12);
$container->addElement(new htmlHiddenInput('type', $typeId)); $container->add(new htmlHiddenInput('type', $typeId), 12);
$createPDF = 0; $createPDF = 0;
if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) { if (isset($_POST['createPDF']) && ($_POST['createPDF'] == 'on')) {
$createPDF = 1; $createPDF = 1;
} }
$container->addElement(new htmlHiddenInput('createPDF', $createPDF)); $container->add(new htmlHiddenInput('createPDF', $createPDF), 12);
$container->addElement(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure'])); $container->add(new htmlHiddenInput('pdfStructure', $_POST['pdfStructure']), 12);
foreach ($selectedModules as $selectedModule) { foreach ($selectedModules as $selectedModule) {
$container->addElement(new htmlHiddenInput($typeId . '___' . $selectedModule, 'on')); $container->add(new htmlHiddenInput($typeId . '___' . $selectedModule, 'on'), 12);
} }
} }