source: companies/celepar/admin/inc/class.sovoip.inc.php @ 763

Revision 763, 3.7 KB checked in by niltonneto, 15 years ago (diff)

Importação inicial do Expresso da Celepar

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 = "ou=*";
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                if( $entry )
55                {
56                        foreach($entry as $tmp)
57                                if( $tmp['ou'][0] != "" )
58                                        $result_ou[] = $tmp['ou'][0];
59                }
60               
61                natcasesort($result_ou);
62
63                return (($result_ou) ? $result_ou : '');
64        }       
65
66        public final function getGroupsLdap($pOrg)
67        {
68                $organization = 'ou=' . $pOrg['ou'] .",". $this->ldap_context;
69               
70                $this->ldap = $this->common->ldapConnect($this->ldap_host,$this->ldap_root_dn,$this->ldap_root_pw);
71               
72                if( $this->ldap )       
73                {
74                        $filter = "(&(phpgwAccountType=g)(objectClass=posixGroup))";
75                        $justthese = array("cn","gidNumber");
76                        $search = ldap_list($this->ldap, $organization, $filter, $justthese);
77                        $entry = ldap_get_entries( $this->ldap, $search );
78
79                        if( $entry )
80                        {                                       
81                                $idx = 0;
82                                foreach($entry as $tmp) {
83                                        if( $tmp['gidnumber'][0] != "" ){
84                                                $result_groups[$idx]['gid'] = $tmp['gidnumber'][0];
85                                                $result_groups[$idx++]['cn'] = $tmp['cn'][0];                                           
86                                        }
87                                }
88                        }
89                       
90                        natcasesort($result_groups);
91                }
92               
93                return (($result_groups) ? $result_groups : '');
94        }
95
96        public final function setConfDB($pConf)
97        {
98                $this->db = $GLOBALS['phpgw']->db;
99                if( $this->db )
100                {
101                        foreach($pConf as $key => $tmp )
102                        {
103                                $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='".trim($key)."'";
104                               
105                                $this->db->query($query);
106                                       
107                                if(!$this->db->next_record())
108                                {
109                                        $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','".trim($key)."','".$tmp."')";
110                                        $this->db->query($query);
111                                }
112                                else
113                                {
114                                        $query = "UPDATE phpgw_config SET config_value = '".$tmp."' WHERE config_app = 'phpgwapi' AND config_name = '".trim($key)."'";
115                                        $this->db->query($query);
116                                }
117                        }
118                }       
119        }
120
121        public final function getConfDB()
122        {
123                $this->db = $GLOBALS['phpgw']->db;
124
125                if( $this->db )
126                {
127                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'voip_groups'";
128                       
129                        if(!$this->db->query($query))
130                                return null;
131                       
132                        while($this->db->next_record())
133                                $result[] = $this->db->row();           
134                }
135
136                return (($result) ? $result : '');             
137        }
138}
139?>
Note: See TracBrowser for help on using the repository browser.