-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess.php
executable file
·59 lines (45 loc) · 1.35 KB
/
process.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
<?php
require_once 'vendor/autoload.php';
$config = require 'config.php';
// Check and store the person's email
if (isset($_POST['email']) && !empty($_POST['email'])) {
$email = $_POST['email'];
} else {
die('Required field "email" is missing!');
}
// Check and store the person's name
if (isset($_POST['name'])) {
$name = $_POST['name'];
} else {
die('Required field "name" is missing!');
}
// Check and store the ticket subject
if (isset($_POST['subject'])) {
$subject = $_POST['subject'];
} else {
die('Required field "subject" is missing!');
}
// Check and store the first ticket message
if (isset($_POST['message'])) {
$message = $_POST['message'];
} else {
die('Required field "message" is missing!');
}
$dpApi = new DeskPRO\Api($config['deskpro_url'], $config['api_key']);
$ticketBuilder = $dpApi->tickets->createBuilder();
$personBuilder = $dpApi->people->createPersonEditor();
$personBuilder->setName($name);
try {
$personBuilder->setEmail($email);
} catch (Exception $e) {
// $email is probably not a valid email
die($e->getMessage());
}
$ticketBuilder->setCreatedBy($personBuilder)
->setSubject($subject)
->setMessage($message);
if (isset($_FILES['attach']) && is_uploaded_file($_FILES['attach']['tmp_name'])) {
$ticketBuilder->attach($_FILES['attach']['tmp_name']);
}
$result = $dpApi->tickets->save($ticketBuilder);
var_dump($result->getData());