src/Controller/StaticPagesController.php line 377

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\AccommodationType;
  4. use App\Entity\Blog;
  5. use App\Entity\Bookings;
  6. use App\Entity\CMSBlocks;
  7. use App\Entity\CMSMenu;
  8. use App\Entity\CMSPages;
  9. use App\Entity\Favourites;
  10. use App\Entity\GiftVoucherPurchases;
  11. use App\Entity\ListingQuestions;
  12. use App\Entity\Property;
  13. use App\Entity\PropertyReviews;
  14. use App\Entity\PropertyTags;
  15. use App\Entity\PropertyTagsApplied;
  16. use App\Entity\Regions;
  17. use App\Entity\Terms;
  18. use App\Entity\TermsAcceptance;
  19. use App\Entity\User;
  20. use App\Entity\VoucherCodes;
  21. use App\Entity\WebsiteControl;
  22. use App\Service\GlobalFunctions;
  23. use Liip\ImagineBundle\Imagine\Cache\CacheManager;
  24. use SendGrid\Response as SendGridResponse;
  25. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  26. use Symfony\Component\HttpFoundation\RedirectResponse;
  27. use Symfony\Component\HttpFoundation\Request;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\Routing\Annotation\Route;
  30. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  31. class StaticPagesController extends AbstractController
  32. {
  33.     /**
  34.      * @var CacheManager
  35.      */
  36.     private $liipCache;
  37.     public function __construct(GlobalFunctions $GlobalFnCacheManager $liipCache)
  38.     {
  39.         $this->GlobalFn $GlobalFn;
  40.         $this->liipCache $liipCache;
  41.     }
  42.     /**
  43.      * @Route("/", name="home_page", schemes={"https"})
  44.      */
  45.     public function index(GlobalFunctions $GlobalFn): Response
  46.     {
  47.         $this->get('session')->set('search_query'null);
  48.         $this->get('session')->set('search_filters_location'null);
  49.         $this->get('session')->set('search_filters_experience'null);
  50.         $this->get('session')->set('search_filters_amenity'null);
  51.         $this->get('session')->set('search_filters_propertytype'null);
  52.         $this->get('session')->set('search_filters_groupoptions'null);
  53.         $this->get('session')->set('search_check_in_date''');
  54.         $this->get('session')->set('search_check_out_date''');
  55.         if (isset($_GET['p'])) {
  56.             if ('listing' == $_GET['p']) {
  57.                 $FirstAccomm $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy(['PropertyCode' => $_GET['listingCode']], ['id' => 'ASC'], 10);
  58.                 $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $_GET['listingCode']]);
  59.                 return $this->redirectToRoute('listing', ['listing_slug' => $Property->getListingSlug(), 'room_slug' => $FirstAccomm->getRoomSlug()]);
  60.             }
  61.         }
  62.         $Blogs $this->getDoctrine()->getRepository(Blog::class)->findBy([], ['id' => 'DESC'], 60);
  63.         $conn $this->getDoctrine()->getManager()->getConnection();
  64.         $sql "SELECT *,accommodation_type.key_statement AS 'accomm_key_statement' FROM accommodation_type INNER JOIN property ON accommodation_type.property_code=property.listing_code  WHERE accommodation_type.enabled='1' AND accommodation_type.eating_drinking!='' AND property.listing_status='Listed' ORDER BY RAND() LIMIT 0,4
  65.             ";
  66.         $stmt $conn->prepare($sql);
  67.         $stmt->execute();
  68.         $HomeRooms $stmt->fetchAll();
  69.         $HomeRoomPhotos = [];
  70.         $em $this->getDoctrine()->getManager();
  71.         $Specials_GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->findOneBy(['TagName' => 'Specials']);
  72.         if (null == $Specials_GetTag) {
  73.             $Specials_Rooms = [];
  74.         } else {
  75.             $Specials_GetApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Tag' => $Specials_GetTag]);
  76.             $Specials_Rooms = [];
  77.             shuffle($Specials_GetApplied);
  78.             $i 0;
  79.             foreach ($Specials_GetApplied as $thisApplied) {
  80.                 $Accomm $thisApplied->getRoom();
  81.                 if (null !== $Accomm) {
  82.                     if (== $Accomm->getEnabled() && 'Listed' == $Accomm->getProperty()->getListingStatus()) {
  83.                         if ('' == $Accomm->getSearchHeadline() or 'Display Name of Listing' == $Accomm->getSearchHeadline() && (== $Accomm->getFeaturedFirst() or null == $Accomm->getFeaturedFirst())) {
  84.                         } else {
  85.                             $Specials_Rooms[] = $Accomm;
  86.                             if (== $i) {
  87.                                 break;
  88.                             }
  89.                             ++$i;
  90.                         }
  91.                     }
  92.                 }
  93.             }
  94.         }
  95.         $SweetAsFamily_GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->findOneBy(['TagName' => 'Sweet As for the Family']);
  96.         if (null == $SweetAsFamily_GetTag) {
  97.             $SweetAsFamily_Rooms = [];
  98.         } else {
  99.             $SweetAsFamily_GetApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Tag' => $SweetAsFamily_GetTag]);
  100.             $SweetAsFamily_Rooms = [];
  101.             shuffle($SweetAsFamily_GetApplied);
  102.             $i 0;
  103.             foreach ($SweetAsFamily_GetApplied as $thisApplied) {
  104.                 $Accomm $thisApplied->getRoom();
  105.                 if (null !== $Accomm) {
  106.                     if (== $Accomm->getEnabled() && 'Listed' == $Accomm->getProperty()->getListingStatus()) {
  107.                         if ('' == $Accomm->getSearchHeadline() or 'Display Name of Listing' == $Accomm->getSearchHeadline()) {
  108.                         } else {
  109.                             $SweetAsFamily_Rooms[] = $Accomm;
  110.                             if (== $i) {
  111.                                 break;
  112.                             }
  113.                             ++$i;
  114.                         }
  115.                     }
  116.                 }
  117.             }
  118.         }
  119.         $FurryFriendsWelcome_GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->findOneBy(['TagName' => 'Furry Friends Welcome']);
  120.         if (null == $FurryFriendsWelcome_GetTag) {
  121.             $FurryFriendsWelcome_Rooms = [];
  122.         } else {
  123.             $FurryFriendsWelcome_GetApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Tag' => $FurryFriendsWelcome_GetTag]);
  124.             $FurryFriendsWelcome_Rooms = [];
  125.             shuffle($FurryFriendsWelcome_GetApplied);
  126.             $i 0;
  127.             foreach ($FurryFriendsWelcome_GetApplied as $thisApplied) {
  128.                 $Accomm $thisApplied->getRoom();
  129.                 if (null !== $Accomm) {
  130.                     if (== $Accomm->getEnabled() && 'Listed' == $Accomm->getProperty()->getListingStatus()) {
  131.                         if ('' == $Accomm->getSearchHeadline() or 'Display Name of Listing' == $Accomm->getSearchHeadline()) {
  132.                         } else {
  133.                             $FurryFriendsWelcome_Rooms[] = $Accomm;
  134.                             if (== $i) {
  135.                                 break;
  136.                             }
  137.                             ++$i;
  138.                         }
  139.                     }
  140.                 }
  141.             }
  142.         }
  143.         $GetOffGrid_GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->findOneBy(['TagName' => 'Get Off the Grid']);
  144.         if (null == $GetOffGrid_GetTag) {
  145.             $GetOffGrid_Rooms = [];
  146.         } else {
  147.             $GetOffGrid_GetApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Tag' => $GetOffGrid_GetTag]);
  148.             $GetOffGrid_Rooms = [];
  149.             shuffle($GetOffGrid_GetApplied);
  150.             $i 0;
  151.             foreach ($GetOffGrid_GetApplied as $thisApplied) {
  152.                 $Accomm $thisApplied->getRoom();
  153.                 if (null !== $Accomm) {
  154.                     if (== $Accomm->getEnabled() && 'Listed' == $Accomm->getProperty()->getListingStatus()) {
  155.                         if ('' == $Accomm->getSearchHeadline() or 'Display Name of Listing' == $Accomm->getSearchHeadline()) {
  156.                         } else {
  157.                             $GetOffGrid_Rooms[] = $Accomm;
  158.                             if (== $i) {
  159.                                 break;
  160.                             }
  161.                             ++$i;
  162.                         }
  163.                     }
  164.                 }
  165.             }
  166.         }
  167.         $RomanticRetreats_GetTag $this->getDoctrine()->getRepository(PropertyTags::class)->findOneBy(['TagName' => 'Romantic Retreats']);
  168.         if (null == $RomanticRetreats_GetTag) {
  169.             $RomanticRetreats_Rooms = [];
  170.         } else {
  171.             $RomanticRetreats_GetApplied $this->getDoctrine()->getRepository(PropertyTagsApplied::class)->findBy(['Tag' => $RomanticRetreats_GetTag]);
  172.             $RomanticRetreats_Rooms = [];
  173.             shuffle($RomanticRetreats_GetApplied);
  174.             $i 0;
  175.             foreach ($RomanticRetreats_GetApplied as $thisApplied) {
  176.                 $Accomm $thisApplied->getRoom();
  177.                 if (null !== $Accomm) {
  178.                     if (== $Accomm->getEnabled() && 'Listed' == $Accomm->getProperty()->getListingStatus()) {
  179.                         if ('' == $Accomm->getSearchHeadline() or 'Display Name of Listing' == $Accomm->getSearchHeadline()) {
  180.                         } else {
  181.                             $RomanticRetreats_Rooms[] = $Accomm;
  182.                             if (== $i) {
  183.                                 break;
  184.                             }
  185.                             ++$i;
  186.                         }
  187.                     }
  188.                 }
  189.             }
  190.         }
  191.         foreach ($HomeRooms as $ThisRoom) {
  192.             $Media $GlobalFn->room_photos($ThisRoom['room_code'], 1);
  193.             $Media $this->liipCache->getBrowserPath($Media'mobile_images');
  194.             $HomeRoomPhotos[$ThisRoom['room_code']] = $Media;
  195.         }
  196.         $CurrentDate = new \DateTimeImmutable();
  197.         $TomorrowDate $CurrentDate->add(new \DateInterval('P1D'));
  198.         $Reviews $this->getDoctrine()->getRepository(PropertyReviews::class)->findBy(['StarRating' => 5'Approved' => 1]);
  199.         shuffle($Reviews);
  200.         $i 0;
  201.         $OutputReviews = [];
  202.         foreach ($Reviews as $thisReview) {
  203.             if (null !== $thisReview->getBookingId()) {
  204.                 $ReviewBooking $this->getDoctrine()->getRepository(Bookings::class)->find($thisReview->getBookingId());
  205.                 if ($ReviewBooking) {
  206.                     $Holidaymaker $this->getDoctrine()->getRepository(User::class)->find($ReviewBooking->getHolidaymakerId());
  207.                     $AccommType $this->getDoctrine()->getRepository(AccommodationType::class)->findOneBy(['RoomCode' => $ReviewBooking->getRoomCode()]);
  208.                     $Property $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $AccommType->getPropertyCode()]);
  209.                     $AccommImage $GlobalFn->room_photos($AccommType->getRoomCode(), 1);
  210.                     if ($i 4) {
  211.                         $OutputReviews[] = [$thisReview$AccommType$Holidaymaker$AccommImage$Property];
  212.                     }
  213.                     ++$i;
  214.                 }
  215.             }
  216.         }
  217.         // Get home page popup
  218.         $HomePagePopupEnabled $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'home_page_alert_box_enabled']);
  219.         if (== $HomePagePopupEnabled->getValue()) {
  220.             $PopupBoxEnabled 1;
  221.             $HomePagePopupTitle $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'home_page_alert_box_title'])->getValue();
  222.             $HomePagePopupContent $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'home_page_alert_box_content'])->getValue();
  223.         } else {
  224.             $PopupBoxEnabled 0;
  225.             $HomePagePopupTitle null;
  226.             $HomePagePopupContent null;
  227.         }
  228.         $Regions $this->getDoctrine()->getRepository(Regions::class)->findAll();
  229.         return $this->render('static_pages/newhome.html.twig', [
  230.             'blogs' => $Blogs,
  231.             'is_home_page' => true,
  232.             'HomeRooms' => $HomeRooms,
  233.             'HomeRoomsPhotos' => $HomeRoomPhotos,
  234.             'CurrentDate' => $CurrentDate,
  235.             'TomorrowDate' => $TomorrowDate,
  236.             'reviews' => $OutputReviews,
  237.             'popup_box_enabled' => $PopupBoxEnabled,
  238.             'popup_box_title' => $HomePagePopupTitle,
  239.             'popup_box_content' => $HomePagePopupContent,
  240.             'specials' => $Specials_Rooms,
  241.             'sweetasfamily' => $SweetAsFamily_Rooms,
  242.             'furryfriendswelcome' => $FurryFriendsWelcome_Rooms,
  243.             'getoffgrid' => $GetOffGrid_Rooms,
  244.             'romanticretreats' => $RomanticRetreats_Rooms,
  245.             'regionlist' => $Regions,
  246.         ]);
  247.     }
  248.     public function list()
  249.     {
  250.         return $this->render('static_pages/listyourproperty.html.twig', [
  251.             'controller_name' => 'StaticPagesController',
  252.         ]);
  253.     }
  254.     public function aboutus()
  255.     {
  256.         return $this->render('static_pages/aboutus.html.twig', [
  257.             'controller_name' => 'StaticPagesController',
  258.         ]);
  259.     }
  260.     public function sendTestMessage()
  261.     {
  262.         $sender 'jsm';
  263.         $threadBuilder $this->get('fos_message.composer')->newThread();
  264.         $threadBuilder
  265.             ->addRecipient('jsm'// Retrieved from your backend, your user manager or ...
  266.             ->setSender($sender)
  267.             ->setSubject('Stof commented on your pull request #456789')
  268.             ->setBody('You have a typo, : mondo instead of mongo. Also for coding standards ...');
  269.         $sender $this->get('fos_message.sender');
  270.         $sender->send($threadBuilder->getMessage());
  271.     }
  272.     public function notifications()
  273.     {
  274.         return $this->render('static_pages/notifications.html.twig', [
  275.             'controller_name' => 'StaticPagesController',
  276.         ]);
  277.     }
  278.     public function contactUs()
  279.     {
  280.         return $this->render('static_pages/contactus.html.twig');
  281.     }
  282.     public function faq()
  283.     {
  284.         return $this->render('static_pages/faqs.html.twig');
  285.     }
  286.     public function newsletter(Request $request)
  287.     {
  288.         return $this->render('static_pages/newsletter.html.twig');
  289.     }
  290.     public function topBarStuff(GlobalFunctions $GlobalFn)
  291.     {
  292.         if ($this->isGranted('ROLE_USER')) {
  293.             $UserId $this->get('security.token_storage')->getToken()->getUser()->getId();
  294.             $Favourites $this->getDoctrine()->getRepository(Favourites::class)->findBy([
  295.                 'UserId' => $UserId,
  296.             ]);
  297.             $Rooms = [];
  298.             foreach ($Favourites as $ThisFavourite) {
  299.                 $Rooms[$ThisFavourite->getRoom()->getId()] = $this->getDoctrine()->getRepository(AccommodationType::class)->find($ThisFavourite->getRoom()->getId());
  300.             }
  301.             $RoomPhoto = [];
  302.             foreach ($Favourites as $ThisFavourite) {
  303.                 $RoomPhoto[$ThisFavourite->getRoom()->getId()] = $GlobalFn->room_photos($Rooms[$ThisFavourite->getRoom()->getId()]->getRoomCode(), true);
  304.             }
  305.             $Property = [];
  306.             foreach ($Favourites as $ThisFavourite) {
  307.                 $Property[$ThisFavourite->getRoom()->getId()] = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Rooms[$ThisFavourite->getRoom()->getId()]->getPropertyCode()]);
  308.             }
  309.             return $this->render('static_pages/topbaraddin.html.twig', [
  310.                  'favourites' => $Favourites,
  311.                  'rooms' => $Rooms,
  312.                  'photos' => $RoomPhoto,
  313.                  'properties' => $Property,
  314.             ]);
  315.         } else {
  316.             return new Response('');
  317.         }
  318.     }
  319.     public function NEWtopBarStuff(GlobalFunctions $GlobalFn)
  320.     {
  321.         if ($this->isGranted('ROLE_USER')) {
  322.             $UserId $this->get('security.token_storage')->getToken()->getUser()->getId();
  323.             $Favourites $this->getDoctrine()->getRepository(Favourites::class)->findBy([
  324.                 'UserId' => $UserId,
  325.             ]);
  326.             $Rooms = [];
  327.             foreach ($Favourites as $ThisFavourite) {
  328.                 $Rooms[$ThisFavourite->getRoomId()] = $this->getDoctrine()->getRepository(AccommodationType::class)->find($ThisFavourite->getRoomId());
  329.             }
  330.             $RoomPhoto = [];
  331.             foreach ($Favourites as $ThisFavourite) {
  332.                 $RoomPhoto[$ThisFavourite->getRoomId()] = $GlobalFn->room_photos($Rooms[$ThisFavourite->getRoomId()]->getRoomCode(), true);
  333.             }
  334.             $Property = [];
  335.             foreach ($Favourites as $ThisFavourite) {
  336.                 $Property[$ThisFavourite->getRoomId()] = $this->getDoctrine()->getRepository(Property::class)->findOneBy(['ListingCode' => $Rooms[$ThisFavourite->getRoomId()]->getPropertyCode()]);
  337.             }
  338.             return $this->render('static_pages/NEWtopbaraddin.html.twig', [
  339.                  'favourites' => $Favourites,
  340.                  'rooms' => $Rooms,
  341.                  'photos' => $RoomPhoto,
  342.                  'properties' => $Property,
  343.             ]);
  344.         } else {
  345.             return new Response('');
  346.         }
  347.     }
  348.     public function giftvoucherBuy()
  349.     {
  350.         return $this->render('static_pages/buygiftvoucher.html.twig', [
  351.             'stripe_public_key' => getenv('stripe_public_key'),
  352.         ]);
  353.     }
  354.     public function payGiftVoucherPostal($stripe_tokenGlobalFunctions $GlobalFn)
  355.     {
  356.         $request Request::createFromGlobals();
  357.         $YourName $request->request->get('your_name');
  358.         $YourEmail $request->request->get('your_email');
  359.         $YourMessage $request->request->get('your_message');
  360.         $RecipientName $request->request->get('recipient_name');
  361.         $SendingOption $request->request->get('sending_option');
  362.         $AddressLine1 $request->request->get('address_line1');
  363.         $AddressLine2 $request->request->get('address_line2');
  364.         $AddressLine3 $request->request->get('address_line3');
  365.         $AddressLine4 $request->request->get('address_line4');
  366.         $Amount $request->request->get('amount');
  367.         $AmountWithFee $Amount 5;
  368.         $Purchase = new GiftVoucherPurchases();
  369.         $NewPurchaseCode substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678901234567890'), 016);
  370.         $Purchase->setPurchaseCode($NewPurchaseCode);
  371.         $Purchase->setPurchaserName($YourName);
  372.         $Purchase->setPurchaserEmail($YourEmail);
  373.         $Purchase->setMessage($YourMessage);
  374.         $Purchase->setSendingOption('post');
  375.         $Purchase->setRecipientName($RecipientName);
  376.         $Purchase->setAddressLine1($AddressLine1);
  377.         $Purchase->setAddressLine2($AddressLine2);
  378.         $Purchase->setAddressLine3($AddressLine3);
  379.         $Purchase->setAddressLine4($AddressLine4);
  380.         $Purchase->setAmount($Amount);
  381.         $em $this->getDoctrine()->getManager();
  382.         $em->persist($Purchase);
  383.         $em->flush();
  384.         $StripeToCharge = ($AmountWithFee 0.3) / (0.029);
  385.         $StripeToChargeCorrected ceil($StripeToCharge 100);
  386.         $amount $Amount;
  387.         \Stripe\Stripe::setApiKey(getenv('stripe_secret_key'));
  388.         $ERRORMODE 0;
  389.         $em $this->getDoctrine()->getManager();
  390.         if (== $amount) {
  391.             $ERRORMODE 0;
  392.         } else {
  393.             try {
  394.                 $charge = \Stripe\Charge::create([
  395.                   'amount' => $StripeToChargeCorrected,
  396.                   'currency' => 'nzd',
  397.                   'description' => 'Gift Voucher Purchase #'.$Purchase->getId(),
  398.                   'source' => $stripe_token,
  399.                   'capture' => true,
  400.                 ]);
  401.             } catch (\Stripe\Error\Card $e) {
  402.                 $ERRORMODE 1;
  403.                 $body $e->getJsonBody();
  404.                 $err $body['error'];
  405.                 if ('card_error' == $err['type']) {
  406.                     if ('invalid_number' == $err['code']) {
  407.                         $ErrorReportText "Your credit card number is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  408.                     }
  409.                     if ('invalid_expiry_month' == $err['code']) {
  410.                         $ErrorReportText "Your expiry month is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  411.                     }
  412.                     if ('invalid_expiry_year' == $err['code']) {
  413.                         $ErrorReportText "Your expiry year is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  414.                     }
  415.                     if ('invalid_cvc' == $err['code']) {
  416.                         $ErrorReportText "Your CVC number is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  417.                     }
  418.                     if ('invalid_swipe_data' == $err['code']) {
  419.                         $ErrorReportText "Your swipe data is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  420.                     }
  421.                     if ('incorrect_number' == $err['code']) {
  422.                         $ErrorReportText "Your credit card number is WRONG. Please try again, your card HASN'T BEEN CHARGED.";
  423.                     }
  424.                     if ('expired_card' == $err['code']) {
  425.                         $ErrorReportText "Your credit card has EXPIRED. Please try again, your card HASN'T BEEN CHARGED.";
  426.                     }
  427.                     if ('incorrect_cvc' == $err['code']) {
  428.                         $ErrorReportText "Your CVC number is wrong. Please try again, your card HASN'T BEEN CHARGED.";
  429.                     }
  430.                     if ('incorrect_zip' == $err['code']) {
  431.                         $ErrorReportText "Your ZIP code is wrong. Please try again, your card HASN'T BEEN CHARGED.";
  432.                     }
  433.                     if ('card_declined' == $err['code']) {
  434.                         $ErrorReportText 'Your card has been declined by the bank.';
  435.                     }
  436.                     if ('missing' == $err['code']) {
  437.                         $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (API-CARD-MISSING)";
  438.                     }
  439.                     if ('processing_error' == $err['code']) {
  440.                         $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (API-CARD-PROCESSING)";
  441.                     }
  442.                 }
  443.             } catch (\Stripe\Error\RateLimit $e) {
  444.                 $ERRORMODE 1;
  445.                 // Too many requests made to the API too quickly
  446.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err ratelimit)";
  447.             } catch (\Stripe\Error\InvalidRequest $e) {
  448.                 $ERRORMODE 1;
  449.                 $body $e->getJsonBody();
  450.                 $err $body['error'];
  451.                 // Invalid parameters were supplied to Stripe's API
  452.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err invalidrequest)";
  453.                 echo 'Status is:'.$e->getHttpStatus()."\n";
  454.                 echo 'Type is:'.$err['type']."\n";
  455.                 echo 'Code is:'.$err['code']."\n";
  456.                 // param is '' in this case
  457.                 echo 'Param is:'."\n";
  458.                 echo 'Message is:'.$err['message']."\n";
  459.             } catch (\Stripe\Error\Authentication $e) {
  460.                 $ERRORMODE 1;
  461.                 // Authentication with Stripe's API failed
  462.                 // (maybe you changed API keys recently)
  463.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err auth)";
  464.             } catch (\Stripe\Error\ApiConnection $e) {
  465.                 $ERRORMODE 1;
  466.                 // Network communication with Stripe failed
  467.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err api)";
  468.             } catch (\Stripe\Error\Base $e) {
  469.                 $ERRORMODE 1;
  470.                 // Display a very generic error to the user, and maybe send
  471.                 // yourself an email
  472.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err errgen)";
  473.             } catch (\Throwable $e) {
  474.                 $ERRORMODE 1;
  475.                 // Something else happened, completely unrelated to Stripe
  476.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err exception)";
  477.             }
  478.         }
  479.         if (== $ERRORMODE) {
  480.             $Voucher = new VoucherCodes();
  481.             $NewCode rand(10009999).'-'.rand(10009999).'-'.rand(10009999).'-'.rand(10009999);
  482.             $Expiry = new \DateTime();
  483.             $Expiry $Expiry->add(new \DateInterval('P1Y'));
  484.             $Voucher->setVoucherCode($NewCode);
  485.             $Voucher->setFaceValue($Amount);
  486.             $Voucher->setStoredValue($Amount);
  487.             $Voucher->setExpiry($Expiry);
  488.             $Voucher->setMinimumSpend(0);
  489.             $Voucher->setPurchaseInfo($Purchase);
  490.             $Voucher->setCreatedDate(new \DateTime());
  491.             $em->persist($Voucher);
  492.             $em->flush();
  493.             $CCfee $StripeToCharge $AmountWithFee;
  494.             $GiftReceipt "<table width='100%'>";
  495.             $GiftReceipt .= '<tr>';
  496.             $GiftReceipt .= '<td><strong>Gift Voucher Value</strong></td>';
  497.             $GiftReceipt .= '<td>'.number_format($Amount2).'</td>';
  498.             $GiftReceipt .= '</tr>';
  499.             $GiftReceipt .= '<tr>';
  500.             $GiftReceipt .= '<td><strong>Postal Fee</strong></td>';
  501.             $GiftReceipt .= '<td>5.00</td>';
  502.             $GiftReceipt .= '</tr>';
  503.             $GiftReceipt .= '<tr>';
  504.             $GiftReceipt .= '<td><strong>Credit Card Fee</strong></td>';
  505.             $GiftReceipt .= '<td>'.number_format($CCfee2).'</td>';
  506.             $GiftReceipt .= '</tr>';
  507.             $GiftReceipt .= '<tr>';
  508.             $GiftReceipt .= '<td><strong>Total Paid</strong></td>';
  509.             $GiftReceipt .= '<td>'.number_format($StripeToCharge2).'</td>';
  510.             $GiftReceipt .= '</tr>';
  511.             $GiftReceipt .= '</table>';
  512.             $VoucherViewEmail 'https://'.$_SERVER['SERVER_NAME'].$this->generateUrl('show_gift_voucher', ['purchase_id' => $NewPurchaseCode]);
  513.             // SEND EMAIL - RECEIPT
  514.             $email = new \SendGrid\Mail\Mail();
  515.             $email->setFrom('support@otbt.co.nz''Off The Beaten Track');
  516.             $email->addTo($YourEmail);
  517.             $email->setTemplateId('d-63a8db02d3ac41caa57b9349ef9f625f'); // UPDATED SG TEMPLATE 2024
  518.             $email->addDynamicTemplateDatas([
  519.                 'purchaser_name' => $YourName,
  520.                 'gift_receipt' => $GiftReceipt,
  521.                 'voucher_url' => $VoucherViewEmail,
  522.             ]);
  523.             $sendgrid = new \App\Classes\SendGrid();
  524.             try {
  525.                 $response $sendgrid->send($email);
  526.             } catch (\Throwable $e) {
  527.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  528.             }
  529.             // SEND POSTAL DESPATCH
  530.             $email = new \SendGrid\Mail\Mail();
  531.             $email->setFrom('support@otbt.co.nz''OTBT System');
  532.             $email->addTo('info@otbt.co.nz');
  533.             $email->addTo('jessica@otbt.co.nz');
  534.             $email->setSubject('Gift Voucher Purchase - Postal Despatch');
  535.             $email->addContent(
  536.                 'text/html',
  537.                 "Hi Admin, <br><br>A gift voucher has been purchased online and has been chosen as postal despatch. Please despatch this gift voucher, as per the details below:<br><br>Purchaser: $YourName ($YourEmail) <br>Voucher Code: $NewCode<br>Sending option: $SendingOption<br><br>Address for Delivery:<br>$AddressLine1<br>$AddressLine2<br>$AddressLine3<br>$AddressLine4<br><br>Recipient Name: $RecipientName<br><br><br>NOTE: If the sending option is SEND_TO_PURCHASER then put the name of the purchaser on the envelope (so it can be delivered to them) and the name of the Recipient on the gift voucher. Otherwise use the Recipient name on the envelope. <br><br>Thanks,<br>OTBT System"
  538.             );
  539.             $sendgrid = new \App\Classes\SendGrid();
  540.             try {
  541.                 $response $sendgrid->send($email);
  542.             } catch (\Throwable $e) {
  543.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  544.             }
  545.             // SEND ACCOUNTS NOTIFY
  546.             $email = new \SendGrid\Mail\Mail();
  547.             $email->setFrom('support@otbt.co.nz''Off The Beaten Track');
  548.             // $email->addTo("partner.otbt@luminate.one");
  549.             $email->addTo('support@otbt.co.nz');
  550.             $email->setTemplateId('d-ffb11e3792844a04ba21bd7ddc8c4995'); // UPDATE SG TEMPLATE 2024
  551.             $email->addDynamicTemplateDatas([
  552.                 'purchaser_name' => $YourName,
  553.                 'purchaser_email' => $YourEmail,
  554.                 'gift_receipt' => $GiftReceipt,
  555.                 'purchase_id' => $Purchase->getId(),
  556.             ]);
  557.             $sendgrid = new \App\Classes\SendGrid();
  558.             try {
  559.                 $response $sendgrid->send($email);
  560.             } catch (\Throwable $e) {
  561.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  562.             }
  563.             return new Response('success:'.$NewPurchaseCode);
  564.         } else {
  565.             return new Response('Error: '.$ErrorReportText);
  566.         }
  567.     }
  568.     public function payGiftVoucherEmail($stripe_tokenRequest $requestGlobalFunctions $GlobalFn)
  569.     {
  570.         $YourName $request->request->get('your_name');
  571.         $YourEmail $request->request->get('your_email');
  572.         $YourMessage $request->request->get('your_message');
  573.         $SendingOption $request->request->get('sending_option');
  574.         $RecipientName $request->request->get('recipient_name');
  575.         $RecipientEmail $request->request->get('recipient_email');
  576.         $Amount $request->request->get('amount');
  577.         $AmountWithFee $Amount 0;
  578.         $Purchase = new GiftVoucherPurchases();
  579.         $NewPurchaseCode substr(str_shuffle('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ012345678901234567890'), 016);
  580.         $Purchase->setPurchaseCode($NewPurchaseCode);
  581.         $Purchase->setPurchaserName($YourName);
  582.         $Purchase->setPurchaserEmail($YourEmail);
  583.         $Purchase->setMessage($YourMessage);
  584.         $Purchase->setSendingOption($SendingOption);
  585.         $Purchase->setRecipientName($RecipientName);
  586.         $Purchase->setRecipientEmail($RecipientEmail);
  587.         $Purchase->setAmount($Amount);
  588.         $em $this->getDoctrine()->getManager();
  589.         $em->persist($Purchase);
  590.         $em->flush();
  591.         $StripeToCharge = ($AmountWithFee 0.3) / (0.029);
  592.         $StripeToChargeCorrected ceil($StripeToCharge 100);
  593.         $amount $Amount;
  594.         \Stripe\Stripe::setApiKey(getenv('stripe_secret_key'));
  595.         $ERRORMODE 0;
  596.         $em $this->getDoctrine()->getManager();
  597.         if (== $amount) {
  598.             $ERRORMODE 0;
  599.         } else {
  600.             try {
  601.                 $charge = \Stripe\Charge::create([
  602.                   'amount' => $StripeToChargeCorrected,
  603.                   'currency' => 'nzd',
  604.                   'description' => 'Gift Voucher Purchase #'.$Purchase->getId(),
  605.                   'source' => $stripe_token,
  606.                   'capture' => true,
  607.                 ]);
  608.             } catch (\Stripe\Error\Card $e) {
  609.                 $ERRORMODE 1;
  610.                 $body $e->getJsonBody();
  611.                 $err $body['error'];
  612.                 if ('card_error' == $err['type']) {
  613.                     if ('invalid_number' == $err['code']) {
  614.                         $ErrorReportText "Your credit card number is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  615.                     }
  616.                     if ('invalid_expiry_month' == $err['code']) {
  617.                         $ErrorReportText "Your expiry month is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  618.                     }
  619.                     if ('invalid_expiry_year' == $err['code']) {
  620.                         $ErrorReportText "Your expiry year is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  621.                     }
  622.                     if ('invalid_cvc' == $err['code']) {
  623.                         $ErrorReportText "Your CVC number is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  624.                     }
  625.                     if ('invalid_swipe_data' == $err['code']) {
  626.                         $ErrorReportText "Your swipe data is INVALID. Please try again, your card HASN'T BEEN CHARGED.";
  627.                     }
  628.                     if ('incorrect_number' == $err['code']) {
  629.                         $ErrorReportText "Your credit card number is WRONG. Please try again, your card HASN'T BEEN CHARGED.";
  630.                     }
  631.                     if ('expired_card' == $err['code']) {
  632.                         $ErrorReportText "Your credit card has EXPIRED. Please try again, your card HASN'T BEEN CHARGED.";
  633.                     }
  634.                     if ('incorrect_cvc' == $err['code']) {
  635.                         $ErrorReportText "Your CVC number is wrong. Please try again, your card HASN'T BEEN CHARGED.";
  636.                     }
  637.                     if ('incorrect_zip' == $err['code']) {
  638.                         $ErrorReportText "Your ZIP code is wrong. Please try again, your card HASN'T BEEN CHARGED.";
  639.                     }
  640.                     if ('card_declined' == $err['code']) {
  641.                         $ErrorReportText 'Your card has been declined by the bank.';
  642.                     }
  643.                     if ('missing' == $err['code']) {
  644.                         $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (API-CARD-MISSING)";
  645.                     }
  646.                     if ('processing_error' == $err['code']) {
  647.                         $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (API-CARD-PROCESSING)";
  648.                     }
  649.                 }
  650.             } catch (\Stripe\Error\RateLimit $e) {
  651.                 $ERRORMODE 1;
  652.                 // Too many requests made to the API too quickly
  653.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err ratelimit)";
  654.             } catch (\Stripe\Error\InvalidRequest $e) {
  655.                 $ERRORMODE 1;
  656.                 $body $e->getJsonBody();
  657.                 $err $body['error'];
  658.                 // Invalid parameters were supplied to Stripe's API
  659.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err invalidrequest)";
  660.                 echo 'Status is:'.$e->getHttpStatus()."\n";
  661.                 echo 'Type is:'.$err['type']."\n";
  662.                 echo 'Code is:'.$err['code']."\n";
  663.                 // param is '' in this case
  664.                 echo 'Param is:'."\n";
  665.                 echo 'Message is:'.$err['message']."\n";
  666.             } catch (\Stripe\Error\Authentication $e) {
  667.                 $ERRORMODE 1;
  668.                 // Authentication with Stripe's API failed
  669.                 // (maybe you changed API keys recently)
  670.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err auth)";
  671.             } catch (\Stripe\Error\ApiConnection $e) {
  672.                 $ERRORMODE 1;
  673.                 // Network communication with Stripe failed
  674.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err api)";
  675.             } catch (\Stripe\Error\Base $e) {
  676.                 $ERRORMODE 1;
  677.                 // Display a very generic error to the user, and maybe send
  678.                 // yourself an email
  679.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err errgen)";
  680.             } catch (\Throwable $e) {
  681.                 $ERRORMODE 1;
  682.                 // Something else happened, completely unrelated to Stripe
  683.                 $ErrorReportText "An error occured on OTBT's end. Please logon to the OTBT dashboard to retry payment (err exception)";
  684.             }
  685.         }
  686.         if (== $ERRORMODE) {
  687.             $Voucher = new VoucherCodes();
  688.             $NewCode rand(10009999).'-'.rand(10009999).'-'.rand(10009999).'-'.rand(10009999);
  689.             $Expiry = new \DateTime();
  690.             $Expiry $Expiry->add(new \DateInterval('P1Y'));
  691.             $Voucher->setVoucherCode($NewCode);
  692.             $Voucher->setFaceValue($Amount);
  693.             $Voucher->setStoredValue($Amount);
  694.             $Voucher->setExpiry($Expiry);
  695.             $Voucher->setMinimumSpend(0);
  696.             $Voucher->setPurchaseInfo($Purchase);
  697.             $Voucher->setCreatedDate(new \DateTime());
  698.             $em->persist($Voucher);
  699.             $em->flush();
  700.             $CCfee $StripeToCharge $AmountWithFee;
  701.             $GiftReceipt "<table width='100%'>";
  702.             $GiftReceipt .= '<tr>';
  703.             $GiftReceipt .= '<td><strong>Gift Voucher Value</strong></td>';
  704.             $GiftReceipt .= '<td>'.number_format($Amount2).'</td>';
  705.             $GiftReceipt .= '</tr>';
  706.             $GiftReceipt .= '<tr>';
  707.             $GiftReceipt .= '<td><strong>Credit Card Fee</strong></td>';
  708.             $GiftReceipt .= '<td>'.number_format($CCfee2).'</td>';
  709.             $GiftReceipt .= '</tr>';
  710.             $GiftReceipt .= '<tr>';
  711.             $GiftReceipt .= '<td><strong>Total Paid</strong></td>';
  712.             $GiftReceipt .= '<td>'.number_format($StripeToCharge2).'</td>';
  713.             $GiftReceipt .= '</tr>';
  714.             $GiftReceipt .= '</table>';
  715.             $VoucherViewEmail 'https://'.$_SERVER['SERVER_NAME'].$this->generateUrl('show_gift_voucher', ['purchase_id' => $NewPurchaseCode]);
  716.             // SEND EMAIL - RECEIPT
  717.             $email = new \SendGrid\Mail\Mail();
  718.             $email->setFrom('support@otbt.co.nz''Off The Beaten Track');
  719.             $email->addTo($YourEmail);
  720.             $email->setTemplateId('d-63a8db02d3ac41caa57b9349ef9f625f'); // SG TEMPLATE UPDATE 2024
  721.             $email->addDynamicTemplateDatas([
  722.                 'purchaser_name' => $YourName,
  723.                 'gift_receipt' => $GiftReceipt,
  724.                 'voucher_url' => $VoucherViewEmail,
  725.             ]);
  726.             $sendgrid = new \App\Classes\SendGrid();
  727.             try {
  728.                 $response $sendgrid->send($email);
  729.             } catch (\Throwable $e) {
  730.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  731.             }
  732.             // SEND VOUCHER EMAIL TO WHOEVER
  733.             $email = new \SendGrid\Mail\Mail();
  734.             $email->setFrom('support@otbt.co.nz''Off The Beaten Track');
  735.             $email->addTo($RecipientEmail);
  736.             $email->setTemplateId('d-799d041efae24812b675bae46b4420fe'); // UPDATED SG TEMPLATE 2024
  737.             $email->addDynamicTemplateDatas([
  738.                 'purchaser_name' => $YourName,
  739.                 'purchaser_email' => $YourEmail,
  740.                 'recipient_name' => $RecipientName,
  741.                 'voucher_url' => $VoucherViewEmail,
  742.             ]);
  743.             $sendgrid = new \App\Classes\SendGrid();
  744.             try {
  745.                 $response $sendgrid->send($email);
  746.             } catch (\Throwable $e) {
  747.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  748.             }
  749.             // SEND ACCOUNTS NOTIFY
  750.             $email = new \SendGrid\Mail\Mail();
  751.             $email->setFrom('support@otbt.co.nz''Off The Beaten Track');
  752.             $email->addTo('support@otbt.co.nz');
  753.             // $email->addTo("partner.otbt@luminate.one");
  754.             $email->setTemplateId('d-ffb11e3792844a04ba21bd7ddc8c4995'); // UPDATE SG TEMPLATE 2024
  755.             $email->addDynamicTemplateDatas([
  756.                 'purchaser_name' => $YourName,
  757.                 'purchaser_email' => $YourEmail,
  758.                 'gift_receipt' => $GiftReceipt,
  759.                 'purchase_id' => $Purchase->getId(),
  760.             ]);
  761.             $sendgrid = new \App\Classes\SendGrid();
  762.             try {
  763.                 $response $sendgrid->send($email);
  764.             } catch (\Throwable $e) {
  765.                 echo 'Caught exception: ',  $e->getMessage(), "\n";
  766.             }
  767.             return new Response('success:'.$NewPurchaseCode);
  768.         } else {
  769.             return new Response('Error: '.$ErrorReportText);
  770.         }
  771.     }
  772.     public function giftvoucherPaid($purchase_id)
  773.     {
  774.         $Purchase $this->getDoctrine()->getRepository(GiftVoucherPurchases::class)->findOneBy(['PurchaseCode' => $purchase_id]);
  775.         return $this->render('static_pages/giftvoucherpaid.html.twig', [
  776.              'purchase' => $Purchase,
  777.         ]);
  778.     }
  779.     public function giftvoucherView($purchase_id)
  780.     {
  781.         $Purchase $this->getDoctrine()->getRepository(GiftVoucherPurchases::class)->findOneBy(['PurchaseCode' => $purchase_id]);
  782.         return $this->render('static_pages/giftvoucherview.html.twig', [
  783.              'purchase' => $Purchase,
  784.         ]);
  785.     }
  786.     public function giftvoucherPrint($purchase_id)
  787.     {
  788.         $Purchase $this->getDoctrine()->getRepository(GiftVoucherPurchases::class)->findOneBy(['PurchaseCode' => $purchase_id]);
  789.         return $this->render('static_pages/giftvoucherprint.html.twig', [
  790.              'purchase' => $Purchase,
  791.         ]);
  792.     }
  793.     public function masthead()
  794.     {
  795.         return $this->render('static_pages/aboutwebsite.html.twig');
  796.     }
  797.     public function accept_terms(): Response
  798.     {
  799.         return $this->render('static_pages/acceptterms.html.twig', [
  800.             'returnPath' => $_GET['returnPath'], ]
  801.         );
  802.     }
  803.     public function record_accept_terms(): Response
  804.     {
  805.         $returnPath $_GET['returnPath'];
  806.         $User $this->getUser();
  807.         $User->setTermsAccepted(1);
  808.         $TermsAcceptance = new TermsAcceptance();
  809.         $TermsAcceptance->setUser($User);
  810.         $TermsAcceptance->setAcceptanceIP($_SERVER['REMOTE_ADDR']);
  811.         $TermsAcceptance->setAcceptanceDateTime(new \DateTime());
  812.         $this->getDoctrine()->getManager()->persist($User);
  813.         $this->getDoctrine()->getManager()->persist($TermsAcceptance);
  814.         $this->getDoctrine()->getManager()->flush();
  815.         return new RedirectResponse($returnPath);
  816.     }
  817.     public function referralReward(): Response
  818.     {
  819.         return $this->render('static_pages/propertyreferral.html.twig');
  820.     }
  821.     public function competitionEntry(): Response
  822.     {
  823.         return $this->render('static_pages/competitionentry.html.twig');
  824.     }
  825.     public function roadies(): Response
  826.     {
  827.         return $this->render('static_pages/roadies.html.twig');
  828.     }
  829.     public function hireGear(): Response
  830.     {
  831.         return $this->render('static_pages/hiregear.html.twig');
  832.     }
  833.     public function landownerVideo(): Response
  834.     {
  835.         return $this->render('static_pages/landownervideo.html.twig');
  836.     }
  837.     public function sendEmailFormToSupport($form_name$send_toRequest $request): Response
  838.     {
  839.         // $formData = print_r($request->request, true);
  840.         $formData '';
  841.         foreach ($request->request as $name => $value) {
  842.             $formData .= '<br>';
  843.             $formData .= '<strong>'.$name.'</strong>:<br>';
  844.             $formData .= $value.'<br>';
  845.         }
  846.         $expSendTo explode(','$send_to);
  847.         $email = new \SendGrid\Mail\Mail();
  848.         $email->setFrom('support@otbt.co.nz''OTBT System');
  849.         foreach ($expSendTo as $thisSend) {
  850.             $email->addTo($thisSend);
  851.         }
  852.         $email->setSubject('Email Form Submitted - '.$form_name);
  853.         $email->addContent(
  854.             'text/html',
  855.             'Hi Admin, <br><br><pre>'.$formData.'</pre> <br><br>Thanks,<br>OTBT System'
  856.         );
  857.         $sendgrid = new \App\Classes\SendGrid();
  858.         try {
  859.             $response $sendgrid->send($email);
  860.         } catch (\Throwable $e) {
  861.             echo 'Caught exception: ',  $e->getMessage(), "\n";
  862.         }
  863.         return new Response('success');
  864.     }
  865.     public function iframeCaptive(): Response
  866.     {
  867.         return new Response('success');
  868.     }
  869.     public function globalWebsiteControl(): Response
  870.     {
  871.         // Find unplanned maintenance
  872.         $UnplannedMaintenanceMode $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'unplanned_maintenance_mode']);
  873.         $UnplannedMaintenanceText $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'unplanned_maintenance_text']);
  874.         $newsletter_popup_dismissed $this->get('session')->get('newsletter_popup_dismissed');
  875.         $exitintent_popup_dismissed $this->get('session')->get('exitintent_popup_dismissed');
  876.         $ActiveStylesheet $this->GlobalFn->datedVar('active_stylesheet'date('Y-m-d'));
  877.         if ('var_not_found' == $ActiveStylesheet) {
  878.             $StylesheetURL 'newtheme/css/clean-blog.css';
  879.         } else {
  880.             $StylesheetURL $ActiveStylesheet;
  881.         }
  882.         if ($UnplannedMaintenanceMode) {
  883.             if ('1' == $UnplannedMaintenanceMode->getValue()) {
  884.                 return $this->render('static_pages/headercontrols.html.twig', [
  885.                     'unplanned_maintenance_mode' => true,
  886.                     'unplanned_maintenance_text' => $UnplannedMaintenanceText->getValue(),
  887.                     'planned_maintenance' => null,
  888.                     'site_wide_header_content' => null,
  889.                     'swhcolour' => null,
  890.                     'newsletter_popup_status' => $newsletter_popup_dismissed,
  891.                     'exitintent_popup_status' => $exitintent_popup_dismissed,
  892.                     'stylesheet_url' => $StylesheetURL,
  893.                 ]);
  894.             }
  895.         }
  896.         // Find planned maintenance
  897.         $TimeNow = new \DateTime();
  898.         $PlannedMaintenance $this->getDoctrine()->getRepository("App\Entity\PlannedMaintenance")->createQueryBuilder('t')
  899.                ->where(':current_time BETWEEN t.FromTime AND t.ToTime')
  900.                ->setParameter('current_time'$TimeNow)
  901.                ->getQuery()
  902.                ->getResult();
  903.         if (== count($PlannedMaintenance)) {
  904.             $PlannedMaintenance null;
  905.         } else {
  906.             return $this->render('static_pages/headercontrols.html.twig', [
  907.                 'unplanned_maintenance_mode' => false,
  908.                 'unplanned_maintenance_text' => null,
  909.                 'planned_maintenance' => $PlannedMaintenance,
  910.                 'site_wide_header_content' => null,
  911.                 'swhcolour' => null,
  912.                 'newsletter_popup_status' => $newsletter_popup_dismissed,
  913.                 'exitintent_popup_status' => $exitintent_popup_dismissed,
  914.                 'stylesheet_url' => $StylesheetURL,
  915.             ]);
  916.         }
  917.         // Find site wide headers
  918.         $SiteWideHeader $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'site_wide_header_text']);
  919.         $SiteWideHeaderTimed $this->GlobalFn->datedVar('site_wide_header_text'date('Y-m-d'));
  920.         $SiteWideHeaderColour $this->getDoctrine()->getRepository(WebsiteControl::class)->findOneBy(['KeyName' => 'site_wide_header_colour']);
  921.         if (null == $SiteWideHeaderColour) {
  922.             $SWHColour 'CC7722';
  923.         } else {
  924.             $SWHColour $SiteWideHeaderColour->getValue();
  925.         }
  926.         if ('var_not_found' == $SiteWideHeaderTimed) {
  927.             $SWHText $SiteWideHeader->getValue();
  928.         } else {
  929.             $SWHText $SiteWideHeaderTimed;
  930.         }
  931.         if ('' !== $SiteWideHeader->getValue()) {
  932.             return $this->render('static_pages/headercontrols.html.twig', [
  933.                 'unplanned_maintenance_mode' => false,
  934.                 'unplanned_maintenance_text' => null,
  935.                 'planned_maintenance' => null,
  936.                 'site_wide_header_content' => $SWHText,
  937.                 'swhcolour' => $SWHColour,
  938.                 'newsletter_popup_status' => $newsletter_popup_dismissed,
  939.                 'exitintent_popup_status' => $exitintent_popup_dismissed,
  940.                 'stylesheet_url' => $StylesheetURL,
  941.             ]);
  942.         } else {
  943.             return $this->render('static_pages/headercontrols.html.twig', [
  944.                 'unplanned_maintenance_mode' => false,
  945.                 'unplanned_maintenance_text' => null,
  946.                 'planned_maintenance' => null,
  947.                 'site_wide_header_content' => null,
  948.                 'swhcolour' => null,
  949.                 'newsletter_popup_status' => $newsletter_popup_dismissed,
  950.                 'exitintent_popup_status' => $exitintent_popup_dismissed,
  951.                 'stylesheet_url' => $StylesheetURL,
  952.             ]);
  953.         }
  954.     }
  955.     public function static_page($slug): Response
  956.     {
  957.         $Page $this->getDoctrine()->getRepository(CMSPages::class)->findOneBy(['Slug' => $slug'Type' => 'static']);
  958.         $GetAboveContent $this->getDoctrine()->getRepository(CMSBlocks::class)->findOneBy(['Page' => $Page'Identifier' => 'abovecontent']);
  959.         if (null == $GetAboveContent) {
  960.             $AboveContent '';
  961.         } else {
  962.             $AboveContent $GetAboveContent->getContent();
  963.         }
  964.         $GetBody $this->getDoctrine()->getRepository(CMSBlocks::class)->findOneBy(['Page' => $Page'Identifier' => 'body']);
  965.         if (null == $GetBody) {
  966.             $Body '';
  967.         } else {
  968.             $Body $GetBody->getContent();
  969.         }
  970.         return $this->render('static_pages/staticpage.html.twig', [
  971.             'htmlcontent' => false,
  972.             'page_title' => $Page->getPageTitle(),
  973.             'abovecontent' => $AboveContent,
  974.             'body' => $Body,
  975.         ]);
  976.     }
  977.     public function dynamicMenu(): Response
  978.     {
  979.         $GetItems $this->getDoctrine()->getRepository(CMSMenu::class)->findBy(['ParentItem' => null], ['ItemOrder' => 'ASC']);
  980.         $Env $this->getParameter('kernel.environment');
  981.         return $this->render('static_pages/dynamicMenu.html.twig', [
  982.             'items' => $GetItems,
  983.             'env' => $Env,
  984.         ]);
  985.     }
  986.     public function showNewsletterPopup()
  987.     {
  988.         if (null == $this->get('session')->get('newsletter_popup_shown')) {
  989.         }
  990.     }
  991.     /**
  992.      * @Route("/phplisttest", name="phplisttest")
  993.      */
  994.     public function phplisttest(): Response
  995.     {
  996.         $Email 'hello@concentric.co.nz';
  997.         $ch curl_init();
  998.         $POST_DATA http_build_query([
  999.             'login_name' => 'admin',
  1000.             'password' => '7aqCbgQ2k',
  1001.         ]);
  1002.         curl_setopt($chCURLOPT_URL'http://comms.otbt.co.nz/lists/api/v2/sessions');
  1003.         curl_setopt($chCURLOPT_POST1);
  1004.         curl_setopt($chCURLOPT_POSTFIELDS$POST_DATA);
  1005.         // Receive server response ...
  1006.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1007.         $keyraw curl_exec($ch);
  1008.         $keydec json_decode($keyraw);
  1009.         $key $keydec->key;
  1010.         curl_close($ch);
  1011.         $ch curl_init();
  1012.         $POST_DATA http_build_query([
  1013.             'email' => $Email,
  1014.         ]);
  1015.         curl_setopt($chCURLOPT_URL'http://comms.otbt.co.nz/custom_addsub.php');
  1016.         curl_setopt($chCURLOPT_POST1);
  1017.         curl_setopt($chCURLOPT_POSTFIELDS$POST_DATA);
  1018.         // Receive server response ...
  1019.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1020.         $userid curl_exec($ch);
  1021.         curl_close($ch);
  1022.         $ch curl_init();
  1023.         $POST_DATA http_build_query([
  1024.             'sub_id' => $userid,
  1025.             'list_id' => 3,
  1026.             'action' => 'add',
  1027.         ]);
  1028.         curl_setopt($chCURLOPT_URL'http://comms.otbt.co.nz/custom_linksublist.php');
  1029.         curl_setopt($chCURLOPT_POST1);
  1030.         curl_setopt($chCURLOPT_POSTFIELDS$POST_DATA);
  1031.         // Receive server response ...
  1032.         curl_setopt($chCURLOPT_RETURNTRANSFERtrue);
  1033.         $response curl_exec($ch);
  1034.         curl_close($ch);
  1035.         return new Response('FROM SERVER: '.$response);
  1036.     }
  1037.     /**
  1038.      * @Route("/updatedterms/{id}", name="updatedterms")
  1039.      */
  1040.     public function updatedterms(Terms $Terms)
  1041.     {
  1042.         @$returnPath $_GET['returnPath'];
  1043.         return $this->render('static_pages/acceptupdatedterms.html.twig', [
  1044.             'terms' => $Terms,
  1045.             'returnPath' => $returnPath,
  1046.         ]);
  1047.     }
  1048.     /**
  1049.      * @Route("/updatedterms/{id}/accept", name="updatedterms_accept")
  1050.      */
  1051.     public function updatedterms_accept(Terms $Terms)
  1052.     {
  1053.         $TermsAcceptance = new TermsAcceptance();
  1054.         $TermsAcceptance->setTermsVersion($Terms);
  1055.         $TermsAcceptance->setUser($this->getUser());
  1056.         $TermsAcceptance->setAcceptanceIP($_SERVER['REMOTE_ADDR']);
  1057.         $TermsAcceptance->setAcceptanceDateTime(new \DateTime());
  1058.         $this->getDoctrine()->getManager()->persist($TermsAcceptance);
  1059.         $this->getDoctrine()->getManager()->flush();
  1060.         if (isset($_GET['returnPath'])) {
  1061.             if ('' !== $_GET['returnPath']) {
  1062.                 return new RedirectResponse($_GET['returnPath']);
  1063.             } else {
  1064.                 return $this->redirectToRoute('fos_user_profile_show');
  1065.             }
  1066.         } else {
  1067.             return $this->redirectToRoute('fos_user_profile_show');
  1068.         }
  1069.     }
  1070.     /**
  1071.      * @Route("/ask_a_question", name="ask_a_question")
  1072.      */
  1073.     public function listingNewQA(Request $requestUrlGeneratorInterface $router): Response
  1074.     {
  1075.         $person_name = (string) $request->request->get('person_name');
  1076.         $person_email = (string) $request->request->get('person_email');
  1077.         $question = (string) $request->request->get('question');
  1078.         $room_id = (string) $request->request->get('room_id');
  1079.         /**
  1080.          * @var AccommodationType $Room
  1081.          */
  1082.         $Room $this->getDoctrine()->getRepository(AccommodationType::class)->find($room_id);
  1083.         $Landowner $this->getDoctrine()->getRepository(User::class)->find($Room->getLandownerId());
  1084.         if ('' !== $question) {
  1085.             $newQA = new ListingQuestions();
  1086.             $newQA->setRoom($Room);
  1087.             $newQA->setQuestion($question);
  1088.             $newQA->setAskedDate(new \DateTime());
  1089.             $newQA->setAskedByName($person_name);
  1090.             $newQA->setAskedByEmail($person_email);
  1091.             $entityManager $this->getDoctrine()->getManager();
  1092.             $entityManager->persist($newQA);
  1093.             $entityManager->flush();
  1094.             $ReplyURL 'https://'.$_SERVER['SERVER_NAME'].$router->generate('landowner_qa_answer', ['id' => $newQA->getId()]);
  1095.             $ModerateURL 'https://'.$_SERVER['SERVER_NAME'].$router->generate('admin_listingquestions_moderate', ['id' => $newQA->getId()]);
  1096.             $email = new \SendGrid\Mail\Mail();
  1097.             $email->setFrom('support@otbt.co.nz''OTBT System');
  1098.             $email->addTo('info@otbt.co.nz');
  1099. //            $email->addTo('jordan@luminate.one');
  1100. //             $email->addTo("partner.otbt@luminate.one");
  1101.             $email->setSubject('New QA FROM HOLIDAYMAKER to be moderated');
  1102.             $email->addContent(
  1103.                 'text/html',
  1104.                 "<div style='font-family: Arial, sans-serif;'>
  1105.                         <p style='color: #2d3748; font-size: 16px;'>Hi team,</p>
  1106.                         <p style='color: #2d3748;'>A new question has been asked by a holidaymaker. Please review and moderate it promptly:</p>
  1107.                         <p style='margin: 10px 0; text-align: center;'>
  1108.                             <!--[if mso]>
  1109.                                 <v:roundrect xmlns:v='urn:schemas-microsoft-com:vml' xmlns:w='urn:schemas-microsoft-com:office:word' href='".htmlspecialchars($ModerateURL)."' style='height:40px;v-text-anchor:middle;width:200px;' arcsize='10%' stroke='f' fillcolor='#4299e1'>
  1110.                                     <w:anchorlock/>
  1111.                                     <center style='color:#ffffff;font-family:sans-serif;font-size:13px;font-weight:bold;'>Moderate Now</center>
  1112.                                 </v:roundrect>
  1113.                             <![endif]-->
  1114.                             <!--[if !mso]> <!-->
  1115.                                 <a href='".htmlspecialchars($ModerateURL)."' style='background-color: #4299e1; color: white; padding: 10px 15px; border-radius: 5px; text-decoration: none; display: inline-block; mso-hide: all;'>Moderate Now</a>
  1116.                             <!-- <![endif]-->
  1117.                         </p>
  1118.                         <p style='color: #718096; margin-top: 20px; font-size: 14px;'>OTBT System</p>
  1119.                     </div>"
  1120.             );
  1121.             $sendgrid = new \App\Classes\SendGrid();
  1122.             try {
  1123.                 /** @var SendGridResponse $response */
  1124.                 $response $sendgrid->send($email);
  1125.             } catch (\Throwable $e) {
  1126.                 return new Response('error sending request'500);
  1127.             }
  1128.             if (202 == $response->statusCode()) {
  1129.                 return new Response('success');
  1130.             }
  1131.         }
  1132.         return new Response('something went wrong');
  1133.     }
  1134. }