<?php
/**
 * Template for displaying all pages
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 */

$user_session_token = '';
if( class_exists( 'ApiCrypter' ) && isset( $_SESSION["ownerinfo"][0] ) ){
    $cf = new ApiCrypter;
    $user_session_token = $cf->encrypt($_SESSION["ownerinfo"][0]);
}

get_header(); 

    if(isset($_COOKIE['bookingPopUp'])){
        $mustShowPopUp = $_COOKIE['bookingPopUp'];
    }
    else{
        $mustShowPopUp = "false";
    }
?>
<?php date_default_timezone_set("Australia/Queensland");
//echo date_default_timezone_get(); exit;
//$_SESSION["ownerinfo"][0] = '00070000018'; /* Temporary ID */
$annual_credit = 0;
$available_credit = 0;
$availableToBorrow_credit = 0;
$owner_type = '';
$owner_resorts_original = $owner_resorts = array();

if (isset($_SESSION['WHPPDATA'])) {

    foreach ($_SESSION['WHPPDATA']->data->credits as $credits) {
    	if ($credits->wynMembershipCreditType->code != 'non_eligible') {
            if ($credits->annual > 0)
                $annual_credit = $annual_credit + $credits->annual;

            if ($credits->availableToBorrow > 0)
                $availableToBorrow_credit = $availableToBorrow_credit + $credits->availableToBorrow;
          
            if ($credits->available > 0)
				$available_credit = $available_credit + $credits->available;
        }
    }
	
    $owner_type = $_SESSION['WHPPDATA']->data->tsTier->code;
	if ($owner_type == 'ts-elite-platinum')
	{
		$subtier = $_SESSION['WHPPDATA']->data->subTier->name;
		if ($subtier == '100 Club'){
			$owner_type = 'ts-elite-platinum-100-club';
		}
	}

	
    //$owner_type = 'privileges-diamond';

    $reservationdata = json_decode(getUserInfo('https://hub.wyndhamap.com/hub-api/resorts/get-owner-reservations/', $_SESSION["ownerinfo"][0]));
    if ($reservationdata->status == 'success') {
        foreach ($reservationdata->data as $value) {
            date_i18n(get_option('date_format'), substr($value->checkinDate, 0, -3));

            if (substr($value->checkinDate, 0, -3) >= time()) {
                $owner_resorts_original[] = $value->resort->id;
            } else {
                break;
            }
        }
    }
    $owner_resorts_original = array_unique($owner_resorts_original);
    $args = array(
        'post_type' => 'resorts',
        'posts_per_page' => -1,
        'meta_query' => array(
            'relation' => 'AND',
            array(
                'key' => 'resort_api_id',
                'value' => $owner_resorts_original,
                'compare' => 'IN',
            )
        )
    );
    $the_query = new WP_Query($args);
    $owner_resorts = wp_list_pluck($the_query->posts, 'ID');
}

function getUserInfo($url, $memberId) {
    $url = $url . $memberId;
    $status = 'fail';
    $error = '';
    $data = '';
    $response = wp_remote_get($url);
    if (is_array($response)) {
        $data = json_decode(wp_remote_retrieve_body($response));
        ;
        $status = 'success';
    } else {
        $status = 'fail';
        $error = "Something went wrong:" . $response->get_error_message() . ".";
    }
    return json_encode(array("status" => $status, "data" => $data, "msg" => $error));
}

//$owner_type = $_SESSION['WHPPDATA']->data->tsTier->code;
//$owner_type = 'privileges-elite';
//$_SESSION["ownerinfo"][0] = '00201249143';
?>
<style>
    body{
        background:#f6f6f6;
    }
    label.error{ color: #dc3545;
                 padding-left: 2px; 
    }
</style>
<?php if (!isset($_SESSION["ownerinfo"])) : ?>
        <!--Start Hero Banner -->
		<style>
                .holiday_inspire_banner_custom {
                    background-image: url(<?php echo get_field('image'); ?>) !important;
                }
            </style>
        <section class="holiday_inspire_banner holiday_inspire_banner_custom">
            <div class="container">
                <div class="row justify-content-center">
                    <div class="col-md-12 text-center">
                        <h1 class="h1 text-center my-md-4"><?php the_title(); ?></h1>
                    </div>
                </div>
            </div>
        </section>
        <!--End Hero Banner -->
<?php endif; ?>
<?php do_action("whpp_user_check"); ?>

    <?php //Identify member tier
    $persons = $membersince = "";
    if (isset($_SESSION["ownerinfo"][0])) {
        $personsdata = wp_remote_get('https://hub.wyndhamap.com/hub-api/crm/membership/' . $_SESSION["ownerinfo"][0]);



        if (!is_wp_error($personsdata)) {

            $personsdata = wp_remote_retrieve_body($personsdata);
            $personsdata = json_decode($personsdata);
            if ('SUCCESSFUL' == $personsdata->status) {
                if (count($personsdata->data->persons) > 0) {
                    $membersince = $personsdata->data->firstSaleDt;
                    $persons = $personsdata->data->persons;
					$tierNameRaw = $personsdata->data->tsTier->name;
					$showRow2 = false;
					switch ($tierNameRaw) {
						case "WMSP AC":
							$tierName = 'Premier';
							break;
						case "WMSP Premier":
							$tierName = 'Premier';
							break;
						case "Bronze":
							$tierName = 'Bronze';
							$showRow2 = true;
							break;
						case "Silver":
							$tierName = 'Silver';
							$showRow2 = true;
							break;
						case "Gold":
							$tierName = 'Gold';
							$showRow2 = true;
							break;
						case "Platinum":
							$tierName = 'Platinum';
							$showRow2 = true;
							$subtier = $personsdata->data->subTier->name;
							if ($subtier == '100 Club'){
								$tierName = '100 Club';
							}
							break;
			}
                }
            }
        }
    }
	//Identify member tier end
    /* echo "<pre>";
      print_r($persons);
      echo "</pre>"; */
    ?>


    <?php //Identify member trial tier
    
		if (isset($_SESSION["ownerinfo"][0])) {
			$creditdata = json_decode(getUserInfo('https://hub.wyndhamap.com/hub-api/crm/ownerCredits/', $_SESSION["ownerinfo"][0]));
			//print_r($creditdata);
			if ($creditdata->status == 'success') {
				print_r($creditdata->data->trialTier);
						$owner_trial_tier = $creditdata->data->trialTier;
			}
		}
    ?>

