/asterisk-stats/trunk/cdr.php |
---|
34,7 → 34,7 |
elseif(array_key_exists('s', $_GET) || array_key_exists('list', $_GET)) { |
function do_field($sql, &$params, $fld) { |
if ($fld && $_GET[$fld]) { |
$sql .= " and $fld"; |
$sql .= " AND $fld"; |
if (array_key_exists($fld.'type', $_GET)) { |
$dType = $_GET[$fld.'type']; |
switch ($dType) { |
63,7 → 63,7 |
} |
# Construct Query Here |
$query = BaseQuery(); |
$query = ""; |
$params = array(); |
if ($_GET['before']) { |
84,17 → 84,17 |
$query_limit = ''; |
if(array_key_exists('list',$_GET)) { |
switch($_GET['list']) { |
case 'year': $query .= " and date_trunc('year', calldate) = date_trunc('year', current_date)"; break; |
case 'month': $query .= " and date_trunc('month', calldate) = date_trunc('month', current_date)"; break; |
case 'week': $query .= " and date_trunc('week', calldate) = date_trunc('week', current_date)"; break; |
case 'today': $query .= " and date_trunc('day', calldate) = date_trunc('day', current_date)"; break; |
default: $query_limit .= " limit 1000"; |
case 'year': $query .= " AND date_trunc('year', calldate) = date_trunc('year', current_date)"; break; |
case 'month': $query .= " AND date_trunc('month', calldate) = date_trunc('month', current_date)"; break; |
case 'week': $query .= " AND date_trunc('week', calldate) = date_trunc('week', current_date)"; break; |
case 'today': $query .= " AND date_trunc('day', calldate) = date_trunc('day', current_date)"; break; |
default: $query_limit .= " limit 200"; |
} |
} |
$list_query = "select acctid,calldate,src,dst,billsec,disposition" |
. " from cdr where" |
. $query . " order by calldate desc" . $query_limit; |
$list_query = "SELECT acctid,calldate,src,dst,billsec,disposition" |
. " from cdr where dstchannel != ''" |
. $query . " ORDER BY calldate desc" . $query_limit; |
$result = $db->query_params($list_query, $params); |
$calls_number = $db->num_rows(); |
115,7 → 115,7 |
$display->add_text($cdr->build()); |
// summary |
$sum_query = "select sum(duration) as dur, sum(billsec) as bill from cdr where" . $query; |
$sum_query = "SELECT sum(duration) as dur, sum(billsec) as bill from cdr where dstchannel != ''" . $query; |
$result = $db->query_params($sum_query, $params); |
$line = $db->fetch_row(); |
$cdr = new Table(); |
135,3 → 135,4 |
$display->add_template('cdr'); |
} |
?> |
/asterisk-stats/trunk/summary.php |
---|
16,23 → 16,26 |
die('Hacking attempt!'); |
} |
function add_summary($count_name, $dur_name, $interval) |
{ |
global $db, $display; |
$db->query('SELECT COUNT(acctid), SUM(billsec) FROM cdr WHERE date(calldate) = current_date'); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_TODAY' => $db->get_field(0), |
'CS_TODAY_DUR' => Duration($db->get_field(1)))); |
$db->query('SELECT COUNT(acctid), SUM(billsec) FROM cdr WHERE calldate > (now() - (extract(dow from now()) || \' day\')::interval)'); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_WEEK' => $db->get_field(0), |
'CS_WEEK_DUR' => Duration($db->get_field(1)))); |
$db->query('SELECT COUNT(acctid), SUM(billsec) FROM cdr WHERE EXTRACT(month FROM calldate) = EXTRACT(month FROM now())'); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_MONTH' => $db->get_field(0), |
'CS_MONTH_DUR' => Duration($db->get_field(1)))); |
$db->query('SELECT COUNT(acctid), SUM(billsec) FROM cdr WHERE calldate > (now() - (extract(month from now()) || \' months\')::interval)'); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_YEAR' => $db->get_field(0), |
'CS_YEAR_DUR' => Duration($db->get_field(1)))); |
$db->query('SELECT COUNT(acctid), SUM(billsec) FROM cdr'); |
$db->fetch_row_idx(); |
$display->add_variables(array('CS_TOTAL' => $db->get_field(0), |
'CS_TOTAL_DUR' => Duration($db->get_field(1)))); |
$db->query("select count(acctid), sum(billsec) from cdr where" . BaseQuery() |
. ($interval ? " and date_trunc('" . $interval . "', calldate) = date_trunc('" |
. $interval . "', current_date)" : "")); |
$db->fetch_row_idx(); |
$display->add_variables(array($count_name => $db->get_field(0), |
$dur_name => Duration($db->get_field(1)))); |
} |
add_summary('CS_TODAY', 'CS_TODAY_DUR', 'day'); |
add_summary('CS_WEEK', 'CS_WEEK_DUR', 'week'); |
add_summary('CS_MONTH', 'CS_MONTH_DUR', 'month'); |
add_summary('CS_YEAR', 'CS_YEAR_DUR', 'year'); |
add_summary('CS_TOTAL', 'CS_TOTAL_DUR', null); |
$display->add_template('summary'); |
?> |
/asterisk-stats/trunk/config.php-dist |
---|
33,10 → 33,5 |
$db_password = 'password'; |
$db_database = 'asterisk'; |
// any local specific query |
function BaseQuery() |
{ |
return " dstchannel != ''"; |
} |
?> |