get('session'); $csrf = $request->get('csrf'); $publicKey = $request->get('publicKey'); $field = $this->get('net15.form.forge.fields.manager')->getByPublicKey($publicKey); $files_uploaded = $session->get('files_'.$csrf); $locale = $this->get('request_stack')->getCurrentRequest()->getLocale(); $translator = $this->get('translator'); $files_uploaded['message'] = $translator->trans('file_manager.file.no_file', [], null, $locale); // If CSRF Token is ok we upload files otherwise we send an CSRF Token error if($this->isCsrfTokenValid($field->getid(),$csrf)){ $files = $request->files->all(); // Upload files $files_uploaded = $this->get('net15.file.upload.manager')->upload_file($files, $files_uploaded); // Update uploaded files in session $session->set('files_'.$csrf, $files_uploaded); } else { $files_uploaded['message'] = $translator->trans('file_manager.file.error_csrf_token', [], null, $locale); } $json_datas = json_encode($files_uploaded['files']); // Add message flash if ($files_uploaded['message'] == $translator->trans('file_manager.file.file_uploaded', [], null, $locale)){ $this->get('session')->getFlashBag()->set('success', $files_uploaded['message']); }else{ $this->get('session')->getFlashBag()->set('error', $files_uploaded['message']); } return $this->render('@FileManager/default/list.files.html.twig',['files'=>$files_uploaded['files'],'json_datas'=>$json_datas]); } public function uploadFileFromTicketMessage(Request $request){ // Recuperate a session and all the files that have been uploaded $session = $this->get('session'); $csrf = $request->get('csrf'); $publicKey = $request->get('publicKey'); $ticket = $this->get('net15.ticket.tickets.manager')->getByPublicKey($publicKey); $files_uploaded = $session->get('files_'.$csrf); $locale = $this->get('request_stack')->getCurrentRequest()->getLocale(); $translator = $this->get('translator'); $files_uploaded['message'] = $translator->trans('file_manager.file.no_file', [], null, $locale); // If CSRF Token is ok we upload files otherwise we send an CSRF Token error if($this->isCsrfTokenValid($ticket->getId(),$csrf)){ $files = $request->files->all(); // Upload files $files_uploaded = $this->get('net15.file.upload.manager')->upload_file($files, $files_uploaded); // Update uploaded files in session $session->set('files_'.$csrf, $files_uploaded); } else { $files_uploaded['message'] = $translator->trans('file_manager.file.error_csrf_token', [], null, $locale); } $json_datas = json_encode($files_uploaded['files']); // Add message flash if ($files_uploaded['message'] == $translator->trans('file_manager.file.file_uploaded', [], null, $locale)){ $this->get('session')->getFlashBag()->set('success', $files_uploaded['message']); }else{ $this->get('session')->getFlashBag()->set('error', $files_uploaded['message']); } return $this->render('@FileManager/default/list.files.from.ticket.html.twig',['files'=>$files_uploaded['files'],'json_datas'=>$json_datas]); } /** * @param Request $request * @return JsonResponse * @throws \Doctrine\ORM\ORMException */ public function uploadAvatar(Request $request){ $csrf = $request->get('csrf'); $locale = $this->get('request_stack')->getCurrentRequest()->getLocale(); $translator = $this->get('translator'); $response['message'] = $translator->trans('file_manager.file.no_file', [], null, $locale); $user = $this->getUser(); if($this->isCsrfTokenValid($user->getId(),$csrf)){ $files = $request->files->all(); $response = $this->get('net15.file.upload.manager')->upload_avatar($files, $response, $user); }else { $response['message'] = $translator->trans('file_manager.file.error_csrf_token', [], null, $locale); } return new JsonResponse($response); } /** * @param Request $request * @param ContainerInterface $container * @param TranslatorInterface $translator * @param string|null $js_callback_function * @param string $lang * @return \Symfony\Component\HttpFoundation\Response */ public function fileManagerUploadFile(Request $request, ContainerInterface $container, TranslatorInterface $translator, string $js_callback_function = null, string $lang = ''){ $csrf = $request->get('csrf'); $locale = $this->get('request_stack')->getCurrentRequest()->getLocale(); $response['message'] = $translator->trans('file_manager.file.no_file', [], null, $locale); $response['directory'] = null; $response['success'] = false; $callback_function = $js_callback_function; // $user = $this->getUser(); if($this->isCsrfTokenValid('file_manager_upload_files',$csrf)){ $files = $request->files->all(); /** * @var $file UploadedFile */ foreach ($files['files'] as $file){ $response = $container->get('net15.box.manager')->upload_file($file, $response); } }else { $response['message'] = $translator->trans('file_manager.file.error_csrf_token', [], null, $locale); } return $this->render('@FileManager/default/files_upload/fileManager.files.html.twig', [ 'directory' => $response['directory'], 'message' => $response['message'], 'success' => $response['success'], 'callback_function' => $callback_function, 'lang' => $lang ]); } }