-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogger.php
62 lines (53 loc) · 1.9 KB
/
logger.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
<?php
require_once(INCLUDE_DIR . 'class.plugin.php');
require_once(INCLUDE_DIR . 'class.signal.php');
require_once(INCLUDE_DIR . 'class.app.php');
require_once('config.php');
class LoggerPlugin extends Plugin {
var $config_class = "LoggerPluginConfig";
function bootstrap() {
Signal::connect('model.created', array($this, 'onTicketCreated'), 'Ticket');
}
function onTicketCreated($ticket) {
global $ost;
// Get config data
$logger_url = $this->getConfig()->get('logger-url');
// Get new ticket data
$ticket_id = $ticket->getId();
$ticket_number = $ticket->getNumber();
$ticket_url = $ost->getConfig()->getUrl() . 'scp/tickets.php?number=' . $ticket_number;
// $ticket_subject = $ticket->getSubject();
$ticket_name = $ticket->getName();
$ticket_email = $ticket->getEmail();
// $ticket_topic = $ticket->getTopic()->getName();
// $ticket_lastMessage = $ticket->getLastMessage();
// Create the Json-formatted payload
$data = "payload=" . json_encode(array(
"ticket_id" => "{$ticket_id}",
"ticket_num" => "{$ticket_number}",
"ticket_url" => "{$ticket_url}",
"ticket_author" => "{$ticket_name}",
"ticket_email" => "{$ticket_email}",
"ticket_subject"=> "_SUBJECT_",
"ticket_topic" => "_TOPIC_",
"ticket_msg" => "_MESSAGE_"
));
// Prepare and Curl the data
$ch = curl_init($logger_url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT,10);
$result = curl_exec($ch);
$curl_errno = curl_errno($ch);
$curl_error = curl_error($ch);
curl_close($ch);
// Catch Curl errors and post them in the log file
if ($curl_errno > 0) {
error_log('Curl Error ' . $curl_error);
}
else if($result != 'ok') {
error_log('Curl Error (Check your URL): ' . $result);
}
}
}