function askBranches() { try { if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE if (!isset($_SESSION['supervises_branches'])) { include_once $path . "module_hcd_tools.php"; //Automatically fix missing branch assignments for supervisors eF_assignSupervisorMissingSubBranchesRecursive(); //discover employee role in the hierarchy eF_getRights(); } } #cpp#endif eF_checkParameter($_POST['preffix'], 'text') ? $preffix = $_POST['preffix'] : ($preffix = '%'); if ($_SESSION['s_type'] == "administrator") { $result = eF_getTableData("(module_hcd_branch LEFT OUTER JOIN (module_hcd_employee_works_at_branch JOIN users ON module_hcd_employee_works_at_branch.users_LOGIN = users.login) ON module_hcd_branch.branch_ID = module_hcd_employee_works_at_branch.branch_ID AND module_hcd_employee_works_at_branch.assigned = '1') LEFT OUTER JOIN module_hcd_branch as branch1 ON module_hcd_branch.father_branch_ID = branch1.branch_ID GROUP BY module_hcd_branch.branch_ID ORDER BY branch1.branch_ID", "module_hcd_branch.branch_ID, module_hcd_branch.name, module_hcd_branch.city, module_hcd_branch.address, sum(CASE WHEN users.active=1 THEN 1 END) as employees, sum(CASE WHEN users.active=0 THEN 1 END) as inactive_employees, branch1.branch_ID as father_ID, branch1.name as father, supervisor", ""); } elseif ($_SESSION['supervises_branches']) { $result = eF_getTableData("(module_hcd_branch LEFT OUTER JOIN (module_hcd_employee_works_at_branch JOIN users ON module_hcd_employee_works_at_branch.users_LOGIN = users.login) ON module_hcd_branch.branch_ID = module_hcd_employee_works_at_branch.branch_ID AND module_hcd_employee_works_at_branch.assigned = '1') LEFT OUTER JOIN module_hcd_branch as branch1 ON module_hcd_branch.father_branch_ID = branch1.branch_ID WHERE module_hcd_branch.branch_ID IN (" . $_SESSION['supervises_branches'] . ") GROUP BY module_hcd_branch.branch_ID ORDER BY branch1.branch_ID", "module_hcd_branch.name, module_hcd_branch.city, module_hcd_branch.address, sum(CASE WHEN users.active=1 THEN 1 END) as employees, sum(CASE WHEN users.active=0 THEN 1 END) as inactive_employees, module_hcd_branch.branch_ID, branch1.branch_ID as father_ID, branch1.name as father", ""); } else { $result = array(); } $branches = array(); foreach ($result as $value) { $branches[$value['branch_ID']] = $value; } $tree = new EfrontBranchesTree(); $branchKeys = array_keys($branches); $branchKeys = array_combine($branchKeys, $branchKeys); $branch_results = array(); foreach ($tree->toPathString() as $key => $branch) { if (isset($branchKeys[$key])) { if ($preffix == '%' || stripos($branch, $preffix) !== false || stripos($branch, htmlentities($preffix)) !== false) { $truncated = eF_truncatePath($branch, 80, 6, "...", " → "); $hiname = highlightSearch($truncated, $preffix); $branch_results[$key] = array('branch_ID' => $key, 'name' => $branch, 'path_string' => $hiname); } } } $strs = array(); $strs[] = '<ul>'; foreach ($branch_results as $key => $branch) { $strs[] = '<li id=' . $key . '>' . $branch['path_string'] . '</li>'; } $strs[] = '</ul>'; echo implode("", $strs); } catch (Exception $e) { handleAjaxExceptions($e); } }
#cpp#endif if (!isset($_GET['ajax'])) { if ($_SESSION['s_type'] == 'administrator') { //supervisors don't see groups $groups = EfrontGroup::getGroups(); $smarty->assign("T_GROUPS", $groups); } else { $groups = $currentUser->getGroups(); // Changed for 3.6.15 to show only professor's groups $smarty->assign("T_GROUPS", $groups); } if (G_VERSIONTYPE == 'enterprise') { #cpp#ifdef ENTERPRISE // Create the branches select require_once $path . "module_hcd_tools.php"; eF_getRights(); $company_branches = eF_getTableData("module_hcd_branch", "branch_ID, name, father_branch_ID", "", "father_branch_ID ASC,branch_ID ASC"); if ($_SESSION['s_type'] != 'administrator' && $currentEmployee->isSupervisor()) { //this applies to supervisors only foreach ($company_branches as $key => $value) { if (!in_array($value['branch_ID'], $allowedBranches)) { unset($company_branches[$key]); } } $company_branches = array_values($company_branches); } $filter_branches = eF_createBranchesTreeSelect($company_branches, 4); $smarty->assign("T_BRANCHES", $filter_branches); $job_descriptions = eF_getTableData("module_hcd_job_description", "description,job_description_ID,branch_ID", "", "description ASC"); if ($_SESSION['s_type'] != 'administrator' && $currentEmployee->isSupervisor()) { //this applies to supervisors only
function eF_assignSupervisorMissingSubBranches() { //pr($_SESSION['supervises_branches']); $currentUser = $GLOBALS['currentUser']; $supervisor_at_branches = eF_getRights(); if ($currentUser->aspects['hcd'] instanceof EfrontSupervisor || $currentUser->aspects['hcd'] instanceof EfrontHcdAdministrator) { $derivedSupervisorAtBranches = array_keys($currentUser->aspects['hcd']->getSupervisedBranchesRecursive()); //This dynamically calculates the branches that the user is supervisor. It is used to automatically fix discrepancies (for example, when a user is supervisor in branch A and not in branch A->B->C) } else { $derivedSupervisorAtBranches = array(); } $fixed = false; foreach ($derivedSupervisorAtBranches as $branchId) { if (!in_array($branchId, $supervisor_at_branches['branch_ID'])) { $fields = array('users_login' => $currentUser->user['login'], 'supervisor' => 1, 'assigned' => 0, 'branch_ID' => $branchId); eF_insertTableData("module_hcd_employee_works_at_branch", $fields); $fixed = true; } } return $fixed; }