src/Controller/DefaultController.php line 66

  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\MailSecondarieUtenti;
  4. use App\Entity\PagineEComponenti;
  5. use App\Entity\User;
  6. use App\Model\Mailer;
  7. use App\Model\Security\ReCaptchaGoogle;
  8. use App\Model\Translating\Translating;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Psr\Log\LoggerInterface;
  11. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  12. use Symfony\Component\HttpFoundation\Cookie;
  13. use Symfony\Component\HttpFoundation\File\UploadedFile;
  14. use Symfony\Component\HttpFoundation\Request;
  15. use Symfony\Component\HttpFoundation\Response;
  16. use Symfony\Component\HttpKernel\KernelInterface;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Twig\Environment;
  19. /**
  20.  *
  21.  */
  22. class DefaultController extends AbstractController
  23. {
  24.     /** @var LoggerInterface */
  25.     private $logger;
  26.     /** @var ReturnImpostazioniServiceController */
  27.     private $imp;
  28.     /** @var KernelInterface */
  29.     private $kernel;
  30.     /** @var ServiziController */
  31.     private $servizi;
  32.     /** @var Environment */
  33.     private $twig;
  34.     /** @var Translating */
  35.     private $translating;
  36.     /** @var Mailer */
  37.     private $mailer;
  38.     /**
  39.      * DefaultController constructor.
  40.      * @param LoggerInterface $logger
  41.      * @param ReturnImpostazioniServiceController $imp
  42.      * @param KernelInterface $kernel
  43.      * @param ServiziController $servizi
  44.      * @param Environment $twig
  45.      * @param Translating $translating
  46.      * @param Mailer $mailer
  47.      */
  48.     public function __construct(LoggerInterface $loggerReturnImpostazioniServiceController $impKernelInterface $kernelServiziController $serviziEnvironment $twigTranslating $translatingMailer $mailer)
  49.     {
  50.         $this->logger $logger;
  51.         $this->imp $imp;
  52.         $this->kernel $kernel;
  53.         $this->servizi $servizi;
  54.         $this->twig $twig;
  55.         $this->translating $translating;
  56.         $this->mailer $mailer;
  57.     }
  58.     /**
  59.      * @Route("/", name="homepage")
  60.      */
  61.     public function indexAction(Request $request)
  62.     {
  63.         $customHomePage $this->imp->ritornaImpostazioneDaNome("CustomHomepage");
  64.         if ($customHomePage != ''){
  65.             /** @var PagineEComponenti $pagina */
  66.             $pagina $this->servizi->doctrine->getRepository(PagineEComponenti::class)->find($customHomePage);
  67.             if ($pagina){
  68.                 return $this->render('ZZ_front_end/pagine_secondarie/pagine_secondarie_render.html.twig', array(
  69.                     'pagina' => $pagina
  70.                 ));
  71.             }else{
  72.                 return new Response(""'404');
  73.             }
  74.         }else {
  75.             /** @var User $user */
  76.             $user $this->servizi->OttieniUtenteCorrente();
  77.             if ($user) {
  78.                 if ($user->getUtenteComune()) {
  79.                     return $this->redirectToRoute('home_shop_comune');
  80.                 } else
  81.                     return $this->redirectToRoute('home_shop');
  82.             } else {
  83.                 return $this->redirectToRoute('home_shop_comune');
  84.             }
  85.         }
  86.     }
  87.     /**
  88.      * @Route("/products/home", name="home_prodotti")
  89.      */
  90.     public function productsAction(Request $request)
  91.     {
  92.         /** @var User $user */
  93.         $user $this->servizi->OttieniUtenteCorrente();
  94.         if ($user) {
  95.             if ($user->getUtenteComune()) {
  96.                 return $this->redirectToRoute('home_shop_comune');
  97.             } else
  98.                 return $this->redirectToRoute('home_shop');
  99.         } else {
  100.             if ($this->imp->ritornaImpostazioneDaNome('AbilitaB2C') != '1'){
  101.                 return $this->redirectToRoute('home_login');
  102.             }
  103.             return $this->redirectToRoute('home_shop_comune');
  104.         }
  105.     }
  106.     /**
  107.      * @Route("/admin/uploadFileAsset", name="admin_upload_file_asset", options={"expose"=true})
  108.      */
  109.     public function uploadFileInAsset(Request $request)
  110.     {
  111.         $pathStore $this->kernel->getProjectDir()  . DIRECTORY_SEPARATOR "public" DIRECTORY_SEPARATOR "uploads" DIRECTORY_SEPARATOR;
  112.         $pathRitorno DIRECTORY_SEPARATOR ."uploads" DIRECTORY_SEPARATOR;
  113.         $listaFile $request->files;
  114.         /**
  115.          * @var  $key string
  116.          */
  117.         foreach ($listaFile as $value){
  118.             /** @var  $file UploadedFile */
  119.             $file $value[0];
  120.             $nome time() . "-" $file->getClientOriginalName();
  121.             $file->move($pathStore$nome);
  122.         }
  123.         return new Response("");
  124.     }
  125.     /**
  126.      * @Route("/setLocale/{locale}", name="set_locale")
  127.      */
  128.     public function setlocale(Request $request$locale)
  129.     {
  130.         $request->getSession()->set('_locale'$locale);
  131.         $referral $request->server->get('HTTP_REFERER');
  132.         $response $this->redirect($referral);
  133.         $response->headers->setCookie(new Cookie('_locale'$localestrtotime'+1 year' ), '/'));
  134.         return $response;
  135.     }
  136.     /**
  137.      * @param EntityManagerInterface $em
  138.      * @param string $ip
  139.      * @param string $debug
  140.      * @param boolean $esito
  141.      * @param string $messaggio
  142.      * @param User $utente
  143.      */
  144.     function ScriviRegistroAttivita($em$ip$debug$esito$messaggio$utente)
  145.     {
  146.         $this->servizi->ScriviRegistroAttivita($ip$debug$esito$messaggio$utente);
  147.     }
  148.     /**
  149.      * @Route("/contatto/mail", methods={"POST"}, name="contatto_per_mail")
  150.      */
  151.     public function contattoPerMail(Request $request){
  152.         $sendMail = new Mailer($this->imp$this->twig$this->servizi);
  153.         $mailFrom $this->imp->ritornaImpostazioneDaNome('IndirizzoMailFromInvioComunicazioni');
  154.         $oggetto $request->get('ddflt-oggetto');
  155.         $mailInvio $request->get('ddflt-mail-invio');
  156.         $mailInvioCc $request->get('ddflt-mail-invio-cc');
  157.         $traduzione = new Translating($this->servizi->doctrine$this->logger);
  158.         $traduzione->CaricaTraduzioniDaFamiglia('form_contatto'$request->getLocale());
  159.         $parametri $request->request->keys();
  160.         $procedi true;
  161.         if($oggetto != '' && $mailInvio != ''){
  162.             if (array_key_exists('recaptcha'$parametri)){
  163.                 /*
  164.                  * Il captcha deve essere un input con nome = recaptcha e class = re-captcha-v3
  165.                  */
  166.                 $token $parametri['recaptcha'];
  167.                 if (!ReCaptchaGoogle::captchaverify($token$this->imp)){
  168.                     $procedi false;
  169.                     $this->addFlash(
  170.                         'error',
  171.                         $traduzione->OttieniElementoDizionario('form_contatto_captcha_error''form_contatto')->valoreUscita
  172.                     );
  173.                 }
  174.             }
  175.             if($procedi){
  176.                 $testoMail $traduzione->OttieniElementoDizionario('form_contatto_titolo''form_contatto')->valoreUscita '<br /><br />
  177.                     <table class="table table-responsive table-striped">
  178.                     <thead>
  179.                     <tr>
  180.                         <th>' $traduzione->OttieniElementoDizionario('form_contatto_parametro''form_contatto')->valoreUscita '</th>
  181.                         <th>' $traduzione->OttieniElementoDizionario('form_contatto_valore''form_contatto')->valoreUscita '</th>
  182.                     </tr>
  183.                     </thead>
  184.                     <tbody>';
  185.                 foreach ($parametri as $key) {
  186.                     if ($key != ('recaptcha'||'ddflt-mail-invio'||'ddflt-mail-invio-cc'||'ddflt-oggetto')) {
  187.                         $testoMail .= '<tr><td>' $key '</td><td>' $request->request->get($key) . '</td></tr>';
  188.                     }
  189.                 }
  190.                 $testoMail .= '</tbody></table>';
  191.                 $sendMail->SendMail($oggetto$testoMailexplode(';'$mailFrom), explode(';'$mailInvioCc), ''''true);
  192.                 $this->addFlash(
  193.                     'notice',
  194.                     $traduzione->OttieniElementoDizionario('form_contatto_messaggio_inviato''form_contatto')->valoreUscita
  195.                 );
  196.             }
  197.         }else{
  198.             $procedi false;
  199.             $this->addFlash(
  200.                 'error',
  201.                 $traduzione->OttieniElementoDizionario('form_contatto_captcha_error''form_contatto')->valoreUscita
  202.             );
  203.         }
  204.         return $this->redirect($this->servizi->getRefererRoute($request));
  205.     }
  206.     /**
  207.      * @Route("/contact/form", name="contatto_form", methods={"POST"})
  208.      */
  209.     public function contattoDaForm(Request $request){
  210.         $traduzione $this->translating;
  211.         $traduzione->CaricaTraduzioniDaFamiglia('form_contatto'$request->getLocale());
  212.         $mailInvioContatto $this->imp->ritornaImpostazioneDaNome('MailInvioContattiForm');
  213.         $mailFrom $this->imp->ritornaImpostazioneDaNome('IndirizzoMailFromInvioComunicazioni');
  214.         $arrayMail = array();
  215.         if (strpos($mailInvioContatto';') !== false){
  216.             $arrayMail explode(';'$mailInvioContatto);
  217.         }else{
  218.             array_push($arrayMail$mailInvioContatto);
  219.         }
  220.         $sendMail = new Mailer($this->imp$this->twig$this->servizi);
  221.         $parametri $request->request->keys();
  222.         //return new JsonResponse($request->request->keys());
  223.         if (count($parametri) > 0) {
  224.             $procedi true;
  225.             //Verifico se Ã¨ presente un capcha da verificare
  226.             if (array_key_exists('recaptcha'$parametri)){
  227.                 /*
  228.                  * Il captcha deve essere un input con nome = recaptcha e class = re-captcha-v3
  229.                  */
  230.                 $token $parametri['recaptcha'];
  231.                 if (!ReCaptchaGoogle::captchaverify($token$this->imp)){
  232.                     $procedi false;
  233.                     $this->addFlash(
  234.                         'error',
  235.                         $traduzione->OttieniElementoDizionario('form_contatto_captcha_error''form_contatto')->valoreUscita
  236.                     );
  237.                 }
  238.             }
  239.             if ($procedi) {
  240.                 $testoMail $traduzione->OttieniElementoDizionario('form_contatto_titolo''form_contatto')->valoreUscita '<br /><br />
  241.                     <table class="table table-responsive table-striped">
  242.                     <thead>
  243.                     <tr>
  244.                         <th>' $traduzione->OttieniElementoDizionario('form_contatto_parametro''form_contatto')->valoreUscita '</th>
  245.                         <th>' $traduzione->OttieniElementoDizionario('form_contatto_valore''form_contatto')->valoreUscita '</th>
  246.                     </tr>
  247.                     </thead>
  248.                     <tbody>';
  249.                 foreach ($parametri as $key) {
  250.                     if ($key != 'recaptcha') {
  251.                         $testoMail .= '<tr><td>' $key '</td><td>' $request->request->get($key) . '</td></tr>';
  252.                     }
  253.                 }
  254.                 $testoMail .= '</tbody></table>';
  255.                 $sendMail->SendMail('Contatto da form sito'$testoMail$mailFrom$arrayMail''''true);
  256.                 $this->addFlash(
  257.                     'notice',
  258.                     $traduzione->OttieniElementoDizionario('form_contatto_messaggio_inviato''form_contatto')->valoreUscita
  259.                 );
  260.             }
  261.         }
  262.         return $this->redirect($this->servizi->getRefererRoute($request));
  263.     }
  264.     /**
  265.      * @Route("/admin/masterReset_ppp/{psw}/{da}/{a}", name="master_reset_password")
  266.      */
  267.     public function masterResetPassword(Request $request$psw$da 0$a 100)
  268.     {
  269.         ini_set('max_execution_time', -1);
  270.         ini_set('memory_limit', -1);
  271.         $start microtime(true);
  272.         $this->servizi->doctrine->getConnection()->getConfiguration()->setSQLLogger(null);
  273.         $em $this->servizi->doctrine->getManager();
  274.         $contatore 0;
  275.         $row 0;
  276.         $query_eseguite 0;
  277.         $batch_size 1;
  278.         $this->ScriviRegistroAttivita($em$request->getClientIp(),""true"Chiamata effettuata a /admin/masterReset/  Da: " $da " -- A: " $a$this->servizi->OttieniUtenteCorrente());
  279.         $query_eseguite++;
  280.         if ($psw == "180392"){
  281.             $inviaMail $this->imp->ritornaImpostazioneDaNome("InviaMailNuoviClienti");
  282.             $from $this->imp->ritornaImpostazioneDaNome("IndirizzoMailFromInvioComunicazioni");
  283.             $nomeShop $this->imp->ritornaImpostazioneDaNome("NomeShop");
  284.             $ccMail $this->imp->ritornaImpostazioneDaNome("MailCcComunicazioni");
  285.             /** @var  $user User[] */
  286.             $user $this->servizi->doctrine->getRepository(User::class)->findAll();
  287.             $arrayInvioMail = array();
  288.             for ($i $da; ($i <= $a) && ($a count($user)); $i++) {
  289.                 $item $user[$i];
  290.                 $newPass $this->servizi->randomString(8);
  291.                 $item->setPassword($newPass);
  292.                 $em $this->servizi->doctrine->getManager();
  293.                 $em->persist($item);
  294.                 $em->flush();
  295.                 array_push($arrayInvioMail, array($item$newPass));
  296.             }
  297.             foreach ($arrayInvioMail as $valore)
  298.             {
  299.                 $item $valore[0];//utente
  300.                 $listaMailSecondarie $this->servizi->doctrine->getRepository(MailSecondarieUtenti::class)->findBy(array('azienda' => $item'inviaConfermaOrdine' => true));
  301.                 $adresses = array();
  302.                 foreach ($listaMailSecondarie as $ms)
  303.                 {
  304.                     array_push($adresses$ms->getIndirizzoMail());
  305.                 }
  306.                 array_push($adresses$ccMail);
  307.                 try {
  308.                     if ($inviaMail) {
  309.                         $this->mailer->SendMail(
  310.                             "reset password -- " $nomeShop,
  311.                             $this->renderView(
  312.                                 'email/utenti/cambio_password.html.twig',
  313.                                 array(
  314.                                     'utente' => $item,
  315.                                     'password' => $valore[1]
  316.                                 )
  317.                             ),
  318.                             $item->getEmail(),
  319.                             $adresses,
  320.                             $from
  321.                         );
  322.                         $this->ScriviRegistroAttivita($em$request->getClientIp(), ""true'Mail Reset Inviata: ' $item->getId() . '  -  ' .$item->getRagioneSociale() . ' all\'indirizzo ' $item->getEmail(), null);
  323.                         $query_eseguite++;
  324.                     }
  325.                 }catch (\Exception $e){
  326.                     $this->logger->critical("Errore invio mail: " $e->getMessage());
  327.                     $this->ScriviRegistroAttivita($em$request->getClientIp(), $e->getMessage(), true'Errore invio mail reset password ' $item->getCodiceCliente() . '  -  ' .$item->getRagioneSociale() . ' all\'indirizzo ' $item->getEmail() . " --- Errore: " $e->getMessage(), null);
  328.                     $query_eseguite++;
  329.                 }
  330.                 if ($query_eseguite >= $batch_size) {
  331.                     $contatore $contatore $row;
  332.                     $row 1;
  333.                     $query_eseguite 0;
  334.                     $em->flush();
  335.                     $em->clear();
  336.                 }
  337.             }
  338.             $query_eseguite 0;
  339.             $em->flush();
  340.             $em->clear();
  341.             $this->ScriviRegistroAttivita(null$request->getClientIp(), ""true'Reset master password completato in ' $time_elapsed_secs microtime(true) - $start ' seconds ---- ' $contatore '</br>'null);
  342.             return new Response('Reset master password completata in ' $time_elapsed_secs microtime(true) - $start ' seconds ---- ' $contatore '</br>');
  343.         }else{
  344.             return new Response("ERRORE AUTORIZZAZIONE");
  345.         }
  346.     }
  347.     /**
  348.      * @Route("/pulisciRegistroAttivita", name="pulisci_registro_attivita")
  349.      */
  350.     public function pulisciRegistroAttivitaCronAction(Request $request)
  351.     {
  352.         if ($request->getClientIp() == ("127.0.0.1")) {
  353.             $em $this->servizi->doctrine->getManager();
  354.             $stmt $em->getConnection()->prepare("DELETE FROM registro_attivita WHERE data < DATE_SUB(NOW() , INTERVAL 1 WEEK)");
  355.             $ris $stmt->execute();
  356.             $this->ScriviRegistroAttivita($em$request->getClientIp(), ""true'Pulizia registro attività effettuata'null);
  357.             return new Response($ris "TRUE" "FALSE");
  358.         }
  359.         else{
  360.             return new Response("ACCESSO_NEGATO");
  361.         }
  362.     }
  363.     /**
  364.      * @Route("/pulisciCarrelliVecchi", name="pulisci_carrelli_vecchi")
  365.      */
  366.     public function pulisciCarrelliVecchiCronAction(Request $request)
  367.     {
  368.         if ($request->getClientIp() == ("127.0.0.1")) {
  369.             $em $this->servizi->doctrine->getManager();
  370.             $conn $this->servizi->doctrine->getConnection();
  371.             $ris $conn->executeQuery("DELETE FROM righe_carrello where data_modifica < DATE_SUB(NOW(), INTERVAL 3 MONTH);");
  372.             $conn->executeQuery("DELETE FROM carrello where data_modifica < DATE_SUB(NOW(), INTERVAL 3 MONTH);");
  373.             $this->ScriviRegistroAttivita($em$request->getClientIp(), ""true'Pulizia carrelli vecchi effettuata'null);
  374.             return new Response($ris "TRUE" "FALSE");
  375.         }else{
  376.             return new Response('ACCESSO_NEGATO');
  377.         }
  378.     }
  379.     /**
  380.      * @Route("/admin/puliziaTotaleDatabaseArticoli", name="admin_puliza_totale_database_articoli")
  381.      */
  382.     public function puliziaTotaleDatabaseArticoli(Request $request)
  383.     {
  384.         $em $this->servizi->doctrine->getManager();
  385.         $conn $this->servizi->doctrine->getConnection();
  386.         $conn->executeQuery("SET FOREIGN_KEY_CHECKS=0;");
  387.         $conn->executeQuery("TRUNCATE `albero_menu_prodotti`;");
  388.         $conn->executeQuery("TRUNCATE `articoli`;");
  389.         $conn->executeQuery("TRUNCATE `articoli_in_lingua`;");
  390.         $conn->executeQuery("TRUNCATE `associazione_articoli_cliente`;");
  391.         $conn->executeQuery("TRUNCATE `associazione_attributi`;");
  392.         $conn->executeQuery("TRUNCATE `attributi`;");
  393.         $conn->executeQuery("TRUNCATE `attributi_in_lingua`;");
  394.         $conn->executeQuery("TRUNCATE `carrello`;");
  395.         $conn->executeQuery("TRUNCATE `categorie`;");
  396.         $conn->executeQuery("TRUNCATE `categorie_in_lingua`;");
  397.         $conn->executeQuery("TRUNCATE `combinazione_albero_mappa_categorie_articoli`;");
  398.         $conn->executeQuery("TRUNCATE `listini_vendita`;");
  399.         $conn->executeQuery("TRUNCATE `magazzino_secondario_disponibilita`;");
  400.         $conn->executeQuery("TRUNCATE `mappa_categorie_articoli`;");
  401.         $conn->executeQuery("TRUNCATE `ordini`;");
  402.         $conn->executeQuery("TRUNCATE `ordini_righe`;");
  403.         $conn->executeQuery("TRUNCATE `righe_carrello`;");
  404.         $conn->executeQuery("TRUNCATE `statistiche_categorie`;");
  405.         $conn->executeQuery("TRUNCATE `statistiche_click_articoli`;");
  406.         $conn->executeQuery("TRUNCATE `tipologie_preimpostate`;");
  407.         $conn->executeQuery("TRUNCATE `tipologie_preimpostate_lista`;");
  408.         $conn->executeQuery("TRUNCATE `unita_misura`;");
  409.         $conn->executeQuery("TRUNCATE `varianti`;");
  410.         $conn->executeQuery("TRUNCATE `varianti_in_lingua`;");
  411.         $conn->executeQuery("SET FOREIGN_KEY_CHECKS=1;");
  412.         $this->ScriviRegistroAttivita($em$request->getClientIp(), ""true'Pulizia totale database articoli effettuata'$this->servizi->OttieniUtenteCorrente());
  413.         return new Response("TRUE");
  414.     }
  415.     /**
  416.      * @Route("/admin/puliziaTotaleAnagrafiche", name="admin_pulizia_totale_anagrafiche")
  417.      */
  418.     public function puliziaTotaleAnagraficheDatabase(Request $request)
  419.     {
  420.         $em $this->servizi->doctrine->getManager();
  421.         $conn $this->servizi->doctrine->getConnection();
  422.         $conn->executeQuery("SET FOREIGN_KEY_CHECKS=0;");
  423.         $conn->executeQuery("TRUNCATE `anagrafica_opzioni_aggiuntive`;");
  424.         $conn->executeQuery("TRUNCATE `anagrafiche`;");
  425.         $conn->executeQuery("TRUNCATE `anagrafiche_indirizzi`;");
  426.         $conn->executeQuery("TRUNCATE `risorse_anagrafiche_colonne_valori`;");
  427.         $conn->executeQuery("TRUNCATE `risorse_anagrafiche`;");
  428.         $conn->executeQuery("TRUNCATE `risorse_anagrafiche_colonne`;");
  429.         $conn->executeQuery("TRUNCATE `sconti_anagrafiche`;");
  430.         $conn->executeQuery("TRUNCATE `anagrafiche_blocchi`;");
  431.         $conn->executeQuery("SET FOREIGN_KEY_CHECKS=1;");
  432.         $this->ScriviRegistroAttivita($em$request->getClientIp(), ""true'Pulizia totale database anagrafiche effettuata'$this->servizi->OttieniUtenteCorrente());
  433.         return new Response("TRUE");
  434.     }
  435. }