widgets = new AIO_Time_Clock_Lite_Widgets(); add_action('widgets_init', array($this, 'loadWidgets')); } $this->handleRoles(); } public function getVersion(){ return "1.3.0"; } public function handleRoles(){ remove_role('manager'); $result = add_role( 'manager', __('Manager', 'aio-time-clock-lite'), array( 'read' => true, 'create_posts' => true, 'edit_posts' => true, 'edit_others_posts' => true, 'publish_posts' => true, 'manage_categories' => true, ) ); remove_role('volunteer'); $result = add_role( 'volunteer', __('Volunteer', 'aio-time-clock-lite'), array( 'read' => true, ) ); remove_role('employee'); $result = add_role( 'employee', __('Employee', 'aio-time-clock-lite'), array( 'read' => true, ) ); remove_role('time_clock_admin'); $result = add_role( 'time_clock_admin', __('Time Clock Admin', 'aio-time-clock-lite'), array( 'read' => true, // Allows a user to read 'create_shifts' => true, // Allows user to create new posts 'edit_posts' => true, // Allows user to edit their own posts 'edit_shifts' => true, // Allows user to edit their own posts 'edit_others_posts' => true, // Allows user to edit others posts too 'edit_others_shifts' => true, // Allows user to edit others posts too 'publish_posts' => true, // Allows the user to publish posts 'publish_shifts' => true, // Allows the user to publish posts 'manage_categories' => true, // Allows user to manage post categories 'edit_private_posts' => true, // Allows user to manage post categories 'edit_private_shifts' => true, // Allows user to manage post categories 'read_private_posts' => true, // Allows user to manage post categories 'read_private_shifts' => true, // Allows user to manage post categories 'edit_published_posts' => true, // Allows user to manage post categories 'edit_published_shifts' => true, // Allows user to manage post categories ) ); } public function pluginInitLite() { load_plugin_textdomain( 'aio-time-clock-lite', false, dirname(plugin_basename(__FILE__)).'/languages/' ); } public function addMenuItem(){ $page_hook_suffix = add_menu_page('Time Clock Lite', 'Time Clock Lite', 'edit_posts', 'aio-tc-lite', array( $this, 'settingsPageLite'), 'dashicons-clock'); add_submenu_page('aio-tc-lite', __('Settings', 'aio-time-clock-lite'), __('Settings', 'aio-time-clock-lite'), 'edit_posts', 'aio-tc-lite', array( $this, 'settingsPageLite')); add_submenu_page('aio-tc-lite', __('Real Time Monitoring', 'aio-time-clock-lite'), __('Real Time Monitoring', 'aio-time-clock-lite'), 'edit_posts', 'aio-monitoring-sub', array( $this, 'montioringPage')); add_submenu_page('aio-tc-lite', __('Employees', 'aio-time-clock-lite'), __('Employees', 'aio-time-clock-lite'), 'edit_posts', 'aio-employees-sub', array( $this, 'employeePage')); add_submenu_page('aio-tc-lite', __('Departments', 'aio-time-clock-lite'), __('Departments', 'aio-time-clock-lite'), 'edit_posts', 'aio-department-sub', array( $this, 'departmentPage')); add_submenu_page('aio-tc-lite', __('Shifts', 'aio-time-clock-lite'), __('Shifts', 'aio-time-clock-lite'), 'edit_posts', 'aio-shifts-sub', array( $this, 'shiftsPage')); add_submenu_page('aio-tc-lite', __('Reports', 'aio-time-clock-lite'), __('Reports', 'aio-time-clock-lite'), 'edit_posts', 'aio-reports-sub', array( $this, 'reportsPageLite')); } public function frontEndScripts(){ wp_enqueue_script('jquery'); wp_register_script("aio_time_clock_lite_js", plugins_url('/js/time-clock-lite.js', __FILE__), array('jquery'), $this->getVersion()); wp_localize_script('aio_time_clock_lite_js', 'timeClockAjax', $this->getTranslationStrings() ); wp_register_style('datetimepicker-style', plugins_url('js/datetimepicker/jquery.datetimepicker.css', __FILE__)); wp_register_style('aio-tc-site-style', plugins_url('css/aio-site.css', __FILE__)); wp_enqueue_script('nert-aio-timepicker', plugins_url('js/datetimepicker/jquery.datetimepicker.js', __FILE__), array('jquery')); wp_enqueue_script('aio_time_clock_lite_js'); wp_enqueue_style('datetimepicker-style'); wp_enqueue_style('aio-tc-site-style'); } public function adminScripts(){ wp_enqueue_script('jquery'); wp_register_style('datetimepicker-style', plugins_url('js/datetimepicker/jquery.datetimepicker.css', __FILE__)); wp_enqueue_script('nert-aio-timepicker', plugins_url('js/datetimepicker/jquery.datetimepicker.js', __FILE__), array('jquery')); wp_enqueue_style('datetimepicker-style'); wp_register_script("aio_time_clock_lite_admin_js", plugins_url('/js/time-clock-lite-admin.js', __FILE__), array('jquery'), $this->getVersion()); wp_register_script("aio_time_clock_lite_steps", plugins_url('/js/jquery.steps.min.js', __FILE__), array('jquery')); wp_localize_script('aio_time_clock_lite_admin_js', 'timeClockAdminAjax', $this->getTranslationStrings() ); wp_register_style('aio-tc-admin-style', plugins_url('css/aio-admin.css', __FILE__)); wp_register_style('aio-tc-lite-steps-style', plugins_url('css/jquery.steps.css', __FILE__)); wp_enqueue_script('aio_time_clock_lite_admin_js'); wp_enqueue_script('aio_time_clock_lite_steps'); wp_enqueue_style('aio-tc-admin-style'); wp_enqueue_style('aio-tc-lite-steps-style'); } public function pluginInit() { load_plugin_textdomain( 'aio-time-clock-update-manager', false, dirname(plugin_basename(__FILE__)).'/languages/' ); } public function aio_time_clock_lite_plugin_update() { add_option('aio_time_clock_lite_update_redirect', true); } public function aio_timeclock_lite_plugin_redirect() { if (get_option('aio_time_clock_lite_update_redirect', false)) { delete_option('aio_time_clock_lite_update_redirect'); wp_redirect('?page=aio-tc-lite&tab=news'); } } public function remove_my_post_metaboxes_aio_lite() { remove_meta_box( 'authordiv','shift','normal' ); remove_meta_box( 'commentstatusdiv', 'shift', 'normal' ); remove_meta_box( 'commentsdiv', 'shift', 'normal' ); } public function aio_remove_row_actions( $actions ) { if( get_post_type() === 'shift' ) unset( $actions['view'] ); return $actions; } public function show_aio_time_clock_lite($atts) { $tc_page = $this->aio_check_tc_shortcode_lite(); $nonce = wp_create_nonce("clock_in_nonce"); $link = admin_url('admin-ajax.php?action=clock_in_nonce&post_id=' . get_the_ID() . '&nonce=' . $nonce); require_once "templates/time-clock-style1.php"; } public function show_aio_employee_profile_lite($atts) { $ep_page = $this->check_eprofile_shortcode_lite(); $nonce = wp_create_nonce("clock_in_nonce"); $link = admin_url('admin-ajax.php?action=clock_in_nonce&post_id=' . get_the_ID() . '&nonce=' . $nonce); require_once "aio-employee-profile.php"; } public function aio_time_clock_lite_js() { $clock_action = null; if (isset($_POST["clock_action"])){ $clock_action = sanitize_text_field($_POST["clock_action"]); } $employee_clock_in_time = null; $employee_clock_out_time = null; $is_clocked_in = false; $open_shift_id = null; if (isset($_POST["open_shift_id"])){ $open_shift_id = sanitize_key(intval($_POST["open_shift_id"])); } $new_shift_created = false; global $current_user; $employee = $current_user->ID; $message = null; $time_total = strtotime(0); if ($clock_action == "check_shifts") { $args = array( 'post_type' => 'shift', 'orderby' => 'ID', 'author' => $employee, ); $query = new WP_Query($args); if ($query->have_posts()) { while ($query->have_posts()) { $query->the_post(); $custom = get_post_custom($query->post->ID); $employee_clock_in_time = null; if (isset($custom["employee_clock_in_time"][0])){ $employee_clock_in_time = $custom["employee_clock_in_time"][0]; } $employee_clock_out_time = null; if (isset($custom["employee_clock_out_time"][0])){ $employee_clock_out_time = $custom["employee_clock_out_time"][0]; } if ($employee_clock_in_time != null && $employee_clock_out_time == null) { $open_shift_id = $query->post->ID; $is_clocked_in = true; break; } } } echo json_encode( array( "response" => "success", "message" => $message, "employee" => $employee, "clock_action" => $clock_action, "is_clocked_in" => $is_clocked_in, "open_shift_id" => $open_shift_id, "employee_clock_in_time" => $this->cleanDate($employee_clock_in_time), "employee_clock_out_time" => $this->cleanDate($employee_clock_out_time), ) ); } elseif ($clock_action == "clock_in") { $device_time = null; if (isset($_POST["device_time"])){ $device_time = $_POST["device_time"]; } $current_time = $this->getCurrentTime($device_time); $aio_new_shift = array( 'post_type' => 'shift', 'post_title' => 'Employee Shift', 'post_status' => 'publish', 'post_author' => $employee, ); $new_post_id = wp_insert_post($aio_new_shift); $department = ""; $terms = get_the_terms($current_user->ID, 'department'); if (!empty($terms)) { foreach ($terms as $term) { $department = $term->name; } } add_post_meta($new_post_id, 'employee_clock_in_time', $current_time["current_time"], true); if ($department != null) { add_post_meta($new_post_id, 'department', $department, true); } add_post_meta($new_post_id, 'ip_address_in', $_SERVER['REMOTE_ADDR'], true); $open_shift_id = $new_post_id; $is_clocked_in = true; echo json_encode( array( "response" => "success", "message" => $message, "employee" => $employee, "open_shift_id" => $open_shift_id, "clock_action" => $clock_action, "is_clocked_in" => $is_clocked_in, "employee_clock_in_time" => $this->cleanDate($current_time["current_time"]), "employee_clock_out_time" => null, ) ); } elseif ($clock_action == "clock_out") { $device_time = null; if (isset($_POST["device_time"])){ $device_time = $_POST["device_time"]; } $current_time = $this->getCurrentTime($device_time); $is_clocked_in = false; $employee_clock_in_time = get_post_meta($open_shift_id, 'employee_clock_in_time', true); add_post_meta($open_shift_id, 'employee_clock_out_time', $current_time["current_time"], true); add_post_meta($open_shift_id, 'ip_address_out', $_SERVER['REMOTE_ADDR'], true); $shift_sum = $this->dateDifference($employee_clock_in_time, $current_time["current_time"]); $time_total = $shift_sum; echo json_encode( array( "response" => "success", "message" => $message, "employee" => $employee, "clock_action" => $clock_action, "employee_clock_in_time" => $this->cleanDate($employee_clock_in_time), "employee_clock_out_time" => $this->cleanDate($current_time["current_time"]), "time_total" => $this->secondsToTime($time_total), "is_clocked_in" => $is_clocked_in ) ); } else { echo json_encode( array( "response" => "failed", "message" => __("action does not exist", 'aio-time-clock-lite'), "employee" => $employee, "clock_action" => $clock_action, ) ); } wp_reset_postdata(); die(); } public function secondsToTime($seconds) { if (isset($seconds)){ $dtF = new DateTime('@0'); $dtT = new DateTime("@$seconds"); $days = $dtF->diff($dtT)->format('%D'); $hours = $dtF->diff($dtT)->format('%H'); $minutes = $dtF->diff($dtT)->format('%I'); $hours = $hours + ($days * 24); return $hours . ":" . $minutes; } else{ return '00:00'; } } public function aio_time_clock_lite_admin_js() { $report_type = sanitize_text_field($_POST["report_type"]); $employee = sanitize_key(intval($_POST["employee"])); $date_range_start = date($this->getDateTimeFormat(), strtotime($_POST["aio_pp_start_date"])); $date_range_end = date($this->getDateTimeFormat(), strtotime($_POST["aio_pp_end_date"])); $errors = ""; if ($errors == null) { echo json_encode( array( "response" => "success", "employee" => $employee, "date_range_start" => $date_range_start, "date_range_end" => $date_range_end, "shifts" => $this->getShiftTotalFromRange( $employee, $date_range_start, $date_range_end ), ) ); } else { echo json_encode( array( "response" => "failed", "employee" => $employee, "date_range_start" => $date_range_start, "date_range_end" => $date_range_end, ) ); } die(); } public function aio_tc_custom_post_shift_lite() { $labels = array( 'name' => __('Shifts', 'aio-time-clock-lite'), 'singular_name' => __('Shift', 'aio-time-clock-lite'), 'add_new' => __('Add New', 'shift', 'aio-time-clock-lite'), 'add_new_item' => __('Clock Out', 'aio-time-clock-lite'), 'edit_item' => __('Edit Shift', 'aio-time-clock-lite'), 'new_item' => __('Clock In', 'aio-time-clock-lite'), 'all_items' => __('All Shifts', 'aio-time-clock-lite'), 'view_item' => __('View Shift', 'aio-time-clock-lite'), 'search_items' => __('Search Shifts', 'aio-time-clock-lite'), 'not_found' => __('No shifts found', 'aio-time-clock-lite'), 'not_found_in_trash' => __('No shifts found in the Trash', 'aio-time-clock-lite'), 'parent_item_colon' => '', 'menu_name' => __('Employee Shifts', 'aio-time-clock-lite'), ); $args = array( 'labels' => $labels, 'description' => __('Employee shifts dates and times', 'aio-time-clock-lite'), 'query_var' => true, 'public' => true, 'show_ui' => true, 'supports' => array('title', 'author'), 'has_archive' => true, 'show_tagcloud' => false, 'rewrite' => array('slug' => 'shifts'), 'show_in_nav_menus' => false, 'supports' => false ); register_post_type('shift', $args); } public function aio_timeclock_admin_init_lite() { add_filter('manage_edit-shift_columns', array( $this, 'aio_timeclock_shift_columns_filter_lite'), 10, 1); add_action('manage_shift_posts_custom_column', array( $this, 'aio_timeclock_shift_column_lite'), 10, 2); } public function aio_timeclock_shift_columns_filter_lite($columns) { unset($columns['date']); unset($columns['author']); $columns['employee'] = __('Employee', 'aio-time-clock-lite'); $columns['department'] = __('Department', 'aio-time-clock-lite'); $columns['employee_clock_in_time'] = __('Clock In Time', 'aio-time-clock-lite'); $columns['employee_clock_out_time'] = __('Clock Out Time', 'aio-time-clock-lite'); $columns['total_shift_time'] = __('Total Time', 'aio-time-clock-lite'); return $columns; } public function aio_timeclock_shift_column_lite($column, $post_id) { global $post; $custom = get_post_custom($post_id); $employee_clock_in_time = null; if (isset($custom['employee_clock_in_time'][0])){ $employee_clock_in_time = $custom['employee_clock_in_time'][0]; } $employee_clock_out_time = null; if (isset($custom['employee_clock_out_time'][0])){ $employee_clock_out_time = $custom['employee_clock_out_time'][0]; } $shift_sum = strtotime(0); if ($employee_clock_in_time != null && $employee_clock_out_time != null){ $shift_sum = $this->secondsToTime($this->dateDifference($employee_clock_in_time, $employee_clock_out_time)); } switch ($column) { case 'employee': $first_name = get_the_author_meta('first_name'); $last_name = get_the_author_meta('last_name'); echo $last_name . ", " . $first_name; break; case 'department': echo $this->aioLiteDepartmentColumn(get_the_author_meta('ID')); break; case 'employee_clock_in_time': echo $employee_clock_in_time; break; case 'employee_clock_out_time': echo $employee_clock_out_time; break; case 'total_shift_time': echo $shift_sum; break; } } public function aioLiteDepartmentColumn($author_id) { $department = ""; global $user; global $wordpress; $tax = get_taxonomy( 'department' ); $terms = get_terms( 'department', array( 'hide_empty' => false ) ); if ( !empty( $terms ) ) { foreach ( $terms as $term ) { if (is_object_in_term( $author_id, 'department', $term )){ $department .= $term->name . " "; } } } return $department; } public function getShiftTotal($post_id) { $employee_clock_in_time = get_post_meta($post_id, 'employee_clock_in_time', true); $employee_clock_out_time = get_post_meta($post_id, 'employee_clock_out_time', true); $total_shift_time = strtotime(0); if ($employee_clock_in_time != null && $employee_clock_out_time != null){ if (strtotime($employee_clock_in_time) > strtotime(0) && strtotime($employee_clock_out_time) > strtotime(0)) { $total_shift_time = $this->dateDifference($employee_clock_in_time, $employee_clock_out_time); } } return $total_shift_time; } public function aio_shift_info_box_meta_lite() { add_meta_box( 'shift_info_box', __('Shift Info', 'aio-timeclock'), array($this, 'aio_shift_info_box_content'), 'shift', 'normal', 'high' ); } public function aio_shift_info_box_content() { include "aio-time-clock-box-content.php"; } public function getEmployeeSelect($selected) { $selected = json_decode($selected); $count = 0; $users = get_users('fields=all_with_meta'); usort($users, create_function('$a, $b', 'if($a->last_name == $b->last_name) { return 0;} return ($a->last_name > $b->last_name) ? 1 : -1;')); foreach (array_filter($users, array( $this, 'aio_filter_roles_lite')) as $user) { $active = ""; if ($selected == $user->ID) { $active = "selected"; } echo ''; $count++; } } public function getBuildInRoles(){ return array('aio_tc_employee', 'aio_tc_manager', 'time_clock_admin', 'aio_tc_volunteer', 'aio_tc_contractor', 'employee', 'manager', 'volunteer', 'contractor', 'administrator'); } public function aio_filter_roles_lite($user) { $roles = $this->getBuildInRoles(); return array_intersect($user->roles, $roles); } public function aio_save_shift_meta_lite($post_id) { if (isset($_REQUEST['clock_in'])) { update_post_meta($post_id, 'employee_clock_in_time', sanitize_text_field($_REQUEST['clock_in'])); $employee_clock_out_time = get_post_meta($post_id, 'employee_clock_out_time', true); } if (isset($_REQUEST['clock_out'])) { update_post_meta($post_id, 'employee_clock_out_time', sanitize_text_field($_REQUEST['clock_out'])); } if (isset($_REQUEST['employee_id'])) { remove_action('save_post', array($this, 'aio_save_shift_meta_lite')); $arg = array( 'ID' => $post_id, 'post_author' => sanitize_key(intval($_REQUEST['employee_id'])), ); wp_update_post($arg); add_action('save_post', array($this, 'aio_save_shift_meta_lite')); } } public function removeMetaBoxes() { remove_meta_box('authordiv', 'shift', 'normal'); } public function settingsPageLite() { include "aio-settings.php"; } public function montioringPage() { include "aio-monitoring.php"; } public function reportsPageLite() { include "aio-reports.php"; } public function register_aio_timeclock_lite_settings() { register_setting('nertworks-timeclock-settings-group', 'aio_company_name'); register_setting('nertworks-timeclock-settings-group', 'aio_pay_schedule'); register_setting('nertworks-timeclock-settings-group', 'aio_wage_manage'); register_setting('nertworks-timeclock-settings-group', 'aio_timeclock_time_zone'); register_setting('nertworks-timeclock-settings-group', 'aio_timeclock_text_align'); register_setting('nertworks-timeclock-settings-group', 'aio_timeclock_redirect_employees'); register_setting('nertworks-timeclock-settings-group', 'aio_timeclock_show_avatar'); } public function aio_check_tc_shortcode_lite() { $loop = new WP_Query(array('post_type' => 'page', 'posts_per_page' => -1)); while ($loop->have_posts()): $loop->the_post(); $content = get_the_content(); if (has_shortcode($content, 'show_aio_time_clock_lite')) { return $loop->post->ID; break; } else { //echo "none"; } endwhile; wp_reset_query(); } public function check_eprofile_shortcode_lite() { $loop = new WP_Query(array('post_type' => 'page', 'posts_per_page' => -1)); while ($loop->have_posts()) : $loop->the_post(); $content = get_the_content(); if (has_shortcode($content, 'show_aio_employee_profile_lite')) { return $loop->post->ID; } else { //echo "none"; } endwhile; wp_reset_query(); } public function memberLoginRedirect($redirect_to, $request, $user) { $tc_page = $this->check_tc_shortcode_lite(); $roles = $this->getBuildInRoles(); $aio_custom_roles = get_option("aio_custom_roles"); if (is_array($aio_custom_roles)){ if (count($aio_custom_roles) > 0){ foreach ($aio_custom_roles as $user_role){ $clean_role = strtolower(str_replace(" ", "_", $user_role)); array_push( $roles, $clean_role ); } } } if (is_array($user->roles)) { if (array_intersect($roles, $user->roles)){ return get_permalink($tc_page); } } else { return $redirect_to; } } public function getTimeZoneListLite() { $timezones = $tzlist = DateTimeZone::listIdentifiers(DateTimeZone::ALL); return $timezones; } public function shiftsPage() { wp_redirect( admin_url().'/edit.php?post_type=shift' ); echo ''; exit; } public function employeePage() { include("aio-employees.php"); } public function departmentPage() { wp_redirect( admin_url().'/edit-tags.php?taxonomy=department' ); echo ''; exit; } public function dateDifference($start, $end) { if ($this->isValidDate($start) && $this->isValidDate($end)){ $start = str_replace('/', '-', $start); $end = str_replace('/', '-', $end); $start = new DateTime($start); $end = new DateTime($end); $diff = $end->diff($start); $diff_sec = $diff->format('%r').( // prepend the sign - if negative, change it to R if you want the +, too ($diff->s)+ // seconds (no errors) (60*($diff->i))+ // minutes (no errors) (60*60*($diff->h))+ // hours (no errors) (24*60*60*($diff->d))+ // days (no errors) (30*24*60*60*($diff->m))+ // months (???) (365*24*60*60*($diff->y)) // years (???) ); return $diff_sec; } } public function getShiftTotalFromRange($employee, $date_range_start, $date_range_end) { $shift_total_time = strtotime(0); $shift_array = array(); $count = 0; $loop = new WP_Query(array('post_type' => 'shift', 'author' => $employee, 'posts_per_page' => -1)); while ($loop->have_posts()): $loop->the_post(); $shift_sum = strtotime(0); $shift_id = $loop->post->ID; $custom = get_post_custom($shift_id); $employee_clock_in_time = null; $employee_clock_out_time = null; if (isset($custom["employee_clock_in_time"][0])) { $employee_clock_in_time = $custom["employee_clock_in_time"][0]; } if (isset($custom["employee_clock_out_time"][0])) { $employee_clock_out_time = $custom["employee_clock_out_time"][0]; } $searchDateBegin = $date_range_start; $searchDateEnd = $date_range_end; if ((strtotime($employee_clock_in_time) >= strtotime($searchDateBegin)) && (strtotime($employee_clock_in_time) <= strtotime($searchDateEnd))) { $author_id = $loop->post->post_author; $last_name = get_the_author_meta('last_name', $author_id); $first_name = get_the_author_meta('first_name', $author_id); if ($employee_clock_in_time != null && $employee_clock_out_time != null) { $shift_sum = $this->dateDifference($employee_clock_in_time, $employee_clock_out_time); $shift_total_time += $shift_sum; $shift_sum = $this->secondsToTime($shift_sum); } else{ //$shift_sum = $this->secondsToTime($shift_sum); } array_push($shift_array, array( "shift_id" => $shift_id, "employee_clock_in_time" => $this->cleanDate($employee_clock_in_time), "employee_clock_out_time" => $this->cleanDate($employee_clock_out_time), "first_name" => $first_name, "last_name" => $last_name, "shift_sum" => $shift_sum, ) ); $count++; } endwhile; wp_reset_query(); if ($count > 0){ $shift_total_time = $this->secondsToTime($shift_total_time); } return array( "response" => "success", "shift_count" => $count, "shift_total_time" => $shift_total_time, "shift_array" => $shift_array, ); } public function sumTheTimeLite($time1, $time2) { $times = array($time1, $time2); $seconds = 0; foreach ($times as $time) { list($hour, $minute, $second) = explode(':', $time); $seconds += $hour * 3600; $seconds += $minute * 60; $seconds += $second; } $hours = floor($seconds / 3600); $seconds -= $hours * 3600; $minutes = floor($seconds / 60); $seconds -= $minutes * 60; return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds); } public function modifyWageLite($profile_fields) { $profile_fields['employee_wage'] = __('Wage', 'aio-time-clock-lite'); return $profile_fields; } public function adminNoticesLite() { /* if (get_option('aio_time_clock_lite_update_redirect', false)) { ?>

isTimeMachine($device_time) || !$this->isValidDate($device_time)){ //fall back $timezone = 'UTC'; date_default_timezone_set($timezone); $device_time = date($this->dateFormat); } $current_time = date($this->dateFormat, strtotime($device_time)); $time_type = "device"; } else{ date_default_timezone_set($timezone_option); $current_time = date($this->dateFormat); $time_type = "default"; } } else{ $timezone = 'UTC'; date_default_timezone_set($timezone); $current_time = date($this->dateFormat); $time_type = "default"; } return array( "response" => "success", "timezone_option" => $timezone_option, "current_time" => $current_time, "time_type" => $time_type, "timezone" => $timezone, "device_time" => $device_time ); } public function getDateTimeFormat(){ $date_format = get_option( 'date_format' ); $time_format = get_option( 'time_format' ); if ($date_format == null){ $date_format = 'Y-m-d'; } if ($time_format == null){ $time_format = 'h:i:s A'; } return $date_format . " " . $time_format; } function getDateFormat(){ $date_format = get_option( 'date_format' ); if ($date_format == null){ $date_format = 'Y-m-d'; } return $date_format; } function getTimeFormat(){ $time_format = get_option( 'time_format' ); if ($time_format == null){ $time_format = 'h:i:s A'; } return $time_format; } public function isTimeMachine($date){ $now = date(); $end_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($now)) . " - 10 years")); return (strtotime($date) <= strtotime($end_date)); } public function getTranslationStrings(){ return array( 'ajaxurl' => admin_url('admin-ajax.php'), 'isClockedIn' => __('You are currently clocked in', 'aio-time-clock-lite'), 'clockInTime' => __('Clock In Time', 'aio-time-clock-lite'), 'updateNote' => __('Update Note', 'aio-time-clock-lite'), 'addNote' => __('Add Note', 'aio-time-clock-lite'), 'clockInMessage' => __('Click "CLOCK IN" to START your shift', 'aio-time-clock-lite'), 'locationError' => __('Location Required', 'aio-time-clock-lite'), 'clockedOutMessage' => __('You have been clocked out', 'aio-time-clock-lite'), 'clockOutFail' => __('Clock out failed', 'aio-time-clock-lite'), 'clockInFail' => __('Clock In failed', 'aio-time-clock-lite'), 'currentTime' => __('Current Time', 'aio-time-clock-lite'), 'clockIn' => __('Clock In', 'aio-time-clock-lite'), 'clockOut' => __('Clock Out', 'aio-time-clock-lite'), 'Name' => __('Name', 'aio-time-clock-lite'), 'Options' => __('Options', 'aio-time-clock-lite'), 'ShiftTotal' => __('Shift Total', 'aio-time-clock-lite'), 'TotalShifts' => __('Total Shifts', 'aio-time-clock-lite'), 'TotalShiftTime' => __('Total Shift Time', 'aio-time-clock-lite'), 'TimeClockDetected' => __('Widget time clock disabled while on time clock page', 'aio-time-clock-lite') ); } function aio_lite_update_department_count( $terms, $taxonomy ) { global $wpdb; foreach ( (array) $terms as $term ) { $count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d", $term ) ); do_action( 'edit_term_taxonomy', $term, $taxonomy ); $wpdb->update( $wpdb->term_taxonomy, compact( 'count' ), array( 'term_taxonomy_id' => $term ) ); do_action( 'edited_term_taxonomy', $term, $taxonomy ); } } function aio_lite_register_user_taxonomy() { register_taxonomy( 'department', 'user', array( 'public' => true, 'labels' => array( 'name' => __( 'Department', 'aio-time-clock-lite'), 'singular_name' => __( 'Department', 'aio-time-clock-lite' ), 'menu_name' => __( 'Departments', 'aio-time-clock-lite' ), 'search_items' => __( 'Search Departments', 'aio-time-clock-lite' ), 'popular_items' => __( 'Popular Departments', 'aio-time-clock-lite' ), 'all_items' => __( 'All Departments', 'aio-time-clock-lite' ), 'edit_item' => __( 'Edit Department', 'aio-time-clock-lite' ), 'update_item' => __( 'Update Department', 'aio-time-clock-lite' ), 'add_new_item' => __( 'Add New Department', 'aio-time-clock-lite' ), 'new_item_name' => __( 'New Department Name', 'aio-time-clock-lite' ), 'separate_items_with_commas' => __( 'Separate departments with commas', 'aio-time-clock-lite' ), 'add_or_remove_items' => __( 'Add or remove departments', 'aio-time-clock-lite' ), 'choose_from_most_used' => __( 'Choose from the most popular departments', 'aio-time-clock-lite' ), ), 'rewrite' => array( 'with_front' => true, 'slug' => 'author/department' // Use 'author' (default WP user slug). ), 'capabilities' => array( 'manage_terms' => 'edit_users', // Using 'edit_users' cap to keep this simple. 'edit_terms' => 'edit_users', 'delete_terms' => 'edit_users', 'assign_terms' => 'read', ), 'update_count_callback' => 'aio_lite_update_department_count' // Use a custom function to update the count. ) ); } function aio_tc_lite_save_user_department_terms( $user_id ) { $tax = get_taxonomy( 'department' ); if ( !current_user_can( 'edit_user', $user_id ) && current_user_can( $tax->cap->assign_terms ) ) return false; $term = esc_attr( $_POST['department'] ); wp_set_object_terms( $user_id, array( $term ), 'department', false); clean_object_term_cache( $user_id, 'department' ); } function aio_lite_add_department_admin_page() { $tax = get_taxonomy( 'department' ); add_users_page( esc_attr( $tax->labels->menu_name ), esc_attr( $tax->labels->menu_name ), $tax->cap->manage_terms, 'edit-tags.php?taxonomy=' . $tax->name ); } function aio_lite_manage_department_user_column( $columns ) { unset( $columns['posts'] ); $columns['users'] = __( 'Users', 'aio-time-clock-lite' ); return $columns; } function aio_lite_manage_department_column( $display, $column, $term_id ) { if ( 'users' === $column ) { $term = get_term( $term_id, 'department' ); echo $term->count; } } function aio_lite_edit_user_department_section( $user ) { $tax = get_taxonomy( 'department' ); if ( !current_user_can( $tax->cap->assign_terms ) ) return; $terms = get_terms( 'department', array( 'hide_empty' => false ) ); ?>

ID, 'department', $term ) ); ?> />
cap->assign_terms ) ) return false; $term = esc_attr( $_POST['department'] ); wp_set_object_terms( $user_id, array( $term ), 'department', false); clean_object_term_cache( $user_id, 'department' ); } function aio_lite_disable_username( $username ) { if ( 'department' === $username ) $username = ''; return $username; } public function isValidDate($date) { return (bool) strtotime($date); } public function loadWidgets() { register_widget( 'AIO_Time_Clock_Lite_Widgets' ); } public function checkPermission($user_roles) { $found = 0; global $current_user; $original_roles = $this->getBuildInRoles(); if (isset($original_roles)) { foreach ($user_roles as $r) { if (in_array($r, $original_roles, false)) { $found++; } } } if (current_user_can('administrator')) { $found++; } if ($found > 0) { return true; } else { return false; } } public function cleanDate($date){ if ($this->isValidDate($date) && $date != null){ return date($this->getDateTimeFormat(), strtotime($date)); } else{ return null; } } }