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

Revision 414, 25.1 KB checked in by niltonneto, 16 years ago (diff)

Alterações feitas por João Alfredo.
Email: jakjr@…

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2        /**********************************************************************************\
3        * Expresso Administração                                                                                              *
4        * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br) *
5        * --------------------------------------------------------------------------------*
6        *  This program is free software; you can redistribute it and/or modify it                *
7        *  under the terms of the GNU General Public License as published by the                  *
8        *  Free Software Foundation; either version 2 of the License, or (at your                 *
9        *  option) any later version.                                                                                                     *
10        \**********************************************************************************/
11       
12        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','expressoAdmin1_2');
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                       
48                        switch($access)
49                        {
50                                case list_users:
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] )
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
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
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                       
106                        //What access ?? In the IF, verify if have access.
107                        switch($access)
108                        {
109                                case list_users:
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])
111                                                return true;
112                                        break;
113                                case add_users:
114                                        if ($array_acl[acl_add_users])
115                                                return true;
116                                        break;
117                                case edit_users:
118                                        if ($array_acl[acl_edit_users])
119                                                return true;
120                                        break;
121                                case delete_users:
122                                        if ($array_acl[acl_delete_users])
123                                                return true;
124                                        break;
125                                case rename_users:
126                                        if ($array_acl[acl_rename_users])
127                                                return true;
128                                        break;
129                                case view_users:
130                                        if ($array_acl[acl_view_users])
131                                                return true;
132                                        break;
133                                case edit_users_picture:
134                                        if ($array_acl[acl_edit_users_picture])
135                                                return true;
136                                        break;
137                                case manipulate_corporative_information:
138                                        if ($array_acl[acl_manipulate_corporative_information])
139                                                return true;
140                                        break;
141                                case change_users_password:
142                                        if ($array_acl[acl_change_users_password])
143                                                return true;
144                                        break;
145                                case change_users_quote:
146                                        if ($array_acl[acl_change_users_quote])
147                                                return true;
148                                        break;
149                                case set_user_default_password:
150                                        if ($array_acl[acl_set_user_default_password])
151                                                return true;
152                                        break;
153                                case empty_user_inbox:
154                                        if (($array_acl[acl_empty_user_inbox]) && ($array_acl[acl_edit_users]))
155                                                return true;
156                                        break;
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
162                                        if ($array_acl[acl_edit_sambausers_attributes])
163                                                return true;
164                                        break;
165                                case edit_sambadomains:
166                                        if ($array_acl[acl_edit_sambadomains])
167                                                return true;
168                                        break;
169                               
170                                case list_groups:
171                                        if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups])
172                                                return true;
173                                        break;
174                                case add_groups:
175                                        if ($array_acl[acl_add_groups])
176                                                return true;
177                                        break;
178                                case edit_groups:
179                                        if ($array_acl[acl_edit_groups])
180                                                return true;
181                                        break;
182                                case delete_groups:
183                                        if ($array_acl[acl_delete_groups])
184                                                return true;
185                                        break;
186                                case edit_email_groups:
187                                        if ($array_acl[acl_edit_email_groups])
188                                                return true;
189                                        break;
190                               
191                                case list_maillists:
192                                        if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists])
193                                                return true;
194                                        break;
195                                case add_maillists:
196                                        if ($array_acl[acl_add_maillists])
197                                                return true;
198                                        break;
199                                case edit_maillists:
200                                        if ($array_acl[acl_edit_maillists])
201                                                return true;
202                                        break;
203                                case delete_maillists:
204                                        if ($array_acl[acl_delete_maillists])
205                                                return true;
206                                        break;
207
208                                case list_sectors:
209                                        if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors])
210                                                return true;
211                                        break;
212                                case create_sectors:
213                                        if ($array_acl[acl_create_sectors])
214                                                return true;
215                                        break;
216                                case edit_sectors:
217                                        if ($array_acl[acl_edit_sectors])
218                                                return true;
219                                        break;
220                                case delete_sectors:
221                                        if ($array_acl[acl_delete_sectors])
222                                                return true;
223                                        break;
224
225                                case view_global_sessions:
226                                        if ($array_acl[acl_view_global_sessions])
227                                                return true;
228                                        break;
229
230                                case list_computers:
231                                        if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers])
232                                                return true;
233                                        break;
234                                case create_computers:
235                                        if ($array_acl[acl_create_computers])
236                                                return true;
237                                        break;
238                                case edit_computers:
239                                        if ($array_acl[acl_edit_computers])
240                                                return true;
241                                        break;
242                                case delete_computers:
243                                        if ($array_acl[acl_delete_computers])
244                                                return true;
245                                        break;
246
247                                case view_logs:
248                                        if ($array_acl[acl_view_logs])
249                                                return true;
250                                        break;
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;
268
269                                default:
270                                        return $array_acl["acl_$access"];
271                        }
272                        return false;
273                }
274                */
275               
276                // Read acl from db
277                function read_acl($account_lid)
278                {
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                       
292                        return $result;
293                }
294               
295                // Make a array read humam
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
300                function make_array_acl($acl)
301                {
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",
332                                                                "acl_edit_users_picture",
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"
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                               
349                                $array_acl[$right] = $this->safeBitCheck(bindec($bin), $acl);
350                        }
351                        return $array_acl;
352                }
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                }
365               
366                function get_list($type, $query, $contexts)
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");
378                                $filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)(mailAlternateAddress=$query*)))";
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                                }
395                                ldap_close($ldap_conn);
396                               
397                                if (count($sort))
398                                {
399                                        natcasesort($sort);
400                                        foreach ($sort as $user_uid)
401                                                $return[$user_uid] = $tmp[$user_uid];
402                                }
403                               
404                                return $return;
405                        }
406                        elseif($type == 'groups')
407                        {
408                                $filter="(&(phpgwAccountType=g)(cn=*$query*))";
409                                $justthese = array("gidnumber", "cn", "description");
410                               
411                                $tmp = array();
412                                foreach ($contexts as $index=>$context)
413                                {
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                                        }
423                                }
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;
431                        }
432                        elseif($type == 'maillists')
433                        {
434                                $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))";
435                                $justthese = array("uidnumber", "cn", "uid", "mail");
436
437                                $tmp = array();
438                                foreach ($contexts as $index=>$context)
439                                {
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                                        }
451                                }
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;
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");
464
465                                $tmp = array();
466                                foreach ($contexts as $index=>$context)
467                                {
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
478                                }
479                                ldap_close($ldap_conn);
480                               
481                                if (!empty($sort))
482                                {
483                                        natcasesort($sort);
484                                        foreach ($sort as $computer_cn)
485                                                $return[$computer_cn] = $tmp[$computer_cn];
486                                }
487                               
488                                return $return;
489                        }
490                }
491               
492                function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true, $master=false)
493                {
494                        $s = CreateObject('phpgwapi.sector_search_ldap');
495                        $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master);
496                        return $sectors_info;
497                }               
498                               
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 
506                // Get list of all levels, this function is used for sectors module.
507                function get_sectors_list($contexts)
508                {
509                        $a_sectors = array();
510                       
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);
516                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
517                        ldap_bind($ldap_conn,$dn,$passwd);
518                       
519                        $justthese = array("dn");
520                        $filter = "(ou=*)";
521                       
522                        $systemName = strtolower($GLOBALS['phpgw_info']['server']['system_name']);
523                        if ($systemName != '')
524                                $filter = "(&$filter(phpgwSystem=$systemName))";
525                       
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                        }
535               
536                        ldap_close($ldap_conn);
537
538                        // Retiro o count do array info e inverto o array para ordenação.
539                foreach ($a_sectors as $context)
540            {
541                                $array_dn = ldap_explode_dn ( $context, 1 );
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
548                                $inverted_dn[$context] = implode ( "#", $array_dn_reverse );
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               
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               
639                function make_list_app($account_lid, $user_applications='', $disabled='')
640                {
641                        // create list of ALL available apps
642                        $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps'];
643                       
644                        // create list of available apps for the user
645                        $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'";
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 lang($key)
738                {
739                        if ($_SESSION['phpgw_info']['expressoAdmin']['lang'][$key])
740                                return $_SESSION['phpgw_info']['expressoAdmin']['lang'][$key];
741                        else
742                                return $key . '*';
743                }
744               
745               
746                function checkCPF($cpf)
747                {
748                        $nulos = array("12345678909","11111111111","22222222222","33333333333",
749                               "44444444444","55555555555","66666666666","77777777777",
750                           "88888888888","99999999999","00000000000");
751
752                        /* formato do CPF */
753                        if (!(ereg("^[0-9]{3}[.][0-9]{3}[.][0-9]{3}[-][0-9]{2}$",$cpf)))
754                                return false;
755
756                        /* Retira todos os caracteres que nao sejam 0-9 */
757                        $cpf = ereg_replace("[^0-9]", "", $cpf);
758
759                        /*Retorna falso se houver letras no cpf */
760                        if (!(ereg("[0-9]",$cpf)))
761                        return false;
762
763                        /* Retorna falso se o cpf for nulo */
764                        if( in_array($cpf, $nulos) )
765                        return false;
766
767                        /*Calcula o penúltimo dígito verificador*/
768                        $acum=0;
769                        for($i=0; $i<9; $i++)
770                        {
771                                $acum+= $cpf[$i]*(10-$i);
772                        }
773
774                        $x=$acum % 11;
775                        $acum = ($x>1) ? (11 - $x) : 0;
776                        /* Retorna falso se o digito calculado eh diferente do passado na string */
777                        if ($acum != $cpf[9]){
778                                return false;
779                        }
780                        /*Calcula o último dígito verificador*/
781                        $acum=0;
782                        for ($i=0; $i<10; $i++)
783                        {
784                                $acum+= $cpf[$i]*(11-$i);
785                        }
786
787                        $x=$acum % 11;
788                        $acum = ($x > 1) ? (11-$x) : 0;
789                        /* Retorna falso se o digito calculado eh diferente do passado na string */
790                        if ( $acum != $cpf[10])
791                        {
792                                return false;
793                        }
794                        /* Retorna verdadeiro se o cpf eh valido */
795                        return true;
796                }
797               
798                function make_lang($ram_lang)
799                {
800                        $a_lang = split("_", $ram_lang);
801                        $a_lang_reverse  = array_reverse ( $a_lang, true );
802                        array_pop ( $a_lang_reverse );
803                        $a_lang  = array_reverse ( $a_lang_reverse, true );
804                        $a_new_lang = implode ( " ", $a_lang );
805                        return lang($a_new_lang);
806                }
807
808                function make_dinamic_lang($template_obj, $block)
809                {
810                        $tpl_vars = $template_obj->get_undefined($block);
811                        $array_langs = array();
812                       
813                        foreach ($tpl_vars as $atribute)
814                        {
815                                $lang = strstr($atribute, 'lang_');
816                                if($lang !== false)
817                                {
818                                        //$template_obj->set_var($atribute, $this->make_lang($atribute));
819                                        $array_langs[$atribute] = $this->make_lang($atribute);
820                                }
821                        }
822                        return $array_langs;
823                }
824        }
825       
826        class sectors_object
827        {
828                var $sector_name;
829                var $sector_context;
830                var $sector_level;
831                var $sector_leaf;
832                var $sectors_list = array();
833                var $level;
834               
835                function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf)
836                {
837                        $this->sector_name = $sector_name;
838                        $this->sector_context = $sector_context;
839                        $this->sector_level = $sector_level;
840                        $this->sector_leaf = $sector_leaf;
841                }
842        }       
Note: See TracBrowser for help on using the repository browser.