source: contrib/listAdmin/inc/class.functions.inc.php @ 3312

Revision 3312, 25.4 KB checked in by rafaelraymundo, 14 years ago (diff)

Ticket #1174 - Disponibilização do módulo de Listas(Mailman)

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