I use the following method. I have one script (rack_query.php.php) and refer in the file local.php to this script. It generates a csv from the sql querie which you can define on your own. The directory queries is an virtual directory configured in apache. That way I only have to copy one file "local.php" if I upgrade. Hope it helps, gretz Killsystem On Sat, 13 Sep 2008 21:14:10 -0400, Jason Ledford <jledford@xxxxxxxxxxxx> wrote: > That is pretty much what I was looking for. The only addition that would > be nice is to be able to export that, maybe a csv option or something. > Other than that it looks great. > > Thanks.
<?php $db=mysql_connect('localhost','USER','PASSWORT'); if (!$db) { die('Not connected : ' . mysql_error()); } $db_selected = mysql_select_db('racktables', $db); if (!$db_selected) { die ('Can\'t use foo : ' . mysql_error()); } //SQL query starts here $sql = "SELECT DISTINCT(RackObject.name) AS servername, RackObject.Barcode AS serialnumber, RackObject.comment AS comment, " . "REPLACE(d1.dict_value, '%GPASS%',' ') AS OS, ". "IF (INSTR(d2.dict_value,'|')<=0,REPLACE(d2.dict_value, '%GPASS%',' '),REPLACE(REPLACE(LEFT(d2.dict_value,INSTR(d2.dict_value,'|')-2), '%GPASS%',' '),'[[','')) AS hardware, ". "IF (INSTR(av2.string_value,'|')<=0,REPLACE(av2.string_value, '%GPASS%',' '),REPLACE(REPLACE(LEFT(av2.string_value,INSTR(av2.string_value,'|')-2), '%GPASS%',' '),'[[','')) AS contact, ". "d4.dict_value AS Serverraum, "."r2.name AS rackname ". "FROM RackObject ". "LEFT JOIN AttributeValue AS av1 ON (av1.object_id = RackObject.id AND av1.attr_id = 4) ". "LEFT JOIN Dictionary AS d1 ON d1.dict_key = av1.uint_value ". "LEFT JOIN AttributeValue AS av2 ON (av2.object_id = RackObject.id AND av2.attr_id = 14) ". "LEFT JOIN AttributeValue AS av3 ON (av3.object_id = RackObject.id AND av3.attr_id = 2) ". "LEFT JOIN Dictionary AS d2 ON d2.dict_key = av3.uint_value ". "LEFT JOIN RackSpace AS r1 ON r1.object_id = RackObject.id ". "LEFT JOIN Rack AS r2 ON r1.rack_id = r2.id ". "LEFT JOIN Dictionary AS d4 ON d4.dict_key = r2.row_id ". "WHERE RackObject.objtype_id = 4 ORDER BY RackObject.id;"; //SQL query end here $rsSearchResults = mysql_query($sql, $db) or die(mysql_error()); $columns = mysql_num_fields($rsSearchResults); while ($i < $columns) { $meta = mysql_fetch_field($rsSearchResults, $i); if ($meta) { $out .= '"'.$meta->name.'";'; } $i++; } $out .="\n"; while ($l = mysql_fetch_array($rsSearchResults)) { for ($i = 0; $i < $columns; $i++) { $out .='"'.$l["$i"].'";'; } $out .="\n"; } // Output to browser with appropriate mime type, you choose ;) header("Content-type: text/x-csv"); //header("Content-type: text/csv"); //header("Content-type: application/csv"); header("Content-Disposition: attachment; filename=Serverliste.csv"); echo $out; mysql_close($db); exit; ?>
<?php $localreports[] = array ( 'title' => 'Custom reports', 'type' => 'custom', 'func' => 'getOwnReports' ); function getOwnReports() { echo "<table>\n"; echo "<tr><th class=tdright>Serverlist</th><td class=tdleft><a href=\"./queries/rack_query.php\">download</a></td></tr>\n"; echo "</table>\n"; } ?>