source: trunk/instant_messenger/inc/class.db_im.inc.php @ 41

Revision 41, 3.5 KB checked in by niltonneto, 17 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2define('PHPGW_INCLUDE_ROOT','../');     
3define('PHPGW_API_INC','../phpgwapi/inc');
4require_once(PHPGW_API_INC.'/class.db.inc.php');
5       
6class db_im
7{       
8       
9        var $db;
10        var $db_name;
11        var $db_host;
12        var $db_port;
13        var $db_user;
14        var $db_pass;
15        var $db_type;
16       
17        function db_im(){
18                $this->db_name = $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'];
19                $this->db_host = $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'];
20                $this->db_port = $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'];
21                $this->db_user = $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'];
22                $this->db_pass = $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'];
23                $this->db_type = $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'];
24               
25                $this->db = new db();           
26                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type);
27        }
28
29        function get_contacts_im($pFrom = false, $pTo)
30        {               
31                $result = array();
32                $from = explode("/",$pFrom);
33                $to = explode("/",$pTo);
34                if($pFrom)
35                        $query = "select im_from, im_to from phpgw_im_auth_user where im_from = '".$from[0]."' and im_to = '".$to[0]."'";
36                else
37                        $query = "select im_from, im_to from phpgw_im_auth_user where im_to = '".$to[0]."' order by im_from";                   
38       
39        if (!$this->db->query($query))
40                return null;
41               
42                while($this->db->next_record())
43                        $result[] = $this->db->row();
44
45                return $result;
46        }
47       
48        function insert_contacts($pFrom, $pTo)
49        {
50                $from = explode("/",$pFrom);
51                $to = explode("/",$pTo);
52                $query = "insert into phpgw_im_auth_user values('".$from[0]."','".$to[0]."')";
53                return $this->query_db($query);         
54        }
55       
56        function delete_contacts($pFrom, $pTo)
57        {
58                $from = explode("/",$pFrom);
59                $to = explode("/",$pTo);
60                $query = "delete from phpgw_im_auth_user where im_from = '".$from[0]."' and im_to = '".$to[0]."'";
61                return $this->query_db($query);
62        }
63       
64        function get_accounts_acl()
65        {
66                $result = array();
67                $query = "select acl_appname, acl_account from phpgw_acl where acl_appname = 'instant_messenger' order by acl_account";
68               
69                if (!$this->db->query($query))
70                return null;
71               
72                while($this->db->next_record())
73                        $result[] = $this->db->row();
74
75                return $result;
76        }
77       
78        function query_db($pQuery)
79        {
80                if (!$this->db->query($pQuery))
81                return false;
82                else
83                        return true;
84        }
85       
86        function set_preferences($param)
87        {
88                $preferences = $param['preferences'];
89                $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id'];
90                $app_name = "instant_messenger";
91
92                $query = "insert into phpgw_preferences values('".$user_id."','".$app_name."','".serialize($preferences)."')";
93               
94                if($this->query_db($query)){
95                        return 1;
96                }else{
97                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='".$app_name."' and preference_owner='".$user_id."'";
98                        if($this->query_db($query))
99                                return 1;
100                        else
101                                return 0;                       
102                }               
103        }
104       
105        function get_preferences()
106        {
107                $result = array();
108                $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id'];
109                $app_name = "instant_messenger";
110               
111                $query = "select * from phpgw_preferences where preference_owner = '".$user_id."' and preference_app = '".$app_name."'";
112               
113                if (!$this->db->query($query))
114                return NULL;
115               
116                while($this->db->next_record())
117                        $result[] = $this->db->row();
118
119                if(count($result) > 0){
120                        return unserialize($result[0]['preference_value']);
121                }else{
122                        return "ch_time:true;ch_offline:true;ch_contacts:false;rd_nm:true;rd_al:false;rd_ch:false";
123                }
124               
125        }
126}
127?>
Note: See TracBrowser for help on using the repository browser.