Plugin Directory

Changeset 2732889


Ignore:
Timestamp:
05/27/2022 08:33:47 PM (4 years ago)
Author:
rezgo
Message:

committing version 4.1.6

Location:
rezgo/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • rezgo/trunk/readme.txt

    r2713519 r2732889  
    44Tags:  tour operator software, tour booking system, activity booking software, tours, activities, events, attractions, booking, reservation, ticketing, e-commerce, business, rezgo
    55Requires at least: 3.3.0
    6 Tested up to: 5.9.3
     6Tested up to: 6.0
    77Requires PHP: 5.2
    8 Stable tag: 4.1.5
     8Stable tag: 4.1.6
    99
    1010Sell your tours, activities, and events on your WordPress website using Rezgo.
     
    134134
    135135== Changelog ==
     136= 4.1.6 =
     137* Bug fixes
     138
    136139= 4.1.5 =
    137140* Template UI updates
  • rezgo/trunk/rezgo.php

    r2713519 r2732889  
    55    Plugin URI: https://wordpress.org/plugins/rezgo/
    66    Description: Connect WordPress to your Rezgo account and accept online bookings directly on your website.
    7     Version: 4.1.5
     7    Version: 4.1.6
    88    Author: Rezgo
    99    Author URI: http://www.rezgo.com
     
    5454define('REZGO_PLUGIN_NAME', 'rezgo');
    5555define('REZGO_PLUGIN_DIR', plugin_dir_path(__FILE__));
    56 define('REZGO_PLUGIN_VERSION', '4.1.5');
     56define('REZGO_PLUGIN_VERSION', '4.1.6');
    5757
    5858require_once('rezgo/include/page_header.php');
  • rezgo/trunk/rezgo/include/class.rezgo.php

    r2713519 r2732889  
    11<?php
    22
    3     /*
    4         This is the Rezgo parser class, it handles processing for the Rezgo API.
    5        
    6         VERSION:
    7                 3.1.0
    8        
    9         - Documentation and latest version
    10                 https://www.rezgo.com/rezgo-open-source-booking-engine/
    11        
    12         - Finding your Rezgo CID and API KEY
    13                 https://www.rezgo.com/support-article/create-api-keys
    14        
    15         AUTHOR:
    16                 Kevin Campbell
    17                 John McDonald
    18        
    19         Copyright (c) 2012-2020, Rezgo (A Division of Sentias Software Corp.)
    20         All rights reserved.
    21        
    22         Redistribution and use in source form, with or without modification,
    23         is permitted provided that the following conditions are met:
    24        
    25         * Redistributions of source code must retain the above copyright
    26         notice, this list of conditions and the following disclaimer.
    27         * Neither the name of Rezgo, Sentias Software Corp, nor the names of
    28         its contributors may be used to endorse or promote products derived
    29         from this software without specific prior written permission.
    30         * Source code is provided for the exclusive use of Rezgo members who
    31         wish to connect to their Rezgo API. Modifications to source code
    32         may not be used to connect to competing software without specific
    33         prior written permission.
    34        
    35         THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    36         "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    37         LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    38         A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    39         HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    40         SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    41         LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    42         DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    43         THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    44         (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    45         OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    46     */
    47 
    48     class RezgoSite {
    49    
    50         var $version = '3.1.0';
    51        
    52         var $requestID;
    53         var $instanceID;
    54        
    55         var $xml_path;
    56         var $contents;
    57         var $get;
    58         var $xml;
    59         var $secure = 'http://';
    60         var $obj;
    61        
    62         var $country_list;
    63        
    64         // indexes are used to split up response caches by different criteria
    65         var $tours_index = 0; // split up by search string
    66         var $company_index = 0; // split up by CID (for vendors only, suppliers use 0)
    67         var $currency_values;
    68         var $tour_limit;
    69         var $refid;
    70         var $promo_code;
    71         var $pageTitle;
    72         var $metaTags;
    73        
    74         // calendar specific values
    75         var $calendar_name;
    76         var $calendar_com;
    77         var $calendar_active;
    78        
    79         var $calendar_prev;
    80         var $calendar_next;
    81        
    82         var $calendar_months = array();
    83         var $calendar_years = array();
    84        
    85         // api result caches improve performance by not hitting the gateway multiple times
    86         // searches that have differing args sort them into arrays with the index variables above
    87         var $company_response;
    88         var $page_response = array();
    89         var $tags_response;     
    90         var $search_response;
    91         var $tour_availability_response;
    92         var $search_bookings_response;
    93         var $search_total;
    94         var $cart_total;
    95         var $commit_response;
    96         var $contact_response;
    97         var $ticket_response;
    98         var $waiver_response;
    99         var $signing_response;
    100         var $review_response;
    101         var $pickup_response;
    102         var $payment_response;
    103         var $public_response;
    104 
    105         var $lead_passenger_email;
    106         var $lead_passenger_first_name;
    107         var $lead_passenger_last_name;
    108 
    109         var $cart_api_response;
    110         var $cart_api_request;
    111         var $cart_data;
    112         var $cart_status;
    113        
    114         // primary_forms
    115         var $form_display = array();
    116         // group_forms
    117         var $gf_form_display = array();
    118        
    119         var $tour_forms;
    120         var $all_required;
    121         var $cart = array();
    122         var $cart_token;
    123         var $cart_trigger_code;
    124 
    125         var $cart_ids;
    126         var $gift_card;
    127        
    128         // debug and error stacks
    129         var $error_stack;
    130         var $debug_stack;
    131        
    132         // ------------------------------------------------------------------------------
    133         // if the class was called with an argument then we use that as the object name
    134         // this allows us to load the object globalls for included templates.
    135         // ------------------------------------------------------------------------------
    136 
    137         function __construct($secure=null, $newID=null) {
    138             if (!$this->config('REZGO_SKIP_BUFFER')) ob_start();
    139 
    140             // check the config file to make sure it's loaded
    141             if (!$this->config('REZGO_CID')) $this->error('REZGO_CID definition missing, check config file', 1);
    142            
    143             if($newID) { $this->requestID = $this->setRequestID(); }
    144             else { $this->requestID = ($_SESSION['requestID']) ? $_SESSION['requestID'] : $this->setRequestID(); }
    145            
    146             // get request ID if it exists, otherwise generate a fresh one
    147             $this->requestID = ($_SESSION['requestID']) ? $_SESSION['requestID'] : $this->setRequestID();
    148            
    149             $this->origin = $this->config('REZGO_ORIGIN');
    150 
    151             // assemble API address
    152             $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
    153             $this->api_post_string = 'xml='.urlencode('<request><transcode>'.REZGO_CID.'</transcode><key>'.REZGO_API_KEY.'</key>');
    154             $this->advanced_xml_path = REZGO_XML.'/xml?req='.$this->requestID.'&g='.$this->origin.'&'.$this->api_post_string;
    155 
    156             if (isset($this->path)){
    157                 if (!defined("REZGO_PATH")) define("REZGO_PATH", $this->path);
    158             }
    159             // it's possible to define the document root manually if there is an issue with the _SERVER variable
    160             if (!defined("REZGO_DOCUMENT_ROOT")) define("REZGO_DOCUMENT_ROOT", $_SERVER["DOCUMENT_ROOT"]);
    161 
    162             // assemble template and url path
    163             if (REZGO_CUSTOM_TEMPLATE_USE) {
    164                 $this->path = str_replace(REZGO_DOCUMENT_ROOT, '', WP_CONTENT_DIR) .'/rezgo/templates/'.REZGO_TEMPLATE.'/';
    165             } else {
    166                 $this->path = REZGO_DIR.'/templates/'.REZGO_TEMPLATE;
    167             }
    168 
    169             $this->ajax_url = REZGO_URL_BASE;
    170             $this->base = REZGO_URL_BASE;
    171 
    172             // set the secure mode for this particular page
    173             $this->setSecure($secure);
    174 
    175             // perform some variable filtering
    176             if (isset($_REQUEST['start_date'])) {
    177                 if (strtotime($_REQUEST['start_date']) == 0) unset($_REQUEST['start_date']);
    178             }
    179 
    180             if (isset($_REQUEST['end_date'])) {
    181                 if (strtotime($_REQUEST['end_date']) == 0) unset($_REQUEST['end_date']);
    182             }
    183 
    184             // handle the refID if one is set
    185             if (isset($_REQUEST['refid']) || isset($_REQUEST['ttl']) || isset($_COOKIE['rezgo_refid_val']) || isset($_SESSION['rezgo_refid_val'])) {
    186                
    187                 if (isset($_REQUEST['refid']) || isset($_REQUEST['ttl'])) {
    188                     $this->searchCart();
    189                     if ($this->cart) $this->updateRefId($_REQUEST['refid']);
    190                    
    191                     $new_header = $_SERVER['REQUEST_URI'];
    192 
    193                     // remove the refid information wherever it is
    194                     $new_header = preg_replace("/&?refid=[^&\/]*/", "", $new_header);
    195                     $new_header = str_replace("?&", "?", $new_header);
    196                     $new_header = preg_replace("/&?ttl=[^&\/]*/", "", $new_header);
    197                     $new_header = str_replace("?&", "?", $new_header);
    198 
    199                     if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
    200 
    201                     $refid = $this->requestStr('refid');
    202 
    203                     $ttl = ($this->requestStr('ttl')) ? $this->requestStr('ttl') : 7200;
    204                    
    205                 } elseif (isset($_SESSION['rezgo_refid_val'])) {
    206                
    207                     $refid = $_SESSION['rezgo_refid_val'];
    208                     $ttl = $_SESSION['rezgo_refid_ttl'];
    209                    
    210                 }
    211                 elseif (isset($_COOKIE['rezgo_refid_val'])) {
    212                
    213                     $refid = $_COOKIE['rezgo_refid_val'];
    214                     $ttl = $_COOKIE['rezgo_refid_ttl'];
    215                    
    216                 }
    217 
    218                 $this->setCookie("rezgo_refid_val", $refid);
    219                 $this->setCookie("rezgo_refid_ttl", $ttl);
    220 
    221                 // if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
    222                 //  setcookie("rezgo_refid_val", $refid, time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
    223                 //  setcookie("rezgo_refid_ttl", $ttl, time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
    224                 // } else {
    225                 //  setcookie("rezgo_refid_val", $refid, time() + $ttl, '/', $_SERVER['HTTP_HOST']);
    226                 //  setcookie("rezgo_refid_ttl", $ttl, time() + $ttl, '/', $_SERVER['HTTP_HOST']);
    227                 // }
    228 
    229                 // we need to set the session here before we header the user off or the old session will override the new refid each time
    230                 if ($ttl > 0 && !is_multisite()) {
    231                     $_SESSION['rezgo_refid_val'] = $refid;
    232                     $_SESSION['rezgo_refid_ttl'] = $ttl;
    233                 } else {
    234                     unset($_SESSION['rezgo_refid_val']);
    235                     unset($_SESSION['rezgo_refid_ttl']);
    236                 }
    237 
    238                 if (isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header);
    239 
    240             }   
    241 
    242             // handle the promo code if one is set
    243             if(isset($_REQUEST['promo'])) {
    244                
    245                 $ttl = 1209600; // two weeks is the default time-to-live for the promo cookie
    246                
    247                 if(isset($_REQUEST['promo']) && !$_REQUEST['promo']) {
    248                     $_REQUEST['promo'] = ' '; // force a request below
    249                     $ttl = -1; // set the ttl to -1, removing the promo code
    250                 }
    251                
    252                 if($_REQUEST['promo']) {
    253 
    254                     if($_REQUEST['promo'] == ' ') unset($_REQUEST['promo']);
    255 
    256                     $this->searchCart();
    257                     if ($this->cart) $this->updatePromo($_REQUEST['promo']);
    258                
    259                     $new_header = $_SERVER['REQUEST_URI'];
    260                    
    261                     // remove the promo information wherever it is
    262                     $new_header = preg_replace("/&?promo=[^&\/]*/", "", $new_header);
    263                     $new_header = str_replace("?&", "?", $new_header);
    264                    
    265                     // in case the format is /promo/text and the htaccess isn't reformatting it for above
    266                     $new_header = preg_replace("/promo\/[^\/]*/", "", $new_header);
    267                     $new_header = str_replace("//", "/", $new_header);
    268                    
    269                     if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
    270 
    271                     $promo = $this->requestStr('promo');
    272 
    273                     $this->setCookie("rezgo_promo", $promo);
    274                     $_SESSION['promo'] = $_REQUEST['promo'];
    275 
    276                 }
    277 
    278                 // we need to set the session here before we header the user off or the old session will override the new promo code each time
    279                 if(!is_multisite()) {
    280                     $_SESSION['promo'] = $promo;
    281                 } else {
    282                     unset($_SESSION['promo']);
    283                 }
    284 
    285                 if(isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header);
    286             }
    287 
    288             // handle the add to cart request if one is set
    289             if($_REQUEST['order'] == 'clear' && is_array($_REQUEST['add'])) {
    290                
    291                 $cart = $this->createCart();
    292                
    293                 $this->cart_token = $cart;
    294                 $this->setCookie('rezgo_cart_token_'.REZGO_CID, $cart);
    295                 $_COOKIE['rezgo_cart_token_'.REZGO_CID] = $cart;
    296                
    297                 $this->addCart();
    298 
    299                 $new_header = $_SERVER['REQUEST_URI'];
    300                 // remove the order=clear and add information wherever it is
    301                 $new_header = preg_replace("/&?order=clear/", "", $new_header);
    302                 $new_header = str_replace("?&", "?", $new_header);
    303 
    304                 $promo = ($_REQUEST['promo']) ? '?promo='.$_REQUEST['promo'] : '';
    305 
    306                 // remove the promo information wherever it is
    307                 $new_header = preg_replace("/&?promo=[^&\/]*/", "", $new_header);
    308                 $new_header = str_replace("?&", "?", $new_header);
    309 
    310                 // replace order with book in URI
    311                 $new_header = str_replace("order", "book", $new_header);
    312 
    313                 // remove the cart information wherever it is
    314                 $new_header = preg_replace("/&?add\[[^&\/]*\]=[^&\/]*/", "", $new_header);
    315                 $new_header = str_replace("?&", "?", $new_header);
    316 
    317                 if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
    318 
    319                 if(isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header.$cart.$promo);
    320 
    321                 if ($_REQUEST['promo']) $this->updatePromo($_REQUEST['promo']);
    322                
    323                 exit;
    324            
    325                
    326             }
    327            
    328             // registering global events, these can be manually changed later with the same methods
    329             $this->setRefId();
    330             // set promo code to what is returned by the cart API
    331             $this->setPromoCode();
    332         }
    333        
    334         function config($arg) {
    335             if(!defined($arg)) {
    336                 return 0;
    337             } else {
    338                 if(constant($arg) == '') { return 0; }
    339                 else { return constant($arg); }
    340             }
    341         }
    342        
    343         function error($message, $exit=null) {
    344             throw new ErrorException($message);
    345         }
    346        
    347         function debug($message, $i=null) {
    348             $stack = debug_backtrace();
    349             $stack = $stack[count($stack)-1]; // get the origin point
    350            
    351             $message = urldecode($message);
    352 
    353             if($this->config('REZGO_FIREBUG_XML')) {
    354                 if(($i == 'commit' || $i == 'commitOrder' || $i == 'add_transaction') && $this->config('REZGO_SWITCH_COMMIT')) {
    355                     if($this->config('REZGO_STOP_COMMIT')) {
    356                         echo $_SESSION['error_catch'] = 'STOP::'.$message.'<br><br>';
    357                     }
    358                 } else {
    359                     $_SESSION['debug'][] = addslashes($message);
    360                 }
    361             }
    362 
    363             if($this->config('REZGO_DISPLAY_XML'))  {
    364                 if(($i == 'commit' || $i == 'commitOrder' || $i == 'add_transaction') && $this->config('REZGO_SWITCH_COMMIT')) {
    365                     die('STOP::'.$message);
     3/*
     4    This is the Rezgo parser class, it handles processing for the Rezgo API.
     5
     6    VERSION:
     7            3.1.0
     8
     9    - Documentation and latest version
     10            https://www.rezgo.com/rezgo-open-source-booking-engine/
     11
     12    - Finding your Rezgo CID and API KEY
     13            https://www.rezgo.com/support-article/create-api-keys
     14
     15    AUTHOR:
     16            Kevin Campbell
     17            John McDonald
     18
     19    Copyright (c) 2012-2020, Rezgo (A Division of Sentias Software Corp.)
     20    All rights reserved.
     21
     22    Redistribution and use in source form, with or without modification,
     23    is permitted provided that the following conditions are met:
     24
     25    * Redistributions of source code must retain the above copyright
     26    notice, this list of conditions and the following disclaimer.
     27    * Neither the name of Rezgo, Sentias Software Corp, nor the names of
     28    its contributors may be used to endorse or promote products derived
     29    from this software without specific prior written permission.
     30    * Source code is provided for the exclusive use of Rezgo members who
     31    wish to connect to their Rezgo API. Modifications to source code
     32    may not be used to connect to competing software without specific
     33    prior written permission.
     34
     35    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     36    "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     37    LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     38    A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     39    HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     40    SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     41    LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     42    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     43    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     44    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     45    OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     46*/
     47
     48class RezgoSite {
     49
     50    var $version = '3.1.0';
     51
     52    var $requestID;
     53    var $instanceID;
     54
     55    var $xml_path;
     56    var $contents;
     57    var $get;
     58    var $xml;
     59    var $secure = 'http://';
     60    var $obj;
     61
     62    var $country_list;
     63
     64    // indexes are used to split up response caches by different criteria
     65    var $tours_index = 0; // split up by search string
     66    var $company_index = 0; // split up by CID (for vendors only, suppliers use 0)
     67    var $currency_values;
     68    var $tour_limit;
     69    var $refid;
     70    var $promo_code;
     71    var $pageTitle;
     72    var $metaTags;
     73
     74    // calendar specific values
     75    var $calendar_name;
     76    var $calendar_com;
     77    var $calendar_active;
     78
     79    var $calendar_prev;
     80    var $calendar_next;
     81
     82    var $calendar_months = array();
     83    var $calendar_years = array();
     84
     85    // api result caches improve performance by not hitting the gateway multiple times
     86    // searches that have differing args sort them into arrays with the index variables above
     87    var $company_response;
     88    var $page_response = array();
     89    var $tags_response;
     90    var $search_response;
     91    var $tour_availability_response;
     92    var $search_bookings_response;
     93    var $search_total;
     94    var $cart_total;
     95    var $commit_response;
     96    var $contact_response;
     97    var $ticket_response;
     98    var $waiver_response;
     99    var $signing_response;
     100    var $review_response;
     101    var $pickup_response;
     102    var $payment_response;
     103    var $public_response;
     104
     105    var $lead_passenger_email;
     106    var $lead_passenger_first_name;
     107    var $lead_passenger_last_name;
     108
     109    var $cart_api_response;
     110    var $cart_api_request;
     111    var $cart_data;
     112    var $cart_status;
     113
     114    // primary_forms
     115    var $form_display = array();
     116    // group_forms
     117    var $gf_form_display = array();
     118
     119    var $tour_forms;
     120    var $all_required;
     121    var $cart = array();
     122    var $cart_token;
     123    var $cart_trigger_code;
     124
     125    var $cart_ids;
     126    var $gift_card;
     127
     128    // debug and error stacks
     129    var $error_stack;
     130    var $debug_stack;
     131
     132    // ------------------------------------------------------------------------------
     133    // if the class was called with an argument then we use that as the object name
     134    // this allows us to load the object globalls for included templates.
     135    // ------------------------------------------------------------------------------
     136
     137    function __construct($secure=null, $newID=null) {
     138        if (!$this->config('REZGO_SKIP_BUFFER')) ob_start();
     139
     140        // check the config file to make sure it's loaded
     141        if (!$this->config('REZGO_CID')) $this->error('REZGO_CID definition missing, check config file', 1);
     142
     143        if($newID) { $this->requestID = $this->setRequestID(); }
     144        else { $this->requestID = ($_SESSION['requestID']) ? $_SESSION['requestID'] : $this->setRequestID(); }
     145
     146        // get request ID if it exists, otherwise generate a fresh one
     147        $this->requestID = ($_SESSION['requestID']) ? $_SESSION['requestID'] : $this->setRequestID();
     148
     149        $this->origin = $this->config('REZGO_ORIGIN');
     150
     151        // assemble API address
     152        $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
     153        $this->api_post_string = 'xml='.urlencode('<request><transcode>'.REZGO_CID.'</transcode><key>'.REZGO_API_KEY.'</key>');
     154        $this->advanced_xml_path = REZGO_XML.'/xml?req='.$this->requestID.'&g='.$this->origin.'&'.$this->api_post_string;
     155
     156        if (isset($this->path)){
     157            if (!defined("REZGO_PATH")) define("REZGO_PATH", $this->path);
     158        }
     159        // it's possible to define the document root manually if there is an issue with the _SERVER variable
     160        if (!defined("REZGO_DOCUMENT_ROOT")) define("REZGO_DOCUMENT_ROOT", $_SERVER["DOCUMENT_ROOT"]);
     161
     162        // assemble template and url path
     163        if (REZGO_CUSTOM_TEMPLATE_USE) {
     164            $this->path = str_replace(REZGO_DOCUMENT_ROOT, '', WP_CONTENT_DIR) .'/rezgo/templates/'.REZGO_TEMPLATE.'/';
     165        } else {
     166            $this->path = REZGO_DIR.'/templates/'.REZGO_TEMPLATE;
     167        }
     168
     169        $this->ajax_url = REZGO_URL_BASE;
     170        $this->base = REZGO_URL_BASE;
     171
     172        // set the secure mode for this particular page
     173        $this->setSecure($secure);
     174
     175        // perform some variable filtering
     176        if (isset($_REQUEST['start_date'])) {
     177            if (strtotime($_REQUEST['start_date']) == 0) unset($_REQUEST['start_date']);
     178        }
     179
     180        if (isset($_REQUEST['end_date'])) {
     181            if (strtotime($_REQUEST['end_date']) == 0) unset($_REQUEST['end_date']);
     182        }
     183
     184        // handle the refID if one is set
     185        if (isset($_REQUEST['refid']) || isset($_REQUEST['ttl']) || isset($_COOKIE['rezgo_refid_val']) || isset($_SESSION['rezgo_refid_val'])) {
     186
     187            if (isset($_REQUEST['refid']) || isset($_REQUEST['ttl'])) {
     188                $this->searchCart();
     189                if ($this->cart) $this->updateRefId($_REQUEST['refid']);
     190
     191                $new_header = $_SERVER['REQUEST_URI'];
     192
     193                // remove the refid information wherever it is
     194                $new_header = preg_replace("/&?refid=[^&\/]*/", "", $new_header);
     195                $new_header = str_replace("?&", "?", $new_header);
     196                $new_header = preg_replace("/&?ttl=[^&\/]*/", "", $new_header);
     197                $new_header = str_replace("?&", "?", $new_header);
     198
     199                if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
     200
     201                $refid = $this->requestStr('refid');
     202
     203                $ttl = ($this->requestStr('ttl')) ? $this->requestStr('ttl') : 7200;
     204
     205            } elseif (isset($_SESSION['rezgo_refid_val'])) {
     206
     207                $refid = $_SESSION['rezgo_refid_val'];
     208                $ttl = $_SESSION['rezgo_refid_ttl'];
     209
     210            }
     211            elseif (isset($_COOKIE['rezgo_refid_val'])) {
     212
     213                $refid = $_COOKIE['rezgo_refid_val'];
     214                $ttl = $_COOKIE['rezgo_refid_ttl'];
     215
     216            }
     217
     218            $this->setCookie("rezgo_refid_val", $refid);
     219            $this->setCookie("rezgo_refid_ttl", $ttl);
     220
     221            // if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
     222            //  setcookie("rezgo_refid_val", $refid, time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
     223            //  setcookie("rezgo_refid_ttl", $ttl, time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
     224            // } else {
     225            //  setcookie("rezgo_refid_val", $refid, time() + $ttl, '/', $_SERVER['HTTP_HOST']);
     226            //  setcookie("rezgo_refid_ttl", $ttl, time() + $ttl, '/', $_SERVER['HTTP_HOST']);
     227            // }
     228
     229            // we need to set the session here before we header the user off or the old session will override the new refid each time
     230            if ($ttl > 0 && !is_multisite()) {
     231                $_SESSION['rezgo_refid_val'] = $refid;
     232                $_SESSION['rezgo_refid_ttl'] = $ttl;
     233            } else {
     234                unset($_SESSION['rezgo_refid_val']);
     235                unset($_SESSION['rezgo_refid_ttl']);
     236            }
     237
     238            if (isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header);
     239
     240        }
     241
     242        // handle the promo code if one is set
     243        if(isset($_REQUEST['promo'])) {
     244
     245            $ttl = 1209600; // two weeks is the default time-to-live for the promo cookie
     246
     247            if(isset($_REQUEST['promo']) && !$_REQUEST['promo']) {
     248                $_REQUEST['promo'] = ' '; // force a request below
     249                $ttl = -1; // set the ttl to -1, removing the promo code
     250            }
     251
     252            if($_REQUEST['promo']) {
     253
     254                if($_REQUEST['promo'] == ' ') unset($_REQUEST['promo']);
     255
     256                $this->searchCart();
     257                if ($this->cart) $this->updatePromo($_REQUEST['promo']);
     258
     259                $new_header = $_SERVER['REQUEST_URI'];
     260
     261                // remove the promo information wherever it is
     262                $new_header = preg_replace("/&?promo=[^&\/]*/", "", $new_header);
     263                $new_header = str_replace("?&", "?", $new_header);
     264
     265                // in case the format is /promo/text and the htaccess isn't reformatting it for above
     266                $new_header = preg_replace("/promo\/[^\/]*/", "", $new_header);
     267                $new_header = str_replace("//", "/", $new_header);
     268
     269                if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
     270
     271                $promo = $this->requestStr('promo');
     272
     273                $this->setCookie("rezgo_promo", $promo);
     274                $_SESSION['promo'] = $_REQUEST['promo'];
     275
     276            }
     277
     278            // we need to set the session here before we header the user off or the old session will override the new promo code each time
     279            if(!is_multisite()) {
     280                $_SESSION['promo'] = $promo;
     281            } else {
     282                unset($_SESSION['promo']);
     283            }
     284
     285            if(isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header);
     286        }
     287
     288        // handle the add to cart request if one is set
     289        if($_REQUEST['order'] == 'clear' && is_array($_REQUEST['add'])) {
     290
     291            $cart = $this->createCart();
     292
     293            $this->cart_token = $cart;
     294            $this->setCookie('rezgo_cart_token_'.REZGO_CID, $cart);
     295            $_COOKIE['rezgo_cart_token_'.REZGO_CID] = $cart;
     296
     297            $this->addCart();
     298
     299            $new_header = $_SERVER['REQUEST_URI'];
     300            // remove the order=clear and add information wherever it is
     301            $new_header = preg_replace("/&?order=clear/", "", $new_header);
     302            $new_header = str_replace("?&", "?", $new_header);
     303
     304            $promo = ($_REQUEST['promo']) ? '?promo='.$_REQUEST['promo'] : '';
     305
     306            // remove the promo information wherever it is
     307            $new_header = preg_replace("/&?promo=[^&\/]*/", "", $new_header);
     308            $new_header = str_replace("?&", "?", $new_header);
     309
     310            // replace order with book in URI
     311            $new_header = str_replace("order", "book", $new_header);
     312
     313            // remove the cart information wherever it is
     314            $new_header = preg_replace("/&?add\[[^&\/]*\]=[^&\/]*/", "", $new_header);
     315            $new_header = str_replace("?&", "?", $new_header);
     316
     317            if(substr($new_header, -1) == '?') { $new_header = substr($new_header, 0, -1); }
     318
     319            if(isset($new_header)) $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].$new_header.$cart.$promo);
     320
     321            if ($_REQUEST['promo']) $this->updatePromo($_REQUEST['promo']);
     322
     323            exit;
     324
     325
     326        }
     327
     328        // registering global events, these can be manually changed later with the same methods
     329        $this->setRefId();
     330        // set promo code to what is returned by the cart API
     331        $this->setPromoCode();
     332    }
     333
     334    function config($arg) {
     335        if(!defined($arg)) {
     336            return 0;
     337        } else {
     338            if(constant($arg) == '') { return 0; }
     339            else { return constant($arg); }
     340        }
     341    }
     342
     343    function error($message, $exit=null) {
     344        throw new ErrorException($message);
     345    }
     346
     347    function debug($message, $i=null) {
     348        $stack = debug_backtrace();
     349        $stack = $stack[count($stack)-1]; // get the origin point
     350
     351        $message = urldecode($message);
     352
     353        if($this->config('REZGO_FIREBUG_XML')) {
     354            if(($i == 'commit' || $i == 'commitOrder' || $i == 'add_transaction') && $this->config('REZGO_SWITCH_COMMIT')) {
     355                if($this->config('REZGO_STOP_COMMIT')) {
     356                    echo $_SESSION['error_catch'] = 'STOP::'.$message.'<br><br>';
     357                }
     358            } else {
     359                $_SESSION['debug'][] = addslashes($message);
     360            }
     361        }
     362
     363        if($this->config('REZGO_DISPLAY_XML'))  {
     364            if(($i == 'commit' || $i == 'commitOrder' || $i == 'add_transaction') && $this->config('REZGO_SWITCH_COMMIT')) {
     365                die('STOP::'.$message);
     366            } else {
     367                echo '<textarea rows="2" cols="25">'.$message.'</textarea>';
     368            }
     369        }
     370    }
     371
     372    function setRequestID() {
     373        $this->requestID = $_SESSION['requestID'] = $this->config('REZGO_CID').'-'.time().'-'.$this->randstring(4);
     374        return $this->requestID;
     375    }
     376
     377    function getRequestID() {
     378        return $this->requestID;
     379    }
     380
     381    // generate a random string
     382    function randstring($len = 10) {
     383        $len = $len / 2;
     384
     385        $timestring = microtime();
     386        $secondsSinceEpoch=(integer) substr($timestring, strrpos($timestring, " "), 100);
     387        $microseconds=(double) $timestring;
     388        $seed = mt_rand(0,1000000000) + 10000000 * $microseconds + $secondsSinceEpoch;
     389        mt_srand($seed);
     390        $randstring = "";
     391        for($i=0; $i < $len; $i++) {
     392            $randstring .= mt_rand(0, 9);
     393            $randstring .= chr(ord('A') + mt_rand(0, 24));
     394        }
     395        return($randstring);
     396    }
     397
     398    function secureURL() {
     399        if($this->config('REZGO_FORWARD_SECURE')) {
     400            // forward is set, so we want to direct them to their .rezgo.com domain
     401            $secure_url = $this->getDomain().'.rezgo.com';
     402        } else {
     403            // forward them to this page or our external URL
     404            if($this->config('REZGO_SECURE_URL')) {
     405                $secure_url = $this->config('REZGO_SECURE_URL');
     406            } else {
     407                $secure_url = $_SERVER["HTTP_HOST"];
     408            }
     409        }
     410        return $secure_url;
     411    }
     412
     413    function isVendor() {
     414        $res = (strpos(REZGO_CID, 'p') !== false) ? 1 : 0;
     415        return $res;
     416    }
     417
     418    // clean slashes from the _REQUEST superglobal if escape strings is set in php
     419    function cleanRequest() {
     420        array_walk_recursive($_REQUEST, create_function('&$val', '$val = stripslashes($val);'));
     421    }
     422
     423    // output a fixed number from a request variable
     424    function requestNum($request) {
     425        $r = $_REQUEST[$request];
     426        $r = preg_replace("/[^0-9.]*/", "", $r);
     427        return $r;
     428    }
     429
     430    function requestStr($request) {
     431        $r = $_REQUEST[$request];
     432
     433        $r = strip_tags($r);
     434        $r = preg_replace("/[;<>]*/", "", $r);
     435
     436        return $r;
     437    }
     438
     439    // remove all attributes from a user-entered field
     440    function cleanAttr($request) {
     441        $r = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $request);
     442        $r = strip_tags($r, '<br><strong><p><ul><ol><li><h2><h3><h4>');
     443        return $r;
     444    }
     445
     446    // ------------------------------------------------------------------------------
     447    // read a tour item object into the cache so we can format it later
     448    // ------------------------------------------------------------------------------
     449    function readItem(&$obj) {
     450        $this->obj = $obj;
     451    }
     452
     453    function getItem() {
     454        $obj = $this->obj;
     455        if(!$obj) $this->error('no object found, expecting read object or object argument');
     456        return $obj;
     457    }
     458
     459    // ------------------------------------------------------------------------------
     460    // format a currency response to the standards of this company
     461    // ------------------------------------------------------------------------------
     462    function formatCurrency($num, &$obj=null) {
     463        if(!$obj) $obj = $this->getItem();
     464        return str_replace(" ", "&nbsp;", (($hide) ? '' : $obj->currency_symbol).number_format((float)$num, (int)$obj->currency_decimals, '.', (string)$obj->currency_separator));
     465    }
     466
     467    // ------------------------------------------------------------------------------
     468    // Check if an object has any content in it, for template if statements
     469    // ------------------------------------------------------------------------------
     470    function exists($string) {
     471        $str = (string) $string;
     472        return (strlen(trim($str)) == 0) ? 0 : 1;
     473    }
     474
     475    // ------------------------------------------------------------------------------
     476    // Direct a user to a different page
     477    // ------------------------------------------------------------------------------
     478    function sendTo($path) {
     479        $this->debug('PAGE FORWARDING ( '.$path.' )');
     480        echo '<script>'.REZGO_FRAME_TARGET.'.location.href = "'.$path.'";</script>';
     481        exit;
     482    }
     483
     484    // ------------------------------------------------------------------------------
     485    // Format a string for passing in a URL
     486    // ------------------------------------------------------------------------------
     487    function seoEncode($string) {
     488        $str = trim($string);
     489        $str = str_replace(" ", "-", $str);
     490        $str = preg_replace('/[^A-Za-z0-9\-]/','', $str);
     491        $str = preg_replace('/[\-]+/','-', $str);
     492        if(!$str) $str = urlencode($string);
     493        return strtolower($str);
     494    }
     495
     496    // ------------------------------------------------------------------------------
     497    // Save tour search info
     498    // ------------------------------------------------------------------------------
     499    function saveSearch() {
     500        $search_array = array('pg', 'start_date', 'end_date', 'tags', 'search_in', 'search_for');
     501
     502        foreach($search_array as $v) { if($_REQUEST[$v]) $search[] = $v.'='.rawurlencode($this->requestStr($v)); }
     503
     504        if($search) $search = '?'.implode("&", $search);
     505
     506        if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
     507            setcookie("rezgo_search", $search, strtotime('now +1 week'), str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
     508        } else {
     509            setcookie("rezgo_search", $search, strtotime('now +1 week'), '/', $_SERVER['HTTP_HOST']);
     510        }
     511
     512    }
     513
     514    // ------------------------------------------------------------------------------
     515    // Toggles secure (https) or insecure (http) mode for API queries. Secure mode
     516    // is required when making all commit or modification requests.
     517    // ------------------------------------------------------------------------------
     518    function checkSecure() {
     519        if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
     520            return true;
     521        } else {
     522            return false;
     523        }
     524    }
     525
     526    function setSecureXML($set) {
     527        if($set) { $this->secure = 'https://'; }
     528        else { $this->secure = 'http://'; }
     529    }
     530
     531    function setSecure($set) {
     532        $this->setSecureXML($set);
     533
     534        if($set) {
     535
     536            if($this->config('REZGO_FORWARD_SECURE')) {
     537                // since we are directing to a white label address, clean the request up
     538                if ($_REQUEST['mode'] == 'page_book') {
     539
     540                    $set_refid = $_COOKIE['rezgo_refid_val'] ? '&refid='.$_COOKIE['rezgo_refid_val'] : '';
     541                    $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
     542
     543                    // we are using '?custom_domain' here because it works with the current build for WL
     544                    $request .= '/book/'.$cart_token.'/?custom_domain=1'.$set_refid;
     545                    // $request = '/book?'.$_SERVER['QUERY_STRING'];
     546
     547                } elseif ($_REQUEST['mode'] == 'gift_card') {
     548                    $request = '/gift-card';
     549                }
     550
     551                if (!$_POST['rezgoAction'] == 'add_item'){
     552                    $this->sendTo($this->secure.$this->secureURL().$request);
     553                }
     554            }
     555
     556        } else {
     557            // switch to non-https on the current domain
     558            if($this->checkSecure() && REZGO_ALL_SECURE !== 1) {
     559                if (strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php')===false) {
     560                    $this->sendTo($this->secure.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
     561                }
     562            }
     563        }
     564    }
     565
     566    // ------------------------------------------------------------------------------
     567    // fetch a requested template from the templates directory and load it into a
     568    // variable for display.    If fullpath is set, fetch it from that location instead.
     569    // ------------------------------------------------------------------------------
     570    function getTemplate($req, $fullpath=false) {
     571        reset($GLOBALS);
     572        foreach($GLOBALS as $key => $val) {
     573            if(($key != strstr($key,"HTTP_")) && ($key != strstr($key, "_")) && ($key != 'GLOBALS')) {
     574                global ${$key};
     575            }
     576        }
     577
     578        // wordpress document root includes the install path so we change the path for wordpress installs
     579        if (REZGO_CUSTOM_TEMPLATE_USE) {
     580            $path = WP_CONTENT_DIR.'/rezgo/templates/'.REZGO_TEMPLATE.'/';
     581        } else {
     582            $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
     583            $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
     584            $path .= '/templates/'.REZGO_TEMPLATE.'/';
     585        }
     586
     587        $ext = explode(".", $req);
     588        $ext = (!$ext[1]) ? '.php' : '';
     589
     590        $filename = ($fullpath) ? $req : $path.$req.$ext;
     591
     592        if (is_file($filename)) {
     593            ob_start();
     594            include $filename;
     595            $contents = ob_get_contents();
     596            ob_end_clean();
     597        } else {
     598            $this->error('"'.$req.'" file not found'.(($fullpath) ? '' : ' in "'.$path.'"'));
     599        }
     600
     601        return $contents;
     602    }
     603
     604    // ------------------------------------------------------------------------------
     605    // general request functions for country lists
     606    // ------------------------------------------------------------------------------
     607    function countryName($iso) {
     608        $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
     609        $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
     610
     611        if(!$this->country_list) {
     612            if($this->config('REZGO_COUNTRY_PATH')) {
     613                include(REZGO_COUNTRY_PATH);
     614            } else {
     615                include($path.'/include/countries_list.php');
     616            }
     617            $this->country_list = $countries_list;
     618        }
     619        $iso = (string)$iso;
     620        return ($this->country_list[$iso]) ? ucwords($this->country_list[$iso]) : $iso;
     621    }
     622
     623    function getRegionList($node=null) {
     624        $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
     625        $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
     626
     627        if($this->config('REZGO_COUNTRY_PATH')) {
     628            include(REZGO_COUNTRY_PATH);
     629        } else {
     630            include($path.'/include/countries_list.php');
     631        }
     632
     633        if($node) {
     634            $n = $node.'_state_list';
     635            if($$n) {
     636                return $$n;
     637            } else {
     638                $this->error('"'.$node.'" region node not found');
     639            }
     640        } else {
     641            return $countries_list;
     642        }
     643    }
     644
     645    // ------------------------------------------------------------------------------
     646    // encode scripts for trans numbers
     647    // ------------------------------------------------------------------------------
     648    function encode($enc_text, $iv_len = 16) {
     649        $var = base64_encode($enc_text);
     650        return str_replace("=", "", base64_encode($var.'|'.$var));
     651    }
     652    function decode($enc_text, $iv_len = 16) {
     653        $var = base64_decode($enc_text.'=');
     654        $var = explode("|", $var);
     655        return base64_decode($var[0]);
     656    }
     657
     658    // ------------------------------------------------------------------------------
     659    // encode trans numbers for waivers
     660    // ------------------------------------------------------------------------------
     661    function waiver_encode( $string, $secret='rz|secret' ) {
     662        $key = hash('sha256', 'rz|key');
     663        $iv = substr( hash( 'sha256', $secret ), 0, 16 );
     664        return base64_encode( openssl_encrypt( $string, 'AES-256-CBC', $key, 0, $iv));
     665    }
     666    function waiver_decode( $string, $secret='rz|secret' ) {
     667        $key = hash( 'sha256', 'rz|key' );
     668        $iv = substr( hash( 'sha256', $secret ), 0, 16 );
     669        return openssl_decrypt( base64_decode( $string ), 'AES-256-CBC', $key, 0, $iv );
     670    }
     671
     672    // ------------------------------------------------------------------------------
     673    // Make an API request to Rezgo. $i supports all arguments that the API supports
     674    // for pre-generated queries, or a full query can be passed directly
     675    // ------------------------------------------------------------------------------
     676    function getFile($url, $post='') {
     677        include('fetch.rezgo.php');
     678        return $result;
     679    }
     680
     681    function fetchXML($i, $post='') {
     682
     683        $file = $this->getFile($i, $post);
     684
     685        // attempt to filter out any junk data
     686        $this->get = strstr($file, '<response');
     687
     688        // added extra params for parsing large blocks of xml
     689        libxml_use_internal_errors(true);
     690        $res = $this->xml = simplexml_load_string($this->get, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
     691
     692        $errors = ($res === false) ? libxml_get_errors() : '';
     693
     694        if((!$file || $errors) && strpos($i, 'i=company') === false) {
     695
     696            $error_set = 'Errors: '.var_export($errors, true);
     697
     698            // there has been a fatal error with the API, report the error to the gateway
     699            $this->getFile($i.'&action=report', $post);
     700
     701            $this->error('FATAL ERROR WITH PARSER :: '.$error_set.' :: _GET ('.$i.') _POST ('.html_entity_decode($post).') DATA ('.$file.')');
     702
     703            // send the user to the fatal error page
     704            if(REZGO_FATAL_ERROR_PAGE) {
     705                $this->sendTo(REZGO_FATAL_ERROR_PAGE);
     706            }
     707        }
     708
     709        return $res;
     710    }
     711
     712    function XMLRequest($i, $arguments=null, $advanced=null) {
     713
     714        if($i == 'company') {
     715            if(!$this->company_response[$this->company_index]) {
     716                $arg = ($this->company_index) ? '&q='.$this->company_index : '';
     717                $query = $this->secure.$this->xml_path.'&i=company'.$arg;
     718
     719                if($arguments == 'voucher') {
     720                    $query .= '&a=voucher';
     721                } elseif($arguments == 'ticket') {
     722                    $query .= '&a=ticket';
     723                } elseif($this->config('REZGO_MOBILE_XML')) {
     724                    $query .= '&a=mobile';
     725                }
     726
     727                $xml = $this->fetchXML($query);
     728
     729                if($xml) {
     730                    $this->company_response[$this->company_index] = $xml;
     731                }
     732            }
     733        }
     734        // !i=page
     735        if($i == 'page') {
     736            if(!$this->page_response[$arguments]) {
     737                $query = $this->secure.$this->xml_path.'&i=page&q='.$arguments;
     738
     739                $xml = $this->fetchXML($query);
     740
     741                if($xml) {
     742                    $this->page_response[$arguments] = $xml;
     743                }
     744            }
     745        }
     746        // !i=tags
     747        if($i == 'tags') {
     748            if(!$this->tags_response) {
     749                $query = $this->secure.$this->xml_path.'&i=tags';
     750
     751                $xml = $this->fetchXML($query);
     752
     753                if($xml) {
     754                    if($xml->total > 1) {
     755                        foreach($xml->tag as $v) {
     756                            $this->tags_response[] = $v;
     757                        }
     758                    } else {
     759                        $this->tags_response[] = $xml->tag;
     760                    }
     761                }
     762
     763            }
     764        }
     765        // !i=search
     766        if($i == 'search') {
     767            if(!$this->search_response[$this->tours_index]) {
     768                $query = $this->secure.$this->xml_path.'&i=search&'.$this->tours_index;
     769
     770                if(is_array($this->cart)) $query .= '&cart='.$this->getCartIDs();
     771
     772                $this->setCartToken();
     773                $query .= ($this->cart_token) ? '&cart_token='.$this->cart_token : '';
     774
     775                $xml = $this->fetchXML($query);
     776
     777                $this->search_total = $xml->total;
     778
     779                $c = 0;
     780                if($xml && $xml->total != 0) {
     781                    if($xml->total > 1) {
     782                        foreach($xml->item as $v) {
     783                            // omit packages from WP plugin
     784                            if ((string)$v->availability_type !== 'package'){
     785                                $this->search_response[$this->tours_index][$c] = $v;
     786                                $this->search_response[$this->tours_index][$c++]->index = $this->tours_index;
     787                            }
     788                        }
     789                    } else {
     790                        // omit packages from WP plugin
     791                        if ((string)$xml->item->availability_type !== 'package'){
     792                            $this->search_response[$this->tours_index][$c] = $xml->item;
     793                            $this->search_response[$this->tours_index][$c++]->index = $this->tours_index;
     794                        }
     795                    }
     796                }
     797
     798            }
     799        }
     800        // !i=cart
     801        if($i == 'cart') {
     802            if(!$this->cart_response) {
     803
     804                $query = 'https://'.$this->advanced_xml_path.urlencode('<instruction>cart</instruction><cart>'.$this->getCartIDs().'</cart>'.$arguments.'</request>');
     805
     806                $xml = $this->fetchXML($query);
     807
     808                $this->cart_total = $xml->total;
     809
     810                $c = 0;
     811                if($xml && $xml->total != 0) {
     812                    if($xml->total > 1) {
     813                        foreach($xml->item as $v) {
     814                            $this->cart_response[$c++] = $v;
     815                        }
     816                    } else {
     817                        $this->cart_response[$c++] = $xml->item;
     818                    }
     819                }
     820
     821            }
     822        }
     823        // !i=create_cart
     824        if($i == 'create_cart') {
     825            $query = 'https://'.$this->xml_path;
     826            $post = $this->api_post_string.urlencode($arguments);
     827            $xml = $this->fetchXML($query, $post);
     828            $this->cart_token = $xml->token;
     829        }
     830        // !i=search_cart
     831        if($i == 'search_cart') {
     832
     833            // use the cached result if it is available
     834            if($this->cart_api_response) return;
     835
     836            $query = 'https://'.$this->xml_path;
     837            $post = $this->api_post_string.urlencode($arguments);
     838            $xml = $this->fetchXML($query, $post);
     839
     840            if (!$xml->token) {
     841                $this->setCookie('rezgo_cart_token_'.REZGO_CID, '');
     842            }
     843
     844            $this->cart_total = $xml->total;
     845            $this->cart_trigger_code = $xml->trigger_code;
     846            $this->refid = $xml->refid;
     847
     848            if ($xml->email) $this->lead_passenger_email = $xml->email;
     849            if ($xml->cart->payment->tour_first_name) $this->lead_passenger_first_name = $xml->cart->payment->tour_first_name;
     850            if ($xml->cart->payment->tour_last_name) $this->lead_passenger_last_name = $xml->cart->payment->tour_last_name;
     851
     852            $b = 0;
     853            $c = 0;
     854
     855            if($xml) {
     856                if ($xml->cart){
     857                    // get current <cart> block
     858                    foreach($xml->cart->item as $v) {
     859                        $this->cart_data[$b++] = $v;
     860                    }
     861                }
     862                if ($xml->item){
     863                    foreach($xml->item as $v) {
     864                        $this->cart_api_response[$c++] = $v;
     865                    }
     866                }
     867            }
     868
     869            if ($xml->cart_status) {
     870                $this->cart_status = $xml->cart_status;
     871                $_SESSION['cart_status'] = $xml->cart_status->asXML(); }
     872
     873            // -----------primary forms ----------- //
     874
     875            // get primary forms in <cart> block
     876            if ($xml->cart){
     877                $d = 0;
     878                foreach ($xml->cart->item as $item){
     879                    $cart_pfs[$d] = (object) [];
     880                    $cart_pfs[$d]->primary_forms = $item->primary_forms;
     881                    $d++;
     882                }
     883            }
     884
     885            if ($xml->cart->item->primary_forms) {
     886                $e = 0;
     887                foreach ($xml->item as $item) {
     888                    $item_pfs[$e] = (object) [];
     889                    $item_pfs[$e]->primary_forms = $item->primary_forms;
     890
     891                    for ($f=0; $f < count((is_countable($item->primary_forms->form) ? $item->primary_forms->form : [])); $f++) {
     892                        if ( (($item_pfs[$e]->primary_forms->form[$f]->type == 'checkbox') && ($item_pfs[$e]->primary_forms->form[$f]->price !=0)) ||
     893                            (($item_pfs[$e]->primary_forms->form[$f]->type == 'checkbox_price') && ($item_pfs[$e]->primary_forms->form[$f]->price !=0))
     894                        )
     895                        {
     896
     897                            if ($cart_pfs[$e]->primary_forms->count()) {
     898                                $cart_pfs[$e]->primary_forms->form[$f]->title = $item_pfs[$e]->primary_forms->form[$f]->title;
     899                                $cart_pfs[$e]->primary_forms->form[$f]->price = $item_pfs[$e]->primary_forms->form[$f]->price;
     900                                if ($cart_pfs[$e]->primary_forms->form[$f]->value == 'on') $cart_pf_total += $cart_pfs[$e]->primary_forms->form[$f]->price;
     901                            }
     902                        }
     903
     904                    }
     905                    $e++;
     906                }
     907                if(isset($cart_pf_total)) $this->cart_total += $cart_pf_total;
     908                if(isset($cart_pfs)) $this->form_display = $cart_pfs;
     909            }
     910
     911            // -----------group forms ----------- //
     912
     913            $types = array('adult', 'child', 'senior', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9');
     914
     915            if ($xml->cart){
     916                $f = 0;
     917                foreach ($xml->cart->item as $item){
     918                    $cart_gfs[$f] = (object) [];
     919                    $cart_gfs[$f]->group_forms =  $item->tour_group;
     920                    $f++;
     921                }
     922            }
     923
     924            if ($xml->cart->item->tour_group) {
     925                $g = 0;
     926                foreach ($xml->item as $item){
     927                    $item_gfs[$g] = (object) [];
     928                    $item_gfs[$g]->group_forms = $item->group_forms;
     929
     930                    foreach ($types as $type) {
     931
     932                        if ($cart_gfs[$g]->group_forms->count()) {
     933                            foreach ($cart_gfs[$g]->group_forms->{$type} as $pax) {
     934                                for ($j=0; $j < count((is_countable($pax->forms->form) ? $pax->forms->form : [])); $j++) {
     935
     936                                    $pax->forms->form[$j]->title = $item_gfs[$g]->group_forms->form[$j]->title;
     937                                    $pax->forms->form[$j]->price = $item_gfs[$g]->group_forms->form[$j]->price;
     938
     939                                    $pax_array[$j] = $pax->forms->form[$j];
     940                                    $new_cart_gfs[$g][] = $pax_array[$j];
     941
     942                                    if ($pax_array[$j]->value == 'on') $cart_gf_total += $pax->forms->form[$j]->price;
     943                                }
     944                            }
     945                        }
     946                    }
     947                    $g++;
     948                }
     949                if(isset($cart_gf_total)) $this->cart_total += $cart_gf_total;
     950                if(isset($new_cart_gfs)) $this->gf_form_display = $new_cart_gfs;
     951            }
     952        }
     953        // !i=add_cart
     954        if($i == 'add_cart') {
     955            $query = 'https://'.$this->xml_path;
     956            $post = $this->api_post_string.urlencode($arguments);
     957            $xml = $this->fetchXML($query, $post);
     958
     959            $this->cart_total = $xml->total;
     960            $this->cart_trigger_code = $xml->trigger_code;
     961
     962            $c = 0;
     963            if($xml && $xml->total != 0) {
     964                if($xml->total > 1) {
     965                    foreach($xml->item as $v) {
     966                        $this->cart_api_response[$c++] = $v;
     967                    }
    366968                } else {
    367                     echo '<textarea rows="2" cols="25">'.$message.'</textarea>';
    368                 }
    369             }
    370         }
    371        
    372         function setRequestID() {
    373             $this->requestID = $_SESSION['requestID'] = $this->config('REZGO_CID').'-'.time().'-'.$this->randstring(4);
    374             return $this->requestID;
    375         }
    376        
    377         function getRequestID() {
    378             return $this->requestID;
    379         }
    380        
    381         // generate a random string
    382         function randstring($len = 10) {
    383             $len = $len / 2;
    384            
    385             $timestring = microtime();
    386             $secondsSinceEpoch=(integer) substr($timestring, strrpos($timestring, " "), 100);
    387             $microseconds=(double) $timestring;
    388             $seed = mt_rand(0,1000000000) + 10000000 * $microseconds + $secondsSinceEpoch;
    389             mt_srand($seed);
    390             $randstring = "";
    391             for($i=0; $i < $len; $i++) {
    392                 $randstring .= mt_rand(0, 9);
    393                 $randstring .= chr(ord('A') + mt_rand(0, 24));
    394             }
    395             return($randstring);
    396         }
    397        
    398         function secureURL() {
    399             if($this->config('REZGO_FORWARD_SECURE')) {
    400                 // forward is set, so we want to direct them to their .rezgo.com domain
    401                 $secure_url = $this->getDomain().'.rezgo.com';
    402             } else {
    403                 // forward them to this page or our external URL
    404                 if($this->config('REZGO_SECURE_URL')) {
    405                     $secure_url = $this->config('REZGO_SECURE_URL');
    406                 } else {
    407                     $secure_url = $_SERVER["HTTP_HOST"];
    408                 }   
    409             }
    410             return $secure_url;
    411         }
    412        
    413         function isVendor() {
    414             $res = (strpos(REZGO_CID, 'p') !== false) ? 1 : 0;
    415             return $res;
    416         }
    417        
    418         // clean slashes from the _REQUEST superglobal if escape strings is set in php
    419         function cleanRequest() {
    420             array_walk_recursive($_REQUEST, create_function('&$val', '$val = stripslashes($val);'));
    421         }
    422        
    423         // output a fixed number from a request variable
    424         function requestNum($request) {
    425             $r = $_REQUEST[$request];
    426             $r = preg_replace("/[^0-9.]*/", "", $r);
    427             return $r;
    428         }
    429        
    430         function requestStr($request) {
    431             $r = $_REQUEST[$request];
    432            
    433             $r = strip_tags($r);
    434             $r = preg_replace("/[;<>]*/", "", $r);
    435            
    436             return $r;
    437         }
    438        
    439         // remove all attributes from a user-entered field
    440         function cleanAttr($request) {
    441             $r = preg_replace("/<([a-z][a-z0-9]*)[^>]*?(\/?)>/i",'<$1$2>', $request);
    442             $r = strip_tags($r, '<br><strong><p><ul><ol><li><h2><h3><h4>');
    443             return $r;
    444         }
    445        
    446         // ------------------------------------------------------------------------------
    447         // read a tour item object into the cache so we can format it later
    448         // ------------------------------------------------------------------------------
    449         function readItem(&$obj) {
    450             $this->obj = $obj;
    451         }
    452        
    453         function getItem() {
    454             $obj = $this->obj;
    455             if(!$obj) $this->error('no object found, expecting read object or object argument');
    456             return $obj;
    457         }
    458        
    459         // ------------------------------------------------------------------------------
    460         // format a currency response to the standards of this company
    461         // ------------------------------------------------------------------------------
    462         function formatCurrency($num, &$obj=null) {
    463             if(!$obj) $obj = $this->getItem();
    464             return str_replace(" ", "&nbsp;", (($hide) ? '' : $obj->currency_symbol).number_format((float)$num, (int)$obj->currency_decimals, '.', (string)$obj->currency_separator));
    465         }
    466        
    467         // ------------------------------------------------------------------------------
    468         // Check if an object has any content in it, for template if statements
    469         // ------------------------------------------------------------------------------
    470         function exists($string) {
    471             $str = (string) $string;
    472             return (strlen(trim($str)) == 0) ? 0 : 1;   
    473         }
    474        
    475         // ------------------------------------------------------------------------------
    476         // Direct a user to a different page
    477         // ------------------------------------------------------------------------------
    478         function sendTo($path) {
    479             $this->debug('PAGE FORWARDING ( '.$path.' )');
    480             echo '<script>'.REZGO_FRAME_TARGET.'.location.href = "'.$path.'";</script>';
    481             exit;
    482         }
    483        
    484         // ------------------------------------------------------------------------------
    485         // Format a string for passing in a URL
    486         // ------------------------------------------------------------------------------
    487         function seoEncode($string) {
    488             $str = trim($string);
    489             $str = str_replace(" ", "-", $str);
    490             $str = preg_replace('/[^A-Za-z0-9\-]/','', $str);
    491             $str = preg_replace('/[\-]+/','-', $str);
    492             if(!$str) $str = urlencode($string);
    493             return strtolower($str);   
    494         }
    495        
    496         // ------------------------------------------------------------------------------
    497         // Save tour search info
    498         // ------------------------------------------------------------------------------
    499         function saveSearch() {
    500             $search_array = array('pg', 'start_date', 'end_date', 'tags', 'search_in', 'search_for');
    501            
    502             foreach($search_array as $v) { if($_REQUEST[$v]) $search[] = $v.'='.rawurlencode($this->requestStr($v)); }
    503            
    504             if($search) $search = '?'.implode("&", $search);
    505            
    506             if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
    507                 setcookie("rezgo_search", $search, strtotime('now +1 week'), str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['HTTP_HOST']);
    508             } else {
    509                 setcookie("rezgo_search", $search, strtotime('now +1 week'), '/', $_SERVER['HTTP_HOST']);
    510             }
    511            
    512         }
    513        
    514         // ------------------------------------------------------------------------------
    515         // Toggles secure (https) or insecure (http) mode for API queries. Secure mode
    516         // is required when making all commit or modification requests.
    517         // ------------------------------------------------------------------------------       
    518         function checkSecure() {
    519             if((!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || $_SERVER['SERVER_PORT'] == 443 || $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
    520                 return true;
    521             } else {
    522                 return false;
    523             }
    524         }
    525        
    526         function setSecureXML($set) {
    527             if($set) { $this->secure = 'https://'; }
    528             else { $this->secure = 'http://'; }
    529         }
    530        
    531         function setSecure($set) {
    532             $this->setSecureXML($set);
    533 
    534             if($set) {
    535 
    536                 if($this->config('REZGO_FORWARD_SECURE')) {
    537                     // since we are directing to a white label address, clean the request up
    538                     if ($_REQUEST['mode'] == 'page_book') {
    539 
    540                         $set_refid = $_COOKIE['rezgo_refid_val'] ? '&refid='.$_COOKIE['rezgo_refid_val'] : '';
    541                         $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
    542 
    543                         // we are using '?custom_domain' here because it works with the current build for WL
    544                         $request .= '/book/'.$cart_token.'/?custom_domain=1'.$set_refid;
    545                         // $request = '/book?'.$_SERVER['QUERY_STRING'];
    546 
    547                     } elseif ($_REQUEST['mode'] == 'gift_card') {
    548                         $request = '/gift-card';
    549                     }
    550 
    551                     if (!$_POST['rezgoAction'] == 'add_item'){
    552                         $this->sendTo($this->secure.$this->secureURL().$request);
    553                     }
    554                 }
    555 
    556             } else {
    557                 // switch to non-https on the current domain
    558                 if($this->checkSecure() && REZGO_ALL_SECURE !== 1) {
    559                     if (strpos( $_SERVER['REQUEST_URI'], 'admin-ajax.php')===false) {
    560                         $this->sendTo($this->secure.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
    561                     }
    562                 }
    563             }
    564         }
    565        
    566         // ------------------------------------------------------------------------------
    567         // fetch a requested template from the templates directory and load it into a
    568         // variable for display.    If fullpath is set, fetch it from that location instead.
    569         // ------------------------------------------------------------------------------
    570         function getTemplate($req, $fullpath=false) {
    571             reset($GLOBALS);
    572             foreach($GLOBALS as $key => $val) {
    573                 if(($key != strstr($key,"HTTP_")) && ($key != strstr($key, "_")) && ($key != 'GLOBALS')) {
    574                     global ${$key};
    575                 }
    576             }
    577 
    578             // wordpress document root includes the install path so we change the path for wordpress installs
    579             if (REZGO_CUSTOM_TEMPLATE_USE) {
    580                 $path = WP_CONTENT_DIR.'/rezgo/templates/'.REZGO_TEMPLATE.'/';
    581             } else {
    582                 $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
    583                 $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
    584                 $path .= '/templates/'.REZGO_TEMPLATE.'/';             
    585             }
    586            
    587             $ext = explode(".", $req);
    588             $ext = (!$ext[1]) ? '.php' : '';
    589            
    590             $filename = ($fullpath) ? $req : $path.$req.$ext;
    591 
    592             if (is_file($filename)) {
    593                 ob_start();
    594                 include $filename;
    595                 $contents = ob_get_contents();
    596                 ob_end_clean();
    597             } else {
    598                 $this->error('"'.$req.'" file not found'.(($fullpath) ? '' : ' in "'.$path.'"'));
    599             }
    600 
    601             return $contents;
    602         }
    603        
    604         // ------------------------------------------------------------------------------
    605         // general request functions for country lists
    606         // ------------------------------------------------------------------------------
    607         function countryName($iso) {
    608             $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
    609             $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
    610            
    611             if(!$this->country_list) {
    612                 if($this->config('REZGO_COUNTRY_PATH')) {
    613                     include(REZGO_COUNTRY_PATH);
    614                 } else {
    615                     include($path.'/include/countries_list.php');   
    616                 }
    617                 $this->country_list = $countries_list;
    618             }
    619             $iso = (string)$iso;
    620             return ($this->country_list[$iso]) ? ucwords($this->country_list[$iso]) : $iso;
    621         }
    622        
    623         function getRegionList($node=null) {
    624             $abspath =  (strpos(ABSPATH, 'wordpress/core')) ?  REZGO_DIR : REZGO_DOCUMENT_ROOT.REZGO_DIR;
    625             $path = ($this->config('REZGO_USE_ABSOLUTE_PATH')) ? REZGO_DOCUMENT_ROOT : $abspath;
    626        
    627             if($this->config('REZGO_COUNTRY_PATH')) {
    628                 include(REZGO_COUNTRY_PATH);
    629             } else {
    630                 include($path.'/include/countries_list.php');   
    631             }
    632            
    633             if($node) {
    634                 $n = $node.'_state_list';
    635                 if($$n) {
    636                     return $$n;
    637                 } else {
    638                     $this->error('"'.$node.'" region node not found');
    639                 }
    640             } else {
    641                 return $countries_list;
    642             }
    643         }
    644        
    645         // ------------------------------------------------------------------------------
    646         // encode scripts for trans numbers
    647         // ------------------------------------------------------------------------------
    648         function encode($enc_text, $iv_len = 16) {
    649             $var = base64_encode($enc_text);
    650             return str_replace("=", "", base64_encode($var.'|'.$var));
    651         }
    652         function decode($enc_text, $iv_len = 16) {
    653             $var = base64_decode($enc_text.'=');
    654             $var = explode("|", $var);
    655             return base64_decode($var[0]);
    656         }
    657  
    658         // ------------------------------------------------------------------------------
    659         // encode trans numbers for waivers
    660         // ------------------------------------------------------------------------------
    661         function waiver_encode( $string, $secret='rz|secret' ) {
    662             $key = hash('sha256', 'rz|key');
    663             $iv = substr( hash( 'sha256', $secret ), 0, 16 );
    664             return base64_encode( openssl_encrypt( $string, 'AES-256-CBC', $key, 0, $iv));
    665         }
    666         function waiver_decode( $string, $secret='rz|secret' ) {
    667             $key = hash( 'sha256', 'rz|key' );
    668             $iv = substr( hash( 'sha256', $secret ), 0, 16 );
    669             return openssl_decrypt( base64_decode( $string ), 'AES-256-CBC', $key, 0, $iv );
    670         }
    671        
    672         // ------------------------------------------------------------------------------
    673         // Make an API request to Rezgo. $i supports all arguments that the API supports
    674         // for pre-generated queries, or a full query can be passed directly
    675         // ------------------------------------------------------------------------------
    676         function getFile($url, $post='') {
    677             include('fetch.rezgo.php');
    678             return $result;
    679         }
    680        
    681         function fetchXML($i, $post='') {
    682            
    683             $file = $this->getFile($i, $post);
    684            
    685             // attempt to filter out any junk data
    686             $this->get = strstr($file, '<response');
    687 
    688             // added extra params for parsing large blocks of xml
    689             libxml_use_internal_errors(true);
    690             $res = $this->xml = simplexml_load_string($this->get, 'SimpleXMLElement', LIBXML_COMPACT | LIBXML_PARSEHUGE);
    691            
    692             $errors = ($res === false) ? libxml_get_errors() : '';
    693            
    694             if((!$file || $errors) && strpos($i, 'i=company') === false) {
    695                
    696                 $error_set = 'Errors: '.var_export($errors, true);
    697                
    698                 // there has been a fatal error with the API, report the error to the gateway
    699                 $this->getFile($i.'&action=report', $post);
    700                
    701                 $this->error('FATAL ERROR WITH PARSER :: '.$error_set.' :: _GET ('.$i.') _POST ('.html_entity_decode($post).') DATA ('.$file.')');
    702                
    703                 // send the user to the fatal error page
    704                 if(REZGO_FATAL_ERROR_PAGE) {
    705                     $this->sendTo(REZGO_FATAL_ERROR_PAGE);
    706                 }
    707             }
    708            
    709             return $res;
    710         }
    711        
    712         function XMLRequest($i, $arguments=null, $advanced=null) {
    713            
    714             if($i == 'company') {
    715                 if(!$this->company_response[$this->company_index]) {   
    716                     $arg = ($this->company_index) ? '&q='.$this->company_index : '';
    717                     $query = $this->secure.$this->xml_path.'&i=company'.$arg;
    718                    
    719                     if($arguments == 'voucher') {
    720                         $query .= '&a=voucher';
    721                     } elseif($arguments == 'ticket') {
    722                         $query .= '&a=ticket';
    723                     } elseif($this->config('REZGO_MOBILE_XML')) {
    724                         $query .= '&a=mobile';
    725                     }
    726                    
    727                     $xml = $this->fetchXML($query);
    728                    
    729                     if($xml) {
    730                         $this->company_response[$this->company_index] = $xml;   
    731                     }
    732                 }
    733             }
    734             // !i=page
    735             if($i == 'page') {
    736                 if(!$this->page_response[$arguments]) {
    737                     $query = $this->secure.$this->xml_path.'&i=page&q='.$arguments;
    738                    
    739                     $xml = $this->fetchXML($query);
    740                    
    741                     if($xml) {
    742                         $this->page_response[$arguments] = $xml;
    743                     }   
    744                 }           
    745             }
    746             // !i=tags
    747             if($i == 'tags') {
    748                 if(!$this->tags_response) {
    749                     $query = $this->secure.$this->xml_path.'&i=tags';
    750                
    751                     $xml = $this->fetchXML($query);
    752                    
    753                     if($xml) {
    754                         if($xml->total > 1) {
    755                             foreach($xml->tag as $v) {
    756                                 $this->tags_response[] = $v;
    757                             }
    758                         } else {
    759                             $this->tags_response[] = $xml->tag;
    760                         }   
    761                     }
    762                    
    763                 }
    764             }   
    765             // !i=search
    766             if($i == 'search') {       
    767                 if(!$this->search_response[$this->tours_index]) {
    768                     $query = $this->secure.$this->xml_path.'&i=search&'.$this->tours_index;
    769 
    770                     if(is_array($this->cart)) $query .= '&cart='.$this->getCartIDs();
    771 
    772                     $this->setCartToken();
    773                     $query .= ($this->cart_token) ? '&cart_token='.$this->cart_token : '';
    774                    
    775                     $xml = $this->fetchXML($query);
    776                    
    777                     $this->search_total = $xml->total;
    778                    
    779                     $c = 0;
    780                     if($xml && $xml->total != 0) {
    781                         if($xml->total > 1) {
    782                             foreach($xml->item as $v) {
    783                                 // omit packages from WP plugin
    784                                 if ((string)$v->availability_type !== 'package'){
    785                                     $this->search_response[$this->tours_index][$c] = $v;
    786                                     $this->search_response[$this->tours_index][$c++]->index = $this->tours_index;
    787                                 }
    788                             }
    789                         } else {
    790                             // omit packages from WP plugin
    791                             if ((string)$xml->item->availability_type !== 'package'){
    792                                 $this->search_response[$this->tours_index][$c] = $xml->item;
    793                                 $this->search_response[$this->tours_index][$c++]->index = $this->tours_index;
    794                             }
    795                         }   
    796                     }
    797                
    798                 }
    799             }
    800             // !i=cart
    801             if($i == 'cart') {     
    802                 if(!$this->cart_response) {
    803                    
    804                     $query = 'https://'.$this->advanced_xml_path.urlencode('<instruction>cart</instruction><cart>'.$this->getCartIDs().'</cart>'.$arguments.'</request>');
    805                    
    806                     $xml = $this->fetchXML($query);
    807                    
    808                     $this->cart_total = $xml->total;
    809                    
    810                     $c = 0;
    811                     if($xml && $xml->total != 0) {
    812                         if($xml->total > 1) {
    813                             foreach($xml->item as $v) {
    814                                 $this->cart_response[$c++] = $v;
    815                             }
    816                         } else {
    817                             $this->cart_response[$c++] = $xml->item;
    818                         }
    819                     }
    820                
    821                 }
    822             }
    823             // !i=create_cart
    824             if($i == 'create_cart') {
    825                 $query = 'https://'.$this->xml_path;
    826                 $post = $this->api_post_string.urlencode($arguments);
    827                 $xml = $this->fetchXML($query, $post);
     969                    $this->cart_api_response[$c++] = $xml->item;
     970                }
     971            }
     972
     973            // don't return error on invalid promo code on add, this causes FE to stop redirecting
     974            if ($xml->cart_status->error_code != 9) $this->cart_status = $xml->cart_status;
     975
     976            if (!$this->cart_token) {
    828977                $this->cart_token = $xml->token;
    829             }
    830             // !i=search_cart
    831             if($i == 'search_cart') {
    832        
    833                 // use the cached result if it is available
    834                 if($this->cart_api_response) return;
    835                
    836                 $query = 'https://'.$this->xml_path;
    837                 $post = $this->api_post_string.urlencode($arguments);
    838                 $xml = $this->fetchXML($query, $post);
    839 
    840                 if (!$xml->token) {
    841                     $this->setCookie('rezgo_cart_token_'.REZGO_CID, '');
    842                 }
    843 
    844                 $this->cart_total = $xml->total;
    845                 $this->cart_trigger_code = $xml->trigger_code;
    846                 $this->refid = $xml->refid;
    847 
    848                 if ($xml->email) $this->lead_passenger_email = $xml->email;
    849                 if ($xml->cart->payment->tour_first_name) $this->lead_passenger_first_name = $xml->cart->payment->tour_first_name;
    850                 if ($xml->cart->payment->tour_last_name) $this->lead_passenger_last_name = $xml->cart->payment->tour_last_name;
    851 
    852                 $b = 0;
    853                 $c = 0;
    854                 if($xml) {
    855                     // get current <cart> block
    856                     foreach($xml->cart->item as $v) {
    857                         $this->cart_data[$b++] = $v;
    858                     }
    859                     foreach($xml->item as $v) {
    860                         $this->cart_api_response[$c++] = $v;
    861                     }
    862                 }
    863 
    864                 if ($xml->cart_status) {
    865                     $this->cart_status = $xml->cart_status;
    866                     $_SESSION['cart_status'] = $xml->cart_status->asXML(); }
    867 
    868                 // -----------primary forms ----------- //
    869 
    870                 // get primary forms in <cart> block
    871                 $d = 0;
    872 
    873                 foreach ($xml->cart->item as $item){
    874                     $cart_pfs[$d] = (object) [];
    875                     $cart_pfs[$d]->primary_forms = $item->primary_forms;
    876                     $d++;
    877                 }
    878 
    879                 if ($xml->cart->item->primary_forms) {
    880                     $e = 0;
    881                     foreach ($xml->item as $item) {
    882                         $item_pfs[$e] = (object) [];
    883                         $item_pfs[$e]->primary_forms = $item->primary_forms;
    884 
    885                         for ($f=0; $f < count((is_countable($item->primary_forms->form) ? $item->primary_forms->form : [])); $f++) {
    886                             if ( (($item_pfs[$e]->primary_forms->form[$f]->type == 'checkbox') && ($item_pfs[$e]->primary_forms->form[$f]->price !=0)) ||
    887                                 (($item_pfs[$e]->primary_forms->form[$f]->type == 'checkbox_price') && ($item_pfs[$e]->primary_forms->form[$f]->price !=0))
    888                                 )
    889                             {
    890 
    891                                 if ($cart_pfs[$e]->primary_forms->count()) {
    892                                     $cart_pfs[$e]->primary_forms->form[$f]->title = $item_pfs[$e]->primary_forms->form[$f]->title;
    893                                     $cart_pfs[$e]->primary_forms->form[$f]->price = $item_pfs[$e]->primary_forms->form[$f]->price;
    894                                     if ($cart_pfs[$e]->primary_forms->form[$f]->value == 'on') $cart_pf_total += $cart_pfs[$e]->primary_forms->form[$f]->price;
    895                                 }
    896                             }
    897 
    898                         }
    899                         $e++;
    900                     }
    901                     if(isset($cart_pf_total)) $this->cart_total += $cart_pf_total;
    902                     if(isset($cart_pfs)) $this->form_display = $cart_pfs;
    903                 }
    904 
    905                 // -----------group forms ----------- //
    906 
    907                 $types = array('adult', 'child', 'senior', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9');
    908 
    909                 $f = 0;
    910                 foreach ($xml->cart->item as $item){
    911                     $cart_gfs[$f] = (object) [];
    912                     $cart_gfs[$f]->group_forms =  $item->tour_group;
    913                     $f++;
    914                 }
    915 
    916                 if ($xml->cart->item->tour_group) {
    917                     $g = 0;
    918                     foreach ($xml->item as $item){
    919                         $item_gfs[$g] = (object) [];
    920                         $item_gfs[$g]->group_forms = $item->group_forms;
    921 
    922                         foreach ($types as $type) {
    923 
    924                             if ($cart_gfs[$g]->group_forms->count()) {
    925                                 foreach ($cart_gfs[$g]->group_forms->{$type} as $pax) {
    926                                     for ($j=0; $j < count((is_countable($pax->forms->form) ? $pax->forms->form : [])); $j++) {
    927 
    928                                         $pax->forms->form[$j]->title = $item_gfs[$g]->group_forms->form[$j]->title;
    929                                         $pax->forms->form[$j]->price = $item_gfs[$g]->group_forms->form[$j]->price;
    930 
    931                                         $pax_array[$j] = $pax->forms->form[$j];
    932                                         $new_cart_gfs[$g][] = $pax_array[$j];
    933 
    934                                         if ($pax_array[$j]->value == 'on') $cart_gf_total += $pax->forms->form[$j]->price;
    935                                     }
    936                                 }
    937                             }
    938                         }
    939                         $g++;
    940                     }
    941                     if(isset($cart_gf_total)) $this->cart_total += $cart_gf_total;
    942                     if(isset($new_cart_gfs)) $this->gf_form_display = $new_cart_gfs;
    943                 }
    944             }
    945             // !i=add_cart
    946             if($i == 'add_cart') {     
    947                 $query = 'https://'.$this->xml_path;
    948                 $post = $this->api_post_string.urlencode($arguments);
    949                 $xml = $this->fetchXML($query, $post);
    950 
    951                 $this->cart_total = $xml->total;
    952                 $this->cart_trigger_code = $xml->trigger_code;
    953 
    954                 $c = 0;
    955                 if($xml && $xml->total != 0) { 
    956                     if($xml->total > 1) {
    957                         foreach($xml->item as $v) {
    958                             $this->cart_api_response[$c++] = $v;
    959                         }
    960                     } else {
    961                         $this->cart_api_response[$c++] = $xml->item;
    962                     }
    963                 }
    964 
    965                 // don't return error on invalid promo code on add, this causes FE to stop redirecting
    966                 if ($xml->cart_status->error_code != 9) $this->cart_status = $xml->cart_status;
    967 
    968                 if (!$this->cart_token) {
    969                     $this->cart_token = $xml->token;
    970                     $this->setCookie('rezgo_cart_token_'.REZGO_CID, $this->cart_token);
    971                 }
    972 
    973             }
    974             // !i=update_cart
    975             if($i == 'update_cart') {   
    976                 $query = 'https://'.$this->xml_path;
    977                 $post = $this->api_post_string.urlencode($arguments);
    978                 $xml = $this->fetchXML($query, $post);
    979 
    980                 $this->cart_total = $xml->total;
    981                 $this->cart_trigger_code = $xml->trigger_code;
    982 
    983                 if ($xml->email) $this->lead_passenger_email = $xml->email;
    984                 if ($xml->cart->payment->tour_first_name) $this->lead_passenger_first_name = $xml->cart->payment->tour_first_name;
    985                 if ($xml->cart->payment->tour_last_name) $this->lead_passenger_last_name = $xml->cart->payment->tour_last_name;
    986 
    987                 if ($xml->cart_status) {
    988                     $this->cart_status = $xml->cart_status;
    989                     $_SESSION['cart_status'] = $xml->cart_status->asXML(); }
    990             }
    991             // !i=remove_cart
    992             if($i == 'remove_cart') {       
    993                 $query = 'https://'.$this->xml_path;
    994                 $post = $this->api_post_string.urlencode($arguments);
    995                 $xml = $this->fetchXML($query, $post);
    996             }
    997             // !i=destroy_cart
    998             if($i == 'destroy_cart') {     
    999                 $query = 'https://'.$this->xml_path;
    1000                 $post = $this->api_post_string.urlencode($arguments);
    1001             }
    1002             // !i=search_bookings
    1003             if($i == 'search_bookings') {
    1004                 if(!$this->search_bookings_response[$this->bookings_index]) {
    1005                     $query = $this->secure.$this->xml_path.'&i=search_bookings&'.$this->bookings_index;
    1006                     $xml = $this->fetchXML($query);
    1007                    
    1008                     $c = 0;
    1009                     if($xml && $xml->total != 0) {
    1010                         if($xml->total > 1) {
    1011                             foreach($xml->booking as $v) {
    1012                                 $this->search_bookings_response[$this->bookings_index][$c] = $v;
    1013                                 $this->search_bookings_response[$this->bookings_index][$c++]->index = $this->bookings_index;
    1014                             }
    1015                         } else {
    1016                             $this->search_bookings_response[$this->bookings_index][$c] = $xml->booking;
    1017                             $this->search_bookings_response[$this->bookings_index][$c++]->index = $this->bookings_index;
    1018                         }   
    1019                     }
    1020                
    1021                 }
    1022             }
    1023             // !i=public
    1024             if($i == 'public') {
    1025                 $query = $this->secure.$this->xml_path.'&i=public&amount='.$arguments;
     978                $this->setCookie('rezgo_cart_token_'.REZGO_CID, $this->cart_token);
     979            }
     980
     981        }
     982        // !i=update_cart
     983        if($i == 'update_cart') {
     984            $query = 'https://'.$this->xml_path;
     985            $post = $this->api_post_string.urlencode($arguments);
     986            $xml = $this->fetchXML($query, $post);
     987
     988            $this->cart_total = $xml->total;
     989            $this->cart_trigger_code = $xml->trigger_code;
     990
     991            if ($xml->email) $this->lead_passenger_email = $xml->email;
     992            if ($xml->cart->payment->tour_first_name) $this->lead_passenger_first_name = $xml->cart->payment->tour_first_name;
     993            if ($xml->cart->payment->tour_last_name) $this->lead_passenger_last_name = $xml->cart->payment->tour_last_name;
     994
     995            if ($xml->cart_status) {
     996                $this->cart_status = $xml->cart_status;
     997                $_SESSION['cart_status'] = $xml->cart_status->asXML(); }
     998        }
     999        // !i=remove_cart
     1000        if($i == 'remove_cart') {
     1001            $query = 'https://'.$this->xml_path;
     1002            $post = $this->api_post_string.urlencode($arguments);
     1003            $xml = $this->fetchXML($query, $post);
     1004        }
     1005        // !i=destroy_cart
     1006        if($i == 'destroy_cart') {
     1007            $query = 'https://'.$this->xml_path;
     1008            $post = $this->api_post_string.urlencode($arguments);
     1009        }
     1010        // !i=search_bookings
     1011        if($i == 'search_bookings') {
     1012            if(!$this->search_bookings_response[$this->bookings_index]) {
     1013                $query = $this->secure.$this->xml_path.'&i=search_bookings&'.$this->bookings_index;
    10261014                $xml = $this->fetchXML($query);
    1027                 $this->public_response = (array) $xml->data;
    1028             }
    1029             // !i=commit
    1030             if($i == 'commit') {
    1031                 $query = 'https://'.$this->xml_path.'&i=commit&cart='.$this->getCartIDs().'&'.$arguments;
    1032                
    1033                 $xml = $this->fetchXML($query);
    1034                
    1035                 if($xml) {
    1036                     $this->commit_response = new stdClass();
    1037                     foreach($xml as $k => $v) {
    1038                         $this->commit_response->$k = trim((string)$v); 
    1039                     }
    1040                 }
    1041             }
    1042             // !new commit mode
    1043             if($i == 'commitOrder') {
    1044                 $query = 'https://'.$this->xml_path;
    1045                
    1046                 $post = $this->api_post_string.urlencode('<instruction>commit</instruction><cart>'.$this->getCartIDs().'</cart>'.$arguments.'</request>');
    1047 
    1048                 $xml = $this->fetchXML($query, $post);
    1049                
    1050                 if($xml) {
    1051                     $this->commit_response = new stdClass();
    1052                     foreach($xml as $k => $v) {
    1053                         $this->commit_response->$k = trim((string)$v);
    1054                     }
    1055                 }
    1056             }
    1057             // !i=add gift card
    1058             if($i == 'addGiftCard') {
    1059                 $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
    1060 
    1061                 $query = 'https://'.$this->xml_path;
    1062 
    1063                 $post = $this->api_post_string.urlencode('<instruction>add_card</instruction>'.$arguments.'</request>');
    1064 
    1065                 $xml = $this->fetchXML($query, $post);
    1066                
    1067                 if($xml) {
    1068                     $this->commit_response = new stdClass();
    1069 
    1070                     foreach ($xml as $k => $v) {
    1071                         $this->commit_response->$k = trim((string)$v); 
    1072                     }
    1073                 }
    1074             }
    1075             // !i=search gift card
    1076             if($i == 'searchGiftCard') {
    1077                 $query = $this->secure.$this->xml_path.'&i=cards&q='.$arguments;
    1078                 $res = $this->fetchXML($query);
    1079                 $this->gift_card = $res;
    1080             }
    1081             // !i=contact
    1082             if($i == 'contact') {
    1083                 $query = 'https://'.$this->xml_path.'&i=contact&'.$arguments;
    1084            
    1085                 $xml = $this->fetchXML($query);
    1086                
    1087                 if($xml) {
    1088                     $this->contact_response = new stdClass();
    1089                     foreach($xml as $k => $v) {
    1090                         $this->contact_response->$k = trim((string)$v);
    1091                     }
    1092                 }
    1093             }
    1094             // !i=tickets
    1095             if($i == 'tickets') {
    1096                 if(!$this->ticket_response[$arguments]) {
    1097                     $query = $this->secure.$this->xml_path.'&i=tickets&q='.$arguments;
    1098                    
    1099                     $xml = $this->fetchXML($query);
    1100                    
    1101                     if($xml) {
    1102                         $this->ticket_response[$arguments] = $xml;
    1103                     }   
    1104                 }           
    1105             }   
    1106             // !i=waiver
    1107             if($i == 'waiver') {
    1108                 if(!$this->waiver_response[$arguments]) {
    1109                    
    1110                     if ($advanced == 'com') $target = '&t=com';
    1111                    
    1112                     $query = $this->secure.$this->xml_path.'&i=waiver&q='.$arguments.$target;
    1113                    
    1114                     $xml = $this->fetchXML($query);
    1115                    
    1116                     if($xml) {
    1117                         $this->waiver_response[$arguments] = $xml;
    1118                     }   
    1119                 }           
    1120             }   
    1121             // !i=sign
    1122             if($i == 'sign') {
    1123                 $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
    1124 
    1125                 $query = 'https://'.$this->xml_path;
    1126 
    1127                 $post = $this->api_post_string.urlencode('<instruction>sign</instruction>'.$arguments.'</request>');
    1128 
    1129                 $xml = $this->fetchXML($query, $post);
    1130                
    1131                 if($xml) {
    1132                     $this->signing_response = new stdClass();
    1133 
    1134                     foreach ($xml as $k => $v) {
    1135                         $this->signing_response->$k = trim((string)$v);
    1136                     }
    1137                 }
    1138             }   
    1139             // !i=review
    1140             if($i == 'review') {
    1141                 $query = 'https://'.$this->xml_path.'&i=review&'.$arguments;
    1142            
    1143                 $xml = $this->fetchXML($query);
    1144                
    1145                 if($xml) {
    1146                     $this->review_response = new stdClass();
    1147                     $this->review_response = $xml;
    1148                 }
    1149             }   
    1150             // !i=add_review
    1151             if($i == 'add_review') {
    1152                 //$query = 'https://'.$this->xml_path.'&i=add_review&'.$arguments;
    1153                 $query = 'https://'.$this->xml_path;
    1154 
    1155                 $post = $this->api_post_string.urlencode('<instruction>add_review</instruction>'.$arguments.'</request>');
    1156            
    1157                 $xml = $this->fetchXML($query, $post);
    1158                
    1159                 if($xml) {
    1160                     $this->review_response = new stdClass();
    1161                     foreach($xml as $k => $v) {
    1162                         $this->review_response->$k = trim((string)$v); 
    1163                     }
    1164                 }
    1165             }
    1166             // !i=pickup
    1167             if($i == 'pickup') {
    1168                 $query = 'https://'.$this->xml_path.'&i=pickup&'.$arguments;
    1169            
    1170                 $xml = $this->fetchXML($query);
    1171                
    1172                 if($xml) {
    1173                     $this->pickup_response = new stdClass();
    1174                     $this->pickup_response = $xml;
    1175                 }
    1176             }   
    1177            
    1178             // !i=add_transaction
    1179             if($i == 'add_transaction') {
    1180 
    1181                 $query = 'https://'.$this->xml_path;
    1182 
    1183                 $post = $this->api_post_string.urlencode('<instruction>add_transaction</instruction>'.$arguments.'</request>');
    1184 
    1185                 $xml = $this->fetchXML($query, $post);
    1186                
    1187                 if($xml) {
    1188                     $this->commit_response = new stdClass();
    1189 
    1190                     foreach ($xml as $k => $v) {
    1191                         $this->commit_response->$k = trim((string)$v); 
    1192                     }
    1193                 }
    1194             }
    1195             // !i=payment
    1196             if($i == 'payment') {
    1197                 $query = 'https://'.$this->xml_path.'&i=payment&'.$arguments;
    1198            
    1199                 $xml = $this->fetchXML($query);
    1200                
    1201                 if($xml) {
    1202                     $this->payment_response = new stdClass();
    1203                     $this->payment_response = $xml;
    1204                 }
    1205             }   
    1206            
    1207             if(REZGO_TRACE_XML) {
    1208                 if(!$query && REZGO_INCLUDE_CACHE_XML) $query = 'called cached response';
    1209                 if($query) {
    1210                     $message = $i.' ( '.$query.(($post) ? '&'.$post : '').' )';
    1211                     $this->debug('XML REQUEST: '.$message, $i); // pass the $i as well so we can freeze on commit
    1212                 }
    1213             }
    1214         }
    1215        
    1216         // ------------------------------------------------------------------------------
    1217         // Set specific data
    1218         // ------------------------------------------------------------------------------
    1219         function setTourLimit($limit, $start=null) {
    1220             $str = ($start) ? $start.','.$limit : $limit;
    1221             $this->tour_limit = $str;
    1222         }
    1223 
    1224         function setRefId() {
    1225             $this->searchCart();
    1226             $this->refid = ($this->refid) ? urlencode($this->refid) : urlencode($_COOKIE['rezgo_refid_val']);
    1227         }
    1228        
    1229         function setPromoCode() {
    1230             $this->searchCart();
    1231             // $this->promo_code = ($this->cart_trigger_code) ? urlencode($this->cart_trigger_code) : urlencode($_SESSION['promo']);
    1232             $this->promo_code = ($this->cart_trigger_code) ? urlencode($this->cart_trigger_code) : urlencode($_COOKIE['rezgo_promo']);
    1233         }
    1234        
    1235         function setShoppingCart($array) {
    1236             $this->cart = unserialize(stripslashes($array));
    1237         }
    1238        
    1239         function setPageTitle($str) {
    1240             $this->pageTitle = str_replace('_', ' ', $str);
    1241         }
    1242        
    1243         function setMetaTags($str) {
    1244             $this->metaTags = $str;
    1245         }
    1246 
    1247         function setCookie($name, $data='', $secure=null) {
    1248 
    1249             $secure = $secure ?? $this->checkSecure();
    1250 
    1251             $old_chrome = $this->config('OLD_CHROME');
    1252 
    1253             $data = (is_array($data ?? '')) ? serialize($data) : $data;
    1254 
    1255             if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
    1256                 $path = str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR );
    1257             } else {
    1258                 $path = '/';
    1259             }
    1260 
    1261             $options = [
    1262                 'expires' => time() + (($data) ? REZGO_CART_TTL : -3600),
    1263                 'path' => $path,
    1264                 'domain' => $_SERVER['SERVER_NAME'],
    1265                 'secure' => $secure,
    1266                 'samesite' => ($secure && !$old_chrome) ? 'None' : ''
    1267             ];
    1268            
    1269             setcookie($name, $data, $options);
    1270         }
    1271 
    1272         // ------------------------------------------------------------------------------
    1273         // Fetch specific data
    1274         // ------------------------------------------------------------------------------
    1275         function getSiteStatus() {
    1276             $this->XMLRequest('company');
    1277             return $this->company_response[0]->site_status;
    1278         }
    1279        
    1280         function getHeader() {
    1281             $this->XMLRequest('company');
    1282             $header = $this->company_response[0]->header;
    1283             // handle the tags in the template
    1284             return $this->tag_parse($header);
    1285         }
    1286        
    1287         function getFooter() {
    1288             $this->XMLRequest('company');
    1289             $footer = $this->company_response[0]->footer;
    1290             // handle the tags in the template
    1291             return $this->tag_parse($footer);
    1292         }
    1293        
    1294         function getVoucherHeader() {
    1295             $this->XMLRequest('company', 'voucher');
    1296             $header = $this->company_response[0]->header;
    1297             // handle the tags in the template
    1298             return $this->tag_parse($header);
    1299         }
    1300        
    1301         function getVoucherFooter() {
    1302             $this->XMLRequest('company', 'voucher');
    1303             return $this->company_response[0]->footer;
    1304         }
    1305        
    1306         function getTicketHeader() {
    1307             $this->XMLRequest('company', 'ticket');
    1308             $header = $this->company_response[0]->header;
    1309             return $this->tag_parse($header);
    1310         }
    1311        
    1312         function getTicketFooter() {
    1313             $this->XMLRequest('company', 'ticket');
    1314             return $this->company_response[0]->footer;
    1315         }
    1316 
    1317         function getTicketContent($trans_num) {
    1318             $this->XMLRequest('tickets', $trans_num);
    1319             return $this->ticket_response[$trans_num];
    1320         }
    1321 
    1322         function getWaiverContent($args=null, $target=null) {
    1323             $this->XMLRequest('waiver', $args, $target);
    1324             return $this->waiver_response[$args]->waiver;
    1325         }
    1326 
    1327         function getWaiverForms($args=null) {
    1328             $this->XMLRequest('waiver', $args);
    1329             return $this->waiver_response[$args]->forms->form;
    1330         }
    1331        
    1332         function getStyles() {
    1333             $this->XMLRequest('company');
    1334             return $this->company_response[0]->styles;
    1335         }
    1336        
    1337         function getPageName($page) {
    1338             $this->XMLRequest('page', $page);
    1339             if ($this->page_response[$page]->error) {
    1340                 return '404';
    1341             } else {
    1342                 return $this->page_response[$page]->name;
    1343             }
    1344         }
    1345        
    1346         function getPageContent($page) {
    1347             $this->XMLRequest('page', $page);
    1348             return $this->page_response[$page]->content;
    1349         }
    1350        
    1351         function getAnalytics() {
    1352             $this->XMLRequest('company');
    1353             return $this->company_response[0]->analytics_general;
    1354         }
    1355        
    1356         function getAnalyticsConversion() {
    1357             $this->XMLRequest('company');
    1358             return $this->company_response[0]->analytics_convert;
    1359         }
    1360        
    1361         function getTriggerState() {
    1362             $this->XMLRequest('company');
    1363             return $this->exists($this->company_response[0]->trigger);
    1364         }
    1365        
    1366         function getBookNow() {
    1367             $this->XMLRequest('company');
    1368             return $this->company_response[0]->book_now;
    1369         }
    1370        
    1371         function getCartState() {
    1372             $this->XMLRequest('company');
    1373             return ((int) $this->company_response[0]->cart == 1) ? 1 : 0;
    1374         }
    1375        
    1376         function getTwitterName() {
    1377             $this->XMLRequest('company');
    1378             return $this->company_response[0]->social->twitter_name;
    1379         }
    1380        
    1381         function getPaymentMethods($val=null, $a=null) {
    1382             $this->company_index = ($a) ? (string) $a : 0; // handle multiple company requests for vendor
    1383             $this->XMLRequest('company');
    1384            
    1385             if($this->company_response[$this->company_index]->payment->method[0]) {
    1386                 foreach($this->company_response[$this->company_index]->payment->method as $v) {
    1387                     $ret[] = array('name' => (string)$v, 'add' => (string)$v->attributes()->add);
    1388                     if($val && $val == $v) { return 1; }   
    1389                 }
    1390             } else {
    1391                 $ret[] = array(
    1392                     'name' => (string)$this->company_response[$this->company_index]->payment->method,
    1393                     'add' => (string)$this->company_response[$this->company_index]->payment->method->attributes()->add
    1394                 );
    1395                 if($val && $val == (string)$this->company_response[$this->company_index]->payment->method) { return 1; }               
    1396             }
    1397            
    1398             // if we made it this far with a $val set, return false
    1399             if($val) { return false; }
    1400             else { return $ret; }
    1401         }
    1402        
    1403         function getPaymentCards($a=null) {
    1404             $this->company_index = ($a) ? (string) $a : 0;
    1405             $this->XMLRequest('company');
    1406             $split = explode(",", $this->company_response[$this->company_index]->cards);
    1407             foreach((array) $split as $v) {
    1408                 if(trim($v)) $ret[] = strtolower(trim($v));
    1409             }
    1410             return $ret;
    1411         }
    1412        
    1413         function getPublicPayment($amount, $add=[]) {
    1414             $string = $amount;
    1415             $string .= '&cart=' . $this->cart_token;
    1416            
    1417             if($add) {
    1418                 foreach((array) $add as $k => $v) {
    1419                     $string .= '&add['.$k.']='.$v;
    1420                 }
    1421             }
    1422            
    1423             $this->XMLRequest('public', $string);
    1424             return $this->public_response;
    1425         }
    1426        
    1427         function getCVV($a=null) {
    1428             $this->company_index = ($a) ? (string) $a : 0;
    1429             $this->XMLRequest('company');
    1430             return (int) $this->company_response[$this->company_index]->get_cvv;
    1431         }
    1432        
    1433         function getGateway($a=null) {
    1434             $this->company_index = ($a) ? (string) $a : 0;
    1435             $this->XMLRequest('company');
    1436             return (((int) $this->company_response[$this->company_index]->using_gateway) && ($this->company_response[$this->company_index]->gateway_id != 'tmt')) ? 1 : 0;
    1437         }
    1438        
    1439         function getDomain($a=null) {
    1440             $this->company_index = ($a) ? (string) $a : 0;
    1441             $this->XMLRequest('company');
    1442             return $this->company_response[$this->company_index]->domain;
    1443         }
    1444        
    1445         function getCompanyName($a=null) {
    1446             $this->company_index = ($a) ? (string) $a : 0;
    1447             $this->XMLRequest('company');
    1448             return $this->company_response[$this->company_index]->company_name;
    1449         }
    1450        
    1451         function getCompanyCountry($a=null) {
    1452             $this->company_index = ($a) ? (string) $a : 0;
    1453             $this->XMLRequest('company');
    1454             return $this->company_response[$this->company_index]->country;
    1455         }
    1456        
    1457         function getCompanyPaypal($a=null) {
    1458             $this->company_index = ($a) ? (string) $a : 0;
    1459             $this->XMLRequest('company');
    1460             return $this->company_response[$this->company_index]->paypal_email;
    1461         }
    1462        
    1463         function getCompanyDetails($a=null) {
    1464             $this->company_index = ($a) ? (string) $a : 0;
    1465             $this->XMLRequest('company');
    1466             return $this->company_response[$this->company_index];
    1467         }
    1468        
    1469         // get a list of calendar data     
    1470         function getCalendar($item_id, $date=null) {
    1471             if(!$date) { // no date? set a default date (today)
    1472                 $date = $default_date = strtotime(date("Y-m-15"));
    1473                 $available = ',available'; // get first available date from month API
    1474             } else {
    1475                 $date = date("Y-m-15", strtotime($date));
    1476                 $date = strtotime($date);
    1477             }
    1478 
    1479             // $promo = ($this->promo_code) ? '&trigger_code='.$this->promo_code : ''; 
    1480             $promo = ($this->promo_code != ' ' ) ? '&trigger_code='.$this->promo_code : '';
    1481            
    1482             $query = $this->secure.$this->xml_path.'&i=month&q='.$item_id.'&d='.date("Y-m-d", $date).'&a=group'.$available.$promo; 
    1483            
    1484             $xml = $this->fetchXML($query);
    1485            
    1486             if(REZGO_TRACE_XML) {
    1487                 if($query) {
    1488                     $message = 'month'.' ( '.$query.' )';
    1489                     $this->debug('XML REQUEST: '.$message, 'month');
    1490                 }
    1491             }
    1492            
    1493             // update the date with the one provided from the API response
    1494             // this is done in case we hopped ahead with the API search (a=available)
    1495             $date = $xml->year.'-'.$xml->month.'-15';
    1496            
    1497             $year = date("Y", strtotime($date));
    1498             $month = date("m", strtotime($date));
    1499            
    1500             $date = $base_date = date("Y-m-15", strtotime($date));
    1501             $date = strtotime($date);
    1502                
    1503             $next_partial = date("Y-m", strtotime($base_date.' +1 month'));
    1504             $prev_partial = date("Y-m", strtotime($base_date.' -1 month'));
    1505                
    1506             $this->calendar_next = $next_date = date("Y-m-d", strtotime($base_date.' +1 month'));
    1507             $this->calendar_prev = $prev_date = date("Y-m-d", strtotime($base_date.' -1 month'));
    1508            
    1509            
    1510             $this->calendar_name = (string) $xml->name;
    1511             $this->calendar_com = (string) $xml->com;
    1512             $this->calendar_active = (int) $xml->active;
    1513            
    1514             $days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
    1515            
    1516             $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
    1517            
    1518             $start_day = 1;
    1519             $end_day = date("t", $date);
    1520            
    1521             $start_dow = date("D", strtotime(date("Y-m-1", $date)));
    1522            
    1523             $n = 0;
    1524             foreach($months as $k => $v) {
    1525                 $this->calendar_months[$n] = new stdClass();
    1526                 $this->calendar_months[$n]->selected = ($v == date("F", $date)) ? 'selected' : '';
    1527                 $this->calendar_months[$n]->value = $year.'-'.$v.'-15';
    1528                 $this->calendar_months[$n]->label = $k;
    1529                 $n++;
    1530             }
    1531        
    1532             for($y=date("Y", strtotime(date("Y").' -1 year')); $y<=date("Y", strtotime(date("Y").' +4 years')); $y++) {
    1533                 $this->calendar_years[$n] = new stdClass();
    1534                 $this->calendar_years[$n]->selected = ($y == date("Y", $date)) ? 'selected' : '';
    1535                 $this->calendar_years[$n]->value = $y.'-'.$month.'-15';
    1536                 $this->calendar_years[$n]->label = $y;
    1537                 $n++;
    1538             }
    1539                        
    1540             $c = 0;
    1541             foreach($days as $v) {
    1542                 $c++;
    1543                 if($start_dow == $v) $start_offset = $c;
    1544             }
    1545            
    1546             if($start_offset) {
    1547                 // this will display the lead-up days from last month
    1548                 $last_display = date("t", strtotime($prev_date)) - ($start_offset-2);
    1549                
    1550                 for($d=1; $d<$start_offset; $d++) {
    1551                     $obj = isset($obj) ? $obj : new stdClass();
    1552                     $obj->day = $last_display;
    1553                     $obj->lead = 1; // mark as lead up day, so it's not counted in getCalendarDays($day) calls
    1554                     $this->calendar_days[] = $obj;             
    1555                     $last_display++;
    1556                     unset($obj);
    1557                 }   
    1558             }
    1559            
    1560             $w = $start_offset;
    1561             for($d=1; $d<=$end_day; $d++) {     
    1562                 $obj = isset($obj) ? $obj : new stdClass();
    1563                
    1564                 $xd = $d - 1;           
    1565                 $obj->type = 1;
    1566                
    1567                 if($xml->day->$xd) {
    1568                     $obj->cond = $cond = (string) $xml->day->$xd->attributes()->condition;
    1569                     if($xml->day->$xd->item[0]) {
    1570                         // we want to convert the attribute to something easier to use in the template
    1571                         $n=0;
    1572                         foreach($xml->day->$xd->item as $i) {
    1573                             if($i) {
    1574                                 $obj->items[$n] = new stdClass();
    1575                                 $obj->items[$n]->uid = $i->uid;
    1576                                 $obj->items[$n]->name = $i->name;
    1577                                 $obj->items[$n]->availability = $i->attributes()->value;
    1578                                 $n++;
    1579                             }
    1580                         }
    1581                     } else {
    1582                         if($xml->day->$xd->item) {
    1583                             $obj->items[0] = new stdClass();
    1584                             $obj->items[0]->uid = $xml->day->$xd->item->uid;
    1585                             $obj->items[0]->name = $xml->day->$xd->item->name;
    1586                             $obj->items[0]->availability = $xml->day->$xd->item->attributes()->value;
    1587                         }
    1588                     }
    1589                 }
    1590                
    1591                 $obj->date = strtotime($year.'-'.$month.'-'.$d);
    1592                
    1593                 $obj->day = $d;     
    1594                 $this->calendar_days[] = $obj;         
    1595                 unset($obj);
    1596                
    1597                 if($w == 7) { $w = 1; } else { $w++; }
    1598             }
    1599                
    1600             if($w != 8 && $w != 1) {
    1601                 $d = 0;
    1602                 // this will display the lead-out days for next month
    1603                 while($w != 8) {
    1604                     $d++;
    1605                     $w++;
    1606                     $obj = isset($obj) ? $obj : new stdClass();
    1607                     $obj->day = $d;         
    1608                     $this->calendar_days[] = $obj;
    1609                     unset($obj);
    1610                 }
    1611             }
    1612         }
    1613        
    1614         function getCalendarActive() {
    1615             return $this->calendar_active;
    1616         }
    1617        
    1618         function getCalendarPrev() {
    1619             return $this->calendar_prev;
    1620         }
    1621        
    1622         function getCalendarNext() {
    1623             return $this->calendar_next;
    1624         }
    1625        
    1626         function getCalendarMonths() {
    1627             return $this->calendar_months;
    1628         }
    1629        
    1630         function getCalendarYears() {
    1631             return $this->calendar_years;
    1632         }
    1633        
    1634         function getCalendarDays($day=null) {
    1635             if($day) {
    1636                 foreach($this->calendar_days as $v) {
    1637                     if((int)$v->day == $day && !(int)$v->lead) {
    1638                         $day_response = $v; break;
    1639                     }
    1640                 }
    1641                
    1642                 return (object) $day_response;
    1643             } else {
    1644                 return $this->calendar_days;
    1645             }
    1646         }
    1647        
    1648         function getCalendarId() {
    1649             return $this->calendar_com;
    1650         }
    1651        
    1652         function getCalendarName() {
    1653             return $this->calendar_name;
    1654         }
    1655    
    1656         function getCalendarDiff($date1, $date2) {
    1657             // $date1 and $date2 must have format: Y-M-D
    1658            
    1659             $date1 = new DateTime($date1);
    1660             $date2 = new DateTime($date2);
    1661             $interval = $date1->diff($date2);
    1662            
    1663             $res = '';
    1664            
    1665             if($interval->y > 0) $res .= $interval->y . ' year' . (($interval->y > 1) ? 's' : '') . (($interval->y > 0)?', ':'');
    1666             if($interval->m > 0) $res .= $interval->m . ' month' . (($interval->m > 1) ? 's' : '') . (($interval->m > 0)?', ':'');
    1667             if($interval->d > 0) $res .= $interval->d . ' day' . (($interval->d > 1) ? 's' : '');
    1668            
    1669             return $res;
    1670         }
    1671        
    1672         // get a list of tour data
    1673         function getTours($a=null, $node=null) {
    1674             // generate the search string
    1675             // if no search is specified, find searched items (grouped)
    1676             if(!$a || $a == $_REQUEST) {
    1677                 if($this->requestStr('search_for')) $str .= ($this->requestStr('search_in')) ? '&t='.urlencode($this->requestStr('search_in')) : '&t=smart';   
    1678                 if($this->requestStr('search_for')) $str .= '&q='.urlencode(stripslashes($this->requestStr('search_for')));
    1679                 if($this->requestStr('tags')) $str .= '&f[tags]='.urlencode($this->requestStr('tags'));
    1680                
    1681                 if($this->requestNum('cid')) $str .= '&f[cid]='.urlencode($this->requestNum('cid')); // vendor only
    1682                
    1683                 // details pages
    1684                 if($this->requestNum('com')) $str .= '&t=com&q='.urlencode($this->requestNum('com'));
    1685                 if($this->requestNum('uid')) $str .= '&t=uid&q='.urlencode($this->requestNum('uid'));
    1686                 if($this->requestStr('option')) $str .= '&t=uid&q='.urlencode($this->requestStr('option'));
    1687                 if($this->requestStr('date')) $str .= '&d='.urlencode($this->requestStr('date'));
    1688                
    1689                 $a = ($a) ? $a : 'a=group'.$str;
    1690             }
    1691 
    1692             // $promo = ($this->promo_code) ? '&trigger_code='.$this->promo_code : '';
    1693             $promo = ($this->promo_code != ' ' ) ? '&trigger_code='.$this->promo_code : '';
    1694 
    1695             $limit = '&limit='.$this->tour_limit;
    1696            
    1697             // attach the search as an index including the limit value and promo code
    1698             $this->tours_index = $a.$promo.$limit;
    1699                
    1700             $this->XMLRequest('search');
    1701            
    1702             $return = ($node === null) ? (array) $this->search_response[$this->tours_index] : $this->search_response[$this->tours_index][$node];
    1703 
    1704             return $return;
    1705         }
    1706        
    1707         function getTourAvailability(&$obj=null, $start=null, $end=null) {
    1708             if(!$obj) $obj = $this->getItem();
    1709            
    1710             // check the object, create a list of com ids
    1711             // search the API with those ids and the date search
    1712             // create a list of dates and relevant options to return
    1713        
    1714             $loop = (string) $obj->index;
    1715            
    1716             $d[] = ($start) ? date("Y-M-d", strtotime($start)) : date("Y-M-d", strtotime($this->requestStr(start_date)));
    1717             $d[] = ($end) ? date("Y-M-d", strtotime($end)) : date("Y-M-d", strtotime($this->requestStr(end_date)));
    1718             if($d) { $d = implode(',', $d); } else { return false; }
    1719            
    1720             if(!$this->tour_availability_response[$loop])   {
    1721                 if($this->search_response[$loop]) {
    1722                     foreach((array)$this->search_response[$loop] as $v) {
    1723                         $uids[] = (string)$v->com;
    1724                     }
    1725                    
    1726                     $this->tours_index = 't=com&q='.implode(',', array_unique($uids)).'&d='.$d;
    1727                    
    1728                     $this->XMLRequest('search');
    1729                    
    1730                     $c=0;
    1731                     foreach((array)$this->search_response[$this->tours_index] as $i) {
    1732                         if($i->date) {
    1733                             if($i->date[0]) {
    1734                                 foreach($i->date as $d) {
    1735                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)] = new stdClass();
    1736                                    
    1737                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->id = $c;
    1738                                    
    1739                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c] = new stdClass();
    1740                                    
    1741                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->name = (string)$i->time;
    1742                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->availability = (string)$d->availability;
    1743                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->hide_availability = (string)$d->hide_availability;
    1744                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c++]->uid = (string)$i->uid;
    1745                                     $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->date = strtotime((string)$d->attributes()->value);
    1746                                 }
    1747                             } else {
    1748                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)] = new stdClass();
    1749                                
    1750                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->id = $c;
    1751                                
    1752                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c] = new stdClass();
    1753                                
    1754                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->name = (string)$i->time;
    1755                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->availability = (string)$i->date->availability;
    1756                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->hide_availability = (string)$i->date->hide_availability;
    1757                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c++]->uid = (string)$i->uid;
    1758                                 $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->date = strtotime((string)$i->date->attributes()->value);
    1759                             }
    1760                            
    1761                             // sort by date so the earlier dates always appear first, the api will return them in that order
    1762                             // but if the first item found has a later date than a subsequent item, the dates will be out of order
    1763                             ksort($res[(string)$i->com]);
    1764                         }
    1765                     }
    1766                     $this->tour_availability_response[$loop] = $res;   
    1767                 }
    1768             }
    1769            
    1770             return (array) $this->tour_availability_response[$loop][(string)$obj->com];
    1771         }
    1772        
    1773         function getTourPrices(&$obj=null) {
    1774             if(!$obj) $obj = $this->getItem();
    1775             $com = (string) $obj->com;
    1776            
    1777             $c=0;
    1778             $all_required = 0;
    1779             $valid_count = 0;
    1780             $strike_prices = array();
    1781            
    1782             foreach ($obj->prices->price as $price) {
    1783                 if($price->strike) {
    1784                     $strike_prices[(int) $price->id] = (string) $price->strike;
    1785                 }
    1786             }
    1787 
    1788             if($this->exists($obj->date->price_adult)) {
    1789                 $ret[$c] = new stdClass();
    1790                 $ret[$c]->name = 'adult';
    1791                 $ret[$c]->label = (string) $obj->adult_label;
    1792                 $ret[$c]->required = (string) $obj->adult_required;
    1793                 if($ret[$c]->required) $all_required++;
    1794                 ($obj->date->base_prices->price_adult) ? $ret[$c]->base = (string) $obj->date->base_prices->price_adult : 0;
    1795                 $ret[$c]->price = (string) $obj->date->price_adult;
    1796                 $ret[$c]->strike = $strike_prices[1];
    1797                 $ret[$c]->count = (string) $obj->prices->price[0]->count;
    1798                 $ret[$c++]->total = (string) $obj->total_adult;
    1799                 $valid_count++;
    1800             }
    1801             if($this->exists($obj->date->price_child)) {
    1802                 $ret[$c] = new stdClass();
    1803                 $ret[$c]->name = 'child';
    1804                 $ret[$c]->label = (string) $obj->child_label;
    1805                 $ret[$c]->required = (string) $obj->child_required;
    1806                 if($ret[$c]->required) $all_required++;
    1807                 ($obj->date->base_prices->price_child) ? $ret[$c]->base = (string) $obj->date->base_prices->price_child : 0;
    1808                 $ret[$c]->price = (string) $obj->date->price_child;
    1809                 $ret[$c]->strike = $strike_prices[2];
    1810                 $ret[$c]->count = (string) $obj->prices->price[1]->count;
    1811                 $ret[$c++]->total = (string) $obj->total_child;
    1812                 $valid_count++;
    1813             }
    1814             if($this->exists($obj->date->price_senior)) {
    1815                 $ret[$c] = new stdClass();
    1816                 $ret[$c]->name = 'senior';
    1817                 $ret[$c]->label = (string) $obj->senior_label;
    1818                 $ret[$c]->required = (string) $obj->senior_required;
    1819                 if($ret[$c]->required) $all_required++;
    1820                 ($obj->date->base_prices->price_senior) ? $ret[$c]->base = (string) $obj->date->base_prices->price_senior : 0;
    1821                 $ret[$c]->price = (string) $obj->date->price_senior;
    1822                 $ret[$c]->strike = $strike_prices[3];
    1823                 $ret[$c]->count = (string) $obj->prices->price[2]->count;
    1824                 $ret[$c++]->total = (string) $obj->total_senior;
    1825                 $valid_count++;
    1826             }   
    1827 
    1828             $j=3;
    1829             for($i=4; $i<=9; $i++) {
    1830                 $val = 'price'.$i;
    1831                 if($this->exists($obj->date->$val)) {
    1832                     $ret[$c] = new stdClass();
    1833                     $ret[$c]->name = 'price'.$i;
    1834                     $val = 'price'.$i.'_label';
    1835                     $ret[$c]->label = (string) $obj->$val;
    1836                     $val = 'price'.$i.'_required';
    1837                     $ret[$c]->required = (string) $obj->$val;
    1838                     if($ret[$c]->required) $all_required++;
    1839                     $val = 'price'.$i;
    1840                     ($obj->date->base_prices->$val) ? $ret[$c]->base = (string) $obj->date->base_prices->$val : 0;
    1841                     $ret[$c]->price = (string) $obj->date->$val;
    1842                     $ret[$c]->strike = $strike_prices[$i];
    1843                     $val = 'total_price'.$i;
    1844                     $ret[$c]->count = (string) $obj->prices->price[$j]->count;
    1845                     $ret[$c++]->total = (string) $obj->$val;
    1846                     $valid_count++;
    1847                 }
    1848                 $j++;
    1849             }
    1850 
    1851             // if the total required count is the same as the total price points, or if no prices are required
    1852             // we want to set the all_required flag so that the parser won't display individual required marks
    1853             if($all_required == $valid_count || $all_required == 0) {
    1854                 $this->all_required = 1;
    1855             } else {
    1856                 $this->all_required = 0;
    1857             }           
    1858            
    1859             return (array) $ret;
    1860         }
    1861        
    1862         function getTourBundles(&$obj=null) {
    1863            
    1864             if(!$obj) $obj = $this->getItem();
    1865             $com = (string) $obj->com;
    1866            
    1867             $c = 0;
    1868                    
    1869             $bundle_prices = array();
    1870            
    1871             if(isset($obj->bundles)) {
    1872            
    1873                 foreach ($obj->bundles->bundle as $bundle) {
    1874                    
    1875                     $ret[$c] = new stdClass();
    1876                    
    1877                     if ($this->exists($bundle->name) && $this->exists($bundle->price)) { // bundles must have a name and a price
    1878                    
    1879                         $ret[$c]->id = $c + 1;
    1880                         $ret[$c]->name = $bundle->name;
    1881                        
    1882                         $ret[$c]->label = $this->seoEncode($bundle->name);
    1883                        
    1884                         $ret[$c]->price = $bundle->price;
    1885                         $ret[$c]->visible = $bundle->visible;
    1886                         $ret[$c]->pax = $bundle->pax;
    1887                        
    1888                         unset($bundle_prices);
    1889                         $bundle_makeup = '';
    1890                         $bundle_total = 0;
    1891                        
    1892                         foreach ($bundle->pax->price as $count) {
    1893                            
    1894                             $bundle_total += (int) $count;
    1895                                                    
    1896                             if ($count['id'] == 1) {
    1897                                
    1898                                 $bundle_makeup .= $count . ' ' . $obj->adult_label . ', ';
    1899                                 $bundle_prices['adult'] = (string) $count;
    1900                                
    1901                             } elseif ($count['id'] == 2) {
    1902                                
    1903                                 $bundle_makeup .= $count . ' ' . $obj->child_label . ', ';
    1904                                 $bundle_prices['child'] = (string) $count;
    1905                                
    1906                             } elseif ($count['id'] == 3) {
    1907                                
    1908                                 $bundle_makeup .= $count . ' ' . $obj->senior_label . ', ';
    1909                                 $bundle_prices['senior'] = (string) $count;
    1910                                
    1911                             } else {
    1912                                
    1913                                 $price_label = 'price'.$count['id'].'_label';
    1914                                 $bundle_makeup .= $count . ' ' . $obj->$price_label . ', ';
    1915                                 $bundle_prices['price'.$count['id']] = (string) $count;
    1916                                
    1917                             }
    1918                            
    1919                         }
    1920                            
    1921                         $bundle_makeup = rtrim($bundle_makeup, ', ');
    1922                         $ret[$c]->makeup = $bundle_makeup;
    1923                        
    1924                         $ret[$c]->prices = $bundle_prices;
    1925                        
    1926                         $ret[$c]->total = $bundle_total;
    1927                        
    1928                         $c++;
    1929                    
    1930                     }
    1931                    
    1932                 }
    1933                
    1934             }
    1935                            
    1936             return (array) $ret;
    1937         }
    1938        
    1939         function getTourRequired() {
    1940             return ($this->all_required) ? 0 : 1;
    1941         }
    1942        
    1943         function getTourPriceNum(&$obj=null, $order=null) {
    1944             if(!$obj) $obj = $this->getItem();
    1945             // get the value from either the order object or the _REQUEST var
    1946             $val = (is_object($order)) ? $order->{$obj->name.'_num'} : $_REQUEST[$obj->name.'_num'];
    1947             for($n=1; $n<=$val; $n++) {
    1948                 $ret[] = $n;
    1949             }
    1950             return (array) $ret;
    1951         }
    1952        
    1953         function getTourTags(&$obj=null) {
    1954             if(!$obj) $obj = $this->getItem();         
    1955             if($this->exists($obj->tags)) {
    1956                 $split = explode(',', $obj->tags);
    1957                 foreach((array) $split as $v) {
    1958                     $ret[] = trim($v);
    1959                 }
    1960             }
    1961             return (array) $ret;
    1962         }
    1963        
    1964         function getTourLocations(&$obj=null) {
    1965             if(!$obj) $obj = $this->getItem();
    1966             $c = 0;
    1967             if($obj->additional_locations->location) {
    1968                 if(!$obj->additional_locations->location[0]) {
    1969                     $ret[$c]->country = $obj->additional_locations->location->loc_country;
    1970                     $ret[$c]->state = $obj->additional_locations->location->loc_state;
    1971                     $ret[$c++]->city = $obj->additional_locations->location->loc_city;
    1972                 } else {
    1973                     foreach($obj->additional_locations->location as $v) {
    1974                         $ret[$c]->country = $v->loc_country;
    1975                         $ret[$c]->state = $v->loc_state;
    1976                         $ret[$c++]->city = $v->loc_city;
    1977                     }
    1978                 }
    1979             }
    1980             return (array) $ret;
    1981         }
    1982        
    1983         function getTourMedia(&$obj=null) {
    1984             if(!$obj) $obj = $this->getItem();
    1985             $c = 0;
    1986             if($obj->media->image) {
    1987                 foreach($obj->media->image as $v) {
    1988                     $ret[$c] = new stdClass();
    1989                     $ret[$c]->image = $v->path;
    1990                     $ret[$c]->path = $v->path;
    1991                     $ret[$c]->caption = $v->caption;
    1992                     $ret[$c++]->type = 'image';
    1993                 }
    1994                 return (array) $ret;
    1995             } else { return false; }
    1996         }
    1997        
    1998         function getTourRelated(&$obj=null) {
    1999             if(!$obj) $obj = $this->getItem();         
    2000             $c = 0;
    2001             if($obj->related->items) {
    2002                 foreach($obj->related->items->item as $v) {
    2003                     $ret[$c] = new stdClass();
    2004                    
    2005                     $ret[$c]->com = $v->com;
    2006                     $ret[$c]->image = $v->image;
    2007                     $ret[$c]->starting = $v->starting;
    2008                     $ret[$c]->overview = $v->overview;
    2009                     $ret[$c++]->name = $v->name;
    2010                 }
    2011                 return (array) $ret;
    2012             } else { return false; }
    2013         }
    2014        
    2015         function getCrossSell(&$obj=null) {
    2016             if(!$obj) $obj = $this->getItem();         
    2017             $c = 0;
    2018             if($obj->cross->items) {
    2019                 foreach($obj->cross->items->item as $v) {
    2020                     $ret[$c] = new stdClass();
    2021                    
    2022                     $ret[$c]->com = $v->com;
    2023                     $ret[$c]->image = $v->image;
    2024                     $ret[$c]->starting = $v->starting;
    2025                     $ret[$c]->overview = $v->overview;
    2026                     $ret[$c++]->name = $v->name;
    2027                 }
    2028                 return (array) $ret;
    2029             } else { return false; }
    2030         }
    2031        
    2032         function getCrossSellText(&$obj=null) {
    2033             if(!$obj) $obj = $this->getItem();         
    2034            
    2035             if($obj->cross) {
    2036                
    2037                 $ret = new stdClass();
    2038                
    2039                 $ret->title = $obj->cross->title;
    2040                 $ret->desc = $obj->cross->desc;
    2041                
    2042                 return $ret;
    2043             } else { return false; }
    2044         }
    2045        
    2046         function getTourLineItems(&$obj=null) {
    2047             if(!$obj) $obj = $this->getItem();
    2048            
    2049             if($obj->line_items) {
    2050                 if($obj->line_items->line_item[0]) {
    2051                     foreach($obj->line_items->line_item as $v) {
    2052                         $ret[] = $v;
    2053                     }
    2054                 } else {
    2055                     $ret[] = $obj->line_items->line_item;
    2056                 }
    2057             }
    2058            
    2059             return (array) $ret;
    2060         }
    2061        
    2062         function getTourForms($type='primary', &$obj=null) {
    2063             if(!$obj) $obj = $this->getItem();
    2064             $com = (string) $obj->com;
    2065             $uid = (string) $obj->uid;
    2066            
    2067             $type = strtolower($type);
    2068             if($type != 'primary' && $type != 'group') $this->error('unknown type, expecting "primary" or "group"');
    2069 
    2070             if(!$this->tour_forms[$com.'-'.$uid][$type]) {
    2071                 if($obj->{$type.'_forms'}) {
    2072                    
    2073                     foreach($obj->{$type.'_forms'}->form as $f) {
    2074                         $res[$type][(string)$f->id] = new stdClass();
    2075                        
    2076                         $res[$type][(string)$f->id]->id = (string)$f->id;
    2077                         $res[$type][(string)$f->id]->type = (string)$f->type;
    2078                         $res[$type][(string)$f->id]->title = (string)$f->title;
    2079                         $res[$type][(string)$f->id]->require = (string)$f->require;
    2080                         $res[$type][(string)$f->id]->value = (string)$f->value;
    2081                         $res[$type][(string)$f->id]->instructions = (string)$f->instructions;
    2082                        
    2083                         if((string)$f->price) {
    2084                             if(strpos((string)$f->price, '-') !== false) {
    2085                                 $res[$type][(string)$f->id]->price = str_replace("-", "", (string)$f->price);
    2086                                 $res[$type][(string)$f->id]->price_mod = '-';
    2087                             } else {
    2088                                 $res[$type][(string)$f->id]->price = str_replace("+", "", (string)$f->price);
    2089                                 $res[$type][(string)$f->id]->price_mod = '+';
    2090                             }
    2091                         }
    2092                        
    2093                         if((string)$f->options) {
    2094                             $opt = explode(",", (string)$f->options);
    2095                             foreach((array)$opt as $v) {
    2096                                 $res[$type][(string)$f->id]->options[] = $v;
    2097                             }
    2098                         }
    2099                        
    2100                         if((string)$f->options_instructions) {
    2101                             $opt_inst = explode(",", (string)$f->options_instructions);
    2102                             foreach((array)$opt_inst as $v) {
    2103                                 $res[$type][(string)$f->id]->options_instructions[] = $v;
    2104                             }
    2105                         }
    2106                        
    2107                     }
    2108                    
    2109                 }
    2110                
    2111                 $this->tour_forms[$com.'-'.$uid] = $res;
    2112             }
    2113            
    2114             return (array) $this->tour_forms[$com.'-'.$uid][$type];
    2115         }
    2116        
    2117         function getTagSizes() {
    2118             $this->XMLRequest('tags');
    2119            
    2120             foreach($this->tags_response as $v) {
    2121                 $valid_tags[((string)$v->name)] = (string) $v->count;
    2122             }
    2123             // returns high [0] and low [1] for a list()
    2124             rsort($valid_tags);
    2125             $ret[] = $valid_tags[0];
    2126             sort($valid_tags);
    2127             $ret[] = $valid_tags[0];
    2128                        
    2129             return (array) $ret;
    2130         }
    2131        
    2132         function getTags() {
    2133             $this->XMLRequest('tags');
    2134             return (array) $this->tags_response;
    2135         }
    2136        
    2137         // get a list of booking data
    2138         function getBookings($a=null, $node=null) {
    2139             if(!$a) $this->error('No search argument provided, expected trans_num or formatted search string');
    2140            
    2141             if(strpos($a, '=') === false) $a = 'q='.$a; // in case we just passed the trans_num by itself
    2142            
    2143             $this->bookings_index = $a;
    2144            
    2145             $this->XMLRequest('search_bookings');
    2146            
    2147             $return = ($node === null) ? (array) $this->search_bookings_response[$this->bookings_index] : $this->search_bookings_response[$this->bookings_index][$node];
    2148            
    2149             return $return;
    2150         }
    2151        
    2152         function getBookingPrices(&$obj=null) {
    2153             if(!$obj) $obj = $this->getItem();
    2154            
    2155             $c=0;
    2156             if($obj->adult_num >= 1) {
    2157                 $ret[$c] = new stdClass();
    2158                
    2159                 $ret[$c]->name = 'adult';
    2160                 $ret[$c]->label = (string) $obj->adult_label;
    2161                 ($obj->prices->base_prices->price_adult) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_adult : 0;
    2162                 $ret[$c]->price = (string) ($obj->prices->price_adult / $obj->adult_num);
    2163                 $ret[$c]->number = (string) $obj->adult_num;
    2164                 $ret[$c++]->total = (string) $obj->prices->price_adult;
    2165             }
    2166             if($obj->child_num >= 1) {
    2167                 $ret[$c] = new stdClass();
    2168                
    2169                 $ret[$c]->name = 'child';
    2170                 $ret[$c]->label = (string) $obj->child_label;
    2171                 ($obj->prices->base_prices->price_child) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_child : 0;
    2172                 $ret[$c]->price = (string) ($obj->prices->price_child / $obj->child_num);
    2173                 $ret[$c]->number = (string) $obj->child_num;
    2174                 $ret[$c++]->total = (string) $obj->prices->price_child;
    2175             }
    2176             if($obj->senior_num >= 1) {
    2177                 $ret[$c] = new stdClass();
    2178                
    2179                 $ret[$c]->name = 'senior';
    2180                 $ret[$c]->label = (string) $obj->senior_label;
    2181                 ($obj->prices->base_prices->price_senior) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_senior : 0;
    2182                 $ret[$c]->price = (string) ($obj->prices->price_senior / $obj->senior_num);
    2183                 $ret[$c]->number = (string) $obj->senior_num;
    2184                 $ret[$c++]->total = (string) $obj->prices->price_senior;
    2185             }   
    2186            
    2187             for($i=4; $i<=9; $i++) {
    2188                 $val = 'price'.$i.'_num';
    2189                 if($obj->$val >= 1) {
    2190                     $ret[$c] = new stdClass();
    2191                    
    2192                     $ret[$c]->name = 'price'.$i;
    2193                     $val = 'price'.$i.'_label';
    2194                     $ret[$c]->label = (string) $obj->$val;
    2195                     $val = 'price'.$i;
    2196                     $val2 = 'price'.$i.'_num';
    2197                     ($obj->prices->base_prices->$val) ? $ret[$c]->base = (string) $obj->prices->base_prices->$val : 0;
    2198                     $ret[$c]->price = (string) ($obj->prices->$val / $obj->$val2);
    2199                     $val = 'price'.$i.'_num';
    2200                     $ret[$c]->number = (string) $obj->$val;
    2201                     $val = 'price'.$i;
    2202                     $ret[$c++]->total = (string) $obj->prices->$val;
    2203                 }
    2204             }
    2205 
    2206             return (array) $ret;
    2207         }
    2208        
    2209         function getBookingLineItems(&$obj=null) {
    2210             if(!$obj) $obj = $this->getItem();
    2211            
    2212             if($obj->line_items) {
    2213                 if($obj->line_items->line_item[0]) {
    2214                     foreach($obj->line_items->line_item as $v) {
    2215                         $ret[] = $v;
    2216                     }
    2217                 } else {
    2218                     $ret[] = $obj->line_items->line_item;
    2219                 }
    2220             }
    2221            
    2222             return (array) $ret;               
    2223         }
    2224        
    2225         function getBookingFees(&$obj=null) {
    2226             if(!$obj) $obj = $this->getItem();
    2227            
    2228             if($obj->triggered_fees->triggered_fee[0]) {
    2229                 foreach($obj->triggered_fees->triggered_fee as $v) {
    2230                     $ret[] = $v;
    2231                 }
    2232             } else {
    2233                 $ret[] = $obj->triggered_fees->triggered_fee;
    2234             }
    2235            
    2236             return (array) $ret;               
    2237         }
    2238        
    2239         function getBookingPassengers(&$obj=null) {
    2240             if(!$obj) $obj = $this->getItem();
    2241            
    2242             $c=0;
    2243             if($obj->passengers->passenger[0]) {
    2244                 foreach($obj->passengers->passenger as $v) {
    2245                     // do the forms on the passenger only have one question? if so, fix the formatting so it matches multiple questions
    2246                     if($v->total_forms > 0) {
    2247                         if(!$v->forms->form[0]) {
    2248                             $t = $v->forms->form;
    2249                             unset($v->forms->form); // remove the string value
    2250                             $v->forms->form[] = $t; // replace it with array value
    2251                         }
    2252                     } else {
    2253                         // no forms, fill the value with a blank array so the templates can use it
    2254                         // we add a supress @ modifier to prevent the complex-types error
    2255                         @$v->forms->form = array();
    2256                     }
    2257                    
    2258                     $ret[$c] = $v;
    2259                     @$ret[$c]->num = $v->type->attributes()->num;
    2260                     $val = $v->type.'_label';
    2261                     $ret[$c++]->label = $obj->$val;
    2262                 }
    2263             } else {
    2264                 // do the forms on the passenger only have one question? if so, fix the formatting so it matches multiple questions
    2265                 if($obj->passengers->passenger->total_forms > 0) {
    2266                     if(!$obj->passengers->passenger->forms->form[0]) {
    2267                         $t = $obj->passengers->passenger->forms->form;
    2268                         unset($obj->passengers->passenger->forms->form); // remove the string value
    2269                         $obj->passengers->passenger->forms->form[] = $t; // replace it with array value
    2270                     }
    2271                 } else {
    2272                     // no forms, fill the value with a blank array so the templates can use it
    2273                     @$obj->passengers->passenger->forms->form = array();
    2274                 }
    2275                
    2276                 $ret[$c] = $obj->passengers->passenger;
    2277                 @$ret[$c]->num = $obj->passengers->passenger->type->attributes()->num;
    2278                 $val = $obj->passengers->passenger->type.'_label';
    2279                 $ret[$c++]->label = $obj->$val;
    2280             }
    2281            
    2282             // unset it if the value is empty because we have no group info
    2283             $count = count($ret);
    2284             if($count == 1 && !(string)$ret[0]->num) unset($ret);
    2285            
    2286             // check to make sure the entire array isn't empty of data
    2287             if($count > 1) {
    2288                 foreach((array)$ret as $k => $v) {
    2289                    
    2290                    
    2291                     if((string)$v->first_name) { $present = 1; break; }
    2292                     if((string)$v->last_name) { $present = 1; break; }
    2293 
    2294                     if((string)$v->phone_number) { $present = 1; break; }
    2295                     if((string)$v->email_address) { $present = 1; break; }
    2296                     if((string)$v->total_forms > 0) { $present = 1; break; }
    2297                 }
    2298                
    2299                 // if(!$present) unset($ret);
    2300             }
    2301            
    2302             return (array) $ret;               
    2303         }
    2304        
    2305         function getBookingForms(&$obj=null) {
    2306             if(!$obj) $obj = $this->getItem();
    2307            
    2308             if($obj->primary_forms->total_forms > 0) {
    2309                 if($obj->primary_forms->form[0]) {
    2310                     foreach($obj->primary_forms->form as $v) {
    2311                         $ret[] = $v;
    2312                     }
    2313                 } else {
    2314                     $ret[] = $obj->primary_forms->form;
    2315                 }
    2316             }
    2317                        
    2318             return (array) $ret;
    2319         }
    2320        
    2321         function getBookingCounts(&$obj=null) {
    2322             if(!$obj) $obj = $this->getItem();
    2323            
    2324             $list = array('adult', 'child', 'senior', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9');
    2325             $c=0;
    2326             foreach($list as $v) {
    2327                 $num = $v.'_num';
    2328                 $label = $v.'_label';
    2329                 if($obj->$num > 0) {
    2330                     $ret[$c] = new stdClass();
    2331                     $ret[$c]->label = $obj->$label;
    2332                     $ret[$c++]->num = $obj->$num;
    2333                 }
    2334             }
    2335             return (array) $ret;
    2336         }
    2337        
    2338         function getBookingCurrency(&$obj=null) {
    2339             if(!$obj) $obj = $this->getItem();
    2340            
    2341             return (string) $obj->currency_base;
    2342         }
    2343        
    2344         function getPaxString() {
    2345 
    2346             if($this->requestNum('adult_num')) $pax_list .= '&adult_num='.$this->requestNum('adult_num');
    2347             if($this->requestNum('child_num')) $pax_list .= '&child_num='.$this->requestNum('child_num');
    2348             if($this->requestNum('senior_num')) $pax_list .= '&senior_num='.$this->requestNum('senior_num');
    2349             if($this->requestNum('price4_num')) $pax_list .= '&price4_num='.$this->requestNum('price4_num');
    2350             if($this->requestNum('price5_num')) $pax_list .= '&price5_num='.$this->requestNum('price5_num');
    2351             if($this->requestNum('price6_num')) $pax_list .= '&price6_num='.$this->requestNum('price6_num');
    2352             if($this->requestNum('price7_num')) $pax_list .= '&price7_num='.$this->requestNum('price7_num');
    2353             if($this->requestNum('price8_num')) $pax_list .= '&price8_num='.$this->requestNum('price8_num');
    2354             if($this->requestNum('price9_num')) $pax_list .= '&price9_num='.$this->requestNum('price9_num');
    2355            
    2356             return $pax_list;
    2357         }
    2358        
    2359         // ------------------------------------------------------------------------------
    2360         // Handle parsing the rezgo pseudo tags
    2361         // ------------------------------------------------------------------------------
    2362         function tag_parse($str) {
    2363             $val = ($GLOBALS['pageHeader']) ? $GLOBALS['pageHeader'] : $this->pageTitle;
    2364             $tags = array('[navigation]', '[navigator]');
    2365             $str = str_replace($tags, $val, $str); 
    2366            
    2367             $val = ($GLOBALS['pageMeta']) ? $GLOBALS['pageHeader'] : $this->metaTags;
    2368             $tags = array('[meta]', '[meta_tags]', '[seo]');
    2369             $str = str_replace($tags, $val, $str);
    2370            
    2371             return (string) $str;
    2372         }
    2373        
    2374         // ------------------------------------------------------------------------------
    2375         // Create an outgoing commit request based on the _REQUEST data
    2376         // ------------------------------------------------------------------------------
    2377         function sendBooking($var=null, $arg=null) {
    2378             $r = ($var) ? $var : $_REQUEST;
    2379            
    2380             if($arg) $res[] = $arg; // extra API options
    2381            
    2382             ($r['date']) ? $res[] = 'date='.urlencode($r['date']) : 0;
    2383             ($r['book']) ? $res[] = 'book='.urlencode($r['book']) : 0;
    2384            
    2385             ($r['trigger_code']) ? $res[] = 'trigger_code='.urlencode($r['trigger_code']) : 0;
    2386            
    2387             ($r['adult_num']) ? $res[] = 'adult_num='.urlencode($r['adult_num']) : 0;
    2388             ($r['child_num']) ? $res[] = 'child_num='.urlencode($r['child_num']) : 0;
    2389             ($r['senior_num']) ? $res[] = 'senior_num='.urlencode($r['senior_num']) : 0;
    2390             ($r['price4_num']) ? $res[] = 'price4_num='.urlencode($r['price4_num']) : 0;
    2391             ($r['price5_num']) ? $res[] = 'price5_num='.urlencode($r['price5_num']) : 0;
    2392             ($r['price6_num']) ? $res[] = 'price6_num='.urlencode($r['price6_num']) : 0;
    2393             ($r['price7_num']) ? $res[] = 'price7_num='.urlencode($r['price7_num']) : 0;
    2394             ($r['price8_num']) ? $res[] = 'price8_num='.urlencode($r['price8_num']) : 0;
    2395             ($r['price9_num']) ? $res[] = 'price9_num='.urlencode($r['price9_num']) : 0;
    2396            
    2397             ($r['tour_first_name']) ? $res[] = 'tour_first_name='.urlencode($r['tour_first_name']) : 0;
    2398             ($r['tour_last_name']) ? $res[] = 'tour_last_name='.urlencode($r['tour_last_name']) : 0;
    2399             ($r['tour_address_1']) ? $res[] = 'tour_address_1='.urlencode($r['tour_address_1']) : 0;
    2400             ($r['tour_address_2']) ? $res[] = 'tour_address_2='.urlencode($r['tour_address_2']) : 0;
    2401             ($r['tour_city']) ? $res[] = 'tour_city='.urlencode($r['tour_city']) : 0;
    2402             ($r['tour_stateprov']) ? $res[] = 'tour_stateprov='.urlencode($r['tour_stateprov']) : 0;
    2403             ($r['tour_country']) ? $res[] = 'tour_country='.urlencode($r['tour_country']) : 0;
    2404             ($r['tour_postal_code']) ? $res[] = 'tour_postal_code='.urlencode($r['tour_postal_code']) : 0;
    2405             ($r['tour_phone_number']) ? $res[] = 'tour_phone_number='.urlencode($r['tour_phone_number']) : 0;
    2406             ($r['tour_email_address']) ? $res[] = 'tour_email_address='.urlencode($r['tour_email_address']) : 0;
    2407            
    2408             if($r['tour_group']) {
    2409                 foreach((array) $r['tour_group'] as $k => $v) {
    2410                     foreach((array) $v as $sk => $sv) {
    2411                         $res[] = 'tour_group['.$k.']['.$sk.'][first_name]='.urlencode($sv['first_name']);
    2412                         $res[] = 'tour_group['.$k.']['.$sk.'][last_name]='.urlencode($sv['last_name']);
    2413                         $res[] = 'tour_group['.$k.']['.$sk.'][phone]='.urlencode($sv['phone']);
    2414                         $res[] = 'tour_group['.$k.']['.$sk.'][email]='.urlencode($sv['email']);
    2415                    
    2416                         foreach((array) $sv['forms'] as $fk => $fv) {
    2417                             if(is_array($fv)) $fv = implode(", ", $fv); // for multiselects
    2418                             $res[] = 'tour_group['.$k.']['.$sk.'][forms]['.$fk.']='.urlencode(stripslashes($fv));
    2419                         }
    2420                     }       
    2421                 }
    2422             }
    2423            
    2424             if($r['tour_forms']) {
    2425                 foreach((array) $r['tour_forms'] as $k => $v) {
    2426                     if(is_array($v)) $v = implode(", ", $v); // for multiselects
    2427                     $res[] = 'tour_forms['.$k.']='.urlencode(stripslashes($v));
    2428                 }
    2429             }
    2430 
    2431             // leave the top part in the
    2432            
    2433             ($r['payment_method']) ? $res[] = 'payment_method='.urlencode($r['payment_method']) : 0;
    2434            
    2435             ($r['payment_method_add']) ? $res[] = 'payment_method_add='.urlencode($r['payment_method_add']) : 0;
    2436            
    2437             ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = 'tour_card_token='.urlencode($r['tour_card_token']) : 0;
    2438             ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = 'paypal_token='.urlencode($r['paypal_token']) : 0;
    2439             ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = 'paypal_payer_id='.urlencode($r['paypal_payer_id']) : 0;
    2440            
    2441             ($r['agree_terms']) ? $res[] = 'agree_terms='.urlencode($r['agree_terms']) : 0;
    2442            
    2443             ($r['review_sent']) ? $res[] = 'review_sent='.urlencode($r['review_sent']) : 0;
    2444            
    2445             ($r['marketing_consent']) ? $res[] = 'marketing_consent='.urlencode($r['marketing_consent']) : 0;
    2446            
    2447             // add in external elements
    2448             ($this->refid) ? $res['refid'] = '&refid='.$this->refid : 0;
    2449             ($this->promo_code) ? $res['promo'] = '&trigger_code='.$this->promo_code : 0;
    2450            
    2451             // add in requesting IP
    2452             $res['ip'] = $_SERVER["REMOTE_ADDR"];
    2453            
    2454             $request = '&'.implode('&', $res);
    2455            
    2456             $this->XMLRequest('commit', $request);
    2457            
    2458             return $this->commit_response;
    2459         }
    2460        
    2461         // ------------------------------------------------------------------------------
    2462         // Create an outgoing commit request based on the CART data
    2463         // ------------------------------------------------------------------------------
    2464         function sendBookingOrder($var=null, $arg=null) {
    2465             $r = ($var) ? $var : $_REQUEST;
    2466            
    2467             if($arg) $res[] = $arg; // extra API options
    2468            
    2469             if(!is_array($r['booking'])) $this->error('sendBookingOrder failed. Booking array was not found', 1);
    2470 
    2471             $res[] = '<token>'.$r['cart_token'].'</token>';
    2472            
    2473             foreach($r['booking'] as $b) {
    2474            
    2475                 $res[] = '<booking>';
    2476 
    2477                 $res[] = '<index>'.urlencode($b['index']).'</index>';
    2478                 ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('sendBookingOrder failed. book element "date" is empty', 1);
    2479                 ($b['book']) ? $res[] = '<book>'.urlencode($b['book']).'</book>' : $this->error('sendBookingOrder failed. book element "book" is empty', 1);
    2480                
    2481                 ($b['adult_num']) ? $res[] = '<adult_num>'.urlencode($b['adult_num']).'</adult_num>' : 0;
    2482                 ($b['child_num']) ? $res[] = '<child_num>'.urlencode($b['child_num']).'</child_num>' : 0;
    2483                 ($b['senior_num']) ? $res[] = '<senior_num>'.urlencode($b['senior_num']).'</senior_num>' : 0;
    2484                 ($b['price4_num']) ? $res[] = '<price4_num>'.urlencode($b['price4_num']).'</price4_num>' : 0;
    2485                 ($b['price5_num']) ? $res[] = '<price5_num>'.urlencode($b['price5_num']).'</price5_num>' : 0;
    2486                 ($b['price6_num']) ? $res[] = '<price6_num>'.urlencode($b['price6_num']).'</price6_num>' : 0;
    2487                 ($b['price7_num']) ? $res[] = '<price7_num>'.urlencode($b['price7_num']).'</price7_num>' : 0;
    2488                 ($b['price8_num']) ? $res[] = '<price8_num>'.urlencode($b['price8_num']).'</price8_num>' : 0;
    2489                 ($b['price9_num']) ? $res[] = '<price9_num>'.urlencode($b['price9_num']).'</price9_num>' : 0;
    2490                
    2491                 if($b['tour_group']) {
    2492                    
    2493                     $res[] = '<tour_group>';
    2494                    
    2495                     foreach((array) $b['tour_group'] as $k => $v) {
    2496                         foreach((array) $v as $sk => $sv) {
    2497                             $res[] = '<'.$k.' num="'.$sk.'">';
    2498                            
    2499                             $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
    2500                             $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
    2501                             $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
    2502                             $res[] = '<email>'.urlencode($sv['email']).'</email>';
    2503                            
    2504                             if(is_array($sv['forms'])) {
    2505                                 $res[] = '<forms>';
    2506                                                            
    2507                                 foreach((array) $sv['forms'] as $fk => $fv) {
    2508                                     if(is_array($fv)) $fv = implode(", ", $fv); // for multiselects
    2509                                     $res[] = '<form num="'.$fk.'">'.urlencode(stripslashes($fv)).'</form>';
    2510                                 }
    2511                                
    2512                                 $res[] = '</forms>';
    2513                             }
    2514                            
    2515                             $res[] = '</'.$k.'>';
    2516                            
    2517                         }       
    2518                     }
    2519                    
    2520                     $res[] = '</tour_group>';
    2521                    
    2522                 }
    2523                
    2524                 if($b['tour_forms']) {
    2525                     $res[] = '<tour_forms>';
    2526                
    2527                     foreach((array) $b['tour_forms'] as $k => $v) {
    2528                         if(is_array($v)) $v = implode(", ", $v); // for multiselects
    2529                         $res[] = '<form num="'.$k.'">'.urlencode(stripslashes($v)).'</form>';
    2530                     }
    2531                    
    2532                     $res[] = '</tour_forms>';
    2533                 }
    2534                
    2535                 if($b['pickup']) {
    2536                    
    2537                     $pickup_split = explode("-", stripslashes($b['pickup']));
    2538                    
    2539                     $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
    2540                     if($pickup_split[1]) $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
    2541                    
    2542                 }
    2543                
    2544                 $res[] = '</booking>';
    2545                
    2546             } // cart loop
    2547            
    2548             $res[] = '<payment>';
    2549            
    2550             ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
    2551                
    2552             ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
    2553             ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
    2554             ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
    2555             ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
    2556             ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
    2557             ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
    2558             ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
    2559             ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
    2560             ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
    2561             ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
    2562             ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
    2563            
    2564             ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
    2565            
    2566             ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
    2567            
    2568             ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
    2569             ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
    2570             ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
    2571            
    2572             ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
    2573            
    2574             ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
    2575            
    2576             ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
    2577            
    2578             ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
    2579            
    2580             // add in external elements
    2581             ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
    2582             ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
    2583            
    2584             // add in requesting IP
    2585             $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
    2586            
    2587             // add in 3DS validation fields if available
    2588             if($r['validate']) {
    2589                 $res[] = '<validate>';
    2590                 foreach((array) $r['validate'] as $validate_key => $validate_value) {
    2591                     $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
    2592                 }
    2593                 $res[] = '</validate>';
    2594             }
    2595            
    2596             // GIFT-CARD
    2597             $res[] = '<expected>'.$r['expected'].'</expected>';
    2598             ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
    2599            
    2600             $res[] = '</payment>';
    2601            
    2602             // ticketguardian
    2603             ($r['tour_tg_insurance_coverage']) ? $res[] = '<tg>'.$r['tour_tg_insurance_coverage'].'</tg>' : 0;
    2604            
    2605             ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
    2606            
    2607             $request = implode('', $res);
    2608 
    2609             $this->XMLRequest('commitOrder', $request, 1);
    2610            
    2611             return $this->commit_response;
    2612         }
    2613 
    2614         // ------------------------------------------------------------------------------
    2615         // GIFT CARD
    2616         // ------------------------------------------------------------------------------
    2617         function sendGiftOrder($request=null) {
    2618             $r = $request;
    2619             $res = array();
    2620 
    2621             if($r['rezgoAction'] != 'addGiftCard') {
    2622                 $this->error('sendGiftOrder failed. Card array was not found', 1);
    2623             }
    2624            
    2625             $res[] = '<card>';
    2626                 $res[] = '<number></number>';
    2627                 // AMOUNT
    2628                 if($r['billing_amount'] == 'custom') {
    2629                     $amnt = $r['custom_billing_amount'];
    2630                 }
    2631                 else {
    2632                     $amnt = $r['billing_amount'];
    2633                 }
    2634                 $res[] = '<amount>'.$amnt.'</amount>';
    2635                 $res[] = '<cash_value></cash_value>';
    2636                 $res[] = '<expires></expires>';
    2637                 $res[] = '<max_uses></max_uses>';
    2638                 // NAME
    2639                 $recipient_name = explode(" ", $r['recipient_name'], 2);
    2640                 $res[] = '<first_name>'.$recipient_name[0].'</first_name>';
    2641                 $res[] = '<last_name>'.$recipient_name[1].'</last_name>';
    2642                 $res[] = '<email>'.$r['recipient_email'].'</email>';
    2643                 // MSG
    2644                 $res[] = '<message>'.urlencode(htmlspecialchars_decode($r['recipient_message'], ENT_QUOTES)).'</message>';
    2645                
    2646                 $res[] = '<send>1</send>';
    2647                 $res[] = '<payment>';
    2648                    
    2649                     $res[] = '<token>'.$r['gift_card_token'].'</token>';
    2650                     if($r['payment_id']) $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>';
    2651                    
    2652                     $res[] = '<first_name>'.$r['billing_first_name'].'</first_name>';
    2653                     $res[] = '<last_name>'.$r['billing_last_name'].'</last_name>';
    2654                     $res[] = '<address_1>'.$r['billing_address_1'].'</address_1>';
    2655                     $res[] = '<address_2>'.$r['billing_address_2'].'</address_2>';
    2656                     $res[] = '<city>'.$r['billing_city'].'</city>';
    2657                     $res[] = '<state>'.$r['billing_stateprov'].'</state>';
    2658                     $res[] = '<country>'.$r['billing_country'].'</country>';
    2659                     $res[] = '<postal>'.$r['billing_postal_code'].'</postal>';
    2660                     $res[] = '<phone>'.$r['billing_phone'].'</phone>';
    2661                     $res[] = '<email>'.$r['billing_email'].'</email>';
    2662                     if($r['terms_agree'] == 'on') {
    2663                         $res[] = '<agree_terms>1</agree_terms>';
    2664                     }
    2665                     else {
    2666                         $res[] = '<agree_terms>0</agree_terms>';
    2667                     }
    2668                     $res[] = '<ip>'.$_SERVER['REMOTE_ADDR'].'</ip>';
    2669 
    2670                     // add in 3DS validation fields if available
    2671                     if($r['validate']) {
    2672                         $res[] = '<validate>';
    2673                         foreach((array) $r['validate'] as $validate_key => $validate_value) {
    2674                             $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
     1015
     1016                $c = 0;
     1017                if($xml && $xml->total != 0) {
     1018                    if($xml->total > 1) {
     1019                        foreach($xml->booking as $v) {
     1020                            $this->search_bookings_response[$this->bookings_index][$c] = $v;
     1021                            $this->search_bookings_response[$this->bookings_index][$c++]->index = $this->bookings_index;
    26751022                        }
    2676                         $res[] = '</validate>';
     1023                    } else {
     1024                        $this->search_bookings_response[$this->bookings_index][$c] = $xml->booking;
     1025                        $this->search_bookings_response[$this->bookings_index][$c++]->index = $this->bookings_index;
    26771026                    }
    2678                    
    2679                 $res[] = '</payment>';
    2680             $res[] = '</card>';
    2681 
    2682             $request = implode('', $res);
    2683            
    2684             $this->XMLRequest('addGiftCard', $request, 1);
    2685 
    2686             return $this->commit_response;
    2687         }       
    2688 
    2689         // ------------------------------------------------------------------------------
    2690         // Sign Waiver
    2691         // ------------------------------------------------------------------------------
    2692         function signWaiver($request=null) {
    2693             $r = ($request) ? $request : $_REQUEST;
    2694             $res = array();
    2695            
    2696             $birthdate = $r['pax_birthdate']['year'].'-'.sprintf('%02d', $r['pax_birthdate']['month']).'-'.sprintf('%02d', $r['pax_birthdate']['day']);
    2697            
    2698             if ($r['pax_type'] != 'general') {
    2699            
    2700                 $pax_forms = $r['pax_group'][$r['pax_type']][$r['pax_type_num']]['forms'];
    2701                
    2702                 /*$group_forms = '
    2703                     <type>'.$r['pax_type'].'</type>
    2704                     <num>'.$r['pax_type_num'].'</num>
    2705                     <forms>
    2706                 ';*/
    2707                
    2708                 foreach((array) $pax_forms as $form_id => $form_answer) {
    2709                     if(is_array($form_answer)) { // for multiselects
    2710                         $form_answer = implode(', ', $form_answer);
    2711                         $r['pax_group'][$r['pax_type']][$r['pax_type_num']]['forms'][$form_id] = $form_answer;
    2712                     }
    2713                     //$group_forms .= '<form num="'.$form_id.'">'.$form_answer.'</form>';
    2714                 }
    2715                
    2716                 /*$group_forms .= '
    2717                     </forms>
    2718                 ';*/
    2719            
    2720             }
    2721            
    2722             $group_forms = serialize($r['pax_group']);
    2723                        
    2724             $res[] = '<sign>';
    2725                 $res[] = '<type>pax</type>'; // change to dynamic later
    2726                 $res[] = '<child>'.$r['child'].'</child>';
    2727                 $res[] = '<pax_type>'.$r['pax_type'].'</pax_type>';
    2728                 $res[] = '<pax_type_num>'.$r['pax_type_num'].'</pax_type_num>';
    2729                 $res[] = '<order_code>'.$r['order_code'].'</order_code>';
    2730                 $res[] = '<trans_num>'.$r['trans_num'].'</trans_num>';
    2731                 $res[] = '<item_id>'.$r['pax_item'].'</item_id>';
    2732                 $res[] = '<pax_id>'.$r['pax_id'].'</pax_id>';
    2733                 $res[] = '<first_name>'.$r['pax_first_name'].'</first_name>';
    2734                 $res[] = '<last_name>'.$r['pax_last_name'].'</last_name>';
    2735                 $res[] = '<phone_number>'.$r['pax_phone'].'</phone_number>';
    2736                 $res[] = '<email_address>'.$r['pax_email'].'</email_address>';
    2737                 $res[] = '<birthdate>'.$birthdate.'</birthdate>';
    2738                 $res[] = '<group_forms>'.$group_forms.'</group_forms>';
    2739                 $res[] = '<waiver_text>'.$r['pax_waiver_text'].'</waiver_text>';
    2740                 $res[] = '<signature>'.str_replace('data:image/png;base64,', '', $r['pax_signature']).'</signature>';
    2741             $res[] = '</sign>';
    2742 
    2743             $request = implode('', $res);
    2744            
    2745             $this->XMLRequest('sign', $request, 1);
    2746 
    2747             return $this->signing_response;
    2748         }       
    2749 
    2750         function getGiftCard($request=null) {
    2751             if(!$request) {
    2752                 $this->error('No search argument provided, expected card number');
    2753             }
    2754 
    2755             $this->XMLRequest('searchGiftCard', $request);
    2756 
    2757             return $this->gift_card;
    2758         }
    2759 
    2760         // this function is for sending a partial commit request, it does not add any values itself
    2761         function sendPartialCommit($var=null) {
    2762             $request = '&'.$var;
    2763            
    2764             $this->XMLRequest('commit', $request);
    2765            
    2766             return $this->commit_response;
    2767         }
    2768        
    2769         // send results of contact form
    2770         function sendContact($var=null) {
    2771             $r = ($var) ? $var : $_REQUEST;
    2772            
    2773             // we use full_name instead of name because of a wordpress quirk
    2774             ($r['full_name']) ? $res[] = 'name='.urlencode($r['full_name']) : $this->error('contact element "full_name" is empty', 1);
    2775             ($r['email']) ? $res[] = 'email='.urlencode($r['email']) : $this->error('contact element "email" is empty', 1);
    2776             ($r['body']) ? $res[] = 'body='.urlencode($r['body']) : $this->error('contact element "body" is empty', 1);
    2777            
    2778             ($r['phone']) ? $res[] = 'phone='.urlencode($r['phone']) : 0;
    2779             ($r['address']) ? $res[] = 'address='.urlencode($r['address']) : 0;
    2780             ($r['address2']) ? $res[] = 'address2='.urlencode($r['address2']) : 0;     
    2781             ($r['city']) ? $res[] = 'city='.urlencode($r['city']) : 0;
    2782             ($r['state_prov']) ? $res[] = 'state_prov='.urlencode($r['state_prov']) : 0;
    2783             ($r['country']) ? $res[] = 'country='.urlencode($r['country']) : 0;
    2784 
    2785             $request = '&'.implode('&', $res);
    2786 
    2787             $this->XMLRequest('contact', $request);
    2788 
    2789             return $this->contact_response;
    2790         }
    2791        
    2792         // send review data
    2793         function sendReview($request=null) {
    2794             $r = ($request) ? $request : $_REQUEST;
    2795             $res = array();
    2796            
    2797             $res[] = '<review>';
    2798                 $res[] = '<booking>'.$r['trans_num'].'</booking>';     
    2799                 $res[] = '<rating>'.$r['rating'].'</rating>';
    2800                 $res[] = '<title><![CDATA['.urlencode(htmlspecialchars_decode($r['review_title'], ENT_QUOTES)).']]></title>';
    2801                 $res[] = '<body><![CDATA['.urlencode(htmlspecialchars_decode($r['review_body'], ENT_QUOTES)).']]></body>';
    2802             $res[] = '</review>';
    2803            
    2804             $request = implode('', $res);
    2805 
    2806             $this->XMLRequest('add_review', $request, 1);
    2807            
    2808             return $this->review_response;
    2809         }
    2810        
    2811         // get review data
    2812         function getReview($q=null, $type=null, $limit=null, $sort=null, $order=null) {
    2813            
    2814             // 'type' default is booking // 'limit' default is 5
    2815            
    2816             ($q) ? $res[] = 'q='.urlencode($q) : 0;
    2817             ($type) ? $res[] = 'type='.urlencode($type) : 0;   
    2818             ($limit) ? $res[] = 'limit='.urlencode($limit) : 0;
    2819             ($sort) ? $res[] = 'sort='.urlencode($sort) : 0;       
    2820             ($order) ? $res[] = 'order='.urlencode($order) : 0;     
    2821            
    2822             $request = implode('&', $res);
    2823 
    2824             $this->XMLRequest('review', $request);
    2825 
    2826             return $this->review_response;
    2827         }
    2828        
    2829         // get pickup list
    2830         function getPickupList($option_id=null) {
    2831            
    2832             ($option_id) ? $res[] = 'q='.urlencode($option_id) : 0;     
    2833            
    2834             $request = implode('&', $res);
    2835 
    2836             $this->XMLRequest('pickup', $request);
    2837 
    2838             return $this->pickup_response;
    2839         }
    2840        
    2841         // get pickup location
    2842         function getPickupItem($option_id=null, $pickup_id=null) {
    2843            
    2844             ($option_id) ? $res[] = 'q='.urlencode($option_id) : 0;
    2845             ($pickup_id) ? $res[] = 'pickup='.urlencode($pickup_id) : 0;   
    2846            
    2847             $request = implode('&', $res);
    2848 
    2849             $this->XMLRequest('pickup', $request);
    2850 
    2851             return $this->pickup_response->pickup;
    2852         }
    2853        
    2854         // get payment request
    2855         function getPayment($request_id=null) {
    2856            
    2857             ($request_id) ? $res[] = 'q='.urlencode($request_id) : 0;
    2858            
    2859             $request = implode('&', $res);
    2860 
    2861             $this->XMLRequest('payment', $request);
    2862            
    2863             if ($this->payment_response->error) {
    2864                 return $this->payment_response; // ->error
    2865             } else {
    2866                 return $this->payment_response->payment;
    2867             }
    2868            
    2869         }
    2870 
    2871         // sending payment
    2872         function sendPayment($var=null) {
    2873             $r = ($var) ? $var : $_REQUEST;
    2874             $res = array();
    2875 
    2876             if($r['rezgoAction'] != 'add_payment') {
    2877                 $this->error('sendPayment failed, payment array was not found', 1);
    2878             }
    2879            
    2880             $res[] = '<transaction>';
    2881                 $res[] = '<request>'.$r['request_id'].'</request>';
    2882                 $res[] = '<amount>'.$r['payment_amount'].'</amount>';
    2883                
    2884                 if (strlen($r['tour_order_code']) == 16) {
    2885                     $res[] = '<order>'.$r['tour_order_code'].'</order>';
    2886                 } else {
    2887                     $res[] = '<booking>'.$r['tour_order_code'].'</booking>';
    2888                 }
    2889                
    2890                 $res[] = '<method>Credit Cards</method>';
    2891                 $res[] = '<token>'.$r['tour_card_token'].'</token>';
    2892                
    2893                 if($r['payment_id']) $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>';
    2894                
    2895                 $res[] = '<first_name>'.$r['tour_first_name'].'</first_name>';
    2896                 $res[] = '<last_name>'.$r['tour_last_name'].'</last_name>';
    2897                 $res[] = '<email_address>'.$r['tour_email_address'].'</email_address>';
    2898                 $res[] = '<address_1>'.$r['tour_address_1'].'</address_1>';
    2899                 $res[] = '<address_2>'.$r['tour_address_2'].'</address_2>';
    2900                 $res[] = '<city>'.$r['tour_city'].'</city>';
    2901                 $res[] = '<stateprov>'.$r['tour_stateprov'].'</stateprov>';
    2902                 $res[] = '<country>'.$r['tour_country'].'</country>';
    2903                 $res[] = '<postal_code>'.$r['tour_postal_code'].'</postal_code>';
    2904                 $res[] = '<phone_number>'.$r['tour_phone_number'].'</phone_number>';
    2905                
    2906                 $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>';
    2907                 $res[] = '<ip>'.$_SERVER['REMOTE_ADDR'].'</ip>';
    2908            
    2909                 // add in 3DS validation fields if available
    2910                 if($r['validate']) {
    2911                     $res[] = '<validate>';
    2912                     foreach((array) $r['validate'] as $validate_key => $validate_value) {
    2913                         $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
     1027                }
     1028
     1029            }
     1030        }
     1031        // !i=public
     1032        if($i == 'public') {
     1033            $query = $this->secure.$this->xml_path.'&i=public&amount='.$arguments;
     1034            $xml = $this->fetchXML($query);
     1035            $this->public_response = (array) $xml->data;
     1036        }
     1037        // !i=commit
     1038        if($i == 'commit') {
     1039            $query = 'https://'.$this->xml_path.'&i=commit&cart='.$this->getCartIDs().'&'.$arguments;
     1040
     1041            $xml = $this->fetchXML($query);
     1042
     1043            if($xml) {
     1044                $this->commit_response = new stdClass();
     1045                foreach($xml as $k => $v) {
     1046                    $this->commit_response->$k = trim((string)$v);
     1047                }
     1048            }
     1049        }
     1050        // !new commit mode
     1051        if($i == 'commitOrder') {
     1052            $query = 'https://'.$this->xml_path;
     1053
     1054            $post = $this->api_post_string.urlencode('<instruction>commit</instruction><cart>'.$this->getCartIDs().'</cart>'.$arguments.'</request>');
     1055
     1056            $xml = $this->fetchXML($query, $post);
     1057
     1058            if($xml) {
     1059                $this->commit_response = new stdClass();
     1060                foreach($xml as $k => $v) {
     1061                    $this->commit_response->$k = trim((string)$v);
     1062                }
     1063            }
     1064        }
     1065        // !i=add gift card
     1066        if($i == 'addGiftCard') {
     1067            $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
     1068
     1069            $query = 'https://'.$this->xml_path;
     1070
     1071            $post = $this->api_post_string.urlencode('<instruction>add_card</instruction>'.$arguments.'</request>');
     1072
     1073            $xml = $this->fetchXML($query, $post);
     1074
     1075            if($xml) {
     1076                $this->commit_response = new stdClass();
     1077
     1078                foreach ($xml as $k => $v) {
     1079                    $this->commit_response->$k = trim((string)$v);
     1080                }
     1081            }
     1082        }
     1083        // !i=search gift card
     1084        if($i == 'searchGiftCard') {
     1085            $query = $this->secure.$this->xml_path.'&i=cards&q='.$arguments;
     1086            $res = $this->fetchXML($query);
     1087            $this->gift_card = $res;
     1088        }
     1089        // !i=contact
     1090        if($i == 'contact') {
     1091            $query = 'https://'.$this->xml_path.'&i=contact&'.$arguments;
     1092
     1093            $xml = $this->fetchXML($query);
     1094
     1095            if($xml) {
     1096                $this->contact_response = new stdClass();
     1097                foreach($xml as $k => $v) {
     1098                    $this->contact_response->$k = trim((string)$v);
     1099                }
     1100            }
     1101        }
     1102        // !i=tickets
     1103        if($i == 'tickets') {
     1104            if(!$this->ticket_response[$arguments]) {
     1105                $query = $this->secure.$this->xml_path.'&i=tickets&q='.$arguments;
     1106
     1107                $xml = $this->fetchXML($query);
     1108
     1109                if($xml) {
     1110                    $this->ticket_response[$arguments] = $xml;
     1111                }
     1112            }
     1113        }
     1114        // !i=waiver
     1115        if($i == 'waiver') {
     1116            if(!$this->waiver_response[$arguments]) {
     1117
     1118                if ($advanced == 'com') $target = '&t=com';
     1119
     1120                $query = $this->secure.$this->xml_path.'&i=waiver&q='.$arguments.$target;
     1121
     1122                $xml = $this->fetchXML($query);
     1123
     1124                if($xml) {
     1125                    $this->waiver_response[$arguments] = $xml;
     1126                }
     1127            }
     1128        }
     1129        // !i=sign
     1130        if($i == 'sign') {
     1131            $this->xml_path = REZGO_XML.'/xml?transcode='.REZGO_CID.'&key='.REZGO_API_KEY.'&req='.$this->requestID.'&g='.$this->origin;
     1132
     1133            $query = 'https://'.$this->xml_path;
     1134
     1135            $post = $this->api_post_string.urlencode('<instruction>sign</instruction>'.$arguments.'</request>');
     1136
     1137            $xml = $this->fetchXML($query, $post);
     1138
     1139            if($xml) {
     1140                $this->signing_response = new stdClass();
     1141
     1142                foreach ($xml as $k => $v) {
     1143                    $this->signing_response->$k = trim((string)$v);
     1144                }
     1145            }
     1146        }
     1147        // !i=review
     1148        if($i == 'review') {
     1149            $query = 'https://'.$this->xml_path.'&i=review&'.$arguments;
     1150
     1151            $xml = $this->fetchXML($query);
     1152
     1153            if($xml) {
     1154                $this->review_response = new stdClass();
     1155                $this->review_response = $xml;
     1156            }
     1157        }
     1158        // !i=add_review
     1159        if($i == 'add_review') {
     1160            //$query = 'https://'.$this->xml_path.'&i=add_review&'.$arguments;
     1161            $query = 'https://'.$this->xml_path;
     1162
     1163            $post = $this->api_post_string.urlencode('<instruction>add_review</instruction>'.$arguments.'</request>');
     1164
     1165            $xml = $this->fetchXML($query, $post);
     1166
     1167            if($xml) {
     1168                $this->review_response = new stdClass();
     1169                foreach($xml as $k => $v) {
     1170                    $this->review_response->$k = trim((string)$v);
     1171                }
     1172            }
     1173        }
     1174        // !i=pickup
     1175        if($i == 'pickup') {
     1176            $query = 'https://'.$this->xml_path.'&i=pickup&'.$arguments;
     1177
     1178            $xml = $this->fetchXML($query);
     1179
     1180            if($xml) {
     1181                $this->pickup_response = new stdClass();
     1182                $this->pickup_response = $xml;
     1183            }
     1184        }
     1185
     1186        // !i=add_transaction
     1187        if($i == 'add_transaction') {
     1188
     1189            $query = 'https://'.$this->xml_path;
     1190
     1191            $post = $this->api_post_string.urlencode('<instruction>add_transaction</instruction>'.$arguments.'</request>');
     1192
     1193            $xml = $this->fetchXML($query, $post);
     1194
     1195            if($xml) {
     1196                $this->commit_response = new stdClass();
     1197
     1198                foreach ($xml as $k => $v) {
     1199                    $this->commit_response->$k = trim((string)$v);
     1200                }
     1201            }
     1202        }
     1203        // !i=payment
     1204        if($i == 'payment') {
     1205            $query = 'https://'.$this->xml_path.'&i=payment&'.$arguments;
     1206
     1207            $xml = $this->fetchXML($query);
     1208
     1209            if($xml) {
     1210                $this->payment_response = new stdClass();
     1211                $this->payment_response = $xml;
     1212            }
     1213        }
     1214
     1215        if(REZGO_TRACE_XML) {
     1216            if(!$query && REZGO_INCLUDE_CACHE_XML) $query = 'called cached response';
     1217            if($query) {
     1218                $message = $i.' ( '.$query.(($post) ? '&'.$post : '').' )';
     1219                $this->debug('XML REQUEST: '.$message, $i); // pass the $i as well so we can freeze on commit
     1220            }
     1221        }
     1222    }
     1223
     1224    // ------------------------------------------------------------------------------
     1225    // Set specific data
     1226    // ------------------------------------------------------------------------------
     1227    function setTourLimit($limit, $start=null) {
     1228        $str = ($start) ? $start.','.$limit : $limit;
     1229        $this->tour_limit = $str;
     1230    }
     1231
     1232    function setRefId() {
     1233        $this->searchCart();
     1234        $this->refid = ($this->refid) ? urlencode($this->refid) : urlencode($_COOKIE['rezgo_refid_val']);
     1235    }
     1236
     1237    function setPromoCode() {
     1238        $this->searchCart();
     1239        // $this->promo_code = ($this->cart_trigger_code) ? urlencode($this->cart_trigger_code) : urlencode($_SESSION['promo']);
     1240        $this->promo_code = ($this->cart_trigger_code) ? urlencode($this->cart_trigger_code) : urlencode($_COOKIE['rezgo_promo']);
     1241    }
     1242
     1243    function setShoppingCart($array) {
     1244        $this->cart = unserialize(stripslashes($array));
     1245    }
     1246
     1247    function setPageTitle($str) {
     1248        $this->pageTitle = str_replace('_', ' ', $str);
     1249    }
     1250
     1251    function setMetaTags($str) {
     1252        $this->metaTags = $str;
     1253    }
     1254
     1255    function setCookie($name, $data='', $secure=null) {
     1256
     1257        $secure = $secure ?? $this->checkSecure();
     1258
     1259        $old_chrome = $this->config('OLD_CHROME');
     1260
     1261        $data = (is_array($data ?? '')) ? serialize($data) : $data;
     1262
     1263        if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
     1264            $path = str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR );
     1265        } else {
     1266            $path = '/';
     1267        }
     1268
     1269        $options = [
     1270            'expires' => time() + (($data) ? REZGO_CART_TTL : -3600),
     1271            'path' => $path,
     1272            'domain' => $_SERVER['SERVER_NAME'],
     1273            'secure' => $secure,
     1274            'samesite' => ($secure && !$old_chrome) ? 'None' : ''
     1275        ];
     1276
     1277        setcookie($name, $data, $options);
     1278    }
     1279
     1280    // ------------------------------------------------------------------------------
     1281    // Fetch specific data
     1282    // ------------------------------------------------------------------------------
     1283    function getSiteStatus() {
     1284        $this->XMLRequest('company');
     1285        return $this->company_response[0]->site_status;
     1286    }
     1287
     1288    function getHeader() {
     1289        $this->XMLRequest('company');
     1290        $header = $this->company_response[0]->header;
     1291        // handle the tags in the template
     1292        return $this->tag_parse($header);
     1293    }
     1294
     1295    function getFooter() {
     1296        $this->XMLRequest('company');
     1297        $footer = $this->company_response[0]->footer;
     1298        // handle the tags in the template
     1299        return $this->tag_parse($footer);
     1300    }
     1301
     1302    function getVoucherHeader() {
     1303        $this->XMLRequest('company', 'voucher');
     1304        $header = $this->company_response[0]->header;
     1305        // handle the tags in the template
     1306        return $this->tag_parse($header);
     1307    }
     1308
     1309    function getVoucherFooter() {
     1310        $this->XMLRequest('company', 'voucher');
     1311        return $this->company_response[0]->footer;
     1312    }
     1313
     1314    function getTicketHeader() {
     1315        $this->XMLRequest('company', 'ticket');
     1316        $header = $this->company_response[0]->header;
     1317        return $this->tag_parse($header);
     1318    }
     1319
     1320    function getTicketFooter() {
     1321        $this->XMLRequest('company', 'ticket');
     1322        return $this->company_response[0]->footer;
     1323    }
     1324
     1325    function getTicketContent($trans_num) {
     1326        $this->XMLRequest('tickets', $trans_num);
     1327        return $this->ticket_response[$trans_num];
     1328    }
     1329
     1330    function getWaiverContent($args=null, $target=null) {
     1331        $this->XMLRequest('waiver', $args, $target);
     1332        return $this->waiver_response[$args]->waiver;
     1333    }
     1334
     1335    function getWaiverForms($args=null) {
     1336        $this->XMLRequest('waiver', $args);
     1337        return $this->waiver_response[$args]->forms->form;
     1338    }
     1339
     1340    function getStyles() {
     1341        $this->XMLRequest('company');
     1342        return $this->company_response[0]->styles;
     1343    }
     1344
     1345    function getPageName($page) {
     1346        $this->XMLRequest('page', $page);
     1347        if ($this->page_response[$page]->error) {
     1348            return '404';
     1349        } else {
     1350            return $this->page_response[$page]->name;
     1351        }
     1352    }
     1353
     1354    function getPageContent($page) {
     1355        $this->XMLRequest('page', $page);
     1356        return $this->page_response[$page]->content;
     1357    }
     1358
     1359    function getAnalytics() {
     1360        $this->XMLRequest('company');
     1361        return $this->company_response[0]->analytics_general;
     1362    }
     1363
     1364    function getAnalyticsConversion() {
     1365        $this->XMLRequest('company');
     1366        return $this->company_response[0]->analytics_convert;
     1367    }
     1368
     1369    function getTriggerState() {
     1370        $this->XMLRequest('company');
     1371        return $this->exists($this->company_response[0]->trigger);
     1372    }
     1373
     1374    function getBookNow() {
     1375        $this->XMLRequest('company');
     1376        return $this->company_response[0]->book_now;
     1377    }
     1378
     1379    function getCartState() {
     1380        $this->XMLRequest('company');
     1381        return ((int) $this->company_response[0]->cart == 1) ? 1 : 0;
     1382    }
     1383
     1384    function getTwitterName() {
     1385        $this->XMLRequest('company');
     1386        return $this->company_response[0]->social->twitter_name;
     1387    }
     1388
     1389    function getPaymentMethods($val=null, $a=null) {
     1390        $this->company_index = ($a) ? (string) $a : 0; // handle multiple company requests for vendor
     1391        $this->XMLRequest('company');
     1392
     1393        if($this->company_response[$this->company_index]->payment->method[0]) {
     1394            foreach($this->company_response[$this->company_index]->payment->method as $v) {
     1395                $ret[] = array('name' => (string)$v, 'add' => (string)$v->attributes()->add);
     1396                if($val && $val == $v) { return 1; }
     1397            }
     1398        } else {
     1399            $ret[] = array(
     1400                'name' => (string)$this->company_response[$this->company_index]->payment->method,
     1401                'add' => (string)$this->company_response[$this->company_index]->payment->method->attributes()->add
     1402            );
     1403            if($val && $val == (string)$this->company_response[$this->company_index]->payment->method) { return 1; }
     1404        }
     1405
     1406        // if we made it this far with a $val set, return false
     1407        if($val) { return false; }
     1408        else { return $ret; }
     1409    }
     1410
     1411    function getPaymentCards($a=null) {
     1412        $this->company_index = ($a) ? (string) $a : 0;
     1413        $this->XMLRequest('company');
     1414        $split = explode(",", $this->company_response[$this->company_index]->cards);
     1415        foreach((array) $split as $v) {
     1416            if(trim($v)) $ret[] = strtolower(trim($v));
     1417        }
     1418        return $ret;
     1419    }
     1420
     1421    function getPublicPayment($amount, $add=[]) {
     1422        $string = $amount;
     1423        $string .= '&cart=' . $this->cart_token;
     1424
     1425        if($add) {
     1426            foreach((array) $add as $k => $v) {
     1427                $string .= '&add['.$k.']='.$v;
     1428            }
     1429        }
     1430
     1431        $this->XMLRequest('public', $string);
     1432        return $this->public_response;
     1433    }
     1434
     1435    function getCVV($a=null) {
     1436        $this->company_index = ($a) ? (string) $a : 0;
     1437        $this->XMLRequest('company');
     1438        return (int) $this->company_response[$this->company_index]->get_cvv;
     1439    }
     1440
     1441    function getGateway($a=null) {
     1442        $this->company_index = ($a) ? (string) $a : 0;
     1443        $this->XMLRequest('company');
     1444        return (((int) $this->company_response[$this->company_index]->using_gateway) && ($this->company_response[$this->company_index]->gateway_id != 'tmt')) ? 1 : 0;
     1445    }
     1446
     1447    function getDomain($a=null) {
     1448        $this->company_index = ($a) ? (string) $a : 0;
     1449        $this->XMLRequest('company');
     1450        return $this->company_response[$this->company_index]->domain;
     1451    }
     1452
     1453    function getCompanyName($a=null) {
     1454        $this->company_index = ($a) ? (string) $a : 0;
     1455        $this->XMLRequest('company');
     1456        return $this->company_response[$this->company_index]->company_name;
     1457    }
     1458
     1459    function getCompanyCountry($a=null) {
     1460        $this->company_index = ($a) ? (string) $a : 0;
     1461        $this->XMLRequest('company');
     1462        return $this->company_response[$this->company_index]->country;
     1463    }
     1464
     1465    function getCompanyPaypal($a=null) {
     1466        $this->company_index = ($a) ? (string) $a : 0;
     1467        $this->XMLRequest('company');
     1468        return $this->company_response[$this->company_index]->paypal_email;
     1469    }
     1470
     1471    function getCompanyDetails($a=null) {
     1472        $this->company_index = ($a) ? (string) $a : 0;
     1473        $this->XMLRequest('company');
     1474        return $this->company_response[$this->company_index];
     1475    }
     1476
     1477    // get a list of calendar data
     1478    function getCalendar($item_id, $date=null) {
     1479        if(!$date) { // no date? set a default date (today)
     1480            $date = $default_date = strtotime(date("Y-m-15"));
     1481            $available = ',available'; // get first available date from month API
     1482        } else {
     1483            $date = date("Y-m-15", strtotime($date));
     1484            $date = strtotime($date);
     1485        }
     1486
     1487        // $promo = ($this->promo_code) ? '&trigger_code='.$this->promo_code : '';
     1488        $promo = ($this->promo_code != ' ' ) ? '&trigger_code='.$this->promo_code : '';
     1489
     1490        $query = $this->secure.$this->xml_path.'&i=month&q='.$item_id.'&d='.date("Y-m-d", $date).'&a=group'.$available.$promo;
     1491
     1492        $xml = $this->fetchXML($query);
     1493
     1494        if(REZGO_TRACE_XML) {
     1495            if($query) {
     1496                $message = 'month'.' ( '.$query.' )';
     1497                $this->debug('XML REQUEST: '.$message, 'month');
     1498            }
     1499        }
     1500
     1501        // update the date with the one provided from the API response
     1502        // this is done in case we hopped ahead with the API search (a=available)
     1503        $date = $xml->year.'-'.$xml->month.'-15';
     1504
     1505        $year = date("Y", strtotime($date));
     1506        $month = date("m", strtotime($date));
     1507
     1508        $date = $base_date = date("Y-m-15", strtotime($date));
     1509        $date = strtotime($date);
     1510
     1511        $next_partial = date("Y-m", strtotime($base_date.' +1 month'));
     1512        $prev_partial = date("Y-m", strtotime($base_date.' -1 month'));
     1513
     1514        $this->calendar_next = $next_date = date("Y-m-d", strtotime($base_date.' +1 month'));
     1515        $this->calendar_prev = $prev_date = date("Y-m-d", strtotime($base_date.' -1 month'));
     1516
     1517
     1518        $this->calendar_name = (string) $xml->name;
     1519        $this->calendar_com = (string) $xml->com;
     1520        $this->calendar_active = (int) $xml->active;
     1521
     1522        $days = array('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat');
     1523
     1524        $months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
     1525
     1526        $start_day = 1;
     1527        $end_day = date("t", $date);
     1528
     1529        $start_dow = date("D", strtotime(date("Y-m-1", $date)));
     1530
     1531        $n = 0;
     1532        foreach($months as $k => $v) {
     1533            $this->calendar_months[$n] = new stdClass();
     1534            $this->calendar_months[$n]->selected = ($v == date("F", $date)) ? 'selected' : '';
     1535            $this->calendar_months[$n]->value = $year.'-'.$v.'-15';
     1536            $this->calendar_months[$n]->label = $k;
     1537            $n++;
     1538        }
     1539
     1540        for($y=date("Y", strtotime(date("Y").' -1 year')); $y<=date("Y", strtotime(date("Y").' +4 years')); $y++) {
     1541            $this->calendar_years[$n] = new stdClass();
     1542            $this->calendar_years[$n]->selected = ($y == date("Y", $date)) ? 'selected' : '';
     1543            $this->calendar_years[$n]->value = $y.'-'.$month.'-15';
     1544            $this->calendar_years[$n]->label = $y;
     1545            $n++;
     1546        }
     1547
     1548        $c = 0;
     1549        foreach($days as $v) {
     1550            $c++;
     1551            if($start_dow == $v) $start_offset = $c;
     1552        }
     1553
     1554        if($start_offset) {
     1555            // this will display the lead-up days from last month
     1556            $last_display = date("t", strtotime($prev_date)) - ($start_offset-2);
     1557
     1558            for($d=1; $d<$start_offset; $d++) {
     1559                $obj = isset($obj) ? $obj : new stdClass();
     1560                $obj->day = $last_display;
     1561                $obj->lead = 1; // mark as lead up day, so it's not counted in getCalendarDays($day) calls
     1562                $this->calendar_days[] = $obj;
     1563                $last_display++;
     1564                unset($obj);
     1565            }
     1566        }
     1567
     1568        $w = $start_offset;
     1569        for($d=1; $d<=$end_day; $d++) {
     1570            $obj = isset($obj) ? $obj : new stdClass();
     1571
     1572            $xd = $d - 1;
     1573            $obj->type = 1;
     1574
     1575            if($xml->day->$xd) {
     1576                $obj->cond = $cond = (string) $xml->day->$xd->attributes()->condition;
     1577                if($xml->day->$xd->item[0]) {
     1578                    // we want to convert the attribute to something easier to use in the template
     1579                    $n=0;
     1580                    foreach($xml->day->$xd->item as $i) {
     1581                        if($i) {
     1582                            $obj->items[$n] = new stdClass();
     1583                            $obj->items[$n]->uid = $i->uid;
     1584                            $obj->items[$n]->name = $i->name;
     1585                            $obj->items[$n]->availability = $i->attributes()->value;
     1586                            $n++;
     1587                        }
    29141588                    }
    2915                     $res[] = '</validate>';
    2916                 }
    2917                
    2918             $res[] = '</transaction>';
    2919            
    2920             $request = implode('', $res);
    2921            
    2922             $this->XMLRequest('add_transaction', $request, 1);
    2923 
    2924             return $this->commit_response;
    2925         }       
    2926        
    2927         // add an item to the shopping cart
    2928         function addToCart($item, $clear=0) {
    2929 
    2930             if(!$clear) {
    2931                 // don't load the existing cart if we are clearing it
    2932                 if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
    2933                 elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
    2934 
    2935                 // load the existing cart -- CART API
    2936                 if($_COOKIE['rezgo_cart_token_'.REZGO_CID]){
    2937                     $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
    2938                 }
    2939             }
    2940 
    2941             if ($cart_token){
    2942 
    2943                 $res = array();
    2944                 $res[] = '<cart>'.$cart_token.'</cart>';
    2945                 $res[] = '<action>add</action>';
    2946 
    2947                 $request = implode('', $res);
    2948 
    2949                 $this->XMLRequest('cart', $request, 1);
    2950 
    2951                 $this->cart_response;
    2952 
    2953                 $tour = $this->cart_response;
    2954 
    2955                 $contents = $tour->contents;
    2956                 $decode = json_decode($contents, true);
    2957 
    2958                 // add the new item to the cart
    2959                 foreach((array) $decode as $v) {
    2960                    
    2961                     // at least 1 price point must be set to add this item
    2962                     // this works to remove items as well, if they match the date (above) but have no prices set
    2963                     if(
    2964                         $v['adult_num'] || $v['child_num'] || $v['senior_num'] ||
    2965                         $v['price4_num'] || $v['price5_num'] || $v['price6_num'] ||
    2966                         $v['price7_num'] || $v['price8_num'] || $v['price9_num']
    2967                     ) {
    2968                         $cart[] = $v;
    2969                     }
    2970                 }
    2971                
    2972             }
    2973                
    2974             return $cart;
    2975         }
    2976        
    2977         // add an item to the shopping cart
    2978         function editCart($item) {
    2979            
    2980             // load the existing cart
    2981             if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
    2982             elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
    2983 
    2984             // load the existing cart -- CART API
    2985             if($_COOKIE['rezgo_cart_token_'.REZGO_CID]){
    2986                 $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
    2987             }
    2988 
    2989             // add the new item to the cart
    2990             foreach((array) $item as $k => $v) {
    2991                
    2992                 if($cart[$k]) {
    2993                
    2994                     // at least 1 price point must be set to edit this item
    2995                     // this works to remove items as well, if they match the date (above) but have no prices set
    2996                     if(
    2997                         $v['adult_num'] || $v['child_num'] || $v['senior_num'] ||
    2998                         $v['price4_num'] || $v['price5_num'] || $v['price6_num'] ||
    2999                         $v['price7_num'] || $v['price8_num'] || $v['price9_num']
    3000                     ) {
    3001                         $cart[$k] = $v;
    3002                     } else {
    3003                         unset($cart[$k]);
    3004                     }
    3005                
    3006                 }
    3007             }
    3008            
    3009             return $cart;
    3010         }
    3011        
    3012         // add pickup to the shopping cart
    3013         function pickupCart($index, $pickup) {
    3014            
    3015             // load the existing cart
    3016             if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
    3017             elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
    3018                
    3019             if($cart[$index]) {
    3020                
    3021                 $cart[$index]['pickup'] = $pickup;
    3022            
    3023                 // update cart
    3024                 $ttl = (REZGO_CART_TTL > 0 || REZGO_CART_TTL === 0) ? REZGO_CART_TTL : 86400;
    3025 
    3026                     if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
    3027                         setcookie("rezgo_cart_".REZGO_CID, serialize($cart), time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['SERVER_NAME']);
    3028                     } else {
    3029                         setcookie("rezgo_cart_".REZGO_CID, serialize($cart), time() + $ttl, '/', $_SERVER['SERVER_NAME']);
    3030                     }
    3031                
    3032                 $this->setShoppingCart(serialize($cart));
    3033            
    3034             }
    3035            
    3036             return $cart;
    3037         }
    3038        
    3039         function clearCart() {
    3040             unset($_SESSION['rezgo_cart_'.REZGO_CID]);
    3041             unset($_COOKIE['rezgo_cart_'.REZGO_CID]);
    3042             unset($_SESSION['cart_status']);
    3043 
    3044             $this->setCookie("rezgo_cart_".REZGO_CID, '');
    3045             $this->setCookie("rezgo_cart_token_".REZGO_CID, '');
    3046 
    3047             if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
    3048                 setcookie("rezgo_cart_".REZGO_CID, '', 1, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['SERVER_NAME']);
    3049             } else {
    3050                 setcookie("rezgo_cart_".REZGO_CID, '', 1, '/', $_SERVER['HTTP_HOST']);
    3051             }
    3052            
    3053         }
    3054        
    3055         // get a list of all the item IDs that are currently in the cart (used for search queries)
    3056         function getCartIDs() {
    3057             $n = 1;
    3058             if(is_array($this->cart)) {
    3059                 foreach($this->cart as $k => $v) {
    3060                     $ids[] = $v['uid'];
    3061                     $n++;
    3062                 }
    3063                 $ids = ($ids) ? implode(",", $ids) : '';
    3064             }
    3065             return $ids;
    3066         }
    3067 
    3068         // fetch the full shopping cart including detailed tour info
    3069         function getCart($hide=null) {
    3070 
    3071             // check if there is a cart token in URL, and if it matches current cart
    3072             $request_token = $_REQUEST['cart'];
    3073             $current_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
    3074 
    3075             if ( $request_token && (!isset($current_token)) ){
    3076                 $this->setCookie('rezgo_cart_token_'.REZGO_CID, $request_token);
    3077                 $this->searchToken($request_token);
    3078                
    3079                 $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/'.$_REQUEST['wp_slug'] . '/order');
    3080 
    3081             }
    3082             else if ($request_token) {
    3083                 if ($request_token != $current_token){
    3084 
    3085                     // clear all previous cart contents
    3086                     $this->clearCart();
    3087                     $this->clearCartState();
    3088 
    3089                     $this->setCookie('rezgo_cart_token_'.REZGO_CID, $request_token);
    3090                     $this->searchToken($request_token);
    3091 
    3092                     $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/'.$_REQUEST['wp_slug'] . '/order');
    3093                 }
    3094                 else {
    3095                     $this->cart_token = $current_token;
    3096                 }
    3097             }
    3098             else {
    3099                 $this->cart_token = $current_token;
    3100             }
    3101 
    3102             $cart = $this->cart;
    3103 
    3104             $c = 0;
    3105             foreach ($cart as $item) {
    3106                 $cart[$c++]->booking_date = strtotime((string)$item->date[0]->attributes()->value);
    3107             }
    3108 
    3109             return (array) $cart;
    3110         }
    3111 
    3112         function getFormDisplay(){
    3113             return $this->form_display;
    3114         }
    3115 
    3116         function getGroupFormDisplay(){
    3117             return $this->gf_form_display;
    3118         }
    3119 
    3120         function getCartTotal(){
    3121             return (string) $this->cart_total;
    3122         }
    3123 
    3124         function getCartStatus(){
    3125             return $this->cart_status;
    3126         }
    3127 
    3128         function clearCartState(){
    3129             unset($_SESSION['cart_status']);
    3130             echo '<script>localStorage.clear();</script>';
    3131         }
    3132 
    3133         //*********************//
    3134         //********** CART API       
    3135         //*********************//
    3136 
    3137         function cartRequest($action, $args='') {
    3138            
    3139             $this->setCartToken();
    3140            
    3141             if(!$this->cart_token && $action == 'search') return false;
    3142            
     1589                } else {
     1590                    if($xml->day->$xd->item) {
     1591                        $obj->items[0] = new stdClass();
     1592                        $obj->items[0]->uid = $xml->day->$xd->item->uid;
     1593                        $obj->items[0]->name = $xml->day->$xd->item->name;
     1594                        $obj->items[0]->availability = $xml->day->$xd->item->attributes()->value;
     1595                    }
     1596                }
     1597            }
     1598
     1599            $obj->date = strtotime($year.'-'.$month.'-'.$d);
     1600
     1601            $obj->day = $d;
     1602            $this->calendar_days[] = $obj;
     1603            unset($obj);
     1604
     1605            if($w == 7) { $w = 1; } else { $w++; }
     1606        }
     1607
     1608        if($w != 8 && $w != 1) {
     1609            $d = 0;
     1610            // this will display the lead-out days for next month
     1611            while($w != 8) {
     1612                $d++;
     1613                $w++;
     1614                $obj = isset($obj) ? $obj : new stdClass();
     1615                $obj->day = $d;
     1616                $this->calendar_days[] = $obj;
     1617                unset($obj);
     1618            }
     1619        }
     1620    }
     1621
     1622    function getCalendarActive() {
     1623        return $this->calendar_active;
     1624    }
     1625
     1626    function getCalendarPrev() {
     1627        return $this->calendar_prev;
     1628    }
     1629
     1630    function getCalendarNext() {
     1631        return $this->calendar_next;
     1632    }
     1633
     1634    function getCalendarMonths() {
     1635        return $this->calendar_months;
     1636    }
     1637
     1638    function getCalendarYears() {
     1639        return $this->calendar_years;
     1640    }
     1641
     1642    function getCalendarDays($day=null) {
     1643        if($day) {
     1644            foreach($this->calendar_days as $v) {
     1645                if((int)$v->day == $day && !(int)$v->lead) {
     1646                    $day_response = $v; break;
     1647                }
     1648            }
     1649
     1650            return (object) $day_response;
     1651        } else {
     1652            return $this->calendar_days;
     1653        }
     1654    }
     1655
     1656    function getCalendarId() {
     1657        return $this->calendar_com;
     1658    }
     1659
     1660    function getCalendarName() {
     1661        return $this->calendar_name;
     1662    }
     1663
     1664    function getCalendarDiff($date1, $date2) {
     1665        // $date1 and $date2 must have format: Y-M-D
     1666
     1667        $date1 = new DateTime($date1);
     1668        $date2 = new DateTime($date2);
     1669        $interval = $date1->diff($date2);
     1670
     1671        $res = '';
     1672
     1673        if($interval->y > 0) $res .= $interval->y . ' year' . (($interval->y > 1) ? 's' : '') . (($interval->y > 0)?', ':'');
     1674        if($interval->m > 0) $res .= $interval->m . ' month' . (($interval->m > 1) ? 's' : '') . (($interval->m > 0)?', ':'');
     1675        if($interval->d > 0) $res .= $interval->d . ' day' . (($interval->d > 1) ? 's' : '');
     1676
     1677        return $res;
     1678    }
     1679
     1680    // get a list of tour data
     1681    function getTours($a=null, $node=null) {
     1682        // generate the search string
     1683        // if no search is specified, find searched items (grouped)
     1684        if(!$a || $a == $_REQUEST) {
     1685            if($this->requestStr('search_for')) $str .= ($this->requestStr('search_in')) ? '&t='.urlencode($this->requestStr('search_in')) : '&t=smart';
     1686            if($this->requestStr('search_for')) $str .= '&q='.urlencode(stripslashes($this->requestStr('search_for')));
     1687            if($this->requestStr('tags')) $str .= '&f[tags]='.urlencode($this->requestStr('tags'));
     1688
     1689            if($this->requestNum('cid')) $str .= '&f[cid]='.urlencode($this->requestNum('cid')); // vendor only
     1690
     1691            // details pages
     1692            if($this->requestNum('com')) $str .= '&t=com&q='.urlencode($this->requestNum('com'));
     1693            if($this->requestNum('uid')) $str .= '&t=uid&q='.urlencode($this->requestNum('uid'));
     1694            if($this->requestStr('option')) $str .= '&t=uid&q='.urlencode($this->requestStr('option'));
     1695            if($this->requestStr('date')) $str .= '&d='.urlencode($this->requestStr('date'));
     1696
     1697            $a = ($a) ? $a : 'a=group'.$str;
     1698        }
     1699
     1700        // $promo = ($this->promo_code) ? '&trigger_code='.$this->promo_code : '';
     1701        $promo = ($this->promo_code != ' ' ) ? '&trigger_code='.$this->promo_code : '';
     1702
     1703        $limit = '&limit='.$this->tour_limit;
     1704
     1705        // attach the search as an index including the limit value and promo code
     1706        $this->tours_index = $a.$promo.$limit;
     1707
     1708        $this->XMLRequest('search');
     1709
     1710        $return = ($node === null) ? (array) $this->search_response[$this->tours_index] : $this->search_response[$this->tours_index][$node];
     1711
     1712        return $return;
     1713    }
     1714
     1715    function getTourAvailability(&$obj=null, $start=null, $end=null) {
     1716        if(!$obj) $obj = $this->getItem();
     1717
     1718        // check the object, create a list of com ids
     1719        // search the API with those ids and the date search
     1720        // create a list of dates and relevant options to return
     1721
     1722        $loop = (string) $obj->index;
     1723
     1724        $d[] = ($start) ? date("Y-M-d", strtotime($start)) : date("Y-M-d", strtotime($this->requestStr(start_date)));
     1725        $d[] = ($end) ? date("Y-M-d", strtotime($end)) : date("Y-M-d", strtotime($this->requestStr(end_date)));
     1726        if($d) { $d = implode(',', $d); } else { return false; }
     1727
     1728        if(!$this->tour_availability_response[$loop])   {
     1729            if($this->search_response[$loop]) {
     1730                foreach((array)$this->search_response[$loop] as $v) {
     1731                    $uids[] = (string)$v->com;
     1732                }
     1733
     1734                $this->tours_index = 't=com&q='.implode(',', array_unique($uids)).'&d='.$d;
     1735
     1736                $this->XMLRequest('search');
     1737
     1738                $c=0;
     1739                foreach((array)$this->search_response[$this->tours_index] as $i) {
     1740                    if($i->date) {
     1741                        if($i->date[0]) {
     1742                            foreach($i->date as $d) {
     1743                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)] = new stdClass();
     1744
     1745                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->id = $c;
     1746
     1747                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c] = new stdClass();
     1748
     1749                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->name = (string)$i->time;
     1750                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->availability = (string)$d->availability;
     1751                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c]->hide_availability = (string)$d->hide_availability;
     1752                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->items[$c++]->uid = (string)$i->uid;
     1753                                $res[(string)$i->com][strtotime((string)$d->attributes()->value)]->date = strtotime((string)$d->attributes()->value);
     1754                            }
     1755                        } else {
     1756                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)] = new stdClass();
     1757
     1758                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->id = $c;
     1759
     1760                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c] = new stdClass();
     1761
     1762                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->name = (string)$i->time;
     1763                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->availability = (string)$i->date->availability;
     1764                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c]->hide_availability = (string)$i->date->hide_availability;
     1765                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->items[$c++]->uid = (string)$i->uid;
     1766                            $res[(string)$i->com][strtotime((string)$i->date->attributes()->value)]->date = strtotime((string)$i->date->attributes()->value);
     1767                        }
     1768
     1769                        // sort by date so the earlier dates always appear first, the api will return them in that order
     1770                        // but if the first item found has a later date than a subsequent item, the dates will be out of order
     1771                        ksort($res[(string)$i->com]);
     1772                    }
     1773                }
     1774                $this->tour_availability_response[$loop] = $res;
     1775            }
     1776        }
     1777
     1778        return (array) $this->tour_availability_response[$loop][(string)$obj->com];
     1779    }
     1780
     1781    function getTourPrices(&$obj=null) {
     1782        if(!$obj) $obj = $this->getItem();
     1783        $com = (string) $obj->com;
     1784
     1785        $c=0;
     1786        $all_required = 0;
     1787        $valid_count = 0;
     1788        $strike_prices = array();
     1789
     1790        foreach ($obj->prices->price as $price) {
     1791            if($price->strike) {
     1792                $strike_prices[(int) $price->id] = (string) $price->strike;
     1793            }
     1794        }
     1795
     1796        if($this->exists($obj->date->price_adult)) {
     1797            $ret[$c] = new stdClass();
     1798            $ret[$c]->name = 'adult';
     1799            $ret[$c]->label = (string) $obj->adult_label;
     1800            $ret[$c]->required = (string) $obj->adult_required;
     1801            if($ret[$c]->required) $all_required++;
     1802            ($obj->date->base_prices->price_adult) ? $ret[$c]->base = (string) $obj->date->base_prices->price_adult : 0;
     1803            $ret[$c]->price = (string) $obj->date->price_adult;
     1804            $ret[$c]->strike = $strike_prices[1];
     1805            $ret[$c]->count = (string) $obj->prices->price[0]->count;
     1806            $ret[$c++]->total = (string) $obj->total_adult;
     1807            $valid_count++;
     1808        }
     1809        if($this->exists($obj->date->price_child)) {
     1810            $ret[$c] = new stdClass();
     1811            $ret[$c]->name = 'child';
     1812            $ret[$c]->label = (string) $obj->child_label;
     1813            $ret[$c]->required = (string) $obj->child_required;
     1814            if($ret[$c]->required) $all_required++;
     1815            ($obj->date->base_prices->price_child) ? $ret[$c]->base = (string) $obj->date->base_prices->price_child : 0;
     1816            $ret[$c]->price = (string) $obj->date->price_child;
     1817            $ret[$c]->strike = $strike_prices[2];
     1818            $ret[$c]->count = (string) $obj->prices->price[1]->count;
     1819            $ret[$c++]->total = (string) $obj->total_child;
     1820            $valid_count++;
     1821        }
     1822        if($this->exists($obj->date->price_senior)) {
     1823            $ret[$c] = new stdClass();
     1824            $ret[$c]->name = 'senior';
     1825            $ret[$c]->label = (string) $obj->senior_label;
     1826            $ret[$c]->required = (string) $obj->senior_required;
     1827            if($ret[$c]->required) $all_required++;
     1828            ($obj->date->base_prices->price_senior) ? $ret[$c]->base = (string) $obj->date->base_prices->price_senior : 0;
     1829            $ret[$c]->price = (string) $obj->date->price_senior;
     1830            $ret[$c]->strike = $strike_prices[3];
     1831            $ret[$c]->count = (string) $obj->prices->price[2]->count;
     1832            $ret[$c++]->total = (string) $obj->total_senior;
     1833            $valid_count++;
     1834        }
     1835
     1836        $j=3;
     1837        for($i=4; $i<=9; $i++) {
     1838            $val = 'price'.$i;
     1839            if($this->exists($obj->date->$val)) {
     1840                $ret[$c] = new stdClass();
     1841                $ret[$c]->name = 'price'.$i;
     1842                $val = 'price'.$i.'_label';
     1843                $ret[$c]->label = (string) $obj->$val;
     1844                $val = 'price'.$i.'_required';
     1845                $ret[$c]->required = (string) $obj->$val;
     1846                if($ret[$c]->required) $all_required++;
     1847                $val = 'price'.$i;
     1848                ($obj->date->base_prices->$val) ? $ret[$c]->base = (string) $obj->date->base_prices->$val : 0;
     1849                $ret[$c]->price = (string) $obj->date->$val;
     1850                $ret[$c]->strike = $strike_prices[$i];
     1851                $val = 'total_price'.$i;
     1852                $ret[$c]->count = (string) $obj->prices->price[$j]->count;
     1853                $ret[$c++]->total = (string) $obj->$val;
     1854                $valid_count++;
     1855            }
     1856            $j++;
     1857        }
     1858
     1859        // if the total required count is the same as the total price points, or if no prices are required
     1860        // we want to set the all_required flag so that the parser won't display individual required marks
     1861        if($all_required == $valid_count || $all_required == 0) {
     1862            $this->all_required = 1;
     1863        } else {
     1864            $this->all_required = 0;
     1865        }
     1866
     1867        return (array) $ret;
     1868    }
     1869
     1870    function getTourBundles(&$obj=null) {
     1871
     1872        if(!$obj) $obj = $this->getItem();
     1873        $com = (string) $obj->com;
     1874
     1875        $c = 0;
     1876
     1877        $bundle_prices = array();
     1878
     1879        if(isset($obj->bundles)) {
     1880
     1881            foreach ($obj->bundles->bundle as $bundle) {
     1882
     1883                $ret[$c] = new stdClass();
     1884
     1885                if ($this->exists($bundle->name) && $this->exists($bundle->price)) { // bundles must have a name and a price
     1886
     1887                    $ret[$c]->id = $c + 1;
     1888                    $ret[$c]->name = $bundle->name;
     1889
     1890                    $ret[$c]->label = $this->seoEncode($bundle->name);
     1891
     1892                    $ret[$c]->price = $bundle->price;
     1893                    $ret[$c]->visible = $bundle->visible;
     1894                    $ret[$c]->pax = $bundle->pax;
     1895
     1896                    unset($bundle_prices);
     1897                    $bundle_makeup = '';
     1898                    $bundle_total = 0;
     1899
     1900                    foreach ($bundle->pax->price as $count) {
     1901
     1902                        $bundle_total += (int) $count;
     1903
     1904                        if ($count['id'] == 1) {
     1905
     1906                            $bundle_makeup .= $count . ' ' . $obj->adult_label . ', ';
     1907                            $bundle_prices['adult'] = (string) $count;
     1908
     1909                        } elseif ($count['id'] == 2) {
     1910
     1911                            $bundle_makeup .= $count . ' ' . $obj->child_label . ', ';
     1912                            $bundle_prices['child'] = (string) $count;
     1913
     1914                        } elseif ($count['id'] == 3) {
     1915
     1916                            $bundle_makeup .= $count . ' ' . $obj->senior_label . ', ';
     1917                            $bundle_prices['senior'] = (string) $count;
     1918
     1919                        } else {
     1920
     1921                            $price_label = 'price'.$count['id'].'_label';
     1922                            $bundle_makeup .= $count . ' ' . $obj->$price_label . ', ';
     1923                            $bundle_prices['price'.$count['id']] = (string) $count;
     1924
     1925                        }
     1926
     1927                    }
     1928
     1929                    $bundle_makeup = rtrim($bundle_makeup, ', ');
     1930                    $ret[$c]->makeup = $bundle_makeup;
     1931
     1932                    $ret[$c]->prices = $bundle_prices;
     1933
     1934                    $ret[$c]->total = $bundle_total;
     1935
     1936                    $c++;
     1937
     1938                }
     1939
     1940            }
     1941
     1942        }
     1943
     1944        return (array) $ret;
     1945    }
     1946
     1947    function getTourRequired() {
     1948        return ($this->all_required) ? 0 : 1;
     1949    }
     1950
     1951    function getTourPriceNum(&$obj=null, $order=null) {
     1952        if(!$obj) $obj = $this->getItem();
     1953        // get the value from either the order object or the _REQUEST var
     1954        $val = (is_object($order)) ? $order->{$obj->name.'_num'} : $_REQUEST[$obj->name.'_num'];
     1955        for($n=1; $n<=$val; $n++) {
     1956            $ret[] = $n;
     1957        }
     1958        return (array) $ret;
     1959    }
     1960
     1961    function getTourTags(&$obj=null) {
     1962        if(!$obj) $obj = $this->getItem();
     1963        if($this->exists($obj->tags)) {
     1964            $split = explode(',', $obj->tags);
     1965            foreach((array) $split as $v) {
     1966                $ret[] = trim($v);
     1967            }
     1968        }
     1969        return (array) $ret;
     1970    }
     1971
     1972    function getTourLocations(&$obj=null) {
     1973        if(!$obj) $obj = $this->getItem();
     1974        $c = 0;
     1975        if($obj->additional_locations->location) {
     1976            if(!$obj->additional_locations->location[0]) {
     1977                $ret[$c]->country = $obj->additional_locations->location->loc_country;
     1978                $ret[$c]->state = $obj->additional_locations->location->loc_state;
     1979                $ret[$c++]->city = $obj->additional_locations->location->loc_city;
     1980            } else {
     1981                foreach($obj->additional_locations->location as $v) {
     1982                    $ret[$c]->country = $v->loc_country;
     1983                    $ret[$c]->state = $v->loc_state;
     1984                    $ret[$c++]->city = $v->loc_city;
     1985                }
     1986            }
     1987        }
     1988        return (array) $ret;
     1989    }
     1990
     1991    function getTourMedia(&$obj=null) {
     1992        if(!$obj) $obj = $this->getItem();
     1993        $c = 0;
     1994        if($obj->media->image) {
     1995            foreach($obj->media->image as $v) {
     1996                $ret[$c] = new stdClass();
     1997                $ret[$c]->image = $v->path;
     1998                $ret[$c]->path = $v->path;
     1999                $ret[$c]->caption = $v->caption;
     2000                $ret[$c++]->type = 'image';
     2001            }
     2002            return (array) $ret;
     2003        } else { return false; }
     2004    }
     2005
     2006    function getTourRelated(&$obj=null) {
     2007        if(!$obj) $obj = $this->getItem();
     2008        $c = 0;
     2009        if($obj->related->items) {
     2010            foreach($obj->related->items->item as $v) {
     2011                $ret[$c] = new stdClass();
     2012
     2013                $ret[$c]->com = $v->com;
     2014                $ret[$c]->image = $v->image;
     2015                $ret[$c]->starting = $v->starting;
     2016                $ret[$c]->overview = $v->overview;
     2017                $ret[$c++]->name = $v->name;
     2018            }
     2019            return (array) $ret;
     2020        } else { return false; }
     2021    }
     2022
     2023    function getCrossSell(&$obj=null) {
     2024        if(!$obj) $obj = $this->getItem();
     2025        $c = 0;
     2026        if($obj->cross->items) {
     2027            foreach($obj->cross->items->item as $v) {
     2028                $ret[$c] = new stdClass();
     2029
     2030                $ret[$c]->com = $v->com;
     2031                $ret[$c]->image = $v->image;
     2032                $ret[$c]->starting = $v->starting;
     2033                $ret[$c]->overview = $v->overview;
     2034                $ret[$c++]->name = $v->name;
     2035            }
     2036            return (array) $ret;
     2037        } else { return false; }
     2038    }
     2039
     2040    function getCrossSellText(&$obj=null) {
     2041        if(!$obj) $obj = $this->getItem();
     2042
     2043        if($obj->cross) {
     2044
     2045            $ret = new stdClass();
     2046
     2047            $ret->title = $obj->cross->title;
     2048            $ret->desc = $obj->cross->desc;
     2049
     2050            return $ret;
     2051        } else { return false; }
     2052    }
     2053
     2054    function getTourLineItems(&$obj=null) {
     2055        if(!$obj) $obj = $this->getItem();
     2056
     2057        if($obj->line_items) {
     2058            if($obj->line_items->line_item[0]) {
     2059                foreach($obj->line_items->line_item as $v) {
     2060                    $ret[] = $v;
     2061                }
     2062            } else {
     2063                $ret[] = $obj->line_items->line_item;
     2064            }
     2065        }
     2066
     2067        return (array) $ret;
     2068    }
     2069
     2070    function getTourForms($type='primary', &$obj=null) {
     2071        if(!$obj) $obj = $this->getItem();
     2072        $com = (string) $obj->com;
     2073        $uid = (string) $obj->uid;
     2074
     2075        $type = strtolower($type);
     2076        if($type != 'primary' && $type != 'group') $this->error('unknown type, expecting "primary" or "group"');
     2077
     2078        if(!$this->tour_forms[$com.'-'.$uid][$type]) {
     2079            if($obj->{$type.'_forms'}) {
     2080
     2081                foreach($obj->{$type.'_forms'}->form as $f) {
     2082                    $res[$type][(string)$f->id] = new stdClass();
     2083
     2084                    $res[$type][(string)$f->id]->id = (string)$f->id;
     2085                    $res[$type][(string)$f->id]->type = (string)$f->type;
     2086                    $res[$type][(string)$f->id]->title = (string)$f->title;
     2087                    $res[$type][(string)$f->id]->require = (string)$f->require;
     2088                    $res[$type][(string)$f->id]->value = (string)$f->value;
     2089                    $res[$type][(string)$f->id]->instructions = (string)$f->instructions;
     2090
     2091                    if((string)$f->price) {
     2092                        if(strpos((string)$f->price, '-') !== false) {
     2093                            $res[$type][(string)$f->id]->price = str_replace("-", "", (string)$f->price);
     2094                            $res[$type][(string)$f->id]->price_mod = '-';
     2095                        } else {
     2096                            $res[$type][(string)$f->id]->price = str_replace("+", "", (string)$f->price);
     2097                            $res[$type][(string)$f->id]->price_mod = '+';
     2098                        }
     2099                    }
     2100
     2101                    if((string)$f->options) {
     2102                        $opt = explode(",", (string)$f->options);
     2103                        foreach((array)$opt as $v) {
     2104                            $res[$type][(string)$f->id]->options[] = $v;
     2105                        }
     2106                    }
     2107
     2108                    if((string)$f->options_instructions) {
     2109                        $opt_inst = explode(",", (string)$f->options_instructions);
     2110                        foreach((array)$opt_inst as $v) {
     2111                            $res[$type][(string)$f->id]->options_instructions[] = $v;
     2112                        }
     2113                    }
     2114
     2115                }
     2116
     2117            }
     2118
     2119            $this->tour_forms[$com.'-'.$uid] = $res;
     2120        }
     2121
     2122        return (array) $this->tour_forms[$com.'-'.$uid][$type];
     2123    }
     2124
     2125    function getTagSizes() {
     2126        $this->XMLRequest('tags');
     2127
     2128        foreach($this->tags_response as $v) {
     2129            $valid_tags[((string)$v->name)] = (string) $v->count;
     2130        }
     2131        // returns high [0] and low [1] for a list()
     2132        rsort($valid_tags);
     2133        $ret[] = $valid_tags[0];
     2134        sort($valid_tags);
     2135        $ret[] = $valid_tags[0];
     2136
     2137        return (array) $ret;
     2138    }
     2139
     2140    function getTags() {
     2141        $this->XMLRequest('tags');
     2142        return (array) $this->tags_response;
     2143    }
     2144
     2145    // get a list of booking data
     2146    function getBookings($a=null, $node=null) {
     2147        if(!$a) $this->error('No search argument provided, expected trans_num or formatted search string');
     2148
     2149        if(strpos($a, '=') === false) $a = 'q='.$a; // in case we just passed the trans_num by itself
     2150
     2151        $this->bookings_index = $a;
     2152
     2153        $this->XMLRequest('search_bookings');
     2154
     2155        $return = ($node === null) ? (array) $this->search_bookings_response[$this->bookings_index] : $this->search_bookings_response[$this->bookings_index][$node];
     2156
     2157        return $return;
     2158    }
     2159
     2160    function getBookingPrices(&$obj=null) {
     2161        if(!$obj) $obj = $this->getItem();
     2162
     2163        $c=0;
     2164        if($obj->adult_num >= 1) {
     2165            $ret[$c] = new stdClass();
     2166
     2167            $ret[$c]->name = 'adult';
     2168            $ret[$c]->label = (string) $obj->adult_label;
     2169            ($obj->prices->base_prices->price_adult) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_adult : 0;
     2170            $ret[$c]->price = (string) ($obj->prices->price_adult / $obj->adult_num);
     2171            $ret[$c]->number = (string) $obj->adult_num;
     2172            $ret[$c++]->total = (string) $obj->prices->price_adult;
     2173        }
     2174        if($obj->child_num >= 1) {
     2175            $ret[$c] = new stdClass();
     2176
     2177            $ret[$c]->name = 'child';
     2178            $ret[$c]->label = (string) $obj->child_label;
     2179            ($obj->prices->base_prices->price_child) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_child : 0;
     2180            $ret[$c]->price = (string) ($obj->prices->price_child / $obj->child_num);
     2181            $ret[$c]->number = (string) $obj->child_num;
     2182            $ret[$c++]->total = (string) $obj->prices->price_child;
     2183        }
     2184        if($obj->senior_num >= 1) {
     2185            $ret[$c] = new stdClass();
     2186
     2187            $ret[$c]->name = 'senior';
     2188            $ret[$c]->label = (string) $obj->senior_label;
     2189            ($obj->prices->base_prices->price_senior) ? $ret[$c]->base = (string) $obj->prices->base_prices->price_senior : 0;
     2190            $ret[$c]->price = (string) ($obj->prices->price_senior / $obj->senior_num);
     2191            $ret[$c]->number = (string) $obj->senior_num;
     2192            $ret[$c++]->total = (string) $obj->prices->price_senior;
     2193        }
     2194
     2195        for($i=4; $i<=9; $i++) {
     2196            $val = 'price'.$i.'_num';
     2197            if($obj->$val >= 1) {
     2198                $ret[$c] = new stdClass();
     2199
     2200                $ret[$c]->name = 'price'.$i;
     2201                $val = 'price'.$i.'_label';
     2202                $ret[$c]->label = (string) $obj->$val;
     2203                $val = 'price'.$i;
     2204                $val2 = 'price'.$i.'_num';
     2205                ($obj->prices->base_prices->$val) ? $ret[$c]->base = (string) $obj->prices->base_prices->$val : 0;
     2206                $ret[$c]->price = (string) ($obj->prices->$val / $obj->$val2);
     2207                $val = 'price'.$i.'_num';
     2208                $ret[$c]->number = (string) $obj->$val;
     2209                $val = 'price'.$i;
     2210                $ret[$c++]->total = (string) $obj->prices->$val;
     2211            }
     2212        }
     2213
     2214        return (array) $ret;
     2215    }
     2216
     2217    function getBookingLineItems(&$obj=null) {
     2218        if(!$obj) $obj = $this->getItem();
     2219
     2220        if($obj->line_items) {
     2221            if($obj->line_items->line_item[0]) {
     2222                foreach($obj->line_items->line_item as $v) {
     2223                    $ret[] = $v;
     2224                }
     2225            } else {
     2226                $ret[] = $obj->line_items->line_item;
     2227            }
     2228        }
     2229
     2230        return (array) $ret;
     2231    }
     2232
     2233    function getBookingFees(&$obj=null) {
     2234        if(!$obj) $obj = $this->getItem();
     2235
     2236        if($obj->triggered_fees->triggered_fee[0]) {
     2237            foreach($obj->triggered_fees->triggered_fee as $v) {
     2238                $ret[] = $v;
     2239            }
     2240        } else {
     2241            $ret[] = $obj->triggered_fees->triggered_fee;
     2242        }
     2243
     2244        return (array) $ret;
     2245    }
     2246
     2247    function getBookingPassengers(&$obj=null) {
     2248        if(!$obj) $obj = $this->getItem();
     2249
     2250        $c=0;
     2251        if($obj->passengers->passenger[0]) {
     2252            foreach($obj->passengers->passenger as $v) {
     2253                // do the forms on the passenger only have one question? if so, fix the formatting so it matches multiple questions
     2254                if($v->total_forms > 0) {
     2255                    if(!$v->forms->form[0]) {
     2256                        $t = $v->forms->form;
     2257                        unset($v->forms->form); // remove the string value
     2258                        $v->forms->form[] = $t; // replace it with array value
     2259                    }
     2260                } else {
     2261                    // no forms, fill the value with a blank array so the templates can use it
     2262                    // we add a supress @ modifier to prevent the complex-types error
     2263                    @$v->forms->form = array();
     2264                }
     2265
     2266                $ret[$c] = $v;
     2267                @$ret[$c]->num = $v->type->attributes()->num;
     2268                $val = $v->type.'_label';
     2269                $ret[$c++]->label = $obj->$val;
     2270            }
     2271        } else {
     2272            // do the forms on the passenger only have one question? if so, fix the formatting so it matches multiple questions
     2273            if($obj->passengers->passenger->total_forms > 0) {
     2274                if(!$obj->passengers->passenger->forms->form[0]) {
     2275                    $t = $obj->passengers->passenger->forms->form;
     2276                    unset($obj->passengers->passenger->forms->form); // remove the string value
     2277                    $obj->passengers->passenger->forms->form[] = $t; // replace it with array value
     2278                }
     2279            } else {
     2280                // no forms, fill the value with a blank array so the templates can use it
     2281                @$obj->passengers->passenger->forms->form = array();
     2282            }
     2283
     2284            $ret[$c] = $obj->passengers->passenger;
     2285            @$ret[$c]->num = $obj->passengers->passenger->type->attributes()->num;
     2286            $val = $obj->passengers->passenger->type.'_label';
     2287            $ret[$c++]->label = $obj->$val;
     2288        }
     2289
     2290        // unset it if the value is empty because we have no group info
     2291        $count = count($ret);
     2292        if($count == 1 && !(string)$ret[0]->num) unset($ret);
     2293
     2294        // check to make sure the entire array isn't empty of data
     2295        if($count > 1) {
     2296            foreach((array)$ret as $k => $v) {
     2297
     2298
     2299                if((string)$v->first_name) { $present = 1; break; }
     2300                if((string)$v->last_name) { $present = 1; break; }
     2301
     2302                if((string)$v->phone_number) { $present = 1; break; }
     2303                if((string)$v->email_address) { $present = 1; break; }
     2304                if((string)$v->total_forms > 0) { $present = 1; break; }
     2305            }
     2306
     2307            // if(!$present) unset($ret);
     2308        }
     2309
     2310        return (array) $ret;
     2311    }
     2312
     2313    function getBookingForms(&$obj=null) {
     2314        if(!$obj) $obj = $this->getItem();
     2315
     2316        if($obj->primary_forms->total_forms > 0) {
     2317            if($obj->primary_forms->form[0]) {
     2318                foreach($obj->primary_forms->form as $v) {
     2319                    $ret[] = $v;
     2320                }
     2321            } else {
     2322                $ret[] = $obj->primary_forms->form;
     2323            }
     2324        }
     2325
     2326        return (array) $ret;
     2327    }
     2328
     2329    function getBookingCounts(&$obj=null) {
     2330        if(!$obj) $obj = $this->getItem();
     2331
     2332        $list = array('adult', 'child', 'senior', 'price4', 'price5', 'price6', 'price7', 'price8', 'price9');
     2333        $c=0;
     2334        foreach($list as $v) {
     2335            $num = $v.'_num';
     2336            $label = $v.'_label';
     2337            if($obj->$num > 0) {
     2338                $ret[$c] = new stdClass();
     2339                $ret[$c]->label = $obj->$label;
     2340                $ret[$c++]->num = $obj->$num;
     2341            }
     2342        }
     2343        return (array) $ret;
     2344    }
     2345
     2346    function getBookingCurrency(&$obj=null) {
     2347        if(!$obj) $obj = $this->getItem();
     2348
     2349        return (string) $obj->currency_base;
     2350    }
     2351
     2352    function getPaxString() {
     2353
     2354        if($this->requestNum('adult_num')) $pax_list .= '&adult_num='.$this->requestNum('adult_num');
     2355        if($this->requestNum('child_num')) $pax_list .= '&child_num='.$this->requestNum('child_num');
     2356        if($this->requestNum('senior_num')) $pax_list .= '&senior_num='.$this->requestNum('senior_num');
     2357        if($this->requestNum('price4_num')) $pax_list .= '&price4_num='.$this->requestNum('price4_num');
     2358        if($this->requestNum('price5_num')) $pax_list .= '&price5_num='.$this->requestNum('price5_num');
     2359        if($this->requestNum('price6_num')) $pax_list .= '&price6_num='.$this->requestNum('price6_num');
     2360        if($this->requestNum('price7_num')) $pax_list .= '&price7_num='.$this->requestNum('price7_num');
     2361        if($this->requestNum('price8_num')) $pax_list .= '&price8_num='.$this->requestNum('price8_num');
     2362        if($this->requestNum('price9_num')) $pax_list .= '&price9_num='.$this->requestNum('price9_num');
     2363
     2364        return $pax_list;
     2365    }
     2366
     2367    // ------------------------------------------------------------------------------
     2368    // Handle parsing the rezgo pseudo tags
     2369    // ------------------------------------------------------------------------------
     2370    function tag_parse($str) {
     2371        $val = ($GLOBALS['pageHeader']) ? $GLOBALS['pageHeader'] : $this->pageTitle;
     2372        $tags = array('[navigation]', '[navigator]');
     2373        $str = str_replace($tags, $val, $str);
     2374
     2375        $val = ($GLOBALS['pageMeta']) ? $GLOBALS['pageHeader'] : $this->metaTags;
     2376        $tags = array('[meta]', '[meta_tags]', '[seo]');
     2377        $str = str_replace($tags, $val, $str);
     2378
     2379        return (string) $str;
     2380    }
     2381
     2382    // ------------------------------------------------------------------------------
     2383    // Create an outgoing commit request based on the _REQUEST data
     2384    // ------------------------------------------------------------------------------
     2385    function sendBooking($var=null, $arg=null) {
     2386        $r = ($var) ? $var : $_REQUEST;
     2387
     2388        if($arg) $res[] = $arg; // extra API options
     2389
     2390        ($r['date']) ? $res[] = 'date='.urlencode($r['date']) : 0;
     2391        ($r['book']) ? $res[] = 'book='.urlencode($r['book']) : 0;
     2392
     2393        ($r['trigger_code']) ? $res[] = 'trigger_code='.urlencode($r['trigger_code']) : 0;
     2394
     2395        ($r['adult_num']) ? $res[] = 'adult_num='.urlencode($r['adult_num']) : 0;
     2396        ($r['child_num']) ? $res[] = 'child_num='.urlencode($r['child_num']) : 0;
     2397        ($r['senior_num']) ? $res[] = 'senior_num='.urlencode($r['senior_num']) : 0;
     2398        ($r['price4_num']) ? $res[] = 'price4_num='.urlencode($r['price4_num']) : 0;
     2399        ($r['price5_num']) ? $res[] = 'price5_num='.urlencode($r['price5_num']) : 0;
     2400        ($r['price6_num']) ? $res[] = 'price6_num='.urlencode($r['price6_num']) : 0;
     2401        ($r['price7_num']) ? $res[] = 'price7_num='.urlencode($r['price7_num']) : 0;
     2402        ($r['price8_num']) ? $res[] = 'price8_num='.urlencode($r['price8_num']) : 0;
     2403        ($r['price9_num']) ? $res[] = 'price9_num='.urlencode($r['price9_num']) : 0;
     2404
     2405        ($r['tour_first_name']) ? $res[] = 'tour_first_name='.urlencode($r['tour_first_name']) : 0;
     2406        ($r['tour_last_name']) ? $res[] = 'tour_last_name='.urlencode($r['tour_last_name']) : 0;
     2407        ($r['tour_address_1']) ? $res[] = 'tour_address_1='.urlencode($r['tour_address_1']) : 0;
     2408        ($r['tour_address_2']) ? $res[] = 'tour_address_2='.urlencode($r['tour_address_2']) : 0;
     2409        ($r['tour_city']) ? $res[] = 'tour_city='.urlencode($r['tour_city']) : 0;
     2410        ($r['tour_stateprov']) ? $res[] = 'tour_stateprov='.urlencode($r['tour_stateprov']) : 0;
     2411        ($r['tour_country']) ? $res[] = 'tour_country='.urlencode($r['tour_country']) : 0;
     2412        ($r['tour_postal_code']) ? $res[] = 'tour_postal_code='.urlencode($r['tour_postal_code']) : 0;
     2413        ($r['tour_phone_number']) ? $res[] = 'tour_phone_number='.urlencode($r['tour_phone_number']) : 0;
     2414        ($r['tour_email_address']) ? $res[] = 'tour_email_address='.urlencode($r['tour_email_address']) : 0;
     2415
     2416        if($r['tour_group']) {
     2417            foreach((array) $r['tour_group'] as $k => $v) {
     2418                foreach((array) $v as $sk => $sv) {
     2419                    $res[] = 'tour_group['.$k.']['.$sk.'][first_name]='.urlencode($sv['first_name']);
     2420                    $res[] = 'tour_group['.$k.']['.$sk.'][last_name]='.urlencode($sv['last_name']);
     2421                    $res[] = 'tour_group['.$k.']['.$sk.'][phone]='.urlencode($sv['phone']);
     2422                    $res[] = 'tour_group['.$k.']['.$sk.'][email]='.urlencode($sv['email']);
     2423
     2424                    foreach((array) $sv['forms'] as $fk => $fv) {
     2425                        if(is_array($fv)) $fv = implode(", ", $fv); // for multiselects
     2426                        $res[] = 'tour_group['.$k.']['.$sk.'][forms]['.$fk.']='.urlencode(stripslashes($fv));
     2427                    }
     2428                }
     2429            }
     2430        }
     2431
     2432        if($r['tour_forms']) {
     2433            foreach((array) $r['tour_forms'] as $k => $v) {
     2434                if(is_array($v)) $v = implode(", ", $v); // for multiselects
     2435                $res[] = 'tour_forms['.$k.']='.urlencode(stripslashes($v));
     2436            }
     2437        }
     2438
     2439        // leave the top part in the
     2440
     2441        ($r['payment_method']) ? $res[] = 'payment_method='.urlencode($r['payment_method']) : 0;
     2442
     2443        ($r['payment_method_add']) ? $res[] = 'payment_method_add='.urlencode($r['payment_method_add']) : 0;
     2444
     2445        ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = 'tour_card_token='.urlencode($r['tour_card_token']) : 0;
     2446        ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = 'paypal_token='.urlencode($r['paypal_token']) : 0;
     2447        ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = 'paypal_payer_id='.urlencode($r['paypal_payer_id']) : 0;
     2448
     2449        ($r['agree_terms']) ? $res[] = 'agree_terms='.urlencode($r['agree_terms']) : 0;
     2450
     2451        ($r['review_sent']) ? $res[] = 'review_sent='.urlencode($r['review_sent']) : 0;
     2452
     2453        ($r['marketing_consent']) ? $res[] = 'marketing_consent='.urlencode($r['marketing_consent']) : 0;
     2454
     2455        // add in external elements
     2456        ($this->refid) ? $res['refid'] = '&refid='.$this->refid : 0;
     2457        ($this->promo_code) ? $res['promo'] = '&trigger_code='.$this->promo_code : 0;
     2458
     2459        // add in requesting IP
     2460        $res['ip'] = $_SERVER["REMOTE_ADDR"];
     2461
     2462        $request = '&'.implode('&', $res);
     2463
     2464        $this->XMLRequest('commit', $request);
     2465
     2466        return $this->commit_response;
     2467    }
     2468
     2469    // ------------------------------------------------------------------------------
     2470    // Create an outgoing commit request based on the CART data
     2471    // ------------------------------------------------------------------------------
     2472    function sendBookingOrder($var=null, $arg=null) {
     2473        $r = ($var) ? $var : $_REQUEST;
     2474
     2475        if($arg) $res[] = $arg; // extra API options
     2476
     2477        if(!is_array($r['booking'])) $this->error('sendBookingOrder failed. Booking array was not found', 1);
     2478
     2479        $res[] = '<token>'.$r['cart_token'].'</token>';
     2480
     2481        foreach($r['booking'] as $b) {
     2482
     2483            $res[] = '<booking>';
     2484
     2485            $res[] = '<index>'.urlencode($b['index']).'</index>';
     2486            ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('sendBookingOrder failed. book element "date" is empty', 1);
     2487            ($b['book']) ? $res[] = '<book>'.urlencode($b['book']).'</book>' : $this->error('sendBookingOrder failed. book element "book" is empty', 1);
     2488
     2489            ($b['adult_num']) ? $res[] = '<adult_num>'.urlencode($b['adult_num']).'</adult_num>' : 0;
     2490            ($b['child_num']) ? $res[] = '<child_num>'.urlencode($b['child_num']).'</child_num>' : 0;
     2491            ($b['senior_num']) ? $res[] = '<senior_num>'.urlencode($b['senior_num']).'</senior_num>' : 0;
     2492            ($b['price4_num']) ? $res[] = '<price4_num>'.urlencode($b['price4_num']).'</price4_num>' : 0;
     2493            ($b['price5_num']) ? $res[] = '<price5_num>'.urlencode($b['price5_num']).'</price5_num>' : 0;
     2494            ($b['price6_num']) ? $res[] = '<price6_num>'.urlencode($b['price6_num']).'</price6_num>' : 0;
     2495            ($b['price7_num']) ? $res[] = '<price7_num>'.urlencode($b['price7_num']).'</price7_num>' : 0;
     2496            ($b['price8_num']) ? $res[] = '<price8_num>'.urlencode($b['price8_num']).'</price8_num>' : 0;
     2497            ($b['price9_num']) ? $res[] = '<price9_num>'.urlencode($b['price9_num']).'</price9_num>' : 0;
     2498
     2499            if($b['tour_group']) {
     2500
     2501                $res[] = '<tour_group>';
     2502
     2503                foreach((array) $b['tour_group'] as $k => $v) {
     2504                    foreach((array) $v as $sk => $sv) {
     2505                        $res[] = '<'.$k.' num="'.$sk.'">';
     2506
     2507                        $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
     2508                        $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
     2509                        $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
     2510                        $res[] = '<email>'.urlencode($sv['email']).'</email>';
     2511
     2512                        if(is_array($sv['forms'])) {
     2513                            $res[] = '<forms>';
     2514
     2515                            foreach((array) $sv['forms'] as $fk => $fv) {
     2516                                if(is_array($fv)) $fv = implode(", ", $fv); // for multiselects
     2517                                $res[] = '<form num="'.$fk.'">'.urlencode(stripslashes($fv)).'</form>';
     2518                            }
     2519
     2520                            $res[] = '</forms>';
     2521                        }
     2522
     2523                        $res[] = '</'.$k.'>';
     2524
     2525                    }
     2526                }
     2527
     2528                $res[] = '</tour_group>';
     2529
     2530            }
     2531
     2532            if($b['tour_forms']) {
     2533                $res[] = '<tour_forms>';
     2534
     2535                foreach((array) $b['tour_forms'] as $k => $v) {
     2536                    if(is_array($v)) $v = implode(", ", $v); // for multiselects
     2537                    $res[] = '<form num="'.$k.'">'.urlencode(stripslashes($v)).'</form>';
     2538                }
     2539
     2540                $res[] = '</tour_forms>';
     2541            }
     2542
     2543            if($b['pickup']) {
     2544
     2545                $pickup_split = explode("-", stripslashes($b['pickup']));
     2546
     2547                $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
     2548                if($pickup_split[1]) $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
     2549
     2550            }
     2551
     2552            $res[] = '</booking>';
     2553
     2554        } // cart loop
     2555
     2556        $res[] = '<payment>';
     2557
     2558        ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
     2559
     2560        ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
     2561        ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
     2562        ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
     2563        ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
     2564        ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
     2565        ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
     2566        ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
     2567        ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
     2568        ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
     2569        ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
     2570        ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
     2571
     2572        ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
     2573
     2574        ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
     2575
     2576        ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
     2577        ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
     2578        ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
     2579
     2580        ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
     2581
     2582        ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
     2583
     2584        ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
     2585
     2586        ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
     2587
     2588        // add in external elements
     2589        ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
     2590        ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
     2591
     2592        // add in requesting IP
     2593        $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
     2594
     2595        // add in 3DS validation fields if available
     2596        if($r['validate']) {
     2597            $res[] = '<validate>';
     2598            foreach((array) $r['validate'] as $validate_key => $validate_value) {
     2599                $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
     2600            }
     2601            $res[] = '</validate>';
     2602        }
     2603
     2604        // GIFT-CARD
     2605        $res[] = '<expected>'.$r['expected'].'</expected>';
     2606        ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
     2607
     2608        $res[] = '</payment>';
     2609
     2610        // ticketguardian
     2611        ($r['tour_tg_insurance_coverage']) ? $res[] = '<tg>'.$r['tour_tg_insurance_coverage'].'</tg>' : 0;
     2612
     2613        ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
     2614
     2615        $request = implode('', $res);
     2616
     2617        $this->XMLRequest('commitOrder', $request, 1);
     2618
     2619        return $this->commit_response;
     2620    }
     2621
     2622    // ------------------------------------------------------------------------------
     2623    // GIFT CARD
     2624    // ------------------------------------------------------------------------------
     2625    function sendGiftOrder($request=null) {
     2626        $r = $request;
     2627        $res = array();
     2628
     2629        if($r['rezgoAction'] != 'addGiftCard') {
     2630            $this->error('sendGiftOrder failed. Card array was not found', 1);
     2631        }
     2632
     2633        $res[] = '<card>';
     2634        $res[] = '<number></number>';
     2635        // AMOUNT
     2636        if($r['billing_amount'] == 'custom') {
     2637            $amnt = $r['custom_billing_amount'];
     2638        }
     2639        else {
     2640            $amnt = $r['billing_amount'];
     2641        }
     2642        $res[] = '<amount>'.$amnt.'</amount>';
     2643        $res[] = '<cash_value></cash_value>';
     2644        $res[] = '<expires></expires>';
     2645        $res[] = '<max_uses></max_uses>';
     2646        // NAME
     2647        $recipient_name = explode(" ", $r['recipient_name'], 2);
     2648        $res[] = '<first_name>'.$recipient_name[0].'</first_name>';
     2649        $res[] = '<last_name>'.$recipient_name[1].'</last_name>';
     2650        $res[] = '<email>'.$r['recipient_email'].'</email>';
     2651        // MSG
     2652        $res[] = '<message>'.urlencode(htmlspecialchars_decode($r['recipient_message'], ENT_QUOTES)).'</message>';
     2653
     2654        $res[] = '<send>1</send>';
     2655        $res[] = '<payment>';
     2656
     2657        $res[] = '<token>'.$r['gift_card_token'].'</token>';
     2658        if($r['payment_id']) $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>';
     2659
     2660        $res[] = '<first_name>'.$r['billing_first_name'].'</first_name>';
     2661        $res[] = '<last_name>'.$r['billing_last_name'].'</last_name>';
     2662        $res[] = '<address_1>'.$r['billing_address_1'].'</address_1>';
     2663        $res[] = '<address_2>'.$r['billing_address_2'].'</address_2>';
     2664        $res[] = '<city>'.$r['billing_city'].'</city>';
     2665        $res[] = '<state>'.$r['billing_stateprov'].'</state>';
     2666        $res[] = '<country>'.$r['billing_country'].'</country>';
     2667        $res[] = '<postal>'.$r['billing_postal_code'].'</postal>';
     2668        $res[] = '<phone>'.$r['billing_phone'].'</phone>';
     2669        $res[] = '<email>'.$r['billing_email'].'</email>';
     2670        if($r['terms_agree'] == 'on') {
     2671            $res[] = '<agree_terms>1</agree_terms>';
     2672        }
     2673        else {
     2674            $res[] = '<agree_terms>0</agree_terms>';
     2675        }
     2676        $res[] = '<ip>'.$_SERVER['REMOTE_ADDR'].'</ip>';
     2677
     2678        // add in 3DS validation fields if available
     2679        if($r['validate']) {
     2680            $res[] = '<validate>';
     2681            foreach((array) $r['validate'] as $validate_key => $validate_value) {
     2682                $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
     2683            }
     2684            $res[] = '</validate>';
     2685        }
     2686
     2687        $res[] = '</payment>';
     2688        $res[] = '</card>';
     2689
     2690        $request = implode('', $res);
     2691
     2692        $this->XMLRequest('addGiftCard', $request, 1);
     2693
     2694        return $this->commit_response;
     2695    }
     2696
     2697    // ------------------------------------------------------------------------------
     2698    // Sign Waiver
     2699    // ------------------------------------------------------------------------------
     2700    function signWaiver($request=null) {
     2701        $r = ($request) ? $request : $_REQUEST;
     2702        $res = array();
     2703
     2704        $birthdate = $r['pax_birthdate']['year'].'-'.sprintf('%02d', $r['pax_birthdate']['month']).'-'.sprintf('%02d', $r['pax_birthdate']['day']);
     2705
     2706        if ($r['pax_type'] != 'general') {
     2707
     2708            $pax_forms = $r['pax_group'][$r['pax_type']][$r['pax_type_num']]['forms'];
     2709
     2710            /*$group_forms = '
     2711                <type>'.$r['pax_type'].'</type>
     2712                <num>'.$r['pax_type_num'].'</num>
     2713                <forms>
     2714            ';*/
     2715
     2716            foreach((array) $pax_forms as $form_id => $form_answer) {
     2717                if(is_array($form_answer)) { // for multiselects
     2718                    $form_answer = implode(', ', $form_answer);
     2719                    $r['pax_group'][$r['pax_type']][$r['pax_type_num']]['forms'][$form_id] = $form_answer;
     2720                }
     2721                //$group_forms .= '<form num="'.$form_id.'">'.$form_answer.'</form>';
     2722            }
     2723
     2724            /*$group_forms .= '
     2725                </forms>
     2726            ';*/
     2727
     2728        }
     2729
     2730        $group_forms = serialize($r['pax_group']);
     2731
     2732        $res[] = '<sign>';
     2733        $res[] = '<type>pax</type>'; // change to dynamic later
     2734        $res[] = '<child>'.$r['child'].'</child>';
     2735        $res[] = '<pax_type>'.$r['pax_type'].'</pax_type>';
     2736        $res[] = '<pax_type_num>'.$r['pax_type_num'].'</pax_type_num>';
     2737        $res[] = '<order_code>'.$r['order_code'].'</order_code>';
     2738        $res[] = '<trans_num>'.$r['trans_num'].'</trans_num>';
     2739        $res[] = '<item_id>'.$r['pax_item'].'</item_id>';
     2740        $res[] = '<pax_id>'.$r['pax_id'].'</pax_id>';
     2741        $res[] = '<first_name>'.$r['pax_first_name'].'</first_name>';
     2742        $res[] = '<last_name>'.$r['pax_last_name'].'</last_name>';
     2743        $res[] = '<phone_number>'.$r['pax_phone'].'</phone_number>';
     2744        $res[] = '<email_address>'.$r['pax_email'].'</email_address>';
     2745        $res[] = '<birthdate>'.$birthdate.'</birthdate>';
     2746        $res[] = '<group_forms>'.$group_forms.'</group_forms>';
     2747        $res[] = '<waiver_text>'.$r['pax_waiver_text'].'</waiver_text>';
     2748        $res[] = '<signature>'.str_replace('data:image/png;base64,', '', $r['pax_signature']).'</signature>';
     2749        $res[] = '</sign>';
     2750
     2751        $request = implode('', $res);
     2752
     2753        $this->XMLRequest('sign', $request, 1);
     2754
     2755        return $this->signing_response;
     2756    }
     2757
     2758    function getGiftCard($request=null) {
     2759        if(!$request) {
     2760            $this->error('No search argument provided, expected card number');
     2761        }
     2762
     2763        $this->XMLRequest('searchGiftCard', $request);
     2764
     2765        return $this->gift_card;
     2766    }
     2767
     2768    // this function is for sending a partial commit request, it does not add any values itself
     2769    function sendPartialCommit($var=null) {
     2770        $request = '&'.$var;
     2771
     2772        $this->XMLRequest('commit', $request);
     2773
     2774        return $this->commit_response;
     2775    }
     2776
     2777    // send results of contact form
     2778    function sendContact($var=null) {
     2779        $r = ($var) ? $var : $_REQUEST;
     2780
     2781        // we use full_name instead of name because of a wordpress quirk
     2782        ($r['full_name']) ? $res[] = 'name='.urlencode($r['full_name']) : $this->error('contact element "full_name" is empty', 1);
     2783        ($r['email']) ? $res[] = 'email='.urlencode($r['email']) : $this->error('contact element "email" is empty', 1);
     2784        ($r['body']) ? $res[] = 'body='.urlencode($r['body']) : $this->error('contact element "body" is empty', 1);
     2785
     2786        ($r['phone']) ? $res[] = 'phone='.urlencode($r['phone']) : 0;
     2787        ($r['address']) ? $res[] = 'address='.urlencode($r['address']) : 0;
     2788        ($r['address2']) ? $res[] = 'address2='.urlencode($r['address2']) : 0;
     2789        ($r['city']) ? $res[] = 'city='.urlencode($r['city']) : 0;
     2790        ($r['state_prov']) ? $res[] = 'state_prov='.urlencode($r['state_prov']) : 0;
     2791        ($r['country']) ? $res[] = 'country='.urlencode($r['country']) : 0;
     2792
     2793        $request = '&'.implode('&', $res);
     2794
     2795        $this->XMLRequest('contact', $request);
     2796
     2797        return $this->contact_response;
     2798    }
     2799
     2800    // send review data
     2801    function sendReview($request=null) {
     2802        $r = ($request) ? $request : $_REQUEST;
     2803        $res = array();
     2804
     2805        $res[] = '<review>';
     2806        $res[] = '<booking>'.$r['trans_num'].'</booking>';
     2807        $res[] = '<rating>'.$r['rating'].'</rating>';
     2808        $res[] = '<title><![CDATA['.urlencode(htmlspecialchars_decode($r['review_title'], ENT_QUOTES)).']]></title>';
     2809        $res[] = '<body><![CDATA['.urlencode(htmlspecialchars_decode($r['review_body'], ENT_QUOTES)).']]></body>';
     2810        $res[] = '</review>';
     2811
     2812        $request = implode('', $res);
     2813
     2814        $this->XMLRequest('add_review', $request, 1);
     2815
     2816        return $this->review_response;
     2817    }
     2818
     2819    // get review data
     2820    function getReview($q=null, $type=null, $limit=null, $sort=null, $order=null) {
     2821
     2822        // 'type' default is booking // 'limit' default is 5
     2823
     2824        ($q) ? $res[] = 'q='.urlencode($q) : 0;
     2825        ($type) ? $res[] = 'type='.urlencode($type) : 0;
     2826        ($limit) ? $res[] = 'limit='.urlencode($limit) : 0;
     2827        ($sort) ? $res[] = 'sort='.urlencode($sort) : 0;
     2828        ($order) ? $res[] = 'order='.urlencode($order) : 0;
     2829
     2830        $request = implode('&', $res);
     2831
     2832        $this->XMLRequest('review', $request);
     2833
     2834        return $this->review_response;
     2835    }
     2836
     2837    // get pickup list
     2838    function getPickupList($option_id=null) {
     2839
     2840        ($option_id) ? $res[] = 'q='.urlencode($option_id) : 0;
     2841
     2842        $request = implode('&', $res);
     2843
     2844        $this->XMLRequest('pickup', $request);
     2845
     2846        return $this->pickup_response;
     2847    }
     2848
     2849    // get pickup location
     2850    function getPickupItem($option_id=null, $pickup_id=null) {
     2851
     2852        ($option_id) ? $res[] = 'q='.urlencode($option_id) : 0;
     2853        ($pickup_id) ? $res[] = 'pickup='.urlencode($pickup_id) : 0;
     2854
     2855        $request = implode('&', $res);
     2856
     2857        $this->XMLRequest('pickup', $request);
     2858
     2859        return $this->pickup_response->pickup;
     2860    }
     2861
     2862    // get payment request
     2863    function getPayment($request_id=null) {
     2864
     2865        ($request_id) ? $res[] = 'q='.urlencode($request_id) : 0;
     2866
     2867        $request = implode('&', $res);
     2868
     2869        $this->XMLRequest('payment', $request);
     2870
     2871        if ($this->payment_response->error) {
     2872            return $this->payment_response; // ->error
     2873        } else {
     2874            return $this->payment_response->payment;
     2875        }
     2876
     2877    }
     2878
     2879    // sending payment
     2880    function sendPayment($var=null) {
     2881        $r = ($var) ? $var : $_REQUEST;
     2882        $res = array();
     2883
     2884        if($r['rezgoAction'] != 'add_payment') {
     2885            $this->error('sendPayment failed, payment array was not found', 1);
     2886        }
     2887
     2888        $res[] = '<transaction>';
     2889        $res[] = '<request>'.$r['request_id'].'</request>';
     2890        $res[] = '<amount>'.$r['payment_amount'].'</amount>';
     2891
     2892        if (strlen($r['tour_order_code']) == 16) {
     2893            $res[] = '<order>'.$r['tour_order_code'].'</order>';
     2894        } else {
     2895            $res[] = '<booking>'.$r['tour_order_code'].'</booking>';
     2896        }
     2897
     2898        $res[] = '<method>Credit Cards</method>';
     2899        $res[] = '<token>'.$r['tour_card_token'].'</token>';
     2900
     2901        if($r['payment_id']) $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>';
     2902
     2903        $res[] = '<first_name>'.$r['tour_first_name'].'</first_name>';
     2904        $res[] = '<last_name>'.$r['tour_last_name'].'</last_name>';
     2905        $res[] = '<email_address>'.$r['tour_email_address'].'</email_address>';
     2906        $res[] = '<address_1>'.$r['tour_address_1'].'</address_1>';
     2907        $res[] = '<address_2>'.$r['tour_address_2'].'</address_2>';
     2908        $res[] = '<city>'.$r['tour_city'].'</city>';
     2909        $res[] = '<stateprov>'.$r['tour_stateprov'].'</stateprov>';
     2910        $res[] = '<country>'.$r['tour_country'].'</country>';
     2911        $res[] = '<postal_code>'.$r['tour_postal_code'].'</postal_code>';
     2912        $res[] = '<phone_number>'.$r['tour_phone_number'].'</phone_number>';
     2913
     2914        $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>';
     2915        $res[] = '<ip>'.$_SERVER['REMOTE_ADDR'].'</ip>';
     2916
     2917        // add in 3DS validation fields if available
     2918        if($r['validate']) {
     2919            $res[] = '<validate>';
     2920            foreach((array) $r['validate'] as $validate_key => $validate_value) {
     2921                $res[] = '<'.$validate_key.'>'.$validate_value.'</'.$validate_key.'>';
     2922            }
     2923            $res[] = '</validate>';
     2924        }
     2925
     2926        $res[] = '</transaction>';
     2927
     2928        $request = implode('', $res);
     2929
     2930        $this->XMLRequest('add_transaction', $request, 1);
     2931
     2932        return $this->commit_response;
     2933    }
     2934
     2935    // add an item to the shopping cart
     2936    function addToCart($item, $clear=0) {
     2937
     2938        if(!$clear) {
     2939            // don't load the existing cart if we are clearing it
     2940            if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
     2941            elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
     2942
     2943            // load the existing cart -- CART API
     2944            if($_COOKIE['rezgo_cart_token_'.REZGO_CID]){
     2945                $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
     2946            }
     2947        }
     2948
     2949        if ($cart_token){
     2950
     2951            $res = array();
     2952            $res[] = '<cart>'.$cart_token.'</cart>';
     2953            $res[] = '<action>add</action>';
     2954
     2955            $request = implode('', $res);
     2956
     2957            $this->XMLRequest('cart', $request, 1);
     2958
     2959            $this->cart_response;
     2960
     2961            $tour = $this->cart_response;
     2962
     2963            $contents = $tour->contents;
     2964            $decode = json_decode($contents, true);
     2965
     2966            // add the new item to the cart
     2967            foreach((array) $decode as $v) {
     2968
     2969                // at least 1 price point must be set to add this item
     2970                // this works to remove items as well, if they match the date (above) but have no prices set
     2971                if(
     2972                    $v['adult_num'] || $v['child_num'] || $v['senior_num'] ||
     2973                    $v['price4_num'] || $v['price5_num'] || $v['price6_num'] ||
     2974                    $v['price7_num'] || $v['price8_num'] || $v['price9_num']
     2975                ) {
     2976                    $cart[] = $v;
     2977                }
     2978            }
     2979
     2980        }
     2981
     2982        return $cart;
     2983    }
     2984
     2985    // add an item to the shopping cart
     2986    function editCart($item) {
     2987
     2988        // load the existing cart
     2989        if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
     2990        elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
     2991
     2992        // load the existing cart -- CART API
     2993        if($_COOKIE['rezgo_cart_token_'.REZGO_CID]){
     2994            $cart_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
     2995        }
     2996
     2997        // add the new item to the cart
     2998        foreach((array) $item as $k => $v) {
     2999
     3000            if($cart[$k]) {
     3001
     3002                // at least 1 price point must be set to edit this item
     3003                // this works to remove items as well, if they match the date (above) but have no prices set
     3004                if(
     3005                    $v['adult_num'] || $v['child_num'] || $v['senior_num'] ||
     3006                    $v['price4_num'] || $v['price5_num'] || $v['price6_num'] ||
     3007                    $v['price7_num'] || $v['price8_num'] || $v['price9_num']
     3008                ) {
     3009                    $cart[$k] = $v;
     3010                } else {
     3011                    unset($cart[$k]);
     3012                }
     3013
     3014            }
     3015        }
     3016
     3017        return $cart;
     3018    }
     3019
     3020    // add pickup to the shopping cart
     3021    function pickupCart($index, $pickup) {
     3022
     3023        // load the existing cart
     3024        if($_SESSION['rezgo_cart_'.REZGO_CID]) { $cart = $_SESSION['rezgo_cart_'.REZGO_CID]; }
     3025        elseif($_COOKIE['rezgo_cart_'.REZGO_CID]) { $cart = unserialize(stripslashes($_COOKIE['rezgo_cart_'.REZGO_CID])); }
     3026
     3027        if($cart[$index]) {
     3028
     3029            $cart[$index]['pickup'] = $pickup;
     3030
     3031            // update cart
     3032            $ttl = (REZGO_CART_TTL > 0 || REZGO_CART_TTL === 0) ? REZGO_CART_TTL : 86400;
     3033
     3034            if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
     3035                setcookie("rezgo_cart_".REZGO_CID, serialize($cart), time() + $ttl, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['SERVER_NAME']);
     3036            } else {
     3037                setcookie("rezgo_cart_".REZGO_CID, serialize($cart), time() + $ttl, '/', $_SERVER['SERVER_NAME']);
     3038            }
     3039
     3040            $this->setShoppingCart(serialize($cart));
     3041
     3042        }
     3043
     3044        return $cart;
     3045    }
     3046
     3047    function clearCart() {
     3048        unset($_SESSION['rezgo_cart_'.REZGO_CID]);
     3049        unset($_COOKIE['rezgo_cart_'.REZGO_CID]);
     3050        unset($_SESSION['cart_status']);
     3051
     3052        $this->setCookie("rezgo_cart_".REZGO_CID, '');
     3053        $this->setCookie("rezgo_cart_token_".REZGO_CID, '');
     3054
     3055        if (is_multisite() && !SUBDOMAIN_INSTALL && ( DOMAIN_CURRENT_SITE != REZGO_WP_DIR )) {
     3056            setcookie("rezgo_cart_".REZGO_CID, '', 1, str_replace( DOMAIN_CURRENT_SITE, '', REZGO_WP_DIR ), $_SERVER['SERVER_NAME']);
     3057        } else {
     3058            setcookie("rezgo_cart_".REZGO_CID, '', 1, '/', $_SERVER['HTTP_HOST']);
     3059        }
     3060
     3061    }
     3062
     3063    // get a list of all the item IDs that are currently in the cart (used for search queries)
     3064    function getCartIDs() {
     3065        $n = 1;
     3066        if(is_array($this->cart)) {
     3067            foreach($this->cart as $k => $v) {
     3068                $ids[] = $v['uid'];
     3069                $n++;
     3070            }
     3071            $ids = ($ids) ? implode(",", $ids) : '';
     3072        }
     3073        return $ids;
     3074    }
     3075
     3076    // fetch the full shopping cart including detailed tour info
     3077    function getCart($hide=null) {
     3078
     3079        // check if there is a cart token in URL, and if it matches current cart
     3080        $request_token = $_REQUEST['cart'];
     3081        $current_token = $_COOKIE['rezgo_cart_token_'.REZGO_CID];
     3082
     3083        if ( $request_token && (!isset($current_token)) ){
     3084            $this->setCookie('rezgo_cart_token_'.REZGO_CID, $request_token);
     3085            $this->searchToken($request_token);
     3086
     3087            $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/'.$_REQUEST['wp_slug'] . '/order');
     3088
     3089        }
     3090        else if ($request_token) {
     3091            if ($request_token != $current_token){
     3092
     3093                // clear all previous cart contents
     3094                $this->clearCart();
     3095                $this->clearCartState();
     3096
     3097                $this->setCookie('rezgo_cart_token_'.REZGO_CID, $request_token);
     3098                $this->searchToken($request_token);
     3099
     3100                $this->sendTo((($this->checkSecure()) ? 'https://' : 'http://').$_SERVER['HTTP_HOST'].'/'.$_REQUEST['wp_slug'] . '/order');
     3101            }
     3102            else {
     3103                $this->cart_token = $current_token;
     3104            }
     3105        }
     3106        else {
     3107            $this->cart_token = $current_token;
     3108        }
     3109
     3110        $cart = $this->cart;
     3111
     3112        if ($cart) {
     3113            $c = 0;
     3114            foreach ($cart as $item) {
     3115                $cart[$c++]->booking_date = strtotime((string)$item->date[0]->attributes()->value);
     3116            }
     3117        }
     3118
     3119        return (array) $cart;
     3120    }
     3121
     3122    function getFormDisplay(){
     3123        return $this->form_display;
     3124    }
     3125
     3126    function getGroupFormDisplay(){
     3127        return $this->gf_form_display;
     3128    }
     3129
     3130    function getCartTotal(){
     3131        return (string) $this->cart_total;
     3132    }
     3133
     3134    function getCartStatus(){
     3135        return $this->cart_status;
     3136    }
     3137
     3138    function clearCartState(){
     3139        unset($_SESSION['cart_status']);
     3140        echo '<script>localStorage.clear();</script>';
     3141    }
     3142
     3143    //*********************//
     3144    //********** CART API
     3145    //*********************//
     3146
     3147    function cartRequest($action, $args='') {
     3148
     3149        $this->setCartToken();
     3150
     3151        if(!$this->cart_token && $action == 'search') return false;
     3152
     3153        $res = array();
     3154        $res[] = '<instruction>cart</instruction>';
     3155        $res[] = '<cart>' . $this->cart_token . '</cart>';
     3156        $res[] = '<action>' . $action . '</action>';
     3157        $res[] = $args;
     3158        $res[] = '</request>';
     3159
     3160        $this->cart_api_request = implode('', $res);
     3161
     3162    }
     3163
     3164    function searchToken($token) {
     3165
     3166        // searching can't happen until we have a token, added from the first item added to cart
     3167        if($token) {
     3168
    31433169            $res = array();
    31443170            $res[] = '<instruction>cart</instruction>';
    3145             $res[] = '<cart>' . $this->cart_token . '</cart>';
    3146             $res[] = '<action>' . $action . '</action>';
    3147             $res[] = $args;
     3171            $res[] = '<cart>' . $token . '</cart>';
     3172            $res[] = '<action>search</action>';
    31483173            $res[] = '</request>';
    3149            
     3174
    31503175            $this->cart_api_request = implode('', $res);
    3151            
    3152         }
    3153 
    3154         function searchToken($token) {
    3155      
    3156             // searching can't happen until we have a token, added from the first item added to cart
    3157             if($token) {
    3158            
    3159                 $res = array();
    3160                 $res[] = '<instruction>cart</instruction>';
    3161                 $res[] = '<cart>' . $token . '</cart>';
    3162                 $res[] = '<action>search</action>';
    3163                 $res[] = '</request>';
    3164            
    3165                 $this->cart_api_request = implode('', $res);
    3166                 $this->XMLRequest('search_cart', $this->cart_api_request);
    3167                 $this->cart = $this->cart_api_response;
    3168                
    3169             }
    3170         }
    3171 
    3172         function setCartToken(){
    3173             $this->cart_token = $this->checkIsset($_COOKIE['rezgo_cart_token_'.REZGO_CID]);
    3174         }   
    3175 
    3176         function createCart() {
    3177             $this->cartRequest('create');
    3178             $this->XMLRequest('create_cart', $this->cart_api_request);
    3179             $this->setCookie('rezgo_cart_token_'.REZGO_CID, $this->cart_token);
    3180 
    3181             return $this->cart_token;
    3182         }
    3183  
    3184         function searchCart() {
    3185            
    3186             $res = $this->cartRequest('search');
    3187            
    3188             if($res !== false) {
    3189                 $this->XMLRequest('search_cart', $this->cart_api_request);
    3190                 $this->cart = $this->cart_api_response;
    3191             }
    3192            
    3193         }
    3194 
    3195         function getFormData() {
    3196             return $this->cart_data;
    3197         }
    3198 
    3199         // -------------------------------------------------
    3200         // Create an update request for edit_pax to the CART
    3201         // -------------------------------------------------
    3202         function editPax($var=null, $arg=null) {
    3203 
    3204             $r = ($var) ? $var : $_REQUEST;
    3205            
    3206             if($arg) $res[] = $arg; // extra API options
    3207 
    3208             $res[] = '<item>';
    3209 
    3210                 $res[] = '<index>'.urlencode($r['edit']['index']).'</index>';
    3211                 ($r['edit']['uid']) ? $res[] = '<id>'.urlencode($r['edit']['uid']).'</id>' : $this->error('editPax failed. edit element "uid" is empty', 1);
    3212                 ($r['edit']['date']) ? $res[] = '<date>'.urlencode($r['edit']['date']).'</date>' : $this->error('editPax failed. edit element "date" is empty', 1);
    3213 
    3214                 if (isset($r['edit']['adult_num'])) {
    3215                     if ($r['edit']['adult_num'] != 0) {
    3216                         $res[] = '<adult_num>'.urlencode($r['edit']['adult_num']).'</adult_num>';
    3217                     } else {
    3218                         $res[] = '<adult_num>0</adult_num>';
    3219                     }
    3220                 }
    3221                 if (isset($r['edit']['child_num'])) {
    3222                     if ($r['edit']['child_num'] != 0) {
    3223                         $res[] = '<child_num>'.urlencode($r['edit']['child_num']).'</child_num>';
    3224                     } else {
    3225                         $res[] = '<child_num>0</child_num>';
    3226                     }
    3227                 }
    3228                 if (isset($r['edit']['senior_num'])) {
    3229                     if ($r['edit']['senior_num'] != 0) {
    3230                         $res[] = '<senior_num>'.urlencode($r['edit']['senior_num']).'</senior_num>';
    3231                     } else {
    3232                         $res[] = '<senior_num>0</senior_num>';
    3233                     }
    3234                 }
    3235                 if (isset($r['edit']['price4_num'])) {
    3236                     if ($r['edit']['price4_num'] != 0) {
    3237                         $res[] = '<price4_num>'.urlencode($r['edit']['price4_num']).'</price4_num>';
    3238                     } else {
    3239                         $res[] = '<price4_num>0</price4_num>';
    3240                     }
    3241                 }
    3242                 if (isset($r['edit']['price5_num'])) {
    3243                     if ($r['edit']['price5_num'] != 0) {
    3244                         $res[] = '<price5_num>'.urlencode($r['edit']['price5_num']).'</price5_num>';
    3245                     } else {
    3246                         $res[] = '<price5_num>0</price5_num>';
    3247                     }
    3248                 }
    3249                 if (isset($r['edit']['price6_num'])) {
    3250                     if ($r['edit']['price6_num'] != 0) {
    3251                         $res[] = '<price6_num>'.urlencode($r['edit']['price6_num']).'</price6_num>';
    3252                     } else {
    3253                         $res[] = '<price6_num>0</price6_num>';
    3254                     }
    3255                 }
    3256                 if (isset($r['edit']['price7_num'])) {
    3257                     if ($r['edit']['price7_num'] != 0) {
    3258                         $res[] = '<price7_num>'.urlencode($r['edit']['price7_num']).'</price7_num>';
    3259                     } else {
    3260                         $res[] = '<price7_num>0</price7_num>';
    3261                     }
    3262                 }
    3263                 if (isset($r['edit']['price8_num'])) {
    3264                     if ($r['edit']['price8_num'] != 0) {
    3265                         $res[] = '<price8_num>'.urlencode($r['edit']['price8_num']).'</price8_num>';
    3266                     } else {
    3267                         $res[] = '<price8_num>0</price8_num>';
    3268                     }
    3269                 }
    3270                 if (isset($r['edit']['price9_num'])) {
    3271                     if ($r['edit']['price9_num'] != 0) {
    3272                         $res[] = '<price9_num>'.urlencode($r['edit']['price9_num']).'</price9_num>';
    3273                     } else {
    3274                         $res[] = '<price9_num>0</price9_num>';
    3275                     }
    3276                 }
    3277 
    3278             $res[] = '</item>';
    3279 
    3280             $request = implode('', $res);
    3281 
    3282             $this->cartRequest('update', $request);
    3283             $this->XMLRequest('update_cart', $this->cart_api_request);
    3284 
    3285             if ($this->cart_status){ return $this->cart_status;}
    3286         }
    3287 
    3288         // -----------------------------------------------
    3289         // Create an add request from step_one to the CART
    3290         // -----------------------------------------------
    3291         function addCart($var=null, $arg=null) {
    3292             $r = ($var) ? $var : $_REQUEST;
    3293            
    3294             if($arg) $res[] = $arg; // extra API options
    3295 
    3296             foreach((array) $r['add'] as $k => $v) {
    3297                
    3298                 $res[] = '<item>';
    3299    
    3300                     ($v['uid']) ? $res[] = '<id>' . urlencode($v['uid']) . '</id>' : $this->error('addCart failed. book element "uid" is empty', 1);
    3301                     ($v['date']) ? $res[] = '<date>' . urlencode($v['date']) . '</date>' : $this->error('addCart failed. book element "date" is empty', 1);
    3302        
    3303                     ($v['adult_num']) ? $res[] = '<adult_num>' . urlencode($v['adult_num']) . '</adult_num>' : '';
    3304                     ($v['child_num']) ? $res[] = '<child_num>' . urlencode($v['child_num']) . '</child_num>' : '';
    3305                     ($v['senior_num']) ? $res[] = '<senior_num>' . urlencode($v['senior_num']) . '</senior_num>' : '';
    3306        
    3307                     ($v['price4_num']) ? $res[] = '<price4_num>' . urlencode($v['price4_num']) . '</price4_num>' : '';
    3308                     ($v['price5_num']) ? $res[] = '<price5_num>' . urlencode($v['price5_num']) . '</price5_num>' : '';
    3309                     ($v['price6_num']) ? $res[] = '<price6_num>' . urlencode($v['price6_num']) . '</price6_num>' : '';
    3310                     ($v['price7_num']) ? $res[] = '<price7_num>' . urlencode($v['price7_num']) . '</price7_num>' : '';
    3311                     ($v['price8_num']) ? $res[] = '<price8_num>' . urlencode($v['price8_num']) . '</price8_num>' : '';
    3312                     ($v['price9_num']) ? $res[] = '<price9_num>' . urlencode($v['price9_num']) . '</price9_num>' : '';
    3313    
    3314                 $res[] = '</item>';
    3315    
    3316             }
    3317 
    3318             // include promo and refid if one is set to the add request so it shows on order page
    3319             if ($_COOKIE['rezgo_promo']) $res[] = '<trigger_code>'.$_COOKIE['rezgo_promo'].'</trigger_code>';
    3320             if ($_COOKIE['rezgo_refid_val']) $res[] = '<refid>'.$_COOKIE['rezgo_refid_val'].'</refid>';
    3321 
    3322             $request = implode('', $res);
    3323            
    3324             // var_dump($request);
    3325             $this->cartRequest('add', $request);
    3326             $this->XMLRequest('add_cart', $this->cart_api_request);
    3327 
    3328             if ($this->cart_status){ return $this->cart_status;}
    3329         }
    3330 
    3331         // -----------------------------------------------------
    3332         // Create an update request for trigger_code to the CART
    3333         // -----------------------------------------------------
    3334         function updatePromo( $promo_code='' ) {
    3335 
    3336             // add trigger code
    3337             $res[] = '<trigger_code>'.$promo_code.'</trigger_code>';
    3338 
    3339             $request = implode('' , $res);
    3340            
    3341             // var_dump($request);
    3342             $this->promo_code = $promo_code;
    3343             $this->cartRequest('update', $request);
    3344             $this->XMLRequest('update_cart', $this->cart_api_request);
    3345         }
    3346 
    3347         // -------------------------------------------------
    3348         // Create an update request for refid to the CART
    3349         // -------------------------------------------------
    3350         function updateRefId( $refid='' ) {
    3351 
    3352             $res[] = '<refid>'.$refid.'</refid>';
    3353 
    3354             $request = implode('' , $res);
    3355            
    3356             $this->refid = $refid;
    3357             $this->cartRequest('update', $request);
    3358             $this->XMLRequest('update_cart', $this->cart_api_request);
    3359         }
    3360 
    3361         // ------------------------------------------------------------------------------
    3362         // Create an update request from guest information to the CART
    3363         // ------------------------------------------------------------------------------
    3364         function updateCart($var=null, $arg=null) {
    3365             $r = ($var) ? $var : $_REQUEST;
    3366            
    3367             if($arg) $res[] = $arg; // extra API options
    3368 
    3369             // update lead passenger details
    3370             $res[] = '<email>'.$r['lead_passenger_email'].'</email>';
    3371             $res[] = '<payment>';
    3372                 $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
    3373                 $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
    3374                 $res[] = '<tour_email_address>'.$r['lead_passenger_email'].'</tour_email_address>';
    3375             $res[] = '</payment>';
    3376 
    3377             $c = 1;
    3378             foreach($r['booking'] as $b) {
    3379 
    3380                 $res[] = '<item>';
    3381 
    3382                 $res[] = '<index>'.urlencode($b['index']).'</index>';
    3383                 ($b['uid']) ? $res[] = '<id>'.urlencode($b['uid']).'</id>' : $this->error('updateCart failed. book element "uid" is empty', 1);
    3384                 ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('updateCart failed. book element "date" is empty', 1);
    3385 
    3386                 // ---- NEW cart request format for tour_group
    3387                 if($b['tour_group']) {
    3388                    
    3389                     $res[] = '<tour_group>';
    3390                    
    3391                     foreach((array) $b['tour_group'] as $k => $v) {
    3392                         foreach((array) $v as $sk => $sv) {
    3393                             $res[] = '<'.$k.'>';
    3394                                 $res[] = '<num>'.$sk.'</num>';
    3395                            
    3396                                 $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
    3397                                 $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
    3398                                 $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
    3399                                 $res[] = '<email>'.urlencode($sv['email']).'</email>';
    3400                            
    3401                             if(is_array($sv['forms'])) {
    3402                                 $res[] = '<forms>';
    3403                                                            
    3404                                 foreach((array) $sv['forms'] as $fk => $fv) {
    3405                                     $res[] = '<form>';
    3406                                         $res[] = '<num>'.$fk.'</num>';
    3407                                         if(is_array($fv)) { // for multiselects
    3408                                             foreach($fv as $key => $val){
    3409                                                 // htmlentities() needed for WP to send to DB
    3410                                                 $fv[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
    3411                                             }
    3412                                             $fv = implode(", ", $fv);
    3413                                             $res[] = '<value>'.$fv.'</value>';
    3414                                         } else {
    3415                                             // htmlentities() needed for WP to send to DB
    3416                                             $res[] = '<value>'.urlencode(htmlentities(stripslashes($fv), ENT_QUOTES)).'</value>';
    3417                                         }
    3418                                     $res[] = '</form>';
    3419                                 }
    3420                                
    3421                                 $res[] = '</forms>';
    3422                             }
    3423                            
    3424                             $res[] = '</'.$k.'>';
    3425                            
    3426                         }       
    3427                     }
    3428                     $res[] = '</tour_group>';
    3429                    
    3430                 }
    3431 
    3432                 // ---- NEW cart request format for tour_forms
    3433                 if($b['tour_forms']) {
    3434                     $res[] = '<primary_forms>';
    3435                
    3436                     foreach((array) $b['tour_forms'] as $k => $v) {
    3437                         $res[] ='<form>';
    3438                             $res[] = '<num>'.$k.'</num>';
    3439                             if(is_array($v)) { // for multiselects
    3440                                 foreach($v as $key => $val){
    3441                                     // htmlentities() needed for WP to send to DB
    3442                                     $v[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
    3443                                 }
    3444                                 $v = implode(", ", $v);
    3445                                 $res[] = '<value>'.$v.'</value>';
    3446                             } else {
    3447                                 // htmlentities() needed for WP to send to DB
    3448                                 $res[] = '<value>'.urlencode(htmlentities(stripslashes($v), ENT_QUOTES)).'</value>';
    3449                             }
    3450                         $res[] = '</form>';
    3451                     }
    3452                
    3453                     $res[] = '</primary_forms>';
    3454                 }
    3455 
    3456                 if($b['pickup']) {
    3457                    
    3458                     $pickup_split = explode("-", stripslashes($b['pickup']));
    3459 
    3460                     $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
    3461                     if(isset($pickup_split[1])) {
    3462                         $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
    3463                     } else {
    3464                         $res[] = '<pickup_source></pickup_source>';
    3465                     }
    3466                    
    3467                 } else { $res[] = '<pickup>0</pickup><pickup_source></pickup_source>'; }
    3468 
    3469                 ($b['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
    3470 
    3471                 $res[] = '</item>';
    3472 
    3473             } // cart loop
    3474 
    3475             $request = implode('', $res);
    3476 
    3477             $this->cartRequest('update', $request);
    3478             $this->XMLRequest('update_cart', $this->cart_api_request);
    3479 
    3480         }
    3481 
    3482         // ------------------------------------------------------------------------------
    3483         // DEBUG UPDATE REQUEST
    3484         // ------------------------------------------------------------------------------
    3485         function updateDebug($var=null, $arg=null) {
    3486             $r = ($var) ? $var : $_REQUEST;
    3487            
    3488             if($arg) $res[] = $arg; // extra API options
    3489 
    3490             $res[] = '<email>'.$r['lead_passenger_email'].'</email>';
    3491             $res[] = '<payment>';
    3492                 $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
    3493                 $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
    3494                 $res[] = '<tour_email_address>'.$r['lead_passenger_email'].'</tour_email_address>';
    3495             $res[] = '</payment>';
    3496 
    3497             $c = 1;
    3498             foreach($r['booking'] as $b) {
    3499 
    3500                 $res[] = '<item>';
    3501 
    3502                 $res[] = '<index>'.urlencode($b['index']).'</index>';
    3503                 ($b['uid']) ? $res[] = '<id>'.urlencode($b['uid']).'</id>' : $this->error('updateCart failed. book element "uid" is empty', 1);
    3504                 ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('updateCart failed. book element "date" is empty', 1);
    3505 
    3506                 if($b['tour_group']) {
    3507                    
    3508                     $res[] = '<tour_group>';
    3509                    
    3510                     foreach((array) $b['tour_group'] as $k => $v) {
    3511                         foreach((array) $v as $sk => $sv) {
    3512                             $res[] = '<'.$k.'>';
    3513                                 $res[] = '<num>'.$sk.'</num>';
    3514                            
    3515                                 $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
    3516                                 $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
    3517                                 $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
    3518                                 $res[] = '<email>'.urlencode($sv['email']).'</email>';
    3519                            
    3520                             if(is_array($sv['forms'])) {
    3521                                 $res[] = '<forms>';
    3522                                                            
    3523                                 foreach((array) $sv['forms'] as $fk => $fv) {
    3524                                     $res[] = '<form>';
    3525                                         $res[] = '<num>'.$fk.'</num>';
    3526                                         if(is_array($fv)) { // for multiselects
    3527                                             foreach($fv as $key => $val){
    3528                                                 // htmlentities() needed for WP to send to DB
    3529                                                 $fv[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
    3530                                             }
    3531                                             $fv = implode(", ", $fv);
    3532                                             $res[] = '<value>'.$fv.'</value>';
    3533                                         } else {
    3534                                             // htmlentities() needed for WP to send to DB
    3535                                             $res[] = '<value>'.urlencode(htmlentities(stripslashes($fv), ENT_QUOTES)).'</value>';
    3536                                         }
    3537                                     $res[] = '</form>';
    3538                                 }
    3539                                
    3540                                 $res[] = '</forms>';
    3541                             }
    3542                             $res[] = '</'.$k.'>';
    3543                         }       
    3544                     }
    3545                     $res[] = '</tour_group>';
    3546                 }
    3547                 if($b['tour_forms']) {
    3548                     $res[] = '<primary_forms>';
    3549                
    3550                     foreach((array) $b['tour_forms'] as $k => $v) {
    3551                         $res[] ='<form>';
    3552                             $res[] = '<num>'.$k.'</num>';
    3553                             if(is_array($v)) { // for multiselects
    3554                                 foreach($v as $key => $val){
    3555                                     // htmlentities() needed for WP to send to DB
    3556                                     $v[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
    3557                                 }
    3558                                 $v = implode(", ", $v);
    3559                                 $res[] = '<value>'.$v.'</value>';
    3560                             } else {
    3561                                 // htmlentities() needed for WP to send to DB
    3562                                 $res[] = '<value>'.urlencode(htmlentities(stripslashes($v), ENT_QUOTES)).'</value>';
    3563                             }
    3564                         $res[] = '</form>';
    3565                     }
    3566                
    3567                     $res[] = '</primary_forms>';
    3568                 }
    3569 
    3570                 if($b['pickup']) {
    3571                    
    3572                     $pickup_split = explode("-", stripslashes($b['pickup']));
    3573 
    3574                     $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
    3575                     if(isset($pickup_split[1])) {
    3576                         $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
    3577                     } else {
    3578                         $res[] = '<pickup_source></pickup_source>';
    3579                     }
    3580                    
    3581                 } else { $res[] = '<pickup>0</pickup><pickup_source></pickup_source>'; }
    3582 
    3583                 ($b['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
    3584 
    3585                 $res[] = '</item>';
    3586 
    3587             } // cart loop
    3588 
    3589             $request = implode('', $res);
    3590            
    3591             print_r($request);
    3592         }
    3593 
    3594         // ------------------------------------------------------------------------------
    3595         // DEBUG COMMIT REQUEST
    3596         // ------------------------------------------------------------------------------
    3597         function commitDebug($var=null, $arg=null) {
    3598             $r = ($var) ? $var : $_REQUEST;
    3599            
    3600             if($arg) $res[] = $arg; // extra API options
    3601            
    3602             if(!is_array($r['booking'])) $this->error('sendBookingOrder failed. Booking array was not found', 1);
    3603 
    3604             $res[] = '<token>'.$r['cart_token'].'</token>';
    3605            
    3606             $res[] = '<payment>';
    3607            
    3608             ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
    3609                
    3610             ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
    3611             ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
    3612             ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
    3613             ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
    3614             ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
    3615             ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
    3616             ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
    3617             ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
    3618             ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
    3619             ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
    3620             ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
    3621            
    3622             ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
    3623            
    3624             ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
    3625            
    3626             ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
    3627             ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
    3628             ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
    3629            
    3630             ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
    3631            
    3632             ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
    3633            
    3634             ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
    3635            
    3636             ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
    3637            
    3638             // add in external elements
    3639             ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
    3640             ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
    3641            
    3642             // add in requesting IP
    3643             $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
    3644            
    3645             // GIFT-CARD
    3646             $res[] = '<expected>'.$r['expected'].'</expected>';
    3647             ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
    3648            
    3649             $res[] = '</payment>';
    3650            
    3651             // ticketguardian
    3652             ($r['tour_tg_insurance_coverage']) ? $res[] = '<tg>'.$r['tour_tg_insurance_coverage'].'</tg>' : 0;
    3653            
    3654             ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
    3655            
    3656             $request = implode('', $res);
    3657 
    3658             print_r($request);
    3659         }
    3660 
    3661         // complete booking process
    3662         function commitCart($var=null, $arg=null) {
    3663 
    3664             $r = ($var) ? $var : $_REQUEST;
    3665            
    3666             if($arg) $res[] = $arg; // extra API options
    3667 
    3668             $res[] = '<token>'.$this->cart_token.'</token>';
    3669 
    3670             $res[] = '<payment>';
    3671 
    3672                 ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
    3673                    
    3674                 ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
    3675                 ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
    3676                 ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
    3677                 ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
    3678                 ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
    3679                 ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
    3680                 ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
    3681                 ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
    3682                 ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
    3683                 ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
    3684                 ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
    3685                
    3686                 ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
    3687                
    3688                 ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
    3689                
    3690                 ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
    3691                 ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
    3692                 ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
    3693                
    3694                 ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
    3695                
    3696                 ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
    3697                
    3698                 ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
    3699                
    3700                 ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
    3701                
    3702                 // add in external elements
    3703                 ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
    3704                 ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
    3705                
    3706                 // add in requesting IP
    3707                 $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
    3708                
    3709                 // GIFT-CARD
    3710                 $res[] = '<expected>'.$r['expected'].'</expected>';
    3711                 ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
    3712            
    3713             $res[] = '</payment>';
    3714            
    3715             ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
    3716 
    3717             $request = implode('', $res);
    3718 
    3719             $this->cartRequest('update', $request);
    3720 
    3721             $this->XMLRequest('update_cart', $this->cart_api_request);
    3722             $this->XMLRequest('commitOrder', $request, 1);
    3723            
    3724             return $this->commit_response;
    3725 
    3726         }
    3727 
    3728         function removeCart($index='', $id='', $date=''){
    3729             $item = '<item>';
    3730                 $item .= '<index>'.$index.'</index>';
    3731                 $item .= '<id>'.$id.'</id>';
    3732                 $item .= '<date>'.$date.'</date>'; 
    3733             $item .= '</item>';
    3734 
    3735             $this->cartRequest('remove', $item);
    3736             $this->XMLRequest('remove_cart', $this->cart_api_request);
    3737         }
    3738 
    3739         function destroyCart(){
    3740             $this->cartRequest('destroy');
    3741             $this->XMLRequest('destroy_cart', $this->cart_api_request);
    3742             $this->setCookie('rezgo_cart_token_'.REZGO_CID, '');
    3743         }
    3744 
    3745         function saveLeadPassenger($var=null) {
    3746             $r = ($var) ? $var : $_REQUEST;
    3747 
    3748             $res[] = ($r['lead_passenger_email']) ? '<email>'.$r['lead_passenger_email'].'</email>' : '';
    3749 
    3750             if ($r['lead_passenger_first_name'] || $r['lead_passenger_last_name']) {
    3751                 $res[] = '<payment>';
    3752                     $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
    3753                     $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
    3754                 $res[] = '</payment>';
    3755             }
    3756 
    3757             $request = implode('', $res);
    3758             $this->cartRequest('update', $request);
    3759             $this->XMLRequest('update_cart', $this->cart_api_request);
    3760         }
    3761 
    3762         function getLeadPassenger(){
    3763             $lead_passenger = array();
    3764             $lead_passenger['email'] = (string) $this->lead_passenger_email;
    3765             $lead_passenger['first_name'] = (string) $this->lead_passenger_first_name;
    3766             $lead_passenger['last_name'] = (string) $this->lead_passenger_last_name;
    3767 
    3768             return $lead_passenger;
    3769         }
    3770 
    3771         // FORMAT CARD
    3772         function cardFormat($num) {
    3773             $cc = str_replace(array('-', ' '), '', $num);
    3774             $cc_length = strlen($cc);
    3775             $new_card = substr($cc, -4);
    3776 
    3777             for ($i = $cc_length - 5; $i >= 0; $i--) {
    3778                 if((($i + 1) - $cc_length) % 4 == 0) {
    3779                     $new_card = '-' . $new_card;
    3780                 }
    3781 
    3782                 $new_card = $cc[$i] . $new_card;
    3783             }
    3784 
    3785             return $new_card;
    3786         }       
    3787 
    3788         // ------------------------------------------------------------------------------
    3789         // CLEAR PROMO CODE
    3790         // ------------------------------------------------------------------------------
    3791         function resetPromoCode() {
    3792             unset($_REQUEST['promo']);
    3793             unset($_SESSION['promo']);
    3794             $this->setCookie("rezgo_promo",'');
    3795         }
    3796 
    3797         // ------------------------------------------------------------------------------
    3798         // isset check
    3799         // ------------------------------------------------------------------------------
    3800         function checkIsset($var) {
    3801             return isset($var) ? $var : '';
    3802         }
    3803     }
     3176            $this->XMLRequest('search_cart', $this->cart_api_request);
     3177            $this->cart = $this->cart_api_response;
     3178
     3179        }
     3180    }
     3181
     3182    function setCartToken(){
     3183        $this->cart_token = $this->checkIsset($_COOKIE['rezgo_cart_token_'.REZGO_CID]);
     3184    }
     3185
     3186    function createCart() {
     3187        $this->cartRequest('create');
     3188        $this->XMLRequest('create_cart', $this->cart_api_request);
     3189        $this->setCookie('rezgo_cart_token_'.REZGO_CID, $this->cart_token);
     3190
     3191        return $this->cart_token;
     3192    }
     3193
     3194    function searchCart() {
     3195
     3196        $res = $this->cartRequest('search');
     3197
     3198        if($res !== false) {
     3199            $this->XMLRequest('search_cart', $this->cart_api_request);
     3200            $this->cart = $this->cart_api_response;
     3201        }
     3202
     3203    }
     3204
     3205    function getFormData() {
     3206        return $this->cart_data;
     3207    }
     3208
     3209    // -------------------------------------------------
     3210    // Create an update request for edit_pax to the CART
     3211    // -------------------------------------------------
     3212    function editPax($var=null, $arg=null) {
     3213
     3214        $r = ($var) ? $var : $_REQUEST;
     3215
     3216        if($arg) $res[] = $arg; // extra API options
     3217
     3218        $res[] = '<item>';
     3219
     3220        $res[] = '<index>'.urlencode($r['edit']['index']).'</index>';
     3221        ($r['edit']['uid']) ? $res[] = '<id>'.urlencode($r['edit']['uid']).'</id>' : $this->error('editPax failed. edit element "uid" is empty', 1);
     3222        ($r['edit']['date']) ? $res[] = '<date>'.urlencode($r['edit']['date']).'</date>' : $this->error('editPax failed. edit element "date" is empty', 1);
     3223
     3224        if (isset($r['edit']['adult_num'])) {
     3225            if ($r['edit']['adult_num'] != 0) {
     3226                $res[] = '<adult_num>'.urlencode($r['edit']['adult_num']).'</adult_num>';
     3227            } else {
     3228                $res[] = '<adult_num>0</adult_num>';
     3229            }
     3230        }
     3231        if (isset($r['edit']['child_num'])) {
     3232            if ($r['edit']['child_num'] != 0) {
     3233                $res[] = '<child_num>'.urlencode($r['edit']['child_num']).'</child_num>';
     3234            } else {
     3235                $res[] = '<child_num>0</child_num>';
     3236            }
     3237        }
     3238        if (isset($r['edit']['senior_num'])) {
     3239            if ($r['edit']['senior_num'] != 0) {
     3240                $res[] = '<senior_num>'.urlencode($r['edit']['senior_num']).'</senior_num>';
     3241            } else {
     3242                $res[] = '<senior_num>0</senior_num>';
     3243            }
     3244        }
     3245        if (isset($r['edit']['price4_num'])) {
     3246            if ($r['edit']['price4_num'] != 0) {
     3247                $res[] = '<price4_num>'.urlencode($r['edit']['price4_num']).'</price4_num>';
     3248            } else {
     3249                $res[] = '<price4_num>0</price4_num>';
     3250            }
     3251        }
     3252        if (isset($r['edit']['price5_num'])) {
     3253            if ($r['edit']['price5_num'] != 0) {
     3254                $res[] = '<price5_num>'.urlencode($r['edit']['price5_num']).'</price5_num>';
     3255            } else {
     3256                $res[] = '<price5_num>0</price5_num>';
     3257            }
     3258        }
     3259        if (isset($r['edit']['price6_num'])) {
     3260            if ($r['edit']['price6_num'] != 0) {
     3261                $res[] = '<price6_num>'.urlencode($r['edit']['price6_num']).'</price6_num>';
     3262            } else {
     3263                $res[] = '<price6_num>0</price6_num>';
     3264            }
     3265        }
     3266        if (isset($r['edit']['price7_num'])) {
     3267            if ($r['edit']['price7_num'] != 0) {
     3268                $res[] = '<price7_num>'.urlencode($r['edit']['price7_num']).'</price7_num>';
     3269            } else {
     3270                $res[] = '<price7_num>0</price7_num>';
     3271            }
     3272        }
     3273        if (isset($r['edit']['price8_num'])) {
     3274            if ($r['edit']['price8_num'] != 0) {
     3275                $res[] = '<price8_num>'.urlencode($r['edit']['price8_num']).'</price8_num>';
     3276            } else {
     3277                $res[] = '<price8_num>0</price8_num>';
     3278            }
     3279        }
     3280        if (isset($r['edit']['price9_num'])) {
     3281            if ($r['edit']['price9_num'] != 0) {
     3282                $res[] = '<price9_num>'.urlencode($r['edit']['price9_num']).'</price9_num>';
     3283            } else {
     3284                $res[] = '<price9_num>0</price9_num>';
     3285            }
     3286        }
     3287
     3288        $res[] = '</item>';
     3289
     3290        $request = implode('', $res);
     3291
     3292        $this->cartRequest('update', $request);
     3293        $this->XMLRequest('update_cart', $this->cart_api_request);
     3294
     3295        if ($this->cart_status){ return $this->cart_status;}
     3296    }
     3297
     3298    // -----------------------------------------------
     3299    // Create an add request from step_one to the CART
     3300    // -----------------------------------------------
     3301    function addCart($var=null, $arg=null) {
     3302        $r = ($var) ? $var : $_REQUEST;
     3303
     3304        if($arg) $res[] = $arg; // extra API options
     3305
     3306        foreach((array) $r['add'] as $k => $v) {
     3307
     3308            $res[] = '<item>';
     3309
     3310            ($v['uid']) ? $res[] = '<id>' . urlencode($v['uid']) . '</id>' : $this->error('addCart failed. book element "uid" is empty', 1);
     3311            ($v['date']) ? $res[] = '<date>' . urlencode($v['date']) . '</date>' : $this->error('addCart failed. book element "date" is empty', 1);
     3312
     3313            ($v['adult_num']) ? $res[] = '<adult_num>' . urlencode($v['adult_num']) . '</adult_num>' : '';
     3314            ($v['child_num']) ? $res[] = '<child_num>' . urlencode($v['child_num']) . '</child_num>' : '';
     3315            ($v['senior_num']) ? $res[] = '<senior_num>' . urlencode($v['senior_num']) . '</senior_num>' : '';
     3316
     3317            ($v['price4_num']) ? $res[] = '<price4_num>' . urlencode($v['price4_num']) . '</price4_num>' : '';
     3318            ($v['price5_num']) ? $res[] = '<price5_num>' . urlencode($v['price5_num']) . '</price5_num>' : '';
     3319            ($v['price6_num']) ? $res[] = '<price6_num>' . urlencode($v['price6_num']) . '</price6_num>' : '';
     3320            ($v['price7_num']) ? $res[] = '<price7_num>' . urlencode($v['price7_num']) . '</price7_num>' : '';
     3321            ($v['price8_num']) ? $res[] = '<price8_num>' . urlencode($v['price8_num']) . '</price8_num>' : '';
     3322            ($v['price9_num']) ? $res[] = '<price9_num>' . urlencode($v['price9_num']) . '</price9_num>' : '';
     3323
     3324            $res[] = '</item>';
     3325
     3326        }
     3327
     3328        // include promo and refid if one is set to the add request so it shows on order page
     3329        if ($_COOKIE['rezgo_promo']) $res[] = '<trigger_code>'.$_COOKIE['rezgo_promo'].'</trigger_code>';
     3330        if ($_COOKIE['rezgo_refid_val']) $res[] = '<refid>'.$_COOKIE['rezgo_refid_val'].'</refid>';
     3331
     3332        $request = implode('', $res);
     3333
     3334        // var_dump($request);
     3335        $this->cartRequest('add', $request);
     3336        $this->XMLRequest('add_cart', $this->cart_api_request);
     3337
     3338        if ($this->cart_status){ return $this->cart_status;}
     3339    }
     3340
     3341    // -----------------------------------------------------
     3342    // Create an update request for trigger_code to the CART
     3343    // -----------------------------------------------------
     3344    function updatePromo( $promo_code='' ) {
     3345
     3346        // add trigger code
     3347        $res[] = '<trigger_code>'.$promo_code.'</trigger_code>';
     3348
     3349        $request = implode('' , $res);
     3350
     3351        // var_dump($request);
     3352        $this->promo_code = $promo_code;
     3353        $this->cartRequest('update', $request);
     3354        $this->XMLRequest('update_cart', $this->cart_api_request);
     3355    }
     3356
     3357    // -------------------------------------------------
     3358    // Create an update request for refid to the CART
     3359    // -------------------------------------------------
     3360    function updateRefId( $refid='' ) {
     3361
     3362        $res[] = '<refid>'.$refid.'</refid>';
     3363
     3364        $request = implode('' , $res);
     3365
     3366        $this->refid = $refid;
     3367        $this->cartRequest('update', $request);
     3368        $this->XMLRequest('update_cart', $this->cart_api_request);
     3369    }
     3370
     3371    // ------------------------------------------------------------------------------
     3372    // Create an update request from guest information to the CART
     3373    // ------------------------------------------------------------------------------
     3374    function updateCart($var=null, $arg=null) {
     3375        $r = ($var) ? $var : $_REQUEST;
     3376
     3377        if($arg) $res[] = $arg; // extra API options
     3378
     3379        // update lead passenger details
     3380        $res[] = '<email>'.$r['lead_passenger_email'].'</email>';
     3381        $res[] = '<payment>';
     3382        $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
     3383        $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
     3384        $res[] = '<tour_email_address>'.$r['lead_passenger_email'].'</tour_email_address>';
     3385        $res[] = '</payment>';
     3386
     3387        $c = 1;
     3388        foreach($r['booking'] as $b) {
     3389
     3390            $res[] = '<item>';
     3391
     3392            $res[] = '<index>'.urlencode($b['index']).'</index>';
     3393            ($b['uid']) ? $res[] = '<id>'.urlencode($b['uid']).'</id>' : $this->error('updateCart failed. book element "uid" is empty', 1);
     3394            ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('updateCart failed. book element "date" is empty', 1);
     3395
     3396            // ---- NEW cart request format for tour_group
     3397            if($b['tour_group']) {
     3398
     3399                $res[] = '<tour_group>';
     3400
     3401                foreach((array) $b['tour_group'] as $k => $v) {
     3402                    foreach((array) $v as $sk => $sv) {
     3403                        $res[] = '<'.$k.'>';
     3404                        $res[] = '<num>'.$sk.'</num>';
     3405
     3406                        $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
     3407                        $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
     3408                        $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
     3409                        $res[] = '<email>'.urlencode($sv['email']).'</email>';
     3410
     3411                        if(is_array($sv['forms'])) {
     3412                            $res[] = '<forms>';
     3413
     3414                            foreach((array) $sv['forms'] as $fk => $fv) {
     3415                                $res[] = '<form>';
     3416                                $res[] = '<num>'.$fk.'</num>';
     3417                                if(is_array($fv)) { // for multiselects
     3418                                    foreach($fv as $key => $val){
     3419                                        // htmlentities() needed for WP to send to DB
     3420                                        $fv[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
     3421                                    }
     3422                                    $fv = implode(", ", $fv);
     3423                                    $res[] = '<value>'.$fv.'</value>';
     3424                                } else {
     3425                                    // htmlentities() needed for WP to send to DB
     3426                                    $res[] = '<value>'.urlencode(htmlentities(stripslashes($fv), ENT_QUOTES)).'</value>';
     3427                                }
     3428                                $res[] = '</form>';
     3429                            }
     3430
     3431                            $res[] = '</forms>';
     3432                        }
     3433
     3434                        $res[] = '</'.$k.'>';
     3435
     3436                    }
     3437                }
     3438                $res[] = '</tour_group>';
     3439
     3440            }
     3441
     3442            // ---- NEW cart request format for tour_forms
     3443            if($b['tour_forms']) {
     3444                $res[] = '<primary_forms>';
     3445
     3446                foreach((array) $b['tour_forms'] as $k => $v) {
     3447                    $res[] ='<form>';
     3448                    $res[] = '<num>'.$k.'</num>';
     3449                    if(is_array($v)) { // for multiselects
     3450                        foreach($v as $key => $val){
     3451                            // htmlentities() needed for WP to send to DB
     3452                            $v[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
     3453                        }
     3454                        $v = implode(", ", $v);
     3455                        $res[] = '<value>'.$v.'</value>';
     3456                    } else {
     3457                        // htmlentities() needed for WP to send to DB
     3458                        $res[] = '<value>'.urlencode(htmlentities(stripslashes($v), ENT_QUOTES)).'</value>';
     3459                    }
     3460                    $res[] = '</form>';
     3461                }
     3462
     3463                $res[] = '</primary_forms>';
     3464            }
     3465
     3466            if($b['pickup']) {
     3467
     3468                $pickup_split = explode("-", stripslashes($b['pickup']));
     3469
     3470                $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
     3471                if(isset($pickup_split[1])) {
     3472                    $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
     3473                } else {
     3474                    $res[] = '<pickup_source></pickup_source>';
     3475                }
     3476
     3477            } else { $res[] = '<pickup>0</pickup><pickup_source></pickup_source>'; }
     3478
     3479            ($b['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
     3480
     3481            $res[] = '</item>';
     3482
     3483        } // cart loop
     3484
     3485        $request = implode('', $res);
     3486
     3487        $this->cartRequest('update', $request);
     3488        $this->XMLRequest('update_cart', $this->cart_api_request);
     3489
     3490    }
     3491
     3492    // ------------------------------------------------------------------------------
     3493    // DEBUG UPDATE REQUEST
     3494    // ------------------------------------------------------------------------------
     3495    function updateDebug($var=null, $arg=null) {
     3496        $r = ($var) ? $var : $_REQUEST;
     3497
     3498        if($arg) $res[] = $arg; // extra API options
     3499
     3500        $res[] = '<email>'.$r['lead_passenger_email'].'</email>';
     3501        $res[] = '<payment>';
     3502        $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
     3503        $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
     3504        $res[] = '<tour_email_address>'.$r['lead_passenger_email'].'</tour_email_address>';
     3505        $res[] = '</payment>';
     3506
     3507        $c = 1;
     3508        foreach($r['booking'] as $b) {
     3509
     3510            $res[] = '<item>';
     3511
     3512            $res[] = '<index>'.urlencode($b['index']).'</index>';
     3513            ($b['uid']) ? $res[] = '<id>'.urlencode($b['uid']).'</id>' : $this->error('updateCart failed. book element "uid" is empty', 1);
     3514            ($b['date']) ? $res[] = '<date>'.urlencode($b['date']).'</date>' : $this->error('updateCart failed. book element "date" is empty', 1);
     3515
     3516            if($b['tour_group']) {
     3517
     3518                $res[] = '<tour_group>';
     3519
     3520                foreach((array) $b['tour_group'] as $k => $v) {
     3521                    foreach((array) $v as $sk => $sv) {
     3522                        $res[] = '<'.$k.'>';
     3523                        $res[] = '<num>'.$sk.'</num>';
     3524
     3525                        $res[] = '<first_name>'.urlencode($sv['first_name']).'</first_name>';
     3526                        $res[] = '<last_name>'.urlencode($sv['last_name']).'</last_name>';
     3527                        $res[] = '<phone>'.urlencode($sv['phone']).'</phone>';
     3528                        $res[] = '<email>'.urlencode($sv['email']).'</email>';
     3529
     3530                        if(is_array($sv['forms'])) {
     3531                            $res[] = '<forms>';
     3532
     3533                            foreach((array) $sv['forms'] as $fk => $fv) {
     3534                                $res[] = '<form>';
     3535                                $res[] = '<num>'.$fk.'</num>';
     3536                                if(is_array($fv)) { // for multiselects
     3537                                    foreach($fv as $key => $val){
     3538                                        // htmlentities() needed for WP to send to DB
     3539                                        $fv[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
     3540                                    }
     3541                                    $fv = implode(", ", $fv);
     3542                                    $res[] = '<value>'.$fv.'</value>';
     3543                                } else {
     3544                                    // htmlentities() needed for WP to send to DB
     3545                                    $res[] = '<value>'.urlencode(htmlentities(stripslashes($fv), ENT_QUOTES)).'</value>';
     3546                                }
     3547                                $res[] = '</form>';
     3548                            }
     3549
     3550                            $res[] = '</forms>';
     3551                        }
     3552                        $res[] = '</'.$k.'>';
     3553                    }
     3554                }
     3555                $res[] = '</tour_group>';
     3556            }
     3557            if($b['tour_forms']) {
     3558                $res[] = '<primary_forms>';
     3559
     3560                foreach((array) $b['tour_forms'] as $k => $v) {
     3561                    $res[] ='<form>';
     3562                    $res[] = '<num>'.$k.'</num>';
     3563                    if(is_array($v)) { // for multiselects
     3564                        foreach($v as $key => $val){
     3565                            // htmlentities() needed for WP to send to DB
     3566                            $v[$key] = urlencode(htmlentities(stripslashes($val), ENT_QUOTES));
     3567                        }
     3568                        $v = implode(", ", $v);
     3569                        $res[] = '<value>'.$v.'</value>';
     3570                    } else {
     3571                        // htmlentities() needed for WP to send to DB
     3572                        $res[] = '<value>'.urlencode(htmlentities(stripslashes($v), ENT_QUOTES)).'</value>';
     3573                    }
     3574                    $res[] = '</form>';
     3575                }
     3576
     3577                $res[] = '</primary_forms>';
     3578            }
     3579
     3580            if($b['pickup']) {
     3581
     3582                $pickup_split = explode("-", stripslashes($b['pickup']));
     3583
     3584                $res[] = '<pickup>'.$pickup_split[0].'</pickup>';
     3585                if(isset($pickup_split[1])) {
     3586                    $res[] = '<pickup_source>'.$pickup_split[1].'</pickup_source>';
     3587                } else {
     3588                    $res[] = '<pickup_source></pickup_source>';
     3589                }
     3590
     3591            } else { $res[] = '<pickup>0</pickup><pickup_source></pickup_source>'; }
     3592
     3593            ($b['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
     3594
     3595            $res[] = '</item>';
     3596
     3597        } // cart loop
     3598
     3599        $request = implode('', $res);
     3600
     3601        print_r($request);
     3602    }
     3603
     3604    // ------------------------------------------------------------------------------
     3605    // DEBUG COMMIT REQUEST
     3606    // ------------------------------------------------------------------------------
     3607    function commitDebug($var=null, $arg=null) {
     3608        $r = ($var) ? $var : $_REQUEST;
     3609
     3610        if($arg) $res[] = $arg; // extra API options
     3611
     3612        if(!is_array($r['booking'])) $this->error('sendBookingOrder failed. Booking array was not found', 1);
     3613
     3614        $res[] = '<token>'.$r['cart_token'].'</token>';
     3615
     3616        $res[] = '<payment>';
     3617
     3618        ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
     3619
     3620        ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
     3621        ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
     3622        ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
     3623        ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
     3624        ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
     3625        ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
     3626        ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
     3627        ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
     3628        ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
     3629        ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
     3630        ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
     3631
     3632        ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
     3633
     3634        ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
     3635
     3636        ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
     3637        ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
     3638        ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
     3639
     3640        ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
     3641
     3642        ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
     3643
     3644        ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
     3645
     3646        ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
     3647
     3648        // add in external elements
     3649        ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
     3650        ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
     3651
     3652        // add in requesting IP
     3653        $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
     3654
     3655        // GIFT-CARD
     3656        $res[] = '<expected>'.$r['expected'].'</expected>';
     3657        ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
     3658
     3659        $res[] = '</payment>';
     3660
     3661        // ticketguardian
     3662        ($r['tour_tg_insurance_coverage']) ? $res[] = '<tg>'.$r['tour_tg_insurance_coverage'].'</tg>' : 0;
     3663
     3664        ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
     3665
     3666        $request = implode('', $res);
     3667
     3668        print_r($request);
     3669    }
     3670
     3671    // complete booking process
     3672    function commitCart($var=null, $arg=null) {
     3673
     3674        $r = ($var) ? $var : $_REQUEST;
     3675
     3676        if($arg) $res[] = $arg; // extra API options
     3677
     3678        $res[] = '<token>'.$this->cart_token.'</token>';
     3679
     3680        $res[] = '<payment>';
     3681
     3682        ($r['trigger_code']) ? $res[] = '<trigger_code>'.$r['trigger_code'].'</trigger_code>' : 0;
     3683
     3684        ($r['tour_first_name']) ? $res[] = '<tour_first_name>'.$r['tour_first_name'].'</tour_first_name>' : 0;
     3685        ($r['tour_last_name']) ? $res[] = '<tour_last_name>'.$r['tour_last_name'].'</tour_last_name>' : 0;
     3686        ($r['tour_address_1']) ? $res[] = '<tour_address_1>'.$r['tour_address_1'].'</tour_address_1>' : 0;
     3687        ($r['tour_address_2']) ? $res[] = '<tour_address_2>'.$r['tour_address_2'].'</tour_address_2>' : 0;
     3688        ($r['tour_city']) ? $res[] = '<tour_city>'.$r['tour_city'].'</tour_city>' : 0;
     3689        ($r['tour_stateprov']) ? $res[] = '<tour_stateprov>'.$r['tour_stateprov'].'</tour_stateprov>' : 0;
     3690        ($r['tour_country']) ? $res[] = '<tour_country>'.$r['tour_country'].'</tour_country>' : 0;
     3691        ($r['tour_postal_code']) ? $res[] = '<tour_postal_code>'.$r['tour_postal_code'].'</tour_postal_code>' : 0;
     3692        ($r['tour_phone_number']) ? $res[] = '<tour_phone_number>'.$r['tour_phone_number'].'</tour_phone_number>' : 0;
     3693        ($r['tour_email_address']) ? $res[] = '<tour_email_address>'.$r['tour_email_address'].'</tour_email_address>' : 0;
     3694        ($r['sms']) ? $res[] = '<sms>'.$r['sms'].'</sms>' : 0;
     3695
     3696        ($r['payment_method']) ? $res[] = '<payment_method>'.urlencode(stripslashes($r['payment_method'])).'</payment_method>' : 0;
     3697
     3698        ($r['payment_method_add']) ? $res[] = '<payment_method_add>'.urlencode(stripslashes($r['payment_method_add'])).'</payment_method_add>' : 0;
     3699
     3700        ($r['payment_method'] == 'Credit Cards' && $r['tour_card_token']) ? $res[] = '<tour_card_token>'.$r['tour_card_token'].'</tour_card_token>' : 0;
     3701        ($r['payment_method'] == 'PayPal' && $r['paypal_token']) ? $res[] = '<paypal_token>'.$r['paypal_token'].'</paypal_token>' : 0;
     3702        ($r['payment_method'] == 'PayPal' && $r['paypal_payer_id']) ? $res[] = '<paypal_payer_id>'.$r['paypal_payer_id'].'</paypal_payer_id>' : 0;
     3703
     3704        ($r['payment_method'] == 'Credit Cards' && $r['payment_id']) ? $res[] = '<payment_id>'.$r['payment_id'].'</payment_id>' : 0;
     3705
     3706        ($r['agree_terms']) ? $res[] = '<agree_terms>'.$r['agree_terms'].'</agree_terms>' : 0;
     3707
     3708        ($r['review_sent']) ? $res[] = '<review_sent>'.$r['review_sent'].'</review_sent>' : 0;
     3709
     3710        ($r['marketing_consent']) ? $res[] = '<marketing_consent>'.$r['marketing_consent'].'</marketing_consent>' : 0;
     3711
     3712        // add in external elements
     3713        ($this->refid) ? $res[] = '<refid>'.$this->refid.'</refid>' : 0;
     3714        ($this->promo_code) ? $res[] = '<trigger_code>'.$this->promo_code.'</trigger_code>' : 0;
     3715
     3716        // add in requesting IP
     3717        $res[] = '<ip>'.$_SERVER["REMOTE_ADDR"].'</ip>';
     3718
     3719        // GIFT-CARD
     3720        $res[] = '<expected>'.$r['expected'].'</expected>';
     3721        ($r['gift_card']) ? $res[] = '<gift_card>'.$r['gift_card'].'</gift_card>' : 0;
     3722
     3723        $res[] = '</payment>';
     3724
     3725        ($r['waiver']) ? $res[] = '<waiver>'.str_replace('data:image/png;base64,', '', $r['waiver']).'</waiver>' : 0;
     3726
     3727        $request = implode('', $res);
     3728
     3729        $this->cartRequest('update', $request);
     3730
     3731        $this->XMLRequest('update_cart', $this->cart_api_request);
     3732        $this->XMLRequest('commitOrder', $request, 1);
     3733
     3734        return $this->commit_response;
     3735
     3736    }
     3737
     3738    function removeCart($index='', $id='', $date=''){
     3739        $item = '<item>';
     3740        $item .= '<index>'.$index.'</index>';
     3741        $item .= '<id>'.$id.'</id>';
     3742        $item .= '<date>'.$date.'</date>';
     3743        $item .= '</item>';
     3744
     3745        $this->cartRequest('remove', $item);
     3746        $this->XMLRequest('remove_cart', $this->cart_api_request);
     3747    }
     3748
     3749    function destroyCart(){
     3750        $this->cartRequest('destroy');
     3751        $this->XMLRequest('destroy_cart', $this->cart_api_request);
     3752        $this->setCookie('rezgo_cart_token_'.REZGO_CID, '');
     3753    }
     3754
     3755    function saveLeadPassenger($var=null) {
     3756        $r = ($var) ? $var : $_REQUEST;
     3757
     3758        $res[] = ($r['lead_passenger_email']) ? '<email>'.$r['lead_passenger_email'].'</email>' : '';
     3759
     3760        if ($r['lead_passenger_first_name'] || $r['lead_passenger_last_name']) {
     3761            $res[] = '<payment>';
     3762            $res[] = '<tour_first_name>'.$r['lead_passenger_first_name'].'</tour_first_name>';
     3763            $res[] = '<tour_last_name>'.$r['lead_passenger_last_name'].'</tour_last_name>';
     3764            $res[] = '</payment>';
     3765        }
     3766
     3767        $request = implode('', $res);
     3768        $this->cartRequest('update', $request);
     3769        $this->XMLRequest('update_cart', $this->cart_api_request);
     3770    }
     3771
     3772    function getLeadPassenger(){
     3773        $lead_passenger = array();
     3774        $lead_passenger['email'] = (string) $this->lead_passenger_email;
     3775        $lead_passenger['first_name'] = (string) $this->lead_passenger_first_name;
     3776        $lead_passenger['last_name'] = (string) $this->lead_passenger_last_name;
     3777
     3778        return $lead_passenger;
     3779    }
     3780
     3781    // FORMAT CARD
     3782    function cardFormat($num) {
     3783        $cc = str_replace(array('-', ' '), '', $num);
     3784        $cc_length = strlen($cc);
     3785        $new_card = substr($cc, -4);
     3786
     3787        for ($i = $cc_length - 5; $i >= 0; $i--) {
     3788            if((($i + 1) - $cc_length) % 4 == 0) {
     3789                $new_card = '-' . $new_card;
     3790            }
     3791
     3792            $new_card = $cc[$i] . $new_card;
     3793        }
     3794
     3795        return $new_card;
     3796    }
     3797
     3798    // ------------------------------------------------------------------------------
     3799    // CLEAR PROMO CODE
     3800    // ------------------------------------------------------------------------------
     3801    function resetPromoCode() {
     3802        unset($_REQUEST['promo']);
     3803        unset($_SESSION['promo']);
     3804        $this->setCookie("rezgo_promo",'');
     3805    }
     3806
     3807    // ------------------------------------------------------------------------------
     3808    // isset check
     3809    // ------------------------------------------------------------------------------
     3810    function checkIsset($var) {
     3811        return isset($var) ? $var : '';
     3812    }
     3813}
Note: See TracChangeset for help on using the changeset viewer.