source: trunk/expressoAdmin1_2/inc/class.uiaccounts.inc.php @ 396

Revision 396, 37.4 KB checked in by niltonneto, 16 years ago (diff)

Modificações referente a opção de configurar um ldap_master
no setup do Expresso, usado somente para escrita.

  • 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 uiaccounts
13        {
14                var $public_functions = array
15                (
16                        'list_users'                            => True,
17                        'add_users'                                     => True,
18                        'edit_user'                                     => True,
19                        'view_user'                                     => True,
20                        'show_photo'                            => True,
21                        'show_access_log'                       => True,
22                        'css'                                           => True
23                );
24
25                var $nextmatchs;
26                var $user;
27                var $functions;
28                var $current_config;
29                var $ldap_functions;
30                var $db_functions;
31
32                function uiaccounts()
33                {
34                        $this->user                     = CreateObject('expressoAdmin1_2.user');
35                        $this->nextmatchs       = CreateObject('phpgwapi.nextmatchs');
36                        $this->functions        = CreateObject('expressoAdmin1_2.functions');
37                        $this->ldap_functions = CreateObject('expressoAdmin1_2.ldap_functions');
38                        $this->db_functions = CreateObject('expressoAdmin1_2.db_functions');
39                       
40                        $c = CreateObject('phpgwapi.config','expressoAdmin1_2');
41                        $c->read_repository();
42                        $this->current_config = $c->config_data;
43                       
44                        if(!@is_object($GLOBALS['phpgw']->js))
45                        {
46                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
47                        }
48                        $GLOBALS['phpgw']->js->validate_file('jscode','connector','expressoAdmin1_2');#diretorio, arquivo.js, aplicacao
49                        $GLOBALS['phpgw']->js->validate_file('jscode','expressoadmin','expressoAdmin1_2');
50                        $GLOBALS['phpgw']->js->validate_file('jscode','tabs','expressoAdmin1_2');
51                        $GLOBALS['phpgw']->js->validate_file('jscode','users','expressoAdmin1_2');
52                }
53
54                function list_users()
55                {
56                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
57                        $acl = $this->functions->read_acl($account_lid);
58                        $raw_context = $acl['raw_context'];
59                        $contexts = $acl['contexts'];
60                        foreach ($acl['contexts_display'] as $index=>$tmp_context)
61                        {
62                                $context_display .= '<br>'.$tmp_context;
63                        }
64                        // Verifica se o administrador tem acesso.
65                        if (!$this->functions->check_acl($account_lid,'list_users'))
66                        {
67                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
68                        }
69
70                        if(isset($_POST['query']))
71                        {
72                                // limit query to limit characters
73                                if(eregi('^[a-z_0-9_-].+$',$_POST['query']))
74                                {
75                                        $GLOBALS['query'] = $_POST['query'];
76                                }
77                        }
78                       
79                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
80                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
81                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('User accounts');
82                        $GLOBALS['phpgw']->common->phpgw_header();
83
84                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
85                        $p->set_file(Array('accounts' => 'accounts.tpl'));
86                        $p->set_block('accounts','body');
87                        $p->set_block('accounts','row');
88                        $p->set_block('accounts','row_empty');
89
90                        $var = Array(
91                                'bg_color'                                      => $GLOBALS['phpgw_info']['theme']['bg_color'],
92                                'th_bg'                                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
93                               
94                                'accounts_url'                          => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uiaccounts.list_users'),
95                                'back_url'                                      => $GLOBALS['phpgw']->link('/expressoAdmin1_2/index.php'),
96                                'add_action'                            => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uiaccounts.add_users'),
97                               
98                                'create_user_disabled'          => $this->functions->check_acl($account_lid,'add_users') ? '' : 'disabled',
99                                'context'                                       => $raw_context,
100                                'context_display'                       => $context_display,
101                                'imapDelimiter'                         => $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter'],
102                               
103                                'lang_create_user'                      => lang('Create User'),
104                                'lang_loginid'                          => lang('LoginID'),
105                                'lang_cn'                                       => lang('Name'),
106                                'lang_mail'                                     => lang('E-mail'),
107                                'lang_edit'                                     => lang('edit'),
108                                'lang_rename'                           => lang('rename'),
109                                'lang_delete'                           => lang('delete'),
110                                'lang_search'                           => lang('Search'),
111                                'lang_back'                                     => lang('back'),
112                                'lang_contexts'                         => lang('Contexts')
113                               
114                        );
115                        $p->set_var($var);
116                       
117                        // Save query
118                        $p->set_var('query', $GLOBALS['query']);
119                       
120                        //Admin make a search
121                        if ($GLOBALS['query'] != '')
122                        {
123                                $account_info = $this->functions->get_list('accounts', $GLOBALS['query'], $contexts);
124                        }
125                       
126                        if (!count($account_info) && $GLOBALS['query'] != '')
127                        {
128                                $p->set_var('message',lang('No matches found'));
129                                $p->parse('rows','row_empty',True);
130                        }
131                        else if (count($account_info))
132                        {  // Can edit, delete or rename users ??
133                                if (($this->functions->check_acl($account_lid,'edit_users')) ||
134                                        ($this->functions->check_acl($account_lid,'change_users_password')) ||
135                                        ($this->functions->check_acl($account_lid,'edit_sambausers_attributes')) || 
136                                        ($this->functions->check_acl($account_lid,'change_users_quote')) ||
137                                        ($this->functions->check_acl($account_lid,'manipulate_corporative_information')) ||
138                                        ($this->functions->check_acl($account_lid,'edit_users_phonenumber'))
139                                        )
140                                        $can_edit = True;
141                                elseif ($this->functions->check_acl($account_lid,'view_users'))
142                                        $can_view = True;
143                                if ($this->functions->check_acl($account_lid,'delete_users'))
144                                        $can_delete = True;
145                                if ($this->functions->check_acl($account_lid,'rename_users'))
146                                        $can_rename = True;
147
148                                while (list($null,$account) = each($account_info))
149                                {
150                                        $this->nextmatchs->template_alternate_row_color($p);
151
152                                        $var = array(
153                                                'row_loginid'   => $account['account_lid'],
154                                                'row_cn'                => $account['account_cn'],
155                                                'row_mail'              => (!$account['account_mail']?'<font color=red>Sem E-mail</font>':$account['account_mail'])
156                                        );
157                                        $p->set_var($var);
158
159                                        if ($can_edit)
160                                                $p->set_var('row_edit',$this->row_action('edit','user',$account['account_id']));
161                                        elseif ($can_view)
162                                                $p->set_var('row_edit',$this->row_action('view','user',$account['account_id']));
163                                        else
164                                                $p->set_var('row_edit','&nbsp;');
165
166                                        if ($can_rename)
167                                                $p->set_var('row_rename',"<a href='#' onClick='javascript:rename_user(\"".$account['account_lid']."\",\"".$account['account_id']."\");'>Renomear</a>");
168                                        else
169                                                $p->set_var('row_rename','&nbsp;');
170
171                                        if ($can_delete)
172                                        {
173                                                $p->set_var('row_delete',"<a href='#' onClick='javascript:delete_user(\"".$account['account_lid']."\",\"".$account['account_id']."\");'>Excluir</a>");
174                                        }
175                                        else
176                                                $p->set_var('row_delete','&nbsp;');
177
178                                        $p->parse('rows','row',True);
179                                }
180                        }
181                        $p->pfp('out','body');
182                }
183
184                function add_users()
185                {
186                        $GLOBALS['phpgw']->js->validate_file('jscode','users','expressoAdmin1_2');
187                       
188                        $GLOBALS['phpgw']->js->set_onload('get_available_groups(document.forms[0].context.value);');
189                        $GLOBALS['phpgw']->js->set_onload('get_available_maillists(document.forms[0].context.value);');
190                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
191                                $GLOBALS['phpgw']->js->set_onload('get_available_sambadomains(document.forms[0].context.value, \'create_user\');');
192                       
193                        $manager_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
194                        $acl = $this->functions->read_acl($manager_lid);
195                       
196                        $manager_contexts = $acl['contexts'];
197                       
198                        // Verifica se tem acesso a este modulo
199                        if (!$this->functions->check_acl($manager_lid,'add_users'))
200                        {
201                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
202                        }
203                               
204                        // Imprime nav_bar
205                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
206                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
207                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Create User');
208                        $GLOBALS['phpgw']->common->phpgw_header();
209                       
210                        // Seta template
211                        $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
212                        $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
213                        $t->set_file(array("body" => "accounts_form.tpl"));
214                        $t->set_block('body','main');
215
216                        // Pega combo das organizações e seleciona, caso seja um post, o setor que o usuario selecionou.
217                        foreach ($manager_contexts as $index=>$context)
218                                $combo_manager_org .= $this->functions->get_organizations($context);
219                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], '', true, true, true);
220
221                        // Chama funcao para criar lista de aplicativos disponiveis.
222                        $applications_list = $this->functions->make_list_app($manager_lid);
223
224                        // Cria combo de dominio samba
225                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
226                        {
227                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
228                                $sambadomainname_options = '';
229                                if (count($a_sambadomains))
230                                {
231                                        foreach ($a_sambadomains as $a_sambadomain)
232                                        {
233                                                // So mostra os sambaDomainName do contexto do manager
234                                                if ($this->ldap_functions->exist_sambadomains($manager_contexts, $a_sambadomain['samba_domain_name']))
235                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
236                                        }
237                                }
238                        }
239                       
240                        // Valores default.
241                        $var = Array(
242                                'row_on'                                => "#DDDDDD",
243                                'row_off'                               => "#EEEEEE",
244                                'color_bg1'                             => "#E8F0F0",
245                                //'manager_context'             => $manager_context,
246                                'type'                                  => 'create_user',
247                                'back_url'                              => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uiaccounts.list_users'),
248                                'display_samba_suport'  => $this->current_config['expressoAdmin_samba_support'] == 'true' ? '' : 'none',
249                                'disabled_access_button'=> 'disabled',
250                               
251                                // First ABA
252                                'display_spam_uid'                              => 'display:none',
253                                'lang_general_information'              => lang('General Information'),
254                                'lang_corporative_information'  => lang('Corporative Information'),
255                                'lang_email_config'                             => lang('Email Config'),
256                                'lang_groups_permission'                => lang('Groups Permission'),
257                                'lang_lists_permission'                 => lang('Email Lists'),
258                                'lang_aplication_permission'    => lang('Aplication Permission'),       
259                                'lang_search_organization'              => lang('Search Organiztion'),
260                                'lang_organizations'                    => lang('Organizations'),
261                                'lang_sector'                                   => lang('Sector'),
262                                'lang_account_lid'                              => lang('Login ID'),
263                                'lang_firstname'                                => lang('First Name'),
264                                'lang_lastname'                                 => lang('Last Name'),
265                                'lang_password'                                 => lang('Password'),
266                                'lang_re-password'                              => lang('Re-Password'),
267                                'lang_passwd_expired'                   => lang('Password expired'),
268                                'lang_changepassword'                   => lang('Change password'),                             
269                                'lang_phone'                                    => lang('Phone'),
270                                'lang_photo'                                    => lang('Photo'),
271                                'lang_account_active'                   => lang('Account Active'),
272                                'lang_account_invisible'                => lang('Account Invisible'),
273                                'lang_never'                                    => lang('never'),
274                                'lang_back'                                             => lang('Back'),
275                                'lang_save'                                             => lang('Save'),
276                                'sectors'                                               => $combo_manager_org,
277                                'combo_organizations'                   => $combo_manager_org,
278                                'combo_all_orgs'                                => $combo_all_orgs,
279                                'passwd_expired_checked'                => 'CHECKED',
280                                'changepassword_checked'                => 'CHECKED',
281                                'phpgwaccountstatus_checked'    => 'CHECKED',
282                                'photo_bin'                                             => $GLOBALS['phpgw_info']['server']['webserver_url'].'/expressoAdmin1_2/templates/default/images/photo_celepar.png',
283                                'display_picture'                               => $this->functions->check_acl($manager_lid,'edit_users_picture') ? '' : 'none',
284                                'display_tr_default_password'   => 'none',
285                                'minimumSizeLogin'                              => $this->current_config['expressoAdmin_minimumSizeLogin'],
286                                'defaultDomain'                                 => $this->current_config['expressoAdmin_defaultDomain'],
287                                'concatenateDomain'                             => $this->current_config['expressoAdmin_concatenateDomain'],
288                                'ldap_context'                                  => ldap_dn2ufn($GLOBALS['phpgw_info']['server']['ldap_context']),
289                               
290                                // Corporative Information
291                                'display_corporative_information' => $this->functions->check_acl($manager_lid,'manipulate_corporative_information') ? '' : 'none',
292                                'lang_employeenumber'                   => lang('Employee number'),
293                                'lang_cpf'                                              => lang('cpf'),
294                                'lang_rg'                                               => lang('rg'),
295                                'lang_rguf'                                             => lang('rguf'),
296                               
297                                //MAIL
298                                'lang_activeemailaccount'               => lang('Active email account'),
299                                'lang_email'                                    => lang('E-mail'),
300                                'lang_aliasemail'                               => lang('Alias email'),
301                                'lang_forwardingemail'                  => lang('Forwarding email'),
302                                'lang_email_quota'                              => lang('Email quota in MB'),
303                                'lang_onlyforwarding'                   => lang('Only forwarding'),
304                                'lang_quote_message'                    => lang('leave empty for no quota'),
305                                'lang_email_quota_used'                 => lang('Quota used in MB'),
306                                'accountstatus_checked'                 => 'CHECKED',
307                                'mailquota'                                             => $this->current_config['expressoAdmin_defaultUserQuota'],
308                                'changequote_disabled'                  => $this->functions->check_acl($manager_lid,'change_users_quote') ? '' : 'readonly',
309                                'imapDelimiter'                                 => $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter'],
310                                'input_mailalternateaddress_fields' => '<input type="text" name="mailalternateaddress[]" id="mailalternateaddress" autocomplete="off" value="{mailalternateaddress}" {disabled} size=30>',
311                                'input_mailforwardingaddress_fields'=> '<input type="text" name="mailforwardingaddress[]" id="mailforwardingaddress" autocomplete="off" value="{mailforwardingaddress}" {disabled} size=30>',
312
313                                //Third ABA
314                                'lang_groups'                                   => lang('Groups'),
315                                'lang_user_groups'                              => 'Grupos do Usuário',
316                                'lang_available_groups'                 => 'Grupos disponíveis',
317                                'lang_listGroups'                               => lang('ListGroups'),
318                                'lang_primary_group'                    => lang('Primary Group'),
319                                'lang_add'                                              => lang('Add'),
320                                'lang_rem'                                              => lang('Remove'),
321                               
322                                //Fourd ABA
323                                'lang_user_mail_lists'                  => 'O usuário participa destas Listas de E-mail',
324                                'lang_available_mail_lists'             => 'Listas de E-mail disponíveis',
325                               
326                                //Five ABA
327                                'apps'                                                          => $applications_list,
328                               
329                                //SAMBA ABA
330                                'lang_samba_config'                                     => lang('Samba Config'),
331                                'lang_use_attrs_samba'                          => lang('Use samba attributes'),
332                                'lang_sambadomain'                                      => lang('Domain'),
333                                'lang_sambaAcctFlags'                           => lang('AcctFlags'),
334                                'lang_sambaLogonScript'                         => lang('Logon Script'),
335                                'lang_sambaHomeDirectory'                       => lang('Home Directory'),
336                                'lang_active_user'                                      => lang('Samba User Active'),
337                                'lang_desactive_user'                           => lang('Samba User Desactive'),
338                                'use_attrs_samba_checked'                       => 'CHECKED',
339                                'sambadomainname_options'                       => $sambadomainname_options,
340                                'sambalogonscript'                                      => $this->current_config['expressoAdmin_defaultLogonScript'] != '' ? $this->current_config['expressoAdmin_defaultLogonScript'] : '',
341                                'use_suggestion_in_logon_script'        => $this->current_config['expressoAdmin_defaultLogonScript'] == '' ? 'true' : 'false',
342                        );
343                        $t->set_var($var);
344                        $t->pfp('out','main');
345                }
346               
347                function view_user()
348                {
349                        ExecMethod('expressoAdmin1_2.uiaccounts.edit_user');
350                        return;
351                }
352               
353                function edit_user()
354                {
355                        $manager_account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
356                        $acl = $this->functions->read_acl($manager_account_lid);
357                        $raw_context = $acl['raw_context'];
358                        $contexts = $acl['contexts'];           
359                        $alert_warning = '';
360                       
361                        // Verifica se tem acesso a este modulo
362                        $disabled = 'disabled';
363                        $disabled_password = 'disabled';
364                        $disabled_samba = 'disabled';
365                        $disabled_edit_photo = 'disabled';
366                        $disabled_phonenumber = 'disabled';
367                        $disabled_group = 'disabled';
368                       
369                        $display_picture = 'none';
370                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) &&
371                                (!$this->functions->check_acl($manager_account_lid,'change_users_password')) &&
372                                (!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) &&
373                                (!$this->functions->check_acl($manager_account_lid,'view_users')) &&
374                                (!$this->functions->check_acl($manager_account_lid,'manipulate_corporative_information')) &&
375                                (!$this->functions->check_acl($manager_account_lid,'edit_users_phonenumber'))
376                                )
377                        {
378                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
379                        }
380                        // SOMENTE ALTERAÇÃO DE SENHA
381                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && ($this->functions->check_acl($manager_account_lid,'change_users_password')))
382                        {
383                                $disabled = 'disabled';
384                                $disabled_password = '';
385                        }
386                        // SOMENTE ALTERAÇÃO DOS ATRIBUTOS SAMBA
387                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && ($this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')))
388                        {
389                                $disabled = 'disabled';
390                                $disabled_samba = '';
391                        }
392                        // SOMENTE ALTERAÇÃO DE TELEFONE
393                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && ($this->functions->check_acl($manager_account_lid,'edit_users_phonenumber')))
394                        {
395                                $disabled = 'disabled';
396                                $disabled_phonenumber = '';
397                        }
398                        // SOMENTE GRUPOS
399                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && ($this->functions->check_acl($manager_account_lid,'edit_groups')))
400                        {
401                                $disabled = 'disabled';
402                                $disabled_group = '';
403                        }
404                        // TOTAIS MENOS O SAMBA
405                        if (($this->functions->check_acl($manager_account_lid,'edit_users')) && (!$this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')))
406                        {
407                                $disabled = '';
408                                $disabled_password = '';
409                                $disabled_samba = 'disabled';
410                                $disabled_group = '';
411                        }
412                        // TOTAIS
413                        elseif ($this->functions->check_acl($manager_account_lid,'edit_users'))
414                        {
415                                $disabled = '';
416                                $disabled_password = '';
417                                $disabled_samba = '';
418                                $disabled_phonenumber = '';
419                                $disabled_group = '';
420                        }
421                       
422                        if (!$this->functions->check_acl($manager_account_lid,'change_users_quote'))
423                                $disabled_quote = 'readonly';
424                       
425                        if ($this->functions->check_acl($manager_account_lid,'edit_users_picture'))
426                        {
427                                $disabled_edit_photo = '';
428                                $display_picture = '';
429                        }
430                        // GET all infomations about the user.
431                        $user_info = $this->user->get_user_info($_GET['account_id']);
432
433                        // Formata o CPF
434                        if ($user_info['corporative_information_cpf'] != '')
435                        {
436                                if (strlen($user_info['corporative_information_cpf']) < 11)
437                                {
438                                        while (strlen($user_info['corporative_information_cpf']) < 11)
439                                        {
440                                                $user_info['corporative_information_cpf'] = '0' . $user_info['corporative_information_cpf'];
441                                        }
442                                }
443                                if (strlen($user_info['corporative_information_cpf']) == 11)
444                                {
445                                        $cpf_tmp = str_split($user_info['corporative_information_cpf'], 3);
446                                        $user_info['corporative_information_cpf'] = $cpf_tmp[0] . '.' . $cpf_tmp[1] . '.' . $cpf_tmp[2] . '-' . $cpf_tmp[3];
447                                }
448                        }
449                        // JavaScript
450                        $GLOBALS['phpgw']->js->validate_file("jscode","users","expressoAdmin1_2");
451                        $GLOBALS['phpgw']->js->set_onload("get_available_groups(document.forms[0].context.value);");
452                        $GLOBALS['phpgw']->js->set_onload("get_available_maillists(document.forms[0].context.value);");
453                        $GLOBALS['phpgw']->js->set_onload("use_samba_attrs('".$user_info['sambaUser']."');");
454                       
455                        // Seta header.
456                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
457                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
458
459                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Edit User');
460                        $GLOBALS['phpgw']->common->phpgw_header();
461
462                        // Seta templates.
463                        $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
464                        $t->set_file(array("body" => "accounts_form.tpl"));
465                        $t->set_block('body','main');
466                                                       
467                // ORGANIZATIONS
468                /*
469                        foreach ($contexts as $index=>$context)
470                                $orgs .= $this->functions->get_organizations($context, $user_info['context']);
471                        */
472                               
473                        foreach ($contexts as $index=>$context)
474                                $combo_manager_org .= $this->functions->get_organizations($context, $user_info['context']);
475                        $combo_all_orgs = $this->functions->get_organizations($GLOBALS['phpgw_info']['server']['ldap_context'], $user_info['context'], true, true, true);                       
476
477
478                        // GROUPS.
479                        if (count($user_info['groups_info']) > 0)
480                        {
481                                foreach ($user_info['groups_info'] as $group)
482                                {
483                                        $array_groups[$group['gidnumber']] = $group['cn'];
484                                }
485                                natcasesort($array_groups);
486                                foreach ($array_groups as $gidnumber=>$cn)
487                                {
488                                        // Grupo existe no Banco mas não no Ldap, excluimos grupo do Banco.
489                                        /*
490                                        if (!$this->ldap_functions->group_exist($gidnumber))
491                                        {
492                                                $this->db_functions->delete_group($gidnumber);
493                                                $this->db_functions->write_log("expressoAdmin deletou o grupo $gidnumber do banco, pois não existia no ldap.",'','','','');
494                                                continue;
495                                        }
496                                        */
497                                       
498                                        // O memberUid do usuário está somente no Banco, então adicionamos o memberUid no Ldap.
499                                        if (is_null($user_info['groups_ldap'][$gidnumber]))
500                                        {
501                                                $this->ldap_functions->add_user2group($gidnumber, $user_info['uid']);
502                                                $ea_select_user_groups_options .= "<option value=" . $gidnumber . ">" . $cn . " [Incluido memberUid no Ldap]</option>";
503
504                                                if ($alert_warning == '')
505                                                        $alert_warning = "O expressoAdmin corrigiu as seguintes inconsistências:\\n";
506                                                $alert_warning .= "Incluido atributo memberUid do usuário no grupo:\\n$cn - gidnumber: $gidnumber.";
507                                        }
508                                        else
509                                                $ea_select_user_groups_options .= "<option value=" . $gidnumber . ">" . $cn . "</option>";
510                                       
511                                        if ($gidnumber == $user_info['gidnumber'])
512                                        {
513                                                $ea_combo_primary_user_group_options .= "<option value=" . $gidnumber . " selected>" . $cn . "</option>";
514                                        }
515                                        else
516                                        {
517                                                $ea_combo_primary_user_group_options .= "<option value=" . $gidnumber . ">" . $cn . "</option>";
518                                        }
519                                }
520                               
521                                // O memberUid do usuário está somente no Ldap.
522                                $groups_db = array_flip($user_info['groups']);
523                                foreach ($user_info['groups_ldap'] as $gidnumber=>$cn)
524                                {
525                                        if (is_null($groups_db[$gidnumber]))
526                                        {
527                                                /*
528                                                $this->ldap_functions->remove_user2group($gidnumber, $user_info['uid']);
529                                                if ($alert_warning == '')
530                                                        $alert_warning = "O expressoAdmin corrigiu as seguintes inconsistências:\\n";
531                                                $alert_warning .= "Removido atributo memberUid do usuário do grupo $cn.\\n";
532                                                */
533                                                $ea_select_user_groups_options .= "<option value=" . $gidnumber . ">" . $cn . " [Somente no LDAP]</option>";
534                                        }
535                                }
536                        }
537                       
538                        // MAILLISTS
539                        if (count($user_info['maillists_info']) > 0)
540                        {
541                                foreach ($user_info['maillists_info'] as $maillist)
542                                {
543                                        $array_maillist[$maillist['uid']] = $maillist['uid'] . "  (" . $maillist['mail'] . ") ";
544                                }
545                                natcasesort($array_maillist);
546                                foreach ($array_maillist as $uid=>$option)
547                                {
548                                        $ea_select_user_maillists_options .= "<option value=" . $uid . ">" . $option . "</option>";
549                                }
550                        }
551                       
552                        // APPS.
553                        if ($disabled == 'disabled')
554                                $apps = $this->functions->make_list_app($manager_account_lid, $user_info['apps'], 'disabled');
555                        else
556                                $apps = $this->functions->make_list_app($manager_account_lid, $user_info['apps']);
557                       
558                        //PHOTO
559                        if ($user_info['photo_exist'])
560                        {
561                                $photo_bin = "./index.php?menuaction=expressoAdmin1_2.uiaccounts.show_photo&uidNumber=".$_GET['account_id'];
562                        }
563                        else
564                        {
565                                $photo_bin = $GLOBALS['phpgw_info']['server']['webserver_url'] . '/expressoAdmin1_2/templates/default/images/photo_celepar.png';
566                                $disabled_delete_photo = 'disabled';
567                        }
568
569                        // Cria combo de dominios do samba
570                        if ($this->current_config['expressoAdmin_samba_support'] == 'true')
571                        {
572                                $a_sambadomains = $this->db_functions->get_sambadomains_list();
573                                $sambadomainname_options = '';
574                                if (count($a_sambadomains))
575                                {
576                                        foreach ($a_sambadomains as $a_sambadomain)
577                                        {
578                                                if ($a_sambadomain['samba_domain_sid'] == $user_info['sambasid'])
579                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "' SELECTED>" . $a_sambadomain['samba_domain_name'] . "</option>";
580                                                else
581                                                        $sambadomainname_options .= "<option value='" . $a_sambadomain['samba_domain_sid'] . "'>" . $a_sambadomain['samba_domain_name'] . "</option>";
582                                        }
583                                }
584                        }
585                       
586                        // Mail Alternate & Forwarding
587                        if (is_array($user_info['mailalternateaddress']))
588                        {
589                                for ($i = 0; $i < $user_info['mailalternateaddress']['count']; $i++)
590                                {
591                                        if ($i > 0)
592                                                $input_mailalternateaddress_fields .= '<br>';
593                                        $input_mailalternateaddress_fields .= '<input type="text" name="mailalternateaddress[]" id="mailalternateaddress" autocomplete="off" value="'.$user_info['mailalternateaddress'][$i].'" {disabled} size=30>';
594                                }
595                        }
596                        else
597                        {
598                                $input_mailalternateaddress_fields = '<input type="text" name="mailalternateaddress[]" id="mailalternateaddress" autocomplete="off" value="" {disabled} size=30>';
599                        }
600
601                        if (is_array($user_info['mailforwardingaddress']))
602                        {
603                                for ($i = 0; $i < $user_info['mailforwardingaddress']['count']; $i++)
604                                {
605                                        if ($i > 0)
606                                                $input_mailforwardingaddress_fields .= '<br>';
607                                        $input_mailforwardingaddress_fields .= '<input type="text" name="mailforwardingaddress[]" id="mailforwardingaddress" autocomplete="off" value="'.$user_info['mailforwardingaddress'][$i].'" {disabled} size=30>';
608                                }
609                        }
610                        else
611                        {
612                                $input_mailforwardingaddress_fields = '<input type="text" name="mailforwardingaddress[]" id="mailforwardingaddress" autocomplete="off" value="" {disabled} size=30>';
613                        }
614
615                        if ($alert_warning != '')
616                                $alert_warning = "alert('". $alert_warning ."')";
617                        $var = Array(
618                                'uidnumber'                                     => $_GET['account_id'],
619                                'type'                                          => 'edit_user',
620                                'photo_exist'                           => $user_info['photo_exist'],
621                                'departmentnumber'                      => $user_info['departmentnumber'],
622                                'user_context'                          => $user_info['context'],
623                               
624                                'row_on'                                        => "#DDDDDD",
625                                'row_off'                                       => "#EEEEEE",
626                                'color_bg1'                                     => "#E8F0F0",
627                                'action'                                        => $GLOBALS['phpgw']->link('/index.php','menuaction=expressoAdmin1_2.uiaccounts.validate_user_data_edit'),
628                                'back_url'                                      => './index.php?menuaction=expressoAdmin1_2.uiaccounts.list_users',
629                                'disabled'                                      => $disabled,
630                                'disabled_password'                     => $disabled_password,
631                                'disabled_samba'                        => $disabled_samba,
632                                'changequote_disabled'          => $disabled_quote,
633                                'disable_phonenumber'           => $disabled_phonenumber,
634                                'disable_group'                         => $disabled_group,
635                               
636                                // Display ABAS
637                                'display_corporative_information'=> $this->functions->check_acl($manager_account_lid,'manipulate_corporative_information') ? '' : 'none',
638                                'display_applications'          => $this->functions->check_acl($manager_account_lid,'display_applications') ? '' : 'none',
639                                'display_emaillists'            => $this->functions->check_acl($manager_account_lid,'display_emaillists') ? '' : 'none',
640                                'display_groups'                        => $this->functions->check_acl($manager_account_lid,'display_groups') ? '' : 'none',
641                                'display_emailconfig'           => $this->functions->check_acl($manager_account_lid,'display_emailconfig') ? '' : 'none',
642                               
643                                // First ABA
644                                'alert_warning'                                 => "$alert_warning",
645                                'display_input_account_lid'             => 'display:none',
646                                'lang_general_information'              => lang('General Information'),
647                                'lang_corporative_information'  => lang('Corporative Information'),
648                                'lang_email_config'                             => lang('Email Config'),
649                                'lang_groups_permission'                => lang('Groups Permission'),
650                                'lang_lists_permission'                 => lang('Email Lists'),
651                                'lang_aplication_permission'    => lang('Aplication Permission'),       
652                                'lang_organizations'                    => lang('Organizations'),
653                                'lang_search_organization'              => lang('Search Organiztion'),
654                                'lang_sector'                                   => lang('Sector'),
655                                'lang_account_lid'                              => lang('Login ID'),
656                                'lang_firstname'                                => lang('First Name'),
657                                'lang_lastname'                                 => lang('Last Name'),
658                                'lang_passwd_expired'                   => lang('Password expired'),
659                                'lang_password'                                 => lang('Password'),
660                                'lang_phone'                                    => lang('Phone'),
661                                'lang_photo'                                    => lang('Photo'),
662                                'lang_re-password'                              => lang('Re-Password'),
663                                'lang_changepassword'                   => lang('Change password'),                             
664                                'lang_account_active'                   => lang('Account Active'),
665                                'lang_account_invisible'                => lang('Account Invisible'),
666                                'lang_back'                                             => lang('Back'),
667                                'lang_save'                                             => lang('Save'),
668                               
669                                'sectors'                                               => $combo_manager_org,
670                                'combo_organizations'                   => $combo_manager_org,
671                                'combo_all_orgs'                                => $combo_all_orgs,
672                               
673                                'uid'                                                   => $user_info['uid'],
674                                'givenname'                                             => $user_info['givenname'],
675                                'mail1'                                                 => $user_info['mail'],
676                                'sn'                                                    => $user_info['sn'],
677                                'telephonenumber'                               => $user_info['telephonenumber'],
678                                'photo_bin'                                             => $photo_bin,
679                                'disabled_edit_photo'                   => $disabled_edit_photo,
680                                //'display_picture'                             => $this->functions->check_acl($manager_account_lid,'edit_users_picture') ? '' : 'none',
681                                'display_picture'                               => $display_picture,
682                               
683                                'display_tr_default_password'   => $this->functions->check_acl($manager_account_lid,'set_user_default_password') ? '' : 'none',
684                               
685                                'passwd_expired_checked'                => $user_info['passwd_expired'] == '0' ? 'CHECKED' : '',
686                                'changepassword_checked'                => $user_info['changepassword'] == '1' ? 'CHECKED' : '',
687                                'phpgwaccountstatus_checked'    => $user_info['phpgwaccountstatus'] == 'A' ? 'CHECKED' : '',
688                                'phpgwaccountvisible_checked'   => $user_info['phpgwaccountvisible'] == '-1' ? 'CHECKED' : '',
689
690                                // Corporative Information
691                                'lang_employeenumber'                   => lang('Employee number'),
692                                'lang_cpf'                                              => lang('cpf'),
693                                'lang_rg'                                               => lang('rg'),
694                                'lang_rguf'                                             => lang('rguf'),
695                                'corporative_information_employeenumber' => $user_info['corporative_information_employeenumber'],
696                                'corporative_information_cpf'                   => $user_info['corporative_information_cpf'],
697                                'corporative_information_rg'                    => $user_info['corporative_information_rg'],
698                                'corporative_information_rguf'                  => $user_info['corporative_information_rguf'],
699                               
700                                //MAIL
701                                'disabled_quota_used'           => 'disabled',
702                                'lang_activeemailaccount'       => lang('Active email account'),
703                                'lang_email'                            => lang('E-mail'),
704                                'lang_aliasemail'                       => lang('Alias email'),
705                                'lang_forwardingemail'          => lang('Forwarding email'),
706                                'lang_email_quota'                      => lang('Email quota in MB'),
707                                'lang_onlyforwarding'           => lang('Only forwarding'),
708                                'lang_email_quota_used'         => lang('Quota used in MB'),
709                               
710                                'accountstatus_checked'         => $user_info['accountstatus'] == 'active' ? 'CHECKED' : '',
711                                'mail'                                          => $user_info['mail'],
712                               
713                                //'mailalternateaddress'                => $user_info['mailalternateaddress'],
714                                //'mailforwardingaddress'               => $user_info['mailforwardingaddress'],
715                                'input_mailalternateaddress_fields'     => $input_mailalternateaddress_fields,
716                                'input_mailforwardingaddress_fields'=> $input_mailforwardingaddress_fields,
717                               
718                                'deliverymode_checked'          => $user_info['deliverymode'] == 'forwardOnly' ? 'CHECKED' : '',
719                               
720                                'mailquota'                                     => $user_info['mailquota'],
721                                'mailquota_used'                        => $user_info['mailquota_used'],
722
723                                //Third ABA
724                                'lang_groups'                           => lang('Groups'),
725                                'lang_user_groups'                      => 'Grupos do Usuário',
726                                'lang_available_groups'         => 'Grupos disponíveis',
727                                'lang_primary_group'            => lang('Primary Group'),
728                                'lang_add'                                      => lang('Add'),
729                                'lang_rem'                                      => lang('Remove'),
730                                'ea_select_user_groups_options' => $ea_select_user_groups_options,
731                                'ea_combo_primary_user_group_options'   => $ea_combo_primary_user_group_options,
732                               
733                                //Fourd ABA
734                                'lang_user_mail_lists'                  => 'O usuário participa destas Listas de E-mail',
735                                'lang_available_mail_lists'             => 'Listas de E-mail disponíveis',
736                                'ea_select_user_maillists_options'  => $ea_select_user_maillists_options,
737                                                               
738                                //Five ABA
739                                'apps'  => $apps,
740
741                                //SAMBA ABA
742                                'lang_samba_config'                     => lang('Samba Config'),
743                                'lang_use_attrs_samba'          => lang('Use samba attributes'),
744                                'lang_sambadomain'                      => lang('Domain'),
745                                'lang_sambaAcctFlags'           => lang('AcctFlags'),
746                                'lang_sambaLogonScript'         => lang('Logon Script'),
747                                'lang_sambaHomeDirectory'       => lang('Home Directory'),
748                                'lang_active_user'                      => lang('Samba User Active'),
749                                'lang_desactive_user'           => lang('Samba User Desactive'),
750                               
751                                'userSamba'                                     => $user_info['sambaUser'],
752                                'sambadomainname_options'       => $sambadomainname_options,
753                                'use_attrs_samba_checked'       => $user_info['sambaUser'] ? 'CHECKED' : '',
754                                'active_user_selected'          => $user_info['sambaaccflags'] == '[U          ]' ? 'selected' : '',
755                                'desactive_user_selected'       => $user_info['sambaaccflags'] == '[DU         ]' ? 'selected' : '',
756                                'sambalogonscript'                      => $user_info['sambalogonscript'],
757                                'sambahomedirectory'            => $user_info['homedirectory'],
758                                'defaultLogonScript'            => $this->current_config['expressoAdmin_defaultLogonScript'],
759                                'use_suggestion_in_logon_script' => $this->current_config['expressoAdmin_defaultLogonScript'] == '' ? 'true' : 'false'
760                        );
761                        $t->set_var($var);
762                       
763                        // Devo mostrar aba SAMBA ??
764                        if ( ($this->current_config['expressoAdmin_samba_support'] == 'true') && ($this->functions->check_acl($manager_account_lid,'edit_sambausers_attributes')) )
765                                $t->set_var('display_samba_suport', '');
766                        else
767                                $t->set_var('display_samba_suport', 'none');
768                       
769                        $t->pfp('out','body');                 
770                }
771               
772                function row_action($action,$type,$account_id)
773                {
774                        return '<a href="'.$GLOBALS['phpgw']->link('/index.php',Array(
775                                'menuaction' => 'expressoAdmin1_2.uiaccounts.'.$action.'_'.$type,
776                                'account_id' => $account_id
777                        )).'"> '.lang($action).' </a>';
778                }
779
780                function css()
781                {
782                        $appCSS =
783                        'th.activetab
784                        {
785                                color:#000000;
786                                background-color:#D3DCE3;
787                                border-top-width : 1px;
788                                border-top-style : solid;
789                                border-top-color : Black;
790                                border-left-width : 1px;
791                                border-left-style : solid;
792                                border-left-color : Black;
793                                border-right-width : 1px;
794                                border-right-style : solid;
795                                border-right-color : Black;
796                                font-size: 12px;
797                                font-family: Tahoma, Arial, Helvetica, sans-serif;
798                        }
799                       
800                        th.inactivetab
801                        {
802                                color:#000000;
803                                background-color:#E8F0F0;
804                                border-bottom-width : 1px;
805                                border-bottom-style : solid;
806                                border-bottom-color : Black;
807                                font-size: 12px;
808                                font-family: Tahoma, Arial, Helvetica, sans-serif;                             
809                        }
810                       
811                        .td_left {border-left:1px solid Gray; border-top:1px solid Gray; border-bottom:1px solid Gray;}
812                        .td_right {border-right:1px solid Gray; border-top:1px solid Gray; border-bottom:1px solid Gray;}
813                       
814                        div.activetab{ display:inline; }
815                        div.inactivetab{ display:none; }';
816                       
817                        return $appCSS;
818                }
819
820                function show_photo()
821                {
822                        $uidNumber = $_GET['uidNumber'];
823                        $photo = $this->get_photo($uidNumber);
824                       
825                if ($photo)
826                        {
827                        header("Content-Type: image/jpeg");
828                                $width = imagesx($photo);
829                                $height = imagesy($photo);
830                    $twidth = 80;
831                $theight = 106;
832                                $small_photo = imagecreatetruecolor ($twidth, $theight);
833                                imagecopyresampled($small_photo, $photo, 0, 0, 0, 0,$twidth, $theight, $width, $height);
834                                imagejpeg($small_photo,"",100);
835                                return;
836                        }
837                }
838               
839                function get_photo($uidNumber)
840                {
841                        $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect();
842                        $filter="(&(phpgwAccountType=u)(uidNumber=".$uidNumber."))";
843                        $justthese = array("jpegphoto");
844
845                        $search = ldap_search($ldap_conn, $GLOBALS['phpgw_info']['server']['ldap_context'], $filter, $justthese);
846                        $entry = ldap_first_entry($ldap_conn, $search);
847                        $jpeg_data = ldap_get_values_len($ldap_conn, $entry, "jpegphoto");
848                        $jpegphoto = imagecreatefromstring($jpeg_data[0]);
849                        return $jpegphoto;
850                }
851               
852                function show_access_log()
853                {       
854                        $account_id = $_GET['account_id'];
855                       
856                        $manager_account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
857                        $tmp = $this->functions->read_acl($manager_account_lid);
858                        $manager_context = $tmp[0]['context'];
859                       
860                        // Verifica se tem acesso a este modulo
861                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && (!$this->functions->check_acl($manager_account_lid,'change_users_password')))
862                        {
863                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/expressoAdmin1_2/inc/access_denied.php'));
864                        }
865
866                        // Seta header.
867                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
868                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
869
870                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['expressoAdmin1_2']['title'].' - '.lang('Access Log');
871                        $GLOBALS['phpgw']->common->phpgw_header();
872
873                        // Seta templates.
874                        $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
875                        $t->set_file(array("body" => "accesslog.tpl"));
876                        $t->set_block('body','main');
877                        $t->set_block('body','row','row');
878
879                        // GET access log from the user.
880                        $GLOBALS['phpgw']->db->limit_query("select loginid,ip,li,lo,account_id,sessionid from phpgw_access_log WHERE account_id=".$account_id." order by li desc",$start,__LINE__,__FILE__);
881                        while ($GLOBALS['phpgw']->db->next_record())
882                        {
883                                $records[] = array(
884                                        'loginid'    => $GLOBALS['phpgw']->db->f('loginid'),
885                                        'ip'         => $GLOBALS['phpgw']->db->f('ip'),
886                                        'li'         => $GLOBALS['phpgw']->db->f('li'),
887                                        'lo'         => $GLOBALS['phpgw']->db->f('lo'),
888                                        'account_id' => $GLOBALS['phpgw']->db->f('account_id'),
889                                        'sessionid'  => $GLOBALS['phpgw']->db->f('sessionid')
890                                );
891                        }
892
893                        // Seta as vcariaveis
894                        while (is_array($records) && list(,$record) = each($records))
895                        {
896                                $var = array(
897                                        'row_loginid' => $record['loginid'],
898                                        'row_ip'      => $record['ip'],
899                                        'row_li'      => date("d/m/Y - H:i:s", $record['li']),
900                                        'row_lo'      => $record['lo'] == 0 ? 0 : date("d/m/Y - H:i:s", $record['lo'])
901                                );
902                                $t->set_var($var);
903                                $t->fp('rows','row',True);
904                        }
905
906                        $var = Array(
907                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
908                                'lang_back'             => 'Back',
909                                'back_url'              => "./index.php?menuaction=expressoAdmin1_2.uiaccounts.edit_user&account_id=$account_id",
910                                'lang_loginid'  => lang('Login ID'),
911                                'lang_ip'               => lang('IP'),
912                                'lang_login'    => lang('Log IN'),
913                                'lang_logout'   => lang('Log OUT')
914                        );
915                        $t->set_var($var);
916                        $t->pfp('out','body');
917                }
918        }
919?>
Note: See TracBrowser for help on using the repository browser.