Exemplo n.º 1
0
             $supervising_branches = array_merge($supervising_branches, $this_branch_sbs);
         }
         $supervising_branches = array_merge($supervising_branches, array($branch['branch_ID'] => $branch['branch_ID']));
     }
     $result = eF_getTableDataFlat("module_hcd_employee_works_at_branch", "distinct users_login as login", "supervisor = '1' AND branch_ID IN ('" . implode($supervising_branches, "','") . "')");
     break;
 case 'to_branch_supervisors':
     // Find all branches where this employee works
     $branches_working = eF_getTableDataFlat("module_hcd_employee_works_at_branch JOIN module_hcd_branch ON module_hcd_employee_works_at_branch.branch_ID = module_hcd_branch.branch_ID", "module_hcd_branch.branch_ID", "users_login = '******'login'] . "' AND assigned = '1'");
     $result = eF_getTableDataFlat("module_hcd_employee_works_at_branch", "distinct users_login as login", "supervisor = '1' AND assigned='1' AND branch_ID IN ('" . implode($branches_working['branch_ID'], "','") . "')");
     break;
 case 'specific_branch_job_description':
     $branches_list = $form->exportValue('branch_recipients');
     if ($_POST['include_subbranches']) {
         // Find all subbranches - the $branches array has been defined during the creation of the list
         $subbranches = eF_subBranches($form->exportValue('branch_recipients'), $branches);
         $subbranches[] = $form->exportValue('branch_recipients');
         $branches_list .= "','" . implode(",", $subbranches);
     }
     if ($form->exportValue('job_description_recipients') != "" && $form->exportValue('job_description_recipients') != "0") {
         $result = eF_getTableDataFlat("users JOIN module_hcd_employee_has_job_description ON users.login = module_hcd_employee_has_job_description.users_login JOIN module_hcd_job_description ON module_hcd_job_description.job_description_ID = module_hcd_employee_has_job_description.job_description_ID", "distinct login", "users.active = 1 AND module_hcd_job_description.description = '" . $form->exportValue('job_description_recipients') . "' AND module_hcd_job_description.branch_ID IN ('" . $branches_list . "') ");
     } else {
         $result = eF_getTableDataFlat("users JOIN module_hcd_employee_works_at_branch ON users.login = module_hcd_employee_works_at_branch.users_login", "distinct login", "users.active = 1 AND module_hcd_employee_works_at_branch.branch_ID IN ('" . $branches_list . "') AND module_hcd_employee_works_at_branch.assigned = '1'");
     }
     break;
 case 'specific_job_description':
     if ($form->exportValue('job_description_recipients') != "0") {
         $result = eF_getTableDataFlat("users JOIN module_hcd_employee_has_job_description ON users.login = module_hcd_employee_has_job_description.users_login JOIN module_hcd_job_description ON module_hcd_job_description.job_description_ID = module_hcd_employee_has_job_description.job_description_ID", "distinct login", "users.active = 1 AND module_hcd_job_description.description = '" . $form->exportValue('job_description_recipients') . "'");
     } else {
         $result = eF_getTableDataFlat("users JOIN module_hcd_employee_has_job_description ON users.login = module_hcd_employee_has_job_description.users_login", "distinct login", "users.active = 1");
     }
Exemplo n.º 2
0
 protected function importDataMultiple($type, $data)
 {
     try {
         switch ($type) {
             case "users_to_groups":
                 foreach ($data as $value) {
                     $groups_ID = current($this->getGroupByName($value['groups.name']));
                     $groups[$groups_ID][] = $value['users_login'];
                 }
                 foreach ($groups as $id => $groupUsers) {
                     try {
                         $group = new EfrontGroup($id);
                         $this->log["success"][] = _NEWGROUPASSIGNMENT . " " . $group->group['name'];
                         $group->addUsers($groupUsers);
                     } catch (Exception $e) {
                         $this->log["failure"][] = _LINE . " " . ($key + 2) . ": " . $e->getMessage();
                         // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
                     }
                 }
                 break;
             case "users":
                 $existingUsers = eF_getTableDataFlat("users", "login, active, archive");
                 $roles = EfrontUser::getRoles();
                 foreach (EfrontUser::getRoles(true) as $key => $value) {
                     $rolesTypes[$key] = mb_strtolower($value);
                 }
                 $languages = EfrontSystem::getLanguages();
                 $addedUsers = array();
                 foreach ($data as $key => $value) {
                     try {
                         $newUser = EfrontUser::createUser($value, $existingUsers, false);
                         $existingUsers['login'][] = $newUser->user['login'];
                         $existingUsers['active'][] = $newUser->user['active'];
                         $existingUsers['archive'][] = $newUser->user['archive'];
                         $addedUsers[] = $newUser->user['login'];
                         $this->log["success"][] = _IMPORTEDUSER . " " . $newUser->user['login'];
                     } catch (Exception $e) {
                         if ($this->options['replace_existing']) {
                             if ($this->isAlreadyExistsException($e->getCode(), $type)) {
                                 if (!in_array($value['login'], $existingUsers['login'], true)) {
                                     //For case-insensitive matches
                                     foreach ($existingUsers['login'] as $login) {
                                         if (mb_strtolower($value['login']) == mb_strtolower($login)) {
                                             $value['login'] = $login;
                                         }
                                     }
                                 }
                                 if (!isset($value['user_type'])) {
                                     $value['user_type'] = 'student';
                                 } else {
                                     if (in_array(mb_strtolower($value['user_type']), $roles)) {
                                         $value['user_type'] = mb_strtolower($value['user_type']);
                                     } else {
                                         if ($k = array_search(mb_strtolower($value['user_type']), $rolesTypes)) {
                                             $value['user_types_ID'] = $k;
                                             $value['user_type'] = $roles[$k];
                                         } else {
                                             $value['user_type'] = 'student';
                                         }
                                     }
                                 }
                                 if (!in_array($value['user_type'], EFrontUser::$basicUserTypes)) {
                                     $value['user_type'] = 'student';
                                     $value['user_types_ID'] = 0;
                                 }
                                 if ($value['languages_NAME'] == "") {
                                     unset($value['languages_NAME']);
                                 } elseif (in_array($value['languages_NAME'], array_keys($languages)) === false) {
                                     $value['languages_NAME'] = $GLOBALS['configuration']['default_language'];
                                 }
                                 $this->updateExistingData($key + 2, $type, $value);
                             } else {
                                 $this->log["failure"][] = _LINE . " " . ($key + 2) . ": " . $e->getMessage();
                                 // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
                             }
                         } else {
                             $this->log["failure"][] = _LINE . " " . ($key + 2) . ": " . $e->getMessage();
                             // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
                         }
                     }
                 }
                 $defaultGroup = eF_getTableData("groups", "id", "is_default = 1 AND active = 1");
                 if (!empty($defaultGroup) && !empty($addedUsers)) {
                     $defaultGroup = new EfrontGroup($defaultGroup[0]['id']);
                     $defaultGroup->addUsers($addedUsers);
                 }
                 break;
             case "users_to_jobs":
                 $jobDescriptions = $userJobs = $userBranchesAssigned = $userBranchesUnassigned = array();
                 $result = eF_getTableData("module_hcd_job_description", "job_description_ID, branch_ID, description");
                 foreach ($result as $value) {
                     $jobDescriptions[$value['job_description_ID']] = $value;
                 }
                 $result = eF_getTableData("module_hcd_employee_has_job_description", "*");
                 foreach ($result as $value) {
                     $userJobs[$value['users_login']][$value['job_description_ID']] = $value['job_description_ID'];
                 }
                 $result = eF_getTableData("module_hcd_employee_works_at_branch", "*");
                 foreach ($result as $value) {
                     if ($value['assigned']) {
                         $userBranchesAssigned[$value['users_login']][$value['branch_ID']] = $value;
                     } else {
                         $userBranchesUnassigned[$value['users_login']][$value['branch_ID']] = $value;
                     }
                 }
                 $allBranches = eF_getTableData("module_hcd_branch", "branch_ID, father_branch_ID", "");
                 $addedJobs = $addedBranches = array();
                 foreach ($data as $key => $value) {
                     try {
                         if (!$value['description']) {
                             throw new EfrontJobException(_MISSING_JOB_DESCRIPTION, EfrontJobException::MISSING_JOB_DESCRIPTION);
                         }
                         $branchId = $this->getBranchByName($value['branch_name']);
                         //Executes only once
                         if ($branchId[0]) {
                             if (sizeof($branchId) == 1) {
                                 $branchId = $branchId[0];
                             } else {
                                 throw new EfrontBranchException(_BRANCHNAMEAMBIGUOUS . ': ' . $value['branch_name'], EfrontBranchException::BRANCH_AMBIGUOUS);
                             }
                         } else {
                             throw new EfrontBranchException(_BRANCHDOESNOTEXIST . ': ' . $value['branch_name'], EfrontBranchException::BRANCH_NOT_EXISTS);
                         }
                         $jobId = false;
                         foreach ($jobDescriptions as $job) {
                             if ($job['description'] == $value['description'] && $job['branch_ID'] == $branchId) {
                                 $jobId = $job['job_description_ID'];
                             }
                         }
                         if (!$jobId) {
                             $jobId = eF_insertTableData("module_hcd_job_description", array('description' => $value['description'], 'branch_ID' => $branchId));
                             $jobDescriptions[$jobId] = array('job_description_ID' => $jobId, 'description' => $value['description'], 'branch_ID' => $branchId);
                         }
                         $user = EfrontUserFactory::factory($value["users_login"]);
                         $value['users_login'] = $user->user['login'];
                         if (isset($userJobs[$value['users_login']]) && $this->options['replace_assignments']) {
                             $unset = false;
                             foreach ($userJobs[$value['users_login']] as $key => $v) {
                                 if (!isset($addedJobs[$v][$value['users_login']])) {
                                     $user->aspects['hcd']->removeJob($v);
                                     unset($userJobs[$value['users_login']][$v]);
                                     $unset = true;
                                 }
                             }
                             if ($unset) {
                                 unset($userBranchesAssigned[$value['users_login']]);
                             }
                         }
                         if (isset($userJobs[$value['users_login']][$jobId]) && $this->options['replace_existing']) {
                             eF_deleteTableData("module_hcd_employee_has_job_description", "users_login='******'users_login'] . "' AND job_description_ID ='" . $jobId . "'");
                             unset($userJobs[$value['users_login']][$jobId]);
                         }
                         // Check if this job description is already assigned
                         if (!isset($userJobs[$value['users_login']][$jobId])) {
                             if (!isset($userBranchesAssigned[$value['users_login']][$branchId])) {
                                 // Write to the database the new branch assignment: employee to branch (if such an assignment is not already true)
                                 if (isset($userBranchesUnassigned[$value['users_login']][$branchId])) {
                                     eF_updateTableData("module_hcd_employee_works_at_branch", array("assigned" => 1), "users_login='******'users_login'] . "' and branch_ID={$branchId}");
                                     unset($userBranchesUnassigned[$value['users_login']][$branchId]);
                                 } else {
                                     $fields = array('users_login' => $value['users_login'], 'supervisor' => $value['supervisor'], 'assigned' => '1', 'branch_ID' => $branchId);
                                     eF_insertTableData("module_hcd_employee_works_at_branch", $fields);
                                     if ($value['supervisor']) {
                                         //Iterate through sub branches
                                         foreach (eF_subBranches($branchId, $allBranches) as $subBranchId) {
                                             //If this subranch is not associated with the user, associate it
                                             if (!isset($userBranchesAssigned[$value['users_login']][$subBranchId]) && !isset($userBranchesUnassigned[$value['users_login']][$subBranchId])) {
                                                 $fields = array('users_login' => $value['users_login'], 'supervisor' => 1, 'assigned' => '0', 'branch_ID' => $subBranchId);
                                                 eF_insertTableData("module_hcd_employee_works_at_branch", $fields);
                                                 $userBranchesUnassigned[$value['users_login']][$branchId] = array('branch_ID' => $branchId, 'supervisor' => $value['supervisor'], 'assigned' => 0);
                                             } elseif (isset($userBranchesAssigned[$value['users_login']][$subBranchId]) && $userBranchesAssigned[$value['users_login']][$subBranchId]['supervisor'] == 0) {
                                                 eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 1), "users_login='******'users_login'] . "' and branch_ID={$subBranchId}");
                                                 $userBranchesAssigned[$value['users_login']][$subBranchId]['supervisor'] = 1;
                                             } elseif (isset($userBranchesUnassigned[$value['users_login']][$subBranchId]) && $userBranchesUnassigned[$value['users_login']][$subBranchId]['supervisor'] == 0) {
                                                 eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 1), "users_login='******'users_login'] . "' and branch_ID={$subBranchId}");
                                                 $userBranchesUnassigned[$value['users_login']][$subBranchId]['supervisor'] = 1;
                                             }
                                         }
                                     }
                                 }
                                 $userBranchesAssigned[$value['users_login']][$branchId] = array('branch_ID' => $branchId, 'supervisor' => $value['supervisor'], 'assigned' => 1);
                                 $addedBranches[$branchId][$value['users_login']] = $value['users_login'];
                             } elseif (!$userBranchesAssigned[$value['users_login']][$branchId]['supervisor'] && $value['supervisor']) {
                                 eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 1), "users_login='******'users_login'] . "' and branch_ID={$branchId}");
                                 //Iterate through sub branches
                                 foreach (eF_subBranches($branchId, $allBranches) as $subBranchId) {
                                     //If this subranch is not associated with the user, associate it
                                     if (!isset($userBranchesAssigned[$value['users_login']][$subBranchId]) && !isset($userBranchesUnassigned[$value['users_login']][$subBranchId])) {
                                         $fields = array('users_login' => $value['users_login'], 'supervisor' => 1, 'assigned' => '0', 'branch_ID' => $subBranchId);
                                         eF_insertTableData("module_hcd_employee_works_at_branch", $fields);
                                         $userBranchesUnassigned[$value['users_login']][$branchId] = array('branch_ID' => $branchId, 'supervisor' => $value['supervisor'], 'assigned' => 0);
                                     } elseif (isset($userBranchesAssigned[$value['users_login']][$subBranchId]) && $userBranchesAssigned[$value['users_login']][$subBranchId]['supervisor'] == 0) {
                                         eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 1), "users_login='******'users_login'] . "' and branch_ID={$subBranchId}");
                                         $userBranchesAssigned[$value['users_login']][$subBranchId]['supervisor'] = 1;
                                     } elseif (isset($userBranchesUnassigned[$value['users_login']][$subBranchId]) && $userBranchesUnassigned[$value['users_login']][$subBranchId]['supervisor'] == 0) {
                                         eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 1), "users_login='******'users_login'] . "' and branch_ID={$subBranchId}");
                                         $userBranchesUnassigned[$value['users_login']][$subBranchId]['supervisor'] = 1;
                                     }
                                 }
                             } elseif ($userBranchesAssigned[$value['users_login']][$branchId]['supervisor'] && !$value['supervisor']) {
                                 eF_updateTableData("module_hcd_employee_works_at_branch", array("supervisor" => 0), "users_login='******'users_login'] . "' and branch_ID={$branchId}");
                             }
                             // Write to database the new job assignment: employee to job description
                             $fields = array('users_login' => $value['users_login'], 'job_description_ID' => $jobId);
                             eF_insertTableData("module_hcd_employee_has_job_description", $fields);
                             $userJobs[$value['users_login']][$jobId] = $jobId;
                             $addedJobs[$jobId][$value['users_login']] = $value['users_login'];
                             /*
                             									if ($event_info) {
                             										EfrontEvent::triggerEvent(array("type" => EfrontEvent::HCD_NEW_JOB_ASSIGNMENT, "users_LOGIN" => $this -> login, "lessons_ID" => $branchID, "lessons_name" => $bname[0]['name'], "entity_ID" => $jobID, "entity_name" => $job_description, "timestamp" => $event_info['timestamp'], "explicitly_selected" => $event_info['manager']));
                             									} else {
                             										EfrontEvent::triggerEvent(array("type" => EfrontEvent::HCD_NEW_JOB_ASSIGNMENT, "users_LOGIN" => $this -> login, "lessons_ID" => $branchID, "lessons_name" => $bname[0]['name'], "entity_ID" => $jobID, "entity_name" => $job_description));
                             									}
                             */
                         } else {
                             throw new EfrontUserException(_JOBALREADYASSIGNED . ": " . $value['users_login'], EfrontUserException::WRONG_INPUT_TYPE);
                         }
                         $this->log["success"][] = _LINE . " " . ($key + 2) . " : " . _NEWJOBASSIGNMENT . " " . $value["users_login"] . " - (" . $value['branch_name'] . " - " . $value['description'] . ") ";
                     } catch (Exception $e) {
                         $this->log["failure"][] = _LINE . " " . ($key + 2) . " : " . $e->getMessage() . ' (' . $e->getCode() . ')';
                     }
                 }
                 $courseAssignmentsToUsers = $lessonAssignmentsToUsers = array();
                 $result = eF_getTableData("module_hcd_course_to_job_description", "*");
                 foreach ($result as $value) {
                     foreach ($addedJobs[$value['job_description_ID']] as $user) {
                         $courseAssignmentsToUsers[$value['courses_ID']][] = $user;
                     }
                 }
                 $result = eF_getTableData("module_hcd_lesson_to_job_description", "*");
                 foreach ($result as $value) {
                     foreach ($addedJobs[$value['job_description_ID']] as $user) {
                         $lessonAssignmentsToUsers[$value['lessons_ID']][] = $user;
                     }
                 }
                 if ($GLOBALS['configuration']['mode_propagate_courses_to_branch_users']) {
                     $result = eF_getTableData("module_hcd_course_to_branch", "*");
                     foreach ($result as $value) {
                         foreach ($addedBranches[$value['branches_ID']] as $user) {
                             $courseAssignmentsToUsers[$value['courses_ID']][] = $user;
                         }
                     }
                 }
                 foreach ($courseAssignmentsToUsers as $courseId => $users) {
                     $course = new EfrontCourse($courseId);
                     $course->addUsers($users);
                 }
                 foreach ($lessonAssignmentsToUsers as $lessonId => $users) {
                     $course = new EfrontLesson($lessonId);
                     $course->addUsers($users);
                 }
                 break;
         }
     } catch (Exception $e) {
         $this->log["failure"][] = $e->getMessage() . ' (' . $e->getCode() . ')';
         // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
     }
 }
