[2] | 1 | <?php |
---|
[5509] | 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 | |
---|
[3018] | 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 | } |
---|
[413] | 26 | include_once('class.dynamic_contacts.inc.php'); |
---|
[502] | 27 | |
---|
[2] | 28 | class db_functions |
---|
| 29 | { |
---|
| 30 | |
---|
| 31 | var $db; |
---|
| 32 | var $user_id; |
---|
[757] | 33 | var $related_ids; |
---|
[2] | 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(); |
---|
[525] | 53 | $stringDropDownContacts = ''; |
---|
[757] | 54 | |
---|
| 55 | $query_related = $this->get_query_related('A.id_owner'); // field name for owner |
---|
[525] | 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 '. |
---|
[757] | 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 | |
---|
[2] | 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) |
---|
[1992] | 73 | $stringDropDownContacts = $stringDropDownContacts . urldecode(urldecode($contact['names_ordered'])). ';' . $contact['connection_value'] . ','; |
---|
[2] | 74 | //Retira ultima virgula. |
---|
| 75 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
| 76 | } |
---|
| 77 | else |
---|
| 78 | return null; |
---|
| 79 | |
---|
| 80 | return $stringDropDownContacts; |
---|
| 81 | } |
---|
[757] | 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 | |
---|
[1738] | 92 | $result = array( ); |
---|
[757] | 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 | } |
---|
[2] | 105 | function get_cc_groups() |
---|
| 106 | { |
---|
| 107 | // Pesquisa no CC os Grupos Pessoais. |
---|
| 108 | $stringDropDownContacts = ''; |
---|
| 109 | $result = array(); |
---|
[757] | 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 | |
---|
[2] | 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(); |
---|
[757] | 119 | |
---|
| 120 | // Se houver grupos .... |
---|
[2] | 121 | if (count($result) != 0) |
---|
[757] | 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 | } |
---|
[906] | 129 | $owneruid = ''; |
---|
[757] | 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). |
---|
[1738] | 133 | if(!isset($_SESSION['phpgw_info']['expressomail']['user']['cc_related_ids'][$group['owner']]) && isset($ldap)){ |
---|
[757] | 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']]; |
---|
[906] | 138 | else |
---|
| 139 | $owneruid = ''; |
---|
[757] | 140 | |
---|
| 141 | $stringDropDownContacts .= $group['title']. ';' . ($group['short_name'].$owneruid) . ','; |
---|
| 142 | } |
---|
[2] | 143 | //Retira ultima virgula. |
---|
| 144 | $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); |
---|
| 145 | } |
---|
| 146 | else |
---|
[757] | 147 | return null; |
---|
[2] | 148 | return $stringDropDownContacts; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | function getContactsByGroupAlias($alias) |
---|
| 152 | { |
---|
[757] | 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 | } |
---|
[2] | 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 ". |
---|
[757] | 164 | "A.id_owner =".($owner ? $owner : $this->user_id)." and ". |
---|
[2] | 165 | "D.id_group = E.id_group and ". |
---|
[757] | 166 | "D.id_connection = C.id_connection and E.short_name = '".$alias."'"; |
---|
[2] | 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 | |
---|
[5380] | 189 | if(preg_replace('/\s+/', '', $array_addrs[$i]) != ""){ |
---|
[5805] | 190 | |
---|
[5380] | 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)); |
---|
[5805] | 195 | |
---|
[5380] | 196 | } |
---|
| 197 | else{ |
---|
| 198 | $alias = $array_addrs[$i]; |
---|
| 199 | $alias = preg_replace('/\s/', '', $alias); |
---|
| 200 | } |
---|
[5805] | 201 | |
---|
[5380] | 202 | $arrayContacts = $this -> getContactsByGroupAlias($alias); |
---|
[2] | 203 | |
---|
[5805] | 204 | |
---|
[5380] | 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']; |
---|
[2] | 212 | |
---|
[5380] | 213 | $j++; |
---|
[2] | 214 | } |
---|
[5380] | 215 | }else{ |
---|
| 216 | return array("False" => "$alias"); |
---|
[2] | 217 | } |
---|
| 218 | } |
---|
[5805] | 219 | //-- validação email -- |
---|
[5380] | 220 | else{ |
---|
[5819] | 221 | $array_addrs[$i] = trim($array_addrs[$i]); |
---|
[5805] | 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 | } |
---|
[5380] | 241 | } |
---|
[5805] | 242 | //-- fim -- |
---|
[5380] | 243 | }else{ |
---|
| 244 | $array_addrs_final[$j] = $array_addrs[$i]; |
---|
| 245 | } |
---|
[2] | 246 | } |
---|
| 247 | return $array_addrs_final; |
---|
| 248 | } |
---|
| 249 | |
---|
[1939] | 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 | |
---|
[502] | 255 | function get_dropdown_contacts(){ |
---|
[5134] | 256 | $contacts = $this->get_cc_contacts(); |
---|
| 257 | $groups = $this->get_cc_groups(); |
---|
[2] | 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; |
---|
[502] | 267 | |
---|
[5134] | 268 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['use_dynamic_contacts']) { |
---|
[3018] | 269 | // Free others requests |
---|
| 270 | session_write_close(); |
---|
[484] | 271 | $dynamic_contact = new dynamic_contacts(); |
---|
| 272 | $dynamic = $dynamic_contact->dynamic_contact_toString(); |
---|
[413] | 273 | if ($dynamic) |
---|
[484] | 274 | $stringDropDownContacts .= ($stringDropDownContacts ? ',' : '') . $dynamic; |
---|
| 275 | } |
---|
[2] | 276 | return $stringDropDownContacts; |
---|
| 277 | } |
---|
[27] | 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 | } |
---|
[413] | 310 | |
---|
| 311 | function get_dynamic_contacts() |
---|
| 312 | { |
---|
| 313 | // Pesquisa os emails e ultima inserção nos contatos dinamicos. |
---|
[5134] | 314 | if(!$this->db->select('phpgw_expressomail_contacts','data','id_owner ='.$this->user_id,__LINE__,__FILE__)) |
---|
[413] | 315 | { |
---|
| 316 | return $this->db->Error; |
---|
[502] | 317 | } |
---|
[413] | 318 | while($this->db->next_record()) |
---|
| 319 | { |
---|
| 320 | $result[] = $this->db->row(); |
---|
| 321 | } |
---|
[455] | 322 | if($result) foreach($result as $item) |
---|
[413] | 323 | { |
---|
| 324 | $contacts = unserialize($item['data']); |
---|
| 325 | } |
---|
| 326 | if (count($contacts) == 0) |
---|
| 327 | { |
---|
| 328 | return null; |
---|
| 329 | } |
---|
[484] | 330 | //Sort by email |
---|
| 331 | function cmp($a, $b) { return strcmp($a["email"], $b["email"]);} |
---|
| 332 | usort($contacts,"cmp"); |
---|
[413] | 333 | return $contacts; |
---|
| 334 | } |
---|
| 335 | function update_contacts($contacts=array()) |
---|
| 336 | { |
---|
[5134] | 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); |
---|
[413] | 360 | // Atualiza um email nos contatos dinamicos. |
---|
[5134] | 361 | if(!$this->db->update('phpgw_expressomail_contacts ','data=\''.serialize($old_contatacts).'\'','id_owner ='.$this->user_id,__LINE__,__FILE__)) |
---|
[413] | 362 | { |
---|
[1308] | 363 | return $this->db->Error; |
---|
[413] | 364 | } |
---|
[1308] | 365 | return $contacts; |
---|
[413] | 366 | } |
---|
[1308] | 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 | } |
---|
[413] | 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 | } |
---|
[673] | 398 | |
---|
| 399 | function import_vcard($params){ |
---|
[5388] | 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']; |
---|
[5134] | 406 | $from_ajax = $params['from_ajax']; |
---|
[5388] | 407 | $encoding = strtolower($params['encoding']); |
---|
| 408 | $fileContent = ""; |
---|
[5134] | 409 | $cirus_delimiter = $params['cirus_delimiter']; |
---|
| 410 | $expFolder = explode($cirus_delimiter, $msg_folder); |
---|
[673] | 411 | |
---|
[5134] | 412 | if($msg_number != null && $msg_part != null && $msg_folder != null && (intval($idx_file == '0' ? '1' : $idx_file))) |
---|
| 413 | { |
---|
[5388] | 414 | require_once PHPGW_INCLUDE_ROOT.'/expressoMail1_2/inc/class.attachment.inc.php'; |
---|
[5134] | 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']; |
---|
[5388] | 420 | } |
---|
| 421 | else |
---|
| 422 | $filename = $idx_file; |
---|
| 423 | |
---|
| 424 | // It's necessary to access calendar method. |
---|
[5134] | 425 | $GLOBALS['phpgw_info']['flags']['noappheader'] = True; |
---|
| 426 | $GLOBALS['phpgw_info']['flags']['noappfooter'] = True; |
---|
| 427 | $GLOBALS['phpgw_info']['flags']['currentapp'] = 'calendar'; |
---|
[6105] | 428 | |
---|
[6331] | 429 | if(isset($params['selected']) || isset($params['readable'])){ |
---|
[5394] | 430 | |
---|
[5388] | 431 | $_REQUEST['data'] = $fileContent; |
---|
| 432 | $_REQUEST['type'] = 'iCal'; |
---|
[6331] | 433 | $_REQUEST['params']['calendar'] = isset($params['selected']) ? $params['selected'] : false; |
---|
| 434 | $_REQUEST['readable'] = (isset($params['readable']) && $params['readable']) ? true : false; |
---|
[6295] | 435 | $_REQUEST['analize'] = isset($params['analize']) ? true : false; |
---|
[6331] | 436 | $_REQUEST['params']['status'] = isset($params['status']) ? $params['status'] : false; |
---|
| 437 | $_REQUEST['params']['owner'] = $params['uidAccount']; |
---|
[5514] | 438 | if(isset($params['acceptedSuggestion'])){ |
---|
| 439 | $_REQUEST['params']['acceptedSuggestion'] = $params['acceptedSuggestion']; |
---|
| 440 | $_REQUEST['params']['from'] = $params['from']; |
---|
| 441 | } |
---|
| 442 | |
---|
[5388] | 443 | ob_start(); |
---|
| 444 | include_once(PHPGW_INCLUDE_ROOT.'/prototype/converter.php'); |
---|
| 445 | $output = ob_get_clean(); |
---|
| 446 | $valid = json_decode($output, true); |
---|
[5916] | 447 | |
---|
[5388] | 448 | if($_REQUEST['readable']){ |
---|
[5465] | 449 | if(!is_array($valid)) |
---|
[5388] | 450 | { |
---|
[5415] | 451 | $output = unserialize($output); |
---|
[5916] | 452 | foreach($output as $key => $value) |
---|
| 453 | return $value; |
---|
[5388] | 454 | } |
---|
| 455 | return false; |
---|
[5916] | 456 | } |
---|
| 457 | if(empty($output)) |
---|
[5388] | 458 | return "error"; |
---|
| 459 | return "ok"; |
---|
| 460 | } |
---|
[6105] | 461 | |
---|
| 462 | include_once(PHPGW_INCLUDE_ROOT.'/header.inc.php'); |
---|
| 463 | $uiicalendar = CreateObject("calendar.uiicalendar"); |
---|
[5134] | 464 | if(strtoupper($expFolder[0]) == 'USER' && $expFolder[1]) // IF se a conta o ical estiver em uma conta compartilhada |
---|
| 465 | { |
---|
| 466 | include_once('class.ldap_functions.inc.php'); |
---|
| 467 | $ldap = new ldap_functions(); |
---|
| 468 | $account['uid'] = $expFolder[1]; |
---|
| 469 | $account['uidnumber'] = $ldap->uid2uidnumber($expFolder[1]); |
---|
| 470 | $account['mail'] = $ldap->getMailByUid($expFolder[1]); |
---|
| 471 | |
---|
| 472 | return $uiicalendar->import_from_mail($fileContent, $from_ajax,$account); |
---|
| 473 | } |
---|
| 474 | else |
---|
| 475 | return $uiicalendar->import_from_mail($fileContent, $from_ajax); |
---|
[5388] | 476 | |
---|
[673] | 477 | } |
---|
[1035] | 478 | |
---|
| 479 | function insert_certificate($email,$certificate,$serialnumber,$authoritykeyidentifier=null) |
---|
| 480 | { |
---|
| 481 | if(!$email || !$certificate || !$serialnumber || !$authoritykeyidentifier) |
---|
| 482 | return false; |
---|
| 483 | // Insere uma chave publica na tabela phpgw_certificados. |
---|
| 484 | $data = array ('email' => $email, |
---|
| 485 | 'chave_publica' => $certificate, |
---|
| 486 | 'serialnumber' => $serialnumber, |
---|
| 487 | 'authoritykeyidentifier' => $authoritykeyidentifier); |
---|
| 488 | |
---|
| 489 | if(!$this->db->insert('phpgw_certificados',$data,array(),__LINE__,__FILE__)){ |
---|
| 490 | return $this->db->Error; |
---|
| 491 | } |
---|
| 492 | return true; |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | function get_certificate($email=null) |
---|
| 496 | { |
---|
| 497 | if(!$email) return false; |
---|
| 498 | $result = array(); |
---|
| 499 | |
---|
| 500 | $where = array ('email' => $email, |
---|
| 501 | 'revogado' => 0, |
---|
| 502 | 'expirado' => 0); |
---|
| 503 | |
---|
| 504 | if(!$this->db->select('phpgw_certificados','chave_publica', $where, __LINE__,__FILE__)) |
---|
| 505 | { |
---|
| 506 | $result['dberr1'] = $this->db->Error; |
---|
| 507 | return $result; |
---|
| 508 | } |
---|
| 509 | $regs = array(); |
---|
| 510 | while($this->db->next_record()) |
---|
| 511 | { |
---|
| 512 | $regs[] = $this->db->row(); |
---|
| 513 | } |
---|
| 514 | if (count($regs) == 0) |
---|
| 515 | { |
---|
| 516 | $result['dberr2'] = ' Certificado nao localizado.'; |
---|
| 517 | return $result; |
---|
| 518 | } |
---|
| 519 | $result['certs'] = $regs; |
---|
| 520 | return $result; |
---|
| 521 | } |
---|
| 522 | |
---|
| 523 | function update_certificate($serialnumber=null,$email=null,$authoritykeyidentifier,$expirado,$revogado) |
---|
| 524 | { |
---|
| 525 | if(!$email || !$serialnumber) return false; |
---|
| 526 | if(!$expirado) |
---|
| 527 | $expirado = 0; |
---|
| 528 | if(!$revogado) |
---|
| 529 | $revogado = 0; |
---|
| 530 | |
---|
| 531 | $data = array ('expirado' => $expirado, |
---|
| 532 | 'revogado' => $revogado); |
---|
| 533 | |
---|
| 534 | $where = array ('email' => $email, |
---|
| 535 | 'serialnumber' => $serialnumber, |
---|
| 536 | 'authoritykeyidentifier' => $authoritykeyidentifier); |
---|
| 537 | |
---|
| 538 | if(!$this->db->update('phpgw_certificados',$data,$where,__LINE__,__FILE__)) |
---|
| 539 | { |
---|
| 540 | return $this->db->Error; |
---|
| 541 | } |
---|
| 542 | return true; |
---|
| 543 | } |
---|
| 544 | |
---|
[5134] | 545 | |
---|
| 546 | /** |
---|
| 547 | * @abstract Recupera o valor da regra padrão. |
---|
| 548 | * @return retorna o valor da regra padrão. |
---|
| 549 | */ |
---|
| 550 | function get_default_max_size_rule() |
---|
| 551 | { |
---|
| 552 | $query = "SELECT config_value FROM phpgw_config WHERE config_name = 'expressoAdmin_default_max_size'"; |
---|
| 553 | if(!$this->db->query($query)) |
---|
| 554 | return false; |
---|
| 555 | |
---|
| 556 | $return = array(); |
---|
| 557 | |
---|
| 558 | while($this->db->next_record()) |
---|
| 559 | array_push($return, $this->db->row()); |
---|
| 560 | |
---|
| 561 | return $return; |
---|
| 562 | } |
---|
| 563 | |
---|
| 564 | /** |
---|
| 565 | * @abstract Recupera a regra de um usuário. |
---|
| 566 | * @return retorna a regra que o usuário pertence. Caso o usuário não participe de nenhuma regra, retorna false. |
---|
| 567 | */ |
---|
| 568 | function get_rule_by_user($id_user) |
---|
| 569 | { |
---|
| 570 | $return = array(); |
---|
| 571 | $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user='$id_user' AND configuration_type='MessageMaxSize'"; |
---|
| 572 | |
---|
| 573 | if(!$this->db->query($query)) |
---|
| 574 | return false; |
---|
| 575 | |
---|
| 576 | while($this->db->next_record()) |
---|
| 577 | array_push($return, $this->db->row()); |
---|
| 578 | |
---|
| 579 | return $return; |
---|
| 580 | } |
---|
| 581 | |
---|
| 582 | |
---|
| 583 | function get_rule_by_user_in_groups($id_group) |
---|
| 584 | { |
---|
| 585 | $return = array(); |
---|
| 586 | $query = "SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE configuration_type='MessageMaxSize' AND email_user_type='G' AND email_user='".$id_group."'"; |
---|
| 587 | |
---|
| 588 | if(!$this->db->query($query)) |
---|
| 589 | return false; |
---|
| 590 | |
---|
| 591 | while($this->db->next_record()) |
---|
| 592 | array_push($return, $this->db->row()); |
---|
| 593 | |
---|
| 594 | return $return; |
---|
| 595 | } |
---|
| 596 | function getMaximumRecipientsUser($pUserUID) |
---|
| 597 | { |
---|
| 598 | |
---|
| 599 | $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$pUserUID.'\' AND configuration_type = \'LimitRecipient\' AND email_user_type = \'U\' '; |
---|
| 600 | $this->db->query($query); |
---|
| 601 | |
---|
| 602 | $return = array(); |
---|
| 603 | |
---|
| 604 | while($this->db->next_record()) |
---|
| 605 | $return = $this->db->row(); |
---|
| 606 | |
---|
| 607 | return $return['email_max_recipient']; |
---|
| 608 | } |
---|
| 609 | |
---|
| 610 | function getMaximumRecipientsGroup($pGroupsGuidnumbers) |
---|
| 611 | { |
---|
| 612 | $groupsGuidNumbers = ''; |
---|
| 613 | |
---|
| 614 | foreach ($pGroupsGuidnumbers as $guidNumber => $cn) |
---|
| 615 | $groupsGuidNumbers .= $guidNumber.', '; |
---|
| 616 | |
---|
| 617 | $groupsGuidNumbers = substr($groupsGuidNumbers,0,-2); |
---|
| 618 | |
---|
| 619 | $query = 'SELECT email_max_recipient FROM phpgw_expressoadmin_configuration WHERE email_user IN ('.$groupsGuidNumbers.') AND configuration_type = \'LimitRecipient\' AND email_user_type = \'G\' '; |
---|
| 620 | $this->db->query($query); |
---|
| 621 | |
---|
| 622 | $return = array(); |
---|
| 623 | |
---|
| 624 | while($this->db->next_record()) |
---|
| 625 | $return[] = $this->db->row(); |
---|
| 626 | |
---|
| 627 | $maxSenderReturn = 0; |
---|
| 628 | |
---|
| 629 | foreach ($return as $maxSender) |
---|
| 630 | { |
---|
| 631 | if($maxSender['email_max_recipient'] > $maxSenderReturn) |
---|
| 632 | $maxSenderReturn = $maxSender['email_max_recipient']; |
---|
| 633 | } |
---|
| 634 | |
---|
| 635 | return $maxSenderReturn; |
---|
| 636 | } |
---|
| 637 | |
---|
| 638 | function validadeSharedAccounts($user,$grups,$accountsMails) |
---|
| 639 | { |
---|
| 640 | |
---|
| 641 | $arrayMailsBlocked = array(); |
---|
| 642 | |
---|
| 643 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$user.'\' AND email_recipient = \'*\' AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'U\' '; |
---|
| 644 | $this->db->query($query); |
---|
| 645 | $this->db->next_record(); |
---|
| 646 | if($this->db->row()) |
---|
| 647 | return $arrayMailsBlocked; |
---|
| 648 | |
---|
| 649 | foreach ($grups as $guidNumber => $cn) |
---|
| 650 | { |
---|
| 651 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_user = \''.$guidNumber.'\' AND email_recipient = \'*\' AND configuration_type = \'InstitutionalAccountException\' AND email_user_type = \'G\' '; |
---|
| 652 | $this->db->query($query); |
---|
| 653 | $this->db->next_record(); |
---|
| 654 | if($this->db->row()) |
---|
| 655 | return $arrayMailsBlocked; |
---|
| 656 | |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | foreach ($accountsMails as $mail) |
---|
| 660 | { |
---|
| 661 | |
---|
| 662 | $blocked = true; |
---|
| 663 | |
---|
| 664 | $query = 'SELECT * FROM phpgw_expressoadmin_configuration WHERE email_recipient = \''.$mail.'\' AND configuration_type = \'InstitutionalAccountException\' '; |
---|
| 665 | $this->db->query($query); |
---|
| 666 | |
---|
| 667 | while($this->db->next_record()) |
---|
| 668 | { |
---|
| 669 | $row = $this->db->row(); |
---|
| 670 | |
---|
| 671 | if(($row['email_user'] == '*' || $row['email_user'] == $user) && ($row['email_user_type'] == 'T' || $row['email_user_type'] == 'U')) |
---|
| 672 | $blocked = false; |
---|
| 673 | else if(array_key_exists($row['email_user'], $grups) && $row['email_user_type'] == 'G') |
---|
| 674 | $blocked = false; |
---|
| 675 | |
---|
| 676 | } |
---|
| 677 | |
---|
| 678 | if($blocked == true) |
---|
| 679 | array_push ($arrayMailsBlocked, $mail); |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | return $arrayMailsBlocked; |
---|
| 683 | } |
---|
| 684 | |
---|
[5821] | 685 | function write_log($action, $about) |
---|
| 686 | { |
---|
| 687 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, userinfo) " |
---|
| 688 | . "VALUES('now','" . $_SESSION['phpgw_info']['expressomail']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($about) . "')"; |
---|
| 689 | if (!$this->db->query($sql)) { |
---|
| 690 | return false; |
---|
| 691 | } |
---|
| 692 | return true; |
---|
| 693 | } |
---|
[2] | 694 | } |
---|
[1037] | 695 | ?> |
---|