|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Api\v1; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Controllers\Common\PhpMailController; |
|
6
|
|
|
use App\Http\Controllers\Controller; |
|
7
|
|
|
use App\Model\helpdesk\Settings\Alert; |
|
8
|
|
|
use App\Model\helpdesk\Settings\Company; |
|
9
|
|
|
use App\Model\helpdesk\Settings\System; |
|
10
|
|
|
use App\Model\helpdesk\Ticket\Ticket_attachments; |
|
11
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Collaborator; |
|
12
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Status; |
|
13
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Thread; |
|
14
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
|
15
|
|
|
use App\User; |
|
16
|
|
|
use Auth; |
|
17
|
|
|
use Hash; |
|
18
|
|
|
use Input; |
|
19
|
|
|
use Mail; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* ----------------------------------------------------------------------------- |
|
23
|
|
|
* Ticket Controller |
|
24
|
|
|
* -----------------------------------------------------------------------------. |
|
25
|
|
|
* |
|
26
|
|
|
* |
|
27
|
|
|
* @author Vijay Sebastian <[email protected]> |
|
28
|
|
|
* @copyright (c) 2016, Ladybird Web Solution |
|
29
|
|
|
* @name Faveo HELPDESK |
|
30
|
|
|
* |
|
31
|
|
|
* @version v1 |
|
32
|
|
|
*/ |
|
33
|
|
|
class TicketController extends Controller |
|
34
|
|
|
{ |
|
35
|
|
|
/** |
|
36
|
|
|
* Create a new controller instance. |
|
37
|
|
|
* |
|
38
|
|
|
* @return type response |
|
|
|
|
|
|
39
|
|
|
*/ |
|
40
|
|
|
public function __construct() |
|
41
|
|
|
{ |
|
42
|
|
|
$PhpMailController = new PhpMailController(); |
|
43
|
|
|
$this->PhpMailController = $PhpMailController; |
|
|
|
|
|
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Create Ticket. |
|
48
|
|
|
* |
|
49
|
|
|
* @param type $user_id |
|
50
|
|
|
* @param type $subject |
|
51
|
|
|
* @param type $body |
|
52
|
|
|
* @param type $helptopic |
|
53
|
|
|
* @param type $sla |
|
54
|
|
|
* @param type $priority |
|
55
|
|
|
* |
|
56
|
|
|
* @return type string |
|
57
|
|
|
*/ |
|
58
|
|
|
public function createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach = '') |
|
59
|
|
|
{ |
|
60
|
|
|
try { |
|
61
|
|
|
//return $headers; |
|
62
|
|
|
$max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->first(); |
|
63
|
|
|
//dd($max_number); |
|
64
|
|
|
if ($max_number == null) { |
|
65
|
|
|
$ticket_number = 'AAAA-9999-9999999'; |
|
66
|
|
|
} else { |
|
67
|
|
|
foreach ($max_number as $number) { |
|
68
|
|
|
$ticket_number = $max_number->ticket_number; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
$ticket = new Tickets(); |
|
72
|
|
|
$ticket->ticket_number = $this->ticketNumber($ticket_number); |
|
|
|
|
|
|
73
|
|
|
//dd($this->ticketNumber($ticket_number)); |
|
|
|
|
|
|
74
|
|
|
$ticket->user_id = $user_id; |
|
|
|
|
|
|
75
|
|
|
$ticket->dept_id = $dept; |
|
|
|
|
|
|
76
|
|
|
$ticket->help_topic_id = $helptopic; |
|
|
|
|
|
|
77
|
|
|
$ticket->sla = $sla; |
|
|
|
|
|
|
78
|
|
|
$ticket->assigned_to = $assignto; |
|
|
|
|
|
|
79
|
|
|
$ticket->status = '1'; |
|
|
|
|
|
|
80
|
|
|
$ticket->priority_id = $priority; |
|
|
|
|
|
|
81
|
|
|
$ticket->source = $source; |
|
|
|
|
|
|
82
|
|
|
$ticket->save(); |
|
83
|
|
|
//dd($ticket); |
|
84
|
|
|
$ticket_number = $ticket->ticket_number; |
|
|
|
|
|
|
85
|
|
|
$id = $ticket->id; |
|
|
|
|
|
|
86
|
|
|
if ($form_data != null) { |
|
87
|
|
|
$help_topic = Help_topic::where('id', '=', $helptopic)->first(); |
|
88
|
|
|
$forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get(); |
|
89
|
|
|
foreach ($form_data as $key => $form_details) { |
|
90
|
|
|
foreach ($forms as $from) { |
|
91
|
|
|
if ($from->name == $key) { |
|
92
|
|
|
$form_value = new Ticket_Form_Data(); |
|
93
|
|
|
$form_value->ticket_id = $id; |
|
94
|
|
|
$form_value->title = $from->label; |
|
95
|
|
|
$form_value->content = $form_details; |
|
96
|
|
|
$form_value->save(); |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
//return $headers; |
|
102
|
|
|
$this->storeCollaborators($headers, $id); |
|
103
|
|
|
|
|
104
|
|
|
$thread = $this->ticketThread($subject, $body, $id, $user_id); |
|
105
|
|
|
if (!empty($attach)) { |
|
106
|
|
|
$this->attach($thread, $attach); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
return $thread; |
|
110
|
|
|
} catch (\Exception $e) { |
|
111
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* store_collaborators. |
|
117
|
|
|
* |
|
118
|
|
|
* @param type $headers |
|
119
|
|
|
* |
|
120
|
|
|
* @return type |
|
121
|
|
|
*/ |
|
122
|
|
|
public function storeCollaborators($headers, $id) |
|
123
|
|
|
{ |
|
124
|
|
|
try { |
|
125
|
|
|
//return $headers; |
|
126
|
|
|
$company = $this->company(); |
|
|
|
|
|
|
127
|
|
|
if (isset($headers)) { |
|
128
|
|
|
foreach ($headers as $email) { |
|
129
|
|
|
$name = $email; |
|
130
|
|
|
$email = $email; |
|
|
|
|
|
|
131
|
|
View Code Duplication |
if ($this->checkEmail($email) == false) { |
|
|
|
|
|
|
132
|
|
|
$create_user = new User(); |
|
133
|
|
|
$create_user->user_name = $name; |
|
|
|
|
|
|
134
|
|
|
$create_user->email = $email; |
|
|
|
|
|
|
135
|
|
|
$create_user->active = 1; |
|
|
|
|
|
|
136
|
|
|
$create_user->role = 'user'; |
|
|
|
|
|
|
137
|
|
|
$password = $this->generateRandomString(); |
|
138
|
|
|
$create_user->password = Hash::make($password); |
|
|
|
|
|
|
139
|
|
|
$create_user->save(); |
|
140
|
|
|
$user_id = $create_user->id; |
|
|
|
|
|
|
141
|
|
|
// Mail::send('emails.pass', ['password' => $password, 'name' => $name, 'from' => $company, 'emailadd' => $email], function ($message) use ($email, $name) { |
|
|
|
|
|
|
142
|
|
|
// $message->to($email, $name)->subject('password'); |
|
|
|
|
|
|
143
|
|
|
// }); |
|
144
|
|
|
|
|
145
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $name, 'email' => $email], $message = ['subject' => 'password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $name, 'email_address' => $email, 'user_password' => $password]); |
|
146
|
|
|
} else { |
|
147
|
|
|
$user = $this->checkEmail($email); |
|
148
|
|
|
$user_id = $user->id; |
|
149
|
|
|
} |
|
150
|
|
|
//return $user_id; |
|
151
|
|
|
$collaborator_store = new Ticket_Collaborator(); |
|
152
|
|
|
$collaborator_store->isactive = 1; |
|
|
|
|
|
|
153
|
|
|
$collaborator_store->ticket_id = $id; |
|
|
|
|
|
|
154
|
|
|
$collaborator_store->user_id = $user_id; |
|
|
|
|
|
|
155
|
|
|
$collaborator_store->role = 'ccc'; |
|
|
|
|
|
|
156
|
|
|
$collaborator_store->save(); |
|
157
|
|
|
} |
|
158
|
|
|
} |
|
159
|
|
|
|
|
160
|
|
|
return true; |
|
161
|
|
|
} catch (\Exception $e) { |
|
162
|
|
|
return $e->getMessage(); |
|
163
|
|
|
} |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
/** |
|
167
|
|
|
* Generate Ticket Thread. |
|
168
|
|
|
* |
|
169
|
|
|
* @param type $subject |
|
170
|
|
|
* @param type $body |
|
171
|
|
|
* @param type $id |
|
172
|
|
|
* @param type $user_id |
|
173
|
|
|
* |
|
174
|
|
|
* @return type |
|
175
|
|
|
*/ |
|
176
|
|
|
public function ticketThread($subject, $body, $id, $user_id) |
|
177
|
|
|
{ |
|
178
|
|
|
try { |
|
179
|
|
|
$thread = new Ticket_Thread(); |
|
180
|
|
|
$thread->user_id = $user_id; |
|
|
|
|
|
|
181
|
|
|
$thread->ticket_id = $id; |
|
|
|
|
|
|
182
|
|
|
$thread->poster = 'client'; |
|
|
|
|
|
|
183
|
|
|
$thread->title = $subject; |
|
|
|
|
|
|
184
|
|
|
$thread->body = $body; |
|
|
|
|
|
|
185
|
|
|
$thread->save(); |
|
186
|
|
|
|
|
187
|
|
|
return $thread->id; |
|
|
|
|
|
|
188
|
|
|
} catch (\Exception $e) { |
|
189
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
190
|
|
|
} |
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* Generates Ticket Number. |
|
195
|
|
|
* |
|
196
|
|
|
* @param type $ticket_number |
|
197
|
|
|
* |
|
198
|
|
|
* @return type integer |
|
199
|
|
|
*/ |
|
200
|
|
|
public function ticketNumber($ticket_number) |
|
201
|
|
|
{ |
|
202
|
|
|
try { |
|
203
|
|
|
//dd($ticket_number); |
|
204
|
|
|
$number = $ticket_number; |
|
205
|
|
|
$number = explode('-', $number); |
|
206
|
|
|
$number1 = $number[0]; |
|
207
|
|
|
if ($number1 == 'ZZZZ') { |
|
208
|
|
|
$number1 = 'AAAA'; |
|
209
|
|
|
} |
|
210
|
|
|
$number2 = $number[1]; |
|
211
|
|
|
if ($number2 == '9999') { |
|
212
|
|
|
$number2 = '0000'; |
|
213
|
|
|
} |
|
214
|
|
|
$number3 = $number[2]; |
|
215
|
|
|
if ($number3 == '9999999') { |
|
216
|
|
|
$number3 = '0000000'; |
|
217
|
|
|
} |
|
218
|
|
|
$number1++; |
|
219
|
|
|
$number2++; |
|
220
|
|
|
$number3++; |
|
221
|
|
|
$number2 = sprintf('%04s', $number2); |
|
222
|
|
|
$number3 = sprintf('%07s', $number3); |
|
223
|
|
|
$array = [$number1, $number2, $number3]; |
|
224
|
|
|
$number = implode('-', $array); |
|
225
|
|
|
|
|
226
|
|
|
return $number; |
|
227
|
|
|
} catch (\Exception $e) { |
|
228
|
|
|
dd($e); |
|
229
|
|
|
|
|
230
|
|
|
return $e->getMessage(); |
|
231
|
|
|
} |
|
232
|
|
|
} |
|
233
|
|
|
|
|
234
|
|
|
/** |
|
235
|
|
|
* Generate a random string for password. |
|
236
|
|
|
* |
|
237
|
|
|
* @param type $length |
|
238
|
|
|
* |
|
239
|
|
|
* @return type string |
|
240
|
|
|
*/ |
|
241
|
|
View Code Duplication |
public function generateRandomString($length = 10) |
|
|
|
|
|
|
242
|
|
|
{ |
|
243
|
|
|
try { |
|
244
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
|
245
|
|
|
$charactersLength = strlen($characters); |
|
246
|
|
|
$randomString = ''; |
|
247
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
248
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)]; |
|
249
|
|
|
} |
|
250
|
|
|
|
|
251
|
|
|
return $randomString; |
|
252
|
|
|
} catch (\Exception $e) { |
|
253
|
|
|
return $e->getMessage(); |
|
254
|
|
|
} |
|
255
|
|
|
} |
|
256
|
|
|
|
|
257
|
|
|
/** |
|
258
|
|
|
* Replying a ticket. |
|
259
|
|
|
* |
|
260
|
|
|
* @param type Ticket_Thread $thread |
|
261
|
|
|
* @param type TicketRequest $request |
|
262
|
|
|
* |
|
263
|
|
|
* @return type bool |
|
264
|
|
|
*/ |
|
265
|
|
|
public function reply($thread, $request, $ta, $attach = '') |
|
|
|
|
|
|
266
|
|
|
{ |
|
267
|
|
|
try { |
|
268
|
|
|
$check_attachment = null; |
|
|
|
|
|
|
269
|
|
|
$eventthread = $thread->where('ticket_id', $request->input('ticket_ID'))->first(); |
|
270
|
|
|
//dd($request->input('ticket_ID')); |
|
|
|
|
|
|
271
|
|
|
//dd($eventthread); |
|
272
|
|
|
$eventuserid = $eventthread->user_id; |
|
273
|
|
|
$emailadd = User::where('id', $eventuserid)->first()->email; |
|
274
|
|
|
//dd($emailadd); |
|
275
|
|
|
$source = $eventthread->source; |
|
276
|
|
|
|
|
277
|
|
|
$form_data = $request->except('reply_content', 'ticket_ID', 'attachment'); |
|
278
|
|
|
\Event::fire(new \App\Events\ClientTicketFormPost($form_data, $emailadd, $source)); |
|
279
|
|
|
//dd('yes'); |
|
280
|
|
|
$reply_content = $request->input('reply_content'); |
|
281
|
|
|
$thread->ticket_id = $request->input('ticket_ID'); |
|
282
|
|
|
$thread->poster = 'support'; |
|
283
|
|
|
$thread->body = $request->input('reply_content'); |
|
284
|
|
|
$thread->user_id = Auth::user()->id; |
|
285
|
|
|
$ticket_id = $request->input('ticket_ID'); |
|
286
|
|
|
$tickets = Tickets::where('id', '=', $ticket_id)->first(); |
|
287
|
|
|
$tickets->isanswered = '1'; |
|
288
|
|
|
$tickets->save(); |
|
289
|
|
|
|
|
290
|
|
|
$ticket_user = User::where('id', '=', $tickets->user_id)->first(); |
|
291
|
|
|
|
|
292
|
|
|
if ($tickets->assigned_to == 0) { |
|
293
|
|
|
$tickets->assigned_to = Auth::user()->id; |
|
294
|
|
|
$tickets->save(); |
|
295
|
|
|
$thread2 = new Ticket_Thread(); |
|
296
|
|
|
$thread2->ticket_id = $thread->ticket_id; |
|
|
|
|
|
|
297
|
|
|
$thread2->user_id = Auth::user()->id; |
|
|
|
|
|
|
298
|
|
|
$thread2->is_internal = 1; |
|
|
|
|
|
|
299
|
|
|
$thread2->body = 'This Ticket have been assigned to '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
|
|
300
|
|
|
$thread2->save(); |
|
301
|
|
|
} |
|
302
|
|
|
if ($tickets->status > 1) { |
|
303
|
|
|
$tickets->status = '1'; |
|
304
|
|
|
$tickets->isanswered = '1'; |
|
305
|
|
|
$tickets->save(); |
|
306
|
|
|
} |
|
307
|
|
|
$thread->save(); |
|
308
|
|
|
|
|
309
|
|
|
if (!empty($attach)) { |
|
310
|
|
|
$check_attachment = $this->attach($thread->id, $attach); |
|
|
|
|
|
|
311
|
|
|
} |
|
312
|
|
|
|
|
313
|
|
|
$thread1 = Ticket_Thread::where('ticket_id', '=', $ticket_id)->first(); |
|
314
|
|
|
$ticket_subject = $thread1->title; |
|
|
|
|
|
|
315
|
|
|
$user_id = $tickets->user_id; |
|
316
|
|
|
$user = User::where('id', '=', $user_id)->first(); |
|
317
|
|
|
$email = $user->email; |
|
318
|
|
|
$user_name = $user->user_name; |
|
319
|
|
|
$ticket_number = $tickets->ticket_number; |
|
|
|
|
|
|
320
|
|
|
$company = $this->company(); |
|
|
|
|
|
|
321
|
|
|
$username = $ticket_user->user_name; |
|
322
|
|
View Code Duplication |
if (!empty(Auth::user()->agent_sign)) { |
|
|
|
|
|
|
323
|
|
|
$agentsign = Auth::user()->agent_sign; |
|
|
|
|
|
|
324
|
|
|
} else { |
|
325
|
|
|
$agentsign = null; |
|
|
|
|
|
|
326
|
|
|
} |
|
327
|
|
|
\Event::fire(new \App\Events\FaveoAfterReply($reply_content, $user->phone_number, $request, $tickets)); |
|
328
|
|
|
|
|
329
|
|
|
// Mail::send(array('html' => 'emails.ticket_re-reply'), ['content' => $reply_content, 'ticket_number' => $ticket_number, 'From' => $company, 'name' => $username, 'Agent_Signature' => $agentsign], function ($message) use ($email, $user_name, $ticket_number, $ticket_subject, $check_attachment) { |
|
|
|
|
|
|
330
|
|
|
// $message->to($email, $user_name)->subject($ticket_subject . '[#' . $ticket_number . ']'); |
|
331
|
|
|
// // if(isset($attachments)){ |
|
332
|
|
|
// // if ($check_attachment == 1) { |
|
333
|
|
|
// // $size = count($attach); |
|
334
|
|
|
// // for ($i = 0; $i < $size; $i++) { |
|
335
|
|
|
// // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); |
|
336
|
|
|
// // } |
|
337
|
|
|
// // } |
|
338
|
|
|
// }, true); |
|
339
|
|
|
//dd('reply'); |
|
340
|
|
|
/* |
|
341
|
|
|
* Getting the subject of the thread |
|
342
|
|
|
*/ |
|
343
|
|
|
//dd($eventthread); |
|
344
|
|
|
try { |
|
345
|
|
|
$re = $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $tickets->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $eventthread->title, 'scenario' => 'create-ticket-by-agent', 'body' => $thread->body], $template_variables = ['agent_sign' => Auth::user()->agent_sign, 'ticket_number' => $tickets->number]); |
|
|
|
|
|
|
346
|
|
|
//dd($re); |
|
347
|
|
|
} catch (\Exception $e) { |
|
348
|
|
|
throw new \Exception($e->getMessage()); |
|
349
|
|
|
} |
|
350
|
|
|
|
|
351
|
|
|
$collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket_id)->get(); |
|
352
|
|
|
foreach ($collaborators as $collaborator) { |
|
353
|
|
|
//mail to collaborators |
|
354
|
|
|
$collab_user_id = $collaborator->user_id; |
|
355
|
|
|
$user_id_collab = User::where('id', '=', $collab_user_id)->first(); |
|
356
|
|
|
$collab_email = $user_id_collab->email; |
|
|
|
|
|
|
357
|
|
|
if ($user_id_collab->role == 'user') { |
|
358
|
|
|
$collab_user_name = $user_id_collab->user_name; |
|
|
|
|
|
|
359
|
|
|
} else { |
|
360
|
|
|
$collab_user_name = $user_id_collab->first_name.' '.$user_id_collab->last_name; |
|
|
|
|
|
|
361
|
|
|
} |
|
362
|
|
|
// Mail::send('emails.ticket_re-reply', ['content' => $reply_content, 'ticket_number' => $ticket_number, 'From' => $company, 'name' => $collab_user_name, 'Agent_Signature' => $agentsign], function ($message) use ($collab_email, $collab_user_name, $ticket_number, $ticket_subject, $check_attachment) { |
|
|
|
|
|
|
363
|
|
|
// $message->to($collab_email, $collab_user_name)->subject($ticket_subject . '[#' . $ticket_number . ']'); |
|
364
|
|
|
// // if ($check_attachment == 1) { |
|
365
|
|
|
// // $size = sizeOf($attachments); |
|
366
|
|
|
// // for ($i = 0; $i < $size; $i++) { |
|
367
|
|
|
// // $message->attach($attachments[$i]->getRealPath(), ['as' => $attachments[$i]->getClientOriginalName(), 'mime' => $attachments[$i]->getClientOriginalExtension()]); |
|
368
|
|
|
// // } |
|
369
|
|
|
// // } |
|
370
|
|
|
// }, true); |
|
371
|
|
|
|
|
372
|
|
|
try { |
|
373
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['user' => $admin_user, 'email' => $admin_email], $message = ['subject' => $updated_subject, 'body' => $body, 'scenario' => $mail], $template_variables = ['ticket_agent_name' => $admin_user, 'ticket_client_name' => $username, 'ticket_client_email' => $emailadd, 'user' => $admin_user, 'ticket_number' => $ticket_number2, 'email_address' => $emailadd, 'name' => $ticket_creator]); |
|
|
|
|
|
|
374
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
375
|
|
|
} |
|
376
|
|
|
} |
|
377
|
|
|
|
|
378
|
|
|
return $thread; |
|
379
|
|
|
} catch (\Exception $e) { |
|
380
|
|
|
//dd($e); |
|
381
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
382
|
|
|
} |
|
383
|
|
|
} |
|
384
|
|
|
|
|
385
|
|
|
/** |
|
386
|
|
|
* company. |
|
387
|
|
|
* |
|
388
|
|
|
* @return type |
|
389
|
|
|
*/ |
|
390
|
|
View Code Duplication |
public function company() |
|
|
|
|
|
|
391
|
|
|
{ |
|
392
|
|
|
try { |
|
393
|
|
|
$company = Company::Where('id', '=', '1')->first(); |
|
394
|
|
|
if ($company->company_name == null) { |
|
395
|
|
|
$company = 'Support Center'; |
|
396
|
|
|
} else { |
|
397
|
|
|
$company = $company->company_name; |
|
398
|
|
|
} |
|
399
|
|
|
|
|
400
|
|
|
return $company; |
|
401
|
|
|
} catch (\Exception $e) { |
|
402
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
403
|
|
|
} |
|
404
|
|
|
} |
|
405
|
|
|
|
|
406
|
|
|
/** |
|
407
|
|
|
* Ticket edit and save ticket data. |
|
408
|
|
|
* |
|
409
|
|
|
* @param type $ticket_id |
|
410
|
|
|
* @param type Ticket_Thread $thread |
|
411
|
|
|
* |
|
412
|
|
|
* @return type bool |
|
413
|
|
|
*/ |
|
414
|
|
|
public function ticketEditPost($ticket_id, $thread, $ticket) |
|
415
|
|
|
{ |
|
416
|
|
|
try { |
|
417
|
|
|
$ticket = $ticket->where('id', '=', $ticket_id)->first(); |
|
418
|
|
|
|
|
419
|
|
|
$ticket->sla = Input::get('sla_plan'); |
|
420
|
|
|
$ticket->help_topic_id = Input::get('help_topic'); |
|
421
|
|
|
$ticket->source = Input::get('ticket_source'); |
|
422
|
|
|
$ticket->priority_id = Input::get('ticket_priority'); |
|
423
|
|
|
$ticket->status = Input::get('status'); |
|
424
|
|
|
$ticket->save(); |
|
425
|
|
|
|
|
426
|
|
|
$threads = $thread->where('ticket_id', '=', $ticket_id)->first(); |
|
427
|
|
|
$threads->title = Input::get('subject'); |
|
428
|
|
|
$threads->save(); |
|
429
|
|
|
|
|
430
|
|
|
return $threads; |
|
431
|
|
|
} catch (\Exception $e) { |
|
432
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
433
|
|
|
} |
|
434
|
|
|
} |
|
435
|
|
|
|
|
436
|
|
|
/** |
|
437
|
|
|
* function to assign ticket. |
|
438
|
|
|
* |
|
439
|
|
|
* @param type $id |
|
440
|
|
|
* |
|
441
|
|
|
* @return type bool |
|
442
|
|
|
*/ |
|
443
|
|
|
public function assign($id) |
|
444
|
|
|
{ |
|
445
|
|
|
try { |
|
446
|
|
|
$UserEmail = Input::get('user'); |
|
447
|
|
|
//dd($UserEmail); |
|
448
|
|
|
// $UserEmail = '[email protected]'; |
|
|
|
|
|
|
449
|
|
|
$user = User::where('email', '=', $UserEmail)->first(); |
|
450
|
|
|
if (!$user) { |
|
451
|
|
|
return ['error' => 'No agent not found']; |
|
452
|
|
|
} |
|
453
|
|
|
$user_id = $user->id; |
|
454
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
|
455
|
|
|
if (!$ticket) { |
|
456
|
|
|
return ['error' => 'No ticket not found']; |
|
457
|
|
|
} |
|
458
|
|
|
$ticket_number = $ticket->ticket_number; |
|
459
|
|
|
$ticket->assigned_to = $user_id; |
|
460
|
|
|
$ticket->save(); |
|
461
|
|
|
$ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
|
462
|
|
|
if (!$ticket_thread) { |
|
463
|
|
|
return ['error' => 'No thread not found']; |
|
464
|
|
|
} |
|
465
|
|
|
$ticket_subject = $ticket_thread->title; |
|
466
|
|
|
$thread = new Ticket_Thread(); |
|
467
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
|
|
468
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
|
|
469
|
|
|
$thread->is_internal = 1; |
|
|
|
|
|
|
470
|
|
|
$thread->body = 'This Ticket has been assigned to '.$user->first_name.' '.$user->last_name; |
|
|
|
|
|
|
471
|
|
|
$thread->save(); |
|
472
|
|
|
|
|
473
|
|
|
$company = $this->company(); |
|
|
|
|
|
|
474
|
|
|
$system = $this->system(); |
|
|
|
|
|
|
475
|
|
|
|
|
476
|
|
|
$agent = $user->first_name; |
|
477
|
|
|
$agent_email = $user->email; |
|
478
|
|
|
|
|
479
|
|
|
$master = Auth::user()->first_name.' '.Auth::user()->last_name; |
|
480
|
|
|
if (Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) { |
|
481
|
|
|
// // ticket assigned send mail |
|
482
|
|
|
// Mail::send('emails.Ticket_assign', ['agent' => $agent, 'ticket_number' => $ticket_number, 'from' => $company, 'master' => $master, 'system' => $system], function ($message) use ($agent_email, $agent, $ticket_number, $ticket_subject) { |
|
|
|
|
|
|
483
|
|
|
// $message->to($agent_email, $agent)->subject($ticket_subject . '[#' . $ticket_number . ']'); |
|
|
|
|
|
|
484
|
|
|
// }); |
|
485
|
|
|
|
|
486
|
|
|
try { |
|
487
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket->dept_id), $to = ['name' => $agent, 'email' => $agent_email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'assign-ticket'], $template_variables = ['ticket_agent_name' => $agent, 'ticket_number' => $ticket_number, 'ticket_assigner' => $master]); |
|
488
|
|
|
} catch (\Exception $e) { |
|
489
|
|
|
return 0; |
|
490
|
|
|
} |
|
491
|
|
|
} |
|
492
|
|
|
|
|
493
|
|
|
return 1; |
|
494
|
|
|
} catch (\Exception $e) { |
|
495
|
|
|
return $e->getMessage(); |
|
496
|
|
|
} |
|
497
|
|
|
} |
|
498
|
|
|
|
|
499
|
|
|
/** |
|
500
|
|
|
* Function to delete ticket. |
|
501
|
|
|
* |
|
502
|
|
|
* @param type $id |
|
|
|
|
|
|
503
|
|
|
* @param type Tickets $ticket |
|
504
|
|
|
* |
|
505
|
|
|
* @return type string |
|
506
|
|
|
*/ |
|
507
|
|
|
public function delete($ids, $ticket) |
|
508
|
|
|
{ |
|
509
|
|
|
try { |
|
510
|
|
|
foreach ($ids as $id) { |
|
511
|
|
|
$ticket_delete = $ticket->where('id', '=', $id)->first(); |
|
512
|
|
|
if ($ticket_delete) { |
|
513
|
|
|
if ($ticket_delete->status == 5) { |
|
514
|
|
|
$ticket_delete->delete(); |
|
515
|
|
|
$ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get(); |
|
516
|
|
|
if ($ticket_threads) { |
|
517
|
|
|
foreach ($ticket_threads as $ticket_thread) { |
|
518
|
|
|
if ($ticket_thread) { |
|
519
|
|
|
$ticket_thread->delete(); |
|
520
|
|
|
} |
|
521
|
|
|
} |
|
522
|
|
|
} |
|
523
|
|
|
$ticket_attachments = Ticket_attachments::where('thread_id', '=', $id)->get(); |
|
524
|
|
|
if ($ticket_attachments) { |
|
525
|
|
|
foreach ($ticket_attachments as $ticket_attachment) { |
|
526
|
|
|
if ($ticket_attachment) { |
|
527
|
|
|
$ticket_attachment->delete(); |
|
528
|
|
|
} |
|
529
|
|
|
} |
|
530
|
|
|
} |
|
531
|
|
|
} else { |
|
532
|
|
|
$ticket_delete->is_deleted = 0; |
|
533
|
|
|
$ticket_delete->status = 5; |
|
534
|
|
|
$ticket_delete->save(); |
|
535
|
|
|
$ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first(); |
|
536
|
|
|
$thread = new Ticket_Thread(); |
|
537
|
|
|
$thread->ticket_id = $ticket_delete->id; |
|
|
|
|
|
|
538
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
|
|
539
|
|
|
$thread->is_internal = 1; |
|
|
|
|
|
|
540
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
|
|
541
|
|
|
$thread->save(); |
|
542
|
|
|
} |
|
543
|
|
|
} else { |
|
544
|
|
|
return 'ticket not found'; |
|
545
|
|
|
} |
|
546
|
|
|
} |
|
547
|
|
|
|
|
548
|
|
|
return 'your tickets has been deleted'; |
|
549
|
|
|
} catch (\Exception $e) { |
|
550
|
|
|
return $e->getMessage(); |
|
551
|
|
|
} |
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
/** |
|
555
|
|
|
* check email for dublicate entry. |
|
556
|
|
|
* |
|
557
|
|
|
* @param type $email |
|
558
|
|
|
* |
|
559
|
|
|
* @return type bool |
|
560
|
|
|
*/ |
|
561
|
|
|
public function checkEmail($email) |
|
562
|
|
|
{ |
|
563
|
|
|
try { |
|
564
|
|
|
$check = User::where('email', '=', $email)->first(); |
|
565
|
|
|
if ($check) { |
|
566
|
|
|
return $check; |
|
567
|
|
|
} else { |
|
568
|
|
|
return false; |
|
|
|
|
|
|
569
|
|
|
} |
|
570
|
|
|
} catch (\Exception $e) { |
|
571
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
572
|
|
|
} |
|
573
|
|
|
} |
|
574
|
|
|
|
|
575
|
|
|
/** |
|
576
|
|
|
* system. |
|
577
|
|
|
* |
|
578
|
|
|
* @return type |
|
579
|
|
|
*/ |
|
580
|
|
View Code Duplication |
public function system() |
|
|
|
|
|
|
581
|
|
|
{ |
|
582
|
|
|
try { |
|
583
|
|
|
$system = System::Where('id', '=', '1')->first(); |
|
584
|
|
|
if ($system->name == null) { |
|
585
|
|
|
$system = 'Support Center'; |
|
586
|
|
|
} else { |
|
587
|
|
|
$system = $system->name; |
|
588
|
|
|
} |
|
589
|
|
|
|
|
590
|
|
|
return $system; |
|
591
|
|
|
} catch (\Exception $e) { |
|
592
|
|
|
return $e->getMessage(); |
|
|
|
|
|
|
593
|
|
|
} |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
/** |
|
597
|
|
|
* Create Attachment. |
|
598
|
|
|
* |
|
599
|
|
|
* @param type $thread |
|
600
|
|
|
* @param type $attach |
|
601
|
|
|
* |
|
602
|
|
|
* @return int |
|
603
|
|
|
*/ |
|
604
|
|
|
public function attach($thread, $attach) |
|
605
|
|
|
{ |
|
606
|
|
|
try { |
|
607
|
|
|
$ta = new Ticket_attachments(); |
|
608
|
|
|
foreach ($attach as $file) { |
|
609
|
|
|
$ta->create(['thread_id' => $thread, 'name' => $file['name'], 'size' => $file['size'], 'type' => $file['type'], 'file' => $file['file'], 'poster' => 'ATTACHMENT']); |
|
610
|
|
|
} |
|
611
|
|
|
$ta->create(['thread_id' => $thread, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $file, 'poster' => 'ATTACHMENT']); |
|
|
|
|
|
|
612
|
|
|
|
|
613
|
|
|
return 1; |
|
614
|
|
|
} catch (\Exception $e) { |
|
615
|
|
|
return $e->getMessage(); |
|
616
|
|
|
} |
|
617
|
|
|
} |
|
618
|
|
|
|
|
619
|
|
|
/** |
|
620
|
|
|
* autosearch. |
|
621
|
|
|
* |
|
622
|
|
|
* @return type json |
|
623
|
|
|
*/ |
|
624
|
|
|
public function autosearch() |
|
625
|
|
|
{ |
|
626
|
|
|
$term = \Input::get('term'); |
|
627
|
|
|
$user = \App\User::where('email', 'LIKE', '%'.$term.'%')->orWhere('first_name', 'LIKE', '%'.$term.'%')->orWhere('last_name', 'LIKE', '%'.$term.'%')->orWhere('user_name', 'LIKE', '%'.$term.'%')->lists('email'); |
|
628
|
|
|
|
|
629
|
|
|
return $user; |
|
630
|
|
|
} |
|
631
|
|
|
|
|
632
|
|
|
/** |
|
633
|
|
|
* useradd. |
|
634
|
|
|
* |
|
635
|
|
|
* @param type Image $image |
|
636
|
|
|
* |
|
637
|
|
|
* @return type json |
|
638
|
|
|
*/ |
|
639
|
|
|
public function useradd() |
|
640
|
|
|
{ |
|
641
|
|
|
$email = Input::get('email'); |
|
642
|
|
|
$ticket_id = Input::get('ticket_id'); |
|
643
|
|
|
$company = $this->company(); |
|
|
|
|
|
|
644
|
|
|
$user = new User(); |
|
645
|
|
|
$user->user_name = $email; |
|
|
|
|
|
|
646
|
|
|
$user->email = $email; |
|
|
|
|
|
|
647
|
|
|
$password = $this->generateRandomString(); |
|
648
|
|
|
$user->password = \Hash::make($password); |
|
|
|
|
|
|
649
|
|
|
$user->role = 'user'; |
|
|
|
|
|
|
650
|
|
|
$user->active = 1; |
|
|
|
|
|
|
651
|
|
|
if ($user->save()) { |
|
652
|
|
|
$user_id = $user->id; |
|
|
|
|
|
|
653
|
|
|
$php_mailer = new PhpMailController(); |
|
654
|
|
|
$php_mailer->sendmail($from = $php_mailer->mailfrom('1', '0'), $to = ['name' => $email, 'email' => $email], $message = ['subject' => 'Password', 'scenario' => 'registration-notification'], $template_variables = ['user' => $email, 'email_address' => $email, 'user_password' => $password]); |
|
655
|
|
|
} |
|
656
|
|
|
$ticket_collaborator = new Ticket_Collaborator(); |
|
657
|
|
|
$ticket_collaborator->isactive = 1; |
|
|
|
|
|
|
658
|
|
|
$ticket_collaborator->ticket_id = $ticket_id; |
|
|
|
|
|
|
659
|
|
|
$ticket_collaborator->user_id = $user->id; |
|
|
|
|
|
|
660
|
|
|
$ticket_collaborator->role = 'ccc'; |
|
|
|
|
|
|
661
|
|
|
$ticket_collaborator->save(); |
|
662
|
|
|
|
|
663
|
|
|
$result = [$user->user_name => $user->email]; |
|
|
|
|
|
|
664
|
|
|
|
|
665
|
|
|
return $result; |
|
666
|
|
|
} |
|
667
|
|
|
|
|
668
|
|
|
/** |
|
669
|
|
|
* user remove. |
|
670
|
|
|
* |
|
671
|
|
|
* @return type |
|
672
|
|
|
*/ |
|
673
|
|
View Code Duplication |
public function userremove() |
|
|
|
|
|
|
674
|
|
|
{ |
|
675
|
|
|
$email = Input::get('email'); |
|
676
|
|
|
$ticketid = Input::get('ticketid'); |
|
677
|
|
|
$user = new User(); |
|
678
|
|
|
$user = $user->where('email', $email)->first(); |
|
|
|
|
|
|
679
|
|
|
$ticket_collaborator = Ticket_Collaborator::where('ticket_id', '=', $ticketid) |
|
680
|
|
|
->where('user_id', $user->id) |
|
681
|
|
|
->first(); |
|
682
|
|
|
if ($ticket_collaborator) { |
|
683
|
|
|
$ticket_collaborator->delete(); |
|
684
|
|
|
|
|
685
|
|
|
return 'deleted successfully'; |
|
686
|
|
|
} else { |
|
687
|
|
|
return 'not found'; |
|
688
|
|
|
} |
|
689
|
|
|
} |
|
690
|
|
|
|
|
691
|
|
|
public function getCollaboratorForTicket() |
|
692
|
|
|
{ |
|
693
|
|
|
try { |
|
694
|
|
|
$ticketid = Input::get('ticket_id'); |
|
695
|
|
|
|
|
696
|
|
|
$ticket_collaborator = \DB::table('users') |
|
697
|
|
|
->join('ticket_collaborator', function ($join) use ($ticketid) { |
|
698
|
|
|
$join->on('users.id', '=', 'ticket_collaborator.user_id') |
|
699
|
|
|
->where('ticket_collaborator.ticket_id', '=', $ticketid); |
|
700
|
|
|
}) |
|
701
|
|
|
->select('users.email', 'users.user_name') |
|
702
|
|
|
->get(); |
|
703
|
|
|
if (count($ticket_collaborator) > 0) { |
|
704
|
|
|
foreach ($ticket_collaborator as $key => $collaborator) { |
|
705
|
|
|
$collab[$key]['email'] = $collaborator->email; |
|
|
|
|
|
|
706
|
|
|
$collab[$key]['user_name'] = $collaborator->user_name; |
|
707
|
|
|
$collab[$key]['avatar'] = $this->avatarUrl($collaborator->email); |
|
708
|
|
|
} |
|
709
|
|
|
} else { |
|
710
|
|
|
$collab = $ticket_collaborator; |
|
711
|
|
|
} |
|
712
|
|
|
|
|
713
|
|
|
return $collab; |
|
|
|
|
|
|
714
|
|
|
} catch (\Exception $ex) { |
|
715
|
|
|
return $ex->getMessage(); |
|
716
|
|
|
throw new \Exception('get collaborator for ticket fails'); |
|
|
|
|
|
|
717
|
|
|
} |
|
718
|
|
|
} |
|
719
|
|
|
|
|
720
|
|
View Code Duplication |
public function avatarUrl($email) |
|
|
|
|
|
|
721
|
|
|
{ |
|
722
|
|
|
try { |
|
723
|
|
|
$user = new User(); |
|
724
|
|
|
$user = $user->where('email', $email)->first(); |
|
|
|
|
|
|
725
|
|
|
if ($user->profile_pic) { |
|
726
|
|
|
$url = url('uploads/profilepic/'.$user->profile_pic); |
|
727
|
|
|
} else { |
|
728
|
|
|
$url = \Gravatar::src($email); |
|
729
|
|
|
} |
|
730
|
|
|
|
|
731
|
|
|
return $url; |
|
732
|
|
|
} catch (\Exception $ex) { |
|
733
|
|
|
//return $ex->getMessage(); |
|
|
|
|
|
|
734
|
|
|
throw new \Exception($ex->getMessage()); |
|
735
|
|
|
} |
|
736
|
|
|
} |
|
737
|
|
|
} |
|
738
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.