function render_entry_form($booking_id) { global $byt_cruises_post_type; $booking_object = null; $edit = isset($_GET['edit']) ? absint($_GET['edit']) : 0; if ($booking_id > 0) { $edit = $booking_id; } if (!empty($edit)) { $booking_object = $byt_cruises_post_type->get_cruise_booking($edit); } $cruise_date = null; if (isset($_POST['cruise_date'])) { $cruise_date = wp_kses($_POST['cruise_date'], ''); } else { if ($booking_object != null) { $cruise_date = $booking_object->cruise_date; } } if (isset($cruise_date)) { $cruise_date = date($this->date_format, strtotime($cruise_date)); } $first_name = ''; if (isset($_POST['first_name'])) { $first_name = wp_kses($_POST['first_name'], ''); } else { if ($booking_object != null) { $first_name = $booking_object->first_name; } } $last_name = ''; if (isset($_POST['last_name'])) { $last_name = wp_kses($_POST['last_name'], ''); } else { if ($booking_object != null) { $last_name = $booking_object->last_name; } } $email = ''; if (isset($_POST['email'])) { $email = wp_kses($_POST['email'], ''); } else { if ($booking_object != null) { $email = $booking_object->email; } } $phone = ''; if (isset($_POST['phone'])) { $phone = wp_kses($_POST['phone'], ''); } else { if ($booking_object != null) { $phone = $booking_object->phone; } } $address = ''; if (isset($_POST['address'])) { $address = wp_kses($_POST['address'], ''); } else { if ($booking_object != null) { $address = $booking_object->address; } } $town = ''; if (isset($_POST['town'])) { $town = wp_kses($_POST['town'], ''); } else { if ($booking_object != null) { $town = $booking_object->town; } } $zip = ''; if (isset($_POST['zip'])) { $zip = wp_kses($_POST['zip'], ''); } else { if ($booking_object != null) { $zip = $booking_object->zip; } } $country = ''; if (isset($_POST['country'])) { $country = wp_kses($_POST['country'], ''); } else { if ($booking_object != null) { $country = $booking_object->country; } } $special_requirements = ''; if (isset($_POST['special_requirements'])) { $special_requirements = wp_kses($_POST['special_requirements'], ''); } else { if ($booking_object != null) { $special_requirements = $booking_object->special_requirements; } } $adults = 0; if (isset($_POST['adults'])) { $adults = intval(wp_kses($_POST['adults'], '')); } else { if ($booking_object != null) { $adults = $booking_object->adults; } } $children = 0; if (isset($_POST['children'])) { $children = intval(wp_kses($_POST['children'], '')); } else { if ($booking_object != null) { $children = $booking_object->children; } } $total_price_adults = 0; if (isset($_POST['total_price_adults'])) { $total_price_adults = floatval(wp_kses($_POST['total_price_adults'], '')); } else { if ($booking_object != null) { $total_price_adults = $booking_object->total_price_adults; } } $total_price_children = 0; if (isset($_POST['total_price_children'])) { $total_price_children = floatval(wp_kses($_POST['total_price_children'], '')); } else { if ($booking_object != null) { $total_price_children = $booking_object->total_price_children; } } $total_price = 0; if (isset($_POST['total_price'])) { $total_price = floatval(wp_kses($_POST['total_price'], '')); } else { if ($booking_object != null) { $total_price = $booking_object->total_price; } } $cruise_id = 0; $cabin_type_id = 0; if ($booking_object != null) { $cruise_id = $booking_object->cruise_id; $cabin_type_id = $booking_object->cabin_type_id; } $cruise_id = 0; if (isset($_GET['cruise_id'])) { $cruise_id = absint($_GET['cruise_id']); } else { if (isset($_POST['tour_id'])) { $cruise_id = intval(wp_kses($_POST['cruise_id'], '')); } else { if ($booking_object != null) { $cruise_id = $booking_object->cruise_id; } } } $cabin_type_id = 0; if (isset($_GET['cabin_type_id'])) { $cabin_type_id = absint($_GET['cabin_type_id']); } else { if (isset($_POST['tour_id'])) { $cabin_type_id = intval(wp_kses($_POST['cabin_type_id'], '')); } else { if ($booking_object != null) { $cabin_type_id = $booking_object->cabin_type_id; } } } $cruise_schedule_id = 0; if (isset($_GET['cruise_schedule_id'])) { $cruise_schedule_id = absint($_GET['cruise_schedule_id']); } else { if (isset($_POST['cruise_schedule_id'])) { $cruise_schedule_id = intval(wp_kses($_POST['cruise_schedule_id'], '')); } else { if ($booking_object != null) { $cruise_schedule_id = $booking_object->cruise_schedule_id; } } } if ($booking_object) { echo '<h3>' . __('Update Cruise Booking Entry', 'bookyourtravel') . '</h3>'; } else { echo '<h3>' . __('Add Cruise Booking Entry', 'bookyourtravel') . '</h3>'; } echo '<form id="cruise_booking_entry_form" method="post" action="' . esc_url($_SERVER['REQUEST_URI']) . '" style="clear: both;">'; echo wp_nonce_field('cruise_booking_entry_form_nonce'); echo '<table cellpadding="3" class="form-table"><tbody>'; $cruises_select = '<select id="cruise_id" name="cruise_id" onchange="cruiseBookingCruiseFilterRedirect(' . $edit . ',this.value)">'; $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>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Select cruise entry', 'bookyourtravel') . '</th>'; echo ' <td>' . $cruises_select . '</td>'; echo '</tr>'; $is_price_per_person = 0; if ($cruise_id > 0) { $cruise_obj = new byt_cruise(intval($cruise_id)); $cabin_types_select = '<select id="cabin_type_id" name="cabin_type_id" onchange="cruiseBookingCabinTypeFilterRedirect(' . $edit . ',' . $cruise_id . ',this.value)">'; $cabin_types_select .= '<option value="">' . __('Select cabin type 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>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Select cabin type entry', 'bookyourtravel') . '</th>'; echo ' <td>' . $cabin_types_select . '</td>'; echo '</tr>'; $is_price_per_person = $cruise_obj->get_is_price_per_person(); $cruise_type = __('One-off cruise', 'bookyourtravel'); if ($cruise_obj->get_type_is_repeated() == 1) { $cruise_type = __('Daily cruise', 'bookyourtravel'); } else { if ($cruise_obj->get_type_is_repeated() == 2) { $cruise_type = __('Weekday cruise', 'bookyourtravel'); } else { if ($cruise_obj->get_type_is_repeated() == 3) { $cruise_type = sprintf(__('Cruise on %s.</p>', 'bookyourtravel'), $cruise_obj->get_type_day_of_week_day()); } } } if ($cabin_type_id > 0) { $cruises_schedule_select = '<select id="cruise_schedule_id" name="cruise_schedule_id" onchange="cruiseBookingCruiseScheduleFilterRedirect(' . $edit . ',' . $cruise_id . ',' . $cabin_type_id . ',this.value)">'; $cruises_schedule_select .= '<option value="">' . __('Select cruise schedule', 'bookyourtravel') . '</option>'; $author_id = null; if (!is_super_admin()) { $author_id = get_current_user_id(); } $cruises_schedule_results = $byt_cruises_post_type->list_cruise_schedules(null, 0, 'Id', 'ASC', 0, 0, 0, $cruise_id, $cabin_type_id, $author_id); if (count($cruises_schedule_results) > 0 && $cruises_schedule_results['total'] > 0) { foreach ($cruises_schedule_results['results'] as $cruises_schedule_result) { $schedule_date = date($this->date_format, strtotime($cruises_schedule_result->start_date)); $cruises_schedule_select .= '<option value="' . $cruises_schedule_result->Id . '" ' . ($cruises_schedule_result->Id == $cruise_schedule_id ? 'selected' : '') . '>' . __('From', 'bookyourtravel') . ' ' . $schedule_date . ' ' . __('Days', 'bookyourtravel') . ' ' . $cruises_schedule_result->duration_days . ' ' . __('Price', 'bookyourtravel') . ' ' . $cruises_schedule_result->price . ' [' . $cruise_type . '] </option>'; } } $cruises_schedule_select .= '</select>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Select cruise schedule entry', 'bookyourtravel') . '</th>'; echo ' <td>' . $cruises_schedule_select . '</td>'; echo '</tr>'; } } echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Cruise date', 'bookyourtravel') . '</th>'; echo ' <td>'; echo ' <script>'; echo ' window.datepickerCruiseDateValue = "' . $cruise_date . '";'; echo ' </script>'; echo ' <input class="datepicker" type="text" name="datepicker_cruise_date" id="datepicker_cruise_date" />'; echo ' <input type="hidden" name="cruise_date" id="cruise_date" />'; echo ' </td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('First name', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="first_name" id="first_name" value="' . $first_name . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Last name', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="last_name" id="last_name" value="' . $last_name . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Email', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="email" id="email" value="' . $email . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Phone', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="phone" id="phone" value="' . $phone . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Address', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="address" id="address" value="' . $address . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Town', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="town" id="town" value="' . $town . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Zip', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="zip" id="zip" value="' . $zip . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Country', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="country" id="country" value="' . $country . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Special requirements', 'bookyourtravel') . '</th>'; echo ' <td><textarea type="text" name="special_requirements" id="special_requirements" rows="5" cols="50">' . $special_requirements . '</textarea></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Number of adults', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="adults" id="adults" value="' . $adults . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Number of children', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="children" id="children" value="' . $children . '" /></td>'; echo '</tr>'; if ($is_price_per_person) { echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Total price for adults', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="total_price_adults" id="total_price_adults" value="' . $total_price_adults . '" /></td>'; echo '</tr>'; echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Total price for children', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="total_price_children" id="total_price_children" value="' . $total_price_children . '" /></td>'; echo '</tr>'; } else { echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Total price for cabin', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="total_price_adults" id="total_price_adults" value="' . $total_price_adults . '" /> <input type="hidden" name="total_price_children" id="total_price_children" value="' . $total_price_children . '" /> </td>'; echo '</tr>'; } echo '<tr>'; echo ' <th scope="row" valign="top">' . __('Total price', 'bookyourtravel') . '</th>'; echo ' <td><input type="text" name="total_price" id="total_price" value="' . $total_price . '" /></td>'; echo '</tr>'; echo '</table>'; echo '<p>'; echo '<a href="edit.php?post_type=cruise&page=theme_cruise_schedule_booking_admin.php" class="button-secondary">' . __('Cancel', 'bookyourtravel') . '</a> '; if ($booking_object) { echo '<input id="booking_id" name="booking_id" value="' . $edit . '" type="hidden" />'; echo '<input class="button-primary" type="submit" name="update" value="' . __('Update Booking', 'bookyourtravel') . '"/>'; } else { if ($cruise_id > 0 && $cabin_type_id > 0 && $cruise_schedule_id > 0) { echo '<input class="button-primary" type="submit" name="insert" value="' . __('Add Booking', 'bookyourtravel') . '"/>'; } } echo '</p>'; echo '</form>'; }