Exemplo n.º 3
0
 	 **************************************************** */
 if (G_VERSIONTYPE == 'enterprise') {
     #cpp#ifdef ENTERPRISE
     if (isset($_GET['branch_ID']) && $_GET['branch_ID'] != "" && $_GET['branch_ID'] != "0" || isset($_GET['job_description_ID']) && $_GET['job_description_ID'] != "0" && $_GET['job_description_ID'] != "" || (isset($_GET['skill_ID']) && $_GET['skill_ID'] != "" && $_GET['skill_ID'] != 0 || isset($_GET['other_skills']) && $_GET['other_skills'] != "")) {
         // Check or not the include subbranches checkbox
         if ($_GET['include_sb'] == "true" || $_POST['include_subbranches']) {
             $include_sb = 1;
         } else {
             $include_sb = 0;
         }
         /* branch_ID equals zero when ANY is selected */
         if ($_GET['branch_ID'] != 0) {
             if ($_GET['branch_ID'] > 0) {
                 if ($include_sb) {
                     $branches = eF_getTableData("module_hcd_branch", "branch_ID, name, father_branch_ID", "");
                     $subbranches = eF_subBranches($_GET['branch_ID'], $branches);
                     $subbranches[] = $_GET['branch_ID'];
                     $branches_list = implode("','", $subbranches);
                     $where_part = "module_hcd_employee_works_at_branch.branch_ID IN ('" . $branches_list . "')";
                 } else {
                     $where_part = "module_hcd_employee_works_at_branch.branch_ID = '" . $_GET['branch_ID'] . "'";
                 }
             } else {
                 $leavesArray = eF_getAllBranchLeaves();
                 if ($_GET['branch_ID'] == -1) {
                     $branches_list = implode("','", $leavesArray);
                 } else {
                     $branches_list = implode("','", $leavesArray);
                     $father_branchesArray = eF_getTableDataFlat("module_hcd_branch as branches JOIN module_hcd_branch as father_branches ON branches.father_branch_ID = father_branches.branch_ID", "father_branches.branch_ID", "branches.branch_ID IN ('" . $branches_list . "')");
                     $father_branchesArray = $father_branchesArray['branch_ID'];
                     if ($include_sb) {