Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 1280 → Rev 1281

/asterisk-stats/trunk/summary.php
0,0 → 1,41
<?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(!defined('IN_ASTWEB')) {
die('Hacking attempt!');
}
$db->query('SELECT COUNT(acctid), SUM(duration) 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(duration) 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(duration) 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(duration) 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(duration) FROM cdr');
$db->fetch_row_idx();
$display->add_variables(array('CS_TOTAL' => $db->get_field(0),
'CS_TOTAL_DUR' => Duration($db->get_field(1))));
 
$display->add_template('summary');
?>
/asterisk-stats/trunk/includes/db/postgresql.php
0,0 → 1,102
<?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 ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
class db_obj {
private $connection;
private $result;
private $row;
function __construct($host, $user, $password, $database) {
$this->connection = pg_connect('host='.$host.' user='.$user.' password='.$password.' dbname='.$database) or
die("SQL service unavailable please try again later");
}
 
function __destruct() {
if($this->connection) {
pg_close($this->connection);
}
}
 
function query($sql) {
if($this->connection) {
$this->result = pg_query($this->connection, $sql) or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function query_params($sql, $params) {
if($this->connection) {
$this->result = pg_query_params($this->connection, $sql, $params)
or die('Query failed: '.$sql);
return $this->result;
}
return false;
}
 
function fetch_row() {
if($this->result) {
$this->row = pg_fetch_assoc($this->result);
return $this->row;
}
return false;
}
 
function fetch_row_idx() {
if($this->result) {
$this->row = pg_fetch_row($this->result);
return $this->row;
}
return false;
}
 
function fetch_all() {
if($this->result) {
return pg_fetch_all($this->result);
}
return false;
}
 
function num_rows() {
if($this->result) {
return pg_num_rows($this->result);
}
 
return 0;
}
 
function num_fields() {
if($this->result) {
return pg_num_fields($this->result);
}
}
 
function get_field_name($col) {
if($this->result) {
return pg_field_name($this->result, $col);
}
}
 
function get_field($col) {
if($this->row) {
return $this->row[$col];
}
return NULL;
}
}
?>
/asterisk-stats/trunk/includes/db.php
0,0 → 1,27
<?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 ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
switch($db_type) {
case 'PGSQL':
include($includes.'/db/postgresql.php');
break;
}
 
$db = new db_obj($db_host, $db_user, $db_password, $db_database);
 
?>
/asterisk-stats/trunk/includes/display.php
0,0 → 1,236
<?php
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
class template_handler {
private $data = array();
private $files = array();
private $vars = array();
private $root;
 
function __construct($root_dir) {
$this->root = $root_dir;
}
function add_template($file) {
array_push($this->files, array('FILE' => $file));
}
 
function add_text($text) {
array_push($this->files, array('TEXT' => $text));
}
 
function __toString() {
foreach($this->files as $f) {
if(array_key_exists('FILE', $f)) {
$this->data = array_merge($this->data, file($this->root.'/'.$f['FILE'].'.tpl'));
}
if(array_key_exists('TEXT', $f)) {
array_push($this->data, $f['TEXT']."\n");
}
}
foreach($this->data as $l) {
$form = $form.$this->replace_variables($l);
}
 
return $form;
}
 
function replace_variables($data) {
$varrefs = array();
preg_match_all('/\$\{(\w+)\}/', $data, $varrefs);
$varcount = sizeof($varrefs[1]);
for ($i = 0; $i < $varcount; $i++) {
if(array_key_exists($varrefs[1][$i], $this->vars)) {
$data = str_replace($varrefs[0][$i], $this->vars[$varrefs[1][$i]], $data);
}
}
 
return $data;
}
 
function add_variables($args) {
if(is_array($args)) {
$this->vars = array_merge($this->vars, $args);
}
}
}
 
function display_link($url, $label) {
if(!$label) {
$label = $url;
}
 
return '<A HREF="'.$url.'">'.$label.'</a>';
}
 
function s_text($text) {
if(is_array($text)) {
for($i=0;$i<sizeof($text);$i++) {
$text[$i] = ereg_replace('<', '&lt;', $text[$i]);
$text[$i] = ereg_replace('>', '&gt;', $text[$i]);
}
} else {
$text = ereg_replace('<', '&lt;', $text);
}
 
return $text;
}
 
class Table {
#Define somewhere to store the rows
protected $rowid = 0;
protected $rows = array();
protected $row_styles = array();
protected $hdr = array();
 
#Define an array to store the stylesheet classes for each row
protected $table_class = '';
protected $header_class = '';
 
function __construct($header = array()) {
$this->hdr = $header;
}
 
public function destroy() {
$this->hdr = array();
$this->sc = array();
$this->rows = array();
}
 
public function set_table_class($class) {
$this->table_class = $class;
}
 
public function newrow() {
$this->rows[] = array();
}
 
public function addcell($data) {
$key = count($this->rows) - 1;
if($key < 0) {
$this->newrow();
$key = 0;
}
 
if(!is_array($data)) {
$data = array('text' => $data);
}
 
$this->rows[$key][] = $data;
}
 
public function __toString() {
return $this->build();
}
 
public function build() {
$tag = "table";
if($this->table_class) $tag .= " class=\"$this->table_class\"";
 
$output = "<$tag>\n";
 
#Display the header
if($this->hdr) {
$output .= "\t<thead>\n\t\t<tr>\n";
 
foreach($this->hdr as $cell) {
if(!is_array($cell)) $cell = array('text' => $cell);
 
$tag = $cell['tag'] ? $cell['tag'] : 'th';
 
$output .= "\t\t\t<" . $tag;
if($cell['class']) {
$output .= " class=\"$class\"";
}
 
if($cell['text']) {
$html = s_text($cell['text']);
}
else {
$html = $cell['html'];
}
 
$output .= ">" . $html . "</" . $tag . ">\n";
}
 
$output .= "\t\t</tr>\n\t</thead>\n";
}
 
$output .= "\t<tbody>\n";
 
foreach($this->rows as $row) {
$output .= "\t\t<tr>\n";
 
foreach($row as $cell) {
$tag = $cell['tag'] ? $cell['tag'] : 'td';
 
$output .= "\t\t\t<" . $tag;
if($cell['class']) {
$output .= ' class="' . $cell['class'] . '"';
}
 
if($cell['text']) {
$html = s_text($cell['text']);
}
else {
$html = $cell['html'];
}
if(!$html) $html = '&nbsp;';
 
$output .= ">" . $html . "</" . $tag . ">\n";
}
 
$output .= "\t\t</tr>\n";
}
 
$output .= "\t</tbody>\n</table>\n";
 
return $output;
}
}
 
function Form($method, $action, $text) {
$form = '<form method="'.$method.'" action="'.$action.'">'."\n";
$form .= $text;
$form .= "</form>\n";
return $form;
}
 
function Input($type,$name,$value = '') {
return '<input type="'.$type.'" name="'.$name.'" value="'.$value.'">'."\n";
}
 
function Combo($name, $data, $default) {
if(is_array($data)) {
$output = '<SELECT NAME="'.$name."\">\n";
foreach($data as $options) {
$output .= "\t<OPTION ";
if(is_array($options)) {
$op = array_values($options);
if($default == $op[0]) {
$output .= 'SELECTED ';
}
$output .= 'value="'.$op[0].'">';
if($op[1] == '') {
$output .= $op[0];
} else {
$output .= $op[1];
}
$output .= '</OPTION>'."\n";
} else {
if($options == $default) {
$output .= 'SELECTED ';
}
$output .= 'value="'.$options.'">1'.$options;
}
$output .= "</option>\n";
}
$output .= '</SELECT>'."\n";
}
 
return $output;
}
 
?>
/asterisk-stats/trunk/includes/functions.php
0,0 → 1,49
<?php
 
if(!defined('IN_ASTWEB')) {
die('Hacking Attempt');
}
 
 
$PHP_SELF = $_SERVER['PHP_SELF'];
 
function GetGet($var) {
$val = "";
 
if(array_key_exists($var, $_GET)) {
$val = $_GET[$var];
} elseif(array_key_exists($var, $_POST)) {
$val = $_POST[$var];
} else {
$val = "";
}
 
$val = str_replace("'", "\\'", $val);
$val = str_replace('\\', '\\\\', $val);
 
return $val;
}
 
 
function Duration($seconds) {
$minutes = $seconds / 60;
$seconds = $seconds % 60;
$hours = $minutes / 60;
$minutes = $minutes % 60;
 
return sprintf("%d:%02d:%02d", $hours, $minutes, $seconds);
}
 
function FormatTime($time) {
//Format the time to human readable format
$diff = $time;
$hrsdiff = floor($diff/60/60);
$diff -= $hrsdiff*60*60;
$minsdiff = floor($diff/60);
$diff -= $minsdiff*60;
$secsdiff = $diff;
 
return (' ('.$hrsdiff.'h '.$minsdiff.'m '.$secsdiff.'s)');
}
 
?>
/asterisk-stats/trunk/astweb.php
0,0 → 1,46
<?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. #
####################################################
 
define('IN_ASTWEB', true);
 
include_once('config.php');
include_once($includes.'/display.php');
include_once($includes.'/functions.php');
include_once($includes.'/db.php');
 
$display = new template_handler('template');
$display->add_template('header');
$display->add_template('menu');
 
$pg_globals = array('AST_STYLESHEET' => $site_style,
'AST_SITETITLE' => $site_title,
'AST_DATETIME' => date('Y-m-d H:i:s'),
'HREF_HOME' => $PHP_SELF,
'HREF_CDR' => $PHP_SELF.'?m=cdr',
'HREF_CDR_LIST' => $PHP_SELF.'?m=cdr&list');
$display->add_variables($pg_globals);
 
switch($_GET['m']) {
case 'cdr':
include('cdr.php');
break;
default:
include('summary.php');
}
 
$display->add_template('footer');
echo $display;
 
?>
/asterisk-stats/trunk/template/cdr.tpl
0,0 → 1,49
<form method="${CDR_METHOD}" action="${CDR_ACTION}">
<input type=hidden name=m value=cdr>
<input type=hidden name=s>
<table class="stat cdr search">
<tr>
<th>After</th>
<td><input type=text name="after" value="${AST_DATETIME}"></td>
<td colspan="4" class="desc">Format: YYYY-MM-DD hh:mm:ss</td>
</tr>
<tr>
<th>Before</th>
<td><input type=text name="before" value=""></td>
<td colspan="4" class="desc">Format: YYYY-MM-DD hh:mm:ss</td>
 
</tr>
<tr>
<th>CLI</th>
<td><input type=text name="clid" value=""></td>
<td class="radio"><input type=radio name="clidtype" value="1">Exact</td>
<td class="radio"><input type=radio name="clidtype" value="2">Begins with</td>
<td class="radio"><input type=radio name="clidtype" value="3">Contains</td>
<td class="radio"><input type=radio name="clidtype" value="4">Ends with</td>
</tr>
<tr>
<th>Source</th>
<td><input type=text name="src" value=""></td>
<td class="radio"><input type=radio name="srctype" value="1">Exact</td>
<td class="radio"><input type=radio name="srctype" value="2">Begins with</td>
<td class="radio"><input type=radio name="srctype" value="3">Contains</td>
<td class="radio"><input type=radio name="srctype" value="4">Ends with</td>
</tr>
<tr>
<th>Desination</th>
<td><input type=text name="dst" value=""></td>
<td class="radio"><input type=radio name="dsttype" value="1">Exact</td>
<td class="radio"><input type=radio name="dsttype" value="2">Begins with</td>
<td class="radio"><input type=radio name="dsttype" value="3">Contains</td>
<td class="radio"><input type=radio name="dsttype" value="4">Ends with</td>
</tr>
<tr>
<th>Channel</th>
<td><input type=text name="channel" value=""></td>
<td colspan="4" class="desc">&nbsp;</td>
</tr>
<tr class="buttons">
<td colspan=5><input type=reset name="reset" value="Reset"></td>
<td><input type=submit value="Show CDR"></td>
</tr>
</table>
/asterisk-stats/trunk/template/header.tpl
0,0 → 1,6
<html>
<title>${AST_SITETITLE}</title>
<link rel=stylesheet href=${AST_STYLESHEET} type=text/css>
</head>
<body>
<div class="main">
/asterisk-stats/trunk/template/cdr_detail.tpl
0,0 → 1,52
<div class="rval">Details for call ${CDR_ACCTID}</div>
<table class="stat cdr details">
<tr>
<th>Calldate</th>
<td>${CDR_CALLDATE}&nbsp;</td>
</tr><tr>
<th>CLID</th>
<td>${CDR_CLID}&nbsp;</td>
</tr><tr>
<th>Source</th>
<td>${CDR_SRC}&nbsp;</td>
</tr><tr>
<th>Destination</th>
<td>${CDR_DST}&nbsp;</td>
</tr><tr>
<th>Context</th>
<td>${CDR_DCONTEXT}&nbsp;</td>
</tr><tr>
<th>Channel</th>
<td>${CDR_CHANNEL}&nbsp;</td>
</tr><tr>
<th>Destination Channel</th>
<td>${CDR_DSTCHANNEL}&nbsp;</td>
</tr><tr>
<th>Last Application</th>
<td>${CDR_LASTAPP}&nbsp;</td>
</tr><tr>
<th>Last Data</th>
<td>${CDR_LASTDATA}&nbsp;</td>
</tr><tr>
<th>Duration</th>
<td>${CDR_DURATION}&nbsp;</td>
</tr><tr>
<th>Billed Seconds</th>
<td>${CDR_BILLSEC}&nbsp;</td>
</tr><tr>
<th>Disposition</th>
<td>${CDR_DISPOSITION}&nbsp;</td>
</tr><tr>
<th>AMA Flags</th>
<td>${CDR_AMAFLAGS}&nbsp;</td>
</tr><tr>
<th>Account Code</th>
<td>${CDR_ACCOUNTCODE}&nbsp;</td>
</tr><tr>
<th>Unique ID</th>
<td>${CDR_UNIQUEID}&nbsp;</td>
</tr><tr>
<th>User Field</th>
<td>${CDR_USERFIELD}&nbsp;</td>
</tr>
</table>
/asterisk-stats/trunk/template/summary.tpl
0,0 → 1,28
<table class="calls stat">
<tr>
<th>&nbsp;</th>
<th>calls</th>
<th>duration</th>
</tr><tr>
<td class="t"><a href=${HREF_CDR_LIST}=today>Today</a></td>
<td class="d"><a href=${HREF_CDR_LIST}=today>${CS_TODAY}</a></td>
<td class="di"><a href=${HREF_CDR_LIST}=today>${CS_TODAY_DUR}</a></td>
</tr><tr>
<td class="t"><a href=${HREF_CDR_LIST}=week>This Week</a></td>
<td class="d"><a href=${HREF_CDR_LIST}=week>${CS_WEEK}</a></td>
<td class="di"><a href=${HREF_CDR_LIST}=week>${CS_WEEK_DUR}</a></td>
</tr><tr>
<td class="t"><a href=${HREF_CDR_LIST}=month>This Month</a></td>
<td class="d"><a href=${HREF_CDR_LIST}=month>${CS_MONTH}</a></td>
<td class="di"><a href=${HREF_CDR_LIST}=month>${CS_MONTH_DUR}</a></td>
</tr><tr>
<td class="t"><a href=${HREF_CDR_LIST}=year>This Year</a></td>
<td class="d"><a href=${HREF_CDR_LIST}=year>${CS_YEAR}</a></td>
<td class="di"><a href=${HREF_CDR_LIST}=year>${CS_YEAR_DUR}</a></td>
</tr><tr class="total">
<td class="t"><a href=${HREF_CDR_LIST}>Total</a></td>
<td class="d"><a href=${HREF_CDR_LIST}>${CS_TOTAL}</a></td>
<td class="di"><a href=${HREF_CDR_LIST}>${CS_TOTAL_DUR}</a></td>
</tr>
</table>
 
/asterisk-stats/trunk/template/footer.tpl
0,0 → 1,7
</div>
<div class="copyright">
Copyright &copy; 2006 <a href="http://www.funkynerd.com" target=_blank>funkynerd.com</a><br>
Copyright &copy; 2007 <a href="http://www.26th.net" target=_blank>Anatoli Klassen</a>
</div>
</body>
</html>
/asterisk-stats/trunk/template/menu.tpl
0,0 → 1,7
<table class="menu">
<tr>
<td><a href=..>Up</a></td>
<td><a href=${HREF_HOME}>Summary</a></td>
<td><a href=${HREF_CDR}>Search</a></td>
</tr>
</table>
/asterisk-stats/trunk/astweb.css
0,0 → 1,105
body {
font-family: Verdana;
font-size: 8pt;
}
 
a {
text-decoration: none;
}
 
table.menu {
background-color: #6876F8;
position: fixed;
left: 0;
top: 0;
width: 100%;
height: 40px;
font-size: 14pt;
}
 
table.menu td {
text-align: center;
}
 
table.menu a {
color: #FFFFFF;
}
 
div.copyright {
color: #FFFFFF;
font: 8pt Verdana;
text-align: center;
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #6876F8;
}
 
div.copyright a {
color: #FFFFFF;
}
 
div.main {
margin-top: 50px;
margin-bottom: 50px;
}
 
table.calls a {
color: #000000;
}
 
table.stat th {
color: #FFFFFF;
background-color: #6876F8;
font-weight: bold;
font-size: 10pt;
padding: 5px;
}
 
table.stat td {
border: 1px solid #AAAAAA;
text-align: right;
padding: 5px;
vertical-align: text-bottom;
font-size: 8pt;
}
 
table.cdr td.link {
border: none;
}
 
table.stat tr:hover td {
background-color: #AAAAAA;
}
 
table.calls {
width: 300px;
}
 
table.cdr a {
color: #2B3EF5;
}
 
div.rval {
font-size: 8pt;
padding-top: 16px;
padding-bottom: 16px;
}
 
table.search tr.buttons td {
border: none;
}
 
table.search td.desc {
border: none;
}
 
table.search td.radio {
border: none;
}
 
table.search tr.buttons:hover td {
background-color: #FFFFFF;
}
 
/asterisk-stats/trunk/config.php-dist
0,0 → 1,37
<?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. #
####################################################
 
/* Do NOT touch this! */
if ( !defined('IN_ASTWEB') ) {
die("Hacking attempt");
}
 
/* Configuration settings */
 
$tpl_dir = 'templates';
$img_dir = 'images';
 
$site_title = 'Asterisk Web Interface';
$site_style = 'astweb.css';
 
$includes = 'includes';
 
$db_type = 'PGSQL';
$db_host = 'localhost';
$db_user = 'astweb';
$db_password = 'password';
$db_database = 'asterisk';
 
 
?>
/asterisk-stats/trunk/README
0,0 → 1,6
Original code from Jamie Carl (jazz@funkynerd.com)
 
Anatoli Klassen (dev@26th.net): removed some unused features, improved security, changed look-and-feel.
 
GPL license.
 
/asterisk-stats/trunk/index.php
0,0 → 1,3
<?php
header('Location: astweb.php');
?>
/asterisk-stats/trunk/cdr.php
0,0 → 1,134
<?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(!defined('IN_ASTWEB')) {
die('Hacking attempt!');
}
 
if(array_key_exists('detail', $_GET)) {
$cdr_detail = array();
$db->query_params('SELECT * FROM cdr 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];
}
$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;
}
 
# Construct Query Here
$query = "";
$params = array();
 
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 .= " 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,clid,src,dst,duration,disposition from cdr where 1=1"
. $query . " ORDER BY calldate desc" . $query_limit;
$result = $db->query_params($list_query, $params);
 
$calls_number = $db->num_rows();
$header = array();
for ($hdr=0;$hdr<$db->num_fields();$hdr++) {
array_push($header, $db->get_field_name($hdr));
}
$cdr = new Table($header);
$cdr->set_table_class('stat cdr list');
 
while ($line = $db->fetch_row()) {
$cdr->newrow();
foreach ($line as $col_value) {
$cdr->addcell(trim($col_value));
}
$cdr->addcell(array('class' => 'link', 'html' =>
display_link($PHP_SELF.'?m=cdr&detail='.$line['acctid'], 'Details')));
}
$display->add_text($cdr->build());
// summary
$sum_query = "SELECT sum(duration) as dur, sum(billsec) as bill from cdr where 1=1" . $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(Duration($line['dur']));
$cdr->newrow();
$cdr->addcell(array('tag' => 'th', 'text' => 'Bill Seconds'));
$cdr->addcell(Duration($line['bill']));
$display->add_text($cdr->build());
}
else {
$display->add_variables(array('CDR_METHOD' => 'GET', 'CDR_ACTION' => $PHP_SELF));
$display->add_template('cdr');
}
?>