diff --git a/lam/lib/export.inc b/lam/lib/export.inc new file mode 100644 index 00000000..f084db75 --- /dev/null +++ b/lam/lib/export.inc @@ -0,0 +1,127 @@ +baseDn = $baseDn; + $this->searchScope = $searchScope; + $this->filter = $filter; + $this->attributes = $attributes; + $this->includeSystem = $includeSystem; + $this->saveAsFile = $saveAsFile; + $this->format = $format; + $this->ending = $ending; + } + + /** + * Starts the export process. + * + * @return string JSON result + */ + public function doExport() { + try { + $this->checkParameters(); + } + catch (LAMException $e) { + $data = Exporter::formatMessage('ERROR', $e->getTitle(), $e->getMessage()); + $status = array( + Exporter::STATUS => 'failed', + Exporter::DATA => $data + ); + return json_encode($status); + } + } + + /** + * Returns the HTML for an error message. + * + * @param string $type message type (e.g. INFO) + * @param string $title title + * @param string $message message + * @return string HTML + */ + public static function formatMessage($type, $title, $message) { + $msg = new htmlStatusMessage($type, $title, $message); + $tabindex = 0; + ob_start(); + $msg->generateHTML(null, array($msg), array(), true, $tabindex, 'user'); + $data = ob_get_contents(); + ob_clean(); + return $data; + } + + /** + * Checks the input parameters for validity. + * + * @throws LAMException in case of errors + */ + private function checkParameters() { + if (!get_preg($this->baseDn, 'dn')) { + throw new LAMException(_('Please enter a valid DN in the field:'), _('Base DN')); + } + } + +} diff --git a/lam/lib/import.inc b/lam/lib/import.inc index 3c780c54..6288eece 100644 --- a/lam/lib/import.inc +++ b/lam/lib/import.inc @@ -34,7 +34,7 @@ use \LAMException; include_once('ldap.inc'); /** - * Creates LDAP accounts for file upload. + * Imports LDIF files. * * @author Roland Gruber * @package tools diff --git a/lam/templates/lib/500_lam.js b/lam/templates/lib/500_lam.js index e23dbb34..d77f2343 100644 --- a/lam/templates/lib/500_lam.js +++ b/lam/templates/lib/500_lam.js @@ -901,7 +901,7 @@ window.lam.tools.schema.select = function() { }); }; -window.lam.import = window.lam.import || {}; +window.lam.importexport = window.lam.importexport || {}; /** * Starts the import process. @@ -909,7 +909,7 @@ window.lam.import = window.lam.import || {}; * @param tokenName name of CSRF token * @param tokenValue value of CSRF token */ -window.lam.import.startImport = function(tokenName, tokenValue) { +window.lam.importexport.startImport = function(tokenName, tokenValue) { jQuery(document).ready(function() { jQuery('#progressbarImport').progressbar(); var output = jQuery('#importResults'); @@ -949,6 +949,55 @@ window.lam.import.startImport = function(tokenName, tokenValue) { }); }; +/** + * Starts the export process. + * + * @param tokenName name of CSRF token + * @param tokenValue value of CSRF token + */ +window.lam.importexport.startExport = function(tokenName, tokenValue) { + jQuery(document).ready(function() { + jQuery('#progressbarExport').progressbar({value: 50}); + var output = jQuery('#exportResults'); + var data = { + jsonInput: '' + }; + data[tokenName] = tokenValue; + data['baseDn'] = jQuery('#baseDn').val(); + data['searchScope'] = jQuery('#searchScope').val(); + data['filter'] = jQuery('#filter').val(); + data['attributes'] = jQuery('#attributes').val(); + data['format'] = jQuery('#format').val(); + data['ending'] = jQuery('#ending').val(); + data['includeSystem'] = jQuery('#includeSystem').val(); + data['saveAsFile'] = jQuery('#saveAsFile').val(); + jQuery.ajax({ + url: '../misc/ajax.php?function=export', + method: 'POST', + data: data + }) + .done(function(jsonData){ + if (jsonData.data && (jsonData.data != '')) { + output.append(jsonData.data); + } + if (jsonData.status == 'done') { + jQuery('#progressbarExport').hide(); + jQuery('#btn_submitExportCancel').hide(); + jQuery('#statusExportInprogress').hide(); + jQuery('#statusExportDone').show(); + jQuery('.newexport').show(); + } + else { + jQuery('#progressbarExport').hide(); + jQuery('#btn_submitExportCancel').hide(); + jQuery('#statusExportInprogress').hide(); + jQuery('#statusExportFailed').show(); + jQuery('.newexport').show(); + } + }); + }); +}; + jQuery(document).ready(function() { window.lam.gui.equalHeight(); window.lam.form.autoTrim(); diff --git a/lam/templates/misc/ajax.php b/lam/templates/misc/ajax.php index a246e67c..e8e53a8e 100644 --- a/lam/templates/misc/ajax.php +++ b/lam/templates/misc/ajax.php @@ -1,6 +1,7 @@ doExport(); + ob_end_clean(); + echo $jsonOut; + } elseif ($function === 'upload') { include_once('../../lib/upload.inc'); $typeManager = new \LAM\TYPES\TypeManager(); diff --git a/lam/templates/tools/importexport.php b/lam/templates/tools/importexport.php index cf3ec4bf..0e3f4f67 100644 --- a/lam/templates/tools/importexport.php +++ b/lam/templates/tools/importexport.php @@ -17,6 +17,7 @@ use \htmlResponsiveSelect; use \htmlResponsiveInputField; use \htmlGroup; use \htmlInputField; +use \htmlHiddenInput; use LAM\TYPES\TypeManager; /* @@ -215,7 +216,7 @@ function printImportTabProcessing(&$tabindex) { $container->add(new htmlDiv('importResults', new htmlOutputText('')), 12); $container->add(new htmlJavaScript( - 'window.lam.import.startImport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' + 'window.lam.importexport.startImport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' ), 12); addSecurityTokenToMetaHTML($container); @@ -273,7 +274,7 @@ function printExportTabContent(&$tabindex) { _('One (one level beneath base)') => 'one', _('Sub (entire subtree)') => 'sub' ); - $searchScopeSelect = new htmlResponsiveSelect('searchscope', $searchScopes, array('sub'), _('Search scope')); + $searchScopeSelect = new htmlResponsiveSelect('searchScope', $searchScopes, array('sub'), _('Search scope')); $searchScopeSelect->setHasDescriptiveElements(true); $searchScopeSelect->setSortElements(false); $container->add($searchScopeSelect, 12); @@ -351,6 +352,15 @@ function printExportTabProcessing(&$tabindex) { $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); @@ -367,7 +377,7 @@ function printExportTabProcessing(&$tabindex) { $container->add(new htmlDiv('exportResults', new htmlOutputText('')), 12); $container->add(new htmlJavaScript( - 'window.lam.export.startExport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' + 'window.lam.importexport.startExport(\'' . getSecurityTokenName() . '\', \'' . getSecurityTokenValue() . '\');' ), 12); addSecurityTokenToMetaHTML($container);