Last active
October 7, 2015 13:55
-
-
Save jfinstrom/439bf68d64111ba75ffc to your computer and use it in GitHub Desktop.
Last 30 days of CDR as CSV with FreePBX bootstrap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
if (!@include_once(getenv('FREEPBX_CONF') ? getenv('FREEPBX_CONF') : '/etc/freepbx.conf')) { | |
include_once('/etc/asterisk/freepbx.conf'); | |
} | |
$outfile = '/tmp/report.csv'; | |
$dbh = \FreePBX::Database(); | |
$sql = "SELECT * FROM asteriskcdrdb.cdr WHERE date(calldate) >= date(now()-interval 30 day);"; | |
$stmt = $dbh->prepare($sql); | |
$stmt->execute(); | |
$ret = $stmt->fetchAll(\PDO::FETCH_ASSOC); | |
$colnames = array_keys($ret[0]); | |
$csv = fopen($outfile,'w+'); | |
fputcsv($csv,$colnames); | |
foreach($ret as $row){ | |
fputcsv($csv,$row); | |
} | |
fclose($csv); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Requires FreePBX 12 or higher