<div class="container page-dashboard">
    <div class="row">
        <div class="col-12 d-flex justify-content-between py-2 py-sm-0">
        <h4 class="text-primary page-title font-weight-bold m-0">Dashboard</h4>
 
            <?php
			$user_agent = $_SERVER['HTTP_USER_AGENT'];
            if (isset($_SESSION["ownerinfo"])):
                if (get_field("page_book_now", "options")):
                    $booklink = get_field("page_book_now", "options");
					$param1 = $_SESSION["ownerinfo"][0];
					$param2 = $_SESSION["ownerinfo"][1];
					$param3 = date('Y-m-d H:i:s');
					$param = implode("\t", array($param1, $param2, $param3));
					if (false){
                    ?>

                    <a href="https://new.wyndhamvrap.com/wyndhamvrap/login" class="btn btn-primary mb-0">Make a Booking</a>

					<?php } else { 
					       //echo 'must show value is : '.$mustShowPopUp; 
						   //echo '   Tier name is : '.$tierName; 
					       if (($mustShowPopUp == "false") and (($tierName == "Platinum") OR ($tierName == "Gold"))){?>
						     <a href="#" class="btn btn-primary mb-0" data-book-id="https://booking.wyndhamvrap.com/book-now/?param=<?php echo base64_encode($param); ?>" data-toggle="modal" data-target="#booking" data-backdrop="static">Make a Booking</a>
					         
					        <?php } else  {?>
					         <a href="https://booking.wyndhamvrap.com/book-now/?param=<?php echo base64_encode($param); ?>" class="btn btn-primary mb-0">Make a Booking</a>
					
					
					<!--<a href="https://booking.wyndhamvrap.com/book-now/?param=<?php echo base64_encode($param); ?>" class="btn btn-primary mb-0">Make a Booking</a> -->
					<?php }}

                endif;
            endif;
            ?>
        </div>
    </div>
	
    <div class="row mt-3">
        <div class="col-md-12">
            <div class="card notification dashboard-box-shadow">
                <div class="card-header text-primary font-weight-bold">Notifications</div>
                <div class="card-body p-0">
                    <div class="list-group list-group-flush">							

                        <?php
                        $today = date('Ymd');
                        $args = array(
                            'post_type' => 'notification',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                'relation' => 'AND',
                                array(
                                    'key' => 'date_range_from',
                                    'value' => $today,
                                    'compare' => '<=',
                                    'type' => 'CHAR'
                                ),
                                array(
                                    'key' => 'date_range_to',
                                    'value' => $today,
                                    'compare' => '>=',
                                    'type' => 'CHAR'
                                )
                            ),
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'owner',
                                    'field' => 'slug',
                                    'terms' => $owner_type
                                ),
                            )
                        );
                        $the_query = new WP_Query($args);
						
                        if ($the_query->have_posts()) {
$resortNotifications = [];
                            while ($the_query->have_posts()) : $the_query->the_post();
                                $notification_type = get_field("notification_type");
								
                                if ($notification_type == 'Credits') {
                                    if (get_field("credit_range_minimum") <= $annual_credit AND get_field("credit_range_maximum") >= $annual_credit) {
                                        ?>
                                        <span class="list-group-item list-group-item-action">
                                            <p class="mb-1"><?php echo $notification_type; ?>: <?php the_title(); ?></p>
                                            <small><?php echo get_field("message"); ?></small>
                                        </span>						 
                                        <?php
                                    }
                                } else if ($notification_type == 'Resorts') {
									foreach(get_field("resorts") as $value){
										if (in_array($value, $owner_resorts) && !in_array(get_the_ID(), $resortNotifications)) {											
											?>
											<span class="list-group-item list-group-item-action">
												<p class="mb-1"><?php echo $notification_type; ?>: <?php the_title(); ?></p>
												<small><?php echo get_field("message"); ?></small>
											</span>						 
											<?php
											$resortNotifications[] = get_the_ID();
										}
									}
                                } else {
                                    ?>
                                    <span class="list-group-item list-group-item-action">
                                        <p class="mb-1"><?php echo $notification_type; ?>: <?php the_title(); ?></p>
                                        <small><?php echo get_field("message"); ?></small>
                                    </span>						 
                                    <?php
                                }
                            endwhile;
                        } else {
                            echo '<span class="list-group-item list-group-item-action"><p class="mb-1">No Notifications for this user</p></span>';
                        }
                        ?>
                    </div>
                </div>
            </div>    
        </div>
    </div>

    <!-- <div class="row mt-3 mt-sm-5">
        <div class="col-lg-8">
            <div class="bs-example bs-example-tabs dashboard-box-shadow p-4" role="tabpanel" data-example-id="togglable-tabs">
                <ul id="userAccounts" class="nav nav-tabs nav-tabs-responsive nav-justified" role="tablist">
                    <li role="presentation" class="nav-item active">
                        <a href="#home" class="nav-link" id="home-tab" role="tab" data-toggle="tab" aria-controls="home" aria-expanded="true">
                            <span class="text">Home</span>
                        </a>
                    </li>
                    <li role="presentation" class="nav-item next">
                        <a href="#profile" class="nav-link fa fa-angle-right" role="tab" id="profile-tab" data-toggle="tab" aria-controls="profile">
                            <span class="text">Profile</span>
                        </a>
                    </li>

                    <li role="presentation" class="nav-item">
                        <a href="#samsa" class="nav-link" role="tab" id="samsa-tab" data-toggle="tab" aria-controls="samsa">
                            <span class="text">Franz Kafka</span>
                        </a>
                    </li>
                </ul>
                <div id="userAccountInfo" class="tab-content">
                    <div role="tabpanel" class="tab-pane active" id="natascha" aria-labelledby="natascha-Piazza">
                        <div class="row">
                            <div class="col-md-8 border-right-gray">
                                <div class="row">
                                    <div class="col-md-12 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Owner Number</small>
                                        <p class="mb-0">123456</p>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Birthday</small>
                                        <p class="mb-0">15/08/1985</p>
                                    </div>
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Member Since</small>
                                        <p class="mb-0">11/10/2014</p>
                                    </div>
                                </div>
                                <div class="row d-none d-sm-block">
                                    <div class="col-md-12 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <h5>Contact</h5>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Email</small>
                                        <p class="mb-0">itsamystery@gmail.com</p>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Phone Number</small>
                                        <p class="mb-0">717-534-4402, <br/> 717-533-2729</p>
                                    </div>
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Address</small>
                                        <p class="mb-0 text-right text-sm-left">91 Blueberry Rd, <br/>Hummelstown, PA 17036</p>
                                    </div>
                                </div>
                                <div class="row d-block d-sm-none">
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Wyndham KM Travelled</small>
                                        <p class="mb-0">6, 40, 001</p>
                                    </div>
                                    <div class="col-md-6 d-flex d-sm-block justify-content-between border-bottom py-2">
                                        <small>Privileges</small>
                                        <p class="mb-0">Elite</p>
                                    </div>
                                </div>
                            </div>
                            <div class="col-md-4 d-none d-sm-block">
                                <div class="d-flex justify-content-md-center flex-column">
                                    <div class="mb-3 text-center">   
                                        <img src="<?php echo get_stylesheet_directory_uri(); ?>/html/images/cup_icon.png">
                                    </div>
                                    <span class="border border-primary rounded text-primary p-2 mb-3 mx-4 text-center">Elite Privileges</span>
                                    <span class="border border-primary rounded p-3 text-center">
                                        <h4 class="text-primary mb-0">6,40,001</h4>
                                        Wyndham KM travelled
                                    </span>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div role="tabpanel" class="tab-pane" id="hanna" aria-labelledby="hanna-Piazza">
                        <p>
                            Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo
                            enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio
                            cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
                        </p>
                    </div>

                    <div role="tabpanel" class="tab-pane" id="benjamin" aria-labelledby="benjamin-Barkla">
                        <p>
                            One morning, when Gregor Samsa woke from troubled dreams, he found himself transformed in his bed into a horrible vermin.
                        </p>
                        <p>
                            He lay on his armour-like back, and if he lifted his head a little he could see his brown belly, slightly domed and divided by arches into stiff sections.
                        </p>
                        <p>
                            The bedding was hardly able to cover it and seemed ready to slide off any moment. His many legs, pitifully thin compared with the size of the rest of him, waved about helplessly as he looked. "What's happened to me?
                        </p>
                        <p>
                            " he thought. It wasn't a dream. His room, a proper human room although a little too small, lay peacefully between its four familiar walls.
                        </p>
                        <p>
                            A collection of textile samples lay spread out on the table - Samsa was a travelling salesman - and above it there hung a picture that he had recently cut out of an illustrated magazine and housed in a nice, gilded frame.
                        </p>
                        <p>
                            It showed a lady fitted out with a fur hat and fur boa who sat upright, raising a heavy fur muff that covered the whole of her lower arm towards the viewer. Gregor then turned to look out the window at the dull weather.
                        </p>
                        <p>
                            Drops of rain could be heard hitting the pane, which made him feel quite sad.
                        </p>
                        <p>
                            "How about if I sleep a little bit longer and forget all this nonsense", he thought, but that was something he was unable to do because he was used to sleeping on his right, and in his present state couldn't get into that position. However hard he threw
                            himself onto his right, he always rolled back to where he was.
                        </p>
                        <p>
                            He must have tried it a hundred times, shut his eyes so that he wouldn't have to look at the floundering legs, and only stopped when he began to feel a mild, dull pain there that he had never felt before. "Oh, God", he thought, "what a strenuous career
                            it is that I've chosen!
                        </p>
                    </div>

                    <div role="tabpanel" class="tab-pane" id="john" aria-labelledby="john-Doe">
                        <p>
                            Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo
                            enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio
                            cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
                        </p>
                    </div>

                    <div role="tabpanel" class="tab-pane" id="andy" aria-labelledby="andy">
                        <p>
                            Food truck fixie locavore, accusamus mcsweeney's marfa nulla single-origin coffee squid. Exercitation +1 labore velit, blog sartorial PBR leggings next level wes anderson artisan four loko farm-to-table craft beer twee. Qui photo booth letterpress, commodo
                            enim craft beer mlkshk aliquip jean shorts ullamco ad vinyl cillum PBR. Homo nostrud organic, assumenda labore aesthetic magna delectus mollit. Keytar helvetica VHS salvia yr, vero magna velit sapiente labore stumptown. Vegan fanny pack odio
                            cillum wes anderson 8-bit, sustainable jean shorts beard ut DIY ethical culpa terry richardson biodiesel. Art party scenester stumptown, tumblr butcher vero sint qui sapiente accusamus tattooed echo park.
                        </p>
                    </div>

                </div>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="h-100 dashboard-box-shadow p-4 dashboard-rp-1">
                <a href="#" class="btn btn-primary mb-3 btn-sm">Update Contact Details</a><br />
                <a href="#" class="btn btn-primary mb-3 btn-sm">Book Owner Education Workshop</a><br />
                <a href="#" class="btn btn-primary mb-3 btn-sm">Tell us more about you</a><br />
				
                <h6 class="mt-3">Payment</h6>
                <a href="#" class="btn btn-link p-0">Setup Autopay</a> <br />
                <a href="#" class="btn btn-link p-0">Make a Payment</a>
            </div>
        </div>
    </div> --> 

    <?php
    $persons = $membersince = "";
    if (isset($_SESSION["ownerinfo"][0])) {
		$timeoutArgs = array(
		'timeout'     => 45
		);
        $personsdata = wp_remote_get('https://hub.wyndhamap.com/hub-api/crm/membership/' . $_SESSION["ownerinfo"][0], $timeoutArgs);



        if (!is_wp_error($personsdata)) {

            $personsdata = wp_remote_retrieve_body($personsdata);
            $personsdata = json_decode($personsdata);
            if ('SUCCESSFUL' == $personsdata->status) {
                if (count($personsdata->data->persons) > 0) {
                    $membersince = $personsdata->data->firstSaleDt;
                    $persons = $personsdata->data->persons;
					$tierNameRaw = $personsdata->data->tsTier->name;
					$showRow2 = false;
					switch ($tierNameRaw) {
						case "WMSP AC":
							$tierName = 'Premier';
							break;
						case "WMSP Premier":
							$tierName = 'Premier';
							break;
						case "Bronze":
							$tierName = 'Bronze';
							$showRow2 = true;
							break;
						case "Silver":
							$tierName = 'Silver';
							$showRow2 = true;
							break;
						case "Gold":
							$tierName = 'Gold';
							$showRow2 = true;
							break;
						case "Platinum":
							$tierName = 'Platinum';
							$showRow2 = true;
							$subtier = $personsdata->data->subTier->name;
							if ($subtier == '100 Club'){
								$tierName = '100 Club';
							}
							break;
			}
                }
            }
        }
    }
    /* echo "<pre>";
      print_r($persons);
      echo "</pre>"; */
    ?>

    <div class="dashboard-box-shadow mt-3 mt-sm-5 p-4">
        <div class="row">
            <div class="col-12 px-lg-4">
                <div class="bs-example bs-example-tabs float-md-left w-100" role="tabpanel" data-example-id="togglable-tabs">
                    <ul id="userAccounts" class="nav nav-tabs nav-tabs-responsive nav-justified d-md-block float-md-left" role="tablist">
                        <?php
                        if (is_array($persons)):
                            $i = 1;
                            foreach ($persons as $person):
                                ?>
                                <li role="presentation" class="nav-item float-md-left <?php
                                echo ($i == 1) ? 'active' : '';
                                $i++;
                                ?>">
                                    <a href="#whpp-<?php echo $person->id; ?>" class="nav-link" id="home-<?php echo $person->id; ?>" role="tab" data-toggle="tab" aria-controls="home" aria-expanded="true">
                                        <span class="text"><?php echo ucfirst($person->firstName) . " " . ucfirst($person->lastName); ?></span>
                                    </a>
                                </li>
                            <?php endforeach; ?>
						<?php endif; ?>
                    </ul>
                </div>
            </div>
            <div class="col-md-6 px-lg-4 tab-content border-right-gray">
                <?php
                if (is_array($persons)):
                    $j = 1;
                    foreach ($persons as $person):
                        ?>
                        <div id="whpp-<?php echo $person->id; ?>" class="tab-pane fade <?php echo ($j == 1) ? 'active' : ''; ?> show">
                            <div class="row">
                                    <?php if ($j == 1): ?>
                                    <div class="col-md-6 pt-3 order-md-2 text-right">
                                        <?php
                                        $memberdata = array("ownerNumber" => ($_SESSION['ownerinfo'][0]) ? $_SESSION['ownerinfo'][0] : '',
                                            "personId" => $person->id,
                                            "address" => $person->addresses,
                                            "phones" => $person->phones,
                                            "email" => $person->emails);
                                        ?>

                                        <a href="javaScript:void(0)" data-toggle="modal" data-target="#owner_details" data-persondata= '<?php echo json_encode($memberdata); ?>' > <i id="owner-edit"  class="fa fa-lg fa-pen"></i> </a>
                                    </div>
                                    <?php
                                endif;
                                $j++;
                                ?>
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Owner Number</small>
                                    <p class="mb-0"><?php echo $personsdata->data->membershipNumber; ?></p>
                                </div>
                            </div>
                            <div class="row">
                               <!-- <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Birthday</small>
                                    <p class="mb-0"><?php echo (!empty($person->dob)) ? date_i18n(get_option('date_format'), substr($person->dob, 0, -3)) : 'DOB not available' ; ?></p>
                                </div>-->
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Member Since</small>
                                    <p class="mb-0">
                                        <?php
                                        if (isset($membersince) && !empty($membersince)) {
                                            echo date_i18n(get_option('date_format'), substr($membersince, 0, -3) + (60 * 60 * 24));
                                        } else {
                                            _e("Data not found.");
                                        }
                                        ?>
                                    </p>
                                </div>
                            </div>
                            <div class="row d-none d-sm-block">
                                <div class="col-md-12 d-flex d-sm-block justify-content-between pt-3">
                                    <h6 class="sub-heading m-0">Contact</h6>
                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-12 d-flex d-sm-block justify-content-between py-2">
                                    <small>Email</small>
                                    <?php
                                    if (is_array($person->emails) && isset($person->emails)):
                                        foreach ($person->emails as $email):
                                            ?>
                                            <p class="mb-0"><?php echo $email->email; ?></p>
                                            <?php
                                        endforeach;
                                    endif;
                                    ?>

                                </div>
                            </div>
                            <div class="row">
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Phone Number</small>
                                    <?php
                                    if (is_array($person->phones) && isset($person->phones)):
                                        foreach ($person->phones as $phone):
                                            if (isset($phone->number) && $phone->number > 0):
                                                ?>
                                                <p class="mb-0"><?php echo $phone->number; ?></p>

                                                <?php
                                            endif;
                                        endforeach;
                                    endif;
                                    ?>
                                </div>
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Address</small>
                                    <?php if (is_array($person->addresses) && isset($person->addresses)): ?>
                                            <?php foreach ($person->addresses as $address): ?>
                                            <p class="mb-0 text-right text-sm-left">
                                                <?php echo (isset($address->addressLine1) && !empty($address->addressLine1)) ? $address->addressLine1 : ""; ?> 
                                                <?php echo (isset($address->addressLine2) && !empty($address->addressLine2)) ? ",<br/>" . $address->addressLine2 : ""; ?> 
                                                <?php echo (isset($address->addressLine3) && !empty($address->addressLine3)) ? ",<br/>" . $address->addressLine3 : ""; ?>
                                                <?php echo (isset($address->suburb) && !empty($address->suburb)) ? $address->suburb : ""; ?> 
                                            <?php echo (isset($address->postcode) && !empty($address->postcode)) ? $address->postcode : ""; ?> 
                                            </p>
                                        <?php endforeach; ?>
        <?php endif; ?>
                                </div>
                            </div>
							<div class="row">
							   <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
							      <small>Tier</small><br/>
								  <?php
									if (!empty($owner_trial_tier)) {
										echo ucwords(strtolower($owner_trial_tier));
									} else {
										echo $tierName;
									}
								  ?>
							   </div>
							</div>
                            <!--<div class="row d-block d-sm-none">
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Wyndham KM Travelled</small>
                                    <p class="mb-0">6, 40, 001</p>
                                </div>
                                <div class="col-md-6 d-flex d-sm-block justify-content-between py-2">
                                    <small>Privileges</small>
                                    <p class="mb-0">Elite</p>
                                </div>
                            </div>-->
                        </div>

                    <?php endforeach; ?>
                <?php else: ?>
                    <h5 class="p-3">No data available for this user</h5>
