src/Controller/AccueilController.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class AccueilController extends AbstractController
  9. {
  10.     public function __construct(
  11.         AdminUrlGenerator $adminUrlGenerator
  12.     ) {
  13.         $this->adminUrlGenerator $adminUrlGenerator;
  14.     }
  15.     /**
  16.      * @Route("/", name="app_home")
  17.      */
  18.     public function index(): Response
  19.     {
  20.         return $this->redirectToRoute('admin');
  21.         /* return $this->render('accueil/index.html.twig', [
  22.             'controller_name' => 'AccueilController',
  23.         ]); */
  24.     }
  25.     // get_dirs_content
  26.     public function htmlNiveauIndicator($dirname$racine)
  27.     {
  28.         $res $this->getParentDirs($dirname$racine);
  29.         $html "";
  30.         foreach ($res['name'] as $key => $value) {
  31.             $html .= '<button type="button" class="btn btn-secondary mx-1" onclick="getdirfiles(\'' $res['path'][$key] . '\', \'valid\')">' $value '</button>';
  32.             if (($key 1) < count($res['name'])) {
  33.                 $html .= '<i class="fa fa-chevron-right" style="color: #cbc8c8;"></i>';
  34.             }
  35.         }
  36.         return $html;
  37.     }
  38.     public function htmlDirCRes($dirname$selected$racine)
  39.     {
  40.         $res $this->getDirs($dirname$racine);
  41.         $html '<div class="my-2 p-2">';
  42.         $html .= '<div class="p-2">';
  43.         $html .= '<div class="card p-2">';
  44.         $html .= '<div class="d-flex flex-wrap">';
  45.         $html .= '<i class="bi bi-arrow-return-right"></i>';
  46.         foreach ($res["dir"] as $value) {
  47.             $html .= '<button type="button" class="btn btn-primary mx-1" onclick="getdirfiles(\'' $res["filePath"] . $value '/\', \'valid\')">' $value '</button>';
  48.         }
  49.         $html .= '</div>';
  50.         $html .= '</div>';
  51.         $html .= '';
  52.         $html .= '<i class="bi bi-arrow-bar-down"></i>';
  53.         $html .= '<div class="card p-2">';
  54.         $html .= '<div class="d-flex flex-wrap">';
  55.         //dump($selected);
  56.         foreach ($res["file"] as $value) {
  57.             //dump($value);
  58.             $html .= '<div class="m-2" style="width: 200px; height: fit-content;">';
  59.             $imgPath $res["filePath"];
  60.             if ($racine != '') {
  61.                 if (strpos($res["filePath"], $racine) == 0) {
  62.                     $imgPath substr_replace($res["filePath"], ""0strlen($racine));
  63.                 }
  64.             }
  65.             if (strpos($imgPath"/") != 0) {
  66.                 $imgPath "/" $imgPath;
  67.             }
  68.             if ($this->getUser()->getProjet()->getSwitchEnLigne()) {
  69.                 if ($selected == ("/" $value)) {
  70.                     $html .= '<img id="imagegellery" src="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . '" data-dir="' $imgPath $value '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px solid #5656b5; border-color: #5656b5; background-color: #5656b5" loading="lazy">';
  71.                 } else {
  72.                     $html .= '<img id="imagegellery" src="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . '" data-dir="' $imgPath $value '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  73.                 }
  74.             } else {
  75.                 if ($selected == ("/" $value)) {
  76.                     $html .= '<img id="imagegellery" src="' $this->getUser()->getProjet()->getImageHttpServer() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' $imgPath $value '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px solid #5656b5; border-color: #5656b5; background-color: #5656b5" loading="lazy">';
  77.                 } else {
  78.                     $html .= '<img id="imagegellery" src="' $this->getUser()->getProjet()->getImageHttpServer() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' $imgPath $value '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  79.                 }
  80.             }
  81.             // $html .= '<img src="' . $this->getUser()->getProjet()->getImageHttpServer() . $res["filePath"] . $value . '" data-racine="' . $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' . $res["filePath"] . $value . '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: fit-content; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  82.             $html .= '</div>';
  83.         }
  84.         $html .= '</div>';
  85.         $html .= '</div>';
  86.         $html .= '</div>';
  87.         $html .= '<script>checkImageGalleyExt()</script>';
  88.         return $html;
  89.     }
  90.     public function getParentDirs($dirname$racine)
  91.     {
  92.         $parentsName explode("/"$dirname);
  93.         $parents = [];
  94.         $paths = [];
  95.         $path "";
  96.         $parents[] = '<i class="bi bi-house-door-fill"></i>';
  97.         $paths[] = $racine "/";
  98.         $npaths = [];
  99.         $nparents = [];
  100.         foreach ($parentsName as $value) {
  101.             if ($value != '') {
  102.                 array_push($parents$value);
  103.                 $path .= $value "/";
  104.                 array_push($paths$path);
  105.             }
  106.         }
  107.         if ($racine != '') {
  108.             foreach ($paths as $key => $value) {
  109.                 if ($key != 1) {
  110.                     array_push($npaths$value);
  111.                     array_push($nparents$parents[$key]);
  112.                 }
  113.             }
  114.         } else {
  115.             $npaths $paths;
  116.             $nparents $parents;
  117.         }
  118.         $parentsName['name'] = $nparents;
  119.         $parentsName['path'] = $npaths;
  120.         return $parentsName;
  121.     }
  122.     public function getDirs($dirName$racine)
  123.     {
  124.         if ($this->getUser()->getProjet()->getSwitchEnLigne()) {
  125.             $ftp_server $this->getUser()->getProjet()->getImageFtpServerEnligne();
  126.             $ftp_username $this->getUser()->getProjet()->getImageFtpLoginEnligne();
  127.             $ftp_userpass $this->getUser()->getProjet()->getImageFtpMdpEnligne();
  128.         } else {
  129.             $ftp_server $this->getUser()->getProjet()->getImageFtpServer();
  130.             $ftp_username $this->getUser()->getProjet()->getImageFtpLogin();
  131.             $ftp_userpass $this->getUser()->getProjet()->getImageFtpMdp();
  132.         }
  133.         if (str_contains($ftp_server'/')) {
  134.             $pos strpos($ftp_server'/');
  135.             $racine substr($ftp_server$pos);
  136.             $ftp_server str_replace($racine""$ftp_server);
  137.         }
  138.         $ftp_conn ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  139.         $login ftp_login($ftp_conn$ftp_username$ftp_userpass);
  140.         ftp_set_option($ftp_connFTP_USEPASVADDRESSfalse); // set ftp option
  141.         ftp_pasv($ftp_conntrue); //make connection to passive mode
  142.         $filesPath "";
  143.         $dirs $this->ftp_mlsd_dir($ftp_conn$dirName);
  144.         $files $this->ftp_mlsd_file($ftp_conn$dirName);
  145.         $filesPath $dirName;
  146.         /* if (strpos($dirName, $racine) == 0) {
  147.             $filesPath = substr_replace($dirName, "", 0, strlen($racine));
  148.         } */
  149.         $dirlst = [];
  150.         $dirlst['dir'] = $dirs;
  151.         $dirlst['file'] = $files;
  152.         $dirlst['filePath'] = $filesPath;
  153.         // close connection
  154.         ftp_close($ftp_conn);
  155.         return $dirlst;
  156.     }
  157.     public function ftp_mlsd_dir($ftp_stream$directory)
  158.     {
  159.         $result = [];
  160.         $files ftp_mlsd($ftp_stream$directory);
  161.         if ($files === false) {
  162.             die("Cannot list $directory");
  163.         }
  164.         if (count($files) != 0) {
  165.             foreach ($files as $file) {
  166.                 if ($file["type"] == "dir") {
  167.                     $name $file["name"];
  168.                     array_push($result$name);
  169.                 }
  170.             }
  171.         }
  172.         return $result;
  173.     }
  174.     public function ftp_mlsd_file($ftp_stream$directory)
  175.     {
  176.         $result = [];
  177.         $files ftp_mlsd($ftp_stream$directory);
  178.         if ($files === false) {
  179.             die("Cannot list $directory");
  180.         }
  181.         if (count($files) != 0) {
  182.             foreach ($files as $file) {
  183.                 $name $file["name"];
  184.                 if ($file["type"] == "file") {
  185.                     array_push($result$name);
  186.                 }
  187.             }
  188.         }
  189.         return $result;
  190.     }
  191.     /**
  192.      * @Route("/get/img/upload", name="get_image_upload")
  193.      */
  194.     public function uploadImageFtp(Request $request)
  195.     {
  196.         $file $request->get('file');
  197.         $fileName $request->get('name');
  198.         if ($this->getUser()->getProjet()->getSwitchEnLigne()) {
  199.             $ftp_server $this->getUser()->getProjet()->getImageFtpServerEnligne();
  200.             $ftp_username $this->getUser()->getProjet()->getImageFtpLoginEnligne();
  201.             $ftp_userpass $this->getUser()->getProjet()->getImageFtpMdpEnligne();
  202.         } else {
  203.             $ftp_server $this->getUser()->getProjet()->getImageFtpServer();
  204.             $ftp_username $this->getUser()->getProjet()->getImageFtpLogin();
  205.             $ftp_userpass $this->getUser()->getProjet()->getImageFtpMdp();
  206.         }
  207.         //var_dump($this->csvService->importPage('../csv/2022-05-18-16-49 devil app pro/page.csv', $projet));
  208.         $racine "";
  209.         if (str_contains($ftp_server'/')) {
  210.             $pos strpos($ftp_server'/');
  211.             $racine substr($ftp_server$pos);
  212.             $ftp_server str_replace($racine""$ftp_server);
  213.         }
  214.         $ftp_conn ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
  215.         $login ftp_login($ftp_conn$ftp_username$ftp_userpass);
  216.         ftp_set_option($ftp_connFTP_USEPASVADDRESSfalse); // set ftp option
  217.         ftp_pasv($ftp_conntrue); //make connection to passive mode
  218.         // $file = 'newimg/' . $fileName;
  219.         $data explode(','$file);
  220.         $fp fopen($fileName"w+");
  221.         fwrite($fpbase64_decode($data[1]));
  222.         fclose($fp);
  223.         if (ftp_nlist($ftp_conn$racine "/upload") == false) {
  224.             ftp_mkdir($ftp_conn$racine "/upload");
  225.         }
  226.         $fp2 fopen($fileName"r");
  227.         if (ftp_fput($ftp_conn$racine "/upload/" $fileName$fp2)) {
  228.             $returnstat =  $this->json(['msg' => 'success']);
  229.         } else {
  230.             $returnstat =  $this->json(['msg' => 'non']);
  231.         }
  232.         ftp_close($ftp_conn);
  233.         fclose($fp2);
  234.         unlink($fileName);
  235.         return $returnstat;
  236.     }
  237.     /**
  238.      * @Route("/get/dirs/projet/logo/old", name="get_dirs_content_projet_logoold")
  239.      */
  240.     public function getDirsContentProjetLogo(Request $request)
  241.     {
  242.         $dirname $request->get('dirname');
  243.         $selected $request->get('selected');
  244.         $inputv $request->get('validinput');
  245.         if ($this->getUser()->getProjet()->getSwitchEnLigne()) {
  246.             $imageFtpServer $this->getUser()->getProjet()->getImageFtpServerEnligne();
  247.         } else {
  248.             $imageFtpServer $this->getUser()->getProjet()->getImageFtpServer();
  249.         }
  250.         $racine "";
  251.         if (str_contains($imageFtpServer'/')) {
  252.             $pos strpos($imageFtpServer'/');
  253.             $racine substr($imageFtpServer$pos);
  254.         }
  255.         if ($inputv == 'nnvalid' && $dirname != "") {
  256.             $dirname $racine $dirname;
  257.         } else if ($dirname == "") {
  258.             $dirname $racine "/";
  259.         }
  260.         /* if ($dirname == '') {
  261.             $dirname = '/loue-ton-box/';
  262.         } */
  263.         $content $this->htmlDirCResProjetLogo($dirname$selected$racine);
  264.         $niveauindicator $this->htmlNiveauIndicatorProjetLogo($dirname$racine);
  265.         return $this->json(['content' => $content'niveauindicator' => $niveauindicator]);
  266.     }
  267.     public function htmlNiveauIndicatorProjetLogo($dirname$racine)
  268.     {
  269.         $res $this->getParentDirs($dirname$racine);
  270.         $html "";
  271.         foreach ($res['name'] as $key => $value) {
  272.             $html .= '<button type="button" class="btn btn-secondary mx-1" onclick="getdirfilesprojetlogo(\'' $res['path'][$key] . '\', \'valid\')">' $value '</button>';
  273.             if (($key 1) < count($res['name'])) {
  274.                 $html .= '<i class="fa fa-chevron-right" style="color: #cbc8c8;"></i>';
  275.             }
  276.         }
  277.         return $html;
  278.     }
  279.     public function htmlDirCResProjetLogo($dirname$selected$racine)
  280.     {
  281.         $res $this->getDirs($dirname$racine);
  282.         $html '<div class="my-2 p-2">';
  283.         $html .= '<div class="p-2">';
  284.         $html .= '<div class="card p-2">';
  285.         $html .= '<div class="d-flex flex-wrap">';
  286.         $html .= '<i class="bi bi-arrow-return-right"></i>';
  287.         foreach ($res["dir"] as $value) {
  288.             $html .= '<button type="button" class="btn btn-primary mx-1" onclick="getdirfilesprojetlogo(\'' $res["filePath"] . $value '/\', \'valid\')">' $value '</button>';
  289.         }
  290.         $html .= '</div>';
  291.         $html .= '</div>';
  292.         $html .= '';
  293.         $html .= '<i class="bi bi-arrow-bar-down"></i>';
  294.         $html .= '<div class="card p-2">';
  295.         $html .= '<div class="d-flex flex-wrap">';
  296.         //dump($selected);
  297.         foreach ($res["file"] as $value) {
  298.             //dump($value);
  299.             $html .= '<div class="m-2" style="width: 200px; height: fit-content;">';
  300.             $imgPath $res["filePath"];
  301.             if ($racine != '') {
  302.                 if (strpos($res["filePath"], $racine) == 0) {
  303.                     $imgPath substr_replace($res["filePath"], ""0strlen($racine));
  304.                 }
  305.             }
  306.             if (strpos($imgPath"/") != 0) {
  307.                 $imgPath "/" $imgPath;
  308.             }
  309.             if ($this->getUser()->getProjet()->getSwitchEnLigne()) {
  310.                 if ($selected == ("/" $value)) {
  311.                     $html .= '<img id="imagegelleryprojectlogo" src="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . '" data-dir="' $imgPath $value '" onclick="selectedimageprojetlogo(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px solid #5656b5; border-color: #5656b5; background-color: #5656b5" loading="lazy">';
  312.                 } else {
  313.                     $html .= '<img id="imagegelleryprojectlogo" src="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServerEnligne() . '" data-dir="' $imgPath $value '" onclick="selectedimageprojetlogo(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  314.                 }
  315.             } else {
  316.                 if ($selected == ("/" $value)) {
  317.                     $html .= '<img id="imagegelleryprojectlogo" src="' $this->getUser()->getProjet()->getImageHttpServer() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' $imgPath $value '" onclick="selectedimageprojetlogo(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px solid #5656b5; border-color: #5656b5; background-color: #5656b5" loading="lazy">';
  318.                 } else {
  319.                     $html .= '<img id="imagegelleryprojectlogo" src="' $this->getUser()->getProjet()->getImageHttpServer() . $imgPath $value '" data-racine="' $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' $imgPath $value '" onclick="selectedimageprojetlogo(this)" class="img-thumbnail selectedFtpImg" style="width: 100%; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  320.                 }
  321.             }
  322.             // $html .= '<img src="' . $this->getUser()->getProjet()->getImageHttpServer() . $res["filePath"] . $value . '" data-racine="' . $this->getUser()->getProjet()->getImageHttpServer() . '" data-dir="' . $res["filePath"] . $value . '" onclick="selectedimage(this)" class="img-thumbnail selectedFtpImg" style="width: fit-content; height: fit-content; background-color: white; border: 1px;" loading="lazy">';
  323.             $html .= '</div>';
  324.         }
  325.         $html .= '</div>';
  326.         $html .= '</div>';
  327.         $html .= '</div>';
  328.         $html .= '<script>checkImageGalleyExtProjectLogo()</script>';
  329.         return $html;
  330.     }
  331. }