示例#1
0
                 $oP = new XMLPage("iTop - Export", true);
                 cmdbAbstractObject::DisplaySetAsXML($oP, $oSet, array('localize_values' => $bLocalize));
                 break;
             case 'xlsx':
                 $oP = new ajax_page('');
                 $oExporter = new ExcelExporter();
                 $oExporter->SetObjectList($oFilter);
                 // Run the export by chunk of 1000 objects to limit memory usage
                 $oExporter->SetChunkSize(1000);
                 do {
                     $aStatus = $oExporter->Run();
                     // process one chunk
                 } while ($aStatus['code'] != 'done' && $aStatus['code'] != 'error');
                 if ($aStatus['code'] == 'done') {
                     $oP->SetContentType('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
                     $oP->SetContentDisposition('attachment', $oFilter->GetClass() . '.xlsx');
                     $oP->add(file_get_contents($oExporter->GetExcelFilePath()));
                     $oExporter->Cleanup();
                 } else {
                     $oP->add('Error, xlsx export failed: ' . $aStatus['message']);
                 }
                 break;
             default:
                 $oP = new WebPage("iTop - Export");
                 $oP->add("Unsupported format '{$sFormat}'. Possible values are: html, csv, spreadsheet or xml.");
         }
     }
 } catch (Exception $e) {
     $oP = new WebPage("iTop - Export");
     $oP->p("Error the query can not be executed.");
     if ($e instanceof CoreException) {
示例#2
0
 $sClassName = utils::ReadParam('class_name');
 $sFormat = utils::ReadParam('format', 'csv');
 if (MetaModel::IsValidClass($sClassName)) {
     $oSearch = new DBObjectSearch($sClassName);
     $oSearch->AddCondition('id', 0, '=');
     // Make sure we create an empty set
     $oSet = new CMDBObjectSet($oSearch);
     $sResult = cmdbAbstractObject::GetSetAsCSV($oSet, array('showMandatoryFields' => true));
     $sClassDisplayName = MetaModel::GetName($sClassName);
     $sDisposition = utils::ReadParam('disposition', 'inline');
     if ($sDisposition == 'attachment') {
         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);
 /**
  * Helper to download the file directly from the browser	
  */
 public function DownloadBackup($sFile)
 {
     $oP = new ajax_page('backup');
     $oP->SetContentType("multipart/x-zip");
     $oP->SetContentDisposition('inline', basename($sFile));
     $oP->add(file_get_contents($sFile));
     $oP->output();
 }