Posted on : 2024-12-14 06:14:30 View Type: public
Frazer Xavier

Hi,
There are warnings showing on Job page. Need help in fixing it. I am on PHP 8.2. Screenshot is below.
Hi,
There are warnings showing on Job page. Need help in fixing it. I am on PHP 8.2. Screenshot is below.
Please update the file inside computer-repair-shop >> lib >> includes >> classes >> class-devices.php
If you don't know how to do this you may leave your WP logins otherwise kindly wait for the update thanks.
<?php
/**
* The file contains the functions related to Shortcode Pages
*
* Help setup pages to they can be used in notifications and other items
*
* @package computer-repair-shop
* @version 3.7947
*/
defined( 'ABSPATH' ) || exit;
class WCRB_MANAGE_DEVICES {
function __construct() {
add_action( 'wc_rb_settings_tab_menu_item', array( $this, 'add_devices_tab_in_settings_menu' ), 10, 2 );
add_action( 'wc_rb_settings_tab_body', array( $this, 'add_devices_tab_in_settings_body' ), 10, 2 );
add_action( 'wp_ajax_wc_rb_update_device_settings', array( $this, 'wc_rb_update_device_settings' ) );
add_action( 'wp_ajax_wc_add_device_for_manufacture', array( $this, 'wc_add_device_for_manufacture' ) );
add_action( 'wp_ajax_wc_add_device_row', array( $this, 'wc_add_device_row' ) );
}
function add_devices_tab_in_settings_menu() {
$active = '';
$menu_output = '<li class="tabs-title' . esc_attr($active) . '" role="presentation">';
$menu_output .= '<a href="#wc_rb_manage_devices" role="tab" aria-controls="wc_rb_manage_devices" aria-selected="true" id="wc_rb_manage_devices-label">';
$menu_output .= '<h2>' . esc_html__( 'Devices & Brands', 'computer-repair-shop' ) . '</h2>';
$menu_output .= '</a>';
$menu_output .= '</li>';
echo wp_kses_post( $menu_output );
}
function add_devices_tab_in_settings_body() {
global $wpdb;
$active = '';
$wc_note_label = ( empty( get_option( 'wc_note_label' ) ) ) ? esc_html__( 'Note', 'computer-repair-shop' ) : get_option( 'wc_note_label' );
$wc_pin_code_label = ( empty( get_option( 'wc_pin_code_label' ) ) ) ? esc_html__( 'Pin Code/Password', 'computer-repair-shop' ) : get_option( 'wc_pin_code_label' );
$wc_device_label = ( empty( get_option( 'wc_device_label' ) ) ) ? esc_html__( 'Device', 'computer-repair-shop' ) : get_option( 'wc_device_label' );
$wc_device_brand_label = ( empty( get_option( 'wc_device_brand_label' ) ) ) ? esc_html__( 'Device Brand', 'computer-repair-shop' ) : get_option( 'wc_device_brand_label' );
$wc_device_label_plural = ( empty( get_option( 'wc_device_label_plural' ) ) ) ? esc_html__( 'Devices', 'computer-repair-shop' ) : get_option( 'wc_device_label_plural' );
$wc_device_type_label = ( empty( get_option( 'wc_device_type_label' ) ) ) ? esc_html__( 'Device Type', 'computer-repair-shop' ) : get_option( 'wc_device_type_label' );
$wc_device_type_label_plural = ( empty( get_option( 'wc_device_type_label_plural' ) ) ) ? esc_html__( 'Device Type', 'computer-repair-shop' ) : get_option( 'wc_device_type_label_plural' );
$wc_device_brand_label_plural = ( empty( get_option( 'wc_device_brand_label_plural' ) ) ) ? esc_html__( 'Device Brands', 'computer-repair-shop' ) : get_option( 'wc_device_brand_label_plural' );
$wc_device_id_imei_label = ( empty( get_option( 'wc_device_id_imei_label' ) ) ) ? esc_html__( 'ID/IMEI', 'computer-repair-shop' ) : get_option( 'wc_device_id_imei_label' );
$wc_pin_code_field = get_option( 'wc_pin_code_field' );
$wcpincodefield = ( $wc_pin_code_field == 'on' ) ? 'checked="checked"' : '';
$wc_pin_code_show_inv = get_option( 'wc_pin_code_show_inv' );
$wcpincodeshowinvoice = ( $wc_pin_code_show_inv == 'on' ) ? 'checked="checked"' : '';
//If offer Pick and Delivery.
$wc_offer_pick_deli = get_option( 'wc_offer_pick_deli' );
$instruct = ( $wc_offer_pick_deli == 'on' ) ? 'checked="checked"' : '';
$offer_laptop_one = get_option( 'wc_one_day' );
$offer_laptop_week = get_option( 'wc_one_week' );
$wc_offer_laptop = get_option( 'wc_offer_laptop' );
$offer_laptop = ( $wc_offer_laptop == 'on' ) ? 'checked="checked"' : '';
$pick_deliver_charg = get_option('wc_pick_delivery_charges');
$setting_body = '<div class="tabs-panel team-wrap' . esc_attr($active) . '"
id="wc_rb_manage_devices"
role="tabpanel"
aria-hidden="true"
aria-labelledby="wc_rb_manage_devices-label">';
$setting_body .= '<div class="wc-rb-manage-devices">';
$setting_body .= '<h2>' . esc_html__( 'Brands & Devices', 'computer-repair-shop' ) . '</h2>';
$setting_body .= '<div class="devices_success_msg"></div>';
$setting_body .= '<form data-async data-abide class="needs-validation" novalidate method="post" data-success-class=".devices_success_msg">';
$setting_body .= '<table class="form-table border"><tbody>';
$setting_body .= '<tr><th scope="row"><label for="wc_pin_code_field">' . esc_html__( 'Enable Pin Code Field in Jobs page', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input type="checkbox" ' . esc_html( $wcpincodefield ) . ' name="wc_pin_code_field" id="wc_pin_code_field" /></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="wc_pin_code_show_inv">' . esc_html__( 'Show Pin Code in Invoices/Emails/Status Check', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input type="checkbox" ' . esc_html( $wcpincodeshowinvoice ) . ' name="wc_pin_code_show_inv" id="wc_pin_code_show_inv" /></td></tr>';
if ( rb_is_woocommerce_activated() == TRUE ) {
$wcrbreplacedevices_f = get_option( 'wc_enable_devices_as_woo_products' );
$wcrbreplacedevices = ( $wcrbreplacedevices_f == 'on' ) ? 'checked="checked"' : '';
$setting_body .= '<tr>
<th scope="row">
<label for="wc_enable_devices_as_woo_products">' . esc_html__( 'Replace devices & brands with WooCommerce products', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input type="checkbox" ' . esc_html( $wcrbreplacedevices ) . ' name="wc_enable_devices_as_woo_products" id="wc_enable_devices_as_woo_products" /></td></tr>';
}
$setting_body .= '<tr>';
$setting_body .= '<th scope="row"><label for="wc_note_label">' . esc_html__( 'Other Labels', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><table class="form-table no-padding-table"><tr>';
$setting_body .= '<td><label>' . esc_html__( 'Note label like Device Note', 'computer-repair-shop' );
$setting_body .= '<input name="wc_note_label" id="wc_note_label" class="regular-text" value="' . esc_html( $wc_note_label ) . '" type="text"
placeholder="' . esc_html__( 'Note', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '<td><label>' . esc_html__( 'Pin Code/Password Label', 'computer-repair-shop' ) . '<input name="wc_pin_code_label" id="wc_pin_code_label" class="regular-text"
value="' . esc_html( $wc_pin_code_label ) . '" type="text" placeholder="' . esc_html__( 'Pin Code/Password', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '</tr></table></td></tr>';
$setting_body .= '<tr>';
$setting_body .= '<th scope="row"><label for="wc_device_label">' . esc_html__( 'Device Label', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><table class="form-table no-padding-table"><tr>';
$setting_body .= '<td><label>' . esc_html__( 'Singular device label', 'computer-repair-shop' );
$setting_body .= '<input name="wc_device_label" id="wc_device_label" class="regular-text" value="' . esc_html( $wc_device_label ) . '" type="text"
placeholder="' . esc_html__( 'Device', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '<td><label>' . esc_html__( 'Plural device label', 'computer-repair-shop' ) . '<input name="wc_device_label_plural" id="wc_device_label_plural" class="regular-text"
value="' . esc_html( $wc_device_label_plural ) . '" type="text" placeholder="' . esc_html__( 'Devices', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '</tr></table></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="wc_device_brand_label">' . esc_html__( 'Device Brand Label', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><table class="form-table no-padding-table"><tr><td><label>' . esc_html__( 'Singular device brand label', 'computer-repair-shop' );
$setting_body .= '<input name="wc_device_brand_label" id="wc_device_brand_label" class="regular-text" value="' . esc_html( $wc_device_brand_label ) . '" type="text"
placeholder="' . esc_html__( 'Device Brand', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '<td><label>' . esc_html__( 'Plural device brand label', 'computer-repair-shop' );
$setting_body .= '<input name="wc_device_brand_label_plural" id="wc_device_brand_label_plural" class="regular-text" value="' . esc_html( $wc_device_brand_label_plural ) . '"
type="text" placeholder="' . esc_html__( 'Device Brands', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '</tr></table></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="wc_device_type_label">' . esc_html__( 'Device Type Label', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><table class="form-table no-padding-table"><tr><td><label>' . esc_html__( 'Singular device type label', 'computer-repair-shop' );
$setting_body .= '<input name="wc_device_type_label" id="wc_device_type_label" class="regular-text" value="' . esc_html( $wc_device_type_label ) . '" type="text"
placeholder="' . esc_html__( 'Device Type', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '<td><label>' . esc_html__( 'Plural device type label', 'computer-repair-shop' );
$setting_body .= '<input name="wc_device_type_label_plural" id="wc_device_type_label_plural" class="regular-text" value="' . esc_html( $wc_device_type_label_plural ) . '"
type="text" placeholder="' . esc_html__( 'Device Types', 'computer-repair-shop' ) . '" /></label></td>';
$setting_body .= '</tr></table></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="wc_device_id_imei_label">' . esc_html__( 'ID/IMEI Label', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input name="wc_device_id_imei_label" id="wc_device_id_imei_label" class="regular-text" value="' . esc_html( $wc_device_id_imei_label ) . '" type="text"
placeholder="' . esc_html__( 'ID/IMEI', 'computer-repair-shop' ) . '" /></td></tr></tbody></table>';
//Start of Additional Fields Devices
$setting_body .= '<div class="wc-rb-payment-methods">
<h2>'. esc_html__( 'Additional device fields', 'computer-repair-shop' ) .'</h2>';
$setting_body .= '<div class="wcrb_additional_device_fields_wrap clearfix">';
$extra_device_fields = get_option( '_extra_device_fields' );
if ( is_array( $extra_device_fields ) && ! empty( $extra_device_fields ) ) {
if ( ! wc_rs_license_state() ) :
$setting_body .= '<div class="callout success">'. esc_html__( 'Pro feature! Plugin activation required.', 'computer-repair-shop' ) .'</div>';
endif;
$setting_body .= '<table class="form-table border"><tbody>';
$counter = 0;
foreach( $extra_device_fields as $extra_device_field ) {
$class = ( $counter == 0 ) ? 'wcrb_original wcrb_repater_field' : 'wcrb_repater_field';
$delop = ( $counter == 0 ) ? '' : '<a class="delme delmedeviceextrafield" href="#" title="Remove row"><span class="dashicons dashicons-trash"></span></a>';
$rb_device_field_label = ( isset( $extra_device_field['rb_device_field_label'] ) && ! empty( $extra_device_field['rb_device_field_label'] ) ) ? $extra_device_field['rb_device_field_label'] : '';
$rb_device_field_type = ( isset( $extra_device_field['rb_device_field_type'] ) && ! empty( $extra_device_field['rb_device_field_type'] ) ) ? $extra_device_field['rb_device_field_type'] : '';
$rb_device_field_display_booking_form = ( isset( $extra_device_field['rb_device_field_display_booking_form'] ) && ! empty( $extra_device_field['rb_device_field_display_booking_form'] ) ) ? $extra_device_field['rb_device_field_display_booking_form'] : '';
$rb_device_field_display_in_invoice = ( isset( $extra_device_field['rb_device_field_display_in_invoice'] ) && ! empty( $extra_device_field['rb_device_field_display_in_invoice'] ) ) ? $extra_device_field['rb_device_field_display_in_invoice'] : '';
$rb_device_field_display_for_customer = ( isset( $extra_device_field['rb_device_field_display_for_customer'] ) && ! empty( $extra_device_field['rb_device_field_display_for_customer'] ) ) ? $extra_device_field['rb_device_field_display_for_customer'] : '';
$rb_device_field_id = ( isset( $extra_device_field['rb_device_field_id'] ) && ! empty( $extra_device_field['rb_device_field_id'] ) ) ? $extra_device_field['rb_device_field_id'] : '';
$setting_body .= '<tr class="'. esc_attr( $class ) .'">
<td class="wc_device_name">'. $delop .'
<label>'. esc_html__( 'Field label', 'computer-repair-shop' ) .'<input class="regular-text" name="rb_device_field_label[]" value="'. esc_html( $rb_device_field_label ) .'" type="text"></label></td>
<td><label>'. esc_html__( 'Type', 'computer-repair-shop' ) .'<select name="rb_device_field_type[]"><option value="text">' . esc_html__( 'Text', 'computer-repair-shop' ) . '</option></select></label></td>';
$booking_form_yes = ( $rb_device_field_display_booking_form == 'yes' ) ? ' selected' : '';
$booking_form_no = ( $rb_device_field_display_booking_form == 'no' ) ? ' selected' : '';
$setting_body .= '<td><label>'. esc_html__( 'In booking form?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_booking_form[]">
<option '. esc_attr( $booking_form_yes ) .' value="yes">' . esc_html__( 'Display', 'computer-repair-shop' ) . '</option>
<option '. esc_attr( $booking_form_no ) .' value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label></td>';
$ininvoice_yes = ( $rb_device_field_display_in_invoice == 'yes' ) ? ' selected' : '';
$ininvoice_no = ( $rb_device_field_display_in_invoice == 'no' ) ? ' selected' : '';
$setting_body .= '<td><label>'. esc_html__( 'In invoice?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_in_invoice[]">
<option '. esc_attr( $ininvoice_yes ) .' value="yes">' . esc_html__( 'Display', 'computer-repair-shop' ) . '</option>
<option '. esc_attr( $ininvoice_no ) .' value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label></td>';
$customerout_yes = ( $rb_device_field_display_for_customer == 'yes' ) ? ' selected' : '';
$customerout_no = ( $rb_device_field_display_for_customer == 'no' ) ? ' selected' : '';
$setting_body .= '<td><label>'. esc_html__( 'In customer output?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_for_customer[]">
<option '. esc_attr( $customerout_yes ) .' value="yes">' . esc_html__( 'Display in Status check, my account, emails', 'computer-repair-shop' ) . '</option>
<option '. esc_attr( $customerout_no ) .' value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label>';
$setting_body .= '<input type="hidden" name="rb_device_field_id[]" value="'. esc_html( $rb_device_field_id ) .'" />
</td>
</tr>';
$counter++;
}
$setting_body .= '</tbody></table>';
} else {
$setting_body .= '<table class="form-table border"><tbody>';
$setting_body .= '<tr class="wcrb_original wcrb_repater_field">
<td class="wc_device_name">
<label>'. esc_html__( 'Field label', 'computer-repair-shop' ) .'<input class="regular-text" name="rb_device_field_label[]" type="text"></label></td>
<td><label>'. esc_html__( 'Type', 'computer-repair-shop' ) .'<select name="rb_device_field_type[]"><option value="text">' . esc_html__( 'Text', 'computer-repair-shop' ) . '</option></select></label></td>
<td><label>'. esc_html__( 'In booking form?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_booking_form[]"><option value="yes">' . esc_html__( 'Display', 'computer-repair-shop' ) . '</option><option value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label></td>
<td><label>'. esc_html__( 'In invoice?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_in_invoice[]"><option value="yes">' . esc_html__( 'Display', 'computer-repair-shop' ) . '</option><option value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label></td>
<td><label>'. esc_html__( 'In customer output?', 'computer-repair-shop' ) .'<select name="rb_device_field_display_for_customer[]"><option value="yes">' . esc_html__( 'Display in Status check, my account, emails', 'computer-repair-shop' ) . '</option><option value="no">' . esc_html__( 'Hide', 'computer-repair-shop' ) . '</option></select></label>
<input type="hidden" name="rb_device_field_id[]" value="" />
</td>
</tr>';
$setting_body .= '</tbody></table>';
}
$setting_body .= '<a href="#" class="button-primary alignright adddeviceextrafield">'. esc_html__( 'Add device field', 'computer-repair-shop' ) .'</a>';
$setting_body .= '</div></div>';
//End of Additional Fields Devices
$setting_body .= '<table class="form-table border"><tbody><tr><th scope="row"><label for="offer_pic_de">' . esc_html__( 'Offer pickup and delivery?', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input type="checkbox" ' . esc_html( $instruct ) . ' name="offer_pic_de" id="offer_pic_de" /></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="pick_deliver">' . esc_html__( 'Pick up and delivery charges', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input name="pick_deliver" id="pick_deliver" class="regular-text wc_validate_number" value="' . esc_html( $pick_deliver_charg ) . '" type="text"
placeholder="' . esc_html__( 'Enter the Pick up and delivery charges here', 'computer-repair-shop' ) . '"/></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="offer_laptop">' . esc_html__( 'Offer device rental?', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><input type="checkbox" ' . esc_html( $offer_laptop ) . ' name="offer_laptop" id="offer_laptop" /></td></tr>';
$setting_body .= '<tr><th scope="row"><label for="offer_laptop_one">' . esc_html__( 'Device rent', 'computer-repair-shop' ) . '</label></th>';
$setting_body .= '<td><table class="form-table no-padding-table"><tr><td><label>' . esc_html__( 'Device rent per day', 'computer-repair-shop' );
$setting_body .= '<input name="offer_laptop_one" id="offer_laptop_one" class="regular-text wc_validate_number" value="' . esc_html( $offer_laptop_one ) . '" type="text"
placeholder="' . esc_html__( 'Enter the device rent for one day', 'computer-repair-shop' ) . '"/></label></td>';
$setting_body .= '<td><label>' . esc_html__( 'Device rent per week', 'computer-repair-shop' );
$setting_body .= '<input name="offer_laptop_week" id="offer_laptop_week" class="regular-text wc_validate_number" value="' . esc_html( $offer_laptop_week ) . '" type="text"
placeholder="' . esc_html__( 'Enter the Device rent for one week', 'computer-repair-shop' ) . '"/></label></td></tr></table></td></tr>';
$setting_body .= '</tbody></table>';
$setting_body .= '<input type="hidden" name="form_type" value="wc_rb_update_sett_devices_brands" />';
$setting_body .= wp_nonce_field( 'wcrb_nonce_setting_payment', 'wcrb_nonce_setting_payment_field', true, false );
$setting_body .= '<button type="submit" class="button button-primary" data-type="rbssubmitdevices">' . esc_html__( 'Update Options', 'computer-repair-shop' ) . '</button></form>';
$setting_body .= '</div><!-- wc rb Devices /-->';
$setting_body .= '</div><!-- Tabs Panel /-->';
$allowedHTML = ( function_exists( 'wc_return_allowed_tags' ) ) ? wc_return_allowed_tags() : '';
echo wp_kses( $setting_body, $allowedHTML );
}
function wc_rb_update_device_settings() {
$message = '';
$success = 'NO';
if ( ! isset( $_POST['wcrb_nonce_setting_payment_field'] ) || ! wp_verify_nonce( $_POST['wcrb_nonce_setting_payment_field'], 'wcrb_nonce_setting_payment' ) ) {
$message = esc_html__( 'Couldn\'t verify nonce please reload page.', 'computer-repair-shop' );
} else {
// process form data
if ( rb_is_woocommerce_activated() ) {
$wc_enable_devices_as_woo_products = ( ! isset( $_POST['wc_enable_devices_as_woo_products'] ) ) ? '' : sanitize_text_field( $_POST['wc_enable_devices_as_woo_products'] );
update_option( 'wc_enable_devices_as_woo_products', $wc_enable_devices_as_woo_products );
}
$wc_note_label = ( ! isset( $_POST['wc_note_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_note_label'] );
$wc_pin_code_label = ( ! isset( $_POST['wc_pin_code_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_pin_code_label'] );
$wc_device_label = ( ! isset( $_POST['wc_device_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_label'] );
$wc_device_brand_label = ( ! isset( $_POST['wc_device_brand_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_brand_label'] );
$wc_device_id_imei_label = ( ! isset( $_POST['wc_device_id_imei_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_id_imei_label'] );
$wc_device_label_plural = ( ! isset( $_POST['wc_device_label_plural'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_label_plural'] );
$wc_device_brand_label_plural = ( ! isset( $_POST['wc_device_brand_label_plural'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_brand_label_plural'] );
$wc_device_type_label = ( ! isset( $_POST['wc_device_type_label'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_type_label'] );
$wc_device_type_label_plural = ( ! isset( $_POST['wc_device_type_label_plural'] ) ) ? '' : sanitize_text_field( $_POST['wc_device_type_label_plural'] );
$wc_pin_code_field = ( ! isset( $_POST['wc_pin_code_field'] ) ) ? '' : sanitize_text_field( $_POST['wc_pin_code_field'] );
$wc_pin_code_show_inv = ( ! isset( $_POST['wc_pin_code_show_inv'] ) ) ? '' : sanitize_text_field( $_POST['wc_pin_code_show_inv'] );
$pick_deliver = (!isset($_POST['pick_deliver'])) ? "" : sanitize_text_field($_POST['pick_deliver']);
$offer_laptop = (!isset($_POST['offer_laptop'])) ? "" : sanitize_text_field($_POST['offer_laptop']);
$offer_laptop_one = (!isset($_POST['offer_laptop_one'])) ? "" : sanitize_text_field($_POST['offer_laptop_one']);
$offer_laptop_week = (!isset($_POST['offer_laptop_week'])) ? "" : sanitize_text_field($_POST['offer_laptop_week']);
$offer_pic_de = (!isset($_POST['offer_pic_de'])) ? "" : sanitize_text_field($_POST['offer_pic_de']);
//Process Extra Device fields.
$device_extra_options = array();
for ( $i = 0; $i < count( $_POST["rb_device_field_label"] ); $i++ ) {
$rb_device_field_id = ( isset( $_POST["rb_device_field_id"][$i] ) && ! empty( $_POST["rb_device_field_id"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_id"][$i] ) : wcrb_get_random_unique_username( 'device_field_' );
$rb_device_field_label = ( isset( $_POST["rb_device_field_label"][$i] ) && ! empty( $_POST["rb_device_field_label"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_label"][$i] ) : '';
$rb_device_field_type = ( isset( $_POST["rb_device_field_type"][$i] ) && ! empty( $_POST["rb_device_field_type"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_type"][$i] ) : '';
$rb_device_field_display_booking_form = ( isset( $_POST["rb_device_field_display_booking_form"][$i] ) && ! empty( $_POST["rb_device_field_display_booking_form"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_display_booking_form"][$i] ) : '';
$rb_device_field_display_in_invoice = ( isset( $_POST["rb_device_field_display_in_invoice"][$i] ) && ! empty( $_POST["rb_device_field_display_in_invoice"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_display_in_invoice"][$i] ) : '';
$rb_device_field_display_for_customer = ( isset( $_POST["rb_device_field_display_for_customer"][$i] ) && ! empty( $_POST["rb_device_field_display_for_customer"][$i] ) ) ? sanitize_text_field( $_POST["rb_device_field_display_for_customer"][$i] ) : '';
if ( ! empty( $rb_device_field_label ) ) :
$device_extra_options[] = array(
'rb_device_field_id' => esc_html( $rb_device_field_id ),
'rb_device_field_label' => esc_html( $rb_device_field_label ),
'rb_device_field_type' => esc_html( $rb_device_field_type ),
'rb_device_field_display_booking_form' => esc_html( $rb_device_field_display_booking_form ),
'rb_device_field_display_in_invoice' => esc_html( $rb_device_field_display_in_invoice ),
'rb_device_field_display_for_customer' => esc_html( $rb_device_field_display_for_customer )
);
endif;
}
update_option( '_extra_device_fields', $device_extra_options );
update_option('wc_offer_pick_deli', $offer_pic_de);//Processing offer_pic_de checkbox.
update_option('wc_one_day', $offer_laptop_one);//Processing offer_laptop for one day input box.
update_option('wc_one_week', $offer_laptop_week);//Processing offer_laptop for one week input box.
update_option('wc_offer_laptop', $offer_laptop);//Processing offer_laptop checkbox.
update_option('wc_pick_delivery_charges', $pick_deliver); //Processing pickup and delivery charges.
update_option( 'wc_device_label', $wc_device_label );
update_option( 'wc_device_brand_label', $wc_device_brand_label );
update_option( 'wc_device_label_plural', $wc_device_label_plural );
update_option( 'wc_device_brand_label_plural', $wc_device_brand_label_plural );
update_option( 'wc_device_type_label', $wc_device_type_label );
update_option( 'wc_device_type_label_plural', $wc_device_type_label_plural );
update_option( 'wc_note_label', $wc_note_label );
update_option( 'wc_pin_code_label', $wc_pin_code_label );
update_option( 'wc_device_id_imei_label', $wc_device_id_imei_label );
update_option( 'wc_pin_code_field', $wc_pin_code_field );
update_option( 'wc_pin_code_show_inv', $wc_pin_code_show_inv );
$message = esc_html__( 'Settings updated!', 'computer-repair-shop' );
}
$values['message'] = $message;
$values['success'] = $success;
wp_send_json( $values );
wp_die();
}
function wc_add_device_for_manufacture() {
$message = '';
$device_id = '';
$success = 'NO';
$manufacture = ( isset( $_POST['manufacture'] ) ) ? sanitize_text_field( $_POST['manufacture'] ) : '';
$devicetype = ( isset( $_POST['devicetype'] ) ) ? sanitize_text_field( $_POST['devicetype'] ) : '';
$device_name = ( isset( $_POST['device_name'] ) ) ? sanitize_text_field( $_POST['device_name'] ) : '';
if ( empty ( $manufacture ) || empty( $device_name ) || $manufacture == 'All' ) {
$message = esc_html__( 'Brand and device names cannot be empty.', 'computer-repair-shop' );
} else {
//Check device status
$curr = post_exists( $device_name,'','','rep_devices' );
if ( $curr == '0' ) {
//Post didn't exist let's add
$post_data = array(
'post_title' => $device_name,
'post_status' => 'publish',
'post_type' => 'rep_devices',
);
$post_id = wp_insert_post( $post_data );
if ( isset( $_POST['disable_in_booking_form'] ) && ! empty( $_POST['disable_in_booking_form'] ) ) {
update_post_meta( $post_id, '_disable_in_booking_form', sanitize_text_field( $_POST['disable_in_booking_form'] ) );
}
$tag = array( $manufacture );
wp_set_post_terms( $post_id, $tag, 'device_brand' );
if ( ! empty( $devicetype ) ) {
$type = array( $devicetype );
wp_set_post_terms( $post_id, $type, 'device_type' );
}
$device_id = $post_id;
$message = esc_html__( 'Device Added', 'computer-repair-shop' );
} else {
$device_id = $curr;
$message = esc_html__( 'Device with same name already exists', 'computer-repair-shop' );
}
}
$values['message'] = $message;
$values['device_id'] = $device_id;
$values['success'] = $success;
wp_send_json( $values );
wp_die();
}
/**
* Device Manufacture Options
* Return options
* Outputs selected options
*/
function generate_manufacture_options( $selected_manufacture, $select_all ) {
$selected_manufacture = ( ! empty( $selected_manufacture ) ) ? $selected_manufacture : '';
$wcrb_type = 'rep_devices';
$wcrb_tax = 'device_brand';
$cat_terms = get_terms(
array(
'taxonomy' => $wcrb_tax,
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
'number' => 0
)
);
$wc_device_label = ( empty( get_option( 'wc_device_brand_label' ) ) ) ? esc_html__( 'Brand', 'computer-repair-shop' ) : get_option( 'wc_device_brand_label' );
$wc_device_labels = ( empty( get_option( 'wc_device_brand_label_plural' ) ) ) ? esc_html__( 'Brands', 'computer-repair-shop' ) : get_option( 'wc_device_brand_label_plural' );
$output = "<option value='All'>" . esc_html__("Select", "computer-repair-shop") . ' ' . $wc_device_label . "</option>";
$output = ( isset( $select_all ) && ! empty( $select_all ) ) ? "<option value='All'>" . esc_html__("For All ", "computer-repair-shop") . ' ' . $wc_device_labels . "</option>" : $output;
if( $cat_terms ) :
foreach( $cat_terms as $term ) :
$selected = ( $term->term_id == $selected_manufacture ) ? ' selected' : '';
$output .= '<option ' . $selected . ' value="' . esc_html( $term->term_id ) . '">';
$output .= $term->name;
$output .= '</option>';
endforeach;
endif;
return $output;
}
function generate_device_type_options( $selected_type, $extra_field ) {
$selected_type = ( ! empty( $selected_type ) ) ? $selected_type : '';
$wcrb_type = 'rep_devices';
$wcrb_tax = 'device_type';
$cat_terms = get_terms(
array(
'taxonomy' => $wcrb_tax,
'hide_empty' => false,
'orderby' => 'name',
'order' => 'ASC',
'number' => 0
)
);
$wc_device_label = ( empty( get_option( 'wc_device_type_label' ) ) ) ? esc_html__( 'Type', 'computer-repair-shop' ) : get_option( 'wc_device_type_label' );
$wc_device_labels = ( empty( get_option( 'wc_device_type_label_plural' ) ) ) ? esc_html__( 'Types', 'computer-repair-shop' ) : get_option( 'wc_device_type_label_plural' );
$output = "<option value='All'>" . esc_html__("Select", "computer-repair-shop") . ' ' . $wc_device_label . "</option>";
$output = ( isset( $extra_field ) && ! empty( $extra_field ) ) ? "<option value='All'>" . esc_html__("For All ", "computer-repair-shop") . ' ' . $wc_device_labels . "</option>" : $output;
if( $cat_terms ) :
foreach( $cat_terms as $term ) :
$selected = ( $term->term_id == $selected_type ) ? ' selected' : '';
$output .= '<option ' . $selected . ' value="' . esc_html( $term->term_id ) . '">';
$output .= $term->name;
$output .= '</option>';
endforeach;
endif;
return $output;
}
/**
* Add Device Reveal Form
* Needs to load in footer first
*/
function add_device_reveal_form() {
$output = '';
$wc_device_label = ( empty( get_option( 'wc_device_label' ) ) ) ? esc_html__( 'Device', 'computer-repair-shop' ) : get_option( 'wc_device_label' );
$wc_device_brand_label = ( empty( get_option( 'wc_device_brand_label' ) ) ) ? esc_html__( 'Device Brand', 'computer-repair-shop' ) : get_option( 'wc_device_brand_label' );
$wc_device_type_label = ( empty( get_option( 'wc_device_type_label' ) ) ) ? esc_html__( 'Device Type', 'computer-repair-shop' ) : get_option( 'wc_device_type_label' );
$output .= '<div class="small reveal" id="deviceFormReveal" data-reveal>';
$output .= '<h2>' . esc_html__( 'Add New', 'computer-repair-shop' ) . ' ' . esc_html( $wc_device_label ) . '</h2>';
$output .= '<div class="form-message"></div>';
$output .= '<form data-async data-abide class="needs-validation" novalidate method="post">';
$output .= '<div class="grid-x grid-margin-x">';
$output .= '<div class="cell">
<div data-abide-error class="alert callout hidden">
<p>' . esc_html__( 'There are some errors in your form.', 'computer-repair-shop' ) . '</p>
</div>
</div></div>';
$output .= '<div class="grid-x grid-margin-x">';
$output .= '<div class="cell medium-6">
<label class="have-addition">' . esc_html__( 'Select ', 'computer-repair-shop' ) . esc_html( $wc_device_brand_label ) . '*';
$output .= '<select name="manufacture">';
$output .= $this->generate_manufacture_options( '', '' );
$output .= '</select>';
$output .= '<a href="edit-tags.php?taxonomy=device_brand&post_type=rep_devices" target="_blank" class="button button-primary button-small" title="' . esc_html__( 'Add ', 'computer-repair-shop' ) . $wc_device_brand_label . '"><span class="dashicons dashicons-plus"></span></a>';
$output .= '</label>
</div>';
$output .= '<div class="cell medium-6"><label class="have-addition">' . esc_html__( 'Select ', 'computer-repair-shop' ) . esc_html( $wc_device_type_label ) . '*';
$output .= '<select name="devicetype">';
$output .= $this->generate_device_type_options( '', '' );
$output .= '</select>';
$output .= '<a href="edit-tags.php?taxonomy=device_type&post_type=rep_devices" target="_blank" class="button button-primary button-small" title="' . esc_html__( 'Add ', 'computer-repair-shop' ) . $wc_device_brand_label . '"><span class="dashicons dashicons-plus"></span></a>';
$output .= '</label></div>';
$output .= '<div class="cell medium-6">
<label>' . esc_html( $wc_device_label ) . esc_html__( ' Name', 'computer-repair-shop' ) . '
<input name="device_name" type="text" class="form-control login-field"
value="" id="device_name"/>
</label>';
$output .= '</div>';
$output .= '<div class="cell medium-6"><p></p><p></p>
<label for="disable_in_booking_form">' . sprintf( esc_html__( 'Disable this %s in booking forms', 'computer-repair-shop' ), esc_html( $wc_device_label ) ) . '
<input name="disable_in_booking_form" type="checkbox" class="form-control login-field"
value="yes" id="disable_in_booking_form" /></label>';
$output .= '</div>';
$output .= '</div>';
$output .= '<input name="form_type" type="hidden" value="add_device_form" />';
$output .= '<div class="grid-x grid-margin-x">
<fieldset class="cell medium-6">
<button class="button" type="submit">' . esc_html__( "Add", "computer-repair-shop" ) . ' ' . esc_html( $wc_device_label ) . '</button>
</fieldset>
</div>
</form>
<button class="close-button" data-close aria-label="Close modal" type="button">
<span aria-hidden="true">×</span>
</button>
</div>';
$allowedHTML = ( function_exists( 'wc_return_allowed_tags' ) ) ? wc_return_allowed_tags() : '';
echo wp_kses( $output, $allowedHTML );
}
function list_customer_devices( $view ) {
global $wpdb;
if ( ! is_user_logged_in() ) {
return;
}
$computer_repair_customer_devices = $wpdb->prefix . 'wc_cr_customer_devices';
$current_user = wp_get_current_user();
$customer_id = $current_user->ID;
if ( in_array( 'administrator', (array) $current_user->roles ) && is_admin() ) {
$select_query = "SELECT * FROM `{$computer_repair_customer_devices}` ORDER BY `device_id` DESC";
$view = ( empty( $view ) ) ? 'customer' : $view;
} else {
$select_query = $wpdb->prepare( "SELECT * FROM `{$computer_repair_customer_devices}` WHERE `customer_id`= %d ORDER BY `device_id` DESC", $customer_id );
$view = ( empty( $view ) ) ? $view : 'admin';
}
$select_results = $wpdb->get_results( $select_query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$output = ( $wpdb->num_rows == 0 ) ? esc_html__( 'There is no record available', 'computer-repair-shop' ) : '';
foreach( $select_results as $item ) {
$device_id = $item->device_id;
$device_post_id = $item->device_post_id;
$device_label = $item->device_label;
$serial_nuumber = $item->serial_nuumber;
$pint_code = $item->pint_code;
$customerId = $item->customer_id;
$output .= '<tr>';
$output .= '<td>' . esc_html( $device_id ) . '</td>';
$output .= '<td>' . esc_html( $device_label ) . '</td>';
$output .= '<td>' . esc_html( $serial_nuumber ) . '</td>';
$output .= '<td>' . esc_html( $pint_code ) . '</td>';
if ( is_admin() ) {
$user = get_user_by( 'id', $customerId );
$first_name = empty( $user->first_name ) ? "" : $user->first_name;
$last_name = empty( $user->last_name )? "" : $user->last_name;
$cust_name = $first_name. ' ' .$last_name ;
$output .= '<td>' . esc_html( $cust_name ) . '</td>';
}
$output .= '</tr>';
}
return $output;
}
function backend_customer_devices_output() {
global $wpdb;
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have sufficient permissions to access this page.', 'computer-repair-shop' ) );
}
$wc_device_label = ( empty( get_option( 'wc_device_label_plural' ) ) ) ? esc_html__( 'Devices', 'computer-repair-shop' ) : get_option( 'wc_device_label_plural' );
$sing_device_label = ( empty( get_option( 'wc_device_label' ) ) ) ? esc_html__( 'Device', 'computer-repair-shop' ) : get_option( 'wc_device_label' );
$wc_device_id_imei_label = ( empty( get_option( 'wc_device_id_imei_label' ) ) ) ? esc_html__( 'ID/IMEI', 'computer-repair-shop' ) : get_option( 'wc_device_id_imei_label' );
$wc_pin_code_label = ( empty( get_option( 'wc_pin_code_label' ) ) ) ? esc_html__( 'Pin Code/Password', 'computer-repair-shop' ) : get_option( 'wc_pin_code_label' );
?>
<div class="wrap" id="poststuff">
<h1 class="wp-heading-inline"><?php echo esc_html__( "Customer", "computer-repair-shop" ) . ' ' . esc_html( $wc_device_label ); ?></h1>
<table class="wp-list-table widefat fixed striped users">
<thead><tr>
<th class="manage-column column-id">
<span><?php echo esc_html__( 'ID', 'computer-repair-shop' ); ?></span>
</th>
<th class="manage-column column-name">
<span><?php echo esc_html( $sing_device_label ); ?></span>
</th>
<th class="manage-column column-email">
<span><?php echo esc_html( $wc_device_id_imei_label ); ?></span>
</th>
<th class="manage-column column-phone">
<?php echo esc_html( $wc_pin_code_label ); ?>
</th>
<th class="manage-column column-address">
<?php echo esc_html__( 'Customer', 'computer-repair-shop' ); ?>
</th>
</tr></thead>
<tbody data-wp-lists="list:user">
<?php
$output = $this->list_customer_devices( 'admin' );
$allowedHTML = wc_return_allowed_tags();
echo wp_kses( $output, $allowedHTML );
?>
</tbody>
<tfoot><tr>
<th class="manage-column column-id">
<span><?php echo esc_html__( 'ID', 'computer-repair-shop' ); ?></span>
</th>
<th class="manage-column column-name">
<span><?php echo esc_html( $sing_device_label ); ?></span>
</th>
<th class="manage-column column-email">
<span><?php echo esc_html( $wc_device_id_imei_label ); ?></span>
</th>
<th class="manage-column column-phone">
<?php echo esc_html( $wc_pin_code_label ); ?>
</th>
<th class="manage-column column-address">
<?php echo esc_html__( 'Customer', 'computer-repair-shop' ); ?>
</th>
</tr></tfoot>
</table>
</div> <!-- Wrap Ends /-->
<?php
}
function add_customer_device( $device_post_id, $imei_serial, $device_pincode, $customer_id ) {
global $wpdb;
if ( empty( $device_post_id ) || empty( $customer_id ) ) {
return;
}
$computer_repair_customer_devices = $wpdb->prefix.'wc_cr_customer_devices';
$wc_meta_value = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$computer_repair_customer_devices} WHERE `customer_id` = %d AND `device_post_id` = %s AND `serial_nuumber` = %s", $customer_id, $device_post_id, $imei_serial ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery
if ( ! empty( $wc_meta_value ) ) {
return;
}
$device_label = return_device_label( $device_post_id );
$insert_query = "INSERT INTO
`" . $computer_repair_customer_devices . "`
VALUES
(NULL, %d, %s, %s, %s, %d)";
$wpdb->query( // phpcs:ignore WordPress.DB.DirectDatabaseQuery
$wpdb->prepare($insert_query, array( $device_post_id, $device_label, $imei_serial, $device_pincode, $customer_id ))
);
$history_id = $wpdb->insert_id;
}
function return_extra_device_input_fields( $type ) {
$type = ( empty( $type ) ) ? 'backend' : $type;
$container_class = ( $type == 'backend' ) ? 'cell medium-2_5 small-6' : 'device-item-b';
$extra_fields_array = get_option( '_extra_device_fields' );
$extrafields = '';
if ( ! wc_rs_license_state() ) :
return;
endif;
$extra_fields_arr = '';
$counter = 0;
if ( ! empty( $extra_fields_array ) && is_array( $extra_fields_array ) ) {
foreach( $extra_fields_array as $field_array ) {
$rb_device_field_id = ( isset( $field_array['rb_device_field_id'] ) ) ? $field_array['rb_device_field_id'] : '';
$rb_device_field_label = ( isset( $field_array['rb_device_field_label'] ) ) ? $field_array['rb_device_field_label'] : '';
$rb_device_field_type = ( isset( $field_array['rb_device_field_type'] ) ) ? $field_array['rb_device_field_type'] : '';
$rb_device_field_display_booking_form = ( isset( $field_array['rb_device_field_display_booking_form'] ) ) ? $field_array['rb_device_field_display_booking_form'] : '';
$rb_device_field_display_in_invoice = ( isset( $field_array['rb_device_field_display_in_invoice'] ) ) ? $field_array['rb_device_field_display_in_invoice'] : '';
$rb_device_field_display_for_customer = ( isset( $field_array['rb_device_field_display_for_customer'] ) ) ? $field_array['rb_device_field_display_for_customer'] : '';
if ( $rb_device_field_display_booking_form == 'yes' || $type == 'backend' ) :
$extra_fields_arr .= ( $counter > 0 ) ? '|' : '';
$extrafields .= '<div class="'. esc_attr( $container_class ) .'">';
$extrafields .= '<label for="'. esc_attr( $rb_device_field_id ) .'">';
$extrafields .= ( $type != 'backend' ) ? esc_html( $rb_device_field_label ) : '';
if ( $type == 'frontend' ) {
$extrafields .= '<input type="text" id="'. esc_attr( $rb_device_field_id ) .'" name="'. esc_attr( $rb_device_field_id ) .'_html[]" value="" />';
} else {
$extrafields .= '<input type="text" id="'. esc_attr( $rb_device_field_id ) .'" name="'. esc_attr( $rb_device_field_id ) .'_html" placeholder="'. esc_html( $rb_device_field_label ) .'" value="" />';
}
$extrafields .= '</label>';
$extrafields .= '</div>';
$extra_fields_arr .= $rb_device_field_id;
$counter++;
endif;
}
}
$extra_fields_ident = ( ! empty( $extra_fields_arr ) ) ? '<input type="hidden" id="extrafields_identifier" name="extra_fields_identifier" value="'. esc_html( $extra_fields_arr ) .'" />' : '';
return $extrafields . $extra_fields_ident;
}
function wc_return_job_devices( $job_id, $return_type) {
if ( empty( $job_id ) ) {
return;
}
$return_type = ( empty( $return_type ) ) ? 'job_html' : $return_type;
$wc_device_data = get_post_meta( $job_id, '_wc_device_data', true );
if ( empty( $wc_device_data ) ) {
wc_set_new_device_format( $job_id );
$wc_device_data = get_post_meta( $job_id, '_wc_device_data', true );
}
$wc_pin_code_field = get_option( 'wc_pin_code_field' );
$wc_device_label = ( empty( get_option( 'wc_device_label' ) ) ) ? esc_html__( 'Device', 'computer-repair-shop' ) : get_option( 'wc_device_label' );
$wc_device_id_imei_label = ( empty( get_option( 'wc_device_id_imei_label' ) ) ) ? esc_html__( 'ID/IMEI', 'computer-repair-shop' ) : get_option( 'wc_device_id_imei_label' );
$content = '<table class="grey-bg wc_table"><thead><tr>';
$content .= '<th>' . $wc_device_label . '</th>';
$content .= '<th>' . $wc_device_id_imei_label . '</th>';
if ( $wc_pin_code_field == 'on' ):
$wc_pin_code_label = ( empty( get_option( 'wc_pin_code_label' ) ) ) ? esc_html__( 'Pin Code/Password', 'computer-repair-shop' ) : get_option( 'wc_pin_code_label' );
$content .= '<th>' . esc_html( $wc_pin_code_label ) . '</th>';
endif;
$wc_note_label = ( empty( get_option( 'wc_note_label' ) ) ) ? esc_html__( 'Note', 'computer-repair-shop' ) : get_option( 'wc_note_label' );
$content .= '<th>' . esc_html( $wc_note_label ) . '</th>';
$content .= $this->return_extra_devices_fields( 'heads', '', '' );
$content .= '</tr></thead>';
$content .= '<tbody class="devices_body">';
if ( is_array( $wc_device_data ) && !empty( $wc_device_data ) ) :
foreach ( $wc_device_data as $device_data ) :
$deive_note = ( isset( $device_data['device_note'] ) ) ? $device_data['device_note'] : '';
$device_post_id = ( isset( $device_data['device_post_id'] ) ) ? $device_data['device_post_id'] : '';
$device_id = ( isset( $device_data['device_id'] ) ) ? $device_data['device_id'] : '';
$content .= '<tr class="item-row wc_devices_row">';
$content .= '<td class="wc_device_name"><a class="delme delmewedit" href="#" title="Remove row"><span class="dashicons dashicons-trash"></span></a><a class="editme editmedevice" href="#" title="Edit row"><span class="dashicons dashicons-edit"></span></a>';
$device_label = return_device_label( $device_post_id );
$content .= $device_label;
$content .= '<input type="hidden" name="device_post_name_html[]" value="' . $device_label . '">';
$content .= '<input type="hidden" name="device_post_id_html[]" value="' . $device_post_id . '">';
$content .= '</td>';
$content .= '<td class="wc_device_serial">';
$content .= $device_id;
$content .= '<input type="hidden" name="device_serial_id_html[]" value="' . $device_id . '">';
$content .= '</td>';
if ( $wc_pin_code_field == 'on' ):
$content .= '<td class="wc_device_pin">';
$device_login = ( isset( $device_data['device_login'] ) ) ? $device_data['device_login'] : '';
$content .= esc_html( $device_login );
$content .= '<input type="hidden" name="device_login_html[]" value="' . esc_html( $device_login ) . '">';
$content .= '</td>';
endif;
$content .= '<td class="wc_device_note">';
$content .= $deive_note;
$content .= '<input type="hidden" name="device_note_html[]" value="' . $deive_note . '">';
$content .= '</td>';
$body_arr = $this->return_extra_devices_fields( 'body', '', '' );
if ( is_array( $body_arr ) ) {
foreach( $body_arr as $body_item ) {
$content .= '<td>';
$item_data = ( isset( $device_data[$body_item] ) ) ? $device_data[$body_item] : '';
$content .= esc_html( $item_data );
$content .= '<input type="hidden" name="'. esc_attr( $body_item ) .'_html[]" value="' . esc_html( $item_data ) . '">';
$content .= '</td>';
}
}
$content .= '</tr>';
endforeach;
endif;
$content .= '</tbody>';
$content .= '</table>';
return $content;
}
function return_extra_devices_fields( $type, $in_invoice, $to_customer ) {
if ( empty( $type ) ) {
return;
}
if ( ! wc_rs_license_state() ) {
return;
}
$extra_fields_array = get_option( '_extra_device_fields' );
$return_type = ( ! empty( $type ) ) ? $type : 'heads';
$return_fields_arr = array();
$return_heads = '';
if ( ! empty( $extra_fields_array ) && is_array( $extra_fields_array ) ) {
foreach( $extra_fields_array as $field_array ) {
$rb_device_field_id = ( isset( $field_array['rb_device_field_id'] ) ) ? $field_array['rb_device_field_id'] : '';
$rb_device_field_label = ( isset( $field_array['rb_device_field_label'] ) ) ? $field_array['rb_device_field_label'] : '';
$rb_device_field_type = ( isset( $field_array['rb_device_field_type'] ) ) ? $field_array['rb_device_field_type'] : '';
$rb_device_field_display_booking_form = ( isset( $field_array['rb_device_field_display_booking_form'] ) ) ? $field_array['rb_device_field_display_booking_form'] : '';
$rb_device_field_display_in_invoice = ( isset( $field_array['rb_device_field_display_in_invoice'] ) ) ? $field_array['rb_device_field_display_in_invoice'] : '';
$rb_device_field_display_for_customer = ( isset( $field_array['rb_device_field_display_for_customer'] ) ) ? $field_array['rb_device_field_display_for_customer'] : '';
$return = 'YES';
if ( ! empty( $to_customer ) && $to_customer == 'YES' ) {
$return = 'YES';
//Include items says YES
if ( $rb_device_field_display_for_customer == 'no' ) {
$return = 'NO';
}
}
if ( ! empty( $in_invoice ) && $in_invoice == 'YES' ) {
$return = 'YES';
//Include items says YES
if ( $rb_device_field_display_in_invoice == 'no' ) {
$return = 'NO';
}
}
if ( $return == 'YES' ) {
$return_heads .= '<th>' . esc_html( $rb_device_field_label ) . '</th>';
$return_fields_arr[] = $rb_device_field_id;
}
}
}
return ( $return_type == 'heads' ) ? $return_heads : $return_fields_arr;
}
function wc_add_device_row() {
$content = '';
$wc_pin_code_field = get_option( 'wc_pin_code_field' );
$device_post_id_html = ( isset( $_POST['device_post_id_html'] ) && !empty( $_POST['device_post_id_html'] ) ) ? sanitize_text_field( $_POST['device_post_id_html'] ) : '';
$device_serial_id_html = ( isset( $_POST['device_serial_id_html'] ) && !empty( $_POST['device_serial_id_html'] ) ) ? sanitize_text_field( $_POST['device_serial_id_html'] ) : '';
$device_login_html = ( isset( $_POST['device_login_html'] ) && !empty( $_POST['device_login_html'] ) ) ? sanitize_text_field( $_POST['device_login_html'] ) : '';
$device_note_html = ( isset( $_POST['device_note_html'] ) && !empty( $_POST['device_note_html'] ) ) ? sanitize_text_field( $_POST['device_note_html'] ) : '';
if ( !empty( $device_post_id_html ) || !empty( $device_serial_id_html ) ) {
$content .= '<tr class="item-row wc_devices_row">';
$content .= '<td class="wc_device_name"><a class="delme delmewedit" href="#" title="Remove row"><span class="dashicons dashicons-trash"></span></a>
<a class="editme editmedevice" href="#" title="Edit row"><span class="dashicons dashicons-edit"></span></a>';
$device_label = return_device_label( $device_post_id_html );
$content .= $device_label;
$content .= '<input type="hidden" name="device_post_name_html[]" value="' . $device_label . '">';
$content .= '<input type="hidden" name="device_post_id_html[]" value="' . $device_post_id_html . '">';
$content .= '</td>';
$content .= '<td class="wc_device_serial">';
$content .= $device_serial_id_html;
$content .= '<input type="hidden" name="device_serial_id_html[]" value="' . $device_serial_id_html . '">';
$content .= '</td>';
if ( $wc_pin_code_field == 'on' ):
$content .= '<td class="wc_device_pin">';
$content .= $device_login_html;
$content .= '<input type="hidden" name="device_login_html[]" value="' . $device_login_html . '">';
$content .= '</td>';
endif;
$content .= '<td class="wc_device_note">';
$content .= $device_note_html;
$content .= '<input type="hidden" name="device_note_html[]" value="' . $device_note_html . '">';
$content .= '</td>';
$body_arr = $this->return_extra_devices_fields( 'body', '', '' );
if ( is_array( $body_arr ) ) {
foreach( $body_arr as $body_item ) {
$content .= '<td>';
$item_data = ( isset( $_POST[$body_item.'_html'] ) ) ? sanitize_text_field( $_POST[$body_item.'_html'] ) : '';
$content .= esc_html( $item_data );
$content .= '<input type="hidden" name="'. esc_attr( $body_item ) .'_html[]" value="' . esc_html( $item_data ) . '">';
$content .= '</td>';
}
}
$content .= '</tr>';
$values['row'] = $content;
}
wp_send_json($values);
wp_die();
}
}
Click one of our contacts below to chat on WhatsApp
Do you have any questions?