1 | <?php |
---|
2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
4 | require_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
5 | |
---|
6 | class 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 | var $teste; |
---|
17 | |
---|
18 | function db_im(){ |
---|
19 | $this->db_name = $_SESSION['phpgw_info']['instant_messenger']['server']['db_name']; |
---|
20 | $this->db_host = $_SESSION['phpgw_info']['instant_messenger']['server']['db_host']; |
---|
21 | $this->db_port = $_SESSION['phpgw_info']['instant_messenger']['server']['db_port']; |
---|
22 | $this->db_user = $_SESSION['phpgw_info']['instant_messenger']['server']['db_user']; |
---|
23 | $this->db_pass = $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass']; |
---|
24 | $this->db_type = $_SESSION['phpgw_info']['instant_messenger']['server']['db_type']; |
---|
25 | |
---|
26 | $this->db = new db(); |
---|
27 | $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); |
---|
28 | } |
---|
29 | |
---|
30 | function get_accounts_acl() |
---|
31 | { |
---|
32 | $result = array(); |
---|
33 | $query = "select acl_appname, acl_account from phpgw_acl where acl_appname = 'instant_messenger' order by acl_account"; |
---|
34 | |
---|
35 | if (!$this->db->query($query)) |
---|
36 | return null; |
---|
37 | |
---|
38 | while($this->db->next_record()) |
---|
39 | $result[] = $this->db->row(); |
---|
40 | |
---|
41 | return $result; |
---|
42 | } |
---|
43 | |
---|
44 | function query_db($pQuery) |
---|
45 | { |
---|
46 | if (!$this->db->query($pQuery)) |
---|
47 | return false; |
---|
48 | else |
---|
49 | return true; |
---|
50 | } |
---|
51 | |
---|
52 | function set_preferences($param) |
---|
53 | { |
---|
54 | $preferences = $param['preferences']; |
---|
55 | $user_id = $_SESSION['phpgw_info']['instant_messenger']['user_id']; |
---|
56 | $app_name = $this->name_app(); |
---|
57 | |
---|
58 | $query = "insert into phpgw_preferences values('".$user_id."','".$app_name."','".serialize($preferences)."')"; |
---|
59 | |
---|
60 | if($this->query_db($query)) |
---|
61 | return "true"; |
---|
62 | else{ |
---|
63 | $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='".$app_name."' and preference_owner='".$user_id."'"; |
---|
64 | if($this->query_db($query)) |
---|
65 | return "true"; |
---|
66 | else |
---|
67 | return "false"; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | function get_preferences() |
---|
72 | { |
---|
73 | $result = array(); |
---|
74 | $user_id = $_SESSION['phpgw_info']['instant_messenger']['user_id']; |
---|
75 | $app_name = $this->name_app(); |
---|
76 | |
---|
77 | $query = "select * from phpgw_preferences where preference_owner = '".$user_id."' and preference_app = '".$app_name."'"; |
---|
78 | |
---|
79 | if (!$this->db->query($query)) |
---|
80 | return NULL; |
---|
81 | |
---|
82 | while($this->db->next_record()) |
---|
83 | $result[] = $this->db->row(); |
---|
84 | |
---|
85 | if(count($result) > 0){ |
---|
86 | return unserialize($result[0]['preference_value']); |
---|
87 | }else{ |
---|
88 | return "ch_offline:true;in_time:1;rd_nm:true;rd_ch:false"; |
---|
89 | } |
---|
90 | } |
---|
91 | |
---|
92 | function name_app() |
---|
93 | { |
---|
94 | return "instant_messenger"; |
---|
95 | } |
---|
96 | } |
---|
97 | ?> |
---|