forked from libyerman/queue-stats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanswered_cdr.php
executable file
·243 lines (224 loc) · 10.5 KB
/
answered_cdr.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
<?php
/*
Copyright 2017, https://asterisk-pbx.ru
This file is part of Asterisk Call Center Stats.
Asterisk Call Center Stats is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
Asterisk Call Center Stats is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Asterisk Call Center Stats. If not, see
<http://www.gnu.org/licenses/>.
*/
require_once("config.php");
include("sesvars.php");
//ini_set('display_errors',1);
//error_reporting(E_WARNING);
?>
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Asterisk Call Center Stats</title>
<style type="text/css" media="screen">@import "css/basic.css";</style>
<style type="text/css" media="screen">@import "css/tab.css";</style>
<style type="text/css" media="screen">@import "css/table.css";</style>
<style type="text/css" media="screen">@import "css/fixed-all.css";</style>
<script type="text/javascript" src="js/sorttable.js"></script>
<?php include 'header.php'; ?>
</head>
<?php
if(isset($_POST['pagerows'])) {
$page_rows = $_POST['pagerows'];
$_SESSION['QSTATS']['pagerows']=$page_rows;
} else {
$_SESSION['QSTATS']['pagerows'] = 100;
}
if ( (isset($_POST['callerid_search'])) && (strlen($_POST['callerid_search']) > 0) ) {
$callerid_search = $_POST['callerid_search'];
$sql = "select distinct(callid) from $DBTable where time >= '$start' AND time <= '$end' and data2 like '%$callerid_search%'";
$restemp = mysqli_query($connection, $sql);
foreach($restemp as $temp){
$callid_search .= ",'".$temp['callid']."'";
}
$callid_search = substr($callid_search, 1);
$sql = "select b.time as time, a.time as atime, a.callid as callid, a.queuename as queuename, a.agent as agent, a.event as event, a.data1 as data1, a.data2 as data2, a.data3 as data3, a.data as data4, a.data5 as data5, b.data2 as callerid
from $DBTable as a LEFT JOIN $DBTable as b
on a.callid=b.callid and b.event='ENTERQUEUE'
where b.time >= '$start' AND b.time <= '$end'
and a.event in ('TRANSFER','BLINDTRANSFER','ATTENDEDTRANSFER','COMPLETECALLER','COMPLETEAGENT')
and a.callid in ($callid_search) order by a.callid";
$rescomplete = mysqli_query($connection, $sql);
} elseif ( (isset($_POST['outagent'])) && (strlen($_POST['outagent']) > 0) ) {
$outagent = $_POST['outagent'];
$sql = "select b.time as time, a.time as atime, a.callid as callid, a.queuename as queuename, a.agent as agent, a.event as event, a.data1 as data1, a.data2 as data2, a.data3 as data3, a.data as data4, a.data5 as data5, b.data2 as callerid
from $DBTable as a LEFT JOIN $DBTable as b
on a.callid=b.callid and b.event='ENTERQUEUE'
where b.time >= '$start' AND b.time <= '$end'
and a.event in ('TRANSFER','BLINDTRANSFER','ATTENDEDTRANSFER','COMPLETECALLER','COMPLETEAGENT')
and a.agent in ('$outagent','NONE') order by a.callid";
$rescomplete = mysqli_query($connection, $sql);
} else {
$sql = "select b.time as time, a.time as atime, a.callid as callid, a.queuename as queuename, a.agent as agent, a.event as event, a.data1 as data1, a.data2 as data2, a.data3 as data3, a.data as data4, a.data5 as data5, b.data2 as callerid
from $DBTable as a LEFT JOIN $DBTable as b
on a.callid=b.callid and b.event='ENTERQUEUE'
where b.time >= '$start' AND b.time <= '$end'
AND a.agent IN ($agent , 'NONE')
and a.queuename in ($queue)
and a.event in ('TRANSFER','BLINDTRANSFER','ATTENDEDTRANSFER','COMPLETECALLER','COMPLETEAGENT')
order by a.callid, time limit $page_rows";
$rescomplete = mysqli_query($connection, $sql);
}
mysqli_close($connection);
$start_parts = explode(" ,:", $start);
$end_parts = explode(" ,:", $end);
?>
<body>
<?php include("menu.php"); ?>
<div id="main">
<div id="contents">
<TABLE width='90%' border=0 cellpadding=0 cellspacing=0>
<CAPTION><?php echo $lang["$language"]['report_info']?></CAPTION>
<TBODY>
<TR>
<TD><?php echo $lang["$language"]['queue']?>:</TD>
<TD><?php echo $queue?></TD>
</TR>
</TR>
<TD><?php echo $lang["$language"]['start']?>:</TD>
<TD><?php echo $start_parts[0]?></TD>
</TR>
</TR>
<TR>
<TD><?php echo $lang["$language"]['end']?>:</TD>
<TD><?php echo $end_parts[0]?></TD>
</TR>
<TR>
<TD><?php echo $lang["$language"]['period']?>:</TD>
<TD><?php echo $period?> <?php echo $lang["$language"]['days']?></TD>
</TR>
</TBODY>
</TABLE>
<br />
<div id="search" align="left">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" id="frm1" name="frm1" method="post">
<b><?php echo $lang["$language"]['callerid']?>:</b> <input type="text" id="callerid_search" name="callerid_search" />
<b><?php echo $lang["$language"]['agent'];?>:</b> <input type="text" id="outagent" name="outagent"/>
<button type="submit" name="submit"><?php echo $lang["$language"]['search'];?></button>
</form>
</div>
<div id="rows" align="right">
<form action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?>" id="frm2" name="frm2" method="post">
<b><?php echo $lang["$language"]['page_rows'];?></b>
<select onchange="this.form.submit()" id="pagerows" name="pagerows">
<option selected="<?php echo $_SESSION['QSTATS']['pagerows'];?>"><?php echo $_SESSION['QSTATS']['pagerows'] / 2;?></option>
<option value="100">500</option>
<option value="200">100</option>
<option value="1000">500</option>
<option value="2000">1000</option>
<option value="20000">10000</option>
</select>
</form>
</div>
<br />
<a name='5'></a>
<h3> <?php echo $lang["$language"]['answered_calls']?></h3>
<br />
<table width='90%' cellpadding=1 cellspacing=1 border=0 class='sortable' id='5' >
<TR>
<TH><?php echo $lang["$language"]['date']?></TH>
<TH><?php echo $lang["$language"]['callerid']?></TH>
<TH><?php echo $lang["$language"]['queue']?></TH>
<TH><?php echo $lang["$language"]['agent']?></TH>
<TH><?php echo $lang["$language"]['disconnect_cause']?></TH>
<TH><?php echo $lang["$language"]['holdtime']?></TH>
<TH><?php echo $lang["$language"]['calltime']?></TH>
<TH><?php echo $lang["$language"]['uniqueid']?></TH>
<TH><?php echo $lang["$language"]['recordfile']?></TH>
</TR>
<?php
$header_pdf=array($lang["$language"]['time'],$lang["$language"]['callerid'], $lang["$language"]['queue'],$lang["$language"]['agent'],$lang["$language"]['event'],$lang["$language"]['holdtime'],$lang["$language"]['calltime']);
$width_pdf=array(25,23,23,23,23,25,25,20);
$title_pdf=$lang["$language"]['answered_calls'];
$data_pdf = array();
foreach($rescomplete as $row) {
$event = $row['event'];
$callerid = $row['callerid'];
switch($event) {
case "TRANSFER":
$holdtime = seconds2minutes($row['data3']);
$calltime = seconds2minutes( strtotime($row['atime']) - (strtotime($row['time']) + $row['data3']));
$time = strtotime($row['time']);
break;
case "BLINDTRANSFER":
$holdtime = seconds2minutes(intval($row['data3']));
$calltime = seconds2minutes( strtotime($row['atime']) - (strtotime($row['time']) + $row['data3']));
$time = strtotime($row['time']);
break;
case "ATTENDEDTRANSFER":
$holdtime = seconds2minutes($row['data3']);
$calltime = seconds2minutes( strtotime($row['atime']) - (strtotime($row['time']) + $row['data3']));
$time = strtotime($row['time']);
break;
case "COMPLETEAGENT":
$holdtime = seconds2minutes($row['data1']);
$calltime = seconds2minutes($row['data2']);
$time = strtotime($row['time']);
break;
case "COMPLETECALLER":
$holdtime = seconds2minutes($row['data1']);
$calltime = seconds2minutes($row['data2']);
$time = strtotime($row['time']);
break;
}
if ( ($row['event'] == "BLINDTRANSFER") || ($row['event'] == "TRANSFER") || ($row['event'] == "ATTENDEDTRANSFER") ) {
$cause_hangup=$lang["$language"]['transferto']." ".$row['data1'] ;
}
if ($row['event']=="COMPLETEAGENT") {
$cause_hangup=$lang["$language"]['agent_hungup'] ;
} elseif ($row['event']=="COMPLETECALLER") {
$cause_hangup=$lang["$language"]['caller_hungup'];
}
if ( ($row['event'] == "COMPLETEAGENT") || ($row['event'] == "COMPLETECALLER") || ($row['event'] == "BLINDTRANSFER") || ($row['event'] == "TRANSFER") || ($row['event'] == "ATTENDEDTRANSFER")) {
$page_rows2 += count($row['event']);
$tmpError = $row['callid'] ;
$tmpRec = '<audio controls preload="none">
<source src="dl.php?f=[_file]">
</audio>
<a href="dl.php?f=[_file]">' . $row['callid'] . '</a>';
$rec['filename'] = $row['callid'] . '.mp3';
$rec['path'] = '/home/asterisk/monitor/mp3/'.$rec['filename'];
if (file_exists($rec['path']) && preg_match('/(.*)\.mp3$/i', $rec['filename'])) {
$tmpRes = str_replace('[_file]', base64_encode($rec['filename']), $tmpRec);
} else {
$tmpRes = $tmpError;
}
echo "<TR><TD>" . date('Y-m-d H:i:s', $time) . "</TD>
<TD>" . $callerid . "</TD>
<TD>" . $row['queuename'] . "</TD>
<TD>" . $row['agent'] . "</TD>
<TD>" . $cause_hangup . "</TD>
<TD>" . $holdtime . "</TD>
<TD>" . $calltime . "</TD>
<TD>" . $tmpRes. "</TD>
</TR>\n";
$linea_pdf = array($time,$callerid,$row['queuename'],$row['agent'],$cause_hangup,$holdtime,$calltime);
$data_pdf[]=$linea_pdf;
}
}
mysqli_free_result($rescomplete);
print_exports($header_pdf,$data_pdf,$width_pdf,$title_pdf,$cover_pdf);
?>
</table>
<?php
print_exports($header_pdf,$data_pdf,$width_pdf,$title_pdf,$cover_pdf);
?>
<br/>
</div>
</div>
</body>
<?php include 'footer.php'; ?>
</html>