<?php
namespace App\Controller\FrontEndBundle;
use App\Entity\Group;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Doctrine\ORM\EntityManagerInterface;
use App\Entity\Groupconfigapp;
use App\Services\ImageService;
use Symfony\Component\Mailer\MailerInterface;
use Symfony\Component\Mime\Email;
use App\Services\KlentyService;
class DefaultController extends AbstractController
{
public function getCountryCode($ip)
{
//$fakeIp = "186.152.100.150";
$fakeIp = "35.168.130.76";
//Your BIN database file path
$db = new \IP2Location\Database ('../src/Database/IP2LOCATION-LITE-DB1.BIN', \IP2Location\Database::FILE_IO);
$ipToSearch = $ip == "::1" ? $fakeIp : $ip ;
$records = $db->lookup($ipToSearch, \IP2Location\Database::ALL);
return $records["countryCode"];
}
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
$ip= $request->getClientIp();
$countryCode = $this->getCountryCode($ip);
$renderPage = 'FrontEndBundle/default/index.html.twig';
switch ($countryCode) {
case "AR":
$renderPage = 'FrontEndBundle/default/AR/index.html.twig';
break;
case "MX":
$renderPage = 'FrontEndBundle/default/index.html.twig';
break;
default:
$renderPage = 'FrontEndBundle/default/index.html.twig';
}
$name = 'Pedidos Free';
return $this->render(
$renderPage,
array(
'name' => $name
)
);
}
/**
* @Route("sistema-de-pedidos-online-para-restaurante", name="sistema-de-pedidos-online-para-restaurante")
*/
public function sistemaParaRestaurantesAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/index-restaurant.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/es-mx/", name="es-mx")
*/
public function indexMxAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/index.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/es-ar/", name="es-ar")
*/
public function indexArAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/index-ar.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/contacto", name="contacto")
*/
public function contactAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/contact.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/thanks", name="thanks")
*/
public function thanksAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/thanks.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/precios", name="precios")
*/
public function preciosAction(Request $request)
{
$ip= $request->getClientIp();
$countryCode = $this->getCountryCode($ip);
$renderPage = 'FrontEndBundle/default/price.html.twig';
switch ($countryCode) {
case "AR":
$renderPage = 'FrontEndBundle/default/AR/price.html.twig';
break;
case "MX":
$renderPage = 'FrontEndBundle/default/price.html.twig';
break;
default:
$renderPage = 'FrontEndBundle/default/price.html.twig';
}
$name = 'Pedidos Free';
return $this->render(
$renderPage,
array(
'name' => $name
)
);
}
/**
* @Route("/historias-de-exito", name="historias-de-exito")
*/
public function historiasDeExitoAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/history-success.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/preguntas-frecuentes", name="preguntas-frecuentes")
*/
public function historiasDeExittAction()
{
$name = 'Pedidos Free';
return $this->render(
'FrontEndBundle/default/faqs.html.twig',
array(
'name' => $name
)
);
}
/**
* @Route("/{namegroup}", name="group" )
* @Template("FrontEndBundle/landing/landing.html.twig")
*/
public function groupAction($namegroup, EntityManagerInterface $em,
ImageService $imageService)
{
$group = $em->getRepository(Group::class)->getGroupByUrl($namegroup);
// Segunda forma
// $groupconfigapp = $em->getRepository(Groupconfigapp::class)->getGroupConfigAppByGroupNameAndType($namegroup, $typeconfig);
if ($group && $group->getGroupconfigappsLanding()) {
$groupconfigapp = $group->getGroupconfigappsLanding()[0];
$imagesResult = $imageService->getPathImagesGroup($group);
$pathimageheader = ($imagesResult['pathimageheader']) ? $imagesResult['pathimageheader'] : $groupconfigapp->getImageMain();
$pathimagelogo = ($imagesResult['pathimagelogo']) ? $imagesResult['pathimagelogo'] : $groupconfigapp->getImageLogo() ;
$pathimagelogo = ($imagesResult['pathimagelogo']) ? $imagesResult['pathimagelogo'] : $groupconfigapp->getImageLogo() ;
$pathimagefavicon = ($imagesResult['pathimagefavicon']) ? $imagesResult['pathimagefavicon'] : $groupconfigapp->getImageLogo() ;
return $this->render('FrontEndBundle/landing/landing.html.twig', array(
'name' => "Pedidos Free",
'namegroup' =>$namegroup,
'typeapplication' => $group->getTypeapplication(),
'headtitle' => $groupconfigapp->getHeadTitle(),
'headmetadescription' => $groupconfigapp->getHeadMetaDescription(),
'headmetakeywords' => $groupconfigapp->getHeadMetaKeywords(),
'headerdescription' => $groupconfigapp->getHeaderDescription(),
'middledescription1' => $groupconfigapp->getMiddleDescription1(),
'middledescription2' => $groupconfigapp->getMiddleDescription2(),
'fotterdescription' => $groupconfigapp->getFooterDescription(),
'urlappweb' => $groupconfigapp->getUrlAppWeb(),
'imagemain' => $pathimageheader ,
'imagecellphone' => $groupconfigapp->getImageCellPhone(),
'imagelogo' => $pathimagelogo,
'pathimagefavicon' => $pathimagefavicon,
'facebookfanpage' => $groupconfigapp->getFacebookFanPage(),
'playstoreurl' => $group->getPlaystoreLink(),
'applestoreurl' => $group->getApplestoreLink()
));
} else {
throw $this->createNotFoundException('La página no existe.');
}
}
/**
* @Route("/front/send-email-contact", name="send-email-contact")
* @Method("POST")
*
*/
public function sendEmailContact(Request $request, MailerInterface $mailer)
{
$respArray = array();
$respArray['result'] = true;
$respArray['messages'] = '';
$whatsappLink = "https://api.whatsapp.com/send?phone=" . str_replace("+", "", htmlspecialchars($request->request->get('phone')));
$body = "<b> Nombre : </b>" . htmlspecialchars($request->request->get('name'));
$body .= "<br><b>Local: </b>" . htmlspecialchars($request->request->get('company'));
$body .= "<br><b>Antiguedad: </b>" . htmlspecialchars($request->request->get('seniority'));
$body .= "<br><b>Tipo de local: </b>" . htmlspecialchars($request->request->get('industry'));
$body .= "<br><b>DELIVERY PROPIO: </b>" . htmlspecialchars($request->request->get('deliveryown'));
$body .= "<br><b>Email: </b>" . trim(htmlspecialchars($request->request->get('email')));
$body .= "<br><b>Telefono: </b>" . htmlspecialchars($request->request->get('phone'));
$body .= "<br><b>Horario de contacto: </b>" . htmlspecialchars($request->request->get('schedule_day'));
$body .= "<br><b>Pais: </b>" . htmlspecialchars(strtoupper($request->request->get('country')));
$body .= "<br><b>Ciudad: </b>" . htmlspecialchars($request->request->get('city'));
$body .= "<br><b>Mensaje: </b>" . htmlspecialchars($request->request->get('notes'));
$body .= "<br><b>source: </b>" . htmlspecialchars($request->request->get('source'));
$body .= "<br><b>utm_source: </b>" . htmlspecialchars($request->request->get('utm_source'));
$body .= "<br><b>utm_medium: </b>" . htmlspecialchars($request->request->get('utm_medium'));
$body .= "<br><b>utm_campaign: </b>" . htmlspecialchars($request->request->get('utm_campaign'));
$body .= "<br><b>Existe en klenty: </b>" . htmlspecialchars($request->request->get('exist'));
$email = (new Email())
->from('ventas@pedidosfree.com.ar')
->to("manfredihj@gmail.com")
//->cc('cc@example.com')
//->bcc('manfredihj@gmail.com')
//->replyTo('fabien@example.com')
//->priority(Email::PRIORITY_HIGH)
->subject('Consulta Pedidos Free WEB')
->text('Consulta Pedidos Free WEB')
->html($body);
try {
$mailer->send($email);
$respArray['messages'] = 'Mail enviado correctamente.';
} catch (\Exception $e) {
$respArray['messages'] = 'Error al enviar el mail.';
$respArray['result'] = false;
}
$response = new Response(json_encode($respArray));
return $response;
}
/**
* @Route("/front/validate-prospect", name="validate-prospect")
* @Method("POST")
*
*/
public function validateProspect(Request $request, KlentyService $klentyService)
{
$respArray = array();
$respArray['result'] = true;
$respArray['messages'] = '';
$exist= false;
$email = trim(htmlspecialchars($request->request->get('email')));
try {
$exist = $klentyService->checkIfProspectExist($email);
} catch (\Exception $e) {
$respArray['messages'] = 'error al validar el prospecto.';
$respArray['result'] = false;
}
$respArray['exist'] = $exist;
$response = new Response(json_encode($respArray));
return $response;
}
}