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

Revision 47, 23.1 KB checked in by niltonneto, 17 years ago (diff)

Scripts novos e outras atualizações.

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