-
Notifications
You must be signed in to change notification settings - Fork 11
/
Callrecording.class.php
233 lines (215 loc) · 7.61 KB
/
Callrecording.class.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
<?php
namespace FreePBX\modules;
use FreePBX_Helpers;
use BMO;
use PDO;
class Callrecording extends FreePBX_Helpers implements BMO {
public function __construct($freepbx = null) {
if ($freepbx == null) {
throw new Exception("Not given a FreePBX Object");
}
$this->FreePBX = $freepbx;
$this->db = $freepbx->Database;
}
public function install() {}
public function uninstall() {}
public static function myConfigPageInits() {
return ["routing"];
}
public function doConfigPageInit($page) {
$request = $_REQUEST;
if($page == "callrecording"){
$type = $this->getReq('type','setup');
$action = $this->getReq('action','');
if($this->getReq('delete', false)){
$action = 'delete';
}
$callrecording_id = $this->getReq('callrecording_id',false);
$description = $this->getReq('description','');
$callrecording_mode = $this->getReq('callrecording_mode','');
$dest = $this->getReq('dest','');
if (isset($request['goto0']) && $request['goto0']) {
$dest = $request[ $request['goto0'].'0' ];
}
if('add' == $action){
$this->add($description, $callrecording_mode, $dest);
}
if('edit' == $action){
$this->edit($callrecording_id, $description, $callrecording_mode, $dest);
}
if('delete' == $action){
$this->delete($callrecording_id);
}
if(!empty($action)){
needreload();
}
}
if($page == "routing"){
$viewing_itemid = $request['id'] ?? '';
$action = $request['action'] ?? null;
$route_id = $viewing_itemid;
if (isset($request['Submit']) ) {
$action ??= 'editroute';
}
if ($action){
callrecording_adjustroute($route_id,$action,$request['callrecording'] ?? '');
}
}
}
public function getRecording($id){
$sql = "SELECT callrecording_id, description, callrecording_mode, dest FROM callrecording WHERE callrecording_id = :callrecording_id";
$stmt = $this->db->prepare($sql);
$stmt->execute(['callrecording_id' => $id]);
return $stmt->fetch(PDO::FETCH_ASSOC);
}
public function listAll(){
$sql = "SELECT callrecording_id, description, callrecording_mode, dest FROM callrecording ORDER BY description ";
return $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
public function add($description, $callrecording_mode, $dest){
$sql = "SELECT * FROM callrecording WHERE description = :description";
$stm = $this->db->prepare($sql);
$stm->execute([":description" => $description]);
$ret = $stm->fetch(\PDO::FETCH_ASSOC);
if(empty($ret["description"])){
$sql = "INSERT INTO callrecording (description, callrecording_mode, dest) VALUES (:description, :mode, :dest)";
$stmt = $this->db->prepare($sql);
$stmt->execute([
':description' => $description,
':mode' => $callrecording_mode,
':dest' => $dest,
]);
return $this->db->lastInsertId();
}
return;
}
public function upsert($id,$description, $callrecording_mode, $dest){
$sql = "INSERT INTO callrecording (callrecording_id, description, callrecording_mode, dest) VALUES (:id, :description, :mode, :dest)";
$sql .= " ON DUPLICATE KEY UPDATE description = VALUES(description), callrecording_mode= VALUES(callrecording_mode), dest= VALUES(dest)";
$stmt = $this->db->prepare($sql);
return $stmt->execute([
':id' => $id,
':description' => $description,
':mode' => $callrecording_mode,
':dest' => $dest,
]);
}
public function edit($callrecording_id, $description, $callrecording_mode, $dest){
$sql = "UPDATE callrecording SET description = :description, callrecording_mode = :mode, dest = :dest WHERE callrecording_id = :id";
$stmt = $this->db->prepare($sql);
return $stmt->execute([
':description' => $description,
':mode' => $callrecording_mode,
':dest' => $dest,
':id' => $callrecording_id,
]);
}
public function delete($id){
$sql = "DELETE FROM callrecording WHERE callrecording_id = :callrecording_id";
$stmt = $this->db->prepare($sql);
return $stmt->execute(['callrecording_id' => $id]);
}
public function dumpExtensions(){
$sql = "SELECT * FROM callrecording_module";
return $this->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
}
public function insertExtensionData($extension, $cidnum, $callrecording, $display){
$sql = "INSERT INTO callrecording_module (extension, cidnum, callrecording, display) VALUES (:extension, :cidnum, :callrecording, :display)";
$stmt = $this->db->prepare($sql);
return $stmt->execute([
':extension' => $extension,
':cidnum' => $cidnum,
':callrecording' => $callrecording,
':display' => $display,
]);
}
public function getActionBar($request) {
$buttons = [];
$buttons = [];
switch($request['display']) {
case 'callrecording':
$buttons = ['delete' => ['name' => 'delete', 'id' => 'delete', 'value' => _('Delete')], 'reset' => ['name' => 'reset', 'id' => 'reset', 'value' => _('Reset')], 'submit' => ['name' => 'submit', 'id' => 'submit', 'value' => _('Submit')]];
if (empty($request['extdisplay'])) {
unset($buttons['delete']);
}
if($request['view'] != 'form'){
unset($buttons);
}
break;
}
return $buttons;
}
public function getRightNav($request){
if($request['view']=='form'){
return load_view(__DIR__."/views/bootnav.php",['request' => $request]);
}
}
public function listRules(){
$sql = "SELECT callrecording_id, description, callrecording_mode, dest FROM callrecording ORDER BY description ";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$results = $stmt->fetchall(\PDO::FETCH_ASSOC);
return $results;
}
public function getallRules($id=""){
$sql = "SELECT callrecording_id,description FROM callrecording ORDER BY description ";
$stmt = $this->db->prepare($sql);
$stmt->execute();
$results = $stmt->fetchall(\PDO::FETCH_ASSOC);
$res = [];
if(is_array($results)) {
foreach($results as $r) {
if($r['callrecording_id'] != $id) {
$res[] = $r['description'];
}
}
}
return $res;
}
public function ajaxRequest($req, &$setting) {
return ('getJSON' == $req);
}
public function ajaxHandler(){
if($_REQUEST['command'] == 'getJSON' && $_REQUEST['jdata'] == 'grid'){
return array_values($this->listAll());
}
return [];
}
public function search($query, &$results) {
$rules = $this->listAll();
foreach ($rules as $rule) {
$results[] = ["text" => sprintf(_("Call Recording: %s"),$rule['description']), "type" => "get", "dest" => "?display=callrecording&view=form&extdisplay=".$rule['callrecording_id']];
}
}
public function bulkhandlerExport($type) {
$data = NULL;
switch ($type) {
case "dids":
$dids = $this->FreePBX->Core->getAllDIDs();
$data = [];
$this->FreePBX->Modules->loadFunctionsInc("callrecording");
foreach($dids as $did) {
$key = $did['extension']."/".$did["cidnum"];
$call_rec = callrecording_display_get('did', $did['extension'], $did["cidnum"]);
if(!empty($call_rec)) {
$data[$key] = ["callrecording" => (isset($call_rec[0]) && isset($call_rec[0]['callrecording'])) ? $call_rec[0]['callrecording'] : 'dontcare'];
} else {
$data[$key] = ["callrecording" => 'dontcare'];
}
}
break;
}
return $data;
}
public function bulkhandlerImport($type, $rawData, $replaceExisting = false) {
switch ($type) {
case 'dids':
$this->FreePBX->Modules->loadFunctionsInc("callrecording");
foreach ($rawData as $data) {
$data['callrecording'] ??= 'dontcare';
callrecording_display_update('did', $data['callrecording'], $data['extension'], $data["cidnum"]);
}
break;
}
}
}