source: companies/serpro/expressoAdminSerpro/inc/class.functions.inc.php @ 903

Revision 903, 27.2 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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        include_once('class.db_functions.inc.php');
13        include_once(PHPGW_API_INC.'/class.config.inc.php');
14
15        class functions
16        {
17                var $public_functions = array
18                (
19                        'make_array_acl'        => True,
20                        'check_acl'                     => True,
21                        'read_acl'                      => True,
22                        'exist_account_lid'     => True,
23                        'exist_email'           => True,
24                        'array_invert'          => True
25                );
26
27                var $nextmatchs;
28                var $sectors_list = array();
29                var $current_config;
30
31                function functions()
32                {
33                        $this->db_functions = new db_functions;
34                        $GLOBALS['phpgw']->db = $this->db_functions->db;
35
36                        //$c = CreateObject('phpgwapi.config','expressoAdminSerpro');
37                        $c = new config;
38                        $c->read_repository();
39                        $this->current_config = $c->config_data;
40                }
41
42                // Account and type of access. Return: Have access ? (true/false)
43                function check_acl($account_lid, $access)
44                {
45                        $acl = $this->read_acl($account_lid);
46                        $array_acl = $this->make_array_acl($acl['acl']);
47                        switch($access)
48                        {
49                                case list_users:
50                                        if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information] || $array_acl[acl_edit_users_phonenumber] )
51                                                return true;
52                                        break;
53                                case list_groups:
54                                        if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups])
55                                                return true;
56                                        break;
57                                case list_maillists:
58                                        if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists])
59                                                return true;
60                                        break;
61                                case list_sectors:
62                                        if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors])
63                                                return true;
64                                        break;
65                                case list_computers:
66                                        if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers])
67                                                return true;
68                                        break;
69
70                                case display_groups:
71                                        if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) )
72                                                return true;
73                                        break;
74                                case display_emailconfig:
75                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
76                                                return true;
77                                        break;
78                                case display_applications:
79                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
80                                                return true;
81                                        break;
82                                case display_emaillists:
83                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
84                                                return true;
85                                        break;
86                                case list_institutional_accounts:
87                                        if ($array_acl[acl_add_institutional_accounts] || $array_acl[acl_edit_institutional_accounts] || $array_acl[acl_delete_institutional_accounts])
88                                                return true;
89                                        break;
90                                default:
91                                        return $array_acl["acl_$access"];
92                        }
93                        return false;
94                }
95
96                /* OLD FUNCTION
97                function check_acl($account_lid, $access)
98                {
99                        $acl = $this->read_acl($account_lid);
100                        $array_acl = $this->make_array_acl($acl['acl']);
101
102                        //What access ?? In the IF, verify if have access.
103                        switch($access)
104                        {
105                                case list_users:
106                                        if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information])
107                                                return true;
108                                        break;
109                                case add_users:
110                                        if ($array_acl[acl_add_users])
111                                                return true;
112                                        break;
113                                case edit_users:
114                                        if ($array_acl[acl_edit_users])
115                                                return true;
116                                        break;
117                                case delete_users:
118                                        if ($array_acl[acl_delete_users])
119                                                return true;
120                                        break;
121                                case rename_users:
122                                        if ($array_acl[acl_rename_users])
123                                                return true;
124                                        break;
125                                case view_users:
126                                        if ($array_acl[acl_view_users])
127                                                return true;
128                                        break;
129                                case edit_users_picture:
130                                        if ($array_acl[acl_edit_users_picture])
131                                                return true;
132                                        break;
133                                case manipulate_corporative_information:
134                                        if ($array_acl[acl_manipulate_corporative_information])
135                                                return true;
136                                        break;
137                                case change_users_password:
138                                        if ($array_acl[acl_change_users_password])
139                                                return true;
140                                        break;
141                                case change_users_quote:
142                                        if ($array_acl[acl_change_users_quote])
143                                                return true;
144                                        break;
145                                case set_user_default_password:
146                                        if ($array_acl[acl_set_user_default_password])
147                                                return true;
148                                        break;
149                                case empty_user_inbox:
150                                        if (($array_acl[acl_empty_user_inbox]) && ($array_acl[acl_edit_users]))
151                                                return true;
152                                        break;
153                                case edit_sambausers_attributes:                                case list_maillists:
154                                        if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists])
155                                                return true;
156                                        break;
157
158                                        if ($array_acl[acl_edit_sambausers_attributes])
159                                                return true;
160                                        break;
161                                case edit_sambadomains:
162                                        if ($array_acl[acl_edit_sambadomains])
163                                                return true;
164                                        break;
165
166                                case list_groups:
167                                        if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups])
168                                                return true;
169                                        break;
170                                case add_groups:
171                                        if ($array_acl[acl_add_groups])
172                                                return true;
173                                        break;
174                                case edit_groups:
175                                        if ($array_acl[acl_edit_groups])
176                                                return true;
177                                        break;
178                                case delete_groups:
179                                        if ($array_acl[acl_delete_groups])
180                                                return true;
181                                        break;
182                                case edit_email_groups:
183                                        if ($array_acl[acl_edit_email_groups])
184                                                return true;
185                                        break;
186
187                                case list_maillists:
188                                        if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists])
189                                                return true;
190                                        break;
191                                case add_maillists:
192                                        if ($array_acl[acl_add_maillists])
193                                                return true;
194                                        break;
195                                case edit_maillists:
196                                        if ($array_acl[acl_edit_maillists])
197                                                return true;
198                                        break;
199                                case delete_maillists:
200                                        if ($array_acl[acl_delete_maillists])
201                                                return true;
202                                        break;
203
204                                case list_sectors:
205                                        if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors])
206                                                return true;
207                                        break;
208                                case create_sectors:
209                                        if ($array_acl[acl_create_sectors])
210                                                return true;
211                                        break;
212                                case edit_sectors:
213                                        if ($array_acl[acl_edit_sectors])
214                                                return true;
215                                        break;
216                                case delete_sectors:
217                                        if ($array_acl[acl_delete_sectors])
218                                                return true;
219                                        break;
220
221                                case view_global_sessions:
222                                        if ($array_acl[acl_view_global_sessions])
223                                                return true;
224                                        break;
225
226                                case list_computers:
227                                        if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers])
228                                                return true;
229                                        break;
230                                case create_computers:
231                                        if ($array_acl[acl_create_computers])
232                                                return true;
233                                        break;
234                                case edit_computers:
235                                        if ($array_acl[acl_edit_computers])
236                                                return true;
237                                        break;
238                                case delete_computers:
239                                        if ($array_acl[acl_delete_computers])
240                                                return true;
241                                        break;
242
243                                case view_logs:
244                                        if ($array_acl[acl_view_logs])
245                                                return true;
246                                        break;
247
248                                case display_groups:
249                                        if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) )
250                                                return true;
251                                        break;
252                                case display_emailconfig:
253                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
254                                                return true;
255                                        break;
256                                case display_applications:
257                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
258                                                return true;
259                                        break;
260                                case display_emaillists:
261                                        if ($array_acl[acl_edit_users] || $array_acl[acl_view_users])
262                                                return true;
263                                        break;
264
265                                default:
266                                        return $array_acl["acl_$access"];
267                        }
268                        return false;
269                }
270                */
271
272                // Read acl from db
273                function read_acl($account_lid)
274                {
275                        $acl = $this->db_functions->read_acl($account_lid);
276
277                        $result['acl'] = $acl[0]['acl'];
278                        $result['manager_lid'] = $acl[0]['manager_lid'];
279                        $result['raw_context'] = $acl[0]['context'];
280
281                        $all_contexts = split("%", $acl[0]['context']);
282                        foreach ($all_contexts as $index=>$context)
283                        {
284                                $result['contexts'][] = $context;
285                                $result['contexts_display'][] = str_replace(", ", ".", ldap_dn2ufn( $context ));
286                        }
287
288                        return $result;
289                }
290
291                // Make a array read humam
292                // Last acl:    2.147.483.648 -> edit users phonephone
293                // Last acl:    4.294.967.296 -> add institutional accounts
294                // Last acl:    8.589.934.592 -> edit institutional accounts
295                // Last acl:   17.179.869.184 -> remove institutional accounts
296                function make_array_acl($acl)
297                {
298                        $array_acl_tmp = array();
299                        $tmp = array(           "acl_add_users",
300                                                                "acl_edit_users",
301                                                                "acl_delete_users",
302                                                                "acl_EMPTY1",
303                                                                "acl_add_groups",
304                                                                "acl_edit_groups",
305                                                                "acl_delete_groups",
306                                                                "acl_change_users_password",
307                                                                "acl_add_maillists",
308                                                                "acl_edit_maillists",
309                                                                "acl_delete_maillists",
310                                                                "acl_EMPTY2",
311                                                                "acl_create_sectors",
312                                                                "acl_edit_sectors",
313                                                                "acl_delete_sectors",
314                                                                "acl_edit_sambausers_attributes",
315                                                                "acl_view_global_sessions",
316                                                                "acl_view_logs",
317                                                                "acl_change_users_quote",
318                                                                "acl_set_user_default_password",
319                                                                "acl_create_computers",
320                                                                "acl_edit_computers",
321                                                                "acl_delete_computers",
322                                                                "acl_rename_users",
323                                                                "acl_edit_sambadomains",
324                                                                "acl_view_users",
325                                                                "acl_edit_email_groups",
326                                                                "acl_empty_user_inbox",
327                                                                "acl_manipulate_corporative_information",
328                                                                "acl_edit_users_picture",
329                                                                "acl_edit_scl_email_lists",
330                                                                "acl_edit_users_phonenumber",
331                                                                "acl_add_institutional_accounts",
332                                                                "acl_edit_institutional_accounts",
333                                                                "acl_remove_institutional_accounts"
334                                                                );
335
336                        foreach ($tmp as $index => $right)
337                        {
338                                $bin = '';
339                                for ($i=0; $i<$index; $i++)
340                                {
341                                        $bin .= '0';
342                                }
343                                $bin = '1' . $bin;
344
345                                $array_acl[$right] = $this->safeBitCheck(bindec($bin), $acl);
346                        }
347                        return $array_acl;
348                }
349
350                function safeBitCheck($number,$comparison)
351                {
352                $binNumber = base_convert($number,10,2);
353                $binComparison = strrev(base_convert($comparison,10,2));
354                        $str = strlen($binNumber);
355
356                if ( ($str <= strlen($binComparison)) && ($binComparison{$str-1}==="1") )
357                        return '1';
358                else
359                        return '0';
360                }
361
362                function get_list($type, $query, $contexts)
363                {
364                        $dn             = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
365                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
366                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
367                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
368                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
369                        ldap_bind($ldap_conn,$dn,$passwd);
370
371                        if ($type == 'accounts')
372                        {
373                                $justthese = array("uidnumber", "uid", "cn", "mail","objectclass");
374                                //$filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)(mailAlternateAddress=$query*)))";
375                                $filter="(&(objectclass=".$GLOBALS['phpgw_info']['server']['atributousuarios'].")(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)))";
376
377                                $tmp = array();
378                                foreach ($contexts as $index=>$context)
379                                {
380                                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
381                                        $info = ldap_get_entries($ldap_conn, $search);
382
383                                        for ($i=0; $i < $info['count']; $i++)
384                                        {
385                                                $tmp[$info[$i]['uid'][0]]['account_id']  = $info[$i]['uidnumber'][0];
386                                                $tmp[$info[$i]['uid'][0]]['account_lid'] = $info[$i]['uid'][0];
387                                                $tmp[$info[$i]['uid'][0]]['account_cn']  = $info[$i]['cn'][0];
388                                                $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0];
389                                                $tmp[$info[$i]['uid'][0]]['new_account'] = true;
390                                                foreach ($info[$i]['objectclass'] as $objectclass)
391                                                        {
392                                                        if(strtolower($objectclass) == 'phpgwaccount' )
393                                                                {
394                                                                $tmp[$info[$i]['uid'][0]]['new_account'] = false;
395                                                                }
396                                                        }
397                                                $sort[] = $info[$i]['uid'][0];
398                                        }
399                                }
400                                ldap_close($ldap_conn);
401                                if (count($sort))
402                                {
403                                        natcasesort($sort);
404                                        foreach ($sort as $user_uid)
405                                                $return[$user_uid] = $tmp[$user_uid];
406                                }
407
408                                return $return;
409                        }
410                        elseif($type == 'groups')
411                        {
412                                $filter="(&(phpgwAccountType=g)(cn=*$query*))";
413                                $justthese = array("gidnumber", "cn", "description");
414
415                                $tmp = array();
416                                foreach ($contexts as $index=>$context)
417                                {
418                                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
419                                        $info = ldap_get_entries($ldap_conn, $search);
420                                        for ($i=0; $i < $info['count']; $i++)
421                                        {
422                                                $tmp[$info[$i]['cn'][0]]['cn']= $info[$i]['cn'][0];
423                                                $tmp[$info[$i]['cn'][0]]['description']= $info[$i]['description'][0];
424                                                $tmp[$info[$i]['cn'][0]]['gidnumber']= $info[$i]['gidnumber'][0];
425                                                $sort[] = $info[$i]['cn'][0];
426                                        }
427                                }
428                                ldap_close($ldap_conn);
429
430                                natcasesort($sort);
431                                foreach ($sort as $group_cn)
432                                        $return[$group_cn] = $tmp[$group_cn];
433
434                                return $return;
435                        }
436                        elseif($type == 'maillists')
437                        {
438                                $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))";
439                                $justthese = array("uidnumber", "cn", "uid", "mail");
440
441                                $tmp = array();
442                                foreach ($contexts as $index=>$context)
443                                {
444                                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
445                                        $info = ldap_get_entries($ldap_conn, $search);
446
447                                        for ($i=0; $i < $info['count']; $i++)
448                                        {
449                                                $tmp[$info[$i]['uid'][0]]['uid']                = $info[$i]['uid'][0];
450                                                $tmp[$info[$i]['uid'][0]]['name']               = $info[$i]['cn'][0];
451                                                $tmp[$info[$i]['uid'][0]]['uidnumber']  = $info[$i]['uidnumber'][0];
452                                                $tmp[$info[$i]['uid'][0]]['email']              = $info[$i]['mail'][0];
453                                                $sort[] = $info[$i]['uid'][0];
454                                        }
455                                }
456                                ldap_close($ldap_conn);
457
458                                natcasesort($sort);
459                                foreach ($sort as $maillist_uid)
460                                        $return[$maillist_uid] = $tmp[$maillist_uid];
461
462                                return $return;
463                        }
464                        elseif($type == 'computers')
465                        {
466                                $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W          ])(sambaAcctFlags=[DW         ])(sambaAcctFlags=[I          ])(sambaAcctFlags=[S          ]))(cn=*".$query."*))";
467                                $justthese = array("cn","uidNumber","description");
468
469                                $tmp = array();
470                                foreach ($contexts as $index=>$context)
471                                {
472                                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
473                                        $info = ldap_get_entries($ldap_conn, $search);
474                                        for ($i=0; $i < $info['count']; $i++)
475                                        {
476                                                $tmp[$info[$i]['cn'][0]]['cn']                  = $info[$i]['cn'][0];
477                                                $tmp[$info[$i]['cn'][0]]['uidNumber']   = $info[$i]['uidnumber'][0];
478                                                $tmp[$info[$i]['cn'][0]]['description'] = utf8_decode($info[$i]['description'][0]);
479                                                $sort[] = $info[$i]['cn'][0];
480                                        }
481
482                                }
483                                ldap_close($ldap_conn);
484
485                                natcasesort($sort);
486                                foreach ($sort as $computer_cn)
487                                        $return[$computer_cn] = $tmp[$computer_cn];
488
489                                return $return;
490                        }
491                }
492
493                //Funcao get_states() busca todos os Estados do banco de dados e monta
494                //a option box "UF" da aba "Informacoes Corporativas" das Contas de Usuarios
495                function get_states($state)
496                {
497
498                        $query = "SELECT id_state,state_name FROM phpgw_cc_state ORDER BY state_name";
499
500                        $GLOBALS['phpgw']->db->query($query);
501                        while($GLOBALS['phpgw']->db->next_record())
502                        {
503                                $availableStates[] = $GLOBALS['phpgw']->db->row();
504                        }
505
506//                      $selected = "";
507                        if(count($availableStates))
508                        {
509                                $option = '<option value="_NONE_">'.'Escolha o estado...'.'</option>';
510                                foreach($availableStates as $value)
511                                {
512                                        if($value['id_state'] == $state)
513                                        {
514                                                $option .= '<option selected="selected" value="'.$value['id_state'].'">'.$value['state_name'].'</option>';
515                                        } else{
516                                                $option .= '<option value="'.$value['id_state'].'">'.$value['state_name'].'</option>';
517                                        }
518                                }
519                        }
520
521
522                        return $option;
523                }
524
525                //Funcao get_cities() busca todas as Cidades do banco de dados e devolve
526                //o resultado para o javascript (funcao updateCities() em users.js)
527                //que monta a option box "Cidade" da aba "Informacoes Corporativas" das Contas de Usuarios
528                function get_cities($params)
529                {
530
531                        if($params['state_id'])
532                        {
533                                $st = $params['state_id'];
534                        } else{
535                                $st = $params['st'];
536                        }
537                        $query = "SELECT id_city,city_name FROM phpgw_cc_city WHERE id_state=$st ORDER BY city_name";
538
539                        $availableCities = array();
540
541                        $GLOBALS['phpgw']->db->query($query);
542                        while($GLOBALS['phpgw']->db->next_record())
543                        {
544                                $availableCities[] = $GLOBALS['phpgw']->db->row();
545                        }
546
547
548                        if($params['st'])
549                        {
550                                return $availableCities;
551
552                        } else{
553
554                                if(count($availableCities))
555                                {
556                                        foreach($availableCities as $value)
557                                        {
558                                                if($value['id_city'] == $params['city_id'])
559                                        {
560                                                        $option .= '<option selected="selected" value="'.$value['id_city'].'">'.$value['city_name'].'</option>';
561                                                } else{
562                                                        $option .= '<option value="'.$value['id_city'].'">'.$value['city_name'].'</option>';
563                                                }
564
565                                        }
566                                }
567
568                                return $option;
569                        }
570                }
571
572                function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true, $master=false)
573                {
574                        $s = CreateObject('phpgwapi.sector_search_ldap');
575                        $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master);
576                        return $sectors_info;
577                }
578
579                function get_sectors($selected='', $referral=false, $show_invisible_ou=true)
580                {
581                        $s = CreateObject('phpgwapi.sector_search_ldap');
582                        $sectors_info = $s->get_sectors($selected, $referral, $show_invisible_ou);
583                        return $sectors_info;
584                }
585
586                // Get list of all levels, this function is used for sectors module.
587                function get_sectors_list($contexts)
588                {
589                        $a_sectors = array();
590
591                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
592                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
593                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
594
595                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
596                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
597                        ldap_bind($ldap_conn,$dn,$passwd);
598
599                        $justthese = array("dn");
600                        $filter = "(&(|(objectclass=organizationalunit)(objectclass=domain))(!(objectclass=nsview)))";
601
602                        $systemName = strtolower($GLOBALS['phpgw_info']['server']['system_name']);
603                        if ($systemName != '')
604                                $filter = "(&$filter(phpgwSystem=$systemName))";
605
606
607
608                        foreach ($contexts as $context)
609                        {
610                                $search=ldap_search($ldap_conn, $context, $filter, $justthese);
611                                $info = ldap_get_entries($ldap_conn, $search);
612
613                        for ($i=0; $i<$info["count"]; $i++)
614                    {
615                        $a_sectors[] = $info[$i]['dn'];
616                    }
617                        }
618
619                        ldap_close($ldap_conn);
620
621                        // Retiro o count do array info e inverto o array para ordenaᅵᅵo.
622                        //print_r($a_sectors);
623                foreach ($a_sectors as $context)
624            {
625                                $array_dn = ldap_explode_dn ( $context, 1 );
626
627                $array_dn_reverse  = array_reverse ( $array_dn, true );
628
629                                // Retirar o indice count do array.
630                                array_pop ( $array_dn_reverse );
631
632                                $inverted_dn[$context] = implode ( "#", $array_dn_reverse );
633                        }
634
635                        // Ordenação
636                        natcasesort($inverted_dn);
637
638                        // Construção do select
639                        $level = 0;
640                        $options = array();
641                        foreach ($inverted_dn as $dn=>$invert_ufn)
642                        {
643                $display = '';
644
645                $array_dn_reverse = explode ( "#", $invert_ufn );
646                $array_dn  = array_reverse ( $array_dn_reverse, true );
647
648                $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1);
649
650                if ($level == 0)
651                        $display .= '+';
652                else
653                {
654                                        for ($i=0; $i<$level; $i++)
655                                                $display .= '---';
656                }
657
658                reset ( $array_dn );
659                $display .= ' ' . (current ( $array_dn ) );
660
661                                $dn = trim(strtolower($dn));
662                                $options[$dn] = $display;
663                }
664            return $options;
665                }
666
667                function exist_account_lid($account_lid)
668                {
669                        $conection = $GLOBALS['phpgw']->common->ldapConnect();
670                        $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid);
671                        $result = ldap_get_entries($conection, $sri);
672                        return $result['count'];
673                }
674
675                function exist_email($mail)
676                {
677                        $conection = $GLOBALS['phpgw']->common->ldapConnect();
678                        $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail);
679                        $result = ldap_get_entries($conection, $sri);
680                        ldap_close($conection);
681
682                        if ($result['count'] == 0)
683                                return false;
684                        else
685                                return true;
686                }
687
688                function array_invert($array)
689                {
690                        $result[] = end($array);
691                        while ($item = prev($array))
692                                $result[] = $item;
693                        return $result;
694                }
695
696                function get_next_id()
697                {
698                        // Busco o ID dos accounts
699                        $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'";
700                        $GLOBALS['phpgw']->db->query($query_accounts);
701                        while($GLOBALS['phpgw']->db->next_record())
702                        {
703                                $result_accounts[] = $GLOBALS['phpgw']->db->row();
704                        }
705                        $accounts_id = $result_accounts[0]['id'];
706
707                        // Busco o ID dos groups
708                        $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'";
709                        $GLOBALS['phpgw']->db->query($query_groups);
710                        while($GLOBALS['phpgw']->db->next_record())
711                        {
712                                $result_groups[] = $GLOBALS['phpgw']->db->row();
713                        }
714                        $groups_id = $result_groups[0]['id'];
715
716                        //Retorna o maior dos ID's
717                        if ($accounts_id >= $groups_id)
718                                return $accounts_id;
719                        else
720                                return $groups_id;
721                }
722
723                function make_list_app($account_lid, $user_applications='', $disabled='')
724                {
725                        // create list of ALL available apps
726                        $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps'];
727
728                        // create list of available apps for the user
729                        $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'";
730                        $GLOBALS['phpgw']->db->query($query);
731                        while($GLOBALS['phpgw']->db->next_record())
732                        {
733                                $availableApps[] = $GLOBALS['phpgw']->db->row();
734                        }
735
736                        // Retira alguns modulos
737                        if (count($availableApps))
738                        {
739                                foreach ($availableApps as $key => $value)
740                                {
741                                        if ($value['app'] != 'phpgwapi')
742                                                $tmp[] = $availableApps[$key];
743                                }
744                        }
745                        $availableApps = $tmp;
746
747                        // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes.
748                        $availableAppsUser = array();
749                        if (count($availableApps))
750                        {
751                                foreach($availableApps as $app => $title)
752                                {
753                                        if ($availableAppsGLOBALS[$title['app']])
754                                                $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']];
755                                }
756                        }
757                        // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box.
758                        $applications_list = '';
759                        $app_col1 = '';
760                        $app_col2 = '';
761                        $app_col3 = '';
762                        $total_apps = count($availableAppsUser);
763                        $i = 0;
764                        foreach($availableAppsUser as $app => $data)
765                        {
766                                // 1 coluna
767                                if (($i +1) % 3 == 1)
768                                {
769                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
770                                        $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
771                                        $data['title'],$app,$checked, $disabled);
772                                        if ($i == ($total_apps-1))
773                                                $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1);
774                                }
775
776                                // 2 coluna
777                                if (($i +1) % 3 == 2)
778                                {
779                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
780                                        $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
781                                        $data['title'],$app,$checked, $disabled);
782
783                                        if ($i == ($total_apps-1))
784                                                $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2);
785                                }
786                                // 3 coluna
787                                if (($i +1) % 3 == 0)
788                                {
789                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
790                                        $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
791                                        $data['title'],$app,$checked, $disabled);
792
793                                        // Cria nova linha
794                                        $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3);
795                                }
796                                $i++;
797                        }
798                        return $applications_list;
799                }
800
801                function exist_attribute_in_ldap($dn, $attribute, $value)
802                {
803                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
804                        $search = ldap_search($connection, $dn, $attribute. "=" . $value);
805                        $result = ldap_get_entries($connection, $search);
806                        ldap_close($connection);
807                        //_debug_array($result);
808                        if ($result['count'] == 0)
809                                return false;
810                        else
811                                return true;
812                }
813
814                function getReturnExecuteForm(){
815                        $response = $_SESSION['response'];
816                        $_SESSION['response'] = null;
817                        return $response;
818                }
819
820                function write_log2($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='')
821                {
822                        $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) "
823                        . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')";
824                        $GLOBALS['phpgw']->db->query($sql);
825                        return;
826                }
827
828                function lang($key)
829                {
830                        if ($_SESSION['phpgw_info']['expressoAdmin']['lang'][$key])
831                                return $_SESSION['phpgw_info']['expressoAdmin']['lang'][$key];
832                        else
833                                return $key . '*';
834                }
835
836                function getNextLayer($params)
837                {
838                        $dn     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
839                        $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
840                        $connection     = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
841                        ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
842                        ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
843                        ldap_bind($connection,$dn,$passwd);
844                        if (!$connection)
845                                {
846                                $return['status'] = 'false';
847                                $return['msg'] = 'Falha na conexão ldap';
848                                }
849                                else
850                                {
851                                $filter = "(&(!(objectclass=nsview))(|(objectclass=organizationalunit)(objectclass=domain)))";
852                                $search = ldap_list($connection, $params["ldap_relative_path"],$filter,array("dn","domain","ou"));
853                                $entries = ldap_get_entries($connection, $search);
854                                ldap_close($connection);
855                                foreach ($entries as $index=>$attrib)
856                                        {
857                                        if($attrib['dn'])
858                                                {
859                                                $path = explode (',',$attrib['dn']);
860                                                $sector = explode ('=',$path[0]);
861                                                $result[]=strtoupper($sector[1]).";".$attrib['dn'];
862                                                }
863                                        }
864                                if (count($result) == 0)
865                                        {
866                                        $return['status'] = 'false';
867                                        $return['msg'] = 'Setor não encontrado.';
868                                        }
869                                else
870                                        $return['status'] = 'true';
871                                $return['result'] = $result;
872                                return $return;
873                                }
874                }
875
876        }
877
878        class sectors_object
879        {
880                var $sector_name;
881                var $sector_context;
882                var $sector_level;
883                var $sector_leaf;
884                var $sectors_list = array();
885                var $level;
886
887                function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf)
888                {
889                        $this->sector_name = $sector_name;
890                        $this->sector_context = $sector_context;
891                        $this->sector_level = $sector_level;
892                        $this->sector_leaf = $sector_leaf;
893                }
894        }
Note: See TracBrowser for help on using the repository browser.