forked from FreePBX/setcid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.inc.php
More file actions
147 lines (127 loc) · 4.37 KB
/
functions.inc.php
File metadata and controls
147 lines (127 loc) · 4.37 KB
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
<?php
if (!defined('FREEPBX_IS_AUTH')) { die('No direct script access allowed'); }
function setcid_get_config($engine) {
global $ext;
switch ($engine) {
case 'asterisk':
//Below removed in FREEPBX-6740, Please reference before adding it back
//$ext->addInclude('from-internal-additional', 'app-setcid');
foreach (setcid_list() as $row) {
$ext->add('app-setcid',$row['cid_id'], '', new ext_noop('('.$row['description'].') Changing cid to '.$row['cid_name'].' <'. $row['cid_num'].'>'));
$ext->add('app-setcid',$row['cid_id'], '', new ext_set('CALLERID(name)', $row['cid_name']));
$ext->add('app-setcid',$row['cid_id'], '', new ext_set('CALLERID(num)', $row['cid_num']));
$ext->add('app-setcid',$row['cid_id'], '', new ext_goto($row['dest']));
}
break;
}
}
/** Get a list of all cid
*/
function setcid_list() {
global $db;
$sql = "SELECT cid_id, description, cid_name, cid_num, dest FROM setcid ORDER BY description ";
$results = $db->getAll($sql, DB_FETCHMODE_ASSOC);
if($db->IsError($results)) {
die_freepbx($results->getMessage()."<br><br>Error selecting from setcid");
}
return $results;
}
function setcid_destinations() {
global $module_page;
$extens = array();
// it makes no sense to point at another callerid (and it can be an infinite loop)
if ($module_page == 'setcid') {
return false;
}
// return an associative array with destination and description
foreach (setcid_list() as $row) {
$extens[] = array('destination' => 'app-setcid,' . $row['cid_id'] . ',1', 'description' => $row['description']);
}
return $extens;
}
function setcid_get($cid_id) {
global $db;
$sql = "SELECT cid_id, description, cid_name, cid_num, dest FROM setcid WHERE cid_id = ".$db->escapeSimple($cid_id);
$row = $db->getRow($sql, DB_FETCHMODE_ASSOC);
if($db->IsError($row)) {
die_freepbx($row->getMessage()."<br><br>Error selecting row from setcid");
}
return $row;
}
function setcid_add($description, $cid_name, $cid_num, $dest) {
global $db;
$sql = "INSERT INTO setcid (description, cid_name, cid_num, dest) VALUES (".
"'".$db->escapeSimple($description)."', ".
"'".$db->escapeSimple($cid_name)."', ".
"'".$db->escapeSimple($cid_num)."', ".
"'".$db->escapeSimple($dest)."')";
$result = $db->query($sql);
if($db->IsError($result)) {
die_freepbx($result->getMessage().$sql);
}
}
function setcid_delete($cid_id) {
global $db;
$sql = "DELETE FROM setcid WHERE cid_id = ".$db->escapeSimple($cid_id);
$result = $db->query($sql);
if($db->IsError($result)) {
die_freepbx($result->getMessage().$sql);
}
}
function setcid_edit($cid_id, $description, $cid_name, $cid_num, $dest) {
global $db;
$sql = "UPDATE setcid SET ".
"description = '".$db->escapeSimple($description)."', ".
"cid_name = '".$db->escapeSimple($cid_name)."', ".
"cid_num = '".$db->escapeSimple($cid_num)."', ".
"dest = '".$db->escapeSimple($dest)."' ".
"WHERE cid_id = ".$db->escapeSimple($cid_id);
$result = $db->query($sql);
if($db->IsError($result)) {
die_freepbx($result->getMessage().$sql);
}
}
//----------------------------------------------------------------------------
// Dynamic Destination Registry and Recordings Registry Functions
function setcid_check_destinations($dest=true) {
global $active_modules;
$destlist = array();
if (is_array($dest) && empty($dest)) {
return $destlist;
}
$sql = "SELECT cid_id, description, dest FROM setcid ";
if ($dest !== true) {
$sql .= "WHERE dest in ('".implode("','",$dest)."')";
}
$results = sql($sql,"getAll",DB_FETCHMODE_ASSOC);
$type = isset($active_modules['setcid']['type'])?$active_modules['setcid']['type']:'setup';
foreach ($results as $result) {
$thisdest = $result['dest'];
$thisid = $result['cid_id'];
$destlist[] = array(
'dest' => $thisdest,
'description' => 'Set CallerID: '.$result['description'],
'edit_url' => 'config.php?display=setcid&type=tool&id='.urlencode($thisid),
);
}
return $destlist;
}
function setcid_getdest($id) {
return array("app-setcid,$id,1");
}
function setcid_getdestinfo($dest) {
if (substr(trim($dest),0,11) == 'app-setcid,') {
$grp = explode(',',$dest);
$id = $grp[1];
$thiscid = setcid_get($id);
if (empty($thiscid)) {
return array();
} else {
return array('description' => sprintf(_("Set CallerID %s: "),$thiscid['description']),
'edit_url' => 'config.php?display=setcid&id='.urlencode($id),
);
}
} else {
return false;
}
}