source: trunk/expressoAdmin1_2/inc/class.uidomains.inc.php @ 27

Revision 27, 7.7 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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