Code Duplication    Length = 6-8 lines in 4 locations

main/admin/skills_import.php 1 location

@@ 26-31 (lines=6) @@
23
    // 1. Check if mandatory fields are set.
24
    $mandatory_fields = array('id', 'parent_id', 'name');
25
    foreach ($skills as $index => $skill) {
26
        foreach ($mandatory_fields as $field) {
27
            if (empty($skill[$field])) {
28
                $skill['error'] = get_lang(ucfirst($field).'Mandatory');
29
                $errors[] = $skill;
30
            }
31
        }
32
        // 2. Check skill ID is not empty
33
        if (!isset($skill['id']) || empty($skill['id'])) {
34
            $skill['error'] = get_lang('SkillImportNoID');

main/admin/user_import.php 1 location

@@ 38-43 (lines=6) @@
35
    $usergroup = new UserGroup();
36
37
    foreach ($users as $user) {
38
        foreach ($mandatory_fields as $field) {
39
            if (empty($user[$field])) {
40
                $user['error'] = get_lang($field.'Mandatory');
41
                $errors[] = $user;
42
            }
43
        }
44
        $username = $user['UserName'];
45
        // 2. Check username, first, check whether it is empty.
46
        if (!UserManager::is_username_empty($username)) {

main/admin/user_update_import.php 1 location

@@ 35-42 (lines=8) @@
32
    $usergroup = new UserGroup();
33
34
    foreach ($users as $user) {
35
        foreach ($mandatory_fields as $field) {
36
            if (isset($user[$field])) {
37
                if (empty($user[$field])) {
38
                    $user['error'] = get_lang($field.'Mandatory');
39
                    $errors[] = $user;
40
                }
41
            }
42
        }
43
44
        // 2. Check username, first, check whether it is empty.
45

main/admin/course_import.php 1 location

@@ 24-29 (lines=6) @@
21
22
        // 1. Check whether mandatory fields are set.
23
        $mandatory_fields = array ('Code', 'Title', 'CourseCategory');
24
        foreach ($mandatory_fields as $field) {
25
            if (empty($course[$field])) {
26
                $course['error'] = get_lang($field.'Mandatory');
27
                $errors[] = $course;
28
            }
29
        }
30
31
        // 2. Check current course code.
32
        if (!empty($course['Code'])) {