<?php
namespace App\Controller\FO;
use App\Entity\Articles\Article;
use App\Entity\FO\Atelier;
use App\Entity\Utilisateur\Utilisateur;
use App\Entity\Utilisateur\UtilisateurAtelier;
use App\Form\FO\AtelierType;
use App\Form\FO\SupprimerFileGateAwayType;
use App\Library\Datatable\Util\Datatable;
use App\Security\Voter\EntityVoter;
use App\Service\Fabrication\OqtonService;
use App\Service\Utilisateur\ColonneTableauService;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
class GatewayController extends AbstractController
{
/**
* @Route("/gateway/afficher", name="dtc_gateway_afficher")
*/
public function listerAction(Request $request, $utilisateur = [], EntityManagerInterface $em,OqtonService $oqtonService,String $oqton_smb_input_share,String $oqton_smb_output_share,String $oqton_smb_nets_share)
{
//TEST4toto(Oqcam Nests)tututoto(Oqcam Create Orders)tututoto(Oqcam Nest Status)tutu
//$share->del("/Oqcam Nests/AAAAA/CCCC/3.txt");
$partage = $oqton_smb_input_share;
$share = $oqtonService->connectToSmbShare($partage);
$OqcamCreateOrders = $oqtonService->listerDossier($share,"");
$targetPath = __DIR__.'/../../../public/download/getaway/';
$partage = $oqton_smb_nets_share;
$share = $oqtonService->connectToSmbShare($partage);
$OqcamNests = $oqtonService->listerDossier($share,"");
$partage = $oqton_smb_output_share;
$share = $oqtonService->connectToSmbShare($partage);
$OqcamNestStatus = $oqtonService->listerDossier($share,"");
return $this->render('FO/Gateway/afficher.html.twig', ["OqcamNests"=>$OqcamNests,"OqcamCreateOrders"=>$OqcamCreateOrders,"OqcamNestStatus"=>$OqcamNestStatus]);
}
/**
* @Route("/gateway/telecharger/{share}/{fichier}", name="dtc_gateway_telecharger")
*/
public function telechargerAction(Request $request,String $share,String $fichier,OqtonService $oqtonService)
{
$smb = $oqtonService->connectToSmbShare($share);
$targetPath = __DIR__.'/../../../public/download/getaway/';
$d = $smb->get(base64_decode($fichier),$targetPath.basename(base64_decode($fichier)));
$filename = basename(base64_decode($fichier));
$file_url = $targetPath.basename(base64_decode($fichier));
header('Content-Type: '.mime_content_type($file_url));
header("Content-disposition: attachment; filename=\"".$filename."\"");
readfile($file_url);
unlink($file_url);
exit;
}
/**
* @Route("/gateway/supprimer/{share}/{fichier}", name="dtc_gateway_supprimer_fichier")
*/
public function supprimerAction(Request $request, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator,String $share,String $fichier,OqtonService $oqtonService)
{
$objet = new Atelier;
$objet->setLibelle("A");
$objet->setReference("A");
$titre_modal = $translator->trans("Demande de confirmation");
$user = $this->getUser();
$get = $request->query->all();
$erreur = "";
$form = $this->createForm(SupprimerFileGateAwayType::class, $objet);
$errors = "";
$form->handleRequest($request);
if ($form->isSubmitted()) {
if ($form->isValid()) {
$smb = $oqtonService->connectToSmbShare($share);
$fichier_decode = base64_decode($fichier);
$smb->del($fichier_decode);
$url = "";
$idFile = base64_decode($fichier);
$idFile = str_replace("/","_",$idFile);
$idFile = str_replace(" ","_",$idFile);
$idFile = str_replace(".","_",$idFile);
return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url, 'type' => 'supprimerFichierGateway', 'fichier' =>base64_decode($fichier),'id'=>$idFile]);
//$this->addFlash('notice', $translator->trans('Fichier supprimé avec succès !'));
//return new JsonResponse(['rendu' => '', 'valide' => '1', 'url' => $url]);
} else {
$errors = $validator->validate($objet);
$rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}
$rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
return new JsonResponse(['rendu' => $rendu, 'valide' => '0', 'url' => '', 'titre' => $titre_modal]);
}
}