source: trunk/expressoAdmin1_2/inc/class.bosectors.inc.php @ 6686

Revision 6686, 6.7 KB checked in by cristiano, 12 years ago (diff)

Ticket #2920 - Erro ao criar setor no Expresso Admin - faltando objectclass

  • Property svn:eol-style set to native
  • Property svn:executable set to *
RevLine 
[2]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 bosectors
13        {
14                var $public_functions = array(
15                        'create_sector' => True,
16                        'save_sector'   => True,
17                        'delete_sector' => True
18                );
19       
20                var $so;
21                var $functions;
[471]22                var $db_functions;
23       
[2]24                function bosectors()
25                {
26                        $this->so = createobject('expressoAdmin1_2.sosectors');
27                        $this->functions = $this->so->functions;
[471]28                        $this->db_functions = $this->so->db_functions;
[1391]29                        $this->group = createobject('expressoAdmin1_2.group');
30                        $this->user = createobject('expressoAdmin1_2.user');
[2]31                }
32
33                function create_sector()
34                {
35                        // Verifica o acesso do gerente
36                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'create_sectors'))
37                        {
38                                $return['status'] = false;
[493]39                                $return['msg'] = lang('you do not have access to create sectors') . '.';
[2]40                                return $return;
41                        }
42
43                        // Cria array para incluir no LDAP
44                        $dn = 'ou=' . $_POST['sector'] . ',' . $_POST['context'];                       
45                        $sector_info = array();
46                        $sector_info['ou']                              = $_POST['sector']; 
[6686]47                        $sector_info['objectClass'][]   = 'top';
48                        $sector_info['objectClass'][]   = 'organizationalUnit';
49                        $sector_info['objectClass'][]   = 'phpgwQuotaControlled';
[6553]50                        /*Insere as informações sobre quota total por usuários e por gigabytes de espaço em disco 
[6686]51              Se não vierem os dados, ele coloca 0 (Caso não exista controle de cota).
52             */
53                $sector_info['diskQuota'] = isset($_POST['disk_quota']) ? (int)$_POST['disk_quota'] : 0;
54                $sector_info['usersQuota'] = isset($_POST['users_quota']) ? (int)$_POST['users_quota'] : 0;
[6553]55
[3850]56                        $systemName = $GLOBALS['phpgw_info']['server']['system_name'];
57                        if ($systemName != '')
58                                $sector_info['phpgwSystem'] = strtolower($systemName);
59                       
60                        if ($_POST['sector_visible'])
61                        {
62                                $sector_info['objectClass'][2]  = 'phpgwAccount';
63                                $sector_info['phpgwaccountvisible'] = '-1';
64                        }
65                       
[2]66                        // Chama funcao para escrever no OpenLDAP, case de erro, volta com msg de erro.
67                        if (!$this->so->write_ldap($dn, $sector_info))
68                        {
[89]69                                $_POST['error_messages'] = lang('Error in OpenLDAP recording.');
[2]70                                ExecMethod('expressoAdmin1_2.uisectors.add_sector');
71                                return false;
72                        }
73                       
[5133]74                        //Escreve no log
[414]75                        $this->db_functions->write_log("created sector", "$dn");
[2]76                       
77                        // Volta para o ListSectors
78                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
79                        $GLOBALS['phpgw']->redirect($url);
80                }
[32]81
[1996]82        function save_sector()
[2]83                {
[5133]84                $context = utf8_encode($_POST['context']);
85
86                        $sector_info = $this->so->get_info($context);
[32]87                       
[5133]88                        if (($_POST['sector_visible'] == 'on') && ($sector_info['phpgwaccountvisible'] != '-1'))
[32]89                        {
90                                foreach ($sector_info[0]['objectclass'] as $objectClass)
91                                {
92                                        if ($objectClass == 'phpgwAccount')
93                                                $phpgwAccount = true;
[5133]94                                        else
95                                                $phpgwAccount = false;
[32]96                                }
97                               
98                                if (!$phpgwAccount)
99                                {
100                                        $ldap_mod_add['objectClass'][] = 'phpgwAccount';
101                                }
102                               
103                                $ldap_mod_add['phpgwaccountvisible'] = '-1';
104                                $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
105                        }
[6553]106                        elseif($sector_info['phpgwaccountvisible'] == '-1')
[32]107                        {
[1120]108                                $ldap_mod_del['objectClass'] = 'phpgwAccount';
[32]109                                $ldap_mod_del['phpgwaccountvisible'] = array();
110                                $this->so->remove_attribute($sector_info[0]['dn'], $ldap_mod_del);
[6553]111                        }
[6556]112
113                        if(!in_array('phpgwQuotaControlled',$sector_info[0]['objectclass'] ))
114                        {
115                                $ldap_mod_add = array();
116                                $ldap_mod_add['objectClass'][] = 'phpgwQuotaControlled';
117                                $ldap_mod_add['diskQuota'] = isset($_POST['disk_quota']) ? (int)$_POST['disk_quota'] : 0;
118                                $ldap_mod_add['usersQuota'] = isset($_POST['users_quota']) ? (int)$_POST['users_quota'] : 0;
119
120                                $this->so->add_attribute($sector_info[0]['dn'], $ldap_mod_add);
[32]121                        }
[6556]122                        else
123                        {
124                                $ldap_mod_replace = array();
125                                if(isset($_POST['disk_quota']))
126                                        $ldap_mod_replace['diskQuota'] = (int)$_POST['disk_quota'];
127
128                                if(isset($_POST['users_quota']))
129                                        $ldap_mod_replace['usersQuota'] = (int)$_POST['users_quota'];
130
131                                if(count($ldap_mod_replace) > 0)
132                                        $this->so->replace_attribute($sector_info[0]['dn'], $ldap_mod_replace);
133                        }
[2]134                        // Volta para o ListSectors
[32]135                        ExecMethod('expressoAdmin1_2.uisectors.list_sectors');
[2]136                }
[32]137
[2]138                function delete_sector()
139                {
[1391]140
[2]141                        // Verifica o acesso do gerente
142                        if (!$this->functions->check_acl($_SESSION['phpgw_session']['session_lid'], 'delete_sectors'))
143                        {
144                                $return['status'] = false;
[493]145                                $return['msg'] = lang('you do not have access to delete sectors') . '.';
[2]146                                return $return;
147                        }
148
149                        $sector_dn = $_POST['dn'];
150                        $manager_context = $_POST['manager_context'];
151
[5133]152                        $sector_dn = utf8_encode($sector_dn);
[1391]153
154                        $sector_users = $this->so->get_sector_users($sector_dn);
[5133]155
[2]156                        for ($i=0; $i<count($sector_users)-1; $i++)
157                        {
158                                //_debug_array($user);
159                                // Pega o UID e os grupos que o usuario fz parte.
160                                $uid = $sector_users[$i]['uid'][0];
161                                $account_id = $sector_users[$i]['uidnumber'][0];
162                                $dn = $sector_users[$i]['dn'];
[1391]163                                $this->user->delete(Array('uid' =>  $uid , 'uidnumber' => $account_id));
[2]164                        }
165
166
167                        $sector_groups = $this->so->get_sector_groups($sector_dn);
168                        for ($i=0; $i<count($sector_groups)-1; $i++)
169                        {
170                                $dn = $sector_groups[$i]['dn'];
171                                $gidnumber = $sector_groups[$i]['gidnumber'][0];
172
[1391]173                                //Delete group
174                                $this->group->delete(Array('gidnumber' => $gidnumber, 'cn' => $dn));
[2]175                        }
176                       
[396]177                        if ( (!empty($GLOBALS['phpgw_info']['server']['ldap_master_host'])) &&
178                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_dn'])) &&
179                                 (!empty($GLOBALS['phpgw_info']['server']['ldap_master_root_pw'])) )
180                        {
181                                $connection = $GLOBALS['phpgw']->common->ldapConnect($GLOBALS['phpgw_info']['server']['ldap_master_host'],
182                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_dn'],
183                                                                                                   $GLOBALS['phpgw_info']['server']['ldap_master_root_pw']);
184                        }
185                        else
186                        {
187                                $connection = $GLOBALS['phpgw']->common->ldapConnect();
188                        }
189                       
[2]190                        $this->so->delete_sector_ldap_recursively($connection, $sector_dn);
191                        ldap_close($connection);
192                       
193                        // Volta para o ListGroups
194                        $url = ($GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uisectors.list_sectors'));
195                        $GLOBALS['phpgw']->redirect($url);
196                }
197        }
[1120]198?>
Note: See TracBrowser for help on using the repository browser.