1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\Agent\helpdesk; |
4
|
|
|
|
5
|
|
|
// controllers |
6
|
|
|
use App\Http\Controllers\Common\FileuploadController; |
7
|
|
|
use App\Http\Controllers\Common\NotificationController as Notify; |
8
|
|
|
use App\Http\Controllers\Common\PhpMailController; |
9
|
|
|
use App\Http\Controllers\Controller; |
10
|
|
|
// requests |
11
|
|
|
use App\Http\Requests\helpdesk\CreateTicketRequest; |
12
|
|
|
use App\Http\Requests\helpdesk\TicketRequest; |
13
|
|
|
// models |
14
|
|
|
use App\Model\helpdesk\Agent\Department; |
15
|
|
|
use App\Model\helpdesk\Agent\Teams; |
16
|
|
|
use App\Model\helpdesk\Email\Emails; |
17
|
|
|
use App\Model\helpdesk\Form\Fields; |
18
|
|
|
use App\Model\helpdesk\Manage\Help_topic; |
19
|
|
|
use App\Model\helpdesk\Manage\Sla_plan; |
20
|
|
|
use App\Model\helpdesk\Notification\Notification; |
21
|
|
|
use App\Model\helpdesk\Notification\UserNotification; |
22
|
|
|
use App\Model\helpdesk\Settings\Alert; |
23
|
|
|
use App\Model\helpdesk\Settings\CommonSettings; |
24
|
|
|
use App\Model\helpdesk\Settings\Company; |
25
|
|
|
use App\Model\helpdesk\Settings\Email; |
26
|
|
|
use App\Model\helpdesk\Settings\System; |
27
|
|
|
use App\Model\helpdesk\Ticket\Ticket_attachments; |
28
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Collaborator; |
29
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Form_Data; |
30
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Priority; |
31
|
|
|
use App\Model\helpdesk\Ticket\Ticket_source; |
32
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Status; |
33
|
|
|
use App\Model\helpdesk\Ticket\Ticket_Thread; |
34
|
|
|
use App\Model\helpdesk\Ticket\Tickets; |
35
|
|
|
use App\Model\helpdesk\Utility\CountryCode; |
36
|
|
|
use App\Model\helpdesk\Utility\Date_time_format; |
37
|
|
|
use App\Model\helpdesk\Utility\Timezones; |
38
|
|
|
use App\User; |
39
|
|
|
use Auth; |
40
|
|
|
use DB; |
41
|
|
|
use Exception; |
42
|
|
|
use GeoIP; |
43
|
|
|
// classes |
44
|
|
|
use Hash; |
45
|
|
|
use Illuminate\Http\Request; |
46
|
|
|
use Illuminate\support\Collection; |
47
|
|
|
use Input; |
48
|
|
|
use Lang; |
49
|
|
|
use Mail; |
50
|
|
|
use PDF; |
51
|
|
|
use UTC; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* TicketController. |
55
|
|
|
* |
56
|
|
|
* @author Ladybird <[email protected]> |
57
|
|
|
*/ |
58
|
|
|
class TicketController extends Controller |
59
|
|
|
{ |
60
|
|
|
/** |
61
|
|
|
* Create a new controller instance. |
62
|
|
|
* |
63
|
|
|
* @return type response |
|
|
|
|
64
|
|
|
*/ |
65
|
|
|
public function __construct(PhpMailController $PhpMailController, Notify $NotificationController) |
66
|
|
|
{ |
67
|
|
|
$this->PhpMailController = $PhpMailController; |
|
|
|
|
68
|
|
|
$this->NotificationController = $NotificationController; |
|
|
|
|
69
|
|
|
$this->middleware('auth'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Show the Inbox ticket list page. |
74
|
|
|
* |
75
|
|
|
* @return type response |
76
|
|
|
*/ |
77
|
|
View Code Duplication |
public function inbox_ticket_list() |
|
|
|
|
78
|
|
|
{ |
79
|
|
|
$table = \Datatable::table() |
80
|
|
|
->addColumn( |
81
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
82
|
|
|
->noScript(); |
83
|
|
|
|
84
|
|
|
return view('themes.default1.agent.helpdesk.ticket.inbox', compact('table')); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Show the Open ticket list page. |
89
|
|
|
* |
90
|
|
|
* @return type response |
91
|
|
|
*/ |
92
|
|
View Code Duplication |
public function open_ticket_list() |
|
|
|
|
93
|
|
|
{ |
94
|
|
|
$table = \Datatable::table() |
95
|
|
|
->addColumn( |
96
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
97
|
|
|
->noScript(); |
98
|
|
|
|
99
|
|
|
return view('themes.default1.agent.helpdesk.ticket.open', compact('table')); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Show the answered ticket list page. |
104
|
|
|
* |
105
|
|
|
* @return type response |
106
|
|
|
*/ |
107
|
|
View Code Duplication |
public function answered_ticket_list() |
|
|
|
|
108
|
|
|
{ |
109
|
|
|
$table = \Datatable::table() |
110
|
|
|
->addColumn( |
111
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
112
|
|
|
->noScript(); |
113
|
|
|
|
114
|
|
|
return view('themes.default1.agent.helpdesk.ticket.answered', compact('table')); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Show the Myticket list page. |
119
|
|
|
* |
120
|
|
|
* @return type response |
121
|
|
|
*/ |
122
|
|
View Code Duplication |
public function myticket_ticket_list() |
|
|
|
|
123
|
|
|
{ |
124
|
|
|
$table = \Datatable::table() |
125
|
|
|
->addColumn( |
126
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
127
|
|
|
->noScript(); |
128
|
|
|
|
129
|
|
|
return view('themes.default1.agent.helpdesk.ticket.myticket', compact('table')); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Show the Overdue ticket list page. |
134
|
|
|
* |
135
|
|
|
* @return type response |
136
|
|
|
*/ |
137
|
|
View Code Duplication |
public function overdue_ticket_list() |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
$table = \Datatable::table() |
140
|
|
|
->addColumn( |
141
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
142
|
|
|
->noScript(); |
143
|
|
|
|
144
|
|
|
return view('themes.default1.agent.helpdesk.ticket.overdue', compact('table')); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* Show the Open ticket list page. |
149
|
|
|
* |
150
|
|
|
* @return type response |
151
|
|
|
*/ |
152
|
|
View Code Duplication |
public function dueTodayTicketlist() |
|
|
|
|
153
|
|
|
{ |
154
|
|
|
$table = \Datatable::table() |
155
|
|
|
->addColumn( |
156
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
157
|
|
|
->noScript(); |
158
|
|
|
|
159
|
|
|
return view('themes.default1.agent.helpdesk.ticket.duetodayticket', compact('table')); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* Show the Closed ticket list page. |
164
|
|
|
* |
165
|
|
|
* @return type response |
166
|
|
|
*/ |
167
|
|
View Code Duplication |
public function closed_ticket_list() |
|
|
|
|
168
|
|
|
{ |
169
|
|
|
$table = \Datatable::table() |
170
|
|
|
->addColumn( |
171
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
172
|
|
|
->noScript(); |
173
|
|
|
|
174
|
|
|
return view('themes.default1.agent.helpdesk.ticket.closed', compact('table')); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Show the ticket list page. |
179
|
|
|
* |
180
|
|
|
* @return type response |
181
|
|
|
*/ |
182
|
|
View Code Duplication |
public function assigned_ticket_list() |
|
|
|
|
183
|
|
|
{ |
184
|
|
|
$table = \Datatable::table() |
185
|
|
|
->addColumn( |
186
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
187
|
|
|
->noScript(); |
188
|
|
|
|
189
|
|
|
return view('themes.default1.agent.helpdesk.ticket.assigned', compact('table')); |
190
|
|
|
} |
191
|
|
|
|
192
|
|
|
/** |
193
|
|
|
* Show the New ticket page. |
194
|
|
|
* |
195
|
|
|
* @return type response |
196
|
|
|
*/ |
197
|
|
|
public function newticket(CountryCode $code) |
198
|
|
|
{ |
199
|
|
|
$location = GeoIP::getLocation(); |
200
|
|
|
$phonecode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
201
|
|
|
$pcode = ''; |
202
|
|
|
if ($phonecode) { |
203
|
|
|
$pcode = $phonecode->phonecode; |
204
|
|
|
} |
205
|
|
|
$settings = CommonSettings::select('status')->where('option_name', '=', 'send_otp')->first(); |
206
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
207
|
|
|
|
208
|
|
|
return view('themes.default1.agent.helpdesk.ticket.new', compact('email_mandatory', 'settings'))->with('phonecode', $pcode); |
|
|
|
|
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
/** |
212
|
|
|
* Save the data of new ticket and show the New ticket page with result. |
213
|
|
|
* |
214
|
|
|
* @param type CreateTicketRequest $request |
215
|
|
|
* |
216
|
|
|
* @return type response |
217
|
|
|
*/ |
218
|
|
|
public function post_newticket(CreateTicketRequest $request, CountryCode $code, $api = false) |
219
|
|
|
{ |
220
|
|
|
try { |
221
|
|
|
if ($request->input('email')) { |
222
|
|
|
$email = $request->input('email'); |
223
|
|
|
} else { |
224
|
|
|
$email = null; |
225
|
|
|
} |
226
|
|
|
$fullname = $request->input('first_name').'%$%'.$request->input('last_name'); |
227
|
|
|
$helptopic = $request->input('helptopic'); |
228
|
|
|
$sla = $request->input('sla'); |
229
|
|
|
$duedate = $request->input('duedate'); |
|
|
|
|
230
|
|
|
if ($request->input('assignto')) { |
231
|
|
|
$assignto = $request->input('assignto'); |
232
|
|
|
} else { |
233
|
|
|
$assignto = null; |
234
|
|
|
} |
235
|
|
|
$subject = $request->input('subject'); |
236
|
|
|
$body = $request->input('body'); |
237
|
|
|
$priority = $request->input('priority'); |
238
|
|
|
$phone = $request->input('phone'); |
239
|
|
|
$phonecode = $request->input('code'); |
240
|
|
|
if ($request->input('mobile')) { |
241
|
|
|
$mobile_number = $request->input('mobile'); |
242
|
|
|
} else { |
243
|
|
|
$mobile_number = null; |
244
|
|
|
} |
245
|
|
|
$source = Ticket_source::where('name', '=', 'agent')->first(); |
246
|
|
|
$headers = null; |
247
|
|
|
$help = Help_topic::where('id', '=', $helptopic)->first(); |
248
|
|
|
$form_data = null; |
249
|
|
|
$auto_response = 0; |
250
|
|
|
$status = 1; |
251
|
|
|
if ($phone != null || $mobile_number != null) { |
|
|
|
|
252
|
|
|
$location = GeoIP::getLocation(); |
253
|
|
|
$geoipcode = $code->where('iso', '=', $location->iso_code)->first(); |
|
|
|
|
254
|
|
|
if ($phonecode == null) { |
255
|
|
|
$data = [ |
256
|
|
|
'fails' => Lang::get('lang.country-code-required-error'), |
257
|
|
|
'phonecode' => $geoipcode->phonecode, |
258
|
|
|
'country_code_error' => 1, |
259
|
|
|
]; |
260
|
|
|
if ($api != false) { |
|
|
|
|
261
|
|
|
return $data; |
|
|
|
|
262
|
|
|
} |
263
|
|
|
|
264
|
|
|
return Redirect()->back()->with($data)->withInput($request->except('password')); |
|
|
|
|
265
|
|
|
} else { |
266
|
|
|
$code = CountryCode::select('phonecode')->where('phonecode', '=', $phonecode)->get(); |
267
|
|
|
if (!count($code)) { |
268
|
|
|
$data = [ |
269
|
|
|
'fails' => Lang::get('lang.incorrect-country-code-error'), |
270
|
|
|
'phonecode' => $geoipcode->phonecode, |
271
|
|
|
'country_code_error' => 1, |
272
|
|
|
]; |
273
|
|
|
if ($api != false) { |
|
|
|
|
274
|
|
|
return $data; |
|
|
|
|
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
return Redirect()->back()->with($data)->withInput($request->except('password')); |
|
|
|
|
278
|
|
|
} |
279
|
|
|
} |
280
|
|
|
} |
281
|
|
|
//create user |
282
|
|
|
$result = $this->create_user($email, $fullname, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source->id, $headers, $help->department, $assignto, $form_data, $auto_response, $status); |
|
|
|
|
283
|
|
|
if ($result[1]) { |
284
|
|
|
$status = $this->checkUserVerificationStatus(); |
285
|
|
|
if ($status == 1) { |
286
|
|
|
if ($api != false) { |
|
|
|
|
287
|
|
|
return Lang::get('lang.Ticket-created-successfully'); |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
return Redirect('newticket')->with('success', Lang::get('lang.Ticket-created-successfully')); |
|
|
|
|
291
|
|
|
} else { |
292
|
|
|
if ($api != false) { |
|
|
|
|
293
|
|
|
return Lang::get('lang.Ticket-created-successfully'); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
return Redirect('newticket')->with('success', Lang::get('lang.Ticket-created-successfully2')); |
|
|
|
|
297
|
|
|
} |
298
|
|
|
} else { |
299
|
|
|
if ($api != false) { |
|
|
|
|
300
|
|
|
return Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken'); |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
return Redirect('newticket')->with('fails', Lang::get('lang.failed-to-create-user-tcket-as-mobile-has-been-taken'))->withInput($request->except('password')); |
|
|
|
|
304
|
|
|
} |
305
|
|
|
} catch (Exception $e) { |
306
|
|
|
// dd($e); |
|
|
|
|
307
|
|
|
if ($api != false) { |
|
|
|
|
308
|
|
|
return $e->getMessage(); |
|
|
|
|
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
return Redirect()->back()->with('fails', '<li>'.$e->getMessage().'</li>'); |
|
|
|
|
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|
315
|
|
|
/** |
316
|
|
|
* Shows the ticket thread details. |
317
|
|
|
* |
318
|
|
|
* @param type $id |
319
|
|
|
* |
320
|
|
|
* @return type response |
321
|
|
|
*/ |
322
|
|
|
public function thread($id) |
323
|
|
|
{ |
324
|
|
|
if (Auth::user()->role == 'agent') { |
325
|
|
|
$dept = Department::where('id', '=', Auth::user()->primary_dpt)->first(); |
326
|
|
|
$tickets = Tickets::where('id', '=', $id)->first(); |
327
|
|
|
if ($tickets->dept_id == $dept->id) { |
328
|
|
|
$tickets = $tickets; |
|
|
|
|
329
|
|
|
} elseif ($tickets->assigned_to == Auth::user()->id) { |
330
|
|
|
$tickets = $tickets; |
|
|
|
|
331
|
|
|
} else { |
332
|
|
|
$tickets = null; |
333
|
|
|
} |
334
|
|
|
// $tickets = $tickets->where('dept_id', '=', $dept->id)->orWhere('assigned_to', Auth::user()->id)->first(); |
|
|
|
|
335
|
|
|
// dd($tickets); |
336
|
|
|
} elseif (Auth::user()->role == 'admin') { |
337
|
|
|
$tickets = Tickets::where('id', '=', $id)->first(); |
338
|
|
|
} elseif (Auth::user()->role == 'user') { |
339
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
|
|
|
|
340
|
|
|
$ticket_id = \Crypt::encrypt($id); |
341
|
|
|
|
342
|
|
|
return redirect()->route('check_ticket', compact('ticket_id')); |
343
|
|
|
} |
344
|
|
|
if ($tickets == null) { |
|
|
|
|
345
|
|
|
return redirect()->route('inbox.ticket')->with('fails', \Lang::get('lang.invalid_attempt')); |
346
|
|
|
} |
347
|
|
|
$avg = DB::table('ticket_thread')->where('ticket_id', '=', $id)->where('reply_rating', '!=', 0)->avg('reply_rating'); |
348
|
|
|
$avg_rate = explode('.', $avg); |
349
|
|
|
$avg_rating = $avg_rate[0]; |
350
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
351
|
|
|
$fileupload = new FileuploadController(); |
352
|
|
|
$fileupload = $fileupload->file_upload_max_size(); |
353
|
|
|
$max_size_in_bytes = $fileupload[0]; |
354
|
|
|
$max_size_in_actual = $fileupload[1]; |
355
|
|
|
$tickets_approval = Tickets::where('id', '=', $id)->first(); |
356
|
|
|
|
357
|
|
|
return view('themes.default1.agent.helpdesk.ticket.timeline', compact('tickets', 'max_size_in_bytes', 'max_size_in_actual', 'tickets_approval'), compact('thread', 'avg_rating')); |
358
|
|
|
} |
359
|
|
|
|
360
|
|
View Code Duplication |
public function size() |
|
|
|
|
361
|
|
|
{ |
362
|
|
|
$files = Input::file('attachment'); |
363
|
|
|
if (!$files) { |
364
|
|
|
throw new \Exception('file size exceeded'); |
365
|
|
|
} |
366
|
|
|
$size = 0; |
367
|
|
|
if (count($files) > 0) { |
368
|
|
|
foreach ($files as $file) { |
|
|
|
|
369
|
|
|
$size += $file->getSize(); |
370
|
|
|
} |
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
return $size; |
374
|
|
|
} |
375
|
|
|
|
376
|
|
|
public function error($e, $request) |
377
|
|
|
{ |
378
|
|
|
if ($request->ajax() || $request->wantsJson()) { |
379
|
|
|
$error = $e->getMessage(); |
380
|
|
|
if (is_object($error)) { |
381
|
|
|
$error = $error->toArray(); |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
return response()->json(compact('error')); |
385
|
|
|
//return $message; |
386
|
|
|
} |
387
|
|
|
} |
388
|
|
|
|
389
|
|
|
/** |
390
|
|
|
* Replying a ticket. |
391
|
|
|
* |
392
|
|
|
* @param type Ticket_Thread $thread |
393
|
|
|
* @param type TicketRequest $request |
394
|
|
|
* |
395
|
|
|
* @return type bool |
396
|
|
|
*/ |
397
|
|
|
public function reply(Ticket_Thread $thread, Request $request, Ticket_attachments $ta, $mail = true, $system_reply = true, $user_id = '') |
398
|
|
|
{ |
399
|
|
|
\Event::fire('reply.request', [$request]); |
400
|
|
|
try { |
401
|
|
|
if (is_array($request->file('attachment'))) { |
|
|
|
|
402
|
|
|
} else { |
403
|
|
|
try { |
404
|
|
|
$size = $this->size(); |
405
|
|
|
} catch (Exception $ex) { |
406
|
|
|
return $ex->getMessage(); |
407
|
|
|
} |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
$fileupload = new FileuploadController(); |
411
|
|
|
$fileupload = $fileupload->file_upload_max_size(); |
412
|
|
|
$max_size_in_bytes = $fileupload[0]; |
|
|
|
|
413
|
|
|
$max_size_in_actual = $fileupload[1]; |
|
|
|
|
414
|
|
|
|
415
|
|
|
$attachments = $request->file('attachment'); |
416
|
|
|
$check_attachment = null; |
417
|
|
|
// Event fire |
418
|
|
|
$eventthread = $thread->where('ticket_id', $request->input('ticket_ID'))->first(); |
|
|
|
|
419
|
|
|
//dd($eventthread); |
420
|
|
|
|
421
|
|
|
$eventuserid = $eventthread->user_id; |
422
|
|
|
$emailadd = User::where('id', $eventuserid)->first()->email; |
423
|
|
|
$source = $eventthread->source; |
424
|
|
|
$form_data = $request->except('reply_content', 'ticket_ID', 'attachment'); |
425
|
|
|
\Event::fire(new \App\Events\ClientTicketFormPost($form_data, $emailadd, $source)); |
|
|
|
|
426
|
|
|
$reply_content = $request->input('reply_content'); |
427
|
|
|
|
428
|
|
|
$thread->ticket_id = $request->input('ticket_ID'); |
|
|
|
|
429
|
|
|
$thread->poster = 'support'; |
|
|
|
|
430
|
|
|
$thread->body = $request->input('reply_content'); |
|
|
|
|
431
|
|
|
if ($system_reply == true) { |
|
|
|
|
432
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
433
|
|
|
} else { |
434
|
|
|
$thread->user_id = $eventuserid; |
|
|
|
|
435
|
|
|
if ($user_id !== '') { |
436
|
|
|
$thread->user_id = $user_id; |
|
|
|
|
437
|
|
|
} |
438
|
|
|
} |
439
|
|
|
$ticket_id = $request->input('ticket_ID'); |
440
|
|
|
|
441
|
|
|
$tickets = Tickets::where('id', '=', $ticket_id)->first(); |
442
|
|
|
$tickets->isanswered = '1'; |
443
|
|
|
$tickets->save(); |
444
|
|
|
|
445
|
|
|
$ticket_user = User::where('id', '=', $tickets->user_id)->first(); |
446
|
|
|
if ($system_reply == true) { |
|
|
|
|
447
|
|
|
if ($tickets->assigned_to == 0) { |
448
|
|
|
$tickets->assigned_to = Auth::user()->id; |
449
|
|
|
$tickets->save(); |
450
|
|
|
$thread2 = new Ticket_Thread(); |
451
|
|
|
$thread2->ticket_id = $thread->ticket_id; |
|
|
|
|
452
|
|
|
$thread2->user_id = Auth::user()->id; |
|
|
|
|
453
|
|
|
$thread2->is_internal = 1; |
|
|
|
|
454
|
|
|
$thread2->body = 'This Ticket have been assigned to '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
455
|
|
|
$thread2->save(); |
456
|
|
|
$data = [ |
457
|
|
|
'id' => $tickets->id, |
458
|
|
|
]; |
459
|
|
|
\Event::fire('ticket-assignment', [$data]); |
460
|
|
|
} |
461
|
|
|
if ($tickets->status > 1) { |
462
|
|
|
$this->open($ticket_id, new Tickets()); |
|
|
|
|
463
|
|
|
} |
464
|
|
|
} |
465
|
|
|
$thread->save(); |
466
|
|
|
|
467
|
|
|
if ($attachments != null) { |
468
|
|
|
foreach ($attachments as $attachment) { |
|
|
|
|
469
|
|
|
if ($attachment != null) { |
470
|
|
|
$name = $attachment->getClientOriginalName(); |
471
|
|
|
$type = $attachment->getClientOriginalExtension(); |
472
|
|
|
$size = $attachment->getSize(); |
473
|
|
|
$data = file_get_contents($attachment->getRealPath()); |
474
|
|
|
$attachPath = $attachment->getRealPath(); |
|
|
|
|
475
|
|
|
$ta->create(['thread_id' => $thread->id, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $data, 'poster' => 'ATTACHMENT']); |
|
|
|
|
476
|
|
|
$check_attachment = 1; |
477
|
|
|
} else { |
478
|
|
|
$check_attachment = null; |
479
|
|
|
} |
480
|
|
|
} |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
if ($check_attachment == 1) { |
484
|
|
|
$attachment_files = $this->attachmentSeperate($thread->id); |
|
|
|
|
485
|
|
|
} else { |
486
|
|
|
$attachment_files = null; |
487
|
|
|
} |
488
|
|
|
$threadfirst = Ticket_Thread::where('ticket_id', '=', $ticket_id)->orderBy('id')->first(); |
489
|
|
|
$ticket_subject = $threadfirst->title; |
490
|
|
|
$user_id = $tickets->user_id; |
491
|
|
|
$user = User::where('id', '=', $user_id)->first(); |
492
|
|
|
$email = $user->email; |
493
|
|
|
$user_name = $user->first_name; |
494
|
|
|
$ticket_number = $tickets->ticket_number; |
495
|
|
|
$company = $this->company(); |
|
|
|
|
496
|
|
|
$username = $ticket_user->first_name; |
497
|
|
View Code Duplication |
if (!empty(Auth::user()->agent_sign)) { |
|
|
|
|
498
|
|
|
$agentsign = Auth::user()->agent_sign; |
499
|
|
|
} else { |
500
|
|
|
$agentsign = null; |
501
|
|
|
} |
502
|
|
|
|
503
|
|
|
// Event |
504
|
|
|
\Event::fire(new \App\Events\FaveoAfterReply($reply_content, $user->mobile, $user->country_code, $request, $tickets, $thread)); |
|
|
|
|
505
|
|
|
if (Auth::user()) { |
506
|
|
|
$u_id = Auth::user()->first_name.' '.Auth::user()->last_name; |
507
|
|
|
} else { |
508
|
|
|
$u_id = $this->getAdmin()->first_name.' '.$this->getAdmin()->last_name; |
509
|
|
|
} |
510
|
|
|
$data = [ |
511
|
|
|
'ticket_id' => $request->input('ticket_ID'), |
512
|
|
|
'u_id' => $u_id, |
513
|
|
|
'body' => $request->input('reply_content'), |
514
|
|
|
]; |
515
|
|
|
if (!$request->has('do-not-send')) { |
516
|
|
|
\Event::fire('Reply-Ticket', [$data]); |
517
|
|
|
} |
518
|
|
|
// sending attachments via php mail function |
519
|
|
|
$message = ''; |
|
|
|
|
520
|
|
|
|
521
|
|
|
$line = '---Reply above this line---<br><br>'; |
522
|
|
|
$collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket_id)->get(); |
523
|
|
|
$emails = Emails::where('department', '=', $tickets->dept_id)->first(); |
|
|
|
|
524
|
|
|
if (!$email) { |
525
|
|
|
$mail = false; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
if ($mail == true) { |
|
|
|
|
529
|
|
|
//dd($thread->purify()); |
|
|
|
|
530
|
|
|
//dd($this->replyContent($request->input('reply_content'))); |
|
|
|
|
531
|
|
|
$this->NotificationController->create($ticket_id, Auth::user()->id, '2'); |
532
|
|
|
$this->PhpMailController->sendmail( |
533
|
|
|
$from = $this->PhpMailController->mailfrom('0', $tickets->dept_id), |
534
|
|
|
$to = ['name' => $user_name, 'email' => $email, 'cc' => $collaborators], |
535
|
|
|
$message = [ |
536
|
|
|
'subject' => $ticket_subject.'[#'.$ticket_number.']', |
537
|
|
|
'body' => $line.$request->input('reply_content'), |
538
|
|
|
'scenario' => 'ticket-reply', |
539
|
|
|
'attachments' => $attachment_files, |
540
|
|
|
], |
541
|
|
|
$template_variables = [ |
542
|
|
|
'ticket_number' => $ticket_number, |
543
|
|
|
'user' => $username, 'agent_sign' => $agentsign, |
544
|
|
|
] |
545
|
|
|
); |
546
|
|
|
} |
547
|
|
|
} catch (\Exception $e) { |
548
|
|
|
$result = ['fails' => $e->getMessage()]; |
549
|
|
|
|
550
|
|
|
return response()->json(compact('result')); |
551
|
|
|
} |
552
|
|
|
$result = ['success' => 'Replyed successfully']; |
553
|
|
|
|
554
|
|
|
return response()->json(compact('result')); |
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
/** |
558
|
|
|
* Ticket edit and save ticket data. |
559
|
|
|
* |
560
|
|
|
* @param type $ticket_id |
561
|
|
|
* @param type Ticket_Thread $thread |
562
|
|
|
* |
563
|
|
|
* @return type bool |
564
|
|
|
*/ |
565
|
|
|
public function ticketEditPost($ticket_id, Ticket_Thread $thread, Tickets $ticket) |
566
|
|
|
{ |
567
|
|
|
if (Input::get('subject') == null) { |
568
|
|
|
return 1; |
569
|
|
|
} elseif (Input::get('sla_paln') == null) { |
570
|
|
|
return 2; |
571
|
|
|
} elseif (Input::get('help_topic') == null) { |
572
|
|
|
return 3; |
573
|
|
|
} elseif (Input::get('ticket_source') == null) { |
574
|
|
|
return 4; |
575
|
|
|
} elseif (Input::get('ticket_priority') == null) { |
576
|
|
|
return 5; |
577
|
|
|
} else { |
578
|
|
|
$ticket = $ticket->where('id', '=', $ticket_id)->first(); |
|
|
|
|
579
|
|
|
$ticket->sla = Input::get('sla_paln'); |
580
|
|
|
$ticket->help_topic_id = Input::get('help_topic'); |
581
|
|
|
$ticket->source = Input::get('ticket_source'); |
582
|
|
|
$ticket->priority_id = Input::get('ticket_priority'); |
583
|
|
|
$dept = Help_topic::select('department')->where('id', '=', $ticket->help_topic_id)->first(); |
584
|
|
|
$ticket->dept_id = $dept->department; |
585
|
|
|
$ticket->save(); |
586
|
|
|
|
587
|
|
|
$threads = $thread->where('ticket_id', '=', $ticket_id)->first(); |
|
|
|
|
588
|
|
|
$threads->title = Input::get('subject'); |
589
|
|
|
$threads->save(); |
590
|
|
|
|
591
|
|
|
return 0; |
592
|
|
|
} |
593
|
|
|
} |
594
|
|
|
|
595
|
|
|
/** |
596
|
|
|
* Print Ticket Details. |
597
|
|
|
* |
598
|
|
|
* @param type $id |
599
|
|
|
* |
600
|
|
|
* @return type respponse |
601
|
|
|
*/ |
602
|
|
|
public function ticket_print($id) |
603
|
|
|
{ |
604
|
|
|
$tickets = Tickets:: |
605
|
|
|
leftJoin('ticket_thread', function ($join) { |
606
|
|
|
$join->on('tickets.id', '=', 'ticket_thread.ticket_id') |
607
|
|
|
->whereNotNull('ticket_thread.title'); |
608
|
|
|
}) |
609
|
|
|
->leftJoin('department', 'tickets.dept_id', '=', 'department.id') |
610
|
|
|
->leftJoin('help_topic', 'tickets.help_topic_id', '=', 'help_topic.id') |
611
|
|
|
->where('tickets.id', '=', $id) |
612
|
|
|
->select('ticket_thread.title', 'tickets.ticket_number', 'department.name as department', 'help_topic.topic as helptopic') |
613
|
|
|
->first(); |
614
|
|
|
$ticket = Tickets::where('tickets.id', '=', $id)->first(); |
615
|
|
|
$html = view('themes.default1.agent.helpdesk.ticket.pdf', compact('id', 'ticket', 'tickets'))->render(); |
|
|
|
|
616
|
|
|
$html1 = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
617
|
|
|
|
618
|
|
|
return PDF::load($html1)->show(); |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* Generates Ticket Number. |
623
|
|
|
* |
624
|
|
|
* @param type $ticket_number |
625
|
|
|
* |
626
|
|
|
* @return type integer |
627
|
|
|
*/ |
628
|
|
|
public function ticketNumberold($ticket_number) |
629
|
|
|
{ |
630
|
|
|
$number = $ticket_number; |
631
|
|
|
$number = explode('-', $number); |
632
|
|
|
$number1 = $number[0]; |
633
|
|
|
if ($number1 == 'ZZZZ') { |
634
|
|
|
$number1 = 'AAAA'; |
635
|
|
|
} |
636
|
|
|
$number2 = $number[1]; |
637
|
|
|
if ($number2 == '9999') { |
638
|
|
|
$number2 = '0000'; |
639
|
|
|
} |
640
|
|
|
$number3 = $number[2]; |
641
|
|
|
if ($number3 == '9999999') { |
642
|
|
|
$number3 = '0000000'; |
643
|
|
|
} |
644
|
|
|
$number1++; |
645
|
|
|
$number2++; |
646
|
|
|
$number3++; |
647
|
|
|
$number2 = sprintf('%04s', $number2); |
648
|
|
|
$number3 = sprintf('%07s', $number3); |
649
|
|
|
$array = [$number1, $number2, $number3]; |
650
|
|
|
$number = implode('-', $array); |
651
|
|
|
|
652
|
|
|
return $number; |
653
|
|
|
} |
654
|
|
|
|
655
|
|
|
public function ticketNumber($ticket_number) |
656
|
|
|
{ |
657
|
|
|
$ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); |
658
|
|
|
$setting = $ticket_settings->find(1); |
|
|
|
|
659
|
|
|
$format = $setting->num_format; |
660
|
|
|
$type = $setting->num_sequence; |
661
|
|
|
$number = $this->getNumber($ticket_number, $type, $format); |
662
|
|
|
|
663
|
|
|
return $number; |
664
|
|
|
} |
665
|
|
|
|
666
|
|
|
public function getNumber($ticket_number, $type, $format, $check = true) |
667
|
|
|
{ |
668
|
|
|
$force = false; |
669
|
|
|
if ($check === false) { |
670
|
|
|
$force = true; |
671
|
|
|
} |
672
|
|
|
$controller = new \App\Http\Controllers\Admin\helpdesk\SettingsController(); |
673
|
|
|
if ($ticket_number) { |
674
|
|
|
$number = $controller->nthTicketNumber($ticket_number, $type, $format, $force); |
675
|
|
|
} else { |
676
|
|
|
$number = $controller->switchNumber($format, $type); |
677
|
|
|
} |
678
|
|
|
$number = $this->generateTicketIfExist($number, $type, $format); |
679
|
|
|
|
680
|
|
|
return $number; |
681
|
|
|
} |
682
|
|
|
|
683
|
|
|
public function generateTicketIfExist($number, $type, $format) |
684
|
|
|
{ |
685
|
|
|
$tickets = new Tickets(); |
686
|
|
|
$ticket = $tickets->where('ticket_number', $number)->first(); |
|
|
|
|
687
|
|
|
if ($ticket) { |
688
|
|
|
$number = $this->getNumber($number, $type, $format, false); |
689
|
|
|
} |
690
|
|
|
|
691
|
|
|
return $number; |
692
|
|
|
} |
693
|
|
|
|
694
|
|
|
/** |
695
|
|
|
* check email for dublicate entry. |
696
|
|
|
* |
697
|
|
|
* @param type $email |
698
|
|
|
* |
699
|
|
|
* @return type bool |
700
|
|
|
*/ |
701
|
|
|
public function checkEmail($email) |
702
|
|
|
{ |
703
|
|
|
$check = User::where('email', '=', $email)->orWhere('user_name', $email)->orWhere('mobile', $email)->first(); |
704
|
|
|
if ($check == true) { |
705
|
|
|
return $check; |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
return false; |
|
|
|
|
709
|
|
|
} |
710
|
|
|
|
711
|
|
|
/** |
712
|
|
|
* @category fucntion to check if mobile number is unqique or not |
713
|
|
|
* |
714
|
|
|
* @param string $mobile |
715
|
|
|
* |
716
|
|
|
* @return bool true(if mobile exists in users table)/false (if mobile does not exist in user table) |
717
|
|
|
*/ |
718
|
|
|
public function checkMobile($mobile) |
719
|
|
|
{ |
720
|
|
|
$check = User::where('mobile', '=', $mobile)->first(); |
721
|
|
|
if (count($check) > 0) { |
722
|
|
|
return true; |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
return false; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
/** |
729
|
|
|
* Create User while creating ticket. |
730
|
|
|
* |
731
|
|
|
* @param type $emailadd |
732
|
|
|
* @param type $username |
733
|
|
|
* @param type $subject |
734
|
|
|
* @param type $phone |
735
|
|
|
* @param type $helptopic |
736
|
|
|
* @param type $sla |
737
|
|
|
* @param type $priority |
738
|
|
|
* @param type $system |
|
|
|
|
739
|
|
|
* |
740
|
|
|
* @return type bool |
741
|
|
|
*/ |
742
|
|
|
public function create_user($emailadd, $username, $subject, $body, $phone, $phonecode, $mobile_number, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $from_data, $auto_response, $status) |
743
|
|
|
{ |
744
|
|
|
// define global variables |
745
|
|
|
$email; |
|
|
|
|
746
|
|
|
$username; |
747
|
|
|
$unique = $emailadd; |
748
|
|
|
if (!$emailadd) { |
749
|
|
|
$unique = $mobile_number; |
750
|
|
|
} |
751
|
|
|
// check emails |
752
|
|
|
$ticket_creator = $username; |
753
|
|
|
$checkemail = $this->checkEmail($unique); |
754
|
|
|
$company = $this->company(); |
755
|
|
|
if ($checkemail == false) { |
756
|
|
|
if ($mobile_number != '' || $mobile_number != null) { |
757
|
|
|
$check_mobile = $this->checkMobile($mobile_number); |
758
|
|
|
if ($check_mobile == true) { |
|
|
|
|
759
|
|
|
return ['0' => 'not available', '1' => false]; |
760
|
|
|
} |
761
|
|
|
} |
762
|
|
|
// Generate password |
763
|
|
|
$password = $this->generateRandomString(); |
764
|
|
|
// create user |
765
|
|
|
$user = new User(); |
766
|
|
|
$user_name_123 = explode('%$%', $username); |
767
|
|
|
$user_first_name = $user_name_123[0]; |
768
|
|
|
if (isset($user_name_123[1])) { |
769
|
|
|
$user_last_name = $user_name_123[1]; |
770
|
|
|
$user->last_name = $user_last_name; |
|
|
|
|
771
|
|
|
} |
772
|
|
|
$user->first_name = $user_first_name; |
|
|
|
|
773
|
|
|
$user_status = $this->checkUserVerificationStatus(); |
774
|
|
|
$user->user_name = $unique; |
|
|
|
|
775
|
|
|
if ($emailadd == '') { |
776
|
|
|
$user->email = null; |
|
|
|
|
777
|
|
|
} else { |
778
|
|
|
$user->email = $emailadd; |
|
|
|
|
779
|
|
|
} |
780
|
|
|
$user->password = Hash::make($password); |
|
|
|
|
781
|
|
|
$user->phone_number = $phone; |
|
|
|
|
782
|
|
|
$user->country_code = $phonecode; |
|
|
|
|
783
|
|
|
if ($mobile_number == '') { |
784
|
|
|
$user->mobile = null; |
|
|
|
|
785
|
|
|
} else { |
786
|
|
|
$user->mobile = $mobile_number; |
|
|
|
|
787
|
|
|
} |
788
|
|
|
$user->role = 'user'; |
|
|
|
|
789
|
|
|
$user->active = $user_status; |
|
|
|
|
790
|
|
|
$token = str_random(60); |
791
|
|
|
$user->remember_token = $token; |
|
|
|
|
792
|
|
|
// mail user his/her password |
793
|
|
|
\Event::fire(new \App\Events\ClientTicketFormPost($from_data, $emailadd, $source)); |
794
|
|
|
if ($user->save()) { |
795
|
|
|
$user_id = $user->id; |
|
|
|
|
796
|
|
|
$email_mandatory = CommonSettings::select('status')->where('option_name', '=', 'email_mandatory')->first(); |
797
|
|
|
if ($user_status == 0 || ($email_mandatory->status == 0 || $email_mandatory->status == '0')) { |
798
|
|
|
$value = [ |
799
|
|
|
'full_name' => $username, |
800
|
|
|
'email' => $emailadd, |
801
|
|
|
'code' => $phonecode, |
802
|
|
|
'mobile' => $mobile_number, |
803
|
|
|
'user_name' => $unique, |
804
|
|
|
'password' => $password, |
805
|
|
|
]; |
806
|
|
|
\Event::fire(new \App\Events\LoginEvent($value)); |
|
|
|
|
807
|
|
|
} |
808
|
|
|
// Event fire |
809
|
|
|
\Event::fire(new \App\Events\ReadMailEvent($user_id, $password)); |
810
|
|
|
try { |
811
|
|
|
if ($auto_response == 0) { |
812
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user->first_name, 'email' => $emailadd], $message = ['subject' => null, 'scenario' => 'registration-notification'], $template_variables = ['user' => $user->first_name, 'email_address' => $emailadd, 'user_password' => $password]); |
|
|
|
|
813
|
|
|
if ($user_status == 0) { |
814
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('1', '0'), $to = ['name' => $user->first_name, 'email' => $emailadd], $message = ['subject' => null, 'scenario' => 'registration'], $template_variables = ['user' => $user->first_name, 'email_address' => $emailadd, 'password_reset_link' => url('account/activate/'.$token)]); |
|
|
|
|
815
|
|
|
} |
816
|
|
|
} |
817
|
|
|
} catch (\Exception $e) { |
818
|
|
|
//dd($e); |
819
|
|
|
} |
820
|
|
|
} |
821
|
|
|
} else { |
822
|
|
|
$username = $checkemail->first_name; |
823
|
|
|
$user_id = $checkemail->id; |
824
|
|
|
} |
825
|
|
|
$ticket_number = $this->check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $from_data, $status); |
|
|
|
|
826
|
|
|
|
827
|
|
|
$ticket_number2 = $ticket_number[0]; |
828
|
|
|
$ticketdata = Tickets::where('ticket_number', '=', $ticket_number2)->first(); |
829
|
|
|
$threaddata = Ticket_Thread::where('ticket_id', '=', $ticketdata->id)->first(); |
830
|
|
|
$is_reply = $ticket_number[1]; |
831
|
|
|
//dd($source); |
832
|
|
|
$system = $this->system(); |
|
|
|
|
833
|
|
|
$updated_subject = $threaddata->title.'[#'.$ticket_number2.']'; |
834
|
|
|
if ($ticket_number2) { |
835
|
|
|
// send ticket create details to user |
836
|
|
|
if ($is_reply == 0) { |
837
|
|
|
$mail = 'create-ticket-agent'; |
838
|
|
|
if (Auth::user()) { |
839
|
|
|
$sign = Auth::user()->agent_sign; |
|
|
|
|
840
|
|
|
} else { |
841
|
|
|
$sign = $company; |
|
|
|
|
842
|
|
|
} |
843
|
|
|
if ($source == 3) { |
844
|
|
|
try { |
845
|
|
|
if ($auto_response == 0) { |
846
|
|
|
//dd($source); |
847
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => $updated_subject, 'scenario' => 'create-ticket-by-agent', 'body' => $body], $template_variables = ['agent_sign' => Auth::user()->agent_sign, 'ticket_number' => $ticket_number2]); |
848
|
|
|
} |
849
|
|
|
} catch (\Exception $e) { |
850
|
|
|
//dd($e); |
851
|
|
|
} |
852
|
|
|
} else { |
853
|
|
|
$body2 = null; |
|
|
|
|
854
|
|
|
try { |
855
|
|
|
if ($auto_response == 0) { |
856
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = ['name' => $username, 'email' => $emailadd], $message = ['subject' => $updated_subject, 'scenario' => 'create-ticket'], $template_variables = ['user' => $username, 'ticket_number' => $ticket_number2, 'department_sign' => '']); |
857
|
|
|
} |
858
|
|
|
} catch (\Exception $e) { |
|
|
|
|
859
|
|
|
} |
860
|
|
|
} |
861
|
|
|
} elseif ($is_reply == 1) { |
862
|
|
|
$mail = 'ticket-reply-agent'; |
863
|
|
|
} |
864
|
|
|
|
865
|
|
|
$set_mails = []; |
866
|
|
|
if (Alert::first()->ticket_status == 1 || Alert::first()->ticket_admin_email == 1) { |
867
|
|
|
// send email to admin |
868
|
|
|
$admins = User::where('role', '=', 'admin')->get(); |
869
|
|
|
foreach ($admins as $admin) { |
870
|
|
|
$to_email = $admin->email; |
871
|
|
|
$to_user = $admin->first_name; |
872
|
|
|
$to_user_name = $admin->first_name; |
873
|
|
|
array_push($set_mails, ['to_email' => $to_email, 'to_user' => $to_user, 'to_user_name' => $to_user_name]); |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
|
877
|
|
|
if ($is_reply == 0) { |
878
|
|
|
if (Alert::first()->ticket_status == 1 || Alert::first()->ticket_department_member == 1) { |
879
|
|
|
// send email to agents |
880
|
|
|
$agents = User::where('role', '=', 'agent')->get(); |
881
|
|
|
foreach ($agents as $agent) { |
882
|
|
|
$department_data = Department::where('id', '=', $ticketdata->dept_id)->first(); |
883
|
|
|
|
884
|
|
|
if ($department_data->name == $agent->primary_dpt) { |
885
|
|
|
$to_email = $agent->email; |
886
|
|
|
$to_user = $agent->first_name; |
887
|
|
|
$to_user_name = $agent->first_name; |
888
|
|
|
array_push($set_mails, ['to_email' => $to_email, 'to_user' => $to_user, 'to_user_name' => $to_user_name]); |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
} |
892
|
|
|
// Event fire for new ticket[''] |
|
|
|
|
893
|
|
|
} |
894
|
|
|
if ($is_reply == 1) { |
895
|
|
|
$client_email = $ticketdata->user->email; |
896
|
|
|
$client_user_name = $ticketdata->user->user_name; |
897
|
|
|
array_push($set_mails, ['to_email' => $client_email, 'to_user' => $client_user_name, 'to_user_name' => $client_user_name]); |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
if ($ticketdata->assigned_to) { |
901
|
|
|
$assigned_to = User::where('id', '=', $ticketdata->assigned_to)->first(); |
902
|
|
|
$to_email = $assigned_to->email; |
903
|
|
|
$to_user = $assigned_to->first_name; |
904
|
|
|
$to_user_name = $assigned_to->first_name; |
905
|
|
|
array_push($set_mails, ['to_email' => $to_email, 'to_user' => $to_user, 'to_user_name' => $to_user_name]); |
906
|
|
|
} |
907
|
|
|
|
908
|
|
|
$emails_to_be_sent = array_unique($set_mails, SORT_REGULAR); |
909
|
|
|
|
910
|
|
|
foreach ($emails_to_be_sent as $email_data) { |
911
|
|
|
try { |
912
|
|
|
$this->PhpMailController->sendmail( |
913
|
|
|
$from = $this->PhpMailController->mailfrom('0', $ticketdata->dept_id), $to = [ |
914
|
|
|
'user' => $email_data['to_user'], |
915
|
|
|
'email' => $email_data['to_email'], |
916
|
|
|
], $message = [ |
917
|
|
|
'subject' => $updated_subject, |
918
|
|
|
'body' => $body, 'scenario' => $mail, |
|
|
|
|
919
|
|
|
], $template_variables = [ |
920
|
|
|
'ticket_agent_name' => $email_data['to_user_name'], |
921
|
|
|
'ticket_client_name' => $username, |
922
|
|
|
'ticket_client_email' => $emailadd, |
923
|
|
|
'user' => $email_data['to_user_name'], |
924
|
|
|
'ticket_number' => $ticket_number2, |
925
|
|
|
'email_address' => $emailadd, |
926
|
|
|
'name' => $ticket_creator, ] |
927
|
|
|
); |
928
|
|
|
} catch (\Exception $e) { |
|
|
|
|
929
|
|
|
} |
930
|
|
|
} |
931
|
|
|
$data = [ |
932
|
|
|
'ticket_number' => $ticket_number2, |
933
|
|
|
'user_id' => $user_id, |
934
|
|
|
'subject' => $subject, |
935
|
|
|
'body' => $body, |
936
|
|
|
'status' => $status, |
937
|
|
|
'Priority' => $priority, |
938
|
|
|
]; |
939
|
|
|
\Event::fire('Create-Ticket', [$data]); |
940
|
|
|
$data = [ |
941
|
|
|
'id' => $ticketdata->id, |
942
|
|
|
]; |
943
|
|
|
\Event::fire('ticket-assignment', [$data]); |
944
|
|
|
$this->NotificationController->create($ticketdata->id, $user_id, '3'); |
945
|
|
|
|
946
|
|
|
return ['0' => $ticket_number2, '1' => true]; |
947
|
|
|
} |
948
|
|
|
} |
949
|
|
|
|
950
|
|
|
/** |
951
|
|
|
* Default helptopic. |
952
|
|
|
* |
953
|
|
|
* @return type string |
954
|
|
|
*/ |
955
|
|
|
public function default_helptopic() |
956
|
|
|
{ |
957
|
|
|
$helptopic = '1'; |
958
|
|
|
|
959
|
|
|
return $helptopic; |
960
|
|
|
} |
961
|
|
|
|
962
|
|
|
/** |
963
|
|
|
* Default SLA plan. |
964
|
|
|
* |
965
|
|
|
* @return type string |
966
|
|
|
*/ |
967
|
|
|
public function default_sla() |
968
|
|
|
{ |
969
|
|
|
$sla = '1'; |
970
|
|
|
|
971
|
|
|
return $sla; |
972
|
|
|
} |
973
|
|
|
|
974
|
|
|
/** |
975
|
|
|
* Default Priority. |
976
|
|
|
* |
977
|
|
|
* @return type string |
978
|
|
|
*/ |
979
|
|
|
public function default_priority() |
980
|
|
|
{ |
981
|
|
|
$priority = '1'; |
|
|
|
|
982
|
|
|
|
983
|
|
|
return $prioirty; |
|
|
|
|
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
/** |
987
|
|
|
* Check the response of the ticket. |
988
|
|
|
* |
989
|
|
|
* @param type $user_id |
990
|
|
|
* @param type $subject |
991
|
|
|
* @param type $body |
992
|
|
|
* @param type $helptopic |
993
|
|
|
* @param type $sla |
994
|
|
|
* @param type $priority |
995
|
|
|
* |
996
|
|
|
* @return type string |
997
|
|
|
*/ |
998
|
|
|
public function check_ticket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $status) |
999
|
|
|
{ |
1000
|
|
|
$read_ticket_number = explode('[#', $subject); |
1001
|
|
|
if (isset($read_ticket_number[1])) { |
1002
|
|
|
$separate = explode(']', $read_ticket_number[1]); |
1003
|
|
|
$new_subject = substr($separate[0], 0, 20); |
1004
|
|
|
$find_number = Tickets::where('ticket_number', '=', $new_subject)->first(); |
1005
|
|
|
$thread_body = explode('---Reply above this line---', $body); |
1006
|
|
|
$body = $thread_body[0]; |
1007
|
|
|
if (count($find_number) > 0) { |
1008
|
|
|
$id = $find_number->id; |
1009
|
|
|
$ticket_number = $find_number->ticket_number; |
1010
|
|
|
if ($find_number->status > 1) { |
1011
|
|
|
$find_number->status = 1; |
1012
|
|
|
$find_number->closed = 0; |
1013
|
|
|
$find_number->closed_at = date('Y-m-d H:i:s'); |
1014
|
|
|
$find_number->reopened = 1; |
1015
|
|
|
$find_number->reopened_at = date('Y-m-d H:i:s'); |
1016
|
|
|
$find_number->save(); |
1017
|
|
|
|
1018
|
|
|
$ticket_status = Ticket_Status::where('id', '=', 1)->first(); |
1019
|
|
|
|
1020
|
|
|
$user_name = User::where('id', '=', $user_id)->first(); |
1021
|
|
|
|
1022
|
|
|
if ($user_name->role == 'user') { |
1023
|
|
|
$username = $user_name->user_name; |
1024
|
|
|
} elseif ($user_name->role == 'agent' or $user_name->role == 'admin') { |
1025
|
|
|
$username = $user_name->first_name.' '.$user_name->last_name; |
1026
|
|
|
} |
1027
|
|
|
|
1028
|
|
|
$ticket_threads = new Ticket_Thread(); |
1029
|
|
|
$ticket_threads->ticket_id = $id; |
|
|
|
|
1030
|
|
|
$ticket_threads->user_id = $user_id; |
|
|
|
|
1031
|
|
|
$ticket_threads->is_internal = 1; |
|
|
|
|
1032
|
|
|
$ticket_threads->body = $ticket_status->message.' '.$username; |
|
|
|
|
1033
|
|
|
$ticket_threads->save(); |
1034
|
|
|
// event fire for internal notes |
1035
|
|
|
//event to change status |
1036
|
|
|
$data = [ |
1037
|
|
|
'id' => $ticket_number, |
1038
|
|
|
'status' => 'Open', |
1039
|
|
|
'first_name' => $username, |
1040
|
|
|
'last_name' => '', |
1041
|
|
|
]; |
1042
|
|
|
\Event::fire('change-status', [$data]); |
1043
|
|
|
} |
1044
|
|
|
if (isset($id)) { |
1045
|
|
|
if ($this->ticketThread($subject, $body, $id, $user_id)) { |
1046
|
|
|
// event fire for reply [$subject, $body, $id, $user_id] |
|
|
|
|
1047
|
|
|
return [$ticket_number, 1]; |
1048
|
|
|
} |
1049
|
|
|
} |
1050
|
|
View Code Duplication |
} else { |
|
|
|
|
1051
|
|
|
$ticket_number = $this->createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $status); |
1052
|
|
|
|
1053
|
|
|
return [$ticket_number, 0]; |
1054
|
|
|
} |
1055
|
|
View Code Duplication |
} else { |
|
|
|
|
1056
|
|
|
$ticket_number = $this->createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $status); |
1057
|
|
|
|
1058
|
|
|
return [$ticket_number, 0]; |
1059
|
|
|
} |
1060
|
|
|
} |
1061
|
|
|
|
1062
|
|
|
/** |
1063
|
|
|
* Create Ticket. |
1064
|
|
|
* |
1065
|
|
|
* @param type $user_id |
1066
|
|
|
* @param type $subject |
1067
|
|
|
* @param type $body |
1068
|
|
|
* @param type $helptopic |
1069
|
|
|
* @param type $sla |
1070
|
|
|
* @param type $priority |
1071
|
|
|
* |
1072
|
|
|
* @return type string |
1073
|
|
|
*/ |
1074
|
|
|
public function createTicket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $status) |
1075
|
|
|
{ |
1076
|
|
|
$ticket_number = ''; |
1077
|
|
|
$max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->first(); |
1078
|
|
|
if ($max_number) { |
1079
|
|
|
$ticket_number = $max_number->ticket_number; |
1080
|
|
|
} |
1081
|
|
|
|
1082
|
|
|
$user_status = User::select('active')->where('id', '=', $user_id)->first(); |
|
|
|
|
1083
|
|
|
// dd($user_status->active); |
|
|
|
|
1084
|
|
|
$ticket = new Tickets(); |
1085
|
|
|
$ticket->ticket_number = $this->ticketNumber($ticket_number); |
|
|
|
|
1086
|
|
|
$ticket->user_id = $user_id; |
|
|
|
|
1087
|
|
|
$ticket->dept_id = $dept; |
|
|
|
|
1088
|
|
|
$ticket->help_topic_id = $helptopic; |
|
|
|
|
1089
|
|
|
$ticket->sla = $sla; |
|
|
|
|
1090
|
|
|
$ticket->assigned_to = $assignto; |
|
|
|
|
1091
|
|
|
|
1092
|
|
|
$ticket->priority_id = $priority; |
|
|
|
|
1093
|
|
|
$ticket->source = $source; |
|
|
|
|
1094
|
|
|
$ticket_status = $this->checkUserVerificationStatus(); |
|
|
|
|
1095
|
|
|
//dd($ticket_status); |
1096
|
|
|
// if ($ticket_status == 0) { |
|
|
|
|
1097
|
|
|
// //check if user active then allow ticket creation else create unverified ticket |
1098
|
|
|
// if ($user_status->active == 1) { |
|
|
|
|
1099
|
|
|
// if ($status == null) { |
|
|
|
|
1100
|
|
|
// $ticket->status = 1; |
|
|
|
|
1101
|
|
|
// } else { |
|
|
|
|
1102
|
|
|
// $ticket->status = $status; |
|
|
|
|
1103
|
|
|
// } |
1104
|
|
|
// } else { |
|
|
|
|
1105
|
|
|
// $ticket->status = 6; |
|
|
|
|
1106
|
|
|
// } |
1107
|
|
|
// } else { |
|
|
|
|
1108
|
|
|
// if ($status == null) { |
|
|
|
|
1109
|
|
|
// $ticket->status = 1; |
|
|
|
|
1110
|
|
|
// } else { |
|
|
|
|
1111
|
|
|
// $ticket->status = $status; |
|
|
|
|
1112
|
|
|
// } |
1113
|
|
|
// } |
1114
|
|
|
if ($status == null) { |
1115
|
|
|
$ticket->status = 1; |
|
|
|
|
1116
|
|
|
} else { |
1117
|
|
|
$ticket->status = $status; |
|
|
|
|
1118
|
|
|
} |
1119
|
|
|
$ticket->save(); |
1120
|
|
|
|
1121
|
|
|
$sla_plan = Sla_plan::where('id', '=', $sla)->first(); |
1122
|
|
|
$ovdate = $ticket->created_at; |
|
|
|
|
1123
|
|
|
$new_date = date_add($ovdate, date_interval_create_from_date_string($sla_plan->grace_period)); |
1124
|
|
|
$ticket->duedate = $new_date; |
|
|
|
|
1125
|
|
|
$ticket->save(); |
1126
|
|
|
|
1127
|
|
|
$ticket_number = $ticket->ticket_number; |
|
|
|
|
1128
|
|
|
$id = $ticket->id; |
|
|
|
|
1129
|
|
|
// $this->NotificationController->create($id, $user_id, '3'); |
|
|
|
|
1130
|
|
|
// store Form Data |
1131
|
|
|
// Form Data comes from raising a ticket from client panel |
1132
|
|
|
if ($form_data != null) { |
1133
|
|
|
$help_topic = Help_topic::where('id', '=', $helptopic)->first(); |
1134
|
|
|
//$forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get(); |
|
|
|
|
1135
|
|
|
$form = \App\Model\helpdesk\Form\Forms::find($help_topic->custom_form); |
1136
|
|
|
$form_name = ''; |
|
|
|
|
1137
|
|
|
if ($form) { |
1138
|
|
|
$form_name = $form->formname; |
|
|
|
|
1139
|
|
|
} |
1140
|
|
|
foreach ($form_data as $key => $form_details) { |
1141
|
|
|
if (!is_array($form_details)) { |
1142
|
|
|
$form_value = new Ticket_Form_Data(); |
1143
|
|
|
$form_value->ticket_id = $id; |
|
|
|
|
1144
|
|
|
$form_value->title = $key; |
|
|
|
|
1145
|
|
|
$form_value->content = $form_details; |
|
|
|
|
1146
|
|
|
$form_value->save(); |
1147
|
|
|
} |
1148
|
|
|
} |
1149
|
|
|
} |
1150
|
|
|
// store collaborators |
1151
|
|
|
$this->storeCollaborators($headers, $id); |
1152
|
|
|
if ($this->ticketThread($subject, $body, $id, $user_id) == true) { |
1153
|
|
|
return $ticket_number; |
1154
|
|
|
} |
1155
|
|
|
} |
1156
|
|
|
|
1157
|
|
|
/** |
1158
|
|
|
* Generate Ticket Thread. |
1159
|
|
|
* |
1160
|
|
|
* @param type $subject |
1161
|
|
|
* @param type $body |
1162
|
|
|
* @param type $id |
1163
|
|
|
* @param type $user_id |
1164
|
|
|
* |
1165
|
|
|
* @return type |
1166
|
|
|
*/ |
1167
|
|
|
public function ticketThread($subject, $body, $id, $user_id) |
1168
|
|
|
{ |
1169
|
|
|
$thread = new Ticket_Thread(); |
1170
|
|
|
$thread->user_id = $user_id; |
|
|
|
|
1171
|
|
|
$thread->ticket_id = $id; |
|
|
|
|
1172
|
|
|
$thread->poster = 'client'; |
|
|
|
|
1173
|
|
|
$thread->title = $subject; |
|
|
|
|
1174
|
|
|
$thread->body = $body; |
|
|
|
|
1175
|
|
|
if ($thread->save()) { |
1176
|
|
|
\Event::fire('ticket.details', ['ticket' => $thread]); //get the ticket details |
1177
|
|
|
return true; |
1178
|
|
|
} |
1179
|
|
|
} |
1180
|
|
|
|
1181
|
|
|
/** |
1182
|
|
|
* Generate a random string for password. |
1183
|
|
|
* |
1184
|
|
|
* @param type $length |
1185
|
|
|
* |
1186
|
|
|
* @return type string |
1187
|
|
|
*/ |
1188
|
|
View Code Duplication |
public function generateRandomString($length = 10) |
|
|
|
|
1189
|
|
|
{ |
1190
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
1191
|
|
|
$charactersLength = strlen($characters); |
1192
|
|
|
$randomString = ''; |
1193
|
|
|
for ($i = 0; $i < $length; $i++) { |
1194
|
|
|
$randomString .= $characters[rand(0, $charactersLength - 1)]; |
1195
|
|
|
} |
1196
|
|
|
|
1197
|
|
|
return $randomString; |
1198
|
|
|
} |
1199
|
|
|
|
1200
|
|
|
/** |
1201
|
|
|
* function to Ticket Close. |
1202
|
|
|
* |
1203
|
|
|
* @param type $id |
1204
|
|
|
* @param type Tickets $ticket |
1205
|
|
|
* |
1206
|
|
|
* @return type string |
1207
|
|
|
*/ |
1208
|
|
|
public function close($id, Tickets $ticket) |
|
|
|
|
1209
|
|
|
{ |
1210
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
1211
|
|
View Code Duplication |
if (Auth::user()->role == 'user') { |
|
|
|
|
1212
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->first(); |
1213
|
|
|
} else { |
1214
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->first(); |
1215
|
|
|
} |
1216
|
|
|
// checking for unautherised access attempt on other than owner ticket id |
1217
|
|
|
if ($ticket_status == null) { |
1218
|
|
|
return redirect()->route('unauth'); |
1219
|
|
|
} |
1220
|
|
|
$ticket_status->status = 3; |
1221
|
|
|
$ticket_status->closed = 1; |
1222
|
|
|
$ticket_status->closed_at = date('Y-m-d H:i:s'); |
1223
|
|
|
$ticket_status->save(); |
1224
|
|
|
$ticket_thread = Ticket_Thread::where('ticket_id', '=', $ticket_status->id)->first(); |
1225
|
|
|
$ticket_subject = $ticket_thread->title; |
1226
|
|
|
$ticket_status_message = Ticket_Status::where('id', '=', $ticket_status->status)->first(); |
1227
|
|
|
$thread = new Ticket_Thread(); |
1228
|
|
|
$thread->ticket_id = $ticket_status->id; |
|
|
|
|
1229
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1230
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1231
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
1232
|
|
|
$thread->save(); |
1233
|
|
|
|
1234
|
|
|
$user_id = $ticket_status->user_id; |
1235
|
|
|
$user = User::where('id', '=', $user_id)->first(); |
1236
|
|
|
$email = $user->email; |
1237
|
|
|
$user_name = $user->user_name; |
1238
|
|
|
$ticket_number = $ticket_status->ticket_number; |
1239
|
|
|
|
1240
|
|
|
$system_from = $this->company(); |
|
|
|
|
1241
|
|
|
$sending_emails = Emails::where('department', '=', $ticket_status->dept_id)->first(); |
1242
|
|
|
if ($sending_emails == null) { |
1243
|
|
|
$from_email = $this->system_mail(); |
|
|
|
|
1244
|
|
|
} else { |
1245
|
|
|
$from_email = $sending_emails->id; |
|
|
|
|
1246
|
|
|
} |
1247
|
|
|
try { |
1248
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket_status->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'close-ticket'], $template_variables = ['ticket_number' => $ticket_number]); |
1249
|
|
|
} catch (\Exception $e) { |
1250
|
|
|
return 0; |
1251
|
|
|
} |
1252
|
|
|
$data = [ |
1253
|
|
|
'id' => $ticket_status->ticket_number, |
1254
|
|
|
'status' => 'Closed', |
1255
|
|
|
'first_name' => Auth::user()->first_name, |
1256
|
|
|
'last_name' => Auth::user()->last_name, |
1257
|
|
|
]; |
1258
|
|
|
\Event::fire('change-status', [$data]); |
1259
|
|
|
|
1260
|
|
|
return 'your ticket'.$ticket_status->ticket_number.' has been closed'; |
1261
|
|
|
} |
1262
|
|
|
|
1263
|
|
|
/** |
1264
|
|
|
* function to Ticket resolved. |
1265
|
|
|
* |
1266
|
|
|
* @param type $id |
1267
|
|
|
* @param type Tickets $ticket |
1268
|
|
|
* |
1269
|
|
|
* @return type string |
1270
|
|
|
*/ |
1271
|
|
|
public function resolve($id, Tickets $ticket) |
1272
|
|
|
{ |
1273
|
|
View Code Duplication |
if (Auth::user()->role == 'user') { |
|
|
|
|
1274
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->first(); |
|
|
|
|
1275
|
|
|
} else { |
1276
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->first(); |
|
|
|
|
1277
|
|
|
} |
1278
|
|
|
// checking for unautherised access attempt on other than owner ticket id |
1279
|
|
|
if ($ticket_status == null) { |
1280
|
|
|
return redirect()->route('unauth'); |
1281
|
|
|
} |
1282
|
|
|
// $ticket_status = $ticket->where('id', '=', $id)->first(); |
|
|
|
|
1283
|
|
|
$ticket_status->status = 2; |
1284
|
|
|
$ticket_status->closed = 1; |
1285
|
|
|
$ticket_status->closed_at = date('Y-m-d H:i:s'); |
1286
|
|
|
$ticket_status->save(); |
1287
|
|
|
$ticket_status_message = Ticket_Status::where('id', '=', $ticket_status->status)->first(); |
1288
|
|
|
$thread = new Ticket_Thread(); |
1289
|
|
|
$thread->ticket_id = $ticket_status->id; |
|
|
|
|
1290
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1291
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1292
|
|
|
if (Auth::user()->first_name != null) { |
1293
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
1294
|
|
|
} else { |
1295
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->user_name; |
|
|
|
|
1296
|
|
|
} |
1297
|
|
|
$thread->save(); |
1298
|
|
|
$data = [ |
1299
|
|
|
'id' => $ticket_status->ticket_number, |
1300
|
|
|
'status' => 'Resolved', |
1301
|
|
|
'first_name' => Auth::user()->first_name, |
1302
|
|
|
'last_name' => Auth::user()->last_name, |
1303
|
|
|
]; |
1304
|
|
|
\Event::fire('change-status', [$data]); |
1305
|
|
|
|
1306
|
|
|
return 'your ticket'.$ticket_status->ticket_number.' has been resolved'; |
1307
|
|
|
} |
1308
|
|
|
|
1309
|
|
|
/** |
1310
|
|
|
* function to Open Ticket. |
1311
|
|
|
* |
1312
|
|
|
* @param type $id |
1313
|
|
|
* @param type Tickets $ticket |
1314
|
|
|
* |
1315
|
|
|
* @return type |
1316
|
|
|
*/ |
1317
|
|
|
public function open($id, Tickets $ticket) |
1318
|
|
|
{ |
1319
|
|
View Code Duplication |
if (Auth::user()->role == 'user') { |
|
|
|
|
1320
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->where('user_id', '=', Auth::user()->id)->first(); |
|
|
|
|
1321
|
|
|
} else { |
1322
|
|
|
$ticket_status = $ticket->where('id', '=', $id)->first(); |
|
|
|
|
1323
|
|
|
} |
1324
|
|
|
// checking for unautherised access attempt on other than owner ticket id |
1325
|
|
|
if ($ticket_status == null) { |
1326
|
|
|
return redirect()->route('unauth'); |
1327
|
|
|
} |
1328
|
|
|
$ticket_status->status = 1; |
1329
|
|
|
$ticket_status->reopened_at = date('Y-m-d H:i:s'); |
1330
|
|
|
$ticket_status->save(); |
1331
|
|
|
$ticket_status_message = Ticket_Status::where('id', '=', $ticket_status->status)->first(); |
1332
|
|
|
$thread = new Ticket_Thread(); |
1333
|
|
|
$thread->ticket_id = $ticket_status->id; |
|
|
|
|
1334
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1335
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1336
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
1337
|
|
|
$thread->save(); |
1338
|
|
|
$data = [ |
1339
|
|
|
'id' => $ticket_status->ticket_number, |
1340
|
|
|
'status' => 'Open', |
1341
|
|
|
'first_name' => Auth::user()->first_name, |
1342
|
|
|
'last_name' => Auth::user()->last_name, |
1343
|
|
|
]; |
1344
|
|
|
\Event::fire('change-status', [$data]); |
1345
|
|
|
|
1346
|
|
|
return 'your ticket'.$ticket_status->ticket_number.' has been opened'; |
1347
|
|
|
} |
1348
|
|
|
|
1349
|
|
|
/** |
1350
|
|
|
* Function to delete ticket. |
1351
|
|
|
* |
1352
|
|
|
* @param type $id |
1353
|
|
|
* @param type Tickets $ticket |
1354
|
|
|
* |
1355
|
|
|
* @return type string |
1356
|
|
|
*/ |
1357
|
|
|
public function delete($id, Tickets $ticket) |
1358
|
|
|
{ |
1359
|
|
|
$ticket_delete = $ticket->where('id', '=', $id)->first(); |
|
|
|
|
1360
|
|
|
if ($ticket_delete->status == 5) { |
1361
|
|
|
$ticket_delete->delete(); |
1362
|
|
|
$ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get(); |
1363
|
|
|
foreach ($ticket_threads as $ticket_thread) { |
1364
|
|
|
$ticket_thread->delete(); |
1365
|
|
|
} |
1366
|
|
|
$ticket_attachments = Ticket_attachments::where('ticket_id', '=', $id)->get(); |
1367
|
|
|
foreach ($ticket_attachments as $ticket_attachment) { |
1368
|
|
|
$ticket_attachment->delete(); |
1369
|
|
|
} |
1370
|
|
|
$data = [ |
1371
|
|
|
'id' => $ticket_delete->ticket_number, |
1372
|
|
|
'status' => 'Deleted', |
1373
|
|
|
'first_name' => Auth::user()->first_name, |
1374
|
|
|
'last_name' => Auth::user()->last_name, |
1375
|
|
|
]; |
1376
|
|
|
\Event::fire('change-status', [$data]); |
1377
|
|
|
|
1378
|
|
|
return 'your ticket has been delete'; |
1379
|
|
|
} else { |
1380
|
|
|
$ticket_delete->is_deleted = 1; |
1381
|
|
|
$ticket_delete->status = 5; |
1382
|
|
|
$ticket_delete->save(); |
1383
|
|
|
$ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first(); |
1384
|
|
|
$thread = new Ticket_Thread(); |
1385
|
|
|
$thread->ticket_id = $ticket_delete->id; |
|
|
|
|
1386
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1387
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1388
|
|
|
$thread->body = $ticket_status_message->message.' '.Auth::user()->first_name.' '.Auth::user()->last_name; |
|
|
|
|
1389
|
|
|
$thread->save(); |
1390
|
|
|
$data = [ |
1391
|
|
|
'id' => $ticket_delete->ticket_number, |
1392
|
|
|
'status' => 'Deleted', |
1393
|
|
|
'first_name' => Auth::user()->first_name, |
1394
|
|
|
'last_name' => Auth::user()->last_name, |
1395
|
|
|
]; |
1396
|
|
|
\Event::fire('change-status', [$data]); |
1397
|
|
|
|
1398
|
|
|
return 'your ticket'.$ticket_delete->ticket_number.' has been delete'; |
1399
|
|
|
} |
1400
|
|
|
} |
1401
|
|
|
|
1402
|
|
|
/** |
1403
|
|
|
* Function to ban an email. |
1404
|
|
|
* |
1405
|
|
|
* @param type $id |
1406
|
|
|
* @param type Tickets $ticket |
1407
|
|
|
* |
1408
|
|
|
* @return type string |
1409
|
|
|
*/ |
1410
|
|
|
public function ban($id, Tickets $ticket) |
1411
|
|
|
{ |
1412
|
|
|
$ticket_ban = $ticket->where('id', '=', $id)->first(); |
|
|
|
|
1413
|
|
|
$ban_email = $ticket_ban->user_id; |
1414
|
|
|
$user = User::where('id', '=', $ban_email)->first(); |
1415
|
|
|
$user->ban = 1; |
1416
|
|
|
$user->save(); |
1417
|
|
|
$Email = $user->email; |
|
|
|
|
1418
|
|
|
|
1419
|
|
|
return 'the user has been banned'; |
1420
|
|
|
} |
1421
|
|
|
|
1422
|
|
|
/** |
1423
|
|
|
* function to assign ticket. |
1424
|
|
|
* |
1425
|
|
|
* @param type $id |
1426
|
|
|
* |
1427
|
|
|
* @return type bool |
1428
|
|
|
*/ |
1429
|
|
|
public function assign($id) |
1430
|
|
|
{ |
1431
|
|
|
$ticket_array = []; |
1432
|
|
|
if (strpos($id, ',') !== false) { |
1433
|
|
|
$ticket_array = explode(',', $id); |
1434
|
|
|
} else { |
1435
|
|
|
array_push($ticket_array, $id); |
1436
|
|
|
} |
1437
|
|
|
$UserEmail = Input::get('assign_to'); |
1438
|
|
|
$assign_to = explode('_', $UserEmail); |
1439
|
|
|
$user_detail = null; |
1440
|
|
|
foreach ($ticket_array as $id) { |
1441
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
1442
|
|
|
if ($assign_to[0] == 'team') { |
1443
|
|
|
$ticket->team_id = $assign_to[1]; |
1444
|
|
|
$team_detail = Teams::where('id', '=', $assign_to[1])->first(); |
1445
|
|
|
$assignee = $team_detail->name; |
1446
|
|
|
$ticket_number = $ticket->ticket_number; |
|
|
|
|
1447
|
|
|
$ticket->save(); |
1448
|
|
|
$ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
1449
|
|
|
$ticket_subject = $ticket_thread->title; |
|
|
|
|
1450
|
|
|
$thread = new Ticket_Thread(); |
1451
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
1452
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1453
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1454
|
|
|
$thread->body = 'This Ticket has been assigned to '.$assignee; |
|
|
|
|
1455
|
|
|
$thread->save(); |
1456
|
|
|
} elseif ($assign_to[0] == 'user') { |
1457
|
|
|
$ticket->assigned_to = $assign_to[1]; |
1458
|
|
|
if ($user_detail === null) { |
1459
|
|
|
$user_detail = User::where('id', '=', $assign_to[1])->first(); |
1460
|
|
|
$assignee = $user_detail->first_name.' '.$user_detail->last_name; |
1461
|
|
|
} |
1462
|
|
|
$company = $this->company(); |
|
|
|
|
1463
|
|
|
$system = $this->system(); |
|
|
|
|
1464
|
|
|
$ticket_number = $ticket->ticket_number; |
1465
|
|
|
$ticket->save(); |
1466
|
|
|
$data = [ |
1467
|
|
|
'id' => $id, |
1468
|
|
|
]; |
1469
|
|
|
\Event::fire('ticket-assignment', [$data]); |
1470
|
|
|
$ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
1471
|
|
|
$ticket_subject = $ticket_thread->title; |
1472
|
|
|
$thread = new Ticket_Thread(); |
1473
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
1474
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
1475
|
|
|
$thread->is_internal = 1; |
|
|
|
|
1476
|
|
|
$thread->body = 'This Ticket has been assigned to '.$assignee; |
|
|
|
|
1477
|
|
|
$thread->save(); |
1478
|
|
|
|
1479
|
|
|
$agent = $user_detail->first_name; |
1480
|
|
|
$agent_email = $user_detail->email; |
1481
|
|
|
$ticket_link = route('ticket.thread', $id); |
1482
|
|
|
$master = Auth::user()->first_name.' '.Auth::user()->last_name; |
1483
|
|
|
try { |
1484
|
|
|
$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, 'ticket_link' => $ticket_link]); |
1485
|
|
|
} catch (\Exception $e) { |
1486
|
|
|
return 0; |
1487
|
|
|
} |
1488
|
|
|
} |
1489
|
|
|
} |
1490
|
|
|
|
1491
|
|
|
return 1; |
1492
|
|
|
} |
1493
|
|
|
|
1494
|
|
|
/** |
1495
|
|
|
* Function to post internal note. |
1496
|
|
|
* |
1497
|
|
|
* @param type $id |
1498
|
|
|
* |
1499
|
|
|
* @return type bool |
1500
|
|
|
*/ |
1501
|
|
|
public function InternalNote($id) |
1502
|
|
|
{ |
1503
|
|
|
$InternalContent = Input::get('InternalContent'); |
1504
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
1505
|
|
|
$NewThread = new Ticket_Thread(); |
1506
|
|
|
$NewThread->ticket_id = $thread->ticket_id; |
|
|
|
|
1507
|
|
|
$NewThread->user_id = Auth::user()->id; |
|
|
|
|
1508
|
|
|
$NewThread->is_internal = 1; |
|
|
|
|
1509
|
|
|
$NewThread->poster = Auth::user()->role; |
|
|
|
|
1510
|
|
|
$NewThread->title = $thread->title; |
|
|
|
|
1511
|
|
|
$NewThread->body = $InternalContent; |
|
|
|
|
1512
|
|
|
$NewThread->save(); |
1513
|
|
|
$data = [ |
1514
|
|
|
'ticket_id' => $id, |
1515
|
|
|
'u_id' => Auth::user()->first_name.' '.Auth::user()->last_name, |
1516
|
|
|
'body' => $InternalContent, |
1517
|
|
|
]; |
1518
|
|
|
\Event::fire('Reply-Ticket', [$data]); |
1519
|
|
|
|
1520
|
|
|
return 1; |
1521
|
|
|
} |
1522
|
|
|
|
1523
|
|
|
/** |
1524
|
|
|
* Function to surrender a ticket. |
1525
|
|
|
* |
1526
|
|
|
* @param type $id |
1527
|
|
|
* |
1528
|
|
|
* @return type bool |
1529
|
|
|
*/ |
1530
|
|
|
public function surrender($id) |
1531
|
|
|
{ |
1532
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
1533
|
|
|
$InternalContent = Auth::user()->first_name.' '.Auth::user()->last_name.' has Surrendered the assigned Ticket'; |
1534
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
1535
|
|
|
$NewThread = new Ticket_Thread(); |
1536
|
|
|
$NewThread->ticket_id = $thread->ticket_id; |
|
|
|
|
1537
|
|
|
$NewThread->user_id = Auth::user()->id; |
|
|
|
|
1538
|
|
|
$NewThread->is_internal = 1; |
|
|
|
|
1539
|
|
|
$NewThread->poster = Auth::user()->role; |
|
|
|
|
1540
|
|
|
$NewThread->title = $thread->title; |
|
|
|
|
1541
|
|
|
$NewThread->body = $InternalContent; |
|
|
|
|
1542
|
|
|
$NewThread->save(); |
1543
|
|
|
|
1544
|
|
|
$ticket->assigned_to = null; |
1545
|
|
|
$ticket->save(); |
1546
|
|
|
|
1547
|
|
|
return 1; |
1548
|
|
|
} |
1549
|
|
|
|
1550
|
|
|
/** |
1551
|
|
|
* Search. |
1552
|
|
|
* |
1553
|
|
|
* @param type $keyword |
1554
|
|
|
* |
1555
|
|
|
* @return type array |
1556
|
|
|
*/ |
1557
|
|
|
public function search($keyword) |
1558
|
|
|
{ |
1559
|
|
|
if (isset($keyword)) { |
1560
|
|
|
$data = ['ticket_number' => Tickets::search($keyword)]; |
1561
|
|
|
|
1562
|
|
|
return $data; |
1563
|
|
|
} else { |
1564
|
|
|
return 'no results'; |
1565
|
|
|
} |
1566
|
|
|
} |
1567
|
|
|
|
1568
|
|
|
/** |
1569
|
|
|
* Search. |
1570
|
|
|
* |
1571
|
|
|
* @param type $keyword |
|
|
|
|
1572
|
|
|
* |
1573
|
|
|
* @return type array |
1574
|
|
|
*/ |
1575
|
|
|
public function stores($ticket_number) |
1576
|
|
|
{ |
1577
|
|
|
$this->layout->header = $ticket_number; |
|
|
|
|
1578
|
|
|
$content = View::make('themes.default1.admin.tickets.ticketsearch', with(new Tickets())) |
1579
|
|
|
->with('header', $this->layout->header) |
1580
|
|
|
->with('ticket_number', \App\Model\Tickets::stores($ticket_number)); |
1581
|
|
|
if (Request::header('X-PJAX')) { |
1582
|
|
|
return $content; |
1583
|
|
|
} else { |
1584
|
|
|
$this->layout->content = $content; |
1585
|
|
|
} |
1586
|
|
|
} |
1587
|
|
|
|
1588
|
|
|
/** |
1589
|
|
|
* store_collaborators. |
1590
|
|
|
* |
1591
|
|
|
* @param type $headers |
1592
|
|
|
* |
1593
|
|
|
* @return type |
1594
|
|
|
*/ |
1595
|
|
|
public function storeCollaborators($headers, $id) |
1596
|
|
|
{ |
1597
|
|
|
$company = $this->company(); |
|
|
|
|
1598
|
|
|
if (isset($headers)) { |
1599
|
|
|
foreach ($headers as $email => $name) { |
1600
|
|
|
if ($name == null) { |
1601
|
|
|
$name = $email; |
1602
|
|
|
} |
1603
|
|
|
$name = $name; |
|
|
|
|
1604
|
|
|
$email = $email; |
|
|
|
|
1605
|
|
View Code Duplication |
if ($this->checkEmail($email) == false) { |
|
|
|
|
1606
|
|
|
$create_user = new User(); |
1607
|
|
|
$create_user->first_name = $name; |
|
|
|
|
1608
|
|
|
$create_user->user_name = $email; |
|
|
|
|
1609
|
|
|
$create_user->email = $email; |
|
|
|
|
1610
|
|
|
$create_user->active = 1; |
|
|
|
|
1611
|
|
|
$create_user->role = 'user'; |
|
|
|
|
1612
|
|
|
$password = $this->generateRandomString(); |
1613
|
|
|
$create_user->password = Hash::make($password); |
|
|
|
|
1614
|
|
|
$create_user->save(); |
1615
|
|
|
$user_id = $create_user->id; |
|
|
|
|
1616
|
|
|
try { |
1617
|
|
|
$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]); |
1618
|
|
|
} catch (\Exception $e) { |
|
|
|
|
1619
|
|
|
} |
1620
|
|
|
} else { |
1621
|
|
|
$user = $this->checkEmail($email); |
|
|
|
|
1622
|
|
|
$user_id = $user->id; |
1623
|
|
|
} |
1624
|
|
|
$collaborator_store = new Ticket_Collaborator(); |
1625
|
|
|
$collaborator_store->isactive = 1; |
|
|
|
|
1626
|
|
|
$collaborator_store->ticket_id = $id; |
|
|
|
|
1627
|
|
|
$collaborator_store->user_id = $user_id; |
|
|
|
|
1628
|
|
|
$collaborator_store->role = 'ccc'; |
|
|
|
|
1629
|
|
|
$collaborator_store->save(); |
1630
|
|
|
} |
1631
|
|
|
} |
1632
|
|
|
|
1633
|
|
|
return true; |
1634
|
|
|
} |
1635
|
|
|
|
1636
|
|
|
/** |
1637
|
|
|
* company. |
1638
|
|
|
* |
1639
|
|
|
* @return type |
1640
|
|
|
*/ |
1641
|
|
View Code Duplication |
public function company() |
|
|
|
|
1642
|
|
|
{ |
1643
|
|
|
$company = Company::Where('id', '=', '1')->first(); |
1644
|
|
|
if ($company->company_name == null) { |
1645
|
|
|
$company = 'Support Center'; |
1646
|
|
|
} else { |
1647
|
|
|
$company = $company->company_name; |
1648
|
|
|
} |
1649
|
|
|
|
1650
|
|
|
return $company; |
1651
|
|
|
} |
1652
|
|
|
|
1653
|
|
|
/** |
1654
|
|
|
* system. |
1655
|
|
|
* |
1656
|
|
|
* @return type |
1657
|
|
|
*/ |
1658
|
|
View Code Duplication |
public function system() |
|
|
|
|
1659
|
|
|
{ |
1660
|
|
|
$system = System::Where('id', '=', '1')->first(); |
1661
|
|
|
if ($system->name == null) { |
1662
|
|
|
$system = 'Support Center'; |
1663
|
|
|
} else { |
1664
|
|
|
$system = $system->name; |
1665
|
|
|
} |
1666
|
|
|
|
1667
|
|
|
return $system; |
1668
|
|
|
} |
1669
|
|
|
|
1670
|
|
|
/** |
1671
|
|
|
* shows trashed tickets. |
1672
|
|
|
* |
1673
|
|
|
* @return type response |
1674
|
|
|
*/ |
1675
|
|
View Code Duplication |
public function trash() |
|
|
|
|
1676
|
|
|
{ |
1677
|
|
|
$table = \Datatable::table() |
1678
|
|
|
->addColumn( |
1679
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
1680
|
|
|
->noScript(); |
1681
|
|
|
|
1682
|
|
|
return view('themes.default1.agent.helpdesk.ticket.trash', compact('table')); |
1683
|
|
|
} |
1684
|
|
|
|
1685
|
|
|
/** |
1686
|
|
|
* shows unassigned tickets. |
1687
|
|
|
* |
1688
|
|
|
* @return type |
1689
|
|
|
*/ |
1690
|
|
View Code Duplication |
public function unassigned() |
|
|
|
|
1691
|
|
|
{ |
1692
|
|
|
$table = \Datatable::table() |
1693
|
|
|
->addColumn( |
1694
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
1695
|
|
|
->noScript(); |
1696
|
|
|
|
1697
|
|
|
return view('themes.default1.agent.helpdesk.ticket.unassigned', compact('table')); |
1698
|
|
|
} |
1699
|
|
|
|
1700
|
|
|
/** |
1701
|
|
|
* shows tickets assigned to Auth::user(). |
1702
|
|
|
* |
1703
|
|
|
* @return type |
1704
|
|
|
*/ |
1705
|
|
View Code Duplication |
public function myticket() |
|
|
|
|
1706
|
|
|
{ |
1707
|
|
|
$table = \Datatable::table() |
1708
|
|
|
->addColumn( |
1709
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
1710
|
|
|
->noScript(); |
1711
|
|
|
|
1712
|
|
|
return view('themes.default1.agent.helpdesk.ticket.myticket', compact('table')); |
1713
|
|
|
} |
1714
|
|
|
|
1715
|
|
|
/** |
1716
|
|
|
* cleanMe. |
1717
|
|
|
* |
1718
|
|
|
* @param type $input |
1719
|
|
|
* |
1720
|
|
|
* @return type |
1721
|
|
|
*/ |
1722
|
|
|
public function cleanMe($input) |
1723
|
|
|
{ |
1724
|
|
|
$input = mysqli_real_escape_string($input); |
1725
|
|
|
$input = htmlspecialchars($input, ENT_IGNORE, 'utf-8'); |
1726
|
|
|
$input = strip_tags($input); |
1727
|
|
|
$input = stripslashes($input); |
1728
|
|
|
|
1729
|
|
|
return $input; |
1730
|
|
|
} |
1731
|
|
|
|
1732
|
|
|
/** |
1733
|
|
|
* autosearch. |
1734
|
|
|
* |
1735
|
|
|
* @param type Image $image |
1736
|
|
|
* |
1737
|
|
|
* @return type json |
1738
|
|
|
*/ |
1739
|
|
|
public function autosearch($id) |
|
|
|
|
1740
|
|
|
{ |
1741
|
|
|
$term = \Input::get('term'); |
1742
|
|
|
$user = \App\User::where('email', 'LIKE', '%'.$term.'%')->lists('email'); |
1743
|
|
|
echo json_encode($user); |
1744
|
|
|
} |
1745
|
|
|
|
1746
|
|
|
/** |
1747
|
|
|
* autosearch2. |
1748
|
|
|
* |
1749
|
|
|
* @param type Image $image |
1750
|
|
|
* |
1751
|
|
|
* @return type json |
1752
|
|
|
*/ |
1753
|
|
|
public function autosearch2(User $user) |
1754
|
|
|
{ |
1755
|
|
|
$user = $user->lists('email'); |
|
|
|
|
1756
|
|
|
echo json_encode($user); |
1757
|
|
|
} |
1758
|
|
|
|
1759
|
|
|
/** |
1760
|
|
|
* autosearch. |
1761
|
|
|
* |
1762
|
|
|
* @param type Image $image |
1763
|
|
|
* |
1764
|
|
|
* @return type json |
1765
|
|
|
*/ |
1766
|
|
|
public function usersearch() |
1767
|
|
|
{ |
1768
|
|
|
$email = Input::get('search'); |
1769
|
|
|
$ticket_id = Input::get('ticket_id'); |
1770
|
|
|
$data = User::where('email', '=', $email)->first(); |
1771
|
|
|
if ($data == null) { |
1772
|
|
|
return '<div id="alert11" class="alert alert-warning alert-dismissable">' |
1773
|
|
|
.'<button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>' |
1774
|
|
|
.'<i class="icon fa fa-ban"></i>' |
1775
|
|
|
.'This Email doesnot exist in the system' |
1776
|
|
|
.'</div>' |
1777
|
|
|
.'</div>'; |
1778
|
|
|
} |
1779
|
|
|
$ticket_collaborator = Ticket_Collaborator::where('ticket_id', '=', $ticket_id)->where('user_id', '=', $data->id)->first(); |
1780
|
|
|
if (!isset($ticket_collaborator)) { |
1781
|
|
|
$ticket_collaborator = new Ticket_Collaborator(); |
1782
|
|
|
$ticket_collaborator->isactive = 1; |
|
|
|
|
1783
|
|
|
$ticket_collaborator->ticket_id = $ticket_id; |
|
|
|
|
1784
|
|
|
$ticket_collaborator->user_id = $data->id; |
|
|
|
|
1785
|
|
|
$ticket_collaborator->role = 'ccc'; |
|
|
|
|
1786
|
|
|
$ticket_collaborator->save(); |
1787
|
|
|
|
1788
|
|
|
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-check"></i>Success!</h4><h4><i class="icon fa fa-user"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'</div></div>'; |
1789
|
|
|
} else { |
1790
|
|
|
return '<div id="alert11" class="alert alert-warning alert-dismissable"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-warning"></i>'.$data->user_name.'</h4><div id="message-success1">'.$data->email.'<br/>This user already Collaborated</div></div>'; |
1791
|
|
|
} |
1792
|
|
|
} |
1793
|
|
|
|
1794
|
|
|
/** |
1795
|
|
|
* useradd. |
1796
|
|
|
* |
1797
|
|
|
* @param type Image $image |
1798
|
|
|
* |
1799
|
|
|
* @return type json |
1800
|
|
|
*/ |
1801
|
|
|
public function useradd() |
1802
|
|
|
{ |
1803
|
|
|
$name = Input::get('name'); |
1804
|
|
|
$email = Input::get('email'); |
1805
|
|
|
$ticket_id = Input::get('ticket_id'); |
1806
|
|
|
$user_search = User::where('email', '=', $email)->first(); |
|
|
|
|
1807
|
|
|
if (isset($user_serach)) { |
|
|
|
|
1808
|
|
|
return '<div id="alert11" class="alert alert-warning alert-dismissable" ><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-alert"></i>Alert!</h4><div id="message-success1">This user already Exists</div></div>'; |
1809
|
|
|
} else { |
1810
|
|
|
$company = $this->company(); |
|
|
|
|
1811
|
|
|
$user = new User(); |
1812
|
|
|
$user->first_name = $name; |
|
|
|
|
1813
|
|
|
$user->user_name = $email; |
|
|
|
|
1814
|
|
|
$user->email = $email; |
|
|
|
|
1815
|
|
|
$password = $this->generateRandomString(); |
1816
|
|
|
$user->password = \Hash::make($password); |
|
|
|
|
1817
|
|
|
$user->role = 'user'; |
|
|
|
|
1818
|
|
|
$user->active = 1; |
|
|
|
|
1819
|
|
|
if ($user->save()) { |
1820
|
|
|
$user_id = $user->id; |
|
|
|
|
1821
|
|
|
|
1822
|
|
|
$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]); |
1823
|
|
|
} |
1824
|
|
|
$ticket_collaborator = new Ticket_Collaborator(); |
1825
|
|
|
$ticket_collaborator->isactive = 1; |
|
|
|
|
1826
|
|
|
$ticket_collaborator->ticket_id = $ticket_id; |
|
|
|
|
1827
|
|
|
$ticket_collaborator->user_id = $user->id; |
|
|
|
|
1828
|
|
|
$ticket_collaborator->role = 'ccc'; |
|
|
|
|
1829
|
|
|
$ticket_collaborator->save(); |
1830
|
|
|
|
1831
|
|
|
return '<div id="alert11" class="alert alert-dismissable" style="color:#60B23C;background-color:#F2F2F2;"><button id="dismiss11" type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button><h4><i class="icon fa fa-user"></i>'.$user->user_name.'</h4><div id="message-success1">'.$user->email.'</div></div>'; |
|
|
|
|
1832
|
|
|
} |
1833
|
|
|
} |
1834
|
|
|
|
1835
|
|
|
/** |
1836
|
|
|
* user remove. |
1837
|
|
|
* |
1838
|
|
|
* @return type |
1839
|
|
|
*/ |
1840
|
|
|
public function userremove() |
1841
|
|
|
{ |
1842
|
|
|
$id = Input::get('data1'); |
1843
|
|
|
$ticket_collaborator = Ticket_Collaborator::where('id', '=', $id)->delete(); |
|
|
|
|
1844
|
|
|
|
1845
|
|
|
return 1; |
1846
|
|
|
} |
1847
|
|
|
|
1848
|
|
|
/** |
1849
|
|
|
* select_all. |
1850
|
|
|
* |
1851
|
|
|
* @return type |
1852
|
|
|
*/ |
1853
|
|
|
public function select_all() |
1854
|
|
|
{ |
1855
|
|
|
if (Input::has('select_all')) { |
1856
|
|
|
$selectall = Input::get('select_all'); |
1857
|
|
|
$value = Input::get('submit'); |
1858
|
|
|
foreach ($selectall as $delete) { |
1859
|
|
|
$ticket = Tickets::whereId($delete)->first(); |
1860
|
|
|
if ($value == 'Delete') { |
1861
|
|
|
$this->delete($delete, new Tickets()); |
1862
|
|
|
} elseif ($value == 'Close') { |
1863
|
|
|
$this->close($delete, new Tickets()); |
1864
|
|
|
} elseif ($value == 'Open') { |
1865
|
|
|
$this->open($delete, new Tickets()); |
1866
|
|
|
} elseif ($value == 'Delete forever') { |
1867
|
|
|
$notification = Notification::select('id')->where('model_id', '=', $ticket->id)->get(); |
1868
|
|
|
foreach ($notification as $id) { |
1869
|
|
|
$user_notification = UserNotification::where( |
1870
|
|
|
'notification_id', '=', $id->id); |
1871
|
|
|
$user_notification->delete(); |
1872
|
|
|
} |
1873
|
|
|
$notification = Notification::select('id')->where('model_id', '=', $ticket->id); |
1874
|
|
|
$notification->delete(); |
1875
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $ticket->id)->get(); |
1876
|
|
|
foreach ($thread as $th_id) { |
1877
|
|
|
// echo $th_id->id." "; |
|
|
|
|
1878
|
|
|
$attachment = Ticket_attachments::where('thread_id', '=', $th_id->id)->get(); |
1879
|
|
|
if (count($attachment)) { |
1880
|
|
|
foreach ($attachment as $a_id) { |
1881
|
|
|
// echo $a_id->id . ' '; |
|
|
|
|
1882
|
|
|
$attachment = Ticket_attachments::find($a_id->id); |
1883
|
|
|
$attachment->delete(); |
1884
|
|
|
} |
1885
|
|
|
// echo "<br>"; |
1886
|
|
|
} |
1887
|
|
|
$thread = Ticket_Thread::find($th_id->id); |
1888
|
|
|
// dd($thread); |
|
|
|
|
1889
|
|
|
$thread->delete(); |
1890
|
|
|
} |
1891
|
|
|
$collaborators = Ticket_Collaborator::where('ticket_id', '=', $ticket->id)->get(); |
1892
|
|
|
if (count($collaborators)) { |
1893
|
|
|
foreach ($collaborators as $collab_id) { |
1894
|
|
|
// echo $collab_id->id; |
|
|
|
|
1895
|
|
|
$collab = Ticket_Collaborator::find($collab_id->id); |
1896
|
|
|
$collab->delete(); |
1897
|
|
|
} |
1898
|
|
|
} |
1899
|
|
|
$tickets = Tickets::find($ticket->id); |
1900
|
|
|
$tickets->delete(); |
1901
|
|
|
$data = ['id' => $ticket->id]; |
1902
|
|
|
\Event::fire('ticket-permanent-delete', [$data]); |
1903
|
|
|
} |
1904
|
|
|
} |
1905
|
|
|
if ($value == 'Delete') { |
1906
|
|
|
return redirect()->back()->with('success', lang::get('lang.moved_to_trash')); |
1907
|
|
|
} elseif ($value == 'Close') { |
1908
|
|
|
return redirect()->back()->with('success', Lang::get('lang.tickets_have_been_closed')); |
1909
|
|
|
} elseif ($value == 'Open') { |
1910
|
|
|
return redirect()->back()->with('success', Lang::get('lang.tickets_have_been_opened')); |
1911
|
|
|
} else { |
1912
|
|
|
return redirect()->back()->with('success', Lang::get('lang.hard-delete-success-message')); |
1913
|
|
|
} |
1914
|
|
|
} |
1915
|
|
|
|
1916
|
|
|
return redirect()->back()->with('fails', 'None Selected!'); |
1917
|
|
|
} |
1918
|
|
|
|
1919
|
|
|
/** |
1920
|
|
|
* user time zone. |
1921
|
|
|
* |
1922
|
|
|
* @param type $utc |
1923
|
|
|
* |
1924
|
|
|
* @return type date |
1925
|
|
|
*/ |
1926
|
|
|
public static function usertimezone($utc) |
1927
|
|
|
{ |
1928
|
|
|
$set = System::whereId('1')->first(); |
1929
|
|
|
$timezone = Timezones::whereId($set->time_zone)->first(); |
1930
|
|
|
$tz = $timezone->name; |
1931
|
|
|
$format = $set->date_time_format; |
1932
|
|
|
date_default_timezone_set($tz); |
1933
|
|
|
$offset = date('Z', strtotime($utc)); |
1934
|
|
|
$format = Date_time_format::whereId($format)->first()->format; |
1935
|
|
|
$date = date($format, strtotime($utc) + $offset); |
1936
|
|
|
|
1937
|
|
|
return $date; |
1938
|
|
|
} |
1939
|
|
|
|
1940
|
|
|
/** |
1941
|
|
|
* adding offset to updated_at time. |
1942
|
|
|
* |
1943
|
|
|
* @return date |
1944
|
|
|
*/ |
1945
|
|
|
public static function timeOffset($utc) |
1946
|
|
|
{ |
1947
|
|
|
$set = System::whereId('1')->first(); |
1948
|
|
|
$timezone = Timezones::whereId($set->time_zone)->first(); |
1949
|
|
|
$tz = $timezone->name; |
1950
|
|
|
date_default_timezone_set($tz); |
1951
|
|
|
$offset = date('Z', strtotime($utc)); |
1952
|
|
|
|
1953
|
|
|
return $offset; |
1954
|
|
|
} |
1955
|
|
|
|
1956
|
|
|
/** |
1957
|
|
|
* to get user date time format. |
1958
|
|
|
* |
1959
|
|
|
* @return string |
1960
|
|
|
*/ |
1961
|
|
|
public static function getDateTimeFormat() |
1962
|
|
|
{ |
1963
|
|
|
$set = System::select('date_time_format')->whereId('1')->first(); |
1964
|
|
|
|
1965
|
|
|
return $set->date_time_format; |
1966
|
|
|
} |
1967
|
|
|
|
1968
|
|
|
/** |
1969
|
|
|
* lock. |
1970
|
|
|
* |
1971
|
|
|
* @param type $id |
1972
|
|
|
* |
1973
|
|
|
* @return type null |
1974
|
|
|
*/ |
1975
|
|
|
public function lock($id) |
1976
|
|
|
{ |
1977
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
1978
|
|
|
$ticket->lock_by = Auth::user()->id; |
1979
|
|
|
$ticket->lock_at = date('Y-m-d H:i:s'); |
1980
|
|
|
$ticket->save(); |
1981
|
|
|
} |
1982
|
|
|
|
1983
|
|
|
/** |
1984
|
|
|
* Show the deptopen ticket list page. |
1985
|
|
|
* |
1986
|
|
|
* @return type response |
1987
|
|
|
*/ |
1988
|
|
View Code Duplication |
public function deptopen($id) |
|
|
|
|
1989
|
|
|
{ |
1990
|
|
|
$dept = Department::where('name', '=', $id)->first(); |
1991
|
|
|
if (Auth::user()->role == 'agent') { |
1992
|
|
|
if (Auth::user()->primary_dpt == $dept->id) { |
1993
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.open', compact('id')); |
1994
|
|
|
} else { |
1995
|
|
|
return redirect()->back()->with('fails', 'Unauthorised!'); |
1996
|
|
|
} |
1997
|
|
|
} else { |
1998
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.open', compact('id')); |
1999
|
|
|
} |
2000
|
|
|
} |
2001
|
|
|
|
2002
|
|
|
public function deptTicket($dept, $status) |
2003
|
|
|
{ |
2004
|
|
|
if (\Auth::user()->role === 'agent') { |
2005
|
|
|
$dept2 = Department::where('id', '=', \Auth::user()->primary_dpt)->first(); |
2006
|
|
|
if ($dept !== $dept2->name) { |
2007
|
|
|
return redirect()->back()->with('fails', Lang::get('lang.unauthorized_access')); |
2008
|
|
|
} |
2009
|
|
|
} |
2010
|
|
|
$table = \Datatable::table() |
2011
|
|
|
->addColumn( |
2012
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
2013
|
|
|
->noScript(); |
2014
|
|
|
|
2015
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.tickets', compact('dept', 'status', 'table')); |
2016
|
|
|
} |
2017
|
|
|
|
2018
|
|
|
/** |
2019
|
|
|
* Show the deptclose ticket list page. |
2020
|
|
|
* |
2021
|
|
|
* @return type response |
2022
|
|
|
*/ |
2023
|
|
View Code Duplication |
public function deptclose($id) |
|
|
|
|
2024
|
|
|
{ |
2025
|
|
|
$dept = Department::where('name', '=', $id)->first(); |
2026
|
|
|
if (Auth::user()->role == 'agent') { |
2027
|
|
|
if (Auth::user()->primary_dpt == $dept->id) { |
2028
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.closed', compact('id')); |
2029
|
|
|
} else { |
2030
|
|
|
return redirect()->back()->with('fails', 'Unauthorised!'); |
2031
|
|
|
} |
2032
|
|
|
} else { |
2033
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.closed', compact('id')); |
2034
|
|
|
} |
2035
|
|
|
} |
2036
|
|
|
|
2037
|
|
|
/** |
2038
|
|
|
* Show the deptinprogress ticket list page. |
2039
|
|
|
* |
2040
|
|
|
* @return type response |
2041
|
|
|
*/ |
2042
|
|
View Code Duplication |
public function deptinprogress($id) |
|
|
|
|
2043
|
|
|
{ |
2044
|
|
|
$dept = Department::where('name', '=', $id)->first(); |
2045
|
|
|
if (Auth::user()->role == 'agent') { |
2046
|
|
|
if (Auth::user()->primary_dpt == $dept->id) { |
2047
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.inprogress', compact('id')); |
2048
|
|
|
} else { |
2049
|
|
|
return redirect()->back()->with('fails', 'Unauthorised!'); |
2050
|
|
|
} |
2051
|
|
|
} else { |
2052
|
|
|
return view('themes.default1.agent.helpdesk.dept-ticket.inprogress', compact('id')); |
2053
|
|
|
} |
2054
|
|
|
} |
2055
|
|
|
|
2056
|
|
|
/** |
2057
|
|
|
* Store ratings of the user. |
2058
|
|
|
* |
2059
|
|
|
* @return type Redirect |
2060
|
|
|
*/ |
2061
|
|
View Code Duplication |
public function rating($id, Request $request, \App\Model\helpdesk\Ratings\RatingRef $rating_ref) |
|
|
|
|
2062
|
|
|
{ |
2063
|
|
|
foreach ($request->all() as $key => $value) { |
2064
|
|
|
if (strpos($key, '_') !== false) { |
2065
|
|
|
$ratName = str_replace('_', ' ', $key); |
2066
|
|
|
} else { |
2067
|
|
|
$ratName = $key; |
2068
|
|
|
} |
2069
|
|
|
$ratID = \App\Model\helpdesk\Ratings\Rating::where('name', '=', $ratName)->first(); |
2070
|
|
|
$ratingrefs = $rating_ref->where('rating_id', '=', $ratID->id)->where('ticket_id', '=', $id)->first(); |
|
|
|
|
2071
|
|
|
if ($ratingrefs !== null) { |
2072
|
|
|
$ratingrefs->rating_id = $ratID->id; |
2073
|
|
|
$ratingrefs->ticket_id = $id; |
2074
|
|
|
|
2075
|
|
|
$ratingrefs->thread_id = '0'; |
2076
|
|
|
$ratingrefs->rating_value = $value; |
2077
|
|
|
$ratingrefs->save(); |
2078
|
|
|
} else { |
2079
|
|
|
$rating_ref->rating_id = $ratID->id; |
|
|
|
|
2080
|
|
|
$rating_ref->ticket_id = $id; |
|
|
|
|
2081
|
|
|
|
2082
|
|
|
$rating_ref->thread_id = '0'; |
|
|
|
|
2083
|
|
|
$rating_ref->rating_value = $value; |
|
|
|
|
2084
|
|
|
$rating_ref->save(); |
2085
|
|
|
} |
2086
|
|
|
} |
2087
|
|
|
|
2088
|
|
|
return redirect()->back()->with('Success', 'Thank you for your rating!'); |
2089
|
|
|
} |
2090
|
|
|
|
2091
|
|
|
/** |
2092
|
|
|
* Store Client rating about reply of agent quality. |
2093
|
|
|
* |
2094
|
|
|
* @return type Redirect |
2095
|
|
|
*/ |
2096
|
|
View Code Duplication |
public function ratingReply($id, Request $request, \App\Model\helpdesk\Ratings\RatingRef $rating_ref) |
|
|
|
|
2097
|
|
|
{ |
2098
|
|
|
foreach ($request->all() as $key => $value) { |
2099
|
|
|
$key1 = explode(',', $key); |
2100
|
|
|
if (strpos($key1[0], '_') !== false) { |
2101
|
|
|
$ratName = str_replace('_', ' ', $key1[0]); |
2102
|
|
|
} else { |
2103
|
|
|
$ratName = $key1[0]; |
2104
|
|
|
} |
2105
|
|
|
|
2106
|
|
|
$ratID = \App\Model\helpdesk\Ratings\Rating::where('name', '=', $ratName)->first(); |
2107
|
|
|
$ratingrefs = $rating_ref->where('rating_id', '=', $ratID->id)->where('thread_id', '=', $key1[1])->first(); |
|
|
|
|
2108
|
|
|
|
2109
|
|
|
if ($ratingrefs !== null) { |
2110
|
|
|
$ratingrefs->rating_id = $ratID->id; |
2111
|
|
|
$ratingrefs->ticket_id = $id; |
2112
|
|
|
|
2113
|
|
|
$ratingrefs->thread_id = $key1[1]; |
2114
|
|
|
$ratingrefs->rating_value = $value; |
2115
|
|
|
$ratingrefs->save(); |
2116
|
|
|
} else { |
2117
|
|
|
$rating_ref->rating_id = $ratID->id; |
|
|
|
|
2118
|
|
|
$rating_ref->ticket_id = $id; |
|
|
|
|
2119
|
|
|
|
2120
|
|
|
$rating_ref->thread_id = $key1[1]; |
|
|
|
|
2121
|
|
|
$rating_ref->rating_value = $value; |
|
|
|
|
2122
|
|
|
$rating_ref->save(); |
2123
|
|
|
} |
2124
|
|
|
} |
2125
|
|
|
|
2126
|
|
|
return redirect()->back()->with('Success', 'Thank you for your rating!'); |
2127
|
|
|
} |
2128
|
|
|
|
2129
|
|
|
/** |
2130
|
|
|
* System default email. |
2131
|
|
|
*/ |
2132
|
|
|
public function system_mail() |
2133
|
|
|
{ |
2134
|
|
|
$email = Email::where('id', '=', '1')->first(); |
2135
|
|
|
|
2136
|
|
|
return $email->sys_email; |
2137
|
|
|
} |
2138
|
|
|
|
2139
|
|
|
/** |
2140
|
|
|
* checkLock($id) |
2141
|
|
|
* function to check and lock ticket. |
2142
|
|
|
* |
2143
|
|
|
* @param int $id |
2144
|
|
|
* |
2145
|
|
|
* @return int |
2146
|
|
|
*/ |
2147
|
|
|
public function checkLock($id) |
2148
|
|
|
{ |
2149
|
|
|
$ticket = DB::table('tickets')->select('id', 'lock_at', 'lock_by')->where('id', '=', $id)->first(); |
2150
|
|
|
$cad = DB::table('settings_ticket')->select('collision_avoid')->where('id', '=', 1)->first(); |
2151
|
|
|
$cad = $cad->collision_avoid; //collision avoid duration defined in system |
2152
|
|
|
|
2153
|
|
|
$to_time = strtotime($ticket->lock_at); //last locking time |
2154
|
|
|
|
2155
|
|
|
$from_time = time(); //user system's cureent time |
2156
|
|
|
// difference in last locking time and user system's current time |
2157
|
|
|
$diff = round(abs($to_time - $from_time) / 60, 2); |
2158
|
|
|
|
2159
|
|
|
if ($diff < $cad && Auth::user()->id != $ticket->lock_by) { |
2160
|
|
|
$user_data = User::select('user_name', 'first_name', 'last_name')->where('id', '=', $ticket->lock_by)->first(); |
2161
|
|
|
if ($user_data->first_name != '') { |
2162
|
|
|
$name = $user_data->first_name.' '.$user_data->last_name; |
2163
|
|
|
} else { |
2164
|
|
|
$name = $user_data->username; |
2165
|
|
|
} |
2166
|
|
|
|
2167
|
|
|
return Lang::get('lang.locked-ticket')." <a href='".route('user.show', $ticket->lock_by)."'>".$name.'</a> '.$diff.' '.Lang::get('lang.minutes-ago'); //ticket is locked |
2168
|
|
|
} elseif ($diff < $cad && Auth::user()->id == $ticket->lock_by) { |
2169
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
2170
|
|
|
$ticket->lock_at = date('Y-m-d H:i:s'); |
2171
|
|
|
$ticket->save(); |
2172
|
|
|
|
2173
|
|
|
return 4; //ticket is locked by same user who is requesting access |
2174
|
|
|
} else { |
2175
|
|
|
if (Auth::user()->id == $ticket->lock_by) { |
2176
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
2177
|
|
|
$ticket->lock_at = date('Y-m-d H:i:s'); |
2178
|
|
|
$ticket->save(); |
2179
|
|
|
|
2180
|
|
|
return 1; //ticket is available and lock ticket for the same user who locked ticket previously |
2181
|
|
|
} else { |
2182
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
2183
|
|
|
$ticket->lock_by = Auth::user()->id; |
2184
|
|
|
$ticket->lock_at = date('Y-m-d H:i:s'); |
2185
|
|
|
$ticket->save(); //ticket is available and lock ticket for new user |
2186
|
|
|
return 2; |
2187
|
|
|
} |
2188
|
|
|
} |
2189
|
|
|
} |
2190
|
|
|
|
2191
|
|
|
/** |
2192
|
|
|
* function to Change owner. |
2193
|
|
|
* |
2194
|
|
|
* @param type $id |
2195
|
|
|
* |
2196
|
|
|
* @return type bool |
2197
|
|
|
*/ |
2198
|
|
|
public function changeOwner($id) |
2199
|
|
|
{ |
2200
|
|
|
$action = Input::get('action'); |
2201
|
|
|
$email = Input::get('email'); |
2202
|
|
|
$ticket_id = Input::get('ticket_id'); |
2203
|
|
|
$send_mail = Input::get('send-mail'); |
|
|
|
|
2204
|
|
|
|
2205
|
|
|
if ($action === 'change-add-owner') { |
2206
|
|
|
$name = Input::get('name'); |
2207
|
|
|
$returnValue = $this->changeOwnerAdd($email, $name, $ticket_id); |
2208
|
|
|
if ($returnValue === 0) { |
2209
|
|
|
return 4; |
2210
|
|
|
} elseif ($returnValue === 2) { |
2211
|
|
|
return 5; |
2212
|
|
|
} else { |
|
|
|
|
2213
|
|
|
//do nothing |
2214
|
|
|
} |
2215
|
|
|
} |
2216
|
|
|
$user = User::where('email', '=', $email)->first(); |
2217
|
|
|
$count = count($user); |
2218
|
|
|
if ($count === 1) { |
2219
|
|
|
$user_id = $user->id; |
2220
|
|
|
$ticket = Tickets::where('id', '=', $id)->first(); |
2221
|
|
|
if ($user_id === (int) $ticket->user_id) { |
2222
|
|
|
return 400; |
2223
|
|
|
} |
2224
|
|
|
$ticket_number = $ticket->ticket_number; |
2225
|
|
|
$ticket->user_id = $user_id; |
2226
|
|
|
$ticket->save(); |
2227
|
|
|
$ticket_thread = Ticket_Thread::where('ticket_id', '=', $id)->first(); |
2228
|
|
|
$ticket_subject = $ticket_thread->title; |
2229
|
|
|
$thread = new Ticket_Thread(); |
2230
|
|
|
$thread->ticket_id = $ticket->id; |
|
|
|
|
2231
|
|
|
$thread->user_id = Auth::user()->id; |
|
|
|
|
2232
|
|
|
$thread->is_internal = 1; |
|
|
|
|
2233
|
|
|
$thread->body = 'This ticket now belongs to '.$user->user_name; |
|
|
|
|
2234
|
|
|
$thread->save(); |
2235
|
|
|
|
2236
|
|
|
//mail functionality |
2237
|
|
|
$company = $this->company(); |
2238
|
|
|
$system = $this->system(); |
2239
|
|
|
|
2240
|
|
|
$agent = $user->first_name; |
2241
|
|
|
$agent_email = $user->email; |
2242
|
|
|
|
2243
|
|
|
$master = Auth::user()->first_name.' '.Auth::user()->last_name; |
2244
|
|
|
if (Alert::first()->internal_status == 1 || Alert::first()->internal_assigned_agent == 1) { |
2245
|
|
|
// ticket assigned send mail |
2246
|
|
|
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) { |
2247
|
|
|
$message->to($agent_email, $agent)->subject($ticket_subject.'[#'.$ticket_number.']'); |
2248
|
|
|
}); |
2249
|
|
|
} |
2250
|
|
|
|
2251
|
|
|
return 1; |
2252
|
|
|
} else { |
2253
|
|
|
return 0; |
2254
|
|
|
} |
2255
|
|
|
} |
2256
|
|
|
|
2257
|
|
|
/** |
2258
|
|
|
* useradd. |
2259
|
|
|
* |
2260
|
|
|
* @param type Image $image |
2261
|
|
|
* |
2262
|
|
|
* @return type json |
2263
|
|
|
*/ |
2264
|
|
|
public function changeOwnerAdd($email, $name, $ticket_id) |
2265
|
|
|
{ |
2266
|
|
|
$name = $name; |
|
|
|
|
2267
|
|
|
$email = $email; |
|
|
|
|
2268
|
|
|
$ticket_id = $ticket_id; |
|
|
|
|
2269
|
|
|
$validator = \Validator::make( |
2270
|
|
|
['email' => $email, |
2271
|
|
|
'name' => $name, ], ['email' => 'required|email', |
2272
|
|
|
] |
2273
|
|
|
); |
2274
|
|
|
$user = User::where('email', '=', $email)->first(); |
2275
|
|
|
$count = count($user); |
2276
|
|
|
if ($count === 1) { |
2277
|
|
|
return 0; |
2278
|
|
|
} elseif ($validator->fails()) { |
2279
|
|
|
return 2; |
2280
|
|
|
} else { |
2281
|
|
|
$company = $this->company(); |
|
|
|
|
2282
|
|
|
$user = new User(); |
2283
|
|
|
$user->user_name = $name; |
|
|
|
|
2284
|
|
|
$user->email = $email; |
|
|
|
|
2285
|
|
|
$password = $this->generateRandomString(); |
2286
|
|
|
$user->password = \Hash::make($password); |
|
|
|
|
2287
|
|
|
$user->role = 'user'; |
|
|
|
|
2288
|
|
|
if ($user->save()) { |
2289
|
|
|
$user_id = $user->id; |
|
|
|
|
2290
|
|
|
try { |
2291
|
|
|
$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]); |
2292
|
|
|
} catch (\Exception $e) { |
|
|
|
|
2293
|
|
|
} |
2294
|
|
|
} |
2295
|
|
|
|
2296
|
|
|
return 1; |
2297
|
|
|
} |
2298
|
|
|
} |
2299
|
|
|
|
2300
|
|
|
public function getMergeTickets($id) |
2301
|
|
|
{ |
2302
|
|
|
if ($id == 0) { |
2303
|
|
|
$t_id = Input::get('data1'); |
2304
|
|
View Code Duplication |
foreach ($t_id as $value) { |
|
|
|
|
2305
|
|
|
$title = Ticket_Thread::select('title')->where('ticket_id', '=', $value)->first(); |
2306
|
|
|
echo "<option value='$value'>".$title->title.'</option>'; |
2307
|
|
|
} |
2308
|
|
|
} else { |
2309
|
|
|
$ticket = Tickets::select('user_id')->where('id', '=', $id)->first(); |
2310
|
|
|
$ticket_data = Tickets::select('ticket_number', 'id') |
2311
|
|
|
->where('user_id', '=', $ticket->user_id)->where('id', '!=', $id)->where('status', '=', 1)->get(); |
2312
|
|
View Code Duplication |
foreach ($ticket_data as $value) { |
|
|
|
|
2313
|
|
|
$title = Ticket_Thread::select('title')->where('ticket_id', '=', $value->id)->first(); |
2314
|
|
|
echo "<option value='$value->id'>".$title->title.'</option>'; |
2315
|
|
|
} |
2316
|
|
|
} |
2317
|
|
|
} |
2318
|
|
|
|
2319
|
|
|
public function checkMergeTickets($id) |
2320
|
|
|
{ |
2321
|
|
|
if ($id == 0) { |
2322
|
|
|
if (Input::get('data1') == null || count(Input::get('data1')) == 1) { |
2323
|
|
|
return 0; |
2324
|
|
|
} else { |
2325
|
|
|
$t_id = Input::get('data1'); |
2326
|
|
|
$previousValue = null; |
2327
|
|
|
$match = 1; |
2328
|
|
|
foreach ($t_id as $value) { |
2329
|
|
|
$ticket = Tickets::select('user_id')->where('id', '=', $value)->first(); |
2330
|
|
|
if ($previousValue == null || $previousValue == $ticket->user_id) { |
2331
|
|
|
$previousValue = $ticket->user_id; |
2332
|
|
|
$match = 1; |
2333
|
|
|
} else { |
2334
|
|
|
$match = 2; |
2335
|
|
|
break; |
2336
|
|
|
} |
2337
|
|
|
} |
2338
|
|
|
|
2339
|
|
|
return $match; |
2340
|
|
|
} |
2341
|
|
|
} else { |
2342
|
|
|
$ticket = Tickets::select('user_id')->where('id', '=', $id)->first(); |
2343
|
|
|
$ticket_data = Tickets::select('ticket_number', 'id') |
2344
|
|
|
->where('user_id', '=', $ticket->user_id) |
2345
|
|
|
->where('id', '!=', $id) |
2346
|
|
|
->where('status', '=', 1)->get(); |
2347
|
|
|
if (isset($ticket_data) && count($ticket_data) >= 1) { |
2348
|
|
|
return 1; |
2349
|
|
|
} else { |
2350
|
|
|
return 0; |
2351
|
|
|
} |
2352
|
|
|
} |
2353
|
|
|
} |
2354
|
|
|
|
2355
|
|
|
public function mergeTickets($id) |
2356
|
|
|
{ |
2357
|
|
|
// split the phrase by any number of commas or space characters, |
2358
|
|
|
// which include " ", \r, \t, \n and \f |
2359
|
|
|
$t_id = preg_split("/[\s,]+/", $id); |
2360
|
|
|
if (count($t_id) > 1) { |
2361
|
|
|
$p_id = Input::get('p_id'); //parent ticket id |
2362
|
|
|
$t_id = array_diff($t_id, [$p_id]); |
2363
|
|
|
} else { |
2364
|
|
|
$t_id = Input::get('t_id'); //getting array of tickets to merge |
2365
|
|
|
if ($t_id == null) { |
2366
|
|
|
return 2; |
2367
|
|
|
} else { |
2368
|
|
|
$temp_id = Input::get('p_id'); //getting parent ticket |
2369
|
|
|
if ($id == $temp_id) { |
2370
|
|
|
$p_id = $id; |
2371
|
|
|
} else { |
2372
|
|
|
$p_id = $temp_id; |
2373
|
|
|
array_push($t_id, $id); |
2374
|
|
|
$t_id = array_diff($t_id, [$temp_id]); |
2375
|
|
|
} |
2376
|
|
|
} |
2377
|
|
|
} |
2378
|
|
|
$parent_ticket = Tickets::select('ticket_number')->where('id', '=', $p_id)->first(); |
2379
|
|
|
$parent_thread = Ticket_Thread::where('ticket_id', '=', $p_id)->first(); |
2380
|
|
|
foreach ($t_id as $value) {//to create new thread of the tickets to be merged with parent |
2381
|
|
|
$thread = Ticket_Thread::where('ticket_id', '=', $value)->first(); |
2382
|
|
|
$ticket = Tickets::select('ticket_number')->where('id', '=', $value)->first(); |
2383
|
|
|
Ticket_Thread::where('ticket_id', '=', $value) |
2384
|
|
|
->update(['ticket_id' => $p_id]); |
2385
|
|
|
Ticket_Form_Data::where('ticket_id', '=', $value) |
2386
|
|
|
->update(['ticket_id' => $p_id]); |
2387
|
|
|
Ticket_Collaborator::where('ticket_id', '=', $value) |
2388
|
|
|
->update(['ticket_id' => $p_id]); |
2389
|
|
|
Tickets::where('id', '=', $value) |
2390
|
|
|
->update(['status' => 3]); |
2391
|
|
|
//event has $p_id and $value |
2392
|
|
|
\Event::fire('ticket.merge', [['parent' => $p_id, 'child' => $value]]); |
2393
|
|
|
if (!empty(Input::get('reason'))) { |
2394
|
|
|
$reason = Input::get('reason'); |
2395
|
|
|
} else { |
2396
|
|
|
$reason = Lang::get('lang.no-reason'); |
2397
|
|
|
} |
2398
|
|
|
if (!empty(Input::get('title'))) { |
2399
|
|
|
Ticket_Thread::where('ticket_id', '=', $p_id)->first() |
2400
|
|
|
->update(['title' => Input::get('title')]); |
2401
|
|
|
} |
2402
|
|
|
|
2403
|
|
|
$new_thread = new Ticket_Thread(); |
2404
|
|
|
$new_thread->ticket_id = $thread->ticket_id; |
|
|
|
|
2405
|
|
|
$new_thread->user_id = Auth::user()->id; |
|
|
|
|
2406
|
|
|
$new_thread->is_internal = 0; |
|
|
|
|
2407
|
|
|
$new_thread->title = $thread->title; |
|
|
|
|
2408
|
|
|
$new_thread->body = Lang::get('lang.get_merge_message'). |
|
|
|
|
2409
|
|
|
" <a href='".route('ticket.thread', [$p_id]). |
2410
|
|
|
"'>#".$parent_ticket->ticket_number.'</a><br><br><b>'.Lang::get('lang.merge-reason').':</b> '.$reason; |
2411
|
|
|
$new_thread->format = $thread->format; |
|
|
|
|
2412
|
|
|
$new_thread->ip_address = $thread->ip_address; |
|
|
|
|
2413
|
|
|
|
2414
|
|
|
$new_parent_thread = new Ticket_Thread(); |
2415
|
|
|
$new_parent_thread->ticket_id = $p_id; |
|
|
|
|
2416
|
|
|
$new_parent_thread->user_id = Auth::user()->id; |
|
|
|
|
2417
|
|
|
$new_parent_thread->is_internal = 1; |
|
|
|
|
2418
|
|
|
$new_parent_thread->title = $thread->title; |
|
|
|
|
2419
|
|
|
$new_parent_thread->body = Lang::get('lang.ticket')." <a href='".route('ticket.thread', [$value])."'>#".$ticket->ticket_number.'</a> '.Lang::get('lang.ticket_merged').'<br><br><b>'.Lang::get('lang.merge-reason').':</b> '.$reason; |
|
|
|
|
2420
|
|
|
$new_parent_thread->format = $parent_thread->format; |
|
|
|
|
2421
|
|
|
$new_parent_thread->ip_address = $parent_thread->ip_address; |
|
|
|
|
2422
|
|
|
if ($new_thread->save() && $new_parent_thread->save()) { |
2423
|
|
|
$success = 1; |
2424
|
|
|
} else { |
2425
|
|
|
$success = 0; |
2426
|
|
|
} |
2427
|
|
|
} |
2428
|
|
|
$this->sendMergeNotification($p_id, $t_id); |
2429
|
|
|
|
2430
|
|
|
return $success; |
|
|
|
|
2431
|
|
|
} |
2432
|
|
|
|
2433
|
|
|
public function getParentTickets($id) |
2434
|
|
|
{ |
2435
|
|
|
$title = Ticket_Thread::select('title')->where('ticket_id', '=', $id)->first(); |
2436
|
|
|
echo "<option value='$id'>".$title->title.'</option>'; |
2437
|
|
|
$tickets = Input::get('data1'); |
2438
|
|
View Code Duplication |
foreach ($tickets as $value) { |
|
|
|
|
2439
|
|
|
$title = Ticket_Thread::select('title')->where('ticket_id', '=', $value)->first(); |
2440
|
|
|
echo "<option value='$value'>".$title->title.'</option>'; |
2441
|
|
|
} |
2442
|
|
|
} |
2443
|
|
|
|
2444
|
|
|
/* |
2445
|
|
|
* chumper's function to return data to chumper datatable. |
2446
|
|
|
* @param Array-object $tickets |
2447
|
|
|
* |
|
|
|
|
2448
|
|
|
* @return Array-object |
2449
|
|
|
*/ |
|
|
|
|
2450
|
|
|
|
2451
|
|
|
public static function getTable($tickets) |
2452
|
|
|
{ |
2453
|
|
|
return \Datatables::of($tickets) |
2454
|
|
|
->addColumn('id', function ($tickets) { |
2455
|
|
|
return "<input type='checkbox' name='select_all[]' id='".$tickets->id."' onclick='someFunction(this.id)' class='selectval icheckbox_flat-blue' value='".$tickets->id."'></input>"; |
2456
|
|
|
}) |
2457
|
|
|
->addColumn('title', function ($tickets) { |
2458
|
|
|
if (isset($tickets->ticket_title)) { |
2459
|
|
|
$string = str_limit($tickets->ticket_title, 20); |
2460
|
|
|
} else { |
2461
|
|
|
$string = '(no subject)'; |
2462
|
|
|
} |
2463
|
|
|
$collab = $tickets->countcollaborator; |
2464
|
|
|
if ($collab > 0) { |
2465
|
|
|
$collabString = ' <i class="fa fa-users"></i>'; |
2466
|
|
|
} else { |
2467
|
|
|
$collabString = null; |
2468
|
|
|
} |
2469
|
|
|
$attachCount = $tickets->countattachment; |
2470
|
|
|
if ($attachCount > 0) { |
2471
|
|
|
$attachString = ' <i class="fa fa-paperclip"></i>'; |
2472
|
|
|
} else { |
2473
|
|
|
$attachString = ''; |
2474
|
|
|
} |
2475
|
|
|
$css = $tickets->css; |
2476
|
|
|
$titles = ''; |
|
|
|
|
2477
|
|
|
if ($tickets->ticket_title) { |
2478
|
|
|
$titles = $tickets->ticket_title; |
|
|
|
|
2479
|
|
|
} |
2480
|
|
|
$tooltip_script = self::tooltip($tickets->id); |
2481
|
|
|
|
2482
|
|
|
return "<div class='tooltip1' id='tool".$tickets->id."'> |
2483
|
|
|
<a href='".route('ticket.thread', [$tickets->id])."'>".ucfirst($string)." <span style='color:green'>(".$tickets->countthread.") <i class='".$css."'></i></span> |
2484
|
|
|
</a>".$collabString.$attachString.$tooltip_script. |
2485
|
|
|
"<span class='tooltiptext' id='tooltip".$tickets->id."'>Loading...</span></div>"; |
2486
|
|
|
}) |
2487
|
|
|
->addColumn('ticket_number', function ($tickets) { |
2488
|
|
|
return "<a href='".route('ticket.thread', [$tickets->id])."' title='".$tickets->ticket_number."'>#".$tickets->ticket_number.'</a>'; |
2489
|
|
|
}) |
2490
|
|
|
->addColumn('priority', function ($tickets) { |
2491
|
|
|
$rep = ($tickets->last_replier == 'client') ? '#F39C12' : '#000'; |
2492
|
|
|
$priority = $tickets->priority; |
2493
|
|
|
if ($priority != null) { |
2494
|
|
|
$prio = '<button class="btn btn-xs '.$rep.'" style="background-color: '.$tickets->priority_color.'; color:#F7FBCB">'.ucfirst($tickets->priority).'</button>'; |
2495
|
|
|
} else { |
2496
|
|
|
$prio = $tickets->last_relier_role; |
2497
|
|
|
} |
2498
|
|
|
|
2499
|
|
|
return $prio; |
2500
|
|
|
}) |
2501
|
|
|
->addColumn('user_name', function ($tickets) { |
2502
|
|
|
$from = $tickets->first_name; |
2503
|
|
|
$url = route('user.show', $tickets->user_id); |
2504
|
|
|
$name = ''; |
|
|
|
|
2505
|
|
|
if ($from) { |
2506
|
|
|
$name = $tickets->first_name.' '.$tickets->last_name; |
2507
|
|
|
} else { |
2508
|
|
|
$name = $tickets->user_name; |
2509
|
|
|
} |
2510
|
|
|
$color = ''; |
2511
|
|
|
if ($tickets->verified == 0 || $tickets->verified == '0') { |
2512
|
|
|
$color = "<i class='fa fa-exclamation-triangle' title='".Lang::get('lang.accoutn-not-verified')."'></i>"; |
2513
|
|
|
} |
2514
|
|
|
|
2515
|
|
|
return "<a href='".$url."' title='".Lang::get('lang.see-profile1').' '.ucfirst($tickets->user_name).'''.Lang::get('lang.see-profile2')."'><span style='color:#508983'>".ucfirst(str_limit($name, 30)).' <span style="color:#f75959">'.$color.'</span></span></a>'; |
2516
|
|
|
}) |
2517
|
|
|
->addColumn('assign_user_name', function ($tickets) { |
2518
|
|
|
if ($tickets->assigned_to == null) { |
2519
|
|
|
return "<span style='color:red'>Unassigned</span>"; |
2520
|
|
|
} else { |
2521
|
|
|
$assign = $tickets->assign_user_name; |
|
|
|
|
2522
|
|
|
$url = route('user.show', $tickets->assigned_to); |
2523
|
|
|
|
2524
|
|
|
return "<a href='".$url."' title='".Lang::get('lang.see-profile1').' '.ucfirst($tickets->assign_first_name).'''.Lang::get('lang.see-profile2')."'><span style='color:green'>".ucfirst($tickets->assign_first_name).' '.ucfirst($tickets->assign_last_name).'</span></a>'; |
2525
|
|
|
} |
2526
|
|
|
}) |
2527
|
|
View Code Duplication |
->addColumn('updated_at', function ($tickets) { |
|
|
|
|
2528
|
|
|
$TicketDatarow = $tickets->updated_at; |
2529
|
|
|
$updated = '--'; |
2530
|
|
|
if ($TicketDatarow) { |
2531
|
|
|
$updated = $tickets->updated_at; |
2532
|
|
|
} |
2533
|
|
|
|
2534
|
|
|
return '<span style="display:none">'.$updated.'</span>'.UTC::usertimezone($updated); |
2535
|
|
|
}) |
2536
|
|
View Code Duplication |
->addColumn('created_at', function ($tickets) { |
|
|
|
|
2537
|
|
|
$TicketDatarow = $tickets->created_at; |
2538
|
|
|
$updated = '--'; |
2539
|
|
|
if ($TicketDatarow) { |
2540
|
|
|
$updated = $tickets->created_at; |
2541
|
|
|
} |
2542
|
|
|
|
2543
|
|
|
return '<span style="display:none">'.$updated.'</span>'.UTC::usertimezone($updated); |
2544
|
|
|
}) |
2545
|
|
|
->make(); |
2546
|
|
|
} |
2547
|
|
|
|
2548
|
|
|
/** |
2549
|
|
|
*@category function to call and show ticket details in tool tip via ajax |
2550
|
|
|
* |
2551
|
|
|
*@param null |
2552
|
|
|
* |
2553
|
|
|
*@return string //script to load tooltip data |
2554
|
|
|
*/ |
2555
|
|
|
public static function tooltip($ticketid) |
2556
|
|
|
{ |
2557
|
|
|
return "<script> |
2558
|
|
|
var timeoutId; |
2559
|
|
|
$('#tool".$ticketid."').hover(function() { |
2560
|
|
|
if (!timeoutId) { |
2561
|
|
|
timeoutId = window.setTimeout(function() { |
2562
|
|
|
timeoutId = null; // EDIT: added this line |
2563
|
|
|
$.ajax({ |
2564
|
|
|
url:'".url('ticket/tooltip')."', |
2565
|
|
|
dataType:'html', |
2566
|
|
|
type:'get', |
2567
|
|
|
data:{'ticketid':".$ticketid."}, |
2568
|
|
|
success : function(html){ |
2569
|
|
|
$('#tooltip".$ticketid."').html(html); |
2570
|
|
|
}, |
2571
|
|
|
}); |
2572
|
|
|
}, 2000); |
2573
|
|
|
} |
2574
|
|
|
}, |
2575
|
|
|
function () { |
2576
|
|
|
if (timeoutId) { |
2577
|
|
|
window.clearTimeout(timeoutId); |
2578
|
|
|
timeoutId = null; |
2579
|
|
|
} else { |
2580
|
|
|
} |
2581
|
|
|
}); |
2582
|
|
|
</script>"; |
2583
|
|
|
} |
2584
|
|
|
|
2585
|
|
|
public function getTooltip(Request $request) |
2586
|
|
|
{ |
2587
|
|
|
$ticketid = $request->input('ticketid'); |
2588
|
|
|
$ticket = Tickets::find($ticketid); |
2589
|
|
|
$firstThread = $ticket->thread()->select('user_id', 'poster', 'body')->first(); |
2590
|
|
|
$lastThread = $ticket->thread()->select('user_id', 'poster', 'body')->orderBy('id', 'desc')->first(); |
2591
|
|
|
|
2592
|
|
|
return '<b>'.$firstThread->user->user_name.' ('.$firstThread->poster.')</b></br>' |
2593
|
|
|
.$firstThread->purify().'<br><hr>' |
2594
|
|
|
.'<b>'.$lastThread->user->user_name.'('.$lastThread->poster.')</b>' |
2595
|
|
|
.$lastThread->purify().'<br><hr>'; |
2596
|
|
|
} |
2597
|
|
|
|
2598
|
|
|
//Auto-close tickets |
2599
|
|
View Code Duplication |
public function autoCloseTickets() |
|
|
|
|
2600
|
|
|
{ |
2601
|
|
|
$workflow = \App\Model\helpdesk\Workflow\WorkflowClose::whereId(1)->first(); |
2602
|
|
|
|
2603
|
|
|
if ($workflow->condition == 1) { |
2604
|
|
|
$overdues = Tickets::where('status', '=', 1)->where('isanswered', '=', 0)->orderBy('id', 'DESC')->get(); |
2605
|
|
|
if (count($overdues) == 0) { |
2606
|
|
|
$tickets = null; |
|
|
|
|
2607
|
|
|
} else { |
2608
|
|
|
$i = 0; |
2609
|
|
|
foreach ($overdues as $overdue) { |
2610
|
|
|
// $sla_plan = Sla_plan::where('id', '=', $overdue->sla)->first(); |
|
|
|
|
2611
|
|
|
|
2612
|
|
|
$ovadate = $overdue->created_at; |
2613
|
|
|
$new_date = date_add($ovadate, date_interval_create_from_date_string($workflow->days.' days')).'<br/><br/>'; |
2614
|
|
|
if (date('Y-m-d H:i:s') > $new_date) { |
2615
|
|
|
$i++; |
2616
|
|
|
$overdue->status = 3; |
2617
|
|
|
$overdue->closed = 1; |
2618
|
|
|
$overdue->closed_at = date('Y-m-d H:i:s'); |
2619
|
|
|
$overdue->save(); |
2620
|
|
|
// if($workflow->send_email == 1) { |
|
|
|
|
2621
|
|
|
// $this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $overdue->dept_id), $to = ['name' => $user_name, 'email' => $email], $message = ['subject' => $ticket_subject.'[#'.$ticket_number.']', 'scenario' => 'close-ticket'], $template_variables = ['ticket_number' => $ticket_number]); |
2622
|
|
|
// } |
2623
|
|
|
} |
2624
|
|
|
} |
2625
|
|
|
// dd(count($value)); |
|
|
|
|
2626
|
|
|
// if ($i > 0) { |
2627
|
|
|
// $tickets = new collection($value); |
2628
|
|
|
// } else { |
2629
|
|
|
// $tickets = null; |
2630
|
|
|
// } |
2631
|
|
|
} |
2632
|
|
|
} else { |
|
|
|
|
2633
|
|
|
} |
2634
|
|
|
} |
2635
|
|
|
|
2636
|
|
|
/** |
2637
|
|
|
* @category function to chech if user verifcaition required for creating tickets or not |
2638
|
|
|
* |
2639
|
|
|
* @param null |
2640
|
|
|
* |
2641
|
|
|
* @return int 0/1 |
2642
|
|
|
*/ |
2643
|
|
|
public function checkUserVerificationStatus() |
2644
|
|
|
{ |
2645
|
|
|
$status = CommonSettings::select('status') |
2646
|
|
|
->where('option_name', '=', 'send_otp') |
2647
|
|
|
->first(); |
2648
|
|
|
if ($status->status == 0 || $status->status == '0') { |
2649
|
|
|
return 1; |
2650
|
|
|
} else { |
2651
|
|
|
return 0; |
2652
|
|
|
} |
2653
|
|
|
} |
2654
|
|
|
|
2655
|
|
|
/** |
2656
|
|
|
* This function is used for auto filling in new ticket. |
2657
|
|
|
* |
2658
|
|
|
* @return type view |
2659
|
|
|
*/ |
2660
|
|
|
public function autofill() |
2661
|
|
|
{ |
2662
|
|
|
return view('themes.default1.agent.helpdesk.ticket.getautocomplete'); |
2663
|
|
|
} |
2664
|
|
|
|
2665
|
|
|
public function pdfThread($threadid) |
2666
|
|
|
{ |
2667
|
|
|
try { |
2668
|
|
|
$threads = new Ticket_Thread(); |
2669
|
|
|
$thread = $threads->leftJoin('tickets', 'ticket_thread.ticket_id', '=', 'tickets.id') |
|
|
|
|
2670
|
|
|
->leftJoin('users', 'ticket_thread.user_id', '=', 'users.id') |
2671
|
|
|
->where('ticket_thread.id', $threadid) |
2672
|
|
|
->first(); |
2673
|
|
|
//dd($thread); |
2674
|
|
|
if (!$thread) { |
2675
|
|
|
throw new Exception('Sorry we can not find your request'); |
2676
|
|
|
} |
2677
|
|
|
$company = \App\Model\helpdesk\Settings\Company::where('id', '=', '1')->first(); |
2678
|
|
|
$system = \App\Model\helpdesk\Settings\System::where('id', '=', '1')->first(); |
2679
|
|
|
$ticket = Tickets::where('id', $thread->ticket_id)->first(); |
2680
|
|
|
$html = view('themes.default1.agent.helpdesk.ticket.thread-pdf', compact('thread', 'system', 'company', 'ticket'))->render(); |
|
|
|
|
2681
|
|
|
$html1 = mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'); |
2682
|
|
|
|
2683
|
|
|
return PDF::load($html1)->show(); |
2684
|
|
|
} catch (Exception $ex) { |
2685
|
|
|
return redirect()->back()->with('fails', $ex->getMessage()); |
2686
|
|
|
} |
2687
|
|
|
} |
2688
|
|
|
|
2689
|
|
|
public static function getSourceByname($name) |
2690
|
|
|
{ |
2691
|
|
|
$sources = new Ticket_source(); |
2692
|
|
|
$source = $sources->where('name', $name)->first(); |
|
|
|
|
2693
|
|
|
|
2694
|
|
|
return $source; |
2695
|
|
|
} |
2696
|
|
|
|
2697
|
|
|
public static function getSourceById($sourceid) |
2698
|
|
|
{ |
2699
|
|
|
$sources = new Ticket_source(); |
2700
|
|
|
$source = $sources->where('id', $sourceid)->first(); |
|
|
|
|
2701
|
|
|
|
2702
|
|
|
return $source; |
2703
|
|
|
} |
2704
|
|
|
|
2705
|
|
|
public static function getSourceCssClass($sourceid) |
2706
|
|
|
{ |
2707
|
|
|
$css = 'fa fa-comment'; |
2708
|
|
|
$source = self::getSourceById($sourceid); |
2709
|
|
|
if ($source) { |
2710
|
|
|
$css = $source->css_class; |
2711
|
|
|
} |
2712
|
|
|
|
2713
|
|
|
return $css; |
2714
|
|
|
} |
2715
|
|
|
|
2716
|
|
|
public function getSystemDefaultHelpTopic() |
2717
|
|
|
{ |
2718
|
|
|
$ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); |
2719
|
|
|
$ticket_setting = $ticket_settings->find(1); |
|
|
|
|
2720
|
|
|
$help_topicid = $ticket_setting->help_topic; |
2721
|
|
|
|
2722
|
|
|
return $help_topicid; |
2723
|
|
|
} |
2724
|
|
|
|
2725
|
|
|
public function getSystemDefaultSla() |
2726
|
|
|
{ |
2727
|
|
|
$ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); |
2728
|
|
|
$ticket_setting = $ticket_settings->find(1); |
|
|
|
|
2729
|
|
|
$sla = $ticket_setting->sla; |
2730
|
|
|
|
2731
|
|
|
return $sla; |
2732
|
|
|
} |
2733
|
|
|
|
2734
|
|
|
public function getSystemDefaultPriority() |
2735
|
|
|
{ |
2736
|
|
|
$ticket_settings = new \App\Model\helpdesk\Settings\Ticket(); |
2737
|
|
|
$ticket_setting = $ticket_settings->find(1); |
|
|
|
|
2738
|
|
|
$priority = $ticket_setting->priority; |
2739
|
|
|
|
2740
|
|
|
return $priority; |
2741
|
|
|
} |
2742
|
|
|
|
2743
|
|
|
public function getSystemDefaultDepartment() |
2744
|
|
|
{ |
2745
|
|
|
$systems = new \App\Model\helpdesk\Settings\System(); |
2746
|
|
|
$system = $systems->find(1); |
|
|
|
|
2747
|
|
|
$department = $system->department; |
2748
|
|
|
|
2749
|
|
|
return $department; |
2750
|
|
|
} |
2751
|
|
|
|
2752
|
|
|
public function findTicketFromTicketCreateUser($result = []) |
2753
|
|
|
{ |
2754
|
|
|
$ticket_number = $this->checkArray('0', $result); |
2755
|
|
|
if ($ticket_number !== '') { |
2756
|
|
|
$tickets = new \App\Model\helpdesk\Ticket\Tickets(); |
2757
|
|
|
$ticket = $tickets->where('ticket_number', $ticket_number)->first(); |
|
|
|
|
2758
|
|
|
if ($ticket) { |
2759
|
|
|
return $ticket; |
2760
|
|
|
} |
2761
|
|
|
} |
2762
|
|
|
} |
2763
|
|
|
|
2764
|
|
|
public function findUserFromTicketCreateUserId($result = []) |
2765
|
|
|
{ |
2766
|
|
|
$ticket = $this->findTicketFromTicketCreateUser($result); |
2767
|
|
|
if ($ticket) { |
2768
|
|
|
$userid = $ticket->user_id; |
2769
|
|
|
|
2770
|
|
|
return $userid; |
2771
|
|
|
} |
2772
|
|
|
} |
2773
|
|
|
|
2774
|
|
|
public function checkArray($key, $array) |
2775
|
|
|
{ |
2776
|
|
|
$value = ''; |
2777
|
|
|
if (array_key_exists($key, $array)) { |
2778
|
|
|
$value = $array[$key]; |
2779
|
|
|
} |
2780
|
|
|
|
2781
|
|
|
return $value; |
2782
|
|
|
} |
2783
|
|
|
|
2784
|
|
|
public function getAdmin() |
2785
|
|
|
{ |
2786
|
|
|
$users = new \App\User(); |
2787
|
|
|
$admin = $users->where('role', 'admin')->first(); |
|
|
|
|
2788
|
|
|
|
2789
|
|
|
return $admin; |
2790
|
|
|
} |
2791
|
|
|
|
2792
|
|
|
public function attachmentSeperateOld($attach) |
2793
|
|
|
{ |
2794
|
|
|
$attacment = []; |
2795
|
|
|
if ($attach != null) { |
2796
|
|
|
$size = count($attach); |
2797
|
|
|
for ($i = 0; $i < $size; $i++) { |
2798
|
|
|
$file_name = $attach[$i]->getClientOriginalName(); |
2799
|
|
|
$file_path = $attach[$i]->getRealPath(); |
2800
|
|
|
$mime = $attach[$i]->getClientMimeType(); |
2801
|
|
|
$attacment[$i]['file_name'] = $file_name; |
2802
|
|
|
$attacment[$i]['file_path'] = $file_path; |
2803
|
|
|
$attacment[$i]['mime'] = $mime; |
2804
|
|
|
} |
2805
|
|
|
} |
2806
|
|
|
|
2807
|
|
|
return $attacment; |
2808
|
|
|
} |
2809
|
|
|
|
2810
|
|
|
public function attachmentSeperate($thread_id) |
2811
|
|
|
{ |
2812
|
|
|
if ($thread_id) { |
2813
|
|
|
$array = []; |
2814
|
|
|
$attachment = new Ticket_attachments(); |
2815
|
|
|
$attachments = $attachment->where('thread_id', $thread_id)->get(); |
|
|
|
|
2816
|
|
|
if ($attachments->count() > 0) { |
2817
|
|
|
foreach ($attachments as $key => $attach) { |
2818
|
|
|
$array[$key]['file_path'] = $attach->file; |
2819
|
|
|
$array[$key]['file_name'] = $attach->name; |
2820
|
|
|
$array[$key]['mime'] = $attach->type; |
2821
|
|
|
$array[$key]['mode'] = 'data'; |
2822
|
|
|
} |
2823
|
|
|
|
2824
|
|
|
return $array; |
2825
|
|
|
} |
2826
|
|
|
} |
2827
|
|
|
} |
2828
|
|
|
|
2829
|
|
|
/** |
2830
|
|
|
* @return type |
2831
|
|
|
*/ |
2832
|
|
View Code Duplication |
public function followupTicketList() |
|
|
|
|
2833
|
|
|
{ |
2834
|
|
|
try { |
2835
|
|
|
$table = \Datatable::table() |
2836
|
|
|
->addColumn( |
2837
|
|
|
'', Lang::get('lang.subject'), Lang::get('lang.ticket_id'), Lang::get('lang.priority'), Lang::get('lang.from'), Lang::get('lang.assigned_to'), Lang::get('lang.last_activity'), Lang::get('lang.created-at')) |
2838
|
|
|
->noScript(); |
2839
|
|
|
|
2840
|
|
|
return view('themes.default1.agent.helpdesk.followup.followup', compact('table')); |
2841
|
|
|
} catch (Exception $e) { |
2842
|
|
|
return Redirect()->back()->with('fails', $e->getMessage()); |
2843
|
|
|
} |
2844
|
|
|
} |
2845
|
|
|
|
2846
|
|
View Code Duplication |
public static function getSubject($subject) |
|
|
|
|
2847
|
|
|
{ |
2848
|
|
|
//$subject = $this->attributes['title']; |
|
|
|
|
2849
|
|
|
$array = imap_mime_header_decode($subject); |
2850
|
|
|
$title = ''; |
2851
|
|
|
if (is_array($array) && count($array) > 0) { |
2852
|
|
|
foreach ($array as $text) { |
2853
|
|
|
$title .= $text->text; |
2854
|
|
|
} |
2855
|
|
|
|
2856
|
|
|
return wordwrap($title, 70, "<br>\n"); |
2857
|
|
|
} |
2858
|
|
|
|
2859
|
|
|
return wordwrap($subject, 70, "<br>\n"); |
2860
|
|
|
} |
2861
|
|
|
|
2862
|
|
|
public function replyContent($content) |
2863
|
|
|
{ |
2864
|
|
|
preg_match_all('/<img[^>]+>/i', $content, $result); |
2865
|
|
|
$url = []; |
2866
|
|
|
$encode = []; |
2867
|
|
|
$img = []; |
2868
|
|
|
foreach ($result as $key=>$img_tag) { |
|
|
|
|
2869
|
|
|
//dd($img_tag); |
2870
|
|
|
preg_match_all('/(src)=("[^"]*")/i', $img_tag[$key], $img[$key]); |
2871
|
|
|
} |
2872
|
|
|
for ($i = 0; $i < count($img); $i++) { |
|
|
|
|
2873
|
|
|
$url = $img[$i][2][0]; |
2874
|
|
|
$encode = $this->divideUrl($img[$i][2][0]); |
2875
|
|
|
} |
2876
|
|
|
|
2877
|
|
|
return str_replace($url, $encode, $content); |
2878
|
|
|
} |
2879
|
|
|
|
2880
|
|
|
public function divideUrl($url) |
2881
|
|
|
{ |
2882
|
|
|
$baseurl = url('/'); |
2883
|
|
|
$trim = str_replace($baseurl, '', $url); |
2884
|
|
|
$trim = str_replace('"', '', $trim); |
2885
|
|
|
$trim = substr_replace($trim, '', 0, 1); |
2886
|
|
|
$path = public_path($trim); |
2887
|
|
|
|
2888
|
|
|
return $this->fileContent($path); |
2889
|
|
|
} |
2890
|
|
|
|
2891
|
|
|
public function fileContent($path) |
2892
|
|
|
{ |
2893
|
|
|
$exist = \File::exists($path); |
2894
|
|
|
$base64 = ''; |
2895
|
|
|
if ($exist) { |
2896
|
|
|
$content = \File::get($path); |
2897
|
|
|
$type = \File::extension($path); |
2898
|
|
|
$base64 = 'data:image/'.$type.';base64,'.base64_encode($content); |
2899
|
|
|
} |
2900
|
|
|
|
2901
|
|
|
return $base64; |
2902
|
|
|
} |
2903
|
|
|
|
2904
|
|
|
/** |
2905
|
|
|
*@category function to send notification of ticket merging to the owners |
2906
|
|
|
* |
2907
|
|
|
*@param srting array $t_id, $p_id |
2908
|
|
|
* |
2909
|
|
|
*@return null |
2910
|
|
|
*/ |
2911
|
|
|
public function sendMergeNotification($p_id, $t_id) |
2912
|
|
|
{ |
2913
|
|
|
try { |
2914
|
|
|
$ticket_details = Tickets::select('ticket_number', 'user_id', 'dept_id')->where('id', '=', $p_id)->first(); |
2915
|
|
|
$user_detail = User::where('id', '=', $ticket_details->user_id)->first(); |
2916
|
|
|
if ($user_detail->count() > 0) { |
2917
|
|
|
if ($user_detail->email !== null || $user_detail->email !== '') { |
2918
|
|
|
$meged_ticket_details = Tickets::select('ticket_number')->whereIn('id', $t_id)->get(); |
2919
|
|
|
$child_ticket_numbers = []; |
2920
|
|
|
foreach ($meged_ticket_details as $value) { |
2921
|
|
|
array_push($child_ticket_numbers, $value->ticket_number); |
2922
|
|
|
} |
2923
|
|
|
// dd(implode(", ",$child_ticket_numbers), $ticket_details->ticket_number); |
|
|
|
|
2924
|
|
|
$this->PhpMailController->sendmail($from = $this->PhpMailController->mailfrom('0', $ticket_details->dept_id), $to = ['user' => $user_detail->full_name, 'email' => $user_detail->email], $message = ['subject' => '', 'body' => '', 'scenario' => 'merge-ticket-notification'], $template_variables = ['user' => $user_detail->full_name, 'ticket_number' => $ticket_details->ticket_number, 'ticket_link' => route('ticket.thread', $p_id), 'merged_ticket_numbers' => implode(', ', $child_ticket_numbers)]); |
2925
|
|
|
} |
2926
|
|
|
} |
2927
|
|
|
} catch (\Exception $e) { |
2928
|
|
|
//catch the exception |
2929
|
|
|
} |
2930
|
|
|
} |
2931
|
|
|
} |
2932
|
|
|
|
Adding a
@return
annotation 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.