Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Custom Public Pages Manager
- Plugin URI:
- Description: Custom public pages management module for the NL site
- Author: Jos van der Wielen
- Version: 2.2
- */
- /*
- NOTE FOR DEVELOPERS:
- SOME METHODS IN THE CLASS BELOW, AS WELL AS SOME PROCEDURAL FUNCTIONS AFTER THAT, ARE USED FOR ADMIN PURPOSES.
- THESE ADMIN FUNCTIONS (FRONT-END AND BACK-END) NEED TO TAKE "AANVRAGEN" FROM BOTH NL AND BE DATABASES INTO ACCOUNT,
- SO DATABASE SWITCHES ARE INCLUDED IN MANY PLACES.
- 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.
- IF THE QUERIES ARE SQL ONLY, A SECOND 'REMOTE' WPDB IS CONNECTED AND USED FOR THE BE DATABASE
- WHEN A "POD" NEEDS TO BE QUERIED ON THE BELGIAN DATABASE IN A FUNCTION THAT ONLY RUNS ON THE NL SYSTEM,
- THE WPDB CONNECTION ITSELF IS TEMPORARILY SWAPPED FOR A CONNECTION WITH THE BE DATABASE, AND RESET AFTER THE POD HAS DONE IT'S THING
- */
- // create global variables that can be seen by header.php
- $tag_values = array();
- $game_values = array();
- $location_values = array();
- $town_values = array();
- $array_tags = array();
- $array_games = $array_game_names = array();
- $array_towns = $array_town_names = array();
- $array_locations = $array_location_names = array();
- $parsetype = '0';
- DEFINE ( 'VIES_URL', 'http://ec.europa.eu/taxation_customs/vies/services/checkVatService' );
- class Custom_Pages_Manager {
- public function __construct() {
- add_action( 'template_redirect', array( $this, 'front_controller' ) );
- add_action( 'custom_generate_rewrite_rules_for_all_games_towns_locations', array( $this, 'generate_rewrite_rules_for_all_games_towns_locations' ));
- add_action( 'custom_beschikbaarheid_in_stappen', array( $this, 'beschikbaarheid_in_stappen' ));
- add_action( 'custom_beschikbaarheidsaanvraag', array( $this, 'beschikbaarheidsaanvraag' ));
- add_action( 'custom_ophalen_beschikbaarheid_bij_locatie', array( $this, 'ophalen_beschikbaarheid_bij_locatie' ));
- add_action( 'custom_verwerken_beschikbaarheid_van_locatie', array( $this, 'verwerken_beschikbaarheid_van_locatie' ));
- add_action( 'custom_afhandelen_beschikbaarheidsaanvraag', array( $this, 'afhandelen_beschikbaarheidsaanvraag' ));
- add_action( 'custom_verwerken_afhandeling_beschikbaarheidsaanvraag', array( $this, 'verwerken_afhandeling_beschikbaarheidsaanvraag' ));
- add_action( 'custom_reserveren', array( $this, 'reserveren' ));
- add_action( 'custom_contactform', array( $this, 'contactform' ));
- /* add_action( 'custom_contacted', array( $this, 'contacted' ));*/
- add_action( 'custom_sitemap_page', array( $this, 'sitemap_page' ));
- add_action( 'custom_mutatie_aantal', array( $this, 'mutatie_aantal' ));
- add_action( 'custom_print_reserveringen', array( $this, 'print_reserveringen' ));
- add_action( 'custom_recensies', array( $this, 'recensies' ));
- add_action( 'wp_ajax_nopriv_beschikbaarheid_steps_towns_per_game', array( $this, 'beschikbaarheid_steps_towns_per_game'));
- add_action( 'wp_ajax_nopriv_beschikbaarheid_steps_locations_per_town', array( $this, 'beschikbaarheid_steps_locations_per_town'));
- add_action( 'wp_ajax_beschikbaarheid_steps_towns_per_game', array( $this, 'beschikbaarheid_steps_towns_per_game'));
- add_action( 'wp_ajax_beschikbaarheid_steps_locations_per_town', array( $this, 'beschikbaarheid_steps_locations_per_town'));
- }
- //=====================================================================================
- public function beschikbaarheid_in_stappen(){
- global $wpdb;
- $games = $wpdb->get_results( "SELECT id, game_code, game_name FROM wp_pods_games ORDER BY game_order " );
- include dirname(__FILE__) . '/templates/tpl_beschikbaarheid_in_stappen.php';
- exit;
- }
- //=====================================================================================
- public function beschikbaarheid_steps_towns_per_game() {
- global $wpdb;
- $errors = array();
- // DIT IS EEN AJAX CALL VOOR ALLE BEZOEKERS, DUS ALS NIET INGELOGD
- check_ajax_referer( 'my-spesscccial-string', 'security' );
- $game_code = isset( $_POST['game_code'] ) ? $_POST['game_code'] : '';
- if (empty($game_code)) {
- $errors[] = 'Ontbrekende game code';
- if ( defined( 'DOING_AJAX' ) ) {
- // echo the content as a json array
- echo json_encode(
- array(
- 'result' => false,
- 'data' => "Ontbrekende game code"
- )
- );
- }
- }
- $params = array(
- 'select' => '
- t.id as location_id,
- t.location_name,
- t.location_code,
- #t.location_coordinates,
- town.id as town_id,
- town.town_name as town_name,
- town.town_code as town_code,
- town.town_coordinates as town_coordinates,
- location_images.guid as location_image
- ',
- 'join' => '
- INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."' ",
- 'orderby' => 'town.town_name',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $bLocation = true;
- $game_towns_locations_values = $locations_pod->rows;
- // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
- $data["geolocations"] = '[';
- $comma='';
- $prev_town_code = '';
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- if ($row['town_code'] != $prev_town_code) {
- // FIRST ROW FOR THIS TOWN
- $prev_town_code = $row['town_code'];
- $game_towns[] = $row;
- }
- }
- // add 'Locaties in Nederland' and 'Eigen locatie' as the first elements (for all games but the culi game)
- if ($game_code != 'food-en-fun-culi-spel') {
- $eigen_locatie = array(
- 'town_code' => 'eigen-locatie',
- 'town_name' => 'Eigen locatie',
- 'town_coordinates' => ''
- );
- array_unshift($game_towns, $eigen_locatie);
- }
- ob_start();
- if (isset($game_towns) && count($game_towns) > 0) { ?>
- <option value="">Kies een plaats</option>
- <?php foreach ($game_towns as $game_town): ?>
- <option value="<?php print $game_town['town_code']; ?>"><?php print $game_town['town_name']; ?></option>
- <?php endforeach; ?>
- <?php
- $temp_content = ob_get_contents();
- ob_end_clean();
- if ( defined( 'DOING_AJAX' ) ) {
- // echo the content as a json array
- echo json_encode(
- array(
- 'result' => true,
- 'data' => $temp_content
- )
- );
- }
- wp_die();
- } else {
- if ( defined( 'DOING_AJAX' ) ) {
- // echo the content as a json array
- echo json_encode(
- array(
- 'result' => false,
- 'data' => "geen plaatsen gevonden"
- )
- );
- }
- wp_die();
- }
- }
- }
- //=====================================================================================
- public function beschikbaarheid_steps_locations_per_town() {
- global $wpdb;
- global $array_games, $array_towns, $array_locations;
- global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
- global $tag_values, $game_values, $town_values, $location_values, $rel_location_game_values, $town_locations_games_values;
- global $wpdb;
- $errors = array();
- // DIT IS EEN AJAX CALL VOOR ALLE BEZOEKERS, DUS ALS NIET INGELOGD
- check_ajax_referer( 'my-spesscccial-string', 'security' );
- $game_code = isset( $_POST['game_code'] ) ? $_POST['game_code'] : '';
- $town_code = isset( $_POST['town_code'] ) ? $_POST['town_code'] : '';
- if (empty($game_code) || empty($town_code)) {
- $errors[] = 'Ontbrekende game of town code';
- if ( defined( 'DOING_AJAX' ) ) {
- // echo the content as a json array
- echo json_encode(
- array(
- 'result' => false,
- 'data' => "Ontbrekende game of town code"
- )
- );
- }
- wp_die();
- }
- $town_row = $wpdb->get_row( "SELECT town_name FROM wp_pods_towns WHERE town_code = '".$town_code."'" );
- $town_name = $town_row->town_name;
- // GET THE TOWN'S COORDINATES
- $params = array(
- 'select' => '
- t.location_coordinates
- ',
- 'where' => " town.town_code = '".$town_code."' ",
- 'limit' => 0
- );
- $town_coords_pod = pods( 'locations', $params );
- $town_coords = $town_coords_pod->rows[0]->location_coordinates;
- // GET ALL LOCATIONS WITHIN 15 KM OF THE TOWN WHERE THIS GAME IS PLAYED
- $json_geolocation = $town_coords;
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- if ( isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
- && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
- ) {
- $center_latitude = $obj_googlemapcoords->lat;
- $center_longitude = $obj_googlemapcoords->lng;
- // array to hold selected location ids
- $location_codes_near_town = array();
- // first get all locations, regardless
- $params_radius = array(
- 'select' => '
- t.location_code,
- t.location_coordinates
- ',
- 'limit' => 0
- );
- $tmp_locations_pod_radius = pods( 'locations', $params_radius );
- $tmp_locations_pod_radius_total = $tmp_locations_pod_radius->total();
- // now select those locations close to the town
- if ($tmp_locations_pod_radius_total > 0 ):
- while ($tmp_locations_pod_radius->fetch() ):
- $row_radius = $tmp_locations_pod_radius->row();
- $json_geolocation_radius = $row_radius['location_coordinates'];
- $obj_googlemapcoords_radius = json_decode($json_geolocation_radius);
- if (!empty($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lng) ) {
- if ( isset($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lat)
- && isset($obj_googlemapcoords_radius->lng) && !empty($obj_googlemapcoords_radius->lng)
- ) {
- $check_latitude = $obj_googlemapcoords_radius->lat;
- $check_longitude = $obj_googlemapcoords_radius->lng;
- }
- }
- if (empty($check_latitude) || empty($check_longitude) ) continue;
- $sql = 'SELECT DISTINCT
- ( 3959 * acos(cos(radians('.$center_latitude.')) * cos( radians( '.$check_latitude.' ) )
- * cos( radians( '.$check_longitude.' ) - radians('.$center_longitude.') )
- + sin(radians('.$center_latitude.')) * sin(radians('.$check_latitude.' )))
- ) AS distance';
- $distance = $wpdb->get_row( $sql )->distance;
- if (is_numeric($distance) && $distance > 0 && $distance < 7):
- // OK, select this location, is close enough
- $location_codes_near_town[] = $row_radius['location_code'];
- endif;
- endwhile;
- endif;
- }
- }
- $orlocationsin = '';
- if (count($location_codes_near_town) > 0 ) {
- // location sfound in the area, create an IN string for the next SQL
- $orlocationsin = ' OR t.location_code IN ("'. implode('", "', $location_codes_near_town).'")';
- }
- // GET THE LOCATIONS FOR THIS GAME IN THIS TOWN
- $params = array(
- 'select' => '
- DISTINCT
- CASE
- WHEN town.town_code = "'.$_POST['town_code'].'" THEN 0
- WHEN t.location_code = "eigen-locatie" THEN 2
- ELSE 1
- END AS first_sort,
- t.id as location_id,
- t.location_name,
- t.address_1,
- t.postal_code,
- t.location_code,
- t.location_name,
- t.location_text,
- t.location_coordinates,
- town.id as town_id,
- town.town_name as town_name,
- town.town_code as town_code,
- town.town_coordinates
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND ( town.town_code = '".$town_code."' OR t.location_code = 'eigen-locatie' ".$orlocationsin ." ) ",
- 'orderby' => 'first_sort, location_order, location_name',
- 'limit' => 0
- );
- $game_town_locations_pod = pods( 'locations', $params );
- $game_town_locations_values_totalrows = $game_town_locations_pod->total();
- if ( $game_town_locations_values_totalrows > 0 ) {
- // COLLECT VALUES FOR ALL LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
- $game_town_locations_values = $game_town_locations_pod->rows;
- }
- $firsttime=true;
- ob_start();
- if (isset($game_town_locations_values) && count($game_town_locations_values) > 0) {
- foreach($game_town_locations_values as $game_town_location_values) {
- $location_code = $game_town_location_values->location_code;
- $town_name = $game_town_location_values->town_name;
- $params = array(
- 'select' => ' t.* ',
- 'where' => 'game_code = "'.$game_code.'"',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- $game_values = array();
- while ($games_pod->fetch() ) {
- $row = $games_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($games_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $game_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
- }
- }
- }
- $game_name = $game_values['game_name'];
- $params = array(
- 'select' => ' t.* ',
- 'where' => 'location_code = "'.$location_code.'"',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $location_values = array();
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($locations_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $location_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $locations_pod->display($fieldname) ;
- }
- }
- }
- $location_name = $location_values['location_name'];
- // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
- $params = array(
- 'select' => 'wp_rel_locations_games.*
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (
- t.id = wp_rel_locations_games.location_id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND location_code = '".$location_code."'",
- 'orderby' => 'min_number',
- 'limit' => 0
- );
- $rel_location_game_pod = pods( 'locations', $params );
- if ( $rel_location_game_pod->total() > 0 ) {
- $rel_location_game_values = $rel_location_game_pod->rows;
- $bLocation_games = true;
- }
- // MINIMUM_PERSONS MAXIMUM_PERSONS
- $location_game['minimum_persons'] = 0;
- $location_game['maximum_persons'] = 0;
- 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)) {
- $rel_location_game_obj = $wpdb->get_row(
- "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$rel_location_game_values[0]->location_id."
- AND game_id = ".$rel_location_game_values[0]->game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- "
- );
- $location_game['minimum_persons'] = (int)$rel_location_game_obj->min_aantal_pers;
- $location_game['maximum_persons'] = (int)$rel_location_game_obj->max_aantal_pers;
- }
- //---------------------------------------------------------------------------------------
- // GET THE NUMBER OF LOCATIONS FOR THIS GAME IN THIS TOWN
- $params = array(
- 'select' => 'DISTINCT t.location_code',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND ( town.town_code = '".$town_code."' OR t.location_code = 'eigen-locatie' )
- ",
- 'orderby' => 't.location_order',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- // $game_town_locations_values_totalrows = $locations_pod->total();
- // if ( $game_town_locations_values_totalrows > 0 ) {
- // $bLocation = true;
- // $game_town_locations_values = $locations_pod->rows;
- // }
- /*--------------------------------------------------------------
- // NUMBER OF LOCATIONS IN THIS TOWN
- //-------------------------------------------------------------- */
- if ( /* $location_values['location_code'] != 'eigen-locatie' && */ $firsttime ):
- $firsttime=false;
- $in = 'in';
- if ( $location_values['location_code'] == 'eigen-locatie') $in = '';
- if ($game_town_locations_values_totalrows == 1) {
- 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>';
- } elseif ($game_town_locations_values_totalrows > 1) {
- 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>';
- } ?>
- <?php
- endif; ?>
- <div class="greybox">
- <div class="widget">
- <div class="widget-title">
- <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>
- </div>
- <div class="widget-content">
- <?php if ($bLocation_games):
- print format_element('rel_location_game_values', $rel_location_game_values);
- endif; ?>
- </div>
- </div>
- <div class="greybox2">
- <div class="sixcol column">
- <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;">
- <a href="#whereis" class="gotowhereis"><?php print strip_tags($location_values['location_name']); ?></a><br />
- </div>
- <br />
- <?php
- /*--------------------------------------------------------------
- // MINIMUM_PERSONS MAXIMUM_PERSONS
- //-------------------------------------------------------------- */ ?>
- <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;">
- Van <?php print $location_game['minimum_persons']; ?> tot <?php print $location_game['maximum_persons']; ?> personen
- </div>
- <?php
- /*--------------------------------------------------------------
- // GAME_DURATION
- //-------------------------------------------------------------- */ ?>
- <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;">
- <?php print $game_values['game_duration']; ?>
- </div>
- <?php
- /*--------------------------------------------------------------
- // GAME_DOCUMENTS
- //-------------------------------------------------------------- */ ?>
- <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;">
- <?php print format_element('game_documents', $game_values['game_documents']); ?>
- </div>
- <p> </p>
- </div>
- <div class="sixcol column last">
- <?php
- print format_element('includes_text', $rel_location_game_values[0]->includes_text);
- if ($game_values['game_code'] == 'onfortuinlijke-bankier') { ?>
- <div style="width:96%; text-align:center;">
- <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
- </div><?php
- }
- if ($game_values['game_code'] == 'into-the-box') { ?>
- <div style="width:96%; text-align:center;">
- <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel kluis + boekjes</a>
- </div><?php
- }
- if ($game_values['game_code'] == 'koudgemaakte-kok') { ?>
- <div style="width:96%; text-align:center;">
- <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
- </div><?php
- }
- if ($game_values['game_code'] == 'mysterie-spel-back-to-school') { ?>
- <div style="width:96%; text-align:center;">
- <a href="<?php print home_url()."/webshop"; ?>" target="_blank" class="element-button small primary" style="width:100%;">Bestel de spelboekjes</a>
- </div><?php
- } ?>
- </div>
- <div class="clear"></div>
- </div>
- <div style="text-align: center; padding-top:20px;">
- <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 ; ?>">
- <div class="element-button small primary handheldonly" style="font-size: 1.2em; background-color:#b12418!important; ">Vraag beschikbaarheid op</div>
- </a>
- </div>
- </div>
- <p> </p>
- <?php
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- if ( defined( 'DOING_AJAX' ) ) {
- // echo the content as a json array
- echo json_encode(
- array(
- 'result' => true,
- 'data' => $temp_content
- )
- );
- }
- wp_die();
- }
- }
- //=====================================================================================
- public function mutatie_aantal() {
- // TOONT FORM, PAGINA tpl_page_mutatie_aantal.php
- // AFHANDELEN FORM SUBMIT:
- // --> email naar dinerspel met link naar aanvraag edit page OP NL SITE
- // --> email naar locatie (maar zonder een eventuele opm die klant kan hebben ingevoerd)
- global $wpdb;
- $site_country = SITECOUNTRY; // must be defined in the wp-config
- $errors = array();
- if ($_POST) {
- if (!$_POST['access_code'] || empty($_POST['access_code']) ) {
- $errors[] = 'Ontbrekende toegangscode';
- exit();
- } else {
- $access_code = $_POST['access_code'];
- }
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_klant_mutatie = '".esc_sql($_POST['access_code'])."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- // hieronder is niet nodig, want deze functie moet gewoon draaien op de site waar de aanvraag bij hoort
- // if ( empty($recordset) ) {
- // // FOR TESTING: try again in BE database
- // $remote_wpdb = new WPDB( DB_USER2, DB_PASSWORD2, DB_NAME2, DB_HOST2);
- // $recordset = $remote_wpdb->get_results( $sqlQuery );
- // $site_country = 'BE';
- // $homeurl = HOMEURL_BE;
- // } else {
- // $site_country = 'NL';
- // $homeurl = HOMEURL_NL;
- // }
- if ( empty($recordset) ) {
- $errors[] = 'Deze pagina is niet (meer) beschikbaar';
- exit();
- } else {
- $row_aanvraag = $recordset[0];
- $oud_aantal_pers = $row_aanvraag->aantal_pers;
- }
- if (empty($_POST['aantal_pers'] )) {
- $errors[] = 'Graag het aantal personen invullen';
- } elseif (!is_numeric($_POST['aantal_pers'])) {
- $errors[] = 'Graag uitsluitend een aantal invullen bij Aantal personen';
- } else {
- //---------------------------------------------------------------------------------------
- // CHECK THE NUMBER OF PERSONS ENTERED
- // calculate the min aantal based on location, game and aantal_pers from aanvraag
- $sql = "SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'";
- // if ($site_country == 'BE') {
- // $row = $remote_wpdb->get_row($sql);
- // } else {
- $row = $wpdb->get_row($sql);
- // }
- $location_id = $row->location_id;
- $zelfstandige_locatie = $row->zelfstandige_locatie;
- if (!empty($location_id)) {
- $sql = "SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'";
- // if ($site_country == 'BE') {
- // $row = $remote_wpdb->get_col($sql);
- // } else {
- $row = $wpdb->get_col($sql);
- //}
- $game_id = $row[0];
- $sql = "
- SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$location_id."
- AND game_id = ".$game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- ";
- // if ($site_country == 'BE') {
- // $rel_location_game_obj = $remote_wpdb->get_row($sql);
- // } else {
- $rel_location_game_obj = $wpdb->get_row($sql);
- // }
- $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
- $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
- }
- //---------------------------------------------------------------------------------------
- // 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
- $voorlopig_min_aantal = round($row_aanvraag->aantal_pers - (15 * ($row_aanvraag->aantal_pers/100) ), 0, PHP_ROUND_HALF_DOWN);
- if ($voorlopig_min_aantal < $min_aantal_pers) $voorlopig_min_aantal = $min_aantal_pers;
- //---------------------------------------------------------------------------------------
- // check if there already is a fixed number in the aanvraag, if there is, we will use that
- if (isset($row_aanvraag->minimum_aantal_bevestigd) && (int)$row_aanvraag->minimum_aantal_bevestigd > 0) {
- $voorlopig_min_aantal = (int)$row_aanvraag->minimum_aantal_bevestigd;
- }
- //---------------------------------------------------------------------------------------
- // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
- if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
- $voorlopig_min_aantal = $row_aanvraag->min_aantal_override;
- }
- $post_aantal_pers = (int)$_POST['aantal_pers'];
- if ( $post_aantal_pers < $voorlopig_min_aantal || $post_aantal_pers > $max_aantal_pers ) {
- $errors[] = 'Het minimum aantal deelnemers is: '.$voorlopig_min_aantal.'. Het maximum aantal is: '.$max_aantal_pers;
- }
- }
- //---------------------------------------------------------------------------------------
- if (count($errors) == 0) {
- // CREATE VARIABLES FROM ROW_AANVRAAG
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- // create certain allowed variables from the $_POST as well
- $arr_allowed_fields = array('access_code', 'game_code', 'town_code', 'location_code', 'voorkeursdatum', 'bedrijfsnaam', 'telefoon',
- 'adres', 'postcode', 'woonplaats', 'country_code', 'btw_nummer', 'opmerking_klant_res', 'aantal_pers', 'eigen_locatie_data');
- foreach ($_POST as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = stripslashes(htmlspecialchars($value, ENT_QUOTES,'UTF-8'));
- }
- }
- $sqlQuery = "UPDATE wp_pods_aanvragen
- SET aantal_pers = '".esc_sql($post_aantal_pers)."',
- opmerking_klant_mutatie_aantal = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_klant_mutatie_aantal'], ENT_QUOTES,'UTF-8')))."',
- modified = NOW()
- WHERE
- code_klant_mutatie = '".esc_sql($access_code)."'";
- // if ($site_country == 'BE') {
- // $updres = $remote_wpdb->get_results( $sqlQuery );
- // } else {
- $updres = $wpdb->get_results( $sqlQuery );;
- //}
- $aantal_pers = $post_aantal_pers;
- $geslacht = $row_aanvraag->geslacht;
- $aanhef = ($geslacht == 'Vrouw') ? 'Mevrouw' : 'De heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $opmerking_klant = stripslashes($opmerking_klant);
- $opmerking_klant_res = stripslashes($opmerking_klant_res);
- $opmerking_klant_mutatie_aantal = stripslashes($_POST['opmerking_klant_mutatie_aantal']);
- $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>';
- if ($location_code == 'eigen-locatie') {
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- } else {
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- }
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_mutatie_aantal_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $headers = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
- get_header();
- $multiple_recipients = array(
- MAILTO_RESERVERINGEN,
- );
- $mailresult = wp_mail($multiple_recipients, ' Mutatie aantal via '.$website, $message, $headers);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_mutatie_aantal_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- } else {
- // NO POST, GET THE aanvraag from the code in the url
- // get access code
- $redirecturl = $_SERVER['REDIRECT_URL'];
- $arrUrl = explode('/', $redirecturl);
- $key = array_search('mutatie-aantal', $arrUrl);
- $access_code = $arrUrl[($key+1)];
- if (!$access_code || empty($access_code) ) exit();
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_klant_mutatie = '".esc_sql($access_code)."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- if ( empty($recordset) ) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- $row_aanvraag = $recordset[0];
- // check if date still allows mutation
- $reserveringsdatum = $row_aanvraag->reserveringsdatum;
- if (!empty($reserveringsdatum) && $reserveringsdatum <> '0000-00-00') {
- $today = date_create(); // Current time and date
- $today = date_format($today, 'Y-m-d 00:00:00');
- $today = date_create($today);
- $reserveringsdatum = date_create($reserveringsdatum);
- $reserveringsdatum = date_format($reserveringsdatum, 'Y-m-d 00:00:00');
- $reserveringsdatum = date_create($reserveringsdatum);
- $diff = date_diff( $today, $reserveringsdatum );
- if ( $diff->days < 3 ) {
- $message = '
- <strong>U kunt het aantal deelnemers tot maximaal twee dagen voor de speldatum online wijzigen.<br>
- Daarna is de pagina niet meer beschikbaar.<br>
- <br>
- U kunt het aantal deelnemers op dit moment helaas niet meer verminderen.<br>
- Vermeerderen kan eventueel wel. Stuurt u dan even een mailtje naar <a href="mailto:[email protected]">[email protected]</a>
- </strong>';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- } else {
- // something must be really wrong, if there is no game date...
- $message = '
- <h3>U kunt het aantal deelnemers tot maximaal twee dagen voor de speldatum online wijzigen.<br>
- Daarna is de pagina niet meer beschikbaar.<br>
- <br>
- U kunt het aantal deelnemers op dit moment helaas niet meer verminderen.<br>
- Vermeerderen kan eventueel wel. Stuurt u dan even een mailtje naar <a href="mailto:[email protected]">[email protected]</a>';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- // get extra data
- $sql = "SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'";
- // if ($site_country == 'BE') {
- // $row = $remote_wpdb->get_row($sql);
- // } else {
- $row = $wpdb->get_row($sql);
- // }
- $location_id = $row->location_id;
- $zelfstandige_locatie = $row->zelfstandige_locatie;
- if (!empty($location_id)) {
- $sql = "SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'";
- // if ($site_country == 'BE') {
- // $row = $remote_wpdb->get_col($sql);
- // } else {
- $row = $wpdb->get_col($sql);
- // }
- $game_id = $row[0];
- $sql = "
- SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$location_id."
- AND game_id = ".$game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- ";
- // if ($site_country == 'BE') {
- // $rel_location_game_obj = $remote_wpdb->get_row($sql);
- // } else {
- $rel_location_game_obj = $wpdb->get_row($sql);
- // }
- $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
- $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
- }
- //---------------------------------------------------------------------------------------
- // 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
- $voorlopig_min_aantal = round($row_aanvraag->aantal_pers - (15 * ($row_aanvraag->aantal_pers/100) ), 0, PHP_ROUND_HALF_DOWN);
- if ($voorlopig_min_aantal < $min_aantal_pers) $voorlopig_min_aantal = $min_aantal_pers;
- //---------------------------------------------------------------------------------------
- // check if there already is is a fixed number in the aanvraag, if there is, we will use that
- if (isset($row_aanvraag->minimum_aantal_bevestigd) && (int)$row_aanvraag->minimum_aantal_bevestigd > 0) {
- $voorlopig_min_aantal = (int)$row_aanvraag->minimum_aantal_bevestigd;
- }
- //---------------------------------------------------------------------------------------
- // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
- if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
- $voorlopig_min_aantal = $row_aanvraag->min_aantal_override;
- }
- }
- // below is for both first page load as well as page after $_POST
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- $geslacht = $row_aanvraag->geslacht;
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords(stripslashes($name));
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', stripslashes($town_code)) );
- $location_name = ucwords(str_replace('-', ' ', stripslashes($location_code)) );
- $website = 'Dinerspel.nl';
- $form_action = home_url().'/mutatie-aantal';
- $opmerking_klant = stripslashes($opmerking_klant);
- $opmerking_klant_res = stripslashes($opmerking_klant_res);
- if ($location_code == 'eigen-locatie') {
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- } else {
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- }
- //----------------------------------
- // show form to start reservation
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_mutatie_aantal.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- //================================================
- public function front_controller() {
- //================================================
- global $wpdb, $wp_query, $current_user;
- global $tag_values, $game_values, $town_values, $location_values, $town_locations_games_values, $rel_location_game_values;
- global $array_tags, $array_games, $array_towns, $array_locations;
- global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
- global $parsetype;
- global $arr_grote_steden;
- $arr_grote_steden = array('antwerpen', 'brussel', 'amsterdam', 'den-haag', 'rotterdam' );
- // skip the rest of this check if it concerns a page that has no 'category_name' in the query_vars
- if (strpos($wp_query->query_vars['category_name'], '%E2') !== false ||
- strpos($wp_query->query_vars['category_name'], '%9DA') !== false ) {
- return;
- }
- if (is_page() && is_front_page()) {
- // we only do the non standard pages here
- return;
- }
- // INTERCEPT URLS FOR WHICH WE HAVE A SPECIFIC ACTION FUNCTION SET UP IN THIS CONTROLLER
- switch ($wp_query->query_vars['category_name'] ) {
- case 'beschikbaarheid_in_stappen':
- do_action( 'custom_beschikbaarheid_in_stappen' );
- return;
- break;
- case 'beschikbaarheidsaanvraag':
- do_action( 'custom_beschikbaarheidsaanvraag' );
- return;
- break;
- case 'reageer-op-beschikbaarheidsaanvraag':
- do_action( 'custom_ophalen_beschikbaarheid_bij_locatie' );
- return;
- break;
- case 'verwerk-beschikbaarheid-van-locatie':
- do_action( 'custom_verwerken_beschikbaarheid_van_locatie' );
- return;
- break;
- case 'beschikbaarheidsaanvraag-afhandelen':
- do_action( 'custom_afhandelen_beschikbaarheidsaanvraag' );
- return;
- break;
- case 'verwerken-afhandeling-beschikbaarheidsaanvraag':
- do_action( 'custom_verwerken_afhandeling_beschikbaarheidsaanvraag' );
- return;
- break;
- case 'reserveren':
- do_action( 'custom_reserveren' );
- return;
- break;
- case 'mutatie-aantal':
- do_action( 'custom_mutatie_aantal' );
- return;
- break;
- case 'sitemap':
- do_action( 'custom_sitemap_page' );
- return;
- break;
- case 'contactform':
- do_action( 'custom_contactform' );
- return;
- break;
- /*
- case 'contacted':
- do_action( 'custom_contacted' );
- return;
- break;*/
- case 'searchtown':
- // first check if the town is in our towns table
- $searchtown_row = $wpdb->get_row( "SELECT town_code FROM wp_pods_towns WHERE LOWER(town_name) = '".esc_attr(trim(strtolower($_GET['s'])))."'");
- if ($searchtown_row) {
- wp_redirect( home_url().'/'.$searchtown_row->town_code);
- exit();
- } else {
- // if no:
- wp_redirect( home_url().'/plaatsen');
- exit();
- }
- break;
- case 'recensies':
- do_action( 'custom_recensies' );
- return;
- break;
- }
- //----------------------------------------------------------------------------------
- // SET UP ARRAYS FOR ALL TAGS, ALL GAMES_CODES, ALL TOWN_CODES, AND ALL LOCATION_CODES
- $rows = $wpdb->get_results( "SELECT tag_name, tag_text FROM wp_pods_tags " );
- foreach ( $rows as $row ):
- $array_tags[] = $row->tag_name;
- $array_tags_texts[] = $row->tag_text;
- endforeach;
- $rows = $wpdb->get_results( "SELECT game_code, game_name FROM wp_pods_games ORDER BY game_order " );
- foreach ( $rows as $row ):
- $array_games[] = $row->game_code;
- $array_game_names[] = $row->game_name;
- endforeach;
- $rows = $wpdb->get_results( "SELECT town_code, town_name FROM wp_pods_towns ORDER BY town_name" );
- foreach ( $rows as $row ):
- $array_towns[] = $row->town_code;
- $array_town_names[] = $row->town_name;
- endforeach;
- $rows = $wpdb->get_results( "SELECT location_code, location_name FROM wp_pods_locations " );
- foreach ( $rows as $row ) :
- $array_locations[] = $row->location_code;
- $array_location_names[] = $row->location_name;
- endforeach;
- //----------------------------------------------------------------------------------
- //-----------------------------------------------------------------------------------------
- $parsetype = '0';
- // // FIRST CHECK IF $CONTROL_ACTION IS A COMBINATION OF TAG/GAMES_CODE/TOWN_CODE/LOCATION_CODE
- // if (isset($control_action)) {
- // $arr_action = explode('/', $control_action);
- // $parsetype_array = $this->_check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations);
- // $parsetype = $parsetype_array[0];
- // $part_1 = $parsetype_array[1];
- // $part_2 = $parsetype_array[2];
- // $part_3 = $parsetype_array[3];
- // $part_4 = $parsetype_array[4];
- // }
- // CHECK $WP_QUERY->QUERY_VARS['CATEGORY_NAME'] && $WP_QUERY->QUERY_VARS['NAME']
- // THEY PERHAPS CONTAIN A COMBINATION OF TAG/GAMES_CODE/TOWN_CODE/ AND/OR LOCATION_CODE)
- if ($parsetype == '0') {
- if (!empty($wp_query->query_vars['category_name'])) {
- // this gets everything but the last element, if it is of the form game/town/location
- $arr_action = explode('/', $wp_query->query_vars['category_name']);
- // the location will have ended up in the name field:
- if (strpos($wp_query->query_vars['name'], '%E2') === false &&
- strpos($wp_query->query_vars['name'], '%9DA') === false ) {
- $arr_action[] = $wp_query->query_vars['name'] ;
- }
- } elseif (!empty($wp_query->query_vars['name'])) {
- if (strpos($wp_query->query_vars['name'], '%E2') === false &&
- strpos($wp_query->query_vars['name'], '%9DA') === false ) {
- $arr_action = explode('/', $wp_query->query_vars['name']);
- }
- }
- if (isset($arr_action) && count($arr_action) > 0) {
- switch ($arr_action[0]) {
- case 'plaatsen':
- $parsetype = 15;
- break;
- case 'restaurants':
- $parsetype = 19;
- break;
- case 'eigen-locatie':
- $parsetype = 17;
- break;
- default:
- $parsetype_array = $this->_check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations);
- //--------------------------------
- $parsetype = $parsetype_array[0];
- //--------------------------------
- $part_1 = $parsetype_array[1];
- $part_2 = $parsetype_array[2];
- $part_3 = $parsetype_array[3];
- $part_4 = $parsetype_array[4];
- break;
- }
- }
- }
- if ($parsetype != '0') {
- /*
- $parsetype = '1'; // TREFWOORD/SPEL/PLAATS/LOCATIE
- $parsetype = '2'; // TREFWOORD/SPEL/LOCATIE
- $parsetype = '3'; // TREFWOORD/SPEL/PLAATS
- $parsetype = '4'; // TREFWOORD/LOCATIE
- $parsetype = '5'; // TREFWOORD/PLAATS
- $parsetype = '6'; // TREFWOORD/SPEL
- $parsetype = '11'; // SPEL/TREFWOORD
- $parsetype = '12'; // SPEL/PLAATS
- $parsetype = '18'; // SPEL/EIGEN-LOCATIE
- $parsetype = '13'; // SPEL/PLAATS/LOCATIE
- $parsetype = '9'; // PLAATS/SPEL
- $parsetype = '14'; // PLAATS/LOCATIE
- $parsetype = '8'; // PLAATS
- $parsetype = '17'; // EIGEN-LOCATIE
- $parsetype = '10'; // SPEL
- $parsetype = '7'; // TREFWOORD
- $parsetype = '15'; // ALLE PLAATSEN
- $parsetype = '16'; // ALLE SPELLEN
- $parsetype = '19'; // ALLE LOCATiES
- */
- $bTag = $bGame = $bTown = $bLocation = $bLocation_games = $bTown_games = false;
- //--------------------------------------------------------------------------------------------------------
- // COLLECT TAG INFO
- //--------------------------------------------------------------------------------------------------------
- if ( in_array($parsetype, array('1', '2', '3', '4', '5', '6', '7', '11'))) { // TREFWOORD
- // TAGS
- switch ($parsetype) {
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- $tag_name = $part_1;
- break;
- case '11':
- $tag_name = $part_2;
- break;
- }
- $params = array(
- 'select' => ' t.* ',
- 'where' => 'tag_name = "'.$tag_name.'"',
- 'limit' => 0
- );
- $tags_pod = pods( 'tags', $params );
- if ( $tags_pod->total() > 0 ) {
- $tag_fields = array();
- while ($tags_pod->fetch() ) {
- $row = $tags_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($tags_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $tag_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $tags_pod->display($fieldname) ;
- }
- }
- }
- $bTag = true;
- }
- //--------------------------------------------------------------------------------------------------------
- // COLLECT GAME INFO
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('1', '2', '3', '6', '9', '10', '11', '12', '13', '18'))){ // GAME
- $bGame = true;
- switch ($parsetype) {
- case '1':
- case '2':
- case '3':
- case '6':
- case '9':
- $game_code = $part_2;
- break;
- case '10':
- case '11':
- case '12':
- case '13':
- case '18':
- $game_code = $part_1;
- break;
- }
- $params = array(
- //'select' => ' t.game_code ',
- 'select' => ' t.* ',
- 'where' => 'game_code = "'.$game_code.'"',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- $game_values = array();
- while ($games_pod->fetch() ) {
- $row = $games_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($games_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $game_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
- }
- }
- }
- $game_name = $game_values['game_name'];
- }
- //--------------------------------------------------------------------------------------------------------
- // COLLECT TOWN INFO
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('1', '3', '5', '8','9','12','13', '14'))) { // PLAATS
- // TOWNS
- switch ($parsetype) {
- case '1':
- case '3':
- $town_code = $part_3;
- break;
- case '5':
- case '12':
- case '13':
- $town_code = $part_2;
- break;
- case '8':
- case '9':
- case '14':
- $town_code = $part_1;
- break;
- }
- $params = array(
- //'select' => ' t.town_code ',
- 'select' => ' t.* ',
- 'where' => 'town_code = "'.$town_code.'"',
- 'limit' => 0
- );
- $towns_pod = pods( 'towns', $params );
- if ( $towns_pod->total() > 0 ) {
- $town_values = array();
- while ($towns_pod->fetch() ) {
- $row = $towns_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($towns_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $town_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $towns_pod->display($fieldname) ;
- }
- }
- }
- $town_name = $town_values['town_name'];
- $bTown = true;
- }
- //--------------------------------------------------------------------------------------------------------
- // COLLECT LOCATION INFO
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('1', '2', '4', '13', '14', '18'))) { // LOCATIE
- switch ($parsetype) {
- case '1':
- $location_code = $part_4;
- break;
- case '2':
- case '13':
- $location_code = $part_3;
- break;
- case '4':
- case '14':
- case '18':
- $location_code = $part_2;
- break;
- }
- $params = array(
- //'select' => ' t.location_code ',
- 'select' => ' t.* ',
- 'where' => 'location_code = "'.$location_code.'"',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $location_values = array();
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($locations_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $location_values[$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $locations_pod->display($fieldname) ;
- }
- }
- }
- $location_name = $location_values['location_name'];
- $bLocation = true;
- }
- //--------------------------------------------------------------------------------------------------------
- // IF GAME ONLY PAGE, COLLECT CITIES + LOCATIONS (INCL MAP COORDINATES) WHERE THE GAME CAN BE PLAYED
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('10'))) { // SPEL
- // GAME INFO HAS BEEN COLLECTED --> $game_code & $game_name are available
- $params = array(
- 'select' => '
- t.id as location_id,
- t.location_name,
- t.location_code,
- #t.location_coordinates,
- town.id as town_id,
- town.town_name as town_name,
- town.town_code as town_code,
- town.town_coordinates as town_coordinates,
- location_images.guid as location_image
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."' ",
- 'orderby' => 'town.town_name',
- 'limit' => 0
- );
- // #AND location_code <> 'eigen-locatie'
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $bLocation = true;
- $game_towns_locations_values = $locations_pod->rows;
- // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
- $data["geolocations"] = '[';
- $comma='';
- $prev_town_code = '';
- $game_towns = array();
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- if ($row['town_code'] != $prev_town_code) {
- // FIRST ROW FOR THIS TOWN
- $prev_town_code = $row['town_code'];
- $game_towns[] = $row;
- }
- if (isset($row['town_coordinates']) && !empty($row['town_coordinates']) ) {
- $json_geolocation = $row['town_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- /*
- $location_name = $row['location_name'];
- $location_code = $row['location_code'];
- $address_1 = $row['address_1'];
- $postal_code = $row['postal_code'];
- */
- $town = $row['town_name'];
- $town_code = $row['town_code'];
- /*
- $info = $location_name;
- $info .= (!empty($address_1)) ? ' - '.$address_1 : '';
- $info .= (!empty($postal_code)) ? ' - '.$postal_code : '';
- $info .= (!empty($town)) ? ' - '.$town : '';
- $url = $game_code.'/'.$town_code.'/'.$location_code;
- */
- $info = (!empty($town)) ? $town : '';
- $url = home_url().'/'.$game_code.'/'.$town_code;
- $data["geolocations"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- }
- }
- $data["geolocations"] .= '
- ]';
- // add 'Locaties in Nederland' and 'Eigen locatie' as the first elements (for all games but the culi game)
- if ($game_code != 'food-en-fun-culi-spel') {
- $eigen_locatie = array(
- 'town_code' => 'eigen-locatie',
- 'town_name' => 'Eigen locatie',
- 'town_coordinates' => ''
- );
- array_unshift($game_towns, $eigen_locatie);
- }
- }
- }
- // TAG+TOWN
- //--------------------------------------------------------------------------------------------------------
- // IF TAG+TOWN PAGE, WE NEED TO SHOW ALL OTHER TAGS FOR THIS TOWN
- // SO COLLECT LOCATIONS IN THE TOWN, DETERMINE WHICH GAMES CAN BE PLAYED, AND WHAT TAGS THESE GAMES HAVE
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('5'))) { // TREFWOORD + PLAATS
- $tag_town_other_town_tags_values = array();
- $tag_town_games_images_values_arr = array();
- $tag_town_games_images_values = '';
- // GET ALL GAME CODES and their tags
- $params = array(
- 'select' => ' t.* ',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- while ($games_pod->fetch() ) {
- // add game images to the tag_town_games_images_values_arr array, so the slider will have something to show besides town images
- $tag_town_game_images_str = $games_pod->display( 'game_images' );
- $tag_town_game_images_arr = explode(' ', $tag_town_game_images_str);
- foreach($tag_town_game_images_arr as $tag_town_game_image) {
- if (!in_array($tag_town_game_image, $tag_town_games_images_values_arr)) {
- array_push($tag_town_games_images_values_arr, $tag_town_game_image);
- }
- }
- $tmp_game_code = $games_pod->display( 'game_code' ); //print "<br />------------------------game_code: ".$game_code;
- $tmp_str_tags = $games_pod->display( 'game_tags' ); // --> string! 'familiefeesten' of 'familiefeesten en henparties'
- $tmp_game_tags = $games_pod->field( 'game_tags' ); // --> array:
- // get all locations where this game is played IN THIS town
- $params = array(
- 'select' => ' t.location_code, town.town_code ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => "game_code = '".$tmp_game_code."'
- AND town.town_code = '".$town_code."'
- AND location_code <> 'eigen-locatie' ",
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- // OK this game is played in $town_code, so we can add it's tags to the 'tag_town_other_town_tags_values' array
- // unless it is THE tag for this page, or it is already in the array
- foreach ($tmp_game_tags as $tmp_game_tag) {
- $tmp_tag_name = $tmp_game_tag['tag_name'];
- if ($tmp_tag_name != $tag_name && !in_array($tmp_tag_name, $tag_town_other_town_tags_values)) {
- array_push($tag_town_other_town_tags_values, $tmp_tag_name);
- }
- }
- }
- }
- $tag_town_games_images_values = implode(' ', $tag_town_games_images_values_arr);
- }
- }
- // GAME+TOWN
- //--------------------------------------------------------------------------------------------------------
- // IF GAME+TOWN PAGE, COLLECT LOCATIONS IN THE TOWN WHERE THE GAME CAN BE PLAYED
- // PLUS OTHER GAMES THAT CAN BE PLAYED IN THE TOWN
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('12', '9'))) { // SPEL + PLAATS
- // GAME INFO HAS BEEN COLLECTED --> $game_code & $game_name are available
- // TOWN INFO HAS BEEN COLLECTED --> $town_code & $town_name are available
- // GET THE LOCATIONS FOR THIS GAME IN THIS TOWN
- $params = array(
- 'select' => 'DISTINCT t.id as location_id,
- t.location_name,
- t.address_1,
- t.postal_code,
- t.location_code,
- t.location_name,
- t.location_text,
- t.location_coordinates,
- town.id as town_id,
- town.town_name as town_name,
- town.town_code as town_code,
- location_images.guid as location_image',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND town.town_code = '".$town_code."'",
- 'orderby' => 't.location_name',
- 'limit' => 0
- );
- // AND location_code <> 'eigen-locatie'
- $game_town_locations_pod = pods( 'locations', $params );
- $game_town_locations_values_totalrows = $game_town_locations_pod->total();
- if ( $game_town_locations_values_totalrows > 0 ) {
- $bLocation = true;
- // COLLECT VALUES FOR ALL LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
- $game_town_locations_values = $game_town_locations_pod->rows;
- // GET GOOGLE COORDS FOR THE LOCATIONS IN THIS TOWN WHERE THIS GAME CAN BE PLAYED
- $game_town["geolocations"] = '[';
- while ($game_town_locations_pod->fetch() ) {
- $row = $game_town_locations_pod->row();
- if (isset($row['location_coordinates']) ) {
- // ADD THIS LOCATION COORDS TO THE GOOGLE MAP ARRAY
- $json_geolocation = $row['location_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- $goo_location_name = $row['location_name'];
- $goo_location_code = $row['location_code'];
- $goo_address_1 = $row['address_1'];
- $goo_postal_code = $row['postal_code'];
- $info = $goo_location_name;
- $info .= (!empty($goo_address_1)) ? ' - '.$goo_address_1 : '';
- $info .= (!empty($goo_postal_code)) ? ' - '.$goo_postal_code : '';
- $info .= (!empty($town_name)) ? ' - '.$town_name : '';
- $info .= $text_games_per_location;
- // $url = $game_code.'/'.$town_code.'/'.$goo_location_code;
- $url = home_url().'/'.$town_code.'/'.$goo_location_code;
- $game_town["geolocations"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- }
- }
- if ($game_town["geolocations"] == '[') {
- $game_town["geolocations"] = '';
- } else {
- $game_town["geolocations"] .= '
- ]';
- }
- }
- }
- // GAME+OWN-LOCATION
- //--------------------------------------------------------------------------------------------------------
- // IF GAME+OWN-LOCATION PAGE, COLLECT PRICES AND OTHER GAME/LOCATION RELATION INFO
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('18'))) { // SPEL + PLAATS + EIGEN LOCATIE
- // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
- $params = array(
- 'select' => 'wp_rel_locations_games.*
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (
- t.id = wp_rel_locations_games.location_id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND location_code = 'eigen-locatie' ",
- 'orderby' => 'min_number',
- 'limit' => 0
- );
- $rel_location_game_pod = pods( 'locations', $params );
- if ( $rel_location_game_pod->total() > 0 ) {
- $rel_location_game_values = $rel_location_game_pod->rows;
- $bLocation_games = true;
- }
- //---------------------------------------------------------------------------------------
- // GET ALL OTHER GAMES PLAYED IN EIGEN LOCATIE
- $game_own_location_other_games_values = array();
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.diner_price,
- t.diner_price_foodfun
- ',
- 'where' => " location_code = 'eigen-locatie' ",
- 'limit' => 0
- );
- $tmp_locations_pod = pods( 'locations', $params );
- //die($tmp_locations_pod->sql);
- $tmp_locations_pod_total = $tmp_locations_pod->total();
- if ( $tmp_locations_pod_total > 0 ):
- $i=0;
- while ($tmp_locations_pod->fetch() ):
- $row = $tmp_locations_pod->row();
- $game_own_location_other_games_values[$i]['location_code'] = $row['location_code'];
- $game_own_location_other_games_values[$i]['location_name'] = $row['location_name'];
- $game_params = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => 'INNER JOIN wp_rel_locations_games ON
- (wp_rel_locations_games.game_id = t.id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'where' => 'game_code <> "'.$game_code.'"
- AND wp_rel_locations_games.location_id = "'.$row['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- ',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $tmp_games_pod = pods( 'games', $game_params );
- //die($tmp_games_pod->sql);
- // collect data for the games played at this location
- if ( $tmp_games_pod->total() > 0 ):
- $lowest_price = 999.99;
- $prev_game_code = '';
- while ($tmp_games_pod->fetch() ):
- $row2 = $tmp_games_pod->row();
- $tmp_games_game_code = $row2['game_code'];
- // (NOG) NIET GEIMPLEMENTEERD, MISSCHIEN NIET ECHT NODIG
- // // game has an indicator, 'own_location', if it is zero, skip 'eigen-locatie's
- // if ($row2['own_location'] == '0' && $row['location_code'] == 'eigen-locatie') continue;
- // collect images for this game
- $img_game_params = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$tmp_games_game_code.'"',
- 'limit' => 0
- );
- $img_games_pod = pods( 'games', $img_game_params );
- if ( $img_games_pod->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- true
- );
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] = $thumbnail;
- }
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_code'] = $row2['game_code'];
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_name'] = $row2['game_name'];
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr'] = $row2['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($tmp_games_game_code == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- if ($tmp_games_game_code == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2['game_price'] < $lowest_price) {
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2['min_number'] < $low_min_number) {
- $low_min_number = $row2['min_number'];
- }
- if ($row2['max_number'] > $high_max_number) {
- $high_max_number = $row2['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2['min_number'];
- $high_max_number = $row2['max_number'];
- $prev_game_code = $row2['game_code'];
- }
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
- $game_own_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
- endwhile;
- endif;
- $i++;
- endwhile;
- endif;
- }
- // GAME+TOWN+LOCATION
- //--------------------------------------------------------------------------------------------------------
- // IF GAME+TOWN+LOCATION PAGE, COLLECT PRICES AND OTHER GAME/LOCATION RELATION INFO
- //--------------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('13'))) { // SPEL + PLAATS + LOCATIE
- // GAME INFO HAS BEEN COLLECTED --> $game_code & $game_name are available
- // TOWN INFO HAS BEEN COLLECTED --> $town_code & $town_name are available
- // LOCATION INFO HAS BEEN COLLECTED --> $location_code & $location_name are available
- // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
- $params = array(
- 'select' => 'wp_rel_locations_games.*
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (
- t.id = wp_rel_locations_games.location_id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND location_code = '".$location_code."'",
- 'orderby' => 'min_number',
- 'limit' => 0
- );
- $rel_location_game_pod = pods( 'locations', $params );
- if ( $rel_location_game_pod->total() > 0 ) {
- $rel_location_game_values = $rel_location_game_pod->rows;
- $bLocation_games = true;
- }
- // MINIMUM_PERSONS MAXIMUM_PERSONS
- $location_game['minimum_persons'] = 0;
- $location_game['maximum_persons'] = 0;
- 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)) {
- $rel_location_game_obj = $wpdb->get_row(
- "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$rel_location_game_values[0]->location_id."
- AND game_id = ".$rel_location_game_values[0]->game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- "
- );
- $location_game['minimum_persons'] = (int)$rel_location_game_obj->min_aantal_pers;
- $location_game['maximum_persons'] = (int)$rel_location_game_obj->max_aantal_pers;
- }
- //---------------------------------------------------------------------------------------
- // GET ALL OTHER LOCATIONS IN THIS TOWN
- $params = array(
- 'select' => ' t.location_code, t.location_name ',
- 'where' => " town.town_code = '".$town_code."'
- ",
- 'orderby' => 't.location_name',
- 'limit' => 0
- );
- $game_town_location_other_locations_in_town_pod = pods( 'locations', $params );
- $game_town_location_other_locations_in_town_totalrows = $game_town_location_other_locations_in_town_pod->total();
- if ($game_town_location_other_locations_in_town_totalrows > 0 ) {
- $game_town_location_other_locations_in_town_values = $game_town_location_other_locations_in_town_pod->rows;
- }
- //---------------------------------------------------------------------------------------
- // GET THE NUMBER OF LOCATIONS FOR THIS GAME IN THIS TOWN
- $params = array(
- 'select' => 'DISTINCT t.location_code',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."'
- AND town.town_code = '".$town_code."'
- AND location_code <> 'eigen-locatie'
- ",
- 'orderby' => 't.location_name',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- $game_town_locations_values_totalrows = $locations_pod->total();
- if ( $game_town_locations_values_totalrows > 0 ) {
- $bLocation = true;
- $game_town_locations_values = $locations_pod->rows;
- }
- //---------------------------------------------------------------------------------------
- // GET ALL OTHER GAMES PLAYED IN THIS LOCATION
- $game_town_location_other_games_values = array();
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.diner_price,
- t.diner_price_foodfun
- ',
- 'where' => " (town.town_code = '".$town_code."'
- AND location_code = '".$location_code."')
- OR
- (location_code = 'eigen-locatie')
- ",
- 'orderby' => 'location_name',
- 'limit' => 0
- );
- $tmp_locations_pod = pods( 'locations', $params );
- $tmp_locations_pod_total = $tmp_locations_pod->total();
- if ( $tmp_locations_pod_total > 0 ):
- $i=0;
- while ($tmp_locations_pod->fetch() ):
- $row = $tmp_locations_pod->row();
- $game_town_location_other_games_values[$i]['location_code'] = $row['location_code'];
- $game_town_location_other_games_values[$i]['location_name'] = $row['location_name'];
- $game_params = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => 'INNER JOIN wp_rel_locations_games ON (
- wp_rel_locations_games.game_id = t.id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'where' => 'game_code <> "'.$game_code.'"
- AND wp_rel_locations_games.location_id = "'.$row['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- ',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $tmp_games_pod = pods( 'games', $game_params );
- // collect data for the games played at this location
- if ( $tmp_games_pod->total() > 0 ):
- $lowest_price = 999.99;
- $prev_game_code = '';
- while ($tmp_games_pod->fetch() ):
- $row2 = $tmp_games_pod->row();
- $tmp_games_game_code = $row2['game_code'];
- // game has an indicator, 'own_location', if it is zero, skip 'eigen-locatie's
- if ($row2['own_location'] == '0' && $row['location_code'] == 'eigen-locatie') continue;
- // collect images for this game
- $img_game_params = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$tmp_games_game_code.'"',
- 'limit' => 0
- );
- $img_games_pod = pods( 'games', $img_game_params );
- if ( $img_games_pod->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- false
- );
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] = $thumbnail;
- }
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_code'] = $row2['game_code'];
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_name'] = $row2['game_name'];
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr'] = $row2['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($tmp_games_game_code == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- if ($tmp_games_game_code == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2['game_price'] < $lowest_price) {
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2['min_number'] < $low_min_number) {
- $low_min_number = $row2['min_number'];
- }
- if ($row2['max_number'] > $high_max_number) {
- $high_max_number = $row2['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2['min_number'];
- $high_max_number = $row2['max_number'];
- $prev_game_code = $row2['game_code'];
- }
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
- $game_town_location_other_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
- endwhile;
- endif;
- $i++;
- endwhile;
- endif;
- }
- // TOWN+LOCATION
- if (in_array($parsetype, array('14'))): // PLAATS + LOCATIE
- // TOWN INFO HAS BEEN COLLECTED --> $town_code & $town_name are available
- // LOCATION INFO HAS BEEN COLLECTED --> $location_code & $location_name are available
- // GET THE GAME/LOCATION RELATIONSHIP, THE PRICES etc.
- $params = array(
- 'select' => 'wp_rel_locations_games.*
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => "location_code = '".$location_code."'",
- 'limit' => 0
- );
- $rel_location_game_pod = pods( 'locations', $params );
- if ( $rel_location_game_pod->total() > 0 ) {
- $rel_location_game_values = $rel_location_game_pod->rows;
- $bLocation_games = true;
- }
- //---------------------------------------------------------------------------------------
- // GET ALL GAMES PLAYED IN THIS LOCATION
- $town_location_slider_images = '';
- $town_location_games_values = array();
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.location_coordinates,
- t.diner_price,
- t.diner_price_foodfun
- ',
- 'where' => " (town.town_code = '".$town_code."'
- AND location_code = '".$location_code."')
- ",
- 'orderby' => 'location_name',
- 'limit' => 0
- );
- $tmp_locations_pod = pods( 'locations', $params );
- $tmp_locations_pod_total = $tmp_locations_pod->total();
- if ( $tmp_locations_pod_total > 0 ):
- $i=0;
- while ($tmp_locations_pod->fetch() ):
- $row = $tmp_locations_pod->row();
- $town_location_games_values[$i]['location_code'] = $row['location_code'];
- $town_location_games_values[$i]['location_name'] = $row['location_name'];
- // for the big top slider:
- if (!empty($location_values['location_images']) && strpos($town_location_slider_images, $location_values['location_images']) === false ) {
- $town_location_slider_images .= $location_values['location_images'].' ';
- }
- $game_params = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => 'INNER JOIN wp_rel_locations_games ON (
- wp_rel_locations_games.game_id = t.id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'where' => 'wp_rel_locations_games.location_id = "'.$row['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- ',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $tmp_games_pod = pods( 'games', $game_params );
- // collect data for the games played at this location
- if ( $tmp_games_pod->total() > 0 ):
- $lowest_price = 999.99;
- $prev_game_code = '';
- while ($tmp_games_pod->fetch() ):
- $row2 = $tmp_games_pod->row();
- $tmp_games_game_code = $row2['game_code'];
- // collect images for this game
- $img_game_params = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$tmp_games_game_code.'"',
- 'limit' => 0
- );
- $img_games_pod = pods( 'games', $img_game_params );
- if ( $img_games_pod->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- true
- );
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_image'] = $thumbnail;
- // for the big top slider:
- // if (!empty($game_images_str) && strpos($game_images_str, $town_location_slider_images) === false ) {
- if (!empty($game_images_str) && strpos($town_location_slider_images, $game_images_str) === false ) {
- $town_location_slider_images .= $game_images_str.' ';
- }
- }
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_code'] = $row2['game_code'];
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_name'] = $row2['game_name'];
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['game_short_descr'] = $row2['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($row2['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- if ($tmp_games_game_code == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2['game_price'] < $lowest_price) {
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2['min_number'] < $low_min_number) {
- $low_min_number = $row2['min_number'];
- }
- if ($row2['max_number'] > $high_max_number) {
- $high_max_number = $row2['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2['min_number'];
- $high_max_number = $row2['max_number'];
- $prev_game_code = $row2['game_code'];
- }
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['lowest_total_price']= $lowest_total_price;
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['low_min_number'] = $low_min_number;
- $town_location_games_values[$i]['location_games'][$tmp_games_game_code]['high_max_number'] = $high_max_number;
- endwhile;
- endif;
- $i++;
- endwhile;
- endif;
- endif; // if (in_array($parsetype, array('14'))) { // PLAATS + LOCATIE
- //---------------------------------------------------------------------------------------------------
- // IF TAG ONLY PAGE,
- //---------------------------------------------------------------------------------------------------
- // info tekst over trefwoord
- // -> select tag_text from tags where tag_name = %s
- // namen van de spellen (met link en wellicht korte intro tekst met placeholders)
- // -> select game_name, short_tag_descr FROM games
- // fetch rows, while
- // if '$tag_name' in array game_tags
- // Linkjes naar artikelen over trefwoord.
- // -> NEW: artikelen? (overleg)
- // linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
- // -> select all towns, generate url '/tag_name/town_code'
- // linkjes naar andere trefwoorden?
- // generate links '/tag_name':
- // -> select tag_name from tags where NOT current_tag_name, print url
- if (in_array($parsetype, array('5', '7'))) { // TREFWOORD
- //--------------------------------------------------------------------------------------
- // info tekst over trefwoord
- // -> zie $tag_values['tag_name']
- //--------------------------------------------------------------------------------------
- // namen van de spellen (met link en wellicht korte intro tekst met placeholders)
- // -> select game_name, short_descr_tag FROM games
- // fetch rows, while
- // if '$tag_name' in array game_tags
- $params = array(
- 'select' => ' t.* ',
- 'orderby' => 'game_order',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- $tag_games_values = array();
- // $tag_games_img_per_game_values = array();
- // $tag_games_slider_values = array();
- while ($games_pod->fetch() ) {
- $tmp_game_code = $games_pod->display( 'game_code' );
- $game_images_str = $games_pod->display( 'game_images' );
- $game_images_arr = explode(' ', $game_images_str);
- $str_tags = $games_pod->display( 'game_tags' );
- $arr_tags = $games_pod->field( 'game_tags' );
- // Select this game row if it has a tag in its tags array that equals the tag from the url
- $select_row = false;
- if (is_array($arr_tags) && count($arr_tags) > 0) {
- foreach($arr_tags as $tag) {
- if ($tag['tag_name'] == $tag_name) $select_row = true;
- }
- }
- if ($select_row) {
- $tag_games_values[] = $games_pod->row();
- $tag_games_img_per_game_values[$tmp_game_code] = $game_images_arr[0];
- // $tag_games_slider_values[] = end($game_images_arr);
- // $tag_games_slider_values[] = $game_images_arr[0];
- // if (isset($game_images_arr[1])) $tag_games_slider_values[] = $game_images_arr[1];
- // if (isset($game_images_arr[2])) $tag_games_slider_values[] = $game_images_arr[2];
- $tag_games_slider_values .= ' '.$game_images_str;
- }
- }
- //$tag_games_slider_values = implode(' ', $tag_games_slider_values);
- }
- //--------------------------------------------------------------------------------------
- // linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
- // -> $array_towns en $array_town_names
- //--------------------------------------------------------------------------------------
- // linkjes naar andere trefwoorden?
- // generate links '/tag_name':
- $key = in_array($tag_name, $array_tags);
- $tag_other_tag_names = array();
- foreach ( $array_tags as $tag_name_from_array ) {
- if ($tag_name_from_array != $tag_name) $tag_other_tag_names[] = $tag_name_from_array;
- }
- }
- //---------------------------------------------------------------------------------------------------
- // IF TOWN ONLY PAGE,
- //---------------------------------------------------------------------------------------------------
- // info tekst over plaats
- // -> select town_text from towns where town_name = %s
- // namen van de spellen (met link en wellicht korte intro tekst met placeholders)
- // -> select game_name, short_town_descr FROM games
- // fetch rows, while
- // if '$town_name' in array game_towns
- // Linkjes naar artikelen over trefwoord.
- // -> NEW: artikelen? (overleg)
- // linkjes naar alle plaatsen i.c.m. trefwoord (bijv: /bedrijfsuitje/utrecht)
- // -> select all towns, generate url '/town_name/town_code'
- // linkjes naar andere trefwoorden?
- // generate links '/town_name':
- // -> select town_name from towns where NOT current_town_name, print url
- if (in_array($parsetype, array('5', '8', '9', '12', '13'))) { // PLAATS
- // GET ALL GAMES/LOCATIONS PLAYED IN THIS TOWN
- $town_locations_games_values = array();
- $params = array(
- 'select' => 'CASE
- WHEN t.location_code = "eigen-locatie" THEN 1
- ELSE 0
- END AS first_sort,
- t.id as location_id,
- t.location_name,
- t.location_code,
- t.country,
- t.location_coordinates,
- t.diner_price,
- t.diner_price_foodfun
- ',
- 'where' => " town.town_code = '".$town_code."' OR t.location_code = 'eigen-locatie' ",
- 'orderby' => 'first_sort, location_order, location_name',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- $locations_pod_total = $locations_pod->total();
- if ( $locations_pod_total > 0 ):
- $i=0;
- $data["geolocations"] = '[';
- $town_tagnames_values=array();
- $comma='';
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- $town_locations_games_values[$i]['location_code'] = $row['location_code'];
- $town_locations_games_values[$i]['location_name'] = $row['location_name'];
- $town_locations_games_values[$i]['country'] = $row['country'];
- // GET ALL GAMES FOR THIS LOCATION
- $game_params = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON
- (wp_rel_locations_games.location_id = "'.$row['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $game_params );
- // collect data for the games played at this location
- if ( $games_pod->total() > 0 ) {
- $lowest_price = 999.99;
- $prev_game_code = '';
- $text_games_per_location = '\r\n\r\nDinerspellen:';
- while ($games_pod->fetch() ) {
- $row2 = $games_pod->row();
- $tmp_game_code = $row2['game_code'];
- // collect images for this game
- $img_game_params = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$tmp_game_code.'"',
- 'limit' => 0
- );
- $img_games_pod = pods( 'games', $img_game_params );
- if ( $img_games_pod->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- true
- );
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_image'] = $thumbnail;
- }
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_code'] = $row2['game_code'];
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_name'] = $row2['game_name'];
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['game_short_descr'] = $row2['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($row2['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- if ($tmp_game_code == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2['game_price'] < $lowest_price) {
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2['min_number'] < $low_min_number) {
- $low_min_number = $row2['min_number'];
- }
- if ($row2['max_number'] > $high_max_number) {
- $high_max_number = $row2['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2['min_number'];
- $high_max_number = $row2['max_number'];
- $prev_game_code = $row2['game_code'];
- // build up a string of game-names for this location, so these games can be shown in the map info popups
- $text_games_per_location .= '\r\n - '.$row2['game_name'];
- }
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['lowest_total_price']= $lowest_total_price;
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['low_min_number'] = $low_min_number;
- $town_locations_games_values[$i]['location_games'][$tmp_game_code]['high_max_number'] = $high_max_number;
- // collect the tagnames that this game has, add to array if not there already
- $town_game_tags = $img_games_pod->display( 'game_tags' );
- $town_game_tags_arr = explode(' ', $town_game_tags);
- foreach($town_game_tags_arr as $town_game_tag) {
- $town_game_tag = str_replace(',','',$town_game_tag);
- if (!in_array($town_game_tag, $town_tagnames_values) && $town_game_tag <> 'and' && $town_game_tag <> 'en') {
- array_push($town_tagnames_values, $town_game_tag);
- }
- }
- if (isset($row['location_coordinates']) ) {
- // GET ALL LOCATION COORDS FOR THE GOOGLE MAP
- $json_geolocation = $row['location_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- $goo_location_name = $row['location_name'];
- $goo_location_code = $row['location_code'];
- $goo_address_1 = $row['address_1'];
- $goo_postal_code = $row['postal_code'];
- $info = $goo_location_name;
- $info .= (!empty($goo_address_1)) ? ' - '.$goo_address_1 : '';
- $info .= (!empty($goo_postal_code)) ? ' - '.$goo_postal_code : '';
- $info .= (!empty($town_name)) ? ' - '.$town_name : '';
- $info .= $text_games_per_location;
- // $url = $game_code.'/'.$town_code.'/'.$goo_location_code;
- $url = home_url().'/'.$town_code.'/'.$goo_location_code;
- if ( isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
- && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
- && isset($info) && !empty($info)
- && isset($url) && !empty($url)
- ) {
- $data["geolocations"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- }
- }
- }
- }
- $i++;
- }
- if ($data["geolocations"] == '[') {
- $data["geolocations"] = '';
- } else {
- $data["geolocations"] .= '
- ]';
- }
- endif;
- }
- //---------------------------------------------------------------------------------------------------
- // IF PAGE 'EIGEN LOCATIE'
- //---------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('17'))) {
- $own_location_games_values = array();
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.location_text
- ',
- 'where' => "t.location_code = 'eigen-locatie' ",
- 'limit' => 0
- );
- $own_locations_pod = pods( 'locations', $params );
- $own_locations_pod_total = $own_locations_pod->total();
- if ( $own_locations_pod_total > 0 ):
- $i=0;
- while ($own_locations_pod->fetch() ) {
- $row = $own_locations_pod->row();
- $own_location_games_values['location_text'] = $row['location_text'];
- // GET ALL GAMES FOR THIS LOCATION
- $own_location_game_params = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON
- (wp_rel_locations_games.location_id = "'.$row['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $own_location_games_pod = pods( 'games', $own_location_game_params );
- // collect data for the games played at this location
- if ( $own_location_games_pod->total() > 0 ) {
- $lowest_price = 999.99;
- $prev_game_code = '';
- $text_games_per_location = '\r\n\r\nDinerspellen:';
- while ($own_location_games_pod->fetch() ) {
- $row2 = $own_location_games_pod->row();
- $own_location_game_code = $row2['game_code'];
- // collect images for this game
- $img_game_params = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$own_location_game_code.'"',
- 'limit' => 0
- );
- $img_games_pod = pods( 'games', $img_game_params );
- if ( $img_games_pod->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- true
- );
- $own_location_games_values['location_games'][$own_location_game_code]['game_image'] = $thumbnail;
- }
- $own_location_games_values['location_games'][$own_location_game_code]['game_code'] = $row2['game_code'];
- $own_location_games_values['location_games'][$own_location_game_code]['game_name'] = $row2['game_name'];
- $own_location_games_values['location_games'][$own_location_game_code]['game_short_descr'] = $row2['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($row2['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- if ($own_location_game_code == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2['game_price'] < $lowest_price) {
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2['min_number'] < $low_min_number) {
- $low_min_number = $row2['min_number'];
- }
- if ($row2['max_number'] > $high_max_number) {
- $high_max_number = $row2['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2['min_number'];
- $high_max_number = $row2['max_number'];
- $prev_game_code = $row2['game_code'];
- // build up a string of game-names for this location, so these games can be shown in the map info popups
- $text_games_per_location .= '\r\n - '.$row2['game_name'];
- }
- $own_location_games_values['location_games'][$own_location_game_code]['lowest_total_price']= $lowest_total_price;
- $own_location_games_values['location_games'][$own_location_game_code]['low_min_number'] = $low_min_number;
- $own_location_games_values['location_games'][$own_location_game_code]['high_max_number'] = $high_max_number;
- }
- }
- $i++;
- }
- endif;
- // collect towns images for a slider
- $all_towns_slider_images = '';
- $params = array(
- 'select' => ' town_images.guid as town_images ',
- 'limit' => 0
- );
- $towns_pod = pods( 'towns', $params );
- if ( $towns_pod->total() > 0 ) {
- while ($towns_pod->fetch() ) {
- $row = $towns_pod->row();
- // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
- // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN
- $this_town_images = $row['town_images'];
- if (!empty($this_town_images) && @strpos($this_town_images, $all_towns_slider_images) === false ) {
- $all_towns_slider_images .= $this_town_images.' ';
- }
- }
- }
- }
- //---------------------------------------------------------------------------------------------------
- // IF "ALL TOWNS" PAGE,
- //---------------------------------------------------------------------------------------------------
- // Intro tekstje algemeen
- // -> general_content['all_towns']
- // Kaart met vlaggetjes op alle plaatsen (popup met restaurants)
- if (in_array($parsetype, array('15'))) { // ALLE PLAATSEN
- //--------------------------------------------------------------------------------------
- // -> general_content['all_towns']
- $row = $wpdb->get_col("SELECT all_towns FROM wp_pods_general_content " );
- $all_towns_text_value = $row[0];
- //--------------------------------------------------------------------------------------
- // namen van de plaatsen (met link)
- $params = array(
- 'select' => ' town_code, town_name, town_coordinates, town_images.guid as town_images ',
- 'limit' => 0
- );
- $towns_pod = pods( 'towns', $params );
- if ( $towns_pod->total() > 0 ) {
- // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
- $data["town_coordinates"] = '[';
- $all_towns_slider_images = '';
- $prev_town_code = '';
- while ($towns_pod->fetch() ) {
- $row = $towns_pod->row();
- // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
- // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN, GET THE FIRST ONE OF EACH
- if ($row['town_code'] != $prev_town_code) {
- // FIRST ROW FOR THIS TOWN
- $prev_town_code = $row['town_code'];
- $all_towns_values[] = $row;
- $this_town_images = $row['town_images'];
- if (!empty($this_town_images)) $all_towns_slider_images .= $this_town_images.' ';
- // collect the names of restaurants in this town, to be shown on hover over map flags
- // ONLY LOCATIONS THAT ARE LINKED TO GAMES
- // (WHEN LOCATIONS ARE NO LONGER NEEDED, THEY ARE NOT PHYSICALLY REMOVED, ONLY THEIR RELATIONSHIPS WITH GAMES ARE)
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
- 'where' => " town.town_code = '".$row['town_code']."'" ,
- 'orderby' => 'location_name',
- 'limit' => 0
- );
- $tmp_locations_pod = pods( 'locations', $params );
- $tmp_locations_pod_total = $tmp_locations_pod->total();
- if ( $tmp_locations_pod_total > 0 ):
- $text_locations_per_town = '';
- while ($tmp_locations_pod->fetch() ):
- $row2 = $tmp_locations_pod->row();
- $text_locations_per_town .= '\r\n - '.$row2['location_name'];
- endwhile;
- if (isset($row['town_coordinates']) && !empty($row['town_coordinates']) ) {
- $json_geolocation = $row['town_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- $town_name = $row['town_name'];
- $town_code = $row['town_code'];
- $town_country = $row['country'];
- $info = htmlspecialchars($town_name, ENT_QUOTES,'UTF-8');
- $info .= (!empty($town_country)) ? ', '.htmlspecialchars($town_country, ENT_QUOTES,'UTF-8') : '';
- $info .= htmlspecialchars($text_locations_per_town, ENT_QUOTES,'UTF-8');
- $url = $town_code;
- $data["town_coordinates"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".$info."', '".$url."']";
- $comma=", ";
- }
- }
- endif;
- } else {
- // MUST BE MULTIPLE ROWS FOR SAME TOWN, DIFFER ONLY RE. FIELD 'TOWN_IMAGES'
- }
- }
- $data["town_coordinates"] .= '
- ]';
- }
- // add 'Eigen locatie' as the first element
- $eigen_locatie = array(
- 'town_code' => 'eigen-locatie',
- 'town_name' => 'Eigen locatie',
- 'town_coordinates' => ''
- );
- array_unshift($all_towns_values, $eigen_locatie);
- }
- //---------------------------------------------------------------------------------------------------
- // IF "ALL LOCATIONS" PAGE,
- //---------------------------------------------------------------------------------------------------
- if (in_array($parsetype, array('19'))) { // ALLE RESTAURANTS
- // FIRST ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
- $params = array(
- 'select' => ' location_code, location_images.guid as location_images ',
- 'where' => ' location_code <> "eigen-locatie" ',
- 'limit' => 0
- );
- $all_locations_slider_images='';
- $one_image_per_location=array();
- $location_images_pod = pods( 'locations', $params );
- if ( $location_images_pod->total() > 0 ) {
- while ($location_images_pod->fetch() ) {
- $row = $location_images_pod->row();
- if (!empty($row['location_images'])) $all_locations_slider_images .= $row['location_images'].' ';
- // per 'location' store the first image in a array $one_image_per_location
- $temp_array = explode(' ', $row['location_images']);
- $curr_image = $temp_array[0];
- if (!empty($curr_image)) {
- // use a smaller size if available
- $curr_image_300 = str_replace('.jpg','-300x225.jpg', $curr_image);
- $curr_image_300_testurl = str_replace(home_url(), '', $curr_image_300);
- $curr_image_300_testurl = $_SERVER["DOCUMENT_ROOT"] .$curr_image_300_testurl;
- if (is_file($curr_image_300_testurl)) $curr_image = $curr_image_300;
- }
- $one_image_per_location[ $row['location_code'] ] = $curr_image;
- }
- }
- // NOW COLLECT INFO ABOUT THE LOCATIONS, THEIR TOWNS, AND THE GAMES PLAYED
- // Not all this info is actually used in the template: the price and num_persons are not shown
- $params = array(
- 'select' => ' t.location_code,
- t.location_name,
- t.address_1,
- t.postal_code,
- t.location_coordinates,
- t.diner_price,
- t.diner_price_foodfun,
- town.id as town_id,
- town.town_name as town_name,
- town.town_code as town_code,
- wp_pods_games.game_code,
- wp_pods_games.game_name,
- wp_rel_locations_games.min_number,
- wp_rel_locations_games.max_number,
- wp_rel_locations_games.game_price
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (
- t.id = wp_rel_locations_games.location_id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => ' location_code <> "eigen-locatie" ',
- 'orderby' => 'town_name, location_name, game_name, min_number ',
- 'limit' => 0
- );
- $town_location_games_values = array();
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $data["location_coordinates"] = '[';
- $prev_location_code = '';
- $prev_location_game_combi = '';
- $price_number_data = array();
- $text_games_per_location = "\r\n - spel 1 - aaaaaaaaaa\r\n - spel 2 - bbbbbbbbbb";
- $prev_key='';
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- //-------------------------------------------------------------------------------------------
- // one time per location, ADD COORDINATE LINES TO STRING $data["location_coordinates"]
- if ( $row['location_code'] != $prev_location_code) {
- if (isset($row['location_coordinates']) && !empty($row['location_coordinates']) ) {
- $json_geolocation = $row['location_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- $location_name = $row['location_name'];
- $location_code = $row['location_code'];
- $address_1 = $row['address_1'];
- $town_name = $row['town_name'];
- $town_code = $row['town_code'];
- $postal_code = $row['postal_code'];
- $location_country = $row['country'];
- $info = htmlspecialchars($location_name, ENT_QUOTES,'UTF-8');
- $info .= (!empty($address_1)) ? ', '.htmlspecialchars($address_1, ENT_QUOTES,'UTF-8') : '';
- $info .= (!empty($postal_code)) ? ', '.htmlspecialchars($postal_code, ENT_QUOTES,'UTF-8') : '';
- $info .= (!empty($town_name)) ? ', '.htmlspecialchars($town_name, ENT_QUOTES,'UTF-8') : '';
- $info .= (!empty($location_country)) ? ', '.htmlspecialchars($location_country, ENT_QUOTES,'UTF-8') : '';
- //$info .= $text_games_per_location;
- $url = $town_code.'/'.$location_code;
- $data["location_coordinates"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- }
- }
- //-------------------------------------------------------------------------------------------
- if ( $prev_location_game_combi != $row['location_code'].'-'.$row['game_code']) {
- // complete the previous location/game combi (if there was a prev_location_game_combi ):
- // add "lowest min_number, the highest max_number, and the lowest price" to the price_number_data array
- if (!empty($prev_location_game_combi)) {
- $price_number_data[$prev_location_game_combi]['lowest_price'] = $lowest_price;
- $price_number_data[$prev_location_game_combi]['lowest_total_price'] = $lowest_total_price;
- $price_number_data[$prev_location_game_combi]['low_min_number'] = $low_min_number;
- $price_number_data[$prev_location_game_combi]['high_max_number'] = $high_max_number;
- }
- // then collect info for this new location/game combi
- $town_locations_games_values[] = $row;
- // and initialise the loop for same location/game
- if ($row['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $row['diner_price_foodfun'];
- } else {
- $diner_price = $row['diner_price'];
- }
- $lowest_price =$row['game_price'];
- $low_min_number = $row['min_number'];
- $high_max_number = $row['max_number'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- } else {
- // for each group of "wp_rel_locations_games" rows per "location/game" combination,
- // swap "lowest min_number, the highest max_number, and the lowest price" if better candidates are found
- if ($row['game_price'] < $lowest_price) {
- $lowest_price = $row['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row['min_number'] < $low_min_number) {
- $low_min_number = $row['min_number'];
- }
- if ($row['max_number'] > $high_max_number) {
- $high_max_number = $row['max_number'];
- }
- }
- //-------------------------------------------------------------------------------------------
- $prev_location_code = $row['location_code'];
- $prev_location_game_combi = $row['location_code'].'-'.$row['game_code'];
- }
- // complete the last location/game combi:
- if (!empty($prev_location_game_combi)) {
- $price_number_data[$prev_location_game_combi]['lowest_price'] = $lowest_price;
- $price_number_data[$prev_location_game_combi]['lowest_total_price'] = $lowest_total_price;
- $price_number_data[$prev_location_game_combi]['low_min_number'] = $low_min_number;
- $price_number_data[$prev_location_game_combi]['high_max_number'] = $high_max_number;
- }
- }
- // loop complete, finish
- $data["location_coordinates"] .= '
- ]';
- // -> general_content['all_locations']
- $row = $wpdb->get_col("SELECT all_locations FROM wp_pods_general_content " );
- $all_locations_text_value = $row[0];
- }
- //---------------------------------------------------------------------------------------
- // GET ALL GAMES PLAYED WITHIN A RADIUS OF 15 KM OF THIS TOWN
- if ( in_array($parsetype, array('5', '8', '13', '14' ))) { // plaats, spel/plaats/locatie, plaats/locatie
- if (isset($town_values['town_coordinates']) ) {
- $json_geolocation = $town_values['town_coordinates'];
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- if ( isset($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lat)
- && isset($obj_googlemapcoords->lng) && !empty($obj_googlemapcoords->lng)
- ) {
- //error_log('lat: '.$obj_googlemapcoords->lat.' - lng: '.$obj_googlemapcoords->lng);
- $center_latitude = $obj_googlemapcoords->lat;
- $center_longitude = $obj_googlemapcoords->lng;
- $town_location_games_values_radius = array();
- //$town_location_slider_images_radius = array();
- $town_location_slider_images_radius = '';
- // $parsetype = '8'; // PLAATS
- // $parsetype = '5'; // TREFWOORD/PLAATS
- // $parsetype = '13'; // SPEL/PLAATS/LOCATIE
- // $parsetype = '14'; // PLAATS/LOCATIE
- if (in_array($parsetype, array('13', '14' )) && isset($location_code) && !empty($location_code)) {
- // $do_radius = TRUE;
- $params_radius = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.diner_price,
- t.diner_price_foodfun,
- t.location_coordinates,
- town.town_code as town_code,
- town.town_name as town_name
- ',
- 'where' => " location_code <> '".$location_code."'
- ",
- 'orderby' => 'town_name, location_name',
- 'limit' => 0
- );
- } elseif (in_array($parsetype, array('5', '8')) && isset($town_code) && !empty($town_code)) {
- // $do_radius = TRUE;
- $params_radius = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code,
- t.diner_price,
- t.diner_price_foodfun,
- t.location_coordinates,
- town.town_code as town_code,
- town.town_name as town_name
- ',
- 'where' => " town.town_code <> '".$town_code."'
- ",
- 'orderby' => 'town_name, location_name',
- 'limit' => 0
- );
- }
- $tmp_locations_pod_radius = pods( 'locations', $params_radius );
- $tmp_locations_pod_radius_total = $tmp_locations_pod_radius->total();
- if ($tmp_locations_pod_radius_total > 0 ):
- $i=0;
- while ($tmp_locations_pod_radius->fetch() ):
- $row_radius = $tmp_locations_pod_radius->row();
- $json_geolocation_radius = $row_radius['location_coordinates'];
- $obj_googlemapcoords_radius = json_decode($json_geolocation_radius);
- if (!empty($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lng) ) {
- if ( isset($obj_googlemapcoords_radius->lat) && !empty($obj_googlemapcoords_radius->lat)
- && isset($obj_googlemapcoords_radius->lng) && !empty($obj_googlemapcoords_radius->lng)
- ) {
- $check_latitude = $obj_googlemapcoords_radius->lat;
- $check_longitude = $obj_googlemapcoords_radius->lng;
- }
- }
- if (empty($check_latitude) || empty($check_longitude) ) continue;
- $sql = 'SELECT DISTINCT
- ( 3959 * acos(cos(radians('.$center_latitude.')) * cos( radians( '.$check_latitude.' ) )
- * cos( radians( '.$check_longitude.' ) - radians('.$center_longitude.') )
- + sin(radians('.$center_latitude.')) * sin(radians('.$check_latitude.' )))
- ) AS distance';
- $distance = $wpdb->get_row( $sql )->distance;
- if (is_numeric($distance) && $distance > 0 && $distance < 7):
- $town_location_games_values_radius[$i]['location_code'] = $row_radius['location_code'];
- $town_location_games_values_radius[$i]['location_name'] = $row_radius['location_name'];
- $town_location_games_values_radius[$i]['town_code'] = $row_radius['town_code'];
- $town_location_games_values_radius[$i]['town_name'] = $row_radius['town_name'];
- if (!empty($location_values['location_images']) && @strpos($location_values['location_images'], $town_location_slider_images_radius) === false ) {
- $town_location_slider_images_radius .= $location_values['location_images'].' ';
- }
- $game_params_radius = array(
- 'select' => 't.id as game_id,
- t.game_code,
- t.game_name,
- t.game_short_descr,
- wp_rel_locations_games.* ',
- 'join' => 'INNER JOIN wp_rel_locations_games ON (
- wp_rel_locations_games.game_id = t.id
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- )',
- 'where' => 'wp_rel_locations_games.location_id = "'.$row_radius['location_id'].'"
- AND wp_rel_locations_games.game_id = t.id
- AND wp_rel_locations_games.activated = 1
- ',
- 'orderby' => 'game_order, game_code, min_number',
- 'limit' => 0
- );
- $tmp_games_pod_radius = pods( 'games', $game_params_radius );
- // collect data for the games played at this location
- if ( $tmp_games_pod_radius->total() > 0 ):
- $lowest_price = 999.99;
- $prev_game_code = '';
- while ($tmp_games_pod_radius->fetch() ):
- $row2_radius = $tmp_games_pod_radius->row();
- $tmp_games_game_code_radius = $row2_radius['game_code'];
- // collect images for this game
- $img_game_params_radius = array(
- 'select' => ' t.id ',
- 'where' => 'game_code = "'.$tmp_games_game_code_radius.'"',
- 'limit' => 0
- );
- $img_games_pod_radius = pods( 'games', $img_game_params_radius );
- if ( $img_games_pod_radius->total() > 0 ) {
- $thumbnail = pods_image_url(
- $img_games_pod_radius->field( 'game_images', TRUE ),
- 'thumbnail-rectangle',
- 0,
- true
- );
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_image'] = $thumbnail;
- // for the big top slider:
- //if (!empty($game_images_str_radius) && strpos($game_images_str_radius, $town_location_slider_images_radius) === false ) {
- if (!empty($game_images_str_radius) && @strpos($town_location_slider_images_radius, $game_images_str_radius) === false ) {
- $town_location_slider_images_radius .= $game_images_str_radius.' ';
- }
- }
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_code'] = $row2_radius['game_code'];
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_name'] = $row2_radius['game_name'];
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['game_short_descr'] = $row2_radius['game_short_descr'];
- // get the lowset total price for each game, plus the lowest number of people
- if ($row2_radius['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $row_radius['diner_price_foodfun'];
- } else {
- $diner_price = $row_radius['diner_price'];
- }
- if ($tmp_games_game_code_radius == $prev_game_code) {
- // override if lower than the previous game-prices occurrence
- if ($row2_radius['game_price'] < $lowest_price) {
- $lowest_price = $row2_radius['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- }
- if ($row2_radius['min_number'] < $low_min_number) {
- $low_min_number = $row2_radius['min_number'];
- }
- if ($row2_radius['max_number'] > $high_max_number) {
- $high_max_number = $row2_radius['max_number'];
- }
- } else {
- // the first game-prices occurrence
- $lowest_price = $row2_radius['game_price'];
- $lowest_total_price = (float)$diner_price + (float)$lowest_price;
- $low_min_number = $row2_radius['min_number'];
- $high_max_number = $row2_radius['max_number'];
- $prev_game_code = $row2_radius['game_code'];
- }
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['lowest_total_price']= $lowest_total_price;
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['low_min_number'] = $low_min_number;
- $town_location_games_values_radius[$i]['location_games'][$tmp_games_game_code_radius]['high_max_number'] = $high_max_number;
- endwhile;
- endif;
- endif;
- $i++;
- endwhile;
- endif;
- }
- }
- }
- }
- if (in_array($parsetype, array('7'))) {
- include dirname(__FILE__) . '/templates/tpl_tag.php';
- exit();
- }
- if (in_array($parsetype, array('5'))) {
- include dirname(__FILE__) . '/templates/tpl_tag_town.php';
- exit();
- }
- if (in_array($parsetype, array('1'))) {
- //include dirname(__FILE__) . '/templates/tpl_tag_game_town_location.php';
- include dirname(__FILE__) . '/templates/tpl_game_town_location.php';
- exit();
- }
- if (in_array($parsetype, array('10'))) {
- include dirname(__FILE__) . '/templates/tpl_game.php';
- exit();
- }
- if (in_array($parsetype, array('12', '9'))) {
- include dirname(__FILE__) . '/templates/tpl_game_town.php';
- exit();
- }
- if (in_array($parsetype, array('13'))) {
- // for the datepicker in the form
- //$currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- //$curryear = $currlocaldate->format('Y');
- date_default_timezone_set('Europe/Amsterdam');
- $curryear = date('Y');
- if ($location_code == 'eigen-locatie') {
- include dirname(__FILE__) . '/templates/tpl_game_town_own_location.php';
- } else {
- include dirname(__FILE__) . '/templates/tpl_game_town_location.php';
- }
- exit();
- }
- if (in_array($parsetype, array('18'))) {
- // for the datepicker in the form
- // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- // $curryear = $currlocaldate->format('Y');
- date_default_timezone_set('Europe/Amsterdam');
- $curryear = date('Y');
- include dirname(__FILE__) . '/templates/tpl_game_own_location.php';
- exit();
- }
- if (in_array($parsetype, array('8'))) {
- include dirname(__FILE__) . '/templates/tpl_town.php';
- exit();
- }
- if (in_array($parsetype, array('17'))) {
- include dirname(__FILE__) . '/templates/tpl_own_location.php';
- exit();
- }
- // WE USE '12' FOR THIS (tpl_game_town)
- // if (in_array($parsetype, array('9'))) {
- // include dirname(__FILE__) . '/templates/tpl_town_game.php';
- // exit();
- // }
- if (in_array($parsetype, array('14'))) {
- include dirname(__FILE__) . '/templates/tpl_town_location.php';
- exit();
- }
- if (in_array($parsetype, array('15'))) {
- include dirname(__FILE__) . '/templates/tpl_all_towns.php';
- exit();
- }
- if (in_array($parsetype, array('16'))) {
- include dirname(__FILE__) . '/templates/tpl_all_games.php';
- exit();
- }
- if (in_array($parsetype, array('19'))) {
- include dirname(__FILE__) . '/templates/tpl_all_locations.php';
- exit();
- }
- }
- }
- //==========================================================================================================================
- public function _check_action_array($arr_action, $array_tags, $array_games, $array_towns, $array_locations) {
- //==========================================================================================================================
- $parsetype = '0';
- $part_1 = $part_2 = $part_3 = $part_4 = '';
- if (isset($arr_action[0])) $part_1 = $arr_action[0];
- if (isset($arr_action[1])) $part_2 = $arr_action[1];
- if (isset($arr_action[2])) $part_3 = $arr_action[2];
- if (isset($arr_action[3])) $part_4 = $arr_action[3];
- // TRY TO MATCH WITH PARSETYPE 1 - TREFWOORD/SPEL/PLAATS/LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
- (isset($part_3) && !empty($part_3) && in_array($part_3, $array_towns) ) &&
- (isset($part_4) && !empty($part_4) && in_array($part_4, $array_locations) )
- ) {
- $parsetype = '1'; // TREFWOORD/SPEL/PLAATS/LOCATIE
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 2 - TREFWOORD/SPEL/LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
- (isset($part_3) && !empty($part_3) && in_array($part_3, $array_locations) )
- ) {
- $parsetype = '2'; // TREFWOORD/SPEL/PLAATS/LOCATIE
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 3 - TREFWOORD/SPEL/PLAATS/
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) ) &&
- (isset($part_3) && !empty($part_3) && in_array($part_3, $array_towns) )
- ) {
- $parsetype = '3'; // TREFWOORD/SPEL/PLAATS
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 13 - SPEL/PLAATS/LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) ) &&
- (isset($part_3) && !empty($part_3) && in_array($part_3, $array_locations) )
- ) {
- $parsetype = '13'; // TREFWOORD/SPEL
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 4 - TREFWOORD/LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_locations) )
- ) {
- $parsetype = '4'; // TREFWOORD/LOCATIE
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 5 - TREFWOORD/PLAATS
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) )
- ) {
- $parsetype = '5'; // TREFWOORD/PLAATS
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 6 - TREFWOORD/SPEL
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) )
- ) {
- $parsetype = '6'; // TREFWOORD/SPEL
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 9 - PLAATS/SPEL
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_games) )
- ) {
- $parsetype = '9'; // PLAATS/SPEL
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 14 - PLAATS/LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_locations) )
- ) {
- $parsetype = '14'; // PLAATS/LOCATIE
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 11 - SPEL/TREFWOORD
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_tags) )
- ) {
- $parsetype = '11';
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 12 - SPEL/PLAATS
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) ) &&
- (isset($part_2) && !empty($part_2) && in_array($part_2, $array_towns) )
- ) {
- $parsetype = '12';
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 18 - SPEL/EIGEN-LOCATIE
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) ) &&
- (isset($part_2) && $part_2 == 'eigen-locatie' )
- ) {
- $parsetype = '18';
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 7 - TREFWOORD
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_tags) )
- ) {
- $parsetype = '7'; // TREFWOORD
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 8 - PLAATS
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_towns) )
- ) {
- $parsetype = '8'; // SPEL
- }
- }
- if ($parsetype == '0') {
- // TRY TO MATCH WITH PARSETYPE 10 - SPEL
- if (
- (isset($part_1) && !empty($part_1) && in_array($part_1, $array_games) )
- ) {
- $parsetype = '10'; // SPEL
- }
- }
- return array($parsetype, $part_1, $part_2, $part_3, $part_4);
- }
- //=====================================================================================
- public function beschikbaarheidsaanvraag() {
- global $wpdb;
- // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- // $curryear = $currlocaldate->format('Y');
- date_default_timezone_set('Europe/Amsterdam');
- $curryear = date('Y');
- // // cannot process form without these fields:
- if (
- ( isset( $_POST['game_code']) && !empty( $_POST['game_code']) &&
- isset( $_POST['town_code']) && !empty( $_POST['town_code']) &&
- isset( $_POST['location_code']) && !empty( $_POST['location_code'])
- )
- ||
- ( isset( $_POST['game_code']) && !empty( $_POST['game_code']) &&
- isset( $_POST['location_code']) && $_POST['location_code'] == 'eigen-locatie'
- )
- ) {
- // OK, continue
- } else {
- exit();
- }
- if ( empty($_POST['tijd2'])) {
- //ok
- } else {
- // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
- wp_redirect( home_url());
- die();
- //-------------------------------------------------------------------------------
- }
- $errors = array();
- $arrRequiredFields = array('emailadres', 'voornaam', 'achternaam', 'voorkeursdatum_1', 'aantal_pers', 'tijd');
- // check if all required fields have been filled in
- foreach($_POST as $key => $value) {
- if (empty($value) ) {
- if (in_array($key, $arrRequiredFields) ) {
- $key2show = ucfirst(str_replace('_', ' ', $key));
- array_push( $errors, 'Vul svp uw '.$key2show.' in');
- }
- }
- }
- $user_email = ( isset ( $_POST['emailadres'] ) ? trim($_POST['emailadres']) : '' );
- if ( !empty($user_email) && !is_email( $user_email ) )
- array_push( $errors, 'Vult u a.u.b. een geldig e-mailadres in');
- // elseif ( email_exists( $user_email ) )
- // array_push( $errors, 'Er is al een account met dit e-mailadres' );
- if ( !is_numeric($_POST['aantal_pers']) )
- array_push( $errors, 'Vult u a.u.b. uitsluitend een aantal in<br />bij Aantal personen');
- // create certain allowed variables from the $_POST
- $arr_allowed_fields = array('voornaam', 'achternaam', 'geslacht', 'emailadres', 'telefoon', 'game_code', 'town_code', 'location_code', 'voorkeursdatum_1', 'voorkeursdatum_2', 'aantal_pers', 'tijd', 'opmerking_klant');
- foreach ($_POST as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = trim($value);
- }
- }
- $game_code = $_POST['game_code'];
- $town_code = $_POST['town_code'];
- $location_code = $_POST['location_code'];
- //---------------------------------------------------------------------------------------
- // GET THE MIN AND MAX NUMBER OF PERSONS
- $sql = $wpdb->prepare("SELECT id as game_id, game_name FROM wp_pods_games WHERE game_code = %s", $game_code);
- $game_row = $wpdb->get_row($sql, ARRAY_A);
- $game_id = $game_row['game_id'];
- $game_name = $game_row['game_name'];
- $sql = $wpdb->prepare("SELECT id as town_id, town_name FROM wp_pods_towns WHERE town_code = %s", $town_code);
- $town_row = $wpdb->get_row($sql, ARRAY_A);
- $town_id = $town_row['town_id'];
- $town_name = $town_row['town_name'];
- $sql = $wpdb->prepare("SELECT id as location_id, location_name, email_address, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $location_id = $location_row['location_id'];
- $location_name = $location_row['location_name'];
- $location_email = $location_row['email_address'];
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- if (!empty($location_id)) {
- $rel_location_game_obj = $wpdb->get_row(
- "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$location_id."
- AND game_id = ".$game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- "
- );
- $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
- $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
- }
- $post_aantal_pers = (int)$_POST['aantal_pers'];
- if ( $post_aantal_pers < $min_aantal_pers || $post_aantal_pers > $max_aantal_pers ) {
- $errors[] = 'Het minimum aantal deelnemers is: '.$min_aantal_pers.'. Het maximum aantal is: '.$max_aantal_pers;
- }
- if ( !empty( $errors ) ) {
- // form fields errors, populate form and show again
- // for the datepicker in the form
- // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- // $curryear = $currlocaldate->format('Y');
- date_default_timezone_set('Europe/Amsterdam');
- $curryear = date('Y');
- include dirname(__FILE__) . '/templates/tpl_beschikbaarheidsaanvraag.php';
- exit();
- //-------------------------------------------------------------------------------
- }
- // OK, store this 'aanvraag' and send out emails
- if (!empty($_POST['voorkeursdatum_1'])) {
- $date1 = new DateTime(str_replace('/', '-', $_POST['voorkeursdatum_1']));
- $voorkeursdatum_1_ymd = $date1->format('Y-m-d');
- } else {
- $voorkeursdatum_1_ymd = '';
- }
- if (!empty($_POST['voorkeursdatum_2'])) {
- $date1 = new DateTime(str_replace('/', '-', $_POST['voorkeursdatum_2']));
- $voorkeursdatum_2_ymd = $date1->format('Y-m-d');
- } else {
- $voorkeursdatum_2_ymd = '';
- }
- $code_locatie = random_string();
- $code_dinerspel = random_string();
- $code_klant = random_string();
- $code_klant_mutatie = random_string();
- $url_code_locatie = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $url_code_dinerspel = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
- $url_code_klant = home_url().'/reserveren/'.$code_klant;
- $sqlQuery = $wpdb->prepare(
- "INSERT wp_pods_aanvragen SET
- name = %s,
- voornaam = %s,
- geslacht = %s,
- emailadres = %s,
- telefoon = %s,
- game_code = %s,
- town_code = %s,
- location_code = %s,
- voorkeursdatum_1 = %s,
- voorkeursdatum_2 = %s,
- aantal_pers = %d,
- tijd = %s,
- opmerking_klant = %s,
- code_locatie = %s,
- code_dinerspel = %s,
- code_klant = %s,
- code_klant_mutatie = %s,
- url_code_locatie = %s,
- url_code_dinerspel = %s,
- url_code_klant = %s,
- created = NOW(),
- send_doc_1 = '0',
- send_doc_2 = '1',
- send_doc_3 = '1',
- send_doc_4 = '1',
- action_status = 'Informatief',
- action_date = '',
- planning_status = 'OPEN'
- ",
- $achternaam,
- $voornaam,
- $geslacht,
- $emailadres,
- $telefoon,
- $game_code,
- $town_code,
- $location_code,
- $voorkeursdatum_1_ymd,
- $voorkeursdatum_2_ymd,
- $aantal_pers,
- $tijd,
- $opmerking_klant,
- $code_locatie,
- $code_dinerspel,
- $code_klant,
- $code_klant_mutatie,
- $url_code_locatie,
- $url_code_dinerspel,
- $url_code_klant
- );
- $updres = $wpdb->get_results( $sqlQuery );
- //////////////////////////////////////////////////////////////////////////////////
- $voorkeursdatum_1 = format_nlDate($_POST['voorkeursdatum_1']);
- $voorkeursdatum_2 = format_nlDate($_POST['voorkeursdatum_2']);
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($achternaam);
- //$geslacht = strtolower($geslacht);
- $opmerking_klant = stripslashes($opmerking_klant);
- $website = 'Dinerspel.nl';
- //======================================================
- if ($location_code == 'eigen-locatie') {
- //======================================================
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- //----------------------------------
- // stuur email naar KLANT
- //----------------------------------
- $klant_email = $emailadres;
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_EL_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar DINERSPEL
- //----------------------------------
- $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
- $url_msg = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_EL_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag voor eigen locatie via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_EL_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- //=====================================================================================
- } elseif ($zelfstandige_locatie) {
- //=====================================================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur email naar KLANT
- //----------------------------------
- $klant_email = $emailadres;
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar (ZELFSTANDIGE) LOCATIE
- //----------------------------------
- if (!empty($location_email)) {
- $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- }
- //----------------------------------
- // stuur email naar DINERSPEL
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_ZL_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- //=====================================================================================
- } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
- //=====================================================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur email naar KLANT
- //----------------------------------
- $klant_email = $emailadres;
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar LOCATIE
- //----------------------------------
- if (!empty($location_email)) {
- $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- }
- //----------------------------------
- // stuur email naar DINERSPEL
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- //======================================================
- } else {
- //======================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur email naar KLANT
- //----------------------------------
- $klant_email = $emailadres;
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $klant_email, 'Bedankt voor uw beschikbaarheidsaanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar LOCATIE
- //----------------------------------
- if (!empty($location_email)) {
- $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $location_email, ' Nieuwe beschikbaarheid via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- }
- //----------------------------------
- // stuur email naar DINERSPEL
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- }
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit();
- }
- //================================================
- public function ophalen_beschikbaarheid_bij_locatie() {
- //================================================
- global $wpdb;
- // get access code
- $redirecturl = $_SERVER['REDIRECT_URL'];
- $arrUrl = explode('/', $redirecturl);
- $key = array_search('reageer-op-beschikbaarheidsaanvraag', $arrUrl);
- $access_code = $arrUrl[($key+1)];
- if (!$access_code || empty($access_code) ) exit();
- // Get activation record for the user
- $sql = $wpdb->prepare("SELECT * FROM wp_pods_aanvragen
- WHERE code_locatie = %s", $access_code);
- $row_aanvraag = $wpdb->get_row($sql, ARRAY_A);
- if ( !$row_aanvraag ) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- // create certain allowed variables from $arr_aanvraag[0]
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $achternaam = ucwords($name);
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- // check if perhaps ZELFSTANDIGE LOCATIE
- $sql = $wpdb->prepare("SELECT zelfstandige_locatie FROM wp_pods_locations
- WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $form_action = home_url().'/verwerk-beschikbaarheid-van-locatie';
- //----------------------------------
- // show form to enter response
- //----------------------------------
- ob_start();
- if ($zelfstandige_locatie || $game_code == 'onfortuinlijke-bankier' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'into-the-box' || $game_code == 'koudgemaakte-kok') {
- // In that case the location's availablility will be the only thing needed, show a different form
- // because the location needs to be able to add a comment for the customer
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_ZL_voor_locatie.php");
- } else{
- include_once(dirname(__FILE__) . "/templates/tpl_page_beschikbaarheidsaanvraag_voor_locatie.php");
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- //=====================================================================================
- public function verwerken_beschikbaarheid_van_locatie(){
- global $wpdb;
- if (!$_POST['access_code'] || empty($_POST['access_code']) ) exit();
- // Get activation record for the user
- // $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- // WHERE code_locatie = '".esc_sql($_POST['access_code'])."'";
- // $recordset = $wpdb->get_results( $sqlQuery );
- $sql = $wpdb->prepare("SELECT * FROM wp_pods_aanvragen WHERE code_locatie = %s", $_POST['access_code']);
- $row_aanvraag = $wpdb->get_row($sql, ARRAY_A);
- if ( !$row_aanvraag) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $emailadres_klant = $emailadres;
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- // check if perhaps ZELFSTANDIGE LOCATIE
- $sql = $wpdb->prepare("SELECT zelfstandige_locatie FROM wp_pods_locations
- WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $achternaam = ucwords($name);
- $voorkeursdatum_1_janee_locatie = ($_POST['voorkeursdatum_1_janee'] == 'ja') ? 1 : 0 ;
- $voorkeursdatum_2_janee_locatie = ($_POST['voorkeursdatum_2_janee'] == 'ja') ? 1 : 0 ;
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- $sqlQuery = $wpdb->prepare(
- "UPDATE wp_pods_aanvragen
- SET voorkeursdatum_1_janee_locatie = %s,
- voorkeursdatum_2_janee_locatie = %s,
- opmerking_locatie = %s,
- code_locatie = '',
- date_location_beschikbaarheid = NOW(),
- modified = NOW()
- WHERE code_locatie = %s
- ",
- $voorkeursdatum_1_janee_locatie,
- $voorkeursdatum_2_janee_locatie,
- stripslashes(htmlspecialchars($_POST['opmerking_locatie'], ENT_QUOTES,'UTF-8')),
- $_POST['access_code']
- );
- $updres = $wpdb->get_results( $sqlQuery );
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $url_msg = home_url().'/beschikbaarheidsaanvraag-afhandelen/'.$code_dinerspel;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- //include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
- if ($zelfstandige_locatie) {
- // In that case the location's availablility will be the only thing needed, show a different form
- // because the location needs to be able to add a comment for the customer
- // also, the customer will be notified right away
- //----------------------------------
- // stuur email naar Dinerspel
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_ZL_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //$activate_link = home_url().'/reserveren/'.$code_klant;
- $url_msg = home_url().'/reserveren/'.$code_klant;
- $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- ob_start();
- if ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 1) {
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_beide_data.php");
- }
- if ( ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 0) ||
- ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_2_janee_locatie == 1) ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_1_janee_locatie == 0) {
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_ZL_naar_klant_beide_niet.php");
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
- // In that case the location's availablility will be the only thing needed, show a different form
- // because the location needs to be able to add a comment for the customer
- // also, the customer will be notified right away
- //----------------------------------
- // stuur email naar Dinerspel
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //$activate_link = home_url().'/reserveren/'.$code_klant;
- $url_msg = home_url().'/reserveren/'.$code_klant;
- $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- ob_start();
- if ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 1) {
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
- }
- if ( ($voorkeursdatum_1_janee_locatie == 1 && $voorkeursdatum_2_janee_locatie == 0) ||
- ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_2_janee_locatie == 1) ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee_locatie == 0 && $voorkeursdatum_1_janee_locatie == 0) {
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- } else {
- // 'normale' locatie, alleen bericht naar dinerspel
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_reactie_locatie_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Reactie van locatie op nieuwe aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- }
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_reactie_locatie_naar_dinerspel_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- //=====================================================================================
- public function afhandelen_beschikbaarheidsaanvraag(){
- // DOOR DINERSPEL, GETRIGGERD VIA LINK IN EMAIL GESTUURD NAAR DINERSPEL
- // EMAIL: tpl_email_reactie_locatie_naar_dinerspel.php
- global $wpdb;
- // get access code
- $redirecturl = $_SERVER['REDIRECT_URL'];
- $arrUrl = explode('/', $redirecturl);
- $key = array_search('beschikbaarheidsaanvraag-afhandelen', $arrUrl);
- $access_code = $arrUrl[($key+1)];
- if (!$access_code || empty($access_code) ) exit();
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_dinerspel = '".esc_sql($access_code)."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- if ( empty($recordset) ) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- $row_aanvraag = $recordset[0];
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $achternaam = $name;
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- if ($location_code == 'eigen-locatie') {
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $website = 'Dinerspel.nl';
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- $form_action = home_url().'/verwerken-afhandeling-beschikbaarheidsaanvraag';
- //----------------------------------
- // show form to enter response
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_afhandelen_beschikbaarheidsaanvraag_EL_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- } else {
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $form_action = home_url().'/verwerken-afhandeling-beschikbaarheidsaanvraag';
- //----------------------------------
- // show form to enter response
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_afhandelen_beschikbaarheidsaanvraag_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- }
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- //=====================================================================================
- public function verwerken_afhandeling_beschikbaarheidsaanvraag(){
- // GETRIGGERD VIA SUBMIT FORM OP PAGINA tpl_page_afhandelen_beschikbaarheidsaanvraag_dinerspel.php
- global $wpdb;
- if (!$_POST['access_code'] || empty($_POST['access_code']) ) exit();
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_dinerspel = '".esc_sql($_POST['access_code'])."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- if ( empty($recordset) ) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- $row_aanvraag = $recordset[0];
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $emailadres_klant = $emailadres;
- $voorkeursdatum_1_janee = ($_POST['voorkeursdatum_1_janee'] == 'ja') ? 1 : 0 ;
- $voorkeursdatum_2_janee = ($_POST['voorkeursdatum_2_janee'] == 'ja') ? 1 : 0 ;
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- $sqlQuery = "UPDATE wp_pods_aanvragen
- SET
- voorkeursdatum_1_janee_dinerspel = '".esc_sql($voorkeursdatum_1_janee)."',
- voorkeursdatum_2_janee_dinerspel = '".esc_sql($voorkeursdatum_2_janee)."',
- opmerking_dinerspel = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_dinerspel'], ENT_QUOTES,'UTF-8')))."',
- date_dinerspel_beschikbaarheid = NOW(),
- modified = NOW()
- WHERE code_dinerspel = '".esc_sql($_POST['access_code'])."'";
- $updres = $wpdb->get_results( $sqlQuery );
- if ($location_code == 'eigen-locatie') {
- $website = 'Dinerspel.nl';
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $opmerking_dinerspel = stripslashes($_POST['opmerking_dinerspel']);
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- $url_msg = home_url().'/reserveren/'.$code_klant;
- $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
- ob_start();
- if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_data.php");
- if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ||
- ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_niet.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- } else {
- $website = 'Dinerspel.nl';
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $emailadres_klant = $emailadres;
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $opmerking_dinerspel = stripslashes($_POST['opmerking_dinerspel']);
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- //$activate_link = home_url().'/reserveren/'.$code_klant;
- $url_msg = home_url().'/reserveren/'.$code_klant;
- $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- ob_start();
- if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
- if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ||
- ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
- include_once(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres_klant, ' Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- }
- //----------------------------------
- // show thank you page
- //----------------------------------
- $message = 'Email naar klant is verstuurd';
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- //=====================================================================================
- public function reserveren() {
- // TOONT FORM, PAGINA tpl_page_reserveren_dinerspel.php
- // AFHANDELEN FORM SUBMIT (--> email naar dinerspel met link naar aanvraag edit page
- global $wpdb;
- $errors = array();
- if ($_POST) {
- if (!$_POST['access_code'] || empty($_POST['access_code']) ) {
- $error[] = 'Ontbrekende toegangscode';
- exit();
- } else {
- $access_code = $_POST['access_code'];
- }
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_klant = '".esc_sql($_POST['access_code'])."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- if ( empty($recordset) ) {
- $errors[] = 'Deze pagina is niet (meer) beschikbaar';
- exit();
- } else {
- $row_aanvraag = $recordset[0];
- }
- if (empty($_POST['telefoon'] )) {
- $errors[] = 'Graag uw telefoonnummer invullen a.u.b.';
- }
- if (empty($_POST['adres'] )) {
- $errors[] = 'Graag uw adres invullen t.b.v. de administratie';
- }
- if (empty($_POST['postcode'] )) {
- $errors[] = 'Graag uw postcode invullen t.b.v. de administratie';
- }
- if (empty($_POST['woonplaats'] )) {
- $errors[] = 'Graag uw woonplaats invullen t.b.v. de administratie';
- }
- if (empty($_POST['aantal_pers'] )) {
- $errors[] = 'Graag het aantal personen invullen t.b.v. de administratie';
- } elseif (!is_numeric($_POST['aantal_pers'])) {
- $errors[] = 'Graag uitsluitend een aantal invullen bij Aantal personen';
- }
- 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') ) {
- $errors[] = 'Gaat u a.u.b. akkoord met onze voorwaarden';
- }
- if (!empty($_POST['btw_nummer'] )) {
- $vatNumber = trim($_POST['btw_nummer']);
- $vatNumber = str_replace('.', '', $vatNumber);
- $vatNumber = str_replace(' ', '', $vatNumber);
- $vatNumber = preg_replace('/[^0-9]/', '', $vatNumber);
- $_POST['btw_nummer'] = $vatNumber;
- $checkresult = viesCheckVAT ( $_POST['country_code'], $vatNumber ); // '19386256'
- //print_r($checkresult);
- //die();
- if (!is_array($checkresult) || !isset($checkresult['valid']) || $checkresult['valid'] == 'false') {
- $errors[] = '
- Het door u ingevulde BTW nummer blijkt niet juist te zijn.<br />
- U kunt doorgaan met reserveren zonder BTW nummer, maar de prijs wordt dan inclusief BTW berekend.<br />
- Als u het nummer wilt corrigeren:<br>
- - gebruik geen punten of spaties<br>
- - verwijder voorvoegsels als NL of BE (dus voer alleen de cijfers in)';
- }
- }
- //---------------------------------------------------------------------------------------
- // GET THE MIN AND MAX NUMBER OF PERSONS
- $row = $wpdb->get_row("SELECT id as location_id, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'" );
- $location_id = $row->location_id;
- $zelfstandige_locatie = $row->zelfstandige_locatie;
- if (!empty($location_id)) {
- $row = $wpdb->get_col("SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'" );
- $game_id = $row[0];
- $rel_location_game_obj = $wpdb->get_row(
- "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$location_id."
- AND game_id = ".$game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- "
- );
- $min_aantal_pers = (int)$rel_location_game_obj->min_aantal_pers;
- $max_aantal_pers = (int)$rel_location_game_obj->max_aantal_pers;
- }
- $post_aantal_pers = (int)$_POST['aantal_pers'];
- if ( $post_aantal_pers < $min_aantal_pers || $post_aantal_pers > $max_aantal_pers ) {
- $errors[] = 'Het minimum aantal deelnemers is: '.$min_aantal_pers.'. Het maximum aantal is: '.$max_aantal_pers;
- }
- if (count($errors) == 0) {
- // EERSTE VERWERKING RESERVERING (GAAT NOG NIET VERDER DAN EMNAIL NAAR DINERSPEL)
- // CREATE VARIABLES FROM ROW_AANVRAAG
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- // create certain allowed variables from the $_POST as well
- $arr_allowed_fields = array('access_code', 'game_code', 'town_code', 'location_code', 'voorkeursdatum', 'bedrijfsnaam', 'telefoon',
- 'adres', 'postcode', 'woonplaats', 'country_code', 'btw_nummer', 'opmerking_klant_res', 'aantal_pers', 'eigen_locatie_data');
- foreach ($_POST as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = stripslashes(htmlspecialchars($value, ENT_QUOTES,'UTF-8'));
- }
- }
- // Haal landnaam op a.d.h.v. land code
- $country_name = return_country_name($country_code);
- // block BTW voor NL bedrijven
- if ($country_code == 'NL') $btw_nummer = '';
- if (isset($_POST['voorkeursdatum'])) {
- $reserveringsdatum = ($voorkeursdatum == '2') ? $voorkeursdatum_2 : $voorkeursdatum_1 ;
- $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
- $reserveringsdatum_ymd = $date1->format('Y-m-d');
- $reserveringsdatum = format_nlDate($reserveringsdatum);
- } else {
- // no date was chosen ,so there was no choice - only one date available
- // use field voorkeursdatum_1_janee_dinerspel or voorkeursdatum_2_janee_dinerspel
- // or field voorkeursdatum_1_janee_locatie or voorkeursdatum_2_janee_locatie
- // to determine which date to reserve
- if ($zelfstandige_locatie || $game_code == 'onfortuinlijke-bankier' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'into-the-box' || $game_code == 'koudgemaakte-kok') {
- // only "locatie" can have have responded, so
- if ($voorkeursdatum_1_janee_locatie == '1') {
- $reserveringsdatum = $voorkeursdatum_1 ;
- $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
- $reserveringsdatum_ymd = $date1->format('Y-m-d');
- $reserveringsdatum = format_nlDate($voorkeursdatum_1);
- } else {
- $reserveringsdatum = $voorkeursdatum_2 ;
- $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
- $reserveringsdatum_ymd = $date1->format('Y-m-d');
- $reserveringsdatum = format_nlDate($voorkeursdatum_2);
- }
- } else {
- // must be "dinerspel"
- if ($voorkeursdatum_1_janee_dinerspel == '1') {
- $reserveringsdatum = $voorkeursdatum_1 ;
- $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
- $reserveringsdatum_ymd = $date1->format('Y-m-d');
- $reserveringsdatum = format_nlDate($voorkeursdatum_1);
- } else {
- $reserveringsdatum = $voorkeursdatum_2 ;
- $date1 = new DateTime(str_replace('/', '-', $reserveringsdatum));
- $reserveringsdatum_ymd = $date1->format('Y-m-d');
- $reserveringsdatum = format_nlDate($voorkeursdatum_2);
- }
- }
- }
- if ($zelfstandige_locatie || $game_code == 'onfortuinlijke-bankier' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'into-the-box' || $game_code == 'koudgemaakte-kok') {
- $new_action_status = 'Gereserveerd';
- $new_reservering = '1';
- } else {
- $new_action_status = 'Voorlopige reservering';
- $new_reservering = '0';
- }
- $sqlQuery = "UPDATE wp_pods_aanvragen
- SET action_status = '".$new_action_status."',
- reservering = '".$new_reservering."',
- reserveringsdatum = '".$reserveringsdatum_ymd."',
- aantal_pers = '".esc_sql($aantal_pers)."',
- bedrijfsnaam = '".esc_sql(stripslashes(htmlspecialchars($_POST['bedrijfsnaam'], ENT_QUOTES,'UTF-8')))."',
- adres = '".esc_sql(stripslashes(htmlspecialchars($_POST['adres'], ENT_QUOTES,'UTF-8')))."',
- postcode = '".esc_sql($postcode)."',
- woonplaats = '".esc_sql(stripslashes(htmlspecialchars($_POST['woonplaats'], ENT_QUOTES,'UTF-8')))."',
- country_code = '".$country_code."',
- country_name = '".$country_name."',
- btw_nummer = '".esc_sql($btw_nummer)."',
- telefoon = '".esc_sql($telefoon)."',
- send_doc_1 = '0',
- send_doc_2 = '1',
- send_doc_3 = '1',
- send_doc_4 = '1',
- opmerking_klant_res = '".esc_sql(stripslashes(htmlspecialchars($_POST['opmerking_klant_res'], ENT_QUOTES,'UTF-8')))."',
- ";
- if (isset($eigen_locatie_data)) {
- $sqlQuery .= "
- eigen_locatie_data = '".esc_sql($eigen_locatie_data)."',
- ";
- }
- $sqlQuery .= "
- code_klant = '',
- date_booked = NOW(),
- modified = NOW()
- WHERE
- code_klant = '".esc_sql($access_code)."'";
- $updres = $wpdb->get_results( $sqlQuery );
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $opmerking_klant = stripslashes($opmerking_klant);
- $opmerking_klant_res = stripslashes($opmerking_klant_res);
- // THIS SCRIPT CAN RUN ON THE NL AS WELL AS THE BE SITE
- $site_country = SITECOUNTRY; // must be defined in the wp-config
- $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>';
- //=====================================================================================
- if ($location_code == 'eigen-locatie') {
- //=====================================================================================
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $opmerking_locatie = stripslashes($_POST['opmerking_locatie']);
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_EL_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_EL_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- //=====================================================================================
- } elseif ($zelfstandige_locatie) {
- //=====================================================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_klant.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- $headers = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
- get_header();
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres, ' Reservering bij '.$website, $message, $headers);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar LOCATIE
- //---------------------------
- // $row = $wpdb->get_col("SELECT email_address FROM wp_pods_locations WHERE location_code = '".$location_code."'" );
- // $location_email = $row[0];
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_locatie.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $locatie_emailadres, ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_ZL_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_ZL_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- //=====================================================================================
- } elseif ( $game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
- // do-it-yourself zoals onfortuinlijke bankier en the Box
- //=====================================================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $url_msg = home_url().'/mutatie-aantal/'.$code_klant_mutatie;
- $activate_link = '<a href="'.$url_msg.'">AANTAL PERSONEN AANPASSEN</a>';
- //----------------------------------
- // stuur email naar KLANT
- //---------------------------
- $klant_emailadres = $emailadres;
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_klant.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- $headers = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
- get_header();
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $emailadres, ' Reservering bij '.$website, $message, $headers);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar LOCATIE
- //---------------------------
- // $row = $wpdb->get_col("SELECT email_address FROM wp_pods_locations WHERE location_code = '".$location_code."'" );
- // $location_email = $row[0];
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_locatie.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $locatie_emailadres, ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- //=====================================================================================
- } else { // normale locaties
- //=====================================================================================
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $sql = $wpdb->prepare("SELECT email_address, telephone, contactperson, zelfstandige_locatie FROM wp_pods_locations WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- //----------------------------------
- // stuur email naar DINERSPEL
- //---------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_gereserveerd_naar_dinerspel.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail(get_option('admin_email'), ' Reservering via '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_gereserveerd_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- }
- } else {
- // NO POST, GET THE aanvraag from the code in the url
- // get access code
- $redirecturl = $_SERVER['REDIRECT_URL'];
- $arrUrl = explode('/', $redirecturl);
- $key = array_search('reserveren', $arrUrl);
- $access_code = $arrUrl[($key+1)];
- if (!$access_code || empty($access_code) ) exit();
- // Get activation record for the user
- $sqlQuery = "SELECT * FROM wp_pods_aanvragen
- WHERE code_klant = '".esc_sql($access_code)."'";
- $recordset = $wpdb->get_results( $sqlQuery );
- if ( empty($recordset) ) {
- $message = 'Deze pagina is niet (meer) beschikbaar';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- $row_aanvraag = $recordset[0];
- }
- foreach ($row_aanvraag as $key => $value) {
- $arrSkip = array('submit');
- if (!in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords(stripslashes($name));
- //$geslacht = strtolower($geslacht);
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', stripslashes($town_code)) );
- $location_name = ucwords(str_replace('-', ' ', stripslashes($location_code)) );
- $website = 'Dinerspel.nl';
- $form_action = home_url().'/reserveren';
- $opmerking_klant = stripslashes($opmerking_klant);
- $opmerking_klant_res = stripslashes($opmerking_klant_res);
- // get the 'conditions_document' // klant moet akkoord gaan met voorwaarden
- $params = array(
- 'select' => ' t.* ',
- 'where' => 'location_code = "'.$location_code.'"',
- 'limit' => 0
- );
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- $location_values = array();
- while ($locations_pod->fetch() ) {
- $location_row = $locations_pod->row();
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $conditions_document_url = (isset($location_row['conditions_document'])) ? $location_row['conditions_document'] : $locations_pod->display('conditions_document') ;
- }
- }
- if ($location_code == 'eigen-locatie') {
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- } else {
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- if ($location_row) {
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- }
- }
- //---------------------------------------------------------------------------------------
- // GET THE MIN AND MAX NUMBER OF PERSONS
- $row = $wpdb->get_col("SELECT id as location_id FROM wp_pods_locations WHERE location_code = '".$row_aanvraag->location_code."'" );
- $location_id = $row[0];
- $row = $wpdb->get_col("SELECT id as game_id FROM wp_pods_games WHERE game_code = '".$row_aanvraag->game_code."'" );
- $game_id = $row[0];
- if (!empty($location_id)) {
- $rel_location_game_obj = $wpdb->get_row(
- "SELECT MIN(min_number) as min_aantal_pers, MAX(max_number) as max_aantal_pers
- FROM wp_rel_locations_games
- WHERE location_id = ".$location_id."
- AND game_id = ".$game_id."
- AND (min_number IS NOT NULL AND min_number > 0)
- AND (max_number IS NOT NULL AND max_number > 0)
- "
- );
- $min_aantal_pers = $rel_location_game_obj->min_aantal_pers;
- $max_aantal_pers = $rel_location_game_obj->max_aantal_pers;
- }
- // CHECK IF THIS AANVRAAG HAS AN OVERRRIDE FOR THE MIN NUMBER
- if (isset($row_aanvraag->min_aantal_override) && is_numeric($row_aanvraag->min_aantal_override) && $row_aanvraag->min_aantal_override > 0) {
- $min_aantal_pers = $row_aanvraag->min_aantal_override;
- }
- //----------------------------------
- // show form to start reservation
- //----------------------------------
- ob_start();
- if ($zelfstandige_locatie || $game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
- if ($voorkeursdatum_1_janee_locatie == '0' && $voorkeursdatum_2_janee_locatie == '0') {
- // this should not be possible, klant should not have received an email with reservation access
- $message = 'Er is geen beschikbaarheid...';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit();
- }
- if ( ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ||
- ($voorkeursdatum_1_janee_locatie == '0' && $voorkeursdatum_2_janee_locatie == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee_locatie == '1' && $voorkeursdatum_2_janee_locatie == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- }
- if ($zelfstandige_locatie) {
- include_once(dirname(__FILE__) . "/templates/tpl_page_reservering_ZL.php");
- } else {
- include_once(dirname(__FILE__) . "/templates/tpl_page_reservering.php");
- }
- } else {
- if ($voorkeursdatum_1_janee_dinerspel == '0' && $voorkeursdatum_2_janee_dinerspel == '0') {
- // this should not be possible, klant should not have received an email with reservation access
- $message = 'Er is geen beschikbaarheid...';
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit();
- }
- if ( ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel == '0') ||
- ($voorkeursdatum_1_janee_dinerspel == '0' && $voorkeursdatum_2_janee_dinerspel == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee_dinerspel == '1' && $voorkeursdatum_2_janee_dinerspel == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- }
- if ($location_code == 'eigen-locatie') {
- include_once(dirname(__FILE__) . "/templates/tpl_page_reservering_EL.php");
- } else {
- include_once(dirname(__FILE__) . "/templates/tpl_page_reservering.php");
- }
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_response.php';
- exit;
- }
- //=====================================================================================
- public function contactform(){
- global $wpdb;
- $errors = array();
- if ( isset($_POST['tijd2']) && !empty($_POST['tijd2'])) {
- // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
- wp_redirect( home_url());
- die();
- //-------------------------------------------------------------------------------
- }
- if ($_POST) {
- if (!isset($_SESSION)) session_start();
- if (isset($_SESSION['capanswer']) && isset($_POST['capanswer']) && $_SESSION['capanswer'] == $_POST['capanswer'] ) {
- // value entered is correct
- } else {
- array_push( $errors, 'Het antwoord op de controlevraag is onjuist. Graag de twee getallen optellen en de som invullen.' );
- }
- $emailadres = ( isset ( $_POST['emailadres'] ) ? $_POST['emailadres'] : '' );
- $emailadres2 = ( isset ( $_POST['bevestig_emailadres'] ) ? $_POST['bevestig_emailadres'] : '' );
- if ( !empty($emailadres) && !is_email( $emailadres ) )
- array_push( $errors, __("Graag een geldig emailadres invullen", 'custom-pages-manager'));
- if ( $emailadres != $emailadres2 )
- array_push( $errors, __("Emailadressen zijn niet gelijk", 'custom-pages-manager'));
- $arrRequiredFields = array('naam', 'emailadres','bevestig_emailadres', 'bericht',);
- $arrRequiredFieldsNL = array(
- 'naam' => 'uw naam',
- 'emailadres' => 'uw E-mailadres',
- 'bevestig_emailadres' => 'E-mailadres ter bevestiging',
- 'bericht' => 'uw bericht',
- );
- // check if all required fields have been filled in
- foreach($_POST as $key => $value) {
- if (empty($value) ) {
- if (in_array($key, $arrRequiredFields) ) {
- $arrkey2show = explode('_', $key);
- unset($arrkey2show[0]); // remove first bit
- $name2show = implode('_', $arrkey2show);
- $name2show = ucfirst(str_replace('_', ' ', $name2show));
- array_push( $errors, __("Vul svp in: ", 'custom-pages-manager').$arrRequiredFieldsNL[$key]);
- }
- }
- }
- if (!empty($_POST)) {
- // create certain allowed variables from the $_POST as well
- $arr_allowed_fields = array('naam', 'telefoon', 'adres', 'plaats', 'emailadres', 'bevestig_emailadres', 'bericht');
- foreach ($_POST as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = $value;
- }
- }
- if ( !empty( $errors ) ) {
- // form fields errors, populate form and show again
- if (!isset($_SESSION)) session_start();
- $digit1 = mt_rand(1,10);
- $digit2 = mt_rand(1,10);
- $math = "$digit1 + $digit2";
- $_SESSION['capanswer'] = $digit1 + $digit2;
- include dirname(__FILE__) . '/templates/tpl_contactform.php';
- exit;
- }
- //----------------------------------
- // stuur email naar Dinerspel
- //---------------------------
- $message = "
- Bericht van: ".$naam."<br />
- <br />
- Telefoon: ".$telefoon."<br />
- <br />
- Emailadres: ".$emailadres."<br />
- <br />
- Bericht: ".$bericht."<br />
- <br />
- ";
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), ' Contactformulier '.$website, $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- $message = "Uw bericht is verstuurd. Wij zullen z.s.m. contact opnemen.<br />
- <br />
- Met vriendelijke groeten,<br />
- Moordspel.be";
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit;
- }
- }
- if (!isset($_SESSION)) session_start();
- $digit1 = mt_rand(1,10);
- $digit2 = mt_rand(1,10);
- $math = "$digit1 + $digit2";
- $_SESSION['capanswer'] = $digit1 + $digit2;
- include dirname(__FILE__) . '/templates/tpl_contactform.php';
- exit;
- }
- //================================================
- public function sitemap_page() {
- //================================================
- $sitemap = array();
- $static_urls = array(
- 'spellen',
- 'plaatsen',
- 'contact',
- 'webshop'
- );
- foreach($static_urls as $url) {
- $sitemap[] = $url;
- }
- $dynamic_urls = generate_sitemap_urls();
- foreach($dynamic_urls as $url) {
- $sitemap[] = $url;
- }
- //----------------------------------
- // show sitemap template
- //----------------------------------
- include dirname(__FILE__) . '/templates/tpl_sitemap.php';
- exit;
- }
- //=====================================================================================
- public function recensies() {
- global $wpdb;
- // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- // $currlocaldate = $currlocaldate->format('Y-m-d H:i:s');
- date_default_timezone_set('Europe/Amsterdam');
- $currlocaldate = date('Y-m-d H:i:s');
- // INITIALISE THE RECENSIES PAGE
- // 1. GET THE LOCATIONS AND THEIR TOWNS
- $params = array(
- 'select' => ' t.location_code,
- t.location_name,
- town.id as town_id,
- town.town_code as town_code,
- town.town_name as town_name
- ',
- //'where' => ' location_name <> "eigen-locatie" ',
- 'orderby' => 'town_name, location_name ',
- 'limit' => 0
- );
- $towns_locations_options = '<option value="">Welke plaats en locatie? *</option>
- ';
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- while ($locations_pod->fetch() ) {
- $row = $locations_pod->row();
- if ( !empty($locations_pod->row()['town_name']) ) {
- $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>
- ';
- } elseif ( !empty($locations_pod->row()['location_name']) && $locations_pod->row()['location_name'] == "Eigen locatie") {
- $town = '';
- $towns_locations_options .= '<option value="eigen_locatie">Eigen locatie</options>
- ';
- }
- }
- }
- // 2. GET THE GAMES
- $games_options = '<option value="">Welk spel heeft u gespeeld? *</option>
- ';
- $params = array(
- 'select' => 'game_code, game_name',
- 'orderby' => 'game_name ',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- while ($games_pod->fetch() ) {
- if ( !empty($games_pod->row()['game_name']) ) {
- $games_options .= '<option value="'.$games_pod->row()['game_code'].'">'.$games_pod->row()['game_name'].'</options>
- ';
- }
- }
- }
- if ( isset($_POST) && count($_POST) > 0) {
- // Process a new "recensie"
- if ( empty($_POST['tijd2'])) {
- //ok
- } else {
- // invisible field was filled in --> CAUGHT IN THE HONEY POT - MUST BE A SPAMBOT
- wp_redirect( home_url());
- die();
- //-------------------------------------------------------------------------------
- }
- $errors = array();
- $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');
- $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');
- // check if all required fields have been filled in
- foreach($_POST as $key => $value) {
- if (empty($value) ) {
- if (in_array($key, $arrRequiredFields) ) {
- $fieldname = $arrRequiredFieldNames[$key];
- array_push( $errors, 'Vul a.u.b. uw '.$fieldname.' in');
- }
- }
- }
- if ( empty( $errors ) && !is_numeric($_POST['ds_rec_aantal_pers']) )
- array_push( $errors, 'Vult u a.u.b. uitsluitend een aantal in<br />bij Aantal deelnemers');
- // create certain allowed variables from the $_POST
- $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');
- foreach ($_POST as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = trim($value);
- }
- }
- if ( !empty( $errors ) ) {
- // form fields errors, populate form and show again
- // for the datepicker in the form
- // $currlocaldate = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- // $curryear = $currlocaldate->format('Y');
- date_default_timezone_set('Europe/Amsterdam');
- $currlocaldate = date('Y-m-d H:i:s');
- $curryear = date('Y');
- include dirname(__FILE__) . '/templates/tpl_recensies.php';
- exit();
- //-------------------------------------------------------------------------------
- }
- // OK, no errors, store this 'recensie' and send out emails
- if (!empty($_POST['ds_rec_reserveringsdatum'])) {
- $date1 = new DateTime(str_replace('/', '-', $_POST['ds_rec_reserveringsdatum']));
- $ds_rec_reserveringsdatum = $date1->format('Y-m-d');
- } else {
- $ds_rec_reserveringsdatum = '';
- }
- $ds_rec_reserveringsdatum = format_nlDate($ds_rec_reserveringsdatum);
- $ds_rec_name = ucwords($ds_rec_name);
- $ds_rec_unieke_spel_code = stripslashes($ds_rec_unieke_spel_code);
- $ds_rec_content = stripslashes($ds_rec_content);
- // SAVE POST
- $recensie_post = array(
- 'post_title' => 'Recentie van '. $ds_rec_voornaam. ' '. $ds_rec_name,
- 'post_date' => $currlocaldate,
- 'post_content' => ' ',
- 'post_status' => 'pending',
- 'post_type' => 'recensies',
- );
- $post_id = wp_insert_post( $recensie_post );
- // SAVE POST META STUFF
- // split the ds_rec_town_code_location_code field into the separate codes
- $post_array = $_POST;
- $arr_town_location = explode('_', $_POST['ds_rec_town_code_location_code']);
- $post_array['ds_rec_town_code'] = $arr_town_location[0];
- $post_array['ds_rec_location_code'] = $arr_town_location[1];
- $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');
- foreach ($post_array as $key => $value) {
- $arrSkip = array('submit');
- if (in_array($key, $arr_allowed_fields) && !in_array($key, $arrSkip)) {
- $$key = $value = trim($value);
- $this->custom_update_post_meta( $post_id, $key, $value );
- }
- }
- if (isset($_FILES['image'])) {
- $this->custom_image_upload ( $_FILES['image'], $post_id, true );
- }
- //----------------------------------
- // stuur email naar DINERSPEL
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_email_recensie_ontvangen.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), 'Recensie ontvangen', $message);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- //----------------------------------
- // show thank you page
- //----------------------------------
- ob_start();
- include_once(dirname(__FILE__) . "/templates/tpl_page_recensie_thankyou.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- include dirname(__FILE__) . '/templates/tpl_info.php';
- exit();
- } else {
- // No $_POST vars, so just show the page with empty form
- include dirname(__FILE__) . '/templates/tpl_recensies.php';
- exit();
- }
- }
- //=====================================================================================
- /**
- * Updates post meta for a post. It also automatically deletes or adds the value to field_name if specified
- *
- * @access protected
- * @param integer The post ID for the post we're updating
- * @param string The field we're updating/adding/deleting
- * @param string [Optional] The value to update/add for field_name. If left blank, data will be deleted.
- * @return void
- */
- public function custom_update_post_meta( $post_id, $field_name, $value = '' )
- {
- if ( empty( $value ) OR ! $value )
- {
- delete_post_meta( $post_id, $field_name );
- }
- elseif ( ! get_post_meta( $post_id, $field_name ) )
- {
- add_post_meta( $post_id, $field_name, $value );
- }
- else
- {
- update_post_meta( $post_id, $field_name, $value );
- }
- }
- //=====================================================================================
- /**
- *
- */
- public function custom_image_upload( $file, $post_id=0, $set_as_featured=false ) {
- if (empty($file['name']) || empty($file['tmp_name']) ) return;
- $upload = wp_upload_bits( $file['name'], null, file_get_contents( $file['tmp_name'] ) );
- $wp_filetype = wp_check_filetype( basename( $upload['file'] ), null );
- $wp_upload_dir = wp_upload_dir();
- $attachment = array(
- 'guid' => $wp_upload_dir['baseurl'] . _wp_relative_upload_path( $upload['file'] ),
- 'post_mime_type' => $wp_filetype['type'],
- 'post_title' => preg_replace('/\.[^.]+$/', '', basename( $upload['file'] )),
- 'post_content' => '',
- 'post_status' => 'inherit'
- );
- $attach_id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
- require_once(ABSPATH . 'wp-admin/includes/image.php');
- $attach_data = wp_generate_attachment_metadata( $attach_id, $upload['file'] );
- wp_update_attachment_metadata( $attach_id, $attach_data );
- if( $set_as_featured == true ) {
- update_post_meta( $post_id, '_thumbnail_id', $attach_id );
- }
- }
- }
- // END CLASS
- //================================================================
- //================================================================
- $pages_manager = new Custom_Pages_Manager();
- //================================================================
- //=====================================================================================
- add_shortcode( "list_all_games", "shortcode_list_all_games" );
- //=====================================================================================
- if(!function_exists('shortcode_list_all_games')) {
- function shortcode_list_all_games($atts){
- global $wpdb;
- $params = array(
- 'select' => ' t.* ',
- 'orderby' => 'game_order',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- $games = array();
- $games_images_values_arr = array();
- $i=0;
- while ($games_pod->fetch() ) {
- $games_images_values = '';
- $row = $games_pod->row();
- // get pods values for all fields, in pods row as well as through "display only" (from related tables)
- foreach($games_pod->fields as $podsfield) {
- $fieldname = $podsfield['name'];
- $games[$i][$fieldname] = (isset($row[$fieldname])) ? $row[$fieldname] : $games_pod->display($fieldname) ;
- }
- // add game images to the tag_town_games_images_values_arr array, so the slider will have something to show besides town images
- $tmp_game_images_str = $games_pod->display( 'game_images' );
- $games_images_values .= ' '.$games_pod->display( 'game_images' );
- $i++;
- }
- }
- // get info text for all games page
- $row = $wpdb->get_col("SELECT all_games FROM wp_pods_general_content " );
- $all_games_text_value = $row[0];
- // GET ALL TOWNS
- $all_games_towns_values = [];
- $data["geolocations"] = '[';
- $comma='';
- $rows = $wpdb->get_results( "SELECT town_code, town_name, town_coordinates FROM wp_pods_towns ORDER BY town_name" );
- foreach ( $rows as $row ):
- $town_name = $row->town_name;
- $town_code = $row->town_code;
- // check if the town has 1 or more locations linked to active games
- $count_games = 0;
- $params = array(
- 'select' => 't.id',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
- 'where' => " town.town_code = '".$row->town_code."'",
- 'limit' => 0
- );
- $rel_location_games = pods( 'locations', $params );
- $count_games = $rel_location_games->total();
- if ($count_games > 0 && !empty($town_name) && isset($row->town_coordinates) && !empty($row->town_coordinates) ) {
- $json_geolocation = $row->town_coordinates;
- $obj_googlemapcoords = json_decode($json_geolocation);
- if (!empty($obj_googlemapcoords->lat) && !empty($obj_googlemapcoords->lng) ) {
- $info = $town_name;
- $url = home_url().'/'.$town_code;
- $data["geolocations"] .= $comma . "
- [".$obj_googlemapcoords->lat.", ".$obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- $all_games_towns_values[] = $row;
- }
- endforeach;
- $data["geolocations"] .= '
- ]';
- // add 'Eigen locatie' as the first element
- $eigen_locatie = (object)array(
- 'town_code' => 'eigen-locatie',
- 'town_name' => 'Eigen locatie',
- 'town_coordinates' => ''
- );
- array_unshift($all_games_towns_values, $eigen_locatie);
- ob_start();
- include dirname(__FILE__) . '/templates/tpl_games.php';
- $temp_content = ob_get_contents();
- ob_end_clean();
- return $temp_content;
- exit();
- }
- }
- //=====================================================================================
- // SHORTCODE homepage_title_text_map_area
- //=====================================================================================
- add_shortcode( "homepage_title_text_map_area", "shortcode_homepage_title_text_map_area" );
- if(!function_exists('shortcode_homepage_title_text_map_area')) {
- function shortcode_homepage_title_text_map_area($atts){
- if ( is_front_page() && is_page() ) {
- $home_values = format_element('home_values', array());
- include dirname(__FILE__) . "/templates/tpl_homepage_title_text_map_area.php";
- }
- }
- }
- //-------------------------------------------------------------------------
- function getTownName($town_id) {
- //-------------------------------------------------------------------------
- // get the text value for the townId
- $params = array( 'where' => 'id = "'.$town_id.'"', 'limit' => 0 );
- $townpod = pods( 'towns' )->find( $params);
- if ( $townpod->total() > 0 ) {
- while ($townpod->fetch() ) {
- $row = $townpod->row();
- if ( !empty( $row ) ) {
- return $townpod->field('town_name');
- } else {
- return 'Geen plaatsnaam gevonden';
- }
- }
- } else {
- return 'Geen plaatsnaam gevonden';
- }
- }
- //-------------------------------------------------------------------------
- function format_element($key, $field='', $extra_attr=array()) {
- //-------------------------------------------------------------------------
- global $array_games, $array_towns, $array_locations;
- global $array_game_names, $array_town_names, $array_location_names, $array_random_location_names;
- global $tag_values, $game_values, $town_values, $location_values, $rel_location_game_values, $town_locations_games_values;
- global $wpdb;
- ob_start();
- switch ($key) {
- // SHOW GAMES DROPDOWN
- case 'game_select':
- foreach($array_games as $key=>$value):
- if (!empty($value)): ?>
- <option value="<?php print $value; ?>"><?php print $array_game_names[$key]; ?></option>
- <?php
- endif;
- endforeach;
- break;
- // SHOW TOWNS DROPDOWN
- case 'town_select':
- foreach($array_towns as $key=>$value):
- if (!empty($value)): ?>
- <option value="<?php print $value; ?>"><?php print $array_town_names[$key]; ?></option>
- <?php
- endif;
- endforeach;
- break;
- // SHOW LOCATIONS DROPDOWN
- case 'location_select':
- foreach($array_locations as $key=>$value):
- if (!empty($value)): ?>
- <option value="<?php print $value; ?>"><?php print $array_location_names[$key]; ?></option>
- <?php
- endif;
- endforeach;
- break;
- // SHOW IMAGES
- case 'tag_images':
- $array_images = $field;
- foreach($array_images as $img_url):
- if (!empty($img_url)) { ?>
- <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
- title="<?php print $tag_values['game_name']; ?>"
- alt="<?php print $tag_values['game_name']; ?>"
- />
- <?php
- }
- endforeach;
- break;
- case 'game_images':
- $array_images = explode(' ', $field);
- if (isset($extra_attr['list']) && count($array_images) > 0 ) {
- $img_url = $array_images[0];
- ?>
- <img src="<?php print str_replace('http://', 'https://', $img_url); ?>"
- style="
- max-width:150px;
- margin:0 20px 10px 0;
- background-color: #fff;
- padding:5px;
- border:1px solid #ccc;
- "
- align="left"
- title="<?php print $game_values['game_name']; ?>"
- alt="<?php print $game_values['game_name']; ?>"
- />
- <?php
- } else {
- foreach($array_images as $img_url):
- if (!empty($img_url)) { ?>
- <img src="<?php print str_replace('http://', 'https://', $img_url); ?>"
- style="
- max-width:150px;
- margin:0 20px 10px 0;
- background-color: #fff;
- padding:5px;
- border:1px solid #ccc;
- "
- title="<?php print $game_values['game_name']; ?>"
- alt="<?php print $game_values['game_name']; ?>"
- />
- <?php if (isset($extra_attr['one'])) break;
- }
- endforeach;
- }
- break;
- case 'town_images':
- $array_images = explode(' ', $field);
- foreach($array_images as $img_url):
- if (!empty($img_url)) { ?>
- <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
- title="<?php print $town_values['town_name']; ?>"
- alt="<?php print $town_values['town_name']; ?>"
- />
- <?php
- if (isset($extra_attr['one'])) break;
- }
- endforeach;
- break;
- case 'images_slider':
- $array_images = explode(' ', trim($field));
- shuffle($array_images);
- $i=1;
- foreach($array_images as $img_url):
- if (!empty($img_url)) {
- // use a smaller size if available
- $curr_image_300 = str_replace('.jpg','-300x225.jpg', $img_url);
- $curr_image_300_testurl = str_replace(home_url(), '', $curr_image_300);
- $curr_image_300_testurl = $_SERVER["DOCUMENT_ROOT"] .$curr_image_300_testurl;
- if (is_file($curr_image_300_testurl)) $img_url = $curr_image_300;
- $img_url = str_replace('http://', 'https://', $img_url);
- $slides[] = '
- <li>
- <div class="slide-media nonhomeslide-media" style="padding:0px">
- <div style="">
- <img src="'.$img_url.'" style="padding:5px; border:1px solid #ddd; width:98%;"
- />
- </div>
- </div>
- </li>';
- $i++;
- if ($i > 20) break; // no more than 20 slides
- }
- endforeach;
- if (is_array($slides)) {
- return '
- <div class="flexslider nonhomeflexslider" id="flexid">
- <ul class="slides">
- '.implode('', $slides).'
- </ul>
- </div>';
- } else {
- return false;
- }
- break;
- case 'location_images':
- $array_images = explode(' ', $field);
- foreach($array_images as $img_url):
- if (!empty($img_url)) { ?>
- <img src="<?php print str_replace('http://', 'https://', $img_url); ?>" style="max-height:200px;"
- title="<?php print $location_games_values['location_name']; ?>"
- alt="<?php print $location_games_values['location_name']; ?>"
- />
- <?php
- if (isset($extra_attr['one'])) break;
- }
- endforeach;
- break;
- // SHOW VIDEO FILES
- case 'game_videos':
- case 'location_video_files':
- case 'town_videos':
- $array_videos = explode(' ', $field);
- foreach($array_videos as $video_url):
- if (!empty($video_url)) { ?>
- <iframe src="<?php print $video_url; ?>" frameborder="0" allowfullscreen ></iframe>
- <?php
- }
- endforeach;
- break;
- // SHOW VIDEO URLS
- case 'location_video_urls':
- $array_videos = explode(' ', $field);
- foreach($array_videos as $video_url):
- if (!empty($video_url)) {
- // should be a youtube video, get the code
- $tmparray = explode('/', $video_url);
- $video_code = $tmparray[count($tmparray)-1];
- $tmparray = explode('=', $video_code);
- $video_code = $tmparray[count($tmparray)-1];
- ?>
- <iframe width="420" height="315" src="http://www.youtube.com/embed/<?php print $video_code; ?>?autoplay=1"></iframe>
- <?php
- }
- endforeach;
- break;
- case 'rel_location_game_values': ?>
- <table>
- <tr>
- <th>Aantal personen</th>
- <?php
- 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') ) {
- print '<th>Spel + spelbegeleiding:</th>';
- } 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') ) {
- print '<th>Spel</th>';
- } 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') {
- print '<th>Diner + spel</th>';
- } else {
- print '<th>Dinerspel + menu + spelbegeleiding</th>';
- }
- ?>
- </tr> <?php
- 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')) {
- foreach($rel_location_game_values as $location_game): ?>
- <tr>
- <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
- <td>€<?php print ( !empty($location_game->game_price)) ? number_format((float)$location_game->game_price, 2, ',', '.') : '0,00'; ?> incl. BTW per persoon
- </td>
- </tr><?php
- endforeach;
- } 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') ) {
- foreach($rel_location_game_values as $location_game): ?>
- <tr>
- <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
- <td>€<?php print ( !empty($location_game->game_price)) ? number_format((float)$location_game->game_price, 2, ',', '.') : '0,00'; ?> incl. BTW per persoon
- </td>
- </tr><?php
- endforeach;
- } else {
- foreach($rel_location_game_values as $location_game):
- if ($game_values['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $location_values['diner_price_foodfun'];
- } else {
- $diner_price = $location_values['diner_price'];
- }
- ?>
- <tr>
- <td>Van <?php print $location_game->min_number; ?> t/m <?php print $location_game->max_number; ?> personen</td>
- <td> Diner €<?php print ( !empty($diner_price) ) ? number_format((float)$diner_price, 2, ',', '.') : '0,00'; ?>
- + Spel €<?php print ( !empty($location_game->game_price)) ? number_format((float)$location_game->game_price, 2, ',', '.') : '0,00'; ?>
- = <strong>€<?php
- if ( !empty($diner_price) && !empty($location_game->game_price) ) {
- $total_price = (float)$diner_price + (float)$location_game->game_price;
- print number_format($total_price, 2, ',', '.');
- }
- ?></strong> incl. BTW p.p.
- </td>
- </tr><?php
- endforeach;
- } ?>
- </table> <?php
- break;
- case 'location_games_totalprice':
- // first get the lowest game price
- if (isset($rel_location_game_values)):
- $lowest_price = 9999.99;
- foreach($rel_location_game_values as $location_game):
- if ($location_game->game_price < $lowest_price) $lowest_price = $location_game->game_price;
- endforeach;
- if ($lowest_price == 9999.99) $lowest_price = 0.00;
- if ($game_values['game_code'] == 'food-en-fun-culi-spel') {
- $diner_price = $location_values['diner_price_foodfun'];
- } else {
- $diner_price = $location_values['diner_price'];
- }
- $total_price = (float)$diner_price + (float)$lowest_price;
- print number_format($total_price, 2, ',', '.');
- endif;
- break;
- // SHOW LINKS TO DOCUMENTS
- case 'conditions_document':
- case 'booking_conditions_file':
- $array_documents = explode(' ', $field);
- foreach($array_documents as $document_url):
- if (!empty($document_url)) {
- // get the name without the path
- $arr_docpath = explode('/', $document_url);
- $docname = str_replace('.pdf', '', end($arr_docpath) );
- ?>
- <div><a href="<?php echo $document_url; ?>" target="_blank">
- <img src="<?php print home_url(); ?>/wp-content/uploads/2016/04/pdf_icon.jpg" align="middle" /> <?php echo $docname; ?>
- </a></div>
- <?php
- }
- endforeach;
- break;
- case 'game_documents':
- $array_documents = explode(' ', $field);
- foreach($array_documents as $document_url):
- if (!empty($document_url)) {
- // get the name without the path
- $arr_docpath = explode('/', $document_url);
- $docname = str_replace('.pdf', '', end($arr_docpath) );
- ?>
- <div>
- <a href="<?php echo $document_url; ?>" target="_blank"><?php echo $docname; ?></a>
- </div>
- <?php
- }
- endforeach;
- break;
- case 'location_coordinates' :
- case 'town_coordinates' :
- $json_geolocation = $field;
- $obj_googlemapcoords = json_decode($json_geolocation);
- ?>
- <div class="google-map-container">
- <div class="google-map" id="google-map"></div>
- <input type="hidden" class="map-latitude" value="<?php print $obj_googlemapcoords->lat; ?>" />
- <input type="hidden" class="map-longitude" value="<?php print $obj_googlemapcoords->lng; ?>" />
- <input type="hidden" class="map-zoom" value="14" />
- <input type="hidden" class="map-description" value="<?php print $location_values["location_name"].', '.$location_values['address_1']; ?>" />
- </div>
- <?php
- break;
- case 'tag_text_town' :
- if ($town_locations_games_values) $field = insertrandomlocation($field, $town_locations_games_values);
- if ($town_locations_games_values) $field = insertrandomlocationgame($field, $town_locations_games_values);
- $field = str_replace('[plaats]', $town_values['town_name'], $field);
- $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
- print wpautop($field);
- break;
- case 'game_short_descr_tag' :
- //if ($tag_values['single_plural'] == 'Meervoudsvorm') {
- $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
- //} else {
- // $field = str_replace('[trefwoord]', 'een '.$tag_values['tag_name'], $field);
- //}
- print wpautop($field);
- break;
- case 'game_text_town_tag_location' :
- if ($town_locations_games_values) $field = insertrandomlocation($field, $town_locations_games_values);
- $field = str_replace('[plaats]', $town_values['town_name'], $field);
- $field = str_replace('[trefwoord]', $tag_values['tag_name'], $field);
- print wpautop($field);
- break;
- case 'game_text_town' :
- $field = str_replace('[plaats]', $town_values['town_name'], $field);
- print wpautop($field);
- break;
- case 'game_text_town_location' :
- $field = str_replace('[plaats]', $town_values['town_name'], $field);
- $field = str_replace('[locatie]', $location_values['location_name'], $field);
- print wpautop($field);
- break;
- case 'game_text_town_own_location' :
- $field = str_replace('[plaats]', $town_values['town_name'], $field);
- print wpautop($field);
- break;
- case 'back_print_buttons' :
- return '<p> </p>';
- break;
- case 'home_values' :
- // if home page, provide data for the google map and towns to show
- $home_values = array();
- if (is_page() && is_front_page()) {
- //--------------------------------------------------------------------------------------
- // namen van de plaatsen (met link) - center panel
- $params = array(
- 'select' => ' town_code, town_name, town_coordinates, town_images.guid as town_images ',
- 'limit' => 0
- );
- $home_towns_pod = pods( 'towns', $params );
- if ( $home_towns_pod->total() > 0 ) {
- // GET ALL MAP LOCATIONS FOR THE GOOGLE MAP
- $home_values["town_coordinates"] = '[';
- $home_prev_town_code = '';
- while ($home_towns_pod->fetch() ) {
- $home_row = $home_towns_pod->row();
- // ASSEMBLE A STRING WITH IMAGES FOR THE SLIDER
- // EACH ROW HAS 1 IMAGE, THERE CAN BE MULTIPLE ROWS FOR EACH TOWN, GET THE FIRST ONE OF EACH
- if ($home_row['town_code'] != $home_prev_town_code) {
- // FIRST ROW FOR THIS TOWN
- $home_prev_town_code = $home_row['town_code'];
- $home_values["towns"][] = $home_row;
- // collect the names of restaurants in this town, to be shown on hover over map flags
- $params = array(
- 'select' => 't.id as location_id,
- t.location_name,
- t.location_code
- ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id AND wp_rel_locations_games.activated = 1)',
- 'where' => " town.town_code = '".$home_row['town_code']."'" ,
- 'orderby' => 'location_name',
- 'limit' => 0
- );
- $home_locations_pod = pods( 'locations', $params );
- $home_locations_pod_total = $home_locations_pod->total();
- if ( $home_locations_pod_total > 0 ):
- $home_text_locations_per_town = '';
- while ($home_locations_pod->fetch() ):
- $home_row2 = $home_locations_pod->row();
- $home_text_locations_per_town .= '\r\n - '.$home_row2['location_name'];
- endwhile;
- if (isset($home_row['town_coordinates']) && !empty($home_row['town_coordinates']) ) {
- $home_json_geolocation = $home_row['town_coordinates'];
- $home_obj_googlemapcoords = json_decode($home_json_geolocation);
- if (!empty($home_obj_googlemapcoords->lat) && !empty($home_obj_googlemapcoords->lng) ) {
- $town_name = $home_row['town_name'];
- $town_code = $home_row['town_code'];
- $town_country = $home_row['country'];
- $info = htmlspecialchars($town_name, ENT_QUOTES,'UTF-8');
- $info .= (!empty($town_country)) ? ', '.htmlspecialchars($town_country, ENT_QUOTES,'UTF-8') : '';
- $info .= $home_text_locations_per_town;
- $url = $town_code;
- $home_values["town_coordinates"] .= $comma . "
- [".$home_obj_googlemapcoords->lat.", ".$home_obj_googlemapcoords->lng.", '".htmlspecialchars($info, ENT_QUOTES,'UTF-8')."', '".$url."']";
- $comma=", ";
- }
- }
- endif;
- } else {
- // MUST BE MULTIPLE ROWS FOR SAME TOWN, DIFFER ONLY RE. FIELD 'TOWN_IMAGES'
- }
- }
- $home_values["town_coordinates"] .= '
- ]';
- }
- //--------------------------------------------------------------------------------------
- // text for the right panel
- $row = $wpdb->get_col("SELECT all_towns FROM wp_pods_general_content " );
- $home_values['home_towns_text_value'] = $row[0];
- return $home_values;
- }
- break;
- default:
- // just show the text, with wp line breaks
- print wpautop($field);
- break;
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- return $temp_content;
- }
- //-------------------------------------------------------------------------
- function insertrandomlocation($field, $town_locations_games_values) {
- //-------------------------------------------------------------------------
- // collect the location names for this town in array_location_names
- $array_random_location_names = array();
- foreach ($town_locations_games_values as $key => $locations_games_values) {
- //$array_location_names[$locations_games_values['location_name']] = $locations_games_values['location_name'];
- array_push($array_random_location_names, $locations_games_values['location_name']);
- }
- // randomize
- shuffle($array_random_location_names);
- // split the text up in parts separated by '[location]'
- // then join them together again, inserting a random location_name from array_location_names
- $location_indexes = explode('[locatie]', $field);
- $field = "";
- foreach ($location_indexes as $k=>$v) {
- $field .= $v;
- if ($k != count($location_indexes) - 1) {
- if ($array_random_location_names[$k] == 'Eigen locatie') $array_random_location_names[$k] = 'uw eigen locatie';
- $field .= $array_random_location_names[$k];
- }
- }
- // split the text up in parts separated by '[opsomming]'
- // then join them together again, inserting all random location_names from array_location_names
- // first create the string of location names:
- $opsomming='';
- $comma='';
- foreach ($array_random_location_names as $key => $value) {
- if ($value == 'Eigen locatie') $value = 'uw eigen locatie';
- $opsomming .= $comma.'<strong>'.$value.'</strong>';
- $comma= ', ';
- }
- //print "<br />opsomming: ".$opsomming;
- $location_indexes = explode('[opsomming]', $field);
- $field = "";
- foreach ($location_indexes as $k=>$v) {
- $field .= $v;
- if ($k != count($location_indexes) - 1) {
- $field .= $opsomming;
- }
- }
- return $field;
- }
- //-------------------------------------------------------------------------
- function insertrandomlocationgame($field, $town_locations_games_values) {
- //-------------------------------------------------------------------------
- // collect the location name / game name combinations for this town in array_location_names
- $array_random_location_games_names = array();
- foreach ($town_locations_games_values as $key => $locations_games) {
- if ($locations_games['location_name'] && $locations_games['location_name'] != 'Eigen locatie') {
- $array_random_location_games_names[$locations_games['location_name']][] = $locations_games['location_name'];
- if (isset($locations_games['location_games'])) {
- foreach ($locations_games['location_games'] as $key => $value) {
- if ($value['game_name'] != 'Hollandse Helden') {
- $array_random_location_games_names[$locations_games['location_name']][] = $value['game_name'];
- }
- }
- }
- }
- }
- // array now looks like this:
- /*
- array_random_location_games_names:
- Array
- (
- [0] => Array
- (
- [0] => Restaurant Gusto Garbon
- [1] => Moordvlucht Moordspel
- [2] => Miss Murder Moordspel
- [3] => Flight Murder Mystery Game
- )
- */
- // create a new array for all possible combinations of restaurants and games
- $array_random_location_games_strings = array();
- foreach ($array_random_location_games_names as $key1 => $location_games) {
- // build a string for each game + same location name
- foreach ($location_games as $key2 => $value) {
- if ($key2 > 0) {
- $string_location_games = $location_games[$key2];
- if ($location_games[0] != 'Eigen locatie' && $location_games[0] != 'Hollandse Helden') {
- $string_location_games .= ' in '.$location_games[0];
- $array_random_location_games_strings[] = $string_location_games;
- }
- }
- }
- }
- // randomize
- shuffle($array_random_location_games_strings);
- // split the text up in parts separated by '[game-location]'
- // then join them together again, inserting a random location_name from array_random_location_games_names
- $location_indexes = explode('[spel-locatie]', $field);
- $field = "";
- foreach ($location_indexes as $k=>$v) {
- if ($v != 'Eigen locatie' && $v != 'Hollandse Helden') {
- $field .= $v;
- if ($k != count($location_indexes) - 1) {
- $field .= $array_random_location_games_strings[$k];
- }
- }
- }
- // split the text up in parts separated by '[opsomming]'
- // then join them together again, inserting all random location_games_names from array_location_names
- // first create the string of location names:
- $opsomming='';
- $comma='';
- foreach ($array_random_location_games_names as $key => $value) {
- $opsomming .= $comma.'<strong>'.$value.'</strong>';
- $comma= ', ';
- }
- //print "<br />opsomming: ".$opsomming;
- $location_indexes = explode('[opsomming]', $field);
- $field = "";
- foreach ($location_indexes as $k=>$v) {
- $field .= $v;
- if ($k != count($location_indexes) - 1) {
- $field .= $opsomming;
- }
- }
- return $field;
- }
- //================================================================
- function generate_sitemap_urls() {
- global $wpdb;
- $array_towns = $wpdb->get_col( "SELECT town_code FROM wp_pods_towns " );
- $arr_urls = array();
- // get all game codes
- $params = array(
- 'select' => ' t.* ',
- 'limit' => 0
- );
- $games_pod = pods( 'games', $params );
- if ( $games_pod->total() > 0 ) {
- while ($games_pod->fetch() ) {
- $game_code = $games_pod->display( 'game_code' );
- $str_tags = $games_pod->display( 'game_tags' );
- $arr_tags = $games_pod->field( 'game_tags' );
- if ($arr_tags) foreach($arr_tags as $tag) {
- if (!empty($tag['tag_name']) && !in_array($tag['tag_name'], $arr_urls)) {
- // this tag has not yet been added as a url
- $arr_urls[] = $tag['tag_name'];
- }
- }
- // get all locations where this game is played, which also provides the towns for the url
- $params = array(
- 'select' => ' t.location_code, town.town_code ',
- 'join' => ' INNER JOIN wp_rel_locations_games ON (t.id = wp_rel_locations_games.location_id)
- INNER JOIN wp_pods_games ON (wp_pods_games.id = wp_rel_locations_games.game_id AND wp_rel_locations_games.activated = 1) ',
- 'where' => " game_code = '".$game_code."' ",
- 'limit' => 0
- );
- if (!empty($game_code)) {
- $arr_urls[] = $game_code;
- }
- $locations_pod = pods( 'locations', $params );
- if ( $locations_pod->total() > 0 ) {
- while ($locations_pod->fetch() ) {
- $town_code = $locations_pod->display( 'town_code' );
- $town_code_url = $town_code;
- if (!empty($town_code) && !in_array($town_code_url, $arr_urls)) {
- // this town_code_url has not yet been added as a url
- $arr_urls[] = $town_code_url;
- }
- if (!empty($town_code) && !in_array( $game_code."/".$town_code, $arr_urls)) {
- $arr_urls[] = $game_code."/".$town_code;
- }
- $location_code = $locations_pod->display( 'location_code' );
- if (!empty($town_code) && !empty($location_code) && $location_code <> 'eigen-locatie' && !in_array( $game_code."/".$town_code."/".$location_code, $arr_urls)) {
- $arr_urls[] = $game_code."/".$town_code."/".$location_code;
- }
- if (!empty($game_code) && $location_code == 'eigen-locatie' && !in_array( $game_code."/eigen-locatie", $arr_urls)) {
- $arr_urls[] = $game_code."/eigen-locatie";
- // if game can be played in eigen locatie, then add this url for all towns as well
- foreach($array_towns as $town_code) {
- if (!in_array( $game_code."/".$town_code."/eigen-locatie", $arr_urls)) {
- $arr_urls[] = $game_code."/".$town_code."/eigen-locatie";
- }
- }
- }
- if (!empty($town_code) && !empty($location_code) && $location_code <> 'eigen-locatie' && !in_array( $town_code."/".$location_code, $arr_urls)) {
- $arr_urls[] = $town_code."/".$location_code;
- }
- if ($arr_tags) foreach($arr_tags as $tag) {
- $tag_town_url = $tag['tag_name'].'/'.$town_code;
- if (!empty($tag['tag_name']) && !empty($town_code) && !in_array($tag_town_url, $arr_urls)) {
- // this tag_town_url has not yet been added as a url
- $arr_urls[] = $tag_town_url;
- }
- }
- }
- }
- }
- }
- sort($arr_urls );
- return $arr_urls;
- }
- //================================================================================
- // CRON ACTION FOR "ONCE hourly" EVENTS
- //================================================================================
- add_action('custom_hourly_event', 'do_this_hourly');
- function do_this_hourly() {
- //error_log('**************** do_this_hourly ');
- // SEND REMINDERS TO LOCATIONS THAT STILL HAVE NOT RESPONDED
- send_reminder_to_location();
- send_reminder_to_dinerspel();
- send_reminder_to_client();
- //--------------------------------------------------------------------------------------------
- // SEND_WEEKLY_REPORT_TO_LOCATION(), EVERY NIGHT WEDNESDAY on thursday
- //--------------------------------------------------------------------------------------------
- // Check that the hour is Thursday morning between 0 and 2
- $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- $day = $currlocaldatetime->format('N');
- $hour = $currlocaldatetime->format('H');
- if($day == 4 && $hour > 0 && $hour < 2)
- {
- send_weekly_report_to_location();
- } else {
- }
- }
- //================================================================================
- // CRON ACTION FOR "ONCE WEEKLY" EVENTS
- //================================================================================
- /////////////////////////////////////////// add_action('custom_weekly_event', 'do_this_weekly');
- // function do_this_weekly() {
- // // error_log('**************** custom_weekly_event ');
- // }
- // RUN THE SITEMAP SCRIPT AT LEAST ONCE A DAY:
- //================================================================================
- // CRON ACTION FOR "ONCE DAILY" EVENTS
- //================================================================================
- add_action('custom_daily_event', 'do_this_daily');
- function do_this_daily() {
- //error_log('**************** custom_daily_event ');
- global $wpdb;
- // BUILD THE SITEMAP AT LEAST ONCE A DAY:
- // ------------------------------------------------------------
- $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- $now = $currlocaldatetime->format('Y-m-d H:i:s');
- require_once(dirname(__FILE__) . "/Sitemap.php");
- $sitemap = new Sitemap;
- $ignore_urls = array(
- 'vragen',
- 'fout-pagina'
- );
- $static_urls = array(
- 'spellen',
- 'plaatsen',
- 'contact',
- 'webshop'
- );
- $rows = $wpdb->get_results( "
- SELECT post_name
- FROM wp_posts p
- INNER JOIN
- wp_postmeta pm ON (
- pm.post_id = p.id
- AND post_type = 'page'
- AND meta_key = '_wp_page_template'
- )
- ORDER BY post_name"
- );
- foreach ( $rows as $row ) {
- $pagename = $row->post_name;
- if (!empty($pagename) && !in_array( $pagename, $static_urls) && !in_array( $pagename, $ignore_urls) ) {
- $static_urls[] = $pagename;
- }
- }
- foreach($static_urls as $url) {
- $sitemap->url($url, $now, 'monthly');
- }
- $arr_urls = generate_sitemap_urls();
- foreach($arr_urls as $url) {
- $sitemap->url($url, $now, 'monthly');
- }
- $sitemap->close();
- unset ($sitemap);
- }
- //==================================================================
- // SEND REMINDERS TO LOCATIONS THAT STILL HAVE NOT RESPONDED 48 HOURS
- // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_HOURLY)
- function send_reminder_to_location() {
- //error_log('**************** send_reminder_to_location ');
- global $wpdb;
- // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
- $sql = "SELECT * FROM wp_pods_aanvragen
- WHERE code_locatie <> ''
- AND location_code <> 'eigen-locatie'
- AND created < DATE_SUB(NOW(), INTERVAL 48 HOUR)
- AND (date_48_hours_email_sent IS NULL
- OR date_48_hours_email_sent = '0000-00-00 00:00:00')
- ";
- //error_log('**************** sql ******************* ');
- //error_log(print_r($sql,true));
- $rows = $wpdb->get_results(
- "SELECT * FROM wp_pods_aanvragen
- WHERE code_locatie <> ''
- AND location_code <> 'eigen-locatie'
- AND created < DATE_SUB(NOW(), INTERVAL 48 HOUR)
- AND (date_48_hours_email_sent IS NULL
- OR date_48_hours_email_sent = '0000-00-00 00:00:00')
- ", ARRAY_A);
- if ( $rows ) {
- foreach ($rows as $row) {
- // send email
- // create certain allowed variables from $arr_aanvraag[0]
- foreach ($row as $key => $value) {
- $$key = $value;
- }
- $aanvraag_id = $id;
- $achternaam = ucwords($name);
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- // check if perhaps ZELFSTANDIGE LOCATIE
- $sql = $wpdb->prepare("SELECT zelfstandige_locatie, email_address FROM wp_pods_locations
- WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $location_email = $location_row['email_address'];
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur HERINNERING naar LOCATIE
- //----------------------------------
- if (!empty($location_email)) {
- $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- if ($zelfstandige_locatie) {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
- } else {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( $location_email, 'HERINNERING (48 UUR): Nieuwe beschikbaarheid via '.$website, $message);
- error_log('************** wp_mail( '.$location_email.', HERINNERING (48 UUR): Nieuwe beschikbaarheid via... ); MAILRESULT: '.$mailresult);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- // set date flag to indicate this email has been sent
- $sql = "
- UPDATE wp_pods_aanvragen
- SET modified = NOW(),
- date_48_hours_email_sent = NOW()
- WHERE id = ".$aanvraag_id;
- $updres = $wpdb->get_results( $sql );
- }
- }
- }
- }
- //==================================================================
- // SEND REMINDERS TO DINERSPEL IF LOCATIONS STILL HAVE NOT RESPONDED AFTER 72 HOURS
- // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY()
- function send_reminder_to_dinerspel() {
- //error_log('**************** send_reminder_to_DINERSPEL ');
- global $wpdb;
- // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
- // $rows = $wpdb->get_results(
- // "SELECT * FROM wp_pods_aanvragen
- // WHERE code_locatie <> ''
- // AND location_code <> 'eigen-locatie'
- // AND created < DATE_SUB(NOW(), INTERVAL 72 HOUR)
- // AND (date_72_hours_email_sent IS NULL
- // OR date_72_hours_email_sent = '0000-00-00 00:00:00')
- // ", ARRAY_A);
- $sql = "SELECT * FROM wp_pods_aanvragen
- WHERE code_locatie > ''
- AND location_code > ''
- AND location_code <> 'eigen-locatie'
- AND created < DATE_SUB(NOW(), INTERVAL 72 HOUR)
- AND (date_72_hours_email_sent IS NULL
- OR date_72_hours_email_sent = '0000-00-00 00:00:00')
- ";
- $rows = $wpdb->get_results($sql, ARRAY_A);
- if ( $rows ) {
- foreach ($rows as $row) {
- // send email
- // create certain allowed variables from $arr_aanvraag[0]
- foreach ($row as $key => $value) {
- $$key = $value;
- }
- $aanvraag_id = $id;
- $achternaam = ucwords($name);
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- // check if perhaps ZELFSTANDIGE LOCATIE
- $sql = $wpdb->prepare("SELECT zelfstandige_locatie, email_address FROM wp_pods_locations
- WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $location_email = $location_row['email_address'];
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- //----------------------------------
- // stuur HERINNERING naar DINERSPEL
- //----------------------------------
- $url_msg = home_url().'/reageer-op-beschikbaarheidsaanvraag/'.$code_locatie;
- $activate_link = '<a href="'.$url_msg.'">'.$url_msg .'</a>';
- ob_start();
- if ($zelfstandige_locatie) {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_ZL_naar_locatie.php");
- } else {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheidsaanvraag_naar_locatie.php");
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail( get_option('admin_email'), 'HERINNERING (72 UUR): Nieuwe beschikbaarheid via '.$website, $message);
- error_log('************** wp_mail('.get_option(admin_email).', HERINNERING (72 UUR): Nieuwe beschikbaarheid via... ); MAILRESULT: '.$mailresult);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- // set date flag to indicate this email has been sent
- $sql = "
- UPDATE wp_pods_aanvragen
- SET modified = NOW(),
- date_72_hours_email_sent = NOW()
- WHERE id = ".$aanvraag_id;
- $updres = $wpdb->get_results( $sql );
- }
- }
- }
- //==================================================================
- // SEND REMINDERS TO CLIENTS THAT STILL HAVE NOT MADE A RESERVATION AFTER 7 DAYS
- // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY()
- /*
- Email versturen als:
- # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
- # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
- # één of beide voorkeurdata moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
- # het niet een EL betreft:
- # het niet een ZL locatie is
- # het niet een doe-het-zelf spel betreft
- # er de laatste 7 dagen niets is gebeurd met de aanvraag
- # deze herinnering nog niet eerder is verzonden:
- */
- function send_reminder_to_client() {
- //error_log('**************** send_reminder_to_client ');
- global $wpdb;
- // NO NEED FOR "NL/BE SWITCH DATABASE" LOGIC, AS THIS FUNCTION IS TRIGGERED ON BOTH WEBSITES, EACH FOR THEIR OWN DATABASE
- $sql = "SELECT aanvr.id as aanvraag_id, locs.id as location_id, aanvr.*, locs.*
- FROM wp_pods_aanvragen aanvr
- INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
- WHERE
- # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
- code_locatie = ''
- # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
- AND code_klant <> ''
- # één of beide datums moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
- AND ((voorkeursdatum_1_janee_locatie = 1 AND voorkeursdatum_1_janee_dinerspel = 1)
- OR
- (voorkeursdatum_2_janee_locatie = 1 AND voorkeursdatum_2_janee_dinerspel = 1))
- # het niet een EL betreft:
- AND locs.location_code <> 'eigen-locatie'
- # het niet een ZL locatie is
- AND zelfstandige_locatie = 0
- # status is NIET
- AND action_status NOT IN ('Gereserveerd', 'Geen_interesse', 'Afgehandeld' )
- # het niet het doe-het-zelf spel betreft
- AND game_code <> 'onfortuinlijke-bankier'
- AND game_code <> 'mysterie-spel-back-to-school'
- AND game_code <> 'koudgemaakte-kok'
- AND game_code <> 'into-the-box'
- # laatste 7 dagen is er niets gebeurd met de aanvraag
- AND aanvr.modified < DATE_SUB(NOW(), INTERVAL 7 DAY)
- # deze herinnering is nog niet eerder verzonden:
- AND (date_7_days_email_sent IS NULL
- OR date_7_days_email_sent = '0000-00-00 00:00:00')
- ";
- $rows = $wpdb->get_results(
- "SELECT aanvr.id as aanvraag_id, locs.id as location_id, aanvr.*, locs.*
- FROM wp_pods_aanvragen aanvr
- INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
- WHERE
- # locatie heeft gereageerd, dus code_locatie moet leeg zijn:
- code_locatie = ''
- # klant heeft nog niet gereserveerd, dus code_klant is niet leeg:
- AND code_klant <> ''
- # één of beide datums moeten door zowel locatie als dinerspel als beschikbaar zijn opgegeven:
- AND ((voorkeursdatum_1_janee_locatie = 1 AND voorkeursdatum_1_janee_dinerspel = 1)
- OR
- (voorkeursdatum_2_janee_locatie = 1 AND voorkeursdatum_2_janee_dinerspel = 1))
- # het niet een EL betreft:
- AND locs.location_code <> 'eigen-locatie'
- # het niet een ZL locatie is
- AND zelfstandige_locatie = 0
- # het niet het doe-het-zelf spel betreft
- AND game_code <> 'onfortuinlijke-bankier'
- AND game_code <> 'mysterie-spel-back-to-school'
- AND game_code <> 'koudgemaakte-kok'
- AND game_code <> 'into-the-box'
- # laatste 7 dagen is er niets gebeurd met de aanvraag
- AND aanvr.modified < DATE_SUB(NOW(), INTERVAL 7 DAY)
- # deze herinnering is nog niet eerder verzonden:
- AND (date_7_days_email_sent IS NULL
- OR date_7_days_email_sent = '0000-00-00 00:00:00')
- ",
- ARRAY_A);
- if ( $rows ) {
- foreach ($rows as $row) {
- // send email
- // create certain allowed variables from $arr_aanvraag[0]
- foreach ($row as $key => $value) {
- $$key = $value;
- }
- $emailadres_klant = $emailadres;
- // test
- /////$emailadres_klant = get_option('admin_email');
- $sql = $wpdb->prepare("
- SELECT zelfstandige_locatie, email_address, telephone, contactperson
- FROM wp_pods_locations
- WHERE location_code = %s", $location_code);
- $location_row = $wpdb->get_row($sql, ARRAY_A);
- $zelfstandige_locatie = $location_row['zelfstandige_locatie'];
- $locatie_emailadres = $location_row['email_address'];
- $locatie_telefoon = $location_row['telephone'];
- $locatie_contactpersoon = $location_row['contactperson'];
- $game_name = ucwords(str_replace('-', ' ', $game_code) );
- $town_name = ucwords(str_replace('-', ' ', $town_code) );
- $location_name = ucwords(str_replace('-', ' ', $location_code) );
- $website = 'Dinerspel.nl';
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $voorkeursdatum_1 = format_nlDate($voorkeursdatum_1);
- $voorkeursdatum_2 = format_nlDate($voorkeursdatum_2);
- $gameurltext = $game_name.' in '.$location_name.' in '.$town_name;
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'">'.home_url().'/'.$game_code.'/'.$town_code.'/'.$location_code.'</a>';
- $url_msg = home_url().'/reserveren/'.$code_klant;
- $activate_link = '<a href="'.$url_msg.'">ONLINE RESERVEREN</a>';
- $laatste_actie_was_een_week_geleden = true;
- ob_start();
- if ($zelfstandige_locatie) {
- continue; // skip these, do not send them a reminder
- } elseif ($game_code == 'onfortuinlijke-bankier' || $game_code == 'into-the-box' || $game_code == 'mysterie-spel-back-to-school' || $game_code == 'koudgemaakte-kok') {
- $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_locatie ;
- $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_locatie ;
- if ($voorkeursdatum_1_janee == 1 && $voorkeursdatum_2_janee == 1) {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
- }
- if ( ($voorkeursdatum_1_janee == 1 && $voorkeursdatum_2_janee == 0) ||
- ($voorkeursdatum_1_janee == 0 && $voorkeursdatum_2_janee == 1) ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee == 0 && $voorkeursdatum_1_janee == 0) {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
- }
- } elseif ($location_code == 'eigen-locatie') {
- $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_dinerspel ;
- $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_dinerspel ;
- $gameurltext = $game_name.' in eigen locatie';
- $gameurllink = '<a href="'.home_url().'/'.$game_code.'/eigen-locatie">'.home_url().'/'.$game_code.'/eigen-locatie</a>';
- if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1')
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_data.php");
- if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ||
- ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0')
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_EL_naar_klant_beide_niet.php");
- } else {
- $voorkeursdatum_1_janee = $voorkeursdatum_1_janee_dinerspel ;
- $voorkeursdatum_2_janee = $voorkeursdatum_2_janee_dinerspel ;
- if ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '1') {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_data.php");
- }
- if ( ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ||
- ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '1') ) {
- $date_1_or_2 = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? '1' : '2';
- $date_available = ($voorkeursdatum_1_janee == '1' && $voorkeursdatum_2_janee == '0') ? $voorkeursdatum_1 : $voorkeursdatum_2;
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_1_datum.php");
- }
- if ($voorkeursdatum_1_janee == '0' && $voorkeursdatum_2_janee == '0') {
- include(dirname(__FILE__) . "/templates/tpl_email_beschikbaarheid_naar_klant_beide_niet.php");
- }
- }
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- if (!empty($message)) {
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail($emailadres_klant, 'HERINNERING (NA 7 DAGEN): Beschikbaarheid m.b.t. uw aanvraag via '.$website, $message);
- error_log('************** wp_mail( '.$emailadres_klant.', HERINNERING (NA 7 DAGEN): Beschikbaarheid m.b.t. uw aanvraag via... ); MAILRESULT: '.$mailresult);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- // set date flag to indicate this email has been sent
- $sql = "
- UPDATE wp_pods_aanvragen
- SET modified = NOW(),
- date_7_days_email_sent = NOW()
- WHERE id = ".$aanvraag_id;
- $updres = $wpdb->get_results( $sql );
- }
- }
- }
- }
- //==================================================================
- function send_recensie_invite_to_client() {
- error_log('**************** send_recensie_invite_to_client ');
- global $wpdb;
- // kan met de gewone wpdb
- $sql =
- "SELECT aanvr.id as aanvraag_id, locs.id as location_id, aanvr.*, locs.*
- FROM wp_pods_aanvragen aanvr
- INNER JOIN wp_pods_locations locs ON (aanvr.location_code = locs.location_code)
- WHERE
- # klant heeft gereserveerd, dus code_klant is leeg:
- code_klant = ''
- # reserveringsdatum was gisteren
- AND aanvr.reserveringsdatum = DATE_FORMAT(DATE_SUB(NOW(), INTERVAL 1 DAY), '%Y-%m-%d')
- # deze herinnering is nog niet eerder verzonden:
- AND date_recensie_invite_email_sent = '0000-00-00 00:00:00'
- ORDER BY aanvr.reserveringsdatum DESC
- ";
- $rows = $wpdb->get_results($sql, ARRAY_A);
- if ( $rows ) {
- foreach ($rows as $row) {
- // send email
- // create certain allowed variables from $arr_aanvraag[0]
- foreach ($row as $key => $value) {
- $$key = $value;
- }
- $emailadres_klant = $emailadres;
- $website = 'Dinerspel.nl';
- $aanhef = ($geslacht == 'Vrouw') ? 'mevrouw' : 'heer';
- $voornaam = ucfirst($voornaam);
- $achternaam = ucwords($name);
- //$geslacht = strtolower($geslacht);
- $url_msg = home_url().'/recensies/';
- $activate_link = '<a href="'.$url_msg.'">EEN RECENSIE PLAATSEN</a>';
- ob_start();
- include(dirname(__FILE__) . "/templates/tpl_email_recensie_invite.php");
- $temp_content = ob_get_contents();
- ob_end_clean();
- $message = $temp_content;
- if (!empty($message)) {
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- $mailresult = wp_mail($emailadres_klant, 'Plaats uw recensie en Foto van de Maand', $message);
- error_log('**************** wp_mail('.$emailadres_klant.', Uw unieke spelcode van Dinerspel.nl, message); MAILRESULT: '.$mailresult);
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- // set date flag to indicate this email has been sent
- $sql = "
- UPDATE wp_pods_aanvragen
- SET modified = NOW(),
- date_recensie_invite_email_sent = NOW()
- WHERE id = ".$aanvraag_id;
- $updres = $wpdb->get_results( $sql );
- }
- }
- }
- }
- //==================================================================
- // SEND WEEKLY REPORT TO LOCATIONS ABOUT OUTSTANDING RESERVATIONS
- // THIS FUNCTION IS TRIGGERED IN FUNCTION DO_THIS_DAILY)
- function send_weekly_report_to_location() {
- error_log('**************** send_weekly_report_to_location ');
- global $wpdb;
- $website = 'Dinerspel.nl';
- $currlocaldatetime = new DateTime(date(DATE_ATOM), new DateTimeZone('Europe/Amsterdam'));
- $vandaag = $currlocaldatetime->format('d-m-Y');
- $arr_selected_fields = array('reserveringsdatum', 'game_code', 'geslacht', 'name', 'tijd');
- $str_selected_fields = implode(", ", $arr_selected_fields);
- $arr_selected_field_labels = array('Reserveringsdatum', 'Spel', 'Klant', 'Tijd');
- // LOOP THRU ALL LOCAIONS EXCEPT EIGEN-LOCATIE
- $rows = $wpdb->get_results( "SELECT location_code, location_name, email_address
- FROM wp_pods_locations
- WHERE location_code <> 'eigen-locatie'
- AND id IN (SELECT wp_pods_locations.id
- FROM wp_pods_locations
- INNER JOIN wp_rel_locations_games
- ON (wp_pods_locations.id = wp_rel_locations_games.location_id AND activated = 1)
- )
- " );
- foreach ( $rows as $row ) {
- // COLLECT RESERVATIONS FROM BOTH DINERSPEL AND MOORDDINER FOR THIS LOCATION
- $location_code = $row->location_code;
- $location_name = $row->location_name;
- $location_email = $row->email_address;
- $sqlQuery = "SELECT ".$str_selected_fields."
- FROM wp_pods_aanvragen
- WHERE reserveringsdatum > DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))
- AND action_status = 'Gereserveerd'
- AND location_code = '".$location_code."'
- ORDER BY reserveringsdatum
- ";
- $recordset1 = $wpdb->get_results( $sqlQuery, ARRAY_A );
- if (DB_HOST2 > ' ') {
- $remote_wpdb = new WPDB( DB_USER2, DB_PASSWORD2, DB_NAME2, DB_HOST2);
- $sqlQuery = "SELECT ".$str_selected_fields."
- FROM wp_pods_aanvragen
- WHERE reserveringsdatum > DATE(DATE_SUB(NOW(), INTERVAL 1 DAY))
- AND action_status = 'Gereserveerd'
- AND location_code = '".$location_code."'
- ORDER BY reserveringsdatum
- ";
- $recordset2 = $remote_wpdb->get_results( $sqlQuery, ARRAY_A );
- } else {
- $recordset2 = array();
- }
- $recordset = array_merge($recordset1, $recordset2);
- if ( empty($recordset) && !empty($location_email)) {
- ob_start();
- include(dirname(__FILE__) . "/templates/tpl_email_wekelijks_overzicht_naar_locatie.php");
- $message = ob_get_contents();
- $headers = 'From: Dinerspel.nl <'.MAILFROM_RESERVERINGEN.'>';
- get_header();
- ob_end_clean();
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- if(wp_mail( $location_email, 'Openstaande reserveringen via '.$website, $message, $headers)) {
- error_log('************** wp_mail( '.$location_email.', GEEN Openstaande reserveringen via... ); MAILRESULT: OK, sent');
- } else {
- error_log('************** wp_mail( '.$location_email.', GEEN Openstaande reserveringen via... ); MAILRESULT: mail_error');
- };
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- continue; // GO TO NEXT $row
- }
- if ( empty($location_email)) {
- continue; // GO TO NEXT $row
- }
- // BELOW FOR WHEN RECORDSET IS NOT EMPTY
- $sort = new SortMdArray;
- $sort->sortByKey($recordset);
- // CREATE LIST OF RESERVATIONS FOR THIS LOCATION
- ob_start();
- print '
- <table cellpadding="2" cellspacing="0">
- <tr>';
- foreach ($arr_selected_field_labels as $fieldlabel) {
- print '
- <th>'.$fieldlabel.'</th>';
- }
- print '
- </tr>';
- foreach ($recordset as $record) {
- print '
- <tr>';
- foreach ($record as $fieldname=> $fieldvalue) {
- if ($fieldname == 'geslacht') {
- $aanhef = ($fieldvalue == 'Man') ? 'heer' : 'mevrouw';
- } elseif ($fieldname == 'name') {
- print '
- <td>'.$aanhef.' '.utf8_decode($fieldvalue).'</td>';
- } elseif ($fieldname == 'reserveringsdatum') {
- $dateObj = new DateTime($fieldvalue);
- $dateformatted = $dateObj->format('d-m-Y');
- print '
- <td>'.$dateformatted.'</td>';
- } else {
- print '
- <td>'.$fieldvalue.'</td>';
- }
- }
- print '
- </tr>';
- }
- print '
- </table>';
- $div_report_table = ob_get_contents();
- ob_end_clean();
- //----------------------------------
- // stuur overzicht naar LOCATIE
- //----------------------------------
- ob_start();
- include(dirname(__FILE__) . "/templates/tpl_email_wekelijks_overzicht_naar_locatie.php");
- $message = ob_get_contents();
- ob_end_clean();
- add_filter( 'wp_mail_content_type', 'set_html_content_type' );
- if(wp_mail( $location_email, 'Openstaande reserveringen via '.$website, $message)) {
- error_log('************** wp_mail( '.$location_email.', X Openstaande reserveringen via... ); MAILRESULT: OK, sent');
- } else {
- error_log('************** wp_mail( '.$location_email.', X Openstaande reserveringen via... ); MAILRESULT: mail_error');
- };
- remove_filter( 'wp_mail_content_type', 'set_html_content_type' );
- } // endif foreach array_locations
- }
- /**
- * VIES VAT number validation
- *
- * @author Eugen Mihailescu
- *
- * @param string $countryCode
- * @param string $vatNumber
- * @param int $timeout
- */
- function viesCheckVAT($countryCode, $vatNumber, $timeout = 30) {
- $response = array ();
- $pattern = '/<(%s).*?>([\s\S]*)<\/\1/';
- $keys = array (
- 'countryCode',
- 'vatNumber',
- 'requestDate',
- 'valid',
- 'name',
- 'address'
- );
- $content = "<s11:Envelope xmlns:s11='http://schemas.xmlsoap.org/soap/envelope/'>
- <s11:Body>
- <tns1:checkVat xmlns:tns1='urn:ec.europa.eu:taxud:vies:services:checkVat:types'>
- <tns1:countryCode>%s</tns1:countryCode>
- <tns1:vatNumber>%s</tns1:vatNumber>
- </tns1:checkVat>
- </s11:Body>
- </s11:Envelope>";
- $opts = array (
- 'http' => array (
- 'method' => 'POST',
- 'header' => "Content-Type: text/xml; charset=utf-8; SOAPAction: checkVatService",
- 'content' => sprintf ( $content, trim($countryCode), trim($vatNumber) ),
- 'timeout' => $timeout
- )
- );
- $ctx = stream_context_create ( $opts );
- $result = file_get_contents ( VIES_URL, false, $ctx );
- if (preg_match ( sprintf ( $pattern, 'checkVatResponse' ), $result, $matches )) {
- foreach ( $keys as $key )
- preg_match ( sprintf ( $pattern, $key ), $matches [2], $value ) && $response [$key] = $value [2];
- }
- return $response;
- }
- //----------------------------------------------------------------------------
- function return_country_name($country_code) {
- $ountries = array(
- "AD" => "Andorra",
- "AE" => "Verenigde Arabische Emiraten",
- "AF" => "Afghanistan",
- "AG" => "Antigua en Barbuda",
- "AI" => "Anguilla",
- "AL" => "Albanië",
- "AM" => "Armenië",
- "AO" => "Angola",
- "AQ" => "Antarctica",
- "AR" => "Argentinië",
- "AS" => "Amerikaans-Samoa",
- "AT" => "Oostenrijk",
- "AU" => "Australië",
- "AW" => "Aruba",
- "AX" => "Γ land",
- "AZ" => "Azerbeidzjan",
- "BA" => "Bosnië en Herzegovina",
- "BB" => "Barbados",
- "BD" => "Bangladesh",
- "BE" => "België",
- "BF" => "Faso Burkina Faso",
- "BG" => "Bulgarije",
- "BH" => "Bahrein",
- "BI" => "Burundi",
- "BJ" => "Benin",
- "BL" => "Saint-Bartholemy",
- "BM" => "Bermuda",
- "BN" => "Brunei",
- "BO" => "Bolivia",
- "BQ" => "Caribisch Nederland",
- "BR" => "Brazilië",
- "BS" => "Bahama's",
- "BT" => "Bhutan",
- "BV" => "Bouveteiland",
- "BW" => "Botswana",
- "BY" => "Wit-Rusland",
- "BZ" => "Belize",
- "CA" => "Canada",
- "CC" => "Cocoseilanden",
- "CD" => "Congo-Kinshasa",
- "CF" => "Centraal-Afrikaanse Republiek",
- "CG" => "Congo-Brazzaville",
- "CH" => "Zwitserland",
- "CI" => "Ivoorkust",
- "CK" => "Cookeilanden",
- "CL" => "Chili",
- "CM" => "Kameroen",
- "CN" => "China",
- "CO" => "Colombia",
- "CR" => "Costa Rica",
- "CU" => "Cuba",
- "CV" => "Kaapverdië",
- "CW" => "CuraΓ§ao",
- "CX" => "Christmaseiland",
- "CY" => "Cyprus",
- "CZ" => "Tsjechië",
- "DE" => "Duitsland",
- "DJ" => "Djibouti",
- "DK" => "Denemarken",
- "DM" => "Dominica",
- "DO" => "Dominicaanse Republiek",
- "DZ" => "Algerije",
- "EC" => "Ecuador",
- "EE" => "Estland",
- "EG" => "Egypte",
- "EH" => "Westelijke Sahara",
- "ER" => "Eritrea",
- "ES" => "Spanje",
- "ET" => "Ethiopië",
- "FI" => "Finland",
- "FJ" => "Fiji",
- "FK" => "Falklandeilanden",
- "FM" => "Micronesia",
- "FO" => "FaerOer",
- "FR" => "Frankrijk",
- "GA" => "Gabon",
- "GB" => "Verenigd Koninkrijk",
- "GD" => "Grenada",
- "GE" => "Georgië",
- "GF" => "Frans-Guyana",
- "GG" => "Guernsey",
- "GH" => "Ghana",
- "GI" => "Gibraltar",
- "GL" => "Groenland",
- "GM" => "Gambia",
- "GN" => "Guinee",
- "GP" => "Guadeloupe",
- "GQ" => "Equatoriaal-Guinea",
- "GR" => "Griekenland",
- "GS" => "Zuid-Georgia en de Zuidelijke Sandwicheilanden",
- "GT" => "Guatemala",
- "GU" => "Guam",
- "GW" => "Guinee-Bissau",
- "GY" => "Guyana",
- "HK" => "Hongkong",
- "HM" => "Heard en McDonaldeilanden",
- "HN" => "Honduras",
- "HR" => "Kroatië",
- "HT" => "Haiti",
- "HU" => "Hongarije",
- "ID" => "Indonesië",
- "IE" => "Ierland",
- "IL" => "Israël",
- "IM" => "Man",
- "IN" => "India",
- "IO" => "Brits Indische Oceaanterritorium",
- "IQ" => "Irak",
- "IR" => "Iran",
- "IS" => "IJsland",
- "IT" => "Italië",
- "JE" => "Jersey",
- "JM" => "Jamaica",
- "JO" => "Jordanië",
- "JP" => "Japan",
- "KE" => "Kenia",
- "KG" => "Kirgizië",
- "KH" => "Cambodja",
- "KI" => "Kiribati",
- "KM" => "Comoren",
- "KN" => "Saint Kitts en Nevis",
- "KP" => "Noord-Korea",
- "KR" => "Zuid-Korea",
- "KW" => "Koeweit",
- "KY" => "Kaaimaneilanden",
- "KZ" => "Kazachstan",
- "LA" => "Laos",
- "LB" => "Libanon",
- "LC" => "Saint Lucia",
- "LI" => "Liechtenstein",
- "LK" => "Sri Lanka",
- "LR" => "Liberia",
- "LS" => "Lesotho",
- "LT" => "Litouwen",
- "LU" => "Luxemburg",
- "LV" => "Letland",
- "LY" => "Libië",
- "MA" => "Marokko",
- "MC" => "Monaco",
- "MD" => "Moldavië",
- "ME" => "Montenegro",
- "MF" => "Sint-Maarten",
- "MG" => "Madagaskar",
- "MH" => "Marshalleilanden",
- "MK" => "Macedonië",
- "ML" => "Mali",
- "MM" => "Myanmar",
- "MN" => "Mongolië",
- "MO" => "Macau",
- "MP" => "Noordelijke Marianen",
- "MQ" => "Martinique",
- "MR" => "Mauritanië",
- "MS" => "Montserrat",
- "MT" => "Malta",
- "MU" => "Mauritius",
- "MV" => "Maldiven",
- "MW" => "Malawi",
- "MX" => "Mexico",
- "MY" => "Maleisië",
- "MZ" => "Mozambique",
- "NA" => "Namibië",
- "NC" => "Nieuw-Caledonië",
- "NE" => "Niger",
- "NF" => "Norfolk",
- "NG" => "Nigeria",
- "NI" => "Nicaragua",
- "NL" => "Nederland",
- "NO" => "Noorwegen",
- "NP" => "Nepal",
- "NR" => "Nauru",
- "NU" => "Niue",
- "NZ" => "Nieuw-Zeeland",
- "OM" => "Oman",
- "PA" => "Panama",
- "PE" => "Peru",
- "PF" => "Frans-Polynesië",
- "PG" => "Papoea-Nieuw-Guinea",
- "PH" => "Filipijnen",
- "PK" => "Pakistan",
- "PL" => "Polen",
- "PM" => "Saint-Pierre en Miquelon",
- "PN" => "Pitcairneilanden",
- "PR" => "Rico Puerto Rico",
- "PS" => "Palestina",
- "PT" => "Portugal",
- "PW" => "Palau",
- "PY" => "Paraguay",
- "QA" => "Qatar",
- "RE" => "Reunion",
- "RO" => "Roemenië",
- "RS" => "Servië",
- "RU" => "Rusland",
- "RW" => "Rwanda",
- "SA" => "Saoedi-Arabië",
- "SB" => "Salomonseilanden",
- "SC" => "Seychellen",
- "SD" => "Soedan",
- "SE" => "Zweden",
- "SG" => "Singapore",
- "SH" => "Koninkrijk Sint-Helena, Ascension en Tristan da Cunha",
- "SI" => "Slovenië",
- "SJ" => "Spitsbergen en Jan Mayen",
- "SK" => "Slowakije",
- "SL" => "Leone Sierra Leone",
- "SM" => "Marino San Marino",
- "SN" => "Senegal",
- "SO" => "Somalië",
- "SR" => "Suriname",
- "SS" => "Zuid-Soedan",
- "ST" => "Sao TomΓ© en Principe",
- "SV" => "El Salvador",
- "SX" => "Sint Maarten",
- "SY" => "Syrië",
- "SZ" => "Swaziland",
- "TC" => "Turks- en Caicoseilanden",
- "TD" => "Tsjaad",
- "TF" => "Franse Zuidelijke en Antarctische Gebieden",
- "TG" => "Togo",
- "TH" => "Thailand",
- "TJ" => "Tadzjikistan",
- "TK" => "Tokelau",
- "TL" => "Oost-Timor",
- "TM" => "Turkmenistan",
- "TN" => "Tunesië",
- "TO" => "Tonga",
- "TR" => "Turkije",
- "TT" => "Trinidad en Tobago",
- "TV" => "Tuvalu",
- "TW" => "Taiwan",
- "TZ" => "Tanzania",
- "UA" => "Oekraine",
- "UG" => "Oeganda",
- "UM" => "Pacifische eilanden van de VS Kleine afgelegen eilanden van de Verenigde Staten",
- "US" => "Verenigde Staten",
- "UY" => "Uruguay",
- "UZ" => "Oezbekistan",
- "VA" => "Vaticaanstad",
- "VC" => "Saint Vincent en de Grenadines",
- "VE" => "Venezuela",
- "VG" => "Britse Maagdeneilanden",
- "VI" => "Amerikaanse Maagdeneilanden",
- "VN" => "Vietnam",
- "VU" => "Vanuatu",
- "WF" => "Wallis en Futuna",
- "WS" => "Samoa",
- "YE" => "Jemen",
- "YT" => "Mayotte",
- "ZA" => "Zuid-Afrika",
- "ZM" => "Zambia",
- "ZW" => "Zimbabwe"
- );
- return $ountries[$country_code];
- }
Advertisement
Add Comment
Please, Sign In to add comment