source: trunk/expressoAdmin1_2/inc/class.socomputers.inc.php @ 7673

Revision 7673, 4.8 KB checked in by douglasz, 11 years ago (diff)

Ticket #3236 - Correcoes para Performance: Function Within Loop Declaration.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /************************************************************************************\
3        * Expresso Administração                                                                                                     *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br)        *
5        * -----------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                       *
7        *  under the terms of the GNU General Public License as published by the                         *
8        *  Free Software Foundation; either version 2 of the License, or (at your                        *
9        *  option) any later version.                                                                                                            *
10        \************************************************************************************/
11
12        class socomputers
13        {
14                var $functions;
15                var $ldap_connection;
16                var $db_functions;
17               
18                function socomputers()
19                {
20                        $this->functions = CreateObject('expressoAdmin1_2.functions');
21                        $this->db_functions = CreateObject('expressoAdmin1_2.db_functions');
22                       
23                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
24                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
25                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
26                        {
27                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
28                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
29                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
30                        }
31                        else
32                        {
33                                $this->ldap_connection = $GLOBALS['phpgw']->common->ldapConnect();
34                        }
35                }
36
37                function write_ldap($dn, $info)
38                {
39                        if (ldap_add($this->ldap_connection, $dn, $info))
40                        {
41                                ldap_close($this->ldap_connection);
42                                return true;
43                        }
44                        else
45                        {
46                                ldap_close($this->ldap_connection);
47                                return false;
48                        }
49                }
50               
51                function exist_computer_uid($computer_cn)
52                {
53                        $search = ldap_search($this->ldap_connection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $computer_cn . '$');
54                        $result = ldap_get_entries($this->ldap_connection, $search);
55                        ldap_close($this->ldap_connection);
56                        if ($result['count'] == 0)
57                                return false;
58                        else
59                                return true;
60                }
61               
62                function get_computer_data($uidnumber)
63                {
64                        $manager_acl = $this->functions->read_acl($_SESSION['phpgw_info']['expresso']['user']['account_lid']);
65                        $manager_contexts = $manager_acl['contexts'];
66                       
67                        foreach ($manager_contexts as $index=>$context)
68                        {
69                                $search = ldap_search($this->ldap_connection, $context, "uidNumber=$uidnumber");
70                                $result = ldap_get_entries($this->ldap_connection, $search);
71                       
72                                if ($result['count'])
73                                {
74                                        // Recupera o DN
75                                        $computer_data['dn'] = $result[0]['dn'];
76                       
77                                        //Recupera o Nome do Computador (CN)
78                                        $computer_data['computer_cn'] = $result[0]['cn'][0];
79
80                                        //Recupera a flag SAMBA
81                                        $computer_data['sambaAcctFlags'] = $result[0]['sambaacctflags'][0];
82                       
83                                        // Recupera a descrição
84                                        $computer_data['computer_description'] = utf8_decode($result[0]['description'][0]);
85                       
86                                        // Recupera o contexto do email_list
87                                        $tmp = explode(",", $computer_data['dn']);
88                    $tmp_count = count($tmp);
89                                        for ($i = 1; $i < $tmp_count; ++$i)
90                                                $computer_data['context'] .= $tmp[$i] . ',';
91                                        $computer_data['context'] = substr($computer_data['context'],0,(strlen($computer_data['context']) - 1));
92                       
93                                        $a_tmp = explode("-", $result[0]['sambasid'][0]);
94                                        array_pop($a_tmp);
95                                        $computer_data['sambasid'] = implode("-", $a_tmp);
96                       
97                                        return $computer_data;
98                                }
99                        }
100                }
101               
102                function delete_computer_ldap($dn)
103                {
104                        $result = @ldap_delete($this->ldap_connection, $dn);
105                        @ldap_close($this->ldap_connection);
106                        $this->db_functions->write_log('deleted computer',$dn);
107                        return $result;                         
108                }
109               
110                function rename_ldap($old_dn, $new_rdn, $new_context)
111                {
112                        $result = ldap_rename($this->ldap_connection, $old_dn, $new_rdn, $new_context, true);
113                        ldap_close($this->ldap_connection);
114                        $this->db_functions->write_log('rename computer',$old_dn . '->' . $new_rdn);
115                        return $result;
116                }
117               
118                function ldap_add_attribute($ldap_add_attribute, $dn)
119                {
120                        $result = ldap_mod_add($this->ldap_connection, $dn, $ldap_add_attribute);
121                        ldap_close($this->ldap_connection);
122                        $this->db_functions->write_log('added ldap attributes from computer',$dn);                                             
123                        return $result;
124                }
125               
126                function ldap_remove_attribute($ldap_remove_attribute, $dn)
127                {
128                        $result = ldap_mod_del($this->ldap_connection, $dn, $ldap_remove_attribute);
129                        ldap_close($this->ldap_connection);
130                        $this->db_functions->write_log('removed ldap attributes from computer',$dn);                                           
131                        return $result;
132                }
133
134                function ldap_replace_attribute($ldap_replace_attribute, $dn)
135                {
136                        $result = ldap_mod_replace($this->ldap_connection, $dn, $ldap_replace_attribute);
137                        ldap_close($this->ldap_connection);
138                        $this->db_functions->write_log('replace ldap attributes from computer',$dn);
139                        return $result;
140                }
141        }
142?>
Note: See TracBrowser for help on using the repository browser.