forked from sirportly/whmcs-data-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsirportly_functions.php
executable file
·192 lines (159 loc) · 6.43 KB
/
sirportly_functions.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
<?PHP
function sirportly_api($action,$token,$secret,$postfields=array()){
$settings = sirportly_settings();
$ssl = ($settings['ssl'] == 'on' ? 'https://' : 'http://');
$url = $ssl.$settings['url'];
$query_string = "";
foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url.$action);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Auth-Token: '.$token,'X-Auth-Secret: '.$secret));
curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$jsondata = curl_exec($ch);
if (curl_error($ch))
{
global $smarty;
$true = true;
$smarty->assign_by_ref('sirportly_error', $true);
}
curl_close($ch);
$arr = json_decode($jsondata,true);
if ($arr['error']) {
global $smarty;
$true = true;
$smarty->assign_by_ref('sirportly_error', $true);
}
return $arr;
}
function sirportly_admin($action,$token,$secret,$postfields=array()){
$settings = sirportly_settings();
$ssl = ($settings['ssl'] == 'on' ? 'https://' : 'http://');
$url = $ssl.$settings['url'];
$curl = curl_init();
$header = array('X-Auth-Token: '.$token, 'X-Auth-Secret: '.$secret);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_URL, $url.$action);
curl_setopt($curl, CURLOPT_BUFFERSIZE, 131072);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postfields);
$result = curl_exec($curl);
curl_close($curl);
return json_decode($result, true);
}
function sirportly_brands($token,$secret){
$brand_array = array();
$brand_array[0] = 'Disabled';
$brands = sirportly_api('/api/v1/objects/brands',$token,$secret);
foreach ($brands as $key => $value) {
$brand_array[$value['id']] = $value['name'];
}
return $brand_array;
}
function sirportly_reply_to_ticket($token,$secret,$ticket_reference,$reply,$customer){
$reply_result = sirportly_api('/api/v1/tickets/post_update',$token,$secret,array('ticket' => $ticket_reference, 'message' => $reply, 'customer' => $customer));
return $reply_result;
}
function sirportly_view_ticket($token,$secret,$reference){
$ticket = sirportly_api('/api/v1/tickets/ticket',$token,$secret,array('reference' => $reference));
return $ticket;
}
function sirportly_status($token,$secret){
$status_array = array();
$status = sirportly_api('/api/v1/objects/statuses',$token,$secret);
foreach ($status as $key => $value) {
$status_array[$value['id']] = $value['name'];
}
return $status_array;
}
function sirportly_customer_id($id){
$sirportly_customer = select_query('sirportly_customers', '', array('customerid' => $id));
if (!mysql_num_rows($sirportly_customer)) {
mysql_query("INSERT INTO `sirportly_customers` (`userid`, `customerid`) VALUES ('".$_SESSION['uid']."', '".$id."');");
}
}
function sirportly_priorities($token,$secret){
$priority_array = array();
$priority = sirportly_api('/api/v1/objects/priorities',$token,$secret);
foreach ($priority as $key => $value) {
$priority_array[] = array('id' => $value['id'], 'name' => $value['name']);
}
return array_reverse($priority_array);
}
function sirportly_enabled()
{
$sirportly_settings = sirportly_settings();
return ($sirportly_settings['brand'] ? true : false);
}
function sirportly_clientarea_departments($token,$secret,$brand){
$department_array = array();
$departments = sirportly_api('/api/v1/objects/departments',$token,$secret,array('brand' => $brand));
foreach ($departments as $key => $value) {
if (!$value['private']) {
$department_array[] = array('id' => $value['id'], 'name' => $value['name']);
}
}
return $department_array;
}
function sirportly_submit_ticket($token,$secret,$params){
$ticket = sirportly_api('/api/v1/tickets/submit',$token,$secret,$params);
return $ticket;
}
function sirportly_clientarea_tickets($token,$secret,$customer,$brand=''){
$ticket_array = array();
$tickets = sirportly_spql($token,$secret,"SELECT tickets.id, tickets.reference, tickets.subject, tickets.submitted_at, tickets.last_update_posted_at, priorities.name, priorities.colour, departments.name FROM tickets WHERE brands.id = '".$brand."' AND customers.id = '".$customer."' ORDER BY tickets.last_update_posted_at DESC");
foreach ($tickets['results'] as $key => $value) {
$ticket_array[] = array(
'id' => $value['0'],
'tid' => $value['1'],
'c' => $value['0'],
'date' => fromMySQLDate($value['3'],'time'),
'department' => $value['7'],
'subject' => $value['2'],
'status' => '<span style="color:#'.$value['6'].'">'.$value['5'].'</span>',
'urgengy' => $value['7'],
'lastreply' => ($value['4'] ? fromMySQLDate($value['4'], 'time') : 'Never'),
'unread' => 1,
);
}
return $ticket_array;
}
function sirportly_open_tickets($token,$secret,$customer,$brand)
{
$ticket_array = array();
$tickets = sirportly_api('/api/v1/tickets/spql',$token,$secret,array('spql' => "SELECT tickets.reference, tickets.id, tickets.subject, statuses.name, departments.name, tickets.last_update_posted_at, tickets.submitted_at, priorities.name FROM tickets WHERE tickets.status_type != '1' AND customers.id = '".$customer."' AND brands.id = '".$brand."'"));
foreach ($tickets['results'] as $key => $ticket) {
$created_at = fromMySQLDate($ticket['6'],'time');
$last_updated = ($ticket['5'] ? fromMySQLDate($ticket['5'],'time') : 'Never');
$ticket_array[] = array(
'date' => $created_at,
'tid' => $ticket['0'],
'subject' => $ticket['2'],
'c' => $ticket['1'],
'lastreply' => $last_updated,
'department' => $ticket['4'],
'status' => $ticket['3'],
'priority' => $ticket['7']);
}
return $ticket_array;
}
function sirportly_spql($token,$secret,$query)
{
return sirportly_api('/api/v1/tickets/spql',$token,$secret,array('spql' => $query));
}
function sirportly_settings()
{
$result = select_query('tbladdonmodules', '', array('module' => 'sirportly'));
$settings = array();
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$settings[$row['setting']] = $row['value'];
}
return $settings;
}