source: trunk/jabberit_messenger/inc/class.db_im.inc.php @ 563

Revision 563, 12.9 KB checked in by niltonneto, 15 years ago (diff)

Correções referentes ao release 0.7.10

  • Property svn:executable set to *
Line 
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
13define('PHPGW_INCLUDE_ROOT','../');     
14define('PHPGW_API_INC','../phpgwapi/inc');
15require_once(PHPGW_API_INC . '/class.db.inc.php');
16       
17class 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;userOfflineJabberit:true";
129        }
130
131        public final function setPreferences($pParam)
132        {
133                $preferences = $preferences1 = $pParam['preferences1'];
134               
135                if(isset($pParam['preferences2']))
136                {
137                        $preferences2 = $pParam['preferences2'];
138                        $preferences .= ";". $preferences2;
139                }
140               
141                $user_id  = $this->user_id;
142               
143                $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')";
144                               
145                if($this->db->query($query))
146                {
147                        return "true";
148                }
149                else
150                {
151                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'";
152
153                        if($this->db->query($query))
154                                return "true";
155                        else
156                                return "false";                 
157                }               
158        }
159       
160        public final function setApplications($pApplications)
161        {
162                $apps = serialize($pApplications);
163               
164                if( $this->db )
165                {
166                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'";
167                               
168                        $this->db->query($query);
169                                       
170                        if(!$this->db->next_record())
171                        {
172                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')";
173                                $this->db->query($query);
174                                return true;
175                        }
176                        else
177                        {
178                                $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'";
179                                $this->db->query($query);
180                                return true;
181                        }
182                }
183                return false;   
184        }
185       
186        public final function setAttributesLdap($pAttributes)
187        {
188                $values = $pAttributes['conf'];
189                $attributesOrg = "";           
190
191                if( $this->db )
192                {
193                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
194
195                        if ( $this->db->query($query) )
196                        {       
197                                while($this->db->next_record())
198                                        $result[] = $this->db->row();
199               
200                                if(count($result) > 0)
201                                        $attributesOrg = $result[0]['config_value'];
202                        }
203
204                        if( trim($attributesOrg) == "" )
205                        {
206                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')";
207                                $this->db->query($query);
208                               
209                                $attr = explode(";", $values);
210                                $values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>";
211                                return $values;
212                        }
213                        else
214                        {
215                                $org = explode(",", $attributesOrg);
216                                $newValue = explode(";", $values);
217                               
218                                foreach( $org as $tmp )
219                                {
220                                        $attr = explode(";",$tmp);
221                                        if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) )
222                                                return false;
223                                }
224
225                                $values = $values . "," . $attributesOrg;
226                                $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
227                                $this->db->query($query);
228
229                                $return = explode(",",$values);
230                                natcasesort($return);
231
232                                $values = "<return>";
233                               
234                                foreach($return as $tmp)
235                                {
236                                        $attr = explode(";", $tmp);
237                                        $values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>";
238                                }
239                                       
240                                $values .= "</return>";
241                               
242                                return $values;                         
243                        }
244                }
245                return false;
246        }
247
248        public final function setGroupsLocked($pGroups)
249        {
250                $groups = "";
251               
252                if( is_array($pGroups) )
253                {
254                        foreach($pGroups as $tmp)               
255                                if(trim($tmp) != "")
256                                        $groups .= $tmp . ";";
257               
258                        $groups = substr($groups, 0, strlen($groups) - 1 );             
259                }
260               
261                if( $this->db )
262                {
263                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";       
264                       
265                        if($this->db->query($query))
266                        {
267
268                                if ( $this->db->query($query) )
269                                {       
270                                        while($this->db->next_record())
271                                                $result[] = $this->db->row();
272                                }
273
274                                if( count($result) == 0 )
275                                {
276                                        $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');";
277                                        $this->db->query($query);
278                                        return true;
279                                }
280                                else
281                                {
282                                        $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
283                                        $this->db->query($query);
284                                        return true;
285                                }
286                        }
287                }
288               
289                return false;
290        }
291       
292        public final function setUseParticipantsExternal($pFlag)
293        {
294                $flag = $pFlag['value'];
295                $return = "";
296               
297                if( $this->db )
298                {
299                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit';";
300
301                        if ( $this->db->query($query) )
302                        {       
303                                while($this->db->next_record())
304                                        $result[] = $this->db->row();
305                        }
306
307                        if(count($result) == 0)
308                        {
309                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','use_external_participants_jabberit','".$flag."')";
310                                $this->db->query($query);
311                                return true;
312                        }
313                        else
314                        {
315                                $query = "UPDATE phpgw_config SET config_value = '".$flag."' WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit'";
316                                $this->db->query($query);
317                                return true;
318                        }
319                }
320                return false;
321        }
322       
323        public final function setOrganization($pOrganization)
324        {
325                $organization = $pOrganization['organization'];
326                $orgConfiguration = "";
327               
328                if( $this->db )
329                {
330                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
331
332                        if ( $this->db->query($query) )
333                        {       
334                                while($this->db->next_record())
335                                        $result[] = $this->db->row();
336               
337                                if(count($result) > 0)
338                                        $orgConfiguration = $result[0]['config_value'];
339                        }
340
341                        if( trim($orgConfiguration) == "" )
342                        {
343                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','conf_organization_jabberit','".$organization."')";
344                                $this->db->query($query);
345                               
346                                return "<return><ou attr='".$organization."'>".$organization."</ou></return>";
347                        }
348                        else
349                        {
350                                $orgAux = explode(",",$orgConfiguration);
351                               
352                                foreach( $orgAux as $tmp )
353                                {
354                                        if(strtolower(trim($tmp)) === strtolower(trim($organization)))
355                                                return false;
356                                }
357
358                                $value = $orgConfiguration . "," . $organization;
359                                $query = "UPDATE phpgw_config SET config_value = '".$value."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
360                                $this->db->query($query);
361
362                                $return = explode(",",$value);
363                                natcasesort($return);
364
365                                $values = "<return>";
366                               
367                                foreach($return as $tmp)
368                                        $values .= "<ou attr='" . $tmp . "'>" . $tmp . "</ou>";
369                                       
370                                $values .= "</return>";
371                               
372                                return $values;                 
373                        }
374                }
375                return false;
376        }
377       
378        public final function removeAttributesLdap($pOrg)
379        {
380                $organization = $pOrg['org'];
381               
382                if( $this->db )
383                {
384                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
385                               
386                        if ( $this->db->query($query) )
387                        {       
388                                while( $this->db->next_record() )
389                                        $result[] = $this->db->row();
390               
391                                if( count($result) > 0 )
392                                        $attributesOrg = $result[0]['config_value'];
393                        }
394
395                        $attributesOrg = explode(",", $attributesOrg);
396                        $newValue = "";
397                        foreach($attributesOrg as $tmp)
398                        {
399                                $attr = explode(";",$tmp);
400                                 
401                                if( strtolower(trim($attr[0])) != strtolower(trim($organization)))
402                                {
403                                        $newValue .= $attr[0] . ";" . $attr[1] . ",";
404                                }
405                        }
406                       
407                        $newValue = substr($newValue, 0,(strlen($newValue) -1 ));
408                       
409                        if( trim($newValue) != "")
410                                $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
411                        else
412                                $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'";
413                               
414                        if( $this->db->query($query))
415                                return true;
416                        else
417                                return false;
418                }
419                return false;   
420        }
421       
422        public final function removeParticipantsExternal($pOrganization)
423        {
424               
425                $organization = $pOrganization['participants'];
426               
427                if( $this->db )
428                {
429                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
430                               
431                        if ( $this->db->query($query) )
432                        {       
433                                while( $this->db->next_record() )
434                                        $result[] = $this->db->row();
435               
436                                if( count($result) > 0 )
437                                        $valueDB = $result[0]['config_value'];
438                        }
439
440                        $OrgDB = explode(",", $valueDB);
441                        $newValue = "";
442
443                        foreach($OrgDB as $tmp)
444                        {
445                                if( strtolower(trim($tmp)) != strtolower(trim($organization)))
446                                        $newValue .= $tmp . ",";
447                        }
448                       
449                        $newValue = substr($newValue, 0,(strlen($newValue) -1 ));
450                       
451                        if( trim($newValue) != "")
452                                $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
453                        else
454                                $query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'";
455                               
456                        if( $this->db->query($query))
457                                return true;
458                        else
459                                return false;
460                }
461                return false;   
462        }
463}
464?>
Note: See TracBrowser for help on using the repository browser.