source: companies/serpro/jabberit_messenger/inc/class.db_im.inc.php @ 903

Revision 903, 5.1 KB checked in by niltonneto, 15 years ago (diff)

Importacao inicial do Expresso do Serpro

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        }
38
39        private final function connectDB()
40        {
41                $this->db = new db();
42                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);         
43        }       
44
45        public final function getApplicationsEnabled()
46        {
47                $this->connectDB();
48                $this->db->query("SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'");
49                if($this->db->num_rows())
50                {
51                        $tmp = "";
52                        while($this->db->next_record())
53                        {
54                                $tmp[]= $this->db->row();
55                        }
56                        return $tmp[0]['config_value'];
57                }
58                return false;
59        }
60       
61        public final function getApplicationsList()
62        {
63                $this->connectDB();
64                $this->db->query("SELECT * FROM phpgw_applications WHERE app_enabled = '1' order by app_name");
65                if($this->db->num_rows())
66                {
67                        while ($this->db->next_record())
68                        {
69                                $app = $this->db->f('app_name');
70                                $title = @$GLOBALS['phpgw_info']['apps'][$app]['title'];
71                                if (empty($title))
72                                {
73                                        $title = lang($app) == $app.'*' ? $app : lang($app);
74                                }
75                                $apps[$app] = array(
76                                        'title'  => $title,
77                                        'name'   => $app,
78                                        'status' => $this->db->f('app_enabled')
79                                );
80                        }
81                }
82                return $apps;
83        }
84
85        public final function get_accounts_acl()
86        {
87                $this->connectDB();                     
88               
89                $query  = "select acl_account from phpgw_acl where acl_location in (select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger') ";
90                $query .= "union select acl_account from phpgw_acl where acl_appname = 'jabberit_messenger'";
91               
92                if( $this->db->query($query) ) 
93                {
94                        $users = array();
95                        $new_users = array();
96                        while($this->db->next_record())
97                                $users[] = $this->db->row();
98
99                        if(is_array($users))
100                                foreach($users as $tmp)
101                                        $new_users[] = $tmp['acl_account'];
102                       
103                        return $new_users;
104                }
105               
106                return false;
107        }
108       
109        public final function getPreferences()
110        {
111                $this->connectDB();
112               
113                $result = array();
114                $query = "select * from phpgw_preferences where preference_owner = '".$this->user_id."' and preference_app = 'jabberit_messenger'";
115               
116                if ( $this->db->query($query) )
117                {       
118                        while($this->db->next_record())
119                                $result[] = $this->db->row();
120       
121                        if(count($result) > 0)
122                                return unserialize($result[0]['preference_value']);
123                }
124
125                return "openWindowJabberit:true";
126        }
127
128        public final function setPreferences($pParam)
129        {
130                $this->connectDB();
131                $preferences = $pParam['preferences'];
132                $user_id  = $this->user_id;
133               
134                $query = "insert into phpgw_preferences values('".$user_id."','jabberit_messenger','".serialize($preferences)."')";
135                               
136                if($this->db->query($query))
137                {
138                        return "true";
139                }
140                else
141                {
142                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='jabberit_messenger' and preference_owner='".$user_id."'";
143
144                        if($this->db->query($query))
145                                return "true";
146                        else
147                                return "false";                 
148                }               
149        }
150       
151        public final function setApplications($pApplications)
152        {
153                $this->connectDB();
154                $apps = serialize($pApplications);
155               
156                if( $this->db )
157                {
158                        $query = "SELECT * FROM phpgw_config WHERE config_app = 'phpgwapi' and config_name ='apps_jabberit'";
159                               
160                        $this->db->query($query);
161                                       
162                        if(!$this->db->next_record())
163                        {
164                                $query = "INSERT INTO phpgw_config(config_app,config_name,config_value) VALUES('phpgwapi','apps_jabberit','".$apps."')";
165                                $this->db->query($query);
166                                return true;
167                        }
168                        else
169                        {
170                                $query = "UPDATE phpgw_config SET config_value = '".$apps."' WHERE config_app = 'phpgwapi' AND config_name = 'apps_jabberit'";
171                                $this->db->query($query);
172                                return true;
173                        }
174                }
175                return false;   
176        }
177}
178?>
Note: See TracBrowser for help on using the repository browser.