This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
ds_tables.php
122 lines (88 loc) · 3.67 KB
/
ds_tables.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
<?php
//error_reporting(E_ALL);
//
// DataSources for DataTables() he! for those systems, where upgrade not possible and integrating just one page is best method!
//
if(!$_SESSION)
session_start();
if ( !isset($_SESSION['UID']) ) {
header("Location: index.php");
}
include_once('vendor/autoload.php');
include_once('include/config.php');
include_once('include/datatables.php');
Epi::init('api', 'route', 'database', 'template');
Epi::setSetting('exceptions', true);
EpiDatabase::employ('mysql', $config->ini['DB']['name'],
$config->ini['DB']['host'],
$config->ini['DB']['user'],
$config->ini['DB']['password']
) or die(' DB Employ ERROR');
$operators = $config->getExtensions( $_SESSION['tenantid'] );
$_tenant_id = (int)$_SESSION['tenantid'];
$_tenant_name = $_SESSION['tenantname'];;
// Merge Requests together //
$params_array = array_merge($_POST,$_GET);
// Explode into var names:
foreach ( $params_array as $key => $value) { ${$key} = $value; } // strymno
header('Content-Type: application/json');
// Table switcher : //
switch( $tbl ){
case 'recordings':
$json = array();
$data = array();
$fields = array(
'uniqueid' => '#ID#',
'calldate' => 'Call date',
'direction' => 'Type',
'src' => 'From',
'dst' => 'To',
'duration' => 'Duration',
'billsec' => 'Talk',
'disposition' => 'Result',
'channel' => 'Channel',
'dstchannel' => 'Channel',
'recording' => 'Recording',
'tenant_id' => 'Recording'
);
$LIMIT = $_GET['length'] ? $_GET['length'] : 100;
$OPTIONS = DataTables::getSorter($fields);
$WHERE = DataTables::getFilter($fields);
$SQL = "SELECT " . implode(',', array_keys($fields)) . " FROM t_cdrs ";
try {
$_rows = getDatabase()->all( "{$SQL} {$WHERE} {$OPTIONS}" ) ;
}catch(Exception $e) {
echo 'Exception: ' . $e->getMessage() ;
return;
}
if ( $_rows )
foreach( $_rows as $_row){
$record = null;
if( isset($_row['recording']) && file_exists( "/var/spool/asterisk/monitor/{$_row['recording']}" ) &&
filesize( "/var/spool/asterisk/monitor/{$_row['recording']}" ) > 61 ){
$record = $_row['recording'];
}
if(!$record && file_exists("/var/spool/asterisk/monitor/{$_row['uniqueid']}.WAV") &&
filesize("/var/spool/asterisk/monitor/{$_row['uniqueid']}.WAV") > 61 ){
$record = $_row['uniqueid'];
}
$_row['recording'] = ($record) ? "<div class=audio ><audio src='media/play.php?mode=cdrs&uniqueid={$_row['recording']}' preload='auto' controls></audio></div>" : '' ;
unset( $_row['tenant_id']);
//$_row['has_recording'] = $is_recorded;
$_row['dstchannel'] = DataTables::chanDescribed($_row['dstchannel'], $_row['channel'], $_tenant_id );
$_row['channel'] = DataTables::chanDescribed($_row['channel'], $_row['dstchannel'], $_tenant_id );
if( (count($data)) < $LIMIT )
$data[] = $_row;
}
else{
$data = array( 'response' => array( 'status' => 'NO DATA', 'message' => "NO ROWS! {$SQL} {$WHERE} {$OPTIONS} " ) ) ;
}
break;
}
$json = array();
$json['data'] = $data;
$json['draw'] = $_GET['draw'] ? $_GET['draw'] : 1;
$json['recordsTotal'] = count($data);
$json['recordsFiltered'] = getDatabase()->one( "SELECT count(*) AS cnt FROM t_cdrs {$WHERE}" )['cnt'] ;
echo json_encode($json);
?>