| 1 |
<?php |
| 2 |
/** |
| 3 |
* Operation logs extensions. |
| 4 |
* Enable/Disable the operation log metabox on: |
| 5 |
* - The editing order screen |
| 6 |
* - The editing member screen |
| 7 |
* |
| 8 |
* @package Welcart |
| 9 |
* @author Collne Inc. |
| 10 |
*/ |
| 11 |
|
| 12 |
/** |
| 13 |
* OPERATION_LOG class |
| 14 |
*/ |
| 15 |
class OPERATION_LOG { |
| 16 |
/** |
| 17 |
* Extended Options. |
| 18 |
* |
| 19 |
* @var object |
| 20 |
*/ |
| 21 |
public static $opts; |
| 22 |
|
| 23 |
/** |
| 24 |
* Construct. |
| 25 |
*/ |
| 26 |
public function __construct() { |
| 27 |
|
| 28 |
self::initialize_data(); |
| 29 |
|
| 30 |
if ( is_admin() ) { |
| 31 |
add_action( 'usces_action_admin_system_extentions', array( $this, 'setting_form' ) ); |
| 32 |
add_action( 'init', array( $this, 'save_data' ) ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
/** |
| 37 |
* Handle init data. |
| 38 |
*/ |
| 39 |
public function initialize_data() { |
| 40 |
global $usces; |
| 41 |
$options = get_option( 'usces_ex', array() ); |
| 42 |
$options['system']['operation_log']['status'] = isset( $options['system']['operation_log']['status'] ) ? (int) $options['system']['operation_log']['status'] : 1; |
| 43 |
$options['system']['operation_log']['order_status'] = isset( $options['system']['operation_log']['order_status'] ) ? (int) $options['system']['operation_log']['order_status'] : 1; |
| 44 |
$options['system']['operation_log']['member_status'] = isset( $options['system']['operation_log']['member_status'] ) ? (int) $options['system']['operation_log']['member_status'] : 1; |
| 45 |
|
| 46 |
if ( empty( $options['system']['operation_log']['admin_log_retention_period'] ) ) { |
| 47 |
// Migrate the log setting from the "usces" option to "usces_ex" option. |
| 48 |
if ( ! empty( $usces->options['system']['admin_log_retention_period'] ) ) { |
| 49 |
$options['system']['operation_log']['admin_log_retention_period'] = $usces->options['system']['admin_log_retention_period']; |
| 50 |
} else { |
| 51 |
$options['system']['operation_log']['admin_log_retention_period'] = '6 months'; |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
update_option( 'usces_ex', $options ); |
| 56 |
self::$opts = $options['system']['operation_log']; |
| 57 |
} |
| 58 |
|
| 59 |
/** |
| 60 |
* Check if the operation log is enabled or not. |
| 61 |
* |
| 62 |
* @return boolean true/false |
| 63 |
*/ |
| 64 |
public static function is_enabled() { |
| 65 |
return 1 === self::$opts['status']; |
| 66 |
} |
| 67 |
|
| 68 |
/** |
| 69 |
* Check if the operation log is enabled or not. |
| 70 |
* |
| 71 |
* @return boolean true/false |
| 72 |
*/ |
| 73 |
public static function is_disabled() { |
| 74 |
return 0 === self::$opts['status']; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get the retention period. |
| 79 |
* |
| 80 |
* @return string |
| 81 |
*/ |
| 82 |
public static function get_retention_period() { |
| 83 |
return self::$opts['admin_log_retention_period']; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Check if the order metabox is enabled or not. |
| 88 |
* |
| 89 |
* @return boolean true/false |
| 90 |
*/ |
| 91 |
public static function is_order_metabox_enabled() { |
| 92 |
return self::is_enabled() && 1 === self::$opts['order_status']; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Check if the member metabox is enabled or not. |
| 97 |
* |
| 98 |
* @return boolean true/false |
| 99 |
*/ |
| 100 |
public static function is_member_metabox_enabled() { |
| 101 |
return self::is_enabled() && 1 === self::$opts['member_status']; |
| 102 |
} |
| 103 |
|
| 104 |
/** |
| 105 |
* Handle save data. |
| 106 |
*/ |
| 107 |
public function save_data() { |
| 108 |
global $usces; |
| 109 |
|
| 110 |
$action = filter_input( INPUT_POST, 'usces_operation_log_option_update' ); |
| 111 |
if ( ! empty( $action ) ) { |
| 112 |
check_admin_referer( 'admin_system', 'wc_nonce' ); |
| 113 |
if ( ! current_user_can( 'wel_manage_setting' ) ) { |
| 114 |
wp_die( __( 'You do not have sufficient permissions to access this page.' ) ); |
| 115 |
} |
| 116 |
|
| 117 |
$status = filter_input( INPUT_POST, 'operation_log_status' ); |
| 118 |
$order_status = filter_input( INPUT_POST, 'order_operation_log_status' ); |
| 119 |
$member_status = filter_input( INPUT_POST, 'member_operation_log_status' ); |
| 120 |
$admin_log_retention_period = filter_input( INPUT_POST, 'admin_log_retention_period' ); |
| 121 |
|
| 122 |
self::$opts['status'] = (int) $status; |
| 123 |
if ( self::is_disabled() ) { |
| 124 |
$order_status = 0; |
| 125 |
$member_status = 0; |
| 126 |
$admin_log_retention_period = '6 months'; |
| 127 |
} |
| 128 |
self::$opts['order_status'] = (int) $order_status; |
| 129 |
self::$opts['member_status'] = (int) $member_status; |
| 130 |
self::$opts['admin_log_retention_period'] = $admin_log_retention_period; |
| 131 |
|
| 132 |
$options = get_option( 'usces_ex', array() ); |
| 133 |
$options['system']['operation_log'] = self::$opts; |
| 134 |
update_option( 'usces_ex', $options ); |
| 135 |
|
| 136 |
// Remove the log setting at the "usces" option. |
| 137 |
if ( isset( $usces->options['system']['admin_log_retention_period'] ) ) { |
| 138 |
unset( $usces->options['system']['admin_log_retention_period'] ); |
| 139 |
update_option( 'usces', $usces->options ); |
| 140 |
} |
| 141 |
} |
| 142 |
} |
| 143 |
|
| 144 |
/** |
| 145 |
* Handel build setting from. |
| 146 |
*/ |
| 147 |
public function setting_form() { |
| 148 |
$status = self::$opts['status']; |
| 149 |
$order_status = self::$opts['order_status']; |
| 150 |
$member_status = self::$opts['member_status']; |
| 151 |
$admin_log_retention_period = self::$opts['admin_log_retention_period']; |
| 152 |
?> |
| 153 |
<form action="" method="post" name="option_form" id="operation_log_form"> |
| 154 |
<div class="postbox"> |
| 155 |
<div class="postbox-header"> |
| 156 |
<h2> |
| 157 |
<span><?php esc_attr_e( 'Operation Log', 'usces' ); ?></span> |
| 158 |
<?php if ( self::$opts['status'] ) { ?> |
| 159 |
<span class="running"><?php esc_attr_e( 'Running', 'usces' ); ?></span> |
| 160 |
<?php } else { ?> |
| 161 |
<span class="stopped"><?php esc_attr_e( 'Stopped', 'usces' ); ?></span> |
| 162 |
<?php } ?> |
| 163 |
</h2> |
| 164 |
<div class="handle-actions"> |
| 165 |
<button type="button" class="handlediv" id="operation_log"> |
| 166 |
<span class="screen-reader-text"> |
| 167 |
<?php |
| 168 |
// translators: %s: Toggle panel name. |
| 169 |
sprintf( esc_html__( 'Toggle panel: %s' ), esc_html__( 'Operation Log', 'usces' ) ); |
| 170 |
?> |
| 171 |
</span> |
| 172 |
<span class="toggle-indicator"></span> |
| 173 |
</button> |
| 174 |
</div> |
| 175 |
</div> |
| 176 |
<div class="inside"> |
| 177 |
<table class="form_table"> |
| 178 |
<tr height="35"> |
| 179 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_operation_log_status');"><?php esc_attr_e( 'Operation Log', 'usces' ); ?></a></th> |
| 180 |
<td width="10"> |
| 181 |
<input name="operation_log_status" id="operation_log_status0" type="radio" value="0" <?php checked( '0', $status ); ?>/> |
| 182 |
</td> |
| 183 |
<td width="100"><label for="operation_log_status0"><?php esc_attr_e( 'disable', 'usces' ); ?></label></td> |
| 184 |
<td width="10"> |
| 185 |
<input name="operation_log_status" id="operation_log_status1" type="radio" value="1" <?php checked( '1', $status ); ?> /> |
| 186 |
</td><td width="100"><label for="operation_log_status1"><?php esc_attr_e( 'enable', 'usces' ); ?></label></td> |
| 187 |
<td><div id="ex_operation_log_status" class="explanation"><?php esc_attr_e( 'Control enable or disable the operation log.', 'usces' ); ?><?php esc_attr_e( 'Select "Disable" if you wish to stop the operation log.', 'usces' ); ?></div></td> |
| 188 |
</tr> |
| 189 |
<tr height="35" class="metabox_operation_log_status" style="display:none;"> |
| 190 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_order_operation_log_status');"><?php esc_attr_e( 'Order Operation Log', 'usces' ); ?></a></th> |
| 191 |
<td width="10"> |
| 192 |
<input name="order_operation_log_status" id="order_operation_log_status0" type="radio" value="0" <?php checked( '0', $order_status ); ?>/> |
| 193 |
</td> |
| 194 |
<td width="100"><label for="order_operation_log_status0"><?php esc_attr_e( 'disable', 'usces' ); ?></label></td> |
| 195 |
<td width="10"> |
| 196 |
<input name="order_operation_log_status" id="order_operation_log_status1" type="radio" value="1" <?php checked( '1', $order_status ); ?> /> |
| 197 |
</td><td width="100"><label for="order_operation_log_status1"><?php esc_attr_e( 'enable', 'usces' ); ?></label></td> |
| 198 |
<td><div id="ex_order_operation_log_status" class="explanation"><?php esc_attr_e( 'Control enable or disable the display of the order operation log.', 'usces' ); ?><?php esc_attr_e( 'Select "Disable" if you wish to stop the display of the order operation log.', 'usces' ); ?></div></td> |
| 199 |
</tr> |
| 200 |
<tr height="35" class="metabox_operation_log_status" style="display:none;"> |
| 201 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_member_operation_log_status');"><?php esc_attr_e( 'Member Operation Log', 'usces' ); ?></a></th> |
| 202 |
<td width="10"> |
| 203 |
<input name="member_operation_log_status" id="member_operation_log_status0" type="radio" value="0" <?php checked( '0', $member_status ); ?>/> |
| 204 |
</td> |
| 205 |
<td width="100"><label for="member_operation_log_status0"><?php esc_attr_e( 'disable', 'usces' ); ?></label></td> |
| 206 |
<td width="10"> |
| 207 |
<input name="member_operation_log_status" id="member_operation_log_status1" type="radio" value="1" <?php checked( '1', $member_status ); ?> /> |
| 208 |
</td><td width="100"><label for="member_operation_log_status1"><?php esc_attr_e( 'enable', 'usces' ); ?></label></td> |
| 209 |
<td><div id="ex_member_operation_log_status" class="explanation"><?php esc_attr_e( 'Control enable or disable the display of the member operation log.', 'usces' ); ?><?php esc_attr_e( 'Select "Disable" if you wish to stop the display of the member operation log.', 'usces' ); ?></div></td> |
| 210 |
</tr> |
| 211 |
<tr height="35" class="metabox_operation_log_status" style="display:none;"> |
| 212 |
<th class="system_th"><a style="cursor:pointer;" onclick="toggleVisibility('ex_admin_log_notice');"> |
| 213 |
<?php esc_html_e( 'Operation log retention period', 'usces' ); ?></a> |
| 214 |
</th> |
| 215 |
<td width="100" colspan="4"> |
| 216 |
<select name="admin_log_retention_period"> |
| 217 |
<option value="6 months" <?php selected( $admin_log_retention_period, '6 months' ); ?>><?php esc_html_e( '6 months', 'usces' ); ?></option> |
| 218 |
<option value="1 year" <?php selected( $admin_log_retention_period, '1 year' ); ?>><?php esc_html_e( '1 year', 'usces' ); ?></option> |
| 219 |
<option value="3 years" <?php selected( $admin_log_retention_period, '3 years' ); ?>><?php esc_html_e( '3 years', 'usces' ); ?></option> |
| 220 |
<option value="5 years" <?php selected( $admin_log_retention_period, '5 years' ); ?>><?php esc_html_e( '5 years', 'usces' ); ?></option> |
| 221 |
</select> |
| 222 |
</td> |
| 223 |
<td><div id="ex_admin_log_notice" class="explanation"><?php esc_html_e( 'The period when the admin logs will be deleted.', 'usces' ); ?></div></td> |
| 224 |
</tr> |
| 225 |
</table> |
| 226 |
<hr /> |
| 227 |
<input name="usces_operation_log_option_update" type="submit" class="button button-primary" value="<?php esc_attr_e( 'change decision', 'usces' ); ?>" /> |
| 228 |
<script type="text/javascript"> |
| 229 |
(function ($) { |
| 230 |
const operationLog = { |
| 231 |
statusRadioEles: $('input[type=radio][name=operation_log_status]'), |
| 232 |
subSettingEles: $('tr.metabox_operation_log_status'), |
| 233 |
start: function () { |
| 234 |
this.onClickStatusRadio(); |
| 235 |
this.onReady(); |
| 236 |
}, |
| 237 |
onClickStatusRadio: function () { |
| 238 |
const _self = this; |
| 239 |
_self.statusRadioEles.on('click', function () { |
| 240 |
const isEnabled = '1' === this.value; |
| 241 |
if (isEnabled) { |
| 242 |
_self.subSettingEles.fadeIn(); |
| 243 |
} else { |
| 244 |
_self.subSettingEles.fadeOut(); |
| 245 |
} |
| 246 |
}); |
| 247 |
}, |
| 248 |
onReady: function () { |
| 249 |
const checkedRadioStatusEle = $( |
| 250 |
'input[type=radio][name=operation_log_status]:checked' |
| 251 |
); |
| 252 |
checkedRadioStatusEle.trigger('click'); |
| 253 |
}, |
| 254 |
}; |
| 255 |
|
| 256 |
operationLog.start(); |
| 257 |
})(jQuery); |
| 258 |
</script> |
| 259 |
</div> |
| 260 |
</div><!--postbox--> |
| 261 |
<?php wp_nonce_field( 'admin_system', 'wc_nonce' ); ?> |
| 262 |
</form> |
| 263 |
<?php |
| 264 |
} |
| 265 |
} |
| 266 |
|