source: sandbox/2.3-MailArchiver/agileProjects/inc/class.functions.inc.php @ 6779

Revision 6779, 27.2 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2946 - Liberado Expresso(branch 2.3) integrado ao MailArchiver?.

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