source: sandbox/expressoMail1_2/MailArchiver/2.2/reports/inc/class.uireports_logon.inc.php @ 4644

Revision 4644, 32.0 KB checked in by fernando-alberto, 13 years ago (diff)

Ticket #1269 - Mergiando revisoes do brach22 de rev4447 ate rev4643

Line 
1<?php
2        /*************************************************************************************\
3        * Expresso Relatório                                                                                                     *
4        * by Elvio Rufino da Silva (elviosilva@yahoo.com.br, elviosilva@cepromat.mt.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 uireports_logon
13        {
14                var $public_functions = array
15                (
16                        'report_logon_print_pdf'                        => True,
17                        'report_logon_group'                            => True,
18                        'report_logon_group_setor_print'        => True,
19                        'show_access'                                           => True,
20                        'get_user_info'                                         => True,
21                        'css'                                                           => True
22                );
23
24                var $nextmatchs;
25                var $user;
26                var $functions;
27                var $current_config;
28                var $ldap_functions;
29                var $db_functions;
30
31                function uireports_logon()
32                {
33                        $this->user                     = CreateObject('reports.user');
34                        $this->nextmatchs       = CreateObject('phpgwapi.nextmatchs');
35                        $this->functions        = CreateObject('reports.functions');
36                        $this->ldap_functions = CreateObject('reports.ldap_functions');
37                        $this->db_functions = CreateObject('reports.db_functions');
38                        $this->fpdf = CreateObject('reports.uireports_fpdf'); // Class para PDF
39                                                                       
40                        $c = CreateObject('phpgwapi.config','reports'); // cria o objeto relatorio no $c
41                        $c->read_repository(); // na classe config do phpgwapi le os dados da tabela phpgw_config where relatorio, como passagem acima
42                        $this->current_config = $c->config_data; // carrega os dados em do array no current_config
43
44                        if(!@is_object($GLOBALS['phpgw']->js))
45                        {
46                                $GLOBALS['phpgw']->js = CreateObject('phpgwapi.javascript');
47                        }
48                        $GLOBALS['phpgw']->js->validate_file('jscode','cc','reports');
49                }
50               
51                function report_logon_print_pdf()
52                {
53                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
54                        $acl = $this->functions->read_acl($account_lid);
55                        $raw_context = $acl['raw_context'];
56                        $contexts = $acl['contexts'];
57                        foreach ($acl['contexts_display'] as $index=>$tmp_context)
58                        {
59                                $context_display .= $tmp_context;
60                        }
61
62
63                        if (!$this->functions->check_acl($account_lid,'list_users'))
64                        {
65                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/reports/inc/access_denied.php'));
66                        }
67
68                        $grouplist = trim($_POST[setor]);
69                        $grouplist = trim(ereg_replace("-","",$grouplist));
70
71                        $setordn = trim($_POST[setordn]);
72                        $subtitulo1 = trim($_POST[subtitulo]);
73                       
74                        $vnumacesso = trim($_POST[nacesso]);
75                        $numacesso = abs(round($vnumacesso));
76
77                        if ($vnumacesso==999){
78                                $numacesso = lang('Never login');
79                        }
80
81
82                        define('FPDF_FONTPATH','font/');
83                        $data_atual = date("d/m/Y");
84                        $titulo_system = $GLOBALS['phpgw_info']['apps']['reports']['title'];                   
85
86                        $pdf=new uireports_fpdf("L");
87                        $pdf->Open();
88                        $pdf->AddPage();
89
90                        //Set font and colors
91                        $pdf->SetFont('Arial','B',14);
92                        $pdf->SetFillColor(0,0,0);
93                        $pdf->SetTextColor(0,0,200);
94                        $pdf->SetDrawColor(0,0,0);
95                        $pdf->SetLineWidth(.2);
96
97                        //Table header
98                        $SubTitulo = lang('reports title6');
99                        $SubTituloR = lang('Report Generated by Expresso Reports');
100                        $SubTitulo1 = $subtitulo1;
101                        $GLOBALS['phpgw_info']['apps']['reports']['subtitle'] = $SubTituloR;
102                        $pdf->Cell(0,8,$SubTitulo,0,1,'C',0);
103
104
105                        //Set font and colors
106                        $pdf->SetFont('Arial','B',8);
107                        $pdf->SetFillColor(0,0,0);
108                        $pdf->SetTextColor(0,0,200);
109                        $pdf->SetDrawColor(0,0,0);
110                        $pdf->SetLineWidth(.3);
111
112//                      $pdf->Cell(0,10,$SubTitulo1,0,1,'C',0);
113                        $pdf->MultiCell(0,3,$SubTitulo1,0,'C',0);
114                                               
115                        $pdf->Cell(0,2,' ',0,1,'C',0);
116                        $pdf->Cell(0,5,'Data..: '.$data_atual,0,0,'L',0);
117                        $pdf->Cell(0,5,$titulo_system,0,1,'R',0);
118                                                                                               
119                        $account_info = $this->functions->get_list_user_sector_logon($setordn,$contexts,0,$numacesso);
120
121                        if (count($account_info))
122                        {
123                                //Restore font and colors
124                                $pdf->SetFont('Arial','',8);
125                                $pdf->SetFillColor(224,235,255);
126                                $pdf->SetTextColor(0);
127
128                                $pdf->Cell(60,5,lang('loginid'),1,0,'L',1);
129                                $pdf->Cell(60,5,lang('name'),1,0,'L',1);
130                                $pdf->Cell(70,5,lang('report email'),1,0,'L',1);
131                                $pdf->Cell(25,5,lang('Creation Date'),1,0,'C',1);
132                                $pdf->Cell(25,5,lang('Last access'),1,0,'C',1);
133                                $pdf->Cell(22,5,lang('Days without login'),1,0,'L',1);                         
134                                $pdf->Cell(18,5,lang('status'),1,1,'L',1);
135
136                               
137                                while (list($null,$accountp) = each($account_info))
138                                {
139
140                                        $access_log = $this->functions->show_access_log($accountp['account_id']);
141
142                                        $access_log_array = explode("#",$access_log);
143                                       
144                                        $accountp['li_dias'] = $access_log_array[1];
145                                        $accountp['li_date'] = $access_log_array[0];
146
147                                        $tmpp[$contap]['account_id'] = $accountp['account_id'];
148                                        $tmpp[$contap]['account_lid'] = $accountp['account_lid'];
149                                        $tmpp[$contap]['account_cn'] = $accountp['account_cn'];
150                                        $tmpp[$contap]['account_status'] = $accountp['account_accountstatus'];
151                                        $tmpp[$contap]['account_mail'] = $accountp['account_mail'];
152                                        $tmpp[$contap]['createTimestamp'] = $accountp['createtimestamp'];
153                                        $tmpp[$contap]['li_dias']= $accountp['li_dias'];
154                                        $tmpp[$contap]['li_date']= $accountp['li_date'];
155
156                                        $sortp[] = $accountp['li_dias'];
157
158                                        if (count($sortp))
159                                        {
160                                                natcasesort($sortp);
161                                        }
162
163                                        $contap = $contap + 1;
164                                }
165
166                                while (list($key,$accountr1) = each($sortp))
167                                {
168                                        if ($key == 0){
169                                                $key = '';
170                                                $returnp[] = $tmpp[$key];
171                                        }else{
172                                                $returnp[] = $tmpp[$key];
173                                        }
174                                }
175
176                                $returnp = array_reverse($returnp);
177
178                                while (list($null,$accountr) = each($returnp))
179                                {
180                                                $row_cn = $accountr['account_cn'];
181                                                $account_lid = $accountr['account_lid'];
182                                                $row_mail = (!$accountr['account_mail'] ? lang('Without E-mail') : $accountr['account_mail']);
183                                                $row_timestamp = substr($accountr['createTimestamp'], 6, 2)."/".substr($accountr['createTimestamp'], 4, 2)."/".substr($accountr['createTimestamp'], 0, 4);
184                                                $row_li_date = $accountr['li_date'] == lang('Never login') ? lang('Never login') : $accountr['li_date'];
185                                                $row_li_dias = $accountr['li_dias'];
186                                                $row_status = $accountr['account_status'] == 'active' ? lang('Activated') : lang('Disabled');
187                                               
188                                                $pdf->Cell(60,5,$account_lid,0,0,'L',0);
189                                                $pdf->Cell(60,5,$row_cn,0,0,'L',0);
190                                                $pdf->Cell(70,5,$row_mail,0,0,'L',0);
191                                                $pdf->Cell(25,5,$row_timestamp,0,0,'C',0);
192
193                                                if ($row_li_date == lang('Never login'))
194                                                {
195                                                        //Muda cor fonte
196                                                        $pdf->SetTextColor(256,0,0);
197                                                        $pdf->Cell(25,5,$row_li_date,0,0,'C',0);
198                                                        //Restaura cor fonte
199                                                        $pdf->SetTextColor(0);
200                                                }
201                                                else
202                                                {
203                                                        //Restaura cor fonte
204                                                        $pdf->SetTextColor(0);
205                                                        $pdf->Cell(25,5,$row_li_date,0,0,'C',0);
206                                                }
207
208                                                $pdf->Cell(22,5,$row_li_dias,0,0,'C',0);                                                                                                                                               
209
210                                                if ($row_status == 'Ativado')
211                                                {
212                                                        //Restaura cor fonte
213                                                        $pdf->SetTextColor(0);
214                                                        $pdf->Cell(18,5,$row_status,0,1,'L',0);
215                                                }
216                                                else
217                                                {
218                                                        //Muda cor fonte
219                                                        $pdf->SetTextColor(256,0,0);
220                                                        $pdf->Cell(18,5,$row_status,0,1,'L',0);                                 
221                                                        //Restaura cor fonte
222                                                        $pdf->SetTextColor(0);
223                                                }
224                                }
225                        }
226
227                        $pdf->Output();
228
229                        return;
230                }
231
232                function report_logon_group()
233                {
234                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
235                        $manager_acl = $this->functions->read_acl($account_lid);
236                        $raw_context = $acl['raw_context'];
237                        $contexts = $manager_acl['contexts'];
238                        $conta_context = count($manager_acl['contexts_display']);
239                        foreach ($manager_acl['contexts_display'] as $index=>$tmp_context)
240                        {
241                                $index = $index +1;
242
243                                if ($conta_context == $index)
244                                {
245                                        $context_display .= $tmp_context;
246                                }
247                                else
248                                {
249                                        $context_display .= $tmp_context.'&nbsp;|&nbsp;';
250                                }
251                        }
252                       
253                        // Verifica se tem acesso a este modulo
254                        if (!$this->functions->check_acl($account_lid,'list_sectors'))
255                        {
256                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/reports/inc/access_denied.php'));
257                        }
258
259                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
260                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
261                       
262                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['reports']['title'].' - '.lang('report of time without logging by Organization');
263                        $GLOBALS['phpgw']->common->phpgw_header();
264
265                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
266                        $p->set_file(array('groups'   => 'report_logon_group.tpl'));
267                        $p->set_block('groups','list','list');
268                        $p->set_block('groups','row','row');
269                        $p->set_block('groups','row_empty','row_empty');
270
271                        // Seta as variaveis padroes.
272                        $var = Array(
273                                'th_bg'                                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
274                                'back_url'                              => $GLOBALS['phpgw']->link('/reports/index.php'),
275                                'context_display'               => $context_display
276                        );
277                        $p->set_var($var);
278                        $p->set_var($this->functions->make_dinamic_lang($p, 'list'));
279                       
280
281                        $GLOBALS['organizacaodn'] = $_POST['organizacaodn'];
282
283                        $contextsdn = $GLOBALS['organizacaodn'];
284
285                        // Save query
286                        $varorganizacao = explode(",",$contextsdn);
287                        $varorganizacao_nome = trim(strtoupper(ereg_replace("ou=","",$varorganizacao[0])));
288                        $varorganizacao_nome = trim(strtoupper(ereg_replace("DC=","",$varorganizacao_nome)));
289                        $user_logon = $GLOBALS['phpgw_info']['user'][account_lid];
290
291                        // carrega os grupos no listbox
292                        /************* DESCOMENTE ESTE PARTE DO CODIGO PARA LISTAR TODOS OS GRUPOS, SEM LISTAR POR USUSARIO LOGADO ***********
293                        $sectors_info = $this->functions->get_groups_list($contexts,"*");
294                        $sectors_info_dn = $this->functions->get_groups_list_dn($contexts,"*");
295                        /* ************************************* FIM *********************************************************************** */
296
297                        $sectors_info = $this->functions->get_list_context_logon($user_logon,$contexts,0);
298                        $sectors_info_dn = $this->functions->get_list_groups_dn($user_logon,$contexts,0);
299
300                        if (!count($sectors_info))
301                        {
302                                $p->set_var('notselect',lang('No matches found'));
303                        }
304                        else
305                        {
306                                foreach($sectors_info as $context=>$sector)
307                                {
308                                       
309                                        $sectordn = $sectors_info_dn[$context];
310
311                                        $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
312                                       
313                                        if ($context == 0 && $contextsdn <> "")
314                                        {
315                                                if (trim(strtoupper($varorganizacao_nome)) ==  trim(strtoupper($sector)))
316                                                {
317                                                        $sector_options .= "<option selected value='" .$contextsdn. "'>" .$varorganizacao_nome. "</option>";
318                                                }
319                                                else
320                                                {
321                                                        $sector_options .= "<option selected value='" .$contextsdn. "'>" .$varorganizacao_nome. "</option>";
322                                                        $sector_options .= "<option value='" . $sectordn . "'>". $sector . "</option>";
323                                                }
324
325                                        }
326                                        else
327                                        {
328                                                if ( trim(strtoupper($varorganizacao_nome)) !=  trim(strtoupper($sector)))
329                                                {
330                                                        $sectorok = trim(strtoupper(ereg_replace("dc=","",$sector)));
331                                                        $sectorok = trim(strtoupper(ereg_replace("dc=","",$sectorok)));
332                                                        $sector_options .= "<option value='" . $sectordn . "'>". $sectorok . "</option>";
333                                                }
334                                        }
335
336                                        $varselect = Array(
337                                                'tr_color'      => $tr_color,
338                                                'organizacaodn' => $contextsdn,
339                                                'group_name'    => $sector_options
340                                        );                                     
341                                }
342
343                                $p->set_var($varselect);
344                        }
345
346                        // ************** inicio carregar a sub-lista das organizações ****************
347                        //Admin make a search
348                        if ($GLOBALS['organizacaodn'] != '')
349                        {
350                                // Conta a quantidade de Usuario do grupo raiz
351                                $account_user = $this->functions->get_count_user_sector($contextsdn,$contexts,0);
352                                $totaluser = "(".$account_user.")";
353
354                                $p->set_var('organizacao', $varorganizacao_nome);
355                                $p->set_var('all_user', lang('all'));
356                                $p->set_var('total_user', $totaluser);
357
358                                $setorg = $contextsdn;
359
360                                $groups_info = $this->functions->get_sectors_list($contexts,$setorg);
361
362                                if (!count($groups_info))
363                                {
364                                        $p->set_var('message',lang('No sector found'));
365                                        $p->parse('rows','row_empty',True);                             
366                                }
367                                else
368                                {
369                                        $ii = 0;
370                                        foreach($groups_info as $context=>$groups)
371                                        {
372                                                $explode_groups = explode("#",$groups);
373                                                $ii = $ii + 1;
374                                                $tr_color = $this->nextmatchs->alternate_row_color($tr_color);
375                                                $varsuborg = Array(
376                                                        'tr_color'                                      => $tr_color,
377                                                        'div_nacesso'                           => "div_nacesso".$ii,
378                                                        'formname'                                      => "form".$ii,
379                                                        'formsubmit'                            => "document.form".$ii.".submit()",
380                                                        'sector_name'                           => $explode_groups[0],
381                                                        'sector_namedn'                         => $explode_groups[1],
382                                                        'sector_namedn_completo'        => $explode_groups[2],                 
383                                                );                                     
384
385                                                $p->set_var($varsuborg);                                       
386                                                $p->parse('rows','row',True);
387                                        }
388                                }
389                        }
390
391                        $p->pfp('out','list');
392                }
393
394                function report_logon_group_setor_print()
395                {
396                        $vnumacesso = trim($_POST[nacesso]);
397                        $numacesso = abs(round($vnumacesso));
398
399                        if ($vnumacesso==999){
400                                $numacesso = "Nunca logou";
401                        }
402
403                        $grouplist = trim($_POST[setor]);
404                        $grouplist = trim(ereg_replace("-","",$grouplist));
405                        $organizacao = trim($_POST[organizacao]);
406                        $setordn = trim($_POST[setordn]);
407                        $organizacaodn = trim($_POST[organizacaodn]);
408                        $sectornamedncompleto = trim($_POST[sectornamedncompleto]);
409                        $Psectornamedncompleto = trim($_POST[Psectornamedncompleto]);
410
411                        if ($sectornamedncompleto=="" && $Psectornamedncompleto=="")
412                        {                       
413                                $sectornamedncompleto = $organizacao;
414                        }
415                        else if ($sectornamedncompleto=="" && $Psectornamedncompleto <> "")
416                        {
417                                $sectornamedncompleto = $Psectornamedncompleto;
418                        }
419                        else
420                        {
421                                $sectornamedncompleto = $organizacao." | ".$sectornamedncompleto;
422                        }
423
424                        $data_atual = date("d/m/Y");
425                        $titulo_system = $GLOBALS['phpgw_info']['apps']['reports']['title'];
426                       
427                        $account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
428                        $acl = $this->functions->read_acl($account_lid);
429                        $raw_context = $acl['raw_context'];
430                        $contexts = $acl['contexts'];
431                        foreach ($acl['contexts_display'] as $index=>$tmp_context)
432                        {
433                                $context_display .= $tmp_context;
434                        }
435                        // Verifica se o administrador tem acesso.
436                        if (!$this->functions->check_acl($account_lid,'list_users'))
437                        {
438                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/reports/inc/access_denied.php'));
439                        }
440
441                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
442                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
443                        $GLOBALS['phpgw_info']['flags']['app_header'] =  $GLOBALS['phpgw_info']['apps']['reports']['title'].' - '.lang('report user');
444                        $GLOBALS['phpgw']->common->phpgw_header();
445
446                        $p = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
447                        $p->set_file(Array('accounts' => 'report_logon_group_print.tpl'));
448                        $p->set_block('accounts','body');
449                        $p->set_block('accounts','rowpag');
450                        $p->set_block('accounts','row');
451                        $p->set_block('accounts','row_empty');
452                       
453                        $var = Array(
454                                'bg_color'                                      => $GLOBALS['phpgw_info']['theme']['bg_color'],
455                                'th_bg'                                         => $GLOBALS['phpgw_info']['theme']['th_bg'],
456                                'subtitulo'                                     => lang('reports title6'),
457                                'subtitulo1'                            => $sectornamedncompleto,
458                                'context'                                       => $raw_context,
459                                'titulo'                                        => $titulo_system,
460                                'data_atual'                            => $data_atual,                         
461                                'context_display'                       => $context_display,
462                                'organizacaodn'                         => $organizacaodn,
463                                'organizacao'                           => $organizacao,
464                                'sector_name'                           => $grouplist,
465                                'sector_namedn'                         => $setordn,
466                                'nacesso'                                       => $vnumacesso,
467                                'imapDelimiter'                         => $_SESSION['phpgw_info']['expresso']['email_server']['imapDelimiter']
468                        );
469
470                        $p->set_var($var);
471                        $p->set_var($this->functions->make_dinamic_lang($p, 'body'));
472
473                        // ************ PAGINAÇÃO *******************************
474
475                        // verifica se exixte usuarios no LDAP
476                        $account_info = $this->functions->get_list_user_sector_logon($setordn,$contexts,0,$numacesso);
477
478                        if (!count($account_info))
479                        {
480                                $p->set_var('message',lang('No user found'));
481                                $p->parse('rows','row_empty',True);
482                        }
483                        else if (count($account_info))
484                        {
485                                if ($vnumacesso==0){
486                                        //url do paginador
487                                        $url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/index.php?menuaction=reports.uireports_logon.report_logon_group_setor_print';
488       
489                                        // **** Grupo de paginas ****
490                                        $gpag = $_POST[gpage];
491       
492                                        $grupopage = 20;
493                                       
494                                        if (!$gpag){
495                                                $gpag  = 1;
496                                        }
497       
498                                        // recebe o numero da pagina
499                                        $npag = $_POST[page];
500       
501                                        // verifica se o get com o numero da pagina é nulo
502                                        if (!$npag)
503                                        {
504                                                $npag = 1;
505                                        }
506       
507                                        // conta total dos registros
508                                        $numreg = count($account_info);
509                                       
510                                        // numero de registro por paginação
511                                        $numpage = 53;
512                                       
513                                        $tp = ceil($numreg/$numpage);
514                                        $inicio = $page - 1;
515                                        $inicio = $inicio * $numpage;
516               
517                                        // valor maximo de paginação
518                                        $totalnpag =  (int)($tp/$grupopage);
519                                        $restonpag = $tp % $grupopage;
520       
521                                        if ($restonpag > 0)
522                                        {
523                                                $maxtotalnpag = $totalnpag + 1;
524                                        }
525                                        else
526                                        {
527                                                $maxtotalnpag = $totalnpag;
528                                        }
529                                        // inicio fim para imprimir a paginação
530                                        if( $tp > $grupopage)
531                                        {
532                                                // inicio do for da paginação
533                                                if ($gpag <= ($totalnpag))
534                                                {
535                                                        $fimgpg = $gpag * $grupopage;
536                                                        $iniciogpg = (($fimgpg - $grupopage)+1);
537                                                }
538                                                else
539                                                {
540                                                        $iniciogpg = (($gpag - 1) * $grupopage);
541                                                        $fimgpg = $iniciogpg + $restonpag;
542                                                }
543                                        }
544                                        else
545                                        {
546                                                // inicio do for da paginação
547                                                $iniciogpg = 1;
548                                                $fimgpg =  $tp;
549                                        }
550       
551
552                                        // Imprime valores de contagen de registro e pagina
553                                        $p->set_var('cont_user',$numreg);
554                                        $p->set_var('cont_page',$tp);
555                                        $p->set_var('page_now',$npag);
556       
557                                        // ********** busca no LDAP as informação paginada e imprime ****************
558                                        $paginas = $this->functions->Paginate_user_logon('accounts',$setordn,$contexts,'cn','asc',$npag,$numpage,$numacesso);
559
560                                        $tmpp = array();
561                                        $contap = 0;
562                                        while (list($null,$accountp) = each($paginas))
563                                        {
564                                                $access_log =  $this->functions->show_access_log($accountp['uidNumber'][0]);
565       
566                                                $access_log_array = explode("#",$access_log);
567                                               
568                                                $accountp['li_dias'][0] = $access_log_array[1];
569                                                $accountp['li_date'][0] = $access_log_array[0];
570       
571                                                $tmpp[$contap]['account_id']     = $accountp['uidNumber'][0];
572                                                $tmpp[$contap]['account_lid'] = $accountp['uid'][0];
573                                                $tmpp[$contap]['account_cn'] = $accountp['cn'][0];
574                                                $tmpp[$contap]['account_status'] = $accountp['accountStatus'][0];
575                                                $tmpp[$contap]['account_mail'] = $accountp['mail'][0];
576                                                $tmpp[$contap]['createTimestamp'] = $accountp['createTimestamp'][0];
577                                                $tmpp[$contap]['li_dias']= $accountp['li_dias'][0];
578                                                $tmpp[$contap]['li_date']= $accountp['li_date'][0];
579       
580                                                $sortp[] = $accountp['li_dias'][0];
581       
582                                                if (count($sortp))
583                                                {
584                                                        natcasesort($sortp);
585                                                }
586       
587                                                $contap = $contap + 1;
588                                        }
589       
590                                        while (list($key,$accountr1) = each($sortp))
591                                        {
592                                                $returnp[] = $tmpp[$key];
593                                        }
594       
595                                        $returnp = array_reverse($returnp);
596                                       
597                                        $ii = 0;
598                                       
599                                        while (list($null,$accountr) = each($returnp))
600                                        {
601                                                $this->nextmatchs->template_alternate_row_color($p);
602                                                $ii = $ii + 1;
603                                               
604                                                $varr = array(
605                                                        'formname'              => "formlog".$ii,
606                                                        'formsubmit'    => "document.formlog".$ii.".submit()",
607                                                        'row_idnumber'  => $accountr['account_id'],
608                                                        'row_loginid'   => $accountr['account_lid'],
609                                                        'row_cn'                => $accountr['account_cn'],
610                                                        'row_status'    => $accountr['account_status'] == 'active' ? '<font color="#0033FF">Ativado</font> ' : '<font color="#FF0000">Desativado</font>',
611                                                        'row_mail'              => (!$accountr['account_mail']?'<font color=red>Sem E-mail</font>':$accountr['account_mail']),
612                                                        'row_timestamp'         => substr($accountr['createTimestamp'], 6, 2)."/".substr($accountr['createTimestamp'], 4, 2)."/".substr($accountr['createTimestamp'], 0, 4),
613                                                        'row_li_date'           => $accountr['li_date'] ==lang('Never login') ? '<font color="#FF0000">'.$accountr['li_date'].'</font>' : $accountr['li_date'],
614                                                        'row_li_dias'           => $accountr['li_dias']
615                                                );
616                                               
617                                                $p->set_var($varr);
618               
619                                                $p->parse('rows','row',True);
620                                        }
621                                        // ********************** Fim ****************************
622       
623                                        // grupo de pagina anteriores
624                                        if ($gpag > 1)
625                                        {
626                                                $gpaga = $gpag - 1;
627                                                $varp = Array(
628                                                        'paginat'       =>      "<form name='anterior' method='POST' action='$url'>
629                                                        <input type='hidden' name='setor' value='$grouplist'>
630                                                        <input type='hidden' name='organizacao' value='$organizacao'>
631                                                        <input type='hidden' name='setordn' value='$setordn'>
632                                                        <input type='hidden' name='organizacaodn' value='$organizacaodn'>
633                                                        <input type='hidden' name='page' value='$npag'>
634                                                        <input type='hidden' name='gpage' value='$gpaga'>
635                                                        <input type='hidden' name='Psectornamedncompleto' value='$sectornamedncompleto'>
636                                                        <div style='float:left;' onClick='document.anterior.submit()'><a href='#'>".lang('Previous Pages')."<<&nbsp;&nbsp;&nbsp;</a></div></form>"
637                                                );
638                                                $p->set_var($varp);                                             
639               
640                                                        $p->parse('pages','rowpag',True);
641                                        }
642                                        // **** FIM *******
643       
644                                        // imprime a paginação
645                                        if ($fimgpg > 1)
646                                        {
647                                                for($x = $iniciogpg; $x <= $fimgpg; $x++)
648                                                {
649                                                        $varp = Array(
650                                                                'paginat'       =>  "<form name='form".$x."' method='POST' action='$url'>
651                                                                <input type='hidden' name='setor' value='$grouplist'>
652                                                                <input type='hidden' name='organizacao' value='$organizacao'>
653                                                                <input type='hidden' name='setordn' value='$setordn'>
654                                                                <input type='hidden' name='organizacaodn' value='$organizacaodn'>
655                                                                <input type='hidden' name='page' value='$x'>
656                                                                <input type='hidden' name='gpage' value='$gpag'>
657                                                                <input type='hidden' name='Psectornamedncompleto' value='$sectornamedncompleto'>
658                                                                <div style='float:left;' onClick='document.form".$x.".submit()'><a href='#'>$x&nbsp;</a></div></form>"
659                                                        );
660       
661                                                        $p->set_var($varp);                                             
662               
663                                                        $p->parse('pages','rowpag',True);
664                                                }
665                                        }
666                       
667                                        // proximo grupo de pagina
668                                        if ($gpag < $maxtotalnpag && $maxtotalnpag > 0)
669                                        {
670                                                $gpagp = $gpag + 1;
671                                                $varp = Array(
672                                                        'paginat'       =>  "<form name='proximo' method='POST' action='$url'>
673                                                        <input type='hidden' name='setor' value='$grouplist'>
674                                                        <input type='hidden' name='organizacao' value='$organizacao'>
675                                                        <input type='hidden' name='setordn' value='$setordn'>
676                                                        <input type='hidden' name='organizacaodn' value='$organizacaodn'>
677                                                        <input type='hidden' name='page' value='$npag'>
678                                                        <input type='hidden' name='gpage' value='$gpagp'>
679                                                        <input type='hidden' name='Psectornamedncompleto' value='$sectornamedncompleto'>
680                                                        <div style='float:left;' onClick='document.proximo.submit()'><a href='#'>&nbsp;&nbsp;&nbsp;>>".lang('Next Page')."</a></div></form>"
681                                                );
682                                                $p->set_var($varp);                                             
683       
684                                                $p->parse('pages','rowpag',True);
685                                        }
686       
687                                        $vart = Array(
688                                                'page'  => $npag,
689                                                'gpage' => $gpag
690                                        );
691               
692                                        $p->set_var($vart);
693                                        // ************************* FIM PAGINAÇÃO ***********************                                                     
694
695                                }else{
696                                // ******** caso não for zero não vai paginar *****************
697                                        //url do paginador
698                                        $url = $GLOBALS['phpgw_info']['server']['webserver_url'].'/index.php?menuaction=reports.uireports_logon.report_logon_group_setor_print';
699
700                                        // conta total dos registros
701                                        $numreg = count($account_info);
702
703                                        // Imprime valores de contagen de registro e pagina
704                                        $p->set_var('cont_user',$numreg);
705                                        $p->set_var('cont_page',"1");
706                                        $p->set_var('page_now',"1");
707
708                                        // ********** busca no LDAP as informação paginada e imprime ****************
709                                        $paginas =$this->functions->get_list_user_sector_logon($setordn,$contexts,0,$numacesso);
710
711                                        $tmpp = array();
712                                        $contap = 0;
713                                        while (list($null,$accountp) = each($paginas))
714                                        {
715                                                $access_log =  $this->functions->show_access_log($accountp['account_id']);
716       
717                                                $access_log_array = explode("#",$access_log);
718                                               
719                                                if ($numacesso<>lang('Never login')){
720                                                        $accountp['li_dias'] = $access_log_array[1];
721                                                        $accountp['li_date'] = $access_log_array[0];
722               
723                                                        $tmpp[$contap]['account_id']     = $accountp['account_id'];
724                                                        $tmpp[$contap]['account_lid'] = $accountp['account_lid'];
725                                                        $tmpp[$contap]['account_cn'] = $accountp['account_cn'];
726                                                        $tmpp[$contap]['account_status'] = $accountp['account_accountstatus'];
727                                                        $tmpp[$contap]['account_mail'] = $accountp['account_mail'];
728                                                        $tmpp[$contap]['createTimestamp'] = $accountp['createtimestamp'];
729                                                        $tmpp[$contap]['li_dias']= $accountp['li_dias'];
730                                                        $tmpp[$contap]['li_date']= $accountp['li_date'];
731               
732                                                        $sortp[] = $accountp['li_dias'];
733                                                }else{
734                                                        if ($numacesso == $access_log_array[0]) {
735                                                                $accountp['li_dias'] = $access_log_array[1];
736                                                                $accountp['li_date'] = $access_log_array[0];
737                       
738                                                                $tmpp[$contap]['account_id']     = $accountp['account_id'];
739                                                                $tmpp[$contap]['account_lid'] = $accountp['account_lid'];
740                                                                $tmpp[$contap]['account_cn'] = $accountp['account_cn'];
741                                                                $tmpp[$contap]['account_status'] = $accountp['account_accountstatus'];
742                                                                $tmpp[$contap]['account_mail'] = $accountp['account_mail'];
743                                                                $tmpp[$contap]['createTimestamp'] = $accountp['createtimestamp'];
744                                                                $tmpp[$contap]['li_dias']= $accountp['li_dias'];
745                                                                $tmpp[$contap]['li_date']= $accountp['li_date'];
746                       
747                                                                $sortp[] = $accountp['li_dias'];
748                                                        }
749                                                }       
750
751                                                if (count($sortp))
752                                                {
753                                                        natcasesort($sortp);
754                                                }
755       
756                                                $contap = $contap + 1;
757                                        }
758       
759                                        while (list($key,$accountr1) = each($sortp))
760                                        {
761                                                $returnp[] = $tmpp[$key];
762                                        }
763       
764                                        $returnp = array_reverse($returnp);
765                                       
766                                        $ii = 0;
767                                       
768                                        while (list($null,$accountr) = each($returnp))
769                                        {
770                                                $this->nextmatchs->template_alternate_row_color($p);
771                                                $ii = $ii + 1;
772                                               
773                                                $varr = array(
774                                                        'formname'              => "formlog".$ii,
775                                                        'formsubmit'    => "document.formlog".$ii.".submit()",
776                                                        'row_idnumber'  => $accountr['account_id'],
777                                                        'row_loginid'   => $accountr['account_lid'],
778                                                        'row_cn'                => $accountr['account_cn'],
779                                                        'row_status'    => $accountr['account_status'] == 'active' ? '<font color="#0033FF">'.lang('Activated').'</font> ' : '<font color="#FF0000">'.lang('Disabled').'</font>',
780                                                        'row_mail'              => (!$accountr['account_mail']?'<font color=red>'.lang('Without E-mail').'</font>':$accountr['account_mail']),
781                                                        'row_timestamp'         => substr($accountr['createTimestamp'], 6, 2)."/".substr($accountr['createTimestamp'], 4, 2)."/".substr($accountr['createTimestamp'], 0, 4),
782                                                        'row_li_date'           => $accountr['li_date'] ==lang('Never login') ? '<font color="#FF0000">'.$accountr['li_date'].'</font>' : $accountr['li_date'],
783                                                        'row_li_dias'           => $accountr['li_dias']
784                                                );
785                                               
786                                                $p->set_var($varr);
787               
788                                                $p->parse('rows','row',True);
789                                        }
790                                        // ********************** Fim ****************************
791                                }
792                        }
793
794                        $p->pfp('out','body');
795                }
796
797                function get_user_info($userdn,$usercontexts,$usersizelimit)
798                {
799                        $user_info = $this->functions->Paginate_user('accounts',$setordn,$contexts,'cn','asc',$npag,$numpage);
800
801                        return $user_info;
802                }
803
804                function css()
805                {
806                        $appCSS =
807                        'th.activetab
808                        {
809                                color:#000000;
810                                background-color:#D3DCE3;
811                                border-top-width : 1px;
812                                border-top-style : solid;
813                                border-top-color : Black;
814                                border-left-width : 1px;
815                                border-left-style : solid;
816                                border-left-color : Black;
817                                border-right-width : 1px;
818                                border-right-style : solid;
819                                border-right-color : Black;
820                                font-size: 12px;
821                                font-family: Tahoma, Arial, Helvetica, sans-serif;
822                        }
823                       
824                        th.inactivetab
825                        {
826                                color:#000000;
827                                background-color:#E8F0F0;
828                                border-bottom-width : 1px;
829                                border-bottom-style : solid;
830                                border-bottom-color : Black;
831                                font-size: 12px;
832                                font-family: Tahoma, Arial, Helvetica, sans-serif;                             
833                        }
834                       
835                        .td_left {border-left:1px solid Gray; border-top:1px solid Gray; border-bottom:1px solid Gray;}
836                        .td_right {border-right:1px solid Gray; border-top:1px solid Gray; border-bottom:1px solid Gray;}
837                       
838                        div.activetab{ display:inline; }
839                        div.inactivetab{ display:none; }';
840                       
841                        return $appCSS;
842                }
843
844                function show_access()
845                {       
846                        $vnumacesso = trim($_POST['nacesso']);
847                        $account_id = $_POST['account_id'];
848                        $nome_usuario = $_POST['nome_usuario'];
849                        $grouplist = $_POST['setor'];
850                        $organizacao = $_POST['organizacao'];
851                        $setordn = $_POST['setordn'];
852                        $organizacaodn = $_POST['organizacaodn'];
853                        $x = $_POST['page'];
854                        $gpag = $_POST['gpage'];
855                        $sectornamedncompleto = $_POST['Psectornamedncompleto'];
856
857                        $manager_account_lid = $GLOBALS['phpgw']->accounts->data['account_lid'];
858                        $tmp = $this->functions->read_acl($manager_account_lid);
859                        $manager_context = $tmp[0]['context'];
860                       
861                        // Verifica se tem acesso a este modulo
862                        if ((!$this->functions->check_acl($manager_account_lid,'edit_users')) && (!$this->functions->check_acl($manager_account_lid,'change_users_password')))
863                        {
864                                $GLOBALS['phpgw']->redirect($GLOBALS['phpgw']->link('/reports/inc/access_denied.php'));
865                        }
866
867                        // Seta header.
868                        unset($GLOBALS['phpgw_info']['flags']['noheader']);
869                        unset($GLOBALS['phpgw_info']['flags']['nonavbar']);
870
871                        $GLOBALS['phpgw_info']['flags']['app_header'] = $GLOBALS['phpgw_info']['apps']['reports']['title'].' - '.lang('Access Log');
872                        $GLOBALS['phpgw']->common->phpgw_header();
873
874                        // Seta templates.
875                        $t = CreateObject('phpgwapi.Template',PHPGW_APP_TPL);
876                        $t->set_file(array("body" => "accesslog.tpl"));
877                        $t->set_block('body','main');
878                        $t->set_block('body','row','row');
879
880                        // GET access log from the user.
881                        $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__);
882                        while ($GLOBALS['phpgw']->db->next_record())
883                        {
884                                $records[] = array(
885                                        'loginid'       => $GLOBALS['phpgw']->db->f('loginid'),
886                                        'ip'            => $GLOBALS['phpgw']->db->f('ip'),
887                                        'li'            => $GLOBALS['phpgw']->db->f('li'),
888                                        'lo'            => $GLOBALS['phpgw']->db->f('lo'),
889                                        'account_id'    => $GLOBALS['phpgw']->db->f('account_id'),
890                                        'sessionid'     => $GLOBALS['phpgw']->db->f('sessionid')
891                                );
892                        }
893
894                        // Seta as vcariaveis
895                        while (is_array($records) && list(,$record) = each($records))
896                        {
897                                $var = array(
898                                        'row_loginid' => $record['loginid'],
899                                        'row_ip'      => $record['ip'],
900                                        'row_li'      => date("d/m/Y - H:i:s", $record['li']),
901                                        'row_lo'      => $record['lo'] == 0 ? 0 : date("d/m/Y - H:i:s", $record['lo'])
902                                );
903                                $t->set_var($var);
904                                $t->fp('rows','row',True);
905                        }
906
907                        $var = Array(
908                                'th_bg'                 => $GLOBALS['phpgw_info']['theme']['th_bg'],
909                                'nome_usuario'  => $nome_usuario,                               
910                                'back_url'              =>  "<form name='formlog' method='POST' action='./index.php?menuaction=reports.uireports_logon.report_logon_group_setor_print'>
911                                <input type='hidden' name='setor' value='$grouplist'>
912                                <input type='hidden' name='organizacao' value='$organizacao'>
913                                <input type='hidden' name='setordn' value='$setordn'>
914                                <input type='hidden' name='organizacaodn' value='$organizacaodn'>
915                                <input type='hidden' name='page' value='$x'>
916                                <input type='hidden' name='gpage' value='$gpag'>
917                                <input type='hidden' name='Psectornamedncompleto' value='$sectornamedncompleto'>
918                                <input type='hidden' name='nacesso' value='$vnumacesso'>
919                                <input name='button' type='submit' value='".lang('back')."'></div></form>"
920                        );
921
922                        $t->set_var($var);
923                        $t->set_var($this->functions->make_dinamic_lang($t, 'body'));
924                        $t->pfp('out','body');
925                }
926        }
927?>
Note: See TracBrowser for help on using the repository browser.