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

Revision 63, 23.6 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

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