HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers110/franciscaansebeweging.nl/app/Komma/Contact/ContactController.php
<?php

/**
 * Short description for the file.
 *
 * @author      Komma <support@komma.pro>
 * @copyright   (c) 2012-2015, Komma Mediadesign
 */

namespace Komma\Contact;

use Ixudra\Curl\Facades\Curl;
use Komma\Blocks\BlockService;
use Komma\Kms\Schools\School;
use Komma\Mailers\MailService;
use Komma\Pages\PageService;

class ContactController extends \BaseController
{
    protected $contactService;
    protected $mailService;
    protected $pageService;
    protected $blockService;
    public $languageService;

    /**
     * ContactController constructor.
     * @param ContactService $contactService
     * @param MailService $mailService
     * @param PageService $pageService
     */
    public function __construct(ContactService $contactService, BlockService $blockService, MailService $mailService, PageService $pageService)
    {
        parent::__construct();

        $this->pageService = $pageService;
        $this->mailService = $mailService;
        $this->contactService = $contactService;
        $this->blockService = $blockService;
    }


    /**
     * This method returns the contact form view
     *
     * @param bool $sent
     * @return mixed
     */
    public function contactForm()
    {

        //get content of page by route because of the multiple news overviews all page links
        $page = $this->pageService->getPageByRoute(\Request::path());

        $page->send = \Input::get('v', false);

        // Get root parent and append code_name to page
        // So we can find out to which branch/school the page belongs
        if($page->getDepth() != 1)
        {
            $page->root = $this->pageService->getRootParent($page);
        }
        else
        {
            // The page itself is the root branch, so to prevent writing if/else statements append it as branch
            $page->root = $page;
        }


        $links = $this->pageService->getAllRoutes();

        //Return the view
        return \View::make('layouts.pages.contact')
            ->with('page', $page)
            ->with('links', $links);


    }

    public function contactSuccess()
    {
        return $this->contactForm(true);
    }

    /**
     * This method processes the contact form
     *
     * @return null
     */
    public function contactFormProcess()
    {
        //Validate the input
        $validation = $this->contactService->validateContactForm(\Input::all());

//        If validation is not null and the request is  via ajax, return the validation messages
//        if($validation !== null && \Request::ajax()) return $validation;

        //If The validation is not null, redirect back to the form with the errors.
        if($validation !== null) {
            \Log::info($validation);

            return \Redirect::back()->withErrors($validation)->withInput();
        }
        $inputs = \Input::all();

        $result = $this->recaptcha(isset($inputs['g-recaptcha-response']) ? $inputs['g-recaptcha-response'] : '');

        if(is_array($result)){
            $validation = ['recaptcha' => [$result['errors']['secretCode'][0]]]; // Fix de structuur

            return \Redirect::back()->withErrors($validation)->withInput();
        }


        $this->mailService->saveMailToDatabase(\Input::all());
        $this->mailService->sendContactForm(\Input::all());

        //If the request ia via ajax, return the string true
        //For the normal request show the contactForm page. with the send variable set to true
//        return \Redirect::to(\URL::previous() . '?v=true');
        //return Redirect::back()->with('errors', $error);
        return \Redirect::route('contact.success');
    }

