switch ($sFormat) { case 'xlsx': $oPage = new ajax_page(""); $oPage->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); $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 {
if ($iSearch !== false) { $bViewLink = true; unset($aFields[$iSearch]); } else { $bViewLink = false; } $sFields = implode(',', $aFields); $aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => false, 'extra_fields' => $sFields, 'view_link' => $bViewLink); } else { $aExtraParams = array('menu' => false, 'toolkit_menu' => false, 'display_limit' => false, 'localize_values' => $bLocalize, 'zlist' => 'details'); } $oResultBlock = new DisplayBlock($oFilter, 'list', false, $aExtraParams); $oResultBlock->Display($oP, 'expresult'); break; case 'csv': $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);
// Big result sets cause long OQL that cannot be passed (serialized) as a GET parameter // Therefore we don't use the standard "search_oql" operation of UI.php to display the CSV $iCategory = utils::ReadParam('category', ''); $iRuleIndex = utils::ReadParam('rule', 0); $oAuditCategory = MetaModel::GetObject('AuditCategory', $iCategory); $oDefinitionFilter = DBObjectSearch::FromOQL($oAuditCategory->Get('definition_set')); FilterByContext($oDefinitionFilter, $oAppContext); $oDefinitionSet = new CMDBObjectSet($oDefinitionFilter); $oFilter = GetRuleResultFilter($iRuleIndex, $oDefinitionFilter, $oAppContext); $oErrorObjectSet = new CMDBObjectSet($oFilter); $oAuditRule = MetaModel::GetObject('AuditRule', $iRuleIndex); $sFileName = utils::ReadParam('filename', null, true, 'string'); $bAdvanced = utils::ReadParam('advanced', false); $sAdvanced = $bAdvanced ? '&advanced=1' : ''; 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();
global $aPageParams; assert(isset($aPageParams[$sParam])); assert($aPageParams[$sParam]['mandatory']); $sValue = utils::ReadParam($sParam, null, true, $sSanitizationFilter); if (is_null($sValue)) { $oP->p("ERROR: Missing argument '{$sParam}'\n"); UsageAndExit($oP); } return trim($sValue); } ///////////////////////////////// // Main program if (utils::IsModeCLI()) { $oP = new CLIPage("iTop - Bulk import"); } else { $oP = new CSVPage("iTop - Bulk import"); } try { utils::UseParamFile(); } catch (Exception $e) { $oP->p("Error: " . $e->GetMessage()); $oP->output(); exit - 2; } if (utils::IsModeCLI()) { // Next steps: // specific arguments: 'csvfile' // $sAuthUser = ReadMandatoryParam($oP, 'auth_user', 'raw_data'); $sAuthPwd = ReadMandatoryParam($oP, 'auth_pwd', 'raw_data'); $sCsvFile = ReadMandatoryParam($oP, 'csvfile', 'raw_data');