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

Revision 594, 34.9 KB checked in by niltonneto, 15 years ago (diff)

Resolve #392

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