db = new db(); $this->db->Halt_On_Error = 'no'; } // BEGIN of functions. function get_cc_contacts() { $result = array(); $stringDropDownContacts = ''; // Pesquisa no CC os nomes e email dos contatos. $query = 'select A.names_ordered, C.connection_value from phpgw_cc_contact A,'. 'phpgw_cc_contact_conns B, phpgw_cc_connections C where '. 'A.id_contact = B.id_contact and B.id_connection = C.id_connection '. 'and B.id_typeof_contact_connection = 1 and '. 'A.id_owner ='.$this -> user_id.' order by A.names_ordered'; if (!$this->db->query($query)) return null; while($this->db->next_record()) $result[] = $this->db->row(); if (count($result) != 0) { // Monta string foreach($result as $contact) $stringDropDownContacts = $stringDropDownContacts . $contact['names_ordered']. ';' . $contact['connection_value'] . ','; //Retira ultima virgula. $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); } else return null; return $stringDropDownContacts; } function get_cc_groups() { // Pesquisa no CC os Grupos Pessoais. $stringDropDownContacts = ''; $result = array(); $query = 'select title, short_name from phpgw_cc_groups where owner ='.$this -> user_id.' order by title'; // Executa a query if (!$this->db->query($query)) return null; // Retorna cada resultado while($this->db->next_record()) $result[] = $this->db->row(); // Se houver grupos .... if (count($result) != 0) { foreach($result as $group) $stringDropDownContacts .= $group['title']. ';' . $group['short_name'] . ','; //Retira ultima virgula. $stringDropDownContacts = substr($stringDropDownContacts,0,(strlen($stringDropDownContacts) - 1)); } else return null; return $stringDropDownContacts; } function getContactsByGroupAlias($alias) { $query = "select C.id_connection, A.names_ordered, C.connection_value from phpgw_cc_contact A, ". "phpgw_cc_contact_conns B, phpgw_cc_connections C,phpgw_cc_contact_grps D,phpgw_cc_groups E where ". "A.id_contact = B.id_contact and B.id_connection = C.id_connection ". "and B.id_typeof_contact_connection = 1 and ". "A.id_owner =".$this -> user_id." and ". "D.id_group = E.id_group and ". "D.id_connection = C.id_connection and E.short_name = '".$alias. "' order by A.names_ordered"; if (!$this->db->query($query)) { exit ('Query failed! File: '.__FILE__.' on line'.__LINE__); } $return = false; while($this->db->next_record()) { $return[] = $this->db->row(); } return $return; } function getAddrs($array_addrs) { $array_addrs_final = array(); for($i = 0; $i < count($array_addrs); $i++){ $j = count($array_addrs_final); if(!strchr($array_addrs[$i],'@') && strchr($array_addrs[$i],'<') && strchr($array_addrs[$i],'>')) { $alias = substr($array_addrs[$i], strpos($array_addrs[$i],'<'), strpos($array_addrs[$i],'>')); $alias = str_replace('<','', str_replace('>','',$alias)); $arrayContacts = $this -> getContactsByGroupAlias($alias); if($arrayContacts) { foreach($arrayContacts as $index => $contact){ if($contact['names_ordered']) { $array_addrs_final[$j] = '"'.$contact['names_ordered'].'" <'.$contact['connection_value'].'>'; } else $array_addrs_final[$j] = $contact['connection_value']; $j++; } } } else $array_addrs_final[$j++] = $array_addrs[$i]; } return $array_addrs_final; } function get_dropdown_contacts(){ $contacts = $this -> get_cc_contacts(); $groups = $this -> get_cc_groups(); if(($contacts) && ($groups)) $stringDropDownContacts = $contacts . ',' . $groups; elseif ((!$contacts) && (!$groups)) $stringDropDownContacts = ''; elseif (($contacts) && (!$groups)) $stringDropDownContacts = $contacts; elseif ((!$contacts) && ($groups)) $stringDropDownContacts = $groups; return $stringDropDownContacts; } /* function update_preferences($params){ $aux = explode("##",$params['prefe_string']); $new_prefe = array(); foreach($aux as $key=>$tmp){ if($key == 0){ $new_prefe['max_email_per_page'] = $tmp; } if($key == 1){ $new_prefe['save_deleted_msg'] = $tmp; } if($key == 2){ $new_prefe['delete_trash_messages_after_n_days'] = $tmp; } if($key == 3){ $new_prefe['delete_and_show_previous_message'] = $tmp; } if($key == 4){ $new_prefe['alert_new_msg'] = $tmp; } if($key == 5){ $new_prefe['mainscreen_showmail'] = $tmp; } if($key == 10){ $new_prefe['signature'] = $tmp; } if($key == 7){ $new_prefe['hide_folders'] = $tmp; } if($key == 6){ $new_prefe['save_in_folder'] = $tmp; } if($key == 8){ $new_prefe['line_height'] = $tmp; } if($key == 9){ $new_prefe['font_size'] = $tmp; } if($key == 11){ $new_prefe['use_shortcuts'] = $tmp; } } $string_serial = serialize($new_prefe); $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial); $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'". " and preference_owner = '".$this->user_id."'"; if (!$this->db->query($query)) return "Failed!"; else return "OK!"; } */ function update_preferences($params){ $string_serial = urldecode($params['prefe_string']); $string_serial = get_magic_quotes_gpc() ? $string_serial : addslashes($string_serial); $query = "update phpgw_preferences set preference_value = '".$string_serial."' where preference_app = 'expressoMail'". " and preference_owner = '".$this->user_id."'"; if (!$this->db->query($query)) return $this->db->error; else return array("success" => true); } function getUserByEmail($params){ // Follow the referral $email = $params['email']; $query = 'select A.names_ordered, C.connection_name, C.connection_value, A.photo'. ' from phpgw_cc_contact A, phpgw_cc_contact_conns B, '. 'phpgw_cc_connections C where A.id_contact = B.id_contact'. ' and B.id_connection = C.id_connection and A.id_contact ='. '(select A.id_contact from phpgw_cc_contact A, phpgw_cc_contact_conns B,'. 'phpgw_cc_connections C where A.id_contact = B.id_contact'. ' and B.id_connection = C.id_connection and A.id_owner = '.$this -> user_id. ' and C.connection_value = \''.$email.'\') and '. 'C.connection_is_default = true and B.id_typeof_contact_connection = 2'; if (!$this->db->query($query)) return null; if($this->db->next_record()) { $result = $this->db->row(); $obj = array("cn" => $result['names_ordered'], "email" => $email, "type" => "personal", "telefone" => $result['connection_value']); if($result['photo']) $_SESSION['phpgw_info']['expressomail']['contact_photo'] = array($result['photo']); return $obj; } return $result; } } ?>