$dstchannel = str_replace('AND dst', '', $dst); $dst = "{$dst_type} ({$dst_remaining} OR dstchannel {$dstchannel})"; } // Build the "WHERE" part of the query $where = "WHERE {$date_range} {$cnum} {$outbound_cnum} {$cnam} {$dst_cnam} {$did} {$dst} {$userfield} {$accountcode} {$disposition} {$duration}"; if (isset($_POST['need_csv']) && $_POST['need_csv'] == 'true') { $query = "(SELECT calldate, clid, did, src, dst, dcontext, channel, dstchannel, lastapp, lastdata, duration, billsec, disposition, amaflags, accountcode, uniqueid, userfield, cnum, cnam, outbound_cnum, outbound_cnam, dst_cnam FROM {$db_name}.{$db_table_name} {$where} {$order} {$sort} LIMIT {$result_limit})"; $resultcsv = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC); cdr_export_csv($resultcsv); } if (empty($resultcdr) && isset($_POST['need_html']) && $_POST['need_html'] == 'true') { $query = "SELECT `calldate`, `clid`, `did`, `src`, `dst`, `dcontext`, `channel`, `dstchannel`, `lastapp`, `lastdata`, `duration`, `billsec`, `disposition`, `amaflags`, `accountcode`, `uniqueid`, `userfield`, unix_timestamp(calldate) as `call_timestamp`, `recordingfile`, `cnum`, `cnam`, `outbound_cnum`, `outbound_cnam`, `dst_cnam` FROM {$db_name}.{$db_table_name} {$where} {$order} {$sort} LIMIT {$result_limit}"; $resultscdr = $dbcdr->getAll($query, DB_FETCHMODE_ASSOC); $resultscdr = is_array($resultscdr) ? $resultscdr : array(); foreach ($resultscdr as &$call) { $file = FreePBX::Cdr()->processPath($call['recordingfile']); if (empty($file)) { //hide files that dont exist $call['recordingfile'] = ''; } } } if (isset($resultscdr)) { $tot_calls_raw = sizeof($resultscdr); } else { $tot_calls_raw = 0; } if ($tot_calls_raw) { // This is a bit of a hack, if we generated CEL data above, then these are simply the records all related to that CEL // event stream. //