function trav_tour_schedule_render_manage_page()
    {
        global $wpdb;
        if (!empty($_POST['save'])) {
            trav_tour_schedule_save_action();
            return;
        }
        $default_schedule_data = array('id' => '', 'tour_id' => '', 'st_id' => 0, 'tour_date' => date('Y-m-d'), 'duration' => '', 'max_people' => 1, 'price' => '', 'child_price' => '', 'is_daily' => 0, 'date_to' => '');
        $schedule_data = array();
        if ('add' == $_REQUEST['action']) {
            $page_title = "Add New Tour Schedule";
        } elseif ('edit' == $_REQUEST['action']) {
            $page_title = 'Edit Tour Schedule<a href="edit.php?post_type=tour&amp;page=schedules&amp;action=add" class="add-new-h2">Add New</a>';
            if (empty($_REQUEST['schedule_id'])) {
                echo "<h2>You attempted to edit an item that doesn't exist. Perhaps it was deleted?</h2>";
                return;
            }
            $schedule_id = sanitize_text_field($_REQUEST['schedule_id']);
            $post_table_name = $wpdb->prefix . 'posts';
            $where = 'schedule.id = %3$d';
            if (!current_user_can('manage_options')) {
                $where .= " AND tour.post_author = '" . get_current_user_id() . "' ";
            }
            $sql = $wpdb->prepare('SELECT schedule.* , tour.post_title as tour_name FROM %1$s as schedule
							INNER JOIN %2$s as tour ON schedule.tour_id=tour.ID
							WHERE ' . $where, TRAV_TOUR_SCHEDULES_TABLE, $post_table_name, $schedule_id);
            $schedule_data = $wpdb->get_row($sql, ARRAY_A);
            if (empty($schedule_data)) {
                echo "<h2>You attempted to edit an item that doesn't exist. Perhaps it was deleted?</h2>";
                return;
            }
        }
        $schedule_data = array_replace($default_schedule_data, $schedule_data);
        $schedule_types = trav_tour_get_schedule_types($schedule_data['tour_id']);
        ?>

		<div class="wrap">
			<h2><?php 
        echo wp_kses_post($page_title);
        ?>
</h2>
			<?php 
        if (isset($_REQUEST['updated'])) {
            echo '<div id="message" class="updated below-h2"><p>Schedule saved</p></div>';
        }
        ?>
			<form method="post" onsubmit="return manage_schedule_validateForm();">
				<input type="hidden" name="id" value="<?php 
        echo esc_attr($schedule_data['id']);
        ?>
">
				<table class="trav_admin_table trav_tour_schedule_manage_table">
					<tr>
						<th>Tour</th>
						<td>
							<select name="tour_id" id="tour_id">
								<?php 
        echo trav_tour_get_tour_list($schedule_data['tour_id']);
        ?>
							</select>
						</td>
					</tr>
					<tr class="schedule_type_wrapper<?php 
        if (empty($schedule_types)) {
            echo ' hide';
        }
        ?>
">
						<th>Schedule Type</th>
						<td>
							<select name="st_id" id="schedule_type">
								<?php 
        echo trav_tour_get_schedule_type_list($schedule_data['tour_id'], $schedule_data['st_id']);
        ?>
							</select>
						</td>
					</tr>
					<tr>
						<th>Max People</th>
						<td><input type="number" name="max_people" min="1" value="<?php 
        echo esc_attr($schedule_data['max_people']);
        ?>
"></td>
					</tr>
					<tr>
						<th>Duration</th>
						<td><input type="text" name="duration" id="duration" value="<?php 
        echo esc_attr($schedule_data['duration']);
        ?>
"></td>
						<td>You can put duration information to this field. For example 2 hours, 1 day etc</td>
					</tr>
					<tr>
						<th>Is Daily?</th>
						<td>
							<label for="is_daily">
								<input type="checkbox" id="is_daily" name="is_daily" value="1" <?php 
        if (!empty($schedule_data['is_daily'])) {
            echo esc_attr('checked');
        }
        ?>
>
							</label>
						</td>
						<td>Check this option if this tour is opened daily based.</td>
					</tr>
					<tr class="start_date">
						<th>Tour Date</th>
						<td><input type="text" name="tour_date" id="tour_date" value="<?php 
        echo esc_attr($schedule_data['tour_date']);
        ?>
"></td>
					</tr>
					<tr class="end_date">
						<th>End Date</th>
						<td><input type="text" name="date_to" id="date_to" value="<?php 
        if (!empty($schedule_data['date_to']) && $schedule_data['date_to'] != '9999-12-31') {
            echo esc_attr($schedule_data['date_to']);
        }
        ?>
"></td>
					</tr>
					<tr>
						<th>Charge Per Person?</th>
						<td>
							<label for="per_person_yn">
								<input type="checkbox" id="per_person_yn" name="per_person_yn" value="1" <?php 
        if (!empty($schedule_data['per_person_yn'])) {
            echo esc_attr('checked');
        }
        ?>
>
							</label>
						</td>
						<td>Check this option if this tour is charged per person.</td>
					</tr>
					<tr class="price">
						<th>Price</th>
						<td><input type="text" name="price" value="<?php 
        echo esc_attr($schedule_data['price']);
        ?>
"></td>
					</tr>
					<tr class="child_price">
						<th>Price Per Child</th>
						<td><input type="text" name="child_price" value="<?php 
        echo esc_attr($schedule_data['child_price']);
        ?>
"></td>
					</tr>
				</table>
				<input type="submit" class="button-primary" name="save" value="Save Schedule">
				<a href="edit.php?post_type=tour&amp;page=schedules" class="button-secondary">Cancel</a>
				<?php 
        wp_nonce_field('trav_tour_schedule_manage', 'schedule_save');
        ?>
			</form>
		</div>
		<?php 
    }
Beispiel #2
0
 function trav_ajax_tour_get_schedule_type()
 {
     if (isset($_POST['tour_id'])) {
         echo trav_tour_get_schedule_type_list($_POST['tour_id']);
     }
     exit;
 }
    function trav_tour_booking_render_manage_page()
    {
        global $wpdb, $trav_options;
        $post_table_name = $wpdb->prefix . 'posts';
        $site_currency_symbol = trav_get_site_currency_symbol();
        if (!empty($_POST['save'])) {
            trav_tour_booking_save_action();
            return;
        }
        $booking_data = array();
        if ('add' == $_REQUEST['action']) {
            $page_title = "Add New Tour booking";
        } elseif ('edit' == $_REQUEST['action']) {
            $page_title = 'Edit Tour Booking<a href="edit.php?post_type=tour&amp;page=tour_bookings&amp;action=add" class="add-new-h2">Add New</a>';
            if (empty($_REQUEST['booking_id'])) {
                echo "<h2>You attempted to edit an item that doesn't exist. Perhaps it was deleted?</h2>";
                return;
            }
            $booking_id = $_REQUEST['booking_id'];
            $where = 'booking.id = %3$d';
            if (!current_user_can('manage_options')) {
                $where .= " AND tour.post_author = '" . get_current_user_id() . "' ";
            }
            $sql = $wpdb->prepare('SELECT booking.*, tour.ID as tour_id, tour.post_title as tour_name FROM %1$s as booking
									INNER JOIN %2$s as tour ON booking.tour_id=tour.ID
									WHERE ' . $where, TRAV_TOUR_BOOKINGS_TABLE, $post_table_name, $booking_id);
            $booking_data = $wpdb->get_row($sql, ARRAY_A);
            if (empty($booking_data)) {
                echo "<h2>You attempted to edit an item that doesn't exist. Perhaps it was deleted?</h2>";
                return;
            }
        }
        $tour_id = empty($booking_data['tour_id']) ? '' : $booking_data['tour_id'];
        $schedule_types = trav_tour_get_schedule_types($tour_id);
        ?>

		<div class="wrap">
			<h2><?php 
        echo wp_kses_post($page_title);
        ?>
</h2>
			<?php 
        if (isset($_REQUEST['updated'])) {
            echo '<div id="message" class="updated below-h2"><p>Booking saved</p></div>';
        }
        ?>
			<form method="post" onsubmit="return manage_booking_validateForm();">
				<input type="hidden" name="id" value="<?php 
        if (!empty($booking_data['id'])) {
            echo esc_attr($booking_data['id']);
        }
        ?>
">
				<div class="one-half">
					<h3>Booking Detail</h3>
					<table class="trav_admin_table trav_booking_manage_table">
						<tr>
							<th>Tour</th>
							<td>
								<select name="tour_id" id="tour_id">
									<?php 
        echo trav_tour_get_tour_list($booking_data['tour_id']);
        ?>
								</select>
							</td>
						</tr>
						<tr class="schedule_type_wrapper<?php 
        if (empty($schedule_types)) {
            echo ' hide';
        }
        ?>
">
							<th>Schedule Type</th>
							<td>
								<select name="st_id" id="schedule_type">
									<?php 
        echo trav_tour_get_schedule_type_list($booking_data['tour_id'], $booking_data['st_id']);
        ?>
								</select>
							</td>
						</tr>
						<tr>
							<th>Tour Date</th>
							<td><input type="text" name="tour_date" id="tour_date" value="<?php 
        if (!empty($booking_data['tour_date'])) {
            echo esc_attr($booking_data['tour_date']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Adults</th>
							<td><input type="number" name="adults" value="<?php 
        if (!empty($booking_data['adults'])) {
            echo esc_attr($booking_data['adults']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Children</th>
							<td><input type="number" name="kids" value="<?php 
        if (!empty($booking_data['kids'])) {
            echo esc_attr($booking_data['kids']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Total Price</th>
							<td><input type="text" name="total_price" value="<?php 
        if (!empty($booking_data['total_price'])) {
            echo esc_attr($booking_data['total_price']);
        }
        ?>
"> <?php 
        echo esc_html($site_currency_symbol);
        ?>
</td>
						</tr>
						<?php 
        if (trav_is_multi_currency()) {
            ?>
							<tr>
								<th>User Currency</th>
								<td>
									<select name="currency_code">
										<?php 
            foreach (array_filter($trav_options['site_currencies']) as $key => $content) {
                ?>
											<option value="<?php 
                echo esc_attr($key);
                ?>
" <?php 
                if (!empty($booking_data['currency_code'])) {
                    selected($key, $booking_data['currency_code']);
                }
                ?>
><?php 
                echo esc_html($key);
                ?>
</option>
										<?php 
            }
            ?>
									</select>
								</td>
							</tr>
							<tr>
								<th>Exchange Rate</th>
								<td><input type="text" name="exchange_rate" value="<?php 
            if (!empty($booking_data['exchange_rate'])) {
                echo esc_attr($booking_data['exchange_rate']);
            }
            ?>
"></td>
							</tr>
							<tr>
								<th>Total Price in User Currency</th>
								<td><label> <?php 
            if (!empty($booking_data['total_price']) && !empty($booking_data['exchange_rate'])) {
                echo esc_attr($booking_data['total_price'] * $booking_data['exchange_rate']) . esc_html(trav_get_currency_symbol($booking_data['currency_code']));
            }
            ?>
</td>
							</tr>
						<?php 
        }
        ?>
						<?php 
        if (!empty($booking_data['deposit_price']) && !($booking_data['deposit_price'] == 0)) {
            ?>
							<tr>
								<th>Deposit Amount</th>
								<td><input type="text" name="deposit_price" value="<?php 
            if (!empty($booking_data['deposit_price'])) {
                echo esc_attr($booking_data['deposit_price']);
            }
            ?>
"> <?php 
            echo esc_html(trav_get_currency_symbol($booking_data['currency_code']));
            ?>
</td>
							</tr>
							<tr>
								<th>Deposit Paid</th>
								<td>
									<select name="deposit_paid">
										<?php 
            $deposit_paid = array('1' => 'yes', '0' => 'no');
            ?>
										<?php 
            foreach ($deposit_paid as $key => $content) {
                ?>
											<option value="<?php 
                echo esc_attr($key);
                ?>
" <?php 
                selected($key, $booking_data['deposit_paid']);
                ?>
><?php 
                echo esc_html($content);
                ?>
</option>
										<?php 
            }
            ?>
									</select>
								</td>
							</tr>
							<?php 
            if (!empty($booking_data['deposit_paid'])) {
                $other_data = unserialize($booking_data['other']);
                if (!empty($other_data['pp_transaction_id'])) {
                    ?>
								<tr>
									<th>Paypal Payment Transaction ID</th>
									<td><label><?php 
                    echo $other_data['pp_transaction_id'];
                    ?>
</label></td>
								</tr>
							<?php 
                }
            }
            ?>
						<?php 
        }
        ?>
						<tr>
							<th>Status</th>
							<td>
								<select name="status">
									<?php 
        $statuses = array('0' => 'cancelled', '1' => 'upcomming', '2' => 'completed');
        if (!isset($booking_data['status'])) {
            $booking_data['status'] = 1;
        }
        ?>
									<?php 
        foreach ($statuses as $key => $content) {
            ?>
										<option value="<?php 
            echo esc_attr($key);
            ?>
" <?php 
            selected($key, $booking_data['status']);
            ?>
><?php 
            echo esc_html($content);
            ?>
</option>
									<?php 
        }
        ?>
								</select>
							</td>
						</tr>
					</table>
				</div>
				<div class="one-half">
					<h3>Customer Infomation</h3>
					<table  class="trav_admin_table trav_booking_manage_table">
						<tr>
							<th>First Name</th>
							<td><input type="text" name="first_name" value="<?php 
        if (!empty($booking_data['first_name'])) {
            echo esc_attr($booking_data['first_name']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Last Name</th>
							<td><input type="text" name="last_name" value="<?php 
        if (!empty($booking_data['last_name'])) {
            echo esc_attr($booking_data['last_name']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Email</th>
							<td><input type="email" name="email" value="<?php 
        if (!empty($booking_data['email'])) {
            echo esc_attr($booking_data['email']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Country Code</th>
							<td><input type="text" name="country_code" value="<?php 
        if (!empty($booking_data['country_code'])) {
            echo esc_attr($booking_data['country_code']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Phone</th>
							<td><input type="text" name="phone" value="<?php 
        if (!empty($booking_data['phone'])) {
            echo esc_attr($booking_data['phone']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Address</th>
							<td><input type="text" name="address" value="<?php 
        if (!empty($booking_data['address'])) {
            echo esc_attr($booking_data['address']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>City</th>
							<td><input type="text" name="city" value="<?php 
        if (!empty($booking_data['city'])) {
            echo esc_attr($booking_data['city']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Zip</th>
							<td><input type="text" name="zip" value="<?php 
        if (!empty($booking_data['zip'])) {
            echo esc_attr($booking_data['zip']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Country</th>
							<td><input type="text" name="country" value="<?php 
        if (!empty($booking_data['country'])) {
            echo esc_attr($booking_data['country']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Special Requirements</th>
							<td><textarea name="special_requirements"><?php 
        if (!empty($booking_data['special_requirements'])) {
            echo esc_textarea(stripslashes($booking_data['special_requirements']));
        }
        ?>
</textarea></td>
						</tr>
						<tr>
							<th>Booking No</th>
							<td><input type="text" name="booking_no" value="<?php 
        if (!empty($booking_data['booking_no'])) {
            echo esc_attr($booking_data['booking_no']);
        }
        ?>
"></td>
						</tr>
						<tr>
							<th>Pin Code</th>
							<td><input type="text" name="pin_code" value="<?php 
        if (!empty($booking_data['pin_code'])) {
            echo esc_attr($booking_data['pin_code']);
        }
        ?>
"></td>
						</tr>
					</table>
				</div>
				<input type="submit" class="button-primary button_save_booking" name="save" value="Save booking">
				<a href="edit.php?post_type=tour&amp;page=tour_bookings" class="button-secondary">Cancel</a>
				<?php 
        wp_nonce_field('trav_manage_tour_bookings', 'booking_save');
        ?>
			</form>
		</div>
		<?php 
        if (!empty($trav_options['vld_credit_card']) && !empty($trav_options['cc_off_charge']) && !empty($booking_data['other'])) {
            $cc_fields = array('cc_type' => 'CREDIT CARD TYPE', 'cc_holder_name' => 'CARD HOLDER NAME', 'cc_number' => 'CARD NUMBER', 'cc_cid' => 'CARD IDENTIFICATION NUMBER', 'cc_exp_year' => 'EXPIRATION YEAR', 'cc_exp_month' => 'EXPIRATION MONTH');
            $cc_infos = unserialize($booking_data['other']);
            echo '<style>.cc_table{background:#fff;margin-top:30px;}.cc_table td{padding:10px;}.cc_table,.cc_table tr,.cc_table td{border:1px solid #000; border-collapse: collapse;}</style>';
            echo '<div style="clear:both"></div><h3>Credit Card Info</h3><table class="cc_table"><tbody>';
            foreach ($cc_fields as $key => $label) {
                if (!empty($cc_infos[$key])) {
                    echo '<tr><td><label>' . $label . '</label></td><td>' . $cc_infos[$key] . '</td></tr>';
                }
            }
            echo '</tbody></table>';
        }
    }