-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSetcid.class.php
More file actions
135 lines (125 loc) · 3.76 KB
/
Setcid.class.php
File metadata and controls
135 lines (125 loc) · 3.76 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
<?php
// vim: set ai ts=4 sw=4 ft=php:
/**
* Set CID
*/
namespace FreePBX\modules;
use BMO;
use FreePBX_Helpers;
use PDO;
class Setcid extends FreePBX_Helpers implements BMO {
public function install() {}
public function uninstall() {}
public function doConfigPageInit($display) {}
public function ajaxRequest($req, &$setting) {
switch($req) {
case "getable":
return true;
break;
}
return false;
}
public function ajaxHandler() {
switch($_REQUEST['command']) {
case "getable":
$cids = $this->listAll();
foreach($cids as &$cid) {
$cid['actions'] = '<a href="?display=setcid&view=form&id='.$cid['cid_id'].'"><i class="fa fa-edit"></i></i></a> <a href="?display=setcid&action=delete&id='.$cid['cid_id'].'"><i class="fa fa-trash"></i></a>';
}
return $cids;
break;
}
}
public function showPage() {
if(isset($_REQUEST['action'])) {
if($_REQUEST['action'] == "delete") {
$this->delete($_REQUEST['id']);
\needreload();
} elseif($_REQUEST['action'] == "save") {
$id = !empty($_REQUEST['id']) ? $_REQUEST['id'] : null;
$goto = $_REQUEST[$_REQUEST['goto0'].'0'];
$this->update($id, $_REQUEST['description'], $_REQUEST['cid_name'], $_REQUEST['cid_num'], $goto);
\needreload();
}
}
$view = !empty($_REQUEST['view']) ? $_REQUEST['view'] : "";
$usage_list = '';
switch($view) {
case "form":
if(isset($_REQUEST['id'])) {
$usage_list = $this->FreePBX->View->destinationUsage(setcid_getdest($_REQUEST['id']));
$item = $this->get($_REQUEST['id']);
} else {
$item = array(
"cid_name" => '${CALLERID(name)}',
"cid_num" => '${CALLERID(num)}'
);
}
$content = load_view(__DIR__."/views/form.php",array("item" => $item));
break;
default:
$content = load_view(__DIR__."/views/grid.php",array());
break;
}
return load_view(__DIR__."/views/main.php",array("content" => $content, "usage_list" => $usage_list));
}
public function listAll() {
$sql = "SELECT cid_id, description, cid_name, cid_num, dest FROM setcid ORDER BY description ";
$sth = $this->Database->prepare($sql);
$sth->execute();
$results = $sth->fetchAll(PDO::FETCH_ASSOC);
return !empty($results) ? $results : array();
}
public function get($id) {
$sql = "SELECT cid_id, description, cid_name, cid_num, dest FROM setcid WHERE cid_id = ?";
$sth = $this->Database->prepare($sql);
$sth->execute(array($id));
$results = $sth->fetch(PDO::FETCH_ASSOC);
return !empty($results) ? $results : array();
}
public function update($id = null, $description = '', $name = '', $number = '', $dest = '') {
$sql = "REPLACE INTO setcid (cid_id, description, cid_name, cid_num, dest) VALUES (?, ?, ?, ?, ?)";
$sth = $this->Database->prepare($sql);
return $sth->execute(array($id, $description, $name, $number, $dest));
}
public function delete($id) {
$sql = "DELETE FROM setcid WHERE cid_id = ?";
$sth = $this->Database->prepare($sql);
return $sth->execute(array($id));
}
public function getActionBar($request) {
$buttons = array();
if($request['display'] == 'setcid' && isset($request['view'])) {
switch($request['view']) {
case 'form':
$buttons = array(
'delete' => array(
'name' => 'delete',
'id' => 'delete',
'value' => _('Delete')
),
'reset' => array(
'name' => 'reset',
'id' => 'reset',
'value' => _('Reset')
),
'submit' => array(
'name' => 'submit',
'id' => 'submit',
'value' => _('Submit')
)
);
break;
}
}
if(empty($request['id'])) {
unset($buttons['delete']);
}
return $buttons;
}
public function getRightNav($request) {
if(isset($request['view']) && $request['view'] == 'form'){
return load_view(__DIR__."/views/rnav.php",array());
}
}
}