    /**
     * This method processes the contact form
     *
     * @return null
     */
    public function travelProcess()
    {

        $input = \Input::all();

        //Validate the input
        $validation = $this->contactService->validateTravelForm($input);

//        If validation is not null and the request is  via ajax, return the validation messages
//        if($validation !== null && \Request::ajax()) return $validation;

        //If The validation is not null, redirect back to the form with the errors.
        if($validation !== null) {
            \Log::info($validation);

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $inputs = \Input::all();

        $result = $this->recaptcha(isset($inputs['g-recaptcha-response']) ? $inputs['g-recaptcha-response'] : '');

        if(is_array($result)){
            $validation = ['recaptcha' => [$result['errors']['secretCode'][0]]]; // Fix de structuur

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $this->mailService->saveMailToDatabase(\Input::all(), 'travel-form');
        $this->mailService->sendTravelForm(\Input::all());
        $this->mailService->sendTravelFormCustomer(\Input::all());

        //TODO write mail to subscribe as confirm

        \Session::put('travelId', $input['travelId']);

        //For the normal request show the contactForm page. with the send variable set to true
        return \Redirect::route('travelSubscribe.success');
    }

    /**
     * This method processes the contact form
     *
     * @return null
     */
    public function subscribeProcess()
    {

        $input = \Input::all();

        //Validate the input
        $validation = $this->contactService->validateSubscribeForm($input);

//        If validation is not null and the request is  via ajax, return the validation messages
//        if($validation !== null && \Request::ajax()) return $validation;

        //If The validation is not null, redirect back to the form with the errors.
        if($validation !== null) {
            \Log::info($validation);

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $inputs = \Input::all();

        $result = $this->recaptcha(isset($inputs['g-recaptcha-response']) ? $inputs['g-recaptcha-response'] : '');

        if(is_array($result)){
            $validation = ['recaptcha' => [$result['errors']['secretCode'][0]]]; // Fix de structuur

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $this->mailService->saveMailToDatabase(\Input::all(), 'subscribe-form');
        $this->mailService->sendSubscribeForm(\Input::all());
        $this->mailService->sendSubscribeFormCustomer(\Input::all());

        //TODO write mail to subscribe as confirm

        //For the normal request show the contactForm page. with the send variable set to true
        return \Redirect::route('subscribe.success');
    }

    /**
     * This method processes the contact form
     *
     * @return null
     */
    public function becomeFriendProcess()
    {

        $input = \Input::all();

        //Validate the input
        $validation = $this->contactService->validateBecomeFriendForm($input);

//        If validation is not null and the request is  via ajax, return the validation messages
//        if($validation !== null && \Request::ajax()) return $validation;

        //If The validation is not null, redirect back to the form with the errors.
        if($validation !== null) {
            \Log::info($validation);

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $inputs = \Input::all();

        $result = $this->recaptcha(isset($inputs['g-recaptcha-response']) ? $inputs['g-recaptcha-response'] : '');

        if(is_array($result)){
            $validation = ['recaptcha' => [$result['errors']['secretCode'][0]]]; // Fix de structuur

            return \Redirect::back()->withErrors($validation)->withInput();
        }

        $this->mailService->saveMailToDatabase(\Input::all(), 'become-friend-form');
        $this->mailService->sendBecomeFriendForm(\Input::all());
        $this->mailService->sendBecomeFriendFormCustomer(\Input::all());

        //TODO write mail to subscribe as confirm

        //For the normal request show the contactForm page. with the send variable set to true
        return \Redirect::route('becomeFriend.success');
    }

    public function thanks()
    {

        // Else use the home
        $page = $this->pageService->getPageByCodeName('about');


        $thanks = [
            'title'       => \KommaLang::get('subscribeThanksTitle'),
            'description' => \KommaLang::get('subscribeFormThanksDescription'),
        ];

        switch (\Request::segment(1)){

            case 'contact':
                $thanks['title'] = \KommaLang::get('contactThanksTitle');
                $thanks['description'] = \KommaLang::get('contactThanksDescription');
                break;
        }

        //get all page links
        $links = $this->pageService->getAllRoutes();

        return \View::make('layouts.pages.thanks')
            ->with('page', $page)
            ->with('thanks', (object) $thanks)
            ->with('links', $links);

    }

    public function recaptcha($recaptcha) {
        if(empty($recaptcha)){
            return [
                'status' => 422,
                'errors' => [
                    'secretCode' => ['Uw invoer is niet gevalideerd. Vink het vakje ‘Ik ben geen robot’ aan en probeer het opnieuw.'],
                ],
            ];
        } else {
            $ch = curl_init();

            curl_setopt($ch, CURLOPT_URL, 'https://www.google.com/recaptcha/api/siteverify');
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query([
                'secret' => '6LfQlkQrAAAAAGkSqNfp85DVkjtDFda5XMFaI65i', // Use Config instead of getenv()
                'response' => $recaptcha, // Use Input facade for Laravel 4
            ]));
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

            $response = curl_exec($ch);

            if (curl_errno($ch)) {
                // Handle cURL error
                return [
                    'status' => 500,
                    'errors' => ['message' => ['Er ging iets mis bij de controle. Probeer het opnieuw.']],
                ];
            }

            curl_close($ch);

            $responseData = json_decode($response, true);

            // Validate response
            if (! isset($responseData['success']) || ! $responseData['success']) {
                return [
                    'status' => 422,
                    'errors' => [
                        'secretCode' => ['Uw invoer is niet gevalideerd. Vink het vakje ‘Ik ben geen robot’ aan en probeer het opnieuw.'],
                    ],
                ];
            }
        }

        return null;
    }

}