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

Revision 283, 23.9 KB checked in by wmerlotto, 16 years ago (diff)

Internacionalizacao do ExpressoAdmin

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