<?php endif; ?>
         </div>
            <div class="col-md-6 px-lg-4">

                <div class="row">
                    <!-- <div class="col-md-12 py-3">
                         <a class="btn edit-privileges"> Edit Privileges </a>
                     </div> -->
                </div>

                <div class="row">
                    <div class="col-md-7 col-sm-6 py-3">
                        <ul class="list-unstyled privilege-links">
                            <li> <a href="<?php echo (get_field("book_owner_education_workshop", "options")) ? get_field("book_owner_education_workshop", "options") : " "; ?>" target="_blank" > Book Owner Education Workshop </a> </li>
                            <?php if (get_field("tell_us_more_about_you", "options")): ?>
                                <li> <a href="javaScript:void(0)" data-toggle="modal" data-target="#more_about_you"> Tell Us More About You </a> </li>
								<li><a href="https://us2.list-manage.com/subscribe?u=0d9a7cc916681abe66f174498&id=a3319891b3" target="_blank">Email Preferences</a></li>
<?php endif; ?>
                        </ul>
                        <h6 class="sub-heading pt-3"> Payment </h6>
                        <ul class="list-unstyled privilege-links">
                            <?php if (have_rows('payment', 'options')): ?>
                                <?php
                                while (have_rows('payment', 'options')): the_row();

                                    $target = '';
                                    $tab = get_sub_field('open_in_new_tab');
                                    if ($tab == 1) {
                                        $target = 'target="_blank"';
                                    }
                                    ?>
                                    <li> <a href="<?php echo (the_sub_field('url')) ? the_sub_field('url') : " "; ?>" <?php echo $target; ?> > <?php echo the_sub_field('lable'); ?> </a> </li>
                                <?php endwhile; ?>
