1 | <?php |
---|
2 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
3 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
4 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
5 | |
---|
6 | class db_functions |
---|
7 | { |
---|
8 | |
---|
9 | var $db; |
---|
10 | var $user_id; |
---|
11 | |
---|
12 | function db_functions(){ |
---|
13 | $this->db = new db(); |
---|
14 | $this->db->Halt_On_Error = 'no'; |
---|
15 | $this->db->connect( |
---|
16 | $_SESSION['phpgw_info']['expressomail']['server']['db_name'], |
---|
17 | $_SESSION['phpgw_info']['expressomail']['server']['db_host'], |
---|
18 | $_SESSION['phpgw_info']['expressomail']['server']['db_port'], |
---|
19 | $_SESSION['phpgw_info']['expressomail']['server']['db_user'], |
---|
20 | $_SESSION['phpgw_info']['expressomail']['server']['db_pass'], |
---|
21 | $_SESSION['phpgw_info']['expressomail']['server']['db_type'] |
---|
22 | ); |
---|
23 | $this -> user_id = $_SESSION['phpgw_info']['expressomail']['user']['account_id']; |
---|
24 | } |
---|
25 | |
---|
26 | // BEGIN of functions. |
---|
27 | function get_cc_contacts() |
---|
28 | { |
---|
29 | $result = array(); |
---|
30 | $stringDropDownContacts = ''; |
---|
31 | // Pesquisa no CC os nomes e email dos contatos. |
---|
32 | $query = 'select A.names_ordered, C.connection_value from phpgw_cc_contact A,'. |
---|
33 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
34 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
35 | 'and B.id_typeof_contact_connection = 1 and '. |
---|
36 | 'A.id_owner ='.$this -> user_id.' order by A.names_ordered'; |
---|
37 | |
---|
38 | if (!$this->db->query($query)) |
---|
39 | return null; |
---|
40 | |
---|
41 | |
---|
42 | while($this->db->next_record()) |
---|
43 | $result[] = $this->db->row(); |
---|
44 | |
---|
45 | if (count($result) != 0) |
---|
46 | { |
---|
47 | // Monta string |
---|
48 | foreach($result as $contact) |
---|
49 | $stringDropDownContacts = $stringDropDownContacts . $contact['names_ordered']. ';' . $contact['connection_value'] . ','; |
---|
50 | //Retira ultima virgula. |
---|
51 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
52 | } |
---|
53 | else |
---|
54 | return null; |
---|
55 | |
---|
56 | return $stringDropDownContacts; |
---|
57 | } |
---|
58 | |
---|
59 | function get_cc_groups() |
---|
60 | { |
---|
61 | // Pesquisa no CC os Grupos Pessoais. |
---|
62 | $stringDropDownContacts = ''; |
---|
63 | $result = array(); |
---|
64 | $query = 'select title, short_name from phpgw_cc_groups where owner ='.$this -> user_id.' order by title'; |
---|
65 | // Executa a query |
---|
66 | if (!$this->db->query($query)) |
---|
67 | return null; |
---|
68 | // Retorna cada resultado |
---|
69 | while($this->db->next_record()) |
---|
70 | $result[] = $this->db->row(); |
---|
71 | // Se houver grupos .... |
---|
72 | if (count($result) != 0) |
---|
73 | { |
---|
74 | foreach($result as $group) |
---|
75 | $stringDropDownContacts .= $group['title']. ';' . $group['short_name'] . ','; |
---|
76 | //Retira ultima virgula. |
---|
77 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
78 | } |
---|
79 | else |
---|
80 | return null; |
---|
81 | |
---|
82 | return $stringDropDownContacts; |
---|
83 | } |
---|
84 | |
---|
85 | function getContactsByGroupAlias($alias) |
---|
86 | { |
---|
87 | |
---|
88 | $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". |
---|
89 | "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". |
---|
90 | "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". |
---|
91 | "and B.id_typeof_contact_connection = 1 and ". |
---|
92 | "A.id_owner =".$this -> user_id." and ". |
---|
93 | "D.id_group = E.id_group and ". |
---|
94 | "D.id_connection = C.id_connection and E.short_name = '".$alias. |
---|
95 | "' order by A.names_ordered"; |
---|
96 | |
---|
97 | if (!$this->db->query($query)) |
---|
98 | { |
---|
99 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
100 | } |
---|
101 | |
---|
102 | $return = false; |
---|
103 | |
---|
104 | while($this->db->next_record()) |
---|
105 | { |
---|
106 | $return[] = $this->db->row(); |
---|
107 | } |
---|
108 | |
---|
109 | return $return; |
---|
110 | } |
---|
111 | |
---|
112 | function getAddrs($array_addrs) { |
---|
113 | $array_addrs_final = array(); |
---|
114 | |
---|
115 | for($i = 0; $i < count($array_addrs); $i++){ |
---|
116 | $j = count($array_addrs_final); |
---|
117 | |
---|
118 | if(!strchr($array_addrs[$i],'@') |
---|
119 | && strchr($array_addrs[$i],'<') |
---|
120 | && strchr($array_addrs[$i],'>')) { |
---|
121 | |
---|
122 | $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>')); |
---|
123 | $alias = str_replace('<','', str_replace('>','',$alias)); |
---|
124 | $arrayContacts = $this -> getContactsByGroupAlias($alias); |
---|
125 | |
---|
126 | if($arrayContacts) { |
---|
127 | foreach($arrayContacts as $index => $contact){ |
---|
128 | if($contact['names_ordered']) { |
---|
129 | $array_addrs_final[$j] = '"'.$contact['names_ordered'].'" <'.$contact['connection_value'].'>'; |
---|
130 | } |
---|
131 | else |
---|
132 | $array_addrs_final[$j] = $contact['connection_value']; |
---|
133 | |
---|
134 | $j++; |
---|
135 | } |
---|
136 | } |
---|
137 | } |
---|
138 | else |
---|
139 | $array_addrs_final[$j++] = $array_addrs[$i]; |
---|
140 | } |
---|
141 | return $array_addrs_final; |
---|
142 | } |
---|
143 | |
---|
144 | function get_dropdown_contacts(){ |
---|
145 | |
---|
146 | $contacts = $this -> get_cc_contacts(); |
---|
147 | $groups = $this -> get_cc_groups(); |
---|
148 | |
---|
149 | if(($contacts) && ($groups)) |
---|
150 | $stringDropDownContacts = $contacts . ',' . $groups; |
---|
151 | elseif ((!$contacts) && (!$groups)) |
---|
152 | $stringDropDownContacts = ''; |
---|
153 | elseif (($contacts) && (!$groups)) |
---|
154 | $stringDropDownContacts = $contacts; |
---|
155 | elseif ((!$contacts) && ($groups)) |
---|
156 | $stringDropDownContacts = $groups; |
---|
157 | |
---|
158 | return $stringDropDownContacts; |
---|
159 | } |
---|
160 | /* |
---|
161 | function update_preferences($params){ |
---|
162 | |
---|
163 | $aux = explode("##",$params['prefe_string']); |
---|
164 | $new_prefe = array(); |
---|
165 | |
---|
166 | foreach($aux as $key=>$tmp){ |
---|
167 | if($key == 0){ |
---|
168 | $new_prefe['max_email_per_page'] = $tmp; |
---|
169 | } |
---|
170 | if($key == 1){ |
---|
171 | $new_prefe['save_deleted_msg'] = $tmp; |
---|
172 | } |
---|
173 | if($key == 2){ |
---|
174 | $new_prefe['delete_trash_messages_after_n_days'] = $tmp; |
---|
175 | } |
---|
176 | if($key == 3){ |
---|
177 | $new_prefe['delete_and_show_previous_message'] = $tmp; |
---|
178 | } |
---|
179 | if($key == 4){ |
---|
180 | $new_prefe['alert_new_msg'] = $tmp; |
---|
181 | } |
---|
182 | if($key == 5){ |
---|
183 | $new_prefe['mainscreen_showmail'] = $tmp; |
---|
184 | } |
---|
185 | if($key == 10){ |
---|
186 | $new_prefe['signature'] = $tmp; |
---|
187 | } |
---|
188 | if($key == 7){ |
---|
189 | $new_prefe['hide_folders'] = $tmp; |
---|
190 | } |
---|
191 | if($key == 6){ |
---|
192 | $new_prefe['save_in_folder'] = $tmp; |
---|
193 | } |
---|
194 | if($key == 8){ |
---|
195 | $new_prefe['line_height'] = $tmp; |
---|
196 | } |
---|
197 | if($key == 9){ |
---|
198 | $new_prefe['font_size'] = $tmp; |
---|
199 | } |
---|
200 | if($key == 11){ |
---|
201 | $new_prefe['use_shortcuts'] = $tmp; |
---|
202 | } |
---|
203 | } |
---|
204 | |
---|
205 | $string_serial = serialize($new_prefe); |
---|
206 | $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial); |
---|
207 | $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'". |
---|
208 | " and preference_owner = '".$this->user_id."'"; |
---|
209 | |
---|
210 | if (!$this->db->query($query)) |
---|
211 | return "Failed!"; |
---|
212 | else |
---|
213 | return "OK!"; |
---|
214 | } |
---|
215 | */ |
---|
216 | function update_preferences($params){ |
---|
217 | $string_serial = urldecode($params['prefe_string']); |
---|
218 | $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial); |
---|
219 | $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'". |
---|
220 | " and preference_owner = '".$this->user_id."'"; |
---|
221 | |
---|
222 | if (!$this->db->query($query)) |
---|
223 | return $this->db->error; |
---|
224 | else |
---|
225 | return array("success" => true); |
---|
226 | } |
---|
227 | function getUserByEmail($params){ |
---|
228 | // Follow the referral |
---|
229 | $email = $params['email']; |
---|
230 | $query = 'select A.names_ordered, C.connection_name, C.connection_value, A.photo'. |
---|
231 | ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, '. |
---|
232 | 'phpgw_cc_connections C where A.id_contact = B.id_contact'. |
---|
233 | ' and B.id_connection = C.id_connection and A.id_contact ='. |
---|
234 | '(select A.id_contact from phpgw_cc_contact A, phpgw_cc_contact_conns B,'. |
---|
235 | 'phpgw_cc_connections C where A.id_contact = B.id_contact'. |
---|
236 | ' and B.id_connection = C.id_connection and A.id_owner = '.$this -> user_id. |
---|
237 | ' and C.connection_value = \''.$email.'\') and '. |
---|
238 | 'C.connection_is_default = true and B.id_typeof_contact_connection = 2'; |
---|
239 | |
---|
240 | if (!$this->db->query($query)) |
---|
241 | return null; |
---|
242 | |
---|
243 | |
---|
244 | if($this->db->next_record()) { |
---|
245 | $result = $this->db->row(); |
---|
246 | |
---|
247 | $obj = array("cn" => $result['names_ordered'], |
---|
248 | "email" => $email, |
---|
249 | "type" => "personal", |
---|
250 | "telefone" => $result['connection_value']); |
---|
251 | |
---|
252 | if($result['photo']) |
---|
253 | $_SESSION['phpgw_info']['expressomail']['contact_photo'] = array($result['photo']); |
---|
254 | |
---|
255 | return $obj; |
---|
256 | } |
---|
257 | return $result; |
---|
258 | } |
---|
259 | } |
---|
260 | ?> |
---|