source: trunk/expressoAdmin1_2/inc/class.functions.inc.php @ 396

Revision 396, 24.9 KB checked in by niltonneto, 16 years ago (diff)

Modificações referente a opção de configurar um ldap_master
no setup do Expresso, usado somente para escrita.

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