\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Import")), 12); $sources = array( _('Text input') => 'text', _('File') => 'file', ); $sourceRadio = new htmlResponsiveRadio(_('Source'), 'source', $sources, 'text'); $sourceRadio->setTableRowsToHide( array( 'file' => array('text'), 'text' => array('file') ) ); $sourceRadio->setTableRowsToShow( array( 'text' => array('text'), 'file' => array('file') ) ); $container->add($sourceRadio, 12); $container->addVerticalSpacer('1rem'); $container->add(new htmlResponsiveInputFileUpload('file', _('File'), '750'), 12); $container->add(new htmlResponsiveInputTextarea('text', '', '60', '20', _('LDIF data'), '750'), 12); $container->add(new htmlResponsiveInputCheckbox('noStop', false, _('Don\'t stop on errors')), 12); $container->addVerticalSpacer('3rem'); $button = new htmlButton('submitImport', _('Submit')); $container->add($button, 12, 12, 12, 'text-center'); addSecurityTokenToMetaHTML($container); parseHtml(null, $container, array(), false, $tabindex, 'user'); echo "\n"; } /** * Prints the content area for the import tab during processing state. * * @param int $tabindex tabindex */ function printImportTabProcessing(&$tabindex) { try { checkImportData(); } catch (LAMException $e) { $container = new htmlResponsiveRow(); $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()), 12); parseHtml(null, $container, array(), false, $tabindex, 'user'); printImportTabContent($tabindex); return; } echo "
\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Import")), 12); $container->add(new htmlDiv('statusImportInprogress', new htmlOutputText(_('Status') . ': ' . _('in progress'))), 12); $container->add(new htmlDiv('statusImportDone', new htmlOutputText(_('Status') . ': ' . _('done')), array('hidden')), 12); $container->add(new htmlDiv('statusImportFailed', new htmlOutputText(_('Status') . ': ' . _('failed')), array('hidden')), 12); $container->addVerticalSpacer('1rem'); $container->add(new htmlDiv('progressbarImport', new htmlOutputText('')), 12); $container->addVerticalSpacer('3rem'); $button = new htmlButton('submitImportCancel', _('Cancel')); $container->add($button, 12, 12, 12, 'text-center'); $newImportButton = new htmlLink(_('New import'), null, null, true); $container->add($newImportButton, 12, 12, 12, 'text-center hidden newimport'); $container->addVerticalSpacer('3rem'); $container->add(new htmlDiv('importResults', new htmlOutputText('')), 12); $container->add(new htmlJavaScript( 'window.lam.importexport.startImport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' ), 12); addSecurityTokenToMetaHTML($container); parseHtml(null, $container, array(), false, $tabindex, 'user'); echo "
\n"; } /** * Checks if the import data is ok. * * @throws LAMException error message if not valid */ function checkImportData() { $source = $_POST['source']; $ldif = ''; if ($source == 'text') { $ldif = $_POST['text']; } else { $handle = fopen($_FILES['file']['tmp_name'], "r"); $ldif = fread($handle, 100000000); fclose($handle); } if (empty($ldif)) { throw new LAMException(_('You must either upload a file or provide an import in the text box.')); } $lines = preg_split("/\n|\r\n|\r/", $ldif); $importer = new Importer(); $tasks = $importer->getTasks($lines); $_SESSION[Importer::SESSION_KEY_TASKS] = $tasks; $_SESSION[Importer::SESSION_KEY_COUNT] = sizeof($tasks); $_SESSION[Importer::SESSION_KEY_STOP_ON_ERROR] = (!isset($_POST['noStop']) || ($_POST['noStop'] != 'on')); } /** * Prints the content area for the export tab. * * @param int $tabindex tabindex */ function printExportTabContent(&$tabindex) { echo "
\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Export")), 12); $baseDnField = new htmlResponsiveInputField(_('Base DN'), 'baseDn', getDefaultBaseDn(), '751', true); $baseDnField->showDnSelection(); $container->add($baseDnField, 12); $searchScopes = array( _('Base (base dn only)') => 'base', _('One (one level beneath base)') => 'one', _('Sub (entire subtree)') => 'sub' ); $searchScopeSelect = new htmlResponsiveSelect('searchScope', $searchScopes, array('sub'), _('Search scope')); $searchScopeSelect->setHasDescriptiveElements(true); $searchScopeSelect->setSortElements(false); $container->add($searchScopeSelect, 12); $container->add(new htmlResponsiveInputField(_('Search filter'), 'filter', '(objectClass=*)', '752'), 12); $container->add(new htmlResponsiveInputField(_('Attributes'), 'attributes', '*', '753'), 12); $container->add(new htmlResponsiveInputCheckbox('includeSystem', false, _('Include system attributes'), '754'), 12); $container->add(new htmlResponsiveInputCheckbox('saveAsFile', false, _('Save as file')), 12); $formats = array( 'CSV' => 'csv', 'LDIF' => 'ldif' ); $formatSelect = new htmlResponsiveSelect('format', $formats, array('ldif'), _('Export format')); $formatSelect->setHasDescriptiveElements(true); $formatSelect->setSortElements(false); $container->add($formatSelect, 12); $endings = array( 'Windows' => 'windows', 'Unix' => 'unix' ); $endingsSelect = new htmlResponsiveSelect('ending', $endings, array('unix'), _('End of line')); $endingsSelect->setHasDescriptiveElements(true); $endingsSelect->setSortElements(false); $container->add($endingsSelect, 12); $container->addVerticalSpacer('3rem'); $button = new htmlButton('submitExport', _('Submit')); $container->add($button, 12, 12, 12, 'text-center'); addSecurityTokenToMetaHTML($container); parseHtml(null, $container, array(), false, $tabindex, 'user'); echo "
\n"; } /** * Returns the default base DN. * * @return string base DN */ function getDefaultBaseDn() { $typeManager = new TypeManager(); $baseDn = ''; foreach ($typeManager->getConfiguredTypes() as $type) { $suffix = $type->getSuffix(); if (empty($baseDn) || (!empty($suffix) && (strlen($suffix) < strlen($baseDn)))) { $baseDn = $suffix; } } $treeSuffix = $_SESSION['config']->get_Suffix('tree'); if (empty($baseDn) || (!empty($treeSuffix) && (strlen($treeSuffix) < strlen($baseDn)))) { $baseDn = $treeSuffix; } return $baseDn; } /** * Prints the content area for the export tab during processing state. * * @param int $tabindex tabindex */ function printExportTabProcessing(&$tabindex) { try { checkExportData(); } catch (LAMException $e) { $container = new htmlResponsiveRow(); $container->add(new htmlStatusMessage('ERROR', $e->getTitle(), $e->getMessage()), 12); parseHtml(null, $container, array(), false, $tabindex, 'user'); printExportTabContent($tabindex); return; } echo "
\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Export")), 12); $container->add(new htmlHiddenInput('baseDn', $_POST['baseDn']), 12); $container->add(new htmlHiddenInput('searchScope', $_POST['searchScope']), 12); $container->add(new htmlHiddenInput('filter', $_POST['filter']), 12); $container->add(new htmlHiddenInput('attributes', $_POST['attributes']), 12); $container->add(new htmlHiddenInput('format', $_POST['format']), 12); $container->add(new htmlHiddenInput('ending', $_POST['ending']), 12); $container->add(new htmlHiddenInput('includeSystem', isset($_POST['includeSystem']) && ($_POST['includeSystem'] === 'on') ? 'true' : 'false'), 12); $container->add(new htmlHiddenInput('saveAsFile', isset($_POST['saveAsFile']) && ($_POST['saveAsFile'] === 'on') ? 'true' : 'false'), 12); $container->add(new htmlDiv('statusExportInprogress', new htmlOutputText(_('Status') . ': ' . _('in progress'))), 12); $container->add(new htmlDiv('statusExportDone', new htmlOutputText(_('Status') . ': ' . _('done')), array('hidden')), 12); $container->add(new htmlDiv('statusExportFailed', new htmlOutputText(_('Status') . ': ' . _('failed')), array('hidden')), 12); $container->addVerticalSpacer('1rem'); $container->add(new htmlDiv('progressbarExport', new htmlOutputText('')), 12); $container->addVerticalSpacer('3rem'); $button = new htmlButton('submitExportCancel', _('Cancel')); $container->add($button, 12, 12, 12, 'text-center'); $newExportButton = new htmlLink(_('New export'), null, null, true); $container->add($newExportButton, 12, 12, 12, 'text-center hidden newexport'); $container->addVerticalSpacer('3rem'); $exportText = new htmlOutputText(''); $exportText->setPreformatted(true); $container->add(new htmlDiv('exportResults', $exportText), 12); $container->add(new htmlJavaScript( 'window.lam.importexport.startExport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' ), 12); addSecurityTokenToMetaHTML($container); parseHtml(null, $container, array(), false, $tabindex, 'user'); echo "
\n"; } /** * Checks if the export data is ok. * * @throws LAMException error message if not valid */ function checkExportData() { if (empty($_POST['baseDn'])) { throw new LAMException(_('This field is required.'), _('Base DN')); } } include '../../lib/adminFooter.inc';