source: sandbox/2.3-MailArchiver/admin/inc/class.sovoip.inc.php @ 6779

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

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

Line 
1<?php
2
3 /**************************************************************************\
4  * Expresso Livre - Voip - administration                                   *
5  *                                                                                                                                      *
6  * --------------------------------------------                             *
7  *  This program is free software; you can redistribute it and/or modify it *
8  *  under the terms of the GNU General Public License as published by the   *
9  *  Free Software Foundation; either version 2 of the License, or (at your  *
10  *  option) any later version.                                              *
11  \**************************************************************************/
12
13define('PHPGW_INCLUDE_ROOT', '../');
14define('PHPGW_API_INC','../phpgwapi/inc');
15require_once( PHPGW_API_INC . '/class.common.inc.php' );
16
17class sovoip
18{
19        private $db;
20        private $common;
21        private $ldap;
22        private $ldap_host;
23        private $ldap_root_dn;
24        private $ldap_root_pw;
25        private $ldap_context;
26
27        final function __construct()
28        {
29                $this->ldap_host         = $_SESSION['admin']['server']['ldap_host'];
30                $this->ldap_root_dn      = $_SESSION['admin']['server']['ldap_root_dn'];
31                $this->ldap_root_pw  = $_SESSION['admin']['server']['ldap_root_pw'];
32                $this->ldap_context  = $_SESSION['admin']['server']['ldap_context'];
33                $this->common = new common();
34        }
35
36        final function __destruct()
37        {
38                if( $this->ldap )
39                        ldap_close($this->ldap);
40        }
41
42        public final function getOuLdap()
43        {
44                $this->ldap = $this->common->ldapConnect();
45               
46                if ( $this->ldap )     
47                {
48                        $filter = "objectClass=organizationalUnit";
49                        $justthese = array("ou");
50                        $search = ldap_list($this->ldap, $this->ldap_context, $filter, $justthese);
51                        $entry = ldap_get_entries($this->ldap, $search);
52                }
53
54                //$result_ou[] = "";
55
56                if( $entry['count'] > 0 )
57                {
58                        foreach($entry as $tmp)
59                                if( $tmp['ou'][0] != "" )
60                                        $result_ou[] = $tmp['ou'][0];
61                }else{
62                    $result_ou[] = $this->ldap_context;
63                }
64               
65                natcasesort($result_ou);
66
67                return (($result_ou) ? $result_ou : '');
68        }       
69
70        public final function getGroupsLdap($pOrg)
71        {
72                if($pOrg['ou'] == $this->ldap_context)
73                    $organization = $this->ldap_context;
74                else
75                    $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context;
76               
77                $this->ldap = $this->common->ldapConnect($this->ldap_host,$this->ldap_root_dn,$this->ldap_root_pw);
78               
79                if( $this->ldap )       
80                {
81                        $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))";
82                        $justthese = array("cn","gidNumber");
83                        $search = ldap_search($this->ldap, $organization, $filter, $justthese);
84                        $entry = ldap_get_entries( $this->ldap, $search );
85
86                        if( $entry )
87                        {                                       
88                                $idx = 0;
89                                foreach($entry as $tmp) {
90                                        if( $tmp['gidnumber'][0] != "" ){
91                                                $result_groups[$idx]['gid'] = $tmp['gidnumber'][0];
92                                                $result_groups[$idx++]['cn'] = $tmp['cn'][0];                                           
93                                        }
94                                }
95                        }
96                       
97                        natcasesort($result_groups);
98                }
99               
100                return (($result_groups) ? $result_groups : '');
101        }
102
103        public final function setConfDB($pConf)
104        {
105                $this->db = $GLOBALS['phpgw']->db;
106                if( $this->db )
107                {
108                        foreach($pConf as $key => $tmp )
109                        {
110                                $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='".trim($key)."'";
111                               
112                                $this->db->query($query);
113                                       
114                                if(!$this->db->next_record())
115                                {
116                                        $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','".trim($key)."','".$tmp."')";
117                                        $this->db->query($query);
118                                }
119                                else
120                                {
121                                        $query = "UPDATE phpgw_config SET config_value = '".$tmp."' WHERE config_app = 'phpgwapi' AND config_name = '".trim($key)."'";
122                                        $this->db->query($query);
123                                }
124                        }
125                }       
126        }
127
128        public final function getConfDB()
129        {
130                $this->db = $GLOBALS['phpgw']->db;
131
132                if( $this->db )
133                {
134                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'voip_groups'";
135                       
136                        if(!$this->db->query($query))
137                                return null;
138                       
139                        while($this->db->next_record())
140                                $result[] = $this->db->row();           
141                }
142
143                return (($result) ? $result : '');             
144        }
145}
146?>
Note: See TracBrowser for help on using the repository browser.