<?php endif; ?>
                        </ul>
						<h6 class="sub-heading pt-3"> Annual Levy </h6>
                        <ul class="list-unstyled privilege-links"> 
                        	<li> <a href="https://pitstop.wyndhamvrap.com/annual-levies-notification/"> 2022 - Annual Levies </a> </li>
                        </ul>
                    </div>

                    <div class="col-md-5 col-sm-6 py-2">
                        <h6 class="sub-heading pt-2"> Quick links </h6>
                        <ul class="list-unstyled privilege-links">
                            <?php if (have_rows('quick_links', 'options')): ?>
                                <?php
                                while (have_rows('quick_links', 'options')): the_row();

                                    $target = '';
                                    $tab = get_sub_field('open_in_new_tab');
                                    if ($tab == 1) {
                                        $target = 'target="_blank"';
                                    }
                                    $url = get_sub_field('url');
                                    $url = str_replace('{{user_session_token}}', $user_session_token, $url);
                                    ?>
                                    <li> <a  href="<?php echo $url ? $url : ""; ?>" <?php echo $target; ?>> <?php echo the_sub_field('lable'); ?> </a> </li>
                                <?php endwhile; ?>
<?php endif; ?>
                        <li><a href="https://booking.wyndhamvrap.com/reservation-history/?param=<?php echo base64_encode($param); ?>">Reservation History</a> </li>
						<li><a href="https://booking.wyndhamvrap.com/edit-profile/?param=<?php echo base64_encode($param); ?>">Edit Your Profile</a> </li>
                        <li><a href="/owner-certificate/" target="_blank">Owner Certificate</a> </li>
						<li><a href="/wr-exchange-program/" target="_blank">Wyndham Rewards Exchange</a> </li>
                        <li><a href="https://clubwyndhamsp.com/wp-content/uploads/2021/03/21-574-CW-Annual-Leavies-Owner-Dashboard-Digi.pdf" target="_blank">2021 Annual Levies</a> </li>
                        
                         

						
                        </ul>
                    </div>
                </div>

            </div>
        
    </div>
   </div>
    <div class="row">
        <div class="col-md-9">
            <div class="row mt-3 mt-sm-5">
                <div class="col-md-12">
                    <h5 class="h5 p-4 mb-0 bg-white text-primary">Credit Balance</h5>
                </div>
            </div>
            <div class="row">
                <div class="col-md-8">
                    <div class="dashboard-box-shadow credit-eligibility">
                        <h6 class="mt-0 p-3 subtitle">Available Credits</h6>
                        <div>
                            <?php
                            if (isset($_SESSION["ownerinfo"][0])) {
						
                                $resudata = json_decode(getUserInfo('https://hub.wyndhamap.com/hub-api/iris/get-credit-expiry/', $_SESSION["ownerinfo"][0]));
                                if ($resudata->status == 'success') {
                                    // print_r($resudata->data);
                                    // exit;
                                    ?>
                                    <table class="table mb-0 d-none d-sm-block d-sm-table">
                                        <thead>
                                            <tr>
                                                <th scope="col">Eligibility Type</th>
                                                <th scope="col">Credits</th>
                                                <th scope="col">Expiration Date</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <?php
											$allExpiringCredits = 0;
                                            foreach ($resudata->data as $value) {
                                                ?>
                                                <tr>
                                                    <td class="text-primary font-weight-bold"><?php echo $value->eligibilityType; ?></td>
                                                    <td><?php 
													echo $value->expiringCreditAmt; 
													$allExpiringCredits = $allExpiringCredits + $value->expiringCreditAmt;
													?></td>
                                                    <td><?php echo $value->creditExpirationDate; ?></td>
                                                </tr>
											<?php 
											} 
											echo "<tr><td>Sub Total</td><td>".$allExpiringCredits."</td><td></td></tr>";
											?>
		
                                        </tbody>
                                    </table>
                                    <table class="table table-borderless d-block d-sm-none">
                                        <?php
                                        foreach ($resudata->data as $value) {
                                            ?>
                                            <tr>    
                                                <th colspan="2" class="text-primary"><?php echo $value->eligibilityType; ?></th>
                                            </tr>
                                            <tr>
                                                <td>Credits</td>
                                                <td><?php echo $value->expiringCreditAmt; ?></td>
                                            </tr>
                                            <tr class="border-bottom">
                                                <td>Expiration Date</td>
                                                <td><?php echo $value->creditExpirationDate; ?></td>
                                            </tr>                            
                                    <?php } ?>
                                    </table>
                                    <?php
                                } else { ?>
									<table class="table mb-0 d-none d-sm-block d-sm-table">
                                        <thead>
                                            <tr>
                                                <th scope="col" align="center">Eligibility Type</th>
                                                <th scope="col" align="center">Credits</th>
                                                <th scope="col" align="center">Expiration Date</th>
                                            </tr>
                                        </thead>
										   <tr>
										  <td>Sub Total</td>
										  <td>0</td>
										  <td></td>
										 </tr>
								  </table>
                                    
                              <?php  }
                            } else {
                                echo '<h5 class="p-3">No data available for this user</h5>';
                            }
                            ?>
                        </div>
                    </div>
                </div>
                <div class="col-md-4 d-none d-sm-block">
                    <div class="annual-credits dashboard-box-shadow p-4">
                        <h6 class="subtitle">Annual Credits</h6>
                        <h4 class="text-primary"><?php echo $annual_credit; ?> &nbsp;<small class="font-size-sm text-muted">Credits</small></h4>
                    </div>
                    <div class="available-to-borrow dashboard-box-shadow mt-3 p-4">
                        <h6  class="subtitle">Available to borrow</h6>
                        <h4 class="text-primary"><?php echo $availableToBorrow_credit; ?> &nbsp;<small class="font-size-sm text-muted">Credits</small></h4>
                    </div>
                    <div class="available-to-borrow dashboard-box-shadow mt-3 p-4">
                        <h6  class="subtitle">Available + Available to borrow</h6>
                        <h4 class="text-primary"><?php echo $availableToBorrow_credit + $available_credit; ?> &nbsp;<small class="font-size-sm text-muted">Credits</small></h4>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-3 mb-4 mb-sm-0">
            <div class="mt-3 mt-sm-5">
                <h5 class="h5 p-4 mb-0 bg-white text-primary"> Housekeeping Tokens </h5>
            </div>
            <section class="row">
                <div class="col-12">
                    <article class="credit-eligibility dashboard-box-shadow p-4">
                        <h6  class="subtitle">Available</h6>
                        <h4 class="text-primary"><?php echo (isset($_SESSION['WHPPDATA']->data->housekeeping)) ? $_SESSION['WHPPDATA']->data->housekeeping : 0; ?></h4>
                    </article>
                    <article class="house-keeping-tokens dashboard-box-shadow p-4 mt-3">
                        <h6  class="subtitle">Available to borrow</h6>
                        <h4 class="text-primary"><?php echo (isset($_SESSION['WHPPDATA']->data->availableBonus)) ? $_SESSION['WHPPDATA']->data->availableBonus : 0; ?></h4>
                    </article>
                </div>

            </section>
        </div>
    </div>

    <?php
    $financedata = '';
    if (isset($_SESSION["ownerinfo"][0])) {
        $financedata = json_decode(getUserInfo('https://hub.wyndhamap.com/hub-api/finance/get-ownership-finance-details/', $_SESSION["ownerinfo"][0]));
    }
    if (isset($financedata->status) && $financedata->status == 'success') {
        // print_r($resudata->data);
        // exit;
        ?>
        <div class="row mt-3 mt-sm-5">       
            <div class="col-md-6 mb-4 mb-sm-0">
                <section class="levies-finance dashboard-box-shadow h-100">
                    <h5 class="h5 text-primary border-bottom-gray p-3 mb-0"> Finance </h5>
                    <article class="py-3 aricle_finance grid-overflow">
                        <table class="table table-borderless">                        
                            <tr>
                                <td> <h6 class="subtitle m-0">Finance Account Status </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->financeStatus)) ? $financedata->data->financesList[0]->financeStatus : "--"; ?> </h6> </td>
                            </tr>      
							<?php if(isset($financedata->data->financesList[0]->financeStatus) && $financedata->data->financesList[0]->financeStatus != 'Paid Off') { ?> 							
                            <tr>
                                <td> <h6 class="subtitle m-0">Currency </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->currency)) ? $financedata->data->financesList[0]->currency : "--"; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Overdue Amount </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->financeOverdue)) ? $financedata->data->financesList[0]->financeOverdue : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Finance Payout Amount  </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->cashOutAmount)) ? $financedata->data->financesList[0]->cashOutAmount : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Current Interest Amount  </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->interestRate)) ? $financedata->data->financesList[0]->interestRate : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Daily Interest Amount  </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->dailyInterestAmount)) ? $financedata->data->financesList[0]->dailyInterestAmount : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Monthly Repayment Amount  </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->paymentAmount)) ? $financedata->data->financesList[0]->paymentAmount : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0"> Monthly Payment Due Date </h6> </td>
                                <td> <h6 class="text-primary m-0"> 
                                        <?php echo (isset($financedata->data->financesList[0]->cycleDay)) ? $financedata->data->financesList[0]->cycleDay : 0; ?> 
    <?php echo (isset($financedata->data->financesList[0]->cycleDaySuffix)) ? $financedata->data->financesList[0]->cycleDaySuffix : 0; ?>  of each month 
                                    </h6> 
                                </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0"> Finance Direct Debit Setup </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo ( isset($financedata->data->financesList[0]->financeDirectDebit) && $financedata->data->financesList[0]->financeDirectDebit == 1) ? 'YES' : 'NO'; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Finance Payment Method </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->financePayMethod)) ? $financedata->data->financesList[0]->financePayMethod : "--"; ?> </h6> </td>
                            </tr>  
							<?php
							}
							?>
                        </table>
                    </article>
                </section>
            </div>
            <div class="col-md-6 mb-4 mb-sm-0">
                <section class="credit-eligibility dashboard-box-shadow h-100">
                    <h5 class="h5 text-primary border-bottom-gray p-3 mb-0"> Levies </h5>
                    <article class="py-3 aricle_finance grid-overflow">
                        <table class="table table-borderless">
                            <tr>
                                <td> <h6 class="subtitle m-0">Levies Account Status </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->leviesStatus)) ? $financedata->data->financesList[0]->leviesStatus : "--"; ?> </h6> </td>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Currency </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->currency)) ? $financedata->data->financesList[0]->currency : "--"; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Overdue Amount </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->leviesOverdue)) ? $financedata->data->financesList[0]->leviesOverdue : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Payment Frequency </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->leviesPayFrequency)) ? $financedata->data->financesList[0]->leviesPayFrequency : "--"; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Payment Amount </h6> </td>
                                <td> <h6 class="text-primary m-0"> $<?php echo (isset($financedata->data->financesList[0]->leviesPayAmount)) ? $financedata->data->financesList[0]->leviesPayAmount : 0; ?> </h6> </td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Levies Direct Debit Setup </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->leviesDirectDebit) && $financedata->data->financesList[0]->leviesDirectDebit == 1) ? 'YES' : 'NO'; ?> </h6>								
								</td>
                            </tr>
                            </tr>                             
                            <tr>
                                <td> <h6 class="subtitle m-0">Levies Payment method </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo (isset($financedata->data->financesList[0]->leviesPayMethod)) ? $financedata->data->financesList[0]->leviesPayMethod : " --"; ?> </h6> </td>
                            </tr>
                        </table>
						<h5 class="h5 text-primary border-bottom-gray p-3 mb-0"> Levy Composition </h5>
						<?php
							$operating = 86.74;
							$insurance = 0.78;
							$reserveFund = 12.47;
							$gst = 0.00;
							$totalLevy = $operating + $insurance + $reserveFund + $gst + 0.01;
						?>
						<table class="table table-borderless">
                            <tr>
                                <td> <h6 class="subtitle m-0">Operating </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo $operating.'%'; ?> </h6> </td>
								<?php
								      $oper = 0.000;
									  $ins = 0.000;
									  $rsFund = 0.000;
									  $gst1 = 0.000;
								  if (isset($financedata->data->financesList[0]->leviesAnnual)){
									  $oper = number_format((float)(($financedata->data->financesList[0]->leviesAnnual)*($operating/100)), 3, '.', '');
									  $ins = number_format((float)(($financedata->data->financesList[0]->leviesAnnual)*($insurance/100)), 3, '.', '');
									  $rsFund = number_format((float)(($financedata->data->financesList[0]->leviesAnnual)*($reserveFund/100)), 3, '.', '');
									  $gst1 = number_format((float)(($financedata->data->financesList[0]->leviesAnnual)*($gst/100)), 3, '.', ''); 
								  }
								      $totLevy = $oper + $ins + $rsFund + $gst1;
								?>
								<td> <h6 class="text-primary m-0"> <?php echo '$'.number_format((float)$oper, 2, '.', ''); ?> </h6> </td>
                            </tr>
							<tr>
                                <td> <h6 class="subtitle m-0">Insurance </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo $insurance.'%'; ?> </h6> </td>
								<td> <h6 class="text-primary m-0"> <?php echo '$'.number_format((float)$ins, 2, '.', ''); ?> </h6> </td>
                            </tr>
							<tr>
                                <td> <h6 class="subtitle m-0">Reserve Fund </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo $reserveFund.'%'; ?> </h6> </td>
								<td> <h6 class="text-primary m-0"> <?php echo '$'.number_format((float)$rsFund, 2, '.', ''); ?> </h6> </td>
                            </tr>
							<tr>
                                <td> <h6 class="subtitle m-0">GST </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo $gst.'%'; ?> </h6> </td>
								<td> <h6 class="text-primary m-0"> <?php echo '$'.number_format((float)$gst1, 2, '.', ''); ?> </h6> </td>
                            </tr>
							<tr>
                                <td> <h6 class="subtitle m-0">Total Levy </h6> </td>
                                <td> <h6 class="text-primary m-0"> <?php echo number_format((float)$totalLevy, 2, '.', '').'%'; ?> </h6> </td>
      							<td> <h6 class="text-primary m-0"> <?php echo '$'.number_format((float)$totLevy, 2, '.', ''); ?> </h6> </td>
                            </tr>
                            
                        </table>
                    </article>

                </section>
            </div>
        </div>
