#!/usr/bin/php
<?php
if ($argc < 4 )
{
exit( "Usage: find-recording.php <days> <cid> <did>\n Eg: find-recording.php 2 0123456789 0987654321\n\n" );
}
$look_back_days = $argv[1];
$did = $argv[3];
$cid = $argv[2];
$sql = "select start_stamp, caller_id_number, destination_number, record_path, record_name, xml_cdr_uuid from v_xml_cdr
where to_timestamp(end_epoch) > current_date -".$look_back_days."
and to_timestamp(end_epoch) < current_date
and caller_destination = '".$did."'
and caller_id_number = '".$cid."'
and record_name is not NULL";
$dbconn = pg_connect("host=127.0.0.1 port=5432 dbname=fusionpbx user=fusionpbx password=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
if (!$dbconn) {
echo "An error occurred connecting to the database.\n";
exit(1);
}
$result = pg_query($dbconn, $sql);
if (!$result) {
echo "An error occurred with the database query.\n";
exit(1);
}
$rec_count = pg_num_rows($result);
echo $rec_count." recording(s) to list.\n";
while ($row = pg_fetch_row($result)) {
$calltime = str_replace(" ", "_", str_replace(":", "-", $row[0]));
$caller = str_replace("+", "", $row[1]);
$callee = str_replace("+", "", $row[2]);
$recording_file = $row[3]."/".$row[4];
$call_uuid = $row[5];
echo $call_uuid.", ".$recording_file.", ".$callee.", ".$caller.", ".$calltime."\n";
}
pg_free_result($result);
pg_close($dbconn);
echo "Listing complete.\n\n";
exit(0);
?>