示例#1
0
文件: ask.php 项目: bqq1986/efront
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);
    }
}
示例#2
0
     } else {
         if ($_GET['set_default_group']) {
             $groups = $currentUser->getGroups();
             if (sizeof($groups) > 0) {
                 $group = new EfrontGroup(current($groups));
                 echo json_encode(array('status' => true, 'foreign_ID' => $group->group['id'], 'name' => $group->group['name']));
             }
             exit;
         } else {
             if ($_GET['set_default_branch']) {
                 if (G_VERSIONTYPE == 'enterprise') {
                     #cpp#ifdef ENTERPRISE
                     if (!isset($_SESSION['supervises_branches'])) {
                         require_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
                 $branches = explode(",", $_SESSION['supervises_branches']);
                 if ($_SESSION['supervises_branches'] && sizeof($branches) > 0) {
                     $branch = new EfrontBranch($branches[0]);
                     echo json_encode(array('status' => true, 'foreign_ID' => $branch->branch['branch_ID'], 'name' => $branch->branch['name']));
                 }
                 exit;
             }
         }
     }
 }