<?php } ?>
    <div class="row mt-3 mt-sm-5">
        <div class="col-lg-6">
            <section class="reservation-history dashboard-box-shadow">
                <h5 class="h5 text-primary border-bottom-gray px-4 py-3 m-0"><a href="https://booking.wyndhamvrap.com/reservation-history/?param=<?php echo base64_encode($param); ?>">Reservation History</a></h5>
                <?php
                if (isset($reservationdata->status) && $reservationdata->status == 'success') {
                    ?>

                    <div class="grid-overflow" style="min-height:0px !important">
                        <table class="d-none d-sm-block d-sm-table table mb-0">
                            <thead>
                                <tr>
                                    <th>Check-In Date</th>
                                    <th>Resort Name</th>
									<th>Reservation Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                foreach ($reservationdata->data as $value) {
                                    ?>
                                    <tr>
                                        <td>
        <?php $wpdb ?>
                                            <?php echo date_i18n(get_option('date_format'), substr($value->checkinDate, 0, -3) + (60 * 60 * 24)); ?></td>
                                        <td class="text-light text-primary m-0"><?php echo $value->resort->name; ?></td>
										<td class="text-light text-primary m-0"><?php echo $value->status->name; ?></td>
                                    </tr>
    <?php } ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="list-group d-block d-sm-none" style="max-height:300px; overflow-y:auto !important;">
                        <?php
                        foreach ($reservationdata->data as $value) {
                            ?>
                            <a href="#" class="list-group-item list-group-item-action flex-column align-items-start rounded-0">
                                <div class="d-flex w-100 justify-content-between">
                                    <h5 class="mb-0 text-primary"><?php echo date_i18n(get_option('date_format'), substr($value->checkinDate, 0, -3) + (60 * 60 * 24)); ?></h5>
                                </div>
                                <p class="mb-1"><?php echo $value->resort->name; ?></p>
                            </a>                    
    <?php } ?>
                    </div>

                    <?php
                } else {
                    echo '<h5 class="p-3">No data available for this user</h5>';
                }
                ?>
            </section>
        </div>
        <div class="col-lg-6 mt-3 mt-lg-0 mt-sm-3 p-lg-0">
            <section class="benefit-panel dashboard-box-shadow">
                <h5 class="h5 text-primary p-3 border-bottom-gray">Benefits Panel for <?php
									if (!empty($owner_trial_tier)) {
										echo ucwords(strtolower($owner_trial_tier));
									} else {
										echo $tierName;
									}
								  ?></h5>
                <div class="grid-overflow d-none d-sm-block">
                    <ul class="list-group mb-0 d-none d-sm-block">
                        <?php
                        $today = date('Ymd');
                        $args = array(
                            'post_type' => 'benefit',
                            'posts_per_page' => -1,
                            'meta_query' => array(
                                'relation' => 'AND',
                                array(
                                    'key' => 'date_range_from',
                                    'value' => $today,
                                    'compare' => '<=',
                                    'type' => 'CHAR'
                                ),
                                array(
                                    'key' => 'date_range_to',
                                    'value' => $today,
                                    'compare' => '>=',
                                    'type' => 'CHAR'
                                )
                            ),
                            'tax_query' => array(
                                array(
                                    'taxonomy' => 'owner',
                                    'field' => 'slug',
                                    'terms' => $owner_type
                                ),
                            )
                        );
                        $the_query = new WP_Query($args);
                        if ($the_query->have_posts()) {
                            while ($the_query->have_posts()) : $the_query->the_post();
                                ?>
                                <li class="list-group-item d-flex">
								<a traget = "_blank" href="<?php echo get_field("more_info_link"); ?>"><?php the_title(); ?></a> 
								<span class="py-3 pl-5 pr-2 <!--text-truncate --> "><?php echo get_field("message"); ?></span></li>						 
                                <?php
                            endwhile;
                        } else {
                            echo '<li class="d-flex"><h5 class="p-3">No Benefits for this user</h5></li>';
                        }
                        ?>                
                    </ul>
                </div>
                <div class="list-group d-block d-sm-none" style="max-height:300px; overflow-y:auto !important;">
                    <?php
                    if ($the_query->have_posts()) {
                        while ($the_query->have_posts()) : $the_query->the_post();
                            ?>
                            <a href="<?php echo get_field("more_info_link"); ?>" class="list-group-item list-group-item-action flex-column align-items-start rounded-0 p-3 border-bottom m-0 border-top-0 border-left-0 border-left-0">
                                <div class="d-flex w-100 justify-content-between">
                                    <h5 class="mb-0 text-primary"><?php the_title(); ?></h5>
                                </div>
                                <p class="mb-1"><?php echo get_field("message"); ?></p>
                            </a>
                            <?php
                        endwhile;
                    } else {
                        echo '<h5 class="p-3">No Benefits for this user</h5>';
                    }
                    ?>     
                </div>
            </section>
        </div>
    </div>

    <div class="row mt-5">
        <div class="col-md-12">
            <div class="dashboard-deals hot-Deals">
                <?php
                $args = array(
                    'post_type' => 'deals',
                    'meta_key' => 'deal_type',
                    'meta_value' => 'deal',
                    'posts_per_page' => -1,
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'deal_types',
                            'field' => 'slug',
                            'terms' => 'hot-deals'
                        ),
                    )
                );
                $the_query = new WP_Query($args);
                if ($the_query->have_posts()) {
                    $colors = array("light-blue", "light-green", "orange", "blue", "pink", "yellow");
                    $i = 0;
                    while ($the_query->have_posts()) : $the_query->the_post();
                        ?>
                        <div class="col-lg-4 col-md-6">
                            <div class="card rounded-0  mb-4 hot_deals_row_1 <?php echo $colors[$i]; ?>">
                                <div class="picture">
                                    <?php
                                    $image = get_field('deal_image');
                                    if (!empty($image)):
                                        ?>
                                        <a href="<?php the_permalink(); ?>" class="card-img-top"><img src="<?php echo $image['url']; ?>" alt="Card image cap"></a>
        <?php endif; ?>
                                    <div class="deal"><span><?php the_field('duration'); ?></span><span>Days</span></div>
                                </div>
                                <div class="card-body">
                                    <h5 class="card-title"> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h5>					
                                    <p class="card-text"><span><?php the_field('currency'); ?> <?php the_field('price'); ?><?php the_field('credits'); ?></span></p>
                                </div>
                                <div class="card-footer"> <?php the_field('footer_info'); ?> </div>
                            </div>
                        </div>
                        <?php
                        $i++;
                    endwhile;
                }
                ?>
            </div>
        </div>
    </div>




    <div class="modal fade" id="owner_details">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">
                <form id="owner-details">
                    <div class="modal-header">
                        <h4 class="modal-title">Owner Details</h4>
                        <button type="button" class="close" data-dismiss="modal">&times;</button>
                    </div>

                    <div class="modal-body" style="max-height: 520px; overflow-y: auto;">

                        <input type="hidden" class="form-control" id="OwnerNumber" name="OwnerNumber" >
                        <input type="hidden" class="form-control" id="personId" name="personId">
                        <input type="hidden" class="form-control" id="action" name="action" value="ownerupdate">

                        <div class="form-group">
                            <label for="email">Email :</label>
                            <input type="email" class="form-control" id="email" name="email">
                        </div>
                        <div class="form-group">
                            <label for="Address1">Address Line 1 :</label>
                            <textarea rows="3" class="form-control" id="Address1" name="Address1"></textarea>
                        </div>
                        <div class="form-group">
                            <label for="Address2">Address Line 2 :</label>
                            <textarea rows="3" class="form-control" id="Address2" name="Address2"></textarea>
                        </div>

                        <div class="form-group">
                            <label for="suburb">Suburb :</label>
                            <input type="text" class="form-control" id="suburb" name="suburb">
                        </div>

                        <div class="form-group">
                            <label for="country">Country :</label>
                            <select class="form-control" id="country" name="country">
                                <option value="">Please Select</option>
                                <option value="AUS">Australia</option>
                                <option value="NZ">New Zealand</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="state">State :</label>
                            <select class="form-control" id="state" name="state" value="state">
                                <option value="">Please Select</option>
                                <option value="ACT">Australian Capital Territory</option>
                                <option value="NSW">New South Wales</option>
                                <option value="NT">Northern Territory</option>
                                <option value="QLD">Queensland</option>
                                <option value="SA">South Australia</option>
                                <option value="TAS">Tasmania</option>
                                <option value="VIC">Victoria</option>
                                <option value="WA">Western Australia</option>
                                <option value="NA">Not Applicable</option>
                            </select>
                        </div>

                        <div class="form-group">
                            <label for="postcode">Postcode :</label>
                            <input type="text" class="form-control" name="Postcode" id="Postcode">
                        </div>

                        <div class="form-group">
                            <label for="homePhone">Home Phone :</label>
                            <input type="text" class="form-control" name="homePhone" id="homePhone">
                        </div>

                        <div class="form-group">
                            <label for="mobilePhone">Mobile Phone :</label>
                            <input type="text" class="form-control" id="mobilePhone" name="mobilePhone">
                        </div>

                        <div class="form-group">
                            <label for="workPhone">Work Phone :</label>
                            <input type="text" class="form-control" id="workPhone" name="workPhone">
                        </div>

                    </div>

                    <div class="modal-footer">
                        <button type="submit" class="btn btn-outline-primary" >Update</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="modal fade" id="more_about_you">
        <div class="modal-dialog modal-dialog-centered modal-lg">
            <div class="modal-content">

                <div class="modal-header">
                    <h4 class="modal-title"> Tell Us More About You</h4>
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                </div>


                <div class="modal-body" id="tell-us-more-about-you" style="max-height: 570px; overflow-y: auto;">

                    <?php
                    if (get_field("tell_us_more_about_you", "options")) {
                        $code = get_field("tell_us_more_about_you", "options");
                        if (isset($_SESSION["ownerinfo"])) {
                            $code = str_replace("]", "userid='" . $_SESSION["ownerinfo"][0] . "']", $code);
                        }

                        //[contact-form-7 id="1192" title="Tell Us More About You"]
                        $match_res = preg_match('/id="([^"]*)"/i', $code, $matches);
                        $formid = $matches[1];
                        echo do_shortcode($code);
                    }
                    ?>	  
                    <!-- <div class="form-group">
                         <label for="Phone">Phone :</label>
                         <input type="text" class="form-control" id="Phone">
                     </div>
                     <div class="form-group">
                         <label for="email">Email :</label>
                         <input type="email" class="form-control" id="email">
                     </div> -->
                </div>
            </div>
        </div>
    </div>
