ToniDev

class-custom-public-pages-manager.php

May 26th, 2022 (edited)
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 332.44 KB | None | 0 0
  1. <?php
  2. /*
  3.   Plugin Name: Custom Public Pages Manager
  4.   Plugin URI:
  5.   Description: Custom public pages management module for the NL site
  6.   Author: Jos van der Wielen
  7.   Version: 2.2
  8. */
  9.  
  10.  
  11. /*
  12.  
  13. NOTE FOR DEVELOPERS:
  14.  
  15. SOME METHODS IN THE CLASS BELOW, AS WELL AS SOME PROCEDURAL FUNCTIONS AFTER THAT, ARE USED FOR ADMIN PURPOSES.
  16.  
  17. THESE ADMIN FUNCTIONS (FRONT-END AND BACK-END) NEED TO TAKE "AANVRAGEN" FROM BOTH NL AND BE DATABASES INTO ACCOUNT,
  18. SO DATABASE SWITCHES ARE INCLUDED IN MANY PLACES.
  19.  
  20. ESPECIALLY FUNCTIONALITY DEALING WITH PLANNING (GUIDES, GUIDE-AANVRAAG RELATIONS), MUST COMBINE ARRAYS OF AANVRAGEN FROM BOTH DATABASES WITH THE PLANNING DATA THAT IS ONLY AVAILABLE IN THE NL DATABASE.
  21.  
  22. IF THE QUERIES ARE SQL ONLY, A SECOND 'REMOTE' WPDB IS CONNECTED AND USED FOR THE BE DATABASE
  23.  
  24. WHEN A "POD" NEEDS TO BE QUERIED ON THE BELGIAN DATABASE IN A FUNCTION THAT ONLY RUNS ON THE NL SYSTEM,
  25. THE WPDB CONNECTION ITSELF IS TEMPORARILY SWAPPED FOR A CONNECTION WITH THE BE DATABASE, AND RESET AFTER THE POD HAS DONE IT'S THING
  26.  
  27. */
  28.  
  29. // create global variables that can be seen by header.php
  30. $tag_values = array();
  31. $game_values = array();
  32. $location_values = array();
  33. $town_values = array();
  34. $array_tags = array();
  35. $array_games = $array_game_names = array();
  36. $array_towns = $array_town_names = array();
  37. $array_locations = $array_location_names = array();
  38. $parsetype = '0';
  39.  
  40.  
  41. DEFINE ( 'VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService' );
  42.  
  43.  
  44. class Custom_Pages_Manager {
  45.  
  46.   public function __construct() {
  47.  
  48.     add_action( 'template_redirect', array( $this, 'front_controller' ) );
  49.     add_action( 'custom_generate_rewrite_rules_for_all_games_towns_locations', array( $this, 'generate_rewrite_rules_for_all_games_towns_locations' ));
  50.  
  51.     add_action( 'custom_beschikbaarheid_in_stappen', array( $this, 'beschikbaarheid_in_stappen' ));
  52.  
  53.     add_action( 'custom_beschikbaarheidsaanvraag', array( $this, 'beschikbaarheidsaanvraag' ));
  54.     add_action( 'custom_ophalen_beschikbaarheid_bij_locatie', array( $this, 'ophalen_beschikbaarheid_bij_locatie' ));
  55.  
  56.     add_action( 'custom_verwerken_beschikbaarheid_van_locatie', array( $this, 'verwerken_beschikbaarheid_van_locatie' ));
  57.     add_action( 'custom_afhandelen_beschikbaarheidsaanvraag', array( $this, 'afhandelen_beschikbaarheidsaanvraag' ));
  58.     add_action( 'custom_verwerken_afhandeling_beschikbaarheidsaanvraag', array( $this, 'verwerken_afhandeling_beschikbaarheidsaanvraag' ));
  59.     add_action( 'custom_reserveren', array( $this, 'reserveren' ));
  60.     add_action( 'custom_contactform', array( $this, 'contactform' ));
  61. /*    add_action( 'custom_contacted', array( $this, 'contacted' ));*/
  62.     add_action( 'custom_sitemap_page', array( $this, 'sitemap_page' ));
  63.     add_action( 'custom_mutatie_aantal', array( $this, 'mutatie_aantal' ));
  64.     add_action( 'custom_print_reserveringen', array( $this, 'print_reserveringen' ));
  65.     add_action( 'custom_recensies', array( $this, 'recensies' ));
  66.  
  67.     add_action( 'wp_ajax_nopriv_beschikbaarheid_steps_towns_per_game', array( $this, 'beschikbaarheid_steps_towns_per_game'));
  68.     add_action( 'wp_ajax_nopriv_beschikbaarheid_steps_locations_per_town', array( $this, 'beschikbaarheid_steps_locations_per_town'));
  69.  
  70.     add_action( 'wp_ajax_beschikbaarheid_steps_towns_per_game', array( $this, 'beschikbaarheid_steps_towns_per_game'));
  71.     add_action( 'wp_ajax_beschikbaarheid_steps_locations_per_town', array( $this, 'beschikbaarheid_steps_locations_per_town'));
  72.  
  73.   }
  74.  
  75.   //=====================================================================================
  76.   public function beschikbaarheid_in_stappen(){
  77.  
  78.     global  $wpdb;
  79.     $games = $wpdb->get_results( "SELECT id, game_code, game_name FROM wp_pods_games ORDER BY game_order  " );
  80.  
  81.     include dirname(__FILE__) . '/templates/tpl_beschikbaarheid_in_stappen.php';
  82.     exit;
  83.   }
  84.  
  85.  
  86.  
  87.   //=====================================================================================
  88.   public function beschikbaarheid_steps_towns_per_game() {
  89.    
  90.     global $wpdb;
  91.     $errors = array();
  92.  
  93.     // DIT IS EEN AJAX CALL VOOR ALLE BEZOEKERS, DUS ALS NIET INGELOGD
  94.  
  95.     check_ajax_referer( 'my-spesscccial-string', 'security' );
  96.  
  97.     $game_code = isset( $_POST['game_code'] ) ? $_POST['game_code'] : '';
  98.     if (empty($game_code)) {
  99.         $errors[] = 'Ontbrekende game code';
  100.         if ( defined( 'DOING_AJAX' ) ) {
  101.             // echo the content as a json array
  102.             echo json_encode(
  103.                 array(
  104.                     'result' => false,
  105.                     'data' => "Ontbrekende game code"
  106.                 )
  107.             );
  108.         }
  109.     }
  110.  
  111.     $params = array(
  112.         'select'    => '
  113.            t.id as location_id,
  114.            t.location_name,
  115.            t.location_code,
  116.            #t.location_coordinates,
  117.  
  118.            town.id as town_id,
  119.            town.town_name as town_name,
  120.            town.town_code as town_code,
  121.            town.town_coordinates as town_coordinates,
  122.  
  123.            location_images.guid as location_image
  124.           ',
  125.  
  126.         'join'      => '
  127.            INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  128.            INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  129.  
  130.         'where'     => " game_code = '".$game_code."' ",
  131.         'orderby'     => 'town.town_name',
  132.         'limit'     => 0
  133.     );
  134.     $locations_pod = pods( 'locations', $params );
  135.     if ( $locations_pod->total() > 0 ) {
  136.       $bLocation = true;
  137.       $game_towns_locations_values = $locations_pod->rows;
  138.  
  139.  
  140.       // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
  141.       $data["geolocations"] = '[';
  142.       $comma='';
  143.       $prev_town_code = '';
  144.       while ($locations_pod->fetch() ) {
  145.         $row = $locations_pod->row();
  146.  
  147.         if ($row['town_code'] != $prev_town_code) {
  148.             // FIRST ROW FOR THIS TOWN
  149.             $prev_town_code = $row['town_code'];
  150.             $game_towns[] = $row;
  151.         }
  152.  
  153.       }
  154.  
  155.       // add 'Locaties in Nederland' and 'Eigen locatie'  as the first elements (for all games but the culi game)
  156.       if ($game_code != 'food-en-fun-culi-spel') {
  157.         $eigen_locatie = array(
  158.           'town_code' => 'eigen-locatie',
  159.           'town_name' => 'Eigen locatie',
  160.           'town_coordinates' => ''
  161.         );
  162.         array_unshift($game_towns, $eigen_locatie);
  163.       }
  164.  
  165.       ob_start();
  166.       if (isset($game_towns) && count($game_towns) > 0) { ?>
  167.  
  168.           <option value="">Kies een plaats</option>
  169.           <?php foreach ($game_towns as $game_town): ?>
  170.           <option value="<?php print $game_town['town_code']; ?>"><?php print $game_town['town_name']; ?></option>
  171.           <?php endforeach; ?>
  172.  
  173.         <?php
  174.         $temp_content = ob_get_contents();
  175.         ob_end_clean();
  176.  
  177.         if ( defined( 'DOING_AJAX' ) ) {
  178.             // echo the content as a json array
  179.             echo json_encode(
  180.                 array(
  181.                     'result' => true,
  182.                     'data' => $temp_content
  183.                 )
  184.             );
  185.         }
  186.         wp_die();
  187.  
  188.       } else {
  189.  
  190.         if ( defined( 'DOING_AJAX' ) ) {
  191.             // echo the content as a json array
  192.             echo json_encode(
  193.                 array(
  194.                     'result' => false,
  195.                     'data' => "geen plaatsen gevonden"
  196.                 )
  197.             );
  198.         }
  199.         wp_die();    
  200.  
  201.       }
  202.     }
  203.   }
  204.  
  205.  
  206.  
  207.   //=====================================================================================
  208.  
  209.   public function beschikbaarheid_steps_locations_per_town() {
  210.    
  211.     global $wpdb;
  212.     global $array_games, $array_towns, $array_locations;
  213.     global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
  214.     global $tag_values, $game_values, $town_values, $location_values, $rel_location_game_values, $town_locations_games_values;
  215.     global $wpdb;
  216.  
  217.     $errors = array();
  218.  
  219.     // DIT IS EEN AJAX CALL VOOR ALLE BEZOEKERS, DUS ALS NIET INGELOGD
  220.  
  221.     check_ajax_referer( 'my-spesscccial-string', 'security' );
  222.  
  223.     $game_code = isset( $_POST['game_code'] ) ? $_POST['game_code'] : '';
  224.     $town_code = isset( $_POST['town_code'] ) ? $_POST['town_code'] : '';
  225.     if (empty($game_code) || empty($town_code)) {
  226.         $errors[] = 'Ontbrekende game of town code';
  227.         if ( defined( 'DOING_AJAX' ) ) {
  228.             // echo the content as a json array
  229.             echo json_encode(
  230.                 array(
  231.                     'result' => false,
  232.                     'data' => "Ontbrekende game of town code"
  233.                 )
  234.             );
  235.         }
  236.         wp_die();  
  237.     }
  238.  
  239.  
  240.     $town_row = $wpdb->get_row( "SELECT town_name FROM wp_pods_towns WHERE town_code = '".$town_code."'" );
  241.     $town_name = $town_row->town_name;
  242.  
  243.     // GET THE TOWN'S COORDINATES
  244.     $params = array(
  245.         'select'    => '
  246.            t.location_coordinates
  247.            ',
  248.         'where'     => " town.town_code = '".$town_code."' ",
  249.         'limit'     => 0
  250.     );
  251.     $town_coords_pod = pods( 'locations', $params );
  252.     $town_coords = $town_coords_pod->rows[0]->location_coordinates;
  253.  
  254.     // GET ALL LOCATIONS WITHIN 15 KM OF THE TOWN WHERE THIS GAME IS PLAYED
  255.     $json_geolocation   = $town_coords;
  256.     $obj_googlemapcoords   = json_decode($json_geolocation);
  257.     if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  258.         if (   isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
  259.         && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
  260.         ) {
  261.  
  262.           $center_latitude = $obj_googlemapcoords->lat;
  263.           $center_longitude = $obj_googlemapcoords->lng;
  264.  
  265.           // array to hold selected location ids
  266.           $location_codes_near_town = array();
  267.  
  268.           // first get all locations, regardless
  269.           $params_radius = array(
  270.               'select'    => '
  271.                              t.location_code,
  272.                              t.location_coordinates
  273.                             ',
  274.               'limit'     => 0
  275.           );
  276.  
  277.           $tmp_locations_pod_radius = pods( 'locations', $params_radius );
  278.           $tmp_locations_pod_radius_total = $tmp_locations_pod_radius->total();
  279.  
  280.           // now select those locations close to the town
  281.  
  282.           if ($tmp_locations_pod_radius_total > 0 ):
  283.               while ($tmp_locations_pod_radius->fetch() ):
  284.                   $row_radius = $tmp_locations_pod_radius->row();
  285.  
  286.                   $json_geolocation_radius   = $row_radius['location_coordinates'];
  287.                   $obj_googlemapcoords_radius   = json_decode($json_geolocation_radius);
  288.                   if (!empty($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lng)  ) {
  289.                       if (   isset($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lat)
  290.                           && isset($obj_googlemapcoords_radius->lng) && !empty($obj_googlemapcoords_radius->lng)
  291.                           ) {
  292.  
  293.                           $check_latitude = $obj_googlemapcoords_radius->lat;
  294.                           $check_longitude = $obj_googlemapcoords_radius->lng;
  295.                       }
  296.                   }
  297.  
  298.                   if (empty($check_latitude) || empty($check_longitude) ) continue;
  299.  
  300.                   $sql = 'SELECT DISTINCT
  301.                              (   3959 * acos(cos(radians('.$center_latitude.')) * cos( radians( '.$check_latitude.' ) )
  302.                                  * cos( radians(  '.$check_longitude.' ) - radians('.$center_longitude.') )
  303.                                  + sin(radians('.$center_latitude.')) * sin(radians('.$check_latitude.' )))
  304.                              ) AS distance';
  305.                   $distance = $wpdb->get_row( $sql )->distance;
  306.  
  307.                   if (is_numeric($distance) && $distance > 0 && $distance < 7):
  308.                     // OK, select this location, is close enough
  309.                     $location_codes_near_town[] = $row_radius['location_code'];
  310.                   endif;
  311.  
  312.               endwhile;
  313.           endif;
  314.  
  315.         }
  316.  
  317.     }
  318.     $orlocationsin = '';
  319.     if (count($location_codes_near_town) > 0 ) {
  320.         // location sfound in the area, create an IN string for the next SQL
  321.         $orlocationsin = ' OR t.location_code IN ("'. implode('", "', $location_codes_near_town).'")';
  322.     }
  323.  
  324.     // GET THE LOCATIONS FOR THIS GAME IN THIS TOWN
  325.     $params = array(
  326.         'select'    => '
  327.          DISTINCT
  328.  
  329.            CASE
  330.                WHEN town.town_code = "'.$_POST['town_code'].'" THEN 0
  331.                WHEN t.location_code = "eigen-locatie" THEN 2
  332.                ELSE 1
  333.            END AS first_sort,
  334.            t.id as location_id,
  335.            t.location_name,
  336.            t.address_1,
  337.            t.postal_code,
  338.            t.location_code,
  339.            t.location_name,
  340.            t.location_text,
  341.            t.location_coordinates,
  342.  
  343.            town.id as town_id,
  344.            town.town_name as town_name,
  345.            town.town_code as town_code,
  346.            town.town_coordinates
  347.            ',
  348.  
  349.         'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  350.                         INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  351.  
  352.         'where'     => " game_code = '".$game_code."'
  353.                         AND ( town.town_code = '".$town_code."'  OR t.location_code = 'eigen-locatie' ".$orlocationsin ." ) ",
  354.         'orderby'     => 'first_sort, location_order, location_name',
  355.         'limit'     => 0
  356.     );
  357.  
  358.     $game_town_locations_pod = pods( 'locations', $params );
  359.  
  360.     $game_town_locations_values_totalrows = $game_town_locations_pod->total();
  361.     if ( $game_town_locations_values_totalrows > 0 ) {
  362.         // COLLECT  VALUES FOR ALL LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
  363.         $game_town_locations_values = $game_town_locations_pod->rows;
  364.  
  365.     }
  366.  
  367.  
  368.  
  369.     $firsttime=true;
  370.     ob_start();
  371.     if (isset($game_town_locations_values) && count($game_town_locations_values) > 0) {
  372.  
  373.       foreach($game_town_locations_values as $game_town_location_values) {
  374.  
  375.         $location_code = $game_town_location_values->location_code;
  376.         $town_name = $game_town_location_values->town_name;
  377.  
  378.         $params = array(
  379.             'select'    => ' t.* ',
  380.             'where' => 'game_code = "'.$game_code.'"',
  381.             'limit'     => 0
  382.         );
  383.         $games_pod = pods( 'games', $params );
  384.         if ( $games_pod->total() > 0 ) {
  385.             $game_values = array();
  386.             while ($games_pod->fetch() ) {
  387.                 $row = $games_pod->row();
  388.                 // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  389.                 foreach($games_pod->fields as $podsfield) {
  390.                     $fieldname = $podsfield['name'];
  391.                     $game_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
  392.                 }
  393.             }
  394.         }
  395.         $game_name = $game_values['game_name'];
  396.  
  397.  
  398.  
  399.  
  400.         $params = array(
  401.             'select'    => ' t.* ',
  402.             'where' => 'location_code = "'.$location_code.'"',
  403.             'limit'     => 0
  404.         );
  405.         $locations_pod = pods( 'locations', $params );
  406.         if ( $locations_pod->total() > 0 ) {
  407.             $location_values = array();
  408.             while ($locations_pod->fetch() ) {
  409.                 $row = $locations_pod->row();
  410.                 // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  411.                 foreach($locations_pod->fields as $podsfield) {
  412.                     $fieldname = $podsfield['name'];
  413.                     $location_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $locations_pod->display($fieldname) ;
  414.                 }
  415.             }
  416.         }
  417.         $location_name = $location_values['location_name'];
  418.  
  419.  
  420.       // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
  421.       $params = array(
  422.           'select'    => 'wp_rel_locations_games.*
  423.                         ',
  424.           'join'      => ' INNER JOIN wp_rel_locations_games ON (
  425.                              t.id = wp_rel_locations_games.location_id
  426.                              AND (min_number IS NOT NULL AND min_number > 0)
  427.                              AND (max_number IS NOT NULL AND max_number > 0)
  428.                           )
  429.                           INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  430.  
  431.           'where'     => " game_code = '".$game_code."'
  432.                           AND location_code = '".$location_code."'",
  433.           'orderby'     => 'min_number',
  434.           'limit'     => 0
  435.       );
  436.       $rel_location_game_pod = pods( 'locations', $params );
  437.       if ( $rel_location_game_pod->total() > 0 ) {
  438.           $rel_location_game_values = $rel_location_game_pod->rows;
  439.           $bLocation_games = true;
  440.       }
  441.  
  442.       // MINIMUM_PERSONS  MAXIMUM_PERSONS
  443.       $location_game['minimum_persons'] = 0;
  444.       $location_game['maximum_persons'] = 0;
  445.       if (isset($rel_location_game_values[0]->location_id) && !empty($rel_location_game_values[0]->location_id) && isset($rel_location_game_values[0]->game_id)) {
  446.         $rel_location_game_obj = $wpdb->get_row(
  447.             "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  448.               FROM wp_rel_locations_games
  449.              WHERE location_id = ".$rel_location_game_values[0]->location_id."
  450.                AND game_id     = ".$rel_location_game_values[0]->game_id."
  451.                AND (min_number IS NOT NULL AND min_number > 0)
  452.                AND (max_number IS NOT NULL AND max_number > 0)
  453.            "
  454.         );
  455.         $location_game['minimum_persons'] = (int)$rel_location_game_obj->min_aantal_pers;
  456.         $location_game['maximum_persons'] = (int)$rel_location_game_obj->max_aantal_pers;
  457.       }
  458.  
  459.       //---------------------------------------------------------------------------------------
  460.       // GET THE NUMBER OF LOCATIONS FOR THIS GAME IN THIS TOWN
  461.       $params = array(
  462.           'select'    => 'DISTINCT t.location_code',
  463.  
  464.           'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  465.                           INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  466.  
  467.           'where'     => " game_code = '".$game_code."'
  468.                           AND ( town.town_code = '".$town_code."'  OR t.location_code = 'eigen-locatie' )
  469.                           ",
  470.           'orderby'     => 't.location_order',
  471.           'limit'     => 0
  472.       );
  473.       $locations_pod = pods( 'locations', $params );
  474.  
  475.       // $game_town_locations_values_totalrows = $locations_pod->total();
  476.       // if ( $game_town_locations_values_totalrows > 0 ) {
  477.       //     $bLocation = true;
  478.       //     $game_town_locations_values = $locations_pod->rows;
  479.       // }
  480.  
  481.  
  482.  
  483.       /*--------------------------------------------------------------
  484.       // NUMBER OF LOCATIONS IN THIS TOWN
  485.       //-------------------------------------------------------------- */
  486.       if ( /*   $location_values['location_code'] != 'eigen-locatie' && */  $firsttime ):
  487.         $firsttime=false;
  488.  
  489.         $in = 'in';
  490.         if ( $location_values['location_code'] == 'eigen-locatie') $in = '';
  491.  
  492.         if ($game_town_locations_values_totalrows == 1) {
  493.           print '<div style="font-weight:700; margin:0;padding:0; color: #3e0a82;">Er is 1 resultaat voor dit spel '.$in.' '.$town_row->town_name.' of directe omgeving:<br /></div>';
  494.         } elseif ($game_town_locations_values_totalrows > 1) {
  495.           print '<div style="font-weight:700; margin:0;padding:0; color: #3e0a82;">Er zijn '.$game_town_locations_values_totalrows.' resultaten voor dit spel '.$in.' '.$town_row->town_name.' en directe omgeving:<br /></div>';
  496.         } ?>
  497.  
  498.       <?php
  499.       endif; ?>
  500.  
  501.  
  502.     <div class="greybox">
  503.       <div class="widget">
  504.         <div class="widget-title">
  505.             <h3 class="nomargin"><?php print $game_values['game_name']; ?> in <?php print $location_values['location_name']; ?> <?php if ($location_values['location_code'] != 'eigen-locatie') print '('.$game_town_location_values->town_name.')'; ?></h3>
  506.         </div>
  507.         <div class="widget-content">
  508.             <?php if ($bLocation_games):
  509.                 print format_element('rel_location_game_values', $rel_location_game_values);
  510.             endif; ?>
  511.         </div>
  512.       </div>
  513.  
  514.       <div class="greybox2">
  515.  
  516.         <div class="sixcol column">
  517.  
  518.             <div style="padding-top: 0px; height: 22px; background-image: url('<?php print home_url(); ?>/wp-content/uploads/2016/03/knife_fork.png'); background-repeat: no-repeat; padding-left:60px;">
  519.                 <a href="#whereis" class="gotowhereis"><?php print strip_tags($location_values['location_name']); ?></a><br />
  520.             </div>
  521.             <br />
  522.             <?php
  523.             /*--------------------------------------------------------------
  524.             // MINIMUM_PERSONS  MAXIMUM_PERSONS
  525.             //-------------------------------------------------------------- */ ?>
  526.             <div style="padding-top: 10px; height: 36px; background-image: url('<?php print home_url(); ?>/wp-content/uploads/2016/03/people.png'); background-repeat: no-repeat; padding-left:60px;">
  527.                 Van <?php print $location_game['minimum_persons']; ?> tot <?php print $location_game['maximum_persons']; ?> personen
  528.             </div>
  529.  
  530.             <?php
  531.             /*--------------------------------------------------------------
  532.             // GAME_DURATION
  533.             //-------------------------------------------------------------- */ ?>
  534.             <div style="padding-top: 10px; height: 36px; background-image: url('<?php print home_url(); ?>/wp-content/uploads/2016/03/time.png'); background-repeat: no-repeat; padding-left:60px;">
  535.                 <?php print $game_values['game_duration']; ?>
  536.             </div>
  537.             <?php
  538.  
  539.  
  540.             /*--------------------------------------------------------------
  541.             // GAME_DOCUMENTS
  542.             //-------------------------------------------------------------- */ ?>
  543.             <div style="margin-top: 10px; height: 36px; background-image: url('<?php print home_url(); ?>/wp-content/uploads/2016/04/download.png'); background-repeat: no-repeat; padding-left:60px;">
  544.                 <?php print format_element('game_documents', $game_values['game_documents']); ?>
  545.             </div>
  546.  
  547.           <p>&nbsp;</p>
  548.  
  549.         </div>
  550.  
  551.         <div class="sixcol column last">
  552.             <?php
  553.             print format_element('includes_text', $rel_location_game_values[0]->includes_text);
  554.  
  555.             if ($game_values['game_code'] == 'onfortuinlijke-bankier') { ?>
  556.                 <div style="width:96%; text-align:center;">
  557.                     <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
  558.                 </div><?php
  559.             }
  560.  
  561.             if ($game_values['game_code'] == 'into-the-box') { ?>
  562.                 <div style="width:96%; text-align:center;">
  563.                     <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel kluis + boekjes</a>
  564.                 </div><?php
  565.             }
  566.             if ($game_values['game_code'] == 'koudgemaakte-kok') { ?>
  567.                 <div style="width:96%; text-align:center;">
  568.                     <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
  569.                 </div><?php
  570.             }
  571.  
  572.             if ($game_values['game_code'] == 'mysterie-spel-back-to-school') { ?>
  573.                 <div style="width:96%; text-align:center;">
  574.                     <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
  575.                 </div><?php
  576.             } ?>
  577.  
  578.         </div>
  579.         <div class="clear"></div>
  580.  
  581.       </div>
  582.  
  583.       <div style="text-align: center; padding-top:20px;">
  584.         <a class="gametownloc_anchor" href="<?php print home_url(); ?>/<?php print $game_code; ?>/<?php print $game_town_location_values->town_code; ?>/<?php print $location_code ; ?>">
  585.           <div class="element-button small primary handheldonly" style="font-size: 1.2em; background-color:#b12418!important; ">Vraag beschikbaarheid op</div>  
  586.         </a>
  587.  
  588.     </div>
  589.     </div>
  590.  
  591.     <p>&nbsp;</p>
  592.  
  593.       <?php
  594.       }
  595.  
  596.       $temp_content = ob_get_contents();
  597.       ob_end_clean();
  598.  
  599.       if ( defined( 'DOING_AJAX' ) ) {
  600.           // echo the content as a json array
  601.           echo json_encode(
  602.               array(
  603.                   'result' => true,
  604.                   'data' => $temp_content
  605.               )
  606.           );
  607.       }
  608.       wp_die();
  609.     }
  610.  
  611.  
  612.   }
  613.  
  614.  
  615.  
  616.  
  617.  
  618.  
  619.  
  620.  
  621.  
  622.  
  623.   //=====================================================================================
  624.   public function mutatie_aantal() {
  625.  
  626.     // TOONT FORM, PAGINA  tpl_page_mutatie_aantal.php
  627.     // AFHANDELEN FORM SUBMIT:
  628.     //    -->  email naar dinerspel met link naar aanvraag edit page OP NL SITE
  629.     //    -->  email naar locatie (maar zonder een eventuele opm die klant kan hebben ingevoerd)
  630.  
  631.     global $wpdb;
  632.  
  633.     $site_country = SITECOUNTRY;   // must be defined in the wp-config
  634.  
  635.     $errors = array();
  636.  
  637.     if ($_POST) {
  638.  
  639.       if (!$_POST['access_code'] || empty($_POST['access_code']) ) {
  640.           $errors[] = 'Ontbrekende toegangscode';
  641.           exit();
  642.       } else {
  643.           $access_code = $_POST['access_code'];
  644.       }
  645.  
  646.       // Get activation record for the user
  647.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  648.                 WHERE code_klant_mutatie = '".esc_sql($_POST['access_code'])."'";
  649.       $recordset = $wpdb->get_results( $sqlQuery );
  650.  
  651.  
  652.       // hieronder is niet nodig, want deze functie moet gewoon draaien op de site waar de aanvraag bij hoort
  653.       // if ( empty($recordset) ) {
  654.       //   // FOR TESTING: try again in BE database
  655.       //   $remote_wpdb = new WPDB( DB_USER2, DB_PASSWORD2, DB_NAME2, DB_HOST2);
  656.       //   $recordset = $remote_wpdb->get_results( $sqlQuery );
  657.       //   $site_country = 'BE';
  658.       //   $homeurl = HOMEURL_BE;
  659.       // } else {
  660.       //   $site_country = 'NL';
  661.       //   $homeurl = HOMEURL_NL;
  662.       // }
  663.  
  664.  
  665.       if ( empty($recordset) ) {
  666.           $errors[] = 'Deze pagina is niet (meer) beschikbaar';
  667.           exit();
  668.       } else {
  669.           $row_aanvraag   = $recordset[0];
  670.           $oud_aantal_pers =  $row_aanvraag->aantal_pers;
  671.       }
  672.  
  673.       if (empty($_POST['aantal_pers'] )) {
  674.           $errors[] = 'Graag het aantal personen invullen';
  675.       } elseif (!is_numeric($_POST['aantal_pers'])) {
  676.           $errors[] = 'Graag uitsluitend een aantal invullen bij Aantal personen';
  677.  
  678.       } else {
  679.  
  680.         //---------------------------------------------------------------------------------------
  681.         // CHECK THE NUMBER OF PERSONS ENTERED
  682.  
  683.         // calculate the min aantal based on location, game and aantal_pers from aanvraag
  684.  
  685.         $sql = "SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'";
  686.         // if ($site_country == 'BE') {
  687.         //   $row = $remote_wpdb->get_row($sql);
  688.         // } else {
  689.         $row = $wpdb->get_row($sql);
  690.         // }
  691.         $location_id            = $row->location_id;
  692.         $zelfstandige_locatie   = $row->zelfstandige_locatie;
  693.  
  694.         if (!empty($location_id)) {
  695.           $sql = "SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'";
  696.           // if ($site_country == 'BE') {
  697.           //   $row = $remote_wpdb->get_col($sql);
  698.           // } else {
  699.           $row = $wpdb->get_col($sql);
  700.           //}
  701.           $game_id = $row[0];
  702.  
  703.           $sql = "
  704.            SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  705.              FROM wp_rel_locations_games
  706.             WHERE location_id = ".$location_id."
  707.               AND game_id     = ".$game_id."
  708.               AND (min_number IS NOT NULL AND min_number > 0)
  709.               AND (max_number IS NOT NULL AND max_number > 0)
  710.          ";
  711.           // if ($site_country == 'BE') {
  712.           //   $rel_location_game_obj = $remote_wpdb->get_row($sql);
  713.           // } else {
  714.           $rel_location_game_obj = $wpdb->get_row($sql);
  715.           // }
  716.  
  717.           $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
  718.           $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
  719.         }
  720.  
  721.         //---------------------------------------------------------------------------------------
  722.         // Use 85% of the estimated number of people that the client had specified, unless this would be less than the min. number for the game/location
  723.         $voorlopig_min_aantal = round($row_aanvraag->aantal_pers - (15 * ($row_aanvraag->aantal_pers/100) ), 0, PHP_ROUND_HALF_DOWN);
  724.         if ($voorlopig_min_aantal < $min_aantal_pers) $voorlopig_min_aantal = $min_aantal_pers;
  725.  
  726.  
  727.         //---------------------------------------------------------------------------------------
  728.         // check if there already is a fixed number in the aanvraag, if there is, we will use that
  729.         if (isset($row_aanvraag->minimum_aantal_bevestigd) && (int)$row_aanvraag->minimum_aantal_bevestigd > 0) {
  730.           $voorlopig_min_aantal = (int)$row_aanvraag->minimum_aantal_bevestigd;
  731.         }
  732.  
  733.         //---------------------------------------------------------------------------------------
  734.         // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
  735.         if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
  736.             $voorlopig_min_aantal = $row_aanvraag->min_aantal_override;
  737.         }
  738.  
  739.         $post_aantal_pers = (int)$_POST['aantal_pers'];
  740.  
  741.         if ( $post_aantal_pers < $voorlopig_min_aantal || $post_aantal_pers > $max_aantal_pers ) {
  742.             $errors[] = 'Het minimum aantal deelnemers is: '.$voorlopig_min_aantal.'. Het maximum aantal is: '.$max_aantal_pers;
  743.         }
  744.  
  745.       }
  746.  
  747.  
  748.       //---------------------------------------------------------------------------------------
  749.  
  750.       if (count($errors) ==  0)  {
  751.  
  752.         // CREATE VARIABLES FROM ROW_AANVRAAG
  753.         foreach ($row_aanvraag as $key => $value) {
  754.             $arrSkip = array('submit');
  755.             if (!in_array($key, $arrSkip)) {
  756.               $$key = $value;
  757.             }
  758.         }
  759.  
  760.         // create certain allowed variables from the $_POST as well
  761.         $arr_allowed_fields = array('access_code', 'game_code', 'town_code', 'location_code', 'voorkeursdatum', 'bedrijfsnaam', 'telefoon',
  762.              'adres', 'postcode', 'woonplaats', 'country_code', 'btw_nummer', 'opmerking_klant_res', 'aantal_pers', 'eigen_locatie_data');
  763.         foreach ($_POST as $key => $value) {
  764.             $arrSkip = array('submit');
  765.             if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  766.               $$key = stripslashes(htmlspecialchars($value, ENT_QUOTES,'UTF-8'));
  767.             }
  768.         }
  769.  
  770.         $sqlQuery = "UPDATE wp_pods_aanvragen
  771.                        SET aantal_pers = '".esc_sql($post_aantal_pers)."',
  772.                            opmerking_klant_mutatie_aantal = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_klant_mutatie_aantal'], ENT_QUOTES,'UTF-8')))."',
  773.                            modified = NOW()
  774.                      WHERE
  775.                            code_klant_mutatie = '".esc_sql($access_code)."'";
  776.        
  777.         // if ($site_country == 'BE') {
  778.         //   $updres = $remote_wpdb->get_results( $sqlQuery );
  779.         // } else {
  780.           $updres = $wpdb->get_results( $sqlQuery );;
  781.         //}
  782.  
  783.  
  784.         $aantal_pers = $post_aantal_pers;
  785.  
  786.         $geslacht = $row_aanvraag->geslacht;
  787.         $aanhef = ($geslacht == 'Vrouw') ? 'Mevrouw' : 'De heer';
  788.         $voornaam = ucfirst($voornaam);
  789.         $achternaam = ucwords($name);
  790.         //$geslacht = strtolower($geslacht);
  791.         $game_name = ucwords(str_replace('-', ' ', $game_code) );
  792.         $town_name = ucwords(str_replace('-', ' ', $town_code) );
  793.         $location_name = ucwords(str_replace('-', ' ', $location_code) );
  794.         $website = 'Dinerspel.nl';
  795.         $opmerking_klant = stripslashes($opmerking_klant);
  796.         $opmerking_klant_res = stripslashes($opmerking_klant_res);
  797.         $opmerking_klant_mutatie_aantal = stripslashes($_POST['opmerking_klant_mutatie_aantal']);
  798.  
  799.         $link_to_edit_aanvraag = '<a href="'.HOMEURL_NL.'/ds-wijzig-aanvraag-reservering/?site_country='.$site_country.'&id='.$row_aanvraag->id.'">Open deze aanvraag (front-end)</a>';
  800.  
  801.  
  802.         if ($location_code == 'eigen-locatie') {
  803.             $gameurltext = $game_name.' in eigen locatie';
  804.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  805.         } else {
  806.             $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  807.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  808.         }
  809.  
  810.         //----------------------------------
  811.         // stuur email naar DINERSPEL
  812.         //---------------------------
  813.         $game_name = ucwords(str_replace('-', ' ', $game_code) );
  814.         $town_name = ucwords(str_replace('-', ' ', $town_code) );
  815.         $location_name = ucwords(str_replace('-', ' ', $location_code) );
  816.         $website = 'Dinerspel.nl';
  817.  
  818.         ob_start();
  819.         include_once(dirname(__FILE__) . "/templates/tpl_email_mutatie_aantal_naar_dinerspel.php");
  820.         $temp_content = ob_get_contents();
  821.         ob_end_clean();
  822.         $message = $temp_content;
  823.  
  824.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  825.  
  826.         $headers        = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
  827.         get_header();
  828.  
  829.         $multiple_recipients = array(
  830.             MAILTO_RESERVERINGEN,
  831.         );
  832.  
  833.  
  834.         $mailresult = wp_mail($multiple_recipients, ' Mutatie aantal via '.$website, $message, $headers);
  835.  
  836.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  837.  
  838.         //----------------------------------
  839.         // show  thank you page
  840.         //----------------------------------
  841.         ob_start();
  842.         include_once(dirname(__FILE__) . "/templates/tpl_page_mutatie_aantal_thankyou.php");
  843.         $temp_content = ob_get_contents();
  844.         ob_end_clean();
  845.         $message = $temp_content;
  846.  
  847.         include dirname(__FILE__) . '/templates/tpl_info.php';
  848.         exit;
  849.  
  850.       }
  851.  
  852.  
  853.  
  854.     } else {
  855.  
  856.       // NO POST, GET THE aanvraag from the code in the url
  857.  
  858.       // get access code
  859.       $redirecturl = $_SERVER['REDIRECT_URL'];
  860.       $arrUrl = explode('/', $redirecturl);
  861.       $key = array_search('mutatie-aantal', $arrUrl);
  862.       $access_code = $arrUrl[($key+1)];
  863.  
  864.       if (!$access_code || empty($access_code) ) exit();
  865.  
  866.       // Get activation record for the user
  867.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  868.                 WHERE code_klant_mutatie = '".esc_sql($access_code)."'";
  869.       $recordset = $wpdb->get_results( $sqlQuery );
  870.       if ( empty($recordset) ) {
  871.         $message = 'Deze pagina is niet (meer) beschikbaar';
  872.         include dirname(__FILE__) . '/templates/tpl_response.php';
  873.         exit;
  874.       }
  875.  
  876.       $row_aanvraag   = $recordset[0];
  877.  
  878.  
  879.  
  880.  
  881.       // check if date still allows mutation
  882.       $reserveringsdatum = $row_aanvraag->reserveringsdatum;
  883.       if (!empty($reserveringsdatum) && $reserveringsdatum <> '0000-00-00') {
  884.  
  885.         $today  = date_create(); // Current time and date
  886.         $today = date_format($today, 'Y-m-d 00:00:00');
  887.         $today = date_create($today);
  888.  
  889.         $reserveringsdatum = date_create($reserveringsdatum);
  890.         $reserveringsdatum = date_format($reserveringsdatum, 'Y-m-d 00:00:00');
  891.         $reserveringsdatum = date_create($reserveringsdatum);
  892.  
  893.         $diff   = date_diff( $today, $reserveringsdatum );
  894.         if ( $diff->days < 3 ) {
  895.           $message = '
  896.            <strong>U kunt het aantal deelnemers tot maximaal twee dagen voor de speldatum online wijzigen.<br>
  897.            Daarna is de pagina niet meer beschikbaar.<br>
  898.            <br>
  899.            U kunt het aantal deelnemers op dit moment helaas niet meer verminderen.<br>
  900.            Vermeerderen kan eventueel wel. Stuurt u dan even een mailtje naar <a href="mailto:[email protected]">[email protected]</a>
  901.            </strong>';
  902.           include dirname(__FILE__) . '/templates/tpl_response.php';
  903.           exit;
  904.         }
  905.  
  906.       } else {
  907.         // something must be really wrong, if there is no game date...
  908.           $message = '
  909.            <h3>U kunt het aantal deelnemers tot maximaal twee dagen voor de speldatum online wijzigen.<br>
  910.            Daarna is de pagina niet meer beschikbaar.<br>
  911.            <br>
  912.            U kunt het aantal deelnemers op dit moment helaas niet meer verminderen.<br>
  913.            Vermeerderen kan eventueel wel. Stuurt u dan even een mailtje naar <a href="mailto:[email protected]">[email protected]</a>';
  914.           include dirname(__FILE__) . '/templates/tpl_response.php';
  915.           exit;
  916.       }
  917.  
  918.  
  919.  
  920.       // get extra data
  921.  
  922.       $sql = "SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'";
  923.       // if ($site_country == 'BE') {
  924.       //   $row = $remote_wpdb->get_row($sql);
  925.       // } else {
  926.         $row = $wpdb->get_row($sql);
  927.       // }
  928.       $location_id            = $row->location_id;
  929.       $zelfstandige_locatie   = $row->zelfstandige_locatie;
  930.  
  931.       if (!empty($location_id)) {
  932.         $sql = "SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'";
  933.         // if ($site_country == 'BE') {
  934.         //   $row = $remote_wpdb->get_col($sql);
  935.         // } else {
  936.           $row = $wpdb->get_col($sql);
  937.         // }
  938.         $game_id = $row[0];
  939.  
  940.         $sql = "
  941.          SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  942.            FROM wp_rel_locations_games
  943.           WHERE location_id = ".$location_id."
  944.             AND game_id     = ".$game_id."
  945.             AND (min_number IS NOT NULL AND min_number > 0)
  946.             AND (max_number IS NOT NULL AND max_number > 0)
  947.        ";
  948.         // if ($site_country == 'BE') {
  949.         //   $rel_location_game_obj = $remote_wpdb->get_row($sql);
  950.         // } else {
  951.           $rel_location_game_obj = $wpdb->get_row($sql);
  952.         // }
  953.  
  954.         $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
  955.         $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
  956.       }
  957.  
  958.       //---------------------------------------------------------------------------------------
  959.       // Use 85% of the estimated number of people that the client had specified, unless this would be less than the min. number for the game/location
  960.       $voorlopig_min_aantal = round($row_aanvraag->aantal_pers - (15 * ($row_aanvraag->aantal_pers/100) ), 0, PHP_ROUND_HALF_DOWN);
  961.       if ($voorlopig_min_aantal < $min_aantal_pers) $voorlopig_min_aantal = $min_aantal_pers;
  962.  
  963.       //---------------------------------------------------------------------------------------
  964.       // check if there already is is a fixed number in the aanvraag, if there is, we will use that
  965.       if (isset($row_aanvraag->minimum_aantal_bevestigd) && (int)$row_aanvraag->minimum_aantal_bevestigd > 0) {
  966.         $voorlopig_min_aantal = (int)$row_aanvraag->minimum_aantal_bevestigd;
  967.       }
  968.  
  969.       //---------------------------------------------------------------------------------------
  970.       // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
  971.       if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
  972.           $voorlopig_min_aantal = $row_aanvraag->min_aantal_override;
  973.       }
  974.  
  975.  
  976.     }
  977.  
  978.     // below is for both first page load as well as page after $_POST
  979.  
  980.     foreach ($row_aanvraag as $key => $value) {
  981.         $arrSkip = array('submit');
  982.         if (!in_array($key, $arrSkip)) {
  983.               $$key = $value;
  984.         }
  985.     }
  986.  
  987.     $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  988.     $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  989.  
  990.     $geslacht = $row_aanvraag->geslacht;
  991.     $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  992.  
  993.     $voornaam = ucfirst($voornaam);
  994.     $achternaam = ucwords(stripslashes($name));
  995.     $game_name = ucwords(str_replace('-', ' ', $game_code) );
  996.     $town_name = ucwords(str_replace('-', ' ', stripslashes($town_code)) );
  997.     $location_name = ucwords(str_replace('-', ' ', stripslashes($location_code)) );
  998.     $website = 'Dinerspel.nl';
  999.  
  1000.     $form_action = home_url().'/mutatie-aantal';
  1001.  
  1002.     $opmerking_klant = stripslashes($opmerking_klant);
  1003.     $opmerking_klant_res = stripslashes($opmerking_klant_res);  
  1004.     if ($location_code == 'eigen-locatie') {
  1005.  
  1006.         $gameurltext = $game_name.' in eigen locatie';
  1007.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  1008.  
  1009.     } else {
  1010.  
  1011.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  1012.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  1013.  
  1014.     }
  1015.  
  1016.  
  1017.     //----------------------------------
  1018.     // show form to start reservation
  1019.     //----------------------------------
  1020.  
  1021.     ob_start();
  1022.         include_once(dirname(__FILE__) . "/templates/tpl_page_mutatie_aantal.php");
  1023.     $temp_content = ob_get_contents();
  1024.     ob_end_clean();
  1025.     $message = $temp_content;
  1026.  
  1027.     include dirname(__FILE__) . '/templates/tpl_response.php';
  1028.     exit;
  1029.  
  1030.   }
  1031.  
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038.  
  1039.  
  1040.  
  1041.   //================================================
  1042.   public function front_controller() {
  1043.   //================================================
  1044.       global $wpdb, $wp_query, $current_user;
  1045.       global $tag_values, $game_values, $town_values, $location_values, $town_locations_games_values, $rel_location_game_values;
  1046.       global $array_tags, $array_games, $array_towns, $array_locations;
  1047.       global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
  1048.       global $parsetype;
  1049.  
  1050.  
  1051.       global $arr_grote_steden;
  1052.       $arr_grote_steden = array('antwerpen', 'brussel', 'amsterdam', 'den-haag', 'rotterdam' );
  1053.  
  1054.       // skip the rest of this check if it concerns a page that has no 'category_name' in the query_vars
  1055.       if (strpos($wp_query->query_vars['category_name'], '%E2') !== false ||
  1056.           strpos($wp_query->query_vars['category_name'], '%9DA') !== false ) {
  1057.           return;
  1058.       }
  1059.  
  1060.  
  1061.       if (is_page() && is_front_page()) {
  1062.           // we only do the non standard pages here
  1063.           return;
  1064.       }
  1065.  
  1066.  
  1067.  
  1068.       // INTERCEPT URLS FOR WHICH WE HAVE A SPECIFIC ACTION FUNCTION SET UP IN THIS CONTROLLER
  1069.       switch ($wp_query->query_vars['category_name'] ) {
  1070.  
  1071.           case 'beschikbaarheid_in_stappen':
  1072.               do_action( 'custom_beschikbaarheid_in_stappen' );
  1073.               return;
  1074.               break;
  1075.  
  1076.           case 'beschikbaarheidsaanvraag':
  1077.               do_action( 'custom_beschikbaarheidsaanvraag' );
  1078.               return;
  1079.               break;
  1080.  
  1081.           case 'reageer-op-beschikbaarheidsaanvraag':
  1082.               do_action( 'custom_ophalen_beschikbaarheid_bij_locatie' );
  1083.               return;
  1084.               break;
  1085.  
  1086.           case 'verwerk-beschikbaarheid-van-locatie':
  1087.               do_action( 'custom_verwerken_beschikbaarheid_van_locatie' );
  1088.               return;
  1089.               break;
  1090.  
  1091.           case 'beschikbaarheidsaanvraag-afhandelen':
  1092.               do_action( 'custom_afhandelen_beschikbaarheidsaanvraag' );
  1093.               return;
  1094.               break;
  1095.  
  1096.           case 'verwerken-afhandeling-beschikbaarheidsaanvraag':
  1097.               do_action( 'custom_verwerken_afhandeling_beschikbaarheidsaanvraag' );
  1098.               return;
  1099.               break;
  1100.  
  1101.           case 'reserveren':
  1102.               do_action( 'custom_reserveren' );
  1103.               return;
  1104.               break;
  1105.  
  1106.           case 'mutatie-aantal':
  1107.               do_action( 'custom_mutatie_aantal' );
  1108.               return;
  1109.               break;
  1110.  
  1111.           case 'sitemap':
  1112.               do_action( 'custom_sitemap_page' );
  1113.               return;
  1114.               break;
  1115.  
  1116.           case 'contactform':
  1117.               do_action( 'custom_contactform' );
  1118.               return;
  1119.               break;
  1120. /*
  1121.           case 'contacted':
  1122.               do_action( 'custom_contacted' );
  1123.               return;
  1124.               break;*/
  1125.  
  1126.           case 'searchtown':
  1127.  
  1128.               // first check if the town is in our towns table
  1129.               $searchtown_row = $wpdb->get_row( "SELECT town_code FROM wp_pods_towns  WHERE LOWER(town_name) = '".esc_attr(trim(strtolower($_GET['s'])))."'");
  1130.               if ($searchtown_row) {
  1131.                   wp_redirect( home_url().'/'.$searchtown_row->town_code);
  1132.                   exit();
  1133.  
  1134.               } else {
  1135.               // if no:
  1136.                   wp_redirect( home_url().'/plaatsen');
  1137.                   exit();
  1138.               }
  1139.               break;
  1140.  
  1141.           case 'recensies':
  1142.               do_action( 'custom_recensies' );
  1143.               return;
  1144.               break;
  1145.  
  1146.  
  1147.       }
  1148.  
  1149.  
  1150.       //----------------------------------------------------------------------------------
  1151.       // SET UP ARRAYS FOR ALL TAGS, ALL GAMES_CODES, ALL TOWN_CODES, AND ALL LOCATION_CODES
  1152.  
  1153.       $rows = $wpdb->get_results( "SELECT tag_name, tag_text FROM wp_pods_tags " );
  1154.       foreach ( $rows as $row ):
  1155.           $array_tags[] = $row->tag_name;
  1156.           $array_tags_texts[] = $row->tag_text;
  1157.       endforeach;
  1158.  
  1159.       $rows = $wpdb->get_results( "SELECT game_code, game_name FROM wp_pods_games ORDER BY game_order  " );
  1160.       foreach ( $rows as $row ):
  1161.           $array_games[] = $row->game_code;
  1162.           $array_game_names[] = $row->game_name;
  1163.       endforeach;
  1164.  
  1165.       $rows = $wpdb->get_results( "SELECT town_code, town_name FROM wp_pods_towns ORDER BY town_name" );
  1166.       foreach ( $rows as $row ):
  1167.           $array_towns[] = $row->town_code;
  1168.           $array_town_names[] = $row->town_name;
  1169.       endforeach;
  1170.  
  1171.       $rows = $wpdb->get_results( "SELECT location_code, location_name FROM wp_pods_locations " );
  1172.       foreach ( $rows as $row ) :
  1173.           $array_locations[] = $row->location_code;
  1174.           $array_location_names[] = $row->location_name;
  1175.       endforeach;
  1176.       //----------------------------------------------------------------------------------
  1177.  
  1178.  
  1179.       //-----------------------------------------------------------------------------------------
  1180.       $parsetype = '0';
  1181.       // // FIRST CHECK IF $CONTROL_ACTION IS A COMBINATION OF TAG/GAMES_CODE/TOWN_CODE/LOCATION_CODE
  1182.       // if (isset($control_action)) {
  1183.       //     $arr_action = explode('/', $control_action);
  1184.       //     $parsetype_array = $this->_check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations);
  1185.       //     $parsetype = $parsetype_array[0];
  1186.       //     $part_1 = $parsetype_array[1];
  1187.       //     $part_2 = $parsetype_array[2];
  1188.       //     $part_3 = $parsetype_array[3];
  1189.       //     $part_4 = $parsetype_array[4];
  1190.       // }
  1191.  
  1192.       // CHECK $WP_QUERY->QUERY_VARS['CATEGORY_NAME'] && $WP_QUERY->QUERY_VARS['NAME']
  1193.       // THEY PERHAPS CONTAIN A COMBINATION OF  TAG/GAMES_CODE/TOWN_CODE/ AND/OR LOCATION_CODE)
  1194.       if ($parsetype == '0') {
  1195.  
  1196.           if (!empty($wp_query->query_vars['category_name'])) {
  1197.               // this gets everything but the last element, if it is of the form game/town/location
  1198.             $arr_action = explode('/', $wp_query->query_vars['category_name']);
  1199.               // the location will have ended up in the name field:
  1200.  
  1201.               if (strpos($wp_query->query_vars['name'], '%E2') === false &&
  1202.                   strpos($wp_query->query_vars['name'], '%9DA') === false ) {
  1203.                 $arr_action[] = $wp_query->query_vars['name'] ;
  1204.               }
  1205.  
  1206.           } elseif (!empty($wp_query->query_vars['name'])) {
  1207.               if (strpos($wp_query->query_vars['name'], '%E2') === false &&
  1208.                   strpos($wp_query->query_vars['name'], '%9DA') === false ) {
  1209.                 $arr_action = explode('/', $wp_query->query_vars['name']);
  1210.             }
  1211.           }
  1212.  
  1213.  
  1214.           if (isset($arr_action) && count($arr_action) > 0) {
  1215.             switch ($arr_action[0]) {
  1216.  
  1217.                   case 'plaatsen':
  1218.                     $parsetype = 15;
  1219.                     break;
  1220.  
  1221.                   case 'restaurants':
  1222.                       $parsetype = 19;
  1223.                       break;
  1224.  
  1225.                   case 'eigen-locatie':
  1226.                       $parsetype = 17;
  1227.                       break;
  1228.  
  1229.                 default:
  1230.                     $parsetype_array = $this->_check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations);
  1231.                     //--------------------------------
  1232.                     $parsetype = $parsetype_array[0];
  1233.                     //--------------------------------
  1234.                     $part_1 = $parsetype_array[1];
  1235.                     $part_2 = $parsetype_array[2];
  1236.                     $part_3 = $parsetype_array[3];
  1237.                     $part_4 = $parsetype_array[4];
  1238.                     break;
  1239.             }
  1240.         }
  1241.       }
  1242.  
  1243.  
  1244.       if ($parsetype != '0') {
  1245.           /*
  1246.           $parsetype = '1';  // TREFWOORD/SPEL/PLAATS/LOCATIE
  1247.           $parsetype = '2';  // TREFWOORD/SPEL/LOCATIE
  1248.           $parsetype = '3';  // TREFWOORD/SPEL/PLAATS
  1249.  
  1250.           $parsetype = '4';  // TREFWOORD/LOCATIE
  1251.           $parsetype = '5';  // TREFWOORD/PLAATS
  1252.           $parsetype = '6';  // TREFWOORD/SPEL
  1253.  
  1254.           $parsetype = '11'; // SPEL/TREFWOORD
  1255.           $parsetype = '12'; // SPEL/PLAATS
  1256.           $parsetype = '18'; // SPEL/EIGEN-LOCATIE
  1257.  
  1258.           $parsetype = '13'; // SPEL/PLAATS/LOCATIE
  1259.  
  1260.           $parsetype = '9';  // PLAATS/SPEL
  1261.           $parsetype = '14'; // PLAATS/LOCATIE
  1262.  
  1263.           $parsetype = '8';  // PLAATS
  1264.           $parsetype = '17'; // EIGEN-LOCATIE
  1265.           $parsetype = '10'; // SPEL
  1266.           $parsetype = '7';  // TREFWOORD
  1267.  
  1268.           $parsetype = '15';  // ALLE PLAATSEN
  1269.           $parsetype = '16';  // ALLE SPELLEN
  1270.           $parsetype = '19';  // ALLE LOCATiES
  1271.  
  1272.           */
  1273.           $bTag = $bGame = $bTown = $bLocation = $bLocation_games = $bTown_games = false;
  1274.  
  1275.  
  1276.           //--------------------------------------------------------------------------------------------------------
  1277.           // COLLECT TAG INFO
  1278.           //--------------------------------------------------------------------------------------------------------
  1279.           if ( in_array($parsetype, array('1', '2', '3', '4', '5', '6', '7', '11'))) {  // TREFWOORD
  1280.  
  1281.               // TAGS
  1282.               switch ($parsetype) {
  1283.                   case '1':
  1284.                   case '2':
  1285.                   case '3':
  1286.                   case '4':
  1287.                   case '5':
  1288.                   case '6':
  1289.                   case '7':
  1290.                       $tag_name = $part_1;
  1291.                       break;
  1292.                   case '11':
  1293.                       $tag_name = $part_2;
  1294.                       break;
  1295.               }
  1296.  
  1297.               $params = array(
  1298.                   'select'    => ' t.* ',
  1299.                   'where' => 'tag_name = "'.$tag_name.'"',
  1300.                   'limit'     => 0
  1301.               );
  1302.               $tags_pod = pods( 'tags', $params );
  1303.               if ( $tags_pod->total() > 0 ) {
  1304.                   $tag_fields = array();
  1305.                   while ($tags_pod->fetch() ) {
  1306.                       $row = $tags_pod->row();
  1307.                       // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  1308.                       foreach($tags_pod->fields as $podsfield) {
  1309.                           $fieldname = $podsfield['name'];
  1310.                           $tag_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $tags_pod->display($fieldname) ;
  1311.                       }
  1312.                   }
  1313.               }
  1314.               $bTag = true;
  1315.           }
  1316.  
  1317.           //--------------------------------------------------------------------------------------------------------
  1318.           // COLLECT GAME INFO
  1319.           //--------------------------------------------------------------------------------------------------------
  1320.           if (in_array($parsetype, array('1', '2', '3', '6', '9', '10', '11', '12', '13', '18'))){   // GAME
  1321.  
  1322.               $bGame = true;
  1323.  
  1324.               switch ($parsetype) {
  1325.                   case '1':
  1326.                   case '2':
  1327.                   case '3':
  1328.                   case '6':
  1329.                   case '9':
  1330.                       $game_code = $part_2;
  1331.                       break;
  1332.                   case '10':
  1333.                   case '11':
  1334.                   case '12':
  1335.                   case '13':
  1336.                   case '18':
  1337.                       $game_code = $part_1;
  1338.                       break;
  1339.               }
  1340.               $params = array(
  1341.                   //'select'    => ' t.game_code ',
  1342.                   'select'    => ' t.* ',
  1343.                   'where' => 'game_code = "'.$game_code.'"',
  1344.                   'limit'     => 0
  1345.               );
  1346.               $games_pod = pods( 'games', $params );
  1347.               if ( $games_pod->total() > 0 ) {
  1348.                   $game_values = array();
  1349.                   while ($games_pod->fetch() ) {
  1350.                       $row = $games_pod->row();
  1351.                       // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  1352.                       foreach($games_pod->fields as $podsfield) {
  1353.                           $fieldname = $podsfield['name'];
  1354.                           $game_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
  1355.                       }
  1356.                   }
  1357.               }
  1358.               $game_name = $game_values['game_name'];
  1359.  
  1360.           }
  1361.  
  1362.  
  1363.           //--------------------------------------------------------------------------------------------------------
  1364.           // COLLECT TOWN INFO
  1365.           //--------------------------------------------------------------------------------------------------------
  1366.           if (in_array($parsetype, array('1', '3', '5', '8','9','12','13', '14'))) {  // PLAATS
  1367.               // TOWNS
  1368.               switch ($parsetype) {
  1369.                   case '1':
  1370.                   case '3':
  1371.                       $town_code = $part_3;
  1372.                       break;
  1373.                   case '5':
  1374.                   case '12':
  1375.                   case '13':
  1376.                       $town_code = $part_2;
  1377.                       break;
  1378.                   case '8':
  1379.                   case '9':
  1380.                   case '14':
  1381.                       $town_code = $part_1;
  1382.                       break;
  1383.               }
  1384.               $params = array(
  1385.                   //'select'    => ' t.town_code ',
  1386.                   'select'    => ' t.* ',
  1387.                   'where' => 'town_code = "'.$town_code.'"',
  1388.                   'limit'     => 0
  1389.               );
  1390.               $towns_pod = pods( 'towns', $params );
  1391.               if ( $towns_pod->total() > 0 ) {
  1392.                   $town_values = array();
  1393.                   while ($towns_pod->fetch() ) {
  1394.                       $row = $towns_pod->row();
  1395.                       // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  1396.                       foreach($towns_pod->fields as $podsfield) {
  1397.                           $fieldname = $podsfield['name'];
  1398.                           $town_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $towns_pod->display($fieldname) ;
  1399.                       }
  1400.                   }
  1401.               }
  1402.               $town_name = $town_values['town_name'];
  1403.               $bTown = true;
  1404.           }
  1405.  
  1406.  
  1407.  
  1408.           //--------------------------------------------------------------------------------------------------------
  1409.           // COLLECT LOCATION INFO
  1410.           //--------------------------------------------------------------------------------------------------------
  1411.           if (in_array($parsetype, array('1', '2', '4', '13', '14', '18'))) {  // LOCATIE
  1412.  
  1413.               switch ($parsetype) {
  1414.                   case '1':
  1415.                       $location_code = $part_4;
  1416.                       break;
  1417.                   case '2':
  1418.                   case '13':
  1419.                       $location_code = $part_3;
  1420.                       break;
  1421.                   case '4':
  1422.                   case '14':
  1423.                   case '18':
  1424.                       $location_code = $part_2;
  1425.                       break;
  1426.               }
  1427.  
  1428.               $params = array(
  1429.                   //'select'    => ' t.location_code ',
  1430.                   'select'    => ' t.* ',
  1431.                   'where' => 'location_code = "'.$location_code.'"',
  1432.                   'limit'     => 0
  1433.               );
  1434.               $locations_pod = pods( 'locations', $params );
  1435.               if ( $locations_pod->total() > 0 ) {
  1436.                   $location_values = array();
  1437.                   while ($locations_pod->fetch() ) {
  1438.                       $row = $locations_pod->row();
  1439.                       // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  1440.                       foreach($locations_pod->fields as $podsfield) {
  1441.                           $fieldname = $podsfield['name'];
  1442.                           $location_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $locations_pod->display($fieldname) ;
  1443.                       }
  1444.                   }
  1445.               }
  1446.               $location_name = $location_values['location_name'];
  1447.  
  1448.               $bLocation = true;
  1449.           }
  1450.  
  1451.  
  1452.  
  1453.  
  1454.           //--------------------------------------------------------------------------------------------------------
  1455.           // IF GAME ONLY PAGE, COLLECT CITIES + LOCATIONS (INCL MAP COORDINATES) WHERE THE GAME CAN BE PLAYED
  1456.           //--------------------------------------------------------------------------------------------------------
  1457.           if (in_array($parsetype, array('10'))) {  // SPEL
  1458.  
  1459.               // GAME INFO HAS BEEN COLLECTED     --> $game_code & $game_name are available
  1460.               $params = array(
  1461.                   'select'    => '
  1462.                                  t.id as location_id,
  1463.                                  t.location_name,
  1464.                                  t.location_code,
  1465.                                  #t.location_coordinates,
  1466.  
  1467.                                  town.id as town_id,
  1468.                                  town.town_name as town_name,
  1469.                                  town.town_code as town_code,
  1470.                                  town.town_coordinates as town_coordinates,
  1471.  
  1472.                                  location_images.guid as location_image
  1473.                                 ',
  1474.  
  1475.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  1476.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1477.  
  1478.                   'where'     => " game_code = '".$game_code."' ",
  1479.                   'orderby'     => 'town.town_name',
  1480.                   'limit'     => 0
  1481.               );
  1482.       //                                     #AND location_code <> 'eigen-locatie'
  1483.  
  1484.               $locations_pod = pods( 'locations', $params );
  1485.               if ( $locations_pod->total() > 0 ) {
  1486.                 $bLocation = true;
  1487.                 $game_towns_locations_values = $locations_pod->rows;
  1488.  
  1489.  
  1490.                 // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
  1491.                 $data["geolocations"] = '[';
  1492.                 $comma='';
  1493.                 $prev_town_code = '';
  1494.                 $game_towns = array();
  1495.                 while ($locations_pod->fetch() ) {
  1496.                   $row = $locations_pod->row();
  1497.  
  1498.                   if ($row['town_code'] != $prev_town_code) {
  1499.                       // FIRST ROW FOR THIS TOWN
  1500.                       $prev_town_code = $row['town_code'];
  1501.                       $game_towns[] = $row;
  1502.                   }
  1503.  
  1504.                   if (isset($row['town_coordinates']) && !empty($row['town_coordinates']) ) {
  1505.  
  1506.                     $json_geolocation   = $row['town_coordinates'];
  1507.                     $obj_googlemapcoords   = json_decode($json_geolocation);
  1508.  
  1509.                     if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  1510.                       /*
  1511.                       $location_name      = $row['location_name'];
  1512.                       $location_code      = $row['location_code'];
  1513.                       $address_1          = $row['address_1'];
  1514.                       $postal_code        = $row['postal_code'];
  1515.                       */
  1516.                       $town          = $row['town_name'];
  1517.                       $town_code     = $row['town_code'];
  1518.                       /*
  1519.                       $info               = $location_name;
  1520.                       $info              .= (!empty($address_1)) ? ' - '.$address_1 : '';
  1521.                       $info              .= (!empty($postal_code)) ? ' - '.$postal_code : '';
  1522.                       $info              .= (!empty($town)) ? ' - '.$town : '';
  1523.                       $url                =  $game_code.'/'.$town_code.'/'.$location_code;
  1524.                       */
  1525.                       $info               = (!empty($town)) ? $town : '';
  1526.                       $url                =  home_url().'/'.$game_code.'/'.$town_code;
  1527.  
  1528.                       $data["geolocations"] .= $comma . "
  1529.                      [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  1530.                       $comma=", ";
  1531.                     }
  1532.                   }
  1533.  
  1534.               }
  1535.               $data["geolocations"] .= '
  1536. ]';
  1537.  
  1538.               // add 'Locaties in Nederland' and 'Eigen locatie'  as the first elements (for all games but the culi game)
  1539.  
  1540.               if ($game_code != 'food-en-fun-culi-spel') {
  1541.                 $eigen_locatie = array(
  1542.                   'town_code' => 'eigen-locatie',
  1543.                   'town_name' => 'Eigen locatie',
  1544.                   'town_coordinates' => ''
  1545.               );
  1546.               array_unshift($game_towns, $eigen_locatie);
  1547.             }
  1548.  
  1549.           }
  1550.         }
  1551.  
  1552.  
  1553.  
  1554.         // TAG+TOWN
  1555.  
  1556.         //--------------------------------------------------------------------------------------------------------
  1557.         // IF TAG+TOWN PAGE, WE NEED TO SHOW ALL OTHER TAGS FOR THIS TOWN
  1558.         // SO COLLECT LOCATIONS IN THE TOWN, DETERMINE WHICH GAMES CAN BE PLAYED, AND WHAT TAGS THESE GAMES HAVE
  1559.         //--------------------------------------------------------------------------------------------------------
  1560.         if (in_array($parsetype, array('5'))) {  // TREFWOORD + PLAATS
  1561.  
  1562.           $tag_town_other_town_tags_values = array();
  1563.           $tag_town_games_images_values_arr = array();
  1564.           $tag_town_games_images_values = '';
  1565.  
  1566.           // GET ALL GAME CODES and their tags
  1567.           $params = array(
  1568.             'select'    => ' t.* ',
  1569.             'limit'     => 0
  1570.           );
  1571.           $games_pod = pods( 'games', $params );
  1572.           if ( $games_pod->total() > 0 ) {
  1573.  
  1574.             while ($games_pod->fetch() ) {
  1575.  
  1576.               // add game images to the tag_town_games_images_values_arr array, so the slider will have something to show besides town images
  1577.               $tag_town_game_images_str = $games_pod->display( 'game_images' );
  1578.               $tag_town_game_images_arr = explode(' ', $tag_town_game_images_str);
  1579.               foreach($tag_town_game_images_arr as $tag_town_game_image) {
  1580.                   if (!in_array($tag_town_game_image, $tag_town_games_images_values_arr)) {
  1581.                       array_push($tag_town_games_images_values_arr, $tag_town_game_image);
  1582.                   }
  1583.               }
  1584.  
  1585.               $tmp_game_code = $games_pod->display( 'game_code' );   //print "<br />------------------------game_code: ".$game_code;
  1586.               $tmp_str_tags = $games_pod->display( 'game_tags' );  // --> string!  'familiefeesten'  of 'familiefeesten en henparties'
  1587.               $tmp_game_tags = $games_pod->field( 'game_tags' ); // --> array:
  1588.  
  1589.               // get all locations where this game is played IN THIS town
  1590.               $params = array(
  1591.                   'select'    => ' t.location_code, town.town_code ',
  1592.  
  1593.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  1594.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1595.  
  1596.                   'where'     => "game_code = '".$tmp_game_code."'
  1597.                                  AND town.town_code = '".$town_code."'
  1598.                                  AND location_code <> 'eigen-locatie' ",
  1599.                 'limit'     => 0
  1600.               );
  1601.  
  1602.               $locations_pod = pods( 'locations', $params );
  1603.               if ( $locations_pod->total() > 0 ) {
  1604.  
  1605.                 // OK this game is played in $town_code, so we can add it's tags to the 'tag_town_other_town_tags_values' array
  1606.                 // unless it is THE tag for this page, or it is already in the array
  1607.                 foreach ($tmp_game_tags as $tmp_game_tag) {
  1608.                   $tmp_tag_name = $tmp_game_tag['tag_name'];
  1609.                   if ($tmp_tag_name != $tag_name  && !in_array($tmp_tag_name, $tag_town_other_town_tags_values)) {
  1610.                       array_push($tag_town_other_town_tags_values, $tmp_tag_name);
  1611.                   }
  1612.                 }
  1613.  
  1614.               }
  1615.             }
  1616.  
  1617.             $tag_town_games_images_values = implode(' ', $tag_town_games_images_values_arr);
  1618.           }
  1619.  
  1620.         }
  1621.  
  1622.         // GAME+TOWN
  1623.  
  1624.         //--------------------------------------------------------------------------------------------------------
  1625.         // IF GAME+TOWN PAGE, COLLECT LOCATIONS IN THE TOWN WHERE THE GAME CAN BE PLAYED
  1626.         // PLUS OTHER GAMES THAT CAN BE PLAYED IN THE TOWN
  1627.         //--------------------------------------------------------------------------------------------------------
  1628.         if (in_array($parsetype, array('12', '9'))) {  // SPEL + PLAATS
  1629.  
  1630.               // GAME INFO HAS BEEN COLLECTED     --> $game_code & $game_name are available
  1631.               // TOWN INFO HAS BEEN COLLECTED     --> $town_code & $town_name are available
  1632.  
  1633.               // GET THE LOCATIONS FOR THIS GAME IN THIS TOWN
  1634.               $params = array(
  1635.                   'select'    => 'DISTINCT t.id as location_id,
  1636.                                  t.location_name,
  1637.                                  t.address_1,
  1638.                                  t.postal_code,
  1639.                                  t.location_code,
  1640.                                  t.location_name,
  1641.                                  t.location_text,
  1642.                                  t.location_coordinates,
  1643.  
  1644.                                  town.id as town_id,
  1645.                                  town.town_name as town_name,
  1646.                                  town.town_code as town_code,
  1647.  
  1648.                                  location_images.guid as location_image',
  1649.  
  1650.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  1651.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1652.  
  1653.                   'where'     => " game_code = '".$game_code."'
  1654.                                   AND town.town_code = '".$town_code."'",
  1655.                   'orderby'     => 't.location_name',
  1656.                   'limit'     => 0
  1657.               );
  1658.  
  1659.               //       AND location_code <> 'eigen-locatie'
  1660.  
  1661.               $game_town_locations_pod = pods( 'locations', $params );
  1662.  
  1663.               $game_town_locations_values_totalrows = $game_town_locations_pod->total();
  1664.               if ( $game_town_locations_values_totalrows > 0 ) {
  1665.                   $bLocation = true;
  1666.  
  1667.                   // COLLECT  VALUES FOR ALL LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
  1668.                   $game_town_locations_values = $game_town_locations_pod->rows;
  1669.  
  1670.                   // GET GOOGLE COORDS FOR THE LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
  1671.                   $game_town["geolocations"] = '[';
  1672.                   while ($game_town_locations_pod->fetch() ) {
  1673.                       $row = $game_town_locations_pod->row();
  1674.                       if (isset($row['location_coordinates']) ) {
  1675.                           // ADD THIS LOCATION COORDS TO THE GOOGLE MAP ARRAY
  1676.                           $json_geolocation   = $row['location_coordinates'];
  1677.                           $obj_googlemapcoords   = json_decode($json_geolocation);
  1678.  
  1679.                           if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  1680.  
  1681.                               $goo_location_name      = $row['location_name'];
  1682.                               $goo_location_code      = $row['location_code'];
  1683.                               $goo_address_1          = $row['address_1'];
  1684.                               $goo_postal_code        = $row['postal_code'];
  1685.                               $info               = $goo_location_name;
  1686.                               $info              .= (!empty($goo_address_1)) ? ' - '.$goo_address_1 : '';
  1687.                               $info              .= (!empty($goo_postal_code)) ? ' - '.$goo_postal_code : '';
  1688.                               $info              .= (!empty($town_name)) ? ' - '.$town_name : '';
  1689.                               $info              .= $text_games_per_location;
  1690.                               // $url             =  $game_code.'/'.$town_code.'/'.$goo_location_code;
  1691.                               $url                =  home_url().'/'.$town_code.'/'.$goo_location_code;
  1692.                               $game_town["geolocations"] .= $comma . "
  1693.                              [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  1694.                               $comma=", ";
  1695.                           }
  1696.                       }
  1697.  
  1698.                   }
  1699.                   if ($game_town["geolocations"] == '[')  {
  1700.                       $game_town["geolocations"] = '';
  1701.                   } else {
  1702.                       $game_town["geolocations"] .= '
  1703. ]';
  1704.                 }
  1705.  
  1706.               }
  1707.  
  1708.           }
  1709.  
  1710.  
  1711.  
  1712.           // GAME+OWN-LOCATION
  1713.  
  1714.           //--------------------------------------------------------------------------------------------------------
  1715.           // IF GAME+OWN-LOCATION PAGE, COLLECT PRICES AND OTHER GAME/LOCATION RELATION INFO
  1716.           //--------------------------------------------------------------------------------------------------------
  1717.           if (in_array($parsetype, array('18'))) {  // SPEL + PLAATS + EIGEN LOCATIE
  1718.  
  1719.               // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
  1720.               $params = array(
  1721.                   'select'    => 'wp_rel_locations_games.*
  1722.                                 ',
  1723.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (
  1724.                                      t.id = wp_rel_locations_games.location_id
  1725.                                      AND (min_number IS NOT NULL AND min_number > 0)
  1726.                                      AND (max_number IS NOT NULL AND max_number > 0)
  1727.                                   )
  1728.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1729.  
  1730.                   'where'     => " game_code = '".$game_code."'
  1731.                                   AND location_code = 'eigen-locatie' ",
  1732.                   'orderby'     => 'min_number',
  1733.                   'limit'     => 0
  1734.               );
  1735.               $rel_location_game_pod = pods( 'locations', $params );
  1736.               if ( $rel_location_game_pod->total() > 0 ) {
  1737.                   $rel_location_game_values = $rel_location_game_pod->rows;
  1738.                   $bLocation_games = true;
  1739.               }
  1740.  
  1741.               //---------------------------------------------------------------------------------------
  1742.               // GET ALL OTHER GAMES PLAYED IN EIGEN LOCATIE
  1743.               $game_own_location_other_games_values = array();
  1744.  
  1745.  
  1746.               $params = array(
  1747.                   'select'    => 't.id as location_id,
  1748.                                  t.location_name,
  1749.                                  t.location_code,
  1750.                                  t.diner_price,
  1751.                                  t.diner_price_foodfun
  1752.                                 ',
  1753.                   'where'     => " location_code = 'eigen-locatie' ",
  1754.                   'limit'     => 0
  1755.               );
  1756.  
  1757.               $tmp_locations_pod = pods( 'locations', $params );
  1758.               //die($tmp_locations_pod->sql);
  1759.               $tmp_locations_pod_total = $tmp_locations_pod->total();
  1760.               if ( $tmp_locations_pod_total > 0 ):
  1761.                   $i=0;
  1762.                   while ($tmp_locations_pod->fetch() ):
  1763.                       $row = $tmp_locations_pod->row();
  1764.                       $game_own_location_other_games_values[$i]['location_code'] = $row['location_code'];
  1765.                       $game_own_location_other_games_values[$i]['location_name'] = $row['location_name'];
  1766.  
  1767.                       $game_params = array(
  1768.                               'select'    => 't.id as game_id,
  1769.                                              t.game_code,
  1770.                                              t.game_name,
  1771.                                              t.game_short_descr,
  1772.                                              wp_rel_locations_games.* ',
  1773.                               'join'      => 'INNER JOIN wp_rel_locations_games ON
  1774.                                                  (wp_rel_locations_games.game_id = t.id
  1775.                                                      AND (min_number IS NOT NULL AND min_number > 0)
  1776.                                                      AND (max_number IS NOT NULL AND max_number > 0)
  1777.                                                   )',
  1778.                               'where'     => 'game_code <> "'.$game_code.'"
  1779.                                              AND wp_rel_locations_games.location_id = "'.$row['location_id'].'"
  1780.                                              AND wp_rel_locations_games.game_id = t.id
  1781.                                              AND wp_rel_locations_games.activated = 1
  1782.                                             ',
  1783.                               'orderby'   => 'game_order, game_code, min_number',
  1784.                               'limit'     => 0
  1785.                       );
  1786.                       $tmp_games_pod = pods( 'games', $game_params );
  1787.                       //die($tmp_games_pod->sql);
  1788.  
  1789.                       // collect data for the games played at this location
  1790.                       if ( $tmp_games_pod->total() > 0 ):
  1791.                           $lowest_price = 999.99;
  1792.                           $prev_game_code = '';
  1793.                           while ($tmp_games_pod->fetch() ):
  1794.                               $row2 = $tmp_games_pod->row();
  1795.                               $tmp_games_game_code = $row2['game_code'];
  1796.  
  1797.  
  1798.                       // (NOG) NIET GEIMPLEMENTEERD, MISSCHIEN NIET ECHT NODIG
  1799.                               // // game has an indicator, 'own_location', if it is zero, skip 'eigen-locatie's
  1800.                               // if ($row2['own_location'] == '0'  &&  $row['location_code'] == 'eigen-locatie') continue;
  1801.  
  1802.                               // collect images for this game
  1803.                               $img_game_params = array(
  1804.                                   'select'    => ' t.id ',
  1805.                                   'where' => 'game_code = "'.$tmp_games_game_code.'"',
  1806.                                   'limit'     => 0
  1807.                               );
  1808.                               $img_games_pod = pods( 'games', $img_game_params );
  1809.                               if ( $img_games_pod->total() > 0 ) {
  1810.                                   $thumbnail = pods_image_url(
  1811.                                         $img_games_pod->field( 'game_images', TRUE ),
  1812.                                         'thumbnail-rectangle',
  1813.                                         0,
  1814.                                         true
  1815.                                   );
  1816.                                   $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] =  $thumbnail;
  1817.                               }
  1818.  
  1819.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_code']         = $row2['game_code'];
  1820.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_name']         = $row2['game_name'];
  1821.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr']  = $row2['game_short_descr'];
  1822.  
  1823.                               // get the lowset total price for each game, plus the lowest number of people
  1824.                               if ($tmp_games_game_code == 'food-en-fun-culi-spel') {
  1825.                                   $diner_price = $row['diner_price_foodfun'];
  1826.                               } else {
  1827.                                   $diner_price = $row['diner_price'];
  1828.                               }
  1829.                               if ($tmp_games_game_code == $prev_game_code) {
  1830.                                   // override if lower than the previous game-prices occurrence
  1831.                                   if ($row2['game_price'] < $lowest_price) {
  1832.                                       $lowest_price = $row2['game_price'];
  1833.                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  1834.                                   }
  1835.                                   if ($row2['min_number'] < $low_min_number) {
  1836.                                       $low_min_number = $row2['min_number'];
  1837.                                   }
  1838.                                   if ($row2['max_number'] > $high_max_number) {
  1839.                                       $high_max_number = $row2['max_number'];
  1840.                                   }
  1841.                               } else {
  1842.                                   // the first game-prices occurrence
  1843.                                   $lowest_price        = $row2['game_price'];
  1844.                                   $lowest_total_price  =  (float)$diner_price + (float)$lowest_price;
  1845.                                   $low_min_number   = $row2['min_number'];
  1846.                                   $high_max_number  = $row2['max_number'];
  1847.  
  1848.                                   $prev_game_code      = $row2['game_code'];
  1849.                               }
  1850.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
  1851.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
  1852.                               $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
  1853.  
  1854.                           endwhile;
  1855.                       endif;
  1856.                       $i++;
  1857.                   endwhile;
  1858.               endif;
  1859.           }
  1860.  
  1861.  
  1862.  
  1863.           // GAME+TOWN+LOCATION
  1864.  
  1865.           //--------------------------------------------------------------------------------------------------------
  1866.           // IF GAME+TOWN+LOCATION PAGE, COLLECT PRICES AND OTHER GAME/LOCATION RELATION INFO
  1867.           //--------------------------------------------------------------------------------------------------------
  1868.           if (in_array($parsetype, array('13'))) {  // SPEL + PLAATS + LOCATIE
  1869.  
  1870.               // GAME INFO HAS BEEN COLLECTED     --> $game_code & $game_name are available
  1871.               // TOWN INFO HAS BEEN COLLECTED     --> $town_code & $town_name are available
  1872.               // LOCATION INFO HAS BEEN COLLECTED --> $location_code & $location_name are available
  1873.  
  1874.               // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
  1875.               $params = array(
  1876.                   'select'    => 'wp_rel_locations_games.*
  1877.                                 ',
  1878.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (
  1879.                                      t.id = wp_rel_locations_games.location_id
  1880.                                      AND (min_number IS NOT NULL AND min_number > 0)
  1881.                                      AND (max_number IS NOT NULL AND max_number > 0)
  1882.                                   )
  1883.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1884.  
  1885.                   'where'     => " game_code = '".$game_code."'
  1886.                                   AND location_code = '".$location_code."'",
  1887.                   'orderby'     => 'min_number',
  1888.                   'limit'     => 0
  1889.               );
  1890.               $rel_location_game_pod = pods( 'locations', $params );
  1891.               if ( $rel_location_game_pod->total() > 0 ) {
  1892.                   $rel_location_game_values = $rel_location_game_pod->rows;
  1893.                   $bLocation_games = true;
  1894.               }
  1895.  
  1896.               // MINIMUM_PERSONS  MAXIMUM_PERSONS
  1897.               $location_game['minimum_persons'] = 0;
  1898.               $location_game['maximum_persons'] = 0;
  1899.               if (isset($rel_location_game_values[0]->location_id) && !empty($rel_location_game_values[0]->location_id) && isset($rel_location_game_values[0]->game_id)) {
  1900.                 $rel_location_game_obj = $wpdb->get_row(
  1901.                     "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  1902.                       FROM wp_rel_locations_games
  1903.                      WHERE location_id = ".$rel_location_game_values[0]->location_id."
  1904.                        AND game_id     = ".$rel_location_game_values[0]->game_id."
  1905.                        AND (min_number IS NOT NULL AND min_number > 0)
  1906.                        AND (max_number IS NOT NULL AND max_number > 0)
  1907.                    "
  1908.                 );
  1909.                 $location_game['minimum_persons'] = (int)$rel_location_game_obj->min_aantal_pers;
  1910.                 $location_game['maximum_persons'] = (int)$rel_location_game_obj->max_aantal_pers;
  1911.               }
  1912.  
  1913.               //---------------------------------------------------------------------------------------
  1914.               // GET ALL OTHER LOCATIONS IN THIS TOWN
  1915.               $params = array(
  1916.                   'select'    => ' t.location_code,  t.location_name ',
  1917.                   'where'     => " town.town_code = '".$town_code."'
  1918.                                 ",
  1919.                   'orderby'     => 't.location_name',
  1920.                   'limit'     => 0
  1921.               );
  1922.               $game_town_location_other_locations_in_town_pod = pods( 'locations', $params );
  1923.               $game_town_location_other_locations_in_town_totalrows = $game_town_location_other_locations_in_town_pod->total();
  1924.               if ($game_town_location_other_locations_in_town_totalrows > 0 ) {
  1925.                   $game_town_location_other_locations_in_town_values = $game_town_location_other_locations_in_town_pod->rows;
  1926.               }
  1927.  
  1928.  
  1929.  
  1930.               //---------------------------------------------------------------------------------------
  1931.               // GET THE NUMBER OF LOCATIONS FOR THIS GAME IN THIS TOWN
  1932.               $params = array(
  1933.                   'select'    => 'DISTINCT t.location_code',
  1934.  
  1935.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  1936.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  1937.  
  1938.                   'where'     => " game_code = '".$game_code."'
  1939.                                   AND town.town_code = '".$town_code."'
  1940.                                   AND location_code <> 'eigen-locatie'
  1941.                                   ",
  1942.                   'orderby'     => 't.location_name',
  1943.                   'limit'     => 0
  1944.               );
  1945.               $locations_pod = pods( 'locations', $params );
  1946.  
  1947.               $game_town_locations_values_totalrows = $locations_pod->total();
  1948.               if ( $game_town_locations_values_totalrows > 0 ) {
  1949.                   $bLocation = true;
  1950.                   $game_town_locations_values = $locations_pod->rows;
  1951.               }
  1952.  
  1953.               //---------------------------------------------------------------------------------------
  1954.               // GET ALL OTHER GAMES PLAYED IN THIS LOCATION
  1955.               $game_town_location_other_games_values = array();
  1956.  
  1957.  
  1958.               $params = array(
  1959.                   'select'    => 't.id as location_id,
  1960.                                  t.location_name,
  1961.                                  t.location_code,
  1962.                                  t.diner_price,
  1963.                                  t.diner_price_foodfun
  1964.                                 ',
  1965.                   'where'     => " (town.town_code = '".$town_code."'
  1966.                                   AND location_code = '".$location_code."')
  1967.                                   OR
  1968.                                   (location_code = 'eigen-locatie')
  1969.                                   ",
  1970.                   'orderby'     => 'location_name',
  1971.                   'limit'     => 0
  1972.               );
  1973.  
  1974.               $tmp_locations_pod = pods( 'locations', $params );
  1975.               $tmp_locations_pod_total = $tmp_locations_pod->total();
  1976.               if ( $tmp_locations_pod_total > 0 ):
  1977.                   $i=0;
  1978.                   while ($tmp_locations_pod->fetch() ):
  1979.                       $row = $tmp_locations_pod->row();
  1980.                       $game_town_location_other_games_values[$i]['location_code'] = $row['location_code'];
  1981.                       $game_town_location_other_games_values[$i]['location_name'] = $row['location_name'];
  1982.  
  1983.                       $game_params = array(
  1984.                               'select'    => 't.id as game_id,
  1985.                                              t.game_code,
  1986.                                              t.game_name,
  1987.                                              t.game_short_descr,
  1988.                                              wp_rel_locations_games.* ',
  1989.                               'join'      => 'INNER JOIN wp_rel_locations_games ON (
  1990.                                                  wp_rel_locations_games.game_id = t.id
  1991.                                                  AND (min_number IS NOT NULL AND min_number > 0)
  1992.                                                  AND (max_number IS NOT NULL AND max_number > 0)
  1993.                                              )',
  1994.                               'where'     => 'game_code <> "'.$game_code.'"
  1995.                                              AND wp_rel_locations_games.location_id = "'.$row['location_id'].'"
  1996.                                              AND wp_rel_locations_games.game_id = t.id
  1997.                                              AND wp_rel_locations_games.activated = 1
  1998.                                             ',
  1999.                               'orderby'   => 'game_order, game_code, min_number',
  2000.                               'limit'     => 0
  2001.                       );
  2002.                       $tmp_games_pod = pods( 'games', $game_params );
  2003.  
  2004.                       // collect data for the games played at this location
  2005.                       if ( $tmp_games_pod->total() > 0 ):
  2006.                           $lowest_price = 999.99;
  2007.                           $prev_game_code = '';
  2008.                           while ($tmp_games_pod->fetch() ):
  2009.                               $row2 = $tmp_games_pod->row();
  2010.                               $tmp_games_game_code = $row2['game_code'];
  2011.  
  2012.  
  2013.  
  2014.  
  2015.                               // game has an indicator, 'own_location', if it is zero, skip 'eigen-locatie's
  2016.                               if ($row2['own_location'] == '0'  &&  $row['location_code'] == 'eigen-locatie') continue;
  2017.  
  2018.  
  2019.  
  2020.  
  2021.                               // collect images for this game
  2022.                               $img_game_params = array(
  2023.                                   'select'    => ' t.id ',
  2024.                                   'where' => 'game_code = "'.$tmp_games_game_code.'"',
  2025.                                   'limit'     => 0
  2026.                               );
  2027.                               $img_games_pod = pods( 'games', $img_game_params );                              
  2028.                               if ( $img_games_pod->total() > 0 ) {
  2029.                                   $thumbnail = pods_image_url(
  2030.                                         $img_games_pod->field( 'game_images', TRUE ),
  2031.                                         'thumbnail-rectangle',
  2032.                                         0,
  2033.                                         false
  2034.                                     );
  2035.                                   $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] =  $thumbnail;
  2036.                               }
  2037.                              
  2038.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_code']         = $row2['game_code'];
  2039.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_name']         = $row2['game_name'];
  2040.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr']  = $row2['game_short_descr'];
  2041.  
  2042.                               // get the lowset total price for each game, plus the lowest number of people
  2043.                               if ($tmp_games_game_code == 'food-en-fun-culi-spel') {
  2044.                                   $diner_price = $row['diner_price_foodfun'];
  2045.                               } else {
  2046.                                   $diner_price = $row['diner_price'];
  2047.                               }
  2048.                               if ($tmp_games_game_code == $prev_game_code) {
  2049.                                   // override if lower than the previous game-prices occurrence
  2050.                                   if ($row2['game_price'] < $lowest_price) {
  2051.                                       $lowest_price = $row2['game_price'];
  2052.                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2053.                                   }
  2054.                                   if ($row2['min_number'] < $low_min_number) {
  2055.                                       $low_min_number = $row2['min_number'];
  2056.                                   }
  2057.                                   if ($row2['max_number'] > $high_max_number) {
  2058.                                       $high_max_number = $row2['max_number'];
  2059.                                   }
  2060.                               } else {
  2061.                                   // the first game-prices occurrence
  2062.                                   $lowest_price       = $row2['game_price'];
  2063.                                   $lowest_total_price  =  (float)$diner_price + (float)$lowest_price;
  2064.                                   $low_min_number   = $row2['min_number'];
  2065.                                   $high_max_number  = $row2['max_number'];
  2066.  
  2067.                                   $prev_game_code     = $row2['game_code'];
  2068.                               }
  2069.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
  2070.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
  2071.                               $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
  2072.  
  2073.                           endwhile;
  2074.                       endif;
  2075.                       $i++;
  2076.                   endwhile;
  2077.               endif;
  2078.  
  2079.           }
  2080.  
  2081.  
  2082.  
  2083.  
  2084.  
  2085.  
  2086.  
  2087.           // TOWN+LOCATION
  2088.  
  2089.           if (in_array($parsetype, array('14'))):  // PLAATS + LOCATIE
  2090.               // TOWN INFO HAS BEEN COLLECTED     --> $town_code & $town_name are available
  2091.               // LOCATION INFO HAS BEEN COLLECTED --> $location_code & $location_name are available
  2092.  
  2093.               // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
  2094.               $params = array(
  2095.                   'select'    => 'wp_rel_locations_games.*
  2096.                                 ',
  2097.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  2098.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  2099.  
  2100.                   'where'     => "location_code = '".$location_code."'",
  2101.                   'limit'     => 0
  2102.               );
  2103.               $rel_location_game_pod = pods( 'locations', $params );
  2104.               if ( $rel_location_game_pod->total() > 0 ) {
  2105.                   $rel_location_game_values = $rel_location_game_pod->rows;
  2106.                   $bLocation_games = true;
  2107.               }
  2108.  
  2109.  
  2110.               //---------------------------------------------------------------------------------------
  2111.               // GET ALL GAMES PLAYED IN THIS LOCATION
  2112.  
  2113.               $town_location_slider_images = '';
  2114.               $town_location_games_values = array();
  2115.               $params = array(
  2116.                   'select'    => 't.id as location_id,
  2117.                                  t.location_name,
  2118.                                  t.location_code,
  2119.                                  t.location_coordinates,
  2120.                                  t.diner_price,
  2121.                                  t.diner_price_foodfun
  2122.                                 ',
  2123.                   'where'     => " (town.town_code = '".$town_code."'
  2124.                                   AND location_code = '".$location_code."')
  2125.                                   ",
  2126.                   'orderby'     => 'location_name',
  2127.                   'limit'     => 0
  2128.               );
  2129.  
  2130.               $tmp_locations_pod = pods( 'locations', $params );
  2131.               $tmp_locations_pod_total = $tmp_locations_pod->total();
  2132.               if ( $tmp_locations_pod_total > 0 ):
  2133.                   $i=0;
  2134.                   while ($tmp_locations_pod->fetch() ):
  2135.                       $row = $tmp_locations_pod->row();
  2136.                       $town_location_games_values[$i]['location_code'] = $row['location_code'];
  2137.                       $town_location_games_values[$i]['location_name'] = $row['location_name'];
  2138.  
  2139.                       // for the big top slider:
  2140.  
  2141.                       if (!empty($location_values['location_images']) && strpos($town_location_slider_images, $location_values['location_images']) === false ) {
  2142.                           $town_location_slider_images .= $location_values['location_images'].' ';
  2143.                       }
  2144.  
  2145.                       $game_params = array(
  2146.                               'select'    => 't.id as game_id,
  2147.                                              t.game_code,
  2148.                                              t.game_name,
  2149.                                              t.game_short_descr,
  2150.                                              wp_rel_locations_games.* ',
  2151.                               'join'      => 'INNER JOIN wp_rel_locations_games ON (
  2152.                                                  wp_rel_locations_games.game_id = t.id
  2153.                                                  AND (min_number IS NOT NULL AND min_number > 0)
  2154.                                                  AND (max_number IS NOT NULL AND max_number > 0)
  2155.                                              )',
  2156.                               'where'     => 'wp_rel_locations_games.location_id = "'.$row['location_id'].'"
  2157.                                              AND wp_rel_locations_games.game_id = t.id
  2158.                                              AND wp_rel_locations_games.activated = 1
  2159.                                             ',
  2160.                               'orderby'   => 'game_order, game_code, min_number',
  2161.                               'limit'     => 0
  2162.                       );
  2163.                       $tmp_games_pod = pods( 'games', $game_params );
  2164.  
  2165.                       // collect data for the games played at this location
  2166.                       if ( $tmp_games_pod->total() > 0 ):
  2167.                           $lowest_price = 999.99;
  2168.                           $prev_game_code = '';
  2169.                           while ($tmp_games_pod->fetch() ):
  2170.                               $row2 = $tmp_games_pod->row();
  2171.                               $tmp_games_game_code = $row2['game_code'];
  2172.  
  2173.                               // collect images for this game
  2174.                               $img_game_params = array(
  2175.                                   'select'    => ' t.id ',
  2176.                                   'where' => 'game_code = "'.$tmp_games_game_code.'"',
  2177.                                   'limit'     => 0
  2178.                               );
  2179.                               $img_games_pod = pods( 'games', $img_game_params );
  2180.                               if ( $img_games_pod->total() > 0 ) {
  2181.                                   $thumbnail = pods_image_url(
  2182.                                         $img_games_pod->field( 'game_images', TRUE ),
  2183.                                         'thumbnail-rectangle',
  2184.                                         0,
  2185.                                         true
  2186.                                   );
  2187.                                   $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] =  $thumbnail;
  2188.  
  2189.                                   // for the big top slider:
  2190. //                                  if (!empty($game_images_str) && strpos($game_images_str, $town_location_slider_images) === false ) {
  2191.                                   if (!empty($game_images_str) && strpos($town_location_slider_images, $game_images_str) === false ) {
  2192.                                       $town_location_slider_images .= $game_images_str.' ';
  2193.                                 }
  2194.  
  2195.                               }
  2196.  
  2197.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_code']         = $row2['game_code'];
  2198.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_name']         = $row2['game_name'];
  2199.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr']  = $row2['game_short_descr'];
  2200.  
  2201.                               // get the lowset total price for each game, plus the lowest number of people
  2202.                               if ($row2['game_code'] == 'food-en-fun-culi-spel') {
  2203.                                   $diner_price = $row['diner_price_foodfun'];
  2204.                               } else {
  2205.                                   $diner_price = $row['diner_price'];
  2206.                               }
  2207.                               if ($tmp_games_game_code == $prev_game_code) {
  2208.                                   // override if lower than the previous game-prices occurrence
  2209.                                   if ($row2['game_price'] < $lowest_price) {
  2210.                                       $lowest_price = $row2['game_price'];
  2211.                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2212.                                   }
  2213.                                   if ($row2['min_number'] < $low_min_number) {
  2214.                                       $low_min_number = $row2['min_number'];
  2215.                                   }
  2216.                                   if ($row2['max_number'] > $high_max_number) {
  2217.                                       $high_max_number = $row2['max_number'];
  2218.                                   }
  2219.                               } else {
  2220.                                   // the first game-prices occurrence
  2221.                                   $lowest_price        = $row2['game_price'];
  2222.                                   $lowest_total_price  =  (float)$diner_price + (float)$lowest_price;
  2223.                                   $low_min_number   = $row2['min_number'];
  2224.                                   $high_max_number  = $row2['max_number'];
  2225.  
  2226.                                   $prev_game_code      = $row2['game_code'];
  2227.                               }
  2228.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
  2229.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
  2230.                               $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
  2231.  
  2232.                           endwhile;
  2233.                       endif;
  2234.                       $i++;
  2235.                   endwhile;
  2236.               endif;
  2237.  
  2238.  
  2239.  
  2240.           endif; // if (in_array($parsetype, array('14'))) {  // PLAATS + LOCATIE
  2241.  
  2242.  
  2243.  
  2244.  
  2245.  
  2246.  
  2247.           //---------------------------------------------------------------------------------------------------
  2248.           // IF TAG ONLY PAGE,
  2249.           //---------------------------------------------------------------------------------------------------
  2250.  
  2251.  
  2252.  
  2253.           //     info tekst over trefwoord
  2254.           // ->      select tag_text from tags where tag_name = %s
  2255.  
  2256.           //     namen van de spellen (met link en wellicht korte intro tekst met placeholders)
  2257.           // ->      select game_name, short_tag_descr FROM games
  2258.           //         fetch rows, while
  2259.           //             if '$tag_name' in array game_tags
  2260.  
  2261.           //     Linkjes naar artikelen over trefwoord.
  2262.           // ->      NEW: artikelen?  (overleg)
  2263.  
  2264.           //     linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
  2265.           // ->      select all towns, generate url '/tag_name/town_code'
  2266.  
  2267.           //     linkjes naar andere trefwoorden?
  2268.           //     generate links '/tag_name':
  2269.           // ->      select tag_name from tags where NOT current_tag_name,  print url
  2270.  
  2271.           if (in_array($parsetype, array('5', '7'))) {  // TREFWOORD
  2272.  
  2273.               //--------------------------------------------------------------------------------------
  2274.               //     info tekst over trefwoord
  2275.               // ->       zie $tag_values['tag_name']
  2276.  
  2277.               //--------------------------------------------------------------------------------------
  2278.               //     namen van de spellen (met link en wellicht korte intro tekst met placeholders)
  2279.               // ->      select game_name, short_descr_tag FROM games
  2280.               //         fetch rows, while
  2281.               //             if '$tag_name' in array game_tags
  2282.               $params = array(
  2283.                 'select'    => ' t.*  ',
  2284.                 'orderby'    => 'game_order',
  2285.                 'limit'     => 0
  2286.               );
  2287.               $games_pod = pods( 'games', $params );
  2288.               if ( $games_pod->total() > 0 ) {
  2289.  
  2290.                   $tag_games_values = array();
  2291. //                    $tag_games_img_per_game_values = array();
  2292. //                  $tag_games_slider_values = array();
  2293.                   while ($games_pod->fetch() ) {
  2294.  
  2295.                       $tmp_game_code = $games_pod->display( 'game_code' );
  2296.  
  2297.  
  2298.                           $game_images_str = $games_pod->display( 'game_images' );
  2299.                           $game_images_arr = explode(' ', $game_images_str);
  2300.  
  2301.  
  2302.                       $str_tags = $games_pod->display( 'game_tags' );
  2303.                       $arr_tags = $games_pod->field( 'game_tags' );
  2304.                       // Select this game row if it has a tag in its tags array that equals the tag from the url
  2305.                       $select_row = false;
  2306.                       if (is_array($arr_tags) && count($arr_tags) > 0) {
  2307.                           foreach($arr_tags as $tag) {
  2308.                               if ($tag['tag_name'] == $tag_name) $select_row = true;
  2309.                           }
  2310.                       }
  2311.                       if ($select_row) {
  2312.                           $tag_games_values[] = $games_pod->row();
  2313.                           $tag_games_img_per_game_values[$tmp_game_code] = $game_images_arr[0];
  2314.  
  2315.  
  2316.                           // $tag_games_slider_values[] = end($game_images_arr);
  2317.                           // $tag_games_slider_values[] = $game_images_arr[0];
  2318.                           // if (isset($game_images_arr[1])) $tag_games_slider_values[] = $game_images_arr[1];
  2319.                           // if (isset($game_images_arr[2])) $tag_games_slider_values[] = $game_images_arr[2];
  2320.  
  2321.                           $tag_games_slider_values .= ' '.$game_images_str;
  2322.                       }
  2323.                   }
  2324.  
  2325.                   //$tag_games_slider_values = implode(' ', $tag_games_slider_values);
  2326.  
  2327.               }
  2328.  
  2329.  
  2330.               //--------------------------------------------------------------------------------------
  2331.               //     linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
  2332.               // ->      $array_towns en $array_town_names
  2333.  
  2334.               //--------------------------------------------------------------------------------------
  2335.               //     linkjes naar andere trefwoorden?
  2336.               //     generate links '/tag_name':
  2337.  
  2338.               $key = in_array($tag_name, $array_tags);
  2339.               $tag_other_tag_names = array();
  2340.               foreach ( $array_tags as $tag_name_from_array )  {
  2341.                   if ($tag_name_from_array != $tag_name) $tag_other_tag_names[] = $tag_name_from_array;
  2342.               }
  2343.           }
  2344.  
  2345.  
  2346.  
  2347.  
  2348.           //---------------------------------------------------------------------------------------------------
  2349.           // IF TOWN ONLY PAGE,
  2350.           //---------------------------------------------------------------------------------------------------
  2351.  
  2352.  
  2353.  
  2354.           //     info tekst over plaats
  2355.           // ->      select town_text from towns where town_name = %s
  2356.  
  2357.           //     namen van de spellen (met link en wellicht korte intro tekst met placeholders)
  2358.           // ->      select game_name, short_town_descr FROM games
  2359.           //         fetch rows, while
  2360.           //             if '$town_name' in array game_towns
  2361.  
  2362.           //     Linkjes naar artikelen over trefwoord.
  2363.           // ->      NEW: artikelen?  (overleg)
  2364.  
  2365.           //     linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
  2366.           // ->      select all towns, generate url '/town_name/town_code'
  2367.  
  2368.           //     linkjes naar andere trefwoorden?
  2369.           //     generate links '/town_name':
  2370.           // ->      select town_name from towns where NOT current_town_name,  print url
  2371.  
  2372.  
  2373.           if (in_array($parsetype, array('5', '8', '9', '12', '13'))) {  // PLAATS
  2374.  
  2375.               // GET ALL GAMES/LOCATIONS PLAYED IN THIS TOWN
  2376.               $town_locations_games_values = array();
  2377.  
  2378.               $params = array(
  2379.                   'select'    => 'CASE
  2380.                                      WHEN t.location_code = "eigen-locatie" THEN 1
  2381.                                      ELSE 0
  2382.                                  END AS first_sort,
  2383.                                  t.id as location_id,
  2384.                                  t.location_name,
  2385.                                  t.location_code,
  2386.                                  t.country,
  2387.                                  t.location_coordinates,
  2388.                                  t.diner_price,
  2389.                                  t.diner_price_foodfun
  2390.                                 ',
  2391.                   'where'     => " town.town_code = '".$town_code."'  OR t.location_code = 'eigen-locatie' ",
  2392.                   'orderby'     => 'first_sort, location_order, location_name',
  2393.                   'limit'     => 0
  2394.               );
  2395.  
  2396.               $locations_pod = pods( 'locations', $params );
  2397.               $locations_pod_total = $locations_pod->total();
  2398.               if ( $locations_pod_total > 0 ):
  2399.                   $i=0;
  2400.                   $data["geolocations"] = '[';
  2401.                   $town_tagnames_values=array();
  2402.                   $comma='';
  2403.  
  2404.                   while ($locations_pod->fetch() ) {
  2405.                       $row = $locations_pod->row();
  2406.                       $town_locations_games_values[$i]['location_code'] = $row['location_code'];
  2407.                       $town_locations_games_values[$i]['location_name'] = $row['location_name'];
  2408.                       $town_locations_games_values[$i]['country'] = $row['country'];
  2409.  
  2410.                       // GET ALL GAMES FOR THIS LOCATION
  2411.                       $game_params = array(
  2412.                           'select'    => 't.id as game_id,
  2413.                                          t.game_code,
  2414.                                          t.game_name,
  2415.                                          t.game_short_descr,
  2416.                                          wp_rel_locations_games.* ',
  2417.                           'join'      => ' INNER JOIN wp_rel_locations_games ON
  2418.                                              (wp_rel_locations_games.location_id = "'.$row['location_id'].'"
  2419.                                               AND wp_rel_locations_games.game_id = t.id
  2420.                                               AND wp_rel_locations_games.activated = 1
  2421.                                               AND (min_number IS NOT NULL AND min_number > 0)
  2422.                                               AND (max_number IS NOT NULL AND max_number > 0)
  2423.                                              )',
  2424.                           'orderby'   => 'game_order, game_code, min_number',
  2425.                           'limit'     => 0
  2426.                       );
  2427.                       $games_pod = pods( 'games', $game_params );
  2428.  
  2429.                       // collect data for the games played at this location
  2430.                       if ( $games_pod->total() > 0 ) {
  2431.  
  2432.                           $lowest_price = 999.99;
  2433.                           $prev_game_code = '';
  2434.                           $text_games_per_location = '\r\n\r\nDinerspellen:';
  2435.  
  2436.                           while ($games_pod->fetch() ) {
  2437.                               $row2 = $games_pod->row();
  2438.                               $tmp_game_code = $row2['game_code'];
  2439.  
  2440.                               // collect images for this game
  2441.                               $img_game_params = array(
  2442.                                   'select'    => ' t.id ',
  2443.                                   'where' => 'game_code = "'.$tmp_game_code.'"',
  2444.                                   'limit'     => 0
  2445.                               );
  2446.                               $img_games_pod = pods( 'games', $img_game_params );
  2447.                               if ( $img_games_pod->total() > 0 ) {
  2448.                                   $thumbnail = pods_image_url(
  2449.                                         $img_games_pod->field( 'game_images', TRUE ),
  2450.                                         'thumbnail-rectangle',
  2451.                                         0,
  2452.                                         true
  2453.                                   );
  2454.                                                                     $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_image'] =  $thumbnail;
  2455.                               }
  2456.  
  2457.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_code']         = $row2['game_code'];
  2458.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_name']         = $row2['game_name'];
  2459.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_short_descr']  = $row2['game_short_descr'];
  2460.  
  2461.                               // get the lowset total price for each game, plus the lowest number of people
  2462.                               if ($row2['game_code'] == 'food-en-fun-culi-spel') {
  2463.                                   $diner_price = $row['diner_price_foodfun'];
  2464.                               } else {
  2465.                                   $diner_price = $row['diner_price'];
  2466.                               }
  2467.                               if ($tmp_game_code == $prev_game_code) {
  2468.                                   // override if lower than the previous game-prices occurrence
  2469.                                   if ($row2['game_price'] < $lowest_price) {
  2470.                                       $lowest_price = $row2['game_price'];
  2471.                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2472.                                   }
  2473.                                   if ($row2['min_number'] < $low_min_number) {
  2474.                                       $low_min_number = $row2['min_number'];
  2475.                                   }
  2476.                                   if ($row2['max_number'] > $high_max_number) {
  2477.                                       $high_max_number = $row2['max_number'];
  2478.                                   }
  2479.                               } else {
  2480.                                   // the first game-prices occurrence
  2481.                                   $lowest_price       = $row2['game_price'];
  2482.                                   $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2483.                                   $low_min_number  = $row2['min_number'];
  2484.                                   $high_max_number  = $row2['max_number'];
  2485.  
  2486.                                   $prev_game_code     = $row2['game_code'];
  2487.  
  2488.                                   // build up a string of game-names for this location, so these games can be shown in the map info popups
  2489.                                   $text_games_per_location .= '\r\n - '.$row2['game_name'];
  2490.  
  2491.                               }
  2492.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['lowest_total_price']= $lowest_total_price;
  2493.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['low_min_number'] = $low_min_number;
  2494.                               $town_locations_games_values[$i]['location_games'][$tmp_game_code]['high_max_number'] = $high_max_number;
  2495.  
  2496.                               // collect the tagnames that this game has, add to array if not there already
  2497.                               $town_game_tags = $img_games_pod->display( 'game_tags' );
  2498.                               $town_game_tags_arr = explode(' ', $town_game_tags);
  2499.                               foreach($town_game_tags_arr as $town_game_tag) {
  2500.                                   $town_game_tag = str_replace(',','',$town_game_tag);
  2501.                                   if (!in_array($town_game_tag, $town_tagnames_values) && $town_game_tag <> 'and' && $town_game_tag <> 'en') {
  2502.                                       array_push($town_tagnames_values, $town_game_tag);
  2503.                                   }
  2504.                               }
  2505.  
  2506.  
  2507.  
  2508.                               if (isset($row['location_coordinates']) ) {
  2509.                                   // GET ALL LOCATION COORDS FOR THE GOOGLE MAP
  2510.                                   $json_geolocation   = $row['location_coordinates'];
  2511.                                   $obj_googlemapcoords   = json_decode($json_geolocation);
  2512.        
  2513.                                   if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  2514.        
  2515.                                       $goo_location_name      = $row['location_name'];
  2516.                                       $goo_location_code      = $row['location_code'];
  2517.                                       $goo_address_1          = $row['address_1'];
  2518.                                       $goo_postal_code        = $row['postal_code'];
  2519.                                       $info               = $goo_location_name;
  2520.                                       $info              .= (!empty($goo_address_1)) ? ' - '.$goo_address_1 : '';
  2521.                                       $info              .= (!empty($goo_postal_code)) ? ' - '.$goo_postal_code : '';
  2522.                                       $info              .= (!empty($town_name)) ? ' - '.$town_name : '';
  2523.        
  2524.                                       $info              .= $text_games_per_location;
  2525.                                       // $url             =  $game_code.'/'.$town_code.'/'.$goo_location_code;
  2526.                                       $url                =  home_url().'/'.$town_code.'/'.$goo_location_code;
  2527.        
  2528.                                       if (   isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
  2529.                                           && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
  2530.                                           && isset($info) && !empty($info)
  2531.                                           && isset($url) && !empty($url)
  2532.                                          ) {
  2533.                                         $data["geolocations"] .= $comma . "
  2534.                                         [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  2535.                                         $comma=", ";
  2536.                                     }
  2537.                                 }
  2538.                               }
  2539.        
  2540.  
  2541.  
  2542.  
  2543.  
  2544.                           }
  2545.  
  2546.                       }
  2547.  
  2548.  
  2549.                          
  2550.  
  2551.  
  2552.                       $i++;
  2553.                   }
  2554.                   if ($data["geolocations"] == '[')  {
  2555.                       $data["geolocations"] = '';
  2556.                   } else {
  2557.                       $data["geolocations"] .= '
  2558. ]';
  2559.                   }
  2560.  
  2561.  
  2562.  
  2563.               endif;
  2564.  
  2565.           }
  2566.  
  2567.  
  2568.  
  2569.  
  2570.           //---------------------------------------------------------------------------------------------------
  2571.           // IF PAGE 'EIGEN LOCATIE'
  2572.           //---------------------------------------------------------------------------------------------------
  2573.  
  2574.           if (in_array($parsetype, array('17'))) {
  2575.  
  2576.               $own_location_games_values = array();
  2577.               $params = array(
  2578.                   'select'    => 't.id as location_id,
  2579.                                  t.location_name,
  2580.                                  t.location_code,
  2581.                                  t.location_text
  2582.                                 ',
  2583.                   'where'     => "t.location_code = 'eigen-locatie' ",
  2584.                   'limit'     => 0
  2585.               );
  2586.  
  2587.               $own_locations_pod = pods( 'locations', $params );
  2588.               $own_locations_pod_total = $own_locations_pod->total();
  2589.  
  2590.               if ( $own_locations_pod_total > 0 ):
  2591.  
  2592.                   $i=0;
  2593.                   while ($own_locations_pod->fetch() ) {
  2594.                       $row = $own_locations_pod->row();
  2595.                       $own_location_games_values['location_text'] = $row['location_text'];
  2596.  
  2597.                       // GET ALL GAMES FOR THIS LOCATION
  2598.                       $own_location_game_params = array(
  2599.                           'select'    => 't.id as game_id,
  2600.                                          t.game_code,
  2601.                                          t.game_name,
  2602.                                          t.game_short_descr,
  2603.                                          wp_rel_locations_games.* ',
  2604.                           'join'      => ' INNER JOIN wp_rel_locations_games ON
  2605.                                              (wp_rel_locations_games.location_id = "'.$row['location_id'].'"
  2606.                                               AND wp_rel_locations_games.game_id = t.id
  2607.                                               AND wp_rel_locations_games.activated = 1
  2608.                                               AND (min_number IS NOT NULL AND min_number > 0)
  2609.                                               AND (max_number IS NOT NULL AND max_number > 0)
  2610.                                              )',
  2611.                           'orderby'   => 'game_order, game_code, min_number',
  2612.                           'limit'     => 0
  2613.                       );
  2614.                       $own_location_games_pod = pods( 'games', $own_location_game_params );
  2615.  
  2616.                       // collect data for the games played at this location
  2617.                       if ( $own_location_games_pod->total() > 0 ) {
  2618.  
  2619.                           $lowest_price = 999.99;
  2620.                           $prev_game_code = '';
  2621.                           $text_games_per_location = '\r\n\r\nDinerspellen:';
  2622.  
  2623.                           while ($own_location_games_pod->fetch() ) {
  2624.                               $row2 = $own_location_games_pod->row();
  2625.                               $own_location_game_code = $row2['game_code'];
  2626.  
  2627.                               // collect images for this game
  2628.                               $img_game_params = array(
  2629.                                   'select'    => ' t.id ',
  2630.                                   'where' => 'game_code = "'.$own_location_game_code.'"',
  2631.                                   'limit'     => 0
  2632.                               );
  2633.                               $img_games_pod = pods( 'games', $img_game_params );
  2634.                               if ( $img_games_pod->total() > 0 ) {
  2635.                                   $thumbnail = pods_image_url(
  2636.                                         $img_games_pod->field( 'game_images', TRUE ),
  2637.                                         'thumbnail-rectangle',
  2638.                                         0,
  2639.                                         true
  2640.                                   );
  2641.                                   $own_location_games_values['location_games'][$own_location_game_code]['game_image'] =  $thumbnail;
  2642.                               }
  2643.  
  2644.                               $own_location_games_values['location_games'][$own_location_game_code]['game_code']         = $row2['game_code'];
  2645.                               $own_location_games_values['location_games'][$own_location_game_code]['game_name']         = $row2['game_name'];
  2646.                               $own_location_games_values['location_games'][$own_location_game_code]['game_short_descr']  = $row2['game_short_descr'];
  2647.  
  2648.                               // get the lowset total price for each game, plus the lowest number of people
  2649.                               if ($row2['game_code'] == 'food-en-fun-culi-spel') {
  2650.                                   $diner_price = $row['diner_price_foodfun'];
  2651.                               } else {
  2652.                                   $diner_price = $row['diner_price'];
  2653.                               }
  2654.                               if ($own_location_game_code == $prev_game_code) {
  2655.                                   // override if lower than the previous game-prices occurrence
  2656.                                   if ($row2['game_price'] < $lowest_price) {
  2657.                                       $lowest_price = $row2['game_price'];
  2658.                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2659.                                   }
  2660.                                   if ($row2['min_number'] < $low_min_number) {
  2661.                                       $low_min_number = $row2['min_number'];
  2662.                                   }
  2663.                                   if ($row2['max_number'] > $high_max_number) {
  2664.                                       $high_max_number = $row2['max_number'];
  2665.                                   }
  2666.                               } else {
  2667.                                   // the first game-prices occurrence
  2668.                                   $lowest_price       = $row2['game_price'];
  2669.                                   $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2670.                                   $low_min_number  = $row2['min_number'];
  2671.                                   $high_max_number  = $row2['max_number'];
  2672.  
  2673.                                   $prev_game_code     = $row2['game_code'];
  2674.  
  2675.                                   // build up a string of game-names for this location, so these games can be shown in the map info popups
  2676.                                   $text_games_per_location .= '\r\n - '.$row2['game_name'];
  2677.  
  2678.                               }
  2679.                               $own_location_games_values['location_games'][$own_location_game_code]['lowest_total_price']= $lowest_total_price;
  2680.                               $own_location_games_values['location_games'][$own_location_game_code]['low_min_number'] = $low_min_number;
  2681.                               $own_location_games_values['location_games'][$own_location_game_code]['high_max_number'] = $high_max_number;
  2682.  
  2683.                           }
  2684.                       }
  2685.  
  2686.  
  2687.                       $i++;
  2688.                   }
  2689.  
  2690.               endif;
  2691.  
  2692.               // collect towns images for a slider
  2693.               $all_towns_slider_images = '';
  2694.               $params = array(
  2695.                 'select'    => ' town_images.guid as town_images  ',
  2696.                 'limit'     => 0
  2697.               );
  2698.               $towns_pod = pods( 'towns', $params );
  2699.               if ( $towns_pod->total() > 0 ) {
  2700.                   while ($towns_pod->fetch() ) {
  2701.                       $row = $towns_pod->row();
  2702.                       // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
  2703.                       // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN
  2704.                       $this_town_images = $row['town_images'];
  2705.                       if (!empty($this_town_images) && @strpos($this_town_images, $all_towns_slider_images) === false ) {
  2706.                           $all_towns_slider_images .= $this_town_images.' ';
  2707.                       }
  2708.                   }
  2709.               }
  2710.  
  2711.           }
  2712.  
  2713.  
  2714.           //---------------------------------------------------------------------------------------------------
  2715.           // IF "ALL TOWNS" PAGE,
  2716.           //---------------------------------------------------------------------------------------------------
  2717.           //     Intro tekstje algemeen
  2718.           // ->      general_content['all_towns']
  2719.  
  2720.           //    Kaart met vlaggetjes op alle plaatsen (popup met restaurants)
  2721.  
  2722.           if (in_array($parsetype, array('15'))) {  // ALLE PLAATSEN
  2723.  
  2724.               //--------------------------------------------------------------------------------------
  2725.               // ->      general_content['all_towns']
  2726.  
  2727.               $row = $wpdb->get_col("SELECT all_towns FROM wp_pods_general_content " );
  2728.               $all_towns_text_value = $row[0];
  2729.  
  2730.               //--------------------------------------------------------------------------------------
  2731.               //     namen van de plaatsen (met link)
  2732.               $params = array(
  2733.                 'select'    => ' town_code, town_name, town_coordinates, town_images.guid as town_images  ',
  2734.                 'limit'     => 0
  2735.               );
  2736.               $towns_pod = pods( 'towns', $params );
  2737.               if ( $towns_pod->total() > 0 ) {
  2738.  
  2739.  
  2740.                 // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
  2741.                 $data["town_coordinates"] = '[';
  2742.                 $all_towns_slider_images = '';
  2743.                 $prev_town_code = '';
  2744.  
  2745.                 while ($towns_pod->fetch() ) {
  2746.  
  2747.                     $row = $towns_pod->row();
  2748.  
  2749.                     // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
  2750.                     // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN, GET THE FIRST ONE OF EACH
  2751.  
  2752.                     if ($row['town_code'] != $prev_town_code) {
  2753.  
  2754.                         // FIRST ROW FOR THIS TOWN
  2755.                         $prev_town_code = $row['town_code'];
  2756.  
  2757.                           $all_towns_values[] = $row;
  2758.  
  2759.                         $this_town_images = $row['town_images'];
  2760.                         if (!empty($this_town_images)) $all_towns_slider_images .= $this_town_images.' ';
  2761.  
  2762.  
  2763.  
  2764.  
  2765.  
  2766.                     // collect the names of restaurants in this town, to be shown on hover over map flags
  2767.                     // ONLY LOCATIONS THAT ARE LINKED TO GAMES
  2768.                     // (WHEN LOCATIONS ARE NO LONGER NEEDED, THEY ARE NOT PHYSICALLY REMOVED, ONLY THEIR RELATIONSHIPS WITH GAMES ARE)
  2769.                     $params = array(
  2770.                         'select'    => 't.id as location_id,
  2771.                                        t.location_name,
  2772.                                        t.location_code
  2773.                                       ',
  2774.  
  2775.                         'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
  2776.  
  2777.  
  2778.                         'where'     => " town.town_code = '".$row['town_code']."'" ,
  2779.                         'orderby'     => 'location_name',
  2780.                         'limit'     => 0
  2781.                     );
  2782.  
  2783.  
  2784.  
  2785.  
  2786.                     $tmp_locations_pod = pods( 'locations', $params );
  2787.                     $tmp_locations_pod_total = $tmp_locations_pod->total();
  2788.                     if ( $tmp_locations_pod_total > 0 ):
  2789.                         $text_locations_per_town = '';
  2790.                         while ($tmp_locations_pod->fetch() ):
  2791.                             $row2 = $tmp_locations_pod->row();
  2792.                             $text_locations_per_town .= '\r\n - '.$row2['location_name'];
  2793.                         endwhile;
  2794.  
  2795.    
  2796.                         if (isset($row['town_coordinates']) && !empty($row['town_coordinates']) ) {
  2797.    
  2798.                             $json_geolocation   = $row['town_coordinates'];
  2799.                             $obj_googlemapcoords   = json_decode($json_geolocation);
  2800.    
  2801.                             if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  2802.                                 $town_name          = $row['town_name'];
  2803.                                 $town_code          = $row['town_code'];
  2804.                                 $town_country       = $row['country'];
  2805.                                 $info               = htmlspecialchars($town_name, ENT_QUOTES,'UTF-8');
  2806.                                 $info              .= (!empty($town_country)) ? ', '.htmlspecialchars($town_country, ENT_QUOTES,'UTF-8') : '';
  2807.                                   $info              .= htmlspecialchars($text_locations_per_town, ENT_QUOTES,'UTF-8');
  2808.                                 $url                =  $town_code;
  2809.                                 $data["town_coordinates"] .= $comma . "
  2810.                                 [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".$info."', '".$url."']";
  2811.                                 $comma=", ";
  2812.                             }
  2813.                         }
  2814.  
  2815.                     endif;
  2816.  
  2817.  
  2818.                     } else {
  2819.                         // MUST BE MULTIPLE ROWS FOR SAME TOWN, DIFFER ONLY RE. FIELD 'TOWN_IMAGES'
  2820.  
  2821.                     }
  2822.  
  2823.  
  2824.  
  2825.                 }
  2826.                 $data["town_coordinates"] .= '
  2827. ]';
  2828.               }
  2829.  
  2830.  
  2831.               // add 'Eigen locatie'  as the first element
  2832.               $eigen_locatie = array(
  2833.                   'town_code' => 'eigen-locatie',
  2834.                   'town_name' => 'Eigen locatie',
  2835.                   'town_coordinates' => ''
  2836.               );
  2837.               array_unshift($all_towns_values, $eigen_locatie);
  2838.  
  2839.           }
  2840.  
  2841.  
  2842.           //---------------------------------------------------------------------------------------------------
  2843.           // IF "ALL LOCATIONS" PAGE,
  2844.           //---------------------------------------------------------------------------------------------------
  2845.  
  2846.           if (in_array($parsetype, array('19'))) {  // ALLE RESTAURANTS
  2847.  
  2848.               // FIRST ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
  2849.               $params = array(
  2850.                   'select'    => ' location_code, location_images.guid as location_images ',
  2851.                   'where'     => ' location_code <> "eigen-locatie" ',
  2852.                   'limit'     => 0
  2853.               );
  2854.               $all_locations_slider_images='';
  2855.               $one_image_per_location=array();
  2856.               $location_images_pod = pods( 'locations', $params );
  2857.               if ( $location_images_pod->total() > 0 ) {
  2858.                   while ($location_images_pod->fetch() ) {
  2859.                       $row = $location_images_pod->row();
  2860.                       if (!empty($row['location_images'])) $all_locations_slider_images .= $row['location_images'].' ';
  2861.  
  2862.                       // per 'location' store the first image in a array $one_image_per_location
  2863.                       $temp_array = explode(' ', $row['location_images']);
  2864.                       $curr_image = $temp_array[0];
  2865.                       if (!empty($curr_image)) {
  2866.                           // use a smaller size if available
  2867.                           $curr_image_300 = str_replace('.jpg','-300x225.jpg', $curr_image);
  2868.  
  2869.                           $curr_image_300_testurl = str_replace(home_url(), '', $curr_image_300);
  2870.                           $curr_image_300_testurl = $_SERVER["DOCUMENT_ROOT"] .$curr_image_300_testurl;
  2871.  
  2872.                           if (is_file($curr_image_300_testurl)) $curr_image = $curr_image_300;
  2873.                       }
  2874.                       $one_image_per_location[ $row['location_code'] ] = $curr_image;
  2875.                   }
  2876.               }
  2877.  
  2878.  
  2879.               // NOW  COLLECT INFO ABOUT THE LOCATIONS, THEIR TOWNS, AND THE GAMES PLAYED
  2880.  
  2881.               // Not all this info is actually used in the template: the price and num_persons are not shown
  2882.  
  2883.               $params = array(
  2884.                   'select'    =>  '   t.location_code,
  2885.                                      t.location_name,
  2886.                                      t.address_1,
  2887.                                      t.postal_code,
  2888.                                      t.location_coordinates,
  2889.                                      t.diner_price,
  2890.                                      t.diner_price_foodfun,
  2891.                                      town.id as town_id,
  2892.                                      town.town_name as town_name,
  2893.                                      town.town_code as town_code,
  2894.                                      wp_pods_games.game_code,
  2895.                                      wp_pods_games.game_name,
  2896.                                      wp_rel_locations_games.min_number,
  2897.                                      wp_rel_locations_games.max_number,
  2898.                                      wp_rel_locations_games.game_price
  2899.                                  ',
  2900.                   'join'      => ' INNER JOIN wp_rel_locations_games ON (
  2901.                                      t.id = wp_rel_locations_games.location_id
  2902.                                      AND (min_number IS NOT NULL AND min_number > 0)
  2903.                                      AND (max_number IS NOT NULL AND max_number > 0)
  2904.                                   )
  2905.                                   INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  2906.                   'where'     => ' location_code <> "eigen-locatie" ',
  2907.                   'orderby'   => 'town_name, location_name, game_name, min_number ',
  2908.                   'limit'     => 0
  2909.               );
  2910.  
  2911.               $town_location_games_values = array();
  2912.  
  2913.               $locations_pod = pods( 'locations', $params );
  2914.               if ( $locations_pod->total() > 0 ) {
  2915.  
  2916.                   $data["location_coordinates"] = '[';
  2917.                   $prev_location_code = '';
  2918.                   $prev_location_game_combi = '';
  2919.                   $price_number_data = array();
  2920.                   $text_games_per_location = "\r\n - spel 1 - aaaaaaaaaa\r\n - spel 2 - bbbbbbbbbb";
  2921.                   $prev_key='';
  2922.  
  2923.                   while ($locations_pod->fetch() ) {
  2924.  
  2925.                       $row = $locations_pod->row();
  2926.  
  2927.                       //-------------------------------------------------------------------------------------------
  2928.                       // one time per location, ADD COORDINATE LINES TO STRING $data["location_coordinates"]
  2929.                       if ( $row['location_code'] !=  $prev_location_code) {
  2930.  
  2931.                           if (isset($row['location_coordinates']) && !empty($row['location_coordinates']) ) {
  2932.                               $json_geolocation       = $row['location_coordinates'];
  2933.                               $obj_googlemapcoords    = json_decode($json_geolocation);
  2934.                               if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  2935.                                   $location_name      = $row['location_name'];
  2936.                                   $location_code      = $row['location_code'];
  2937.                                   $address_1          = $row['address_1'];
  2938.                                   $town_name          = $row['town_name'];
  2939.                                   $town_code          = $row['town_code'];
  2940.                                   $postal_code        = $row['postal_code'];
  2941.                                   $location_country   = $row['country'];
  2942.                                   $info               = htmlspecialchars($location_name, ENT_QUOTES,'UTF-8');
  2943.                                   $info              .= (!empty($address_1)) ? ', '.htmlspecialchars($address_1, ENT_QUOTES,'UTF-8') : '';
  2944.                                   $info              .= (!empty($postal_code)) ? ', '.htmlspecialchars($postal_code, ENT_QUOTES,'UTF-8') : '';
  2945.                                   $info              .= (!empty($town_name)) ? ', '.htmlspecialchars($town_name, ENT_QUOTES,'UTF-8') : '';
  2946.                                   $info              .= (!empty($location_country)) ? ', '.htmlspecialchars($location_country, ENT_QUOTES,'UTF-8') : '';
  2947.                                   //$info              .= $text_games_per_location;
  2948.                                   $url                =  $town_code.'/'.$location_code;
  2949.                                   $data["location_coordinates"] .= $comma . "
  2950.                                  [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  2951.                                   $comma=", ";
  2952.                               }
  2953.                           }
  2954.  
  2955.                       }
  2956.  
  2957.                       //-------------------------------------------------------------------------------------------
  2958.                       if ( $prev_location_game_combi != $row['location_code'].'-'.$row['game_code']) {
  2959.  
  2960.                           // complete the previous location/game combi (if there was a prev_location_game_combi ):
  2961.                           // add "lowest min_number, the highest max_number, and the lowest price" to the price_number_data array
  2962.                           if (!empty($prev_location_game_combi)) {
  2963.                               $price_number_data[$prev_location_game_combi]['lowest_price']       = $lowest_price;
  2964.                               $price_number_data[$prev_location_game_combi]['lowest_total_price'] = $lowest_total_price;
  2965.                               $price_number_data[$prev_location_game_combi]['low_min_number']     = $low_min_number;
  2966.                               $price_number_data[$prev_location_game_combi]['high_max_number']    = $high_max_number;
  2967.                           }
  2968.  
  2969.                           // then collect info for this new location/game combi
  2970.                           $town_locations_games_values[] = $row;
  2971.                           // and initialise the loop for same location/game
  2972.                           if ($row['game_code'] == 'food-en-fun-culi-spel') {
  2973.                               $diner_price = $row['diner_price_foodfun'];
  2974.                           } else {
  2975.                               $diner_price = $row['diner_price'];
  2976.                           }
  2977.                           $lowest_price =$row['game_price'];
  2978.                           $low_min_number = $row['min_number'];
  2979.                           $high_max_number =  $row['max_number'];
  2980.                           $lowest_total_price = (float)$diner_price + (float)$lowest_price;
  2981.  
  2982.                       } else {
  2983.  
  2984.                           // for each group of "wp_rel_locations_games" rows per "location/game" combination,
  2985.                           // swap "lowest min_number, the highest max_number, and the lowest price" if better candidates are found
  2986.                           if ($row['game_price'] < $lowest_price) {
  2987.                               $lowest_price = $row['game_price'];
  2988.                               $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  2989.                           }
  2990.                           if ($row['min_number'] < $low_min_number) {
  2991.                               $low_min_number = $row['min_number'];
  2992.                           }
  2993.                           if ($row['max_number'] > $high_max_number) {
  2994.                               $high_max_number = $row['max_number'];
  2995.                           }
  2996.                       }
  2997.  
  2998.                       //-------------------------------------------------------------------------------------------
  2999.                       $prev_location_code = $row['location_code'];
  3000.                       $prev_location_game_combi = $row['location_code'].'-'.$row['game_code'];
  3001.  
  3002.                   }
  3003.  
  3004.  
  3005.                   // complete the last location/game combi:
  3006.                   if (!empty($prev_location_game_combi)) {
  3007.                       $price_number_data[$prev_location_game_combi]['lowest_price']       = $lowest_price;
  3008.                       $price_number_data[$prev_location_game_combi]['lowest_total_price'] = $lowest_total_price;
  3009.                       $price_number_data[$prev_location_game_combi]['low_min_number']     = $low_min_number;
  3010.                       $price_number_data[$prev_location_game_combi]['high_max_number']    = $high_max_number;
  3011.                   }
  3012.               }
  3013.  
  3014.               // loop complete, finish
  3015.               $data["location_coordinates"] .= '
  3016. ]';
  3017.               // ->      general_content['all_locations']
  3018.  
  3019.               $row = $wpdb->get_col("SELECT all_locations FROM wp_pods_general_content " );
  3020.               $all_locations_text_value = $row[0];
  3021.  
  3022.           }
  3023.  
  3024.  
  3025.  
  3026.  
  3027.  
  3028.  
  3029.  
  3030.           //---------------------------------------------------------------------------------------
  3031.           // GET ALL GAMES PLAYED WITHIN A RADIUS OF 15 KM OF THIS TOWN
  3032.  
  3033.               if ( in_array($parsetype, array('5', '8', '13', '14' ))) {  // plaats, spel/plaats/locatie, plaats/locatie
  3034.  
  3035.               if (isset($town_values['town_coordinates']) ) {
  3036.                   $json_geolocation   = $town_values['town_coordinates'];
  3037.                   $obj_googlemapcoords   = json_decode($json_geolocation);
  3038.                   if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  3039.                       if (   isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
  3040.                           && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
  3041.                           ) {
  3042.  
  3043.  
  3044. //error_log('lat: '.$obj_googlemapcoords->lat.' - lng: '.$obj_googlemapcoords->lng);
  3045.  
  3046.  
  3047.                           $center_latitude = $obj_googlemapcoords->lat;
  3048.                           $center_longitude = $obj_googlemapcoords->lng;
  3049.  
  3050.                           $town_location_games_values_radius = array();
  3051.                           //$town_location_slider_images_radius = array();
  3052.                           $town_location_slider_images_radius = '';
  3053.  
  3054.  
  3055.           // $parsetype = '8';  // PLAATS
  3056.           // $parsetype = '5';  // TREFWOORD/PLAATS
  3057.           // $parsetype = '13'; // SPEL/PLAATS/LOCATIE
  3058.           // $parsetype = '14'; // PLAATS/LOCATIE
  3059.  
  3060.                           if (in_array($parsetype, array('13', '14' )) && isset($location_code) && !empty($location_code)) {
  3061.                               // $do_radius = TRUE;
  3062.                               $params_radius = array(
  3063.                                   'select'    => 't.id as location_id,
  3064.                                                  t.location_name,
  3065.                                                  t.location_code,
  3066.                                                  t.diner_price,
  3067.                                                  t.diner_price_foodfun,
  3068.                                                  t.location_coordinates,
  3069.                                                  town.town_code as town_code,
  3070.                                                  town.town_name as town_name
  3071.                                                 ',
  3072.                                   'where'     => " location_code <> '".$location_code."'
  3073.                                                   ",
  3074.                                   'orderby'     => 'town_name, location_name',
  3075.                                   'limit'     => 0
  3076.                               );
  3077.                           } elseif (in_array($parsetype, array('5', '8')) && isset($town_code) && !empty($town_code)) {
  3078.                               // $do_radius = TRUE;
  3079.                               $params_radius = array(
  3080.                                   'select'    => 't.id as location_id,
  3081.                                                  t.location_name,
  3082.                                                  t.location_code,
  3083.                                                  t.diner_price,
  3084.                                                  t.diner_price_foodfun,
  3085.                                                  t.location_coordinates,
  3086.                                                  town.town_code as town_code,
  3087.                                                  town.town_name as town_name
  3088.                                                 ',
  3089.                                   'where'     => " town.town_code <> '".$town_code."'
  3090.                                                   ",
  3091.                                   'orderby'     => 'town_name, location_name',
  3092.                                   'limit'     => 0
  3093.                               );
  3094.                           }
  3095.  
  3096.                          $tmp_locations_pod_radius = pods( 'locations', $params_radius );
  3097.                           $tmp_locations_pod_radius_total = $tmp_locations_pod_radius->total();
  3098.  
  3099.                           if ($tmp_locations_pod_radius_total > 0 ):
  3100.                               $i=0;
  3101.                               while ($tmp_locations_pod_radius->fetch() ):
  3102.                                   $row_radius = $tmp_locations_pod_radius->row();
  3103.  
  3104.                                   $json_geolocation_radius   = $row_radius['location_coordinates'];
  3105.                                   $obj_googlemapcoords_radius   = json_decode($json_geolocation_radius);
  3106.                                   if (!empty($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lng)  ) {
  3107.                                       if (   isset($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lat)
  3108.                                           && isset($obj_googlemapcoords_radius->lng) && !empty($obj_googlemapcoords_radius->lng)
  3109.                                           ) {
  3110.  
  3111.                                           $check_latitude = $obj_googlemapcoords_radius->lat;
  3112.                                           $check_longitude = $obj_googlemapcoords_radius->lng;
  3113.                                       }
  3114.                                   }
  3115.  
  3116.                                   if (empty($check_latitude) || empty($check_longitude) ) continue;
  3117.  
  3118.                                   $sql = 'SELECT DISTINCT
  3119.                                              (   3959 * acos(cos(radians('.$center_latitude.')) * cos( radians( '.$check_latitude.' ) )
  3120.                                                  * cos( radians(  '.$check_longitude.' ) - radians('.$center_longitude.') )
  3121.                                                  + sin(radians('.$center_latitude.')) * sin(radians('.$check_latitude.' )))
  3122.                                              ) AS distance';
  3123.                                   $distance = $wpdb->get_row( $sql )->distance;
  3124.  
  3125.                                   if (is_numeric($distance) && $distance > 0 && $distance < 7):
  3126.  
  3127.  
  3128.                                       $town_location_games_values_radius[$i]['location_code'] = $row_radius['location_code'];
  3129.                                       $town_location_games_values_radius[$i]['location_name'] = $row_radius['location_name'];
  3130.                                       $town_location_games_values_radius[$i]['town_code']     = $row_radius['town_code'];
  3131.                                       $town_location_games_values_radius[$i]['town_name']     = $row_radius['town_name'];
  3132.  
  3133.                                       if (!empty($location_values['location_images']) && @strpos($location_values['location_images'], $town_location_slider_images_radius) === false ) {
  3134.                                           $town_location_slider_images_radius .= $location_values['location_images'].' ';
  3135.                                       }
  3136.  
  3137.  
  3138.  
  3139.                                       $game_params_radius = array(
  3140.                                               'select'    => 't.id as game_id,
  3141.                                                              t.game_code,
  3142.                                                              t.game_name,
  3143.                                                              t.game_short_descr,
  3144.                                                              wp_rel_locations_games.* ',
  3145.                                               'join'      => 'INNER JOIN wp_rel_locations_games ON (
  3146.                                                                  wp_rel_locations_games.game_id = t.id
  3147.                                                                  AND (min_number IS NOT NULL AND min_number > 0)
  3148.                                                                  AND (max_number IS NOT NULL AND max_number > 0)
  3149.                                                              )',
  3150.                                               'where'     => 'wp_rel_locations_games.location_id = "'.$row_radius['location_id'].'"
  3151.                                                              AND wp_rel_locations_games.game_id = t.id
  3152.                                                              AND wp_rel_locations_games.activated = 1
  3153.                                                             ',
  3154.                                               'orderby'   => 'game_order, game_code, min_number',
  3155.                                               'limit'     => 0
  3156.                                       );
  3157.                                       $tmp_games_pod_radius = pods( 'games', $game_params_radius );
  3158.  
  3159.                                       // collect data for the games played at this location
  3160.                                       if ( $tmp_games_pod_radius->total() > 0 ):
  3161.                                           $lowest_price = 999.99;
  3162.                                           $prev_game_code = '';
  3163.                                           while ($tmp_games_pod_radius->fetch() ):
  3164.                                               $row2_radius = $tmp_games_pod_radius->row();
  3165.                                               $tmp_games_game_code_radius = $row2_radius['game_code'];
  3166.  
  3167.                                               // collect images for this game
  3168.                                               $img_game_params_radius = array(
  3169.                                                   'select'    => ' t.id ',
  3170.                                                   'where' => 'game_code = "'.$tmp_games_game_code_radius.'"',
  3171.                                                   'limit'     => 0
  3172.                                               );
  3173.                                               $img_games_pod_radius = pods( 'games', $img_game_params_radius );
  3174.  
  3175.                                               if ( $img_games_pod_radius->total() > 0 ) {
  3176.                                                   $thumbnail = pods_image_url(
  3177.                                                         $img_games_pod_radius->field( 'game_images', TRUE ),
  3178.                                                         'thumbnail-rectangle',
  3179.                                                         0,
  3180.                                                         true
  3181.                                                   );
  3182.                                                  
  3183.                                                   $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_image'] =  $thumbnail;
  3184.  
  3185.                                                   // for the big top slider:
  3186.                                                   //if (!empty($game_images_str_radius) && strpos($game_images_str_radius, $town_location_slider_images_radius) === false ) {
  3187.                                                   if (!empty($game_images_str_radius) && @strpos($town_location_slider_images_radius, $game_images_str_radius) === false ) {
  3188.                                                       $town_location_slider_images_radius .= $game_images_str_radius.' ';
  3189.                                                   }
  3190.  
  3191.                                               }
  3192.  
  3193.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_code']         = $row2_radius['game_code'];
  3194.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_name']         = $row2_radius['game_name'];
  3195.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_short_descr']  = $row2_radius['game_short_descr'];
  3196.  
  3197.                                               // get the lowset total price for each game, plus the lowest number of people
  3198.                                               if ($row2_radius['game_code'] == 'food-en-fun-culi-spel') {
  3199.                                                   $diner_price = $row_radius['diner_price_foodfun'];
  3200.                                               } else {
  3201.                                                   $diner_price = $row_radius['diner_price'];
  3202.                                               }
  3203.                                               if ($tmp_games_game_code_radius == $prev_game_code) {
  3204.                                                   // override if lower than the previous game-prices occurrence
  3205.                                                   if ($row2_radius['game_price'] < $lowest_price) {
  3206.                                                       $lowest_price = $row2_radius['game_price'];
  3207.                                                       $lowest_total_price =  (float)$diner_price + (float)$lowest_price;
  3208.                                                   }
  3209.                                                   if ($row2_radius['min_number'] < $low_min_number) {
  3210.                                                       $low_min_number = $row2_radius['min_number'];
  3211.                                                   }
  3212.                                                   if ($row2_radius['max_number'] > $high_max_number) {
  3213.                                                       $high_max_number = $row2_radius['max_number'];
  3214.                                                   }
  3215.                                               } else {
  3216.                                                   // the first game-prices occurrence
  3217.                                                   $lowest_price        = $row2_radius['game_price'];
  3218.                                                   $lowest_total_price  =  (float)$diner_price + (float)$lowest_price;
  3219.                                                   $low_min_number   = $row2_radius['min_number'];
  3220.                                                   $high_max_number  = $row2_radius['max_number'];
  3221.  
  3222.                                                   $prev_game_code      = $row2_radius['game_code'];
  3223.                                               }
  3224.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['lowest_total_price']= $lowest_total_price;
  3225.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['low_min_number'] = $low_min_number;
  3226.                                               $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['high_max_number'] = $high_max_number;
  3227.  
  3228.                                           endwhile;
  3229.                                       endif;
  3230.                                   endif;
  3231.  
  3232.                                   $i++;
  3233.                               endwhile;
  3234.                           endif;
  3235.  
  3236.  
  3237.                       }
  3238.                   }
  3239.  
  3240.               }
  3241.           }
  3242.  
  3243.  
  3244.           if (in_array($parsetype, array('7'))) {
  3245.               include dirname(__FILE__) . '/templates/tpl_tag.php';
  3246.               exit();
  3247.           }
  3248.           if (in_array($parsetype, array('5'))) {
  3249.               include dirname(__FILE__) . '/templates/tpl_tag_town.php';
  3250.               exit();
  3251.           }
  3252.           if (in_array($parsetype, array('1'))) {
  3253.               //include dirname(__FILE__) . '/templates/tpl_tag_game_town_location.php';
  3254.                   include dirname(__FILE__) . '/templates/tpl_game_town_location.php';
  3255.               exit();
  3256.           }
  3257.  
  3258.  
  3259.           if (in_array($parsetype, array('10'))) {
  3260.               include dirname(__FILE__) . '/templates/tpl_game.php';
  3261.               exit();
  3262.           }
  3263.           if (in_array($parsetype, array('12', '9'))) {
  3264.               include dirname(__FILE__) . '/templates/tpl_game_town.php';
  3265.               exit();
  3266.           }
  3267.           if (in_array($parsetype, array('13'))) {
  3268.  
  3269.               // for the datepicker in the form
  3270.               //$currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  3271.               //$curryear = $currlocaldate->format('Y');
  3272.               date_default_timezone_set('Europe/Amsterdam');
  3273.               $curryear = date('Y');
  3274.  
  3275.  
  3276.               if ($location_code == 'eigen-locatie') {
  3277.                   include dirname(__FILE__) . '/templates/tpl_game_town_own_location.php';
  3278.               } else {
  3279.                   include dirname(__FILE__) . '/templates/tpl_game_town_location.php';
  3280.               }
  3281.               exit();
  3282.           }
  3283.           if (in_array($parsetype, array('18'))) {
  3284.               // for the datepicker in the form
  3285.               // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  3286.               // $curryear = $currlocaldate->format('Y');
  3287.               date_default_timezone_set('Europe/Amsterdam');
  3288.               $curryear = date('Y');
  3289.               include dirname(__FILE__) . '/templates/tpl_game_own_location.php';
  3290.               exit();
  3291.           }
  3292.  
  3293.  
  3294.           if (in_array($parsetype, array('8'))) {
  3295.               include dirname(__FILE__) . '/templates/tpl_town.php';
  3296.               exit();
  3297.           }
  3298.  
  3299.           if (in_array($parsetype, array('17'))) {
  3300.               include dirname(__FILE__) . '/templates/tpl_own_location.php';
  3301.               exit();
  3302.           }
  3303.  
  3304.           // WE USE '12' FOR THIS (tpl_game_town)
  3305.           // if (in_array($parsetype, array('9'))) {
  3306.           //     include dirname(__FILE__) . '/templates/tpl_town_game.php';
  3307.           //     exit();
  3308.           // }
  3309.           if (in_array($parsetype, array('14'))) {
  3310.               include dirname(__FILE__) . '/templates/tpl_town_location.php';
  3311.               exit();
  3312.           }
  3313.  
  3314.  
  3315.           if (in_array($parsetype, array('15'))) {
  3316.               include dirname(__FILE__) . '/templates/tpl_all_towns.php';
  3317.               exit();
  3318.           }
  3319.           if (in_array($parsetype, array('16'))) {
  3320.               include dirname(__FILE__) . '/templates/tpl_all_games.php';
  3321.               exit();
  3322.           }
  3323.           if (in_array($parsetype, array('19'))) {
  3324.               include dirname(__FILE__) . '/templates/tpl_all_locations.php';
  3325.               exit();
  3326.           }
  3327.  
  3328.  
  3329.       }
  3330.  
  3331.   }
  3332.  
  3333.  
  3334.   //==========================================================================================================================
  3335.   public function _check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations) {
  3336.   //==========================================================================================================================
  3337.  
  3338.       $parsetype = '0';
  3339.       $part_1 = $part_2 = $part_3 = $part_4 = '';
  3340.       if (isset($arr_action[0])) $part_1 = $arr_action[0];
  3341.       if (isset($arr_action[1])) $part_2 = $arr_action[1];
  3342.       if (isset($arr_action[2])) $part_3 = $arr_action[2];
  3343.       if (isset($arr_action[3])) $part_4 = $arr_action[3];
  3344.  
  3345.       // TRY TO MATCH WITH PARSETYPE 1  - TREFWOORD/SPEL/PLAATS/LOCATIE
  3346.       if  (
  3347.           (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3348.           (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
  3349.           (isset($part_3) && !empty($part_3) && in_array($part_3, $array_towns) )  &&
  3350.           (isset($part_4) && !empty($part_4) && in_array($part_4, $array_locations) )
  3351.           ) {
  3352.           $parsetype = '1'; // TREFWOORD/SPEL/PLAATS/LOCATIE
  3353.       }
  3354.  
  3355.  
  3356.       if ($parsetype == '0') {
  3357.           // TRY TO MATCH WITH PARSETYPE 2  - TREFWOORD/SPEL/LOCATIE
  3358.           if  (
  3359.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3360.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
  3361.               (isset($part_3) && !empty($part_3) && in_array($part_3, $array_locations) )
  3362.               ) {
  3363.               $parsetype = '2';  // TREFWOORD/SPEL/PLAATS/LOCATIE
  3364.           }
  3365.       }
  3366.  
  3367.       if ($parsetype == '0') {
  3368.           // TRY TO MATCH WITH PARSETYPE 3  - TREFWOORD/SPEL/PLAATS/
  3369.           if  (
  3370.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3371.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
  3372.               (isset($part_3) && !empty($part_3) && in_array($part_3, $array_towns) )
  3373.               ) {
  3374.               $parsetype = '3';  // TREFWOORD/SPEL/PLAATS
  3375.           }
  3376.       }
  3377.  
  3378.       if ($parsetype == '0') {
  3379.           // TRY TO MATCH WITH PARSETYPE 13 - SPEL/PLAATS/LOCATIE
  3380.           if  (
  3381.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )  &&
  3382.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) ) &&
  3383.               (isset($part_3) && !empty($part_3) && in_array($part_3, $array_locations) )
  3384.              ) {
  3385.               $parsetype = '13';  // TREFWOORD/SPEL
  3386.           }
  3387.       }
  3388.  
  3389.       if ($parsetype == '0') {
  3390.           // TRY TO MATCH WITH PARSETYPE 4  - TREFWOORD/LOCATIE
  3391.           if  (
  3392.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3393.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_locations) )
  3394.               ) {
  3395.               $parsetype = '4';  // TREFWOORD/LOCATIE
  3396.           }
  3397.       }
  3398.  
  3399.       if ($parsetype == '0') {
  3400.           // TRY TO MATCH WITH PARSETYPE 5  - TREFWOORD/PLAATS
  3401.           if  (
  3402.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3403.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) )
  3404.               ) {
  3405.               $parsetype = '5';  // TREFWOORD/PLAATS
  3406.           }
  3407.       }
  3408.  
  3409.       if ($parsetype == '0') {
  3410.           // TRY TO MATCH WITH PARSETYPE 6  - TREFWOORD/SPEL
  3411.           if  (
  3412.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
  3413.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) )
  3414.               ) {
  3415.               $parsetype = '6';  // TREFWOORD/SPEL
  3416.           }
  3417.       }
  3418.  
  3419.       if ($parsetype == '0') {
  3420.           // TRY TO MATCH WITH PARSETYPE 9  - PLAATS/SPEL
  3421.           if  (
  3422.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) ) &&
  3423.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) )
  3424.               ) {
  3425.               $parsetype = '9';  // PLAATS/SPEL
  3426.           }
  3427.       }
  3428.  
  3429.       if ($parsetype == '0') {
  3430.           // TRY TO MATCH WITH PARSETYPE 14  - PLAATS/LOCATIE
  3431.           if  (
  3432.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) ) &&
  3433.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_locations) )
  3434.               ) {
  3435.               $parsetype = '14';  // PLAATS/LOCATIE
  3436.           }
  3437.       }
  3438.  
  3439.       if ($parsetype == '0') {
  3440.           // TRY TO MATCH WITH PARSETYPE 11  - SPEL/TREFWOORD
  3441.           if  (
  3442.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )  &&
  3443.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_tags) )
  3444.              ) {
  3445.               $parsetype = '11';
  3446.           }
  3447.       }
  3448.  
  3449.       if ($parsetype == '0') {
  3450.           // TRY TO MATCH WITH PARSETYPE 12  - SPEL/PLAATS
  3451.           if  (
  3452.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )  &&
  3453.               (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) )
  3454.              ) {
  3455.               $parsetype = '12';
  3456.           }
  3457.       }
  3458.  
  3459.       if ($parsetype == '0') {
  3460.           // TRY TO MATCH WITH PARSETYPE 18  - SPEL/EIGEN-LOCATIE
  3461.           if  (
  3462.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )  &&
  3463.               (isset($part_2) && $part_2 == 'eigen-locatie' )
  3464.              ) {
  3465.               $parsetype = '18';
  3466.           }
  3467.       }
  3468.  
  3469.       if ($parsetype == '0') {
  3470.           // TRY TO MATCH WITH PARSETYPE 7  - TREFWOORD
  3471.           if  (
  3472.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) )
  3473.               ) {
  3474.               $parsetype = '7';  // TREFWOORD
  3475.           }
  3476.       }
  3477.  
  3478.       if ($parsetype == '0') {
  3479.           // TRY TO MATCH WITH PARSETYPE 8  - PLAATS
  3480.           if  (
  3481.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) )
  3482.               ) {
  3483.               $parsetype = '8';  // SPEL
  3484.           }
  3485.       }
  3486.  
  3487.       if ($parsetype == '0') {
  3488.           // TRY TO MATCH WITH PARSETYPE 10  - SPEL
  3489.           if  (
  3490.               (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )
  3491.               ) {
  3492.               $parsetype = '10';  // SPEL
  3493.           }
  3494.       }
  3495.  
  3496.       return array($parsetype, $part_1, $part_2, $part_3, $part_4);
  3497.  
  3498.   }
  3499.  
  3500.  
  3501.   //=====================================================================================
  3502.   public function beschikbaarheidsaanvraag() {
  3503.     global  $wpdb;
  3504.     // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  3505.     // $curryear = $currlocaldate->format('Y');
  3506.     date_default_timezone_set('Europe/Amsterdam');
  3507.     $curryear = date('Y');
  3508.  
  3509.     // // cannot process form without these fields:
  3510.     if (
  3511.         (   isset( $_POST['game_code'])     && !empty( $_POST['game_code'])     &&
  3512.             isset( $_POST['town_code'])     && !empty( $_POST['town_code'])     &&
  3513.             isset( $_POST['location_code']) && !empty( $_POST['location_code'])
  3514.         )
  3515.         ||
  3516.         (   isset( $_POST['game_code'])     && !empty( $_POST['game_code'])     &&
  3517.             isset( $_POST['location_code']) && $_POST['location_code'] == 'eigen-locatie'
  3518.         )
  3519.        ) {
  3520.         // OK, continue
  3521.     } else {
  3522.         exit();
  3523.     }
  3524.  
  3525.  
  3526.     if ( empty($_POST['tijd2'])) {
  3527.         //ok
  3528.     } else {
  3529.         // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
  3530.         wp_redirect( home_url());
  3531.         die();
  3532.         //-------------------------------------------------------------------------------
  3533.     }
  3534.  
  3535.  
  3536.     $errors = array();
  3537.     $arrRequiredFields = array('emailadres', 'voornaam', 'achternaam', 'voorkeursdatum_1', 'aantal_pers', 'tijd');
  3538.  
  3539.         // check if all required fields have been filled in
  3540.         foreach($_POST as $key => $value) {
  3541.             if (empty($value) ) {
  3542.                 if (in_array($key, $arrRequiredFields) ) {
  3543.                     $key2show = ucfirst(str_replace('_', ' ', $key));
  3544.                     array_push( $errors, 'Vul svp uw '.$key2show.' in');
  3545.                 }
  3546.             }
  3547.          }
  3548.  
  3549.         $user_email = ( isset ( $_POST['emailadres'] ) ? trim($_POST['emailadres']) : '' );
  3550.         if ( !empty($user_email) && !is_email( $user_email ) )
  3551.             array_push( $errors, 'Vult u a.u.b. een geldig e-mailadres in');
  3552.     // elseif ( email_exists( $user_email ) )
  3553.     //     array_push( $errors, 'Er is al een account met dit e-mailadres' );
  3554.  
  3555.     if ( !is_numeric($_POST['aantal_pers']) )
  3556.             array_push( $errors, 'Vult u a.u.b. uitsluitend een aantal in<br />bij Aantal personen');
  3557.  
  3558.     // create certain allowed variables from the $_POST
  3559.     $arr_allowed_fields = array('voornaam', 'achternaam', 'geslacht', 'emailadres', 'telefoon', 'game_code', 'town_code', 'location_code', 'voorkeursdatum_1', 'voorkeursdatum_2', 'aantal_pers', 'tijd', 'opmerking_klant');
  3560.     foreach ($_POST as $key => $value) {
  3561.         $arrSkip = array('submit');
  3562.         if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  3563.           $$key = trim($value);
  3564.         }
  3565.     }
  3566.  
  3567.     $game_code = $_POST['game_code'];
  3568.     $town_code = $_POST['town_code'];
  3569.     $location_code = $_POST['location_code'];
  3570.  
  3571.     //---------------------------------------------------------------------------------------
  3572.     // GET THE MIN AND MAX NUMBER OF PERSONS
  3573.  
  3574.     $sql = $wpdb->prepare("SELECT id as game_id, game_name FROM wp_pods_games WHERE game_code = %s", $game_code);
  3575.     $game_row = $wpdb->get_row($sql, ARRAY_A);
  3576.     $game_id = $game_row['game_id'];
  3577.     $game_name = $game_row['game_name'];
  3578.  
  3579.     $sql = $wpdb->prepare("SELECT id as town_id, town_name FROM wp_pods_towns WHERE town_code = %s", $town_code);
  3580.     $town_row = $wpdb->get_row($sql, ARRAY_A);
  3581.     $town_id = $town_row['town_id'];
  3582.     $town_name = $town_row['town_name'];
  3583.  
  3584.     $sql = $wpdb->prepare("SELECT id as location_id, location_name, email_address, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
  3585.     $location_row = $wpdb->get_row($sql, ARRAY_A);
  3586.     $location_id = $location_row['location_id'];
  3587.     $location_name = $location_row['location_name'];
  3588.     $location_email = $location_row['email_address'];
  3589.     $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  3590.  
  3591.  
  3592.     if (!empty($location_id)) {
  3593.  
  3594.     $rel_location_game_obj = $wpdb->get_row(
  3595.         "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  3596.           FROM wp_rel_locations_games
  3597.          WHERE location_id = ".$location_id."
  3598.            AND game_id     = ".$game_id."
  3599.            AND (min_number IS NOT NULL AND min_number > 0)
  3600.            AND (max_number IS NOT NULL AND max_number > 0)
  3601.        "
  3602.     );
  3603.     $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
  3604.     $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
  3605.     }
  3606.  
  3607.     $post_aantal_pers = (int)$_POST['aantal_pers'];
  3608.     if ( $post_aantal_pers < $min_aantal_pers || $post_aantal_pers > $max_aantal_pers ) {
  3609.         $errors[] = 'Het minimum aantal deelnemers is: '.$min_aantal_pers.'. Het maximum aantal is: '.$max_aantal_pers;
  3610.     }
  3611.  
  3612.  
  3613.     if ( !empty( $errors ) ) {
  3614.       // form fields errors, populate form and show again
  3615.  
  3616.       // for the datepicker in the form
  3617.       // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  3618.       // $curryear = $currlocaldate->format('Y');
  3619.       date_default_timezone_set('Europe/Amsterdam');
  3620.       $curryear = date('Y');
  3621.  
  3622.       include dirname(__FILE__) . '/templates/tpl_beschikbaarheidsaanvraag.php';
  3623.       exit();
  3624.       //-------------------------------------------------------------------------------
  3625.     }
  3626.  
  3627.  
  3628.     // OK, store this 'aanvraag' and send out emails
  3629.  
  3630.     if (!empty($_POST['voorkeursdatum_1'])) {
  3631.       $date1 = new DateTime(str_replace('/', '-', $_POST['voorkeursdatum_1']));
  3632.       $voorkeursdatum_1_ymd = $date1->format('Y-m-d');
  3633.     } else {
  3634.         $voorkeursdatum_1_ymd = '';
  3635.     }
  3636.     if (!empty($_POST['voorkeursdatum_2'])) {
  3637.         $date1 = new DateTime(str_replace('/', '-', $_POST['voorkeursdatum_2']));
  3638.         $voorkeursdatum_2_ymd = $date1->format('Y-m-d');
  3639.     } else {
  3640.         $voorkeursdatum_2_ymd = '';
  3641.     }
  3642.  
  3643.     $code_locatie = random_string();
  3644.     $code_dinerspel = random_string();
  3645.     $code_klant = random_string();
  3646.     $code_klant_mutatie = random_string();
  3647.  
  3648.     $url_code_locatie   = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  3649.     $url_code_dinerspel   = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
  3650.     $url_code_klant   = home_url().'/reserveren/'.$code_klant;
  3651.  
  3652.     $sqlQuery = $wpdb->prepare(
  3653.         "INSERT wp_pods_aanvragen SET
  3654.  
  3655.             name                    = %s,
  3656.             voornaam                = %s,
  3657.             geslacht                = %s,
  3658.             emailadres              = %s,
  3659.             telefoon                = %s,
  3660.             game_code               = %s,
  3661.             town_code               = %s,
  3662.             location_code           = %s,
  3663.             voorkeursdatum_1        = %s,
  3664.             voorkeursdatum_2        = %s,
  3665.             aantal_pers             = %d,
  3666.             tijd                    = %s,
  3667.             opmerking_klant         = %s,
  3668.             code_locatie            = %s,
  3669.             code_dinerspel          = %s,
  3670.             code_klant              = %s,
  3671.             code_klant_mutatie      = %s,
  3672.             url_code_locatie        = %s,
  3673.             url_code_dinerspel      = %s,
  3674.             url_code_klant          = %s,
  3675.             created                 = NOW(),
  3676.             send_doc_1 = '0',
  3677.             send_doc_2 = '1',
  3678.             send_doc_3 = '1',
  3679.             send_doc_4 = '1',
  3680.             action_status           = 'Informatief',
  3681.             action_date             = '',
  3682.                 planning_status         = 'OPEN'
  3683.         ",
  3684.  
  3685.         $achternaam,
  3686.         $voornaam,
  3687.         $geslacht,
  3688.         $emailadres,
  3689.         $telefoon,
  3690.         $game_code,
  3691.         $town_code,
  3692.         $location_code,
  3693.         $voorkeursdatum_1_ymd,
  3694.         $voorkeursdatum_2_ymd,
  3695.         $aantal_pers,
  3696.         $tijd,
  3697.         $opmerking_klant,
  3698.         $code_locatie,
  3699.         $code_dinerspel,
  3700.         $code_klant,
  3701.         $code_klant_mutatie,
  3702.         $url_code_locatie,
  3703.         $url_code_dinerspel,
  3704.         $url_code_klant
  3705.     );
  3706.     $updres = $wpdb->get_results( $sqlQuery );
  3707.  
  3708.   //////////////////////////////////////////////////////////////////////////////////
  3709.  
  3710.       $voorkeursdatum_1 = format_nlDate($_POST['voorkeursdatum_1']);
  3711.       $voorkeursdatum_2 = format_nlDate($_POST['voorkeursdatum_2']);
  3712.  
  3713.       $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  3714.       $voornaam = ucfirst($voornaam);
  3715.       $achternaam = ucwords($achternaam);
  3716.       //$geslacht = strtolower($geslacht);
  3717.       $opmerking_klant = stripslashes($opmerking_klant);
  3718.       $website = 'Dinerspel.nl';
  3719.  
  3720.  
  3721. //======================================================
  3722.       if ($location_code == 'eigen-locatie') {
  3723. //======================================================
  3724.  
  3725.         $gameurltext = $game_name.' in eigen locatie';
  3726.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  3727.  
  3728.         //----------------------------------
  3729.         // stuur email naar KLANT
  3730.         //----------------------------------
  3731.         $klant_email = $emailadres;
  3732.         ob_start();
  3733.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_EL_thankyou.php");
  3734.         $temp_content = ob_get_contents();
  3735.         ob_end_clean();
  3736.         $message = $temp_content;
  3737.  
  3738.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3739.         $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
  3740.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3741.  
  3742.  
  3743.         //----------------------------------
  3744.         // stuur email naar DINERSPEL
  3745.         //----------------------------------
  3746.         $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
  3747.         $url_msg = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
  3748.         $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  3749.  
  3750.         ob_start();
  3751.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_EL_naar_dinerspel.php");
  3752.         $temp_content = ob_get_contents();
  3753.         ob_end_clean();
  3754.         $message = $temp_content;
  3755.  
  3756.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3757.         $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag voor eigen locatie via '.$website, $message);
  3758.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3759.  
  3760.         //----------------------------------
  3761.         // show  thank you page
  3762.         //----------------------------------
  3763.         ob_start();
  3764.         include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_EL_thankyou.php");
  3765.         $temp_content = ob_get_contents();
  3766.         ob_end_clean();
  3767.         $message = $temp_content;
  3768.  
  3769. //=====================================================================================
  3770.       } elseif ($zelfstandige_locatie) {
  3771. //=====================================================================================
  3772.  
  3773.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  3774.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  3775.  
  3776.         //----------------------------------
  3777.         // stuur email naar KLANT
  3778.         //----------------------------------
  3779.         $klant_email = $emailadres;
  3780.  
  3781.         ob_start();
  3782.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
  3783.         $temp_content = ob_get_contents();
  3784.         ob_end_clean();
  3785.         $message = $temp_content;
  3786.  
  3787.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3788.         $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
  3789.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3790.  
  3791.         //----------------------------------
  3792.         // stuur email naar (ZELFSTANDIGE) LOCATIE
  3793.         //----------------------------------
  3794.         if (!empty($location_email)) {
  3795.             $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  3796.             $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  3797.  
  3798.             ob_start();
  3799.             include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
  3800.             $temp_content = ob_get_contents();
  3801.             ob_end_clean();
  3802.             $message = $temp_content;
  3803.  
  3804.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3805.             $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
  3806.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3807.         }
  3808.  
  3809.         //----------------------------------
  3810.         // stuur email naar DINERSPEL
  3811.         //----------------------------------
  3812.  
  3813.         ob_start();
  3814.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_dinerspel.php");
  3815.         $temp_content = ob_get_contents();
  3816.         ob_end_clean();
  3817.         $message = $temp_content;
  3818.  
  3819.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3820.         $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
  3821.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3822.  
  3823.         //----------------------------------
  3824.         // show  thank you page
  3825.         //----------------------------------
  3826.         ob_start();
  3827.         include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_ZL_thankyou.php");
  3828.         $temp_content = ob_get_contents();
  3829.         ob_end_clean();
  3830.         $message = $temp_content;
  3831.  
  3832.  
  3833. //=====================================================================================
  3834.       } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
  3835. //=====================================================================================
  3836.  
  3837.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  3838.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  3839.  
  3840.         //----------------------------------
  3841.         // stuur email naar KLANT
  3842.         //----------------------------------
  3843.         $klant_email = $emailadres;
  3844.  
  3845.         ob_start();
  3846.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
  3847.         $temp_content = ob_get_contents();
  3848.         ob_end_clean();
  3849.         $message = $temp_content;
  3850.  
  3851.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3852.         $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
  3853.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3854.  
  3855.         //----------------------------------
  3856.         // stuur email naar LOCATIE
  3857.         //----------------------------------
  3858.         if (!empty($location_email)) {
  3859.             $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  3860.             $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  3861.  
  3862.             ob_start();
  3863.             include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
  3864.             $temp_content = ob_get_contents();
  3865.             ob_end_clean();
  3866.             $message = $temp_content;
  3867.  
  3868.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3869.             $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
  3870.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3871.         }
  3872.  
  3873.         //----------------------------------
  3874.         // stuur email naar DINERSPEL
  3875.         //----------------------------------
  3876.  
  3877.         ob_start();
  3878.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_dinerspel.php");
  3879.         $temp_content = ob_get_contents();
  3880.         ob_end_clean();
  3881.         $message = $temp_content;
  3882.  
  3883.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3884.         $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
  3885.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3886.  
  3887.         //----------------------------------
  3888.         // show  thank you page
  3889.         //----------------------------------
  3890.         ob_start();
  3891.         include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_thankyou.php");
  3892.         $temp_content = ob_get_contents();
  3893.         ob_end_clean();
  3894.         $message = $temp_content;
  3895.  
  3896. //======================================================
  3897.       } else {
  3898. //======================================================
  3899.  
  3900.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  3901.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  3902.  
  3903.         //----------------------------------
  3904.         // stuur email naar KLANT
  3905.         //----------------------------------
  3906.         $klant_email = $emailadres;
  3907.         ob_start();
  3908.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
  3909.         $temp_content = ob_get_contents();
  3910.         ob_end_clean();
  3911.         $message = $temp_content;
  3912.  
  3913.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3914.         $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
  3915.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3916.  
  3917.         //----------------------------------
  3918.         // stuur email naar LOCATIE
  3919.         //----------------------------------
  3920.  
  3921.         if (!empty($location_email)) {
  3922.             $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  3923.             $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  3924.  
  3925.             ob_start();
  3926.             include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
  3927.             $temp_content = ob_get_contents();
  3928.             ob_end_clean();
  3929.             $message = $temp_content;
  3930.  
  3931.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3932.             $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
  3933.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3934.         }
  3935.  
  3936.  
  3937.         //----------------------------------
  3938.         // stuur email naar DINERSPEL
  3939.         //----------------------------------
  3940.  
  3941.         ob_start();
  3942.         include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_dinerspel.php");
  3943.         $temp_content = ob_get_contents();
  3944.         ob_end_clean();
  3945.         $message = $temp_content;
  3946.  
  3947.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3948.         $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
  3949.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  3950.  
  3951.  
  3952.         //----------------------------------
  3953.         // show  thank you page
  3954.         //----------------------------------
  3955.         ob_start();
  3956.         include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_thankyou.php");
  3957.         $temp_content = ob_get_contents();
  3958.         ob_end_clean();
  3959.         $message = $temp_content;
  3960.       }
  3961.  
  3962.       include dirname(__FILE__) . '/templates/tpl_info.php';
  3963.       exit();
  3964.  
  3965.   }
  3966.  
  3967.  
  3968.  
  3969.   //================================================
  3970.   public function ophalen_beschikbaarheid_bij_locatie() {
  3971.   //================================================
  3972.  
  3973.       global $wpdb;
  3974.  
  3975.       // get access code
  3976.       $redirecturl = $_SERVER['REDIRECT_URL'];
  3977.       $arrUrl = explode('/', $redirecturl);
  3978.       $key = array_search('reageer-op-beschikbaarheidsaanvraag', $arrUrl);
  3979.       $access_code = $arrUrl[($key+1)];
  3980.  
  3981.       if (!$access_code || empty($access_code) ) exit();
  3982.  
  3983.       // Get activation record for the user
  3984.       $sql = $wpdb->prepare("SELECT * FROM  wp_pods_aanvragen
  3985.                 WHERE code_locatie = %s", $access_code);
  3986.  
  3987.       $row_aanvraag = $wpdb->get_row($sql, ARRAY_A);
  3988.       if ( !$row_aanvraag ) {
  3989.         $message = 'Deze pagina is niet (meer) beschikbaar';
  3990.           include dirname(__FILE__) . '/templates/tpl_response.php';
  3991.                   exit;
  3992.       }
  3993.  
  3994.       // create certain allowed variables from $arr_aanvraag[0]
  3995.  
  3996.       foreach ($row_aanvraag as $key => $value) {
  3997.                   $arrSkip = array('submit');
  3998.                   if (!in_array($key, $arrSkip)) {
  3999.                     $$key = $value;
  4000.                   }
  4001.               }
  4002.       $achternaam = ucwords($name);
  4003.  
  4004.       $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  4005.       $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  4006.  
  4007.       // check if perhaps ZELFSTANDIGE LOCATIE
  4008.       $sql = $wpdb->prepare("SELECT zelfstandige_locatie FROM  wp_pods_locations
  4009.                 WHERE location_code = %s", $location_code);
  4010.       $location_row = $wpdb->get_row($sql, ARRAY_A);
  4011.       $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  4012.  
  4013.       $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4014.       $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4015.       $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4016.       $website = 'Dinerspel.nl';
  4017.       $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4018.       $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4019.       $form_action = home_url().'/verwerk-beschikbaarheid-van-locatie';
  4020.  
  4021.       //----------------------------------
  4022.       // show form to enter response
  4023.       //----------------------------------
  4024.       ob_start();
  4025.       if ($zelfstandige_locatie ||  $game_code == 'onfortuinlijke-bankier' ||  $game_code == 'mysterie-spel-back-to-school' ||  $game_code == 'into-the-box' ||  $game_code == 'koudgemaakte-kok') {
  4026.           // In that case the location's availablility will be the only thing needed, show a different form
  4027.           // because the location needs to be able to add a comment for the customer
  4028.           include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_ZL_voor_locatie.php");
  4029.       } else{
  4030.         include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_voor_locatie.php");
  4031.       }
  4032.       $temp_content = ob_get_contents();
  4033.       ob_end_clean();
  4034.       $message = $temp_content;
  4035.  
  4036.       include dirname(__FILE__) . '/templates/tpl_response.php';
  4037.       exit;
  4038.  
  4039.   }
  4040.  
  4041.  
  4042.  
  4043.   //=====================================================================================
  4044.   public function verwerken_beschikbaarheid_van_locatie(){
  4045.  
  4046.       global  $wpdb;
  4047.  
  4048.       if (!$_POST['access_code'] || empty($_POST['access_code']) ) exit();
  4049.  
  4050.       // Get activation record for the user
  4051.       // $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  4052.       //            WHERE code_locatie = '".esc_sql($_POST['access_code'])."'";
  4053.       // $recordset = $wpdb->get_results( $sqlQuery );
  4054.  
  4055.       $sql = $wpdb->prepare("SELECT * FROM  wp_pods_aanvragen WHERE code_locatie = %s", $_POST['access_code']);
  4056.       $row_aanvraag = $wpdb->get_row($sql, ARRAY_A);
  4057.       if ( !$row_aanvraag) {
  4058.         $message = 'Deze pagina is niet (meer) beschikbaar';
  4059.         include dirname(__FILE__) . '/templates/tpl_info.php';
  4060.         exit;
  4061.       }
  4062.       foreach ($row_aanvraag as $key => $value) {
  4063.         $arrSkip = array('submit');
  4064.         if (!in_array($key, $arrSkip)) {
  4065.           $$key = $value;
  4066.             }
  4067.         }
  4068.       $voornaam = ucfirst($voornaam);
  4069.       $achternaam = ucwords($name);
  4070.       //$geslacht = strtolower($geslacht);
  4071.       $emailadres_klant = $emailadres;
  4072.       $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  4073.  
  4074.       // check if perhaps ZELFSTANDIGE LOCATIE
  4075.       $sql = $wpdb->prepare("SELECT zelfstandige_locatie FROM  wp_pods_locations
  4076.                 WHERE location_code = %s", $location_code);
  4077.       $location_row = $wpdb->get_row($sql, ARRAY_A);
  4078.       $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  4079.  
  4080.       $achternaam = ucwords($name);
  4081.       $voorkeursdatum_1_janee_locatie = ($_POST['voorkeursdatum_1_janee'] == 'ja') ? 1 : 0  ;
  4082.       $voorkeursdatum_2_janee_locatie = ($_POST['voorkeursdatum_2_janee'] == 'ja') ? 1 : 0  ;
  4083.  
  4084.       $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  4085.       $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  4086.       $sqlQuery = $wpdb->prepare(
  4087.           "UPDATE wp_pods_aanvragen
  4088.              SET voorkeursdatum_1_janee_locatie = %s,
  4089.                  voorkeursdatum_2_janee_locatie = %s,
  4090.                  opmerking_locatie = %s,
  4091.                 code_locatie = '',
  4092.                              date_location_beschikbaarheid = NOW(),
  4093.                 modified = NOW()
  4094.                   WHERE code_locatie = %s
  4095.                 ",
  4096.                 $voorkeursdatum_1_janee_locatie,
  4097.                 $voorkeursdatum_2_janee_locatie,
  4098.                       stripslashes(htmlspecialchars($_POST['opmerking_locatie'], ENT_QUOTES,'UTF-8')),
  4099.                 $_POST['access_code']
  4100.       );
  4101.       $updres = $wpdb->get_results( $sqlQuery );
  4102.  
  4103.  
  4104.       //----------------------------------
  4105.       // stuur email naar DINERSPEL
  4106.       //---------------------------
  4107.       $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4108.       $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4109.       $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4110.       $website = 'Dinerspel.nl';
  4111.       $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
  4112.       $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4113.       $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4114.  
  4115.       $url_msg = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
  4116.       $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  4117.  
  4118.       //include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
  4119.  
  4120.       if ($zelfstandige_locatie) {
  4121.  
  4122.           // In that case the location's availablility will be the only thing needed, show a different form
  4123.           // because the location needs to be able to add a comment for the customer
  4124.  
  4125.           // also, the customer will be notified right away
  4126.  
  4127.           //----------------------------------
  4128.           // stuur email naar Dinerspel
  4129.           //---------------------------
  4130.           ob_start();
  4131.           include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_ZL_naar_dinerspel.php");
  4132.           $temp_content = ob_get_contents();
  4133.           ob_end_clean();
  4134.           $message = $temp_content;
  4135.           add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4136.           $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
  4137.           remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4138.  
  4139.  
  4140.           //----------------------------------
  4141.           // stuur email naar KLANT
  4142.           //---------------------------
  4143.  
  4144.           $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
  4145.  
  4146.           $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4147.           $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4148.  
  4149.           //$activate_link = home_url().'/reserveren/'.$code_klant;
  4150.           $url_msg = home_url().'/reserveren/'.$code_klant;
  4151.           $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
  4152.  
  4153.           $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4154.           $location_row = $wpdb->get_row($sql, ARRAY_A);
  4155.           $locatie_emailadres = $location_row['email_address'];
  4156.           $locatie_telefoon = $location_row['telephone'];
  4157.           $locatie_contactpersoon = $location_row['contactperson'];
  4158.  
  4159.           ob_start();
  4160.           if ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 1) {
  4161.                   include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_beide_data.php");
  4162.           }
  4163.           if ( ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie ==  0) ||
  4164.                ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_2_janee_locatie ==  1) ) {
  4165.  
  4166.                   $date_1_or_2    = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? '1' : '2';
  4167.                   $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  4168.                   include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_1_datum.php");
  4169.           }
  4170.  
  4171.           if ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_1_janee_locatie == 0)  {
  4172.                   include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_beide_niet.php");
  4173.           }
  4174.  
  4175.           $temp_content = ob_get_contents();
  4176.           ob_end_clean();
  4177.           $message = $temp_content;
  4178.  
  4179.           add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4180.           $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
  4181.           remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4182.  
  4183.  
  4184.       } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
  4185.  
  4186.         // In that case the location's availablility will be the only thing needed, show a different form
  4187.         // because the location needs to be able to add a comment for the customer
  4188.  
  4189.         // also, the customer will be notified right away
  4190.  
  4191.         //----------------------------------
  4192.         // stuur email naar Dinerspel
  4193.         //---------------------------
  4194.         ob_start();
  4195.         include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
  4196.         $temp_content = ob_get_contents();
  4197.         ob_end_clean();
  4198.         $message = $temp_content;
  4199.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4200.         $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
  4201.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4202.  
  4203.  
  4204.         //----------------------------------
  4205.         // stuur email naar KLANT
  4206.         //---------------------------
  4207.  
  4208.         $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
  4209.  
  4210.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4211.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4212.  
  4213.         //$activate_link = home_url().'/reserveren/'.$code_klant;
  4214.         $url_msg = home_url().'/reserveren/'.$code_klant;
  4215.         $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
  4216.  
  4217.         $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4218.         $location_row = $wpdb->get_row($sql, ARRAY_A);
  4219.         $locatie_emailadres = $location_row['email_address'];
  4220.         $locatie_telefoon = $location_row['telephone'];
  4221.         $locatie_contactpersoon = $location_row['contactperson'];
  4222.  
  4223.         ob_start();
  4224.         if ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 1) {
  4225.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
  4226.         }
  4227.  
  4228.         if ( ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie ==  0) ||
  4229.              ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_2_janee_locatie ==  1) ) {
  4230.  
  4231.                 $date_1_or_2    = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? '1' : '2';
  4232.                 $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  4233.  
  4234.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
  4235.         }
  4236.  
  4237.         if ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_1_janee_locatie == 0)  {
  4238.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
  4239.         }
  4240.  
  4241.         $temp_content = ob_get_contents();
  4242.         ob_end_clean();
  4243.         $message = $temp_content;
  4244.  
  4245.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4246.         $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
  4247.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4248.  
  4249.  
  4250.       } else {
  4251.  
  4252.         // 'normale' locatie, alleen bericht naar dinerspel
  4253.  
  4254.         ob_start();
  4255.         include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
  4256.         $temp_content = ob_get_contents();
  4257.         ob_end_clean();
  4258.         $message = $temp_content;
  4259.  
  4260.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4261.         $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
  4262.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4263.       }
  4264.  
  4265.  
  4266.       //----------------------------------
  4267.       // show  thank you page
  4268.       //----------------------------------
  4269.       ob_start();
  4270.       include_once(dirname(__FILE__) . "/templates/tpl_page_reactie_locatie_naar_dinerspel_thankyou.php");
  4271.       $temp_content = ob_get_contents();
  4272.       ob_end_clean();
  4273.       $message = $temp_content;
  4274.  
  4275.       include dirname(__FILE__) . '/templates/tpl_info.php';
  4276.       exit;
  4277.  
  4278.  
  4279.    }
  4280.  
  4281.  
  4282.   //=====================================================================================
  4283.   public function afhandelen_beschikbaarheidsaanvraag(){
  4284.  
  4285.       // DOOR DINERSPEL, GETRIGGERD VIA LINK IN EMAIL GESTUURD NAAR DINERSPEL
  4286.       //   EMAIL: tpl_email_reactie_locatie_naar_dinerspel.php
  4287.  
  4288.       global $wpdb;
  4289.  
  4290.       // get access code
  4291.       $redirecturl = $_SERVER['REDIRECT_URL'];
  4292.       $arrUrl = explode('/', $redirecturl);
  4293.       $key = array_search('beschikbaarheidsaanvraag-afhandelen', $arrUrl);
  4294.       $access_code = $arrUrl[($key+1)];
  4295.  
  4296.       if (!$access_code || empty($access_code) ) exit();
  4297.  
  4298.       // Get activation record for the user
  4299.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  4300.                 WHERE code_dinerspel = '".esc_sql($access_code)."'";
  4301.       $recordset = $wpdb->get_results( $sqlQuery );
  4302.  
  4303.       if ( empty($recordset) ) {
  4304.         $message = 'Deze pagina is niet (meer) beschikbaar';
  4305.         include dirname(__FILE__) . '/templates/tpl_info.php';
  4306.         exit;
  4307.       }
  4308.       $row_aanvraag   = $recordset[0];
  4309.       foreach ($row_aanvraag as $key => $value) {
  4310.           $arrSkip = array('submit');
  4311.           if (!in_array($key, $arrSkip)) {
  4312.             $$key = $value;
  4313.           }
  4314.       }
  4315.  
  4316.       $achternaam = $name;
  4317.       $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  4318.       $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  4319.  
  4320.       if ($location_code == 'eigen-locatie') {
  4321.  
  4322.           $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4323.           $website = 'Dinerspel.nl';
  4324.           $gameurltext = $game_name.' in eigen locatie';
  4325.           $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  4326.           $form_action = home_url().'/verwerken-afhandeling-beschikbaarheidsaanvraag';
  4327.  
  4328.           //----------------------------------
  4329.           // show form to enter response
  4330.           //----------------------------------
  4331.           ob_start();
  4332.           include_once(dirname(__FILE__) . "/templates/tpl_page_afhandelen_beschikbaarheidsaanvraag_EL_dinerspel.php");
  4333.           $temp_content = ob_get_contents();
  4334.           ob_end_clean();
  4335.           $message = $temp_content;
  4336.  
  4337.       } else {
  4338.  
  4339.         $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4340.         $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4341.         $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4342.         $website = 'Dinerspel.nl';
  4343.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4344.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4345.         $form_action = home_url().'/verwerken-afhandeling-beschikbaarheidsaanvraag';
  4346.  
  4347.         //----------------------------------
  4348.         // show form to enter response
  4349.         //----------------------------------
  4350.         ob_start();
  4351.         include_once(dirname(__FILE__) . "/templates/tpl_page_afhandelen_beschikbaarheidsaanvraag_dinerspel.php");
  4352.         $temp_content = ob_get_contents();
  4353.         ob_end_clean();
  4354.         $message = $temp_content;
  4355.  
  4356.       }
  4357.  
  4358.       include dirname(__FILE__) . '/templates/tpl_response.php';
  4359.       exit;
  4360.  
  4361.   }
  4362.  
  4363.   //=====================================================================================
  4364.  
  4365.   public function verwerken_afhandeling_beschikbaarheidsaanvraag(){
  4366.  
  4367.       // GETRIGGERD VIA SUBMIT FORM OP PAGINA  tpl_page_afhandelen_beschikbaarheidsaanvraag_dinerspel.php
  4368.  
  4369.  
  4370.       global $wpdb;
  4371.       if (!$_POST['access_code'] || empty($_POST['access_code']) ) exit();
  4372.  
  4373.       // Get activation record for the user
  4374.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  4375.                 WHERE code_dinerspel = '".esc_sql($_POST['access_code'])."'";
  4376.       $recordset = $wpdb->get_results( $sqlQuery );
  4377.       if ( empty($recordset) ) {
  4378.         $message = 'Deze pagina is niet (meer) beschikbaar';
  4379.                   include dirname(__FILE__) . '/templates/tpl_info.php';
  4380.                   exit;
  4381.               }
  4382.       $row_aanvraag   = $recordset[0];
  4383.       foreach ($row_aanvraag as $key => $value) {
  4384.                   $arrSkip = array('submit');
  4385.                   if (!in_array($key, $arrSkip)) {
  4386.                     $$key = $value;
  4387.                   }
  4388.               }
  4389.       $emailadres_klant = $emailadres;
  4390.       $voorkeursdatum_1_janee = ($_POST['voorkeursdatum_1_janee'] == 'ja') ? 1 : 0  ;
  4391.       $voorkeursdatum_2_janee = ($_POST['voorkeursdatum_2_janee'] == 'ja') ? 1 : 0  ;
  4392.  
  4393.       $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  4394.       $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  4395.  
  4396.       $sqlQuery = "UPDATE wp_pods_aanvragen
  4397.                      SET
  4398.                      voorkeursdatum_1_janee_dinerspel = '".esc_sql($voorkeursdatum_1_janee)."',
  4399.                      voorkeursdatum_2_janee_dinerspel = '".esc_sql($voorkeursdatum_2_janee)."',
  4400.  
  4401.                      opmerking_dinerspel = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_dinerspel'], ENT_QUOTES,'UTF-8')))."',
  4402.                      date_dinerspel_beschikbaarheid = NOW(),
  4403.                      modified = NOW()
  4404.                    WHERE code_dinerspel = '".esc_sql($_POST['access_code'])."'";
  4405.       $updres = $wpdb->get_results( $sqlQuery );
  4406.  
  4407.       if ($location_code == 'eigen-locatie') {
  4408.  
  4409.               $website = 'Dinerspel.nl';
  4410.               $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4411.  
  4412.               $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  4413.               $voornaam = ucfirst($voornaam);
  4414.               $achternaam = ucwords($name);
  4415.               //$geslacht = strtolower($geslacht);
  4416.               $opmerking_dinerspel = stripslashes($_POST['opmerking_dinerspel']);
  4417.  
  4418.               $gameurltext = $game_name.' in eigen locatie';
  4419.               $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  4420.  
  4421.               //----------------------------------
  4422.               // stuur email naar KLANT
  4423.               //---------------------------
  4424.               $url_msg = home_url().'/reserveren/'.$code_klant;
  4425.               $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
  4426.  
  4427.               ob_start();
  4428.               if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
  4429.                       include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_data.php");
  4430.  
  4431.               if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ||
  4432.                    ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee ==  '1') ) {
  4433.                       $date_1_or_2    = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? '1' : '2';
  4434.                       $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  4435.                       include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_1_datum.php");
  4436.               }
  4437.  
  4438.               if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
  4439.                       include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_niet.php");
  4440.  
  4441.               $temp_content = ob_get_contents();
  4442.               ob_end_clean();
  4443.               $message = $temp_content;
  4444.  
  4445.               add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4446.               $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
  4447.               remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4448.  
  4449.  
  4450.       } else {
  4451.  
  4452.         $website = 'Dinerspel.nl';
  4453.         $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4454.         $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4455.         $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4456.  
  4457.         $emailadres_klant = $emailadres;
  4458.         $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  4459.         $voornaam = ucfirst($voornaam);
  4460.         $achternaam = ucwords($name);
  4461.         //$geslacht = strtolower($geslacht);
  4462.         $opmerking_dinerspel = stripslashes($_POST['opmerking_dinerspel']);
  4463.  
  4464.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4465.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4466.  
  4467.         //----------------------------------
  4468.         // stuur email naar KLANT
  4469.         //---------------------------
  4470.         //$activate_link = home_url().'/reserveren/'.$code_klant;
  4471.         $url_msg = home_url().'/reserveren/'.$code_klant;
  4472.         $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
  4473.  
  4474.         $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4475.         $location_row = $wpdb->get_row($sql, ARRAY_A);
  4476.         $locatie_emailadres = $location_row['email_address'];
  4477.         $locatie_telefoon = $location_row['telephone'];
  4478.         $locatie_contactpersoon = $location_row['contactperson'];
  4479.  
  4480.         ob_start();
  4481.         if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
  4482.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
  4483.  
  4484.         if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ||
  4485.              ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee ==  '1') ) {
  4486.                 $date_1_or_2    = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? '1' : '2';
  4487.                 $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  4488.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
  4489.             }
  4490.  
  4491.         if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
  4492.                 include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
  4493.  
  4494.         $temp_content = ob_get_contents();
  4495.         ob_end_clean();
  4496.         $message = $temp_content;
  4497.  
  4498.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4499.         $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
  4500.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4501.  
  4502.       }
  4503.  
  4504.  
  4505.       //----------------------------------
  4506.       // show  thank you page
  4507.       //----------------------------------
  4508.       $message = 'Email naar klant is verstuurd';
  4509.  
  4510.       include dirname(__FILE__) . '/templates/tpl_info.php';
  4511.       exit;
  4512.  
  4513.       }
  4514.  
  4515.   //=====================================================================================
  4516.  
  4517.   public function reserveren() {
  4518.  
  4519.     // TOONT FORM, PAGINA  tpl_page_reserveren_dinerspel.php
  4520.     // AFHANDELEN FORM SUBMIT  (-->  email naar dinerspel met link naar aanvraag edit page
  4521.  
  4522.     global $wpdb;
  4523.     $errors = array();
  4524.  
  4525.     if ($_POST) {
  4526.  
  4527.       if (!$_POST['access_code'] || empty($_POST['access_code']) ) {
  4528.           $error[] = 'Ontbrekende toegangscode';
  4529.           exit();
  4530.       } else {
  4531.           $access_code = $_POST['access_code'];
  4532.       }
  4533.  
  4534.       // Get activation record for the user
  4535.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  4536.                 WHERE code_klant = '".esc_sql($_POST['access_code'])."'";
  4537.       $recordset = $wpdb->get_results( $sqlQuery );
  4538.       if ( empty($recordset) ) {
  4539.           $errors[] = 'Deze pagina is niet (meer) beschikbaar';
  4540.           exit();
  4541.       } else {
  4542.           $row_aanvraag   = $recordset[0];
  4543.       }
  4544.  
  4545.       if (empty($_POST['telefoon'] )) {
  4546.           $errors[] = 'Graag uw telefoonnummer invullen a.u.b.';
  4547.       }
  4548.  
  4549.       if (empty($_POST['adres'] )) {
  4550.           $errors[] = 'Graag uw adres invullen t.b.v. de administratie';
  4551.       }
  4552.  
  4553.       if (empty($_POST['postcode'] )) {
  4554.           $errors[] = 'Graag uw postcode invullen t.b.v. de administratie';
  4555.       }
  4556.  
  4557.       if (empty($_POST['woonplaats'] )) {
  4558.           $errors[] = 'Graag uw woonplaats invullen t.b.v. de administratie';
  4559.       }
  4560.  
  4561.       if (empty($_POST['aantal_pers'] )) {
  4562.           $errors[] = 'Graag het aantal personen invullen t.b.v. de administratie';
  4563.       } elseif (!is_numeric($_POST['aantal_pers'])) {
  4564.           $errors[] = 'Graag uitsluitend een aantal invullen bij Aantal personen';
  4565.       }
  4566.  
  4567.       if ( empty($_POST['voorwaarden'] ) && ( $row_aanvraag->game_code != 'onfortuinlijke-bankier' &&  $row_aanvraag->game_code != 'mysterie-spel-back-to-school' &&  $row_aanvraag->game_code != 'into-the-box' &&  $row_aanvraag->game_code != 'koudgemaakte-kok') ) {
  4568.           $errors[] = 'Gaat u a.u.b. akkoord met onze voorwaarden';
  4569.       }
  4570.  
  4571.  
  4572.       if (!empty($_POST['btw_nummer'] )) {
  4573.  
  4574.           $vatNumber = trim($_POST['btw_nummer']);
  4575.           $vatNumber = str_replace('.', '', $vatNumber);
  4576.           $vatNumber = str_replace(' ', '', $vatNumber);
  4577.           $vatNumber = preg_replace('/[^0-9]/', '', $vatNumber);
  4578.           $_POST['btw_nummer'] = $vatNumber;
  4579.  
  4580.           $checkresult = viesCheckVAT ( $_POST['country_code'], $vatNumber );  // '19386256'
  4581. //print_r($checkresult);
  4582. //die();
  4583.           if (!is_array($checkresult) || !isset($checkresult['valid']) || $checkresult['valid'] == 'false') {
  4584.               $errors[] = '
  4585. Het door u ingevulde BTW nummer blijkt niet juist te zijn.<br />
  4586. &nbsp; &nbsp;U kunt doorgaan met reserveren zonder BTW nummer, maar de prijs wordt dan inclusief BTW berekend.<br />
  4587. &nbsp; &nbsp;Als u het nummer wilt corrigeren:<br>
  4588. &nbsp; &nbsp;- gebruik geen punten of spaties<br>
  4589. &nbsp; &nbsp;- verwijder voorvoegsels als NL of BE (dus voer alleen de cijfers in)';
  4590.           }
  4591.  
  4592.       }
  4593.  
  4594.  
  4595.       //---------------------------------------------------------------------------------------
  4596.       // GET THE MIN AND MAX NUMBER OF PERSONS
  4597.  
  4598.       $row = $wpdb->get_row("SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'" );
  4599.       $location_id            = $row->location_id;
  4600.       $zelfstandige_locatie   = $row->zelfstandige_locatie;
  4601.  
  4602.       if (!empty($location_id)) {
  4603.       $row = $wpdb->get_col("SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'" );
  4604.       $game_id = $row[0];
  4605.  
  4606.       $rel_location_game_obj = $wpdb->get_row(
  4607.           "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  4608.             FROM wp_rel_locations_games
  4609.            WHERE location_id = ".$location_id."
  4610.              AND game_id     = ".$game_id."
  4611.              AND (min_number IS NOT NULL AND min_number > 0)
  4612.              AND (max_number IS NOT NULL AND max_number > 0)
  4613.          "
  4614.       );
  4615.  
  4616.       $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
  4617.       $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
  4618.       }
  4619.  
  4620.       $post_aantal_pers = (int)$_POST['aantal_pers'];
  4621.  
  4622.       if ( $post_aantal_pers < $min_aantal_pers || $post_aantal_pers > $max_aantal_pers ) {
  4623.           $errors[] = 'Het minimum aantal deelnemers is: '.$min_aantal_pers.'. Het maximum aantal is: '.$max_aantal_pers;
  4624.       }
  4625.  
  4626.       if (count($errors) ==  0)  {
  4627.  
  4628.         // EERSTE VERWERKING RESERVERING  (GAAT NOG NIET VERDER DAN EMNAIL NAAR DINERSPEL)
  4629.  
  4630.         // CREATE VARIABLES FROM ROW_AANVRAAG
  4631.         foreach ($row_aanvraag as $key => $value) {
  4632.             $arrSkip = array('submit');
  4633.             if (!in_array($key, $arrSkip)) {
  4634.               $$key = $value;
  4635.             }
  4636.         }
  4637.  
  4638.         // create certain allowed variables from the $_POST as well
  4639.         $arr_allowed_fields = array('access_code', 'game_code', 'town_code', 'location_code', 'voorkeursdatum', 'bedrijfsnaam', 'telefoon',
  4640.              'adres', 'postcode', 'woonplaats', 'country_code', 'btw_nummer', 'opmerking_klant_res', 'aantal_pers', 'eigen_locatie_data');
  4641.         foreach ($_POST as $key => $value) {
  4642.             $arrSkip = array('submit');
  4643.             if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  4644.               $$key = stripslashes(htmlspecialchars($value, ENT_QUOTES,'UTF-8'));
  4645.             }
  4646.         }
  4647.  
  4648.         // Haal landnaam op a.d.h.v. land code
  4649.         $country_name = return_country_name($country_code);
  4650.  
  4651.         // block BTW  voor NL bedrijven
  4652.         if ($country_code == 'NL') $btw_nummer = '';
  4653.  
  4654.         if (isset($_POST['voorkeursdatum'])) {
  4655.  
  4656.           $reserveringsdatum = ($voorkeursdatum == '2') ? $voorkeursdatum_2  : $voorkeursdatum_1 ;
  4657.           $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
  4658.           $reserveringsdatum_ymd = $date1->format('Y-m-d');
  4659.  
  4660.           $reserveringsdatum = format_nlDate($reserveringsdatum);
  4661.  
  4662.         } else {
  4663.  
  4664.           // no date was chosen ,so there was no choice - only one date available
  4665.           // use field voorkeursdatum_1_janee_dinerspel or voorkeursdatum_2_janee_dinerspel
  4666.           // or field voorkeursdatum_1_janee_locatie or voorkeursdatum_2_janee_locatie
  4667.           // to determine which date to reserve
  4668.  
  4669.  
  4670.  
  4671.           if ($zelfstandige_locatie  ||  $game_code == 'onfortuinlijke-bankier' ||  $game_code == 'mysterie-spel-back-to-school' ||  $game_code == 'into-the-box' ||  $game_code == 'koudgemaakte-kok') {
  4672.  
  4673.             // only "locatie" can have have responded, so
  4674.             if ($voorkeursdatum_1_janee_locatie == '1') {
  4675.                 $reserveringsdatum = $voorkeursdatum_1 ;
  4676.                 $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
  4677.                 $reserveringsdatum_ymd = $date1->format('Y-m-d');
  4678.                 $reserveringsdatum = format_nlDate($voorkeursdatum_1);
  4679.             } else {
  4680.                 $reserveringsdatum = $voorkeursdatum_2 ;
  4681.                 $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
  4682.                 $reserveringsdatum_ymd = $date1->format('Y-m-d');
  4683.                 $reserveringsdatum = format_nlDate($voorkeursdatum_2);
  4684.             }
  4685.  
  4686.           } else {
  4687.  
  4688.               // must be "dinerspel"
  4689.             if ($voorkeursdatum_1_janee_dinerspel == '1') {
  4690.                 $reserveringsdatum = $voorkeursdatum_1 ;
  4691.                 $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
  4692.                 $reserveringsdatum_ymd = $date1->format('Y-m-d');
  4693.                 $reserveringsdatum = format_nlDate($voorkeursdatum_1);
  4694.             } else {
  4695.                 $reserveringsdatum = $voorkeursdatum_2 ;
  4696.                 $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
  4697.                 $reserveringsdatum_ymd = $date1->format('Y-m-d');
  4698.                 $reserveringsdatum = format_nlDate($voorkeursdatum_2);
  4699.             }
  4700.  
  4701.           }
  4702.  
  4703.         }
  4704.  
  4705.  
  4706.  
  4707.         if ($zelfstandige_locatie  ||  $game_code == 'onfortuinlijke-bankier' ||   $game_code == 'mysterie-spel-back-to-school' ||  $game_code == 'into-the-box' ||  $game_code == 'koudgemaakte-kok') {
  4708.             $new_action_status  = 'Gereserveerd';
  4709.             $new_reservering    = '1';
  4710.         } else {
  4711.             $new_action_status = 'Voorlopige reservering';
  4712.             $new_reservering    = '0';
  4713.         }
  4714.  
  4715.         $sqlQuery = "UPDATE wp_pods_aanvragen
  4716.            SET action_status = '".$new_action_status."',
  4717.              reservering = '".$new_reservering."',
  4718.              reserveringsdatum = '".$reserveringsdatum_ymd."',
  4719.              aantal_pers = '".esc_sql($aantal_pers)."',
  4720.                bedrijfsnaam = '".esc_sql(stripslashes(htmlspecialchars($_POST['bedrijfsnaam'], ENT_QUOTES,'UTF-8')))."',
  4721.                adres = '".esc_sql(stripslashes(htmlspecialchars($_POST['adres'], ENT_QUOTES,'UTF-8')))."',
  4722.                 postcode = '".esc_sql($postcode)."',
  4723.                woonplaats = '".esc_sql(stripslashes(htmlspecialchars($_POST['woonplaats'], ENT_QUOTES,'UTF-8')))."',
  4724.                country_code = '".$country_code."',
  4725.                country_name = '".$country_name."',  
  4726.              btw_nummer = '".esc_sql($btw_nummer)."',
  4727.              telefoon = '".esc_sql($telefoon)."',
  4728.                send_doc_1 = '0',
  4729.                send_doc_2 = '1',
  4730.                send_doc_3 = '1',
  4731.                send_doc_4 = '1',
  4732.                opmerking_klant_res = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_klant_res'], ENT_QUOTES,'UTF-8')))."',
  4733.        ";
  4734.  
  4735.  
  4736.         if (isset($eigen_locatie_data)) {
  4737.             $sqlQuery .= "
  4738.                 eigen_locatie_data = '".esc_sql($eigen_locatie_data)."',
  4739.            ";
  4740.         }
  4741.  
  4742.         $sqlQuery .= "
  4743.                code_klant = '',
  4744.                date_booked = NOW(),
  4745.                   modified = NOW()
  4746.             WHERE
  4747.                code_klant = '".esc_sql($access_code)."'";
  4748.  
  4749.         $updres = $wpdb->get_results( $sqlQuery );
  4750.  
  4751.         $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  4752.         $voornaam = ucfirst($voornaam);
  4753.         $achternaam = ucwords($name);
  4754.         //$geslacht = strtolower($geslacht);
  4755.         $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4756.         $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4757.         $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4758.         $website = 'Dinerspel.nl';
  4759.         $opmerking_klant = stripslashes($opmerking_klant);
  4760.         $opmerking_klant_res = stripslashes($opmerking_klant_res);
  4761.  
  4762.         // THIS SCRIPT CAN RUN ON THE NL AS WELL AS THE BE SITE
  4763.         $site_country = SITECOUNTRY;   // must be defined in the wp-config
  4764.         $link_to_edit_aanvraag = '<a href="'.HOMEURL_NL.'/ds-wijzig-aanvraag-reservering/?site_country='.$site_country.'&id='.$row_aanvraag->id.'">Open deze aanvraag (front-end)</a>';
  4765.  
  4766.  
  4767.         //=====================================================================================
  4768.         if ($location_code == 'eigen-locatie') {
  4769.         //=====================================================================================
  4770.  
  4771.           $gameurltext = $game_name.' in eigen locatie';
  4772.           $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  4773.  
  4774.           $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4775.           $location_row = $wpdb->get_row($sql, ARRAY_A);
  4776.           $locatie_emailadres = $location_row['email_address'];
  4777.           $locatie_telefoon = $location_row['telephone'];
  4778.           $locatie_contactpersoon = $location_row['contactperson'];
  4779.  
  4780.           //----------------------------------
  4781.           // stuur email naar DINERSPEL
  4782.           //---------------------------
  4783.               $game_name = ucwords(str_replace('-', ' ', $game_code) );
  4784.               $town_name = ucwords(str_replace('-', ' ', $town_code) );
  4785.               $location_name = ucwords(str_replace('-', ' ', $location_code) );
  4786.               $website = 'Dinerspel.nl';
  4787.               $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
  4788.  
  4789.  
  4790.           ob_start();
  4791.           include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_EL_naar_dinerspel.php");
  4792.           $temp_content = ob_get_contents();
  4793.           ob_end_clean();
  4794.           $message = $temp_content;
  4795.  
  4796.           add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4797.           $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
  4798.           remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4799.  
  4800.           //----------------------------------
  4801.           // show  thank you page
  4802.           //----------------------------------
  4803.           ob_start();
  4804.           include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_EL_thankyou.php");
  4805.           $temp_content = ob_get_contents();
  4806.           ob_end_clean();
  4807.           $message = $temp_content;
  4808.  
  4809.           include dirname(__FILE__) . '/templates/tpl_info.php';
  4810.           exit;
  4811.  
  4812.         //=====================================================================================
  4813.         } elseif ($zelfstandige_locatie) {
  4814.         //=====================================================================================
  4815.  
  4816.           $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4817.           $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4818.           $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4819.           $location_row = $wpdb->get_row($sql, ARRAY_A);
  4820.           $locatie_emailadres = $location_row['email_address'];
  4821.           $locatie_telefoon = $location_row['telephone'];
  4822.           $locatie_contactpersoon = $location_row['contactperson'];
  4823.             $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  4824.  
  4825.           //----------------------------------
  4826.           // stuur email naar KLANT
  4827.           //---------------------------
  4828.           ob_start();
  4829.           include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_klant.php");
  4830.           $temp_content = ob_get_contents();
  4831.           ob_end_clean();
  4832.           $message = $temp_content;
  4833.  
  4834.           $headers        = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
  4835.           get_header();
  4836.  
  4837.           add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4838.           $mailresult = wp_mail( $emailadres, ' Reservering bij '.$website, $message, $headers);
  4839.           remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4840.  
  4841.           //----------------------------------
  4842.           // stuur email naar LOCATIE
  4843.           //---------------------------
  4844.           // $row = $wpdb->get_col("SELECT email_address FROM wp_pods_locations WHERE location_code = '".$location_code."'" );
  4845.           // $location_email = $row[0];
  4846.           ob_start();
  4847.             include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_locatie.php");
  4848.             $temp_content = ob_get_contents();
  4849.             ob_end_clean();
  4850.             $message = $temp_content;
  4851.  
  4852.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4853.             $mailresult = wp_mail( $locatie_emailadres, ' Reservering via '.$website, $message);
  4854.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4855.  
  4856.             //----------------------------------
  4857.             // stuur email naar DINERSPEL
  4858.             //---------------------------
  4859.  
  4860.             ob_start();
  4861.             include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_dinerspel.php");
  4862.             $temp_content = ob_get_contents();
  4863.             ob_end_clean();
  4864.             $message = $temp_content;
  4865.  
  4866.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4867.             $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
  4868.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4869.  
  4870.             //----------------------------------
  4871.             // show  thank you page
  4872.             //----------------------------------
  4873.             ob_start();
  4874.             include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_ZL_thankyou.php");
  4875.             $temp_content = ob_get_contents();
  4876.             ob_end_clean();
  4877.             $message = $temp_content;
  4878.  
  4879.             include dirname(__FILE__) . '/templates/tpl_info.php';
  4880.             exit;
  4881.  
  4882.  
  4883.           //=====================================================================================
  4884.           } elseif ( $game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
  4885.  
  4886.             // do-it-yourself zoals onfortuinlijke bankier en the Box
  4887.           //=====================================================================================
  4888.  
  4889.             $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4890.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4891.  
  4892.             $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4893.             $location_row = $wpdb->get_row($sql, ARRAY_A);
  4894.             $locatie_emailadres = $location_row['email_address'];
  4895.             $locatie_telefoon = $location_row['telephone'];
  4896.             $locatie_contactpersoon = $location_row['contactperson'];
  4897.             $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  4898.             $url_msg = home_url().'/mutatie-aantal/'.$code_klant_mutatie;
  4899.             $activate_link = '<a href="'.$url_msg.'">AANTAL PERSONEN AANPASSEN</a>';
  4900.  
  4901.  
  4902.             //----------------------------------
  4903.             // stuur email naar KLANT
  4904.             //---------------------------
  4905.             $klant_emailadres = $emailadres;
  4906.             ob_start();
  4907.             include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_klant.php");
  4908.             $temp_content = ob_get_contents();
  4909.             ob_end_clean();
  4910.             $message = $temp_content;
  4911.  
  4912.  
  4913.             $headers        = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
  4914.             get_header();
  4915.  
  4916.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4917.             $mailresult = wp_mail( $emailadres, ' Reservering bij '.$website, $message, $headers);
  4918.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4919.  
  4920.             //----------------------------------
  4921.             // stuur email naar LOCATIE
  4922.             //---------------------------
  4923.             // $row = $wpdb->get_col("SELECT email_address FROM wp_pods_locations WHERE location_code = '".$location_code."'" );
  4924.             // $location_email = $row[0];
  4925.             ob_start();
  4926.             include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_locatie.php");
  4927.             $temp_content = ob_get_contents();
  4928.             ob_end_clean();
  4929.             $message = $temp_content;
  4930.  
  4931.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4932.             $mailresult = wp_mail( $locatie_emailadres, ' Reservering via '.$website, $message);
  4933.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4934.  
  4935.             //----------------------------------
  4936.             // stuur email naar DINERSPEL
  4937.             //---------------------------
  4938.             ob_start();
  4939.                   include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_dinerspel.php");
  4940.             $temp_content = ob_get_contents();
  4941.             ob_end_clean();
  4942.             $message = $temp_content;
  4943.  
  4944.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4945.             $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
  4946.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4947.  
  4948.             //----------------------------------
  4949.             // show  thank you page
  4950.             //----------------------------------
  4951.             ob_start();
  4952.                   include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_thankyou.php");
  4953.             $temp_content = ob_get_contents();
  4954.             ob_end_clean();
  4955.             $message = $temp_content;
  4956.  
  4957.             include dirname(__FILE__) . '/templates/tpl_info.php';
  4958.             exit;
  4959.  
  4960.           //=====================================================================================
  4961.           } else {   // normale locaties
  4962.           //=====================================================================================
  4963.  
  4964.  
  4965.             $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  4966.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  4967.  
  4968.             $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
  4969.             $location_row = $wpdb->get_row($sql, ARRAY_A);
  4970.             $locatie_emailadres = $location_row['email_address'];
  4971.             $locatie_telefoon = $location_row['telephone'];
  4972.             $locatie_contactpersoon = $location_row['contactperson'];
  4973.             $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  4974.  
  4975.             //----------------------------------
  4976.             // stuur email naar DINERSPEL
  4977.             //---------------------------
  4978.             ob_start();
  4979.                   include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_dinerspel.php");
  4980.             $temp_content = ob_get_contents();
  4981.             ob_end_clean();
  4982.             $message = $temp_content;
  4983.  
  4984.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4985.             $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
  4986.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  4987.  
  4988.             //----------------------------------
  4989.             // show  thank you page
  4990.             //----------------------------------
  4991.             ob_start();
  4992.                   include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_thankyou.php");
  4993.             $temp_content = ob_get_contents();
  4994.             ob_end_clean();
  4995.             $message = $temp_content;
  4996.  
  4997.             include dirname(__FILE__) . '/templates/tpl_info.php';
  4998.             exit;
  4999.  
  5000.           }
  5001.  
  5002.         }
  5003.  
  5004.     } else {
  5005.  
  5006.       // NO POST, GET THE aanvraag from the code in the url
  5007.  
  5008.       // get access code
  5009.       $redirecturl = $_SERVER['REDIRECT_URL'];
  5010.       $arrUrl = explode('/', $redirecturl);
  5011.       $key = array_search('reserveren', $arrUrl);
  5012.       $access_code = $arrUrl[($key+1)];
  5013.  
  5014.       if (!$access_code || empty($access_code) ) exit();
  5015.  
  5016.       // Get activation record for the user
  5017.       $sqlQuery = "SELECT * FROM  wp_pods_aanvragen
  5018.                 WHERE code_klant = '".esc_sql($access_code)."'";
  5019.       $recordset = $wpdb->get_results( $sqlQuery );
  5020.       if ( empty($recordset) ) {
  5021.         $message = 'Deze pagina is niet (meer) beschikbaar';
  5022.         include dirname(__FILE__) . '/templates/tpl_response.php';
  5023.         exit;
  5024.       }
  5025.       $row_aanvraag   = $recordset[0];
  5026.  
  5027.     }
  5028.  
  5029.  
  5030.  
  5031.     foreach ($row_aanvraag as $key => $value) {
  5032.       $arrSkip = array('submit');
  5033.       if (!in_array($key, $arrSkip)) {
  5034.             $$key = $value;
  5035.       }
  5036.     }
  5037.  
  5038.     $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  5039.     $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  5040.  
  5041.     $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  5042.     $voornaam = ucfirst($voornaam);
  5043.     $achternaam = ucwords(stripslashes($name));
  5044.     //$geslacht = strtolower($geslacht);
  5045.     $game_name = ucwords(str_replace('-', ' ', $game_code) );
  5046.     $town_name = ucwords(str_replace('-', ' ', stripslashes($town_code)) );
  5047.     $location_name = ucwords(str_replace('-', ' ', stripslashes($location_code)) );
  5048.     $website = 'Dinerspel.nl';
  5049.  
  5050.     $form_action = home_url().'/reserveren';
  5051.  
  5052.     $opmerking_klant = stripslashes($opmerking_klant);
  5053.     $opmerking_klant_res = stripslashes($opmerking_klant_res);
  5054.  
  5055.     // get the 'conditions_document' // klant moet akkoord gaan met voorwaarden
  5056.     $params = array(
  5057.         'select'    => ' t.* ',
  5058.         'where' => 'location_code = "'.$location_code.'"',
  5059.         'limit'     => 0
  5060.     );
  5061.  
  5062.     $locations_pod = pods( 'locations', $params );
  5063.     if ( $locations_pod->total() > 0 ) {
  5064.       $location_values = array();
  5065.       while ($locations_pod->fetch() ) {
  5066.           $location_row = $locations_pod->row();
  5067.           $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  5068.           $conditions_document_url = (isset($location_row['conditions_document'])) ? $location_row['conditions_document'] : $locations_pod->display('conditions_document') ;
  5069.       }
  5070.     }
  5071.  
  5072.     if ($location_code == 'eigen-locatie') {
  5073.  
  5074.       $gameurltext = $game_name.' in eigen locatie';
  5075.       $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  5076.  
  5077.     } else {
  5078.  
  5079.       $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  5080.       $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  5081.  
  5082.       if ($location_row) {
  5083.           $locatie_emailadres = $location_row['email_address'];
  5084.           $locatie_telefoon = $location_row['telephone'];
  5085.           $locatie_contactpersoon = $location_row['contactperson'];
  5086.       }
  5087.  
  5088.     }
  5089.  
  5090.  
  5091.     //---------------------------------------------------------------------------------------
  5092.     // GET THE MIN AND MAX NUMBER OF PERSONS
  5093.     $row = $wpdb->get_col("SELECT id as location_id FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'" );
  5094.     $location_id = $row[0];
  5095.     $row = $wpdb->get_col("SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'" );
  5096.     $game_id = $row[0];
  5097.  
  5098.     if (!empty($location_id)) {
  5099.     $rel_location_game_obj = $wpdb->get_row(
  5100.         "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
  5101.           FROM wp_rel_locations_games
  5102.          WHERE location_id = ".$location_id."
  5103.            AND game_id     = ".$game_id."
  5104.            AND (min_number IS NOT NULL AND min_number > 0)
  5105.            AND (max_number IS NOT NULL AND max_number > 0)
  5106.        "
  5107.     );
  5108.  
  5109.     $min_aantal_pers = $rel_location_game_obj->min_aantal_pers;
  5110.     $max_aantal_pers = $rel_location_game_obj->max_aantal_pers;
  5111.     }
  5112.  
  5113.     // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
  5114.     if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
  5115.         $min_aantal_pers = $row_aanvraag->min_aantal_override;
  5116.     }
  5117.  
  5118.  
  5119.     //----------------------------------
  5120.     // show form to start reservation
  5121.     //----------------------------------
  5122.     ob_start();
  5123.  
  5124.  
  5125.     if ($zelfstandige_locatie  ||  $game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
  5126.  
  5127.         if ($voorkeursdatum_1_janee_locatie == '0' && $voorkeursdatum_2_janee_locatie == '0') {
  5128.             // this should not be possible, klant should not have received an email with reservation access
  5129.           $message = 'Er is geen beschikbaarheid...';
  5130.           include dirname(__FILE__) . '/templates/tpl_response.php';
  5131.           exit();
  5132.         }
  5133.  
  5134.         if ( ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ||
  5135.              ($voorkeursdatum_1_janee_locatie == '0' && $voorkeursdatum_2_janee_locatie ==  '1') ) {
  5136.                 $date_1_or_2    = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? '1' : '2';
  5137.                 $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  5138.         }
  5139.  
  5140.         if ($zelfstandige_locatie) {
  5141.             include_once(dirname(__FILE__) . "/templates/tpl_page_reservering_ZL.php");
  5142.         } else {
  5143.             include_once(dirname(__FILE__) . "/templates/tpl_page_reservering.php");
  5144.         }
  5145.  
  5146.     } else {
  5147.  
  5148.       if ($voorkeursdatum_1_janee_dinerspel == '0' && $voorkeursdatum_2_janee_dinerspel == '0') {
  5149.           // this should not be possible, klant should not have received an email with reservation access
  5150.           $message = 'Er is geen beschikbaarheid...';
  5151.           include dirname(__FILE__) . '/templates/tpl_response.php';
  5152.           exit();
  5153.       }
  5154.  
  5155.       if ( ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel ==  '0') ||
  5156.            ($voorkeursdatum_1_janee_dinerspel == '0' && $voorkeursdatum_2_janee_dinerspel ==  '1') ) {
  5157.               $date_1_or_2    = ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel ==  '0') ? '1' : '2';
  5158.               $date_available = ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  5159.       }
  5160.  
  5161.       if ($location_code == 'eigen-locatie') {
  5162.           include_once(dirname(__FILE__) . "/templates/tpl_page_reservering_EL.php");
  5163.       } else {
  5164.         include_once(dirname(__FILE__) . "/templates/tpl_page_reservering.php");
  5165.       }
  5166.  
  5167.     }
  5168.  
  5169.     $temp_content = ob_get_contents();
  5170.     ob_end_clean();
  5171.     $message = $temp_content;
  5172.  
  5173.     include dirname(__FILE__) . '/templates/tpl_response.php';
  5174.     exit;
  5175.  
  5176.   }
  5177.  
  5178.  
  5179.  
  5180.   //=====================================================================================
  5181.   public function contactform(){
  5182.  
  5183.     global  $wpdb;
  5184.  
  5185.     $errors = array();
  5186.  
  5187.     if ( isset($_POST['tijd2']) && !empty($_POST['tijd2'])) {
  5188.         // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
  5189.         wp_redirect( home_url());
  5190.         die();
  5191.         //-------------------------------------------------------------------------------
  5192.     }
  5193.  
  5194.     if ($_POST) {
  5195.  
  5196.       if (!isset($_SESSION)) session_start();
  5197.       if (isset($_SESSION['capanswer']) && isset($_POST['capanswer']) && $_SESSION['capanswer'] == $_POST['capanswer'] ) {
  5198.           // value entered is correct
  5199.       } else {
  5200.             array_push( $errors, 'Het antwoord op de controlevraag is onjuist. Graag de twee getallen optellen en de som invullen.' );
  5201.       }    
  5202.  
  5203.  
  5204.       $emailadres = ( isset ( $_POST['emailadres'] ) ? $_POST['emailadres'] : '' );
  5205.       $emailadres2 = ( isset ( $_POST['bevestig_emailadres'] ) ? $_POST['bevestig_emailadres'] : '' );
  5206.  
  5207.       if ( !empty($emailadres) && !is_email( $emailadres ) )
  5208.           array_push( $errors,  __("Graag een geldig emailadres invullen", 'custom-pages-manager'));
  5209.       if ( $emailadres != $emailadres2 )
  5210.           array_push( $errors,  __("Emailadressen zijn niet gelijk", 'custom-pages-manager'));
  5211.  
  5212.       $arrRequiredFields = array('naam', 'emailadres','bevestig_emailadres', 'bericht',);
  5213.       $arrRequiredFieldsNL = array(
  5214.         'naam' => 'uw naam',
  5215.         'emailadres' => 'uw E-mailadres',
  5216.         'bevestig_emailadres' => 'E-mailadres ter bevestiging',
  5217.         'bericht' => 'uw bericht',
  5218.  
  5219.                                   );
  5220.       // check if all required fields have been filled in
  5221.       foreach($_POST as $key => $value) {
  5222.         if (empty($value) ) {
  5223.           if (in_array($key, $arrRequiredFields) ) {
  5224.             $arrkey2show = explode('_', $key);
  5225.             unset($arrkey2show[0]); // remove first bit
  5226.             $name2show = implode('_', $arrkey2show);
  5227.             $name2show = ucfirst(str_replace('_', ' ', $name2show));
  5228.             array_push( $errors, __("Vul svp in: ", 'custom-pages-manager').$arrRequiredFieldsNL[$key]);
  5229.           }
  5230.         }
  5231.       }
  5232.  
  5233.  
  5234.  
  5235.       if (!empty($_POST)) {
  5236.  
  5237.         // create certain allowed variables from the $_POST as well
  5238.           $arr_allowed_fields = array('naam', 'telefoon', 'adres', 'plaats', 'emailadres', 'bevestig_emailadres', 'bericht');
  5239.         foreach ($_POST as $key => $value) {
  5240.             $arrSkip = array('submit');
  5241.             if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  5242.               $$key = $value;
  5243.             }
  5244.         }
  5245.  
  5246.  
  5247.         if ( !empty( $errors ) ) {
  5248.           // form fields errors, populate form and show again
  5249.  
  5250.           if (!isset($_SESSION)) session_start();
  5251.           $digit1 = mt_rand(1,10);
  5252.           $digit2 = mt_rand(1,10);
  5253.           $math = "$digit1 + $digit2";
  5254.           $_SESSION['capanswer'] = $digit1 + $digit2;  
  5255.  
  5256.           include dirname(__FILE__) . '/templates/tpl_contactform.php';
  5257.           exit;
  5258.         }
  5259.  
  5260.       //----------------------------------
  5261.       // stuur email naar Dinerspel
  5262.       //---------------------------
  5263.  
  5264.       $message = "
  5265.    Bericht van: ".$naam."<br />
  5266.    <br />
  5267.    Telefoon: ".$telefoon."<br />
  5268.    <br />
  5269.    Emailadres: ".$emailadres."<br />
  5270.    <br />
  5271.    Bericht: ".$bericht."<br />
  5272.    <br />
  5273.    ";
  5274.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  5275.         $mailresult = wp_mail( get_option('admin_email'), ' Contactformulier '.$website, $message);
  5276.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  5277.  
  5278.         //----------------------------------
  5279.         // show  thank you page
  5280.         //----------------------------------
  5281.         $message = "Uw bericht is verstuurd. Wij zullen z.s.m. contact opnemen.<br />
  5282.    <br />
  5283.    Met vriendelijke groeten,<br />
  5284.    Moordspel.be";
  5285.  
  5286.         include dirname(__FILE__) . '/templates/tpl_info.php';
  5287.         exit;
  5288.  
  5289.       }
  5290.     }
  5291.  
  5292.     if (!isset($_SESSION)) session_start();
  5293.     $digit1 = mt_rand(1,10);
  5294.     $digit2 = mt_rand(1,10);
  5295.     $math = "$digit1 + $digit2";
  5296.     $_SESSION['capanswer'] = $digit1 + $digit2;
  5297.  
  5298.     include dirname(__FILE__) . '/templates/tpl_contactform.php';
  5299.     exit;
  5300.  
  5301.  
  5302.   }
  5303.  
  5304.  
  5305.  
  5306.  
  5307.   //================================================
  5308.   public function sitemap_page() {
  5309.   //================================================
  5310.  
  5311.     $sitemap = array();
  5312.  
  5313.     $static_urls = array(
  5314.         'spellen',
  5315.         'plaatsen',
  5316.         'contact',
  5317.         'webshop'
  5318.         );
  5319.     foreach($static_urls as $url) {
  5320.         $sitemap[] = $url;
  5321.     }
  5322.  
  5323.     $dynamic_urls = generate_sitemap_urls();
  5324.     foreach($dynamic_urls as $url) {
  5325.         $sitemap[] = $url;
  5326.     }
  5327.  
  5328.     //----------------------------------
  5329.     // show sitemap template
  5330.     //----------------------------------
  5331.     include dirname(__FILE__) . '/templates/tpl_sitemap.php';
  5332.     exit;
  5333.  
  5334.   }
  5335.  
  5336.  
  5337.  
  5338.  
  5339.   //=====================================================================================
  5340.   public function recensies() {
  5341.  
  5342.     global  $wpdb;
  5343.     // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  5344.     // $currlocaldate = $currlocaldate->format('Y-m-d H:i:s');
  5345.     date_default_timezone_set('Europe/Amsterdam');
  5346.     $currlocaldate = date('Y-m-d H:i:s');
  5347.  
  5348.     // INITIALISE THE RECENSIES PAGE
  5349.  
  5350.     // 1. GET THE LOCATIONS AND THEIR TOWNS
  5351.     $params = array(
  5352.         'select'    =>  '   t.location_code,
  5353.                            t.location_name,
  5354.                            town.id as town_id,
  5355.                            town.town_code as town_code,
  5356.                            town.town_name as town_name
  5357.                        ',
  5358.         //'where'     => ' location_name <> "eigen-locatie" ',
  5359.         'orderby'   => 'town_name, location_name ',
  5360.         'limit'     => 0
  5361.     );
  5362.     $towns_locations_options = '<option value="">Welke plaats en locatie? *</option>
  5363. ';
  5364.     $locations_pod = pods( 'locations', $params );
  5365.     if ( $locations_pod->total() > 0 ) {
  5366.         while ($locations_pod->fetch() ) {
  5367.             $row = $locations_pod->row();
  5368.  
  5369.  
  5370.             if ( !empty($locations_pod->row()['town_name']) ) {
  5371.                 $towns_locations_options .= '<option value="'.$locations_pod->row()['town_code'].'_'.$locations_pod->row()['location_code'].'">'.$locations_pod->row()['town_name'].', '.$locations_pod->row()['location_name'].'</options>
  5372. ';
  5373.             } elseif ( !empty($locations_pod->row()['location_name']) && $locations_pod->row()['location_name'] == "Eigen locatie") {
  5374.                 $town = '';
  5375.                 $towns_locations_options .= '<option value="eigen_locatie">Eigen locatie</options>
  5376. ';
  5377.             }
  5378.         }
  5379.     }
  5380.  
  5381.  
  5382.     // 2. GET THE GAMES
  5383.     $games_options = '<option value="">Welk spel heeft u gespeeld? *</option>
  5384. ';
  5385.     $params = array(
  5386.         'select'    =>  'game_code, game_name',
  5387.         'orderby'   => 'game_name ',
  5388.         'limit'     => 0
  5389.     );
  5390.     $games_pod = pods( 'games', $params );
  5391.     if ( $games_pod->total() > 0 ) {
  5392.         while ($games_pod->fetch() ) {
  5393.             if ( !empty($games_pod->row()['game_name']) ) {
  5394.                 $games_options .= '<option value="'.$games_pod->row()['game_code'].'">'.$games_pod->row()['game_name'].'</options>
  5395. ';
  5396.             }
  5397.         }
  5398.     }
  5399.  
  5400.  
  5401.  
  5402.     if ( isset($_POST) && count($_POST) > 0) {
  5403.       // Process a new "recensie"
  5404.  
  5405.       if ( empty($_POST['tijd2'])) {
  5406.           //ok
  5407.       } else {
  5408.           // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
  5409.           wp_redirect( home_url());
  5410.           die();
  5411.           //-------------------------------------------------------------------------------
  5412.       }
  5413.  
  5414.       $errors = array();
  5415.       $arrRequiredFields = array('ds_rec_voornaam', 'ds_rec_name', 'ds_rec_email', 'ds_rec_reserveringsdatum', 'ds_rec_town_code_location_code', 'ds_rec_game_code', 'ds_rec_aantal_pers');
  5416.       $arrRequiredFieldNames = array('ds_rec_voornaam' => 'Voornaam', 'ds_rec_name' => 'Achternaam', 'ds_rec_email' => 'Emailadres', 'ds_rec_reserveringsdatum' => 'Datum', 'ds_rec_town_code_location_code' => 'Plaats, locatie', 'ds_rec_game_code' => 'Spel', 'ds_rec_aantal_pers' => 'Aantal deelnemers');
  5417.  
  5418.       // check if all required fields have been filled in
  5419.       foreach($_POST as $key => $value) {
  5420.           if (empty($value) ) {
  5421.               if (in_array($key, $arrRequiredFields) ) {
  5422.                   $fieldname = $arrRequiredFieldNames[$key];
  5423.                   array_push( $errors, 'Vul a.u.b. uw '.$fieldname.' in');
  5424.               }
  5425.           }
  5426.       }
  5427.  
  5428.       if ( empty( $errors ) && !is_numeric($_POST['ds_rec_aantal_pers']) )
  5429.                   array_push( $errors, 'Vult u a.u.b. uitsluitend een aantal in<br />bij Aantal deelnemers');
  5430.  
  5431.       // create certain allowed variables from the $_POST
  5432.       $arr_allowed_fields = array('ds_rec_voornaam', 'ds_rec_name', 'ds_rec_email', 'ds_rec_reserveringsdatum', 'ds_rec_town_code_location_code', 'ds_rec_game_code', 'ds_rec_aantal_pers', 'ds_rec_unieke_spel_name', 'ds_rec_content');
  5433.       foreach ($_POST as $key => $value) {
  5434.           $arrSkip = array('submit');
  5435.           if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  5436.             $$key = trim($value);
  5437.           }
  5438.       }
  5439.  
  5440.       if ( !empty( $errors ) ) {
  5441.           // form fields errors, populate form and show again
  5442.  
  5443.               // for the datepicker in the form
  5444.               // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  5445.               // $curryear = $currlocaldate->format('Y');
  5446.               date_default_timezone_set('Europe/Amsterdam');
  5447.               $currlocaldate = date('Y-m-d H:i:s');
  5448.               $curryear = date('Y');
  5449.  
  5450.           include dirname(__FILE__) . '/templates/tpl_recensies.php';
  5451.           exit();
  5452.           //-------------------------------------------------------------------------------
  5453.       }
  5454.  
  5455.  
  5456.       // OK, no errors, store this 'recensie' and send out emails
  5457.  
  5458.       if (!empty($_POST['ds_rec_reserveringsdatum'])) {
  5459.           $date1 = new DateTime(str_replace('/', '-', $_POST['ds_rec_reserveringsdatum']));
  5460.           $ds_rec_reserveringsdatum = $date1->format('Y-m-d');
  5461.       } else {
  5462.           $ds_rec_reserveringsdatum = '';
  5463.       }
  5464.       $ds_rec_reserveringsdatum = format_nlDate($ds_rec_reserveringsdatum);
  5465.  
  5466.       $ds_rec_name = ucwords($ds_rec_name);
  5467.       $ds_rec_unieke_spel_code = stripslashes($ds_rec_unieke_spel_code);
  5468.       $ds_rec_content = stripslashes($ds_rec_content);
  5469.  
  5470.       // SAVE POST
  5471.  
  5472.       $recensie_post = array(
  5473.           'post_title' => 'Recentie van '. $ds_rec_voornaam. ' '. $ds_rec_name,
  5474.           'post_date' => $currlocaldate,
  5475.           'post_content' => ' ',
  5476.           'post_status' => 'pending',
  5477.           'post_type' => 'recensies',
  5478.       );
  5479.       $post_id = wp_insert_post( $recensie_post );
  5480.  
  5481.       // SAVE POST META STUFF
  5482.  
  5483.       // split the ds_rec_town_code_location_code field into the separate codes
  5484.       $post_array = $_POST;
  5485.       $arr_town_location = explode('_', $_POST['ds_rec_town_code_location_code']);
  5486.       $post_array['ds_rec_town_code'] = $arr_town_location[0];
  5487.       $post_array['ds_rec_location_code'] = $arr_town_location[1];
  5488.  
  5489.       $arr_allowed_fields = array('ds_rec_voornaam', 'ds_rec_name', 'ds_rec_email', 'ds_rec_reserveringsdatum', 'ds_rec_town_code', 'ds_rec_location_code', 'ds_rec_game_code', 'ds_rec_aantal_pers', 'ds_rec_unieke_spel_code', 'ds_rec_content');
  5490.       foreach ($post_array as $key => $value) {
  5491.           $arrSkip = array('submit');
  5492.           if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
  5493.             $$key = $value = trim($value);
  5494.             $this->custom_update_post_meta( $post_id,  $key, $value );
  5495.           }
  5496.       }
  5497.  
  5498.       if (isset($_FILES['image'])) {
  5499.           $this->custom_image_upload ( $_FILES['image'], $post_id, true );
  5500.       }
  5501.  
  5502.  
  5503.       //----------------------------------
  5504.       // stuur email naar DINERSPEL
  5505.       //----------------------------------
  5506.  
  5507.       ob_start();
  5508.       include_once(dirname(__FILE__) . "/templates/tpl_email_recensie_ontvangen.php");
  5509.       $temp_content = ob_get_contents();
  5510.       ob_end_clean();
  5511.       $message = $temp_content;
  5512.  
  5513.       add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  5514.       $mailresult = wp_mail( get_option('admin_email'), 'Recensie ontvangen', $message);
  5515.       remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  5516.  
  5517.       //----------------------------------
  5518.       // show  thank you page
  5519.       //----------------------------------
  5520.       ob_start();
  5521.       include_once(dirname(__FILE__) . "/templates/tpl_page_recensie_thankyou.php");
  5522.       $temp_content = ob_get_contents();
  5523.       ob_end_clean();
  5524.       $message = $temp_content;
  5525.       include dirname(__FILE__) . '/templates/tpl_info.php';
  5526.       exit();
  5527.  
  5528.     } else {
  5529.  
  5530.       // No $_POST vars, so just show the page with empty form
  5531.  
  5532.       include dirname(__FILE__) . '/templates/tpl_recensies.php';
  5533.       exit();
  5534.     }
  5535.   }
  5536.  
  5537.  
  5538.   //=====================================================================================
  5539.   /**
  5540.     * Updates post meta for a post. It also automatically deletes or adds the value to field_name if specified
  5541.     *
  5542.     * @access     protected
  5543.     * @param      integer     The post ID for the post we're updating
  5544.     * @param      string      The field we're updating/adding/deleting
  5545.     * @param      string      [Optional] The value to update/add for field_name. If left blank, data will be deleted.
  5546.     * @return     void
  5547.     */
  5548.   public function custom_update_post_meta( $post_id, $field_name, $value = '' )
  5549.   {
  5550.     if ( empty( $value ) OR ! $value )
  5551.     {
  5552.         delete_post_meta( $post_id, $field_name );
  5553.     }
  5554.     elseif ( ! get_post_meta( $post_id, $field_name ) )
  5555.     {
  5556.         add_post_meta( $post_id, $field_name, $value );
  5557.     }
  5558.     else
  5559.     {
  5560.         update_post_meta( $post_id, $field_name, $value );
  5561.     }
  5562.   }
  5563.  
  5564.  
  5565.  
  5566.   //=====================================================================================
  5567.   /**
  5568.     *
  5569.     */
  5570.   public function custom_image_upload( $file, $post_id=0, $set_as_featured=false ) {
  5571.  
  5572.     if (empty($file['name']) || empty($file['tmp_name']) ) return;
  5573.  
  5574.     $upload = wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
  5575.  
  5576.     $wp_filetype = wp_check_filetype( basename( $upload['file'] ), null );
  5577.  
  5578.     $wp_upload_dir = wp_upload_dir();
  5579.  
  5580.     $attachment = array(
  5581.         'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $upload['file'] ),
  5582.         'post_mime_type' => $wp_filetype['type'],
  5583.         'post_title' => preg_replace('/\.[^.]+$/', '', basename( $upload['file'] )),
  5584.         'post_content' => '',
  5585.         'post_status' => 'inherit'
  5586.     );
  5587.  
  5588.     $attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
  5589.  
  5590.     require_once(ABSPATH . 'wp-admin/includes/image.php');
  5591.  
  5592.     $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
  5593.     wp_update_attachment_metadata( $attach_id, $attach_data );
  5594.  
  5595.     if( $set_as_featured == true ) {
  5596.         update_post_meta( $post_id, '_thumbnail_id', $attach_id );
  5597.     }
  5598.  
  5599.   }
  5600.  
  5601.  
  5602.  
  5603. }
  5604. // END CLASS
  5605. //================================================================
  5606.  
  5607.  
  5608. //================================================================
  5609. $pages_manager = new Custom_Pages_Manager();
  5610. //================================================================
  5611.  
  5612.  
  5613.  
  5614.  
  5615.  
  5616. //=====================================================================================
  5617. add_shortcode( "list_all_games", "shortcode_list_all_games" );
  5618. //=====================================================================================
  5619. if(!function_exists('shortcode_list_all_games')) {
  5620.     function shortcode_list_all_games($atts){
  5621.         global  $wpdb;
  5622.         $params = array(
  5623.             'select'    => ' t.* ',
  5624.             'orderby'   => 'game_order',
  5625.             'limit'     => 0
  5626.         );
  5627.         $games_pod = pods( 'games', $params );
  5628.         if ( $games_pod->total() > 0 ) {
  5629.             $games = array();
  5630.             $games_images_values_arr = array();
  5631.             $i=0;
  5632.             while ($games_pod->fetch() ) {
  5633.                 $games_images_values = '';
  5634.                 $row = $games_pod->row();
  5635.                 // get pods values for all fields, in pods row as well as through "display only" (from related tables)
  5636.                 foreach($games_pod->fields as $podsfield) {
  5637.                     $fieldname = $podsfield['name'];
  5638.                     $games[$i][$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
  5639.                 }
  5640.  
  5641.                 // add game images to the tag_town_games_images_values_arr array, so the slider will have something to show besides town images
  5642.                 $tmp_game_images_str = $games_pod->display( 'game_images' );
  5643.                 $games_images_values .= ' '.$games_pod->display( 'game_images' );
  5644.  
  5645.  
  5646.                 $i++;
  5647.             }
  5648.         }
  5649.  
  5650.         // get info text for all games page
  5651.         $row = $wpdb->get_col("SELECT all_games FROM wp_pods_general_content " );
  5652.         $all_games_text_value = $row[0];
  5653.  
  5654.  
  5655.         // GET ALL TOWNS
  5656.         $all_games_towns_values = [];
  5657.         $data["geolocations"] = '[';
  5658.         $comma='';
  5659.         $rows = $wpdb->get_results( "SELECT town_code, town_name, town_coordinates FROM wp_pods_towns ORDER BY town_name" );
  5660.         foreach ( $rows as $row ):
  5661.             $town_name                  = $row->town_name;
  5662.             $town_code                  = $row->town_code;
  5663.  
  5664.  
  5665.             // check if the town has 1 or more locations linked to active games
  5666.             $count_games = 0;
  5667.             $params = array(
  5668.                 'select'    => 't.id',
  5669.                 'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
  5670.                 'where'     => " town.town_code = '".$row->town_code."'",
  5671.                 'limit'     => 0
  5672.             );
  5673.             $rel_location_games = pods( 'locations', $params );
  5674.             $count_games = $rel_location_games->total();
  5675.  
  5676.  
  5677.  
  5678.             if ($count_games > 0 && !empty($town_name) && isset($row->town_coordinates) && !empty($row->town_coordinates) ) {
  5679.  
  5680.                 $json_geolocation       = $row->town_coordinates;
  5681.                 $obj_googlemapcoords    = json_decode($json_geolocation);
  5682.  
  5683.                 if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng)  ) {
  5684.                     $info               = $town_name;
  5685.                     $url                = home_url().'/'.$town_code;
  5686.  
  5687.                     $data["geolocations"] .= $comma . "
  5688.                    [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  5689.                     $comma=", ";
  5690.                 }
  5691.  
  5692.                 $all_games_towns_values[] = $row;
  5693.  
  5694.             }
  5695.  
  5696.         endforeach;
  5697.  
  5698.         $data["geolocations"] .= '
  5699. ]';
  5700.  
  5701.         // add 'Eigen locatie'  as the first element
  5702.  
  5703.         $eigen_locatie = (object)array(
  5704.             'town_code' => 'eigen-locatie',
  5705.             'town_name' => 'Eigen locatie',
  5706.             'town_coordinates' => ''
  5707.         );
  5708.         array_unshift($all_games_towns_values, $eigen_locatie);
  5709.  
  5710.         ob_start();
  5711.         include dirname(__FILE__) . '/templates/tpl_games.php';
  5712.  
  5713.         $temp_content = ob_get_contents();
  5714.         ob_end_clean();
  5715.         return $temp_content;
  5716.         exit();
  5717.     }
  5718. }
  5719.  
  5720.  
  5721.  
  5722. //=====================================================================================
  5723. //  SHORTCODE homepage_title_text_map_area
  5724. //=====================================================================================
  5725. add_shortcode( "homepage_title_text_map_area", "shortcode_homepage_title_text_map_area" );
  5726.  
  5727. if(!function_exists('shortcode_homepage_title_text_map_area')) {
  5728.     function shortcode_homepage_title_text_map_area($atts){
  5729.  
  5730.         if ( is_front_page() && is_page() ) {
  5731.                 $home_values = format_element('home_values', array());
  5732.                 include dirname(__FILE__) . "/templates/tpl_homepage_title_text_map_area.php";
  5733.         }
  5734.     }
  5735. }
  5736.  
  5737.  
  5738. //-------------------------------------------------------------------------
  5739. function getTownName($town_id) {
  5740. //-------------------------------------------------------------------------
  5741.  
  5742.     // get the text value for the townId
  5743.     $params = array( 'where' => 'id = "'.$town_id.'"', 'limit' => 0 );
  5744.     $townpod = pods( 'towns' )->find( $params);
  5745.     if ( $townpod->total() > 0 ) {
  5746.         while ($townpod->fetch() ) {
  5747.             $row = $townpod->row();
  5748.             if ( !empty( $row ) ) {
  5749.                 return $townpod->field('town_name');
  5750.             } else {
  5751.                 return 'Geen plaatsnaam gevonden';
  5752.             }
  5753.         }
  5754.     } else {
  5755.         return 'Geen plaatsnaam gevonden';
  5756.     }
  5757.  
  5758. }
  5759.  
  5760. //-------------------------------------------------------------------------
  5761. function format_element($key, $field='', $extra_attr=array()) {
  5762. //-------------------------------------------------------------------------
  5763.   global $array_games, $array_towns, $array_locations;
  5764.   global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
  5765.   global $tag_values, $game_values, $town_values, $location_values, $rel_location_game_values, $town_locations_games_values;
  5766.   global $wpdb;
  5767.  
  5768.   ob_start();
  5769.  
  5770.   switch ($key) {
  5771.  
  5772.      // SHOW GAMES DROPDOWN
  5773.     case 'game_select':
  5774.       foreach($array_games as $key=>$value):
  5775.         if (!empty($value)): ?>
  5776.           <option value="<?php print $value; ?>"><?php print $array_game_names[$key]; ?></option>
  5777.           <?php
  5778.         endif;
  5779.       endforeach;
  5780.       break;
  5781.  
  5782.         // SHOW TOWNS DROPDOWN
  5783.     case 'town_select':
  5784.     foreach($array_towns as $key=>$value):
  5785.       if (!empty($value)): ?>
  5786.         <option value="<?php print $value; ?>"><?php print $array_town_names[$key]; ?></option>
  5787.         <?php
  5788.       endif;
  5789.     endforeach;
  5790.  
  5791.     break;
  5792.         // SHOW LOCATIONS DROPDOWN
  5793.         case 'location_select':
  5794.             foreach($array_locations as $key=>$value):
  5795.                 if (!empty($value)): ?>
  5796.                     <option value="<?php print $value; ?>"><?php print $array_location_names[$key]; ?></option>
  5797.                     <?php
  5798.                 endif;
  5799.             endforeach;
  5800.             break;
  5801.  
  5802.  
  5803.         // SHOW IMAGES
  5804.         case 'tag_images':
  5805.             $array_images = $field;
  5806.             foreach($array_images as $img_url):
  5807.                 if (!empty($img_url)) { ?>
  5808.                     <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
  5809.                       title="<?php print $tag_values['game_name']; ?>"
  5810.                         alt="<?php print $tag_values['game_name']; ?>"
  5811.                     />
  5812.                 <?php
  5813.                 }
  5814.             endforeach;
  5815.             break;
  5816.  
  5817.         case 'game_images':
  5818.             $array_images = explode(' ', $field);
  5819.             if (isset($extra_attr['list']) && count($array_images) > 0 ) {
  5820.                 $img_url = $array_images[0];
  5821.                 ?>
  5822.                 <img src="<?php print str_replace('http://', 'https://', $img_url); ?>"
  5823.                     style="
  5824.                         max-width:150px;
  5825.                         margin:0 20px 10px 0;
  5826.                         background-color: #fff;
  5827.                         padding:5px;
  5828.                         border:1px solid #ccc;
  5829.                     "
  5830.                     align="left"
  5831.                     title="<?php print $game_values['game_name']; ?>"
  5832.                     alt="<?php print $game_values['game_name']; ?>"
  5833.                 />
  5834.                 <?php
  5835.  
  5836.             } else {
  5837.             foreach($array_images as $img_url):
  5838.                 if (!empty($img_url)) { ?>
  5839.                         <img src="<?php print str_replace('http://', 'https://', $img_url); ?>"
  5840.                         style="
  5841.                             max-width:150px;
  5842.                             margin:0 20px 10px 0;
  5843.                             background-color: #fff;
  5844.                             padding:5px;
  5845.                             border:1px solid #ccc;
  5846.                         "
  5847.                       title="<?php print $game_values['game_name']; ?>"
  5848.                         alt="<?php print $game_values['game_name']; ?>"
  5849.                     />
  5850.                     <?php if (isset($extra_attr['one'])) break;
  5851.                 }
  5852.             endforeach;
  5853.             }
  5854.  
  5855.             break;
  5856.  
  5857.         case 'town_images':
  5858.             $array_images = explode(' ', $field);
  5859.             foreach($array_images as $img_url):
  5860.                 if (!empty($img_url)) { ?>
  5861.                     <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
  5862.                       title="<?php print $town_values['town_name']; ?>"
  5863.                         alt="<?php print $town_values['town_name']; ?>"
  5864.                     />
  5865.                 <?php
  5866.                 if (isset($extra_attr['one'])) break;
  5867.                 }
  5868.             endforeach;
  5869.             break;
  5870.  
  5871.  
  5872.         case 'images_slider':
  5873.  
  5874.             $array_images = explode(' ', trim($field));
  5875.             shuffle($array_images);
  5876.             $i=1;
  5877.             foreach($array_images as $img_url):
  5878.                 if (!empty($img_url)) {
  5879.  
  5880.                     // use a smaller size if available
  5881.                     $curr_image_300 = str_replace('.jpg','-300x225.jpg', $img_url);
  5882.                     $curr_image_300_testurl = str_replace(home_url(), '', $curr_image_300);
  5883.                     $curr_image_300_testurl = $_SERVER["DOCUMENT_ROOT"] .$curr_image_300_testurl;
  5884.                     if (is_file($curr_image_300_testurl)) $img_url = $curr_image_300;
  5885.                     $img_url = str_replace('http://', 'https://', $img_url);
  5886.                     $slides[] = '
  5887.                        <li>
  5888.                            <div class="slide-media nonhomeslide-media" style="padding:0px">
  5889.                            <div style="">
  5890.                                <img src="'.$img_url.'" style="padding:5px; border:1px solid #ddd; width:98%;"
  5891.                                />
  5892.                            </div>
  5893.                            </div>
  5894.                        </li>';
  5895.  
  5896.                     $i++;
  5897.                     if ($i > 20) break;  // no more than 20 slides
  5898.                 }
  5899.             endforeach;
  5900.             if (is_array($slides)) {
  5901.                 return '
  5902.            <div class="flexslider nonhomeflexslider" id="flexid">
  5903.                <ul class="slides">
  5904.                    '.implode('', $slides).'
  5905.                </ul>
  5906.            </div>';
  5907.             } else {
  5908.                 return false;
  5909.             }
  5910.             break;
  5911.  
  5912.  
  5913.  
  5914.  
  5915.  
  5916.         case 'location_images':
  5917.             $array_images = explode(' ', $field);
  5918.             foreach($array_images as $img_url):
  5919.                 if (!empty($img_url)) { ?>
  5920.                     <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
  5921.                       title="<?php print $location_games_values['location_name']; ?>"
  5922.                         alt="<?php print $location_games_values['location_name']; ?>"
  5923.                     />
  5924.                 <?php
  5925.                 if (isset($extra_attr['one'])) break;
  5926.                 }
  5927.             endforeach;
  5928.             break;
  5929.  
  5930.  
  5931.         // SHOW VIDEO FILES
  5932.         case 'game_videos':
  5933.         case 'location_video_files':
  5934.         case 'town_videos':
  5935.             $array_videos = explode(' ', $field);
  5936.             foreach($array_videos as $video_url):
  5937.                 if (!empty($video_url)) { ?>
  5938.                     <iframe src="<?php print $video_url; ?>" frameborder="0" allowfullscreen ></iframe>
  5939.             <?php
  5940.                 }
  5941.             endforeach;
  5942.             break;
  5943.  
  5944.  
  5945.         // SHOW VIDEO URLS
  5946.         case 'location_video_urls':
  5947.             $array_videos = explode(' ', $field);
  5948.             foreach($array_videos as $video_url):
  5949.             if (!empty($video_url)) {
  5950.                 // should be a youtube video, get the code
  5951.                 $tmparray = explode('/', $video_url);
  5952.                 $video_code = $tmparray[count($tmparray)-1];
  5953.                 $tmparray = explode('=', $video_code);
  5954.                 $video_code = $tmparray[count($tmparray)-1];
  5955.                 ?>
  5956.                     <iframe width="420" height="315" src="http://www.youtube.com/embed/<?php print $video_code; ?>?autoplay=1"></iframe>
  5957.                 <?php
  5958.                 }
  5959.             endforeach;
  5960.             break;
  5961.  
  5962.  
  5963.         case 'rel_location_game_values': ?>
  5964.  
  5965.             <table>
  5966.                 <tr>
  5967.                     <th>Aantal personen</th>
  5968.                     <?php
  5969.                     if ($location_values['location_code'] == 'eigen-locatie'  && ($game_values['game_code'] != 'onfortuinlijke-bankier' && $game_values['game_code'] != 'into-the-box' && $game_values['game_code'] != 'mysterie-spel-back-to-school' && $game_values['game_code'] != 'koudgemaakte-kok') ) {
  5970.                         print '<th>Spel + spelbegeleiding:</th>';
  5971.                     } elseif ($location_values['location_code'] == 'eigen-locatie'  && ($game_values['game_code'] != 'onfortuinlijke-bankier' || $game_values['game_code'] == 'into-the-box' || $game_values['game_code'] == 'mysterie-spel-back-to-school' || $game_values['game_code'] == 'koudgemaakte-kok') ) {
  5972.                         print '<th>Spel</th>';
  5973.                     } elseif ($game_values['game_code'] == 'onfortuinlijke-bankier' || $game_values['game_code'] == 'into-the-box' || $game_values['game_code'] == 'mysterie-spel-back-to-school' || $game_values['game_code'] == 'koudgemaakte-kok') {
  5974.                         print '<th>Diner + spel</th>';
  5975.                     } else {
  5976.                         print '<th>Dinerspel + menu + spelbegeleiding</th>';
  5977.                     }
  5978.                     ?>
  5979.                 </tr> <?php
  5980.  
  5981.             if ($location_values['location_code'] == 'eigen-locatie'  && ($game_values['game_code'] != 'onfortuinlijke-bankier' && $game_values['game_code'] != 'into-the-box' && $game_values['game_code'] != 'mysterie-spel-back-to-school' || $game_values['game_code'] != 'koudgemaakte-kok')) {
  5982.                 foreach($rel_location_game_values as $location_game): ?>
  5983.                     <tr>
  5984.                         <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
  5985.                         <td>&euro;<?php print ( !empty($location_game->game_price)) ? number_format((float)$location_game->game_price, 2, ',', '.') : '0,00'; ?> incl. BTW per persoon
  5986.                         </td>
  5987.                     </tr><?php
  5988.                 endforeach;
  5989.  
  5990.             } elseif ($location_values['location_code'] == 'eigen-locatie'  && ($game_values['game_code'] == 'onfortuinlijke-bankier' || $game_values['game_code'] == 'into-the-box' || $game_values['game_code'] == 'mysterie-spel-back-to-school' || $game_values['game_code'] == 'koudgemaakte-kok')  ) {
  5991.  
  5992.                 foreach($rel_location_game_values as $location_game): ?>
  5993.                     <tr>
  5994.                         <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
  5995.                         <td>&euro;<?php print ( !empty($location_game->game_price))       ? number_format((float)$location_game->game_price, 2, ',', '.') : '0,00'; ?> incl. BTW per persoon
  5996.                         </td>
  5997.                     </tr><?php
  5998.                 endforeach;
  5999.  
  6000.             } else {
  6001.  
  6002.                 foreach($rel_location_game_values as $location_game):
  6003.  
  6004.                     if ($game_values['game_code'] == 'food-en-fun-culi-spel') {
  6005.                         $diner_price = $location_values['diner_price_foodfun'];
  6006.                     } else {
  6007.                         $diner_price = $location_values['diner_price'];
  6008.                     }
  6009.                     ?>
  6010.                     <tr>
  6011.                         <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
  6012.                         <td> Diner  &euro;<?php print ( !empty($diner_price) ) ? number_format((float)$diner_price, 2, ',', '.') : '0,00'; ?>
  6013.                              + Spel &euro;<?php print ( !empty($location_game->game_price))       ? number_format((float)$location_game->game_price, 2, ',', '.')      : '0,00'; ?>
  6014.                              =      <strong>&euro;<?php
  6015.                                 if ( !empty($diner_price) && !empty($location_game->game_price) ) {
  6016.                                     $total_price =  (float)$diner_price + (float)$location_game->game_price;
  6017.                                     print number_format($total_price, 2, ',', '.');
  6018.                                 }
  6019.                              ?></strong> incl. BTW p.p.
  6020.                         </td>
  6021.                     </tr><?php
  6022.                 endforeach;
  6023.             } ?>
  6024.  
  6025.             </table> <?php
  6026.             break;
  6027.  
  6028.         case 'location_games_totalprice':
  6029.             // first get the lowest game price
  6030.             if (isset($rel_location_game_values)):
  6031.                 $lowest_price = 9999.99;
  6032.                 foreach($rel_location_game_values as $location_game):
  6033.                     if ($location_game->game_price < $lowest_price) $lowest_price = $location_game->game_price;
  6034.                 endforeach;
  6035.                 if ($lowest_price == 9999.99) $lowest_price = 0.00;
  6036.  
  6037.                     if ($game_values['game_code'] == 'food-en-fun-culi-spel') {
  6038.                         $diner_price = $location_values['diner_price_foodfun'];
  6039.                     } else {
  6040.                         $diner_price = $location_values['diner_price'];
  6041.                     }
  6042.  
  6043.                 $total_price =  (float)$diner_price + (float)$lowest_price;
  6044.                 print number_format($total_price, 2, ',', '.');
  6045.             endif;
  6046.             break;
  6047.  
  6048.  
  6049.         // SHOW LINKS TO DOCUMENTS
  6050.         case 'conditions_document':
  6051.         case 'booking_conditions_file':
  6052.             $array_documents = explode(' ', $field);
  6053.             foreach($array_documents as $document_url):
  6054.                 if (!empty($document_url)) {
  6055.                     // get the name without the path
  6056.                     $arr_docpath = explode('/', $document_url);
  6057.                     $docname = str_replace('.pdf', '', end($arr_docpath) );
  6058.                     ?>
  6059.                     <div><a href="<?php echo $document_url; ?>" target="_blank">
  6060.                         <img src="<?php print home_url(); ?>/wp-content/uploads/2016/04/pdf_icon.jpg" align="middle" />  <?php echo $docname; ?>
  6061.                     </a></div>
  6062.                 <?php
  6063.                 }
  6064.             endforeach;
  6065.             break;
  6066.  
  6067.         case 'game_documents':
  6068.             $array_documents = explode(' ', $field);
  6069.             foreach($array_documents as $document_url):
  6070.                 if (!empty($document_url)) {
  6071.                     // get the name without the path
  6072.                     $arr_docpath = explode('/', $document_url);
  6073.                     $docname = str_replace('.pdf', '', end($arr_docpath) );
  6074.                     ?>
  6075.                     <div>
  6076.                         <a href="<?php echo $document_url; ?>" target="_blank"><?php echo $docname; ?></a>
  6077.                     </div>
  6078.                 <?php
  6079.                 }
  6080.             endforeach;
  6081.             break;
  6082.  
  6083.  
  6084.         case 'location_coordinates' :
  6085.         case 'town_coordinates' :
  6086.  
  6087.             $json_geolocation       = $field;
  6088.             $obj_googlemapcoords    = json_decode($json_geolocation);
  6089.             ?>
  6090.             <div class="google-map-container">
  6091.                 <div class="google-map" id="google-map"></div>
  6092.                 <input type="hidden" class="map-latitude" value="<?php print $obj_googlemapcoords->lat; ?>" />
  6093.                 <input type="hidden" class="map-longitude" value="<?php print $obj_googlemapcoords->lng; ?>" />
  6094.                 <input type="hidden" class="map-zoom" value="14" />
  6095.                 <input type="hidden" class="map-description" value="<?php print $location_values["location_name"].', '.$location_values['address_1']; ?>" />
  6096.             </div>
  6097.             <?php
  6098.             break;
  6099.  
  6100.         case 'tag_text_town' :
  6101.  
  6102.             if ($town_locations_games_values) $field = insertrandomlocation($field, $town_locations_games_values);
  6103.             if ($town_locations_games_values) $field = insertrandomlocationgame($field, $town_locations_games_values);
  6104.  
  6105.             $field = str_replace('[plaats]', $town_values['town_name'], $field);
  6106.             $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
  6107.             print wpautop($field);
  6108.             break;
  6109.  
  6110.         case 'game_short_descr_tag' :
  6111.             //if ($tag_values['single_plural'] == 'Meervoudsvorm') {
  6112.                 $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
  6113.             //} else {
  6114.               //  $field = str_replace('[trefwoord]', 'een '.$tag_values['tag_name'], $field);
  6115.             //}
  6116.             print wpautop($field);
  6117.             break;
  6118.  
  6119.         case 'game_text_town_tag_location' :
  6120.  
  6121.             if ($town_locations_games_values) $field = insertrandomlocation($field, $town_locations_games_values);
  6122.  
  6123.             $field = str_replace('[plaats]', $town_values['town_name'], $field);
  6124.             $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
  6125.             print wpautop($field);
  6126.             break;
  6127.  
  6128.         case 'game_text_town' :
  6129.             $field = str_replace('[plaats]', $town_values['town_name'], $field);
  6130.             print wpautop($field);
  6131.             break;
  6132.  
  6133.         case 'game_text_town_location' :
  6134.           $field = str_replace('[plaats]', $town_values['town_name'], $field);
  6135.           $field = str_replace('[locatie]', $location_values['location_name'], $field);
  6136.           print wpautop($field);
  6137.           break;
  6138.  
  6139.         case 'game_text_town_own_location' :
  6140.           $field = str_replace('[plaats]', $town_values['town_name'], $field);
  6141.           print wpautop($field);
  6142.           break;
  6143.  
  6144.         case 'back_print_buttons' :
  6145.           return '<p>&nbsp;</p>';
  6146.           break;
  6147.  
  6148.  
  6149.  
  6150.         case 'home_values' :
  6151.  
  6152.           // if home page, provide data for the google map and towns to show
  6153.           $home_values = array();
  6154.           if (is_page() && is_front_page()) {
  6155.  
  6156.                 //--------------------------------------------------------------------------------------
  6157.                 //  namen van de plaatsen (met link)  -  center panel
  6158.                 $params = array(
  6159.                   'select'    => ' town_code, town_name, town_coordinates, town_images.guid as town_images  ',
  6160.                   'limit'     => 0
  6161.                 );
  6162.                 $home_towns_pod = pods( 'towns', $params );
  6163.                 if ( $home_towns_pod->total() > 0 ) {
  6164.  
  6165.  
  6166.               // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
  6167.               $home_values["town_coordinates"] = '[';
  6168.               $home_prev_town_code = '';
  6169.  
  6170.                     while ($home_towns_pod->fetch() ) {
  6171.  
  6172.                         $home_row = $home_towns_pod->row();
  6173.  
  6174.                         // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
  6175.                         // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN, GET THE FIRST ONE OF EACH
  6176.  
  6177.                         if ($home_row['town_code'] != $home_prev_town_code) {
  6178.  
  6179.                             // FIRST ROW FOR THIS TOWN
  6180.                             $home_prev_town_code = $home_row['town_code'];
  6181.  
  6182.                             $home_values["towns"][] = $home_row;
  6183.  
  6184.                             // collect the names of restaurants in this town, to be shown on hover over map flags
  6185.                             $params = array(
  6186.                                 'select'    => 't.id as location_id,
  6187.                                                t.location_name,
  6188.                                                t.location_code
  6189.                                               ',
  6190.  
  6191.  
  6192.                                 'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
  6193.  
  6194.  
  6195.  
  6196.                                 'where'     => " town.town_code = '".$home_row['town_code']."'" ,
  6197.                                 'orderby'     => 'location_name',
  6198.                                 'limit'     => 0
  6199.                             );
  6200.  
  6201.                             $home_locations_pod = pods( 'locations', $params );
  6202.                             $home_locations_pod_total = $home_locations_pod->total();
  6203.  
  6204.                             if ( $home_locations_pod_total > 0 ):
  6205.  
  6206.                                 $home_text_locations_per_town = '';
  6207.                                 while ($home_locations_pod->fetch() ):
  6208.                                     $home_row2 = $home_locations_pod->row();
  6209.                                     $home_text_locations_per_town .= '\r\n - '.$home_row2['location_name'];
  6210.                                 endwhile;
  6211.  
  6212.  
  6213.                                 if (isset($home_row['town_coordinates']) && !empty($home_row['town_coordinates']) ) {
  6214.  
  6215.                     $home_json_geolocation    = $home_row['town_coordinates'];
  6216.                     $home_obj_googlemapcoords = json_decode($home_json_geolocation);
  6217.    
  6218.                                     if (!empty($home_obj_googlemapcoords->lat) && !empty($home_obj_googlemapcoords->lng)  ) {
  6219.                       $town_name          = $home_row['town_name'];
  6220.                       $town_code          = $home_row['town_code'];
  6221.                       $town_country       = $home_row['country'];
  6222.                       $info               = htmlspecialchars($town_name, ENT_QUOTES,'UTF-8');
  6223.                       $info              .= (!empty($town_country)) ? ', '.htmlspecialchars($town_country, ENT_QUOTES,'UTF-8') : '';
  6224.                                         $info              .= $home_text_locations_per_town;
  6225.                                         $url                =  $town_code;
  6226.                                         $home_values["town_coordinates"] .= $comma . "
  6227.                                         [".$home_obj_googlemapcoords->lat.", ".$home_obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
  6228.                                         $comma=", ";
  6229.                                     }
  6230.                                 }
  6231.  
  6232.  
  6233.                 endif;
  6234.  
  6235.  
  6236.  
  6237.  
  6238.                         } else {
  6239.                             // MUST BE MULTIPLE ROWS FOR SAME TOWN, DIFFER ONLY RE. FIELD 'TOWN_IMAGES'
  6240.  
  6241.                         }
  6242.  
  6243.  
  6244.                     }
  6245.                     $home_values["town_coordinates"] .= '
  6246.                ]';
  6247.                 }
  6248.  
  6249.             //--------------------------------------------------------------------------------------
  6250.             //  text for the right panel
  6251.             $row = $wpdb->get_col("SELECT all_towns FROM wp_pods_general_content " );
  6252.             $home_values['home_towns_text_value'] = $row[0];
  6253.             return $home_values;
  6254.             }
  6255.  
  6256.  
  6257.           break;
  6258.  
  6259.  
  6260.  
  6261.  
  6262.         default:
  6263.             // just show the text, with wp line breaks
  6264.             print wpautop($field);
  6265.             break;
  6266.     }
  6267.  
  6268.     $temp_content = ob_get_contents();
  6269.     ob_end_clean();
  6270.     return $temp_content;
  6271. }
  6272.  
  6273. //-------------------------------------------------------------------------
  6274. function insertrandomlocation($field, $town_locations_games_values) {
  6275. //-------------------------------------------------------------------------
  6276.  
  6277.     // collect the location names for this town in array_location_names
  6278.     $array_random_location_names = array();
  6279.     foreach ($town_locations_games_values as $key => $locations_games_values) {
  6280.         //$array_location_names[$locations_games_values['location_name']] = $locations_games_values['location_name'];
  6281.         array_push($array_random_location_names, $locations_games_values['location_name']);
  6282.     }
  6283.     // randomize
  6284.     shuffle($array_random_location_names);
  6285.  
  6286.     // split the text up in parts separated by '[location]'
  6287.     // then join them together again, inserting a random location_name from array_location_names
  6288.     $location_indexes = explode('[locatie]', $field);
  6289.     $field = "";
  6290.     foreach ($location_indexes as $k=>$v) {
  6291.         $field .= $v;
  6292.         if ($k != count($location_indexes) - 1) {
  6293.  
  6294.             if ($array_random_location_names[$k] == 'Eigen locatie') $array_random_location_names[$k] = 'uw eigen locatie';
  6295.  
  6296.             $field .= $array_random_location_names[$k];
  6297.         }
  6298.     }
  6299.  
  6300.     // split the text up in parts separated by '[opsomming]'
  6301.     // then join them together again, inserting all random location_names from array_location_names
  6302.     // first create the string of location names:
  6303.  
  6304.     $opsomming='';
  6305.     $comma='';
  6306.     foreach ($array_random_location_names as $key => $value) {
  6307.         if ($value == 'Eigen locatie') $value = 'uw eigen locatie';
  6308.         $opsomming .= $comma.'<strong>'.$value.'</strong>';
  6309.         $comma= ', ';
  6310.     }
  6311. //print "<br />opsomming: ".$opsomming;
  6312.     $location_indexes = explode('[opsomming]', $field);
  6313.     $field = "";
  6314.     foreach ($location_indexes as $k=>$v) {
  6315.         $field .= $v;
  6316.         if ($k != count($location_indexes) - 1) {
  6317.             $field .= $opsomming;
  6318.         }
  6319.     }
  6320.  
  6321.     return $field;
  6322. }
  6323.  
  6324. //-------------------------------------------------------------------------
  6325. function insertrandomlocationgame($field, $town_locations_games_values) {
  6326. //-------------------------------------------------------------------------
  6327.  
  6328.     // collect the location name / game name combinations for this town in array_location_names
  6329.     $array_random_location_games_names = array();
  6330.     foreach ($town_locations_games_values as $key => $locations_games) {
  6331.         if ($locations_games['location_name'] && $locations_games['location_name'] != 'Eigen locatie') {
  6332.             $array_random_location_games_names[$locations_games['location_name']][] = $locations_games['location_name'];
  6333.             if (isset($locations_games['location_games'])) {
  6334.                 foreach ($locations_games['location_games'] as $key => $value) {
  6335.                     if ($value['game_name'] != 'Hollandse Helden') {
  6336.                         $array_random_location_games_names[$locations_games['location_name']][] = $value['game_name'];
  6337.                     }
  6338.                 }
  6339.             }
  6340.         }
  6341.     }
  6342.  
  6343.     // array now looks like this:
  6344.     /*
  6345.     array_random_location_games_names:
  6346.     Array
  6347.     (
  6348.         [0] => Array
  6349.             (
  6350.                 [0] => Restaurant Gusto Garbon
  6351.                 [1] => Moordvlucht Moordspel
  6352.                 [2] => Miss Murder Moordspel
  6353.                 [3] => Flight Murder Mystery Game
  6354.             )
  6355.     */
  6356.  
  6357.  
  6358.     // create a new array for all possible combinations of restaurants and games
  6359.     $array_random_location_games_strings = array();
  6360.     foreach ($array_random_location_games_names as $key1 => $location_games) {
  6361.  
  6362.  
  6363.         // build a string for each game + same location name
  6364.         foreach ($location_games as $key2 => $value) {
  6365.  
  6366.  
  6367.             if ($key2 > 0) {
  6368.  
  6369.                 $string_location_games = $location_games[$key2];
  6370.                 if ($location_games[0] != 'Eigen locatie' && $location_games[0] != 'Hollandse Helden') {
  6371.                     $string_location_games .= ' in '.$location_games[0];
  6372.                     $array_random_location_games_strings[] = $string_location_games;
  6373.                 }
  6374.             }
  6375.         }
  6376.     }
  6377.  
  6378.     // randomize
  6379.     shuffle($array_random_location_games_strings);
  6380.  
  6381.     // split the text up in parts separated by '[game-location]'
  6382.     // then join them together again, inserting a random location_name from array_random_location_games_names
  6383.     $location_indexes = explode('[spel-locatie]', $field);
  6384.     $field = "";
  6385.     foreach ($location_indexes as $k=>$v) {
  6386.         if ($v != 'Eigen locatie' && $v != 'Hollandse Helden') {
  6387.             $field .= $v;
  6388.             if ($k != count($location_indexes) - 1) {
  6389.                 $field .= $array_random_location_games_strings[$k];
  6390.             }
  6391.         }
  6392.     }
  6393.  
  6394.  
  6395.     // split the text up in parts separated by '[opsomming]'
  6396.     // then join them together again, inserting all random location_games_names from array_location_names
  6397.     // first create the string of location names:
  6398.  
  6399.     $opsomming='';
  6400.     $comma='';
  6401.     foreach ($array_random_location_games_names as $key => $value) {
  6402.         $opsomming .= $comma.'<strong>'.$value.'</strong>';
  6403.         $comma= ', ';
  6404.     }
  6405. //print "<br />opsomming: ".$opsomming;
  6406.     $location_indexes = explode('[opsomming]', $field);
  6407.     $field = "";
  6408.     foreach ($location_indexes as $k=>$v) {
  6409.         $field .= $v;
  6410.         if ($k != count($location_indexes) - 1) {
  6411.             $field .= $opsomming;
  6412.         }
  6413.     }
  6414.  
  6415.     return $field;
  6416. }
  6417.  
  6418.  
  6419. //================================================================
  6420. function generate_sitemap_urls() {
  6421.  
  6422.     global  $wpdb;
  6423.  
  6424.     $array_towns = $wpdb->get_col( "SELECT town_code FROM wp_pods_towns " );
  6425.  
  6426.     $arr_urls = array();
  6427.     // get all game codes
  6428.     $params = array(
  6429.       'select'    => ' t.* ',
  6430.       'limit'     => 0
  6431.     );
  6432.     $games_pod = pods( 'games', $params );
  6433.     if ( $games_pod->total() > 0 ) {
  6434.  
  6435.         while ($games_pod->fetch() ) {
  6436.  
  6437.             $game_code = $games_pod->display( 'game_code' );
  6438.             $str_tags = $games_pod->display( 'game_tags' );
  6439.             $arr_tags = $games_pod->field( 'game_tags' );
  6440.             if ($arr_tags) foreach($arr_tags as $tag) {
  6441.                 if (!empty($tag['tag_name']) && !in_array($tag['tag_name'], $arr_urls)) {
  6442.                     // this tag has not yet been added as a url
  6443.                     $arr_urls[] = $tag['tag_name'];
  6444.                 }
  6445.             }
  6446.  
  6447.             // get all locations where this game is played, which also provides the towns for the url
  6448.             $params = array(
  6449.                 'select'    => ' t.location_code, town.town_code ',
  6450.                 'join'      => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
  6451.                                 INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1)  ',
  6452.                 'where'     => " game_code = '".$game_code."' ",
  6453.                 'limit'     => 0
  6454.             );
  6455.  
  6456.             if (!empty($game_code)) {
  6457.                 $arr_urls[] = $game_code;
  6458.             }
  6459.  
  6460.             $locations_pod = pods( 'locations', $params );
  6461.             if ( $locations_pod->total() > 0 ) {
  6462.                 while ($locations_pod->fetch() ) {
  6463.  
  6464.                     $town_code = $locations_pod->display( 'town_code' );
  6465.  
  6466.                     $town_code_url = $town_code;
  6467.                     if (!empty($town_code) && !in_array($town_code_url, $arr_urls)) {
  6468.                         // this town_code_url has not yet been added as a url
  6469.                         $arr_urls[] = $town_code_url;
  6470.                     }
  6471.  
  6472.                     if (!empty($town_code) && !in_array( $game_code."/".$town_code, $arr_urls)) {
  6473.                         $arr_urls[] = $game_code."/".$town_code;
  6474.                     }
  6475.  
  6476.                     $location_code = $locations_pod->display( 'location_code' );
  6477.                     if (!empty($town_code) &&  !empty($location_code) && $location_code <> 'eigen-locatie' && !in_array( $game_code."/".$town_code."/".$location_code, $arr_urls)) {
  6478.                         $arr_urls[] = $game_code."/".$town_code."/".$location_code;
  6479.                     }
  6480.  
  6481.                     if (!empty($game_code) && $location_code == 'eigen-locatie' && !in_array( $game_code."/eigen-locatie", $arr_urls)) {
  6482.                         $arr_urls[] = $game_code."/eigen-locatie";
  6483.  
  6484.                         //  if game can be played in eigen locatie, then add this url for all towns as well
  6485.                         foreach($array_towns as $town_code) {
  6486.                             if (!in_array( $game_code."/".$town_code."/eigen-locatie", $arr_urls)) {
  6487.                                 $arr_urls[] = $game_code."/".$town_code."/eigen-locatie";
  6488.                             }
  6489.                         }
  6490.  
  6491.                     }
  6492.  
  6493.                     if (!empty($town_code) &&  !empty($location_code) && $location_code <> 'eigen-locatie' && !in_array( $town_code."/".$location_code, $arr_urls)) {
  6494.                         $arr_urls[] = $town_code."/".$location_code;
  6495.                     }
  6496.  
  6497.                     if ($arr_tags) foreach($arr_tags as $tag) {
  6498.                         $tag_town_url = $tag['tag_name'].'/'.$town_code;
  6499.                         if (!empty($tag['tag_name']) && !empty($town_code) && !in_array($tag_town_url, $arr_urls)) {
  6500.                             // this tag_town_url has not yet been added as a url
  6501.                             $arr_urls[] = $tag_town_url;
  6502.                         }
  6503.                     }
  6504.                 }
  6505.             }
  6506.         }
  6507.     }
  6508.     sort($arr_urls );
  6509.  
  6510.     return $arr_urls;
  6511. }
  6512.  
  6513.  
  6514.  
  6515.  
  6516. //================================================================================
  6517. // CRON ACTION FOR "ONCE hourly" EVENTS
  6518. //================================================================================
  6519. add_action('custom_hourly_event', 'do_this_hourly');
  6520.  
  6521. function do_this_hourly() {
  6522.  
  6523.     //error_log('**************** do_this_hourly ');
  6524.  
  6525.     // SEND REMINDERS TO LOCATIONS THAT STILL HAVE NOT RESPONDED
  6526.     send_reminder_to_location();
  6527.     send_reminder_to_dinerspel();
  6528.     send_reminder_to_client();
  6529.  
  6530.  
  6531.     //--------------------------------------------------------------------------------------------
  6532.     // SEND_WEEKLY_REPORT_TO_LOCATION(), EVERY NIGHT WEDNESDAY on thursday
  6533.     //--------------------------------------------------------------------------------------------
  6534.     // Check that the hour is Thursday morning between 0 and 2
  6535.     $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  6536.  
  6537.     $day = $currlocaldatetime->format('N');
  6538.     $hour = $currlocaldatetime->format('H');
  6539.  
  6540.     if($day == 4 && $hour > 0 && $hour < 2)
  6541.     {
  6542.  
  6543.         send_weekly_report_to_location();
  6544.     } else {
  6545.  
  6546.     }
  6547.  
  6548. }
  6549.  
  6550.                   //================================================================================
  6551.                   // CRON ACTION FOR "ONCE WEEKLY" EVENTS
  6552.                   //================================================================================
  6553.                   ///////////////////////////////////////////   add_action('custom_weekly_event', 'do_this_weekly');
  6554.                   // function do_this_weekly() {
  6555.                   //   // error_log('**************** custom_weekly_event ');
  6556.                   // }
  6557.  
  6558.  
  6559.  
  6560. // RUN THE SITEMAP SCRIPT AT LEAST ONCE A DAY:
  6561. //================================================================================
  6562. // CRON ACTION FOR "ONCE DAILY" EVENTS
  6563. //================================================================================
  6564. add_action('custom_daily_event', 'do_this_daily');
  6565. function do_this_daily() {
  6566.  
  6567.     //error_log('**************** custom_daily_event ');
  6568.  
  6569.     global $wpdb;
  6570.  
  6571.     // BUILD THE SITEMAP AT LEAST ONCE A DAY:
  6572.     // ------------------------------------------------------------
  6573.  
  6574.     $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  6575.     $now = $currlocaldatetime->format('Y-m-d H:i:s');
  6576.  
  6577.     require_once(dirname(__FILE__) . "/Sitemap.php");
  6578.     $sitemap = new Sitemap;
  6579.  
  6580.     $ignore_urls = array(
  6581.       'vragen',
  6582.       'fout-pagina'
  6583.     );
  6584.     $static_urls = array(
  6585.         'spellen',
  6586.         'plaatsen',
  6587.         'contact',
  6588.         'webshop'
  6589.         );
  6590.  
  6591.     $rows = $wpdb->get_results( "
  6592.        SELECT  post_name
  6593.          FROM  wp_posts p
  6594.         INNER  JOIN
  6595.                wp_postmeta pm ON (
  6596.                    pm.post_id = p.id
  6597.                    AND post_type = 'page'
  6598.                    AND meta_key = '_wp_page_template'
  6599.                )
  6600.         ORDER BY post_name"
  6601.       );
  6602.     foreach ( $rows as $row ) {
  6603.         $pagename = $row->post_name;
  6604.         if (!empty($pagename) && !in_array( $pagename, $static_urls) && !in_array( $pagename, $ignore_urls) ) {
  6605.             $static_urls[] = $pagename;
  6606.         }
  6607.     }
  6608.  
  6609.     foreach($static_urls as $url) {
  6610.         $sitemap->url($url, $now, 'monthly');
  6611.     }
  6612.  
  6613.     $arr_urls = generate_sitemap_urls();
  6614.     foreach($arr_urls as $url) {
  6615.         $sitemap->url($url, $now, 'monthly');
  6616.     }
  6617.     $sitemap->close();
  6618.     unset ($sitemap);
  6619.  
  6620. }
  6621.  
  6622.  
  6623.  
  6624. //==================================================================
  6625. // SEND REMINDERS TO LOCATIONS THAT STILL HAVE NOT RESPONDED 48 HOURS
  6626. // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_HOURLY)
  6627.  
  6628. function send_reminder_to_location() {
  6629.  
  6630.     //error_log('**************** send_reminder_to_location ');
  6631.     global $wpdb;
  6632.  
  6633. // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
  6634.  
  6635. $sql = "SELECT * FROM  wp_pods_aanvragen
  6636.          WHERE code_locatie <> ''
  6637.            AND location_code <> 'eigen-locatie'
  6638.            AND created < DATE_SUB(NOW(), INTERVAL 48 HOUR)
  6639.            AND (date_48_hours_email_sent  IS NULL
  6640.                 OR date_48_hours_email_sent = '0000-00-00 00:00:00')
  6641.        ";
  6642. //error_log('**************** sql ******************* ');
  6643. //error_log(print_r($sql,true));
  6644.  
  6645.  
  6646.     $rows = $wpdb->get_results(
  6647.         "SELECT * FROM  wp_pods_aanvragen
  6648.          WHERE code_locatie <> ''
  6649.            AND location_code <> 'eigen-locatie'
  6650.            AND created < DATE_SUB(NOW(), INTERVAL 48 HOUR)
  6651.            AND (date_48_hours_email_sent  IS NULL
  6652.                 OR date_48_hours_email_sent = '0000-00-00 00:00:00')
  6653.        ", ARRAY_A);
  6654.     if ( $rows ) {
  6655.         foreach ($rows as $row) {
  6656.             // send email
  6657.  
  6658.             // create certain allowed variables from $arr_aanvraag[0]
  6659.             foreach ($row as $key => $value) {
  6660.                 $$key = $value;
  6661.             }
  6662.             $aanvraag_id = $id;
  6663.             $achternaam = ucwords($name);
  6664.             $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  6665.             $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  6666.  
  6667.             // check if perhaps ZELFSTANDIGE LOCATIE
  6668.             $sql = $wpdb->prepare("SELECT zelfstandige_locatie, email_address FROM  wp_pods_locations
  6669.                       WHERE location_code = %s", $location_code);
  6670.             $location_row = $wpdb->get_row($sql, ARRAY_A);
  6671.             $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  6672.             $location_email = $location_row['email_address'];
  6673.  
  6674.             $game_name = ucwords(str_replace('-', ' ', $game_code) );
  6675.             $town_name = ucwords(str_replace('-', ' ', $town_code) );
  6676.             $location_name = ucwords(str_replace('-', ' ', $location_code) );
  6677.             $website = 'Dinerspel.nl';
  6678.             $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  6679.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  6680.  
  6681.             //----------------------------------
  6682.             // stuur HERINNERING naar LOCATIE
  6683.             //----------------------------------
  6684.             if (!empty($location_email)) {
  6685.                 $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  6686.                 $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  6687.  
  6688.                 ob_start();
  6689.                 if ($zelfstandige_locatie) {
  6690.                     include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
  6691.                 } else {
  6692.                     include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
  6693.                 }
  6694.                 $temp_content = ob_get_contents();
  6695.                 ob_end_clean();
  6696.                 $message = $temp_content;
  6697.  
  6698.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  6699.             $mailresult = wp_mail( $location_email, 'HERINNERING (48 UUR): Nieuwe beschikbaarheid via '.$website, $message);
  6700. error_log('************** wp_mail( '.$location_email.',   HERINNERING (48 UUR): Nieuwe beschikbaarheid via... );  MAILRESULT: '.$mailresult);
  6701.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  6702.  
  6703.                 // set date flag to indicate this email has been sent
  6704.                 $sql = "
  6705.                    UPDATE wp_pods_aanvragen
  6706.                       SET modified = NOW(),
  6707.                           date_48_hours_email_sent = NOW()
  6708.                     WHERE id = ".$aanvraag_id;
  6709.                 $updres = $wpdb->get_results( $sql );
  6710.             }
  6711.         }
  6712.     }
  6713. }
  6714.  
  6715.  
  6716.  
  6717. //==================================================================
  6718. // SEND REMINDERS TO DINERSPEL IF LOCATIONS STILL HAVE NOT RESPONDED AFTER 72 HOURS
  6719. // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY()
  6720.  
  6721. function send_reminder_to_dinerspel() {
  6722.  
  6723.     //error_log('**************** send_reminder_to_DINERSPEL ');
  6724.     global $wpdb;
  6725.  
  6726. // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
  6727.  
  6728.     // $rows = $wpdb->get_results(
  6729.     //     "SELECT * FROM  wp_pods_aanvragen
  6730.     //       WHERE code_locatie <> ''
  6731.     //         AND location_code <> 'eigen-locatie'
  6732.     //         AND created < DATE_SUB(NOW(), INTERVAL 72 HOUR)
  6733.     //         AND (date_72_hours_email_sent  IS NULL
  6734.     //              OR date_72_hours_email_sent = '0000-00-00 00:00:00')
  6735.     //     ", ARRAY_A);
  6736.  
  6737. $sql = "SELECT * FROM  wp_pods_aanvragen
  6738.          WHERE code_locatie > ''
  6739.            AND location_code > ''
  6740.            AND location_code <> 'eigen-locatie'
  6741.            AND created < DATE_SUB(NOW(), INTERVAL 72 HOUR)
  6742.            AND (date_72_hours_email_sent  IS NULL
  6743.                 OR date_72_hours_email_sent = '0000-00-00 00:00:00')
  6744.        ";
  6745.  
  6746.     $rows = $wpdb->get_results($sql, ARRAY_A);
  6747.     if ( $rows ) {
  6748.         foreach ($rows as $row) {
  6749.             // send email
  6750.  
  6751.             // create certain allowed variables from $arr_aanvraag[0]
  6752.             foreach ($row as $key => $value) {
  6753.                 $$key = $value;
  6754.             }
  6755.             $aanvraag_id = $id;
  6756.  
  6757.             $achternaam = ucwords($name);
  6758.             $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  6759.             $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  6760.  
  6761.             // check if perhaps ZELFSTANDIGE LOCATIE
  6762.             $sql = $wpdb->prepare("SELECT zelfstandige_locatie, email_address FROM  wp_pods_locations
  6763.                       WHERE location_code = %s", $location_code);
  6764.             $location_row = $wpdb->get_row($sql, ARRAY_A);
  6765.             $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  6766.             $location_email = $location_row['email_address'];
  6767.  
  6768.             $game_name = ucwords(str_replace('-', ' ', $game_code) );
  6769.             $town_name = ucwords(str_replace('-', ' ', $town_code) );
  6770.             $location_name = ucwords(str_replace('-', ' ', $location_code) );
  6771.             $website = 'Dinerspel.nl';
  6772.             $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  6773.             $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  6774.  
  6775.             //----------------------------------
  6776.             // stuur HERINNERING naar DINERSPEL
  6777.             //----------------------------------
  6778.             $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
  6779.             $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
  6780.  
  6781.             ob_start();
  6782.             if ($zelfstandige_locatie) {
  6783.                 include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
  6784.             } else {
  6785.                 include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
  6786.             }
  6787.             $temp_content = ob_get_contents();
  6788.             ob_end_clean();
  6789.             $message = $temp_content;
  6790.  
  6791.             add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  6792.             $mailresult = wp_mail( get_option('admin_email'), 'HERINNERING (72 UUR): Nieuwe beschikbaarheid via '.$website, $message);
  6793. error_log('************** wp_mail('.get_option(admin_email).',   HERINNERING (72 UUR): Nieuwe beschikbaarheid via... );  MAILRESULT: '.$mailresult);
  6794.             remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  6795.  
  6796.             // set date flag to indicate this email has been sent
  6797.             $sql = "
  6798.                UPDATE wp_pods_aanvragen
  6799.                   SET modified = NOW(),
  6800.                       date_72_hours_email_sent = NOW()
  6801.                 WHERE id = ".$aanvraag_id;
  6802.             $updres = $wpdb->get_results( $sql );
  6803.  
  6804. }
  6805.     }
  6806. }
  6807.  
  6808.  
  6809.  
  6810. //==================================================================
  6811. // SEND REMINDERS TO CLIENTS THAT STILL HAVE NOT MADE A RESERVATION AFTER 7 DAYS
  6812. // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY()
  6813.  
  6814. /*
  6815. Email versturen als:
  6816.             # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
  6817.             # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
  6818.             # één of beide voorkeurdata moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
  6819.             # het niet een EL betreft:
  6820.             # het niet een ZL locatie is
  6821.             # het niet een doe-het-zelf spel betreft
  6822.             # er de laatste 7 dagen niets is gebeurd met de aanvraag
  6823.             # deze herinnering nog niet eerder is verzonden:
  6824. */
  6825.  
  6826.  
  6827.  
  6828. function send_reminder_to_client() {
  6829.  
  6830.   //error_log('**************** send_reminder_to_client ');
  6831.   global $wpdb;
  6832.  
  6833.  
  6834. // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
  6835.  
  6836.   $sql = "SELECT aanvr.id as aanvraag_id,  locs.id as location_id, aanvr.*, locs.*
  6837.           FROM wp_pods_aanvragen aanvr
  6838.     INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
  6839.          WHERE
  6840.            # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
  6841.            code_locatie = ''
  6842.  
  6843.            # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
  6844.            AND code_klant <> ''
  6845.  
  6846.            # één of beide datums moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
  6847.            AND ((voorkeursdatum_1_janee_locatie = 1 AND voorkeursdatum_1_janee_dinerspel = 1)
  6848.                OR
  6849.                 (voorkeursdatum_2_janee_locatie = 1 AND voorkeursdatum_2_janee_dinerspel = 1))
  6850.  
  6851.            # het niet een EL betreft:
  6852.            AND locs.location_code <> 'eigen-locatie'
  6853.  
  6854.            # het niet een ZL locatie is
  6855.            AND zelfstandige_locatie = 0
  6856.  
  6857.            # status is NIET
  6858.            AND action_status NOT IN ('Gereserveerd', 'Geen_interesse', 'Afgehandeld' )
  6859.  
  6860.            # het niet het doe-het-zelf spel betreft
  6861.            AND game_code <> 'onfortuinlijke-bankier'
  6862.            AND game_code <> 'mysterie-spel-back-to-school'
  6863.             AND game_code <> 'koudgemaakte-kok'
  6864.            AND game_code <> 'into-the-box'
  6865.  
  6866.            # laatste 7 dagen is er niets gebeurd met de aanvraag
  6867.            AND aanvr.modified < DATE_SUB(NOW(), INTERVAL 7 DAY)
  6868.  
  6869.            # deze herinnering is nog niet eerder verzonden:
  6870.            AND (date_7_days_email_sent  IS NULL
  6871.                 OR date_7_days_email_sent = '0000-00-00 00:00:00')
  6872.        ";
  6873.  
  6874.  
  6875.  
  6876.   $rows = $wpdb->get_results(
  6877.         "SELECT aanvr.id as aanvraag_id,  locs.id as location_id, aanvr.*, locs.*
  6878.           FROM wp_pods_aanvragen aanvr
  6879.     INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
  6880.          WHERE
  6881.            # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
  6882.            code_locatie = ''
  6883.  
  6884.            # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
  6885.            AND code_klant <> ''
  6886.  
  6887.            # één of beide datums moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
  6888.            AND ((voorkeursdatum_1_janee_locatie = 1 AND voorkeursdatum_1_janee_dinerspel = 1)
  6889.                OR
  6890.                 (voorkeursdatum_2_janee_locatie = 1 AND voorkeursdatum_2_janee_dinerspel = 1))
  6891.  
  6892.            # het niet een EL betreft:
  6893.            AND locs.location_code <> 'eigen-locatie'
  6894.  
  6895.            # het niet een ZL locatie is
  6896.            AND zelfstandige_locatie = 0
  6897.  
  6898.            # het niet het doe-het-zelf spel betreft
  6899.            AND game_code <> 'onfortuinlijke-bankier'
  6900.            AND game_code <> 'mysterie-spel-back-to-school'
  6901.             AND game_code <> 'koudgemaakte-kok'
  6902.            AND game_code <> 'into-the-box'
  6903.  
  6904.            # laatste 7 dagen is er niets gebeurd met de aanvraag
  6905.            AND aanvr.modified < DATE_SUB(NOW(), INTERVAL 7 DAY)
  6906.  
  6907.            # deze herinnering is nog niet eerder verzonden:
  6908.            AND (date_7_days_email_sent  IS NULL
  6909.                 OR date_7_days_email_sent = '0000-00-00 00:00:00')
  6910.        ",
  6911.  
  6912.         ARRAY_A);
  6913.  
  6914.   if ( $rows ) {
  6915.     foreach ($rows as $row) {
  6916.       // send email
  6917.  
  6918.       // create certain allowed variables from $arr_aanvraag[0]
  6919.       foreach ($row as $key => $value) {
  6920.           $$key = $value;
  6921.       }
  6922.       $emailadres_klant = $emailadres;
  6923.  
  6924.  
  6925.  
  6926.       // test
  6927.       /////$emailadres_klant = get_option('admin_email');
  6928.  
  6929.  
  6930.  
  6931.  
  6932.       $sql = $wpdb->prepare("
  6933.          SELECT zelfstandige_locatie, email_address, telephone, contactperson
  6934.            FROM wp_pods_locations
  6935.           WHERE location_code = %s", $location_code);
  6936.       $location_row = $wpdb->get_row($sql, ARRAY_A);
  6937.       $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
  6938.       $locatie_emailadres = $location_row['email_address'];
  6939.       $locatie_telefoon = $location_row['telephone'];
  6940.       $locatie_contactpersoon = $location_row['contactperson'];
  6941.  
  6942.       $game_name = ucwords(str_replace('-', ' ', $game_code) );
  6943.       $town_name = ucwords(str_replace('-', ' ', $town_code) );
  6944.       $location_name = ucwords(str_replace('-', ' ', $location_code) );
  6945.       $website = 'Dinerspel.nl';
  6946.  
  6947.       $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  6948.       $voornaam = ucfirst($voornaam);
  6949.       $achternaam = ucwords($name);
  6950.       //$geslacht = strtolower($geslacht);
  6951.  
  6952.       $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
  6953.       $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
  6954.  
  6955.         $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
  6956.         $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
  6957.  
  6958.         $url_msg = home_url().'/reserveren/'.$code_klant;
  6959.         $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
  6960.  
  6961.         $laatste_actie_was_een_week_geleden = true;
  6962.  
  6963.         ob_start();
  6964.  
  6965.         if ($zelfstandige_locatie) {
  6966.  
  6967.             continue;  // skip these, do not send them a reminder
  6968.  
  6969.         } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
  6970.  
  6971.             $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_locatie ;
  6972.             $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_locatie ;
  6973.  
  6974.             if ($voorkeursdatum_1_janee == 1 && $voorkeursdatum_2_janee == 1) {
  6975.                     include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
  6976.             }
  6977.             if ( ($voorkeursdatum_1_janee == 1 && $voorkeursdatum_2_janee ==  0) ||
  6978.                  ($voorkeursdatum_1_janee == 0 && $voorkeursdatum_2_janee ==  1) ) {
  6979.  
  6980.                     $date_1_or_2    = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? '1' : '2';
  6981.                     $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  6982.                     include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
  6983.             }
  6984.  
  6985.             if ($voorkeursdatum_1_janee == 0 && $voorkeursdatum_1_janee == 0)  {
  6986.                     include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
  6987.             }
  6988.  
  6989.         } elseif ($location_code == 'eigen-locatie') {
  6990.  
  6991.           $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_dinerspel ;
  6992.           $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_dinerspel ;
  6993.  
  6994.           $gameurltext = $game_name.' in eigen locatie';
  6995.           $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
  6996.  
  6997.           if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
  6998.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_data.php");
  6999.  
  7000.           if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ||
  7001.                ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee ==  '1') ) {
  7002.                   $date_1_or_2    = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? '1' : '2';
  7003.                   $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  7004.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_1_datum.php");
  7005.           }
  7006.  
  7007.           if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
  7008.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_niet.php");
  7009.  
  7010.         } else {
  7011.  
  7012.           $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_dinerspel ;
  7013.           $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_dinerspel ;
  7014.  
  7015.           if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1') {
  7016.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
  7017.           }
  7018.  
  7019.  
  7020.           if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ||
  7021.                ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee ==  '1') ) {
  7022.                   $date_1_or_2    = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? '1' : '2';
  7023.                   $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee ==  '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
  7024.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
  7025.           }
  7026.  
  7027.           if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0') {
  7028.                   include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
  7029.           }
  7030.  
  7031.         }
  7032.  
  7033.         $temp_content = ob_get_contents();
  7034.         ob_end_clean();
  7035.         $message = $temp_content;
  7036.         if (!empty($message)) {
  7037.           add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7038.           $mailresult = wp_mail($emailadres_klant, 'HERINNERING (NA 7 DAGEN): Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
  7039. error_log('************** wp_mail( '.$emailadres_klant.',  HERINNERING (NA 7 DAGEN): Beschikbaarheid m.b.t. uw aanvraag via... );  MAILRESULT: '.$mailresult);
  7040.           remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7041.  
  7042.  
  7043.  
  7044.           // set date flag to indicate this email has been sent
  7045.           $sql = "
  7046.              UPDATE wp_pods_aanvragen
  7047.                 SET modified = NOW(),
  7048.                     date_7_days_email_sent = NOW()
  7049.               WHERE id = ".$aanvraag_id;
  7050.           $updres = $wpdb->get_results( $sql );
  7051.         }
  7052.       }
  7053.     }
  7054. }
  7055.  
  7056.  
  7057.  
  7058.  
  7059.  
  7060.  
  7061. //==================================================================
  7062.  
  7063. function send_recensie_invite_to_client() {
  7064.  
  7065.     error_log('**************** send_recensie_invite_to_client ');
  7066.     global $wpdb;
  7067.  
  7068.     //  kan met de gewone wpdb
  7069.  
  7070.     $sql =
  7071.         "SELECT aanvr.id as aanvraag_id,  locs.id as location_id, aanvr.*, locs.*
  7072.           FROM wp_pods_aanvragen aanvr
  7073.     INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
  7074.          WHERE
  7075.            # klant heeft gereserveerd, dus code_klant is leeg:
  7076.            code_klant = ''
  7077.  
  7078.            # reserveringsdatum was gisteren
  7079.            AND aanvr.reserveringsdatum = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), '%Y-%m-%d')
  7080.  
  7081.            # deze herinnering is nog niet eerder verzonden:
  7082.            AND date_recensie_invite_email_sent = '0000-00-00 00:00:00'
  7083.  
  7084.    ORDER BY aanvr.reserveringsdatum DESC
  7085.        ";
  7086.  
  7087.     $rows = $wpdb->get_results($sql, ARRAY_A);
  7088.     if ( $rows ) {
  7089.       foreach ($rows as $row) {
  7090.         // send email
  7091.  
  7092.         // create certain allowed variables from $arr_aanvraag[0]
  7093.         foreach ($row as $key => $value) {
  7094.             $$key = $value;
  7095.         }
  7096.         $emailadres_klant = $emailadres;
  7097.  
  7098.  
  7099.         $website = 'Dinerspel.nl';
  7100.  
  7101.         $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
  7102.         $voornaam = ucfirst($voornaam);
  7103.         $achternaam = ucwords($name);
  7104.         //$geslacht = strtolower($geslacht);
  7105.  
  7106.         $url_msg = home_url().'/recensies/';
  7107.         $activate_link = '<a href="'.$url_msg.'">EEN RECENSIE PLAATSEN</a>';
  7108.  
  7109.         ob_start();
  7110.         include(dirname(__FILE__) . "/templates/tpl_email_recensie_invite.php");
  7111.         $temp_content = ob_get_contents();
  7112.         ob_end_clean();
  7113.         $message = $temp_content;
  7114.         if (!empty($message)) {
  7115.  
  7116.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7117.         $mailresult = wp_mail($emailadres_klant, 'Plaats uw recensie en Foto van de Maand', $message);
  7118. error_log('**************** wp_mail('.$emailadres_klant.', Uw unieke spelcode van Dinerspel.nl, message); MAILRESULT: '.$mailresult);
  7119.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7120.  
  7121.         // set date flag to indicate this email has been sent
  7122.         $sql = "
  7123.          UPDATE wp_pods_aanvragen
  7124.             SET modified = NOW(),
  7125.                 date_recensie_invite_email_sent = NOW()
  7126.           WHERE id = ".$aanvraag_id;
  7127.         $updres = $wpdb->get_results( $sql );
  7128.       }
  7129.     }
  7130.   }
  7131. }
  7132.  
  7133.  
  7134.  
  7135.  
  7136. //==================================================================
  7137. // SEND WEEKLY REPORT TO LOCATIONS ABOUT OUTSTANDING RESERVATIONS
  7138. // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY)
  7139.  
  7140. function send_weekly_report_to_location() {
  7141.  
  7142.   error_log('**************** send_weekly_report_to_location ');
  7143.  
  7144.   global $wpdb;
  7145.   $website = 'Dinerspel.nl';
  7146.   $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
  7147.   $vandaag = $currlocaldatetime->format('d-m-Y');
  7148.  
  7149.   $arr_selected_fields = array('reserveringsdatum', 'game_code', 'geslacht', 'name', 'tijd');
  7150.   $str_selected_fields = implode(", ", $arr_selected_fields);
  7151.   $arr_selected_field_labels = array('Reserveringsdatum', 'Spel', 'Klant', 'Tijd');
  7152.  
  7153.  
  7154.   // LOOP THRU ALL LOCAIONS EXCEPT EIGEN-LOCATIE
  7155.   $rows = $wpdb->get_results( "SELECT location_code, location_name, email_address
  7156.                                 FROM wp_pods_locations
  7157.                                WHERE location_code <> 'eigen-locatie'
  7158.  
  7159.  
  7160.                                  AND id IN (SELECT wp_pods_locations.id
  7161.                                               FROM wp_pods_locations
  7162.                                              INNER JOIN wp_rel_locations_games
  7163.                                                      ON (wp_pods_locations.id = wp_rel_locations_games.location_id  AND activated = 1)
  7164.                                            )
  7165.  
  7166.  
  7167.                              " );
  7168.  
  7169.   foreach ( $rows as $row ) {
  7170.  
  7171.     // COLLECT RESERVATIONS FROM BOTH DINERSPEL AND MOORDDINER FOR THIS LOCATION
  7172.  
  7173.     $location_code  = $row->location_code;
  7174.     $location_name  = $row->location_name;
  7175.     $location_email = $row->email_address;
  7176.  
  7177.     $sqlQuery = "SELECT ".$str_selected_fields."
  7178.                   FROM  wp_pods_aanvragen
  7179.                  WHERE reserveringsdatum >  DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))
  7180.                    AND action_status = 'Gereserveerd'
  7181.                    AND location_code = '".$location_code."'
  7182.                  ORDER BY reserveringsdatum
  7183.                ";
  7184.     $recordset1 = $wpdb->get_results( $sqlQuery, ARRAY_A );
  7185.  
  7186.  
  7187.     if (DB_HOST2 > ' ') {
  7188.  
  7189.         $remote_wpdb = new WPDB( DB_USER2, DB_PASSWORD2, DB_NAME2, DB_HOST2);
  7190.         $sqlQuery = "SELECT ".$str_selected_fields."
  7191.                       FROM  wp_pods_aanvragen
  7192.                      WHERE reserveringsdatum > DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))
  7193.                        AND action_status = 'Gereserveerd'
  7194.                        AND location_code = '".$location_code."'
  7195.                      ORDER BY reserveringsdatum
  7196.                    ";
  7197.         $recordset2 = $remote_wpdb->get_results( $sqlQuery, ARRAY_A );
  7198.     } else {
  7199.         $recordset2 = array();
  7200.     }
  7201.  
  7202.  
  7203.  
  7204.     $recordset = array_merge($recordset1, $recordset2);
  7205.  
  7206.     if ( empty($recordset) && !empty($location_email)) {
  7207.  
  7208.         ob_start();
  7209.         include(dirname(__FILE__) . "/templates/tpl_email_wekelijks_overzicht_naar_locatie.php");
  7210.         $message = ob_get_contents();
  7211.  
  7212.         $headers        = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
  7213.         get_header();
  7214.  
  7215.         ob_end_clean();
  7216.         add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7217.         if(wp_mail( $location_email, 'Openstaande reserveringen via '.$website, $message, $headers)) {
  7218.              error_log('************** wp_mail( '.$location_email.',   GEEN Openstaande reserveringen via... );  MAILRESULT: OK, sent');
  7219.         } else {
  7220.             error_log('************** wp_mail( '.$location_email.',  GEEN Openstaande reserveringen via... );  MAILRESULT: mail_error');
  7221.         };
  7222.         remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7223.  
  7224.         continue; // GO TO NEXT $row
  7225.     }
  7226.  
  7227.     if ( empty($location_email)) {
  7228.         continue; // GO TO NEXT $row
  7229.     }
  7230.  
  7231.     // BELOW FOR WHEN RECORDSET IS NOT EMPTY
  7232.  
  7233.     $sort = new SortMdArray;
  7234.     $sort->sortByKey($recordset);
  7235.  
  7236.     // CREATE LIST OF RESERVATIONS FOR THIS LOCATION
  7237.     ob_start();
  7238.     print '
  7239.    <table cellpadding="2" cellspacing="0">
  7240.        <tr>';
  7241.     foreach ($arr_selected_field_labels as $fieldlabel) {
  7242.         print '
  7243.            <th>'.$fieldlabel.'</th>';
  7244.     }
  7245.     print '
  7246.        </tr>';
  7247.  
  7248.  
  7249.     foreach ($recordset as $record) {
  7250.         print '
  7251.        <tr>';
  7252.         foreach ($record as $fieldname=> $fieldvalue) {
  7253.             if ($fieldname == 'geslacht') {
  7254.                 $aanhef = ($fieldvalue == 'Man') ? 'heer' : 'mevrouw';
  7255.  
  7256.             } elseif ($fieldname == 'name') {
  7257.                 print '
  7258.            <td>'.$aanhef.' '.utf8_decode($fieldvalue).'</td>';
  7259.  
  7260.             } elseif ($fieldname == 'reserveringsdatum') {
  7261.  
  7262.                 $dateObj = new DateTime($fieldvalue);
  7263.                 $dateformatted = $dateObj->format('d-m-Y');
  7264.                 print '
  7265.              <td>'.$dateformatted.'</td>';
  7266.  
  7267.             } else {
  7268.                 print '
  7269.              <td>'.$fieldvalue.'</td>';
  7270.             }
  7271.         }
  7272.         print '
  7273.        </tr>';
  7274.     }
  7275.     print '
  7276.    </table>';
  7277.  
  7278.     $div_report_table = ob_get_contents();
  7279.     ob_end_clean();
  7280.  
  7281.     //----------------------------------
  7282.     // stuur overzicht naar LOCATIE
  7283.     //----------------------------------
  7284.     ob_start();
  7285.     include(dirname(__FILE__) . "/templates/tpl_email_wekelijks_overzicht_naar_locatie.php");
  7286.     $message = ob_get_contents();
  7287.     ob_end_clean();
  7288.  
  7289.     add_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7290.     if(wp_mail( $location_email, 'Openstaande reserveringen via '.$website, $message)) {
  7291.          error_log('************** wp_mail( '.$location_email.',  X Openstaande reserveringen via... );  MAILRESULT: OK, sent');
  7292.     } else {
  7293.         error_log('************** wp_mail( '.$location_email.', X Openstaande reserveringen via... );  MAILRESULT: mail_error');
  7294.     };
  7295.     remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
  7296.  
  7297.   } // endif foreach array_locations
  7298.  
  7299. }
  7300.  
  7301. /**
  7302.  * VIES VAT number validation
  7303.  *
  7304.  * @author Eugen Mihailescu
  7305.  *
  7306.  * @param string $countryCode
  7307.  * @param string $vatNumber
  7308.  * @param int $timeout
  7309.  */
  7310. function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) {
  7311.  
  7312.   $response = array ();
  7313.   $pattern = '/<(%s).*?>([\s\S]*)<\/\1/';
  7314.   $keys = array (
  7315.           'countryCode',
  7316.           'vatNumber',
  7317.           'requestDate',
  7318.           'valid',
  7319.           'name',
  7320.           'address'
  7321.   );
  7322.  
  7323.   $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
  7324.  <s11:Body>
  7325.    <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'>
  7326.      <tns1:countryCode>%s</tns1:countryCode>
  7327.      <tns1:vatNumber>%s</tns1:vatNumber>
  7328.    </tns1:checkVat>
  7329.  </s11:Body>
  7330. </s11:Envelope>";
  7331.  
  7332.   $opts = array (
  7333.           'http' => array (
  7334.                   'method' => 'POST',
  7335.                   'header' => "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService",
  7336.                   'content' => sprintf ( $content, trim($countryCode), trim($vatNumber) ),
  7337.                   'timeout' => $timeout
  7338.           )
  7339.   );
  7340.  
  7341.   $ctx = stream_context_create ( $opts );
  7342.   $result = file_get_contents ( VIES_URL, false, $ctx );
  7343.  
  7344.   if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) {
  7345.       foreach ( $keys as $key )
  7346.           preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) && $response [$key] = $value [2];
  7347.   }
  7348.   return $response;
  7349. }
  7350.  
  7351.  
  7352. //----------------------------------------------------------------------------
  7353. function return_country_name($country_code) {
  7354.  
  7355.   $ountries = array(
  7356.     "AD" => "Andorra",
  7357.     "AE" => "Verenigde Arabische Emiraten",
  7358.     "AF" => "Afghanistan",
  7359.     "AG" => "Antigua en Barbuda",
  7360.     "AI" => "Anguilla",
  7361.     "AL" => "Albani&euml;",
  7362.     "AM" => "Armeni&euml;",
  7363.     "AO" => "Angola",
  7364.     "AQ" => "Antarctica",
  7365.     "AR" => "Argentini&euml;",
  7366.     "AS" => "Amerikaans-Samoa",
  7367.     "AT" => "Oostenrijk",
  7368.     "AU" => "Australi&euml;",
  7369.     "AW" => "Aruba",
  7370.     "AX" => "Γ…land",
  7371.     "AZ" => "Azerbeidzjan",
  7372.     "BA" => "Bosni&euml; en Herzegovina",
  7373.     "BB" => "Barbados",
  7374.     "BD" => "Bangladesh",
  7375.     "BE" => "Belgi&euml;",
  7376.     "BF" => "Faso Burkina Faso",
  7377.     "BG" => "Bulgarije",
  7378.     "BH" => "Bahrein",
  7379.     "BI" => "Burundi",
  7380.     "BJ" => "Benin",
  7381.     "BL" => "Saint-Bartholemy",
  7382.     "BM" => "Bermuda",
  7383.     "BN" => "Brunei",
  7384.     "BO" => "Bolivia",
  7385.     "BQ" => "Caribisch Nederland",
  7386.     "BR" => "Brazili&euml;",
  7387.     "BS" => "Bahama's",
  7388.     "BT" => "Bhutan",
  7389.     "BV" => "Bouveteiland",
  7390.     "BW" => "Botswana",
  7391.     "BY" => "Wit-Rusland",
  7392.     "BZ" => "Belize",
  7393.     "CA" => "Canada",
  7394.     "CC" => "Cocoseilanden",
  7395.     "CD" => "Congo-Kinshasa",
  7396.     "CF" => "Centraal-Afrikaanse Republiek",
  7397.     "CG" => "Congo-Brazzaville",
  7398.     "CH" => "Zwitserland",
  7399.     "CI" => "Ivoorkust",
  7400.     "CK" => "Cookeilanden",
  7401.     "CL" => "Chili",
  7402.     "CM" => "Kameroen",
  7403.     "CN" => "China",
  7404.     "CO" => "Colombia",
  7405.     "CR" => "Costa Rica",
  7406.     "CU" => "Cuba",
  7407.     "CV" => "Kaapverdi&euml;",
  7408.     "CW" => "CuraΓ§ao",
  7409.     "CX" => "Christmaseiland",
  7410.     "CY" => "Cyprus",
  7411.     "CZ" => "Tsjechi&euml;",
  7412.     "DE" => "Duitsland",
  7413.     "DJ" => "Djibouti",
  7414.     "DK" => "Denemarken",
  7415.     "DM" => "Dominica",
  7416.     "DO" => "Dominicaanse Republiek",
  7417.     "DZ" => "Algerije",
  7418.     "EC" => "Ecuador",
  7419.     "EE" => "Estland",
  7420.     "EG" => "Egypte",
  7421.     "EH" => "Westelijke Sahara",
  7422.     "ER" => "Eritrea",
  7423.     "ES" => "Spanje",
  7424.     "ET" => "Ethiopi&euml;",
  7425.     "FI" => "Finland",
  7426.     "FJ" => "Fiji",
  7427.     "FK" => "Falklandeilanden",
  7428.     "FM" => "Micronesia",
  7429.     "FO" => "FaerOer",
  7430.     "FR" => "Frankrijk",
  7431.     "GA" => "Gabon",
  7432.     "GB" => "Verenigd Koninkrijk",
  7433.     "GD" => "Grenada",
  7434.     "GE" => "Georgi&euml;",
  7435.     "GF" => "Frans-Guyana",
  7436.     "GG" => "Guernsey",
  7437.     "GH" => "Ghana",
  7438.     "GI" => "Gibraltar",
  7439.     "GL" => "Groenland",
  7440.     "GM" => "Gambia",
  7441.     "GN" => "Guinee",
  7442.     "GP" => "Guadeloupe",
  7443.     "GQ" => "Equatoriaal-Guinea",
  7444.     "GR" => "Griekenland",
  7445.     "GS" => "Zuid-Georgia en de Zuidelijke Sandwicheilanden",
  7446.     "GT" => "Guatemala",
  7447.     "GU" => "Guam",
  7448.     "GW" => "Guinee-Bissau",
  7449.     "GY" => "Guyana",
  7450.     "HK" => "Hongkong",
  7451.     "HM" => "Heard en McDonaldeilanden",
  7452.     "HN" => "Honduras",
  7453.     "HR" => "Kroati&euml;",
  7454.     "HT" => "Haiti",
  7455.     "HU" => "Hongarije",
  7456.     "ID" => "Indonesi&euml;",
  7457.     "IE" => "Ierland",
  7458.     "IL" => "Isra&euml;l",
  7459.     "IM" => "Man",
  7460.     "IN" => "India",
  7461.     "IO" => "Brits Indische Oceaanterritorium",
  7462.     "IQ" => "Irak",
  7463.     "IR" => "Iran",
  7464.     "IS" => "IJsland",
  7465.     "IT" => "Itali&euml;",
  7466.     "JE" => "Jersey",
  7467.     "JM" => "Jamaica",
  7468.     "JO" => "Jordani&euml;",
  7469.     "JP" => "Japan",
  7470.     "KE" => "Kenia",
  7471.     "KG" => "Kirgizi&euml;",
  7472.     "KH" => "Cambodja",
  7473.     "KI" => "Kiribati",
  7474.     "KM" => "Comoren",
  7475.     "KN" => "Saint Kitts en Nevis",
  7476.     "KP" => "Noord-Korea",
  7477.     "KR" => "Zuid-Korea",
  7478.     "KW" => "Koeweit",
  7479.     "KY" => "Kaaimaneilanden",
  7480.     "KZ" => "Kazachstan",
  7481.     "LA" => "Laos",
  7482.     "LB" => "Libanon",
  7483.     "LC" => "Saint Lucia",
  7484.     "LI" => "Liechtenstein",
  7485.     "LK" => "Sri Lanka",
  7486.     "LR" => "Liberia",
  7487.     "LS" => "Lesotho",
  7488.     "LT" => "Litouwen",
  7489.     "LU" => "Luxemburg",
  7490.     "LV" => "Letland",
  7491.     "LY" => "Libi&euml;",
  7492.     "MA" => "Marokko",
  7493.     "MC" => "Monaco",
  7494.     "MD" => "Moldavi&euml;",
  7495.     "ME" => "Montenegro",
  7496.     "MF" => "Sint-Maarten",
  7497.     "MG" => "Madagaskar",
  7498.     "MH" => "Marshalleilanden",
  7499.     "MK" => "Macedoni&euml;",
  7500.     "ML" => "Mali",
  7501.     "MM" => "Myanmar",
  7502.     "MN" => "Mongoli&euml;",
  7503.     "MO" => "Macau",
  7504.     "MP" => "Noordelijke Marianen",
  7505.     "MQ" => "Martinique",
  7506.     "MR" => "Mauritani&euml;",
  7507.     "MS" => "Montserrat",
  7508.     "MT" => "Malta",
  7509.     "MU" => "Mauritius",
  7510.     "MV" => "Maldiven",
  7511.     "MW" => "Malawi",
  7512.     "MX" => "Mexico",
  7513.     "MY" => "Maleisi&euml;",
  7514.     "MZ" => "Mozambique",
  7515.     "NA" => "Namibi&euml;",
  7516.     "NC" => "Nieuw-Caledoni&euml;",
  7517.     "NE" => "Niger",
  7518.     "NF" => "Norfolk",
  7519.     "NG" => "Nigeria",
  7520.     "NI" => "Nicaragua",
  7521.     "NL" => "Nederland",
  7522.     "NO" => "Noorwegen",
  7523.     "NP" => "Nepal",
  7524.     "NR" => "Nauru",
  7525.     "NU" => "Niue",
  7526.     "NZ" => "Nieuw-Zeeland",
  7527.     "OM" => "Oman",
  7528.     "PA" => "Panama",
  7529.     "PE" => "Peru",
  7530.     "PF" => "Frans-Polynesi&euml;",
  7531.     "PG" => "Papoea-Nieuw-Guinea",
  7532.     "PH" => "Filipijnen",
  7533.     "PK" => "Pakistan",
  7534.     "PL" => "Polen",
  7535.     "PM" => "Saint-Pierre en Miquelon",
  7536.     "PN" => "Pitcairneilanden",
  7537.     "PR" => "Rico Puerto Rico",
  7538.     "PS" => "Palestina",
  7539.     "PT" => "Portugal",
  7540.     "PW" => "Palau",
  7541.     "PY" => "Paraguay",
  7542.     "QA" => "Qatar",
  7543.     "RE" => "Reunion",
  7544.     "RO" => "Roemeni&euml;",
  7545.     "RS" => "Servi&euml;",
  7546.     "RU" => "Rusland",
  7547.     "RW" => "Rwanda",
  7548.     "SA" => "Saoedi-Arabi&euml;",
  7549.     "SB" => "Salomonseilanden",
  7550.     "SC" => "Seychellen",
  7551.     "SD" => "Soedan",
  7552.     "SE" => "Zweden",
  7553.     "SG" => "Singapore",
  7554.     "SH" => "Koninkrijk Sint-Helena, Ascension en Tristan da Cunha",
  7555.     "SI" => "Sloveni&euml;",
  7556.     "SJ" => "Spitsbergen en Jan Mayen",
  7557.     "SK" => "Slowakije",
  7558.     "SL" => "Leone Sierra Leone",
  7559.     "SM" => "Marino San Marino",
  7560.     "SN" => "Senegal",
  7561.     "SO" => "Somali&euml;",
  7562.     "SR" => "Suriname",
  7563.     "SS" => "Zuid-Soedan",
  7564.     "ST" => "Sao TomΓ© en Principe",
  7565.     "SV" => "El Salvador",
  7566.     "SX" => "Sint Maarten",
  7567.     "SY" => "Syri&euml;",
  7568.     "SZ" => "Swaziland",
  7569.     "TC" => "Turks- en Caicoseilanden",
  7570.     "TD" => "Tsjaad",
  7571.     "TF" => "Franse Zuidelijke en Antarctische Gebieden",
  7572.     "TG" => "Togo",
  7573.     "TH" => "Thailand",
  7574.     "TJ" => "Tadzjikistan",
  7575.     "TK" => "Tokelau",
  7576.     "TL" => "Oost-Timor",
  7577.     "TM" => "Turkmenistan",
  7578.     "TN" => "Tunesi&euml;",
  7579.     "TO" => "Tonga",
  7580.     "TR" => "Turkije",
  7581.     "TT" => "Trinidad en Tobago",
  7582.     "TV" => "Tuvalu",
  7583.     "TW" => "Taiwan",
  7584.     "TZ" => "Tanzania",
  7585.     "UA" => "Oekraine",
  7586.     "UG" => "Oeganda",
  7587.     "UM" => "Pacifische eilanden van de VS Kleine afgelegen eilanden van de Verenigde Staten",
  7588.     "US" => "Verenigde Staten",
  7589.     "UY" => "Uruguay",
  7590.     "UZ" => "Oezbekistan",
  7591.     "VA" => "Vaticaanstad",
  7592.     "VC" => "Saint Vincent en de Grenadines",
  7593.     "VE" => "Venezuela",
  7594.     "VG" => "Britse Maagdeneilanden",
  7595.     "VI" => "Amerikaanse Maagdeneilanden",
  7596.     "VN" => "Vietnam",
  7597.     "VU" => "Vanuatu",
  7598.     "WF" => "Wallis en Futuna",
  7599.     "WS" => "Samoa",
  7600.     "YE" => "Jemen",
  7601.     "YT" => "Mayotte",
  7602.     "ZA" => "Zuid-Afrika",
  7603.     "ZM" => "Zambia",
  7604.     "ZW" => "Zimbabwe"
  7605.   );
  7606.  
  7607.   return $ountries[$country_code];
  7608. }
  7609.  
Advertisement
Add Comment
Please, Sign In to add comment