PluginProbe
Fluent Support – Helpdesk & Customer Support Ticket System / 1.5.2
Fluent Support – Helpdesk & Customer Support Ticket System v1.5.2
2.4.0 2.3.2 2.3.1 2.3.0 2.2.1 2.2.0 trunk 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.10.5 1.4.0 1.4.1 1.4.2 1.4.5 1.4.6 1.4.7 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 All 68 releases
fluent-support / app / Http / Controllers / UploaderController.php

UploaderController.php in Fluent Support – Helpdesk & Customer Support Ticket System 1.5.2, at app/Http/Controllers/UploaderController.php

77 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentSupport\App\Http\Controllers;
4
5 use FluentSupport\App\Models\Attachment;
6 use FluentSupport\App\Models\Ticket;
7 use FluentSupport\App\Services\EmailNotification\Settings;
8 use FluentSupport\App\Services\Helper;
9 use FluentSupport\App\Services\Includes\FileSystem;
10 use FluentSupport\Framework\Request\Request;
11
12 class UploaderController extends Controller
13 {
14 public function uploadTicketFiles(Request $request)
15 {
16 $settings = (new Settings())->globalBusinessSettings();
17 $maxFileSize = absint($settings['max_file_size']);
18 $mimeHeadings = Helper::getAcceptedMimeHeadings();
19
20 $maxSizeBytes = $maxFileSize * 1024;
21
22 $files = $this->validate($this->request->files(), [
23 'file' => 'max:' . $maxSizeBytes . '|mimetypes:' . implode(',', Helper::ticketAcceptedFileMiles())
24 ], [
25 'file.mimetypes' => sprintf(__('Only %s files are allowed.', 'fluent-support'), implode(', ', $mimeHeadings)),
26 'file.max' => sprintf(__('The file can not be more than %dMB. Please upload somewhere like dropbox/google drive and paste the link in the response', 'fluent-support'), $maxFileSize)
27 ]);
28
29 $ticketId = $request->get('ticket_id');
30
31 if ($ticketId == 'undefined') {
32 $ticketId = NULL;
33 }
34
35 if ($ticketId && $request->get('intended_ticket_hash') && Helper::isPublicSignedTicketEnabled()) {
36 $ticket = Ticket::with(['customer'])->findOrFail($ticketId);
37 $person = $ticket->customer;
38 } else {
39 $person = Helper::getCurrentPerson();
40 }
41
42 if ($person->person_type == 'customer') {
43 $disabledFields = apply_filters('fluent_support/disabled_ticket_fields', []);
44 if (in_array('file_upload', $disabledFields)) {
45 return $this->sendError([
46 'message' => 'You do not have permission to upload a file'
47 ]);
48 }
49 }
50
51 $uploadedFiles = FileSystem::setSubDir('ticket_' . $ticketId)->put($files);
52
53 $attachments = [];
54 foreach ($uploadedFiles as $file) {
55
56 $fileData = [
57 'ticket_id' => $ticketId,
58 'person_id' => $person->id,
59 'file_type' => $file['type'],
60 'file_path' => $file['file_path'],
61 'full_url' => $file['url'],
62 'title' => $file['name'],
63 'driver' => 'local',
64 'status' => 'in-active'
65 ];
66
67 $attachment = Attachment::create($fileData);
68 $attachments[] = $attachment->file_hash;
69 }
70
71 return [
72 'attachments' => $attachments
73 ];
74
75 }
76 }
77