Ejemplo n.º 1
0
 protected function importData($line, $type, $data)
 {
     //pr($line);exit;
     try {
         switch ($type) {
             case "users":
                 $newUser = EfrontUser::createUser($data);
                 $this->log["success"][] = _LINE . " {$line}: " . _IMPORTEDUSER . " " . $newUser->login;
                 break;
             case "users_to_courses":
                 //Check if a user exists and whether it has the same case
                 $userFound = false;
                 if (!in_array($data['users_login'], $this->allUserLogins)) {
                     //For case-insensitive matches
                     foreach ($this->allUserLogins as $login) {
                         if (mb_strtolower($data['users_login']) == mb_strtolower($login)) {
                             $data['users_login'] = $login;
                             $userFound = true;
                         }
                     }
                 } else {
                     $userFound = true;
                 }
                 if ($userFound) {
                     $courses_name = trim($data['course_name']);
                     $courses_ID = $this->getCourseByName($courses_name);
                     unset($data['course_name']);
                     if ($courses_ID) {
                         foreach ($courses_ID as $course_ID) {
                             $data['courses_ID'] = $course_ID;
                             $course = new EfrontCourse($course_ID);
                             if (is_null($this->course_users[$course_ID])) {
                                 $result = eF_getTableDataFlat("users_to_courses", "users_LOGIN", "courses_ID={$course_ID} AND archive=0");
                                 $this->course_users[$course_ID] = array_combine($result['users_LOGIN'], $result['users_LOGIN']);
                             }
                             if (isset($this->course_users[$course_ID][$data['users_login']])) {
                                 throw new Exception("User is already assigned to the course", self::USER_TO_COURSE_EXISTS);
                             }
                             //$course -> addUsers($data['users_login'], (isset($data['user_type']) && $data['user_type']?$data['user_type']:"student"));
                             $course->addUsers($data['users_login'], isset($data['user_type']) ? $data['user_type'] : "student");
                             $where = "users_login = '******'users_login'] . "' AND courses_ID = " . $data['courses_ID'];
                             $data['completed'] ? $data['completed'] = 1 : ($data['completed'] = 0);
                             EfrontCourse::persistCourseUsers($data, $where, $data['courses_ID'], $data['users_login']);
                             if ($data['active']) {
                                 $course->confirm($data['users_login']);
                             } else {
                                 $course->unconfirm($data['users_login']);
                             }
                             $this->course_users[$course_ID][$data['users_login']] = $data['users_login'];
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWCOURSEASSIGNMENT . " " . $courses_name . " - " . $data['users_login'];
                         }
                     } else {
                         if ($courses_name != "") {
                             $course = EfrontCourse::createCourse(array("name" => $courses_name));
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWCOURSE . " " . $courses_name;
                             $course->addUsers($data['users_login'], isset($data['user_type']) ? $data['user_type'] : "student");
                             $courses_ID = $course->course['id'];
                             $this->courseNamesToIds[$courses_name] = array($courses_ID);
                             $where = "users_login = '******'users_login'] . "' AND courses_ID = " . $courses_ID;
                             EfrontCourse::persistCourseUsers($data, $where, $courses_ID, $data['users_login']);
                             if ($data['active']) {
                                 $course->confirm($data['users_login']);
                             } else {
                                 $course->unconfirm($data['users_login']);
                             }
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWCOURSEASSIGNMENT . " " . $courses_name . " - " . $data['users_login'];
                         } else {
                             $this->log["failure"][] = _LINE . " {$line}: " . _COULDNOTFINDCOURSE . " " . $courses_name;
                         }
                     }
                 } else {
                     $this->log["failure"][] = _LINE . " {$line}: " . _USERDOESNOTEXIST . ": " . $data['users_login'];
                 }
                 break;
             case "users_to_lessons":
                 //Check if a user exists and whether it has the same case
                 $userFound = false;
                 if (!in_array($data['users_login'], $this->allUserLogins)) {
                     //For case-insensitive matches
                     foreach ($this->allUserLogins as $login) {
                         if (mb_strtolower($data['users_login']) == mb_strtolower($login)) {
                             $data['users_login'] = $login;
                             $userFound = true;
                         }
                     }
                 } else {
                     $userFound = true;
                 }
                 if ($userFound) {
                     $lessons_name = trim($data['lesson_name']);
                     $lessons_ID = $this->getLessonByName($lessons_name);
                     unset($data['lesson_name']);
                     if ($lessons_ID) {
                         foreach ($lessons_ID as $lesson_ID) {
                             $data['lessons_ID'] = $lesson_ID;
                             $lesson = new EfrontLesson($lesson_ID);
                             if (is_null($this->lesson_users[$lesson_ID])) {
                                 $result = eF_getTableDataFlat("users_to_lessons", "users_LOGIN", "lessons_ID={$lesson_ID} AND archive=0");
                                 $this->lesson_users[$lesson_ID] = array_combine($result['users_LOGIN'], $result['users_LOGIN']);
                             }
                             if (isset($this->lesson_users[$lesson_ID][$data['users_login']])) {
                                 throw new Exception("User is already assigned to the lesson", self::USER_TO_LESSON_EXISTS);
                             }
                             if (!$lesson->lesson['course_only']) {
                                 $lesson->addUsers($data['users_login'], isset($data['user_type']) ? $data['user_type'] : "student");
                             }
                             $data['completed'] ? $data['completed'] = 1 : ($data['completed'] = 0);
                             eF_updateTableData("users_to_lessons", $data, "users_login = '******'users_login'] . "' AND lessons_ID = " . $data['lessons_ID']);
                             if (!$lesson->lesson['course_only']) {
                                 if ($data['active']) {
                                     $lesson->confirm($data['users_login']);
                                 } else {
                                     $lesson->unconfirm($data['users_login']);
                                 }
                             }
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWLESSONASSIGNMENT . " " . $lessons_name . " - " . $data['users_login'];
                         }
                     } else {
                         if ($lessons_name != "") {
                             $lesson = EfrontLesson::createLesson(array("name" => $lessons_name, 'course_only' => false));
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWLESSON . " " . $lessons_name;
                             $lesson->addUsers($data['users_login'], isset($data['user_type']) ? $data['user_type'] : "student");
                             $lessons_ID = $lesson->lesson['id'];
                             $this->lessonNamesToIds[$lessons_name] = array($lessons_ID);
                             eF_updateTableData("users_to_lessons", $data, "users_login = '******'users_login'] . "' AND lessons_ID = " . $lessons_ID);
                             if ($data['active']) {
                                 $lesson->confirm($data['users_login']);
                             } else {
                                 $lesson->unconfirm($data['users_login']);
                             }
                             $this->log["success"][] = _LINE . " {$line}: " . _NEWLESSONASSIGNMENT . " " . $lessons_name . " - " . $data['users_login'];
                         } else {
                             $this->log["failure"][] = _LINE . " {$line}: " . _COULDNOTFINDLESSON . " " . $lessons_name;
                         }
                     }
                 } else {
                     $this->log["failure"][] = _LINE . " {$line}: " . _USERDOESNOTEXIST . ": " . $data['users_login'];
                 }
                 break;
             case "users_to_groups":
                 //debug();
                 $groups_ID = $this->getGroupByName($data['groups.name']);
                 $group_name = $data['groups.name'];
                 unset($data['groups.name']);
                 foreach ($groups_ID as $group_ID) {
                     $data['groups_ID'] = $group_ID;
                     $group = new EfrontGroup($group_ID);
                     $group->addUsers(array($data['users_login']));
                     $this->log["success"][] = _LINE . " {$line}: " . _NEWGROUPASSIGNMENT . " " . $group_name . " - " . $data['users_login'];
                 }
                 break;
                 //debug(false);
                 #cpp#ifdef ENTERPRISE
             //debug(false);
             #cpp#ifdef ENTERPRISE
             case "employees":
                 $this->cleanUpEmptyValues($data);
                 // a bit customized here, based on the fact that employees are always created together AFTER users (so the object should exist)
                 eF_updateTableData("module_hcd_employees", $data, "users_login='******'users_login'] . "'");
                 break;
             case "branches":
                 // If no father defined - root, else we may need to create the father first
                 $data['father_branch_ID'] = $this->getFatherBranchId($data['father_branch_name']);
                 $father_name = $data['father_branch_name'];
                 $branch_ID = $this->getBranchByName($data['name']);
                 $branch_name = $data['name'];
                 if (sizeof($branch_ID) > 0 && $data['name'] != $data['father_branch_name']) {
                     //TODO
                     unset($data['father_branch_name']);
                     $data['branch_ID'] = $branch_ID[0];
                     throw new EfrontBranchException(_BRANCHALREADYEXISTS, EfrontBranchException::BRANCH_EXISTS);
                 } else {
                     unset($data['father_branch_name']);
                     $data['url'] = EfrontBranch::getBranchUrl($data['name']);
                     $branch = EfrontBranch::createBranch($data);
                     $this->setBranchByName($branch_name, $branch->branch['branch_ID']);
                 }
                 $this->log["success"][] = _LINE . " {$line}: " . _NEWBRANCH . " " . $branch_name;
                 break;
             case "job_descriptions":
                 if ($data['branch_name'] == "") {
                     $data['branch_ID'] = "all";
                     // this denotes to the createJob class to put the job in all branches
                 } else {
                     $data['branch_ID'] = $this->getBranchByName($data['branch_name']);
                     if (sizeof($data['branch_ID']) > 0) {
                         //TODO: maybe different handling when multiple branches are found
                         $data['branch_ID'] = $data['branch_ID'][0];
                     } else {
                         throw new EfrontJobException(_BRANCHDESIGNATEDFORTHISJOBDESCRIPTIONDOESNOTEXIST, EfrontJobException::BRANCH_NOT_EXISTS);
                     }
                 }
                 unset($data['branch_name']);
                 if ($data['description'] != "") {
                     $job_ID = $this->getJobByName($data['description']);
                     if (sizeof($job_ID) > 0) {
                         $data['job_description_ID'] = $job_ID[0];
                         throw new EfrontJobException(_JOBDESCRIPTIONEXISTSALREADY, EfrontJobException::JOB_ALREADY_EXISTS);
                     } else {
                         EfrontJob::createJob($data);
                         $this->log["success"][] = _LINE . " {$line}: " . _NEWJOB . " " . $data['description'];
                     }
                 } else {
                     $this->log["failure"][] = _LINE . " {$line}: " . _NOTITLEPROVIDEDFORNEWJOB;
                 }
                 break;
             case "skills":
                 if ($data['skill_category'] == "") {
                     throw new EfrontSkillException(_MISSINGSKILLCATEGORY, EfrontSkillException::INVALID_SKILL_CATEGORY);
                 } else {
                     $data['categories_ID'] = $this->getSkillCategoryByName($data['skill_category']);
                     if ($data['categories_ID'][0] != "") {
                         $data['categories_ID'] = $data['categories_ID'][0];
                     } else {
                         // create skill category
                         $data['categories_ID'] = eF_insertTableData("module_hcd_skill_categories", array('description' => $data['skill_category']));
                         $this->setSkillCategoryByName($data['skill_category'], $data['categories_ID']);
                     }
                 }
                 unset($data['skill_category']);
                 $skill_ID = $this->getSkillByName($data['description']);
                 if ($skill_ID) {
                     //TODO: another double issue
                     $data['skill_ID'] = $skill_ID[0];
                     throw new EfrontSkillException(_SKILLALREADYEXISTS, EfrontSkillException::SKILL_EXISTS);
                 } else {
                     EfrontSkill::createSkill($data);
                     $this->log["success"][] = _LINE . " {$line}: " . _NEWSKILL . " " . $data['description'];
                 }
                 break;
             case "users_to_jobs":
                 // Get user
                 $user = EfrontUserFactory::factory($data["users_login"]);
                 // Get branch id
                 $branch_ID = $this->getBranchByName($data['branch_name']);
                 $branch_name = $data['branch_name'];
                 if ($branch_ID[0] != "") {
                     if (sizeof($branch_ID) == 1) {
                         $branch_ID = $branch_ID[0];
                     } else {
                         throw new EfrontBranchException(_BRANCHNAMEAMBIGUOUS, EfrontBranchException::BRANCH_AMBIGUOUS);
                     }
                 } else {
                     throw new EfrontBranchException(_BRANCHDOESNOTEXIST, EfrontBranchException::BRANCH_NOT_EXISTS);
                 }
                 // Get job id
                 $job_name = $data['description'];
                 if ($job_name != "") {
                     $new_job_description_ID = eF_getJobDescriptionId($job_name, $branch_ID);
                 } else {
                     throw new EfrontJobException(_MISSING_JOB_DESCRIPTION, EfrontJobException::MISSING_JOB_DESCRIPTION);
                 }
                 // Get hcd employee object
                 if ($data['supervisor']) {
                     $employee = new EfrontSupervisor(array("users_login" => $data["users_login"]));
                     $position = 1;
                 } else {
                     $employee = new EfrontEmployee(array("users_login" => $data["users_login"]));
                     $position = 0;
                 }
                 // Assign job
                 try {
                     $employee->addJob($user, $new_job_description_ID, $branch_ID, $position);
                     $this->log["success"][] = _LINE . " {$line}: " . _NEWJOBASSIGNMENT . " " . $data["users_login"] . " - (" . $branch_name . " - " . $job_name . ") ";
                 } catch (Exception $e) {
                     if ($this->options['replace_existing']) {
                         $employee->removeJob($new_job_description_ID);
                         $employee->addJob($user, $new_job_description_ID, $branch_ID, $position);
                         $this->log["success"][] = _LINE . " {$line}: " . _NEWJOBASSIGNMENT . " " . $data["users_login"] . " - (" . $branch_name . " - " . $job_name . ") ";
                     }
                 }
                 break;
             case "users_to_skills":
                 $skill_ID = $this->getSkillByName($data['description']);
                 $skill_name = $data['description'];
                 if ($skill_ID[0] != "") {
                     if (sizeof($skill_ID) == 1) {
                         $skill_ID = $skill_ID[0];
                     } else {
                         throw new EfrontSkillException(_SKILLNAMEAMBIGUOUS, EfrontSkillException::SKILL_AMBIGUOUS);
                     }
                 } else {
                     throw new EfrontSkillException(_SKILLDOESNOTEXIST, EfrontSkillException::SKILL_NOT_EXISTS);
                 }
                 $skill = new EfrontSkill($skill_ID);
                 $skill->assignToEmployee($data['users_login'], $data['specification']);
                 $this->log["success"][] = _LINE . " {$line}: " . _NEWSKILLASSIGNMENT . " " . $data["users_login"] . " - " . $skill_name;
                 break;
             case "courses_to_branches":
                 $branchId = $this->getBranchByName($data['branch_name']);
                 if (!$branchId[0]) {
                     $fields = array('name' => $data['branch_name'], 'url' => EfrontBranch::getBranchUrl($data['branch_name']));
                     $branch = EfrontBranch::createBranch($fields);
                 } else {
                     $branch = new EfrontBranch($branchId[0]);
                 }
                 $courseId = $this->getCourseByName($data['course_name']);
                 if ($courseId[0]) {
                     $branch->addCoursesToBranch($courseId[0]);
                 }
                 $this->log["success"][] = _LINE . " {$line}: " . _NEWCOURSETOBRANCHASSIGNMENT . " " . $data['course_name'] . " - " . $data['branch_name'];
                 break;
                 #cpp#endif
         }
     } catch (Exception $e) {
         if ($this->options['replace_existing']) {
             if ($this->isAlreadyExistsException($e->getCode(), $type)) {
                 $this->updateExistingData($line, $type, $data);
             } else {
                 $this->log["failure"][] = _LINE . " {$line}: " . $e->getMessage();
                 // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
             }
         } else {
             $this->log["failure"][] = _LINE . " {$line}: " . $e->getMessage();
             // ." ". str_replace("\n", "<BR>", $e->getTraceAsString());
         }
     }
 }
Ejemplo n.º 2
0
function askSkills()
{
    try {
        eF_checkParameter($_POST['preffix'], 'text') ? $preffix = $_POST['preffix'] : ($preffix = '%');
        $skills = array();
        $result = EfrontSkill::getAllSkills();
        for ($i = 0; $i < sizeof($result); $i++) {
            if ($preffix == '%' || stripos($result[$i]['description'], $preffix) !== false) {
                $hiname = highlightSearch($result[$i]['description'], $preffix);
                $skills[$i] = array('id' => $result[$i]['skill_ID'], 'description' => $result[$i]['description'], 'path_string' => $result[$i]['category_description'] . '&nbsp;&rarr;&nbsp;' . $hiname);
            }
        }
        $skills = array_values(eF_multisort($skills, 'path_string', 'asc'));
        //Sort results based on path string
        $str = '<ul>';
        for ($k = 0; $k < sizeof($skills); $k++) {
            $str = $str . '<li id=' . $skills[$k]['id'] . '>' . $skills[$k]['path_string'] . '</li>';
        }
        $str .= '</ul>';
        echo $str;
    } catch (Exception $e) {
        handleAjaxExceptions($e);
    }
}
Ejemplo n.º 3
0
        include "sorted_table.php";
    }
}
if (isset($_GET['postAjaxRequest']) && $_change_skills_) {
    try {
        $_GET['specification'] = urldecode($_GET['specification']);
        if (isset($_GET['add_skill'])) {
            if ($_GET['insert'] == "true") {
                $editedEmployee->addSkills($_GET['add_skill'], $_GET['specification'], $_GET['score']);
            } else {
                if ($_GET['insert'] == "false") {
                    $editedEmployee->removeSkills($_GET['add_skill']);
                } else {
                    if (isset($_GET['addAll']) || isset($_GET['removeAll'])) {
                        $skills = array_keys($editedEmployee->getSkills());
                        $allSkills = EfrontSkill::getAllSkills();
                        isset($_GET['filter']) ? $allSkills = eF_filterData($allSkills, $_GET['filter']) : null;
                        foreach ($allSkills as $skill) {
                            if (isset($_GET['removeAll'])) {
                                if (in_array($skill['skill_ID'], $skills)) {
                                    $editedEmployee->removeSkills($skill['skill_ID']);
                                }
                            } else {
                                if (!in_array($skill['skill_ID'], $skills)) {
                                    $editedEmployee->addSkills($skill['skill_ID'], "");
                                }
                            }
                        }
                    } else {
                        if (isset($_GET['from_skillgap_test'])) {
                            $skillsToAdd = array();
Ejemplo n.º 4
0
             } else {
                 // Remove that lesson from the list by swapping it with the last lesson - no questions left to dig
                 $directions_to_cover[$directionId]['lessons'][$selected_lesson] = $directions_to_cover[$directionId]['lessons'][$directions_to_cover[$directionId]['lessonsCount'] - 1];
                 $directions_to_cover[$directionId]['lessonsCount']--;
                 // Do not decrease the questions - none was assigned
             }
         }
     }
 }
 if (G_VERSIONTYPE == 'enterprise') {
     #cpp#ifdef ENTERPRISE
     // For enterprise edition include also any skill or skill_categories requested
     /************** Step 1: Create all the skills involved array in $skills_to_cover ***********/
     foreach ($skill_categories_to_cover as $categoryId => $category) {
         // Get all skill_category lessons
         $skill_category_skills = EfrontSkill::getCategorySkills($categoryId);
         $skill_categories_to_cover[$categoryId]['skills'] = array();
         $skill_categories_to_cover[$categoryId]['skillsCount'] = sizeof($skill_category_skills);
         // used with rand()
         foreach ($skill_category_skills as $skillId => $skill) {
             $skill_categories_to_cover[$categoryId]['skills'][] = $skillId;
             if (!isset($skills_to_cover[$skillId])) {
                 $skills_to_cover[$skillId] = array("id" => $skillId, "questions_asked" => 0, "total_questions" => 0, "questions" => array());
             }
         }
     }
     /********** Step 2: Get all questions related with those questions********/
     $all_implicated_questions = eF_getTableData("questions_to_skills JOIN questions ON id = questions_id", "id, skills_ID", "skills_ID in ('" . implode("','", array_keys($skills_to_cover)) . "') AND type <> 'raw_text'");
     foreach ($all_implicated_questions as $question) {
         $skills_to_cover[$question['skills_ID']]['total_questions']++;
         $skills_to_cover[$question['skills_ID']]['questions'][] = $question['id'];