1
+
2
+ <?php
3
+ #
4
+ # Configuration: Enter the url and key. That is it.
5
+ # url => URL to api/task/cron e.g # http://yourdomain.com/support/api/tickets.json
6
+ # key => API's Key (see admin panel on how to generate a key)
7
+ # $data add custom required fields to the array.
8
+ #
9
+ # Originally authored by [email protected]
10
+ # Modified by ntozier@osTicket / tmib.net
11
+
12
+ // If 1, display things to debug.
13
+ $ debug ="0 " ;
14
+
15
+ // You must configure the url and key in the array below.
16
+
17
+ $ config = array (
18
+ //'url'=>'10.1.2.242/osticket/upload/api/http.php/tickets.json', // URL to site.tld/api/tickets.json
19
+ 'url ' =>'http://10.1.2.242/osticket/upload/api/http.php/tickets.json ' ,
20
+ 'key ' =>'B154D35D63E7A4ADAE8BA8282C6490CD ' // API Key goes here
21
+ );
22
+
23
+ # NOTE: some people have reported having to use "http://your.domain.tld/api/http.php/tickets.json" instead.
24
+
25
+ # Fill in the data for the new ticket, this will likely come from $_POST.
26
+ # NOTE: your variable names in osT are case sensiTive.
27
+ # So when adding custom lists or fields make sure you use the same case
28
+ # For examples on how to do that see Agency and Site below.
29
+
30
+ $ name = $ _POST ['nome ' ];
31
+ $ email = $ _POST ['email ' ];
32
+ $ phone = $ _POST ['telefone ' ];
33
+ $ assunto1 = $ _POST ['assunto1 ' ];
34
+ $ assunto2 = $ _POST ['assunto2 ' ];
35
+ $ assunto3 = $ _POST ['assunto3 ' ];
36
+ $ mensagem = $ _POST ['mensagem ' ];
37
+
38
+ if (!empty ($ assunto3 ) || !empty ($ assunto2 )) {
39
+ if (!empty ($ assunto3 )) {
40
+ $ assunto = $ assunto3 ;
41
+ }
42
+ if (!empty ($ assunto2 )){
43
+ $ assunto = $ assunto2 ;
44
+ }
45
+ }else {
46
+ $ assunto = $ assunto1 ;
47
+ }
48
+
49
+ switch ($ assunto ) {
50
+ case 'Dúvidas sobre certificados ' :
51
+ $ topicId = 17 ;
52
+ break ;
53
+
54
+ case 'Dúvidas sobre cursos ' :
55
+ $ topicId = 18 ;
56
+ break ;
57
+
58
+ case 'Reclamações sobre certificados ' :
59
+ $ topicId = 21 ;
60
+ break ;
61
+
62
+ case 'Reclamações sobre cursos ' :
63
+ $ topicId = 22 ;
64
+ break ;
65
+
66
+ case 'Dúvidas ' :
67
+ $ topicId = 13 ;
68
+ break ;
69
+
70
+ case 'Dúvidas sobre dados cadastrais ' :
71
+ $ topicId = 19 ;
72
+ break ;
73
+
74
+ case 'Outras dúvidas ' :
75
+ $ topicId = 20 ;
76
+ break ;
77
+
78
+ case 'Elogios ' :
79
+ $ topicId = 16 ;
80
+ break ;
81
+
82
+ case 'Reclamações ' :
83
+ $ topicId = 14 ;
84
+ break ;
85
+
86
+ case 'Outras reclamações ' :
87
+ $ topicId = 25 ;
88
+ break ;
89
+
90
+ case 'Reclamações sobre dados cadastrais ' :
91
+ $ topicId = 24 ;
92
+ break ;
93
+
94
+ case 'Reclamações sobre tutor ' :
95
+ $ topicId = 23 ;
96
+ break ;
97
+
98
+ case 'Sugestões ' :
99
+ $ topicId = 15 ;
100
+ break ;
101
+
102
+ default :
103
+ $ topicId = 13 ;
104
+ break ;
105
+ }
106
+
107
+ $ data = array (
108
+ 'name ' => $ name , // from name aka User/Client Name
109
+ 'email ' => $ email , // from email aka User/Client Email
110
+ 'phone ' => $ phone , // phone number aka User/Client Phone Number
111
+ 'subject ' => $ assunto , // test subject, aka Issue Summary
112
+ 'message ' => $ mensagem , // test ticket body, aka Issue Details.
113
+ 'ip ' => $ _SERVER ['REMOTE_ADDR ' ], // Should be IP address of the machine thats trying to open the ticket.
114
+ 'topicId ' => $ topicId , // the help Topic that you want to use for the ticket
115
+ //'Agency' => '58', //this is an example of a custom list entry. This should be the number of the entry.
116
+ //'Site' => 'Bermuda'; // this is an example of a custom text field. You can push anything into here you want.
117
+ 'attachments ' => array ()
118
+ );
119
+
120
+ # more fields are available and are documented at:
121
+ # https://github.com/osTicket/osTicket-1.8/blob/develop/setup/doc/api/tickets.md
122
+
123
+
124
+ print_r ($ data );
125
+ // die();
126
+
127
+
128
+ # Add in attachments here if necessary
129
+ # Note: there is something with this wrong with the file attachment here it does not work.
130
+ //$data['attachments'][] =
131
+ //array('file.txt' =>
132
+ // 'data:text/plain;base64;'
133
+ // .base64_encode(file_get_contents('/file.txt'))); // replace ./file.txt with /path/to/your/test/filename.txt
134
+
135
+
136
+ #pre-checks
137
+ function_exists ('curl_version ' ) or die ('CURL support required ' );
138
+ function_exists ('json_encode ' ) or die ('JSON support required ' );
139
+
140
+ #set timeout
141
+ set_time_limit (30 );
142
+
143
+ #curl post
144
+ $ ch = curl_init ();
145
+ curl_setopt ($ ch , CURLOPT_URL , $ config ['url ' ]);
146
+ curl_setopt ($ ch , CURLOPT_POST , 1 );
147
+ curl_setopt ($ ch , CURLOPT_POSTFIELDS , json_encode ($ data ));
148
+ curl_setopt ($ ch , CURLOPT_USERAGENT , 'osTicket API Client v1.8 ' );
149
+ curl_setopt ($ ch , CURLOPT_HEADER , FALSE );
150
+ curl_setopt ($ ch , CURLOPT_HTTPHEADER , array ( 'Expect: ' , 'X-API-Key: ' .$ config ['key ' ]));
151
+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , FALSE );
152
+ curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , TRUE );
153
+ $ result =curl_exec ($ ch );
154
+ $ code = curl_getinfo ($ ch , CURLINFO_HTTP_CODE );
155
+ curl_close ($ ch );
156
+
157
+ echo $ code ;
158
+
159
+ if ($ code != 201 ){
160
+ header ($ _SERVER ['SERVER_PROTOCOL ' ] . ' 500 Internal Server Error ' , true , 500 );
161
+ echo 'Unable to create ticket: ' .$ result ;
162
+ }
163
+
164
+ $ ticket_id = (int ) $ result ;
165
+
166
+ # Continue onward here if necessary. $ticket_id has the ID number of the
167
+ # newly-created ticket
168
+
169
+ function IsNullOrEmptyString ($ question ){
170
+ return (!isset ($ question ) || trim ($ question )==='' );
171
+ }
172
+ ?>
0 commit comments