widgets = new AIO_Time_Clock_Lite_Widgets(); add_action('widgets_init', array($this, 'loadWidgets')); } $this->handleRoles(); } public function getVersion() { return "1.3.24"; } 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() { //Styles 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_style('datetimepicker-style'); wp_enqueue_style('aio-tc-site-style'); //Scripts wp_enqueue_script('aio_time_clock_lite_js', plugins_url('/js/time-clock-lite.js', __FILE__), array('jquery'), $this->getVersion()); wp_enqueue_script('jquery'); 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_localize_script('aio_time_clock_lite_js', 'timeClockAjax', $this->getTranslationStrings() ); } public function adminScripts() { //Styles wp_register_style('datetimepicker-style', plugins_url('js/datetimepicker/jquery.datetimepicker.css', __FILE__)); wp_enqueue_style('datetimepicker-style'); 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_style('aio-tc-admin-style'); wp_enqueue_style('aio-tc-lite-steps-style'); //Scripts wp_enqueue_script('jquery'); wp_register_script("aio_time_clock_lite_steps", plugins_url('/js/jquery.steps.min.js', __FILE__), array('jquery')); wp_enqueue_script('aio_time_clock_lite_admin_js', plugins_url('/js/time-clock-lite-admin.js', __FILE__), array('jquery'), $this->getVersion()); wp_enqueue_script('nert-aio-timepicker', plugins_url('js/datetimepicker/jquery.datetimepicker.js', __FILE__), array('jquery')); wp_enqueue_script('aio_time_clock_lite_admin_js'); wp_enqueue_script('aio_time_clock_lite_steps'); wp_localize_script('aio_time_clock_lite_admin_js', 'timeClockAdminAjax', $this->getTranslationStrings() ); } 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 ($seconds != null) { $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' => false, '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, 'shiftColumnsFilter'), 10, 1); add_action('manage_shift_posts_custom_column', array($this, 'shiftColumn'), 10, 2); } public function shiftColumnsFilter($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 shiftColumn($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 = $this->cleanDate($custom['employee_clock_in_time'][0]); } $employee_clock_out_time = null; if (isset($custom['employee_clock_out_time'][0])) { $employee_clock_out_time = $this->cleanDate($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)); } $author_id = get_the_author_meta('ID'); switch ($column) { case 'employee': echo $this->getEmployeeName($author_id); break; case 'department': echo $this->getDepartmentColumn($author_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 getDepartmentColumn($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-time-clock-lite'), array($this, 'aio_shift_info_box_content'), 'shift', 'normal', 'high' ); } public function aio_shift_info_box_content() { require_once("aio-time-clock-box-content.php"); } public function getEmployeeSelect($selected = null) { $selected = json_decode($selected); $count = 0; $users = $this->getUsers(); foreach ($users as $user) { $active = ""; if ($selected == $user["employee_id"]) { $active = "selected"; } echo ''; $count++; } } public function getBuiltInRoles() { 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->getBuiltInRoles(); 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', date($this->dateFormat, strtotime($_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', date($this->dateFormat, strtotime($_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->aio_check_tc_shortcode_lite(); $roles = $this->getBuiltInRoles(); if (is_array($user->roles) && $tc_page != null) { 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 (isset($start) && isset($end)) { if ($start != null && $end != null) { if ($this->isValidDate($start) && $this->isValidDate($end)) { $start = str_replace('/', '-', $start); $end = str_replace('/', '-', $end); $s = new DateTime(); $start_date = $s->setTimestamp(intval(strtotime($start))); $e = new DateTime(); $end_date = $e->setTimestamp(intval(strtotime($end))); $diff = $end_date->diff($start_date); $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; } public function getDateFormat() { $date_format = get_option('date_format'); if ($date_format == null) { $date_format = 'Y-m-d'; } return $date_format; } public 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("Y-m-d h:i:s A"); $end_date = date("Y-m-d", strtotime(date("Y-m-d", strtotime($now)) . " - 10 years")); return (strtotime($date) <= strtotime($end_date)); } public 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); } } public 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. ) ); } public 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'); } public 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 ); } public function aio_lite_manage_department_user_column($columns) { unset($columns['posts']); $columns['users'] = __('Users', 'aio-time-clock-lite'); return $columns; } public function aio_lite_manage_department_column($display, $column, $term_id) { if ('users' === $column) { $term = get_term($term_id, 'department'); echo $term->count; } } public function aio_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'); } public function aio_lite_disable_username($username) { if ('department' === $username) { $username = ''; } return $username; } public function isValidDate($date) { $date = str_replace('/', '-', $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->getBuiltInRoles(); 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; } } public function getUsers() { $users = array(); $blog_id = get_current_blog_id(); $built_in_roles = $this->getBuiltInRoles(); $args = array( 'blog_id' => $blog_id, 'role' => '', 'role__in' => $built_in_roles, 'role__not_in' => array(), 'meta_key' => '', 'meta_value' => '', 'meta_compare' => '', 'meta_query' => array(), 'date_query' => array(), 'include' => array(), 'exclude' => array(), 'orderby' => 'login', 'order' => 'ASC', 'offset' => '', 'search' => '', 'number' => '', 'count_total' => false, 'fields' => 'all', 'who' => '', ); $your_users = get_users($args); function compare($a, $b) {return ($a->special > $b->special) ? -1 : 1;} usort($your_users, 'compare'); foreach ($your_users as $user) { array_push( $users, array( "employee_id" => $user->ID, "first_name" => $user->first_name, "last_name" => $user->last_name, "department" => $this->getDepartment($user->ID), "roles" => $user->roles, ) ); } return $users; } public function getEmployeeName($employee_id) { $full_name = null; $first_name = get_the_author_meta('first_name', $employee_id); $last_name = get_the_author_meta('last_name', $employee_id); if (($first_name == null || $last_name == null)) { if ($employee_id != null) { $user_info = get_userdata($employee_id); if (isset($user_info)) { $full_name = $user_info->last_name . ", " . $user_info->first_name; } } } else { $full_name = $last_name . ", " . $first_name; } return $full_name; } public function getDepartment($user_id) { $department = ""; $user_groups = wp_get_object_terms($user_id, 'department', array('fields' => 'all_with_object_id')); // Get user group detail foreach ($user_groups as $user_gro) { $department = $user_gro->name; // Get current user group name } return $department; } public function aio_lite_edit_user_department_section($user) { require_once("templates/department-section.php"); } public function getMonitoringShiftColumn($employee_id){ return '
'.__('Working', 'aio-time-clock').'
'; } 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'), ); } public function getProFeatures(){ $features = array( array( "title" => __('More Settings', 'aio-time-clock-lite'), "description" => __('Easily customize the time clock for your company', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/settings-2.png" ), array( "title" => __('Custom Roles', 'aio-time-clock-lite'), "description" => __('Add your own custom roles for time clock access', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/custom-roles-2.png" ), array( "title" => __('Manager Profiles', 'aio-time-clock-lite'), "description" => __('Manager profiles that can export, import and edit shifts', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/screenshot26.png" ), array( "title" => __('Improved Reports', 'aio-time-clock-lite'), "description" => __('Custom Simple and Advanced Shift Reports', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/advanced-reports.png" ), array( "title" => __('Exportable Reports', 'aio-time-clock-lite'), "description" =>__('Export Reports to Spreadsheet, PDF etc', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/export-reports.png" ), array( "title" => __('Charts and Graphs', 'aio-time-clock-lite'), "description" => __('View activity in the form of a chart', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/chart-graphs-1.png" ), array( "title" => __('Multiple Shift Views', 'aio-time-clock-lite'), "description" => __('View, edit or create bulk shifts', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/shift-views.png" ), array( "title" => __('Predefined Locations', 'aio-time-clock-lite'), "description" => __('Unlimited Clock in Locations', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/locations.png" ), array( "title" => __('IP And GPS Tracking', 'aio-time-clock-lite'), "description" => __('Shifts can show the location of an IP address and a GPS coordinate', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/shift-info.png" ), array( "title" => __('Quick Pick Time Clock', 'aio-time-clock-lite'), "description" => __('List style time clock page with pin pad entry instead of a login', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/quick-pick.png" ), array( "title" => __('Predefined Shifts', 'aio-time-clock-lite'), "description" => __('Create prefined shifts that employees can choose from instead of a dynamic clock', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/predefined-shifts.png" ), array( "title" => __('Extendable', 'aio-time-clock-lite'), "description" => __('Extensions/Addons Supported to allow anything to be possible', 'aio-time-clock-lite'), "image" => "https://codebangers.com/wp-content/uploads/2014/07/extensions-1.png" ) ); return $features; } }