handleRoles();
}
public function getVersion(){
return "1.2.5";
}
public function handleRoles(){
remove_role('manager');
$result = add_role(
'manager',
__('Manager'),
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'),
array(
'read' => true,
)
);
remove_role('employee');
$result = add_role(
'employee',
__('Employee'),
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', __('General Settings', 'aio-time-clock-lite'), __('General 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',
array(
'ajaxurl' => admin_url('admin-ajax.php'),
'isClockedIn' => __('You are currently clocked in.
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.
Total Shift Time: ', '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')
)
);
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', array('ajaxurl' => admin_url('admin-ajax.php')));
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_um_admin_js(){
$call_type = null;
if (isset($_POST["call_type"])){
$call_type = $_POST["call_type"];
}
if ($call_type == "update_plugin"){
echo json_encode(
array(
"response" => "success",
"message" => "found it"
)
);
}
if ($call_type == "activate_plugin"){
$plugin_path = null;
if (isset($_POST["plugin_path"])){
$plugin_path = $_POST["plugin_path"];
}
if ($plugin_path != null){
$activate_result = activate_plugin($plugin_path, false , false, false);
echo json_encode(
array(
"response" => "success",
"message" => "Plugin activated successfully",
"activate_result" => $activate_result,
"plugin_path" => $plugin_path
)
);
}
else{
echo json_encode(
array(
"response" => "failed",
"message" => "plugin path cannot be null"
)
);
}
}
else if ($call_type == "deactivate_plugin"){
$plugin_path = null;
if (isset($_POST["plugin_path"])){
$plugin_path = $_POST["plugin_path"];
}
if ($plugin_path != null){
$deactivate_result = deactivate_plugins( $plugin_path );
echo json_encode(
array(
"response" => "success",
"message" => "Plugin deactivated successfully",
"activate_result" => $deactivate_result,
"plugin_path" => $plugin_path
)
);
}
else{
echo json_encode(
array(
"response" => "failed",
"message" => "plugin path cannot be null"
)
);
}
}
else if ($call_type == "get_plugins"){
require_once("aio-time-clock-update-manager-table.php");
}
else{
echo json_encode(
array(
"response" => "failed",
"message" => "call_type not found"
)
);
}
wp_reset_postdata();
die();
}
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 = sanitize_text_field($_POST["clock_action"]);
$employee_clock_in_time = null;
$employee_clock_out_time = null;
$is_clocked_in = false;
$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);
$open_shift_id = sanitize_key(intval($open_shift_id));
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 = $custom["employee_clock_in_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" => $employee_clock_in_time,
"employee_clock_out_time" => $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" => $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->dateDifferenceLite($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" => $employee_clock_in_time,
"employee_clock_out_time" => $current_time["current_time"],
"time_total" => $this->aio_seconds_to_time_lite($time_total),
"is_clocked_in" => $is_clocked_in
)
);
} else {
echo json_encode(
array(
"response" => "failed",
"message" => "action does not exist",
"employee" => $employee,
"clock_action" => $clock_action,
)
);
}
wp_reset_postdata();
die();
}
public function aio_seconds_to_time_lite($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');
//return $dtF->diff($dtT)->format('%D:%H:%I:%S');
$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->getDateTimeFormatLite(), strtotime($_POST["aio_pp_start_date"]));
$date_range_end = date($this->getDateTimeFormatLite(), 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->aio_seconds_to_time_lite($this->dateDifferenceLite($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 (strtotime($employee_clock_in_time) > strtotime(0) && strtotime($employee_clock_out_time) > strtotime(0)) {
$total_shift_time = $this->dateDifferenceLite($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 getBuildInRolesLite(){
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->getBuildInRolesLite();
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->getBuildInRolesLite();
$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 = array(
'Pacific/Midway' => '(GMT-11:00) Midway Island, Samoa',
'America/Adak' => '(GMT-10:00) Hawaii-Aleutian',
'Etc/GMT+10' => '(GMT-10:00) Hawaii',
'Pacific/Marquesas' => '(GMT-09:30) Marquesas Islands',
'Pacific/Gambier' => '(GMT-09:00) Gambier Islands',
'America/Anchorage' => '(GMT-09:00) Alaska',
'America/Ensenada' => '(GMT-08:00) Tijuana, Baja California',
'Etc/GMT+8' => '(GMT-08:00) Pitcairn Islands',
'America/Los_Angeles' => '(GMT-08:00) Pacific Time (US & Canada)',
'America/Denver' => '(GMT-07:00) Mountain Time (US & Canada)',
'America/Chihuahua' => '(GMT-07:00) Chihuahua, La Paz, Mazatlan',
'America/Dawson_Creek' => '(GMT-07:00) Arizona',
'America/Belize' => '(GMT-06:00) Saskatchewan, Central America',
'America/Cancun' => '(GMT-06:00) Guadalajara, Mexico City, Monterrey',
'Chile/EasterIsland' => '(GMT-06:00) Easter Island',
'America/Chicago' => '(GMT-06:00) Central Time (US & Canada)',
'America/New_York' => '(GMT-05:00) Eastern Time (US & Canada)',
'America/Havana' => '(GMT-05:00) Cuba',
'America/Bogota' => '(GMT-05:00) Bogota, Lima, Quito, Rio Branco',
'America/Caracas' => '(GMT-04:30) Caracas',
'America/Santiago' => '(GMT-04:00) Santiago',
'America/La_Paz' => '(GMT-04:00) La Paz',
'Atlantic/Stanley' => '(GMT-04:00) Faukland Islands',
'America/Campo_Grande' => '(GMT-04:00) Brazil',
'America/Goose_Bay' => '(GMT-04:00) Atlantic Time (Goose Bay)',
'America/Glace_Bay' => '(GMT-04:00) Atlantic Time (Canada)',
'America/St_Johns' => '(GMT-03:30) Newfoundland',
'America/Araguaina' => '(GMT-03:00) UTC-3',
'America/Montevideo' => '(GMT-03:00) Montevideo',
'America/Miquelon' => '(GMT-03:00) Miquelon, St. Pierre',
'America/Godthab' => '(GMT-03:00) Greenland',
'America/Argentina/Buenos_Aires' => '(GMT-03:00) Buenos Aires',
'America/Sao_Paulo' => '(GMT-03:00) Brasilia',
'America/Noronha' => '(GMT-02:00) Mid-Atlantic',
'Atlantic/Cape_Verde' => '(GMT-01:00) Cape Verde Is.',
'Atlantic/Azores' => '(GMT-01:00) Azores',
'Europe/Belfast' => '(GMT) Greenwich Mean Time : Belfast',
'Europe/Dublin' => '(GMT) Greenwich Mean Time : Dublin',
'Europe/Lisbon' => '(GMT) Greenwich Mean Time : Lisbon',
'Europe/London' => '(GMT) Greenwich Mean Time : London',
'Africa/Abidjan' => '(GMT) Monrovia, Reykjavik',
'Europe/Amsterdam' => '(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
'Europe/Belgrade' => '(GMT+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
'Europe/Brussels' => '(GMT+01:00) Brussels, Copenhagen, Madrid, Paris',
'Africa/Algiers' => '(GMT+01:00) West Central Africa',
'Africa/Windhoek' => '(GMT+01:00) Windhoek',
'Asia/Beirut' => '(GMT+02:00) Beirut',
'Africa/Cairo' => '(GMT+02:00) Cairo',
'Asia/Gaza' => '(GMT+02:00) Gaza',
'Africa/Blantyre' => '(GMT+02:00) Harare, Pretoria',
'Asia/Jerusalem' => '(GMT+02:00) Jerusalem',
'Europe/Minsk' => '(GMT+02:00) Minsk',
'Asia/Damascus' => '(GMT+02:00) Syria',
'Europe/Moscow' => '(GMT+03:00) Moscow, St. Petersburg, Volgograd',
'Africa/Addis_Ababa' => '(GMT+03:00) Nairobi',
'Asia/Tehran' => '(GMT+03:30) Tehran',
'Asia/Dubai' => '(GMT+04:00) Abu Dhabi, Muscat',
'Asia/Yerevan' => '(GMT+04:00) Yerevan',
'Asia/Kabul' => '(GMT+04:30) Kabul',
'Asia/Yekaterinburg' => '(GMT+05:00) Ekaterinburg',
'Asia/Tashkent' => '(GMT+05:00) Tashkent',
'Asia/Kolkata' => '(GMT+05:30) Chennai, Kolkata, Mumbai, New Delhi',
'Asia/Katmandu' => '(GMT+05:45) Kathmandu',
'Asia/Dhaka' => '(GMT+06:00) Astana, Dhaka',
'Asia/Novosibirsk' => '(GMT+06:00) Novosibirsk',
'Asia/Rangoon' => '(GMT+06:30) Yangon (Rangoon)',
'Asia/Bangkok' => '(GMT+07:00) Bangkok, Hanoi, Jakarta',
'Asia/Krasnoyarsk' => '(GMT+07:00) Krasnoyarsk',
'Asia/Hong_Kong' => '(GMT+08:00) Beijing, Chongqing, Hong Kong, Urumqi',
'Asia/Irkutsk' => '(GMT+08:00) Irkutsk, Ulaan Bataar',
'Australia/Perth' => '(GMT+08:00) Perth',
'Australia/Eucla' => '(GMT+08:45) Eucla',
'Asia/Tokyo' => '(GMT+09:00) Osaka, Sapporo, Tokyo',
'Asia/Seoul' => '(GMT+09:00) Seoul',
'Asia/Yakutsk' => '(GMT+09:00) Yakutsk',
'Australia/Adelaide' => '(GMT+09:30) Adelaide',
'Australia/Darwin' => '(GMT+09:30) Darwin',
'Australia/Brisbane' => '(GMT+10:00) Brisbane',
'Australia/Hobart' => '(GMT+10:00) Hobart',
'Asia/Vladivostok' => '(GMT+10:00) Vladivostok',
'Australia/Lord_Howe' => '(GMT+10:30) Lord Howe Island',
'Etc/GMT-11' => '(GMT+11:00) Solomon Is., New Caledonia',
'Asia/Magadan' => '(GMT+11:00) Magadan',
'Pacific/Norfolk' => '(GMT+11:30) Norfolk Island',
'Asia/Anadyr' => '(GMT+12:00) Anadyr, Kamchatka',
'Pacific/Auckland' => '(GMT+12:00) Auckland, Wellington',
'Etc/GMT-12' => '(GMT+12:00) Fiji, Kamchatka, Marshall Is.',
'Pacific/Chatham' => '(GMT+12:45) Chatham Islands',
'Pacific/Tongatapu' => '(GMT+13:00) Nukualofa',
'Pacific/Kiritimati' => '(GMT+14:00) Kiritimati'
);
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 dateDifferenceLite($start, $end)
{
if (isset($start) && isset($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 = date($this->getDateTimeFormatLite(), strtotime($custom["employee_clock_in_time"][0]));
}
if (isset($custom["employee_clock_out_time"][0])) {
$employee_clock_out_time = date($this->getDateTimeFormatLite(), strtotime($custom["employee_clock_out_time"][0]));
}
$searchDateBegin = date($this->getDateTimeFormatLite(), strtotime($date_range_start));
$searchDateEnd = date($this->getDateTimeFormatLite(), strtotime($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->dateDifferenceLite($employee_clock_in_time, $employee_clock_out_time);
$shift_total_time += $shift_sum;
$shift_sum = $this->aio_seconds_to_time_lite($shift_sum);
}
else{
//$shift_sum = $this->aio_seconds_to_time_lite($shift_sum);
}
array_push($shift_array,
array(
"shift_id" => $shift_id,
"employee_clock_in_time" => $employee_clock_in_time,
"employee_clock_out_time" => $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->aio_seconds_to_time_lite($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)) {
?>