source: companies/serpro/expressoAdmin1_2/inc/class.uidomains.inc.php @ 903

Revision 903, 7.7 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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