-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.php
More file actions
181 lines (164 loc) · 6.49 KB
/
index.php
File metadata and controls
181 lines (164 loc) · 6.49 KB
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
<?php
// Include configuration
require_once('config.inc.php');
// Open MySQL connection
$db = new mysqli($db_host, $db_user, $db_pass, $db_name);
if ($db->connect_errno) {
echo "Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error;
}
// What's today's date?
$today = date('Ymd');
// Is this a later page?
if ($_GET['date']) {
$pagedate = $_GET['date'];
} else {
$pagedate = $today;
}
$pagedatetime = strtotime($pagedate);
$nextdate = date('Ymd', strtotime('+1 day', $pagedatetime));
$prevdate = date('Ymd', strtotime('-1 day', $pagedatetime));
$sortkeys = array(
0 => "calldate",
"caller",
"called"
);
$sortdirs = array(
0 => "DESC",
"ASC"
);
if ($_GET['sort']) {
$sortkey = $sortkeys[$_GET['sort']];
$sortkeynum = $_GET['sort'];
} else {
$sortkey = 'calldate';
$sortkeynum = 0;
}
if ($_GET['dir']) {
$sortdir = $sortdirs[$_GET['dir']];
$sortdirnum = $_GET['dir'];
} else {
$sortdir = 'DESC';
$sortdirnum = 0;
}
if ($_GET['filter']) {
$filternum = $_GET['filter'];
switch ($_GET['filter']) {
case 0:
$filter = '';
break;
case 1:
$filter = "AND (LENGTH(caller) > $exten_len AND LENGTH(called) = $exten_len)";
break;
case 2:
$filter = "AND (LENGTH(caller) = $exten_len AND LENGTH(called) > $exten_len)";
break;
case 3:
$filter = "AND (LENGTH(caller) = $exten_len AND LENGTH(called) = $exten_len)";
break;
default:
die('Bad filter value');
}
} else {
$filternum = 0;
$filter = '';
}
// Ok let's query some data
$sql = "SELECT `ID`, `calldate`, `callend`, `duration`, `connect_duration`, `caller`, `callername`, `called`, `whohanged` FROM `cdr` WHERE `connect_duration` > 0 {$filter} AND DATE(calldate) = \"{$pagedate}\" ORDER BY `{$sortkey}` {$sortdir}";
if(!$result = $db->query($sql)){
die('There was an error running the query [' . $db->error . ']');
}
if(!$rowsult = $db->query("SELECT COUNT(*) FROM `cdr` WHERE `connect_duration` > 0 AND DATE(calldate) = \"{$pagedate}\"")){
die('There was an error running the query [' . $db->error . ']');
}
$numrowarray = $rowsult->fetch_row();
$numrows = $numrowarray[0];
$prevpage = $startcallid - $limit;
if ($prevpage < 0) {
$prevpage = 0;
}
function sec2hms ($sec, $padHours = false) {
$hms = "";
$hours = intval(intval($sec) / 3600);
$hms .= ($padHours)
? str_pad($hours, 2, "0", STR_PAD_LEFT). ':'
: $hours. ':';
$minutes = intval(($sec / 60) % 60);
$hms .= str_pad($minutes, 2, "0", STR_PAD_LEFT). ':';
$seconds = intval($sec % 60);
$hms .= str_pad($seconds, 2, "0", STR_PAD_LEFT);
return $hms;
}
function sortbuttons ($sortkey) {
echo "<a href=\"?date={$pagedate}&sort={$sortkey}&dir=0&filter={$filternum}\"><img src=\"images/arrow_up.png\" /></a>";
echo "<a href=\"?date={$pagedate}&sort={$sortkey}&dir=1&filter={$filternum}\"><img src=\"images/arrow_down.png\" /></a>";
return TRUE;
}
?>
<!doctype html>
<html lang=en>
<head>
<meta charset=utf-8>
<style type="text/css">
table {font-size:12px;color:#333333;width:100%;border-width: 1px;border-color: #a9a9a9;border-collapse: collapse;}
table th {font-size:12px;background-color:#b8b8b8;border-width: 1px;padding: 8px;border-style: solid;border-color: #a9a9a9;text-align:left;}
table tr {background-color:#ffffff;}
table td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #a9a9a9;}
</style>
<title>Call Recordings</title>
</head>
<body>
<p align="center">Filter Calls:
<?php
switch ($filternum) {
case 0:
echo "<a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=0\">ALL</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=1\">Incoming</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=2\">Outgoing</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=3\">Internal</a>";
break;
case 1:
echo "<a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=0\">All</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=1\">INCOMING</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=2\">Outgoing</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=3\">Internal</a>";
break;
case 2:
echo "<a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=0\">All</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=1\">Incoming</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=2\">OUTGOING</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=3\">Internal</a>";
break;
case 3:
echo "<a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=0\">All</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=1\">Incoming</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=2\">Outgoing</a> | <a href=\"?date={$pagedate}&sort={$sortkeynum}&dir={$sortdirnum}&filter=3\">INTERNAL</a>";
break;
}
?>
</p>
<table border="1">
<tr><th>Call Time<?php sortbuttons(0); ?></th><th>WAV</th><th>Call Duration</th><th>Caller<?php sortbuttons(1); ?></th><th>Callee<?php sortbuttons(2); ?></th><th>Terminating Party</th></tr>
<?php
while($row = $result->fetch_assoc()){
$callid = $row['ID'];
$calldate = $row['calldate'];
$calllen = sec2hms($row['connect_duration']);
$callorig = $row['caller'];
$callorigname = $row['callername'];
if ($callorigname != $callorig) {
$callcnam = "{$callorigname} ({$callorig})";
} else {
$callcnam = $callorig;
}
$callterm = $row['called'];
$callhang = $row['whohanged'];
echo "<tr><td>{$calldate}</td><td><a href=\"getwav.php?id={$callid}\"><img src=\"images/sound.png\" /></a>";
if ($_GET['p']) {
echo "<a href=\"savewav.php?id={$callid}\">s</a><a href=\"getpcap.php?id={$callid}\">P</a><a href=\"savepcap.php?id={$callid}\">S</a>";
}
echo "</td><td>{$calllen}</td><td>{$callcnam}</td><td>{$callterm}</td><td>{$callhang}</td></tr>";
}
?>
<tr><td>
<?php
if (strtotime($nextdate) <= strtotime($today)) {
echo "<a href=\"?date={$nextdate}&sort={$sortkeynum}&dir={$sortdirnum}\">Newer</a>";
} else {
echo "Newer";
}
?>
</td><td colspan="4"><?php echo "{$numrows} calls for {$pagedate}" ?></td><td>
<?php echo "<a href=\"?date={$prevdate}&sort={$sortkeynum}&dir={$sortdirnum}\">Older</a>"; ?>
</td></tr>
</table>
</body>
</html>