-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxmlbrowser.php
405 lines (365 loc) · 12.5 KB
/
xmlbrowser.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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
<?php
/*
* Project Name: FusionBells for FusionPBX
*
* Description: Multicast Bell Notification for
* education environments. Uses FFMPEG for transcoding
* and network delivery.
*
* Requirements: FusionPBX, SQLite and Multicast network
* configuration.
*
* Developer: FikesMedia.com
* Contact: [email protected]
* Copyright: Copyright 2017 FikesMedia All Right Reserved
*/
//Yealink XML Browser Plugin
/*
* Plays desired tone from the dashboard
*
* Christopher Fikes
* 03/03/2017
*/
function manualBell($UUID,$TONE) {
try {
//Connect to DB
$fusionBellDB = new PDO("sqlite:$UUID.db");
//Set ring type from POST
switch ($TONE) {
case 'Normal' :
$toneType = "\"Bell Tone\"";
break;
case 'FireDrill' :
$toneType = "\"Fire Drill Tone\"";
break;
case 'WeatherDrill' :
$toneType = "\"Weather Drill Tone\"";
break;
case 'Silence' :
$toneType = "Silence";
break;
default :
$toneType = "\"Bell Tone\"";
break;
}
if ($toneType !="Silence") {
//Query WAV file used for specified tone
$Result = $fusionBellDB->query("SELECT SettingValue FROM settings WHERE SettingName = $toneType LIMIT 1;");
//Set value is any return given
if(count($Result,0) != 0) {
foreach($Result as $row){
$tone = $row['SettingValue'];
}
}
} else { $tone = "Silence.wav"; }
//Query if this is the ZoneBOX
$ActingZoneBox = $fusionBellDB->prepare('SELECT SettingValue FROM settings WHERE SettingName = ? LIMIT 1');
$ActingZoneBox->execute(array("Acting ZoneBOX"));
//Set value is any return given
foreach ($ActingZoneBox as $row) {
$Setting = $row['SettingValue'];
}
//I am the ZoneBox
if ($Setting == "Disabled") {
sendManualBell($tone);
}
//This is the ZoneBox
elseif ($Setting == "Enabled") {
//Query Multicast address to use
$Result = $fusionBellDB->query("SELECT ZoneValue FROM zones WHERE ZoneName = 'All Tone' LIMIT 1;");
//Set value is any return given
if(count($Result,0) != 0) {
foreach($Result as $row){
$address = $row['ZoneValue'];
}
}
//Call System command with specified parameters
$exec="./ffmpeg -re -i ./tones/$tone -filter_complex 'aresample=16000,asetnsamples=n=160' -acodec g722 -ac 1 -vn -f rtp udp://$address &";
exec($exec);
}
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextScreen Timeout="5" LockIn="no" Beep="no" ><Title wrap="yes">Fusion Bells</Title><Text>Completed Action</Text></YealinkIPPhoneTextScreen>';
}
//Issues connecting
catch (PDOException $e) {
}
}//End manualBell Function
/*
* Get bell schedule for specified getSchedules
* and return as formated JSON
*
* Christopher Fikes
* 05/04/2017
*/
function getSchedule($UUID,$SCHEDULE) {
$schedule = $SCHEDULE;
//Error if Null or blank and send back error message
if(is_null($schedule) || $schedule == ""){
$returnValue = ['error' => 'no values input for GET Schedule'];
header('Content-Type: application/json');
echo json_encode($returnValue);
} else {
try {
//Connect to DB
$fusionBellDB = new PDO("sqlite:$UUID.db");
//Query for specified schedule
$Result = $fusionBellDB->prepare('SELECT Time,Tone,Zone FROM schedules WHERE Schedule = ? ORDER BY Time');
$Result->execute(array($schedule));
//If any results continue
if(count($Result,0) != 0) {
//Array
$returnJSON = array();
//Setup Counter
$i = 0;
//For each returned result append array
foreach($Result as $row){
$Text = $row['Time'] . " " . substr($row['Tone'],0,-4) . " " . $row['Zone'];
array_push($returnJSON, $Text);
$i++;
}
//Return array as formated JSON
header('Content-Type: application/json');
return $returnJSON;
}//End if any results continue
} //End Try
//Issues connecting
catch (PDOException $e) {
//Set JSON Message with Error Text
$returnValue = [ "msg" => "error", "error" => $e->getMessage() ];
header('Content-Type: application/json');
echo json_encode($returnValue);
} //End capture errors
} //End Else no Errors
} //End getSchedule function
/*
* Get Zones and return as formated JSON
*
* Christopher Fikes
* 05/10/2017
*/
function getZones($UUID) {
try {
//Connect to DB
$fusionBellDB = new PDO("sqlite:$UUID.db");
//Query for specified schedule
$Result = $fusionBellDB->prepare('SELECT distinct ZoneName,ZoneValue FROM zones ORDER BY ZoneName');
$Result->execute();
//If any results continue
if(count($Result,0) != 0) {
//Array
$returnJSON = array();
//Setup Counter
$i = 0;
//For each returned result append array
foreach($Result as $row){
$Text = $row['ZoneName'] . " " . $row['ZoneValue'];
array_push($returnJSON, $Text);
$i++;
}
//Return array as formated JSON
header('Content-Type: application/json');
return $returnJSON;
}//End if any results continue
} //End Try
//Issues connecting
catch (PDOException $e) {
//Set JSON Message with Error Text
$returnValue = [ "msg" => "error", "error" => $e->getMessage() ];
header('Content-Type: application/json');
echo json_encode($returnValue);
} //End capture errors
} //End getZones function
/*
* Gets the next bell ring for today.
*
* Christopher Fikes
* 03/06/2017
*/
function getNextRing($UUID) {
$dateNow = date("Y-m-d");
$timeNow = date("H:i");
try {
//Connect to DB
$fusionBellDB = new PDO("sqlite:$UUID.db");
//Select cout of schedules on this day
$Special = $fusionBellDB->prepare("SELECT count(*) FROM calendar WHERE Date = ?");
$Special->execute(array($dateNow));
$Count = $Special->fetchColumn();
//If result found, today has a specified schedule
if($Count != 0) {
//Get Schedule name for today
$Special01 = $fusionBellDB->prepare("SELECT Schedule FROM calendar WHERE Date = ? LIMIT 1");
$Special01->execute(array($dateNow));
while ($row = $Special01->fetch(PDO::FETCH_ASSOC)) {
$Schedule = $row['Schedule'];
//Check to see if there are any more bells in thes schedule for today
$Special02 = $fusionBellDB->prepare("SELECT count(*) FROM schedules WHERE Schedule = ? AND Time > ?");
$Special02->execute(array($Schedule,$timeNow));
$Count = $Special02->fetchColumn();
//If results found, schedule has bells left
if($Count != 0) {
$Special03 = $fusionBellDB->prepare("SELECT * FROM schedules WHERE Schedule = ? AND Time > ? ORDER BY Time LIMIT 1");
$Special03->execute(array($Schedule,$timeNow));
while ($row = $Special03->fetch(PDO::FETCH_ASSOC)) {
$Schedule = $row['Schedule'];
$Tone = $row['Tone'];
$Time = $row['Time'];
$returnJSON=array("Schedule"=>$Schedule,"Time"=>$Time);
}
}
//Else Schedule has played out.
else {
$returnJSON=array("Schedule"=>$Schedule,"Time"=>"Schedule Finished");
}
}
}
//Today has no schedules set using default
else {
$Default01 = $fusionBellDB->prepare("SELECT SettingValue FROM settings WHERE SettingName = ? ");
$Default01->execute(array("Default Schedule"));
while ($row = $Default01->fetch(PDO::FETCH_ASSOC)) {
$Schedule = $row['SettingValue'];
//Check to see if there are any more bells in thes schedule for today
$Default02 = $fusionBellDB->prepare("SELECT count(*) FROM schedules WHERE Schedule = ? AND Time > ?");
$Default02->execute(array($Schedule,$timeNow));
$Count = $Default02->fetchColumn();
//If results found, schedule has bells left
if($Count != 0) {
$Special03 = $fusionBellDB->prepare("SELECT * FROM schedules WHERE Schedule = ? AND Time > ? ORDER BY Time LIMIT 1");
$Special03->execute(array($Schedule,$timeNow));
while ($row = $Special03->fetch(PDO::FETCH_ASSOC)) {
$Schedule = $row['Schedule'];
$Tone = $row['Tone'];
$Time = $row['Time'];
$returnJSON=array("Schedule"=>$Schedule,"Time"=>$Time);
}
}
//Else Schedule has played out.
else {
$returnJSON=array("Schedule"=>$Schedule,"Time"=>"Schedule Finished");
}
}
}
//header('Content-Type: application/json');
return $returnJSON;
}
//Issues connecting
catch (PDOException $e) {
//Print Error Message
print 'Exception : ' . $e->getMessage();
}
}//End getNextRing Function
function sendManualMenu($UUID){
$SERVER = $_SERVER['SERVER_ADDR'];
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextMenu style="numbered" Beep="no" WrapList="yes" Timeout="30" LockIn="yes">';
echo '<Title Warp="yes">Manual Bell Control</Title>';
echo '<MenuItem>';
echo '<Prompt> Normal Bell</Prompt>';
echo '<URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=manual&tone=Normal&uuid='.$UUID.'</URI>';
echo '</MenuItem>';
echo '<MenuItem>';
echo '<Prompt> Fire Drill</Prompt>';
echo '<URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=manual&tone=FireDrill&uuid='.$UUID.'</URI>';
echo '</MenuItem>';
echo '<MenuItem>';
echo '<Prompt> Weather Drill</Prompt>';
echo '<URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=manual&tone=WeatherDrill&uuid='.$UUID.'</URI>';
echo '</MenuItem>';
echo '<MenuItem>';
echo '<Prompt> Silent Tone Diagnostics</Prompt>';
echo '<URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=manual&tone=Silence&uuid='.$UUID.'</URI>';
echo '</MenuItem>';
echo '</YealinkIPPhoneTextMenu>';
}
function devTest($UUID) {
/*
$Dev01 = getNextRing($UUID);
echo $Dev01['Schedule'];
echo $Dev01['Time'];
echo "<br>";
$Schedule = getSchedule($UUID,$Dev01['Schedule']);
echo "Count of Array " . count($Schedule) . "<br>";
print_r($Schedule);
*/
sendSchedule($UUID);
}
function sendSchedule($UUID){
$active = getNextRing($UUID);
$scheduleName = $active['Schedule'];
$nextRing = $active['Time'];
$schedule = getSchedule($UUID,$scheduleName);
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextMenu style="none" Timeout="15" LockIn="no" Beep="no">';
echo '<Title Warp="yes">'. $scheduleName .'</Title>';
echo '<SoftKey index = "1"><Label>Exit</Label><URI>SoftKey:Exit</URI></SoftKey>';
$n = 0;
$count = count($schedule);
while ($n < $count) {
echo '<MenuItem><Prompt>' . $schedule[$n] . '</Prompt><URI></URI></MenuItem>';
$n++;
}
echo '</YealinkIPPhoneTextMenu>';
}
function sendZones($UUID){
$zones = getZones($UUID);
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextMenu style="none" Timeout="15" LockIn="no" Beep="no">';
echo '<Title Warp="yes">Available Zones</Title>';
echo '<SoftKey index = "1"><Label>Exit</Label><URI>SoftKey:Exit</URI></SoftKey>';
$n = 0;
$count = count($zones);
while ($n < $count) {
echo '<MenuItem><Prompt>' . $zones[$n] . '</Prompt><URI></URI></MenuItem>';
$n++;
}
echo '</YealinkIPPhoneTextMenu>';
}
function sendYealinkError() {
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextScreen Timeout="15" LockIn="no" Beep="no"><Title wrap="yes">Fusion Bells </Title><Text> ERROR PLEASE SEE ADMINISTRATOR </Text>';
echo '</YealinkIPPhoneTextScreen >';
}
function sendYealinkMenu($UUID) {
$SERVER = $_SERVER['SERVER_ADDR'];
header('Content-Type: text/xml');
echo '<YealinkIPPhoneTextScreen Timeout="15" LockIn="no" Beep="no"><Title wrap="yes">Fusion Bells </Title><Text> Developed by FikesMedia Powered by FusionPBX</Text>';
echo '<SoftKey index = "1"><Label>Exit</Label><URI>SoftKey:Exit</URI></SoftKey>';
echo '<SoftKey index = "2"><Label>Schedule</Label><URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=schedule&uuid='. $UUID . '</URI></SoftKey>';
echo '<SoftKey index = "3"><Label>Zones</Label><URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=zones&uuid='. $UUID . '</URI></SoftKey>';
echo '<SoftKey index = "4"><Label>Manual</Label><URI>https://'.$SERVER.'/app/fusionbells/xmlbrowser.php?app=manualmenu&uuid='. $UUID . '</URI></SoftKey>';
echo '</YealinkIPPhoneTextScreen >';
}
/*
* MAIN
* Get Variables from submission and route data
*
*/
$UUID = $_GET['uuid'];
$APP = $_GET['app'];
$TONE = $_GET['tone'];
if (!empty($UUID)) {
switch($APP) {
case 'manual' :
manualBell($UUID,$TONE);
//echo "VALUES $TONE $UUID";
break;
case 'manualmenu' :
sendManualMenu($UUID);
break;
case 'dev' :
devTest($UUID);
break;
case 'schedule' :
sendSchedule($UUID);
break;
case 'zones' :
sendZones($UUID);
break;
default :
sendYealinkMenu($UUID);
break;
}
} else {
sendYealinkError();
}