

*/
 $prijzen = get_option(‘product-prijzen’);
add_shortcode(‘offerte-side-bar’, ‘getOfferteSideBar’);
 if (!function_exists(‘getOfferteSideBar’)) {
 function getOfferteSideBar() {
 return
 ‘
‘
 ;
 }
 }
add_shortcode(‘vurenprijs’, ‘getVurenPrijs’);
 if (!function_exists(‘getVurenPrijs’)) {
 function getVurenPrijs() {
 $prijzen = get_option(‘product-prijzen’);
 return $prijzen[‘Noord Europees Vuren, meerprijs per meter’];
 }
 }
 add_shortcode(‘grenenprijs’, ‘getGrenenPrijs’);
 if (!function_exists(‘getGrenenPrijs’)) {
 function getGrenenPrijs() {
 $prijzen = get_option(‘product-prijzen’);
 return $prijzen[‘Midden Europees Grenen (standaard)’];
 }
 }
 add_shortcode(‘douglasprijs’, ‘getDouglasPrijs’);
 if (!function_exists(‘getDouglasPrijs’)) {
 function getDouglasPrijs() {
 $prijzen = get_option(‘product-prijzen’);
 return $prijzen[‘Douglas, meerprijs per meter’];
 }
 }
 add_shortcode(‘bangkiraiprijs’, ‘getBangkiraiPrijs’);
 if (!function_exists(‘getBangkiraiPrijs’)) {
 function getBangkiraiPrijs() {
 $prijzen = get_option(‘product-prijzen’);
 return $prijzen[‘Bangkirai hardhout, meerprijs per meter’];
 }
 }
 add_shortcode(‘reiskostenperkm’, ‘getReisKostenPerKm’);
 if (!function_exists(‘getReisKostenPerKm’)) {
 function getReisKostenPerKm() {
 $prijzen = get_option(‘product-prijzen’);
 return $prijzen[‘Prijs per km’];
 }
 }
require_once( getcwd() . ‘/wp-blog-header.php’);
 require_once( getcwd() . ‘/wp-content/themes/enfold/prijs.php’);
$pricelist = getItems();
$json_pricelist = [];
 foreach ($pricelist AS $key => $value) {
 foreach ($value AS $k => $v) {
 $k = str_replace(‘ ‘, ”, $k);
 if ($k != ‘name’) {
 if (isset($v[‘price’])) {
 $json_pricelist[$k] = $v[‘price’];
 } elseif (is_array($v)) {
 foreach ($v AS $s => $w) {
 if (isset($w[‘price’])) {
 $s = str_replace(‘ ‘, ”, $s);
 $json_pricelist[$k . $s] = $w[‘price’];
 }
 }
 }
 }
 }
 }
 $json_pricelist = json_encode($json_pricelist);
$response = “”;
 function my_contact_form_generate_response($type, $message) {
 global $response;
if($type == “success”) $response = “
{$message}
“;
 else $response = “
{$message}
“;
 }
/* Error meldingen schrijven */
 $conditionserror = “Voordat u de offerte kunt aanvragen moet u eerst akkoord gaan met onze voorwaarden.”;
 $missing_content = “Vul alstublieft alle informatie in.”;
 $email_invalid = “E-mailadres klopt niet.”;
 $message_unsent = “Het bericht is niet verzonden. Probeer het later opnieuw.”;
 $message_sent = “Bedankt! Je bericht is verzonden.”;
 $db_failure = “Er is iets foutgegaan bij het registreren van de nieuwsbrief. Probeer het opnieuw zonder de nieuwsbrief.”;
/* Defining variables */
 $content = ‘
‘;
 $content .= ‘| Informatie |  | 
‘;
 $content .= ‘
| Datum | ‘ . date(‘Y-m-d H:i:s’) . ‘ | 
‘;
 $totalprice = 0;
 $totaladditions = 0;
 $materials = [];
/* Unset waardes die niet in de email moeten */
 $conditions = $_POST[‘Voorwaarden’];
 $email = $_POST[‘Email’];
 $file = $_POST[‘Bestand’];
 unset($_POST[‘Voorwaarden’]);
 unset($_POST[‘Bestand’]);
