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