/**
* Show Read booking Button
*/
function wpbc_for_booking_template__action_read(){
$booking_action = 'set_booking_as_read';
if ( ! wpbc_is_user_can( $booking_action, wpbc_get_current_user_id() ) ) {
return false;
}
$params = array(
'type' => 'button',
'title' => '',
'hint' => array(
'title' => __( 'New booking', 'booking' ),
'position' => 'top'
),
'link' => 'javascript:void(0)',
'action' => " wpbc_ajx_booking_ajax_action_request( {
'booking_action' : '{$booking_action}',
'booking_id' : {{data['parsed_fields']['booking_id']}}
} );
wpbc_button_enable_loading_icon( this ); ",
'icon' => array(
'icon_font' => 'wpbc_icn_fiber_manual_record',// 'wpbc_icn_visibility',
'position' => 'left',
'icon_img' => ''
),
'class' => 'wpbc_is_new_button',
'style' => '',
'mobile_show_text' => true,
'attr' => array()
);
?><# if ( '1' == data.parsed_fields.is_new ) { #><# } #>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Support functions
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Catch some errors, if such errors exist during our Ajx request
*/
class WPBC_AJAX_ERROR_CATCHING{
public $errors_arr;
function __construct() {
$this->errors_arr = array();
// Catch Error messages
add_action( 'wp_error_added', array( $this, 'wpbc_wp_error_added' ), 10, 4 );
if ( ! defined( 'WPBC_AJAX_ERROR_CATCH' ) ) { define( 'WPBC_AJAX_ERROR_CATCH', true ); } // Check somewhere to not show error messages: if ( ( defined( 'WPBC_AJAX_ERROR_CATCH' ) ) && ( WPBC_AJAX_ERROR_CATCH ) ) { return false; }
}
/**
* Catch Error messages
*
* @param $code
* @param $message
* @param $data
* @param $this_link
*
* @return void
*/
function wpbc_wp_error_added( $code, $message, $data, $this_link ){
$this->errors_arr[] = array(
'code' => $code,
'message' => $message,
'data' => $data,
'this_link' => $this_link
) ;
}
/**
* Get summary of all errors
* @return string
*/
function get_error_messages(){
$error_message = array();
foreach ( $this->errors_arr as $error ) {
$error_message[] = 'Error: ' . $error['code'] . '. ' . $error['message'];
}
$error_message = implode( '
', $error_message );
if ( ! empty( $error_message ) ) {
$error_message = ''
.'
' . esc_html__( 'Some errors were encountered.', 'booking' ) . '
'
. $error_message
. '
';
}
return $error_message;
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Check what user can do
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/**
* Check permission of this user on specific actions, like approving or deleting of bookings
*
* @param string $action like 'set_pnding'
* @param int $user_id like 1
*
* @return bool
*/
function wpbc_is_user_can( $action, $user_id = 0 ){
if ( 0 == $user_id ) {
$user_id = wpbc_get_current_user_id();
}
$user = get_userdata( $user_id );
$user_roles = (array) ( empty( $user ) ? array() : $user->roles ); // Standard WordPress Roles: 'administrator' | 'editor' | 'author' | 'contributor' | 'subscriber'
// Get here list of actions that user can do
switch ( $action ) {
case 'set_booking_pending':
break;
case 'set_booking_approved':
break;
case 'move_booking_to_trash':
break;
case 'restore_booking_from_trash':
break;
case 'delete_booking_completely':
// if ( ! in_array( 'administrator', $user_roles ) ) { return false; }
break;
case 'booking_add_google_calendar':
break;
case 'set_booking_locale':
break;
case 'set_booking_as_read':
break;
case 'set_booking_as_unread':
break;
case 'empty_trash':
break;
case 'set_booking_note':
break;
case 'edit_booking':
break;
case 'change_booking_resource':
break;
case 'duplicate_booking_to_other_resource':
break;
case 'set_payment_status':
break;
case 'set_booking_cost':
break;
case 'send_payment_request':
break;
case 'import_google_calendar':
break;
case 'export_csv':
break;
default:
// Default
}
return true;
}