function render_entry_form()
 {
     global $byt_cruises_post_type;
     $cruise_id = 0;
     $cabin_type_id = 0;
     $schedule_object = null;
     $cruise_obj = null;
     $cabin_type_obj = null;
     $is_price_per_person = 0;
     $cruise_type_is_repeated = 0;
     // on-off cruise by default
     $edit = isset($_GET['edit']) ? absint($_GET['edit']) : "";
     if (!empty($edit)) {
         $schedule_object = $byt_cruises_post_type->get_cruise_schedule($edit);
     }
     if (isset($_POST['cruises_select'])) {
         $cruise_id = wp_kses($_POST['cruises_select'], '');
     } else {
         if ($schedule_object != null) {
             $cruise_id = $schedule_object->cruise_id;
         }
     }
     if ($cruise_id) {
         $cruise_obj = new byt_cruise(intval($cruise_id));
         $cruise_id = $cruise_obj->get_base_id();
         $cruise_type_is_repeated = $cruise_obj->get_type_is_repeated();
         $is_price_per_person = $cruise_obj->get_is_price_per_person();
     }
     if (isset($_POST['cabin_types_select'])) {
         $cabin_type_id = wp_kses($_POST['cabin_types_select'], '');
     } else {
         if ($schedule_object) {
             $cabin_type_id = $schedule_object->cabin_type_id;
         }
     }
     if (!empty($cabin_type_id)) {
         $cabin_type_id = BYT_Theme_Utils::get_default_language_post_id($cabin_type_id, 'cabin_type');
     }
     $cruises_select = '<select id="cruises_select" name="cruises_select">';
     $cruises_select .= '<option value="">' . __('Select cruise', 'bookyourtravel') . '</option>';
     $author_id = null;
     if (!is_super_admin()) {
         $author_id = get_current_user_id();
     }
     $cruise_results = $byt_cruises_post_type->list_cruises(0, -1, 'title', 'ASC', 0, array(), array(), array(), false, $author_id);
     if (count($cruise_results) > 0 && $cruise_results['total'] > 0) {
         foreach ($cruise_results['results'] as $cruise_result) {
             global $post;
             $post = $cruise_result;
             setup_postdata($post);
             $cruises_select .= '<option value="' . $post->ID . '" ' . ($post->ID == $cruise_id ? 'selected' : '') . '>' . $post->post_title . '</option>';
         }
     }
     $cruises_select .= '</select>';
     $cabin_types_select = '<select class="normal" id="cabin_types_select" name="cabin_types_select">';
     $cabin_types_select .= '<option value="">' . __('Select cabin type', 'bookyourtravel') . '</option>';
     if ($cruise_obj) {
         $cabin_type_ids = $cruise_obj->get_cabin_types();
         if ($cabin_type_ids && count($cabin_type_ids) > 0) {
             for ($i = 0; $i < count($cabin_type_ids); $i++) {
                 $temp_id = $cabin_type_ids[$i];
                 $cabin_type_obj = new byt_cabin_type(intval($temp_id));
                 $cabin_types_select .= '<option value="' . $temp_id . '" ' . ($temp_id == $cabin_type_id ? 'selected' : '') . '>' . $cabin_type_obj->get_title() . '</option>';
             }
         }
     }
     $cabin_types_select .= '</select>';
     $start_date = null;
     if (isset($_POST['start_date'])) {
         $start_date = wp_kses($_POST['start_date'], '');
     } else {
         if ($schedule_object != null) {
             $start_date = $schedule_object->start_date;
         }
     }
     if (isset($start_date)) {
         $start_date = date($this->date_format, strtotime($start_date));
     }
     $duration_days = 0;
     if (isset($_POST['duration_days'])) {
         $duration_days = intval(wp_kses($_POST['duration_days'], '0'));
     } else {
         if ($schedule_object != null) {
             $duration_days = $schedule_object->duration_days;
         }
     }
     $cabin_count = 1;
     if (isset($_POST['cabin_count'])) {
         $cabin_count = intval(wp_kses($_POST['cabin_count'], '1'));
     } else {
         if ($schedule_object && isset($schedule_object->cabin_count)) {
             $cabin_count = $schedule_object->cabin_count;
         }
     }
     if ($cabin_count == 0) {
         $cabin_count = 1;
     }
     $price = 0;
     if (isset($_POST['price'])) {
         $price = floatval(wp_kses($_POST['price'], '2'));
     } else {
         if ($schedule_object != null) {
             $price = $schedule_object->price;
         }
     }
     $price_child = 0;
     if ($is_price_per_person) {
         if (isset($_POST['price_child'])) {
             $price_child = floatval(wp_kses($_POST['price_child'], '2'));
         } else {
             if ($schedule_object != null) {
                 $price_child = $schedule_object->price_child;
             }
         }
     }
     $end_date = null;
     if (isset($_POST['end_date'])) {
         $end_date = wp_kses($_POST['end_date'], '');
     } else {
         if ($schedule_object != null) {
             $end_date = $schedule_object->end_date;
         }
     }
     if (isset($end_date)) {
         $end_date = date($this->date_format, strtotime($end_date));
     }
     if ($schedule_object) {
         echo '<h3>' . __('Update Cruise Schedule Entry', 'bookyourtravel') . '</h3>';
     } else {
         echo '<h3>' . __('Add Cruise Schedule Entry', 'bookyourtravel') . '</h3>';
     }
     echo '<form id="cruise_schedule_entry_form" method="post" action="' . esc_url($_SERVER['REQUEST_URI']) . '" style="clear: both;">';
     echo wp_nonce_field('cruise_schedule_entry_form');
     echo '<table cellpadding="3" class="form-table"><tbody>';
     echo '<tr>';
     echo '	<th scope="row" valign="top">' . __('Select cruise', 'bookyourtravel') . '</th>';
     echo '	<td>' . $cruises_select . '</td>';
     echo '</tr>';
     echo '<tr>';
     echo '	<th scope="row" valign="top">' . __('Select cabin type', 'bookyourtravel') . '</th>';
     echo '	<td>' . $cabin_types_select . '</td>';
     echo '</tr>';
     echo '<tr id="cabin_count">';
     echo '	<th scope="row" valign="top">' . __('Number of cabins available', 'bookyourtravel') . '</th>';
     echo '	<td><input type="text" name="cabin_count" id="cabin_count" value="' . $cabin_count . '" /></td>';
     echo '</tr>';
     echo '<tr>';
     echo '	<th scope="row" valign="top">' . __('Duration (days)', 'bookyourtravel') . '</th>';
     echo '	<td><input type="text" name="duration_days" id="duration_days" value="' . $duration_days . '" /></td>';
     echo '</tr>';
     echo '<tr>';
     echo '	<th scope="row" valign="top">' . __('Start date', 'bookyourtravel') . '</th>';
     echo '	<td>';
     echo '		<script>';
     echo '			window.datepickerStartDateValue = "' . $start_date . '";';
     echo '  	</script>';
     echo '  	<input class="datepicker" type="text" name="datepicker_start_date" id="datepicker_start_date" />';
     echo '		<input type="hidden" name="start_date" id="start_date" />';
     echo '	</td>';
     echo '</tr>';
     echo '<tr class="is_repeated" ' . ($cruise_type_is_repeated ? '' : 'style="display:none"') . '>';
     echo '	<th scope="row" valign="top">' . __('End date', 'bookyourtravel') . '</th>';
     echo '	<td>';
     echo '		<script>';
     echo '			window.datepickerEndDateValue = "' . $end_date . '";';
     echo '  	</script>';
     echo '  	<input class="datepicker" type="text" name="datepicker_end_date" id="datepicker_end_date" />';
     echo '		<input type="hidden" name="end_date" id="end_date" />';
     echo '	</td>';
     echo '</tr>';
     echo '<tr>';
     echo '	<th scope="row" valign="top">' . __('Price', 'bookyourtravel') . ' <span class="per_person" ' . ($is_price_per_person ? '' : 'style="display:none"') . '>' . __('per adult', 'bookyourtravel') . '</span> <span class="per_person" ' . (!$is_price_per_person ? '' : 'style="display:none"') . '>' . __('per cabin', 'bookyourtravel') . '</span></th>';
     echo '	<td><input type="text" name="price" id="price" value="' . $price . '" /></td>';
     echo '</tr>';
     echo '<tr class="per_person" ' . ($is_price_per_person ? '' : 'style="display:none"') . '>';
     echo '	<th scope="row" valign="top">' . __('Price per child', 'bookyourtravel') . '</th>';
     echo '	<td><input type="text" name="price_child" id="price_child" value="' . $price_child . '" /></td>';
     echo '</tr>';
     echo '</table>';
     echo '<p>';
     echo '<a href="edit.php?post_type=cruise&page=theme_cruise_schedule_admin.php" class="button-secondary">' . __('Cancel', 'bookyourtravel') . '</a>&nbsp;';
     if ($schedule_object) {
         echo '<input id="schedule_id" name="schedule_id" value="' . $edit . '" type="hidden" />';
         echo '<input class="button-primary" type="submit" name="update" value="' . __('Update Cruise Schedule Entry', 'bookyourtravel') . '"/>';
     } else {
         echo '<input class="button-primary" type="submit" name="insert" value="' . __('Add Cruise Schedule Entry', 'bookyourtravel') . '"/>';
     }
     echo '</p>';
     echo '</form>';
 }