</div>
<?php
if (get_field("tell_us_more_about_you", "options")) {
    $code = get_field("tell_us_more_about_you", "options");
    $match_res = preg_match('/id="([^"]*)"/i', $code, $matches);
    ?>
    <script type="text/javascript">
        var whppformid = <?php echo $formid; ?>;
        document.addEventListener('wpcf7mailsent', function (event) {
            if (whppformid == event.detail.contactFormId) {
                var msg = '<div class="text-center text-success pt-3"><i class="fa fa-check-circle fa-5x"></i></div><p class="text-center h5 my-5 px-md-5">' + event.detail.apiResponse.message + '</p>';
                jQuery('div #tell-us-more-about-you').html(msg);
            }
        }, false);
    </script>
    <?php
}
?>

<?php get_footer();
?>
<script src="<?php echo get_stylesheet_directory_uri() . '/html/js/jquery.nicescroll.min.js'; ?>"></script>
<script>

        (function ($) {
            'use strict';
            $(document).ready(function () {

                $("#owner-details").validate({

                    rules: {
                        email: {email: true},
                        Address1: {required: true, maxlength: 250},
                        Address2: {maxlength: 250},
                        suburb: {required: true, maxlength: 100},
                        state: {required: true, maxlength: 2},
                        postcode: {number: true, minlength: 4, maxlength: 4, required: true},
                        country: {required: true, maxlength: 2},
                        homePhone: {number: true, minlength: 6, maxlength: 10},
                        mobilePhone: {number: true, minlength: 10, maxlength: 10},
                        workPhone: {number: true, minlength: 6, maxlength: 10},
                        country: {required: true, maxlength: 2},
                    },
                    submitHandler: function (form, e) {
                        //form.submit();
                        e.preventDefault();
                        var data = $(form).serialize();

                        $.ajax({
                            method: "POST",
                            url: ajax_object.ajax_url,
                            data: data
                        }).done(function (res) {
                            console.log("success" + res);
                            var res = JSON.parse(res);
                            if (res.status) {
                                console.log(res);
                                var msg = '<div class="text-center text-success pt-3"><i class="fa fa-check-circle fa-5x"></i></div><p class="text-center h5 my-5 px-md-5">' + res.msg + '</p>';
                                $('.modal-body').html(msg);
                                $(".modal-footer").html('');
                            } else {
                                console.log(res);
                                var msg = '<div class="text-center text-danger pt-3"><i class="fa fa-times-circle fa-5x"></i></div><p class="text-center h5 my-5 px-md-5">' + res.msg + '</p>';
                                $('.modal-body').html(msg);
                                $(".modal-footer").html('');
                            }

                        }).fail(function (jqXHR, res) {
                            console.log("fail" + res);
                        });

                    }
                });

                $('#owner_details').on('show.bs.modal', function (e) {

                    //var $el = $("#owner-edit");
                    var persondata = $(e.relatedTarget).data('persondata');
                    console.log(persondata);
                    $(e.currentTarget).find('#OwnerNumber').val(persondata.ownerNumber);
                    $(e.currentTarget).find('#personId').val(persondata.personId);
                    $(e.currentTarget).find('#Address1').val(persondata.address[0].addressLine1);
                    $(e.currentTarget).find('#Address2').val(persondata.address[0].addressLine2);
                    $(e.currentTarget).find('#suburb').val(persondata.address[0].suburb);
                    $(e.currentTarget).find('#Postcode').val(persondata.address[0].postcode);

                    var phs = persondata.phones;

                    phs.forEach(function (item, index) {

                        if ("MOBILE" == item.type)
                            $(e.currentTarget).find('#mobilePhone').val(item.number);
                        if ("HOME" == item.type)
                            $(e.currentTarget).find('#homePhone').val(item.number);
                        if ("WORK" == item.type)
                            $(e.currentTarget).find('#workPhone').val(item.number);
                    })

                    $(e.currentTarget).find('#email').val(persondata.email[0].email);
                    debugger;
                    if (persondata.address[0].state.code) {
                        $("#state").find('option:selected').removeAttr("selected");
                        $('#state [value="' + persondata.address[0].state.code + '"]').attr('selected', 'true');
                    }
                    if (persondata.address[0].country.code) {
                        $("#country").find('option:selected').removeAttr("selected");
                        $('#country [value="' + persondata.address[0].country.code + '"]').attr('selected', 'true');
                    }

                });

                $(".youdob").datepicker({
                    format: "dd-mm-yyyy",
                    todayBtn: true,
                    autoclose: true,
                    todayHighlight: true
                });
            });

            $(document).on('show.bs.tab', '.nav-tabs-responsive [data-toggle="tab"]', function (e) {
                var $target = $(e.target);
                var $tabs = $target.closest('.nav-tabs-responsive');
                var $current = $target.closest('li');
                // var $parent = $current.closest('li.dropdown');
                //    $current = $parent.length > 0 ? $parent : $current;
                var $next = $current.next();
                var $prev = $current.prev();
                $tabs.find('>li').removeClass('next prev active');
                $tabs.find('>li>a').removeClass('fa fa-angle-right fa-angle-left');
                $prev.addClass('prev').find("a").addClass("fa fa-angle-left");
                $next.addClass('next').find("a").addClass("fa fa-angle-right");
                $current.addClass("active");
            });


            $('.dashboard-deals').slick({
                infinite: false,
                speed: 300,
                slidesToShow: 3,
                slidesToScroll: 3,
                responsive: [
                    {
                        breakpoint: 1024,
                        settings: {
                            slidesToShow: 3,
                            slidesToScroll: 3,
                            infinite: true,
                            dots: true
                        }
                    },
                    {
                        breakpoint: 600,
                        settings: {
                            slidesToShow: 2,
                            slidesToScroll: 2
                        }
                    },
                    {
                        breakpoint: 480,
                        settings: {
                            slidesToShow: 1,
                            slidesToScroll: 1
                        }
                    }
                ]
            });

            $(".notification .list-group, .reservation-history .list-group, .benefit-panel .list-group, .dashboard-rp-1, .grid-overflow").niceScroll({
                cursorcolor: "#828282",
                cursorwidth: "10px",
                cursoropacitymin: 0,
                zindex: 1050,
                autohidemode: "leave",
                railpadding: {top: 0, right: 3, left: 0, bottom: 0}
            });
            $(".notification .list-group, .reservation-history .list-group, .benefit-panel .list-group, .dashboard-rp-1, .grid-overflow").getNiceScroll().resize();
        })(jQuery);
</script>