1,61 → 1,40 |
<?php |
#################################################### |
# AstWeb - Asterisk PBX Dynamic config environment # |
# # |
# Written by: Jamie Carl # |
# jazz@funkynerd.com # |
# # |
# Copyright (C) 2006 Achieve Corp # |
# # |
# Licence: This software is licenced under the # |
# GNU/GPL. Please see licence.txt for # |
# more information. # |
#################################################### |
|
if(array_key_exists('detail', $_GET)) { |
$cdr_detail = array(); |
$db->query_params("select r.*," |
include_once('includes/common.php'); |
Prolog(); |
|
if(array_key_exists('active', $_GET)) { |
$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 cdr r" |
. " 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", array($_GET['detail'])); |
$detail = $db->fetch_row(); |
|
for($i = 0; $i < $db->num_fields(); ++$i) { |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
. " where acctid=$1 and duration is null", array($_GET['active'])); |
} |
$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'] : ''); |
|
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
} |
elseif(array_key_exists('active', $_GET)) { |
elseif(array_key_exists('detail', $_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," |
$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 activecalls r" |
. " 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 and duration is null", array($_GET['active'])); |
. " where acctid=$1", array($_GET['detail'])); |
} |
else { |
die("No ID to search"); |
} |
|
$cdr_detail = array(); |
$detail = $db->fetch_row(); |
|
for($i = 0; $i < $db->num_fields(); ++$i) { |
62,7 → 41,9 |
$col = $db->get_field_name($i); |
$cdr_detail['CDR_'.strtoupper($col)] = $detail[$col]; |
} |
$cdr_detail['CDR_STATUS'] = ($detail ? 'ACTIVE' : 'NOT FOUND'); |
|
$cdr_detail['CDR_STATUS'] = ($detail ? (array_key_exists('active', $_GET) |
? 'ACTIVE' : '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']); |
71,160 → 52,9 |
$cdr_detail['CDR_DST_PERSON'] = $detail['dst_name'] . ($detail['dst_title'] ? '/' |
. $detail['dst_title'] : ''); |
|
$display->add_variables($cdr_detail); |
$display->add_template('cdr_detail'); |
} |
elseif(array_key_exists('s', $_GET) || array_key_exists('list', $_GET)) { |
function do_field($sql, &$params, $fld) { |
if($fld && $_GET[$fld]) { |
$sql .= " and $fld"; |
if(array_key_exists($fld.'type', $_GET)) { |
$dType = $_GET[$fld.'type']; |
switch($dType) { |
case 1: |
array_push($params, $_GET[$fld]); |
$sql .= "=$" . count($params); |
break; |
case 2: |
array_push($params, "$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
break; |
case 3: |
array_push($params, "%$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
break; |
case 4; |
array_push($params, "%$_GET[$fld]"); |
$sql .= " LIKE $" . count($params); |
} |
} |
else { |
array_push($params, "%$_GET[$fld]%"); |
$sql .= " LIKE $" . count($params); |
} |
} |
return $sql; |
} |
$g_display->add_variables($cdr_detail); |
$g_display->add_template('cdr_detail'); |
|
function do_date_compare($period, $diff = NULL) |
{ |
return " and date_trunc('" . $period . "', calldate)" |
. ($diff ? " + interval '$diff $period'" : "") . " = date_trunc('" |
. $period . "', current_date)"; |
} |
Epilog(); |
|
# Construct Query Here |
$query = BaseQuery(); |
$params = array(); |
$active = false; |
|
if ($_GET['before']) { |
array_push($params, $_GET['before']); |
$query .= " AND calldate < $" . count($params); |
} |
|
if ($_GET['after']) { |
array_push($params, $_GET['after']); |
$query .= " AND calldate > $" . count($params); |
} |
|
$query = do_field($query, $params, 'clid'); |
$query = do_field($query, $params, 'src'); |
$query = do_field($query, $params, 'dst'); |
$query = do_field($query, $params, 'channel'); |
|
$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 'active': |
$active = true; |
$query .= " and duration is null"; |
break; |
|
default: $query_limit .= " limit 1000"; |
} |
} |
|
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" |
. $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" |
. $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->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(strtolower($line['disposition'])); |
$cdr->addcell(array('class' => 'link', 'html' => |
display_link($PHP_SELF . '?m=cdr&' . ($active ? 'active' : 'detail') |
. '=' . $line['acctid'], 'Details'))); |
} |
$display->add_html_text($cdr->build()); |
|
// summary |
if($active) { |
$sum_query = "select" |
. " sum(extract(epoch from date_trunc('second',current_timestamp-calldate))) as dur," |
. " sum(extract(epoch from date_trunc('second',current_timestamp-linkdate))) as bill" |
. " from activecalls where" . $query; |
} |
else { |
$sum_query = "select sum(duration) as dur, sum(billsec) as bill from cdr where" . $query; |
} |
$result = $db->query_params($sum_query, $params); |
$line = $db->fetch_row(); |
$cdr = new Table(); |
$cdr->set_table_class('stat cdr sum'); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Calls')); |
$cdr->addcell($calls_number); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Call Seconds')); |
$cdr->addcell(FormatDuration($line['dur'])); |
$cdr->newrow(); |
$cdr->addcell(array('tag' => 'th', 'text' => 'Bill Seconds')); |
$cdr->addcell(FormatDuration($line['bill'])); |
$display->add_html_text($cdr->build()); |
} |
else { |
$display->add_template('cdr'); |
} |
?> |