/**
  * Enqueue the admin-only CSS and Javascript
  * @since 0.0.1
  */
 public function enqueue_admin_assets()
 {
     // Use the page reference in $admin_page_hooks because
     // it changes in SOME hooks when it is translated.
     // https://core.trac.wordpress.org/ticket/18857
     global $admin_page_hooks;
     $screen = get_current_screen();
     if (empty($screen) || empty($admin_page_hooks['rtb-bookings'])) {
         return;
     }
     if ($screen->base == 'toplevel_page_rtb-bookings' || $screen->base == $admin_page_hooks['rtb-bookings'] . '_page_rtb-settings' || $screen->base == $admin_page_hooks['rtb-bookings'] . '_page_rtb-addons') {
         wp_enqueue_style('rtb-admin', RTB_PLUGIN_URL . '/assets/css/admin.css');
         wp_enqueue_script('rtb-admin', RTB_PLUGIN_URL . '/assets/js/admin.js', array('jquery'), '', true);
         wp_localize_script('rtb-admin', 'rtb_admin', array('nonce' => wp_create_nonce('rtb-admin'), 'strings' => array('add_booking' => __('Add Booking', 'restaurant-reservations'), 'edit_booking' => __('Edit Booking', 'restaurant-reservations'), 'error_unspecified' => __('An unspecified error occurred. Please try again. If the problem persists, try logging out and logging back in.', 'restaurant-reservations'))));
     }
     // Enqueue frontend assets to add/edit bookins on the bookings page
     if ($screen->base == 'toplevel_page_rtb-bookings') {
         $this->register_assets();
         rtb_enqueue_assets();
     }
 }
