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