1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * Expresso Livre * |
---|
4 | * http://www.expressolivre.org * |
---|
5 | * -------------------------------------------- * |
---|
6 | * This program is free software; you can redistribute it and/or modify it * |
---|
7 | * under the terms of the GNU General Public License as published by the * |
---|
8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
9 | * option) any later version. * |
---|
10 | \**************************************************************************/ |
---|
11 | |
---|
12 | if(!isset($_SESSION['phpgw_info']['expressomail']['server']['db_name'])) { |
---|
13 | include_once('../header.inc.php'); |
---|
14 | $_SESSION['phpgw_info']['expressomail']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; |
---|
15 | $_SESSION['phpgw_info']['expressomail']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; |
---|
16 | $_SESSION['phpgw_info']['expressomail']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; |
---|
17 | $_SESSION['phpgw_info']['expressomail']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; |
---|
18 | $_SESSION['phpgw_info']['expressomail']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; |
---|
19 | $_SESSION['phpgw_info']['expressomail']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; |
---|
20 | } |
---|
21 | else{ |
---|
22 | define('PHPGW_INCLUDE_ROOT','../'); |
---|
23 | define('PHPGW_API_INC','../phpgwapi/inc'); |
---|
24 | include_once(PHPGW_API_INC.'/class.db.inc.php'); |
---|
25 | } |
---|
26 | include_once('class.dynamic_contacts.inc.php'); |
---|
27 | |
---|
28 | class db_functions |
---|
29 | { |
---|
30 | |
---|
31 | var $db; |
---|
32 | var $user_id; |
---|
33 | var $related_ids; |
---|
34 | |
---|
35 | function db_functions(){ |
---|
36 | $this->db = new db(); |
---|
37 | $this->db->Halt_On_Error = 'no'; |
---|
38 | $this->db->connect( |
---|
39 | $_SESSION['phpgw_info']['expressomail']['server']['db_name'], |
---|
40 | $_SESSION['phpgw_info']['expressomail']['server']['db_host'], |
---|
41 | $_SESSION['phpgw_info']['expressomail']['server']['db_port'], |
---|
42 | $_SESSION['phpgw_info']['expressomail']['server']['db_user'], |
---|
43 | $_SESSION['phpgw_info']['expressomail']['server']['db_pass'], |
---|
44 | $_SESSION['phpgw_info']['expressomail']['server']['db_type'] |
---|
45 | ); |
---|
46 | $this -> user_id = $_SESSION['phpgw_info']['expressomail']['user']['account_id']; |
---|
47 | } |
---|
48 | |
---|
49 | // BEGIN of functions. |
---|
50 | function get_cc_contacts() |
---|
51 | { |
---|
52 | $result = array(); |
---|
53 | $stringDropDownContacts = ''; |
---|
54 | |
---|
55 | $query_related = $this->get_query_related('A.id_owner'); // field name for owner |
---|
56 | |
---|
57 | // Traz os contatos pessoais e compartilhados |
---|
58 | $query = 'select A.names_ordered, C.connection_value from phpgw_cc_contact A, '. |
---|
59 | 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. |
---|
60 | 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. |
---|
61 | 'and B.id_typeof_contact_connection = 1 and ('.$query_related.') group by '. |
---|
62 | 'A.names_ordered,C.connection_value order by lower(A.names_ordered)'; |
---|
63 | |
---|
64 | if (!$this->db->query($query)) |
---|
65 | return null; |
---|
66 | while($this->db->next_record()) |
---|
67 | $result[] = $this->db->row(); |
---|
68 | |
---|
69 | if (count($result) != 0) |
---|
70 | { |
---|
71 | // Monta string |
---|
72 | foreach($result as $contact) |
---|
73 | $stringDropDownContacts = $stringDropDownContacts . urldecode(urldecode($contact['names_ordered'])). ';' . $contact['connection_value'] . ','; |
---|
74 | //Retira ultima virgula. |
---|
75 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
76 | } |
---|
77 | else |
---|
78 | return null; |
---|
79 | |
---|
80 | return $stringDropDownContacts; |
---|
81 | } |
---|
82 | // Get Related Ids for sharing contacts or groups. |
---|
83 | function get_query_related($field_name){ |
---|
84 | $query_related = $field_name .'='.$this -> user_id; |
---|
85 | // Only at first time, it gets all related ids... |
---|
86 | if(!$this->related_ids) { |
---|
87 | $query = 'select id_related from phpgw_cc_contact_rels where id_contact='.$this -> user_id.' and id_typeof_contact_relation=1'; |
---|
88 | if (!$this->db->query($query)){ |
---|
89 | return $query_related; |
---|
90 | } |
---|
91 | |
---|
92 | $result = array( ); |
---|
93 | while($this->db->next_record()){ |
---|
94 | $row = $this->db->row(); |
---|
95 | $result[] = $row['id_related']; |
---|
96 | } |
---|
97 | if($result) |
---|
98 | $this->related_ids = implode(",",$result); |
---|
99 | } |
---|
100 | if($this->related_ids) |
---|
101 | $query_related .= ' or '.$field_name.' in ('.$this->related_ids.')'; |
---|
102 | |
---|
103 | return $query_related; |
---|
104 | } |
---|
105 | function get_cc_groups() |
---|
106 | { |
---|
107 | // Pesquisa no CC os Grupos Pessoais. |
---|
108 | $stringDropDownContacts = ''; |
---|
109 | $result = array(); |
---|
110 | $query_related = $this->get_query_related('owner'); // field name for 'owner' |
---|
111 | $query = 'select title, short_name, owner from phpgw_cc_groups where '.$query_related.' order by lower(title)'; |
---|
112 | |
---|
113 | // Executa a query |
---|
114 | if (!$this->db->query($query)) |
---|
115 | return null; |
---|
116 | // Retorna cada resultado |
---|
117 | while($this->db->next_record()) |
---|
118 | $result[] = $this->db->row(); |
---|
119 | |
---|
120 | // Se houver grupos .... |
---|
121 | if (count($result) != 0) |
---|
122 | { |
---|
123 | // Create Ldap Object, if exists related Ids for sharing groups. |
---|
124 | if($this->related_ids){ |
---|
125 | $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids']= array(); |
---|
126 | include_once("class.ldap_functions.inc.php"); |
---|
127 | $ldap = new ldap_functions(); |
---|
128 | } |
---|
129 | $owneruid = ''; |
---|
130 | foreach($result as $group){ |
---|
131 | // Searching uid (LDAP), if exists related Ids for sharing groups. |
---|
132 | // Save into user session. It will used before send mail (verify permission). |
---|
133 | if(!isset($_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']]) && isset($ldap)){ |
---|
134 | $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']] = $ldap -> uidnumber2uid($group['owner']); |
---|
135 | } |
---|
136 | if($this->user_id != $group['owner']) |
---|
137 | $owneruid = "::".$_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']]; |
---|
138 | else |
---|
139 | $owneruid = ''; |
---|
140 | |
---|
141 | $stringDropDownContacts .= $group['title']. ';' . ($group['short_name'].$owneruid) . ','; |
---|
142 | } |
---|
143 | //Retira ultima virgula. |
---|
144 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
145 | } |
---|
146 | else |
---|
147 | return null; |
---|
148 | return $stringDropDownContacts; |
---|
149 | } |
---|
150 | |
---|
151 | function getContactsByGroupAlias($alias) |
---|
152 | { |
---|
153 | list($alias,$uid) = explode("::",$alias); |
---|
154 | $cc_related_ids = $_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids']; |
---|
155 | // Explode personal group, If exists related ids (the user has permission to send email). |
---|
156 | if(is_array($cc_related_ids) && $uid){ |
---|
157 | $owner = array_search($uid,$cc_related_ids); |
---|
158 | } |
---|
159 | |
---|
160 | $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". |
---|
161 | "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". |
---|
162 | "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". |
---|
163 | "and B.id_typeof_contact_connection = 1 and ". |
---|
164 | "A.id_owner =".($owner ? $owner : $this->user_id)." and ". |
---|
165 | "D.id_group = E.id_group and ". |
---|
166 | "D.id_connection = C.id_connection and E.short_name = '".$alias."'"; |
---|
167 | |
---|
168 | if (!$this->db->query($query)) |
---|
169 | { |
---|
170 | exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); |
---|
171 | } |
---|
172 | |
---|
173 | $return = false; |
---|
174 | |
---|
175 | while($this->db->next_record()) |
---|
176 | { |
---|
177 | $return[] = $this->db->row(); |
---|
178 | } |
---|
179 | |
---|
180 | return $return; |
---|
181 | } |
---|
182 | |
---|
183 | function getAddrs($array_addrs) { |
---|
184 | $array_addrs_final = array(); |
---|
185 | |
---|
186 | for($i = 0; $i < count($array_addrs); $i++){ |
---|
187 | $j = count($array_addrs_final); |
---|
188 | |
---|
189 | if(preg_replace('/\s+/', '', $array_addrs[$i]) != ""){ |
---|
190 | |
---|
191 | if(strchr($array_addrs[$i],'@') == "") { |
---|
192 | if(strpos($array_addrs[$i],'<') && strpos($array_addrs[$i],'>')){ |
---|
193 | $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>')); |
---|
194 | $alias = str_replace('<','', str_replace('>','',$alias)); |
---|
195 | |
---|
196 | } |
---|
197 | else{ |
---|
198 | $alias = $array_addrs[$i]; |
---|
199 | $alias = preg_replace('/\s/', '', $alias); |
---|
200 | } |
---|
201 | |
---|
202 | $arrayContacts = $this -> getContactsByGroupAlias($alias); |
---|
203 | |
---|
204 | |
---|
205 | if($arrayContacts) { |
---|
206 | foreach($arrayContacts as $index => $contact){ |
---|
207 | if($contact['names_ordered']) { |
---|
208 | $array_addrs_final[$j] = '"'.$contact['names_ordered'].'" <'.$contact['connection_value'].'>'; |
---|
209 | } |
---|
210 | else |
---|
211 | $array_addrs_final[$j] = $contact['connection_value']; |
---|
212 | |
---|
213 | $j++; |
---|
214 | } |
---|
215 | }else{ |
---|
216 | return array("False" => "$alias"); |
---|
217 | } |
---|
218 | } |
---|
219 | //-- validação email -- |
---|
220 | else{ |
---|
221 | $array_addrs[$i] = trim($array_addrs[$i]); |
---|
222 | preg_match('/<([^>]+)>/', $array_addrs[$i], $match); |
---|
223 | if(count($match) == 2){ |
---|
224 | $ex_arr = explode('@', $match[1]); |
---|
225 | }else{ |
---|
226 | $ex_arr = explode('@', $array_addrs[$i]); |
---|
227 | } |
---|
228 | if(count($ex_arr) == 2){ |
---|
229 | if($ex_arr[0] !== '' && $ex_arr[1] !== ''){ |
---|
230 | if(preg_match("/[^0-9a-zA-Z._-]+/", $ex_arr[0]) == 0 && preg_match("/[^0-9a-zA-Z._-]+/", $ex_arr[1]) == 0){ |
---|
231 | $array_addrs_final[$j] = $array_addrs[$i]; |
---|
232 | }else{ |
---|
233 | return array("False" => "$alias"); |
---|
234 | } |
---|
235 | }else{ |
---|
236 | return array("False" => "$alias"); |
---|
237 | } |
---|
238 | }else{ |
---|
239 | return array("False" => "$alias"); |
---|
240 | } |
---|
241 | } |
---|
242 | //-- fim -- |
---|
243 | }else{ |
---|
244 | $array_addrs_final[$j] = $array_addrs[$i]; |
---|
245 | } |
---|
246 | } |
---|
247 | return $array_addrs_final; |
---|
248 | } |
---|
249 | |
---|
250 | //Gera lista de contatos para ser gravado e acessado pelo expresso offline. |
---|
251 | function get_dropdown_contacts_to_cache() { |
---|
252 | return $this->get_dropdown_contacts(); |
---|
253 | } |
---|
254 | |
---|
255 | function get_dropdown_contacts(){ |
---|
256 | $contacts = $this->get_cc_contacts(); |
---|
257 | $groups = $this->get_cc_groups(); |
---|
258 | |
---|
259 | if(($contacts) && ($groups)) |
---|
260 | $stringDropDownContacts = $contacts . ',' . $groups; |
---|
261 | elseif ((!$contacts) && (!$groups)) |
---|
262 | $stringDropDownContacts = ''; |
---|
263 | elseif (($contacts) && (!$groups)) |
---|
264 | $stringDropDownContacts = $contacts; |
---|
265 | elseif ((!$contacts) && ($groups)) |
---|
266 | $stringDropDownContacts = $groups; |
---|
267 | |
---|
268 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
269 | // Free others requests |
---|
270 | session_write_close(); |
---|
271 | $dynamic_contact = new dynamic_contacts(); |
---|
272 | $dynamic = $dynamic_contact->dynamic_contact_toString(); |
---|
273 | if ($dynamic) |
---|
274 | $stringDropDownContacts .= ($stringDropDownContacts ? ',' : '') . $dynamic; |
---|
275 | } |
---|
276 | return $stringDropDownContacts; |
---|
277 | } |
---|
278 | function getUserByEmail($params){ |
---|
279 | // Follow the referral |
---|
280 | $email = $params['email']; |
---|
281 | $query = 'select A.names_ordered, C.connection_name, C.connection_value, A.photo'. |
---|
282 | ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, '. |
---|
283 | 'phpgw_cc_connections C where A.id_contact = B.id_contact'. |
---|
284 | ' and B.id_connection = C.id_connection and A.id_contact ='. |
---|
285 | '(select A.id_contact from phpgw_cc_contact A, phpgw_cc_contact_conns B,'. |
---|
286 | 'phpgw_cc_connections C where A.id_contact = B.id_contact'. |
---|
287 | ' and B.id_connection = C.id_connection and A.id_owner = '.$this -> user_id. |
---|
288 | ' and C.connection_value = \''.$email.'\') and '. |
---|
289 | 'C.connection_is_default = true and B.id_typeof_contact_connection = 2'; |
---|
290 | |
---|
291 | if (!$this->db->query($query)) |
---|
292 | return null; |
---|
293 | |
---|
294 | |
---|
295 | if($this->db->next_record()) { |
---|
296 | $result = $this->db->row(); |
---|
297 | |
---|
298 | $obj = array("cn" => $result['names_ordered'], |
---|
299 | "email" => $email, |
---|
300 | "type" => "personal", |
---|
301 | "telefone" => $result['connection_value']); |
---|
302 | |
---|
303 | if($result['photo']) |
---|
304 | $_SESSION['phpgw_info']['expressomail']['contact_photo'] = array($result['photo']); |
---|
305 | |
---|
306 | return $obj; |
---|
307 | } |
---|
308 | return $result; |
---|
309 | } |
---|
310 | |
---|
311 | function get_dynamic_contacts() |
---|
312 | { |
---|
313 | // Pesquisa os emails e ultima inserção nos contatos dinamicos. |
---|
314 | if(!$this->db->select('phpgw_expressomail_contacts','data','id_owner ='.$this->user_id,__LINE__,__FILE__)) |
---|
315 | { |
---|
316 | return $this->db->Error; |
---|
317 | } |
---|
318 | while($this->db->next_record()) |
---|
319 | { |
---|
320 | $result[] = $this->db->row(); |
---|
321 | } |
---|
322 | if($result) foreach($result as $item) |
---|
323 | { |
---|
324 | $contacts = unserialize($item['data']); |
---|
325 | } |
---|
326 | if (count($contacts) == 0) |
---|
327 | { |
---|
328 | return null; |
---|
329 | } |
---|
330 | //Sort by email |
---|
331 | function cmp($a, $b) { return strcmp($a["email"], $b["email"]);} |
---|
332 | usort($contacts,"cmp"); |
---|
333 | return $contacts; |
---|
334 | } |
---|
335 | function update_contacts($contacts=array()) |
---|
336 | { |
---|
337 | |
---|
338 | |
---|
339 | if(!$this->db->select('phpgw_expressomail_contacts','data','id_owner ='.$this->user_id,__LINE__,__FILE__)) |
---|
340 | { |
---|
341 | $result['dberr1'] = $this->db->Error; |
---|
342 | } |
---|
343 | $regs = array(); |
---|
344 | while($this->db->next_record()) |
---|
345 | { |
---|
346 | $regs[] = $this->db->row(); |
---|
347 | } |
---|
348 | $old_contatacts = array(); |
---|
349 | foreach($regs as $old){ |
---|
350 | $old_contatacts = unserialize($old['data']); |
---|
351 | } |
---|
352 | |
---|
353 | foreach($old_contatacts as $i => $v) |
---|
354 | foreach($contacts as $ii => $vv) |
---|
355 | if(trim($v['email']) == trim($vv['email'])) |
---|
356 | unset($old_contatacts[$i]); |
---|
357 | |
---|
358 | |
---|
359 | $old_contatacts = array_merge( $old_contatacts , $contacts); |
---|
360 | // Atualiza um email nos contatos dinamicos. |
---|
361 | if(!$this->db->update('phpgw_expressomail_contacts ','data=\''.serialize($old_contatacts).'\'','id_owner ='.$this->user_id,__LINE__,__FILE__)) |
---|
362 | { |
---|
363 | return $this->db->Error; |
---|
364 | } |
---|
365 | return $contacts; |
---|
366 | } |
---|
367 | function update_preferences($params){ |
---|
368 | $string_serial = urldecode($params['prefe_string']); |
---|
369 | $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial); |
---|
370 | $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'". |
---|
371 | " and preference_owner = '".$this->user_id."'"; |
---|
372 | |
---|
373 | if (!$this->db->query($query)) |
---|
374 | return $this->db->error; |
---|
375 | else |
---|
376 | return array("success" => true); |
---|
377 | } |
---|
378 | |
---|
379 | function insert_contact($contact) |
---|
380 | { |
---|
381 | $contacts[] = array( 'timestamp' => time(), |
---|
382 | 'email' => $contact ); |
---|
383 | |
---|
384 | // Insere um email nos contatos dinamicos. |
---|
385 | $query = 'INSERT INTO phpgw_expressomail_contacts (data, id_owner) ' . |
---|
386 | 'values ( \''.serialize($contacts).'\', '.$this->user_id.')'; |
---|
387 | |
---|
388 | if(!$this->db->query($query,__LINE__,__FILE__)) |
---|
389 | return $this->db->Error; |
---|
390 | return $contacts; |
---|
391 | } |
---|
392 | |
---|
393 | function remove_dynamic_contact($user_id,$line,$file) |
---|
394 | { |
---|
395 | $where = $user_id.' = id_owner'; |
---|
396 | $this->db->delete('phpgw_expressomail_contacts',$where,$line,$file); |
---|
397 | } |
---|
398 | |
---|
399 | function import_vcard($params){ |
---|
400 | include_once('class.imap_functions.inc.php'); |
---|
401 | $objImap = new imap_functions(); |
---|
402 | $msg_number = $params['msg_number']; |
---|
403 | $idx_file = $params['idx_file']; |
---|
404 | $msg_part = $params['msg_part']; |
---|
405 | $msg_folder = $params['msg_folder']; |
---|
406 | $from_ajax = $params['from_ajax']; |
---|
407 | $encoding = strtolower($params['encoding']); |
---|
408 | $fileContent = ""; |
---|
409 | $cirus_delimiter = $params['cirus_delimiter']; |
---|
410 | $expFolder = explode($cirus_delimiter, $msg_folder); |
---|
411 | |
---|
412 | if($msg_number != null && $msg_part != null && $msg_folder != null && (intval($idx_file == '0' ? '1' : $idx_file))) |
---|
413 | { |
---|
414 | require_once PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
415 | $attachmentObj = new attachment(); |
---|
416 | $attachmentObj->setStructureFromMail($msg_folder,$msg_number); |
---|
417 | $fileContent = $attachmentObj->getAttachment($msg_part); |
---|
418 | $info = $attachmentObj->getAttachmentInfo($msg_part); |
---|
419 | $filename = $info['name']; |
---|
420 | } |
---|
421 | else |
---|
422 | $filename = $idx_file; |
---|
423 | |
---|
424 | // It's necessary to access calendar method. |
---|
425 | $GLOBALS['phpgw_info']['flags']['noappheader'] = True; |
---|
426 | $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; |
---|
427 | $GLOBALS['phpgw_info']['flags']['currentapp'] = 'calendar'; |
---|
428 | include_once(PHPGW_INCLUDE_ROOT.'/header.inc.php'); |
---|
429 | $uiicalendar = CreateObject("calendar.uiicalendar"); |
---|
430 | if($params['selected'] || $params['readable']){ |
---|
431 | $user = $params['id_user']; |
---|
432 | |
---|
433 | $_REQUEST['data'] = $fileContent; |
---|
434 | $_REQUEST['type'] = 'iCal'; |
---|
435 | $_REQUEST['params']['calendar'] = $params['selected']; |
---|
436 | $_REQUEST['readable'] = $params['readable'] ? true : false; |
---|
437 | $_REQUEST['analize'] = isset($params['analize']) ? true : false; |
---|
438 | $_REQUEST['params']['status'] = $params['status']; |
---|
439 | $_REQUEST['params']['owner'] = $_SESSION['phpgw_info']['expressomail']['user']['account_id']; |
---|
440 | if(isset($params['acceptedSuggestion'])){ |
---|
441 | $_REQUEST['params']['acceptedSuggestion'] = $params['acceptedSuggestion']; |
---|
442 | $_REQUEST['params']['from'] = $params['from']; |
---|
443 | } |
---|
444 | |
---|
445 | ob_start(); |
---|
446 | include_once(PHPGW_INCLUDE_ROOT.'/prototype/converter.php'); |
---|
447 | $output = ob_get_clean(); |
---|
448 | $valid = json_decode($output, true); |
---|
449 | if($_REQUEST['readable']){ |
---|
450 | if(!is_array($valid)) |
---|
451 | { |
---|
452 | $output = unserialize($output); |
---|
453 | foreach($output as $key => $value) |
---|
454 | return $value; |
---|
455 | } |
---|
456 | return false; |
---|
457 | } |
---|
458 | |
---|
459 | if(empty($valid)) |
---|
460 | return "error"; |
---|
461 | return "ok"; |
---|
462 | } |
---|
463 | if(strtoupper($expFolder[0]) == 'USER' && $expFolder[1]) // IF se a conta o ical estiver em uma conta compartilhada |
---|
464 | { |
---|
465 | include_once('class.ldap_functions.inc.php'); |
---|
466 | $ldap = new ldap_functions(); |
---|
467 | $account['uid'] = $expFolder[1]; |
---|
468 | $account['uidnumber'] = $ldap->uid2uidnumber($expFolder[1]); |
---|
469 | $account['mail'] = $ldap->getMailByUid($expFolder[1]); |
---|
470 | |
---|
471 | return $uiicalendar->import_from_mail($fileContent, $from_ajax,$account); |
---|
472 | } |
---|
473 | else |
---|
474 | return $uiicalendar->import_from_mail($fileContent, $from_ajax); |
---|
475 | |
---|
476 | } |
---|
477 | |
---|
478 | function insert_certificate($email,$certificate,$serialnumber,$authoritykeyidentifier=null) |
---|
479 | { |
---|
480 | if(!$email || !$certificate || !$serialnumber || !$authoritykeyidentifier) |
---|
481 | return false; |
---|
482 | // Insere uma chave publica na tabela phpgw_certificados. |
---|
483 | $data = array ('email' => $email, |
---|
484 | 'chave_publica' => $certificate, |
---|
485 | 'serialnumber' => $serialnumber, |
---|
486 | 'authoritykeyidentifier' => $authoritykeyidentifier); |
---|
487 | |
---|
488 | if(!$this->db->insert('phpgw_certificados',$data,array(),__LINE__,__FILE__)){ |
---|
489 | return $this->db->Error; |
---|
490 | } |
---|
491 | return true; |
---|
492 | } |
---|
493 | |
---|
494 | function get_certificate($email=null) |
---|
495 | { |
---|
496 | if(!$email) return false; |
---|
497 | $result = array(); |
---|
498 | |
---|
499 | $where = array ('email' => $email, |
---|
500 | 'revogado' => 0, |
---|
501 | 'expirado' => 0); |
---|
502 | |
---|
503 | if(!$this->db->select('phpgw_certificados','chave_publica', $where, __LINE__,__FILE__)) |
---|
504 | { |
---|
505 | $result['dberr1'] = $this->db->Error; |
---|
506 | return $result; |
---|
507 | } |
---|
508 | $regs = array(); |
---|
509 | while($this->db->next_record()) |
---|
510 | { |
---|
511 | $regs[] = $this->db->row(); |
---|
512 | } |
---|
513 | if (count($regs) == 0) |
---|
514 | { |
---|
515 | $result['dberr2'] = ' Certificado nao localizado.'; |
---|
516 | return $result; |
---|
517 | } |
---|
518 | $result['certs'] = $regs; |
---|
519 | return $result; |
---|
520 | } |
---|
521 | |
---|
522 | function update_certificate($serialnumber=null,$email=null,$authoritykeyidentifier,$expirado,$revogado) |
---|
523 | { |
---|
524 | if(!$email || !$serialnumber) return false; |
---|
525 | if(!$expirado) |
---|
526 | $expirado = 0; |
---|
527 | if(!$revogado) |
---|
528 | $revogado = 0; |
---|
529 | |
---|
530 | $data = array ('expirado' => $expirado, |
---|
531 | 'revogado' => $revogado); |
---|
532 | |
---|
533 | $where = array ('email' => $email, |
---|
534 | 'serialnumber' => $serialnumber, |
---|
535 | 'authoritykeyidentifier' => $authoritykeyidentifier); |
---|
536 | |
---|
537 | if(!$this->db->update('phpgw_certificados',$data,$where,__LINE__,__FILE__)) |
---|
538 | { |
---|
539 | return $this->db->Error; |
---|
540 | } |
---|
541 | return true; |
---|
542 | } |
---|
543 | |
---|
544 | |
---|
545 | /** |
---|
546 | * @abstract Recupera o valor da regra padrão. |
---|
547 | * @return retorna o valor da regra padrão. |
---|
548 | */ |
---|
549 | function get_default_max_size_rule() |
---|
550 | { |
---|
551 | $query = "SELECT config_value FROM phpgw_config WHERE config_name = 'expressoAdmin_default_max_size'"; |
---|
552 | if(!$this->db->query($query)) |
---|
553 | return false; |
---|
554 | |
---|
555 | $return = array(); |
---|
556 | |
---|
557 | while($this->db->next_record()) |
---|
558 | array_push($return, $this->db->row()); |
---|
559 | |
---|
560 | return $return; |
---|
561 | } |
---|
562 | |
---|
563 | /** |
---|
564 | * @abstract Recupera a regra de um usuário. |
---|
565 | * @return retorna a regra que o usuário pertence. Caso o usuário não participe de nenhuma regra, retorna false. |
---|
566 | */ |
---|
567 | function get_rule_by_user($id_user) |
---|
568 | { |
---|
569 | $return = array(); |
---|
570 | $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user='$id_user' AND configuration_type='MessageMaxSize'"; |
---|
571 | |
---|
572 | if(!$this->db->query($query)) |
---|
573 | return false; |
---|
574 | |
---|
575 | while($this->db->next_record()) |
---|
576 | array_push($return, $this->db->row()); |
---|
577 | |
---|
578 | return $return; |
---|
579 | } |
---|
580 | |
---|
581 | |
---|
582 | function get_rule_by_user_in_groups($id_group) |
---|
583 | { |
---|
584 | $return = array(); |
---|
585 | $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE configuration_type='MessageMaxSize' AND email_user_type='G' AND email_user='".$id_group."'"; |
---|
586 | |
---|
587 | if(!$this->db->query($query)) |
---|
588 | return false; |
---|
589 | |
---|
590 | while($this->db->next_record()) |
---|
591 | array_push($return, $this->db->row()); |
---|
592 | |
---|
593 | return $return; |
---|
594 | } |
---|
595 | function getMaximumRecipientsUser($pUserUID) |
---|
596 | { |
---|
597 | |
---|
598 | $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$pUserUID.'\' AND configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' '; |
---|
599 | $this->db->query($query); |
---|
600 | |
---|
601 | $return = array(); |
---|
602 | |
---|
603 | while($this->db->next_record()) |
---|
604 | $return = $this->db->row(); |
---|
605 | |
---|
606 | return $return['email_max_recipient']; |
---|
607 | } |
---|
608 | |
---|
609 | function getMaximumRecipientsGroup($pGroupsGuidnumbers) |
---|
610 | { |
---|
611 | $groupsGuidNumbers = ''; |
---|
612 | |
---|
613 | foreach ($pGroupsGuidnumbers as $guidNumber => $cn) |
---|
614 | $groupsGuidNumbers .= $guidNumber.', '; |
---|
615 | |
---|
616 | $groupsGuidNumbers = substr($groupsGuidNumbers,0,-2); |
---|
617 | |
---|
618 | $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user IN ('.$groupsGuidNumbers.') AND configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' '; |
---|
619 | $this->db->query($query); |
---|
620 | |
---|
621 | $return = array(); |
---|
622 | |
---|
623 | while($this->db->next_record()) |
---|
624 | $return[] = $this->db->row(); |
---|
625 | |
---|
626 | $maxSenderReturn = 0; |
---|
627 | |
---|
628 | foreach ($return as $maxSender) |
---|
629 | { |
---|
630 | if($maxSender['email_max_recipient'] > $maxSenderReturn) |
---|
631 | $maxSenderReturn = $maxSender['email_max_recipient']; |
---|
632 | } |
---|
633 | |
---|
634 | return $maxSenderReturn; |
---|
635 | } |
---|
636 | |
---|
637 | function validadeSharedAccounts($user,$grups,$accountsMails) |
---|
638 | { |
---|
639 | |
---|
640 | $arrayMailsBlocked = array(); |
---|
641 | |
---|
642 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$user.'\' AND email_recipient = \'*\' AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' '; |
---|
643 | $this->db->query($query); |
---|
644 | $this->db->next_record(); |
---|
645 | if($this->db->row()) |
---|
646 | return $arrayMailsBlocked; |
---|
647 | |
---|
648 | foreach ($grups as $guidNumber => $cn) |
---|
649 | { |
---|
650 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$guidNumber.'\' AND email_recipient = \'*\' AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' '; |
---|
651 | $this->db->query($query); |
---|
652 | $this->db->next_record(); |
---|
653 | if($this->db->row()) |
---|
654 | return $arrayMailsBlocked; |
---|
655 | |
---|
656 | } |
---|
657 | |
---|
658 | foreach ($accountsMails as $mail) |
---|
659 | { |
---|
660 | |
---|
661 | $blocked = true; |
---|
662 | |
---|
663 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_recipient = \''.$mail.'\' AND configuration_type = \'InstitutionalAccountException\' '; |
---|
664 | $this->db->query($query); |
---|
665 | |
---|
666 | while($this->db->next_record()) |
---|
667 | { |
---|
668 | $row = $this->db->row(); |
---|
669 | |
---|
670 | if(($row['email_user'] == '*' || $row['email_user'] == $user) && ($row['email_user_type'] == 'T' || $row['email_user_type'] == 'U')) |
---|
671 | $blocked = false; |
---|
672 | else if(array_key_exists($row['email_user'], $grups) && $row['email_user_type'] == 'G') |
---|
673 | $blocked = false; |
---|
674 | |
---|
675 | } |
---|
676 | |
---|
677 | if($blocked == true) |
---|
678 | array_push ($arrayMailsBlocked, $mail); |
---|
679 | } |
---|
680 | |
---|
681 | return $arrayMailsBlocked; |
---|
682 | } |
---|
683 | |
---|
684 | function write_log($action, $about) |
---|
685 | { |
---|
686 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) " |
---|
687 | . "VALUES('now','" . $_SESSION['phpgw_info']['expressomail']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')"; |
---|
688 | if (!$this->db->query($sql)) { |
---|
689 | return false; |
---|
690 | } |
---|
691 | return true; |
---|
692 | } |
---|
693 | } |
---|
694 | ?> |
---|