PluginProbe
Booking Calendar / 10.15.7
Booking Calendar v10.15.7
11.9 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 All 205 releases
booking / includes / page-bookings / bookings__listing.php

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

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