1 | <?php |
---|
2 | /***************************************************************************\ |
---|
3 | * Expresso - Expresso Messenger * |
---|
4 | * - Alexandre Correia / Rodrigo Souza * |
---|
5 | * - JETI - http://jeti-im.org/ * |
---|
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 | |
---|
13 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
14 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
15 | require_once(PHPGW_API_INC . '/class.db.inc.php'); |
---|
16 | |
---|
17 | class db_im |
---|
18 | { |
---|
19 | private $db; |
---|
20 | private $db_name; |
---|
21 | private $db_host; |
---|
22 | private $db_port; |
---|
23 | private $db_user; |
---|
24 | private $db_pass; |
---|
25 | private $db_type; |
---|
26 | private $user_id; |
---|
27 | |
---|
28 | public final function __construct() |
---|
29 | { |
---|
30 | $this->db_name = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_name']; |
---|
31 | $this->db_host = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_host']; |
---|
32 | $this->db_port = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_port']; |
---|
33 | $this->db_user = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_user']; |
---|
34 | $this->db_pass = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_pass']; |
---|
35 | $this->db_type = $_SESSION['phpgw_info']['jabberit_messenger']['server']['db_type']; |
---|
36 | $this->user_id = $_SESSION['phpgw_info']['jabberit_messenger']['user_id']; |
---|
37 | $this->connectDB(); |
---|
38 | } |
---|
39 | |
---|
40 | private final function connectDB() |
---|
41 | { |
---|
42 | $this->db = new db(); |
---|
43 | $this->db_name = ( !$this->db_name ) ? $_SESSION['phpgwinfo']['db_name'] : $this->db_name; |
---|
44 | $this->db_host = ( !$this->db_host ) ? $_SESSION['phpgwinfo']['db_host'] : $this->db_host; |
---|
45 | $this->db_port = ( !$this->db_port ) ? $_SESSION['phpgwinfo']['db_port'] : $this->db_port; |
---|
46 | $this->db_user = ( !$this->db_user ) ? $_SESSION['phpgwinfo']['db_user'] : $this->db_user; |
---|
47 | $this->db_pass = ( !$this->db_pass ) ? $_SESSION['phpgwinfo']['db_pass'] : $this->db_pass; |
---|
48 | $this->db_type = ( !$this->db_type ) ? $_SESSION['phpgwinfo']['db_type'] : $this->db_type; |
---|
49 | |
---|
50 | $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); |
---|
51 | } |
---|
52 | |
---|
53 | public final function getApplicationsEnabled() |
---|
54 | { |
---|
55 | |
---|
56 | $this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"); |
---|
57 | if($this->db->num_rows()) |
---|
58 | { |
---|
59 | $tmp = ""; |
---|
60 | while($this->db->next_record()) |
---|
61 | { |
---|
62 | $tmp[]= $this->db->row(); |
---|
63 | } |
---|
64 | return $tmp[0]['config_value']; |
---|
65 | } |
---|
66 | return false; |
---|
67 | } |
---|
68 | |
---|
69 | public final function getApplicationsList() |
---|
70 | { |
---|
71 | $this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name"); |
---|
72 | if($this->db->num_rows()) |
---|
73 | { |
---|
74 | while ($this->db->next_record()) |
---|
75 | { |
---|
76 | $app = $this->db->f('app_name'); |
---|
77 | $title = @$GLOBALS['phpgw_info']['apps'][$app]['title']; |
---|
78 | if (empty($title)) |
---|
79 | { |
---|
80 | $title = lang($app) == $app.'*' ? $app : lang($app); |
---|
81 | } |
---|
82 | $apps[$app] = array( |
---|
83 | 'title' => $title, |
---|
84 | 'name' => $app, |
---|
85 | 'status' => $this->db->f('app_enabled') |
---|
86 | ); |
---|
87 | } |
---|
88 | } |
---|
89 | return $apps; |
---|
90 | } |
---|
91 | |
---|
92 | public final function get_accounts_acl() |
---|
93 | { |
---|
94 | $query = "select acl_account from phpgw_acl where acl_location in (select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger') "; |
---|
95 | $query .= "union select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger'"; |
---|
96 | |
---|
97 | if( $this->db->query($query) ) |
---|
98 | { |
---|
99 | $users = array(); |
---|
100 | $new_users = array(); |
---|
101 | while($this->db->next_record()) |
---|
102 | $users[] = $this->db->row(); |
---|
103 | |
---|
104 | if(is_array($users)) |
---|
105 | foreach($users as $tmp) |
---|
106 | $new_users[] = $tmp['acl_account']; |
---|
107 | |
---|
108 | return $new_users; |
---|
109 | } |
---|
110 | |
---|
111 | return false; |
---|
112 | } |
---|
113 | |
---|
114 | public final function getPreferences() |
---|
115 | { |
---|
116 | $result = array(); |
---|
117 | $query = "select * from phpgw_preferences where preference_owner = '".$this->user_id."' and preference_app = 'jabberit_messenger'"; |
---|
118 | |
---|
119 | if ( $this->db->query($query) ) |
---|
120 | { |
---|
121 | while($this->db->next_record()) |
---|
122 | $result[] = $this->db->row(); |
---|
123 | |
---|
124 | if(count($result) > 0) |
---|
125 | return unserialize($result[0]['preference_value']); |
---|
126 | } |
---|
127 | |
---|
128 | return "openWindowJabberit:true"; |
---|
129 | } |
---|
130 | |
---|
131 | public final function setPreferences($pParam) |
---|
132 | { |
---|
133 | $preferences = $pParam['preferences']; |
---|
134 | $user_id = $this->user_id; |
---|
135 | |
---|
136 | $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')"; |
---|
137 | |
---|
138 | if($this->db->query($query)) |
---|
139 | { |
---|
140 | return "true"; |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'"; |
---|
145 | |
---|
146 | if($this->db->query($query)) |
---|
147 | return "true"; |
---|
148 | else |
---|
149 | return "false"; |
---|
150 | } |
---|
151 | } |
---|
152 | |
---|
153 | public final function setApplications($pApplications) |
---|
154 | { |
---|
155 | $apps = serialize($pApplications); |
---|
156 | |
---|
157 | if( $this->db ) |
---|
158 | { |
---|
159 | $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'"; |
---|
160 | |
---|
161 | $this->db->query($query); |
---|
162 | |
---|
163 | if(!$this->db->next_record()) |
---|
164 | { |
---|
165 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')"; |
---|
166 | $this->db->query($query); |
---|
167 | return true; |
---|
168 | } |
---|
169 | else |
---|
170 | { |
---|
171 | $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'"; |
---|
172 | $this->db->query($query); |
---|
173 | return true; |
---|
174 | } |
---|
175 | } |
---|
176 | return false; |
---|
177 | } |
---|
178 | |
---|
179 | public final function setAttributesLdap($pAttributes) |
---|
180 | { |
---|
181 | $values = $pAttributes['conf']; |
---|
182 | $attributesOrg = ""; |
---|
183 | |
---|
184 | if( $this->db ) |
---|
185 | { |
---|
186 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
187 | |
---|
188 | if ( $this->db->query($query) ) |
---|
189 | { |
---|
190 | while($this->db->next_record()) |
---|
191 | $result[] = $this->db->row(); |
---|
192 | |
---|
193 | if(count($result) > 0) |
---|
194 | $attributesOrg = $result[0]['config_value']; |
---|
195 | } |
---|
196 | |
---|
197 | if( trim($attributesOrg) == "" ) |
---|
198 | { |
---|
199 | $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')"; |
---|
200 | $this->db->query($query); |
---|
201 | |
---|
202 | $attr = explode(";", $values); |
---|
203 | $values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>"; |
---|
204 | return $values; |
---|
205 | } |
---|
206 | else |
---|
207 | { |
---|
208 | $org = explode(",", $attributesOrg); |
---|
209 | $newValue = explode(";", $values); |
---|
210 | |
---|
211 | foreach( $org as $tmp ) |
---|
212 | { |
---|
213 | $attr = explode(";",$tmp); |
---|
214 | if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) ) |
---|
215 | return false; |
---|
216 | } |
---|
217 | |
---|
218 | $values = $values . "," . $attributesOrg; |
---|
219 | $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
220 | $this->db->query($query); |
---|
221 | |
---|
222 | $return = explode(",",$values); |
---|
223 | natcasesort($return); |
---|
224 | |
---|
225 | $values = "<return>"; |
---|
226 | |
---|
227 | foreach($return as $tmp) |
---|
228 | { |
---|
229 | $attr = explode(";", $tmp); |
---|
230 | $values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>"; |
---|
231 | } |
---|
232 | |
---|
233 | $values .= "</return>"; |
---|
234 | |
---|
235 | return $values; |
---|
236 | } |
---|
237 | } |
---|
238 | return false; |
---|
239 | } |
---|
240 | |
---|
241 | public final function removeAttributesLdap($pOrg) |
---|
242 | { |
---|
243 | $organization = $pOrg['org']; |
---|
244 | |
---|
245 | if( $this->db ) |
---|
246 | { |
---|
247 | $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'"; |
---|
248 | |
---|
249 | if ( $this->db->query($query) ) |
---|
250 | { |
---|
251 | while( $this->db->next_record() ) |
---|
252 | $result[] = $this->db->row(); |
---|
253 | |
---|
254 | if( count($result) > 0 ) |
---|
255 | $attributesOrg = $result[0]['config_value']; |
---|
256 | } |
---|
257 | |
---|
258 | $attributesOrg = explode(",", $attributesOrg); |
---|
259 | $newValue = ""; |
---|
260 | foreach($attributesOrg as $tmp) |
---|
261 | { |
---|
262 | $attr = explode(";",$tmp); |
---|
263 | |
---|
264 | if( strtolower(trim($attr[0])) != strtolower(trim($organization))) |
---|
265 | { |
---|
266 | $newValue .= $attr[0] . ";" . $attr[1] . ","; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | $newValue = substr($newValue, 0,(strlen($newValue) -1 )); |
---|
271 | |
---|
272 | if( trim($newValue) != "") |
---|
273 | $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'"; |
---|
274 | else |
---|
275 | $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'"; |
---|
276 | |
---|
277 | if( $this->db->query($query)) |
---|
278 | return true; |
---|
279 | else |
---|
280 | return false; |
---|
281 | } |
---|
282 | return false; |
---|
283 | } |
---|
284 | } |
---|
285 | ?> |
---|