source: branches/2.2/expressoAdmin1_2/inc/class.uidomains.inc.php @ 414

Revision 414, 7.5 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

  • 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 uidomains
13        {
14                var $public_functions = array
15                (
16                        'list_domains'  => True,
17                        'add'                   => True,
18                        'delete'                => True,
19                        'validate_data' => True
20                );
21
22                var $db;
23                var $ldap_functions;
24                var $functions;
25                var $nextmatchs;
26                       
27                function uidomains()
28                {
29                        $this->db = CreateObject('expressoAdmin1_2.db_functions');
30                        $this->ldap_functions = CreateObject('expressoAdmin1_2.ldap_functions');
31                        $this->functions = CreateObject('expressoAdmin1_2.functions');
32                        $this->nextmatchs = CreateObject('phpgwapi.nextmatchs');
33                }
34               
35                function list_domains()
36                {
37                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
38                        $tmp = $this->functions->read_acl($account_lid);
39                        $manager_context = $tmp[0]['context'];
40                        $context_display = $tmp[0]['context_display'];
41                       
42                        // Verifica se o administrador tem acesso.
43                        if (!$this->functions->check_acl($account_lid,'edit_sambadomains'))
44                        {
45                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
46                        }
47                       
48                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
49                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
50
51                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Samba Domains');
52                        $GLOBALS['phpgw']->common->phpgw_header();
53
54                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
55                        $p->set_file(array('domains' => 'domains.tpl'));
56                        $p->set_block('domains','list','list');
57                        $p->set_block('domains','row','row');
58                        $p->set_block('domains','row_empty','row_empty');
59                       
60                        $sambadomains_info = $this->db->get_sambadomains_list();
61                        //_debug_array($sambadomains_info);
62                       
63                        $var = Array(
64                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
65                                'back_url'                              => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php')
66                        );
67                        $p->set_var($var);
68                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
69
70                        if (!count($sambadomains_info))
71                        {
72                                $p->set_var('message',lang('No matches found'));
73                        }
74                        else
75                        {
76                                foreach($sambadomains_info as $domains)
77                                {
78                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
79                                       
80                                        $var = Array(
81                                                'tr_color'              => $tr_color,
82                                                'sambadomainname'       => $domains['samba_domain_name'],
83                                                'sambaSID'                      => $domains['samba_domain_sid'],
84                                                'delete_link'           => $this->row_action('delete',$domains['samba_domain_name'])
85                                        );
86                                        $p->set_var($var);
87                                        $p->fp('rows','row',True);
88                                }
89                        }
90                       
91                        $var = Array(
92                                'action'        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uidomains.add'),
93                                'input_add' => '<input type="submit" value="' . lang('Add Samba Domains') . '">'
94                        );
95                        $p->set_var($var);
96                        $p->parse('rows','row_empty',True);
97                        $p->pfp('out','list');
98                }
99
100               
101                function add()
102                {
103                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
104                        $acl = $this->functions->read_acl($account_lid);
105                        $manager_context = $acl[0]['context'];
106                       
107                        $context = $_GET['context'];
108                       
109                        // Verifica se tem acesso a este modulo
110                        if (!$this->functions->check_acl($account_lid,'edit_sambadomains'))
111                        {
112                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
113                        }
114
115                        // Pega combo das organizações e seleciona, caso seja um post, o setor que o usuario selecionou.
116                        $organizations = $this->functions->get_sectors($_POST['context'], false, false);
117                       
118                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
119                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
120                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Add Samba Domain');
121                        $GLOBALS['phpgw']->common->phpgw_header();
122                       
123                        // Set o template
124                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
125                        $p->set_file(Array('create_sambadomains' => 'domains_form.tpl'));
126                        $p->set_block('create_sambadomains','list','list');
127                                               
128                        // Seta variaveis utilizadas pelo tpl.
129                        $var = Array(
130                                'action'                => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uidomains.validate_data'),
131                                'back_url'              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uidomains.list_domains'),
132                                'row_on'                => "#DDDDDD",
133                                'row_off'               => "#EEEEEE",
134                                'color_bg1'             => "#E8F0F0",
135                                'organizations'         => $organizations,
136                                'sambadomainname'       => $_POST['sambadomainname'],
137                                'sambasid'                      => $_POST['sambasid'],
138                               
139                                'error_messages' => $_POST['error_messages'] == '' ? '' : "<script type='text/javascript'>alert('".$_POST['error_messages']."')</script>",
140                        );
141                        $p->set_var($var);
142                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
143                       
144                        $p->pfp('out','create_sambadomains');
145                }
146               
147                function validate_data()
148                {
149                        if ($_POST['sambadomainname'] == '')
150                        {
151                                $_POST['error_messages'] = lang('Samba domains name is empty') . '.';
152                                ExecMethod('expressoAdmin1_2.uidomains.add');
153                                return;
154                        }
155
156                        if ($_POST['sambasid'] == '')
157                        {
158                                $_POST['error_messages'] = lang('Samba SID is empty') . '.';
159                                ExecMethod('expressoAdmin1_2.uidomains.add');
160                                return;
161                        }
162
163                        // Verifica se o name do dominio está sendo usado.
164                        if ($this->db->exist_domain_name_sid($_POST['sambadomainname'], $_POST['sambasid']))
165                        {
166                                $_POST['error_messages'] = lang('Samba domain name or SID already exist') . '.';
167                                ExecMethod('expressoAdmin1_2.uidomains.add');
168                                return;
169                        }
170
171                        if (!$this->ldap_functions->exist_domain_name_sid($_POST['sambadomainname'], $_POST['sambasid']))
172                        {
173                                $return = $this->ldap_functions->add_sambadomain(strtoupper($_POST['sambadomainname']), $_POST['sambasid'], $_POST['context']);
174                                if (!$return['status'])
175                                {
176                                        $_POST['error_messages'] = $return['msg'];
177                                        ExecMethod('expressoAdmin1_2.uidomains.add');
178                                        return;
179                                }
180                        }
181                       
182                        $this->db->add_sambadomain(strtoupper($_POST['sambadomainname']), $_POST['sambasid']);
183                       
184                        ExecMethod('expressoAdmin1_2.uidomains.list_domains');
185                        return;
186                }
187               
188                function delete()
189                {
190                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
191                        $acl = $this->functions->read_acl($account_lid);
192                        $manager_context = $acl[0]['context'];
193                       
194                        // Verifica se tem acesso a este modulo
195                        if (!$this->functions->check_acl($account_lid,'edit_sambadomains'))
196                        {
197                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
198                        }
199                       
200                        $return = $this->ldap_functions->delete_sambadomain($_GET['sambadomainname']);
201                        if (!$return['status'])
202                        {
203                                echo $return['msg'];
204                                //ExecMethod('expressoAdmin1_2.uidomains.add');
205                                return;
206                        }
207                        $this->db->delete_sambadomain($_GET['sambadomainname']);
208                       
209                        ExecMethod('expressoAdmin1_2.uidomains.list_domains');
210                        return;
211                }
212               
213                function row_action($action,$sambadomainname)
214                {
215                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
216                                'menuaction'            => 'expressoAdmin1_2.uidomains.'.$action,
217                                'sambadomainname'       => $sambadomainname
218                        )).'"> '.lang($action).' </a>';
219                }
220        }
221?>
Note: See TracBrowser for help on using the repository browser.