get_row('SELECT max(maxUnits) as maxPerson FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars', ARRAY_A); $personCount = 2; if(intval($er['maxPerson']) > 0){ $personCount = intval($er['maxPerson']); } update_option('abc_personcount', $personCount); } function abc_booking_setPageview($pagename){ // Returns tracking code for a pagename $rand = rand(1, 1000); $output = ''; if(getAbcSetting('googleanalytics') == 1){ $output = ''; } return $output; } function abc_booking_validateDate($date, $format = 'Y-m-d') { $dateValid = false; switch ($format) { case 'd.m.Y': if (preg_match("/^(0[1-9]|[1-2][0-9]|3[0-1])\.(0[1-9]|1[0-2])\.[0-9]{4}$/",$date)) { $dateValid = true; } break; case 'd/m/Y': if (preg_match("/^(0[1-9]|[1-2][0-9]|3[0-1])\/(0[1-9]|1[0-2])\/[0-9]{4}$/",$date)) { $dateValid = true; } break; case 'm/d/Y': if (preg_match("/^(0[1-9]|1[0-2])\/(0[1-9]|[1-2][0-9]|3[0-1])\/[0-9]{4}$/",$date)) { $dateValid = true; } break; case 'Y-m-d': if (preg_match("/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/",$date)) { $dateValid = true; } break; } return $dateValid; } function abc_booking_formatDate($string) { $dateformat = getAbcSetting('dateformat'); $old_date_timestamp = strtotime($string); $new_date = date($dateformat, $old_date_timestamp); return $new_date; } function abc_booking_formatDateToDB($string) { $dateformat = getAbcSetting("dateformat"); $newDate = ''; $day = ''; $month = ''; $year = ''; switch ($dateformat) { case 'd.m.Y': case 'd/m/Y': $day = substr($string, 0, 2); $month = substr($string, 3, 2); $year = substr($string, 6, 4); $newDate = date('Y-m-d', mktime(0, 0, 0, $month, $day, $year)); break; case 'm/d/Y': $day = substr($string, 3, 2); $month = substr($string, 0, 2); $year = substr($string, 6, 4); $newDate = date('Y-m-d', mktime(0, 0, 0, $month, $day, $year)); break; case 'Y-m-d': $newDate = $string; break; } return $newDate; } function abc_booking_dateDiffInDays($timestamp1, $timestamp2){ $seconds1 = date("U", $timestamp1); $seconds2 = date("U", $timestamp2); $diffSeconds = $timestamp1 - $timestamp2; $diffSeconds = $diffSeconds/86400; $days = (int)$diffSeconds; return $days; } function abc_booking_dateFormatToJS($string) { $dateformat = 'mm/dd/yy'; if($string == "Y-m-d") { $dateformat = 'yy-mm-dd'; } elseif($string == "d.m.Y") { $dateformat = 'dd.mm.yy'; } elseif($string == "d/m/Y") { $dateformat = 'dd/mm/yy'; } elseif($string == "m/d/Y") { $dateformat = 'mm/dd/yy'; } return $dateformat; } function getAbcSetting($settingName) { $output = ''; if($settingName == 'firstdayofweek'){ $output = get_option('start_of_week'); } else { $output = get_option('abc_'.$settingName); } return $output; } // Returns 0 if the minimum number of nights to stay for a certain time is reached. Returns the number of nights needed if no reached. function abc_booking_checkMinimumStay($calendarId, $normFromValue, $normToValue) { global $wpdb; $calendarId = intval($calendarId); $minimumStay = 1; $er = $wpdb->get_row('SELECT max(s.minimumStay) as minimumStay FROM '.$wpdb->prefix.'advanced_booking_calendar_seasons s INNER JOIN '.$wpdb->prefix.'advanced_booking_calendar_seasons_assignment sa ON sa.season_id = s.id WHERE sa.calendar_id = '.$calendarId.' AND ( (sa.start <= \''.$normFromValue.'\' AND sa.end >=\''.$normToValue.'\') OR (sa.start >= \''.$normFromValue.'\' AND sa.end <= \''.$normToValue.'\') OR (sa.start >= \''.$normFromValue.'\' AND sa.start < \''.$normToValue.'\') OR (sa.start <= \''.$normFromValue.'\' AND sa.end >= \''.$normToValue.'\') OR (sa.end <= \''.$normFromValue.'\' AND sa.end >= \''.$normToValue.'\') OR (sa.end > \''.$normFromValue.'\' AND sa.end <= \''.$normToValue.'\') )', ARRAY_A); if($er["minimumStay"] > 0){ $minimumStay = $er["minimumStay"]; }else{ $er = $wpdb->get_row('SELECT minimumStayPreset FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.$calendarId, ARRAY_A); $minimumStay = $er["minimumStayPreset"]; } if(abc_booking_dateDiffInDays(strtotime($normToValue), strtotime($normFromValue)) >= $minimumStay){ return 0; }else{ return $minimumStay; } } function abc_booking_getTotalPrice($calendarId, $startDate, $numberOfDays) { global $wpdb; $calendarId = intval($calendarId); $totalSum = 0; $normFromValue = $startDate; $er = $wpdb->get_row('SELECT pricePreset FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.$calendarId, ARRAY_A); $pricePreset = $er["pricePreset"]; $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 = '.$calendarId.' AND a.end >= \''.$normFromValue.'\' ORDER BY s.lastminute DESC, a.start ASC'; $er = $wpdb->get_results($query, ARRAY_A); $days = array(); $dayCount = 0; if($wpdb->num_rows > 0){ foreach($er as $row) { $time = strtotime($normFromValue); for( $i = 0; $i < $numberOfDays; $i++) { if(strtotime($row["start"]) <= $time && strtotime($row["end"]) >= $time && !isset($days[date("Y-m-d", $time)]) ) { $totalSum += $row["price"]; $days[date("Y-m-d", $time)] = true; $dayCount++; } $time += 86400; } } if($dayCount < $numberOfDays){ $totalSum += ($numberOfDays - $dayCount)*$pricePreset; } }else{ $totalSum += $pricePreset*$numberOfDays; } return $totalSum; } function abc_booking_getBookingVars(){ $bookingVars = array('abc_calendar_name', 'abc_total_price', 'abc_room_price', 'abc_optional_extras', 'abc_mandatory_extras', 'abc_checkin_date', 'abc_checkout_date', 'abc_person_count', 'abc_first_name', 'abc_last_name', 'abc_email', 'abc_phone', 'abc_address', 'abc_zip', 'abc_city', 'abc_county', 'abc_country', 'abc_message'); return $bookingVars; } function abc_booking_setContentTypeHTML($content_type){ return 'text/html'; } // Returns a snapshot of the availability table for a booking. Used by sendAbcAdminMail() function abc_booking_getAvailabilityOverview($bookingData){ global $wpdb; $dateformat = getAbcSetting("dateformat"); $normFromValue = $bookingData["start"]; $normToValue = $bookingData["end"]; $startDate = strtotime('-4 days', strtotime($normFromValue)); // +/- 4 days to show what is going on around the current booking $endDate = strtotime('+4 days', strtotime($normToValue)); $numberOfDays = abc_booking_dateDiffInDays($endDate, $startDate); if($numberOfDays > 20){ $endDate = strtotime('+24 days', $startDate); } $output = ' '; for($tempDate = $startDate; $tempDate <= $endDate; $tempDate = strtotime('+1 day', $tempDate)){ $output .= ''; } $output .= ' '; $bookings = array(); $bookingQuery = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_bookings WHERE end >= "'.date("Y-m-d", $startDate).'" AND start <= "'.date("Y-m-d", $endDate).'" AND state = "confirmed" ORDER BY start', ARRAY_A); foreach($bookingQuery as $bookingRow){ $bookings[$bookingRow["room_id"]][] = $bookingRow; // Getting all confirmed bookings for the current timeframe } $bookingData["room_id"] = getAbcRoomId($bookingData["calendar_id"], $normFromValue, $normToValue, 1); // Adding current booking to the already confirmed bookings //$bookingData["room_id"] = getAbcRoomId($bookingData["calendar_id"], $bookingData["start"], $bookingData["end"]); // Adding current booking to the already confirmed bookings $bookings[$bookingData["room_id"]][] = $bookingData; $er = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_rooms WHERE calendar_id='.$bookingData["calendar_id"].' ORDER BY name', ARRAY_A); foreach($er as $rooms) { $output .= ''; $roomRowDate = $startDate; for($i = 0; $i < ($numberOfDays*2); $i++){ $colSpan = 1; if (isset($bookings[$rooms["id"]])){ // Checking for bookings for the current room $success = false; for($j = 0; $j < count($bookings[$rooms["id"]]); $j++){ // Checking if a booking started before startDate if($bookings[$rooms["id"]][$j]["start"] < date("Y-m-d", $startDate) && $i==0){ $tempEndDate = strtotime($bookings[$rooms["id"]][$j]["end"]); $dayOffset = 0; if ($tempEndDate > $endDate){ $tempEndDate = $endDate; $dayOffset = 1; $success = true; } $dateDiff = abc_booking_dateDiffInDays($tempEndDate, $startDate); $colSpan = ($dateDiff+1)*2; $text = $bookings[$rooms["id"]][$j]["last_name"].', '.sprintf( _n('%d person', '%d persons', $bookings[$rooms["id"]][$j]["persons"], 'advanced-booking-calendar'), $bookings[$rooms["id"]][$j]["persons"] ).', '.date($dateformat, strtotime($bookings[$rooms["id"]][$j]["start"])).' - '.date($dateformat, strtotime($bookings[$rooms["id"]][$j]["end"])); if(mb_strlen($text, "utf-8") > $colSpan*1.5){ $text = mb_substr($text, 0, $colSpan*1.5, "utf-8").'...'; } $output .= ''; $i += ((abc_booking_dateDiffInDays($tempEndDate, $startDate))*2)+1+$dayOffset; $roomRowDate = strtotime('+'.$dateDiff.' day', $roomRowDate); }elseif($bookings[$rooms["id"]][$j]["start"] == date("Y-m-d", $roomRowDate) && $i%2==1) { $tempEndDate = strtotime($bookings[$rooms["id"]][$j]["end"]); $dayOffset = 0; $cssClass = ''; if ($tempEndDate > $endDate){ $tempEndDate = $endDate; $dayOffset = 1; $success = true; $cssClass .= ' abcAvailabilityTableEnding'; } $dateDiff = abs(abc_booking_dateDiffInDays(strtotime($bookings[$rooms["id"]][$j]["start"]), $tempEndDate)); $colSpan = ($dateDiff*2)+$dayOffset; $text = $bookings[$rooms["id"]][$j]["last_name"].', '.sprintf( _n('%d person', '%d persons', $bookings[$rooms["id"]][$j]["persons"], 'advanced-booking-calendar'), $bookings[$rooms["id"]][$j]["persons"] ).', '.date($dateformat, strtotime($bookings[$rooms["id"]][$j]["start"])).' - '.date($dateformat, strtotime($bookings[$rooms["id"]][$j]["end"])); if(mb_strlen($text, "utf-8") > $colSpan*1.5){ $text = mb_substr($text, 0, $colSpan*1.5, "utf-8").'...'; } $output .= ''; $i += ($dateDiff*2)+$dayOffset; $roomRowDate = strtotime('+'.$dateDiff.' day', $roomRowDate); } } if(!$success){ $output .= ''; } } else{ $output .= ''; } if($i%2==1 || $i == 1){ $roomRowDate = strtotime('+1 day', $roomRowDate); } } $output .= ''; } $output .= '
 '.date_i18n('D', $tempDate).'
'.date_i18n('j', $tempDate).'
'.date_i18n('M', $tempDate).'
'.$rooms["name"].''.$text.''.$text.'  
'; return $output; } function sendAbcGuestMail($bookingData){ global $wpdb; $row = $wpdb->get_row('SELECT name FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.intval($bookingData["calendar_id"]), ARRAY_A); $placeholder = array(); $placeholder["abc_calendar_name"] = $row["name"]; $totalPrice = ''; $roomPrice = 0; $dateformat = getAbcSetting('dateformat'); $normFromValue = $bookingData["start"]; $normToValue = $bookingData["end"]; $numberOfDays = floor((strtotime($normToValue) - strtotime($normFromValue))/(60*60*24)); if(!isset($bookingData["price"])){ $totalPrice = abc_booking_getTotalPrice($bookingData["calendar_id"], $normFromValue, $numberOfDays); } else { $totalPrice = $bookingData["price"]; } $roomPrice = $totalPrice; $extrasArray = array(); $placeholder["abc_optional_extras"] = ''; $placeholder["abc_mandatory_extras"] = ''; if(strlen($bookingData["extras"]) > 0 || getAbcExtrasList($numberOfDays, intval($bookingData["persons"]), 2)){ $extrasSelected = explode(',', sanitize_text_field($bookingData["extras"])); foreach(getAbcExtrasList($numberOfDays, intval($bookingData["persons"])) as $extra){ if($extra["mandatory"] == 1){ if(!isset($bookingData["price"])){ $totalPrice += $extra["priceValue"]; } else { $roomPrice -= $extra["priceValue"]; } if(strlen($placeholder["abc_mandatory_extras"]) > 1){ $placeholder["abc_mandatory_extras"] .= ', '; } $placeholder["abc_mandatory_extras"] .= $extra["name"].': '.abc_booking_formatPrice($extra["priceValue"]); }elseif(in_array($extra["id"], $extrasSelected)){ if(!isset($bookingData["price"])){ $totalPrice += $extra["priceValue"]; } else { $roomPrice -= $extra["priceValue"]; } if(strlen($placeholder["abc_optional_extras"]) > 1){ $placeholder["abc_optional_extras"] .= ', '; } $placeholder["abc_optional_extras"] .= $extra["name"].': '.abc_booking_formatPrice($extra["priceValue"]); } } } if(strlen($placeholder["abc_optional_extras"]) == 0){ $placeholder["abc_optional_extras"] = __('No optional extras.', 'advanced-booking-calendar'); } if(strlen($placeholder["abc_mandatory_extras"]) == 0){ $placeholder["abc_mandatory_extras"] = __('No mandatory extras.', 'advanced-booking-calendar'); } $placeholder["abc_room_price"] = abc_booking_formatPrice($roomPrice); $placeholder["abc_total_price"] = abc_booking_formatPrice($totalPrice); $placeholder["abc_checkin_date"] = date($dateformat, strtotime($bookingData["start"])); $placeholder["abc_checkout_date"] = date($dateformat, strtotime($bookingData["end"])); $placeholder["abc_person_count"] = $bookingData["persons"]; $placeholder["abc_first_name"] = $bookingData["first_name"]; $placeholder["abc_last_name"] = $bookingData["last_name"]; $placeholder["abc_email"] = $bookingData["email"]; $placeholder["abc_phone"]= $bookingData["phone"]; $placeholder["abc_address"] = $bookingData["address"]; $placeholder["abc_zip"] = $bookingData["zip"]; $placeholder["abc_city"] = $bookingData["city"]; $placeholder["abc_county"] = $bookingData["county"]; $placeholder["abc_country"] = $bookingData["country"]; $placeholder["abc_message"] = $bookingData["message"]; $adminEmail = getAbcSetting('email'); if(!filter_var($adminEmail,FILTER_VALIDATE_EMAIL)){ $adminEmail = get_option('admin_email'); } $subject = ''; $text = ''; switch ($bookingData["state"]) { case 'open': $subject = get_option('abc_subject_unconfirmed'); $text = get_option('abc_text_unconfirmed'); break; case 'confirmed': $subject = get_option('abc_subject_confirmed'); $text = get_option('abc_text_confirmed'); break; case 'canceled': $subject = get_option('abc_subject_canceled'); $text = get_option('abc_text_canceled'); break; case 'rejected': $subject = get_option('abc_subject_rejected'); $text = get_option('abc_text_rejected'); break; } $bookingVars = abc_booking_getBookingVars(); foreach($bookingVars as $var){ $subject = str_replace('['.$var.']', $placeholder[$var], $subject); $text = str_replace('['.$var.']', $placeholder[$var], $text); } $headers = 'From: '.get_option('blogname').' <'.$adminEmail.'>'."\r\n"; wp_mail($placeholder["abc_email"], $subject, $text, $headers); // Sending email to customer } function sendAbcAdminMail($bookingData){ global $wpdb; $requestQuery = "SELECT name FROM ".$wpdb->prefix."advanced_booking_calendar_calendars WHERE id = ".$bookingData["calendar_id"]; $er = $wpdb->get_row($requestQuery); $calendarName = $er->name; $dateformat = getAbcSetting('dateformat'); $normFromValue = $bookingData["start"]; $normToValue = $bookingData["end"]; $totalPrice = 0; if(!isset($bookingData["price"])){ $numberOfDays = floor((strtotime($normToValue) - strtotime($normFromValue))/(60*60*24)); $totalPrice = abc_booking_getTotalPrice($bookingData["calendar_id"], $normFromValue, $numberOfDays); } else { $totalPrice = $bookingData["price"]; } $roomPrice = $totalPrice; $extrasArray = array(); $optionalExtras = ''; $mandatoryExtras = ''; if(strlen($bookingData["extras"]) > 0 || getAbcExtrasList($numberOfDays, intval($bookingData["persons"]), 2)){ $extrasSelected = explode(',', sanitize_text_field($bookingData["extras"])); foreach(getAbcExtrasList($numberOfDays, intval($bookingData["persons"])) as $extra){ if(in_array($extra["id"], $extrasSelected)){ $totalPrice += $extra["priceValue"]; if(strlen($optionalExtras) > 1){ $optionalExtras.= ', '; } $optionalExtras .= $extra["name"].': '.abc_booking_formatPrice($extra["priceValue"]); }elseif($extra["mandatory"] == 1){ $totalPrice += $extra["priceValue"]; if(strlen($mandatoryExtras) > 1){ $mandatoryExtras .= ', '; } $mandatoryExtras.= $extra["name"].': '.abc_booking_formatPrice($extra["priceValue"]); } } } $priceOutput = ''; if(strlen($mandatoryExtras) > 1 || strlen($optionalExtras) > 1){ if(strlen($mandatoryExtras) > 1){ $priceOutput = 'Additional costs: '.$mandatoryExtras.'
'; } if(strlen($optionalExtras) > 1){ $priceOutput .= 'Selected extras: '.$optionalExtras.'
'; } $priceOutput .= 'Room price: '.abc_booking_formatPrice($roomPrice).'
Total price: '.abc_booking_formatPrice($totalPrice).'
'; } $adminEmail = getAbcSetting('email'); $headers = 'From: '.get_option('blogname').' <'.$adminEmail.'>'."\r\n"; $subject = __('Booking Request', 'advanced-booking-calendar').' '.get_option('blogname'); $adminBody = ' '.__('New Booking Request', 'advanced-booking-calendar').'

