source: companies/serpro/expressoAdmin1_2/inc/class.functions.inc.php @ 903

Revision 903, 25.3 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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 = $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                                $filter="(&(phpgwAccountType=l)(admlista=$admlista)(|(cn=*".$query."*)(uid=*".$query."*)))";
325                                $justthese = array("uidnumber", "cn", "uid", "mail");
326                                $search=ldap_search($ldap_conn, $context, $filter, $justthese);
327                                ldap_sort($ldap_conn, $search, "uid");
328                                $info = ldap_get_entries($ldap_conn, $search);
329                                ldap_close($ldap_conn);
330                               
331                                $i = 0;
332                                $tmp = array();
333                                for ($i=0; $i < $info['count']; $i++)
334                                {
335                                        $tmp[$i]['uid']                 = $info[$i]['uid'][0];
336                                        $tmp[$i]['name']                = $info[$i]['cn'][0];
337                                        $tmp[$i]['uidnumber']           = $info[$i]['uidnumber'][0];
338                                        $tmp[$i]['email']               = $info[$i]['mail'][0];
339                                }
340                                return $tmp;
341                        }
342                        elseif($type == 'computers')
343                        {
344                                $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W          ])(sambaAcctFlags=[DW         ])(sambaAcctFlags=[I          ])(sambaAcctFlags=[S          ]))(cn=*".$query."*))";
345                                $justthese = array("cn","uidNumber","description");
346                                $search=ldap_search($ldap_conn, $context, $filter, $justthese);
347                                ldap_sort($ldap_conn, $search, "cn");
348                                $info = ldap_get_entries($ldap_conn, $search);
349                                ldap_close($ldap_conn);
350                                $tmp = array();
351                                for ($i=0; $i < $info['count']; $i++)
352                                {
353                                        $tmp[$i]['cn']                  = $info[$i]['cn'][0];
354                                        $tmp[$i]['uidNumber']           = $info[$i]['uidnumber'][0];
355                                        $tmp[$i]['description']         = utf8_decode($info[$i]['description'][0]);
356                                }
357                                return $tmp;
358                        }
359                }
360               
361                //Criado nova funᅵᅵo bem mais eficiente!
362                /*
363                function get_organizations($context, $selected='')
364                {
365                        //echo $selected;
366                       
367                        $first_sector_ufn = ldap_dn2ufn($context);
368                        $first_sector_string = split(",", $first_sector_ufn);
369                       
370                        $s = CreateObject('phpgwapi.sector_search_ldap');
371                        $sectors_info = $s->sector_search($context);
372                       
373                        $sector_select = "";
374                        $sector_select .= "<option value='" .$context . "'";
375                        $sector_select .= ">".strtoupper($first_sector_string[0])."</option>\n";
376                       
377                        foreach($sectors_info as $sector)
378                        {
379                                if ($sector->sector_level == 1)
380                                {
381                                        $sector->sector_name = '+ '.$sector->sector_name;
382                                }
383                                else
384                                {
385                                        $sector_space = '';
386                                        for ($i=1; $i < $sector->sector_level; $i++)
387                                                $sector_space = '---'.$sector_space;
388                                        $sector->sector_name = $sector_space.' '.$sector->sector_name;
389                                }
390                                $sector_select .= '<option value="' . strtolower($sector->sector_context) . '"';
391                               
392                                if (trim(strtolower($sector->sector_context)) == $selected)
393                                        $sector_select .= ' selected>' . $sector->sector_name . "</option>\n";
394                                else
395                                        $sector_select .= '>' . $sector->sector_name . "</option>\n";
396                        }
397                        //$sector_select .= "</select>";
398                        return $sector_select; 
399                }
400                */
401               
402                /*
403                function get_organizations($context, $selected='', $show_invisible_ou=false)
404                {
405                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
406                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
407                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
408                       
409                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
410                        ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
411                        ldap_bind($ldap_conn,$dn,$passwd);
412                       
413                        $justthese = array("dn");
414                        $filter = $show_invisible_ou ? "(ou=*)" : "(& (ou=*) (!(phpgwAccountVisible=-1)) )";
415                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
416               
417                ldap_sort($ldap_conn, $search, "ou");
418                $info = ldap_get_entries($ldap_conn, $search);
419                        ldap_close($ldap_conn);
420
421                        // Retiro o count do array info e inverto o array para ordenaᅵᅵo.
422                for ($i=0; $i<$info["count"]; $i++)
423            {
424                                $dn = $info[$i]["dn"];
425                               
426                                // Necessï¿œrio, pq em uma busca com ldapsearch ou=*, traz tb o prï¿œprio ou.
427                                if (strtolower($dn) == $context)
428                                        continue;
429
430                                $array_dn = ldap_explode_dn ( $dn, 1 );
431
432                $array_dn_reverse  = array_reverse ( $array_dn, true );
433
434                                array_pop ( $array_dn_reverse );
435
436                                $inverted_dn[$dn] = implode ( ".", $array_dn_reverse );
437                        }
438
439                        // Ordenaᅵᅵo
440                        natcasesort($inverted_dn);
441                       
442                        // Construᅵᅵo do select
443                        $level = 0;
444                        foreach ($inverted_dn as $dn=>$invert_ufn)
445                        {
446                $display = '';
447
448                $array_dn_reverse = explode ( ".", $invert_ufn );
449                $array_dn  = array_reverse ( $array_dn_reverse, true );
450
451                $level = count( $array_dn ) - 4;
452
453                if ($level == 0)
454                        $display .= '+';
455                else {
456                        for ($i=0; $i<$level; $i++)
457                                $display .= '---';
458                }
459
460                reset ( $array_dn );
461                $display .= ' ' . (current ( $array_dn ) );
462                               
463                                $dn = trim(strtolower($dn));
464                                if ( $dn == $selected )
465                                        $select = ' selected';
466                                else
467                                        $select = '';
468                $options .= "<option value='$dn'$select>$display</option>";
469                }
470
471                        // Cria a primeira entrada na combo
472                        $first_sector_ufn = ldap_dn2ufn($context);
473                        $first_sector_string = split(",", $first_sector_ufn);
474                        $options = "<option value='$context'>" . strtoupper($first_sector_string[0]) . "</option>" . $options;
475
476            return $options;
477                }
478                */
479               
480                function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true)
481                {
482                        $s = CreateObject('phpgwapi.sector_search_ldap');
483                        $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou);
484                        return $sectors_info;
485                }               
486               
487                function get_sectors($selected='', $referral=false, $show_invisible_ou=true)
488                {
489                        $s = CreateObject('phpgwapi.sector_search_ldap');
490                        $sectors_info = $s->get_sectors($selected, $referral, $show_invisible_ou);
491                        return $sectors_info;
492                }               
493 
494                /*
495                function get_sectors($context, $selected='')
496                {
497                        $query = "SELECT sector FROM phpgw_expressoadmin_sectors WHERE organization = '" . $context . "'";
498                        $GLOBALS['phpgw']->db->query($query);
499                        while($GLOBALS['phpgw']->db->next_record())
500                        {
501                                $query_result[] = $GLOBALS['phpgw']->db->row();
502                        }
503                       
504                        if (count($query_result) > 0)
505                        {
506                                foreach ($query_result as $index=>$tmp)
507                                {
508                                        $sector = $tmp['sector'];
509                                        if ($sector == $selected)
510                                                $sector_options .= "<option value='$sector' selected>$sector</option>";
511                                        else
512                                                $sector_options .= "<option value='$sector'>$sector</option>";
513                                }
514                                return $sector_options;
515                        }
516                        else
517                                return false;
518                }
519                */
520               
521                // Get list of all levels, this function is used for sectors module.
522                /*
523                function get_sectors_list($context)
524                {
525                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
526                        ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3);
527                        ldap_set_option($connection, LDAP_OPT_REFERRALS, 0);
528       
529                        if ($connection)
530                        {                               
531                                $bind=ldap_bind($connection);
532                                $filter="ou=*";
533                                $justthese = array("ou");
534                                $search=ldap_list($connection, $context, $filter, $justthese);
535                                ldap_sort($connection, $search, "ou");
536                                $info = ldap_get_entries($connection, $search);
537                                for ($i=0; $i<$info["count"]; $i++)
538                                {
539                                        $this->level++;
540                                        $next_context[$i] = 'ou='.$info[$i]["ou"][0].','.$context;
541                                        $obj = new sectors_object($info[$i]["ou"][0], $next_context[$i], $this->level, 'False');
542                                        array_push($this->sectors_list, $obj);
543                                        $this->get_sectors_list($next_context[$i]);
544                                }
545                        }
546                        ldap_close($connection);
547                        $this->level--;
548                        return $this->sectors_list;
549                }
550                */
551               
552                // Get list of all levels, this function is used for sectors module.
553                function get_sectors_list($context, $selected='', $referral=false ,$show_invisible_ou=false)
554                {
555                        $dn                     = $GLOBALS['phpgw_info']['server']['ldap_root_dn'];
556                        $passwd         = $GLOBALS['phpgw_info']['server']['ldap_root_pw'];
557                        $ldap_conn      = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']);
558                       
559                        ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3);
560                       
561                        if ($referral)
562                                ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1);
563                        else
564                                ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0);
565                       
566                        ldap_bind($ldap_conn,$dn,$passwd);
567                       
568                        $justthese = array("dn");
569                        $filter = "(ou=*)";
570                        $search=ldap_search($ldap_conn, $context, $filter, $justthese);
571               
572                ldap_sort($ldap_conn, $search, "ou");
573                $info = ldap_get_entries($ldap_conn, $search);
574                        ldap_close($ldap_conn);
575
576                        // Retiro o count do array info e inverto o array para ordenaᅵᅵo.
577                for ($i=0; $i<$info["count"]; $i++)
578            {
579                                $dn = $info[$i]["dn"];
580                               
581                                // Necessï¿œrio, pq em uma busca com ldapsearch ou=*, traz tb o prï¿œprio ou.
582                                if (strtolower($dn) == $context)
583                                        continue;
584
585                                $array_dn = ldap_explode_dn ( $dn, 1 );
586
587                $array_dn_reverse  = array_reverse ( $array_dn, true );
588
589                                // Retirar o indice count do array.
590                                array_pop ( $array_dn_reverse );
591
592                                $inverted_dn[$dn] = implode ( "#", $array_dn_reverse );
593                        }
594
595                        // Ordenaᅵᅵo
596                        natcasesort($inverted_dn);
597                       
598                        // Construᅵᅵo do select
599                        $level = 0;
600                        $options = array();
601                        foreach ($inverted_dn as $dn=>$invert_ufn)
602                        {
603                $display = '';
604
605                $array_dn_reverse = explode ( "#", $invert_ufn );
606                $array_dn  = array_reverse ( $array_dn_reverse, true );
607
608                $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1);
609
610                if ($level == 0)
611                        $display .= '+';
612                else
613                {
614                                        for ($i=0; $i<$level; $i++)
615                                                $display .= '---';
616                }
617
618                reset ( $array_dn );
619                $display .= ' ' . (current ( $array_dn ) );
620                               
621                                $dn = trim(strtolower($dn));
622                                $options[$dn] = $display;
623                }
624            return $options;
625                }
626               
627                function exist_account_lid($account_lid)
628                {
629                        $conection = $GLOBALS['phpgw']->common->ldapConnect();
630                        $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid);
631                        $result = ldap_get_entries($conection, $sri);
632                        return $result['count'];
633                }
634               
635                function exist_email($mail)
636                {
637                        $conection = $GLOBALS['phpgw']->common->ldapConnect();
638                        $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail);
639                        $result = ldap_get_entries($conection, $sri);
640                        ldap_close($conection);
641                       
642                        if ($result['count'] == 0)
643                                return false;
644                        else
645                                return true;
646                }
647               
648                function array_invert($array)
649                {
650                        $result[] = end($array);
651                        while ($item = prev($array))
652                                $result[] = $item;
653                        return $result;
654                }
655               
656                function get_next_id()
657                {
658                        // Busco o ID dos accounts
659                        $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'";
660                        $GLOBALS['phpgw']->db->query($query_accounts);
661                        while($GLOBALS['phpgw']->db->next_record())
662                        {
663                                $result_accounts[] = $GLOBALS['phpgw']->db->row();
664                        }                       
665                        $accounts_id = $result_accounts[0]['id'];
666                       
667                        // Busco o ID dos groups
668                        $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'";
669                        $GLOBALS['phpgw']->db->query($query_groups);
670                        while($GLOBALS['phpgw']->db->next_record())
671                        {
672                                $result_groups[] = $GLOBALS['phpgw']->db->row();
673                        }                       
674                        $groups_id = $result_groups[0]['id'];
675                       
676                        //Retorna o maior dos ID's
677                        if ($accounts_id >= $groups_id)
678                                return $accounts_id;
679                        else
680                                return $groups_id;
681                }
682               
683                function increment_id($id, $type)
684                {
685                        $sql = "UPDATE phpgw_nextid set id = '".$id."' WHERE appname = '" . $type . "'";
686                        $GLOBALS['phpgw']->db->query($sql);
687                }
688               
689                function make_list_app($account_lid, $context, $user_applications, $disabled='')
690                {
691                        // create list of ALL available apps
692                        $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps'];
693                       
694                        // create list of available apps for the user
695                        $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."' AND context = '".$context."'";
696                        $GLOBALS['phpgw']->db->query($query);
697                        while($GLOBALS['phpgw']->db->next_record())
698                        {
699                                $availableApps[] = $GLOBALS['phpgw']->db->row();
700                        }
701                       
702                        // Retira alguns modulos
703                        if (count($availableApps))
704                        {
705                                foreach ($availableApps as $key => $value)
706                                {
707                                        if ($value['app'] != 'phpgwapi')
708                                                $tmp[] = $availableApps[$key];
709                                }
710                        }
711                        $availableApps = $tmp;
712                       
713                        // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes.
714                        $availableAppsUser = array();
715                        if (count($availableApps))
716                        {
717                                foreach($availableApps as $app => $title)
718                                {
719                                        if ($availableAppsGLOBALS[$title['app']])
720                                                $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']];
721                                }
722                        }
723                       
724                        // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box.
725                        $applications_list = '';
726                        $app_col1 = '';
727                        $app_col2 = '';
728                        $app_col3 = '';
729                        $total_apps = count($availableAppsUser);
730                        $i = 0;
731                        foreach($availableAppsUser as $app => $data)
732                        {
733                                // 1 coluna
734                                if (($i +1) % 3 == 1)
735                                {
736                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
737                                        $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
738                                        $data['title'],$app,$checked, $disabled);
739                                        if ($i == ($total_apps-1))
740                                                $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1);
741                                }
742                               
743                                // 2 coluna
744                                if (($i +1) % 3 == 2)
745                                {
746                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
747                                        $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
748                                        $data['title'],$app,$checked, $disabled);
749                                       
750                                        if ($i == ($total_apps-1))
751                                                $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2);
752                                }
753                                // 3 coluna
754                                if (($i +1) % 3 == 0)
755                                {
756                                        $checked = $user_applications[$app] ? 'CHECKED' : '';
757                                        $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n",
758                                        $data['title'],$app,$checked, $disabled);
759                                       
760                                        // Cria nova linha
761                                        $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3);                                       
762                                }
763                                $i++;
764                        }
765                        return $applications_list;
766                }
767               
768                function exist_attribute_in_ldap($dn, $attribute, $value)
769                {
770                        $connection = $GLOBALS['phpgw']->common->ldapConnect();
771                        $search = ldap_search($connection, $dn, $attribute. "=" . $value);
772                        $result = ldap_get_entries($connection, $search);
773                        ldap_close($connection);
774                        //_debug_array($result);
775                        if ($result['count'] == 0)
776                                return false;
777                        else
778                                return true;   
779                }
780               
781                function getReturnExecuteForm(){
782                        $response = $_SESSION['response'];
783                        $_SESSION['response'] = null;
784                        return $response;
785                }
786
787                function write_log2($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='')
788                {
789                        $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) "
790                        . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')";
791                        $GLOBALS['phpgw']->db->query($sql);
792                        return;
793                }
794               
795        }
796       
797        class sectors_object
798        {
799                var $sector_name;
800                var $sector_context;
801                var $sector_level;
802                var $sector_leaf;
803                var $sectors_list = array();
804                var $level;
805               
806                function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf)
807                {
808                        $this->sector_name = $sector_name;
809                        $this->sector_context = $sector_context;
810                        $this->sector_level = $sector_level;
811                        $this->sector_leaf = $sector_leaf;
812                }
813        }
Note: See TracBrowser for help on using the repository browser.