14,29 → 14,16 |
|
if(array_key_exists('detail', $_GET)) { |
$cdr_detail = array(); |
$db->query_params("select r.*," |
. " p1.person_name as src_name, e1.entry_title as src_title," |
. " p2.person_name as dst_name, e2.entry_title as dst_title" |
. " from cdr r" |
. " left join telbook_entries e1 on r.src=e1.entry_value" |
. " left join telbook_persons p1 on p1.person_id=e1.entry_person" |
. " left join telbook_entries e2 on r.dst=e2.entry_value" |
. " left join telbook_persons p2 on p2.person_id=e2.entry_person" |
. " where acctid=$1", array($_GET['detail'])); |
$db->query_params('SELECT * FROM cdr WHERE acctid=$1', array($_GET['detail'])); |
$detail = $db->fetch_row(); |
|
for($i = 0; $i < $db->num_fields(); ++$i) { |
for ($i=0;$i<$db->num_fields();$i++) { |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
} |
$cdr_detail['CDR_STATUS'] = ($detail ? 'DONE' : 'NOT FOUND'); |
$cdr_detail['CDR_CALLDATE_F'] = FormatDateTime($detail['calldate']); |
$cdr_detail['CDR_DURATION_F'] = FormatDuration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = FormatDuration($detail['billsec']); |
$cdr_detail['CDR_SRC_PERSON'] = $detail['src_name'] . ($detail['src_title'] ? '/' |
. $detail['src_title'] : ''); |
$cdr_detail['CDR_DST_PERSON'] = $detail['dst_name'] . ($detail['dst_title'] ? '/' |
. $detail['dst_title'] : ''); |
$cdr_detail['CDR_DURATION_F'] = Duration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = Duration($detail['billsec']); |
|
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
43,33 → 30,21 |
} |
elseif(array_key_exists('active', $_GET)) { |
$cdr_detail = array(); |
$db->query_params("select acctid, calldate, linkdate, clid, src, dst, dcontext," |
. " channel, dstchannel, lastapp, lastdata," |
. " extract(epoch from date_trunc('second',current_timestamp-calldate)) as duration," |
. " extract(epoch from date_trunc('second',current_timestamp-linkdate)) as billsec," |
. " disposition, amaflags, accountcode, uniqueid, userfield," |
. " p1.person_name as src_name, e1.entry_title as src_title," |
. " p2.person_name as dst_name, e2.entry_title as dst_title" |
. " from activecalls r" |
. " left join telbook_entries e1 on r.src=e1.entry_value" |
. " left join telbook_persons p1 on p1.person_id=e1.entry_person" |
. " left join telbook_entries e2 on r.dst=e2.entry_value" |
. " left join telbook_persons p2 on p2.person_id=e2.entry_person" |
. " where acctid=$1 and duration is null", array($_GET['active'])); |
$db->query_params("SELECT acctid, calldate, linkdate, clid, src, dst, dcontext," |
. " channel, dstchannel, lastapp, lastdata," |
. " extract(epoch from date_trunc('second',current_timestamp-calldate)) as duration," |
. " extract(epoch from date_trunc('second',current_timestamp-linkdate)) as billsec," |
. " disposition, amaflags, accountcode, uniqueid, userfield FROM activecalls" |
. " WHERE acctid=$1 and duration is null", array($_GET['active'])); |
$detail = $db->fetch_row(); |
|
for($i = 0; $i < $db->num_fields(); ++$i) { |
for ($i=0;$i<$db->num_fields();$i++) { |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
} |
$cdr_detail['CDR_STATUS'] = ($detail ? 'ACTIVE' : 'NOT FOUND'); |
$cdr_detail['CDR_CALLDATE_F'] = FormatDateTime($detail['calldate']); |
$cdr_detail['CDR_DURATION_F'] = FormatDuration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = FormatDuration($detail['billsec']); |
$cdr_detail['CDR_SRC_PERSON'] = $detail['src_name'] . ($detail['src_title'] ? '/' |
. $detail['src_title'] : ''); |
$cdr_detail['CDR_DST_PERSON'] = $detail['dst_name'] . ($detail['dst_title'] ? '/' |
. $detail['dst_title'] : ''); |
$cdr_detail['CDR_DURATION_F'] = Duration($detail['duration']); |
$cdr_detail['CDR_BILLSEC_F'] = Duration($detail['billsec']); |
|
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
106,10 → 81,9 |
return $sql; |
} |
|
function do_date_compare($period, $diff = NULL) |
function do_date_compare($period) |
{ |
return " and date_trunc('" . $period . "', calldate)" |
. ($diff ? " + interval '$diff $period'" : "") . " = date_trunc('" |
return " and date_trunc('" . $period . "', calldate) = date_trunc('" |
. $period . "', current_date)"; |
} |
|
136,11 → 110,10 |
$query_limit = ''; |
if(array_key_exists('list',$_GET)) { |
switch($_GET['list']) { |
case 'year': $query .= do_date_compare('year'); break; |
case 'month': $query .= do_date_compare('month'); break; |
case 'week': $query .= do_date_compare('week'); break; |
case 'lastweek': $query .= do_date_compare('week', 1); break; |
case 'today': $query .= do_date_compare('day'); break; |
case 'year': $query .= do_date_compare('year'); break; |
case 'month': $query .= do_date_compare('month'); break; |
case 'week': $query .= do_date_compare('week'); break; |
case 'today': $query .= do_date_compare('day'); break; |
case 'active': |
$active = true; |
$query .= " and duration is null"; |
152,47 → 125,29 |
|
if($active) { |
$list_query = "select acctid,calldate,src,dst," |
. " extract(epoch from date_trunc('second'," |
. " current_timestamp-linkdate)) as billsec,disposition," |
. " p1.person_name as src_name, e1.entry_title as src_title," |
. " p2.person_name as dst_name, e2.entry_title as dst_title" |
. " from activecalls r" |
. " left join telbook_entries e1 on r.src=e1.entry_value" |
. " left join telbook_persons p1 on p1.person_id=e1.entry_person" |
. " left join telbook_entries e2 on r.dst=e2.entry_value" |
. " left join telbook_persons p2 on p2.person_id=e2.entry_person" |
. " where" |
. " extract(epoch from date_trunc('second'," |
. " current_timestamp-linkdate)) as billsec,disposition" |
. " from activecalls where" |
. $query . " order by calldate desc" . $query_limit; |
} |
else { |
$list_query = "select acctid,calldate,src,dst,billsec,disposition," |
. " p1.person_name as src_name, e1.entry_title as src_title," |
. " p2.person_name as dst_name, e2.entry_title as dst_title" |
. " from cdr r" |
. " left join telbook_entries e1 on r.src=e1.entry_value" |
. " left join telbook_persons p1 on p1.person_id=e1.entry_person" |
. " left join telbook_entries e2 on r.dst=e2.entry_value" |
. " left join telbook_persons p2 on p2.person_id=e2.entry_person" |
. " where" |
$list_query = "select acctid,calldate,src,dst,billsec,disposition" |
. " from cdr where" |
. $query . " order by calldate desc" . $query_limit; |
} |
$result = $db->query_params($list_query, $params); |
|
$calls_number = $db->num_rows(); |
$cdr = new Table(array('ID', 'Call Date', array('text' => 'Source', 'colspan' => 2), |
array('text' => 'Destination', 'colspan' => 2), 'Duration', 'Disposition')); |
$cdr = new Table(array('ID', 'Call Date', 'Source', 'Destination', 'Duration', 'Disposition')); |
$cdr->set_table_class('stat cdr list'); |
|
while($line = $db->fetch_row()) { |
$cdr->newrow(); |
$cdr->addcell($line['acctid']); |
$cdr->addcell(FormatDateTime($line['calldate'])); |
$cdr->addcell(array('text' => $line['src'], 'class' => 'num')); |
$cdr->addcell($line['src_name'] . ($line['src_title'] ? '/' . $line['src_title'] : '')); |
$cdr->addcell(array('text' => $line['dst'], 'class' => 'num')); |
$cdr->addcell($line['dst_name'] . ($line['dst_title'] ? '/' . $line['dst_title'] : '')); |
$cdr->addcell(array('text' => ($line['disposition'] == 'ANSWERED' |
? FormatDuration($line['billsec']) : ''), 'class' => 'duration')); |
$cdr->addcell($line['calldate']); |
$cdr->addcell($line['src']); |
$cdr->addcell($line['dst']); |
$cdr->addcell($line['disposition'] == 'ANSWERED' ? Duration($line['billsec']) : ''); |
$cdr->addcell(strtolower($line['disposition'])); |
$cdr->addcell(array('class' => 'link', 'html' => |
display_link($PHP_SELF . '?m=cdr&' . ($active ? 'active' : 'detail') |
218,10 → 173,10 |
$cdr->addcell($calls_number); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Call Seconds')); |
$cdr->addcell(FormatDuration($line['dur'])); |
$cdr->addcell(Duration($line['dur'])); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Bill Seconds')); |
$cdr->addcell(FormatDuration($line['bill'])); |
$cdr->addcell(Duration($line['bill'])); |
$display->add_html_text($cdr->build()); |
} |
else { |