function hrm_user_can_access($tab = null, $subtab = null, $access_point = null, $inside_role = false)
{
    $user_id = get_current_user_id();
    $super_admin = get_option('hrm_admin', true);
    if ($user_id == $super_admin) {
        return true;
    }
    $page = hrm_page();
    //if tab has no access role
    if (isset($page[$_REQUEST['page']][$tab]['follow_access_role']) && !$page[$_REQUEST['page']][$tab]['follow_access_role']) {
        return true;
    }
    $current_user_role = hrm_current_user_role();
    $roles = get_role($current_user_role);
    if ($inside_role) {
        return isset($roles->capabilities[$access_point]) ? $access_point : false;
    }
    $tab_access = isset($roles->capabilities[$tab . '_' . $access_point]) ? $roles->capabilities[$tab . '_' . $access_point] : '';
    $subtab_access = isset($roles->capabilities[$subtab . '_' . $access_point]) ? $roles->capabilities[$subtab . '_' . $access_point] : '';
    if ($tab_access != $access_point) {
        return false;
    }
    if ($subtab == null) {
        if ($roles->capabilities[$tab . '_' . $access_point] == $access_point) {
            return true;
        } else {
            return false;
        }
    }
    if ($subtab_access != $access_point) {
        return false;
    }
    if (isset($roles->capabilities[$subtab . '_' . $access_point]) && $roles->capabilities[$subtab . '_' . $access_point] == $access_point) {
        return true;
    } else {
        return false;
    }
}
<div class="hrm-update-notification"></div>
<div id="hrm-admin-role"></div>
<?php 
$jk = get_option('pro_test_role');
//hidden form
global $wp_roles;
if (!$wp_roles) {
    $wp_roles = new WP_Roles();
}
//echo '<pre>'; print_r( $wp_roles ); echo '</pre>'; die();
$role_names = $wp_roles->get_names();
$wp_built_in_role = array('administrator', 'editor', 'author', 'contributor', 'subscriber', 'hrm_employee');
$add_permission = hrm_user_can_access($tab, $subtab, 'add') ? true : false;
$delete_permission = hrm_user_can_access($tab, $subtab, 'delete') ? true : false;
$current_user_role = hrm_current_user_role();
foreach ($role_names as $name => $display_name) {
    if ($current_user_role == $name) {
        continue;
    }
    if ($add_permission) {
        $name_id = '<a data-role_name="' . $name . '" data-action="get_role" data-display_name="' . $display_name . '" class="hrm-editable" href="#">' . $name . '</a>';
    } else {
        $name_id = $name;
    }
    $body[] = array($name_id, $display_name);
}
$table['head'] = array('User Role', 'Display Name');
$table['body'] = isset($body) ? $body : array();
$table['td_attr'] = isset($td_attr) ? $td_attr : '';
$table['th_attr'] = array('class="check-column"');
$table['table_attr'] = array('class' => 'widefat');
<div class="hrm-update-notification"></div>
<?php 
if (hrm_current_user_role() == 'hrm_employee') {
    $employer_id = get_current_user_id();
} else {
    $employer_id = isset($_REQUEST['employee_id']) ? trim($_REQUEST['employee_id']) : '';
}
?>
<div id="hrm_personal_language"></div>

