Code Duplication    Length = 11-11 lines in 5 locations

dashboard/application/models/core/Jobs_model.php 5 locations

@@ 33-43 (lines=11) @@
30
            $this->db->truncate('users_ad');
31
32
            $result_admin = ldap_search($ldap_connection, $this->config->item('ldapuserjobouone'), $search_filter, $attributes);
33
            if (FALSE !== $result_admin) {
34
                $entries = ldap_get_entries($ldap_connection, $result_admin);
35
                for ($x = 0; $x < $entries['count']; $x++) {
36
                    if (!empty($entries[$x]['givenname'][0]) &&
37
                            !empty($entries[$x]['samaccountname'][0]) &&
38
                            !empty($entries[$x]['sn'][0]) &&
39
                            !empty($entries[$x]['mail'][0])) {  
40
                        $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0]));
41
                    }
42
                }
43
            }
44
            $result_canterbury = ldap_search($ldap_connection, $this->config->item('ldapuserjoboutwo'), $search_filter, $attributes);
45
            if (FALSE !== $result_canterbury) {
46
                $entries = ldap_get_entries($ldap_connection, $result_canterbury);
@@ 45-55 (lines=11) @@
42
                }
43
            }
44
            $result_canterbury = ldap_search($ldap_connection, $this->config->item('ldapuserjoboutwo'), $search_filter, $attributes);
45
            if (FALSE !== $result_canterbury) {
46
                $entries = ldap_get_entries($ldap_connection, $result_canterbury);
47
                for ($x = 0; $x < $entries['count']; $x++) {
48
                    if (!empty($entries[$x]['givenname'][0]) &&
49
                            !empty($entries[$x]['samaccountname'][0]) &&
50
                            !empty($entries[$x]['sn'][0]) &&
51
                            !empty($entries[$x]['mail'][0])) {
52
                        $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0]));
53
                    }
54
                }
55
            }
56
            $result_sheppy = ldap_search($ldap_connection, $this->config->item('ldapuserjobouthree'), $search_filter, $attributes);
57
            if (FALSE !== $result_sheppy) {
58
                $entries = ldap_get_entries($ldap_connection, $result_sheppy);
@@ 57-67 (lines=11) @@
54
                }
55
            }
56
            $result_sheppy = ldap_search($ldap_connection, $this->config->item('ldapuserjobouthree'), $search_filter, $attributes);
57
            if (FALSE !== $result_sheppy) {
58
                $entries = ldap_get_entries($ldap_connection, $result_sheppy);
59
                for ($x = 0; $x < $entries['count']; $x++) {
60
                    if (!empty($entries[$x]['givenname'][0]) &&
61
                            !empty($entries[$x]['samaccountname'][0]) &&
62
                            !empty($entries[$x]['sn'][0]) &&
63
                            !empty($entries[$x]['mail'][0])) {
64
                        $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0]));
65
                    }
66
                }
67
            }
68
            $result_nicks = ldap_search($ldap_connection, $this->config->item('ldapuserjoboufour'), $search_filter, $attributes);
69
            if (FALSE !== $result_nicks) {
70
                $entries = ldap_get_entries($ldap_connection, $result_nicks);
@@ 69-79 (lines=11) @@
66
                }
67
            }
68
            $result_nicks = ldap_search($ldap_connection, $this->config->item('ldapuserjoboufour'), $search_filter, $attributes);
69
            if (FALSE !== $result_nicks) {
70
                $entries = ldap_get_entries($ldap_connection, $result_nicks);
71
                for ($x = 0; $x < $entries['count']; $x++) {
72
                    if (!empty($entries[$x]['givenname'][0]) &&
73
                            !empty($entries[$x]['samaccountname'][0]) &&
74
                            !empty($entries[$x]['sn'][0]) &&
75
                            !empty($entries[$x]['mail'][0])) {
76
                        $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0]));
77
                    }
78
                }
79
            }
80
            $result_nicks = ldap_search($ldap_connection, $this->config->item('ldapuserjoboufive'), $search_filter, $attributes);
81
            if (FALSE !== $result_nicks) {
82
                $entries = ldap_get_entries($ldap_connection, $result_nicks);
@@ 81-91 (lines=11) @@
78
                }
79
            }
80
            $result_nicks = ldap_search($ldap_connection, $this->config->item('ldapuserjoboufive'), $search_filter, $attributes);
81
            if (FALSE !== $result_nicks) {
82
                $entries = ldap_get_entries($ldap_connection, $result_nicks);
83
                for ($x = 0; $x < $entries['count']; $x++) {
84
                    if (!empty($entries[$x]['givenname'][0]) &&
85
                            !empty($entries[$x]['samaccountname'][0]) &&
86
                            !empty($entries[$x]['sn'][0]) &&
87
                            !empty($entries[$x]['mail'][0])) {
88
                        $ad_users[] = array('first_name' => trim($entries[$x]['givenname'][0]), 'last_name' => trim($entries[$x]['sn'][0]), 'full_name' => trim($entries[$x]['givenname'][0]).' '. trim($entries[$x]['sn'][0]), 'username' => trim($entries[$x]['samaccountname'][0]), 'email' => trim($entries[$x]['mail'][0]));
89
                    }
90
                }
91
            }
92
93
            ldap_unbind($ldap_connection);
94
        }