-
Notifications
You must be signed in to change notification settings - Fork 18
/
Vmx.class.php
314 lines (297 loc) · 11.5 KB
/
Vmx.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
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
<?php
// vim: set ai ts=4 sw=4 ft=php:
namespace FreePBX\modules\Voicemail;
#[\AllowDynamicProperties]
class Vmx {
public function __construct($freepbx = null) {
if ($freepbx == null) {
throw new \Exception("Not given a FreePBX Object");
}
$this->FreePBX = $freepbx;
$this->astman = $this->FreePBX->astman;
}
/*
* This is for Bulkhandler Header
* this this called from bulkhandlerGetHeaders
* */
public function GetHeaders() {
$headers = array(
'vmx_unavail_enabled' => array(
'description' => _('VMX Use when Unavailable "enabled" and for disable use:blocked '),
),
'vmx_busy_enabled' => array(
'description' => _('VMX Use when busy:"enabled" AND for disable this use blocked '),
),
'vmx_temp_enabled' => array(
'description' => _('VMX Use when busy:"enabled" AND for disable this use blocked '),
),
'vmx_play_instructions' => array(
'description' => _('VMX play_instructions, Use yes: no'),
),
'vmx_option_0_number' => array(
'description' => _('Leave blank for go to operator'),
),
'vmx_option_1_number' => array(
'description' => _('To send to followme use "FMextension"'),
),'vmx_option_2_number' => array(
'description' => _('Destination number'),
),
);
return $headers;
}
/*
* This is for Bulkhandler Voicemial export
* this this called from bulkhandlerExport
* */
public function vmxexport($ext) {
$vmxdata = array();
$vmxdata['vmx_unavail_enabled'] = empty($this->getState($ext,'unavail')) ? "blocked" : $this->getState($ext,'unavail');
$vmxdata['vmx_busy_enabled'] = empty($this->getState($ext,'busy')) ? "blocked" : $this->getState($ext,'busy');
$vmxdata['vmx_temp_enabled'] = empty($this->getState($ext,'temp')) ? "blocked" : $this->getState($ext,'temp');
$vmxdata['vmx_play_instructions'] = $this->getVmPlay($ext);
$vmxdata['vmx_option_0_number'] = $this->getMenuOpt($ext,0);
$vmxdata['vmx_option_1_number'] = $this->getMenuOpt($ext,1);
$vmxdata['vmx_option_2_number'] = $this->getMenuOpt($ext,2);
return $vmxdata;
}
/*This is for Bulkhandler Voicemial Import
* This is caller from bulkhandlerImport
* */
public function vmximport($data) {
$data['vmx_unavail_enabled'] = !empty($data['vmx_unavail_enabled']) ? $data['vmx_unavail_enabled'] : "blocked";
$data['vmx_busy_enabled'] = !empty($data['vmx_busy_enabled']) ? $data['vmx_busy_enabled'] : "blocked";
$data['vmx_temp_enabled'] = !empty($data['vmx_temp_enabled']) ? $data['vmx_temp_enabled'] : "blocked";
$data['vmx_play_instructions'] = !empty($data['vmx_play_instructions']) ? $data['vmx_play_instructions'] : "no";
$data['vmx_option_0_number'] = !empty($data['vmx_option_0_number']) ? $data['vmx_option_0_number'] : "";
$data['vmx_option_1_number'] = !empty($data['vmx_option_1_number']) ? $data['vmx_option_1_number'] : "";
$data['vmx_option_2_number'] = !empty($data['vmx_option_2_number']) ? $data['vmx_option_2_number'] : "";
$ext = $data['extension'];
$this->setState($ext,'unavail',$data['vmx_unavail_enabled']);
$this->setState($ext,'busy',$data['vmx_busy_enabled']);
$this->setState($ext,'temp',$data['vmx_temp_enabled']);
if ($data['vmx_play_instructions'] == 1) {
$this->setVmPlay($ext,'unavail',true);
$this->setVmPlay($ext,'busy',true);
$this->setVmPlay($ext,'temp',true);
} else {
$this->setVmPlay($ext,'unavail',false);
$this->setVmPlay($ext,'busy',false);
$this->setVmPlay($ext,'temp',false);
}
$this->setMenuOpt($ext,$data['vmx_option_0_number'],0,'unavail');
$this->setMenuOpt($ext,$data['vmx_option_0_number'],0,'busy');
$this->setMenuOpt($ext,$data['vmx_option_0_number'],0,'temp');
$this->setMenuOpt($ext,$data['vmx_option_1_number'],1,'unavail');
$this->setMenuOpt($ext,$data['vmx_option_1_number'],1,'busy');
$this->setMenuOpt($ext,$data['vmx_option_1_number'],1,'temp');
$this->setMenuOpt($ext,$data['vmx_option_2_number'],2,'unavail');
$this->setMenuOpt($ext,$data['vmx_option_2_number'],2,'busy');
$this->setMenuOpt($ext,$data['vmx_option_2_number'],2,'temp');
return ;
}
/**
* Get all VmX Settings from Extension
* @param {int} $ext Extension Number
*/
public function getSettings($ext) {
$final = array();
if($this->astman->connected()) {
$vmx = $this->astman->database_show('AMPUSER/'.$ext.'/vmx');
foreach($vmx as $family => $value) {
$family = str_replace('/AMPUSER/'.$ext.'/vmx/','',$family);
$e = explode("/",$family);
switch(count($e)) {
case 1:
$final[$e[0]] = $value;
break;
case 2:
$final[$e[0]][$e[1]] = $value;
break;
case 3:
$final[$e[0]][$e[1]][$e[2]] = $value;
break;
case 4:
$final[$e[0]][$e[1]][$e[2]][$e[3]] = $value;
break;
case 5:
$final[$e[0]][$e[1]][$e[2]][$e[3]][$e[4]] = $value;
break;
default:
break;
}
}
}
return $final;
}
/**
* Set VmX State per mode
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
* @param {string} $state="enabled" State: enabled, disabled, blocked
*/
public function setState($ext,$mode="unavail",$state="enabled") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$this->astman->database_put("AMPUSER", $ext."/vmx/".$mode."/state", "$state");
return true;
} else {
return false;
}
}
/**
* Get VmX State per mode
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function getState($ext,$mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
return trim($this->astman->database_get("AMPUSER",$ext."/vmx/$mode/state"));
} else {
return false;
}
}
/**
* Disable All VmX Modes
* @param {int} $ext Extension Number
*/
public function disable($ext) {
return $this->setState($ext,'busy','blocked') && $this->setState($ext,'unavail','blocked') && $this->setState($ext,'temp','blocked');
}
/**
* Check if VmX is initialized for this mode
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function isInitialized($ext,$mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$vmx_state=trim($this->astman->database_get("AMPUSER",$ext."/vmx/$mode/state"));
if (isset($vmx_state) && ($vmx_state == 'enabled' || $vmx_state == 'disabled') || $vmx_state == 'blocked') {
return true;
} else {
return false;
}
}
return false;
}
/**
* Check if VmX is enabled for this mode
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function isEnabled($ext,$mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$vmx_state=trim($this->astman->database_get("AMPUSER",$ext."/vmx/$mode/state"));
if (isset($vmx_state) && ($vmx_state == 'enabled' || $vmx_state == 'disabled')) {
return true;
} else {
return false;
}
}
return false;
}
/**
* Get the Voicemail Play Instructions state
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function getVmPlay($ext,$mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
return (trim($this->astman->database_get("AMPUSER",$ext."/vmx/$mode/vmxopts/timeout")) != 's');
} else {
return false;
}
}
/**
* Set the Voicemail Play Instructions state
* @param {int} $ext Extension Number
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
* @param {bool} $opts Whether to play voicemail instructions or not
*/
public function setVmPlay($ext, $mode="unavail", $opts=true) {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$val = $opts ? '' : 's';
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/vmxopts/timeout", $val);
return true;
} else {
return false;
}
}
/**
* Check if Extension has Find Me Follow Me enabled
* @param {int} $ext Extension Number
*/
public function hasFollowMe($ext) {
if ($this->astman->connected()) {
return ($this->astman->database_get("AMPUSER",$ext."/followme/ddial")) == "" ? false : true;
} else {
return false;
}
}
/**
* Check if the mode for this VmX is set to Find Me Follow Me mode
* @param {int} $ext Extension Number
* @param {int} $digit="1" The VmX Option (0-2)
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function isFollowMe($ext, $digit="1", $mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
return $this->astman->database_get("AMPUSER",$ext."/vmx/$mode/$digit/ext") == 'FM'.$ext ? true : false;
} else {
return false;
}
}
/**
* Set the Find Me Follow Me Mode for this VmX Option
* @param {int} $ext Extension Number
* @param {int} $digit="1" The VmX Option (0-2)
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
* @param {string} $context='ext-findmefollow' The Find Me Follow Me Context
* @param {int} $priority='1' The Find Me Follow Me Priority
*/
public function setFollowMe($ext, $digit="1", $mode="unavail", $context='ext-findmefollow', $priority='1') {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/ext", "FM".$ext);
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/context", $context);
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/pri", $priority);
return true;
} else {
return false;
}
}
/**
* Get VmX Menu Option Desination
* @param {int} $ext Extension Number
* @param {int} $digit="0" The VmX Menu Option
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
*/
public function getMenuOpt($ext, $digit="0", $mode="unavail") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
return trim($this->astman->database_get("AMPUSER",$ext."/vmx/$mode/$digit/ext"));
} else {
return false;
}
}
/**
* Set VmX Menu Option Desination
* @param {int} $ext Extension Number
* @param {int} $opt="" The Destination
* @param {int} $digit="0" The VmX Option (0-2)
* @param {string} $mode="unavail" The mode, can be: unavail, busy, temp
* @param {string} $context='from-internal' The Find Me Follow Me Context
* @param {int} $priority='1' The Find Me Follow Me Priority
*/
public function setMenuOpt($ext,$opt="", $digit="0", $mode="unavail", $context="from-internal", $priority="1") {
if ($this->astman->connected() && ($mode == "unavail" || $mode == "busy" || $mode == "temp")) {
$opt = preg_replace("/[^0-9]\*#/" ,"", $opt);
if ($opt != "") {
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/ext", $opt);
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/context", $context);
$this->astman->database_put("AMPUSER", $ext."/vmx/$mode/$digit/pri", $priority);
} else {
$this->astman->database_deltree("AMPUSER/".$ext."/vmx/$mode/$digit");
}
return true;
} else {
return false;
}
}
}