-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfunctions.inc.php
296 lines (275 loc) · 8.17 KB
/
functions.inc.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
<?php
// This file is part of FreePBX.
//
// FreePBX is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// FreePBX is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with FreePBX. If not, see <http://www.gnu.org/licenses/>.
//
// Copyright (C) 2006 Rob Thomas
function check_schema_device () {
$schema = simplexml_load_file(dirname(dirname(__FILE__)) . "/sccp/sccp.xml");
$eldevice = $schema->xpath("section[@name='device']/params/param");
$results = sql ("SHOW COLUMNS FROM sccpdevice;","getAll",DB_FETCHMODE_ASSOC);
foreach ($eldevice as $value){
$atts_array = (array)$value->attributes();
$name = $atts_array["@attributes"]["name"];
$required = $value->required;
$type = $value->type;
$size = $value->size;
$description = $value->description;
$default = $value->default;
$generic_parser = $value->generic_parser;
$match = false;
foreach ($results as $result){
if (strtolower($name) == strtolower($result["Field"])){
$match = true;
}
}
if (!$match){
//print_r($value);
}
}
}
function check_schema_line () {
$schema = simplexml_load_file("./admin/modules/sccp/sccp.xml");
$eldevice = $schema->xpath("section[@name='line']/params/param");
foreach ($eldevice as $value){
$atts_array = (array)$value->attributes();
$name = $atts_array["@attributes"]["name"];
$required = $value->required;
$type = $value->type;
$size = $value->size;
$description = $value->description;
$default = $value->default;
$generic_parser = $value->generic_parser;
$results = sql ("SHOW COLUMNS FROM SCCPDEVICE;");
}
}
function sccp_devices_list($getall=false) {
$results = sql("SELECT * FROM sccpdevice order by description,name asc","getAll",DB_FETCHMODE_ASSOC);
if(is_array($results)){
foreach($results as $result){
// check to see if we have a dept match for the current AMP User.
// return this item's dialplan destination, and the description
$allowed[] = $result;
}
}
if (isset($allowed)) {
return $allowed;
} else {
return null;
}
}
function sccp_lines_list($getall=false) {
$results = sql("SELECT * FROM sccpline order by name asc","getAll",DB_FETCHMODE_ASSOC);
if(is_array($results)){
foreach($results as $result){
// check to see if we have a dept match for the current AMP User.
// return this item's dialplan destination, and the description
$allowed[] = $result;
}
}
if (isset($allowed)) {
return $allowed;
} else {
return null;
}
}
function sccp_delete_device($device){
sql ("delete from sccpdevice where name='" . $device . "'") ;
}
function sccp_update_device($vars){
if (strlen($vars["name"])>1){
$query = "UPDATE sccpdevice SET ";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
$query .= $key ."=";
if (trim($value)==""){
$query .= "null";
}elseif (substr($value,0,2)=="0x" ){
$query .= "0x" . bin2hex($value);
}elseif (is_numeric($value)){
$query .= "'". trim($value) . "'";
}else{
$query .= "0x" . bin2hex($value);
}
}
$query .= " WHERE name='" . $vars["name"] . "'";
sql($query);
echo $query;
}else{die ("error!!!");};
}
function sccp_delete_line($line){
sql ("delete from sccpline where name='" . $line . "'") ;
}
function sccp_update_line($vars){
if (strlen($vars["name"])>1){
$query = "UPDATE sccpline SET ";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
$query .= $key ."=";
if (trim($value)==""){
$query .= "null";
}elseif (substr($value,0,2)=="0x" ){
$query .= "0x" . bin2hex($value);
}elseif (is_numeric($value)){
$query .= "'". trim($value) . "'";
}else{
$query .= "0x" . bin2hex($value);
}
}
$query .= " WHERE name='" . $vars["name"] . "'";
sql($query);
echo $query;
}else{die ("error!!!");};
}
function sccp_add_device($vars){
$query = "insert into sccpdevice (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
$query .= $key;
}
$query .= ") VALUES (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
if (trim($value)==""){
$query .= "null";
}elseif (substr($value,0,2)=="0x" ){
$query .= "0x" . bin2hex($value);
}elseif (is_numeric($value)){
$query .= "'". trim($value) . "'";
}else{
$query .= "0x" . bin2hex($value);
}
}
$query .= ")";
sql($query);
try {
if (file_exists("/tftpboot/SEPD" .$vars["type"]. ".cnf.xml")){
copy ("/tftpboot/SEPD" .$vars["type"]. ".cnf.xml", "/tftpboot/".$vars["name"].".cnf.xml");
}
}catch(Exception $e){
}
}
function sccp_add_line($vars){
$query = "insert into sccpline (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
$query .= $key;
}
$query .= ") VALUES (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
if (trim($value)==""){
$query .= "null";
}elseif (is_numeric($value)){
$query .= "'". trim($value) . "'";
}else{
$query .= "0x" . bin2hex($value);
}
}
$query .= ")";
sql($query);
}
function sccp_add_button($vars){
$query = "insert into buttonconfig (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
$query .= $key;
}
$query .= ") VALUES (";
$i=0;
foreach ($vars as $key=>$value){
$i++;
if ($i>1){ $query .= ",";}
if (trim($value)==""){
$query .= "null";
}elseif (is_numeric($value)){
$query .= "'" . trim($value) ."'";
}else{
$query .= "0x" . bin2hex($value);
}
}
$query .= ")";
sql($query);
}
function sccp_update($req) {
foreach ($req as $key => $item) {
// Split up...
// 0 - action
// 1 - modulename
// 2 - featurename
$arr = explode("#", $key);
if (count($arr) == 3) {
$action = $arr[0];
$modulename = $arr[1];
$featurename = $arr[2];
$fieldvalue = $item;
// Is there a more efficient way of doing this?
switch ($action)
{
case "ena":
$fcc = new featurecode($modulename, $featurename);
if ($fieldvalue == 1) {
$fcc->setEnabled(true);
} else {
$fcc->setEnabled(false);
}
$fcc->update();
break;
case "custom":
$fcc = new featurecode($modulename, $featurename);
if ($fieldvalue == $fcc->getDefault()) {
$fcc->setCode(''); // using default
} else {
$fcc->setCode($fieldvalue);
}
$fcc->update();
break;
}
}
}
needreload();
}
function sccp_check_extensions($exten=true) {
$extenlist = array();
if (is_array($exten) && empty($exten)) {
return $extenlist;
}
$featurecodes = featurecodes_getAllFeaturesDetailed();
foreach ($featurecodes as $result) {
$thisexten = ($result['customcode'] != '')?$result['customcode']:$result['defaultcode'];
// Ignore disabled codes, and modules, and any exten not being requested unless all (true)
//
if (($result['featureenabled'] == 1) && ($result['moduleenabled'] == 1) && ($exten === true || in_array($thisexten, $exten))) {
$extenlist[$thisexten]['description'] = _("Featurecode: ").$result['featurename']." (".$result['modulename'].":".$result['featuredescription'].")";
$extenlist[$thisexten]['status'] = 'INUSE';
$extenlist[$thisexten]['edit_url'] = 'config.php?type=setup&display=featurecodeadmin';
}
}
return $extenlist;
}
?>