Ejemplo n.º 2
0
 function get_cruise_min_price($cruise_id, $cabin_type_id = 0, $date = null)
 {
     global $wpdb;
     $cruise_obj = new byt_cruise(intval($cruise_id));
     $cruise_id = $cruise_obj->get_base_id();
     if ($cabin_type_id > 0) {
         $cabin_type_obj = new byt_cabin_type(intval($cabin_type_id));
         $cabin_type_id = $cabin_type_obj->get_base_id();
     }
     if (!isset($date)) {
         $date = date('Y-m-d', time());
     }
     $table_name_schedule = BOOKYOURTRAVEL_CRUISE_SCHEDULE_TABLE;
     $sql = "SELECT MIN(schedule.price) \r\n\t\t\t\tFROM {$table_name_schedule} schedule \r\n\t\t\t\tWHERE cruise_id=%d ";
     if ($cabin_type_id > 0) {
         $sql .= $wpdb->prepare(" AND cabin_type_id=%d ", $cabin_type_id);
     }
     if ($cruise_obj->get_type_is_repeated() == 0) {
         // this cruise is a one off and is not repeated. If start date is missed, person cannot participate.
         $sql .= $wpdb->prepare(" AND start_date > %s ", $date);
     } else {
         // daily, weekly, weekdays cruises are recurring which means start date is important only in the sense that cruise needs to have become valid before we can get min price.
     }
     $sql = $wpdb->prepare($sql, $cruise_id);
     $min_price = $wpdb->get_var($sql);
     if (!$min_price) {
         $min_price = 0;
     }
     if ($cabin_type_id == 0) {
         $this->sync_cruise_min_price($cruise_id, $min_price);
     }
     return $min_price;
 }
