forked from jmcguirl/dynroute
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dynroute.class.php
121 lines (118 loc) · 2.86 KB
/
Dynroute.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
<?php
// Copyright (c) 2015-2017 John Fawcett
// This is a dervied work licenced under GPL V3 or later
// The original file was published by Sagoma Technologies in
// Freepbx IVR module
namespace FreePBX\modules;
class Dynroute extends \FreePBX_Helpers implements \BMO {
public function __construct($freepbx = null) {
if ($freepbx == null) {
throw new Exception("Not given a FreePBX Object");
}
$this->FreePBX = $freepbx;
//This is only needed for database stuff. If you are not doing database stuff you don't need this
$this->db = $freepbx->Database;
}
public function install() {}
public function uninstall() {}
public function backup() {}
public function restore($backup) {}
public function doConfigPageInit($page) {
}
public function search($query, &$results) {
$dynroutes = $this->getDetails();
foreach ($dynroutes as $dynroute) {
$results[] = array(
"text" => _("Dynamic Route").": ".$dynroute['name'],
"type" => "get",
"dest" => "?display=dynroute&action=edit&id=".$dynroute['id']
);
}
}
public function getDetails($id = false) {
$sql = 'SELECT * FROM dynroute';
if ($id) {
$sql .= ' where id = :id ';
}
$sql .= ' ORDER BY name';
$sth = $this->Database->prepare($sql);
$sth->execute(array(":id" => $id));
$res = $sth->fetchAll();
if ($id && isset($res[0])) {
return $res[0];
} else {
$res = is_array($res)?$res:array();
return $res;
}
}
public function getActionBar($request) {
$buttons = array();
switch($request['display']) {
case 'dynroute':
$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')
)
);
if (empty($request['id'])) {
unset($buttons['delete']);
}
isset($request['action'])?'':$buttons = NULL;
break;
}
return $buttons;
}
public function pageHook($request){
return \FreePBX::Hooks()->processHooks($request);
}
public function ajaxRequest($req, &$setting) {
switch ($req) {
case 'getJSON':
return true;
break;
default:
return false;
break;
}
}
public function ajaxHandler(){
switch ($_REQUEST['command']) {
case 'getJSON':
switch ($_REQUEST['jdata']) {
case 'grid':
$dynroutes = $this->getDetails();
$ret = array();
foreach ($dynroutes as $r) {
$r['name'] = $r['name'] ? $r['name'] : 'Dynamic Route ID: ' . $r['id'];
$ret[] = array(
'name' => $r['name'],
'description' => $r['description'],
'id' => $r['id'],
'link' => array($r['id'],$r['name'])
);
}
return $ret;
break;
default:
return false;
break;
}
break;
default:
return false;
break;
}
}
}