Example #2
0
function cs_booking_form($params, $content = null)
{
    global $rtb_controller;
    //wp_enqueue_style('intlTelInput', get_template_directory_uri() . '/framework/shortcodes/bookingtable/css/intlTelInput.css');
    //wp_enqueue_script('intlTelInput',get_template_directory_uri() . '/framework/shortcodes/bookingtable/js/intlTelInput.min.js', array('jquery'));
    //wp_enqueue_script('bookingtable',get_template_directory_uri() . '/framework/shortcodes/bookingtable/js/bookingtable.js', array('intlTelInput'));
    // Only allow the form to be displayed once on a page
    if ($rtb_controller->form_rendered === true) {
        return;
    } else {
        $rtb_controller->form_rendered = true;
    }
    // Enqueue assets for the form
    rtb_enqueue_assets();
    // Allow themes and plugins to override the booking form's HTML output.
    $output = apply_filters('rtb_booking_form_html_pre', '');
    if (!empty($output)) {
        return $output;
    }
    // Process a booking request
    if (!empty($_POST['action']) && $_POST['action'] == 'booking_request') {
        if (get_class($rtb_controller->request) === 'stdClass') {
            require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
            $rtb_controller->request = new rtbBooking();
        }
        $rtb_controller->request->insert_booking();
    }
    // Define the form's action parameter
    $booking_page = $rtb_controller->settings->get_setting('booking-page');
    if (!empty($booking_page)) {
        $booking_page = get_permalink($booking_page);
    }
    $settings = get_option('rtb-settings');
    ob_start();
    ?>
    <div class="cs-booking-form">
	<?php 
    if ($rtb_controller->request->request_inserted === true) {
        ?>
	<div class="rtb-message">
		<p><?php 
        echo $rtb_controller->settings->get_setting('success-message');
        ?>
</p>
	</div>
	<?php 
    } else {
        ?>
	<form id="cs-booking-form" method="POST" action="<?php 
        echo esc_attr($booking_page);
        ?>
">
		<input type="hidden" name="action" value="booking_request">
		<?php 
        do_action('rtb_booking_form_before_fields');
        ?>

		<div class="row">
		    <div class="cs-bookTable-date col-xs-12 col-sm-6 col-md-6 col-lg-6">
				<label for="rtb-date"><?php 
        _e('When would you like to book?', THEMENAME);
        ?>
</label>
				<span class="Selectoptions"><input type="text" name="rtb-date" id="rtb-date" value="<?php 
        echo cs_booking_request_input('request_date');
        ?>
" placeholder="<?php 
        _e('Select Date', THEMENAME);
        ?>
"></span>
				<?php 
        echo rtb_print_form_error('date');
        ?>
				<div id="cs-booking-date"></div>
			</div>
			<div class="cs-bookTable-party col-xs-12 col-sm-2 col-md-2 col-lg-2">
				<label for="rtb-party"><?php 
        _e('Party Size :', THEMENAME);
        ?>
</label>
				<span class="Selectoptions"><select name="rtb-party" id="rtb-party">
				    <?php 
        if (empty($settings['party-size'])) {
            $settings['party-size'] = 20;
        }
        for ($i = 1; $i <= $settings['party-size']; $i++) {
            ?>
				    <option value="<?php 
            echo $i;
            ?>
" <?php 
            if (cs_booking_request_input('party') == $i) {
                echo 'selected';
            }
            ?>
><?php 
            echo $i;
            ?>
</option>
				    <?php 
        }
        ?>
				</select>
				</span>
			</div>
			<div class="cs-bookTable-time col-xs-12 col-sm-4 col-md-4 col-lg-4">
				<label for="rtb-time"><?php 
        _e('Preferred dining time:', THEMENAME);
        ?>
</label>
				<span class="Selectoptions"><input type="text" name="rtb-time" id="rtb-time" value="<?php 
        echo cs_booking_request_input('request_time');
        ?>
" placeholder="<?php 
        _e('Select Time', THEMENAME);
        ?>
"></span>
				<?php 
        echo rtb_print_form_error('time');
        ?>
				<div id="cs-booking-time"></div>
			</div>
		</div>
		<div class="row">
		    <div class="name col-xs-12 col-sm-6 col-md-6 col-lg-6">
			     <input type="text" name="rtb-name" id="rtb-name" placeholder="<?php 
        _e('Name', THEMENAME);
        ?>
" value="<?php 
        echo cs_booking_request_input('name');
        ?>
">
			     <?php 
        echo rtb_print_form_error('name');
        ?>
			</div>
			<div class="email col-xs-12 col-sm-6 col-md-6 col-lg-6">
				<input type="text" name="rtb-email" id="rtb-email" placeholder="<?php 
        _e('Email', THEMENAME);
        ?>
" value="<?php 
        echo cs_booking_request_input('email');
        ?>
">
				<?php 
        echo rtb_print_form_error('email');
        ?>
			</div>
		</div>
		<div class="row">
		    <div class="phone col-xs-12 col-sm-6 col-md-6 col-lg-6">
    		    <input type="text" name="rtb-phone" id="rtb-phone" placeholder="<?php 
        _e('Phone', THEMENAME);
        ?>
" value="<?php 
        echo cs_booking_request_input('phone');
        ?>
">
			    <?php 
        echo rtb_print_form_error('phone');
        ?>
			</div>
			<div class="message col-xs-12 col-sm-6 col-md-6 col-lg-6">
				<?php 
        echo rtb_print_form_error('message');
        ?>
				<input type="text" name="rtb-message" id="rtb-message" placeholder="<?php 
        _e('Message', THEMENAME);
        ?>
" value="<?php 
        echo cs_booking_request_input('message');
        ?>
">
			</div>
		</div>

		<?php 
        do_action('rtb_booking_form_after_fields');
        ?>

		<div class="cs-bookTable-submit">
			<button class="btn btn-default" type="submit"><?php 
        _e('BOOK MY TABLE', THEMENAME);
        ?>
</button>
			<span class="des-text"><?php 
        echo _e('Please submit your reservation details and we will contact you to confirm your booking ', THEMENAME);
        ?>
</span>
		</div>

	</form>
	<?php 
    }
    ?>
    </div>
    
    <?php 
    $output = ob_get_clean();
    $output = apply_filters('rtb_booking_form_html_post', $output);
    return $output;
}
    function rtb_print_booking_form()
    {
        global $rtb_controller;
        // Only allow the form to be displayed once on a page
        if ($rtb_controller->form_rendered === true) {
            return;
        } else {
            $rtb_controller->form_rendered = true;
        }
        // Enqueue assets for the form
        rtb_enqueue_assets();
        // Allow themes and plugins to override the booking form's HTML output.
        $output = apply_filters('rtb_booking_form_html_pre', '');
        if (!empty($output)) {
            return $output;
        }
        // Process a booking request
        if (!empty($_POST['action']) && $_POST['action'] == 'booking_request') {
            if (get_class($rtb_controller->request) === 'stdClass') {
                require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
                $rtb_controller->request = new rtbBooking();
            }
            $rtb_controller->request->insert_booking();
        }
        // Define the form's action parameter
        $booking_page = $rtb_controller->settings->get_setting('booking-page');
        if (!empty($booking_page)) {
            $booking_page = get_permalink($booking_page);
        }
        // Retrieve the form fields
        $fields = $rtb_controller->settings->get_booking_form_fields($rtb_controller->request);
        ob_start();
        ?>

<div class="rtb-booking-form">
	<?php 
        if ($rtb_controller->request->request_inserted === true) {
            ?>
	<div class="rtb-message">
		<p><?php 
            echo $rtb_controller->settings->get_setting('success-message');
            ?>
</p>
	</div>
	<?php 
        } else {
            ?>
	<form method="POST" action="<?php 
            echo esc_attr($booking_page);
            ?>
">
		<input type="hidden" name="action" value="booking_request">

		<?php 
            do_action('rtb_booking_form_before_fields');
            ?>

		<?php 
            foreach ($fields as $fieldset => $contents) {
                $fieldset_classes = isset($contents['callback_args']['classes']) ? $contents['callback_args']['classes'] : array();
                $legend_classes = isset($contents['callback_args']['legend_classes']) ? $contents['callback_args']['legend_classes'] : array();
                ?>
		<fieldset <?php 
                echo rtb_print_element_class($fieldset, $fieldset_classes);
                ?>
>

			<?php 
                if (!empty($contents['legend'])) {
                    ?>
			<legend <?php 
                    echo rtb_print_element_class('', $legend_classes);
                    ?>
>
				<?php 
                    echo $contents['legend'];
                    ?>
			</legend>
			<?php 
                }
                ?>

			<?php 
                foreach ($contents['fields'] as $slug => $field) {
                    $args = empty($field['callback_args']) ? null : $field['callback_args'];
                    call_user_func($field['callback'], $slug, $field['title'], $field['request_input'], $args);
                }
                ?>
		</fieldset>
		<?php 
            }
            ?>

		<?php 
            do_action('rtb_booking_form_after_fields');
            ?>

		<?php 
            $button = sprintf('<button type="submit">%s</button>', apply_filters('rtb_booking_form_submit_label', __('Request Booking', 'restaurant-reservations')));
            echo apply_filters('rtb_booking_form_submit_button', $button);
            ?>


	</form>
	<?php 
        }
        ?>
</div>

	<?php 
        $output = ob_get_clean();
        $output = apply_filters('rtb_booking_form_html_post', $output);
        return $output;
    }
    function rtb_print_booking_form()
    {
        global $rtb_controller;
        // Only allow the form to be displayed once on a page
        if ($rtb_controller->form_rendered === true) {
            return;
        } else {
            $rtb_controller->form_rendered = true;
        }
        // Enqueue assets for the form
        rtb_enqueue_assets();
        // Allow themes and plugins to override the booking form's HTML output.
        $output = apply_filters('rtb_booking_form_html_pre', '');
        if (!empty($output)) {
            return $output;
        }
        // Process a booking request
        if (!empty($_POST['action']) && $_POST['action'] == 'booking_request') {
            if (empty($rtb_controller->request)) {
                require_once RTB_PLUGIN_DIR . '/includes/Booking.class.php';
                $rtb_controller->request = new rtbBooking();
            }
            $rtb_controller->request->insert_booking();
        }
        // Set up a dummy request object if no request has been made. This just
        // simplifies the display of values in the form below
        if (empty($rtb_controller->request)) {
            $request = new stdClass();
            $request->request_processed = false;
            $request->request_inserted = false;
        } else {
            $request = $rtb_controller->request;
        }
        // Define the form's action parameter
        $booking_page = $rtb_controller->settings->get_setting('booking-page');
        if (!empty($booking_page)) {
            $booking_page = get_permalink($booking_page);
        }
        // Define the form fields
        //
        // This array defines the field details and a callback function to
        // render each field. To customize the form output, modify the
        // callback functions to point to your custom function. Don't forget
        // to output an error message in your custom callback function. You
        // can use rtb_print_form_error( $slug ) to do this.
        $fields = array('reservation' => array('legend' => __('Book a table', RTB_TEXTDOMAIN), 'fields' => array('date' => array('title' => __('Date', RTB_TEXTDOMAIN), 'request_input' => empty($request->request_date) ? '' : $request->request_date, 'callback' => 'rtb_print_form_text_field'), 'time' => array('title' => __('Time', RTB_TEXTDOMAIN), 'request_input' => empty($request->request_time) ? '' : $request->request_time, 'callback' => 'rtb_print_form_text_field'), 'party' => array('title' => __('Party', RTB_TEXTDOMAIN), 'request_input' => empty($request->party) ? '' : $request->party, 'callback' => 'rtb_print_form_text_field'))), 'contact' => array('legend' => __('Contact Details', RTB_TEXTDOMAIN), 'fields' => array('name' => array('title' => __('Name', RTB_TEXTDOMAIN), 'request_input' => empty($request->name) ? '' : $request->name, 'callback' => 'rtb_print_form_text_field'), 'email' => array('title' => __('Email', RTB_TEXTDOMAIN), 'request_input' => empty($request->email) ? '' : $request->email, 'callback' => 'rtb_print_form_text_field'), 'phone' => array('title' => __('Phone', RTB_TEXTDOMAIN), 'request_input' => empty($request->phone) ? '' : $request->phone, 'callback' => 'rtb_print_form_text_field'), 'add-message' => array('title' => __('Add a Message', RTB_TEXTDOMAIN), 'request_input' => '', 'callback' => 'rtb_print_form_message_link'), 'message' => array('title' => __('Message', RTB_TEXTDOMAIN), 'request_input' => empty($request->message) ? '' : $request->message, 'callback' => 'rtb_print_form_textarea_field'))));
        $fields = apply_filters('rtb_booking_form_fields', $fields, $request);
        ob_start();
        ?>

<div class="rtb-booking-form">
	<?php 
        if ($request->request_inserted === true) {
            ?>
	<div class="rtb-message">
		<p><?php 
            echo $rtb_controller->settings->get_setting('success-message');
            ?>
</p>
	</div>
	<?php 
        } else {
            ?>
	<form method="POST" action="<?php 
            echo esc_attr($booking_page);
            ?>
">
		<input type="hidden" name="action" value="booking_request">

		<?php 
            do_action('rtb_booking_form_before_fields');
            ?>

		<?php 
            foreach ($fields as $fieldset => $contents) {
                ?>
		<fieldset class="<?php 
                echo $fieldset;
                ?>
">

			<?php 
                if (!empty($contents['legend'])) {
                    ?>
			<legend>
				<?php 
                    echo $contents['legend'];
                    ?>
			</legend>
			<?php 
                }
                ?>

			<?php 
                foreach ($contents['fields'] as $slug => $field) {
                    call_user_func($field['callback'], $slug, $field['title'], $field['request_input']);
                }
                ?>
		</fieldset>
		<?php 
            }
            ?>

		<?php 
            do_action('rtb_booking_form_after_fields');
            ?>
		
		<button type="submit"><?php 
            _e('Request Booking', RTB_TEXTDOMAIN);
            ?>
</button>
		
	</form>
	<?php 
        }
        ?>
</div>

	<?php 
        $output = ob_get_clean();
        $output = apply_filters('rtb_booking_form_html_post', $output);
        return $output;
    }