File: D:/HostingSpaces/SBogers10/sportivo.komma.pro/app/Komma/Contact/ContactController.php
<?php
namespace Komma\Contact;
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Response;
use Komma\Blog\BlogService;
use Komma\Mailers\MailRepository;
use Komma\Mailers\MailService;
use Komma\Page\PageService;
use Komma\Sports\SportsService;
class ContactController extends Controller
{
public $data;
protected $pageService;
protected $blogService;
protected $sportService;
protected $mailRepository;
protected $mailer;
public function __construct(MailRepository $mailRepository,PageService $pageService, SportsService $sportsService, BlogService $blogService, MailService $mailer)
{
;
$this->pageService = $pageService;
$this->blogService = $blogService;
$this->sportService = $sportsService;
$this->mailRepository = $mailRepository;
$this->mailer = $mailer;
$this->data = [
'socialMeda' => false,
'articleBlock' => ['header' => 'Recente blog artikelen',
'articles' => $this->blogService->getLatestBlogItems(2),
'footer' => 'Bekijk alle blog artikelen',
'url' => '/blog'],
'grouplessons' => $this->sportService->getGroupLessons(),
'link' => 'http://' . $_SERVER['SERVER_NAME']
];
}
public function contact($submited = false, $error = [])
{
$this->data['error'] = $error;
$this->data['submited'] = $submited;
$this->data = array_merge($this->data, $this->pageService->getContent('contact'));
return \View::make('layouts.pages.contact')->with('data', (object)$this->data);
}
public function subscribe($submited = false, $error = [])
{
$this->data['error'] = $error;
$this->data['submited'] = $submited;
$this->data = array_merge($this->data, $this->pageService->getContent('subscribe'));
return \View::make('layouts.pages.contact')->with('data', (object)$this->data);
}
public function newsletter($submited = false, $error = [])
{
$this->data['error'] = $error;
$this->data['submited'] = $submited;
$this->data = array_merge($this->data, $this->pageService->getContent('newsletter'));
return \View::make('layouts.pages.contact')->with('data', (object)$this->data);
}
public function grouplesson($submited = false, $error = [])
{
$this->data['error'] = $error;
$this->data['submited'] = $submited;
$this->data = array_merge($this->data, $this->pageService->getContent('subscribeGrouplesson'));
$this->data['redirected'] = Input::get('to');
return \View::make('layouts.pages.contact')->with('data', (object)$this->data);
}
public function popUpMail(){
$all = \Request::all();
if (Hash::check('sportivoMail', $all['salt'], ['cost' => 3]))
{
$this->mailRepository->changeSubscribed($all['id'], $all['amount']);
$this->data = array_merge($this->data, $this->pageService->getContent('contact'));
$this->data['contactType'] = 'mailClick';
$this->mailer->popUpSubscribe($all);
return \Redirect::to('/contact/afvalprogramma/bedankt2');
}
else{
return $this->contact();
}
}
public function popUpMailThanks(){
$this->data = array_merge($this->data, $this->pageService->getContent('contact'));
$this->data['contactType'] = 'mailClick';
return \View::make('layouts.pages.contact')->with('data', (object)$this->data);
}
public function sendPopUp(){
$all = \Request::all();
$error = [];
if($all['name'] == "")
{
$error[] = 'Geen naam ingegeven';
}
if(!filter_var($all['email'], FILTER_VALIDATE_EMAIL) || $all['email'] == "")
{
$error[] = "Geen geldig emailadres ingevuld";
}
if(count($error) == 0)
{
$this->mailer->popUpMail($all);
$this->data['submited'] = true;
return $this->contact(true);
}
else
{
return Redirect::to('/');
}
}
public function thanksForm()
{
$all = \Request::all();
$error = [];
if($all['name'] == "")
{
$error[] = 'Geen naam ingegeven';
}
if($all['phone'] == "" && (!filter_var($all['email'], FILTER_VALIDATE_EMAIL) || $all['email'] == ""))
{
$error[] = "Geen geldig contactmanier ingevuld";
}
if($all['message_text'] == "")
{
$error[] = 'Geen bericht ingegeven';
}
if(count($error) == 0)
{
$this->mailer->sendContactForm($all);
$this->data['submited'] = true;
return $this->contact(true);
}
else
{
return $this->contact(false, $error);
}
}
public function thanksNewsletterForm()
{
$all = \Request::all();
$error = [];
if($all['name'] == "")
{
$error[] = 'Geen naam ingegeven';
}
if(!filter_var($all['email'], FILTER_VALIDATE_EMAIL) || $all['email'] == "")
{
$error[] = "Geen geldig emailadres ingevuld";
}
if(count($error) == 0)
{
$this->mailer->sendMailForm($all);
$this->data['submited'] = true;
return $this->newsletter(true);
}
else
{
return $this->newsletter(false, $error);
}
}
public function subscribeThanks()
{
$all = \Request::all();
$error = [];
if($all['first_name'] == "")
{
$error[] = 'Geen voornaam ingegeven';
}
if($all['sur_name'] == "")
{
$error[] = 'Geen achternaam ingegeven';
}
if($all['sex'] == "")
{
$error[] = 'Geen geslacht ingegeven';
}
if($all['birthdate'] == "")
{
$error[] = 'Geen geboortedatum ingegeven';
}
if($all['adres'] == "")
{
$error[] = 'Geen straatnaam ingegeven';
}
if($all['streetnumber'] == "")
{
$error[] = 'Geen staatnummer ingegeven';
}
if($all['zip'] == "")
{
$error[] = 'Geen postcode ingegeven';
}
if($all['city'] == "")
{
$error[] = 'Geen stad ingegeven';
}
if( ! isset($all['fitness']) || $all['fitness'] == null)
{
$error[] = 'Geen soort fitness ingegeven';
}
if($all['amount'] == '')
{
$error[] = 'Geen hoeveelheid ingegeven';
}
if( ! filter_var($all['email'], FILTER_VALIDATE_EMAIL) || $all['email'] == "")
{
$error[] = "Geen geldig email formaat ingevuld";
}
if(count($error) == 0)
{
$this->mailer->subscribeSportivo($all);
$this->data['submited'] = true;
return $this->subscribe(true);
}
else
{
return $this->subscribe(false, $error);
}
}
public function grouplessonThanks()
{
$all = \Request::all();
$error = [];
if($all['name'] == "")
{
$error[] = 'Geen naam ingegeven';
}
if( ! isset($all['grouplesson']) || $all['grouplesson'] == null)
{
$error[] = 'Geen groepsles ingegeven';
}
if( ! filter_var($all['email'], FILTER_VALIDATE_EMAIL) || $all['email'] == "")
{
$error[] = "Geen geldig email formaat ingevuld";
}
if(count($error) == 0)
{
$this->mailer->subscribeGrouplesson($all);
$this->data['submited'] = true;
return $this->grouplesson(true);
}
else
{
return $this->grouplesson(false, $error);
}
}
}