ID ) ) { if ( in_array( 'administrator', $tmsht_options['display_pages']['ts_user']['user_roles'] ) ) { $display_timesheet_page = true; } } else { foreach ( $current_user->caps as $role => $value ) { if ( in_array( $role, $tmsht_options['display_pages']['ts_user']['user_roles'] ) ) { $display_timesheet_page = true; break; } } } if ( $display_timesheet_page ) { if ( isset( $submenu['timesheet_settings'] ) ) $ts_user_page_hook = add_submenu_page( 'timesheet_settings', 'Timesheet', 'Timesheet', 'read', 'timesheet_ts_user', 'tmsht_ts_user_page' ); else $ts_user_page_hook = add_menu_page( 'Timesheet', 'Timesheet', 'read', 'timesheet_ts_user', 'tmsht_ts_user_page', 'dashicons-clock' ); add_action( 'load-' . $ts_user_page_hook, 'tmsht_add_tabs' ); } } if ( isset( $tmsht_options['display_pages']['ts_report']['user_roles'] ) ) { $display_report_page = false; if ( is_multisite() && is_super_admin( $current_user->ID ) ) { if ( in_array( 'administrator', $tmsht_options['display_pages']['ts_user']['user_roles'] ) ) { $display_report_page = true; } } else { foreach ( $current_user->caps as $role => $value ) { if ( in_array( $role, $tmsht_options['display_pages']['ts_report']['user_roles'] ) ) { $display_report_page = true; break; } } } if ( $display_report_page ) { if ( isset( $ts_user_page_hook ) || isset( $submenu['timesheet_settings'] ) ) { $parent_page = isset( $submenu['timesheet_settings'] ) ? 'timesheet_settings' : 'timesheet_ts_user'; $ts_report_page_hook = add_submenu_page( $parent_page, __( 'Reports', 'timesheet' ), __( 'Reports', 'timesheet' ), 'read', 'timesheet_ts_report', 'tmsht_ts_report_page' ); } else { $ts_report_page_hook = add_menu_page( 'Timesheet ' . __( 'Reports', 'timesheet' ), 'Timesheet', 'read', 'timesheet_ts_report', 'tmsht_ts_report_page', 'dashicons-clock' ); } add_action( 'load-' . $ts_report_page_hook, 'tmsht_add_tabs' ); } } add_submenu_page( 'timesheet_settings', 'BWS Panel', 'BWS Panel', 'manage_options', 'tmsht-bws-panel', 'bws_add_menu_render' ); if ( isset( $submenu['timesheet_settings'] ) ) $submenu['timesheet_settings'][] = array( ' ' . __( 'Upgrade to Pro', 'timesheet' ) . '', 'manage_options', 'https://bestwebsoft.com/products/wordpress/plugins/timesheet/?k=3bdf25984ad6aa9d95074e31c5eb9bb3&pn=606&v=' . $tmsht_plugin_info["Version"] . '&wp_v=' . $wp_version ); add_action( 'load-' . $settings_page_hook, 'tmsht_add_tabs' ); } } /* add help tab */ if ( ! function_exists( 'tmsht_add_tabs' ) ) { function tmsht_add_tabs() { $screen = get_current_screen(); $args = array( 'id' => 'tmsht', 'section' => '202101246' ); bws_help_tab( $screen, $args ); } } if ( ! function_exists( 'tmsht_plugins_loaded' ) ) { function tmsht_plugins_loaded() { /* Internationalization */ load_plugin_textdomain( 'timesheet', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' ); } } if ( ! function_exists( 'tmsht_init' ) ) { function tmsht_init() { global $tmsht_plugin_info; $plugin_basename = plugin_basename( __FILE__ ); require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); bws_include_init( $plugin_basename ); if ( empty( $tmsht_plugin_info ) ) { if ( ! function_exists( 'get_plugin_data' ) ) { require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); } $tmsht_plugin_info = get_plugin_data( __FILE__ ); } /* check WordPress version */ bws_wp_min_version_check( $plugin_basename, $tmsht_plugin_info, '3.9' ); if ( is_admin() ) tmsht_register_options(); } } if ( ! function_exists( 'tmsht_admin_init' ) ) { function tmsht_admin_init() { global $bws_plugin_info, $tmsht_plugin_info; /* Add variable for bws_menu */ if ( empty( $bws_plugin_info ) ) $bws_plugin_info = array( 'id' => '606', 'version' => $tmsht_plugin_info["Version"] ); } } if ( ! function_exists( 'tmsht_create_tables' ) ) { function tmsht_create_tables() { global $wpdb; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); /* Table with legends */ if ( ! $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}tmsht_legends';" ) ) { $sql = "CREATE TABLE `{$wpdb->prefix}tmsht_legends` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `color` char(7) NOT NULL, `disabled` BOOLEAN NOT NULL DEFAULT '0', PRIMARY KEY ( `id` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; dbDelta( $sql ); $default_legends = array( array( 'id' => 1, 'name' => __( 'In Office', 'timesheet' ), 'color' => '#94e091', 'disabled' => 0 ), array( 'id' => 2, 'name' => __( 'Remote', 'timesheet' ), 'color' => '#eded76', 'disabled' => 0 ), array( 'id' => 3, 'name' => __( 'Absent', 'timesheet' ), 'color' => '#dd8989', 'disabled' => 0 ), array( 'id' => 4, 'name' => __( 'Vacation', 'timesheet' ), 'color' => '#8da6bf', 'disabled' => 0 ), ); foreach ( $default_legends as $legend ) { $wpdb->insert( "{$wpdb->prefix}tmsht_legends", array( 'id' => $legend['id'], 'name' => $legend['name'], 'color' => $legend['color'], 'disabled' => $legend['disabled'] ), array( '%d', '%s', '%s', '%d' ) ); } } /* Table with ts */ if ( ! $wpdb->query( "SHOW TABLES LIKE '{$wpdb->prefix}tmsht_ts';" ) ) { $sql = "CREATE TABLE `{$wpdb->prefix}tmsht_ts` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT, `user_id` bigint(20) NOT NULL, `time_from` datetime NOT NULL, `time_to` datetime NOT NULL, `legend_id` int(10) NOT NULL, PRIMARY KEY ( `id` ) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;"; dbDelta( $sql ); } } } if ( ! function_exists( 'tmsht_register_options' ) ) { function tmsht_register_options() { global $tmsht_plugin_info, $tmsht_options; $update_option = false; $db_version = '0.1'; if ( ! get_option( 'tmsht_options' ) ) { $default_options = tmsht_get_options_default(); add_option( 'tmsht_options', $default_options ); } $tmsht_options = get_option( 'tmsht_options' ); /* Array merge incase this version has added new options */ if ( ! isset( $tmsht_options['plugin_option_version'] ) || $tmsht_options['plugin_option_version'] != $tmsht_plugin_info["Version"] ) { $default_options = tmsht_get_options_default(); $tmsht_options = array_merge( $default_options, $tmsht_options ); $tmsht_options['plugin_option_version'] = $tmsht_plugin_info["Version"]; $update_option = true; } /* Update tables when update plugin and tables changes*/ if ( ! isset( $tmsht_options['plugin_db_version'] ) || $tmsht_options['plugin_db_version'] != $db_version ) { tmsht_create_tables(); /* update DB version */ $tmsht_options['plugin_db_version'] = $db_version; $update_option = true; } if ( $update_option ) { update_option( 'tmsht_options', $tmsht_options ); } } } if ( ! function_exists( 'tmsht_get_options_default' ) ) { function tmsht_get_options_default() { global $tmsht_plugin_info; if ( ! function_exists( 'get_editable_roles' ) ) require_once( ABSPATH . 'wp-admin/includes/user.php' ); $user_roles = array_keys( get_editable_roles() ); $default_options = array( 'plugin_option_version' => $tmsht_plugin_info["Version"], 'display_settings_notice' => 1, 'suggest_feature_banner' => 1, 'ts_timeline_from' => 0, 'ts_timeline_to' => 24, 'weekends' => array( 'sat', 'sun' ), 'edit_past_days' => 0, 'date_format_type' => 'wp', 'date_format' => get_option( 'date_format' ), 'display_pages' => array( 'ts_user' => array( 'user_roles' => $user_roles, 'user_ids' => array(), 'has_sub_exception' => array() ), 'ts_report' => array( 'user_roles' => array( 'administrator' ), 'user_ids' => array(), 'has_sub_exception' => array() ) ), 'reminder_on_email' => 0, 'day_reminder' => 'fri', 'time_reminder' => '18:00', 'content_reminder' => array( 'subject' => __( 'Timesheet Reminder', 'timesheet' ), 'message' => sprintf( "%s, {user_name},\n\n%s:\n\n{list_days}\n\n{{ts_page_link}%s{/ts_page_link}}\n\n%s", __( 'Hi', 'timesheet' ), __( 'Please complete your timesheet for the following days', 'timesheet' ), __( 'Complete Timesheet Now', 'timesheet' ), __( 'Do not reply to this message. This is an automatic mailing.', 'timesheet' ) ) ), 'first_install' => strtotime( "now" ) ); return $default_options; } } if ( ! function_exists( 'tmsht_plugin_activate' ) ) { function tmsht_plugin_activate() { if ( is_multisite() ) { switch_to_blog( 1 ); register_uninstall_hook( __FILE__, 'tmsht_unistall' ); restore_current_blog(); } else { register_uninstall_hook( __FILE__, 'tmsht_unistall' ); } } } if ( ! function_exists( 'tmsht_admin_scripts_styles' ) ) { function tmsht_admin_scripts_styles() { global $tmsht_plugin_info; if ( isset( $_GET['page'] ) ) { if ( $_GET['page'] == 'timesheet_settings' ) { wp_enqueue_script( 'ts_settings_script', plugins_url( 'js/settings.js', __FILE__ ), array( 'jquery', 'jquery-ui-slider', 'wp-color-picker' ), $tmsht_plugin_info['Version'] ); wp_enqueue_style( 'wp-color-picker' ); wp_enqueue_style( 'jquery-ui', plugins_url( 'css/jquery-ui.css', __FILE__ ), false ); wp_enqueue_style( 'ts_settings_styles', plugins_url( 'css/settings.css', __FILE__ ), false, $tmsht_plugin_info['Version'] ); bws_enqueue_settings_scripts(); } elseif ( $_GET['page'] == 'timesheet_ts_user' || $_GET['page'] == 'timesheet_ts_report' ) { wp_register_script( 'tmsht_datetimepicker_script', plugins_url( 'js/jquery.datetimepicker.full.min.js', __FILE__ ), array( 'jquery' ) ); wp_enqueue_style( 'tmsht_datetimepicker_styles', plugins_url( 'css/jquery.datetimepicker.css', __FILE__ ), false ); if ( $_GET['page'] == 'timesheet_ts_user' ) { wp_enqueue_script( 'tmsht_script', plugins_url( 'js/ts_user_script.js', __FILE__ ), array( 'jquery', 'jquery-ui-selectable', 'jquery-touch-punch', 'tmsht_datetimepicker_script' ), $tmsht_plugin_info['Version'] ); wp_enqueue_style( 'tmsht_styles', plugins_url( 'css/ts_user_styles.css', __FILE__ ), false, $tmsht_plugin_info['Version'] ); } else { wp_enqueue_script( 'tmsht_script', plugins_url( 'js/ts_report_script.js', __FILE__ ), array( 'jquery', 'tmsht_datetimepicker_script' ), $tmsht_plugin_info['Version'] ); wp_enqueue_style( 'tmsht_styles', plugins_url( 'css/ts_report_styles.css', __FILE__ ), false, $tmsht_plugin_info['Version'] ); } $locale = explode( '_', get_locale() ); $datetime_options = array( 'locale' => $locale[0], 'dayOfWeekStart' => get_option( 'start_of_week' ) ); wp_localize_script( 'tmsht_script', 'tmsht_datetime_options', $datetime_options ); } } } } if ( ! function_exists( 'tmsht_generate_color' ) ) { function tmsht_generate_color() { global $wpdb; $wrong_colors = $wpdb->get_col( "SELECT `color` FROM `{$wpdb->prefix}tmsht_legends`" ); $wrong_colors = array_merge( $wrong_colors, array( '#ffffff', '#f9f9f9' ) ); while (1) { $color = sprintf( "#%06x", rand( 0,16777215 ) ); if ( ! in_array( $color, $wrong_colors ) ) { break; } } return $color; } } if ( ! function_exists( 'tmsht_settings_page' ) ) { function tmsht_settings_page() { require_once( dirname( __FILE__ ) . '/includes/class-tmsht-settings.php' ); $page = new Tmsht_Settings_Tabs( plugin_basename( __FILE__ ) ); ?>

Timesheet

display_content(); ?>
get_results( "SELECT * FROM `{$wpdb->prefix}tmsht_legends`", OBJECT_K ); /* Convert stdClass items of array( $tmsht_legends ) to associative array */ $tmsht_legends = json_decode( json_encode( $tmsht_legends ), true ); $tmsht_legends[-1] = array( 'name' => __( 'Please select...', 'timesheet' ), 'color' => 'transparent', 'disabled' => 0 ); ksort( $tmsht_legends ); if ( isset( $_POST['tmsht_save_ts'] ) && check_admin_referer( 'tmsht_nonce_save_ts', 'tmsht_nonce_name' ) ) { if ( isset( $_POST['tmsht_tr_date'] ) && is_array( $_POST['tmsht_tr_date'] ) ) { foreach ( $_POST['tmsht_tr_date'] as $tr_date ) { if ( date( 'Y-m-d', strtotime( $tr_date ) ) < date( 'Y-m-d' ) && $tmsht_options['edit_past_days'] == 0 ) { continue; } $query_results = $wpdb->query( $wpdb->prepare( "DELETE FROM `{$wpdb->prefix}tmsht_ts` WHERE `user_id` = %d AND date(`time_from`) = %s", $current_user->ID, $tr_date ) ); if ( $query_results === false ) { $error = __( 'Data has not been saved.', 'timesheet' ); break; } if ( isset( $_POST['tmsht_to_db'][ $tr_date ] ) && is_array( $_POST['tmsht_to_db'][ $tr_date ] ) ) { foreach ( $_POST['tmsht_to_db'][ $tr_date ] as $ts_interval ) { $ts_interval_arr = explode( '@', $ts_interval ); $ts_interval_from = $ts_interval_arr[0]; $ts_interval_to = $ts_interval_arr[1]; $legend_id = $ts_interval_arr[2]; if ( strtotime( $ts_interval_from ) && strtotime( $ts_interval_to ) && array_key_exists( $legend_id, $tmsht_legends ) ) { $query_results = $wpdb->insert( "{$wpdb->prefix}tmsht_ts", array( 'user_id' => $current_user->ID, 'time_from' => $ts_interval_from, 'time_to' => $ts_interval_to, 'legend_id' => $legend_id ), array( '%d', '%s', '%s', '%d' ) ); if ( $query_results === false ) { $error = __( 'Data has not been saved.', 'timesheet' ); break; } } } } } if ( $error == '' ) { $message = __( 'Data has been saved.', 'timesheet' ); } } else { $error = __( 'Data has not been saved, because there was no change.', 'timesheet' ); } } $ts_data = $wpdb->get_results( "SELECT `time_from`, `time_to`, `legend_id` FROM `{$wpdb->prefix}tmsht_ts` WHERE date(`time_from`) >= '" . $date_from ."' AND date(`time_to`) <= '" . $date_to . "' AND `user_id` = '" . $current_user->ID . "'", ARRAY_A ); foreach ( $ts_data as $key => $value ) { $new_key = date( 'Y-m-d', strtotime( $value['time_from'] ) ); $ts_data[ $new_key ][] = $value; unset( $ts_data[ $key ] ); } $bws_hide_premium_options_check = bws_hide_premium_options_check( $tmsht_options ); ?>

Timesheet

>

>

 
9 ) ? $time_value : ' ' . $time_value ; ?>
" data-td-time-to="">
$td_datetime ) { $td_legend_id = $data['legend_id']; $time_to_adjustment = ( date( 'i', strtotime( $data['time_to'] ) ) == 59 ) ? '24:00' : date( 'H:i', strtotime( $data['time_to'] ) ); $td_title = sprintf( "%s (%s - %s)", $tmsht_legends[ $td_legend_id ]['name'], date( 'H:i', strtotime( $data['time_from'] ) ), $time_to_adjustment ); } } } ?>
" data-fill-time-to="" data-legend-id="" title="">
9 ) ? $time_value : ' ' . $time_value ; ?>
$ts_legend ) { if ( $ts_legend_id < 0 ) { continue; } ?>
get_results( "SELECT {$data} FROM `{$wpdb->base_prefix}users` AS users, `{$wpdb->base_prefix}usermeta` AS umeta WHERE users.ID = umeta.user_id AND umeta.meta_key = '{$wpdb->prefix}capabilities' AND ({$users_in_role_query}) ORDER BY users.user_login ASC", OBJECT_K ); if ( ! empty( $users_in_role ) ) { foreach ( $users_in_role as $user_data ) { if ( $add_additional_data ) { $users[ $user_data->ID ] = array( 'display_name' => $user_data->display_name, 'email' => $user_data->user_email ); } else { $users[ $user_data->ID ] = $user_data->user_login; } } } if ( in_array( 'administrator', $tmsht_options['display_pages']['ts_user']['user_roles'] ) && 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 && ! array_key_exists( $get_user->ID, $users ) ) { if ( $add_additional_data ) { $users[ $get_user->ID ] = array( 'display_name' => $get_user->display_name, 'user_email' => $get_user->user_email ); } else { $users[ $get_user->ID ] = $get_user->user_login; } } } } } return $users; } } /** * Function array_replace (PHP 5 >= 5.3.0, PHP 7) * * @since 0.1.6 * * @param array * @param array * @return array */ if ( ! function_exists( 'tmsht_array_replace' ) ) { function tmsht_array_replace( $array1, $array2 ) { if ( function_exists( 'array_replace' ) ) { return array_replace( $array1, $array2 ); } else { foreach ( $array2 as $key => $value ) { $array1[ $key ] = $value; } return $array1; } } } if ( ! function_exists( 'tmsht_ts_report_page' ) ) { function tmsht_ts_report_page() { global $wpdb, $tmsht_options, $current_user, $tmsht_legends; $message = $error = ""; $week_days_arr = array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ); $day_of_week_start = get_option( 'start_of_week' ); $date_preset_quantity_arr = array( 1, 2, 3 ); $date_preset_units_arr = array( 'week' => __( 'Week', 'timesheet' ), 'month' => __( 'Month', 'timesheet' ) ); $ts_report_group_by_arr = array( 'date' => _x( 'Date', 'Group by', 'timesheet' ), 'user' => _x( 'User', 'Group by', 'timesheet' ) ); $ts_report_view = array( 'hourly' => __( 'Hourly', 'timesheet' ), 'daily' => __( 'Daily', 'timesheet' ) ); /* Get legends */ $tmsht_legends = $wpdb->get_results( "SELECT * FROM `{$wpdb->prefix}tmsht_legends`", OBJECT_K ); /* Convert stdClass items of array( $tmsht_legends ) to associative array */ $tmsht_legends = json_decode( json_encode( $tmsht_legends ), true ); $tmsht_legends[-1] = array( 'name' => __( 'Blank', 'timesheet' ), 'color' => 'transparent', 'disabled' => 1 ); $tmsht_legends[-2] = array( 'name' => __( 'All statuses', 'timesheet' ), 'color' => '#444444', 'disabled' => 0 ); ksort( $tmsht_legends ); /* Get users */ $tmsht_users = tmsht_get_users(); /* Get user meta */ $ts_report_filters = get_user_meta( $current_user->ID, '_tmsht_ts_report_filters', true ); if ( empty( $ts_report_filters ) ) { $ts_report_filters = array( 'date' => array( 'type' => 'period', 'preset' => array() ), 'group_by' => 'date', 'view' => 'hourly', 'legend' => -2, 'users' => array_keys( $tmsht_users ), ); add_user_meta( $current_user->ID, '_tmsht_ts_report_filters', $ts_report_filters ); /** * @deprecated since 0.1.6 * @todo remove after 21.12.2017 */ } else if ( ! isset( $ts_report_filters['view'] ) ) { $ts_report_filters['view'] = 'hourly'; update_user_meta( $current_user->ID, '_tmsht_ts_report_filters', $ts_report_filters ); /*end @todo */ } /* Apply filters */ if ( isset( $_POST['tmsht_generate_ts_report'] ) ) { if ( ( isset( $_POST['tmsht_date_filter_type'] ) && $_POST['tmsht_date_filter_type'] == 'preset' ) && ( isset( $_POST['tmsht_date_preset_unit'] ) && array_key_exists( $_POST['tmsht_date_preset_unit'], $date_preset_units_arr ) ) && isset( $_POST['tmsht_date_preset_quantity'] ) ) { $ts_report_filters['date'] = array( 'type' => 'preset', 'preset' => array( 'quantity' => intval( $_POST['tmsht_date_preset_quantity'] ), 'unit' => $_POST['tmsht_date_preset_unit'] ) ); } else { $ts_report_filters['date'] = array( 'type' => 'period', 'preset' => array() ); } $ts_report_filters['group_by'] = ( array_key_exists( $_POST['tmsht_ts_report_group_by'], $ts_report_group_by_arr ) ) ? $_POST['tmsht_ts_report_group_by'] : 'date'; $ts_report_filters['legend'] = ( array_key_exists( $_POST['tmsht_ts_report_legend'], $tmsht_legends ) ) ? $_POST['tmsht_ts_report_legend'] : -2; $ts_report_filters['view'] = ( -2 != $ts_report_filters['legend'] && array_key_exists( $_POST['tmsht_ts_report_view'], $ts_report_view ) ) ? $_POST['tmsht_ts_report_view'] : 'hourly'; $ts_report_filters['users'] = ( isset( $_POST['tmsht_ts_report_user'] ) && is_array( $_POST['tmsht_ts_report_user'] ) ) ? $_POST['tmsht_ts_report_user'] : array_keys( $tmsht_users ); update_user_meta( $current_user->ID, '_tmsht_ts_report_filters', $ts_report_filters ); } /* Report generation */ $date_from = $filter_date_from = ( isset( $_POST['tmsht_ts_report_date_from'] ) && strtotime( $_POST['tmsht_ts_report_date_from'] ) && $ts_report_filters['date']['type'] == 'period' ) ? $_POST['tmsht_ts_report_date_from'] : date( 'Y-m-d' ); $date_to = $filter_date_to = ( isset( $_POST['tmsht_ts_report_date_to'] ) && strtotime( $_POST['tmsht_ts_report_date_to'] ) && $ts_report_filters['date']['type'] == 'period' ) ? $_POST['tmsht_ts_report_date_to'] : date( 'Y-m-d', strtotime( "next " . $week_days_arr[ $day_of_week_start ] . " +6 days" ) ); if ( $ts_report_filters['date']['type'] == 'preset' ) { $date_from = date( 'Y-m-d' ); $date_to = date( 'Y-m-d', strtotime( "+" . $ts_report_filters['date']['preset']['quantity'] . " " . $ts_report_filters['date']['preset']['unit'] ) ); } $date_period = tmsht_date_period( $date_from, date( 'Y-m-d', strtotime( $date_to . ' +1 day' ) ) ); $selected_users = array(); foreach ( $ts_report_filters['users'] as $user_id ) { if ( array_key_exists( $user_id, $tmsht_users ) ) { $selected_users[] = $user_id; } } $ts_data = array(); if ( $selected_users ) { $ts_data_query = ( 'hourly' == $ts_report_filters['view'] ) ? "SELECT `user_id`, `time_from`, `time_to`, `legend_id`" : "SELECT `user_id`, DATE_FORMAT( `time_from`, '%Y-%m-%d' ) AS `date`"; $ts_data_query .= " FROM `{$wpdb->prefix}tmsht_ts` WHERE date(`time_from`) >= '" . $date_from . "' AND date(`time_to`) <= '" . $date_to . "'"; if ( $ts_report_filters['legend'] > 0 ) $ts_data_query .= " AND `legend_id` = '" . $ts_report_filters['legend'] . "'"; $ts_data_query .= " AND `user_id` IN (" . implode( ',', $selected_users ) . ")"; if ( 'hourly' != $ts_report_filters['view'] ) $ts_data_query .= " GROUP BY `user_id`, DAY(`time_from`)"; $ts_data_query .= " ORDER BY `user_id` ASC, `time_from` ASC"; $ts_get_data = $wpdb->get_results( $ts_data_query, ARRAY_A ); if ( $ts_get_data ) { if ( 'hourly' == $ts_report_filters['view'] ) { if ( $ts_report_filters['group_by'] == 'date' ) { foreach ( $ts_get_data as $data ) { $key_date = date( 'Y-m-d', strtotime( $data['time_from'] ) ); $ts_data[ $key_date ][ $data['user_id'] ][] = $data; } /* need to create empty array for saving sorting - username ASC */ $empty_users_data = array(); foreach ( $selected_users as $user_id ) { $empty_users_data[ $user_id ][] = array(); } foreach ( $date_period as $date ) { $date_formated = date( 'Y-m-d', strtotime( $date ) ); if ( isset( $ts_data[ $date_formated ] ) ) { $ts_data[ $date_formated ] = tmsht_array_replace( $empty_users_data, $ts_data[ $date_formated ] ); } else { $ts_data[ $date_formated ] = array( -1 => array( array() ) ); } } /* sort by time */ ksort( $ts_data ); } else if ( $ts_report_filters['group_by'] == 'user' ) { /* need to create empty array first for saving sorting - username ASC */ foreach ( $selected_users as $user_id ) { $ts_data[ $user_id ] = array(); } foreach ( $ts_get_data as $data ) { $key_date = date( 'Y-m-d', strtotime( $data['time_from'] ) ); $ts_data[ $data['user_id'] ][ $key_date ][] = $data; } $empty_date_data = array(); foreach ( $date_period as $date ) { $date_formated = date( 'Y-m-d', strtotime( $date ) ); $empty_date_data[ $date_formated ][] = array(); } foreach ( $ts_data as $user_id => $data ) { if ( ! empty( $data ) ) { $ts_data[ $user_id ] = tmsht_array_replace( $empty_date_data, $ts_data[ $user_id ] ); } } } } else { if ( $ts_report_filters['group_by'] == 'date' ) { foreach ( $ts_get_data as $data ) { $ts_data[ $data['date'] ][] = $data['user_id']; } foreach ( $date_period as $date ) { $date_formated = date( 'Y-m-d', strtotime( $date ) ); $exists_data_for_users = isset( $ts_data[ $date_formated ] ) ? array_keys( $ts_data[ $date_formated ] ) : array(); if ( ! $exists_data_for_users ) { $ts_data[ $date_formated ] = array( '-1' ); } } /* sort by time */ ksort( $ts_data ); } else { /* need to create empty array first for saving sorting - username ASC */ foreach ( $selected_users as $user_id ) { $ts_data[ $user_id ] = array(); } foreach ( $ts_get_data as $data ) { $ts_data[ $data['user_id'] ][] = $data['date']; } } } } } else { $error = __( 'Select at least one user.', 'timesheet' ); } ?>

Timesheet

>

>

>
>
$tmsht_ts_report_group_by_type ) { ?>

$ts_report_view_type ) { ?>
$legend ) { if ( $legend['disabled'] == 0 ) { ?>
. $ts_value ) { $td_timeline_classes = 'tmsht_ts_report_table_td_dateline'; if ( $ts_key == date( 'Y-m-d' ) ) $td_timeline_classes .= ' tmsht_ts_report_table_td_today tmsht_ts_report_table_highlight_today'; if ( in_array( strtolower( date( 'D', strtotime( $ts_key ) ) ), $tmsht_options['weekends'] ) ) $td_timeline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; ?> $data_per_day ) { $user_data_1_per_day = $user_data_2_per_day = array(); $i = 0; foreach ( $data_per_day as $user_id => $user_data_per_day ) { if ( $i == 0 ) { $user_data_1_per_day[ $user_id ] = $user_data_per_day; } else { $user_data_2_per_day[ $user_id ] = $user_data_per_day; } $i++; } $is_today = ( date( 'Y-m-d', strtotime( $date ) ) == date( 'Y-m-d' ) ); $prev_date = date( 'Y-m-d', strtotime( $date . ' -1 day' ) ); $next_date = date( 'Y-m-d', strtotime( $date . ' +1 day' ) ); $user_data_1_per_day_keys = array_keys( $user_data_1_per_day ); $roll_up_day = ( $user_data_1_per_day_keys[0] == -1 ); $tr_classes = 'tmsht_ts_report_table_tr '; if ( $is_today ) $tr_classes .= ' tmsht_ts_report_table_tr_today_top'; if ( $is_today && count( $ts_data[ $date ] ) == 1 ) $tr_classes .= ' tmsht_ts_report_table_tr_today_bottom'; if ( ! $is_today && $prev_date != date( 'Y-m-d' ) ) $tr_classes .= ' tmsht_ts_report_table_tr_separate_top'; if ( ! $is_today && $next_date != date( 'Y-m-d' ) && count( $ts_data[ $date ] ) == 1 ) $tr_classes .= ' tmsht_ts_report_table_tr_separate_bottom'; if ( $roll_up_day ) $tr_classes .= ' tmsht_ts_report_table_tr_roll_up'; $merge_td = ( ! $roll_up_day ) ? sprintf( 'rowspan="%d"', count( $data_per_day ) ) : sprintf( 'colspan="%d"', 2 ); $tmsht_td_dateline_classes = 'tmsht_ts_report_table_td_dateline'; if ( $is_today ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_today'; if ( in_array( strtolower( date( 'D', strtotime( $date ) ) ), $tmsht_options['weekends'] ) ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; $td_readonly = ( date( 'Y-m-d', strtotime( $date ) ) < date( 'Y-m-d' ) && $tmsht_options['edit_past_days'] == 0 ); ?> $user_data_1 ) { ?> $user_data_2 ) { $tr_classes = 'tmsht_ts_report_table_tr'; if ( $is_today && $tmsht_last_user_id == $user_id ) $tr_classes .= ' tmsht_ts_report_table_tr_today_bottom'; if ( ! $is_today && $tmsht_last_user_id == $user_id && ! array_key_exists( $next_date, $ts_data ) ) $tr_classes .= ' tmsht_ts_report_table_tr_separate_bottom'; ?> $user_data ) { $user_data_1_per_day = $user_data_2_per_day = array(); $i = 0; foreach ( $user_data as $date => $user_data_per_day ) { if ( $i == 0 ) { $user_data_1_per_day[ $date ] = $user_data_per_day; } else { $user_data_2_per_day[ $date ] = $user_data_per_day; } $i++; } $roll_up_day = ( count( $user_data_1_per_day ) == 0 ); $tr_classes = 'tmsht_ts_report_table_tr tmsht_ts_report_table_tr_separate_top'; if ( count( $user_data ) == 0 ) $tr_classes .= ' tmsht_ts_report_table_tr_separate_bottom'; if ( $roll_up_day ) $tr_classes .= ' tmsht_ts_report_table_tr_roll_up'; $merge_td = ( ! $roll_up_day ) ? sprintf( 'rowspan="%d"', count( $user_data ) ) : sprintf( 'colspan="%d"', 2 ); ?> $user_data_1 ) { $is_today = ( date( 'Y-m-d', strtotime( $date ) ) == date( 'Y-m-d' ) ); $tmsht_td_dateline_classes = 'tmsht_ts_report_table_td_dateline'; if ( $is_today ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_today tmsht_ts_report_table_td_today'; if ( in_array( strtolower( date( 'D', strtotime( $date ) ) ), $tmsht_options['weekends'] ) ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; $td_readonly = ( date( 'Y-m-d', strtotime( $date ) ) < date( 'Y-m-d' ) && $tmsht_options['edit_past_days'] == 0 ); ?> $user_data_2 ) { $tmsht_tr_dateline_classes = 'tmsht_ts_report_table_tr'; if ( $date == $last_date && $user_id == $last_user_id ) $tmsht_tr_dateline_classes .= ' tmsht_ts_report_table_tr_separate_bottom'; $tmsht_td_dateline_classes = 'tmsht_ts_report_table_td_dateline'; if ( date( 'Y-m-d', strtotime( $date ) ) == date( 'Y-m-d' ) ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_today tmsht_ts_report_table_td_today'; if ( in_array( strtolower( date( 'D', strtotime( $date ) ) ), $tmsht_options['weekends'] ) ) $tmsht_td_dateline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; $td_readonly = ( date( 'Y-m-d', strtotime( $date ) ) < date( 'Y-m-d' ) && $tmsht_options['edit_past_days'] == 0 ); ?> $ts_value ) { $td_readonly = ( $tmsht_options['edit_past_days'] == 0 && $ts_key < date( 'Y-m-d' ) ); $td_timeline_classes = 'tmsht_ts_report_table_td_time tmsht_ts_report_table_td_time_' . $ts_key; if ( $ts_key == date( 'Y-m-d' ) ) $td_timeline_classes .= ' tmsht_ts_report_table_td_today'; if ( in_array( strtolower( date( 'D', strtotime( $ts_key ) ) ), $tmsht_options['weekends'] ) ) $td_timeline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; ?> $ts_value ) { $td_timeline_classes = 'tmsht_ts_report_table_td_time tmsht_ts_report_table_td_time_' . $ts_key; if ( $is_today ) $td_timeline_classes .= ' tmsht_ts_report_table_td_today'; ?> $ts_value ) { $td_timeline_classes = 'tmsht_ts_report_table_td_dateline'; if ( $ts_key == date( 'Y-m-d' ) ) $td_timeline_classes .= ' tmsht_ts_report_table_td_today tmsht_ts_report_table_highlight_today'; if ( in_array( strtolower( date( 'D', strtotime( $ts_key ) ) ), $tmsht_options['weekends'] ) ) $td_timeline_classes .= ' tmsht_ts_report_table_highlight_weekdays'; ?>
9 ) ? $time_value : ' ' . $time_value ; ?>
()
> ()
9 ) ? $time_value : ' ' . $time_value ; ?>
">
$data ) { if ( $data ) { if ( strtotime( $data['time_from'] ) > $td_datetime_to && strtotime( $data['time_to'] ) > $td_datetime_from ) break; for ( $time_minutes = 0; $time_minutes < 60; $time_minutes += 5 ) { $td_datetime = strtotime( sprintf( "%s %02d:%02d:00", $search_date, $time_value, $time_minutes ) ); if ( strtotime( $data['time_from'] ) <= $td_datetime && strtotime( $data['time_to'] ) > $td_datetime ) { $time_to_adjustment = ( date( 'i', strtotime( $data['time_to'] ) ) == 59 ) ? '24:00' : date( 'H:i', strtotime( $data['time_to'] ) ); $time_legend_array[ $time_minutes ]['td_legend_id'] = $legend_array['td_legend_id'][] = $data['legend_id']; $time_legend_array[ $time_minutes ]['td_title'] = $legend_array['td_title'][] = sprintf( "%s (%s - %s)", $tmsht_legends[ $data['legend_id'] ]['name'], date( 'H:i', strtotime( $data['time_from'] ) ), $time_to_adjustment ); } } if ( strtotime( $data['time_to'] ) < $td_datetime_to ) unset( $user_data[ $user_data_key ] ); } } if ( empty( $time_legend_array ) ) { /**/ } elseif ( 12 == count( $legend_array['td_legend_id'] ) && 1 == count( array_unique( $legend_array['td_legend_id'] ) ) ) { ?>
" data-fill-time-to="" data-legend-id="" title="">
-1, 'td_title' => '' ); ?>
" data-fill-time-to="" data-legend-id="" title="">
format( 'Y-m-d' ); $date_start->modify( '+1 day' ); } return $period; } } if ( ! function_exists( 'tmsht_replacement_content_reminder' ) ) { function tmsht_replacement_content_reminder( $string = "", $params = array() ) { if ( empty( $string ) || ! $params ) { return false; } $replacement = array( '{user_name}' => $params['user']['display_name'], '{list_days}' => $params['days'], '{ts_page}' => sprintf( '%1$s', admin_url( 'admin.php?page=timesheet_ts_user' ) ), ); $string = preg_replace( '|\{\{ts_page_link\}(.*)\{\/ts_page_link\}\}|', sprintf( '%2$s', admin_url( 'admin.php?page=timesheet_ts_user' ), '\\1' ), $string ); $string = str_replace( array_keys( $replacement ), $replacement, $string ); return nl2br( $string ); } } if ( ! function_exists ( 'tmsht_reminder_to_email' ) ) { function tmsht_reminder_to_email() { global $wpdb, $tmsht_options; if ( ! $tmsht_options ) { tmsht_register_options(); } $required_days_arr = array( 'Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat' ); /* Get users */ $tmsht_users = tmsht_get_users( true ); $day_of_week_start = get_option( 'start_of_week' ); $date_from = date( 'Y-m-d', strtotime( "next " . $required_days_arr[ $day_of_week_start ] ) ); $date_to = date( 'Y-m-d', strtotime( $date_from . " +7 days" ) ); $date_period = tmsht_date_period( $date_from, $date_to ); foreach ( $tmsht_options['weekends'] as $weekend ) { $key = array_search( ucfirst( $weekend ), $required_days_arr ); if ( is_int( $key ) ) { unset( $required_days_arr[ $key ] ); } } foreach ( $tmsht_users as $user_id => $user ) { $blank_days = array(); foreach ( $date_period as $date ) { $ts_get_data = $wpdb->get_results( "SELECT `id` FROM `{$wpdb->prefix}tmsht_ts` WHERE date(`time_from`) = '" . date( 'Y-m-d', strtotime( $date ) ) . "' AND `user_id` = " . $user_id, ARRAY_A ); if ( $ts_get_data ) { continue; } $tmsht_short_day_name = date( 'D', strtotime( $date ) ); $tmsht_full_day_name = date_i18n( 'l', strtotime( $date ) ); $tmsht_date = date_i18n( $tmsht_options['date_format'], strtotime( $date ) ); if ( in_array( $tmsht_short_day_name, $required_days_arr ) ) { $blank_days[] = sprintf( '%s (%s)', $tmsht_date, $tmsht_full_day_name ); } } if ( $blank_days ) { $tmsht_list_days = ''; $params = array( 'user' => $user, 'days' => $tmsht_list_days, ); $message = tmsht_replacement_content_reminder( $tmsht_options['content_reminder']['message'], $params ); $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=utf-8\r\n"; wp_mail( $user['email'], $tmsht_options['content_reminder']['subject'], $message, $headers ); } } } } /* delete user data if user was deleted */ if ( ! function_exists( 'tmsht_delete_user' ) ) { function tmsht_delete_user( $user_id ) { global $wpdb; $wpdb->delete( $wpdb->prefix . 'tmsht_ts', array( 'user_id' => $user_id ) ); } } if ( ! function_exists( 'tmsht_action_links' ) ) { function tmsht_action_links( $links, $file ) { if ( ! is_network_admin() ) { /* Static so we don't call plugin_basename on every plugin row. */ static $this_plugin; if ( ! $this_plugin ) $this_plugin = plugin_basename( __FILE__ ); if ( $file == $this_plugin ) { $settings_link = '' . __( 'Settings', 'timesheet' ) . ''; array_unshift( $links, $settings_link ); } } return $links; } } if ( ! function_exists ( 'tmsht_links' ) ) { function tmsht_links( $links, $file ) { $base = plugin_basename( __FILE__ ); if ( $file == $base ) { if ( ! is_network_admin() ) $links[] = '' . __( 'Settings', 'timesheet' ) . ''; $links[] = '' . __( 'FAQ', 'timesheet' ) . ''; $links[] = '' . __( 'Support', 'timesheet' ) . ''; } return $links; } } if ( ! function_exists ( 'tmsht_plugin_banner' ) ) { function tmsht_plugin_banner() { global $hook_suffix, $tmsht_plugin_info; if ( 'plugins.php' == $hook_suffix ) { global $tmsht_options; $tmsht_options = ( empty ( $tmsht_options ) ) ? get_option( 'tmsht_options' ) : $tmsht_options; if ( isset( $tmsht_options['first_install'] ) && strtotime( '-1 week' ) > $tmsht_options['first_install'] ) { bws_plugin_banner( $tmsht_plugin_info, 'tmsht', 'timesheet', '6316f137e58adf88e055718d7cc85346', '606', 'timesheet' ); } bws_plugin_banner_to_settings( $tmsht_plugin_info, 'tmsht_options', 'timesheet', 'admin.php?page=timesheet_settings' ); } if ( isset( $_GET['page'] ) && 'timesheet_settings' == $_GET['page'] ) { bws_plugin_suggest_feature_banner( $tmsht_plugin_info, 'tmsht_options', 'timesheet' ); } } } if ( ! function_exists ( 'tmsht_add_weekly' ) ) { function tmsht_add_weekly( $schedules ) { $schedules['tmsht_weekly'] = array( 'interval' => 604800, 'display' => __( 'Once Weekly', 'timesheet' ) ); return $schedules; } } if ( ! function_exists ( 'tmsht_unistall' ) ) { function tmsht_unistall() { global $wpdb; if ( ! function_exists( 'get_plugins' ) ) require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); $all_plugins = get_plugins(); if ( ! array_key_exists( 'timesheet-pro/timesheet-pro.php', $all_plugins ) ) { if ( is_multisite() ) { $old_blog = $wpdb->blogid; /* Get all blog ids */ $blogids = $wpdb->get_col( "SELECT `blog_id` FROM $wpdb->blogs" ); foreach ( $blogids as $blog_id ) { switch_to_blog( $blog_id ); $meta_key = '_tmsht_ts_report_filters'; $users = get_users( array( 'blog_id' => $blog_id, 'meta_key' => $meta_key, )); foreach ( $users as $user ) { delete_user_meta( $user->ID, $meta_key ); } delete_option( 'tmsht_options' ); $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}tmsht_legends`, `{$wpdb->prefix}tmsht_ts`;" ); } switch_to_blog( $old_blog ); } else { $meta_key = '_tmsht_ts_report_filters'; $users = get_users( array( 'blog_id' => get_current_blog_id(), 'meta_key' => $meta_key, )); foreach ( $users as $user ) { delete_user_meta( $user->ID, $meta_key ); } delete_option( 'tmsht_options' ); $wpdb->query( "DROP TABLE IF EXISTS `{$wpdb->prefix}tmsht_legends`, `{$wpdb->prefix}tmsht_ts`;" ); } } require_once( dirname( __FILE__ ) . '/bws_menu/bws_include.php' ); bws_include_init( plugin_basename( __FILE__ ) ); bws_delete_plugin( plugin_basename( __FILE__ ) ); } } register_activation_hook( __FILE__, 'tmsht_plugin_activate' ); /* Calling a function add administrative menu. */ add_action( 'admin_menu', 'tmsht_admin_menu' ); /* Initialization */ add_action( 'plugins_loaded', 'tmsht_plugins_loaded' ); add_action( 'init', 'tmsht_init' ); add_action( 'admin_init', 'tmsht_admin_init' ); /* Adding stylesheets */ add_action( 'admin_enqueue_scripts', 'tmsht_admin_scripts_styles' ); /* delete ts data, when user was deleted */ add_action( 'delete_user', 'tmsht_delete_user' ); /* Additional links on the plugin page */ add_filter( 'plugin_action_links', 'tmsht_action_links', 10, 2 ); add_filter( 'plugin_row_meta', 'tmsht_links', 10, 2 ); add_action( 'admin_notices', 'tmsht_plugin_banner' ); add_action( 'tmsht_reminder_to_email', 'tmsht_reminder_to_email' ); add_filter( 'cron_schedules', 'tmsht_add_weekly' );