| 1 |
<?php |
| 2 |
/* |
| 3 |
* @package: AJX_Bookings Page |
| 4 |
* @category: o Email Reminders |
| 5 |
* @description: Define AJX_Bookings in admin settings page. - Sending friendly email reminders based on custom ajx_booking. |
| 6 |
* Plugin URI: https://oplugins.com/plugins/email-reminders/#premium |
| 7 |
* Author URI: https://oplugins.com |
| 8 |
* Author: wpdevelop, oplugins |
| 9 |
* Version: 0.0.1 |
| 10 |
* @modified 2020-05-11 |
| 11 |
*/ |
| 12 |
//FixIn: 9.2.1 |
| 13 |
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly |
| 14 |
|
| 15 |
|
| 16 |
/** Show Content |
| 17 |
* Update Content |
| 18 |
* Define Slug |
| 19 |
* Define where to show |
| 20 |
*/ |
| 21 |
class WPBC_Page_AJX_Bookings extends WPBC_Page_Structure { |
| 22 |
|
| 23 |
// public function __construct() { |
| 24 |
// |
| 25 |
// parent::__construct(); |
| 26 |
// |
| 27 |
// } |
| 28 |
|
| 29 |
public function in_page() { |
| 30 |
return 'wpbc'; |
| 31 |
} |
| 32 |
|
| 33 |
public function tabs() { |
| 34 |
|
| 35 |
$is_full_screen = WPBC_User_Custom_Data_Saver::get_user_data_value( wpbc_get_current_user_id(), 'is_full_screen' ); |
| 36 |
$is_full_screen = ( 'On' === $is_full_screen ); |
| 37 |
|
| 38 |
$tabs = array(); |
| 39 |
$tabs['vm_booking_listing'] = array( |
| 40 |
'is_show_top_path' => true, // true | false. By default value is: true. |
| 41 |
'is_show_top_navigation' => true, // true | false. By default value is: false. |
| 42 |
'left_navigation__default_view_mode' => ( $is_full_screen ) ? 'compact' : 'min', // '' | 'min' | 'compact' | 'max' | 'none'. By default value is: ''. |
| 43 |
'page_title' => false, // Header - Title. If false, than hidden. |
| 44 |
'page_description' => false, // Header - Title Description. If false, than hidden. |
| 45 |
'title' => __( 'Bookings', 'booking' ), // Menu - Title. |
| 46 |
'hint' => __( 'Booking Listing', 'booking' ), // Menu - Mouse Over Hint. |
| 47 |
'font_icon' => 'wpbc-bi-collection', // Menu - Icon. |
| 48 |
'link' => '', // Can be skiped, then generated link based on Page and Tab tags. Or can be extenral link. |
| 49 |
'position' => '', // 'left' | 'right' | '' -- Default is ''. |
| 50 |
'css_classes' => '', // CSS classes. |
| 51 |
'icon' => '', // Icon - link to the real PNG img. |
| 52 |
'default' => false, // Is this tab activated by default or not: true || false. |
| 53 |
'disabled' => false, // Is this tab disabled: true || false. |
| 54 |
'hided' => true, // Is this tab hided: true || false. |
| 55 |
'subtabs' => array(), |
| 56 |
); |
| 57 |
|
| 58 |
// $subtabs = array(); |
| 59 |
// $tabs[ 'items' ][ 'subtabs' ] = $subtabs; |
| 60 |
return $tabs; |
| 61 |
} |
| 62 |
|
| 63 |
public function content() { |
| 64 |
|
| 65 |
do_action( 'wpbc_hook_settings_page_header', 'page_booking_listing' ); // Define Notices Section and show some static messages, if needed. |
| 66 |
|
| 67 |
if ( ! wpbc_is_mu_user_can_be_here( 'activated_user' ) ) { |
| 68 |
return false; // Check if MU user activated, otherwise show Warning message. |
| 69 |
} |
| 70 |
|
| 71 |
// ------------------------------------------------------------------------------------------------------------- |
| 72 |
// Get and escape request parameters |
| 73 |
// ------------------------------------------------------------------------------------------------------------- |
| 74 |
$user_request = new WPBC_AJX__REQUEST( |
| 75 |
array( |
| 76 |
'db_option_name' => 'booking_listing_request_params', |
| 77 |
'user_id' => wpbc_get_current_user_id(), |
| 78 |
'request_rules_structure' => wpbc_ajx_get__request_params__names_default(), |
| 79 |
) |
| 80 |
); |
| 81 |
|
| 82 |
$escaped_search_request_params = false; |
| 83 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 84 |
if ( empty( $_REQUEST['overwrite'] ) ) { |
| 85 |
$escaped_search_request_params = $user_request->get_sanitized__saved__user_request_params(); // Get Saved. |
| 86 |
} |
| 87 |
|
| 88 |
// phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing |
| 89 |
if ( ( false === $escaped_search_request_params ) || ( ! empty( $_REQUEST['overwrite'] ) ) ) { |
| 90 |
// This request was not saved before, then get sanitized direct parameters, like: $_REQUEST['resource_id']. |
| 91 |
$request_prefix = false; |
| 92 |
$escaped_search_request_params = $user_request->get_sanitized__in_request__value_or_default( $request_prefix ); // Direct request: $_REQUEST['resource_id'] //. |
| 93 |
} |
| 94 |
|
| 95 |
// ------------------------------------------------------------------------------------------------------------- |
| 96 |
|
| 97 |
|
| 98 |
// Submit. |
| 99 |
$submit_form_name = 'wpbc_ajx_booking_form'; // Define form name. |
| 100 |
|
| 101 |
?><span class="wpdevelop"><?php // BS UI CSS Class. |
| 102 |
|
| 103 |
wpbc_js_for_bookings_page(); // JavaScript functions. |
| 104 |
|
| 105 |
wpbc_ajx_bookings_toolbar( $escaped_search_request_params ); |
| 106 |
|
| 107 |
?></span><?php // BS UI CSS Class. |
| 108 |
|
| 109 |
// TODO: continue here with this new toolbar |
| 110 |
// wpbc_ui__toolbar__bo_listing( $escaped_search_request_params ); |
| 111 |
|
| 112 |
?><div id="wpbc_log_screen" class="wpbc_log_screen"></div><?php |
| 113 |
|
| 114 |
// Content ----------------------------------------------------------------------------------------------------. |
| 115 |
?> |
| 116 |
<div class="clear" style="margin-bottom:10px;"></div> |
| 117 |
<span class="metabox-holder"> |
| 118 |
<form style="min-height:459px;" name="<?php echo esc_attr( $submit_form_name ); ?>" id="<?php echo esc_attr( $submit_form_name ); ?>" action="" method="post"> |
| 119 |
<div class="wpbc_ajx_trigger_hooks"></div> |
| 120 |
<?php |
| 121 |
|
| 122 |
// N o n c e field, and key for checking S u b m i t. |
| 123 |
wp_nonce_field( 'wpbc_settings_page_' . $submit_form_name ); |
| 124 |
?><input type="hidden" name="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" id="is_form_sbmitted_<?php echo esc_attr( $submit_form_name ); ?>" value="1"/><?php |
| 125 |
|
| 126 |
// wpbc_ajx_booking_modify_container_show(); // Container for showing Edit ajx_booking and define Edit and Delete ajx_booking JavaScript vars. |
| 127 |
|
| 128 |
$is_test_sql_directly = false; |
| 129 |
if ( ! $is_test_sql_directly ) { |
| 130 |
|
| 131 |
$this->show_ajx_booking_listing_container_ajax( $escaped_search_request_params ); |
| 132 |
|
| 133 |
$this->show_pagination_container(); |
| 134 |
|
| 135 |
} else { |
| 136 |
$this->show_ajx_booking_listing_container_directly(); // Useful for direct showing of listing without the ajax request, its requirement JavaScript to show data in template!. |
| 137 |
} |
| 138 |
|
| 139 |
?><div class="clear"></div><?php |
| 140 |
|
| 141 |
?> |
| 142 |
</form> |
| 143 |
</span> |
| 144 |
<?php |
| 145 |
|
| 146 |
do_action( 'wpbc_hook_settings_page_footer', 'wpbc-ajx_booking' ); |
| 147 |
|
| 148 |
wpbc_welcome_panel(); // Welcome Panel (links). |
| 149 |
|
| 150 |
// == Hidden Templates for - Booking Actions == |
| 151 |
do_action( 'wpbc_hook_booking_template__hidden_templates' ); |
| 152 |
|
| 153 |
wpbc_show_booking_footer(); // Show rating line. |
| 154 |
} |
| 155 |
|
| 156 |
private function show_pagination_container(){ |
| 157 |
?> |
| 158 |
<div class="wpbc_ajx_booking_pagination"></div> |
| 159 |
<?php |
| 160 |
wpbc_clear_div(); |
| 161 |
|
| 162 |
$wpbc_pagination = new WPBC_Pagination(); |
| 163 |
$wpbc_pagination->init( array( |
| 164 |
'load_on_page' => 'wpbc-ajx_booking', |
| 165 |
'container_header' => '.wpbc_ajx_booking_pagination_header', |
| 166 |
'container_footer' => '.wpbc_ajx_booking_pagination_footer', |
| 167 |
'container' => '.wpbc_ajx_booking_pagination', |
| 168 |
'on_click' => 'wpbc_ajx_booking_pagination_click' // onclick = "javascript: wpbc_ajx_booking_pagination_click( page_num );" - need to define this function in JS file |
| 169 |
)); |
| 170 |
|
| 171 |
/** |
| 172 |
$wpbc_pagination->show( array( // Its showing with JavaScript on document ready |
| 173 |
'page_active' => 3, |
| 174 |
'pages_count' => 20 |
| 175 |
)); |
| 176 |
/**/ |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
private function show_ajx_booking_listing_container_ajax( $escaped_search_request_params ) { |
| 181 |
|
| 182 |
if ( class_exists( 'WPBC_AJX_Bookings' ) ) { |
| 183 |
WPBC_AJX_Bookings::enqueue_js_files_now(); |
| 184 |
} |
| 185 |
|
| 186 |
?> |
| 187 |
<div class="wpbc__wrap__booking_listing"> |
| 188 |
<div class="wpbc__list__table wpbc_selectable_table"> |
| 189 |
<?php $this->spins_loading_container(); ?> |
| 190 |
</div> |
| 191 |
</div> |
| 192 |
<script type="text/javascript"> |
| 193 |
jQuery(document).ready(function () { |
| 194 |
|
| 195 |
var wpbc_booking_listing_wait_counter = 0; |
| 196 |
var wpbc_booking_listing_wait_timer = setInterval( function() { |
| 197 |
|
| 198 |
wpbc_booking_listing_wait_counter++; |
| 199 |
|
| 200 |
if ( |
| 201 |
'undefined' === typeof wpbc_ajx_booking_listing |
| 202 |
|| 'function' !== typeof wpbc_ajx_booking_listing.set_secure_param |
| 203 |
|| 'function' !== typeof wpbc_ajx_booking_send_search_request_with_params |
| 204 |
) { |
| 205 |
if ( wpbc_booking_listing_wait_counter > 20 ) { |
| 206 |
clearInterval( wpbc_booking_listing_wait_timer ); |
| 207 |
} |
| 208 |
return; |
| 209 |
} |
| 210 |
|
| 211 |
clearInterval( wpbc_booking_listing_wait_timer ); |
| 212 |
|
| 213 |
// Set Security - Nonce for Ajax - Listing |
| 214 |
wpbc_ajx_booking_listing.set_secure_param( 'nonce', '<?php echo esc_attr( wp_create_nonce( 'wpbc_ajx_booking_listing_ajx' . '_wpbcnonce' ) ); ?>' ); |
| 215 |
wpbc_ajx_booking_listing.set_secure_param( 'user_id', '<?php echo esc_attr( wpbc_get_current_user_id() ); ?>' ); |
| 216 |
wpbc_ajx_booking_listing.set_secure_param( 'locale', '<?php echo esc_attr( get_user_locale() ); ?>' ); |
| 217 |
|
| 218 |
// Set other parameters |
| 219 |
wpbc_ajx_booking_listing.set_other_param( 'listing_container', '.wpbc__list__table' ); |
| 220 |
|
| 221 |
wpbc_ajx_booking_listing.set_other_param( 'pagination_container', '.wpbc_ajx_booking_pagination' ); |
| 222 |
wpbc_ajx_booking_listing.set_other_param( 'pagination_container_header', '.wpbc_ajx_booking_pagination_header' ); |
| 223 |
wpbc_ajx_booking_listing.set_other_param( 'pagination_container_footer', '.wpbc_ajx_booking_pagination_footer' ); |
| 224 |
|
| 225 |
// Send Ajax request and show listing after this. |
| 226 |
wpbc_ajx_booking_send_search_request_with_params( <?php echo wp_json_encode( $escaped_search_request_params ); ?> ); |
| 227 |
}, 100 ); |
| 228 |
}); |
| 229 |
</script> |
| 230 |
<?php |
| 231 |
} |
| 232 |
|
| 233 |
|
| 234 |
/** |
| 235 |
* Show Spin Loading container. |
| 236 |
* |
| 237 |
* @return void |
| 238 |
*/ |
| 239 |
private function spins_loading_container() { |
| 240 |
?> |
| 241 |
<div class="wpbc_spins_loading_container"> |
| 242 |
<div class="wpbc_booking_form_spin_loader"> |
| 243 |
<div class="wpbc_spins_loader_wrapper"> |
| 244 |
<div class="wpbc_spin_loader_one_new"></div> |
| 245 |
</div> |
| 246 |
</div> |
| 247 |
<span> |
| 248 |
<?php |
| 249 |
esc_html_e( 'Loading', 'booking' ); |
| 250 |
echo ' ...'; |
| 251 |
?> |
| 252 |
</span> |
| 253 |
</div> |
| 254 |
<?php |
| 255 |
} |
| 256 |
|
| 257 |
|
| 258 |
private function show_ajx_booking_listing_container_directly(){ |
| 259 |
|
| 260 |
|
| 261 |
//TODO: We need to send Ajax request and then show the listing (its will make one same way of showing listing and pagination)! |
| 262 |
|
| 263 |
|
| 264 |
$my_ajx_booking = new WPBC_AJX_Bookings; |
| 265 |
|
| 266 |
//////////////////////////////////// |
| 267 |
// 0. Check Nonce if Ajax ( ! used now ) |
| 268 |
//////////////////////////////////// |
| 269 |
if ( 0 ){ |
| 270 |
$action_name = 'wpbc_search_field' . '_wpbcnonce'; // $_POST['element_id'] . '_wpbcnonce'; |
| 271 |
$nonce_post_key = 'nonce'; |
| 272 |
$result_check = check_ajax_referer( $action_name, $nonce_post_key ); |
| 273 |
} |
| 274 |
|
| 275 |
//////////////////////////////////// |
| 276 |
// 1. Direct Clean Params |
| 277 |
//////////////////////////////////// |
| 278 |
$request_params_ajx_booking = array( |
| 279 |
'page_num' => array( 'validate' => 'd', 'default' => 1 ) |
| 280 |
, 'page_items_count' => array( 'validate' => 'd', 'default' => 10 ) |
| 281 |
, 'sort' => array( 'validate' => array( 'booking_id' ), 'default' => 'booking_id' ) |
| 282 |
, 'sort_type' => array( 'validate' => array( 'ASC', 'DESC'),'default' => 'DESC' ) |
| 283 |
, 'status' => array( 'validate' => 's', 'default' => '' ) |
| 284 |
, 'keyword' => array( 'validate' => 's', 'default' => '' ) |
| 285 |
, 'ru_create_date' => array( 'validate' => 'date', 'default' => '' ) |
| 286 |
); |
| 287 |
$request_params_values = array( // Usually $request_params_values is $_REQUEST |
| 288 |
'page_num' => 1, |
| 289 |
'page_items_count' => 3, |
| 290 |
'sort' => 'booking_id', |
| 291 |
'sort_type' => 'DESC', |
| 292 |
'status' => '', |
| 293 |
'keyword' => '', |
| 294 |
'ru_create_date' => '' |
| 295 |
); |
| 296 |
$request_params = wpbc_sanitize_params_in_arr( $request_params_values, $request_params_ajx_booking ); |
| 297 |
|
| 298 |
//////////////////////////////////// |
| 299 |
// 2. Get items array from DB |
| 300 |
//////////////////////////////////// |
| 301 |
$items_arr = wpbc_ajx_get_booking_data_arr( $request_params ); |
| 302 |
debuge($items_arr); |
| 303 |
|
| 304 |
// Show Pagination - $total_num_of_items_in_all_pages = $sql_res[ [ 'count' ] ]; |
| 305 |
// $wpbc_pagination->show_pagination( |
| 306 |
// $request_params_values['page_num'], |
| 307 |
// ceil( $sql_res[ [ 'count' ] ] / $request_params_values['page_items_count'] ) |
| 308 |
// ); |
| 309 |
|
| 310 |
} |
| 311 |
|
| 312 |
} |
| 313 |
|
| 314 |
add_action( 'wpbc_menu_created', array( new WPBC_Page_AJX_Bookings(), '__construct' ) ); // Executed after creation of Menu. |
| 315 |
|