<?php 
$results = hrm_Settings::getInstance()->conditional_query_val('hrm_personal_language', $field = '*', $compare = array('emp_id' => $employer_id));
$language_labels = hrm_Settings::getInstance()->hrm_query('hrm_language');
unset($language_labels['total_row']);
foreach ($language_labels as $key => $language_label) {
    $label[$language_label->id] = $language_label->name;
}
foreach ($results as $key => $value) {
    if ($results['total_row'] == 0 || $key === 'total_row') {
        continue;
    }
    if (!isset($label[$value->language_id])) {
        continue;
    }
    $body[] = array('<input name="hrm_check[' . $value->id . ']" value="" type="checkbox">', '<a href="#" class="hrm-editable" data-table_option="hrm_personal_language"  data-id=' . $value->id . '>' . $label[$value->language_id] . '<a>', hrm_Employee::getInstance()->fluency($value->fluency), hrm_Employee::getInstance()->competency($value->competency), $value->comments);
    $td_attr[] = array('class="check-column"');
}
$table = array();
$table['head'] = array('<input type="checkbox">', __('Language', 'hrm'), __('Fluency', 'hrm'), __('Competency', 'hrm'), __('Comments', 'hrm'));
$table['body'] = isset($body) ? $body : array();
$table['td_attr'] = isset($td_attr) ? $td_attr : array();
예제 #4
0
 function admin_menu()
 {
     $capability = 'read';
     //minimum level: subscriber
     if (hrm_current_user_role() != 'hrm_employee') {
         $menu = add_menu_page(__('HRM', 'hrm'), __('HRM', 'hrm'), $capability, 'hrm_management', array($this, 'admin_page_handler'), '');
         $admin_sub_menu = add_submenu_page('hrm_management', __('Admin', 'hrm'), __('Admin', 'hrm'), $capability, 'hrm_management', array($this, 'admin_page_handler'));
         $pim = add_submenu_page('hrm_management', __('PIM', 'hrm'), __('PIM', 'hrm'), $capability, 'hrm_pim', array($this, 'admin_page_handler'));
         $leave = add_submenu_page('hrm_management', __('Leave', 'hrm'), __('Leave', 'hrm'), $capability, 'hrm_leave', array($this, 'admin_page_handler'));
         $attendance = add_submenu_page('hrm_management', __('Time', 'hrm'), __('Time', 'hrm'), $capability, 'hrm_time', array($this, 'admin_page_handler'));
         $evaluation = add_submenu_page('hrm_management', __('Evaluation', 'hrm'), __('Evaluation', 'hrm'), $capability, 'hrm_evaluation', array($this, 'admin_page_handler'));
         $file = add_submenu_page('hrm_management', __('File', 'hrm'), __('File', 'hrm'), $capability, 'hrm_file', array($this, 'admin_page_handler'));
         $author = add_submenu_page('hrm_management', __('Support', 'hrm'), __('Support', 'hrm'), $capability, 'hrm_author', array($this, 'admin_page_handler'));
         add_action('admin_print_styles-' . $admin_sub_menu, array($this, 'admin_scripts'));
         add_action('admin_print_styles-' . $pim, array($this, 'pim_scripts'));
         add_action('admin_print_styles-' . $leave, array($this, 'leave_scripts'));
         add_action('admin_print_styles-' . $attendance, array($this, 'attendance_scripts'));
         add_action('admin_print_styles-' . $evaluation, array($this, 'evaluation_scripts'));
         add_action('admin_print_styles-' . $author, array($this, 'author_scripts'));
         add_action('admin_print_styles-' . $file, array($this, 'file_scripts'));
     } else {
         $user_id = get_current_user_id();
         $menu = add_menu_page(__('HRM', 'hrm'), __('HRM', 'hrm'), $capability, 'hrm_employee', array($this, 'admin_page_handler'));
         $menu = add_submenu_page('hrm_employee', __('My Info', 'hrm'), __('My Info', 'hrm'), $capability, 'hrm_employee', array($this, 'admin_page_handler'));
         $attendance = add_submenu_page('hrm_employee', __('Time', 'hrm'), __('Time', 'hrm'), $capability, 'hrm_time', array($this, 'admin_page_handler'));
         $file = add_submenu_page('hrm_employee', __('File', 'hrm'), __('File', 'hrm'), $capability, 'hrm_file', array($this, 'admin_page_handler'));
         add_action('admin_print_styles-' . $attendance, array($this, 'attendance_scripts'));
         add_action('admin_print_styles-' . $file, array($this, 'file_scripts'));
         $this->admin_scripts();
     }
 }