if ($sFileName != null) { $oP = new CSVPage("iTop - Export"); $sCharset = MetaModel::GetConfig()->Get('csv_file_default_charset'); $sCSVData = cmdbAbstractObject::GetSetAsCSV($oErrorObjectSet, array('localize_values' => true, 'fields_advanced' => $bAdvanced), $sCharset); if ($sCharset == 'UTF-8') { $sOutputData = UTF8_BOM . $sCSVData; } else { $sOutputData = $sCSVData; } if ($sFileName == '') { // Plain text => Firefox will NOT propose to download the file $oP->add_header("Content-type: text/plain; charset={$sCharset}"); } else { $oP->add_header("Content-type: text/csv; charset={$sCharset}"); } $oP->add($sOutputData); $oP->TrashUnexpectedOutput(); $oP->output(); exit; } else { $oP->add('<div class="page_header"><h1>Audit Errors: <span class="hilite">' . $oAuditRule->Get('description') . '</span></h1><img style="margin-top: -20px; margin-right: 10px; float: right;" src="../images/stop.png"/></div>'); $oP->p('<a href="./audit.php?' . $oAppContext->GetForLink() . '">[Back to audit results]</a>'); $sBlockId = 'audit_errors'; $oP->p("<div id=\"{$sBlockId}\" style=\"clear:both\">\n"); $oBlock = DisplayBlock::FromObjectSet($oErrorObjectSet, 'csv'); $oBlock->Display($oP, 1); $oP->p("</div>\n"); // Adjust the size of the Textarea containing the CSV to fit almost all the remaining space $oP->add_ready_script(" \$('#1>textarea').height(400);"); // adjust the size of the block $sExportUrl = utils::GetAbsoluteUrlAppRoot() . "pages/audit.php?operation=csv&category=" . $oAuditCategory->GetKey() . "&rule=" . $oAuditRule->GetKey();
$oPage->SetContentDisposition('attachment', $sClassDisplayName . '.xlsx'); require_once APPROOT . '/application/excelexporter.class.inc.php'; $writer = new XLSXWriter(); $writer->setAuthor(UserRights::GetUserFriendlyName()); $aHeaders = array(0 => explode(',', $sResult)); // comma is the default separator $writer->writeSheet($aHeaders, $sClassDisplayName, array()); $oPage->add($writer->writeToString()); break; case 'csv': default: $oPage = new CSVPage(""); $oPage->add_header("Content-type: text/csv; charset=utf-8"); $oPage->add_header("Content-disposition: attachment; filename=\"{$sClassDisplayName}.csv\""); $oPage->no_cache(); $oPage->add($sResult); } } else { $oPage = new ajax_page(""); $oPage->no_cache(); $oPage->add('<p style="text-align:center">'); $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&class_name=' . $sClassName . '"><img border="0" src="../images/csv.png"><br/>' . $sClassDisplayName . '.csv</a></div>'); $oPage->add('<div style="display:inline-block;margin:0.5em;"><a style="text-decoration:none" href="' . utils::GetAbsoluteUrlAppRoot() . 'pages/ajax.csvimport.php?operation=get_csv_template&disposition=attachment&format=xlsx&class_name=' . $sClassName . '"><img border="0" src="../images/xlsx.png"><br/>' . $sClassDisplayName . '.xlsx</a></div>'); $oPage->add('</p>'); $oPage->add('<p><textarea rows="5" cols="100">' . $sResult . '</textarea></p>'); } } else { $oPage = new ajax_page("Class {$sClassName} is not a valid class !"); } break; }
$oP = new CSVPage("iTop - Export"); $sFields = implode(',', $aFields); $sCharset = utils::ReadParam('charset', MetaModel::GetConfig()->Get('csv_file_default_charset'), true, 'raw_data'); $sCSVData = cmdbAbstractObject::GetSetAsCSV($oSet, array('fields' => $sFields, 'fields_advanced' => $bFieldsAdvanced, 'localize_values' => $bLocalize), $sCharset); if ($sCharset == 'UTF-8') { $sOutputData = UTF8_BOM . $sCSVData; } else { $sOutputData = $sCSVData; } if ($sFileName == '') { // Plain text => Firefox will NOT propose to download the file $oP->add_header("Content-type: text/plain; charset={$sCharset}"); } else { $oP->add_header("Content-type: text/csv; charset={$sCharset}"); } $oP->add($sOutputData); break; case 'spreadsheet': $oP = new WebPage("iTop - Export for spreadsheet"); // Integration within MS-Excel web queries + HTTPS + IIS: // MS-IIS set these header values with no-cache... while Excel fails to do the job if using HTTPS // Then the fix is to force the reset of header values Pragma and Cache-control header("Pragma:", true); header("Cache-control:", true); $sFields = implode(',', $aFields); $oP->add_style('table br {mso-data-placement:same-cell;}'); // Trick for Excel: keep line breaks inside the same cell ! cmdbAbstractObject::DisplaySetAsHTMLSpreadsheet($oP, $oSet, array('fields' => $sFields, 'fields_advanced' => $bFieldsAdvanced, 'localize_values' => $bLocalize)); break; case 'xml': $oP = new XMLPage("iTop - Export", true);