From b3def32326b7d73410e1cf26d173d2d254d98695 Mon Sep 17 00:00:00 2001 From: lacatoire Date: Tue, 10 Feb 2026 17:35:02 +0100 Subject: [PATCH] Add CSV export for search results Adds an Export CSV button to search results that downloads all matching devices as a CSV file with columns: Data Center, Cabinet, Device Label, Device Type, Serial No, Asset Tag, Primary IP, Owner, Status. Fixes #1386 --- search.php | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/search.php b/search.php index 20c11ac82..144ef3124 100644 --- a/search.php +++ b/search.php @@ -307,6 +307,37 @@ exit; } + // Export search results as CSV + if(isset($_REQUEST['format']) && $_REQUEST['format']=='csv'){ + header('Content-Type: text/csv; charset=utf-8'); + header(sprintf('Content-Disposition: attachment;filename="opendcim-search-%s.csv"', date("YmdHis"))); + $out = fopen('php://output', 'w'); + fputcsv($out, array(__("Data Center"), __("Cabinet"), __("Device Label"), __("Device Type"), __("Serial No"), __("Asset Tag"), __("Primary IP"), __("Owner"), __("Status"))); + $tmpDept = new Department(); + foreach($dctemp as $DataCenterID=>$DataCenterName){ + foreach($cabtemp as $cabID=>$cabRow){ + if($cabRow['dc']==$DataCenterID){ + foreach($devList as $key => $row){ + if($cabID==$row['cabinet']){ + $d = new Device(); + $d->DeviceID = $row['devid']; + $d->GetDevice(); + $ownerName = ''; + if($d->Owner > 0){ + $tmpDept->DeptID = $d->Owner; + $tmpDept->GetDeptByID(); + $ownerName = $tmpDept->Name; + } + fputcsv($out, array($DataCenterName, $cabRow['name'], $d->Label, $d->DeviceType, $d->SerialNo, $d->AssetTag, $d->PrimaryIP, $ownerName, $d->Status)); + } + } + } + } + } + fclose($out); + exit; + } + // This is the looping portion that we'll call for each device function printDevice($row,$skip=false){ global $devList,$vmList; @@ -448,7 +479,10 @@ function hidedevices(){ include( 'sidebar.inc.php' ); ?>
-
'; ?> +'; +?>