<?php

global $post, $cruise_class, $display_mode, $byt_theme_globals, $byt_cruises_post_type, $byt_reviews_post_type;
$cruise_id = $post->ID;
$cruise_obj = new byt_cruise($post);
$base_id = $cruise_obj->get_base_id();
$reviews_total = $byt_reviews_post_type->get_reviews_count($base_id);
$price_decimal_places = $byt_theme_globals->get_price_decimal_places();
$default_currency_symbol = $byt_theme_globals->get_default_currency_symbol();
$show_currency_symbol_after = $byt_theme_globals->show_currency_symbol_after();
$is_price_per_person = $cruise_obj->get_is_price_per_person();
$cruise_image = $cruise_obj->get_main_image();
if (empty($cruise_image)) {
    $cruise_image = BYT_Theme_Utils::get_file_uri('/images/uploads/img.jpg');
}
$score_out_of_10 = 0;
if ($reviews_total > 0) {
    $review_score = $cruise_obj->get_custom_field('review_score', false);
    $score_out_of_10 = round($review_score * 10);
}
$cruise_description_html = BYT_Theme_Utils::strip_tags_and_shorten($cruise_obj->get_description(), 100) . '<a href="' . $cruise_obj->get_permalink() . '">' . __('More info', 'bookyourtravel') . '</a>';
$current_date = date('Y-m-d', time());
$cruise_min_price = $byt_cruises_post_type->get_cruise_min_price($cruise_id, 0, $current_date);
if (empty($display_mode) || $display_mode == 'card') {
    ?>
<!--cruise item-->
<article class="cruise_item <?php 
    echo $cruise_class;
    ?>
">
	<div>