source: branches/2.2/expressoAdmin1_2/inc/class.uiaccounts.inc.php @ 3458

Revision 3458, 35.3 KB checked in by eduardoalex, 13 years ago (diff)

Ticket #1227 - Tratamento da acl na edição de usuários

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