foreach ($_POST AS $key => $value) {
$price = null;
if ($pos = strpos($value, ‘- ‘) !== false ) {
 $value = str_replace(‘- ‘, ”, $value);
 }
/* Check voor toevoegingen, toevoegingen worden niet geteld per meter
 maar aan het einde bij het totaal opgeteld. Toevoegingen hoeven ook niet
 gecheckt te worden op modifier aangezien toevoegingen altijd + zijn. */
 if ($key == ‘Kleurvanhetbeton’) {
 if (isset($pricelist[$key][$value][‘price’])) {
 $totaladditions = $totaladditions + $pricelist[$key][$value][‘price’];
 }
 } elseif ($key == ‘Wiltubetonpalenwaareenlichtleidingingestortzit’) {
 if (isset($pricelist[$key][$value][‘price’])) {
 $totaladditions = $totaladditions + $pricelist[$key][$value][‘price’];
 }
 } elseif ($key == ‘Aantalhoekpalen’) {
 if (isset($pricelist[$key][$value][‘price’])) {
 $totaladditions = $totaladditions + $pricelist[$key][$value][‘price’];
 }
 } elseif ($key == ‘Wiltuookspecialetuinschermenzoalstrellisofvscherm’) {
 if (isset($pricelist[$key][$value][‘price’])) {
 $totaladditions = $totaladditions + $pricelist[$key][$value][‘price’];
 }
 } elseif ($key == ‘Inclusieftuindeur’) {
 /* Er moet minimaal 1 tuindeur zijn wil je de prijs van tuindeuren kunnen berekenen */
 if (isset($pricelist[$key][$value][‘price’]) && $_POST[‘Aantaltuindeuren’] > 0) {
 $totaladditions = $totaladditions + ($pricelist[$key][$value][‘price’] * $_POST[‘Aantaltuindeuren’]);
 }
 }
/* If the value is empty, unset */
 if ($value == ”) {
 unset($_POST[$key]);
 } else {
 if (isset($pricelist[$key])) {
 /* Check if price is set, if not, this is an array containing multiple options */
 if (isset($pricelist[$key][$value][‘price’])) {
 $price = $pricelist[$key][$value];
 } else {
 /* Check if value contains one of these words, if it does, get the price */
 if (strpos($value, ‘enkelzijdig’) !== false) {
 if (isset($pricelist[$key][$value][‘enkelzijdig’][‘price’])) {
 $price = $pricelist[$key][$value][‘enkelzijdig’];
 }
 } elseif (strpos($value, ‘dubbelzijdig’) !== false) {
 if (isset($pricelist[$key][$value][‘dubbelzijdig’][‘price’])) {
 $price = $pricelist[$key][$value][‘dubbelzijdig’];
 }
 } elseif (strpos($value, ‘Grenen’) !== false) {
 if (isset($pricelist[$key][$value][‘grenen’][‘price’])) {
 $price = $pricelist[$key][$value][‘grenen’];
 }
 } elseif (strpos($value, ‘Vuren’) !== false) {
 if (isset($pricelist[$key][$value][‘vuren’][‘price’])) {
 $price = $pricelist[$key][$value][‘vuren’];
 }
 } elseif (strpos($value, ‘Douglas’) !== false) {
 if (isset($pricelist[$key][$value][‘douglas’][‘price’])) {
 $price = $pricelist[$key][$value][‘douglas’];
 }
 } elseif (strpos($value, ‘Bangkirai’) !== false) {
 if (isset($pricelist[$key][$value][‘bangkirai’][‘price’])) {
 $price = $pricelist[$key][$value][‘bangkirai’];
 }
 }
 }
 }
 }
/* Writing content for the email,
 If name is set, print name instead of seo_name */
 if ($key === ‘Totalelengtevandeschutting’) {
 if (isset($pricelist[$key][‘name’])) {
 $content .= ‘
| ‘ . $pricelist[$key][‘name’] . ‘ | ‘ . $value . ‘ Meter | 
‘;
 }
 } else {
 if (isset($pricelist[$key][‘name’])) {
 $content .= ‘
| ‘ . $pricelist[$key][‘name’] . ‘ | ‘ . $value . ‘ | 
‘;
 } else {
 $content .= ‘
| ‘ . $key . ‘ | ‘ . $value . ‘ | 
‘;
 }
 }/* Check if price is being added or distracted from total */
 if (!is_null($price) && isset($price[‘modifier’]) && isset($price[‘price’])) {
 if ($price[‘modifier’] == ‘+’) {
 $totalprice = $totalprice + $price[‘price’];
 } elseif ($price[‘modifier’] == ‘-‘) {
 $totalprice = $totalprice – $price[‘price’];
 }
 }
if (substr($value, 0, 2) === ‘- ‘) {
 $value = substr($value, 2);
 }
/* Materialen opslaan */
 if (isset($pricelist[$key][$value][‘materials’])) {
 $materials[$key] = $pricelist[$key][$value][‘materials’];
 } elseif (isset($pricelist[$key][‘- ‘ . $value][‘materials’])) {
 $materials[$key] = $pricelist[$key][‘- ‘ . $value][‘materials’];
 }
 if (strpos($value, ‘enkelzijdig’) !== false) {
 $_val = explode(‘ ‘, $value);
 foreach ($_val AS $k => $v) {
 if ($v === ‘enkelzijdig’) {
 $materials[$key] = $pricelist[$key][‘- ‘ . $_val[0]. ‘ ‘ . $_val[1]][‘enkelzijdig’][‘materials’];
 }
 }
 }
 if (strpos($value, ‘dubbelzijdig’) !== false) {
 $_val = explode(‘ ‘, $value);
 foreach ($_val AS $k => $v) {
 if ($v === ‘dubbelzijdig’) {
 $materials[$key] = $pricelist[$key][‘- ‘ . $_val[0]. ‘ ‘ . $_val[1]][‘dubbelzijdig’][‘materials’];
 }
 }
 }
 $meters = $_POST[‘Totalelengtevandeschutting’];
 $palen_schermen = floatval(($meters / 1.9));
 $materials[‘palen’] = ceil($palen_schermen);
 $materials[‘schermen’] = round($palen_schermen, 1 , PHP_ROUND_HALF_UP);
 }
 /* Check if the form has been submitted */
 if (isset($_POST[‘Postcode’]) && isset($_POST[‘Totalelengtevandeschutting’])) {
 /* Reiskosten berekenen met Google maps distance matrix */
 $apikey = ‘AIzaSyA3OEgPEabuKy10asaB6vX1ZUgIFHEvDcI’;
 $units = ‘metric’;
 $googleurl = ‘https://maps.googleapis.com/maps/api/distancematrix/’;
 $outputformat = ‘json’;
 $origins = urlencode(‘5706td’);
 $destination = urlencode($_POST[‘Postcode’]);
 /* Bouw de api link */
 $link = $googleurl . $outputformat . ‘?units=’ . $units . ‘&origins=’ . $origins . ‘&destinations=’ . $destination . ‘&key=’ . $apikey;
 $result = json_decode(file_get_contents($link));
 $afstand = $result->rows[0]->elements[0]->distance->value; // Afstand in meters
 $tijd = $result->rows[0]->elements[0]->duration->value; // Tijd in seconden
 $reiskosten = round(($afstand / 1000) * $prijzen[‘Prijs per km’] , 2); // Formule: Prijs per kilometer * aantal km
$content .= ‘
| Reistijd | ‘ . round(($tijd / 60)) . ‘ minuten | 
‘;
 $content .= ‘
| Afstand | ‘ . round(($afstand / 1000),1) . ‘ kilometer | 
‘;/* Prijslijst maken */
 $content .= ‘
| Prijzen |  | 
‘;
$totalprice = $totalprice + $reiskosten;
/* Totaalprijs keer het aantal meters */
 $totalprice = $totalprice * intval($_POST[‘Totalelengtevandeschutting’]);
/* Tel de toevoegingen op bij de totaalprijs */
 $totalprice = $totalprice + $totaladditions;
/* Reiskosten toevoegen aan de mail */
 $content .= ‘
| Voorrijkosten | €’ . $reiskosten . ‘ | 
‘;/* Writing content for the email */
 $content .= ‘
| Prijs totaal | €’ . $totalprice . ‘ | 
‘;/* Totaalprijs + BTW */
 $totalprice = round($totalprice * 1.21, 2);
/* Writing content for the email */
 $content .= ‘
| Prijs inclusief BTW | €’ . $totalprice . ‘ | 
‘;$content .= ‘
| Materialen |  | 
‘;
 foreach ($materials AS $m_key => $mats) {
 $m_key === ‘Ikbengeinteresseerdin’ ? $length = true : $length = false;
 if (is_array($mats)) {
 foreach ($mats AS $k => $m) {
 if ((isset($k) && $k != ”) || (isset($m) && $m != ”)) {
 $content .= ‘
‘;  if (is_int($m)) {  $content .= $k . ‘ | ‘ . $m;  } else {  if ($length) {  $content .= $m . ‘ | ‘ . intval($_POST[‘Totalelengtevandeschutting’]) . ‘ Meter’;  $length = false;  } else {  $content .= $m . ‘ |  ‘;  }  }  $content .= ‘ | 
‘;
 }
 }
 } elseif ($m_key == ‘palen’ || $m_key == ‘schermen’) {
 $content .= ‘
| ‘ . ucfirst($m_key) . ‘ | ‘ . $mats . ‘ | 
‘;
 }
 }
 echo ‘
‘;
/* Setting options for the email */
 $to = get_option(‘admin_email’);
 $subject = “Iemand heeft een offerte aangevraagd”;
 $headers = [
 ‘From: ‘. $email . “\r\n”,
 ‘Reply-To: ‘ . $email . “\r\n”,
 ‘Content-Type: text/html; charset=UTF-8’
 ];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
 my_contact_form_generate_response(“error”, $email_invalid);
 } else {
 /* Check of de voorwaarden zijn geaccepteerd */
 if (!isset($conditions) || strtolower($conditions) !== ‘ja’) {
 my_contact_form_generate_response(“error”, $conditionserror);
 } else {
 $sent = wp_mail($to, $subject, $content, $headers, $attachment);
 if ($sent) {
 my_contact_form_generate_response(“success”, $message_sent); //Verzonden
 } else {
my_contact_form_generate_response(“error”, $message_unsent); //Niet verzonden
 }
 }
 }
 }
get_header();
if(have_posts()) :
 while (have_posts()) : the_post();
 ?>
 U bevindt zich hier: Home / Offerte aanvragen