\n"; $container = new htmlResponsiveRow(); $container->add(new htmlTitle(_("Import")), 12); $sources = array( _('File') => 'file', _('Text input') => 'text' ); $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->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); } 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.import.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); } include '../../lib/adminFooter.inc';