File: D:/HostingSpaces/yoda-ict/yoda-ict.nl/wwwroot/app/controllers/c_offer.class.php
<?php
/**
* c_home.class.php
* Created by Komma Mediadesign.
* Author: mike
* Date: 11/02/14
*/
require_once DOCUMENT_ROOT . 'lib/form/form.class.php';
require_once DOCUMENT_ROOT . 'lib/mail/php_mailer.class.php';
class Offer extends Controller
{
private $name;
public function __construct()
{
$this->name = 'offer';
parent::__construct();
}
/*
* Index of the home page
*/
public function index()
{
// Title
$this->View->setData('page_title', 'Offerte aanvragen | ' . SITE_NAME);
// Generate form
$Form = new Form('offer');
$fields = $Form->generate();
$this->View->setData('form_fields',$fields);
if(isset($_SESSION['offer_errors'])) unset($_SESSION['offer_errors']);
// Load template view
$this->View->render('v_offer');
}
/*
* Validate contact form
*/
public function validate()
{
if(isset($_POST['secretcode']) && $_POST['secretcode'] == 'spamcheckkomma')
{
$Form = new Form($this->name);
if($Form->validate())
{
// Get data for mail
$data = $_SESSION[$this->name]['data'];
// Convert message
$data['message'] = nl2br($data['message']);
$from['email'] = COMPANY_EMAIL;
$from['name'] = $data['first_name'] . ' ' . $data['last_name'];
$to['email'] = COMPANY_EMAIL;
$to['name'] = COMPANY_NAME;
// Create message for mail
$msg = 'Er is een bericht binnen gekomen via het contactformulier op de website:<br /><br />';
foreach($data as $prop => $value)
{
$msg .= '<strong>' . $this->lang[$prop] . '</strong>:<br /> ' . $value . '<br /><br />';
}
// Message client
$clientMsg = 'Geachte heer / mevrouw ' . ucfirst($data['last_name']) . ',<br /><br />';
$clientMsg .= 'Bedankt voor uw aanvraag.<br />';
$clientMsg .= 'Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.<br /><br />';
$clientMsg .= 'Met vriendelijke groet,<br /><br />';
$clientMsg .= 'Frans Rampen,<br />
Yoda ICT';
// Send e-mail
$Mailer = new PHPMailer(TRUE);
try
{
// Mail
$Mailer->AddAddress($to['email'], $to['name']);
$Mailer->SetFrom($from['email'], $from['name']);
$Mailer->Subject = 'YODA ICT - Offerte formulier';
$Mailer->MsgHTML($msg);
$Mailer->Send();
// Mail Client
$ClientMailer = new PHPMailer(TRUE);
$ClientMailer->AddAddress($data['email'], $data['first_name'] . ' ' . $data['last_name']);
$ClientMailer->SetFrom(COMPANY_EMAIL, COMPANY_NAME);
$ClientMailer->Subject = 'Bedankt voor uw vraag';
$ClientMailer->MsgHTML($clientMsg);
$ClientMailer->Send();
// Success message
$_SESSION[$this->name]['success'] = 'Geachte heer / mevrouw ' . ucfirst($data['last_name']) . ',<br /><br />
Bedankt voor uw aanvraag. Deze is in behandeling genomen en we nemen zo spoedig mogelijk contact met u op.<br /><br />Met vriendelijke groet,<br />Yoda ICT B.V.';
}
catch (phpmailerException $e)
{
// Catch mail problem?
$_SESSION[$this->name]['main_error'] = 'Er is iets fout gegaan bij verzenden. <br />Neem contact op met <a href="mailto:info@yoda-ict.nl">info@yoda-ict.nl</a>';
}
unset($_SESSION[$this->name]['data']);
}
}
Fn::redirect('/offerte-aanvragen');
}
public function subject()
{
if(defined('URL_SUB2'))
{
switch(URL_SUB2)
{
case 'hosted-exchange-basic':
$_SESSION['offer']['data']['subject'] = 'Hosted Exchange BASIC';
break;
case 'hosted-exchange-advanced':
$_SESSION['offer']['data']['subject'] = 'Hosted Exchange ADVANCED';
break;
case 'hostingpakket-lite':
$_SESSION['offer']['data']['subject'] = 'Hostingpakket LITE';
break;
case 'hostingpakket-basic':
$_SESSION['offer']['data']['subject'] = 'Hostingpakket BASIC';
break;
case 'hostingpakket-advanced':
$_SESSION['offer']['data']['subject'] = 'Hostingpakket ADVANCED';
break;
}
}
$this->index();
}
}