array( 'label' => __( 'Settings', 'timesheet' ) ), 'display' => array( 'label' => __( 'Display', 'timesheet' ) ), 'notifications' => array( 'label' => __( 'Reminders', 'timesheet' ) ), 'reports' => array( 'label' => __( 'Reports', 'timesheet' ), 'is_pro' => 1, ), 'import-export' => array( 'label' => __( 'Import / Export', 'timesheet' ), 'is_pro' => 1, ), 'misc' => array( 'label' => __( 'Misc', 'timesheet' ) ), 'license' => array( 'label' => __( 'License Key', 'timesheet' ) ), ); parent::__construct( array( 'plugin_basename' => $plugin_basename, 'plugins_info' => $tmsht_plugin_info, 'prefix' => 'tmsht', 'default_options' => tmsht_get_options_default(), 'options' => $tmsht_options, 'tabs' => $tabs, 'wp_slug' => 'timesheet', 'link_key' => '3bdf25984ad6aa9d95074e31c5eb9bb3', 'link_pn' => '606', 'doc_link' => 'https://bestwebsoft.com/documentation/timesheet/timesheet-user-guide/', ) ); $this->days_arr = array( __( 'Mon', 'timesheet' ), __( 'Tue', 'timesheet' ), __( 'Wed', 'timesheet' ), __( 'Thu', 'timesheet' ), __( 'Fri', 'timesheet' ), __( 'Sat', 'timesheet' ), __( 'Sun', 'timesheet' ) ); $this->period_arr = array( __( 'month', 'timesheet' ), __( '6 month', 'timesheet' ), __( 'year', 'timesheet' ) ); $this->date_formats = array( 'wp' => get_option( 'date_format' ), 'custom' => $this->options['date_format'], ); $this->all_roles = get_editable_roles(); ksort( $this->all_roles ); add_filter( get_parent_class( $this ) . '_additional_restore_options', array( $this, 'additional_restore_options' ) ); add_action( get_parent_class( $this ) . '_display_metabox', array( $this, 'display_metabox' ) ); add_action( get_parent_class( $this ) . '_additional_misc_options_affected', array( $this, 'additional_misc_options_affected' ) ); } /** * Save plugin options to the database * * @access public * @return array The action results */ public function save_options() { global $wpdb; $message = ''; $notice = ''; $error = ''; if ( isset( $_POST['tmsht_nonce_field'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['tmsht_nonce_field'] ) ), 'tmsht_action' ) ) { /* Takes all the changed settings on the plugin's admin page and saves them in array 'tmsht_options'. */ if ( isset( $_POST['tmsht_add_ts_legend'] ) ) { $ts_legend_name = ( isset( $_POST['tmsht_add_ts_legend_name'] ) ) ? sanitize_text_field( wp_unslash( $_POST['tmsht_add_ts_legend_name'] ) ) : ''; $ts_legend_color = ( isset( $_POST['tmsht_add_ts_legend_color'] ) ) ? sanitize_text_field( wp_unslash( $_POST['tmsht_add_ts_legend_color'] ) ) : ''; if ( empty( $ts_legend_name ) ) { $error = __( 'Please enter status name.', 'timesheet' ); } if ( ! preg_match( '/^#?([a-f0-9]{6}|[a-f0-9]{3})$/', $ts_legend_color ) ) { if ( empty( $error ) ) { $error .= '
' . __( 'Please choose status color.', 'timesheet' ); } else { $error .= __( 'Please choose status color.', 'timesheet' ); } } if ( empty( $error ) && $wpdb->get_var( $wpdb->prepare( "SELECT `id` FROM `{$wpdb->prefix}tmsht_legends` WHERE `name` = %s OR `color` = %s", $ts_legend_name, $ts_legend_color ) ) ) { $error = sprintf( __( 'Status with name "%1$s" or with color %2$s already exists.', 'timesheet' ), $ts_legend_name, $ts_legend_color ); } if ( empty( $error ) && in_array( $ts_legend_color, array( '#ffffff', '#f9f9f9' ) ) ) { $error = sprintf( __( 'The status with the color %s can not be saved. Please choose a different color.', 'timesheet' ), $ts_legend_color ); } if ( empty( $error ) ) { $query_results = $wpdb->insert( $wpdb->prefix . 'tmsht_legends', array( 'name' => $ts_legend_name, 'color' => $ts_legend_color, ), array( '%s', '%s' ) ); if ( $query_results ) { unset( $ts_legend_name, $ts_legend_color ); $message = __( 'Status has been successfully added.', 'timesheet' ); } else { $error = __( 'Status has not been added.', 'timesheet' ); } } else { $error .= '
' . __( 'Status has not been added.', 'timesheet' ); } } else { /* Set timeline */ $this->options['ts_timeline_from'] = ( isset( $_POST['tmsht_ts_timeline_from'] ) && $_POST['tmsht_ts_timeline_from'] >= 0 && $_POST['tmsht_ts_timeline_from'] <= 23 ) ? intval( $_POST['tmsht_ts_timeline_from'] ) : 0; $this->options['ts_timeline_to'] = ( isset( $_POST['tmsht_ts_timeline_to'] ) && $_POST['tmsht_ts_timeline_to'] <= 24 && $_POST['tmsht_ts_timeline_to'] >= 1 ) ? intval( $_POST['tmsht_ts_timeline_to'] ) : 24; if ( $this->options['ts_timeline_from'] == $this->options['ts_timeline_to'] ) { if ( $this->options['ts_timeline_to'] < 24 ) { $this->options['ts_timeline_to']++; } else { $this->options['ts_timeline_from']--; } } /* Set weekends */ if ( ! empty( $_POST['tmsht_weekends'] ) ) { $tmsht_weekends = (array) $_POST['tmsht_weekends']; foreach ( $tmsht_weekends as $weekend ) { if ( ! in_array( ucfirst( $weekend ), $this->days_arr ) ) { unset( $weekend ); } } $this->options['weekends'] = array_map( 'sanitize_text_field', array_map( 'wp_unslash', $tmsht_weekends ) ); } else { $this->options['weekends'] = array(); } /*Set clear period*/ if ( isset( $_POST['tmsht_clear_timesheet_period'] ) && in_array( $_POST['tmsht_clear_timesheet_period'], $this->period_arr ) ) { $this->options['clear_timesheet_period'] = sanitize_text_field( wp_unslash( $_POST['tmsht_clear_timesheet_period'] ) ); if ( ! wp_next_scheduled( 'tmsht_clear_period_timesheet' ) ) { wp_schedule_event( time(), 'tmsht_weekly', 'tmsht_clear_period_timesheet' ); } } else { $this->options['clear_timesheet_period'] = ''; wp_clear_scheduled_hook( 'tmsht_clear_period_timesheet' ); } /* Enable/disable legends */ $ts_legend_ids = ( isset( $_POST['tmsht_ts_legend_id'] ) && is_array( $_POST['tmsht_ts_legend_id'] ) ) ? array_map( 'intval', $_POST['tmsht_ts_legend_id'] ) : array(); $ts_legend_all_days = ( isset( $_POST['tmsht_ts_legend_all_day'] ) && is_array( $_POST['tmsht_ts_legend_all_day'] ) ) ? array_map( 'intval', $_POST['tmsht_ts_legend_all_day'] ) : array(); $ts_legend_ids_hidden = ( isset( $_POST['tmsht_ts_legend_id_hidden'] ) && is_array( $_POST['tmsht_ts_legend_id_hidden'] ) ) ? array_map( 'intval', $_POST['tmsht_ts_legend_id_hidden'] ) : array(); foreach ( $ts_legend_ids_hidden as $legend_id ) { $color = ( isset( $_POST['tmsht_ts_legend_color'][ $legend_id ] ) && preg_match( '/^#?([a-f0-9]{6}|[a-f0-9]{3})$/', trim( sanitize_text_field( wp_unslash( $_POST['tmsht_ts_legend_color'][ $legend_id ] ) ) ) ) ) ? trim( sanitize_text_field( wp_unslash( $_POST['tmsht_ts_legend_color'][ $legend_id ] ) ) ) : false; $disabled = ( ! in_array( $legend_id, $ts_legend_ids ) ) ? 1 : 0; $all_day = ( ! in_array( $legend_id, $ts_legend_all_days ) ) ? 0 : 1; if ( $color ) { $wpdb->update( $wpdb->prefix . 'tmsht_legends', array( 'color' => $color, 'disabled' => $disabled, 'all_day' => $all_day, ), array( 'id' => $legend_id ), array( '%s', '%d', '%d' ) ); } else { $wpdb->update( $wpdb->prefix . 'tmsht_legends', array( 'disabled' => $disabled, 'all_day' => $all_day, ), array( 'id' => $legend_id ), array( '%d', '%d' ) ); } } /* Set date format */ if ( isset( $_POST['tmsht_date_format_type'] ) ) { switch ( $_POST['tmsht_date_format_type'] ) { case 'custom': $this->options['date_format_type'] = sanitize_text_field( wp_unslash( $_POST['tmsht_date_format_type'] ) ); $this->options['date_format'] = ( isset( $_POST['tmsht_date_format_code'] ) ) ? trim( sanitize_text_field( wp_unslash( $_POST['tmsht_date_format_code'] ) ) ) : ''; break; case 'wp': $this->options['date_format_type'] = $_POST['tmsht_date_format_type']; $this->options['date_format'] = get_option( 'date_format' ); break; default: break; } } $this->options['edit_past_days'] = ( ! empty( $_POST['tmsht_edit_past_days'] ) ) ? 1 : 0; $this->options['reminder_on_email'] = ( ! empty( $_POST['tmsht_reminder_on_email'] ) ) ? 1 : 0; $this->options['day_reminder'] = ( isset( $_POST['tmsht_day_reminder'] ) && in_array( ucfirst( sanitize_text_field( wp_unslash( $_POST['tmsht_day_reminder'] ) ) ), $this->days_arr ) ) ? sanitize_text_field( wp_unslash( $_POST['tmsht_day_reminder'] ) ) : $this->default_options['day_reminder']; $this->options['time_reminder'] = ( isset( $_POST['tmsht_time_reminder'] ) && preg_match( '/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/', sanitize_text_field( wp_unslash( $_POST['tmsht_time_reminder'] ) ) ) ) ? sanitize_text_field( wp_unslash( $_POST['tmsht_time_reminder'] ) ) : $this->default_options['time_reminder']; if ( isset( $_POST['tmsht_reminder_change_state'] ) ) { wp_clear_scheduled_hook( 'tmsht_reminder_to_email' ); if ( $this->options['reminder_on_email'] ) { if ( ! wp_next_scheduled( 'tmsht_reminder_to_email' ) ) { $current_offset = get_option( 'gmt_offset' ); $tzstring = get_option( 'timezone_string' ); /* Remove old Etc mappings. Fallback to gmt_offset. */ if ( false !== strpos( $tzstring, 'Etc/GMT' ) ) { $tzstring = ''; } /* Create a UTC+- zone if no timezone string exists */ if ( empty( $tzstring ) ) { if ( 0 == $current_offset ) { $tzstring = '+0'; } elseif ( $current_offset < 0 ) { $tzstring = $current_offset; } else { $tzstring = '+' . $current_offset; } } $time = strtotime( sprintf( '%s %s:00 %s', ucfirst( $this->options['day_reminder'] ), $this->options['time_reminder'], $tzstring ) ); if ( time() > $time ) { $time = strtotime( sprintf( '%s %s:00 %s +1 week', ucfirst( $this->options['day_reminder'] ), $this->options['time_reminder'], $tzstring ) ); } wp_schedule_event( $time, 'tmsht_weekly', 'tmsht_reminder_to_email' ); } } } $this->options['content_reminder']['subject'] = ( isset( $_POST['tmsht_reminder_subject'] ) ) ? wp_strip_all_tags( wp_kses_post( $_POST['tmsht_reminder_subject'] ) ) : $this->default_options['content_reminder']['subject']; $this->options['content_reminder']['message'] = ( isset( $_POST['tmsht_reminder_message'] ) ) ? wp_strip_all_tags( wp_kses_post( $_POST['tmsht_reminder_message'] ) ) : $this->default_options['content_reminder']['message']; /* Display TS user page for */ $display_ts_user_page_for = ( isset( $_POST['tmsht_display_ts_user_page_for'] ) && is_array( $_POST['tmsht_display_ts_user_page_for'] ) ) ? $_POST['tmsht_display_ts_user_page_for'] : array(); $tmsht_ts_user_roles = array(); foreach ( $display_ts_user_page_for as $role ) { if ( array_key_exists( $role, $this->all_roles ) ) { $tmsht_ts_user_roles[] = sanitize_text_field( wp_unslash( $role ) ); } } $this->options['display_pages']['ts_user']['user_roles'] = $tmsht_ts_user_roles; /* Display TS report page for */ $display_ts_report_page_for = ( isset( $_POST['tmsht_display_ts_report_page_for'] ) && is_array( $_POST['tmsht_display_ts_report_page_for'] ) ) ? $_POST['tmsht_display_ts_report_page_for'] : array(); $ts_report_roles = array(); foreach ( $display_ts_report_page_for as $role ) { if ( array_key_exists( $role, $this->all_roles ) ) { $ts_report_roles[] = sanitize_text_field( wp_unslash( $role ) ); } } $this->options['display_pages']['ts_report']['user_roles'] = $ts_report_roles; /* Save settings if no errors */ if ( empty( $error ) ) { update_option( 'tmsht_options', $this->options ); $message = __( 'Settings saved.', 'timesheet' ); } } } return compact( 'message', 'notice', 'error' ); } /** * Displays 'settings' menu-tab * * @access public */ public function tab_settings() { global $wpdb; $legends = $wpdb->get_results( 'SELECT * FROM `' . $wpdb->prefix . 'tmsht_legends`', ARRAY_A ); ?>

help_phrase(); ?>
days_arr as $day ) { ?>

/> />
date_formats['custom'] ) ); ?>
.
options['edit_past_days'], 1 ); ?> />

help_phrase(); ?>
    

:
{user_name} -
{list_days} -
{ts_page} -
{ts_page_link}Your text{/ts_page_link} -

help_phrase(); ?>
    all_roles as $role => $details ) { $users_in_role = $wpdb->get_results( $wpdb->prepare( 'SELECT users.ID, users.user_login FROM `' . $wpdb->base_prefix . 'users` AS users, `' . $wpdb->base_prefix . 'usermeta` AS umeta WHERE users.ID = umeta.user_id AND umeta.meta_key = %s AND umeta.meta_value LIKE %s ORDER BY users.ID ASC LIMIT 3', $wpdb->prefix . 'capabilities', '%' . $role . '%' ), OBJECT_K ); if ( 'administrator' == $role && $this->is_multisite && ! is_main_site() ) { $super_admins = get_super_admins(); foreach ( $super_admins as $super_admin ) { $get_user = get_user_by( 'login', $super_admin ); if ( $get_user ) { $add_user = array( 'ID' => $get_user->ID, 'user_login' => $get_user->user_login, ); $users_in_role[ $get_user->ID ] = (object) $add_user; } } } ksort( $users_in_role ); if ( count( $users_in_role ) > 0 ) { $checked_attr = ( in_array( $role, $this->options['display_pages']['ts_user']['user_roles'] ) ) ? 'checked="checked"' : ''; ?>
  • hide_pro_tabs ) { ?>
    bws_pro_block_links(); ?>
    all_roles as $role => $details ) { $users_in_role = $wpdb->get_results( $wpdb->prepare( 'SELECT users.ID, users.user_login FROM `' . $wpdb->base_prefix . 'users` AS users, `' . $wpdb->base_prefix . 'usermeta` AS umeta WHERE users.ID = umeta.user_id AND umeta.meta_key = %s AND umeta.meta_value LIKE %s ORDER BY users.ID ASC LIMIT 3', $wpdb->prefix . 'capabilities', '%' . $role . '%' ), OBJECT_K ); if ( 'administrator' == $role && $this->is_multisite && ! is_main_site() ) { $super_admins = get_super_admins(); foreach ( $super_admins as $super_admin ) { $get_user = get_user_by( 'login', $super_admin ); if ( $get_user ) { $add_user = array( 'ID' => $get_user->ID, 'user_login' => $get_user->user_login, ); $users_in_role[ $get_user->ID ] = (object) $add_user; } } } ksort( $users_in_role ); if ( count( $users_in_role ) > 0 ) { $checked_attr = ( in_array( $role, $this->options['display_pages']['ts_report']['user_roles'] ) ) ? 'checked="checked"' : ''; ?>
  • hide_pro_tabs ) { ?>
    bws_pro_block_links(); ?>
hide_pro_tabs ) { ?>
    all_roles as $role => $details ) { if ( count( $users_in_role ) > 0 ) { ?>
bws_pro_block_links(); ?>

help_phrase(); ?>

:

    
bws_pro_block_links(); ?>

help_phrase(); ?>
<







bws_pro_block_links(); ?>
hide_pro_tabs ) { ?>

bws_pro_block_links(); ?>
query( 'DROP TABLE `' . $wpdb->prefix . 'tmsht_legends`' ); tmsht_create_tables(); return $default_options; } } }