'.__('New Booking Request', 'advanced-booking-calendar').'

'.date(getAbcSetting('dateformat'), strtotime($bookingData["start"])).' - '.date(getAbcSetting('dateformat'), strtotime($bookingData["end"])).'

Name: '.$bookingData["first_name"].' '.$bookingData["last_name"].'
From: '.date($dateformat, strtotime($bookingData["start"])).'
To: '.date($dateformat, strtotime($bookingData["end"])).'

Persons: '.$bookingData["persons"].'
Room Type: '.$calendarName.'

Email: '.$bookingData["email"].'
Phone: '.$bookingData["phone"].'
Address: '.$bookingData["address"].'
ZIP Code: '.$bookingData["zip"].'
City: '.$bookingData["city"].'
State / County: '.$bookingData["county"].'

Country: '.$bookingData["country"].'

'.$priceOutput.' Message: '.$bookingData["message"].'

'.abc_booking_getAvailabilityOverview($bookingData).'



 
'; add_filter('wp_mail_content_type', 'abc_booking_setContentTypeHTML'); // Activating HTML wp_mail($adminEmail, $subject, $adminBody, $headers); // Sending email remove_filter('wp_mail_content_type', 'abc_booking_setContentTypeHTML'); // Deactivating HTML } function setAbcBooking($bookingData){ // Inserts booking in DB, returns booking ID global $wpdb; $row = $wpdb->get_row('SELECT name FROM '.$wpdb->prefix.'advanced_booking_calendar_calendars WHERE id = '.intval($bookingData["calendar_id"]), ARRAY_A); $calendarName = $row["name"]; $dateformat = getAbcSetting("dateformat"); // Normalizing entered dates $normFromValue = $bookingData["start"]; $normToValue = $bookingData["end"]; $roomId = getAbcRoomId(intval($bookingData["calendar_id"]), $bookingData["start"], $bookingData["end"], 1); if($roomId < 1){ die('No room available. Booking canceled.'); } $numberOfDays = floor((strtotime($normToValue) - strtotime($normFromValue))/(60*60*24)); $totalPrice = abc_booking_getTotalPrice(intval($bookingData["calendar_id"]), $normFromValue, $numberOfDays); $extrasArray = array(); if(strlen($bookingData["extras"]) > 0 || getAbcExtrasList($numberOfDays, intval($bookingData["persons"]), 2)){ $extrasSelected = explode(',', sanitize_text_field($bookingData["extras"])); foreach(getAbcExtrasList($numberOfDays, intval($bookingData["persons"])) as $extra){ if(in_array($extra["id"], $extrasSelected) || $extra["mandatory"] == 1){ $totalPrice += $extra["priceValue"]; $extrasArray[] = $extra["id"]; } } } $wpdb->insert( $wpdb->prefix.'advanced_booking_calendar_bookings', array( 'start' => $normFromValue, 'end' => $normToValue, 'calendar_id' => intval($bookingData["calendar_id"]), 'persons' => intval($bookingData["persons"]), 'first_name' => sanitize_text_field($bookingData["first_name"]), 'last_name' => sanitize_text_field($bookingData["last_name"]), 'email' => sanitize_text_field($bookingData["email"]), 'phone' => sanitize_text_field($bookingData["phone"]), 'address' => sanitize_text_field($bookingData["address"]), 'zip' => sanitize_text_field($bookingData["zip"]), 'city' =>sanitize_text_field( $bookingData["city"]), 'county' =>sanitize_text_field( $bookingData["county"]), 'country' => sanitize_text_field($bookingData["country"]), 'message' => sanitize_text_field($bookingData["message"]), 'price' => $totalPrice, 'state' => sanitize_text_field($bookingData["state"]), 'room_id' => $roomId )); $bookingId = $wpdb->insert_id; foreach($extrasArray as $extra){ $wpdb->insert( $wpdb->prefix.'advanced_booking_calendar_booking_extras', array( 'booking_id' => $bookingId, 'extra_id' => $extra )); } return $bookingId; } function getAbcRoomId($calId, $abcFromValue, $abcToValue, $dbFormat = 0) { // Returns id > 0, if rooms is available for a timeperiod global $wpdb; $roomId = 0; $normFromValue = $abcFromValue; $normToValue = $abcToValue; if($dbFormat == 0){ $dateformat = getAbcSetting("dateformat"); // Normalizing entered dates $normFromValue = abc_booking_formatDateToDB($abcFromValue); $normToValue = abc_booking_formatDateToDB($abcToValue); } // Getting lowest id for an available room $query = 'SELECT count(id) as bookingCount FROM '.$wpdb->prefix.'advanced_booking_calendar_bookings WHERE calendar_id = \''.$calId.'\' AND state = \'confirmed\''; $bookingCount = $wpdb->get_row($query, ARRAY_A); if($bookingCount['bookingCount'] > 0){ $query = 'SELECT MIN(r.id ) as roomId FROM '.$wpdb->prefix.'advanced_booking_calendar_rooms r WHERE r.calendar_id = \''.$calId.'\' AND r.id not in (SELECT DISTINCT room_id FROM '.$wpdb->prefix.'advanced_booking_calendar_bookings WHERE calendar_id = \''.$calId.'\' 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.'\') ) )'; $er = $wpdb->get_row($query, ARRAY_A); if(isset($er["roomId"])){ $roomId = $er["roomId"]; } // Else $roomId = 0 ==> Overlap or no availability } else { $query = 'SELECT min(id) as roomId FROM '.$wpdb->prefix.'advanced_booking_calendar_rooms WHERE calendar_id = \''.$calId.'\' '; $er = $wpdb->get_row($query, ARRAY_A); $roomId = $er["roomId"]; } return $roomId; } function getAbcAvailability($calId, $abcFromValue, $abcToValue, $dbFormat = 0) {// Checks if a calendar is availability for a timeframe. Returns true if succesful $success = false; if(getAbcRoomId($calId, $abcFromValue, $abcToValue, $dbFormat) > 0){ $success = true; } return $success; } function getAbcExtrasForBooking($bookingId){ global $wpdb; $extras = ''; $er = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_booking_extras WHERE booking_id = '.intval($bookingId), ARRAY_A); foreach($er as $row) { if(strlen($extras)>0){ $extras .= ','; } $extras .= $row['extra_id']; } return $extras; } function getAbcExtrasList($numberOfDays, $abcPersons, $optionalOnly = 0){ global $wpdb; $extrasList = array(); $extrasOptional = ''; $extrasMandatory = ''; $additionalCosts = 0; $condition = ''; if($optionalOnly == 1){ $condition = " WHERE mandatory = 'no'"; }elseif($optionalOnly == 2){ $condition = " WHERE mandatory = 'yes'"; } $er = $wpdb->get_results('SELECT * FROM '.$wpdb->prefix.'advanced_booking_calendar_extras'.$condition.' ORDER BY name', ARRAY_A); foreach($er as $row) { $tempCosts = 0; $tempExplanation = ''; switch($row["calculation"]){ case 'night': $extrasList[$row["id"]]["priceValue"] = $numberOfDays*$row["price"]; $numberOfNights = $numberOfDays; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s for each of the %d nights', 'advanced-booking-calendar'), $price, $numberOfNights); break; case 'day': $extrasList[$row["id"]]["priceValue"] = ($numberOfDays+1)*$row["price"]; $days = $numberOfDays+1; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s for each of the %d days', 'advanced-booking-calendar'), $price, $days); break; case 'once': $extrasList[$row["id"]]["priceValue"] = $row["price"]; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s paid once', 'advanced-booking-calendar'), $price); break; case 'person': $extrasList[$row["id"]]["priceValue"] = $abcPersons*$row["price"]; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s for each of the %d persons', 'advanced-booking-calendar'), $price, $abcPersons); break; case 'personNight': $extrasList[$row["id"]]["priceValue"] = $numberOfDays*$abcPersons*$row["price"]; $numberOfNights = $numberOfDays; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s for each of the %d persons and %d nights', 'advanced-booking-calendar'), $price, $abcPersons, $numberOfNights); break; case 'personDay': $extrasList[$row["id"]]["priceValue"] = ($numberOfDays+1)*$abcPersons*$row["price"]; $days = $numberOfDays+1; $price = abc_booking_formatPrice($row["price"]); $extrasList[$row["id"]]["priceText"] = sprintf( __('%s for each of the %d persons and %d days', 'advanced-booking-calendar'), $price, $abcPersons, $days); break; } $extrasList[$row["id"]]["id"] = intval($row["id"]); $extrasList[$row["id"]]["name"] = esc_html($row["name"]); $extrasList[$row["id"]]["explanation"] = esc_html($row["explanation"]); switch($row["mandatory"]){ case 'yes': $extrasList[$row["id"]]["mandatory"] = 1; break; case 'no': $extrasList[$row["id"]]["mandatory"] = 0; break; } } return $extrasList; } // Subscribing and unsubscribing to newsletter. Just the email is transmitted, nothing else. function subscribeAbcNewsletter($email, $unsubscribe = 0){ $url = 'https://booking-calendar-plugin.com/mc/mailchimp.php'; $data = array('mail' => urlencode($email), 'unsubscribe' => urlencode($unsubscribe)); $data_string = ''; foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } rtrim($data_string, '&'); $ch = curl_init(); curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch,CURLOPT_POST, count($data)); curl_setopt($ch,CURLOPT_POSTFIELDS, $data_string); $result = curl_exec($ch); curl_close($ch); } function getAbcColor($colorInt){ $colorCode = ''; if(is_int($colorInt)){ $colorNumber = $colorInt%12; switch($colorNumber){ case 0: $colorCode = '#a6c6ce'; break; case 1: $colorCode = '#ff6d2a'; break; case 2: $colorCode = '#00c2e6'; break; case 3: $colorCode = '#f9cb01'; break; case 4: $colorCode = '#217084'; break; case 5: $colorCode = '#ff9969'; break; case 6: $colorCode = '#4cd4ed'; break; case 7: $colorCode = '#fbda4d'; break; case 8: $colorCode = '#639ba9'; break; case 9: $colorCode = '#ffc5aa'; break; case 10: $colorCode = '#99e7f5'; break; case 11: $colorCode = '#fdea99'; break; } } return $colorCode; } ?>