forked from chadsmith/OpenVBX-Plugin-Outbound
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.php
95 lines (95 loc) · 3.02 KB
/
queue.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
<?php
$ci =& get_instance();
if(defined("HOOK") AND HOOK) {
set_time_limit(0);
$events = $ci->db->query(sprintf('SELECT id, tenant, number, type, time, callerId, data FROM outbound_queue WHERE time < %d ORDER BY time ASC', time()))->result();
if(count($events)) {
require_once(APPPATH . 'libraries/Services/Twilio.php');
foreach($events as $event) {
$event->data = json_decode($event->data);
$twilio_sid = $ci->settings->get('twilio_sid', $event->tenant);
$twilio_token = $ci->settings->get('twilio_token', $event->tenant);
$service = new Services_Twilio($twilio_sid, $twilio_token);
if('sms' == $event->type)
$service->account->sms_messages->create($event->callerId, $event->number, $event->data->message);
else
$service->account->calls->create($event->callerId, $event->number, $event->data->uri);
$ci->db->delete('outbound_queue', array('id' => $event->id));
}
}
die;
}
$user = OpenVBX::getCurrentUser();
$tenant_id = $user->values['tenant_id'];
$queries = explode(';', file_get_contents(dirname(__FILE__) . '/db.sql'));
foreach($queries as $query)
if(trim($query))
$ci->db->query($query);
if(!empty($_POST['remove'])) {
$ci->db->delete('outbound_queue', array('id' => intval($_POST['remove']), 'tenant' => $tenant_id));
die;
}
$events = $ci->db->query(sprintf('SELECT id, number, type, time, callerId, data FROM outbound_queue WHERE tenant=%d ORDER BY time ASC', $tenant_id))->result();
OpenVBX::addJS('queue.js');
?>
<style>
.vbx-queue h3 {
font-size: 16px;
font-weight: bold;
margin-top: 0;
}
.vbx-queue .event {
clear: both;
width: 95%;
overflow: hidden;
margin: 0 auto;
padding: 5px 0;
border-bottom: 1px solid #eee;
}
.vbx-queue .event span {
display: inline-block;
width: 20%;
text-align: center;
float: left;
vertical-align: middle;
line-height: 24px;
}
.vbx-queue a.delete {
display: inline-block;
height: 24px;
width: 24px;
text-indent: -999em;
background: transparent url(<?php echo asset_url('/assets/i/action-icons-sprite.png'); ?>) no-repeat -68px 0;
}
</style>
<div class="vbx-content-main">
<div class="vbx-content-menu vbx-content-menu-top">
<h2 class="vbx-content-heading">Scheduled Events</h2>
</div>
<div class="vbx-table-section vbx-queue">
<div class="event">
<h3>
<span>Number</span>
<span>Type</span>
<span>Time</span>
<span>Caller ID</span>
<span>Delete</span>
</h3>
</div>
<?php foreach($events as $event): $event->data = json_decode($event->data); ?>
<div class="event" id="event_<?php echo $event->id; ?>">
<p>
<span><?php echo $event->number; ?></span>
<?php if('sms' == $event->type): ?>
<span title="<?php echo htmlentities($event->data->message); ?>">SMS</span>
<?php else: ?>
<span><?php echo htmlentities($event->data->name); ?></span>
<?php endif; ?>
<span><?php echo date('j-M-Y g:i:sa', $event->time); ?></span>
<span><?php echo $event->callerId; ?></span>
<span><a href="" class="delete">X</a></span>
</p>
</div>
<?php endforeach; ?>
</div>
</div>