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

Revision 5133, 35.1 KB checked in by wmerlotto, 12 years ago (diff)

Ticket #2305 - Enviando alteracoes, desenvolvidas internamente na Prognus, do modulo ExpressoAdmin.

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