PluginProbe
Booking Calendar / 10.1.3
Booking Calendar v10.1.3
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 10.11.2 All 203 releases
booking / includes / _booking_hash / booking_hash.php

booking_hash.php in Booking Calendar 10.1.3, at includes/_booking_hash/booking_hash.php

214 lines 6.9 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 Booking Hash Functions
4 * @category Booking Hash
5 * @author wpdevelop
6 *
7 * @web-site http://oplugins.com/
8 * @email info@oplugins.com
9 *
10 * @modified 2022-08-05
11 */
12
13 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
15 // H A S H //FixIn: 9.2.3.3
16
17 /**
18 * Get booking ID and resource ID by booking HASH
19 *
20 * @param $booking_hash
21 *
22 * @return array|false - array( $booking_id, $resource_id ) | false if not found
23 */
24 function wpbc_hash__get_booking_id__resource_id( $booking_hash ) {
25
26 if ( '' == $booking_hash ) {
27 return false;
28 }
29 global $wpdb;
30
31 if ( class_exists( 'wpdev_bk_personal' ) ) {
32
33 $sql = $wpdb->prepare( "SELECT booking_id as id, booking_type as type FROM {$wpdb->prefix}booking as bk WHERE bk.hash = %s", $booking_hash );
34
35 $res = $wpdb->get_results( $sql );
36
37 if ( ( ! empty( $res ) ) && ( is_array( $res ) ) && ( isset( $res[0]->id ) ) && ( isset( $res[0]->type ) ) ) { //FixIn: 8.1.2.13
38 return array( $res[0]->id, $res[0]->type );
39 }
40 } else {
41
42 $sql = $wpdb->prepare( "SELECT booking_id as id FROM {$wpdb->prefix}booking as bk WHERE bk.hash = %s", $booking_hash );
43
44 $res = $wpdb->get_results( $sql );
45
46 if ( ( ! empty( $res ) ) && ( is_array( $res ) ) && ( isset( $res[0]->id ) ) ) { //FixIn: 8.1.2.13
47 return array( $res[0]->id, 1 );
48 }
49 }
50
51 return false;
52 }
53
54
55 /**
56 * Get booking HASH and resource ID
57 * by booking ID
58 *
59 * @param $booking_id
60 *
61 * @return array|false - array( $hash, $resource_id ) | false if not found
62 */
63 function wpbc_hash__get_booking_hash__resource_id( $booking_id ) {
64
65 if ( '' == $booking_id ) {
66 return false;
67 }
68 global $wpdb;
69
70 if ( class_exists( 'wpdev_bk_personal' ) ) {
71
72 $sql = $wpdb->prepare( "SELECT hash, booking_type as type FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id = %d", $booking_id );
73
74 $res = $wpdb->get_results( $sql );
75
76 if ( ( ! empty( $res ) ) && ( is_array( $res ) ) && ( isset( $res[0]->hash ) ) && ( isset( $res[0]->type ) ) ) {
77 return array( $res[0]->hash, $res[0]->type );
78 }
79 } else {
80
81 $sql = $wpdb->prepare( "SELECT hash FROM {$wpdb->prefix}booking as bk WHERE bk.booking_id = %d", $booking_id );
82
83 $res = $wpdb->get_results( $sql );
84
85 if ( ( ! empty( $res ) ) && ( is_array( $res ) ) && ( isset( $res[0]->hash ) ) ) {
86 return array( $res[0]->hash, 1 );
87 }
88 }
89
90 return false;
91 }
92
93
94 /**
95 * Update booking hash to newly generated. Run after creation/modification of booking in post request
96 *
97 * @param $booking_id
98 * @param $resource_id
99 *
100 * @return void
101 */
102 function wpbc_hash__update_booking_hash( $booking_id, $resource_id = '1' ) {
103 global $wpdb;
104
105 $update_sql = $wpdb->prepare( "UPDATE {$wpdb->prefix}booking AS bk SET bk.hash = MD5(%s) WHERE bk.booking_id = %d"
106 , time() . '_' . rand( 1000, 1000000 )
107 , $booking_id
108 );
109 if ( false === $wpdb->query( $update_sql ) ) {
110 ?><script type="text/javascript"> document.getElementById( 'submiting<?php echo $resource_id; ?>' ).innerHTML = '<div style=&quot;height:20px;width:100%;text-align:center;margin:15px auto;&quot;><?php debuge_error( 'Error during updating hash in BD', __FILE__, __LINE__ ); ?></div>'; </script> <?php
111 die();
112 }
113 }
114
115
116 /**
117 * Get JavaScript for start dates selection in calendar after 1.5 second
118 *
119 * @param array $to_select__dates_sql_arr
120 * @param int $resource_id
121 *
122 * @return string - JavaScript code as text
123 */
124 function wpbc_get_dates_selection_js_code( $to_select__dates_sql_arr, $resource_id ){
125
126 $dates_selection_js_code = '<script type="text/javascript"> ' . wpbc_jq_ready_start(); //FixIn: 10.1.3.7
127
128 //FixIn: 10.0.0.50
129 $dates_selection_js_code .= ' var select_dates_in_calendar_id = ' . intval( $resource_id ) . ';';
130 $dates_selection_js_code .= " jQuery( 'body' ).on( 'wpbc_calendar_ajx__loaded_data', function ( event, loaded_resource_id ){ "; // Fire on all booking dates loaded
131 $dates_selection_js_code .= " if ( loaded_resource_id == select_dates_in_calendar_id ){ ";
132
133 $string__dates_sql_arr = array_map( function ( $value ) {
134 $value = explode( ' ', $value );
135 $new_value = "'" . $value[0] . "'";
136 return $new_value;
137 }, $to_select__dates_sql_arr );
138 $string__dates_sql_arr = array_unique($string__dates_sql_arr);
139 $string__dates_sql_str = implode( ',', $string__dates_sql_arr );
140
141 $dates_selection_js_code .= " wpbc_auto_select_dates_in_calendar( select_dates_in_calendar_id, [" . $string__dates_sql_str . "] ); ";
142 $dates_selection_js_code .= " } ";
143 $dates_selection_js_code .= " } ); ";
144
145 $dates_selection_js_code .= wpbc_jq_ready_end() . '</script>'; //FixIn: 10.1.3.7
146
147 return $dates_selection_js_code;
148 }
149
150
151 /**
152 * Get booking ID, from the $_GET['booking_hash'] in url
153 *
154 * @param $booking_hash if default false, then get hash from $_GET['booking_hash'] Otherwise get it from this parameter
155 *
156 * @return int|string ID of booking or '', if not found
157 */
158 function wpbc_get_booking_id__from_hash_in_url( $booking_hash = false ){
159
160 $result_arr = wpbc_get_booking_arr__from_hash_in_url( $booking_hash );
161
162 return $result_arr['booking_id'];
163 }
164
165
166 /**
167 * Get booking ID, from the $_GET['booking_hash'] in url
168 *
169 * @param $booking_hash if default false, then get hash from $_GET['booking_hash'] Otherwise get it from this parameter
170 *
171 * @return int|string ID of ooking resource or '', if not found
172 */
173 function wpbc_get_resource_id__from_hash_in_url( $booking_hash = false ){
174
175 $result_arr = wpbc_get_booking_arr__from_hash_in_url( $booking_hash );
176
177 return $result_arr['resource_id'];
178 }
179
180
181
182 /**
183 * Get booking data ['booking_id' => 2453, 'resource_id' => 4 ], from the URL -- $_GET['booking_hash']
184 *
185 * @param $booking_hash if default false, then get hash from $_REQUEST['booking_hash'] Otherwise get it from this parameter
186 *
187 * @return array if not found then ['booking_id' => '', 'resource_id' => '']
188 * otherwise ['booking_id' => 2453, 'resource_id' => 4 ]
189 */
190 function wpbc_get_booking_arr__from_hash_in_url( $booking_hash = false ){
191
192 if ( empty( $booking_hash ) ) {
193 $booking_hash = ( isset( $_REQUEST['booking_hash'] ) ) ? $_REQUEST['booking_hash'] : '';
194 }
195
196 $booking_id = '';
197 $resource_id = '';
198
199 if ( ! empty( $booking_hash ) ) {
200 $my_booking_id_type = wpbc_hash__get_booking_id__resource_id( $booking_hash );
201
202 if (false !== $my_booking_id_type ){
203 list( $booking_id, $resource_id ) = $my_booking_id_type;
204 }
205 }
206
207 $result = array(
208 'booking_id' => $booking_id,
209 'resource_id' => $resource_id
210 );
211
212 return $result;
213
214 }