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

Revision 697, 16.6 KB checked in by niltonneto, 15 years ago (diff)

Fechamento das ocorrências referentes à versão 0.7.11

  • 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 getGroupsBlocked()
115        {
116                $return = "";
117               
118                if( $this->db )
119                {
120                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";       
121                       
122                        if($this->db->query($query))
123                        {
124
125                                if ( $this->db->query($query) )
126                                {       
127                                        while($this->db->next_record())
128                                                $result[] = $this->db->row();
129                                }
130                               
131                                if( count($result) > 0 )
132                                        $return = $result[0]['config_value'];
133                        }
134                }
135               
136                return $return;
137        }
138       
139        public final function getPreferences()
140        {
141                $result = array();
142                $query = "select * from phpgw_preferences where preference_owner = '".$this->user_id."' and preference_app = 'jabberit_messenger'";
143               
144                if ( $this->db->query($query) )
145                {       
146                        while($this->db->next_record())
147                                $result[] = $this->db->row();
148       
149                        if(count($result) > 0)
150                                return unserialize($result[0]['preference_value']);
151                }
152
153                return "openWindowJabberit:true;openWindowJabberitPopUp:false;flagAwayIM:5";
154                //return "openWindowJabberit:true;openWindowJabberitPopUp:false";               
155        }
156
157        public final function setPreferences($pParam)
158        {
159                $preferences = $pParam['preferences1'];
160               
161                if(isset($pParam['preferences2']))
162                        $preferences .= ";". $pParam['preferences2'];
163               
164                if(isset($pParam['preferences3']))
165                        $preferences .= ";". $pParam['preferences3'];
166               
167                $user_id  = $this->user_id;
168               
169                $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')";
170                               
171                if($this->db->query($query))
172                {
173                        return "true";
174                }
175                else
176                {
177                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'";
178
179                        if($this->db->query($query))
180                                return "true";
181                        else
182                                return "false";                 
183                }               
184        }
185       
186        public final function setApplications($pApplications)
187        {
188                $apps = serialize($pApplications);
189               
190                if( $this->db )
191                {
192                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'";
193                               
194                        $this->db->query($query);
195                                       
196                        if(!$this->db->next_record())
197                        {
198                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')";
199                                $this->db->query($query);
200                                return true;
201                        }
202                        else
203                        {
204                                $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'";
205                                $this->db->query($query);
206                                return true;
207                        }
208                }
209                return false;   
210        }
211       
212        public final function setAttributesLdap($pAttributes)
213        {
214                $values = $pAttributes['conf'];
215                $attributesOrg = "";           
216
217                if( $this->db )
218                {
219                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
220
221                        if ( $this->db->query($query) )
222                        {       
223                                while($this->db->next_record())
224                                        $result[] = $this->db->row();
225               
226                                if(count($result) > 0)
227                                        $attributesOrg = $result[0]['config_value'];
228                        }
229
230                        if( trim($attributesOrg) == "" )
231                        {
232                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','attributes_org_ldap_jabberit','".$values."')";
233                                $this->db->query($query);
234                               
235                                $attr = explode(";", $values);
236                                $values = "<return><ou attr='".$attr[1]."'>".$attr[0]."</ou></return>";
237                                return $values;
238                        }
239                        else
240                        {
241                                $org = explode(",", $attributesOrg);
242                                $newValue = explode(";", $values);
243                               
244                                foreach( $org as $tmp )
245                                {
246                                        $attr = explode(";",$tmp);
247                                        if( strtolower(trim($attr[0])) == strtolower(trim($newValue[0])) )
248                                                return false;
249                                }
250
251                                $values = $values . "," . $attributesOrg;
252                                $query = "UPDATE phpgw_config SET config_value = '".$values."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
253                                $this->db->query($query);
254
255                                $return = explode(",",$values);
256                                natcasesort($return);
257
258                                $values = "<return>";
259                               
260                                foreach($return as $tmp)
261                                {
262                                        $attr = explode(";", $tmp);
263                                        $values .= "<ou attr='" . $attr[1] . "'>" . $attr[0] . "</ou>";
264                                }
265                                       
266                                $values .= "</return>";
267                               
268                                return $values;                         
269                        }
270                }
271                return false;
272        }
273
274        public final function setGroupsLocked($pGroups)
275        {
276                $groups = "";
277               
278                if( is_array($pGroups) )
279                {
280                        foreach($pGroups as $tmp)               
281                                if(trim($tmp) != "")
282                                        $groups .= $tmp . ";";
283               
284                        $groups = substr($groups, 0, strlen($groups) - 1 );             
285                }
286               
287                if( $this->db )
288                {
289                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";       
290                       
291                        if($this->db->query($query))
292                        {
293
294                                if ( $this->db->query($query) )
295                                {       
296                                        while($this->db->next_record())
297                                                $result[] = $this->db->row();
298                                }
299
300                                if( count($result) == 0 )
301                                {
302                                        $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','groups_locked_jabberit','".$groups."');";
303                                        $this->db->query($query);
304                                        return true;
305                                }
306                                else
307                                {
308                                        $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
309                                        $this->db->query($query);
310                                        return true;
311                                }
312                        }
313                }
314               
315                return false;
316        }
317       
318        public final function setOuGroupsLocked($pGroup)
319        {
320                $group = $pGroup['group'];
321                $gidnumber = $pGroup['gidnumber'];
322                $organization = strtoupper($pGroup['ou']);
323
324                if( $this->db )
325                {
326                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";       
327                       
328                        if($this->db->query($query))
329                        {
330
331                                if ( $this->db->query($query) )
332                                {       
333                                        while($this->db->next_record())
334                                                $result[] = $this->db->row();
335                                }
336
337                                $groupsLocked = explode(";",$result[0]['config_value']);
338                                       
339                                foreach( $groupsLocked as $tmp )
340                                {
341                                        $aux = explode(":", $tmp);
342                                        if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
343                                        {
344                                                if( $aux[2] )
345                                                {
346                                                        $ou_groups = explode(",",$aux[2]);
347                                                        natcasesort($ou_groups);
348                                                        $key = array_search($organization, $ou_groups);
349                                                       
350                                                        if( $key === false )
351                                                                array_push($ou_groups, $organization);
352                                                       
353                                                        $groups .= $group.":".$gidnumber.":";
354                                                       
355                                                        $return = "<return>";                                           
356                                                       
357                                                        foreach($ou_groups as $tmp)
358                                                        {
359                                                                $return .= "<ou attr='".$tmp."'>".$tmp."</ou>";
360                                                                $groups .= $tmp .",";   
361                                                        }
362                                                       
363                                                        $return .= "</return>";
364                                                       
365                                                        $groups  = substr($groups,0,strlen($groups)-1);
366                                                        $groups .= ";";
367                                                }
368                                                else
369                                                {
370                                                        $groups .= $group.":".$gidnumber.":".$organization.";";
371                                                        $return = "<return><ou attr='".$organization."'>".$organization."</ou></return>";
372                                                }
373                                        }
374                                        else
375                                                $groups .= $tmp . ";" ;
376                                }
377
378                                $groups = substr($groups,0,strlen($groups)-1);
379
380                                $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
381                                $this->db->query($query);
382                               
383                                return $return;
384                        }
385                }
386               
387                return false;
388        }
389       
390        public final function setUseParticipantsExternal($pFlag)
391        {
392                $flag = $pFlag['value'];
393                $return = "";
394               
395                if( $this->db )
396                {
397                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit';";
398
399                        if ( $this->db->query($query) )
400                        {       
401                                while($this->db->next_record())
402                                        $result[] = $this->db->row();
403                        }
404
405                        if(count($result) == 0)
406                        {
407                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','use_external_participants_jabberit','".$flag."')";
408                                $this->db->query($query);
409                                return true;
410                        }
411                        else
412                        {
413                                $query = "UPDATE phpgw_config SET config_value = '".$flag."' WHERE config_app = 'phpgwapi' AND config_name = 'use_external_participants_jabberit'";
414                                $this->db->query($query);
415                                return true;
416                        }
417                }
418                return false;
419        }
420       
421        public final function setOrganization($pOrganization)
422        {
423                $organization = $pOrganization['organization'];
424                $orgConfiguration = "";
425               
426                if( $this->db )
427                {
428                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
429
430                        if ( $this->db->query($query) )
431                        {       
432                                while($this->db->next_record())
433                                        $result[] = $this->db->row();
434               
435                                if(count($result) > 0)
436                                        $orgConfiguration = $result[0]['config_value'];
437                        }
438
439                        if( trim($orgConfiguration) == "" )
440                        {
441                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','conf_organization_jabberit','".$organization."')";
442                                $this->db->query($query);
443                               
444                                return "<return><ou attr='".$organization."'>".$organization."</ou></return>";
445                        }
446                        else
447                        {
448                                $orgAux = explode(",",$orgConfiguration);
449                               
450                                foreach( $orgAux as $tmp )
451                                {
452                                        if(strtolower(trim($tmp)) === strtolower(trim($organization)))
453                                                return false;
454                                }
455
456                                $value = $orgConfiguration . "," . $organization;
457                                $query = "UPDATE phpgw_config SET config_value = '".$value."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
458                                $this->db->query($query);
459
460                                $return = explode(",",$value);
461                                natcasesort($return);
462
463                                $values = "<return>";
464                               
465                                foreach($return as $tmp)
466                                        $values .= "<ou attr='" . $tmp . "'>" . $tmp . "</ou>";
467                                       
468                                $values .= "</return>";
469                               
470                                return $values;                 
471                        }
472                }
473                return false;
474        }
475       
476        public final function removeOuGroupsLocked($pGroup)
477        {
478                $group = $pGroup['group'];
479                $gidnumber = $pGroup['gidnumber'];
480                $organization = strtoupper($pGroup['ou']);
481                $return = false;
482               
483                if( $this->db )
484                {
485                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";       
486                       
487                        if($this->db->query($query))
488                        {
489
490                                if ( $this->db->query($query) )
491                                {       
492                                        while($this->db->next_record())
493                                                $result[] = $this->db->row();
494                                }
495
496                                $groupsLocked = explode(";",$result[0]['config_value']);
497                               
498                                foreach( $groupsLocked as $tmp )
499                                {
500                                        $aux = explode(":",$tmp);
501                                       
502                                        if(($group.":".$gidnumber) == ($aux[0].":".$aux[1]))
503                                        {
504                                                $ous = explode(",", $aux[2]);
505                                                $key = array_search($organization, $ous);
506
507                                                if( $key !== false )
508                                                        unset($ous[$key]);
509
510                                                $groups .= $group.":".$gidnumber.":";
511                                               
512                                                foreach($ous as $ouTmp)
513                                                        $groups .= $ouTmp .",";
514                                               
515                                                $groups  = substr($groups,0,strlen($groups)-1);
516                                                $groups .= ";";
517                                        }
518                                        else
519                                                $groups .= $tmp . ";" ;                                                                 
520                                }
521                                       
522                                $groups  = substr($groups,0,strlen($groups)-1);
523                       
524                                $query = "UPDATE phpgw_config SET config_value = '".trim($groups)."' WHERE config_app = 'phpgwapi' AND config_name = 'groups_locked_jabberit';";
525
526                                if( $this->db->query($query))
527                                        $return = true;
528                        }
529                }       
530               
531                return $return;
532        }
533       
534        public final function removeAttributesLdap($pOrg)
535        {
536                $organization = $pOrg['org'];
537               
538                if( $this->db )
539                {
540                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'attributes_org_ldap_jabberit'";
541                               
542                        if ( $this->db->query($query) )
543                        {       
544                                while( $this->db->next_record() )
545                                        $result[] = $this->db->row();
546               
547                                if( count($result) > 0 )
548                                        $attributesOrg = $result[0]['config_value'];
549                        }
550
551                        $attributesOrg = explode(",", $attributesOrg);
552                        $newValue = "";
553                        foreach($attributesOrg as $tmp)
554                        {
555                                $attr = explode(";",$tmp);
556                                 
557                                if( strtolower(trim($attr[0])) != strtolower(trim($organization)))
558                                {
559                                        $newValue .= $attr[0] . ";" . $attr[1] . ",";
560                                }
561                        }
562                       
563                        $newValue = substr($newValue, 0,(strlen($newValue) -1 ));
564                       
565                        if( trim($newValue) != "")
566                                $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'attributes_org_ldap_jabberit'";
567                        else
568                                $query = "DELETE from phpgw_config where config_name = 'attributes_org_ldap_jabberit'";
569                               
570                        if( $this->db->query($query))
571                                return true;
572                        else
573                                return false;
574                }
575                return false;   
576        }
577       
578        public final function removeParticipantsExternal($pOrganization)
579        {
580               
581                $organization = $pOrganization['participants'];
582               
583                if( $this->db )
584                {
585                        $query = "SELECT * from phpgw_config WHERE config_app = 'phpgwapi' and config_name = 'conf_organization_jabberit'";
586                               
587                        if ( $this->db->query($query) )
588                        {       
589                                while( $this->db->next_record() )
590                                        $result[] = $this->db->row();
591               
592                                if( count($result) > 0 )
593                                        $valueDB = $result[0]['config_value'];
594                        }
595
596                        $OrgDB = explode(",", $valueDB);
597                        $newValue = "";
598
599                        foreach($OrgDB as $tmp)
600                        {
601                                if( strtolower(trim($tmp)) != strtolower(trim($organization)))
602                                        $newValue .= $tmp . ",";
603                        }
604                       
605                        $newValue = substr($newValue, 0,(strlen($newValue) -1 ));
606                       
607                        if( trim($newValue) != "")
608                                $query = "UPDATE phpgw_config SET config_value = '".$newValue."' WHERE config_app = 'phpgwapi' AND config_name = 'conf_organization_jabberit'";
609                        else
610                                $query = "DELETE from phpgw_config where config_name = 'conf_organization_jabberit'";
611                               
612                        if( $this->db->query($query))
613                                return true;
614                        else
615                                return false;
616                }
617                return false;   
618        }
619}
620?>
Note: See TracBrowser for help on using the repository browser.