| 1 |
<?php |
| 2 |
if ( ! defined( 'ABSPATH' ) ) { |
| 3 |
exit; // Exit if accessed directly! |
| 4 |
} |
| 5 |
|
| 6 |
if ( ! class_exists( 'WPSC_Wh_Settings' ) ) : |
| 7 |
|
| 8 |
final class WPSC_Wh_Settings { |
| 9 |
|
| 10 |
/** |
| 11 |
* Initialize this class |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
public static function init() { |
| 16 |
|
| 17 |
// User interface. |
| 18 |
add_action( 'wp_ajax_wpsc_get_wh_settings', array( __CLASS__, 'get_wh_settings' ) ); |
| 19 |
add_action( 'wp_ajax_wpsc_set_wh_settings', array( __CLASS__, 'set_wh_settings' ) ); |
| 20 |
add_action( 'wp_ajax_wpsc_reset_wh_settings', array( __CLASS__, 'reset_wh_settings' ) ); |
| 21 |
} |
| 22 |
|
| 23 |
/** |
| 24 |
* Reset settings |
| 25 |
* |
| 26 |
* @return void |
| 27 |
*/ |
| 28 |
public static function reset() { |
| 29 |
|
| 30 |
$advanced = apply_filters( |
| 31 |
'wpsc_wh_settings', |
| 32 |
array( |
| 33 |
'allow-agent-modify-wh' => 0, |
| 34 |
'allow-agent-modify-leaves' => 0, |
| 35 |
) |
| 36 |
); |
| 37 |
update_option( 'wpsc-wh-settings', $advanced ); |
| 38 |
} |
| 39 |
|
| 40 |
/** |
| 41 |
* Settings user interface |
| 42 |
* |
| 43 |
* @return void |
| 44 |
*/ |
| 45 |
public static function get_wh_settings() { |
| 46 |
|
| 47 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 48 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 49 |
} |
| 50 |
$settings = get_option( 'wpsc-wh-settings', array() );?> |
| 51 |
|
| 52 |
<form action="#" onsubmit="return false;" class="wpsc-frm-wh-settings"> |
| 53 |
<div class="wpsc-dock-container"> |
| 54 |
<?php |
| 55 |
printf( |
| 56 |
/* translators: Click here to see the documentation */ |
| 57 |
esc_attr__( '%s to see the documentation!', 'supportcandy' ), |
| 58 |
'<a href="https://supportcandy.net/docs/working-hours/" target="_blank">' . esc_attr__( 'Click here', 'supportcandy' ) . '</a>' |
| 59 |
); |
| 60 |
?> |
| 61 |
</div> |
| 62 |
<div class="wpsc-input-group"> |
| 63 |
<div class="label-container"> |
| 64 |
<label for=""><?php esc_attr_e( 'Allow agent to modify working hours', 'supportcandy' ); ?></label> |
| 65 |
</div> |
| 66 |
<select name="allow-agent-modify-wh"> |
| 67 |
<option <?php selected( $settings['allow-agent-modify-wh'], '1' ); ?> value="1"><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></option> |
| 68 |
<option <?php selected( $settings['allow-agent-modify-wh'], '0' ); ?> value="0"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></option> |
| 69 |
</select> |
| 70 |
</div> |
| 71 |
<div class="wpsc-input-group"> |
| 72 |
<div class="label-container"> |
| 73 |
<label for=""><?php esc_attr_e( 'Allow agent to modify his leaves', 'supportcandy' ); ?></label> |
| 74 |
</div> |
| 75 |
<select name="allow-agent-modify-leaves"> |
| 76 |
<option <?php selected( $settings['allow-agent-modify-leaves'], '1' ); ?> value="1"><?php esc_attr_e( 'Enable', 'supportcandy' ); ?></option> |
| 77 |
<option <?php selected( $settings['allow-agent-modify-leaves'], '0' ); ?> value="0"><?php esc_attr_e( 'Disable', 'supportcandy' ); ?></option> |
| 78 |
</select> |
| 79 |
</div> |
| 80 |
<?php do_action( 'wpsc_wh_settings' ); ?> |
| 81 |
<input type="hidden" name="action" value="wpsc_set_wh_settings"> |
| 82 |
<input type="hidden" name="_ajax_nonce" value="<?php echo esc_attr( wp_create_nonce( 'wpsc_set_wh_settings' ) ); ?>"> |
| 83 |
</form> |
| 84 |
<div class="setting-footer-actions"> |
| 85 |
<button |
| 86 |
class="wpsc-button normal primary margin-right" |
| 87 |
onclick="wpsc_set_wh_settings(this);"> |
| 88 |
<?php esc_attr_e( 'Submit', 'supportcandy' ); ?></button> |
| 89 |
<button |
| 90 |
class="wpsc-button normal secondary" |
| 91 |
onclick="wpsc_reset_wh_settings(this, '<?php echo esc_attr( wp_create_nonce( 'wpsc_reset_wh_settings' ) ); ?>');"> |
| 92 |
<?php esc_attr_e( 'Reset default', 'supportcandy' ); ?></button> |
| 93 |
</div> |
| 94 |
<?php |
| 95 |
wp_die(); |
| 96 |
} |
| 97 |
|
| 98 |
/** |
| 99 |
* Save settings |
| 100 |
* |
| 101 |
* @return void |
| 102 |
*/ |
| 103 |
public static function set_wh_settings() { |
| 104 |
|
| 105 |
if ( check_ajax_referer( 'wpsc_set_wh_settings', '_ajax_nonce', false ) != 1 ) { |
| 106 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 107 |
} |
| 108 |
|
| 109 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 110 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 111 |
} |
| 112 |
|
| 113 |
$advanced = apply_filters( |
| 114 |
'wpsc_set_ms_advanced', |
| 115 |
array( |
| 116 |
'allow-agent-modify-wh' => isset( $_POST['allow-agent-modify-wh'] ) ? intval( $_POST['allow-agent-modify-wh'] ) : 0, |
| 117 |
'allow-agent-modify-leaves' => isset( $_POST['allow-agent-modify-leaves'] ) ? intval( $_POST['allow-agent-modify-leaves'] ) : 0, |
| 118 |
) |
| 119 |
); |
| 120 |
update_option( 'wpsc-wh-settings', $advanced ); |
| 121 |
wp_die(); |
| 122 |
} |
| 123 |
|
| 124 |
/** |
| 125 |
* Reset settings to default |
| 126 |
* |
| 127 |
* @return void |
| 128 |
*/ |
| 129 |
public static function reset_wh_settings() { |
| 130 |
|
| 131 |
if ( check_ajax_referer( 'wpsc_reset_wh_settings', '_ajax_nonce', false ) != 1 ) { |
| 132 |
wp_send_json_error( 'Unauthorized request!', 401 ); |
| 133 |
} |
| 134 |
|
| 135 |
if ( ! WPSC_Functions::is_site_admin() ) { |
| 136 |
wp_send_json_error( __( 'Unauthorized access!', 'supportcandy' ), 401 ); |
| 137 |
} |
| 138 |
self::reset(); |
| 139 |
wp_die(); |
| 140 |
} |
| 141 |
} |
| 142 |
endif; |
| 143 |
|
| 144 |
WPSC_Wh_Settings::init(); |
| 145 |
|