Calendar ID not set. Please check the shortcode.
';}
else {
global $abcUrl;
wp_enqueue_style( 'styles-css', $abcUrl.'frontend/css/styles.css' );
wp_enqueue_style( 'font-awesome', $abcUrl.'frontend/css/font-awesome.min.css' );
global $wpdb;
$er = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.intval($atts['calendar']), ARRAY_A);
if(isset($er[0])) {
$divId = uniqid();
$atts['uniqid'] = $divId;
wp_enqueue_script('abc-ajax', $abcUrl.'frontend/js/abc-ajax.js', array('jquery'));
wp_localize_script( 'abc-ajax', 'ajax_abc_booking_SingleCalendar', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'abc_nonce' => wp_create_nonce('abc-nonce'), 'abc_calendar' => $atts['calendar'] ));
wp_enqueue_script('jquery-ui-button');
wp_enqueue_style('jquery-style', 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css');
if(getAbcSetting('firstdayofweek') == 0) {
$weekdayRow = ''.__('Su', 'advanced-booking-calendar').'
'.__('Mo', 'advanced-booking-calendar').'
'.__('Tu', 'advanced-booking-calendar').'
'.__('We', 'advanced-booking-calendar').'
'.__('Th', 'advanced-booking-calendar').'
'.__('Fr', 'advanced-booking-calendar').'
'.__('Sa', 'advanced-booking-calendar').'
';
} else {
$weekdayRow = ''.__('Mo', 'advanced-booking-calendar').'
'.__('Tu', 'advanced-booking-calendar').'
'.__('We', 'advanced-booking-calendar').'
'.__('Th', 'advanced-booking-calendar').'
'.__('Fr', 'advanced-booking-calendar').'
'.__('Sa', 'advanced-booking-calendar').'
'.__('Su', 'advanced-booking-calendar').'
';
}
$calSingleOutput = '
'.date_i18n('F').' '.date_i18n('Y').'
'.$weekdayRow.'
'.abc_booking_getSingleCalendar($atts).'
';
return $calSingleOutput;
} else { return ' ID unknown.';}
}
}
function abc_booking_getMonth($atts){
if(!isset($atts['month'])) {
$cMonth = date("n");
} else {
$cMonth = date("n") + intval(sanitize_text_field($atts['month']));
}
$cYear = date("Y");
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
return date_i18n('F', $timestamp).' '.date('Y', $timestamp);
}
function ajax_abc_booking_getMonth() {
if(!isset( $_POST['abc_nonce'] ) || !wp_verify_nonce($_POST['abc_nonce'], 'abc-nonce') )
die('Permissions check failed!');
if(!isset($_POST['month'])){
echo 'Month not set.';
} else {
echo abc_booking_getMonth($_POST);
}
die();
}
add_action('wp_ajax_abc_booking_getMonth', 'ajax_abc_booking_getMonth');
add_action( 'wp_ajax_nopriv_abc_booking_getMonth', 'ajax_abc_booking_getMonth');
function abc_booking_getSingleCalendar($atts){
$dateformat = getAbcSetting('dateformat');
$firstdayofweek = getAbcSetting('firstdayofweek');
$calSingleOutput ='';
$divId = sanitize_text_field($atts['uniqid']);
if(!isset($atts['month'])) {
$cMonth = date("n");
} else {
$cMonth = date("n") + sanitize_text_field($atts['month']);
}
$cYear = date("Y");
$prev_year = $cYear;
$next_year = $cYear;
$prev_month = $cMonth-1;
$next_month = $cMonth+1;
if ($prev_month == 0 ) {
$prev_month = 12;
$prev_year = $cYear - 1;
}
if ($next_month == 13 ) {
$next_month = 1;
$next_year = $cYear + 1;
}
$timestamp = mktime(0,0,0,$cMonth,1,$cYear);
$maxday = date("t",$timestamp);
$thismonth = getdate ($timestamp);
// Getting confirmed Bookings for the current month
global $wpdb;
$normFromValue = date("Y-m-", $timestamp).'01';
$normToValue = date("Y-m-", $timestamp).$maxday;
$query = 'SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_bookings
WHERE calendar_id = '.$atts['calendar'].'
AND state = \'confirmed\'
AND ( (start <= \''.$normFromValue.'\' AND end >=\''.$normToValue.'\')
OR (start >= \''.$normFromValue.'\' AND end <= \''.$normToValue.'\')
OR (start >= \''.$normFromValue.'\' AND start <= \''.$normToValue.'\')
OR (start <= \''.$normFromValue.'\' AND end >= \''.$normToValue.'\')
OR (end <= \''.$normFromValue.'\' AND end >= \''.$normToValue.'\')
OR (end >= \''.$normFromValue.'\' AND end <= \''.$normToValue.'\')
)';
$bookings = $wpdb->get_results($query, ARRAY_A);
$priceDates = array();
$lastminutePriceDates = array();
// Getting last minute offers
$queryLastminute = 'SELECT * FROM `'.$wpdb->prefix.'advanced_booking_calendar_seasons_assignment` a
INNER JOIN `'.$wpdb->prefix.'advanced_booking_calendar_seasons` s
ON a.season_id = s.id
WHERE a.calendar_id = '.intval(sanitize_text_field($atts['calendar'])).'
AND a.end >= \''.date("Y-m-d", $timestamp).'\'
AND s.lastminute != 0
ORDER BY a.start';
$er = $wpdb->get_results($queryLastminute, ARRAY_A);
foreach($er as $row) {
$time = strtotime(date_i18n("Y-m-d", $timestamp));
for( $i = 0; $i < $maxday; $i++) {
if(strtotime($row["start"]) <= $time && strtotime($row["end"]) >= $time) {
$lastminutePriceDates[date_i18n("Y-m-d", $time)] = $row["price"];
}
$time += 86400;
}
}
// Getting Prices for the current month for the standard seasons
$query = 'SELECT * FROM `'.$wpdb->prefix.'advanced_booking_calendar_seasons_assignment` a
INNER JOIN `'.$wpdb->prefix.'advanced_booking_calendar_seasons` s
ON a.season_id = s.id
WHERE a.calendar_id = '.intval(sanitize_text_field($atts['calendar'])).'
AND a.end >= \''.date("Y-m-d", $timestamp).'\'
AND s.lastminute = 0
ORDER BY a.start DESC';
$er = $wpdb->get_results($query, ARRAY_A);
foreach($er as $row) {
$time = strtotime(date("Y-m-d", $timestamp));
for( $i = 0; $i < $maxday; $i++) {
if(!isset($priceDates[date("Y-m-d", $time)]) && $row["lastminute"] == 0){
if(strtotime($row["start"]) <= $time && strtotime($row["end"]) >= $time) {
$priceDates[date("Y-m-d", $time)] = $row["price"];
}
$time += 86400;
}
}
}
$er = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.intval(sanitize_text_field($atts['calendar'])), ARRAY_A);
$maxAvailability = $er["maxAvailabilities"];
$pricePreset = esc_html($er["pricePreset"]);
$calendarName = esc_html($er["name"]);
$startday = $thismonth['wday'];
if ($firstdayofweek == 1 ){// If first day of the week is a monday
if($startday == 0){
$startday = 7;
}
} else {
$startday += 1;
}
$cTime = $timestamp;
$emptyDays = 0;
$availDates = array();
for ($i=1; $i<($maxday+$startday); $i++) {
$cAvailability = '';
$availDates[date('Y-m-d', $cTime)] = $maxAvailability;
$cssClass = 'abc-box abc-col-day ';
foreach($bookings as $br) {
if ($cTime >= strtotime($br["start"]) && $cTime < strtotime($br["end"])){
$availDates[date('Y-m-d', $cTime)] -= 1;
}
}
if($i % 7 > 1 || $i % 7 == 0 ) {
$cssClass .= 'abc-dotted ';
}
if($i % 7 == 1) {
$calSingleOutput .= '';
}
if($i < $startday){
$calSingleOutput .='
';
$emptyDays++;
} else {
$newCurrentTime = $cTime-86400*$emptyDays; // Getting a new current time, due to "empty days"
$cPrice = 0;
if(isset($priceDates[date('Y-m-d', $newCurrentTime)])) {
$cPrice = abc_booking_formatPrice($priceDates[date('Y-m-d', $newCurrentTime)]);
} else {
$cPrice = abc_booking_formatPrice($pricePreset);
}
$priceOutput = '
';
$title = '';
if(isset($atts["start"]) && isset($atts["end"])){
// Check if date has been selected by user
if(date('Y-m-d', $newCurrentTime) >= sanitize_text_field($atts["start"]) && date('Y-m-d', $newCurrentTime) <= sanitize_text_field($atts["end"])){
$cssClass .= 'abc-date-selected ';
}
}
if(isset($availDates[date('Y-m-d', $newCurrentTime)]) && date('Y-m-d', $newCurrentTime)>= date('Y-m-d') ) {
$cAvailability = $availDates[date('Y-m-d', $newCurrentTime)];
switch ($cAvailability) {
case $maxAvailability:
$cAvailability = $maxAvailability;
$cssClass .= 'abc-avail abc-date-selector ';
$priceOutput .= $cPrice;
$title = "Available:\n".date($dateformat, $newCurrentTime).": ".$cPrice;
break;
case 0:
$cAvailability = '0';
$cssClass .= 'abc-booked ';
$priceOutput .= ' ';
$title = 'Fully booked';
break;
default:
$cssClass .= 'abc-partly-avail abc-date-selector ';
$priceOutput .= $cPrice;
$title = "Partly available:\n".date($dateformat, $newCurrentTime).": ".$cPrice;
break;
}
} elseif(date('Y-m-d', $newCurrentTime)>= date('Y-m-d')) {
$cAvailability = $maxAvailability;
$cssClass .= 'abc-avail ';
$priceOutput .= $cPrice;
$title = "Available:\n".date($dateformat, $newCurrentTime).": ".$cPrice;
} else {
$cssClass .= 'abc-past ';
}
$priceOutput .= '';
$cssClass .= 'abc-date-item ';
$calSingleOutput .='
'.date('j', ($newCurrentTime)).$priceOutput.'
';
}
if($i % 7 == 0 OR $i == ($maxday+$startday-1)) { // Closing row if week is over or last day of month has been reached.
$calSingleOutput .= '
';
}
$cTime += 86400;
}
$calSingleOutput .= abc_booking_setPageview('single-calendar/'.sanitize_title_with_dashes($calendarName).'/'.date_i18n('Y-m', $timestamp)); // Google Analytics Tracking
return $calSingleOutput;
}
function ajax_abc_booking_getSingleCalendar() {
if(!isset( $_POST['abc_nonce'] ) || !wp_verify_nonce($_POST['abc_nonce'], 'abc-nonce') )
die('Permissions check failed!');
if(!isset($_POST['month'])){
echo 'Month not set.';
} else {
echo abc_booking_getSingleCalendar($_POST);
}
die();
}
add_action('wp_ajax_abc_booking_getSingleCalendar', 'ajax_abc_booking_getSingleCalendar');
add_action( 'wp_ajax_nopriv_abc_booking_getSingleCalendar', 'ajax_abc_booking_getSingleCalendar');
// Called by jQuery, when user clicks on available dates.
function ajax_abc_booking_setDataRange() {
$output = '';
$success = false; // Triggers Google Analytics Tracking, if user selected a date range
if(!isset( $_POST['abc_nonce'] ) || !wp_verify_nonce($_POST['abc_nonce'], 'abc-nonce') )
die('Permissions check failed!');
if(!isset($_POST['start']) OR !isset($_POST['end'])){
$output = 'Dates not set.';
} else {
$start = strtotime(sanitize_text_field($_POST['start']));
$end = strtotime(sanitize_text_field($_POST['end']));
$calendarId = sanitize_text_field($_POST['calendar']);
$dateformat = getAbcSetting('dateformat');
$currency = getAbcSetting('currency');
if($start != 0){
$output .= ''.__('Checkin', 'advanced-booking-calendar').': '.date($dateformat, $start).'
'.__('Checkout', 'advanced-booking-calendar').': ';
if($end != 0 && $end > $start){
$success = true;
$output .= date($dateformat, $end);
$numberOfDays = abc_booking_dateDiffInDays($end, $start);
$output .= '
'.__('Total price', 'advanced-booking-calendar').':
'.abc_booking_formatPrice(abc_booking_getTotalPrice($calendarId, date("Y-m-d", $start), $numberOfDays));
if(getAbcSetting("bookingpage") > 0){ // Checking if bookingpage in the settings has been defined
$output .='
';
} else {
$output .= '-';
}
$output .= '
';
}
}
if($success){
global $wpdb;
$er = $wpdb->get_row('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.$calendarId, ARRAY_A);
$calendarName = esc_html($er["name"]);
$output .= abc_booking_setPageview('single-calendar/'.sanitize_title_with_dashes($calendarName).'/date-selected'); // Google Analytics Tracking
}
echo $output;
die();
}
add_action('wp_ajax_abc_booking_setDataRange', 'ajax_abc_booking_setDataRange');
add_action( 'wp_ajax_nopriv_abc_booking_setDataRange', 'ajax_abc_booking_setDataRange');
?>