PluginProbe
Booking Calendar / 11.8.4
Booking Calendar v11.8.4
11.8.4 11.8.3 11.8.2 11.8.1 11.8 11.7 11.6.1 11.6 11.5 11.4.3 11.4.2 11.4.1 11.4 11.3 11.2.1 11.2 11.1 11.0 10.15.7 10.15.6 10.1.3 10.10 10.10.1 10.10.2 10.11 All 204 releases
booking / includes / page-bookings / bookings__listing.php

bookings__listing.php in Booking Calendar 11.8.4, at includes/page-bookings/bookings__listing.php

402 lines 14.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php /**
2 * @version 1.0
3 * @description AJX_Bookings
4 * @category AJX_Bookings Class
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2020-01-23
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit; // Exit if accessed directly.
15 }
16
17 class WPBC_AJX_Bookings {
18
19 /**
20 * Static Variables
21 *
22 * @var string[]
23 */
24 public static $data_separator = array(
25 'r_separator' => '~',
26 'f_separator' => '^',
27 );
28
29
30 // <editor-fold defaultstate="collapsed" desc=" /// JS | CSS files | Tpl loading /// " >
31
32 // JS | CSS =======================================================================================================.
33
34 /**
35 * Define HOOKs for loading CSS and JavaScript files
36 */
37 public function init_load_css_js_tpl() {
38
39 add_action( 'wpbc_enqueue_js_files', array( $this, 'js_load_files' ), 50 );
40 add_action( 'wpbc_enqueue_css_files', array( $this, 'enqueue_css_files' ), 50 );
41
42 add_action( 'wpbc_hook_settings_page_footer', array( $this, 'hook__page_footer_tmpl' ) );
43 }
44
45
46 /**
47 * JSS.
48 *
49 * @param string $where_to_load - slug.
50 *
51 * @return void
52 */
53 public function js_load_files( $where_to_load ) {
54
55 if ( ! is_admin() || ! wpbc_is_bookings_page() ) {
56 return;
57 }
58
59 if ( ( is_admin() ) && ( in_array( $where_to_load, array( 'admin', 'both' ), true ) ) ) {
60 self::enqueue_js_files_now();
61 }
62 }
63
64 /**
65 * Enqueue AJAX booking listing scripts.
66 *
67 * The Booking Listing page prints inline initialization in its content. In Free, the saved default view can differ
68 * from the current tab, so this method is also called directly from the page content as a last-mile guarantee.
69 *
70 * @return void
71 */
72 public static function enqueue_js_files_now() {
73
74 $in_footer = true;
75
76 wp_enqueue_script( 'wpbc-booking_ajx_listing', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__listing.js', array( 'wpbc_all', 'wp-util' ), WP_BK_VERSION_NUM, $in_footer );
77 wp_enqueue_script( 'wpbc-booking_ajx_toolbar_hooks', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__hooks.js', array( 'wpbc-booking_ajx_listing', 'wpbc-ui-chosen-filter' ), WP_BK_VERSION_NUM, $in_footer );
78 wp_enqueue_script( 'wpbc-booking_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/bookings__actions.js', array( 'wpbc-booking_ajx_listing' ), WP_BK_VERSION_NUM, $in_footer );
79 wp_enqueue_script( 'wpbc-boo_listing_ajx_actions', trailingslashit( plugins_url( '', __FILE__ ) ) . '_out/boo_listing__actions.js', array( 'wpbc-booking_ajx_listing' ), WP_BK_VERSION_NUM, $in_footer );
80 }
81
82
83 /**
84 * CSS
85 *
86 * @param string $where_to_load - slug.
87 *
88 * @return void
89 */
90 public function enqueue_css_files( $where_to_load ) {
91 }
92
93 // </editor-fold>
94
95
96 // <editor-fold defaultstate="collapsed" desc=" /// Templates /// " >
97
98 // Templates ===================================================================================================
99
100 /**
101 * Templates at footer of page
102 *
103 * @param string $page - 'wpbc-ajx_booking'.
104 */
105 public function hook__page_footer_tmpl( $page ) {
106
107 if ( 'wpbc-ajx_booking' === $page ) { // it's from >> do_action( 'wpbc_hook_settings_page_footer', 'wpbc-ajx_booking' );.
108
109 wpbc_template__booking_listing_header();
110 wpbc_template__booking_listing_footer();
111 wpbc_template__booking_listing_row();
112
113 $this->template__content_data();
114 }
115 }
116
117 private function template__content_data(){
118
119 // Content Data.
120 ?><script type="text/html" id="tmpl-wpbc_content_data">
121 <strong>{{data.key}}</strong>:<span class="fieldvalue {{data.key}}<#
122 if ( ( data.keyword != '' )
123 && ( undefined != data.value )
124 && ( -1 != data.value.toLowerCase().indexOf( data.keyword.trim().toLowerCase() ) )
125 ) {
126 #> fieldsearchvalue<#
127 }
128 if ( ( undefined != data.value )
129 && ( -1 != data.value.toLowerCase().indexOf( 'refund' ) )
130 ) {
131 #> _refund<#
132 }
133 #>">{{{data.value}}}</span>&nbsp;&nbsp;
134 </script><?php
135 }
136
137 // </editor-fold>
138
139
140 // <editor-fold defaultstate="collapsed" desc=" /// A J A X /// " >
141
142 // A J A X =========================================================================================================.
143
144 /**
145 * Define HOOKs for start loading Ajax
146 */
147 public function define_ajax_hook() {
148
149 // Ajax Handlers. Note. "locale_for_ajax" rechecked in wpbc-ajax.php.
150 add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Admin & Client (logged in usres).
151
152 // Ajax Handlers for actions.
153 add_action( 'wp_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS', 'wpbc_ajax_' . 'WPBC_AJX_BOOKING_ACTIONS' );
154 // add_action( 'wp_ajax_nopriv_' . 'WPBC_AJX_BOOKING_LISTING', array( $this, 'ajax_' . 'WPBC_AJX_BOOKING_LISTING' ) ); // Client (not logged in).
155 }
156
157
158
159 /**
160 * Ajax - Get Listing Data and Response to JS script
161 */
162 public function ajax_WPBC_AJX_BOOKING_LISTING() {
163
164 // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
165 if ( ! isset( $_POST['search_params'] ) || empty( $_POST['search_params'] ) ) { exit; }
166
167 // Security ----------------------------------------------------------------------------------------------- // in Ajax Post: 'nonce': wpbc_ajx_booking_listing.get_secure_param( 'nonce' ),.
168 $action_name = 'wpbc_ajx_booking_listing_ajx' . '_wpbcnonce';
169 $nonce_post_key = 'nonce';
170 $result_check = check_ajax_referer( $action_name, $nonce_post_key );
171
172 $user_id = ( isset( $_REQUEST['wpbc_ajx_user_id'] ) ) ? intval( $_REQUEST['wpbc_ajx_user_id'] ) : wpbc_get_current_user_id(); // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
173
174 /**
175 * SQL ---------------------------------------------------------------------------
176 *
177 * in Ajax Post: 'search_params': wpbc_ajx_booking_listing.search_get_all_params()
178 *
179 * Use prefix "search_params", if Ajax sent -
180 * $_REQUEST['search_params']['page_num'], $_REQUEST['search_params']['page_items_count'],..
181 */
182
183 $user_request = new WPBC_AJX__REQUEST(
184 array(
185 'db_option_name' => 'booking_listing_request_params',
186 'user_id' => $user_id, // FixIn: 9.4.3.2.
187 'request_rules_structure' => wpbc_ajx_get__request_params__names_default(),
188 )
189 );
190
191 $request_prefix = 'search_params';
192 $request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // NOT Direct: $_REQUEST['search_params']['resource_id'].
193
194
195 $data_arr = wpbc_ajx_get_booking_data_arr( $request_params );
196
197 $new_bookings_count = wpbc_db_get_number_new_bookings();
198
199 if ( 'make_reset' === $request_params['ui_reset'] ) {
200
201 $is_reseted = wpbc_ajx__user_request_params__delete( $user_id );
202
203 $request_params['ui_reset'] = $is_reseted ? 'reset_done' : 'reset_error';
204 $request_params['ui_reset_url'] = wpbc_get_bookings_url() . '&tab=vm_booking_listing';
205
206 } else {
207 $is_success_update = wpbc_ajx__user_request_params__save( $request_params, $user_id ); // - $request_params - serialized here automatically.
208 }
209
210 // ---------------------------------------------------------------------------------------------------------.
211 // Send JSON. Its will make "wp_json_encode" - so pass only array, and This function call wp_die( '', '', array( 'response' => null, ) ) Pass JS OBJ: response_data in "jQuery.post( " function on success.
212 wp_send_json(
213 array(
214 'ajx_count' => $data_arr['count'],
215 'ajx_items' => $data_arr['data_arr'],
216 'ajx_booking_resources' => $data_arr['booking_resources'],
217 // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
218 'ajx_search_params' => $_REQUEST['search_params'],
219 'ajx_cleaned_params' => $request_params,
220 'ajx_new_bookings_count' => $new_bookings_count,
221 )
222 );
223 }
224
225 // </editor-fold>
226
227
228 }
229
230
231 /**
232 * Just for loading CSS and JavaScript files
233 */
234 if ( true ) {
235 $wpbc_ajx_booking_loading = new WPBC_AJX_Bookings();
236 $wpbc_ajx_booking_loading->init_load_css_js_tpl();
237 $wpbc_ajx_booking_loading->define_ajax_hook();
238 }
239
240
241
242
243 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
244 // API Hooks
245 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
246
247 /**
248 * Get booking data by booking_ID
249 *
250 * @param $booking_id int
251 *
252 * @return false | stdClass Object (
253 [booking_db] => stdClass Object (
254 [booking_id] => 130
255 [booking_options] =>
256 [trash] => 0
257 [sync_gid] => 15l1028ii1v95ctbpgcf2r2s2h_20171201
258 [is_new] => 0
259 [status] =>
260 [sort_date] => 2022-08-08 00:00:00
261 [modification_date] => 2022-07-24 11:04:32
262 [form] => text^name1^Jessica~text^secondname1^....
263 [hash] => 1d7dc4e06d95726bf9
264 [booking_type] => 1
265 [remark] =>
266 [cost] => 100.00
267 [pay_status] => Failed
268 [pay_request] => 0
269 )
270 [id] => 130
271 [approved] => 0
272 [dates] => Array ( [0] => '2022-08-08 00:00:00' [1] => '2022-08-09 00:00:00' [2] => '2022-08-10 00:00:00' )
273 [child_id] => Array ( [0] => '' [1] => '' [2] => '' )
274 [short_dates] => Array ( [0] => '2022-08-08 00:00:00' [1] => '-' [2] => '2022-08-10 00:00:00' )
275 [short_dates_child_id] => Array ( [0] => '' [1] => '' [2] => '' )
276 [parsed_fields] => Array (
277 [name] => Jessica
278 [secondname] => Simson
279 ...
280 [booking_id] => 130
281 [trash] => 0
282 [sync_gid] => 15l1028ii1v95ctbpgcf2r2s2h_20171201
283 [is_new] => 0
284 [status] =>
285 [sort_date] => 2022-08-08 00:00:00
286 [modification_date] => July 24, 2022 11:04
287 [hash] => 1d7dc4e06d95726bf9060a66235b7dc6
288 [booking_type] => 1
289 [remark] =>
290 [cost] => 100.00
291 [pay_status] => Failed
292 [pay_request] => 0
293 [id] => 130
294 [approved] => 0
295 [booking_options] =>
296 [is_paid] => 0
297 [pay_print_status] => Failed
298 [currency_symbol] => $
299 [resource_title] => Standard
300 [resource_id] => 1
301 [resource_owner_user] => 1
302 [google_calendar_link] => https://calendar.google.com/calendar/r/eventedit?text=...
303 )
304 [templates] => Array (
305 [form_show] => First Name:Jessica
306 Last Name:Simson
307 Email:simson@gmail.com
308 Phone:724 895 34 88
309 Address:Oliver street 10
310 City:Manchester
311 Post code:78998
312 Country:UK
313 Adults: 2
314 Children: 0
315 Details: I want a room with a terrace
316
317 [form_show_nohtml] =>
318 First Name:Jessica
319 Last Name:Simson
320 Email:simson@gmail.com
321 Phone:724 895 34 88
322 Address:Oliver street 10
323 City:Manchester
324 Post code:78998
325 Country:UK
326 Adults: 2
327 Children: 0
328 Details: I want a room with a terrace
329 [short_dates_content] => August 8, 2022 - August 10, 2022
330 [wide_dates_content] => August 8, 2022, August 9, 2022, August 10, 2022
331 [payment_label_template] => Payment Failed
332 )
333 )
334 */
335 function wpbc_search_booking_by_id( $booking_id ) {
336
337 $booking_id = intval( $booking_id );
338
339 if ( ! empty( $booking_id ) ) {
340 $booking_data = wpbc_search_booking_by_keyword( 'id:' . $booking_id );
341
342 if ( ! empty( $booking_data['data_arr'] ) ) {
343 return $booking_data['data_arr'][0];
344 }
345 }
346
347 return false;
348 }
349
350 /**
351 * Search specific booking(s) by Keyword
352 *
353 * @param string $keyword 'email@serv.com'
354 * @param array $search_params default array() array( 'source' => 'csv' )
355 *
356 * @return array(
357 [data_arr] => Array (
358 [0] => Array(
359 [booking_id] => 2772
360 [product_name] => Personal
361 [date_placed] => 2019-10-16
362 [order] => XXA3443ASDDA-232423-423423
363 [email] => email@serv.com
364 [_license_key] => 74826576578436
365 [full_product_name] => Personal (single site)
366 ....
367 )
368 )
369 [count] => 1
370 *
371 */
372 function wpbc_search_booking_by_keyword( $keyword , $search_params = array() ){
373
374 $ajx_booking_listing = new WPBC_AJX_Bookings;
375
376 $request_params = array(
377 'page_num' => 1,
378 'page_items_count' => 99999,
379 'sort' => 'booking_id',
380 'sort_type' => 'DESC',
381 'keyword' => ''
382 );
383
384 // Get Default Parameters
385 $default_param_values = wpbc_ajx_get__request_params__names_default( 'default' );
386 $request_params = wp_parse_args( $request_params, $default_param_values );
387
388 // Get Search Parameters, if passed into function
389 $request_params = wp_parse_args( $search_params, $request_params );
390
391 $request_params['keyword'] = wpbc_sanitize_text( $keyword );
392
393 $ajx_booking_arr = wpbc_ajx_get_booking_data_arr( $request_params );
394
395 return $ajx_booking_arr;
396 }
397 add_filter( 'wpbc_search_booking_by_keyword' , 'wpbc_search_booking_by_keyword' ,10, 2 );
398
399 /**
400 * DevApi: apply_filters( 'wpbc_search_booking_by_keyword', ' d1ca3d0b476c ', array( 'source' => 'csv' ) );
401 */
402